akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	printf("%lf\n",a*b*sin(c/180.0*M_PI)/2.0);
	printf("%lf\n",a+b+sqrt(a*a+b*b-2.0*a*b*cos(c*M_PI/180.0)));
	printf("%lf\n",b*sin(c*M_PI/180.0));
	return 0;
}

Measured memory_bytes: 1228
import sys
import numpy as np

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, W = map(int, readline().split())
things = []
vsum = 0
for i in range(N):
    weight, value = map(int, readline().split())
    things.append((weight, value))
    vsum += value


INF = 1 << 62


def solve():
    dp = INF * np.ones(vsum + 1, dtype=int)
    w0, v0 = things[0]
    dp[0] = 0
    dp[v0] = w0
    for i in range(1, N):
        w, v = things[i]
        np.minimum(dp[v:], dp[:-v] + w, out=dp[v:])
    return np.where(dp <= W)[0][-1]


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 13988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int main()
{
	int sum=0;
	string s;
	cin>>s;
	for(int i=0;i<s.length()/2;i++)
	{
		if(s[i]!=s[s.length()-1-i])sum++;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int nax=1e6+5;
vector<int> edges[nax];
int in_degree[nax];
int dist[nax];
bool visited[nax];

void dfs(int u){
    assert(!visited[u]);
    visited[u]= true;
    for(int v:edges[u]){
        dist[v]=max(dist[v],dist[u]+1);
        --in_degree[v];
        if(in_degree[v]==0){
            dfs(v);
        }
    }
}
int main() {
    int n;
    cin>>n;
    int m;
    cin>>m;
    while (m--){
        int x,y;
        cin>>x>>y;
        edges[x].push_back(y);
        ++in_degree[y];
    }
    for(int i=1;i<=n;i++){
        if(!visited[i] && in_degree[i]==0){
            dfs(i);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,dist[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 35664
import sys
from collections import deque
import numpy as np
input = sys.stdin.readline
H, W = [int(x) for x in input().strip().split()]
S = np.zeros((H + 2) * (W + 2)).reshape(H + 2, W + 2)
u = np.zeros((H + 2) * (W + 2)).reshape(H + 2, W + 2)
d = np.zeros((H + 2) * (W + 2)).reshape(H + 2, W + 2)
l = np.zeros((H + 2) * (W + 2)).reshape(H + 2, W + 2)
r = np.zeros((H + 2) * (W + 2)).reshape(H + 2, W + 2)

for h in range(H):
    s = [1 if i == '.' else 0 for i in input().strip()]
    S[h + 1] = np.array([0] + s + [0])

for h in range(1, H + 1):
    u[h] = (u[h-1] + 1) * S[h]
    d[H+1-h] = (d[H+2-h] + 1) * S[H+1-h]

for w in range(1, W + 1):
    l[:, w] = (l[:, w-1] + 1) * S[:, w]
    r[:, W+1-w] = (r[:, W+2-w] + 1) * S[:, W+1-w]

ans = u+d+l+r
print(int(ans.max()-3))

Measured memory_bytes: 231628
#include <stdio.h>

int main(void)
{
	int a[4],b[4],i,j;
	
	while(scanf("%d",&a[0]) != EOF){
		int hit = 0,blow = 0;
		
		for(i = 1;i < 4;i++){
			scanf("%d",&a[i]);
		}
		for(i = 0;i < 4;i++){
			scanf("%d",&b[i]);
		}
		for(i = 0;i < 4;i++){
			
			if(a[i] == b[i]){
				hit++;
			}
		}
		for(i = 0;i < 4;i++){
			for(j = 0;j < 4;j++){
				if(a[i] == b[j]){
					blow++;
				}
				
			}
		}
		printf("%d %d\n",hit,blow - hit);
	}
	return 0;
}

Measured memory_bytes: 596
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 
ll div(ll n) {
	ll ans = (ll)(1e15);
	for(ll i = 1; i*i <= n; i++) {
		if(n%i == 0) {
			if(n%i == i) {
				ans = min(ans, i + i - 2);
			} else {
				ans = min(ans, i + (n/i) - 2);
			}
		}
	}
	return ans;
}

int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
 ll n;
 cin >> n;
 cout << div(n) << endl;
} //good night.

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::cmp;
use std::collections::HashMap;
use std::collections::HashSet;
use std::char;
use std::cmp::{min, max};
use itertools::Itertools;
use num_integer::div_floor;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_tuple2<T: FromStr, S: FromStr>() -> (T, S) {
    let a = read();
    let b = read();
    (a, b)
}

fn read_tuple3<T: FromStr, S: FromStr, R: FromStr >() -> (T, S, R) {
    let a = read();
    let b = read();
    let c = read();
    (a, b, c)
}

fn main() {
    let s:String = read();
    let t:String = read();
    let sc:Vec<char> = s.chars().collect();
    let tc:Vec<char> = t.chars().collect();
    let mut cnt = 0;
    for i in (0..sc.len()){
        if sc[i] != tc[i] {
            cnt += 1;
        }
    }
    println!("{}", cnt);

}



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

using namespace std;

const int INF = 1 << 30;

string S;
set< int > beet_aizu[26];
int dp[200005], nxt[200005];

int rec(int idx)
{
  if(idx == S.size() + 1) return (0);
  if(dp[idx] < INF) return (dp[idx]);
  for(int i = 0; i < 26; i++) {
    int cost = rec(*beet_aizu[i].upper_bound(idx)) + 1;
    if(cost < dp[idx]) {
      dp[idx] = cost;
      nxt[idx] = i;
    }
  }
  return (dp[idx]);
}

void rec2(int idx)
{
  if(nxt[idx] == -1) return;
  cout << (char) (nxt[idx] + 'a');
  rec2(*beet_aizu[nxt[idx]].upper_bound(idx));
}

int main()
{
  cin >> S;
  for(int i = 0; i < S.size(); i++) {
    beet_aizu[S[i] - 'a'].emplace(i + 1);
  }
  for(int i = 0; i < 26; i++) {
    beet_aizu[i].emplace((int) S.size() + 1);
  }

  fill_n(dp, 200001, INF);
  memset(nxt, -1, sizeof(nxt));
  rec(0);
  rec2(0);
  cout << endl;
}



Measured memory_bytes: 13828
import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int[] c = new int[n];
        int[][] a = new int[n][m];

        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
            for (int j = 0; j < m; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        long ans = Long.MAX_VALUE;

       loop1: for (int i = 0; i < Math.pow(2,n); i++) {
            boolean ok = true;
            long res = 0;
           loop2: for (int k = 0; k < m; k++) {
                long sum = 0;
                for (int j = 0; j < n; j++) {
                    if ((1&i >> j) == 1) {
                        res += c[j];
                        sum += a[j][k];
                    }
                    // System.out.println(sum);
                }
                if (sum < x) {
                    ok = false;
                    break loop2;
                }
                // System.out.println();
            }
            // System.out.println(res/m);
            if (ok) {
                ans = Math.min(ans,res/m);
            }
        }

        if (ans == Long.MAX_VALUE) {
            System.out.println(-1);
        } else {
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 36540
n = int(input())
h = list(map(int,input().split()))

flag = True
count = 0
for i in range(len(h)-1):
    if h[i] < h[i + 1]:
        count = 0
    else:
        count += h[i] - h[i+1]
        if count >= 2:
            flag = False
            print('No')
            exit()

print('Yes')


Measured memory_bytes: 14396
import scala.io.StdIn.{readInt,readLine}
import scala.collection.mutable.ArrayBuffer

object Main {

  def main(args:Array[String]) = {
    val b = new ArrayBuffer[Int]
    var n = 0
    while({n=readInt;n}!=0) {
      val list = {
        for(i<-1 to n) yield {
          val n = readLine.split(" ").map(_.toInt)
          val id = n(0)
          val sec = n(1)*60+n(2)+n(3)*60+n(4)+n(5)*60+n(6)+n(7)*60+n(8)
          (id,sec)
        }
      }.toList.sortWith(_._2<_._2)
      b += list(0)._1
      b += list(1)._1
      b += list(list.length-2)._1
    }
    println(b.mkString("\n"))
  }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=1'000'000'007;
const double EPS=1e-14;
const bool DEBUG=true;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////


void answer(){
    int a, b;
    cin>>a>>b;
    cout<<a*b<<endl;


    return;
}

/////

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(16);

    answer();

    return 0;
}


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

int main() {
    int n,l;
    cin>>n>>l;
    int r=l+n-1;
    int sm=n*(l+r)/2;
    if (r<0)
        sm-=r;
    else if (0<l)
        sm-=l;
    cout<<sm<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int func(int n)
{
    int num;
    vector<string> vec(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vec.at(i);
    }

    sort(vec.begin(),vec.end());
    auto itr = unique(vec.begin(), vec.end());
    vec.erase(itr, vec.end());

    return vec.size();
}

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

    n = func(n);
    cout << n;
    return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>
int main(){
	int n,a;
	scanf("%d",&n);
	a=n%10;
	if(a==2||a==4||a==5||a==7||a==9)printf("hon\n");
	else if(a==0||a==1||a==6||a==8)printf("pon\n");
	else if(a==3)printf("bon\n");
	return 0;
}

Measured memory_bytes: 1648
#include <bits/stdc++.h>
#define lld long long int
#define max 100005
using namespace std;

int q, n[max], menores[max], maiores[max], m, r;

int main(){

    scanf("%d", &q);

    for(int i = 1; i <=q; i++){
        int aux;
        scanf("%d", &aux);
        if(aux>m)m=aux;
        n[aux]++;
    }

    int aux = 0;

    for(int i = 1; i<=m; i++){
        if(i>1){
            menores[i]=aux;
        }
        maiores[i]=q-aux;
        aux+=n[i];

        if(menores[i]==maiores[i])r++;
    }


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


}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
int h[MAX_N];
ll dp[MAX_N];

int main2() {
  int N = nextInt();
  int K = nextInt();
  REP(i, N) h[i] = nextInt();

  const int INF = 1001001001;
  REP(i, MAX_N) dp[i] = INF;
  dp[0] = 0;
  for (int i = 1; i < N; i++) {
    for (int k = 1; k <= K; k++) {
      if (i-k >= 0) chmin(dp[i], dp[i-k] + abs(h[i] - h[i-k]));
    }
  }
  cout << dp[N-1] << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextInt();
        long B = sc.nextInt();
        sc.close();

        long judge = 0;

        for (int i = 1; i <= B; i++) {
            judge = A * i;
            if (judge % B == 0) {
                break;
            }
        }

        System.out.println(judge);
    }

}

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

const int N = 1e6 + 5;
map<int, int> ma;
const int test_time = 8;
int quickPow(int x, int y, int mod) {
    x %= mod;
    int ans = 1;
    while (y) {
        if (y & 1) ans = (1LL * ans * x) % mod;
        y >>= 1;
        x = (1LL * x * x) % mod;
    }
    return ans % mod;
}
bool millerRabbin(int n) {
    if (n < 3) return n == 2;
    int a = n - 1, b = 0;
    while (a % 2 == 0) a /= 2, ++b;
    // test_time 为测试次数,建议设为不小于 8
    // 的整数以保证正确率,但也不宜过大,否则会影响效率
    for (int i = 1, j; i <= test_time; ++i) {
        int x = rand() % (n - 2) + 2, v = quickPow(x, a, n);
        if (v == 1 || v == n - 1) continue;
        for (j = 0; j < b; ++j) {
            v = (long long) v * v % n;
            if (v == n - 1) break;
        }
        if (j >= b) return 0;
    }
    return 1;
}
bool prime_diecom(int n) {
    map<int, int> tmp;
    for (int i = 2; i <= n; i++) {
        while (n != i) {
            if (n % i == 0) {
                if (ma.count(i)) return false;
                tmp[i] = 1;
                n = n / i;
            } else
                break;
        }
        if (millerRabbin(n)) {
            if (ma.count(n)) return false;
            tmp[n] = 1;
            break;
        }
    }
    for (auto &i : tmp) ma[i.first] = 1;

    return true;
}
int main() {
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    bool ispairwise = true, issetwise = true;
    int n;
    cin >> n;
    vector<int> num(n);
    int gcd = 0;
    for (int i = 0; i < n; i++) {
        cin >> num[i];
        if (ispairwise) ispairwise = prime_diecom(num[i]);
        if (i == 0)
            gcd = num[i];
        else
            gcd = __gcd(gcd, num[i]);
    }
    if (gcd != 1) issetwise = false;
    if (ispairwise) {
        puts("pairwise coprime");
    } else if (issetwise) {
        puts("setwise coprime");
    } else {
        puts("not coprime");
    }
    return 0;
}

Measured memory_bytes: 7304
import math,itertools
n = int(input())
x = []
y = []
l = []
d = []
s = []
for i in range(n):
  a,b = map(int,input().split())
  x.append(a)
  y.append(b)
  l.append(i+1)
for j in itertools.permutations(l):
  for k in range(len(j)-1):
    d.append(math.sqrt((x[j[k]-1]-x[j[k+1]-1])**2+(y[j[k]-1]-y[j[k+1]-1])**2))
  s.append(sum(d))
  d = []
print(
sum(s)/math.factorial(n))

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

using ll = long long;

int main() {
    int n, m; cin >> n >> m;
    string s; cin >> s;
    int c = n;
    vector<int> ans;
    while (c > 0) {
        bool ok = false;
        // cerr << c << endl;
        for (int i = m; i > 0; --i) {
            // cerr << "[!]" << i << " " << c << " " << s[c-i] << endl;
            if (c-i < 0) continue;
            if (s[c-i] == '1') continue;
            ok = true;
            c = c-i;
            ans.push_back(i);
            break;
        }
        if (!ok) {
            cout << -1;
            return 0;
        }
    }
    for (int i = 0; i < ans.size(); ++i) {
        cout << ans[ans.size()-1-i] << " ";
    }
    cout << endl;
}


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

const double PI=3.14159265358979; 
int main(){
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  int MIN=h*60+m;
  double j=abs(MIN*PI/360-MIN*PI/30);
  cout<<fixed<<setprecision(11)<<sqrt(a*a+b*b-2*a*b*cos(j))<<endl;
return 0;
}

Measured memory_bytes: 4176
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def sum_matrix(array):
	return sum([sum(x) for x in array])
count = {}
H, W, N = MAP()
ab = [LIST() for _ in range(N)]
for a, b in ab:				
	for i in range(a-3, a):
		for j in range(b-3, b):
			if i < 0 or j < 0:
				continue
			if i+2 >= H or j+2 >= W:
				continue
			else:
				if not str(i)+","+str(j) in count:
					count[str(i)+","+str(j)] = 1
				else:
					count[str(i)+","+str(j)] += 1
ans = [0] * 10
for key in count:
	ans[count[key]] += 1
ans[0] = (H-2)*(W-2)-sum(ans)
for i in ans:
	print(i)

Measured memory_bytes: 151888
N = int(input())
M = N
S = 0

for i in range(10,0,-1):
    p  =  M//10**(i)
    if p != 0:
        M = M - p*10**(i)
    S = S + p
S = S + M

if N%S ==0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
    int map[1000];
    int dx, now;
    int n, m;
    int i, j;
    int ans;
    
    while (1){
        scanf("%d%d", &n, &m);
        
        if (n + m == 0){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%d", &map[i]);
        }
        
        now = ans = 0;
        
        for (i = 0; i < m; i++){
            scanf("%d", &dx);
            if (now < n){
                now += dx + map[now + dx];
                ans++;
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	vector<int>arr;
	arr.push_back(a);
	arr.push_back(b);
	arr.push_back(c);
	sort(arr.begin(),arr.end());
	int mx = arr[2];
	int mx2 = arr[1];
	string s = to_string(mx)+to_string(mx2);
	int tp = stoi(s);
	cout<<tp+arr[0]<<"\n";
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
now = 1
flag = [False] * N
c = 0
temp = [0]*N
hoge = False
for i in range(K):
    if flag[now-1]:
        hoge = True
        break
    temp[now-1] = i
    flag[now-1] = True
    now = A[now-1]
    c += 1
if hoge:
    c -= temp[now-1]
    K -= temp[now-1]
    for _ in range(K%c):
        now = A[now-1]
print(now)

Measured memory_bytes: 32376
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REPEACH(itr, k) for (autaaaaaaaaaaaaaaaaaaaaaaao &&itr : k)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;


const ll INF = 1ll << 60;
const ll MOD = 1000000007;
int n;
vector<int> v(100000);

int func(int a,int b){
    if(a==b){
        return 1;
    }
    return 0;
}
ll md(ll a){
    return a-(a/MOD)*MOD;
}
ll saiki(int a,int b,int c,int i){
    if(i==n-1){
        return func(a,v[i])+func(b,v[i])+func(c,v[i]);
    }
    else if(i==0){
        return md(3*saiki(a+1,b,c,i+1));
    }
    else{
        int tmp=0;
        if(a==v[i]){
            tmp++;
            a++;
        }
        if(b==v[i]){
            tmp++;
            if(tmp==1){
                b++;
            }
        }
        if(c==v[i]){
            tmp++;
            if(tmp==1){
                c++;
            }
        }
        if(tmp==0){
            return 0;
        }
        return md(tmp*saiki(a,b,c,i+1));
    }
}

int main()
{
    cin >> n;
    ll ans=0;
    REP(i,n){
        cin >> v[i];
    }
    if(v[0]!=0){
        cout << 0 << endl;
        return 0;
    }
    cout << saiki(0,0,0,0) << endl;
}

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

int a[1111], b[1111], c[1111], d[1111], p[333], x, y, z;

int main(){
  
  while(cin >> a[0] >> b[0] >> c[0], *a+=*b+*c){
    for(int i=332;i;) p[i--] = 2;
    
    cin >> p[0];
    for(int i=0;i++<*p;) cin >> a[i] >> b[i] >> c[i] >> d[i];
    
    for(int i=0;i++<*p;){
      for(int j=0;j++<*p;){
	if(d[j]) p[a[j]] = p[b[j]] = p[c[j]] = 1;
	else{
	  if(p[a[j]]&p[b[j]]&1) p[c[j]] = 0;
	  else if(p[a[j]]&p[c[j]]&1) p[b[j]] = 0;
	  else if(p[b[j]]&p[c[j]]&1) p[a[j]] = 0;
	}
      }
    }
    for(int i=0;i<*a;) cout << p[++i] << endl;
  }
  
}

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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    int n,count = 0,min;
    vector<int> a;
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin>>x;
        a.push_back(x);
    }
    min = n+1;
    for (int i = 0; i < n; i++)
    {
        if(a[i]<min)
        {
            count++;
            min  = a[i];
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, a[1000], i, ans=0, tmp;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
        ans+=a[i];
    }
    tmp=ans;
    sort(a, a+n);
    i=0;
    while(ans%10==0){
        if(a[i]%10!=0) ans-=a[i];
        i++;
        if(i==n) break;
    }
    if(ans==tmp && ans%10==0) ans=0;
    cout << ans <<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ios::sync_with_stdio(0);
	string s,t;
	int ans=0;
	cin>>s>>t;
	for(int i=0;i<3;i++){
		if(s[i]==t[i])ans++;
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// youngjinp20
// 2020 03

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

typedef long long ll;

const int MAX = 1e5;
int N, K;
int h[MAX];

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

	int dp[MAX];
	for (int i=1; i<N; i++) {
		dp[i] = 1e9;
		for (int j=1; j<=K; j++) {
			if (i >= j) {
				dp[i] = min(dp[i-j] + abs(h[i] - h[i-j]), dp[i]);
			}
		}
	}

	cout << dp[N-1] << endl;

	return 0;
}


Measured memory_bytes: 1024
n=int(input())
s=[i for i in range(n+1)]
a=[1,6,9,36,81,216,729,1296,6561,7776,46656,59049]
for i in range(n+1):
    s[i]=i
for i in range(1,12):
    if a[i]<=n :
        k=a[i]
        for j in range(k,n+1):
            if s[j]>s[j-k]+1:
                s[j]=s[j-k]+1
print(s[n])


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int solve(int a, vector<int> &dp, vector<vector<int>> &V){
	if(dp[a] >= 0) return dp[a];
	dp[a] = 0;
	for(auto u : V[a]){
		dp[a] = max(dp[a],solve(u,dp,V)+1);
	}
	return dp[a];
}

int main(){
	int N,M; cin >> N >> M;
	vector<vector<int>> V(N);
	repp(i,0,M){
		int x,y; cin >> x >> y;
		--x; --y;
		V[x].push_back(y);
	}
	vector<int> dp(N,-1);
	int ans = 0;
	repp(i,0,N) ans = max(ans,solve(i,dp,V));
	cout << ans << endl;
	return 0;
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2097162
#define inf 1e9
#define MOD 1000000007

int main()
{

    string ss;
    ll ans = 0;
    cin >> ss;
    string kk = ss;
    ll ans2 = 0;
    for(ll i = 1; i < ss.size(); i++)
    {

        if(ss[i] == ss[i-1])
        {

            ans++;
            if(ss[i]=='1') ss[i] = '0';
            else ss[i] = '1';
        }
    }
    for(ll i = kk.size()-1; i >= 0; i--)
    {

        if(kk[i]==kk[i+1])
        {

            ans2++;
            if(kk[i]=='1') kk[i] = '0';
            else kk[i] = '1';
        }
    }
    cout << min(ans, ans2);
}


Measured memory_bytes: 512
#define z 1000000
a[z],b[z],n,x,c;
main(i){for(;i++<z;)a[i]=i;for(i=0;i++<z;)if(a[i])for(b[x++]=i,c=i;c<z;c+=i)a[c]=0;for(;~scanf("%d",&n);){c=0;while(b[c]<=n&&b[c++]);printf("%d\n",c);}exit(0);}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    string s, t; cin >> s >> t;
    bool isOK = false;
    for(char i = 'a'; i <= 'z'; ++i){
        string tmp = s+i;
        if(t == tmp) isOK = true;
    }
    if(isOK) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
  string s;
  int i,j_1,j_2 ;
  
  cin >> s ;
  
    
  for(i=0;i<s.length();i++){
    if(s[i]=='A'){
      j_1=i;
      break ;
    }
  }
  
  for(i=0;i<s.length();i++){
    if(s[i]=='Z'){
      j_2=i;
    }
  }
  
  cout << j_2-j_1+1 << endl;
}

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

using namespace std;

typedef pair<int, int> PII;
typedef long long ll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pct __builtin_popcount

#define N 100100
int n, m, q;
int a[N];

int b[N];
int c[N], L;
bool v[N];

int u[N];
int fi[N];

int main () {
	cin >> n >> m >> q;
	for (int i = 0; i < q; i ++) {
		cin >> a[i];
		a[i] --;
	}
	/*
	if (a[q-1] == 0) {
		int u = q-1;
		int nw = 0;
		bool F = true;
		while (nw < m-1 && u >= 0) {
			if (a[u] != nw) {
				F = false; break;
			}
			while (u >= 0 && a[u] <= nw) u--;
			nw ++;
		}
		if (F) {puts ("Yes"); return 0;}
	}
	*/
	memset(v, 0, sizeof v);
	memset(b, -1, sizeof b);
	for (int i = q-1; i >= 0; i --) if (!v[a[i]]) {
		b[a[i]] = L;
		c[L++] = a[i];
		v[a[i]] = 1;
	}
	memset(v, 0, sizeof v);
	int la = 0;
	int lw = 0;
	for (int i = 0; i < L; i ++) {
		if (c[i] != lw) la = i+1;
		v[c[i]] = 1;
		while (v[lw]) lw++;
	}
	if (la == 0) {
		puts ("Yes");
		return 0;
	}
	memset(fi, -1, sizeof fi);
	memset(v, 0, sizeof v);
	for (int i = q-1; i >= 0; i --) {
		if (b[a[i]] >= la) continue;
		if (b[a[i]] == 0 && u[0] == n) continue;
		if (b[a[i]] > 0 && u[b[a[i]]-1] == u[b[a[i]]]) continue;
		if (fi[b[a[i]]] == -1) fi[b[a[i]]] = i;
		v[i] = 1;
		u[b[a[i]]] ++;
	}
	if (u[la-1] != n) {
		puts ("No"); return 0;
	}
	bool F = true;
	for (int i = q-1; i >= 0; i --) if (!v[i]) {
		if (b[a[i]] >= la) {
			if (fi[la-1] < i) {
				F = false; break;
			}
		} else 
		if (b[a[i]] >= 0) {
			if (fi[b[a[i]]] < i) {
				F = false; break;
			}
		}
	}
	if (F) puts ("Yes"); else puts ("No");
	return 0;
}

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

struct State{
  double L, a, b;
  State(double L, double a, double b): L(L), a(a), b(b){}
};

double sq(double d){
  return d*d;
}

int main(){
  int N, M;
  cin >> N >> M;  
  vector<State> V;
  
  double L, a, b;
  for(int i = 0 ; i < N ; i++){
    cin >> L >> a >> b;
    V.push_back(State(L, a, b));
  }

  double ans = 0;
  for(int i = 0 ; i < (1<<N) ; i++){
    if(__builtin_popcount(i) != M) continue;
    
    vector<int> v;
    for(int j = 0 ; j < N ; j++){
      if( i & 1 << j ) v.push_back(j);    
    }
    
    double sum = 0;
    for(int j = 0 ; j < M ; j++){
      for(int k = j+1 ; k < M ; k++){
	sum += sq(V[v[j]].L - V[v[k]].L) + sq(V[v[j]].a - V[v[k]].a) + sq(V[v[j]].b - V[v[k]].b);
      }
    }
    
    ans = max(ans, sum);    
  }
  
  printf("%.10f\n", ans);
  
  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    // int r = count(s.begin(), s.end(), "R")
    int ans = INT_MAX;
    int left = 0;                               //number of whites preceeding the divider
    int right = count(s.begin(), s.end(), 'R'); //number of reds following the divider
    for (int i = 0; i < n; i++)
    {
        ans = min(max(left, right), ans);
        left += s[i] == 'W';
        right -= s[i] == 'R';
    }
    cout << min(max(left, right), ans) << endl;
}

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

#define mp make_pair
#define pb push_back
#define f first
#define s second 
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define forn(i, x, y) for(int i = x; i <= y; i++)
#define forev(i, y, x) for(int i = y; i >= x; i--)

using namespace std;

const int maxn = (int)3e5 + 100;
const int mod = (int)1e9 + 7;
const int P = (int)1e6 + 7;
const int inf = (int)1e9 + 7;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef long double ld;

int n, k, a[maxn], s;
main () {
	cin >> n >> k;
	forn(i, 1, n) cin >> a[i], s += a[i];
	vi d;
	forn(i, 1, sqrt(s)){
		if(s % i == 0)
			d.pb(i), d.pb(s / i);
	}
	sort(all(d));
	reverse(all(d));
	for(auto x : d){
		if(s % x) continue;
		int step = 0;
		vi v;
		forn(i, 1, n){
			if(a[i] % x == 0) continue;
			v.pb(a[i] % x);
		}
		sort(all(v));
		int l = 0, r = sz(v) - 1, s1 = 0, s2 = 0;
		while(l <= r){
			
			if(s1 <= s2){
				s1 += v[l];
				step += v[l];
				l++;
			}else{
				s2 += x - v[r];
				step += x - v[r];
				r--;
			}
		}
		if(s1 != s2) continue;
		if(step <= 2 * k){
			cout << x;
			return 0;
		}
	}
}

Measured memory_bytes: 256
C=[list(map(int,input().split())) for i in range(3)]
Bs=[C[0][i] for i in range(3)]
As=[0,C[1][0]-Bs[0],C[2][0]-Bs[0]]
if all(As[i]+Bs[j]==C[i][j] for i in range(3) for j in range(3)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

struct Node{
	bool operator<(const struct Node &arg) const{
		return weight < arg.weight;
	};
	int from,to,weight;
};

int parent[10000],height[10000];

int getParent(int id){
	if(parent[id] == id)return id;
	else{
		return parent[id] = getParent(parent[id]);
	}
}

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

void unite(int a,int b){	
	int a_parent = getParent(a);
	int b_parent = getParent(b);

	if(a_parent == b_parent)return;

	if(height[a_parent] > height[b_parent]){
		parent[b_parent] = a_parent;
	}else{
		if(height[a_parent] == height[b_parent])height[b_parent]++;
		parent[a_parent] = b_parent;
	}
}


int main(){

	int V,E;

	scanf("%d %d",&V,&E);
	Node nodes[E];

	for(int i = 0; i < V; i++){
		parent[i] = i;
		height[i] = 0;
	}

	for(int i = 0; i < E; i++){
		scanf("%d %d %d",&nodes[i].from,&nodes[i].to,&nodes[i].weight);
	}

	sort(nodes,nodes+E);

	int sum = 0;

	for(int i = 0; i < E; i++){
		if(!isSame(nodes[i].from,nodes[i].to)){
			sum += nodes[i].weight;
			unite(nodes[i].from,nodes[i].to);
		}
	}

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

	return 0;
}



Measured memory_bytes: 3968
#include "iostream"
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;

    int ans;

    if (( 1 <= a && a <= 9 ) && (1 <= b && b <= 9)){
        ans = a*b;
    } else {
        ans = -1;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf = 10000000;
vector<string> maze;
int h,w,k;
int sh,sw,gh,gw;
int dh[4] = {0,0,1,-1};
int dw[4] = {1,-1,0,0};

struct p{
    int d;
    int left;
    int dir = -1;
    int hh, ww;
    p() {
        d = inf;
        left = 0;
    }
    p(int a, int b, int c) {
        d = a;
        left = b;
        dir = c;
    }
    p(int _a, int _b, int _e, int _c, int _d) {
        d = _a;
        left = _b;
        dir = _e;
        hh = _c;
        ww = _d;
    }
    const bool operator >(const p& b) const {
        if (d == b.d) {
            return left < b.left;
        } else {
            return d > b.d;
        }
    }
    const bool operator <(const p& b) const {
        if (d == b.d) {
            return left > b.left;
        } else {
            return d < b.d;
        }
    }
} dp[4][1000010];

int pos(int a, int b) {
    return a * w + b;
}

int main () {
    cin >> h >> w >> k;
    cin >> sh >> sw >> gh >> gw;
    sh--;
    sw--;
    gh--;
    gw--;
    for (int i = 0; i < h; i++) {
        string s;
        cin >> s;
        maze.push_back(s);
    }
    priority_queue<p,vector<p>,greater<p>> pq;
    dp[0][pos(sh,sw)] = p(0,0,0,sh,sw);
    dp[1][pos(sh,sw)] = p(0,0,1,sh,sw);
    dp[2][pos(sh,sw)] = p(0,0,2,sh,sw);
    dp[3][pos(sh,sw)] = p(0,0,3,sh,sw);
    pq.push(p(0,0,0,sh,sw));
    pq.push(p(0,0,1,sh,sw));
    pq.push(p(0,0,2,sh,sw));
    pq.push(p(0,0,3,sh,sw));
    while (!pq.empty()) {
        p tp = pq.top();
        pq.pop();
        int dir = tp.dir;
        int basyo = pos(tp.hh,tp.ww);
        int cost = tp.d;
        int left = tp.left;
        if (dp[dir][basyo] < tp) continue;
        // cout << tp.hh << " " << tp.ww << " " << tp.d << " " << tp.left << " " << tp.dir << endl;
        
        for (int i = 0; i < 4; i++) {
            int th = tp.hh + dh[i];
            int tw = tp.ww + dw[i];
            if (th < 0 || th >= h || tw < 0 || tw >= w) continue;
            if (maze[th][tw] == '@') continue;
            p nxt;
            if (i == dir) {
                nxt = p(cost,left-1,dir,th,tw);
                if (nxt.left < 0) {
                    nxt.d += 1;
                    nxt.left = k-1;
                }
            } else {
                nxt = p(cost+1,k-1,i,th,tw);
            }
            if (dp[nxt.dir][pos(nxt.hh,nxt.ww)] > nxt) {
                dp[nxt.dir][pos(nxt.hh,nxt.ww)] = nxt;
                pq.push(nxt);
            }
        }
    }
    int basyo = pos(gh,gw);
    p ans = min({dp[0][basyo],dp[1][basyo],dp[2][basyo],dp[3][basyo]});
    if (ans.d == inf) {
        cout << -1 << endl;
    } else {
        cout << ans.d << endl;
    }
    return 0;
}

Measured memory_bytes: 87536
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

ll n,m,x,y,idx,T,ans;
vector< ll > arr[100010];
priority_queue< ll > pq;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;
    for(ll i=0; i<n; i++){
        cin >> x >> y;
        if( x>m ) continue;
        arr[m-x].pb( y );
    }

    for(ll i=m; i>=0; i--){
        for( auto val:arr[i] ) pq.push( val );
        if( !pq.empty() ){
            ans+=pq.top();
            pq.pop();
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 5760
from heapq import heapify, heappop, heappush

# 次の桁の生成ルール ex. 1 -> 10, 11, 12
def next_int(n):
    nums = {0: [0, 1],
            1: [0, 1, 2],
            2: [1, 2, 3],
            3: [2, 3, 4],
            4: [3, 4, 5],
            5: [4, 5, 6],
            6: [5, 6, 7],
            7: [6, 7, 8],
            8: [7, 8, 9],
            9: [8, 9]}
    return nums[n]

K = int(input())
queue = [1, 2, 3, 4, 5, 6, 7, 8, 9]  # とりあえず 1 桁目を初期値にとる
heapify(queue)

for _ in range(K-1):
    now = heappop(queue)  # 最小値を取り出す
    # 取り出した値を使って次の桁を生成し queue に投げる
    for next_i in next_int(int(str(now)[-1])):
        heappush(queue, int(str(now)+str(next_i)))

print(heappop(queue))  # K 回目に取り出す最小値


Measured memory_bytes: 10720
#include <bits/stdc++.h>
#define maxn 3001
using namespace std;
typedef long long LL;

int n,m,k;
int ar[maxn][maxn];
LL dp[maxn][maxn][4];

LL f(int r , int c , int d) {
	if(dp[r][c][d] != -1)
		return dp[r][c][d];
	dp[r][c][d] = 0;
	if(r < n) {
		dp[r][c][d] = max( dp[r][c][d] , f(r+1,c,0) );
		dp[r][c][d] = max( dp[r][c][d] , f(r+1,c,1) + ar[r+1][c] );
	}
	if(c < m) {
		dp[r][c][d] = max( dp[r][c][d] , f(r,c+1,d) );
		if(d < 3)
			dp[r][c][d] = max( dp[r][c][d] , f(r,c+1,d+1) + ar[r][c+1] );
	}
	return dp[r][c][d];
}

int main() {
	scanf("%d%d%d",&n,&m,&k);
	for( int i = 0 , x,y,z ; i < k ; i++ ) {
		scanf("%d%d%d",&x,&y,&z);
		ar[x][y] = z;
	}
	memset(dp,-1,sizeof(dp));
	LL ans = max( f(1,1,0) , f(1,1,1) + ar[1][1] );
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 320764
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int L, R, val;
    cin >> L >> R;
    if (R - L > 2020) {
        cout << 0 << endl;
    } else {
        int ans = INT_MAX;
        vector<int> arr;
        for(int i = L; i <= R; i++) {
            arr.push_back(i%2019);
        }

        for(int i = 0; i < arr.size(); i++)
            for(int j = i+1; j < arr.size(); j++)
                ans = min(ans, (arr[i]*arr[j])% 2019);
        cout << ans << endl;

    }
    return 0;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

// 約数列挙
vector<long long> calc_divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll n,m;
  cin >> n >> m;
  auto div=calc_divisor(m);
  
  ll ans=1;
  for(auto d:div){
    if(m/d>=n)ans=d;
  }
  cout << ans << endl;
  
    
  return 0;     
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  string S;
  cin >> S;
  ll w;
  cin >> w;
  for(ll i=0; w*i<=S.size()-1; i++) cout << S[w*i];
  cout << newl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
int main(){
	int n,k,x,y,ans=0;
	cin >> n;
	cin >> k;
	cin >> x;
	cin >> y;
	for(int i=1;i<=n;i++){
		if(i<=k){
			ans+=x;
		}
		else{
			ans+=y;
		}
	}
	cout << ans << endl;	
	return 0;
}

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

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  if(a[0] == a[1] &&  a[1] == a[2]){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
typedef  long long ll;
int main(void){
    ll N;
    cin >> N;
    ll A[N];
    ll x;
    rep(i,N){
        cin >> x;
        A[x-1] = i;
    }
    
    rep(i,N-1) cout << A[i]+1 << " " ; 
    cout <<A[N-1]+1 <<endl;
    
}


Measured memory_bytes: 1536
n     = gets.to_i
ary   = gets.split.map(&:to_i)
count = {}

ary.each do |i|
  if count[i] == nil
    count[i]  = 1
  else
    count[i] += 1
  end
end

ans = 0
count.each do |key, value|
  ans += key > value ? value : value - key
end
puts ans


Measured memory_bytes: 14468
#include<stdio.h>
int main()
{
    long long int i, N, s=0;
    scanf("%lld", &N);
    if(N>=0 && N<=1000000)
    {
        for(i=1; i<=N; i++)
        {
            if(i%3==0 || i%5==0) continue;

            else s+=i;
        }
    }
    printf("%lld\n", s);
    return 0;
}



Measured memory_bytes: 1732
#include<iostream>

using namespace std; 

int main() {
  int n;
  cin >> n; 
  
  int h[n+1];
  h[0] = 0;
  for(int i=1;i<n+1;i++) cin >> h[i];
  int count=0;
  for(int i=0;i<n;i++){
    if(h[i] < h[i+1]) count +=h[i+1]-h[i];
  }
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;



int main() {
   int n;
   string s,t;
   cin >> n >> s;
    t=s;
   //reverse(s.begin(),s.end());

   bool ok = true;
   if(n%2!=0) ok = false;
   rep(i,n/2){
       if(s[i]!=s[i+n/2]) ok=false;
   }
   if(ok) cout << "Yes" << endl;
   else cout << "No" << endl;

}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 20
#define DIVISOR 1000000007

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

int main(void) {
    int n, k;
    get_int2(&n, &k);
    uint64_t ans = 1;
    int i;
    for(i = 0; i < n; i++) {
        ans = (ans * k)%DIVISOR;
    }
    printf("%d\n", (int)ans);
    return 0;
}


Measured memory_bytes: 2064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cfloat>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

int main() {
    llong n;
    cin >> n;

    printf("%.*lf\n", DBL_DIG, (n + 1) / 2 / (double)n);

    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

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

ll lcm(ll a, ll b){
   return a * b / gcd(a, b);
}

int main(){

  ll n,k;cin>>n>>k;


  out(min(abs(n-(n/k)*k),abs(n-(n/k+1)*k)));



  return 0;
}


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

using namespace std;
const int maxx = 1e3 + 10;
int x[maxx];

int main()
{
    int n;
    while(cin>>n)
    {
        for(int i=0; i<n; i++)
            cin>>x[i];
        int maxn = *max_element(x,x+n);
        int minn = *min_element(x,x+n);
        int mi = 21231321;
        for(int i=minn; i<=maxn; i++)
        {
            int ans = 0;
            for(int j=0; j<n; j++)
            {
                int temp = abs(x[j] - i);
//                printf("%d ",temp);
                ans += temp*temp;
            }
//            printf("%d ",ans);
            mi = min(mi,ans);
        }
        printf("%d\n",mi);
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<map>
#define LL long long
#define mod 998244353
using namespace std;
int n,X[201],Y[201];
inline LL gcd(LL x,LL y){return (y==0)?x:gcd(y,x%y);}
struct num{
	LL x,y;
	num(LL xx=0,LL yy=1){LL d=gcd(xx,yy);x=xx/d;y=yy/d;if(y<0){x=-x;y=-y;}}
	friend bool operator<(num a,num b){return (a.x*b.y)<(a.y*b.x);}
	friend bool operator==(num a,num b){return (a.x==b.x)&&(a.y==b.y);}
};
struct line{
	num k,b;
	friend bool operator<(line x,line y){return (x.k<y.k)||(x.k==y.k&&x.b<y.b);}
};
map<line,int>mp;int cn=0,b[40127];
inline int ID(line x)
{
	if(mp.find(x)!=mp.end())return mp[x];
	return mp[x]=++cn;
}
inline int ksm(int p,int k)
{
	int res=1;
	while(k)
	{
		if(k&1)res=1ll*res*p%mod;
		p=1ll*p*p%mod;k>>=1;
	}return res;
}
int main(){
	scanf("%d",&n);int i,j,k,d,ans=ksm(2,n);num K,B;
	for(i=1;i<=n;i++)scanf("%d%d",&X[i],&Y[i]);
	for(i=1;i<=n-1;i++)
	for(j=i+1;j<=n;j++)
	if(i!=j)
	{
		int res=2;
		if(X[i]==X[j]){K=num(1,0);B=X[i];}
		else{K=num(Y[i]-Y[j],X[i]-X[j]);B=num(1ll*X[i]*Y[j]-1ll*X[j]*Y[i],X[i]-X[j]);}
		if(b[d=ID((line){K,B})])continue;b[d]=1;
		for(k=1;k<=n;k++)
		if(k!=i&&k!=j)
		{
			if(X[i]==X[j]){if(X[i]==X[k])++res;}
			else if(K.x*X[k]*B.y+K.y*B.x==B.y*K.y*Y[k])++res;
		}
		res=ksm(2,res)-res-1;res=(res%mod+mod)%mod;
		ans=((ans-res)%mod+mod)%mod;
	}ans=((ans-n)%mod+mod)%mod;
	printf("%d",((ans-1)%mod+mod)%mod);return 0;
}

Measured memory_bytes: 1920
import sys
input = sys.stdin.readline

# -*- coding: utf-8 -*-
A = int(input())

#intの場合
X,Y = map(int,input().split())

if  X % A == 0 or Y % A == 0 :
  print('OK')
elif  X // A != Y // A :
  print('OK')
else:
  print('NG')


Measured memory_bytes: 9172
/*
    アリナ・グレイはかわいい
*/

#include<bits/stdc++.h>
using namespace std;
#define itn int
#define endl "\n"

int main(void){
    string s;
    int k;
    cin >> s >> k;
    map<string,int> P;
    for(int i = 0;i < s.size();i++){
        for(int j = i;j < i+k;j++){
            string t = s.substr(i,(j-i+1));
            P[t]++;
        }
    }
    int count = 0;
    for(auto p:P){
        if(count == k-1)cout << p.first << endl;
        count++;
    }
}


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

int main(){
  int n, k, s, a;
  cin >> n >> k >> s;
  if(s != 1000000000){
    for(int i = 0; i < k; i++)
      cout << s << ' ';
    for(int i = 0; i < n - k; i++)
      cout << s + 1 << ' ';
  }
  else{
    for(int i = 0; i < k; i++)
      cout << s << ' ';
    for(int i = 0; i < n - k; i++)
      cout << 1 << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 1280
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        int n,i,j,k;
        cin>>n;
        ll a[n];
        for(i=0;i<n;i++)cin>>a[i];

        ll ans[n],mx=1;
        for(i=0;i<n;i++)ans[i]=1;

        for(j=n-2;j>=0;j--){
            if(a[j]>=a[j+1])ans[j]=ans[j+1]+1;
            mx=max(mx,ans[j]);
        }

        //for(i=0;i<n;i++)cout<<ans[i]<<" "; cout<<"\n";

        cout<<mx-1;


    }
    return 0;
}

Measured memory_bytes: 1792