akhauriyash/Code-Regression huggingface dataset:
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    r = I()
    ans = 2*r*(22/7)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for(auto& i:mp)

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n+1);
  ll sum = 0;
  rep(i,n) {
    cin >> a[i];
    sum += a[i];
  }
  int counter = 0;
  rep(i, n){
    if (a[i] >= sum/(4.0*m)) counter++;
  }
  // cout << sum/(4.0*m) << endl;
  // cout << counter << endl;
  if (counter >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main(){
    ll n,m,ans=0;
    cin >> n >> m;
    vector<ll> vec(n);
    rep(i,n) cin >> vec[i];
    priority_queue<pair<ll,ll>> q;
    rep(i,n){
        q.push(make_pair(vec[i],1));
    }
    rep(i,m){
        ll b,c;
        cin >> b >> c;
        q.push(make_pair(c,b));
    }
    rep(i,n){
        pair<ll,ll> p=q.top();
        q.pop();
        ans+=p.first;
        if(p.second>1){
            p.second--;
            q.push(p);
        }
    }
    
    cout << ans << endl;

    return 0;
}









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

int main(){
    int n, k;
    cin >> n >> k;
    long long int ans = 0;
    ans = n/k;
    ans = ans * ans * ans;
    if(k%2==0){
        long long int ans1 = (n+k/2)/k;
        ans1 = ans1 * ans1 * ans1;
        ans += ans1;
    }
    
    cout << ans << endl;
    return 0;
}

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

const int MAX_N = 2005, MOD = 1000000007;
typedef long long i64;

int N, K;
i64 fac[MAX_N], ifac[MAX_N], inv[MAX_N], bin[MAX_N];
i64 f[MAX_N][MAX_N], sum[MAX_N];

i64 binom(int n, int m) {
  if (n < m) return 0;
  return fac[n] * ifac[m] % MOD * ifac[n - m] % MOD;
}

int main() {
  scanf("%d%d", &N, &K);
  fac[0] = ifac[0] = inv[1] = bin[0] = 1;
  for (int i = 1; i <= N; ++i) fac[i] = fac[i - 1] * i % MOD;
  for (int i = 2; i <= N; ++i) inv[i] = -(MOD / i) * inv[MOD % i] % MOD;
  for (int i = 1; i <= N; ++i) ifac[i] = ifac[i - 1] * inv[i] % MOD;
  for (int i = 1; i <= N; ++i) bin[i] = (bin[i - 1] + bin[i - 1]) % MOD;
  
  f[0][0] = 1;

  for (int i = 0; i <= N; ++i) {
    for (int j = 0; i + j <= N; ++j) {
      if (j > 0) f[i][j] = f[i][j - 1];
      if (i > 0) f[i][j] = (f[i][j] + sum[i + j]) % MOD;
    }
    for (int j = 0; i + j < N; ++j) {
      //s - i - 1 = j
      sum[i + j + 1] = (sum[i + j + 1] + f[i][j]) % MOD;
    }
  }

  i64 res = 0;
  for (int i = 2; i <= N; ++i) {
    if (K - 1 - N + i < 0) continue;
    res = (res + binom(i - 2, N - K - 1) * bin[N - K - 1] % MOD * f[N - i][K - 1 - N + i] % MOD) % MOD;
  }
  if (K == N) res = f[N - 1][0];
  printf("%lld\n", (res + MOD) % MOD);
  
  return 0;
}


Measured memory_bytes: 31104
N = gets.chomp.to_i
A = gets.chomp.split(' ').map(&:to_i)[0..N].sort
positives, negatives = A.partition{ |v| v > 0 }

min = A.min
max = A.max

puts (if min > 0
  A.reduce(&:+) - min*2
elsif max < 0
  max*2 - A.reduce(&:+)
else
  positives.reduce(0, &:+) - negatives.reduce(0, &:+)
end)

(N-1).times do |i|
  a, b = begin
    if positives.size == 2 && negatives.size == 0
      [ positives.pop, positives.shift ]
    elsif positives.size == 0 && negatives.size == 2
      [ negatives.shift, negatives.pop ]
    elsif positives.size > 1
      [ (negatives.empty? ? positives : negatives).shift, positives.shift ]
    else
      [ (positives.empty? ? negatives : positives).pop, negatives.shift ]
    end
  end
  if a > b 
    positives.push(a - b)
  else
    negatives.unshift(a - b)
  end
  puts [a, b].join(" ")
end


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

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int ans = 0;
    for (; n != 1; ++ans) {
      if (n&1)
	n = n * 3 + 1;
      else
	n /= 2;
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

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

  int ans = 0;
  int m = N+1;
  for (int i = 0; i < N; i++) {
    int P;
    cin >> P;
    if (P <= m){
      ans++;
    }
    m = min(m, P);
  }

  cout << ans << endl;

  return 0;
}


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

const int max_n = 2e5+100;

int n;
bitset<max_n> b;

int compute(int a){
    if(a==0) return 0;

    int r = __builtin_popcount(a);  
    return compute(a%r)+1;
}

int power(int a,int b,int m){
    if(b==0) return 1;
    int t = power(a,b/2,m);
    t = (t*t)%m;
    if(b%2==0) return t;
    else return (t*a)%m;
}

signed main() {
    cin>>n;
    string s;cin>>s;
    b = bitset<max_n>(s);
    int ones = b.count();
    int original = ones;
    vector<int> count,num;
    count.push_back(ones-1);
    count.push_back(ones);
    count.push_back(ones+1);

    for(int c:count){
        if(c<=0){
            num.push_back(0);
        }else{
            int ans=0;
            for(int i=0;i<n;i++){
                if(b[i]){
                    ans+=power(2,i,c);
                    ans%=c;
                }
            }
            num.push_back(ans);
        }
    }

    vector<int> final;
    for(int i=0;i<n;i++){
        b[i] = !b[i];
        if(b[i]) ones++;
        else ones--;

        if(ones>original){
            if(count[2]<=0){
                final.push_back(0);
            }else{
                int ans = num[2];
                ans = (ans+power(2,i,count[2])+count[2])%count[2];
                final.push_back(compute(ans)+1);
            }
        }else if(ones<original){
            if(count[0]<=0){
                final.push_back(0);
            }else{
                int ans = num[0];
                ans = (ans-power(2,i,count[0])+count[0])%count[0];
                final.push_back(compute(ans)+1);
            }
        }else assert(false);

        b[i] = !b[i];
        if(b[i]) ones++;
        else ones--;
    }
    reverse(final.begin(),final.end());
    for(int x:final){
        cout<<x<<endl;
    }


    return 0;
}

Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<int>> a(h,vector<int>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a[i][j];
    }
  }
  int cnt=0;
  vector<int> y,x,Y,X;
  for(int i=0;i<h;i++){
    for(int j=0;j<w-1;j++){
      if(a[i][j]%2==1){
        cnt++;
        y.push_back(i+1);
        x.push_back(j+1);
        Y.push_back(i+1);
        X.push_back(j+2);
        a[i][j+1]++;
      }
    }
  }
  for(int i=0;i<h-1;i++){
    if(a[i][w-1]%2==1){
      cnt++;
      y.push_back(i+1);
      x.push_back(w);
      Y.push_back(i+2);
      X.push_back(w);
      a[i+1][w-1]++;
    }
  }
  cout << cnt << endl;
  for(int i=0;i<cnt;i++){
    cout << y[i] << " " << x[i] << " " << Y[i] << " " << X[i] << endl;
  }
}

Measured memory_bytes: 5224
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;



int main()
{
    int res;
    for(int i=0;i<5;i++)
    {
        int x;
        sc(x)
        if(x==0)
        {
            res=i+1;
            break;
        }
    }
    cout<<res;
}







Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

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

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, D;
    cin >> N >> D;
    D = 2 * D + 1;
    cout << (N + D - 1) / D << endl;
    return 0;
}


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

typedef long long ll;

int main() {
  int N,A,B; cin >>  N >> A >> B;
  if ( N == 2 ) {
    cout << "Borys" << endl;
    return 0;
  }

  if ( (B-A-1) % 2 == 1 ) {
    cout << "Alice" << endl;
  } else {
    cout << "Borys" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = Array.new(n) { b = gets.split.map(&:to_i); b[0] == b[1] }
flag = false
(2...(a.size)).each do |i|
  if a[i] && a[i-1] && a[i-2]
    flag = true
    break
  end
end
puts flag  ? "Yes" : "No"

Measured memory_bytes: 14360
#[warn(unused_mut)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[warn(unused_mut)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[warn(unused_mut)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

/// ans = 2^n - comb(n, a) - comb(n, b)
/// comb(n, k) = n * (n-1) * ... * (n-a+1) / a / (a-1) / ... / 1

fn my_pow(n: u64, a: u64) -> u64 {
    let mut ret = 1;
    let mut tmp = a;
    let mut n = n;
    while n > 0 {
        if n & 1 == 1 {
            ret *= tmp;
            ret %= 1000000007;
        }

        tmp *= tmp;
        tmp %= 1000000007;
        n /= 2;
    }

    ret
}

fn mod_inv(n: u64) -> u64 {
    return my_pow(1000000005, n);
}

fn comb(n: u64, k: u64) -> u64 {
    let mut ret = 1;

    for i in n-k+1..n+1 {
        ret *= i;
        ret %= 1000000007;
    }

    for i in 1..k+1 {
        ret *= mod_inv(i);
        ret %= 1000000007;
    }

    ret
}

fn main() {
    input!{
        n: u64,
        a: u64,
        b: u64,
    }

    let mut ans = my_pow(n, 2);
    ans = (ans + 1000000007 - comb(n, a)) % 1000000007;
    ans = (ans + 1000000007 - comb(n, b)) % 1000000007;
    ans -= 1;
    println!("{}", ans);
}


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

using namespace std;

int main() {
int a,b,ans=0;
cin>>a>>b;
for(int i=a;i<=b;i++)
{
    string x=to_string(i);
    int is=1;
    for(int i=0;i<x.size()/2;i++)
    {
        if(x[i]!=x[x.size()-1-i])
        is=0;
    }
    if(is)
    ans++;
}
cout<<ans;
    return 0;
}


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

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define N 1000000007

using namespace std;

ll A(int n) {
	ll a = 1, b;
	for( int i=1; i<n; i++ ) {
		a *= i;
		a %= N;
	}
	return a;
}

int main(){
	int n;
	cin >> n;
	int a[n];
	int min = 0, max = 0;
	int r[9] = {0};
	for( int i=0; i<n; i++ ) {
		cin >> a[i];
		if( a[i]>=3200 ) {
			r[8]++;
		}else if( a[i]>=2800 ) {
			r[7]++;
		}else if( a[i]>=2400 ) {
			r[6]++;
		}else if( a[i]>=2000 ) {
			r[5]++;
		}else if( a[i]>=1600 ) {
			r[4]++;
		}else if( a[i]>=1200 ) {
			r[3]++;
		}else if( a[i]>=800 ) {
			r[2]++;
		}else if( a[i]>=400 ) {
			r[1]++;
		}else if( a[i]>=1) {
			r[0]++;
		}
	}
	for( int i=0; i<8; i++ ) {
		if( r[i] ) {
			min++;
		}
	}
	max = r[8] + min;
//	if( max>8 ) {
//		max = 8;
//	}
	if( min==0 ) {
		min = 1;
	}
	cout << min << " " << max;
	pfn;
//	int a, b;
//	cin >> a >> b;
//	int result = 0;
//	if( a>b ) {
//		swap(a, b);
//	}
//	if( b-a==0||b-a==1 ) {
//		result = (A(a) * A(b))%N;
//	}
//	if( b-a==0 ) {
//		result = (2*result)%N;
//	}
//	cout << result << endl;
	return 0;
} 

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

#define INF (1<<29)

int sx,sy,gx,gy;
int N;
int lx,ly;
bool fie[300][300];
int D[300][300][6];
int dx[]= {0,1,1,0,-1,-1,0};
int dy[2][7] = { {1,0,-1,-1,-1,0,0},
		 {1,1, 0,-1, 0,1,0} };


struct state{
  int x,y,d,c;
  bool operator<(const state &st ) const{
    return c > st.c;
  }
};

bool outcheck(int x,int y){
  if( 150 - lx <= x && x <= 150+lx &&
      150 - ly <= y && y <= 150+ly ) return false;
  return true;
}

void solve(){
  for(int i=0;i<300;i++)
    for(int j=0;j<300;j++)
      for(int k=0;k<6;k++) D[j][i][k] = INF;

  priority_queue<state> q;
  q.push( (state){sx,sy,0,0} );
  D[sx][sy][0] = 0;
  while( !q.empty() ){
    state p = q.top(); q.pop();
    if( D[p.x][p.y][p.d] < p.c ) continue;
    if( p.x == gx && p.y == gy ) {
      cout << p.c << endl;
      return;
    }
    int rf = p.x & 1;
    int rd = abs((p.x-150) * (p.y-150) * p.d)%6;
    int nd = (p.d+1)%6;
    for(int i=0;i<7;i++){
      int nc = p.c+1;
      if( i == rd ) nc = p.c;
      int nx = p.x + dx[i], ny = p.y + dy[rf][i];
      if( outcheck(nx,ny) ) continue;
      if( fie[nx][ny] ) continue;
      if( D[nx][ny][nd] > nc ){
	D[nx][ny][nd] = nc;
	q.push( (state){nx,ny,nd,nc} );
      }      
    }
  }
  cout << -1 << endl;
}



int main(){
  cin >> sx >> sy >> gx >>gy;
  sx+=150;sy+=150;gx+=150;gy+=150;
  cin >> N;
  for(int i=0;i<N;i++){
    int x,y;
    cin >> x >> y;
    x+=150;y+=150;
    fie[x][y] = true;
  }
  cin >> lx >> ly;
  solve();
}

Measured memory_bytes: 3508
N, K = map(int, input().split())
R, S, P = map(int, input().split())
p = dict()
p['r'] = R
p['s'] = S
p['p'] = P
T = input()


def solve(me, you, memo):
    point = 0
    for i, t in enumerate(T):
        if t == you and (i < K or (i - K >= 0 and memo[i - K] != me)):
            memo[i] = me
            point += p[me]
    return point


m = ['' for _ in range(N)]
pri = [(R, 'r', 's'), (S, 's', 'p'), (P, 'p', 'r')]
pri.sort(reverse=True)
ans = 0
for _, i, u in pri:
    ans += solve(i, u, m)
print(ans)


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

using namespace std;

int main() {
    int N, H, W;
    cin >> N >> H >> W;

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        if (a >= H and b >= W) ans++;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    // 0.25, 0.5, 1.0, 2.0 
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    ll a, b, c;
    a = min(q * 2, h);
    b = min(a * 2, s);
    c = min(b * 2, d);
    ll ans = 0;
    ans += (n / 2) * c;
    n %= 2;
    ans += n * b;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
ll w,h,ans,k;
P o[200005];
int main(void){
    scanf("%lld%lld",&w,&h);
    for(int i=0;i<w;i++){
        scanf("%lld",&o[i].F);
        o[i].S=1;
    }
    for(int i=0;i<h;i++)scanf("%lld",&o[i+w].F);
    k=h+w;
    sort(o,o+k);
    h++;
    w++;
    for(int i=0;i<k;i++){
        if(o[i].S){
            ans+=o[i].F*h;
            w--;
        }else{
            ans+=o[i].F*w;
            h--;
        }
    }
    printf("%lld\n",ans);
}


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

int main() {
	string w;	
	int c, i, s;
	while (cin >> w) {
		if (w == "-") break;
		cin >> c;
		for (int j = i = 0; j < c; j++) {
			cin >> s;
			i += s;
		}
		i %= w.length();
		cout << w.substr(i) << w.substr(0, i) << endl;
	}
	return 0;
}

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

typedef long long ll;

vector<ll> score(int D, vector<ll> c, vector<ll> t, vector<vector<ll>> s) {
    vector<vector<ll>> last(D + 1, vector<ll>(26, 0));
    vector<ll> ret(D);
    ll p = 0;
    rep(d, D) {
        p += s[d][t[d] - 1];
        rep(i, 26) last[d + 1][i] = last[d][i];
        last[d + 1][t[d] - 1] = d + 1;
        rep(i, 26) {
            p -= c[i] * (d + 1 - last[d + 1][i]);
        }
        ret[d] = p;
    }
    return ret;
}

int main() {
    int D;
    cin >> D;
    vector<ll> c(26), t(D);
    rep(i, 26) cin >> c[i];
    vector<vector<ll>> s(D, vector<ll>(26)), last(D + 1, vector<ll>(26, 0));
    rep(i, D) rep(j, 26) cin >> s[i][j];
    ll p = 0;
    rep(d, D) {
        ll q, r = 0, maxq = -1e18;
        rep(j, 26) {
            q = s[d][j];
            rep(i, 26) last[d + 1][i] = last[d][i];
            last[d + 1][j] = d + 1;
            rep(i, 26) {
                q -= c[i] * (d + 1 - last[d + 1][i]);
            }
            if (q > maxq) {
                maxq = q;
                r = j;
            }
        }
        t[d] = r + 1;
        p += maxq;
        rep(i, 26) last[d + 1][i] = last[d][i];
        last[d + 1][r] = d + 1;
    }
    auto ans = score(D, c, t, s);
    ll maxs = ans.back();
    //cout << maxs << "\n";
    rep(j, 25) rep(i, D - 1) {
        swap(t[i], t[i + 1]);
        ans = score(D, c, t, s);
        if (ans.back() > maxs) {
            maxs = ans.back();
        } else {
            swap(t[i], t[i + 1]);
        }
    }
    rep(i, D) cout << t[i] << "\n";
}

Measured memory_bytes: 3992
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[100005];
int len,l,r,s1[36],l1;
int main()
{
	scanf("%s",s+1);
	len=strlen(s+1);
	l=1,r=2;
	if(s[1]==s[2])
	{
		printf("1 2");
		return 0;
	}
	s1[s[1]-'a']++,s1[s[2]-'a']++;
	while(r<len)
	{
		r++;
		s1[s[r]-'a']++;
		if(s[r]!=s[l])
		{
			s1[s[l]-'a']--;
			l++;
		}
		if(s1[s[r]-'a']*2>r-l+1)
		{
			printf("%d %d",l,r);
			return 0;
		}
	}
	printf("-1 -1");
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
lists = [list(map(int, input().split())) for i in range(M)]
# print(lists)
if M > 5 or 3 < N:
    print("-1")
    exit()

number = [0]*N
# print(number)
ss = {i:int(-1) for i in range(10)}
count = 0
for i in lists:
    if ss[i[0]] == -1:
        ss[i[0]] = i[1]
    elif ss[i[0]] != i[1]:
        count += 1
        print("-1")
        break
    else:
        ss[i[0]] = i[1]
# print(ss)
if N > 1:
    if ss[1] == -1:
        ss[1] = 1
        number[0] = 1
# print(ss)
for i in lists:
    number[i[0]-1] = ss[i[0]]

# print(number)
ans = number
ans = "".join(map(str, ans))
ans = int(ans)
ans = str(ans)
if N == 1:
    ans = ans[0]

if count != 1:
    if len(ans) == N:
        print(ans)
    else:
        print("-1")



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

int main(){
	int w, line[100], n, a, b, c;
	char x;

	cin >> w >> n;
	for (int i = 0; i < w; i++){
		line[i] = i + 1;
	}

	for (int i = 0; i < n; i++){
		cin >> a >> x >> b;
		c = line[a-1];
		line[a-1] = line[b-1];
		line[b-1] = c;
	}

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

	return 0;
}


Measured memory_bytes: 3016
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   A : Integer;
   B : Integer;
   M : Integer;
begin
   Get (A);
   Get (B);
   M := A+B;
   if A-B > M then
      M := A-B;
   end if;
   if A*B > M then
      M := A*B;
   end if;
   Put_Line (Integer'Image (M));
end Solve;

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
using namespace std;
long long gcd(long long x, long long y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
int Q; long long A, B, C, D;
int main() {
	cin >> Q;
	while (Q--) {
		cin >> A >> B >> C >> D;
		long long G = gcd(B, D);
		long long mn = A - (A - C - 1) / G * G - B;
		cout << (A < B || B > D || mn < 0 ? "No" : "Yes") << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
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; }

struct edge { int to; int cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main(){
	ll n,k;
	cin >> n >> k;
	ll ans = min(abs(n%k),abs(n%k-k));
	cout << ans << endl;
	return 0;
}

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

int main(void){
    int X, Y;
    cin >> X >> Y;
    int sum = 0;

    switch(X){
        case 1:
            sum += 300000;
            break;
        case 2:
            sum += 200000;
            break;
        case 3:
            sum += 100000;
            break;
    }
    switch(Y){
        case 1:
            sum += 300000;
            break;
        case 2:
            sum += 200000;
            break;
        case 3:
            sum += 100000;
            break;
    }

    if(X == 1 && Y == 1){
        sum += 400000;
    }

    cout << sum << endl;
    
}

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    ll ans = 0;
    for(int i = 0; i < (int)s.size(); ++i){
        int x = s[i] - '0';
        ans += x;
    }
    if(ans % 9 == 0){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define SYOU(x) fixed<<setprecision(x) //小数点桁数を指定する
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
int main(){
    INT(a);

    cout << a*a*a + a*a + a <<endl;
    return 0;
}

Measured memory_bytes: 3772
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 100005;
const int MM = 1000000007;

int N;
int A[MX], F[MX], cnt[MX];
ll I[MX];

int main()
{
	int N;
	scanf("%d", &N);
	I[1] = 1;
	for(int i = 2; i < MX; i++) I[i] = (MM - MM/i) * I[MM%i] % MM;
	for(int i = 1; i <= N+1; i++){
		scanf("%d", A+i);
		cnt[A[i]]++;
	}
	int su = -1;
	for(int i = 1; i <= N; i++) if(cnt[i] == 2) su = i;

	int a = -1, b = -1;
	for(int i = 1; i <= N+1; i++){
		if(A[i] == su){
			if(a == -1 ) a = i;
			else b = N-i+2;
		}
	}
	int d = b+a-2;
	ll m = N+1, m2 = 1;
	printf("%d\n", N);
	for(int i = 2; i <= N+1; i++){
		m = m * (N+2-i) % MM * I[i] % MM;
		m2 = m2 * (d+2-i) % MM * I[i-1] % MM;
		printf("%lld\n", (m - m2 + MM) % MM);
	}
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
 
#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

const int N = 2e5 + 5;

vector <int> v[N];

int32_t main()
{	
	IOS
	int n;
	cin >> n;
	for(int i = 2; i<= n; i++)
	{
		int a;
		cin >> a;
		v[a].push_back(i);
	}
	for(int i = 1; i<= n; i++) cout << v[i].size() << endl;
    return 0;
}

Measured memory_bytes: 14496
/*
 * 	Roses are red
 * 		Violets are blue
 * 			I cried
 * 				And so did you
 */
// #pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifndef rd
#define endl '\n'
#endif
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=1e9;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag,
		tree_order_statistics_node_update> oset;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
auto clk=clock();
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

void solve() {
	int n;
	cin>>n;
	int ea=0,sb=0,both=0;
	int ans=0;
	for(int i=0; i<n; i++) {
		string s;
		cin>>s;
		for(int j=0; j+1<sz(s); j++) {
			if(s[j]=='A'&&s[j+1]=='B')
				ans++;
		}
		if(s[0]=='B'&&s[sz(s)-1]=='A')
			both++;
		else if(s[0]=='B')
			sb++;
		else if(s[sz(s)-1]=='A')
			ea++;
	}
	trace(ans,ea,sb,both,min(ea,sb));
	if(both>0) {
		ans+=both-1;
		if(ea||sb)
			ans+=min(ea,sb)+1;
	} else {
		ans+=min(ea,sb);
	}
	cout<<ans<<endl;
}
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 256
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int N;
  int tmp;
  cin >> N;
  map<int, int> m;
  rep(i, N) {
    cin >> tmp;
    if(m[tmp]!=0) {
      cout << "NO" << endl;
      return 0;
    }
    m[tmp]++;
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 9600
#include <iostream>
#include <utility>
#include <set>
#include <algorithm>
#include <vector>
#define llint long long
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n, d, h;
llint fsum;

const int FACT_MAX = 1000005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint dp[1000005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> h >> d;
	make_fact();
	
	for(int i = 1; i <= n; i++){
		fsum += fact[i], fsum %= mod;
	}
	
	llint sum = 0;
	dp[0] = fact[n], sum += dp[0];
	for(int i = 1; i <= h; i++){
		dp[i] = sum;
		dp[i] *= fsum, dp[i] %= mod;
		sum += dp[i], sum %= mod;
		if(i-d >= 0) sum += mod - dp[i-d], sum %= mod;
	}
	cout << dp[h] * modpow(fsum, mod-2) % mod << endl;
	
	//for(int i = 0; i <= h; i++) cout << dp[i] << " "; cout << endl;
	
	return 0;
}

Measured memory_bytes: 23680
#include <limits.h>
#include <stdio.h>
int main(void)
{
	int n, i;
	int gt = 0, lt = INT_MAX;
	scanf("%d", &n);
	for(i=0; i<n; i++) {
		int temp;
		scanf("%d", &temp);
		if(temp > gt) gt = temp;
		if(temp < lt) lt = temp;
	}
	printf("%d", gt - lt);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main()
{
  char ch;

  while(1){
    scanf("%c",&ch);
    
    if('a' <= ch && ch <= 'z'){
      printf("%c",ch-32);
    }else if(65 <= ch && ch <= 122) {
      printf("%c",ch+32);
    }else printf("%c",ch);
    
    if(ch == '\n') break;
  }

  return 0;
}


Measured memory_bytes: 2032
using System;

namespace ITP1_5_A
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i=1; ;i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int h = int.Parse(input[0]);
                int w = int.Parse(input[1]);

                if (h == 0 && w == 0)
                    break;

                for (int j=1; j<=h; j++)
                {
                    for (int k=1; k<=w; k++)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 8836
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <functional>
using namespace std;

int main(void) {
	int N;
	int A[3000];
	long long int res = 0;
	cin >> N;
	for (int i = 0; i < N;i++) {
		cin >> A[i];
		res += A[i];
	}
	res -= N;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#define ll long long

using namespace std;
typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
    int a[200010];
    cin >> a[0];
    int l = a[0];
    for (int i = 1; i < n; i++)
    {
        cin >> a[i];
        l = l ^ a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cout << (l ^ a[i]) << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 4364
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
using namespace std;



int main(){
	int n,r;
	cin>>n>>r;
	int ir=0;
	if(n>=10) ir=r;
	else{
		ir=r+100*(10-n);
	} 
	cout<<ir;
}

Measured memory_bytes: 256
import java.io.*;

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

        try {
            String[] line = reader.readLine().split(" ");

            int W = Integer.parseInt(line[0]);
            int H = Integer.parseInt(line[1]);
            int x = Integer.parseInt(line[2]);
            int y = Integer.parseInt(line[3]);
            int r = Integer.parseInt(line[4]);

            if((x-r >= 0) && (x+r <= W) && (y-r >= 0) && (y+r <= H)) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24400
#include<stdio.h>

int main(){

  int i, w0,r0,c,r;

  while(1){
    scanf("%d%d%d%d",&r0,&w0,&c,&r);
    if(r0==0 && w0==0 && c==0 && r==0)break;

    for(i=0;;i++){
        //printf("%d\n",i);
        if((r0 + r*i) >= (c * w0) ){
            printf("%d\n",i);
            break;
        }
    }
  }


  return 0;

}

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

int main() {
    ll a,b;cin>>a>>b;
    ll c=__gcd(a,b);
    int ans=0;
    for (ll i=2;i*i<=c&&c!=1;i++)
        if (c%i==0) {
            ans++;
            while (c%i==0)
                c/=i;
        }
    if (c!=1)
        ans++;
    cout<<ans+1<<endl;
    return 0;
}

Measured memory_bytes: 256
list1 = [1,3,5,7,8,10,12]
list2 = [2]
list3 = [4,6,9,11] 
x,y = map(int,input().split())
if (x in list1 and y in list1) or (x in list2 and y in list2) or (x in list3 and y in list3):
    print("Yes")
else:
  print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 998244353;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
const int biggg = 1000000000;
const long eps = .0000000001;


int main ()
{
  prep();
  int n;
  cin >> n;
  int cnts[n] = {0};
  for (int i=0; i<n-1; i++){
      int num;
      cin >> num;
      cnts[--num]++;
  }
  for (int i=0; i<n; i++){
      cout << cnts[i] << " ";
  }
  return 0;
}


Measured memory_bytes: 4424
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n; cin >> n;
  if (n % 2 == 0) cout << n << '\n';
  else cout << n * 2 << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3620
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int ans = 0;
		if(N > K) {
			ans += K * X;
			ans += (N - K) * Y;
		} else {
			ans += N * X;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
using System;

class RemainBall
{
    static void Main(string[] args)
    {
        
        var input = Console.ReadLine().Split(' ');
        string[] color = new string[2];
        color[0] = input[0];
        color[1] = input[1];
        int[] number = new int[2];
        var n = Console.ReadLine().Split(' ');
       for(var i = 0; i< 2; i++)
        {
            number[i] = int.Parse(n[i]);
        }
        var check = Console.ReadLine();
        int check_number = 0;
        for(var i = 0;i< 2;i++)
        {
            if(check == color[i])
            {
                check_number = i;
            }
        }
        number[check_number]--;

        Console.WriteLine("{0} {1}",number[0],number[1]);
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define append push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define pb push_back
#define print(a) cout<<a<<endl
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define all(x) x.begin(), x.end()
#define loop(i,n) for(int i=0;i<n;i++)
const int MOD = 1e9 + 7;
void solve();
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	//cin>> t;
	while(t--){
		solve();
	}
   // cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

void solve()
{
	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	string s;
	cin>>s;
	for(int i=a;i<c-1;i++)
	{
		if(s[i]=='#' and s[i+1]=='#')
		{
			print("No");
			return;
		}
	}
	for(int i=b;i<d-1;i++)
	{
		if(s[i]=='#' and s[i+1]=='#')
		{
			print("No");
			return;
		}
	}
	if(c<d)
	{
		print("Yes");
		return;
	}
	for(int i=b-1;i<d;i++)
	{
		if(s[i-1]=='.' and s[i+1]=='.' and s[i]!='#')
		{
			print("Yes");
			return;
		}
	}
	print("No");
}

Measured memory_bytes: 592
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 25 19:47:38 2020

@author: Kanaru Sato
"""

_ = str(input())
nums = []
for i in range(len(_)):
    nums.append(int(_[i]))

for ops in range(1<<3):
    count = nums[0]
    formula = [str(nums[0])]
    
    for shift in range(3):
        shift = 2-shift
        if ops & (1<<shift):
            count += nums[3-shift]
            formula += ["+",str(nums[3-shift])]
        else:
            count -= nums[3-shift]
            formula += ["-",str(nums[3-shift])]

    if count == 7:
        formula.append("=")
        print("".join(formula)+"7")
        break

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

a = 0
while True:
    all_even = True
    for i in range(N):
        all_even = all_even and (A[i] % 2 == 0)
    
    if all_even == True:
        for i in range(N):
            A[i] = A[i] / 2
            
        a += 1
            
    else:
        break
    
print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>
using namespace std;

int main()
{
    int a[5];
    int ans[10] = {};
    cin >> a[0] >> a[1] >> a[2];
    for (int i = 0; i < 3; i++)
    {
        ans[a[i]]++;
    }
    if (ans[5] == 2 && ans[7] == 1)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A + B + C < 22)
    {
        cout << "win" << endl;
    }
    else
    {
        cout << "bust" << endl;
    }
}

Measured memory_bytes: 256
'''

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

'''

'''o=input().rstrip().split(' ')
x=int(o[0])
y=int(o[1])
a=int(o[2])
b=int(o[3])
c=int(o[4])
H=0;
R=input().rstrip().split(' ')
G=input().rstrip().split(' ')
ANY=input().rstrip().split(' ')
R.sort(key=int,reverse=True)
G.sort(key=int,reverse=True)
ANY.sort(key=int,reverse=True)
while(x>0):
    if int(R[0]) > int(ANY[0]):
        H+=int(R[0])
        del(R[0])
        x-=1;
    else:
        break;
while(y>0):
    if int(G[0]) > int(ANY[0]):
        H+=int(G[0])
        del(G[0])
        y-=1;
    else:
        break;
if(x>0 && y==0):
    for i in range(0,x):
        if i<len(ANY):
            H+=ANY[i];
        else:
            H+=int(R[0])
            del(R[0])
elif(y>0 && x==0):
    for i in range(0,y):
        if i<len(ANY):
            H+=ANY[i];
        else:
            H+=int(G[0])
            del(G[0])
else:
    FF=x+y;
    if FF<=len(ANY):
        for i in range(0,len(ANY)):
            H+=int(ANY[i])
    else:
        for i in range(0,len(ANY)):
            H+=int(ANY[i])
        XX=0;
        YY=0;
        for i in range(0,x):
            '''
            
            
'''

20 3
0 5 15

'''


o=input().rstrip().split(' ')
p=input().rstrip().split(' ')
l=[]
for i in range(1,len(p)):
    l.append(int(p[i]) - int(p[i-1]))
l.append(int(o[0])-int(p[len(p)-1])+int(p[0]))
q=[]
C=list(p)
A=list(C[0])
B=C[1:len(C)];
B.reverse();
C=A+B;
for i in range(1,len(C)):
    q.append(int(o[0]) - int(C[i]))
q.append(int(o[0]) - int(C[0]) + int(q[0]))
S=0
D=0
for i in range(0,len(l)):
    S+=int(l[i]);
    D+=int(q[i])
W=[]
minu = 10000000000000;
for i in range(0,len(l)):
    if i==0:
        F=S-int(l[len(l)-1])
        minu = min(minu,F)
    else:
        F=S-int(l[i-1])
        minu = min(minu,F);
for i in range(0,len(q)):
    if i==0:
        F=D-int(q[len(q)-1])
        minu = min(minu,F)
    else:
        F=D-int(q[i-1])
        minu = min(minu,F);
print(minu)

Measured memory_bytes: 29616
inp = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n')
S = inp.shift()
T = inp.shift()
for (i=S.length-1; i>=0; i--) {
    f = 1
    for (j=0; j<T.length; j++) {
        if (!(S[i+j] == T[j] || S[i+j] == '?')) {
            f = 0
        }
    }
    if (f==1) {
        break;
    }
}
if (f==1) {
    ans = ''
    for (k=0; k<S.length; k++) {
        if (k == i) {
            ans += T
            k += T.length - 1
        } else {
            ans += S[k] == '?' ? 'a' : S[k]
        }
    }
} else {
    ans = 'UNRESTORABLE'
}
console.log(ans)

Measured memory_bytes: 7372
a, b, c = map(int, input().split())

if a > b:
    temp = a
    a = b
    b = temp

if b > c:
    temp = b
    b = c
    c = temp

if a > b:
    temp = a
    a = b
    b = temp

print("{0} {1} {2}".format(a, b, c))


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,s,t,time,limit,k;
  time=0;
  limit=0;
  k=0;
  cin>>n;
  vector<pair<int,int>>pairs(n);
  for(int i=0; i<n; i++){
    cin>>s>>t;
    pairs[i]=make_pair(t,s);
  }
  sort(pairs.begin(),pairs.end());
  for(int i=0; i<n; i++){
    limit=pairs[i].first;
    time=time+pairs[i].second;
    if(time>limit){
      k=1;
      break;
    }
  }
  if(k==1){
    cout<<"No";
  }
  else{
    cout<<"Yes";
  }
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	int t[3], a[3], b[3], i;

	b[0] = b[1] = b[2] = 0;
	for(i=0; i<n; i++) {
		cin >> t[0] >> t[1] >> t[2];
		a[0] = max(b[1], b[2]) + t[0];
		a[1] = max(b[0], b[2]) + t[1];
		a[2] = max(b[0], b[1]) + t[2];
		b[0] = a[0]; b[1] = a[1]; b[2] = a[2];
	}

	cout << max(b[0], max(b[1], b[2])) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using ll = int64_t;
using ld = long double;
using ull = uint64_t;
using namespace std;
using namespace __gnu_pbds;

const int MAXN = 200228;
int d[MAXN];


int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n;
    cin >> n;
    d[0] = 0;
    int ans = 1000000;

    for (int i = 1; i < n; ++i) {
        d[i] = i % 10 + d[i / 10];
        int r = n - i;
        if (i >= r) {
            ans = min(ans, d[i] + d[r]);
        }
       
    }

    cout << ans << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
map<ll,ll> primefactor(ll n){
  map<ll,ll> div;
  ll nn=n;
  for (ll i = 2; i*i <= nn; i++)
  {
    if (n % i == 0)
    {
      div[i]++;
      n/=i;
      i--;
    }
  }
  if(n!=1)div[n]++;
  return div;
}
int main()
{
ll a , b ;
cin >> a >> b ;
map<ll,ll> p=primefactor(a);
map<ll,ll> pb=primefactor(b);
for (auto i = p.begin(); i != p.end(); ++i) {
  if(pb[i->first]!=0)ans++;
}
cout << ans+1 << endl;
return 0;
}


Measured memory_bytes: 384
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        n: i64,
    }

    let ans: i64 = (1..=n).filter(|&i| i % 3 != 0 && i % 5 != 0).sum();
    println!("{}", ans);
}


Measured memory_bytes: 2140