akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }



struct UnionFind {
    vector<int> par, sz;
    
    UnionFind(int n) : par(n, -1), sz(n, 0) { }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) {
            sz[x] += 1;
            return false;
        }
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        sz[x] += sz[y] + 1;
        return true;
    }
    
    int size(int x) {
        return sz[root(x)];
    }

    int set(int x, int v) {
        par[root(x)] = v;
    }
};


/* debug */
/*
ostream& operator << (ostream& s, UnionFind uf) {
    map<int, vector<int> > res;
    for (int i = 0; i < uf.par.size(); ++i) {
        int r = uf.root(i);
        res[r].push_back(i);
    }
    for (map<int, vector<int> >::iterator it = res.begin(); it != res.end(); ++it) {
        s << endl;
        for (int j = 0; j < (int)it->second.size(); ++j) {
            s << it->second[j] << ", ";
        }
    }
    return s << endl;
}
*/


long long H, W, M;
map<int, set<int>> xy, yx;

long long solve() {
    xy.clear(), yx.clear();
    for (int i = 0; i < M; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        xy[x].insert(y);
        yx[y].insert(x);
    }
    int mx = 0, my = 0;
    for (int i = 0; i < H; ++i) chmax(mx, (int)xy[i].size());
    for (int y = 0; y < W; ++y) chmax(my, (int)yx[y].size());

    vector<int> vx, vy;
    for (int x = 0; x < H; ++x) if (xy[x].size() == mx) vx.push_back(x);
    for (int y = 0; y < W; ++y) if (yx[y].size() == my) vy.push_back(y);
    for (auto x : vx) {
        for (auto y : vy) {
            if (!xy[x].count(y)) return mx + my;
        }
    }
    return mx + my - 1;
}


int main() {
    while (cin >> H >> W >> M) {
        cout << solve() << endl;
    }
}

Measured memory_bytes: 91840
n = int(input())
X = [["0", "0", 0]]
for i in range(n):
    s, p = map(str, input().split())
    X.append([s, p, i + 1])
X = sorted(X, key = lambda x : x[0])
X.append(["0", "0", 0])
Y = []
for i in range(1, n + 1):
    if X[i][0] != X[i + 1][0] and X[i - 1][0] != X[i][0]:
        print(X[i][2])
    elif X[i][0] == X[i + 1][0]:
        Y.append([X[i][1], X[i][2]])
    elif X[i][0] != X[i + 1][0] and X[i - 1][0] == X[i][0]:
        Y.append([X[i][1], X[i][2]])
        Y = sorted(Y, key = lambda x : int(x[0]))
        Y.reverse()
        for j in range(len(Y)):
            print(Y[j][1])
        Y = []

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > pipii;
typedef priority_queue<pii,vector<pii>,greater<pii>> minpq;
typedef priority_queue<pii> maxpq;
//const double PI = acos(-1);
const int mod = 1000000007;

// ----------------------DEBUG TEMPLATE--------------------------
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// ----------------------DEBUG TEMPLATE--------------------------



int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s;
    cin>>s;
    s+='S';
    int ans=0;
    int res=0;
    if(s[0]=='R'){
        ans++;
    }
    Fo(i,1,s.length()){
        if(s[i]=='R' && s[i-1]=='R'){
            ans++;
        }
        else if(s[i]=='R' && s[i-1]=='S'){
            ans=1;
        }
        else{
            res=max(res,ans);
            ans=0;
        }
    }
    cout<<res<<endl;




	
	
	
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
from sys import stdin

N = int(stdin.readline().rstrip())
T,A = [int(x) for x in stdin.readline().rstrip().split()]
H = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
target = 100000

for i in range(N):
    deg = T - H[i]*0.006
    gap = abs(deg - A)
    if gap < target:
        ans = i
        target = gap

print(ans+1)

Measured memory_bytes: 3064
loop do
    n, q = gets.split.map(&:to_i)
    break if n == 0 && q == 0
    h = Hash.new
    n.times do
        s = gets.split
        t = h[s[0]]
        if !t
            h[s[0]] = [s[2].to_i - s[1].to_i + 1, s[2].to_i]
        else
            h[s[0]] = [s[2].to_i - s[1].to_i + 1, [s[2].to_i, t[1]].max]
        end
    end
    qr = q.times.map{gets.to_i}
    qr.each do |qq|
        bl = false
        h.each do |k,v|
            if qq.between?(v[0],v[1])
                puts "#{k} #{qq - v[0] + 1}"
                bl = true
                break
            end
        end
        puts "Unknown" if !bl
    end
end

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

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


}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<climits>

using namespace std;
#define x first
#define y second
#define mp make_pair
#define pb push_back

int read()
{
	int x = 0, f = 1; char c = getchar();
	while(!isdigit(c)) { if(c == '-') f = 0; c = getchar(); }
	while(isdigit(c)) { x = (x << 3) + (x << 1) + (c ^ 48); c = getchar(); }
	return f ? x : -x;
}

const int maxn = 2e5 + 10;
int x[maxn], v[maxn], vis[maxn];
vector<pair<int, int> > vec[maxn];
int f1[(int)5e5], f2[(int)5e5];

int main()
{

	int n = read(), V = read();
	x[0] = -1e9 - 2e5 - 10;
	for(int i = 1; i <= n; ++i) x[i] = read();

	v[0] = V;
	int tot = 0; V >>= 1;
	for(tot = 1; ; ++tot) { v[tot] = V; if(!V) break; V >>= 1; }
	for(int i = 0; i <= tot; ++i)
		for(int j = 1; j <= n; ++j)
		{
			if(x[j] - x[j - 1] > v[i]) vec[i].pb(mp(j, j));
			else vec[i][vec[i].size() - 1].y++;
		}

	for(int i = 0; i < (1 << tot); ++i) f2[i] = n + 1;

	for(int i = 1; i <= tot; ++i) 
		f1[1 << i - 1] = vec[i][0].y, f2[1 << i - 1] = vec[i][vec[i].size() - 1].x;

	for(int s = 1; s < (1 << tot); ++s) 
	{
		if(f1[s])
			for(int i = 1; i <= tot; ++i) if(!(s & (1 << i - 1)))
			{
				int p = upper_bound(vec[i].begin(), vec[i].end(), mp(f1[s] + 1, INT_MAX)) - vec[i].begin();
				p--; f1[s | (1 << i - 1)] = max(f1[s | (1 << i - 1)], vec[i][p].y);
			}

		if(f2[s] != n + 1)
			for(int i = 1; i <= tot; ++i) if(!(s & (1 << i - 1)))
			{
				int p = lower_bound(vec[i].begin(), vec[i].end(), mp(f2[s], 0)) - vec[i].begin();
				p--; if(p >= 0) f2[s | (1 << i - 1)] = min(f2[s | (1 << i - 1)], vec[i][p].x);
			}
	}

	for(int i = 0; i < vec[0].size(); ++i)
	{
		int fg = 0;
		for(int s = 0; s < (1 << tot); ++s)
			if(vec[0][i].x <= f1[s] + 1 && vec[0][i].y + 1 >= f2[((1 << tot) - 1) ^ s])
			{ fg = 1; break; }
		if(fg == 1) for(int j = vec[0][i].x; j <= vec[0][i].y; ++j) vis[j] = 1;
	}
	for(int i = 1; i <= n; ++i) if(vis[i]) puts("Possible"); else puts("Impossible");

	return 0;
}

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

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

  vector<int> div;
  for (int i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      div.push_back(i);
      if (m / i != i) div.push_back(m / i);
    }
  }
  sort(div.begin(), div.end());

  for (auto x : div) {
    if (n <= x) {
      cout << m / x << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3620
s = input()

ans = 0
f = 0
be = 0
for k in range(len(s)):
    if s[k] == '<':
        if f != 0 and be != 0:
            ans -= be * f
            be = 0
        ans += be + 1
        f = 0
        be += 1
    elif be ==0:
        f += 1
        ans += be + f
    else:
        f += 1
        ans += be - 1
        be = be - 1
print(ans)


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

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> D, long long M, std::vector<long long> T){
  map<long long, long long> countD;
  map<long long, long long> countT;

  for(long long i = 0; i < N; i++) {
    countD[D[i]]++;
  }

  for(long long i = 0; i < M; i++) {
    countT[T[i]]++;
  }


  for(long long i = 0; i < M; i++) {
    long long now = T[i];
    if(countD[now] < countT[now]) {
      cout << NO << endl;
      return;
    }
  }

  cout << YES << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> D(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&D[i]);
  }
  long long M;
  scanf("%lld",&M);
  std::vector<long long> T(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&T[i]);
  }
    solve(N, std::move(D), M, std::move(T));
    return 0;
}


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

int a,b;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>a>>b;
    if(a>=13){
        cout<<b<<endl;
        return 0;
    }
    if(6<=a){
        cout<<b/2<<endl;
        return 0;
    }
    cout<<0<<endl;

    return 0;
}

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

int main() {
  char b;
  cin >> b;
  char ans;
  if (b == 'A')
  {
    ans = 'T';
  } else if (b == 'C') {
    ans = 'G';
  } else if (b == 'T') {
    ans = 'A';
  } else {
    ans = 'C';
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    int N;
    vector<int> A;

    cin >> N;
    A.resize(N);
    int ans = 0;
    REP(i, N) {
        cin >> A[i];
        if(i % 2 == 0 && A[i] % 2 != 0) {
            ans++;
        }
    }

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

    return 0;
}



Measured memory_bytes: 3684
V, E = [int(_) for _ in input().split()]
G = {}
for i in range(V):
    G[i] = {}
    G[i][i] = 0

for _ in range(E):
    s, t, c = [int(_) for _ in input().split()]
    s -= 1  # 0を始点とする場合
    t -= 1  # 0を始点とする場合
    G[s][t] = c
    G[t][s] = c

INF = 10**10

edges_used = set()
for i in range(V):
    D = [INF] * V
    D[i] = 0  # iを始点とする場合
    used = [False] * V
    used[i] = True
    prev = {}
    while True:
        for j in G[i].keys():
            if D[i] + G[i][j] < D[j]:
                D[j] = D[i] + G[i][j]
                prev[j] = i
        v = -1
        for j in range(V):
            if not used[j] and (v == -1 or D[j] < D[v]):
                v = j
        if v == -1:
            break
        else:
            used[v] = True
            i = v
    for key, value in prev.items():
        if key > value:
            key, value = value, key
        edges_used.add((key + 1, value + 1))

print(E - len(edges_used))

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main() {
	int N, a, b;
	cin >> N;
	int res = 0, count = 0;
	cin >> a;
	for (int i = 1; i < N; i++) {
		cin >> b;
		if (a >= b) count++, res = (res > count) ? res : count;
		else count = 0;
		
		a = b;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()
//a
int main(){

    int a, b; cin >> a >> b;
    cout << a*b << endl;

}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#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 &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;

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

ll lcm(ll a, ll b){
    return a*b / gcd(a,b);
}
int main(){
    ll n,m; cin >> n >> m;
    vector<int> a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) b[i] = a[i] / 2;
    // bool ok = false;
    // while(1){
    //     bool flag1=false, flag0=false;
    //     rep(i,n){
    //         if (b[i]%2==1 && flag1==false) flag1=true;
    //         if (b[i]%2==0 && flag0==false) flag0=true;
    //     }
    //     if (flag1 && flag0) break;
    //     else if (flag1 && !flag0){ok=true; break;}
    // }

    // if (!ok){
    //     cout << 0 << endl;
    //     return 0;
    // }
    ll x = b[0];
    repi(i,1,n){
        ll y = b[i];
        x = lcm(x,y);
    }
    rep(i,n){
        if ((x / b[i]) % 2 == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans;
    if (x>m) ans = 0;
    else ans = (m-x) / (2*x) + 1;
    cout << ans << endl;
    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod=1000000007;
//head

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

    string s, t;
    cin >> s >> t;
    if(t.size() != s.size() + 1) {
        cout << "No" << endl;
    } else if(t.substr(0,s.size()) != s) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}


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

int main() {
    // 入力
    int N;
    cin >> N;
    vector<int>h(N);
    for (int i = 0; i < N ; ++i) {
        cin >> h[i];
    }

    // 正整数1次元DP
    vector<int>dp(N, -1);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < N; ++i) {
        dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]));
    }
    cout << dp[N-1];
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
ab = [tuple(map(int, input().split())) for _ in range(n)]
a, b = map(list, zip(*ab))
a.sort()
b.sort(reverse=True)
a1, b1 = a[n//2], b[n//2]
a2, b2 = a[n//2-1], b[n//2-1]
if n % 2: print(b1 - a1 + 1)
else: print((b1+b2) - (a1+a2) + 1)


Measured memory_bytes: 51556
fun main(args: Array<String>) {
    val n = readLine()!!.split(" ").map { it.toInt() }[0]
    val aArray = Array(n){ 0 }
    for (i in 0 until n) {
        val a = readLine()!!.split(" ").map { it.toInt() }[0]
        aArray[i] = a
    }
    val max = aArray.max()
    val index = aArray.indexOf(max)
    val removeMaxArray = aArray.toMutableList()
    removeMaxArray.removeAt(index)
    val secondMax = removeMaxArray.max()
    for (i in 0 until n){
        if (aArray[i] != max){
            println(max)
        } else {
            println(secondMax)
        }
    }
}

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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), L(N, 0), R(N, 0);
    rep(i, N) {
        cin >> A[i];
        if (i + A[i] < N) L[i + A[i]]++;
        if (i - A[i] >= 0) R[i - A[i]]++;
    }
    ll ans = 0;
    rep(i, N) {
        ans += L[i] * R[i];
    }
    cout << ans << "\n";
}

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

int main(int argc, char const *argv[])
{
	int a, b; cin >> a >> b;
	int ans = 0;
	b--;
	while (b > 0) {
		b -= a - 1;
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include <cmath>
//#include <bits/stdc++.h>
using namespace std;

int main(){
    string S;
    cin>>S;
    size_t N=S.length()+1;
    long int tani[N],j=0,ans=0;
    while(S[j]=='>'){
        j+=1;
    }
    ans+=j*(j+1)/2;
    long int up=0,down=0;
    for (long int i=j;i<N-1;i++){
        if (S[i-1]=='>'&&S[i]=='<'){
            ans+=up*(up+1)/2+down*(down+1)/2-min(up,down);
            up=0;
            down=0;
        }
        if (S[j]=='<') up+=1;
        else down+=1;
            tani[j]=i;
            j+=1;
        }
    if (down==0) ans+=up*(up+1)/2;
    else ans+=up*(up+1)/2+down*(down+1)/2-min(up,down);
    cout<<ans<<endl;
    return 0;
}

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

int main(){
	char A[11], B[11], C[11];
	scanf("%s  %s  %s", A, B, C);
	
	if (A[strlen(A) - 1] == B [0] && B[strlen(B) - 1]  == C [0]){
		printf ("YES\n");
	}
	else {
		printf ("NO\n");
	}
	
	return 0; 
}

Measured memory_bytes: 1620
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}

int dsum(int N){
  if(N == 0)
    return 0;
  else
    return N%10 + dsum(N/10);
}

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

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


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

int main() {
    int N, H, W, A, B, count = 0;
    cin >> N >> H >> W;
    for (int i = 0; i < N; i++) {
        cin >> A >> B;
        if (A >= H && B >= W) count++;
    }
    cout << count << endl;
    return 0;
}

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


int main(void) {
	int N;
	cin >> N;
	long long int x = 1;
	for (long long int i = 0; i < N; i++)
	{
	x *= (i + 1);
	x %= 1000000007;
	
	}
	cout << x << endl;
	getchar();
	getchar();
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextDouble()){
			double a=sc.nextDouble();
			double t=a/9.8;
			double y=4.9*t*t;
			double n=(y+5)/5;
			System.out.println((int)Math.ceil(n));

		}

	}
}

Measured memory_bytes: 27628
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define inver(a) power(a, mod - 2)
using namespace std; 
inline char nc() {
	return getchar();
	static char buf[100000], *l = buf, *r = buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
	x = 0; int f = 1, ch = nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x *= f; 
}
typedef long long ll;
const int mod = 998244353;
const int maxn = 1 << 18;
int r2;
int n, p[maxn];
int a[maxn];
inline int add(int x) {
	return x >= mod ? x - mod : x;
}
inline int dec(int x) {
	return x < 0 ? x + mod : x;
}
ll power(ll x, ll y) {
	ll re = 1;
	while(y) {
		if(y & 1) re = re * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return re;
}
void FWT(int *a, int n) {
	for(int i = 1; i < n; i <<= 1) {
		for(int j = 0, p = i << 1; j < n; j += p) {
			int *u = a + j;
			int *v = a + j + i;
			for(int k = 0; k < i; ++k, ++u, ++v) {
				int x = *u;
				int y = *v;
				*u = add(x + y);
				*v = dec(x - y);
			}
		}
	}
}
void IFWT(int *a, int n) {
	for(int i = 1; i < n; i <<= 1) {
		for(int j = 0, p = i << 1; j < n; j += p) {
			int *u = a + j;
			int *v = a + j + i;
			for(int k = 0; k < i; ++k, ++u, ++v) {
				int x = *u;
				int y = *v;
				*u = (ll)(x + y) * r2 % mod;
				*v = (ll)(x - y) * r2 % mod; *v = dec(*v);
			}
		}
	}
}
void init() {
	r2 = inver(2);
	int sum = 0;
	for(int i = 0; i < n; ++i) {
		sum += p[i];
	}
	sum = inver(sum);
	for(int i = 0; i < n; ++i) {
		p[i] = (ll)p[i] * sum % mod;
	}
}
void solve() {
	init();
	p[0] = dec(p[0] - 1);
	a[0] = n - 1;
	for(int i = 1; i < n; ++i) {
		a[i] = mod - 1;
	}
	FWT(a, n), FWT(p, n);
	for(int i = 0; i < n; ++i) {
		a[i] = a[i] * inver(p[i]) % mod;
	}
	IFWT(a, n);
	ll rec = a[0];
	FWT(a, n);
	a[0] = (ll)(mod - rec) * n % mod;
	IFWT(a, n);
}
int main() {
	read(n), n = 1 << n;
	for(int i = 0; i < n; ++i) {
		read(p[i]);
	}
	solve();
	for(int i = 0; i < n; ++i) {
		printf("%d\n", a[i]);
	}
	return 0;
}


Measured memory_bytes: 4864
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define ME 200000
#define MN 1400000
#define INF 0x7f7f7f7f
int n,m,pl,ql,pc;
int lst[MN+5],pnt[MN+5];
int dis[MN+5]; bool usd[MN+5];
int hd[MN+5],to[MN+5],val[MN+5],nxt[MN+5],rn=0;
struct edge{int p,q,c;}e[ME+5];
bool cmp(edge a,edge b){return a.c<b.c;}
struct DEQUE{
	int mem[MN*2+5],hd,tl;
	DEQUE(){hd=MN,tl=MN+1;}
	int front(){return mem[hd];}
	bool empty(){return hd==tl-1;}
	void hdpush(int x){mem[++hd]=x;}
	void hdpop(){--hd;}
	void tlpush(int x){mem[--tl]=x;}
	void tlpop(){++tl;}
}q;
inline void add(int u,int v,int c){
	++rn;
	nxt[rn]=hd[u],hd[u]=rn;
	to[rn]=v,val[rn]=c;
}
int main(){
	memset(dis,0x7f,sizeof(dis));
	memset(hd,0xff,sizeof(hd));
	scanf("%d%d",&n,&m); pc=n;
	for(int i=1;i<=m;i++)
		scanf("%d%d%d",&e[i].p,&e[i].q,&e[i].c);
	std::sort(e+1,e+1+m,cmp);
	for(int i=1;i<=m;i++){
		if(lst[e[i].p]!=e[i].c){
			lst[e[i].p]=e[i].c,pnt[e[i].p]=(++pc);
			add(e[i].p,pnt[e[i].p],1),add(pnt[e[i].p],e[i].p,0);
		}
		if(lst[e[i].q]!=e[i].c){
			lst[e[i].q]=e[i].c,pnt[e[i].q]=(++pc);
			add(e[i].q,pnt[e[i].q],1),add(pnt[e[i].q],e[i].q,0);
		}
		add(pnt[e[i].p],pnt[e[i].q],0),add(pnt[e[i].q],pnt[e[i].p],0);
	}
	dis[1]=0; q.tlpush(1);
	for(int d=0;;d++){
		while(1){
			int u=q.front();
			if(usd[u]){q.hdpop();continue;}
			if(dis[u]!=d)break;
			q.hdpop(); usd[u]=true;
			for(int i=hd[u];i!=-1;i=nxt[i]){
				if(!usd[to[i]]){
					if(val[i]==0){
						if(dis[to[i]]>d){
							dis[to[i]]=d;
							q.hdpush(to[i]);
						}
					}else{
						if(dis[to[i]]>d+1){
							dis[to[i]]=d+1;
							q.tlpush(to[i]);
						}
					}
				}
			}
		}
		if(dis[n]!=INF||q.empty())break;
	}
	printf("%d",dis[n]==INF?-1:dis[n]);
}

Measured memory_bytes: 39040
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 

int main(void){  
  int n;
  vector<string> col;
  col.push_back("Red");
  col.push_back("Yellow");
  col.push_back("Blue");
  col.push_back("Magenta");
  col.push_back("Green");
  col.push_back("Cyan");
  while(cin>>n,n){
    int c[30][6] = {0};
    int check[30] = {0};
    int t[30][6];
    REP(i,n)
      REP(j,6){
        string tmp;
        cin >> tmp;
        REP(k,6){
          if(col[k] == tmp){
            c[i][j] = k;
            break;
          }
        }
      }
    int count = 0;
    REP(i,n)
      REP(j,6)
        t[i][c[i][j]] = c[i][5-j];
    REP(i,n){
      if(check[i] == 0){
        int check1=0;
        REP(l,3){
          if(c[i][l]<t[i][c[i][l]]) check1++;
        }
        FOR(j,i+1,n){
          int check2 = 0;
          int check3 = 0;
          bool f = true;
          REP(k,6){
            if(t[i][k] != t[j][k]) f=false;
          }
          REP(l,3){
            if(c[j][l]<t[j][c[j][l]]) check2++;
          }
          REP(l,3){
            if(c[i][l] != c[j][l] && c[i][l] != t[j][c[j][l]]) check3++;
          }
          if(check3>0) check3--;
          if((check1+check2+check3)%2!=0) f=false;
          if(f){
            check[j] = 1;
            count++;
          }
        }
      }
    }
    cout<<count<<endl;
  }
}

Measured memory_bytes: 0
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
using namespace std;

typedef long long ll;

const int Maxn = 52;

int n;
ll a[Maxn];
ll k;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		ll tims = (a[i] + k) / n;
		k += tims; a[i] -= tims * ll(n + 1); 
	}
	bool ch = true;
	while (ch) {
		ch = false;
		for (int i = 0; i < n; i++)
			while (a[i] + k >= n) {
				ch = true;
				ll tims = (a[i] + k) / n;
				k += tims; a[i] -= tims * ll(n + 1);
			}
	}
	cout << k << 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++)
typedef long long ll;
int r[200001]={0};
ll f;
set<int> ans;
vector<int> A[200001];
vector<int> X[100001],Y[100001];
int search(int x){
  if(r[x]) return 0;
  f++;
  r[x]=1;
  rep(i,X[x].size()) ans.insert(X[x][i]);
  for(auto i:A[x]) search(i);
}
int main(){
    int n,x,y;
    ll ANS=0;
    cin>>n;
    rep(i,n) cin>>x>>y,X[x].push_back(y),Y[y].push_back(x);
    rep(i,100001){
        if(Y[i].size()){
            rep(j,Y[i].size()) A[Y[i][0]].push_back(Y[i][j]),A[Y[i][j]].push_back(Y[i][0]);
        }
    }
    rep(i,100001) if(A[i].size()&&!r[i]){
        ANS+=f*ans.size();
        ans.clear();
        f=0;
        search(i);
    }
    ANS+=f*ans.size();
    cout<<ANS-n;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];
	vector<ll> S(N+1), X(N+1);
	S[0] = 0;
	X[0] = 0;
	REP(i, N){
		S[i+1] = S[i] + A[i];
		X[i+1] = X[i] ^ A[i];
	}

	ll res = 0;
	REP(i, N){
		int l = i;
		int u = N+1;
		while(u-l > 1){
			int m = (l+u)/2;
			if(S[m]-S[i]!=(int)(X[m]^X[i])){
				u = m;
			}else{
				l = m;
			}
		}
		res += (u - i - 1);
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 4992
from itertools import product, permutations,combinations
def main():
    N = int(input())
    P = input()
    Q = input()
    Nlis = list(range(1,N+1))
    for i in range(len(Nlis)):
        Nlis[i] = str(Nlis[i])

    lis = []
    for i in permutations(Nlis):
        lis.append(' '.join(i))
    sorted(lis)

    print(abs(lis.index(Q)-lis.index(P)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6296
#include <bits/stdc++.h>
typedef long long ll; 
 
using namespace std;
 
int main() {
	int N, Y;
	cin >> N >> Y;

	for (int x = 0; x <= N; ++x) {
		for (int y = 0; y <= N; ++y) {
			int z = N - (x + y);
			if (z < 0) { continue; }

			int sum = 10000*x + 5000*y + 1000*z;
			if (sum == Y) {
				cout << x << " " << y << " " << z << endl;
				return 0;
			}
		}
	}

	cout << "-1 -1 -1" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>

#define PI 3.14159265359

using namespace std;

double line(int x1,int x2,int y1,int y2){
  //return length of line
   return sqrt(
     pow((double)x1-(double)x2,2.0)+
     pow((double)y1-(double)y2,2.0));
 }
//reference:http://imagingsolution.net/math/calc_n_point_area/
//reference:http://d.hatena.ne.jp/nanikaka/20111016/1318734562
int main(int args, char *argc[]){
  int n;
  int count=0;
  //INPUT
  while(cin >> n){
    count++;
    double sum=0;

    if (n==0)
      return 0;
    int x[n],y[n];
    for(int i=0;i<n;i++){
      cin>>x[i]>>y[i];
    }

    for(int i=0;i<n;i++)
      sum+=((double)x[i]*(double)y[(i+1)%n]-(double)x[(i+1)%n]*(double)y[i])/2;

    printf("%d %.1f\n",count,-sum);
  }
  return 0;
}


    /*
    //cosA=(b^2+c^2-a^2)/2bc
    //sinA=cos(90-A)
    //a(1,2),b(0,1),c(0,2)
    double a=line(x[1],x[2],y[1],y[2]);
    double b=line(x[0],x[1],y[0],y[1]);
    double c=line(x[0],x[2],y[0],y[2]);
    double alpha=acos((b*b+c*c-a*a)/(2*b*c));
    //area=bcsin(Theta)
    sum+=(sin(alpha))*b*c/2;
    printf("a:%f,b:%f,c:%f,cos(alpha):%f,sin(alpha):%f,alpha:%f,sum:%f\n",
    a,b,c,(b*b+c*c-a*a)/2/b/c,sin(alpha),alpha,sum);

    for(int i=3;i<n;i++){
      //a(i-1,i),b(0,i-1),c(0,i)
      a=line(x[i],x[i-1],y[i],y[i-1]);
      b=line(x[0],x[i-1],y[0],y[i-1]);
      c=line(x[0],x[i],y[0],y[i]);
      alpha=acos((b*b+c*c-a*a)/(2*b*c));
      sum+=sin(alpha)*b*c/2;
      printf("a:%f,b:%f,c:%f,alpha:%f,sum:%f\n",
      a,b,c,alpha,sum);
    }
    printf("%d %.1f\n",count,sum);
  }
  return 0;
}
*/


Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
  int n,m;
  cin >> n >> m;
  vector<int> v(m,0);
  rep(i,n){
    int k;
    cin >> k;
    rep(j,k){
      int a;
      cin >> a;
      v[a-1]++;
    }
  }
  int ans = 0;
  rep(i,m){
    if(v[i] == n)ans++;
  }
  cout << ans << endl;
}

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

using namespace std;

#define FST first
#define SND second

#define EPS (1e-5)

typedef complex<double> P;
typedef pair<P,P> SEG;

double cross(P a, P b) {
  return a.real()*b.imag()-a.imag()*b.real();
}

bool isIntersectSS(SEG a, SEG b) {
  return (cross(a.SND-a.FST, b.FST-a.FST) * cross(a.SND-a.FST, b.SND-a.FST) < EPS)
    && (cross(b.SND-b.FST, a.FST-b.FST) * cross(b.SND-b.FST, a.SND-b.FST) < EPS);
}

int main() {
  
  int N; cin >> N;
  
  while(N--) {
    P Wall[3];
    for(int i=0; i<3; i++) {
      double x, y; cin >> x >> y;
      Wall[i] = P(x, y);
    }
    
    double x, y;
    cin >> x >> y; P enemy(x, y);
    cin >> x >> y; P orihime(x, y);
    SEG seg(enemy, orihime);
    
    int ok = 0;
    for(int i=0; i<3; i++) {
      ok += isIntersectSS(seg, SEG(Wall[i], Wall[(i+1)%3]));
    }
    
    if(ok == 1) {
      cout << "OK" << endl;
    }
    else {
      cout << "NG" << endl;
    }
  }
  
  return 0;
}

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

int main(int argc, char *argv[]){
  int x,y;
  for(;;){
    cin >> x;
    cin >> y;
    if(x == 0 && y ==0)break;
    x < y?cout << x << " " << y << endl:cout << y << " " << x << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
namespace io{
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline 
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
int main(){
	int a,b,c;
	in3(a,b,c);
	printf("%d",min(b/a,c));
	return 0; 
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


 
int main() {
    float n, a;
    vector<float> var;
    cin >> n;
    for (int i = 0; i < n ; i++){
        cin >> a;
        var.push_back(a);
    }
    if (n == 2)
        cout << (var.at(0) + var.at(1)) / 2 << endl;
    else {
    sort(var.begin() , var.end());
    for (int i = 0; i < n - 1; i++){
        var[i +1] = (var[i] + var[i +1]) / 2;
    }
    cout << var.at(n - 1) << endl;
    
}
}


Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new KK(); }
class KK
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	double[] GR => Strs.Select(double.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	public const int MOD = 1000000007;
	public const long INFL = 4011686018427387913L;
	public KK()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int N;
	long[,] a;
	void Solve()
	{
		N = F;
		a = new long[N, N];
		for (var i = 0; i < N; i++)
		{
			var I = G;
			for (var j = 0; j < N; j++) a[i, j] = I[j];
		}
		dp = new long[1 << N];
		done = new bool[1 << N];
		pair = new long[1 << N];
		for (var s = 1u; s < (1 << N); s++)
		{
			var t = MSB(s);
			for (var i = 0; i < N; i++) if ((s & (1 << i)) != 0) pair[s] += a[t, i];
			pair[s] += pair[s ^ (1 << t)];
		}
		WriteLine(Calc((1u << N) - 1));
	}
	long[] pair;
	long[] dp;
	bool[] done;
	long Calc(uint s)
	{
		if (s == 0) return 0;
		if (!done[s])
		{
			done[s] = true;
			var t = MSB(s);
			var s2 = s ^ (1u << t);
			dp[s] = Calc(s2);
			for (var U = (1u << N) - 1; ; --U)
			{
				if ((U &= s2) == 0) break;
				dp[s] = Max(dp[s], Calc(s2 ^ U) + pair[U | (1u << t)]);
			}
		}
		return dp[s];
	}
	public static int MSB(uint n)
	{
		n |= n >> 1;
		n |= n >> 2;
		n |= n >> 4;
		n |= n >> 8;
		n |= n >> 16;
		return BitCount(n) - 1;
	}
	public static int BitCount(uint n)
	{
		n = (n & 0x55555555) + ((n >> 1) & 0x55555555);
		n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
		n = (n & 0x0f0f0f0f) + ((n >> 4) & 0x0f0f0f0f);
		n = (n & 0x00ff00ff) + ((n >> 8) & 0x00ff00ff);
		return (int)((n & 0x0000ffff) + ((n >> 16) & 0x0000ffff));
	}
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m,x,y; cin>>n>>m>>x>>y;
	int xmx=-101,ymn=101;
	for(int i=0;i<n;++i){
		int X; cin>>X;
		xmx=max(xmx,X);
	}
	for(int i=0;i<m;++i){
		int Y; cin>>Y;
		ymn=min(ymn,Y);
	}
	bool yes=false;
	for(int i=x+1;i<=y;++i){
		if(i>xmx&&i<=ymn)yes=true;
	}
	cout<<(yes?"No War"s:"War"s)<<"\n"s;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) (i%(ll)(1e9 + 7))


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

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

Measured memory_bytes: 256
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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 (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\,
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}
int cnt[205];
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 1;i<=n;i++){
        for(int j=1;j<=i;j++){
            if(i%j == 0) cnt[i]++;
        }
    }
    int ans = 0;
    for(int i = 1;i<=n;i++){
        if(i%2 == 1 && cnt[i] == 8) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
n, m = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(m)]
l = []
l2 = []
l3 = [0 for i in range(n)]
cnt = 0
if (m == 0 and n == 1) or (n == 1 and m == 1 and sc[0] == [1, 0]):
    print(0)
    exit()
for i in sc:
    if i[0] == 1 and i[1] == 0:
        print(-1)
        exit()
    elif i[0] in l and l2[l.index(i[0])] != i[1]:
        print(-1)
        exit()
    else:
        l.append(i[0])
        l2.append(i[1])
        l3[i[0] - 1] = i[1]
        cnt += 1
if l3[0] == 0:
    l3[0] = 1
print(*l3, sep="")

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ARC067
{
    public class D
    {
        private void Run()
        {
            var input = Console.ReadLine().Trim().Split();
            var N = int.Parse(input[0]);
            var A = long.Parse(input[1]);
            var B = long.Parse(input[2]);
            var X = Console.ReadLine().Trim().Split().Select(long.Parse).ToArray();

            long result = 0;
            for (int i = 1; i < X.Length; i++)
            {
                var left = X[i - 1];
                var right = X[i];
                result += Math.Min((right - left) * A, B);
            }
            Console.WriteLine(result);
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new D().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }
    }
}


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

#define MAX 244140625

int Hash[MAX];
char s[13];

int getChar(char);
int getKey();
int find();
void insert();

int main(){
  int n;
  char com[7];

  scanf("%d" ,&n);
  while(n--){
    scanf("%s %s" ,com ,s);

    if(com[0] == 'i'){
      insert();
    }else{
      if(find()){
	puts("yes");
      }else{
	puts("no");
      }
    }
  }

  return 0;
}

int getChar(char ch){
  if(ch == 'A'){
    return 1;
  }else if(ch == 'C'){
    return 2;
  }else if(ch == 'G'){
    return 3;
  }
  return 4;
}

int getKey(){
  int sum = 0, p = 1, i;

  for(i = 0 ; i < strlen(s) ; i++){
    sum += p*(getChar(s[i]));
    p *= 5;
  }
  return sum;
}

int find(){
  int key = getKey();

  if(Hash[key]){
    return 1;
  }

  return 0;
}

void insert(){
  Hash[getKey()] = 1;
}



Measured memory_bytes: 18692
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#define ll long long
ll gcd(ll a,ll b){
    ll s=1,c;
    while(a&&b){
        if((~a&1)&&(~b&1))
            a>>=1,b>>=1,s<<=1;
        else if(~a&1)a>>=1;
        else if(~b&1)b>>=1;
        else if(a>b)a=a-b;
        else c=b-a,b=a,a=c;
    }
    if(!a)return b*s;
    if(!b)return a*s;
}
using namespace std;
int main(){
	ll a,va,b,vb,t;
	cin>>a>>va>>b>>vb>>t;
	if((va-vb)*t-abs(a-b)>=0)
		cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


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

int main() {
    int X, Y;
    cin >> X >> Y;

for (int i = 0; i <= X; i++) {
    if (2*i + 4*(X-i) == Y) {
        cout << "Yes" << endl;
        return 0;
    }
}

cout << "No" << endl;

}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



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

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

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b) { return b ? gcd(b, a%b) : a; }

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    ll a=0,b=0,c=0;
    rep(i,s.size()){
        if(s[i]=='a') a++;
        else if(s[i]=='b') b++;
        else c++;
    }
    vector<ll> d(3);
    d[0]=a;
    d[1]=b;
    d[2]=c;
    sort(ALL(d));
    if(d[2]-d[0]>1){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 512
import math


def eq(x, y):
    return abs(x - y) <= 10e-10


def get_r(_a, _b, _c):
    return math.acos((-_a ** 2 + _b ** 2 + _c ** 2) / (2 * _b * _c))


def _len(_ax, _ay, _bx, _by):
    return math.sqrt((_ax - _bx) ** 2 + (_ay - _by) ** 2)

try:
    while 1:

        xa,ya,xb,yb,xc,yc,xd,yd = map(float, input().split(','))

        ab = _len(xa,ya,xb,yb)
        bc = _len(xc,yc,xb,yb)
        cd = _len(xc,yc,xd,yd)
        ad = _len(xa,ya,xd,yd)

        bd = _len(xd,yd,xb,yb)
        ac = _len(xa,ya,xc,yc)

        A = get_r(bd, ab, ad)
        B = get_r(ac, ab, bc)
        C = get_r(bd, bc, cd)
        D = get_r(ac, ad, cd)

        if eq(A + B + C + D, 2 * math.pi):
            print("YES")
        else:
            print("NO")

except:
    pass

Measured memory_bytes: 7640
while True:
    T,P,R = map(int,input().split())
    if T == 0: break
    wrong = [[0 for i in range(P)] for j in range(T)]
    right = [0 for i in range(T)]
    pena = [0 for i in range(T)]
    for i in range(R):
        tid,pid,time,mes = input().split()
        tid,pid,time = int(tid)-1, int(pid)-1, int(time)
        if mes[0] == 'C':
            right[tid] += 1
            pena[tid] += wrong[tid][pid] * 1200 + time
        else:
            wrong[tid][pid] += 1
    result = []
    for i in range(T):
        result.append((-right[i], pena[i], i))
    for r,p,i in sorted(result):
        print('{0} {1} {2}'.format(i+1, -r, p))

Measured memory_bytes: 5624