akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    vector<pair<double, double>> v;
    double x[n],y[n];
    rep(i,n){
        cin >> x[i] >> y[i];
        v.emplace_back(x[i], y[i]);
    }
    auto f = [](pair<double, double> p1, pair<double, double> p2){ return atan2(p1.second, p1.first) < atan2(p2.second, p2.first); };
    sort(ALL(v), f);
    double ans = 0;
    rep(i,n){
        double X = 0, Y = 0;
        rep(j,n){
            X += v[(i + j) % n].first;
            Y += v[(i + j) % n].second;
            ans = max(ans, sqrt(X * X + Y * Y));
        }
    }
    printf("%.12lf\n", ans);
    return 0;
}

Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))

dif=1000000000000
ans=1
for i in range(n):
    ttt=t-0.006*h[i]
    if abs(ttt-a)<dif:
        dif=abs(ttt-a)
        ans=i+1
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int dan[45]={0},nen[45]={0};
    int n;
    dan[1]=1;
    nen[1]=1;
    dan[2]=2;
    dan[3]=4;
    for(int i=4;i<=35;i++)
    {
        dan[i]=dan[i-1]+dan[i-2]+dan[i-3];
    }
    while(cin>>n)
    {
        nen[n]=dan[n]/3650;
        if(dan[n] % 3650 != 0)
        {
            nen[n]++;
        }
        if(n==0)break;
        cout<<nen[n]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
const long long mod = 1e9 + 7 ;
const int N = 3e5+122; 

int n, m, k, t;
int a[N];
long long ans = 0;
vector<int> v[N];

int main ( ) {
	char c;
	cin >> n >> m;
	cin >> k >> t;
	if(n != k) cout<<1;
	else cout << 0;
	return 0;

}

Measured memory_bytes: 8448
#include <stdio.h>
int main(void)
{
    int n;
    scanf("%d",&n);
    int a[n];
    int b[n];
    int row;
    for(int p=0;p<n;p++)
        scanf("%d %d",&a[p],&b[p]);
    int c=0;
    for(int q=0;q<n;q++)
    {
        if(c<a[q])
        {
            c=a[q];
            row=q;
        }
    }
    int ans;
    ans=a[row]+b[row];
    printf("%d",ans);
}


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

using ll = unsigned long long;

ll S(ll n){
  ll res = 0;
  while(n>0){
    res += n%10;
    n = n/10;
  }
  return res;
}

bool cmp(ll x,ll y){
  return x*S(y)<=y*S(x);
}

bool check(ll n){
  for(ll m=n+1;m<10000000;m++){
    if(!cmp(n,m)){
      return false;
    }
  }
  return true;
}

int main(){
  ll k;
  cin>>k;

  ll n = 0;
  ll d = 1;
  for(ll i=0;i<k;i++){
    ll x = n+d;
    ll y = n+10*d;
    if(cmp(x,y)){
      cout<<x<<endl;
      n = x;
    }else{
      cout<<y<<endl;
      d *= 10;
      n = y;
    }
  }
}


Measured memory_bytes: 256
(let ((n (read))
      (k (read)))
  (princ (cond ((oddp k) (expt (floor (/ n k)) 3))
               (t (let ((h (/ k 2))
                        (ans 0))
                    (incf ans (expt (floor (/ n k)) 3))
                    (incf ans (expt (floor (/ (+ n h) k)) 3))
                    ans)))))


Measured memory_bytes: 16608
#include<bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s)
{
    return '"' + s + '"';
}

string to_string(const char *s)
{
    return to_string((string)s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n; cin >> n; string s; cin >> s;
    vector<int> a, b, c;
    for(int i=0; i<n; i++) {
        if(s[i] == 'R') a.push_back(i);
        if(s[i] == 'G') b.push_back(i);
        if(s[i] == 'B') c.push_back(i);
    }
    ll res = 0;
    for(int ii=0; ii<a.size(); ii++) {
        for(int jj=0; jj<b.size(); jj++) {
            res += c.size();
            int i = a[ii]; int j = b[jj];
            if(binary_search(c.begin(), c.end(), max(i, j) + abs(i-j))) res--;
            if(binary_search(c.begin(), c.end(), min(i, j) - abs(i-j))) res--;
            if((i+j)%2==0 && binary_search(c.begin(), c.end(), (i+j)/2)) res--;

        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3636
package main

import (
	"fmt"
)

func main() {
	var L int
	fmt.Scanf("%d", &L)
	N := -1
	for K := 1; K <= L; K <<= 1 {
		N++
	}
	e := 0
	for i := 0; i < N; i++ {
		e += L >> uint(i) & 1
	}
	fmt.Printf("%d %d\n", N+1, 2*N+e)
	for i := 0; i < N; i++ {
		fmt.Printf("%d %d 0\n", i+1, i+2)
		fmt.Printf("%d %d %d\n", i+1, i+2, 1<<uint(N-i-1))
		if L>>uint(N-i-1)&1 == 1 {
			fmt.Printf("%d %d %d\n", 1, i+2, L&^(1<<uint(N-i)-1))
		}
	}
}


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int k=scan.nextInt();
		ArrayList<Integer>ans=new ArrayList<Integer>();
		if(a>b){
			for(int i=1;i<a+1;i++){
				if(a%i==0&&b%i==0){
					ans.add(i);
				}
			}
		}else{
			for(int i=1;i<b+1;i++){
				if(a%i==0&&b%i==0){
					ans.add(i);
				}
			}

		}
		System.out.println(ans.get(ans.size()-k));
	}
}

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

int main(){
    int N, M;
    cin >> N >> M;
    int costs[N][N];
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            costs[i][j] = 1e9;
        }
    }
    int roads[M][3];
    for(int i = 0; i < M; i++){
        cin >> roads[i][0] >> roads[i][1] >> roads[i][2];
        costs[roads[i][0] - 1][roads[i][1] - 1] = roads[i][2];
        costs[roads[i][1] - 1][roads[i][0] - 1] = roads[i][2];
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            for(int k = 0; k < N; k++){
                costs[j][k] = min(costs[j][k], costs[j][i] + costs[i][k]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < M; i++){
        if(costs[roads[i][0] - 1][roads[i][1] - 1] != roads[i][2]){
            ans++;
        }
    }
    cout << ans << endl;
}


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

int main()
{
    long long m,n;
    scanf("%lld%lld",&n,&m);

    if(m>2*n)
    {
        printf("%lld\n",n+(m-2*n)/4);
    }
    else
    {
        printf("%lld\n",m/2);
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#define MAX 100010
using namespace std;

struct CARD{
    char suit;
    int value;
    bool check;
};

bool checkStable(int n, CARD c[], CARD a[])
{
    for (int i = 0;i < n;i++)
    {
        for (int j = 0;j < n;j++)
        {
            if (a[i].value == c[j].value)
            {
                if (a[i].suit != c[j].suit)
                {
                    if (!c[j].check) return false;
                }
                else
                {
                    c[j].check = true;
                    break;
                }
            }
        }
    }
    for (int i = 0;i < n;i++)
    {
        c[i].check = false;
    }
    return true;
}

int Partition(CARD A[], int p, int r) //[p,r]
{
	CARD tmp;
	CARD x = A[r];
	int i = p-1;
	for (int j = p;j < r;j++)
	{
		if (A[j].value <= x.value)
		{
			i++;
			tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	tmp = A[i+1];
	A[i+1] = A[r];
	A[r] = tmp;
	return i+1;
}

void Quick_Sort(CARD A[], int p, int r)
{
	if (p < r)
	{
		int q = Partition(A, p, r);
		Quick_Sort(A, p, q-1);
		Quick_Sort(A, q+1, r);		
	}
}

int main ()
{
	int n;
	CARD A[MAX], Orig[MAX];
	cin >> n;
	for (int i = 0;i < n;i++)
	{
		cin >> A[i].suit >> A[i].value;
		A[i].check = false;
		Orig[i] = A[i];
	}
	
	Quick_Sort(A, 0, n-1);
	
	bool ch = checkStable(n, Orig, A);
	
	if (ch) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
	
	for (int i = 0;i < n;i++)
	{
		cout << A[i].suit << " " << A[i].value << endl;
	}
	
	return 0;
}


Measured memory_bytes: 5356
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
LL n,k,ans;
LL min(LL x,LL y) {
    if (x<y) return x;
    return y;
}
int main() {
    scanf("%lld%lld",&n,&k);
    for (int i=1;i<=n;i++) {
	for (int j=1;i*j<=n;j++) {
	    LL rx=min(n-i*j,i-1);
	    LL lx=k;	    
	    if (lx<=rx) ans+=rx-lx+1;
	}
    }
    if (!k) k=1;
    for (int i=k;i<=n;i++) ans+=(n-i);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>

#define rep(i,n) for(int (i)=0;i < (n);(i)++)
#define ll long long
#define INF 9223372036854775807

using namespace std;

// input

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

  cin >> n;
  if(n % 2 == 1) {
	cout << n / 2 + 1 << endl;
  } else {
	cout << n / 2 << endl;
  }
  
}



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

int main(){
	int N;
	cin >> N;
	int X[N];
	int MI = 100, MA = 0;
	for(int i=0;i<N;i++){
		cin >> X[i];
		MI = min(X[i], MI);
		MA = max(X[i], MA);
	}
	int ans = 100000000;
	for(int p = MI;p<=MA;p++){
		int tmp = 0;
		for(int i=0;i<N;i++){
			int D = X[i] - p;
			tmp += D * D;
		}
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}


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

int main(){
    int n, m;
    vector<int> x, y;
    cin >> n >> m;
    int val;
    cin >> val;
    x.push_back(val);
    cin >> val;
    y.push_back(val);
    for(int i = 0; i < n; i++){
        cin >> val;
        x.push_back(val);
    }
    for(int i = 0; i < m; i++){
        cin >> val;
        y.push_back(val);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    int a = x.back();
    int b = y.front();
    if(a >= b){
        cout << "War" << endl;
    }else{
        cout << "No War" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import fractions
def factorization(n):
    arr=[]
    tmp=n
    for i in range(2,int(n**0.5)+1):
        if(tmp%i==0):
            cnt=0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
    arr.append([1,1])
    if(tmp!=1):
        arr.append([tmp,1])
    return arr
A,B=map(int,input().split())
g=fractions.gcd(A,B)
li=factorization(g)
print(len(li))

Measured memory_bytes: 64620
#include <iostream>

using namespace std;

int n;

void maxHeapify(int a[],int i){
  int largest;
  // select maximum node in left,itself,right
  if(2*i<=n && a[2*i]>a[i]) largest=2*i;
  else largest=i;
  if(2*i+1<=n && a[2*i+1]>a[largest]) largest=2*i+1;
  if(largest!=i){
    int t=a[i];
    a[i]=a[largest];
    a[largest]=t;
    maxHeapify(a,largest);
  }
}

void buildMaxHeap(int a[]){
  for(int i=n/2;i>=1;i--) maxHeapify(a,i);
}

int main(){
  cin >> n;
  int a[n];
  for(int i=1;i<=n;i++) cin >> a[i];
  buildMaxHeap(a);
  for(int i=1;i<=n;i++) cout << " " << a[i];
  cout << endl;
}

Measured memory_bytes: 4944
def divisor(i):
    s = []
    for j in range(1, int(i ** (1 / 2)) + 1):
        if i % j == 0:
            s.append(i // j)
            s.append(j)
    return sorted(set(s))

n = int(input())
ans = 0
d = divisor(n)
d.pop(0)
for i in d:
    x = n
    while True:
        if not x % i == 0:
            break
        x //= i
    if x % i == 1:
        ans += 1
d = divisor(n - 1)
ans += len(d)
ans -= 1
print(ans)

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

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

    static class Bouquet {
        public static long MOD = 1000000007;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();

            long result = modPow(2, n, MOD) - 1;
            result = modSub(result, com(n, a), MOD);
            result = modSub(result, com(n, b), MOD);
            out.println(result % MOD);
        }

        static long modSub(long x, long n, long mod) {
            long v = x - n;
            if (v < 0) {
                v += mod;
            }
            return v % mod;
        }

        static long modPow(long x, long n, long mod) {
            if (n == 0) {
                return 1;
            }
            long result = modPow(x, n / 2, mod);

            if (n % 2 == 0) {
                return (result * result) % mod;
            }
            return (((result * result) % mod) * x) % mod;
        }

        static long modInv(long a, long mod) {
            return modPow(a, mod - 2, mod);
        }

        static long com(long n, long k) {

            long result = 1;
            for (int i = 0; i < k; i++) {
                result = (result * (n - i)) % MOD;
                result = (result * modInv(i + 1, MOD)) % MOD;
            }
            return result;
        }

    }
}



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

int main() {
  int N, x=0;
  cin >> N;
  for (int i=0; i<N; i++){
    string s;
    cin >> s;
    if (s=="Y"){
      x += 1;
    }
  }
  
  if (x==0){
    cout << "Three" << endl;
  }
  
  else {
    cout << "Four" << endl;
  }     
}


Measured memory_bytes: 3576
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll mod_pow(ll a, ll b) {
	if (b == 0) return 1;
	if (b % 2 == 0) {
		ll x = mod_pow(a, b / 2);
		return (x*x) % MOD;
	}
	return (a*mod_pow(a, b - 1)) % MOD;
}
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	int k = N - 1;
	for (int i = A.size() - 1; i > 0; i -= 2) {
		if (A[i] != k || A[i - 1] != k) {
			cout << 0 << endl;
			return 0;
		}
		k -= 2;
	}
	if (N % 2 && A[0] != 0) {
		cout << 0 << endl;
		return 0;
	}
	cout << mod_pow(2, N / 2) << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=2e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n,m,d[N][2];
char s[N];
vector<int>E[N];
void input()
{
	int x,y;
	n=read<int>(),m=read<int>();
	scanf("%s",s+1);
	For(i,1,m)
	{
		x=read<int>(),y=read<int>();
		E[x].push_back(y);
		E[y].push_back(x);
		d[x][s[y]=='B']++;
		d[y][s[x]=='B']++;
	}
}
int tot,vis[N];
queue<int>q;
void work()
{
	int u;
	For(i,1,n)if(!d[i][0]||!d[i][1])vis[i]=1,q.push(i);
	while(!q.empty())
	{
		u=q.front();q.pop();
		tot++;
		for(int v:E[u])if(!vis[v])
		{
			if(!--d[v][s[u]=='B'])vis[v]=1,q.push(v);
		}
	}
	puts(tot==n?"No":"Yes");
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 13184
import java.util.*;

class Main{

  public static void main(String args[]){
  	Scanner sc=new Scanner(System.in);
    
    int[] data=new int[4];
    
    for(int i=0;i<4;i++){
    	data[i]=sc.nextInt();
    }
    
    //直接会話できる？
    String result="No";
    
    if(Math.abs(data[0]-data[2])<=data[3]){
    	result="Yes";
    }else if(Math.abs(data[0]-data[1])<=data[3] && Math.abs(data[1]-data[2])<=data[3]){
    	result="Yes";
    }
    
    System.out.println(result);
    
  }

}


Measured memory_bytes: 23764
N, A, B, C = map(int, input().split())
bam = [int(input()) for i in range(N)]

mina = 1001
minb = 1001
minc = 1001

ans = 999999
for i in range(4 ** N):
    tmpA = []
    tmpB = []
    tmpC = []
    mp = 0
    for j in reversed(range(0, N * 2, 2)):

            #bit 11の場合　使わない場合
            if (i & (1 << j)) and (i & (1 << (j + 1))):
                pass
            #bit 10の場合　Cの材料
            elif (i & (1 << j)) and not (i & (1 << (j + 1))):
                tmpC.append(bam[int(j / 2)])
            #bit 01の場合　Bの材料
            elif not (i & (1 << j)) and (i & (1 << (j + 1))):
                tmpB.append(bam[int(j / 2)])
            #bit 00の場合　Aの材料
            elif not (i & (1 << j)) and not (i & (1 << (j + 1))):
                tmpA.append(bam[int(j / 2)])
            #どれかが空なら次へ
            
    if not tmpA or not tmpB or not tmpC:
        continue
    #合体処理
    else:
        mp = (len(tmpA) - 1) * 10 + (len(tmpB) - 1) * 10 + (len(tmpC) - 1) * 10
        tmpA = sum(tmpA)
        tmpB = sum(tmpB)
        tmpC = sum(tmpC)
    mp += abs(A- tmpA) + abs(B - tmpB) + abs(C - tmpC)
    ans = min(ans, mp)

print(ans)


Measured memory_bytes: 3064
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let a: u32 = read();

    println!("{}", a + a*a + a*a*a);
}


Measured memory_bytes: 2108
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
color = [[0] * W for _ in range(H)]
nowx = 0
nowy = 0
for i in range(N):
  for j in range(a[i]):
    color[nowx][nowy] = i+1
    if(nowx % 2 == 0 and nowy < W-1):
      nowy += 1
    elif(nowx % 2 == 1 and nowy > 0):
      nowy -= 1
    else:
      nowx += 1
      
for h in range(H):
  print(*color[h])

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

int main(){
  int N,K,X,Y;cin>>N>>K>>X>>Y;
  int ans=0;
  
  for(int i=0;i<min(N,K);i++)ans+=X;
  for(int i=0;i<N-K;i++)ans+=Y;
  
  cout<<ans<<endl;
}

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

using namespace std;

string str;

int skip(int idx) {
  while (str[idx] != '(' && str[idx] != '[' &&
         str[idx] != ')' && str[idx] != ']' && str[idx] != '.') {
    idx++;
  }
  return idx;
}

char corre(char c) {
  if (c == '[') {return ']';}
  if (c == '(') {return ')';}
}

int inKakko(int idx, char kakko) {
  //fprintf(stderr, "inKakko\n");
  while (true) {
    idx = skip(idx);
    //fprintf(stderr, "%d, %c\n", idx, str[idx]);
    if (str[idx] == '.') {
      return -1;
    } else if (str[idx] == corre(kakko)) {
      //fprintf(stderr, "matched %c\n", kakko);
      return idx + 1;
    } else if (str[idx] == '(' || str[idx] == '[') {
      idx = inKakko(idx + 1, str[idx]);
      if (idx < 0) {
        return -1;
      }
    } else {
      return -1;
    }
  }
}

bool _solve(int idx) {
  while (true) {
    idx = skip(idx);
    //fprintf(stderr, "%d, %c\n", idx, str[idx]);
    switch (str[idx]) {
    case '.':
      return true;
    case '(':
    case '[':
      idx = inKakko(idx + 1, str[idx]);
      // fprintf(stderr, "idx=%d\n", idx);
      if (idx < 0) {
        return false;
      }
      break;
    case ')':
    case ']':
      return false;
    }
    //fprintf(stderr, "e%d, %c\n", idx, str[idx]);
  }
}

void solve() {
  if (_solve(0)) {
    printf("yes\n");
  } else {
    printf("no\n");
  }
}

int main() {
  while (true) {
    getline(cin, str);
    //fprintf(stderr, "start\n");
    if (str == ".") {
      return 0;
    }
    solve();
  }
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;cin>>h>>w;
    rep(i,h){
        rep(j,w){
            string s;cin>>s;
            if(s=="snuke"){
                cout<<(char)('A'+j)<<i+1<<endl;
                return 0;
            }

        }
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

#define FOR(i, a, b) for(int i = a; i <= b; i++)

const int MAX = 2 * 1e5 + 10;
int s[MAX];

int main()
{
	int n;
	while(~scanf("%d", &n))
	{
		FOR(i, 0, n - 1)
			scanf("%d", &s[i]);
		int mx = s[1] - s[0], nowmn = min(s[1], s[0]);
		FOR(i, 2, n - 1)
		{
			mx = max(mx, s[i] - nowmn);
			nowmn = min(s[i], nowmn);
		}
		printf("%d\n", mx);
	}
	return 0;
}



Measured memory_bytes: 3504
def p_b():
    n, m, c = map(int, input().split())
    *b, = map(int, input().split())
    ans = 0
    for i in range(n):
        *a, = map(int, input().split())
        tmp = c
        for _a, _b in zip(a, b):
            tmp += _a * _b
        if tmp > 0:
            ans += 1
    print(ans)
    
p_b()

Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
ll mod=1e9+7;

int main()
{
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return 0;

}


Measured memory_bytes: 3620
A, B, C, D = map(int, input().split())

from fractions import gcd
total = B - A + 1
c_multiples = B // C + 1 - (A+C-1) // C
d_multiples = B // D + 1 - (A+D-1) // D
lcm = C * D // gcd(C, D)
lcm_multiples = B // lcm + 1 - (A+lcm-1) // lcm

ans = total - c_multiples - d_multiples + lcm_multiples
print(ans)

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


ll sum(int n);

void go(){
	int a,b,c;cin>>a>>b>>c;
	int ans=min(b/a, c);
	cout << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
    private static int W = 10;
    private static int T = 1000;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            String w = sc.nextLine();
            if (w.length() > W) {
                System.out.println("Condition is invalid.");
                return;
            }
            int c = 0;
            while (sc.hasNext()) {
                String s = sc.next().toLowerCase();
                if (s.equals("END_OF_TEXT")) {
                    break;
                }
                if (s.equals(w)) {
                    c++;
                }
            }
            System.out.println(c);
        } catch (NoSuchElementException e) {
            System.out.println(e);
        }
    }
}



Measured memory_bytes: 26188
#include <bits/stdc++.h>
        //#include <ext/pb_ds/assoc_container.hpp>
        //using namespace __gnu_pbds;
        using namespace std;
        typedef long long int ll;
        typedef unsigned long long int ull;
        typedef long double ld;
        //typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
        #define rep(g, i, n) for (ll g = i; g < n; g++)
        #define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
        #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        #define all(v) v.begin(), v.end()
        #define pb push_back
        #define mxe(v) *max_element(v.begin(),v.end())
        #define mne(v) *min_element(v.begin(),v.end())
        #define bs binary_search
        #define lb lower_bound
        #define ub upper_bound
        #define ve vector
        #define cc continue
        #define bb break
        #define rem 1000000007
        #define PI 3.141592653589793238462643383279502
        //fflush(stdin);
        // do {
        // // process permutation
        // } while (next_permutation(permutation.begin(),permutation.end()));
        //vector.assign (n,value)... for global vectors
        class abc
        {
            public:
            ll x,y;
        };
        int main()
        {
            FAST
            // freopen("input1.txt", "r", stdin);
            // freopen("output.txt", "w", stdout);
            /*ll tests;
            cin>>tests;
            rep (gg,0,tests)
            {}*/
            ll a,b,c;
            cin>>a>>b>>c;
            ll x1=c-a-b;
            if (x1<=0)
            {
                cout<<"No\n";
                return 0;
            }
            ll left=4*a*b;
            ll right=x1*x1;
            if (left<right)
            {
                cout<<"Yes\n";
            }
            else
            {
                cout<<"No\n";
            }
            
        }


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#define RG register
#define IL inline
#define pi acos(-1.0)

#define inf 1e8
using namespace std;

int n,m,R;
int land[300][300],water[300][300],dp[1005][300];
int a[1005];

void pre(){
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++){
          land[i][j]=land[j][i]=inf;
          water[i][j]=water[j][i]=inf;
        }
    for(int i=1;i<=n;i++)
         land[i][i]=0,water[i][i]=0;
}

void floyd(){
    for(int k=1;k<=n;k++)
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++){
                if(k==i||k==j||i==j) continue;
                water[i][j]=min(water[i][j],water[i][k]+water[k][j]);
                land[i][j]=min(land[i][j],land[i][k]+land[k][j]);
            }
}

int main(){
    while(1){
     scanf("%d%d",&n,&m);
     if(n==0&&m==0) break;
     pre();
     for(int i=1;i<=m;i++){
         int l,r; string str;
         int w;
         scanf("%d%d%d",&l,&r,&w);
         cin>>str;
         if(str=="L") land[l][r]=land[r][l]=min(land[r][l],w);
         else water[l][r]=water[r][l]=min(water[r][l],w);
    }
    floyd();
    scanf("%d",&R);
    for(int i=1;i<=R;i++)
        for(int j=1;j<=n;j++)
          dp[i][j]=inf;
    for(int i=1;i<=R;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
      dp[1][i]=water[a[1]][i]+land[i][a[1]];//第一次出发可以将船停到任意处再坐船回到当前目标点
   
   for(int i=1;i<=R;++i){
   		for(int j=1;j<=n;++j){
   			if(dp[i][j]!=inf){
   				dp[i+1][j]=min(dp[i+1][j],dp[i][j]+land[a[i]][a[i+1]]);
   				for(int k=1;k<=n;++k){
   					dp[i+1][k]=min(dp[i+1][k],
					dp[i][j]+land[a[i]][j]+water[j][k]+land[a[i+1]][k]
					   );
				   }
			   }
		   }
   }
     int minn=inf;
     for(int i=1;i<=n;i++)
        minn=min(minn,dp[R][i]);
     printf("%d\n",minn);
    }
    return 0;
}


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

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

#define pb push_back
#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_cs(i, l, n) for (int i = (l); i <= n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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;
}

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;
Graph G;
vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

ll dp[110][110000] = {0};
ll w[110];
ll v[110];

int main()
{
    ll n;
    cin >> n;
    vll a(n);
    rep(i, 0, n) cin >> a[i];

    ll all = 1;
    ll bad = 1;

    rep(i, 0, n)
    {
        all *= 3;
        if (a[i] % 2== 0) {
            bad *=2;
        }
    }

    cout << all - bad << endl;
}

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

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

  std::string s,s1,s2;
  std::cin >> s;

  s1 = "2018";
  s2 = s1 + s.substr(4);
  std::cout << s2 << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int N, M;

int main(void)
{
	cin >> N >> M;
	Graph G(N + 1);

	for (int i = 1; i <= M; i++)
	{
		int A, B;
		cin >> A >> B;
		G[A].push_back(B);
		G[B].push_back(A);
	}

	vector<int> Arrow(N + 1, -1);
	Arrow[1] = 1;
	vector<int> Dist(N + 1, -1);
	Dist[1] = 0;
	queue<int> que;
	que.push(1);
	// int target = 4;
	int foundCount = 0;

	while (!que.empty())
	{
		int now = que.front();
		que.pop();

		if (foundCount == N - 1)
		{
			break;
		}

		for (int next : G[now])
		{
			if (Dist[next] == -1)
			{
				foundCount++;
				Dist[next] = Dist[now] + 1;
				Arrow[next] = now;
				que.push(next);
			}
		}
	}

	if (foundCount == N - 1)
	{
		cout << "Yes" << endl;
		for (int i = 2; i <= N; i++)
		{
			cout << Arrow[i] << endl;
		}
	}
	else
	{
		cout << "No" << endl;
	}
	
}

Measured memory_bytes: 10676
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 100000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem2224 : Save your cat **/

struct Edge {
	int from, to;
	double cost;
	Edge(int from_, int to_, double cost_) : from(from_), to(to_), cost(cost_){}
	bool operator <(const Edge &rhs) const {
		return cost > rhs.cost;
	}
};

struct UnionFind {
	vector<int> data;
	UnionFind(int v) : data(v, -1) {}
	int root(int x) {
		return data[x] < 0 ? x: (data[x] = root(data[x]));
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	void merge(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (size(y) > size(x)) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	int size(int x) {
		return -data[root(x)];
	}
};

double kruskal(const int v, vector<Edge> es) {
	sort(es.begin(), es.end());
	double ans = 0;
	UnionFind uf(v);
	for (int i=0; i<es.size(); i++) {
		if (uf.same(es[i].from, es[i].to)) continue;
		uf.merge(es[i].from, es[i].to);
		ans += es[i].cost;
	}
	return ans;
}

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

	
	vector<double> x(N), y(N);
	vector<Edge> e;
	double sum=0;
	
	rep(i, N) {
		cin>>x[i]>>y[i];
	}
	rep(i, M) {
		int a, b;
		cin>>a>>b;
		double d = sqrt((x[a-1]-x[b-1])*(x[a-1]-x[b-1]) + (y[a-1]-y[b-1])*(y[a-1]-y[b-1]));
		e.push_back(Edge(a-1, b-1, d));
		sum += d;
	}
	
	printf("%.3f\n", sum - kruskal(N, e));
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define UB upper_bound
#define LB lower_bound
#define PB push_back
#define mp make_pair
#define F first
#define S second
#define be(a) (a).begin(),(a).end()
#define deb(x) cout<< #x <<" "<<endl;
#define deb2(x, y) cout<< #x <<" "<< x <<endl<< #y <<" "<<y<<endl
#define fo(i, n) for(long long i=0; i<n; i++)
#define Fo(i, n, k) for(long long i=k; i<n; i++)
#define mod 1000000007
#define int long long

typedef long long ll;

void fileIO()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
typedef vector<pair<int, int>> vll;
typedef unordered_map<int, int> ump;



bool sortbysecdesc(const pair<int, int> &a, 
                    const pair<int, int> &b) 
{ 
    return a.second>b.second;
}



int32_t main()
{
    IOS;
    fileIO();
    int T;
    T = 1;
    //cin>>T;

    while(T--)
    {
        int n, W;
        cin>>n>>W;
        int *w = new int [n];
        int *v = new int [n];

        int maxv = 0;

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

        int *dp = new int[maxv+1];
        for(int i = 0; i<=maxv; i++)dp[i] = -1;
        dp[0] = 0;

        for(int i = 0; i<n; i++)
        {
            for(int j = maxv; j>=1; j--)
            {
                if(v[i]<=j)
                {
                    if(dp[j] == -1)
                    {
                        if(dp[j - v[i]] == -1)dp[j] = -1;
                        else
                        {
                            dp[j] = w[i] + dp[j - v[i]];
                        }
                    }
                    else
                    {
                        if(dp[j - v[i]] != -1)
                        {
                            dp[j] = min(dp[j], w[i] + dp[j - v[i]]);
                        }
                    }
                }
            }
        }

        int ans = 0;

        for(int i = maxv; i>=0; i--)
        {
            if(dp[i] != -1)
            {
                if(dp[i]<=W)
                {
                    ans = i;
                    break;
                }
            }
        }


        

        cout<<ans<<"\n";

        delete [] w;
        delete [] v;
        delete [] dp;
               
        
    }
    
    return 0;
}



Measured memory_bytes: 3892
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define mp make_pair;

const ll prime = 998244353;
const ld PI = 2 * acos(0.0);

/*
cout << fixed << setprecision(10);
*/

int main() {

	ld n;
	cin >> n;
	cout << n * n << endl;


	return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<tuple>
#include<utility>

using namespace std;



int main() {

	int a, b;
	cin >> a >> b;

	if (a >= 13)
		cout << b << endl;

	else if (6 <= a && a <= 12)
		cout << b / 2 << endl;

	else cout << 0 << endl;

	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main() {
    
    int n,m;
    cin>>n>>m;
    set<int> v;
    rep(i,m){
        int t;
        cin>>t;
        v.insert(t);
    }
    vll dp(n+10);
    dp[0]=1;
    rep(i,n){
        if(v.count(i)==1){
            dp[i]=0;
            continue;
        }
        if(v.count(i+1)==0){
            dp[i+1]+=dp[i];
            dp[i+1]%=MOD;
        }
        if(v.count(i+2)==0){
            dp[i+2]+=dp[i];
            dp[i+2]%=MOD;
        }
    }
    fin(dp[n]);

}

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

int main(){
  string S;
  int N;
  cin >> N >> S;
  for(int i=0; i<S.size(); i++){
    S[i]=(S[i]-'A'+N)%26+'A';
  }
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
def s(x):
    ans =0
    for c in str(x):
        ans += int(c)
    return(ans)
def snuke(x):
    return x/s(x)
def next(x,delta):
    return (x//delta + 1) * delta - 1

K = int(input())
ans = [1,2,3,4,5,6,7,8,9]
delta = 10
L = K-9
x=19
while L>0:
    if delta*s(x) >= x:
        ans.append(x)
        L -= 1
        x += delta
    else:
        delta *= 10
        x = next(x,delta)
for i in range(K):
    print(ans[i])

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

int main(){
  int N;
  std::string str;
  std::cin>>N;
  std::cin>>str;
  int dotnum=0;
  int sharpnum = 0;
  std::vector<int> v;

  for(int i = 0; i<N ; i++){
    if(str[i]=='#'){
      sharpnum++;
    }else{
      dotnum++;
    }
  }
  int countdowndot = dotnum;
  int countupsharp = 0;
  v.push_back(countdowndot);
  for(int i = 0 ; i < N ; i++ ){
    if(str[i]=='.'){
      countdowndot--;
      v.push_back(countdowndot+countupsharp);
    }else{
      countupsharp++;
      v.push_back(countdowndot+countupsharp);
    }
  }
  int min = *std::min_element(v.begin(),v.end());
  std::cout<<min<<std::endl;
  return 0;
}


Measured memory_bytes: 1784
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b)
		cout << c << "\n";
	else if (b == c)
		cout << a << "\n";
	else if(a == c)
		cout << b << "\n";
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	string s;
	getline(cin,s);
	//string r;
	ll t=s.size();
		char a='D';
		char b='P';
	for(ll i=0;i<t;i++){
		if(s[i]=='P'&&s[i+1]=='?'){
			s.replace(i+1,1,"D");
		}
		else if(s[i]=='?'){
			if(s[i+1]=='?'){
				s.replace(i,1,"P");
				s.replace(i+1,1,"D");
			}
			else if(s[i+1]=='D'){
			 s.replace(i,1,"P");
			}
			else{
			s.replace(i,1,"D");
			}
		}
	}
	cout<<s;
	
	return 0;
}

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

int main(){
  int k[8];

  string mery = "41212141",ans;
  while(cin >> k[0] >> k[1] >> k[2] >> k[3] >> k[4] >> k[5] >> k[6] >> k[7]){
    int mn = 5<<30,mnum = 5<<30;
    for(int i = 0 ; i < 8 ; i++ ){
      rotate(mery.begin(),mery.begin()+1,mery.end());
      int t = 0;

      for(int j = 0 ; j < 8 ; j++ ){
	if((mery[j]-'0') < k[j])t+=k[j]-(mery[j]-'0');
      }

      if(mn >= t ){

	if(mn == t &&  mnum > atoi(mery.c_str())){
	  mnum = atoi(mery.c_str());
	  mn = t;
	  ans = mery;
	}else if(mn > t){
	  mnum = atoi(mery.c_str());
	  mn = t;
	  ans = mery;
	}

      }
    }
    for(int i = 0 ; i < 8 ; i++ ){
      if(i == 0)cout << ans[i];
      else cout << " " << ans[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
if n >= m:
    print(0)
else:
    b = []
    for i in range(m-1):
        b.append(a[i+1]-a[i])
    b.sort()
    print(sum(b[:m-n:]))

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

int main()
{
	int n;
	cin >> n;
	vector<string> ss(n);
	for (auto &&s : ss)
	{
		cin >> s;
	}

	bool f = true;
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < i; j++)
		{
			f &= (ss[i] != ss[j]);
		}

		f &= (*ss[i - 1].rbegin() == ss[i][0]);
	}

	cout << (f ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define fo(i,n)        for(int i=0; i<n; i++)
#define foa(i,k,n)     for(int i=k; i<=n; i++)
#define fod(i,k,n)     for(int i=n; i>=k; i--)
#define clr(arr)       memset(arr, 0, sizeof arr)
#define hi(x)          cout<<" -> "<<#x<<" : "<<x<<endl;
using namespace std;
const int mod = 1e9 + 7;

int a[1001];
void solve()
{
// #define T
	int n, k;
	cin>>n>>k;
	for(int i=0; i<n; i++)
		cin>>a[i];
	sort(a,a+n);
	int ans=0;
	for(int i=0; i<k; i++)
		ans+=a[i];
	cout<<ans<<endl;
}

int32_t main()
{
///////////////////////////////////////////////////////
#ifdef FIN
	freopen("in.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
///////////////////////////////////////////////////////

	int t = 1;
#ifdef T
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cmath>

using namespace std;

const double pi = 4*atan(1);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, ans;
	char op;
	while(true) {
		cin>>a>>op>>b;
		if     (op=='+') ans=a+b;
		else if(op=='-') ans=a-b;
		else if(op=='*') ans=a*b;
		else if(op=='/') ans=a/b;
		else break;
		cout<<ans<<'\n';
	}
	return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};
/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_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;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/
int main(){
    int N;
    vector<int> ans(0);
    while(cin >> N && N != EOF){
        if (cin.eof()){
            break;
        }
        vector<int> a(N);
        for (int i = 0; i < N; i++){
            cin >> a[i];
        }
        sort(a.begin(), a.end());
        int tmp = 0;
        int sum = 0;
        for (int i = 0; i < N; i++){
            tmp += a[i];
            sum += tmp;
        }
        ans.push_back(sum);
    }
    for (int i = 0; i < ans.size(); i++){
        cout << ans[i] << endl;
    }
}


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

int main(){
  int n;
  cin >> n;
  bool ans = false;
  for (int i = 1;i <= 9;i++){
    for (int j = 1;j <= 9;j++){
      if (i*j == n) ans = true;
    }
  }
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int n = stdIn.nextInt();
		int k = stdIn.nextInt();
		for(int i=0;i<k;i++){
			int x = stdIn.nextInt();
			int y = stdIn.nextInt();
			x = Math.min(x, n-x+1);
			y = Math.min(y, n-y+1);
			int p = Math.min(x, y);
			System.out.println(p%3==0?"3":p%3);
		}
		/* Sampleは下記で通るが，大きいデータは
		 * 二次元配列宣言でヒープが足りなくREとなる
		int[][] p = new int[n][n];
		int left = 0;
		int up = 0;
		int right = n-1;
		int down = n-1;
		int nowColor = 0;
		while(true){
			++nowColor;
			if(nowColor==4) nowColor = 1;
			for(int i=0;i<n;i++){
				if(p[up][i]==0){
					p[up][i] = nowColor;
				}
				if(p[down][i]==0){
					p[down][i] = nowColor;
				}
				if(p[i][left]==0){
					p[i][left] = nowColor;
				}
				if(p[i][right]==0){
					p[i][right] = nowColor;
				}
			}
			up++;
			down--;
			left++;
			right--;
			if(down<up){
				break;
			}
		}
//		for(int i=0;i<n;i++){
//			for(int j=0;j<n;j++){
//				System.out.print(p[i][j]);
//			}
//			System.out.println();
//		}
		int k = stdIn.nextInt();
		for(int i=0;i<k;i++){
			int a = stdIn.nextInt();
			int b = stdIn.nextInt();
			System.out.println(p[b-1][a-1]);
		}*/
	}
}

Measured memory_bytes: 25120
#include<algorithm>
#include<iostream>

using namespace std;

int main(){
    int N,K;
    cin>>N>>K;
    int l[N];
    for(int i=1;i<=N;++i)cin>>l[i];

    sort(l+1,l+N+1,greater<int>());
    int sum=0;
        for(int i=1;i<=K;++i){
            sum+=l[i];
        }
    cout<<sum;
}

Measured memory_bytes: 3140