akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(container) container.begin(), container.end()
#define RevRange(container) container.rbegin(), container.rend()
#define Cin(T, x) T x; cin >> x;
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i];
#define Cout(val) cout << (val) << "\n";
using namespace std;
using ll = long long;
//                1  2  3  4  5  6  7  8  9
int na[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

int gcd(int a, int b){
	return (a % b == 0) ? b : gcd(b, a % b);
}

vector<int> g(vector<vector<int>> &arrs){
    vector<int> ret;
    for(auto &arr : arrs){
        if(ret.size() < arr.size()) ret = arr;
        else if(ret.size() == arr.size() && ret < arr) ret = arr;
    }
    return ret;
}

vector<int> f(int n, vector<int> &a){
    if(n < 0) return {-1};
    if(n == 0) return {};
    
    vector<vector<int>> ret;
    for(auto d : a){
        auto tmp = f(n-na[d], a);
        if(tmp.size() == 1 && tmp[0] == -1) continue;
        tmp.push_back(d);
        ret.push_back(tmp);
    }
    if(ret.empty()) return {-1};
    return g(ret);
}

int main(void){
    Cin(int, n);
    Cin(int, m);
    Cins(int, m, a);
    sort(RevRange(a));
    
    int imin = 0, namin = 100;
    For(i, m){
        if(na[a[i]] < namin) imin = a[i], namin = na[a[i]];
    }
    int k = n/namin;

    vector<vector<int>> ans;
    for(int i = max(0, k-6); i <= k; i ++){
        auto tmp = f(n - namin * i, a);
        if(tmp.size() == 1 && tmp[0] == -1) continue;
        For(j, i) tmp.push_back(imin);
        sort(RevRange(tmp));
        ans.push_back(tmp);
    }
    
    auto po = g(ans);
    for(auto d : po) cout << d;
    cout << "\n";
}



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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (auto& e : a) cin >> e;

  for (int i = k; i < n; i++) cout << (a[i - k] < a[i] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 1000000007
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k % 2)
    cout << -1 * (a - b) << endl;
  else
    cout << (a - b) << endl;
}


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

int main()
{
    int a, b, c = -101;
    cin >> a >> b;
    c = max(a + b, c);
    c = max(a - b, c);
    c = max(a * b, c);
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
string s;
char ans[200007][7];
char anss[200007][7];
int main(){
    cin>>s;
    int n=s.size();
    int sta=0;
    int cnt=1;
    int flag=0;
    ans[cnt][0]=s[0];
    for(int i=1;i<n;++i){
        if(s[sta]==s[i]&&flag==0){
            if(i+1<n){
                cnt++;
                flag=1;
                i++;
                ans[cnt][0]=s[i-1];
                ans[cnt][1]=s[i];
            }
            else if(i==1)
                cnt--;
        }
        else if(s[sta]!=s[i]&&flag==0){
            cnt++;
            sta=i;
            ans[cnt][0]=s[i];
        }
        else if(flag==1){
            cnt++;
            sta=i;
            flag=0;
            ans[cnt][0]=s[i];
        }
    }
    cout<<cnt;
    return 0;
}


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

int main(){
    int n,k,l=0,i=0;
    int cnt = 1,cntnum=0;
    cin >> n >> k;
    int a[n];
    rep(i,n){
        cin >> l;
        a[i]=l;
    }
    if(n==k){
        cout << 1 << endl;
        return 0;
    }
    cnt += (n-k)/(k-1);
    if((n-k)%(k-1)!=0){
        cnt++;
    }
    cout << cnt << endl;
    
}

Measured memory_bytes: 3948
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

x = int(input())

ans = x // 500 * 1000
y = x % 500
ans += y // 5 * 5

print(ans)

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

int main(){
    int taro=0,hanako=0;
    int n;  cin>>n;
    string tc,hc;

    for(int i=0;i<n;i++){
        int longSize;
        cin>>tc>>hc;

        if(tc.size()>hc.size())longSize = tc.size();
        else longSize = hc.size();

        if(tc==hc){
            taro++;
            hanako++;
        }

        for(int j=0;j<longSize;j++){
            if(tc[j]-hc[j]>0){
                taro+=3;
                break;
            }else if(tc[j]-hc[j]<0){
                hanako+=3;
                break;
            }
        }
    }

    cout<<taro<<" "<<hanako<<endl;

    return 0;
}



Measured memory_bytes: 3148
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MAXC 10
#define MAXN
int H,W,N;
long long cont[MAXC+5],x,y;
map<int, map<int,int> >C;
int main()
{
    scanf("%d%d%d",&H,&W,&N);
    cont[0]=(long long)(H-2)*(W-2);
    for(int i=1;i<=N;i++)
    {
        scanf("%d%d",&x,&y);
        for(int k1=0;k1<=2;k1++)
            for(int k2=0;k2<=2;k2++)
            if(x+k1>=3&&y+k2>=3&&x+k1<=H&&y+k2<=W)
            {
                //printf("::%lld %lld\n",x+k1,y+k2);
                C[x+k1][y+k2]++;
                int A=C[x+k1][y+k2];
                cont[A-1]--;//
                cont[A]++;
            }
    }
    for(int i=0;i<=9;i++)
        printf("%lld\n",cont[i]);
}


Measured memory_bytes: 70528
package main

import "fmt"

func main() {
	var k, a, b int

	fmt.Scan(&k)
	fmt.Scan(&a)
	fmt.Scan(&b)

	if a%k == 0 || a/k < b/k {
		fmt.Println("OK")
	} else {
		fmt.Println("NG")
	}
}


Measured memory_bytes: 1756
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.stdio;
import std.string;
import std.traits;

struct Input
{
	int a, b, c;
}

void parseInput(T)(out Input input, T file)
{
	with (file) with (input)
	{
		auto abc = readln().strip().split().map!(to!int).array();
		a = abc[0].to!int;
		b = abc[1].to!int;
		c = abc[2].to!int;
	}
}

auto main2(Input* input)
{
	with (input)
	{
        if (a == b && b == c)
            return "No";
        if (a == b)
            return "Yes";
        if (b == c)
            return "Yes";
        if (c == a)
            return "Yes";
        return "No";
	}
}

alias retType = ReturnType!main2;
static if (!is(retType == void))
{
	unittest { writeln("begin unittest"); }
	auto _placeholder_ = ReturnType!main2.init;

	unittest // example1
	{
		string example =
`5 7 5`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "Yes");
	}

	unittest // example2
	{
		string example =
`4 4 4`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "No");
	}

	unittest // example3
	{
		string example =
`4 9 6`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "No");
	}

	unittest // example4
	{
		string example =
`3 3 4`;
		if (example.empty) return;
		Input input = void;
		parseExample(input, example);
		auto result = main2(&input);
		printResult(result);
		assert(result == "Yes");
	}

	unittest { writeln("end unittest"); }

	void parseExample(out Input input, string example)
	{
		struct Adapter
		{
			string[] _lines;
			this(string input) { _lines = input.splitLines(); }
			string readln() { auto line = _lines[0]; _lines = _lines[1..$]; return line; }
		}
		parseInput(input, Adapter(example));
	}
}

void printResult(T)(T result)
{
	static if (isFloatingPoint!T) writefln("%f", result);
	else writeln(result);
}

void main()
{
	Input input = void;
	parseInput(input, stdin);
	alias retType = ReturnType!main2;
	static if (is(retType == void))
		main2(&input);
	else
	{
		auto result = main2(&input);
		printResult(result);
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, pi> pii;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll n, m, q, ans;
vector<pii> check;
vector<ll> v;

void ok(vector<ll> vv) {
	ll res = 0;
	for (auto it:check) {
		if (vv[it.f.s] - vv[it.f.f] == it.s.f) res += it.s.s;
	}
	ans = max(ans, res);
}

void gen(ll idx) {
	if (idx == n) {ok(v); return;}
	ll lim = 1;
	if (!v.empty()) lim = max(lim, v.back());
	FOR(i, lim, m) {
		v.pb(i);
		gen(idx + 1);
		v.pop_back();
	}
}

int main() {
	fastio; cin >> n >> m >> q;
	FOR(i, 1, q) {
		ll a, b, c, d; cin >> a >> b >> c >> d;
		a--; b--;
		check.pb(pii(pi(a, b), pi(c, d)));
	}
	gen(0);
	cout << ans;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

ll N, W, w, a, b;

int main()
{
    cin >> N >> W;
    vector<vector<ll>> v(4);
    for (int i = 0; i < 4; i++)
        v[i].push_back(0);
    cin >> w >> a;
    v[0].push_back(a);
    for (int i = 1; i < N; i++)
    {
        cin >> a >> b;
        v[a - w].push_back(b);
    }
    for (int i = 0; i < 4; i++)
    {
        sort(v[i].begin() + 1, v[i].end(), greater<int>());
        for (int j = 1; j < v[i].size(); j++)
            v[i][j] += v[i][j - 1];
    }
    ll ans = 0, w1 = v[0].size(), w2 = v[1].size(), w3 = v[2].size(), w4 = v[3].size();
    for (int i = 0; i < w1; i++)
    {
        for (int j = 0; j < w2; j++)
        {
            for (int k = 0; k < w3; k++)
            {
                ll weight = w * i + (w + 1) * j + (w + 2) * k;
                if (weight > W)
                    continue;
                ll l = min(w4 - 1, (W - weight) / (w + 3));
                ans = max(v[0][i] + v[1][j] + v[2][k] + v[3][l], ans);
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
    int n;
    scanf(" %d",&n);
    pair<double,double> coor[n];
    for(int i = 0; i < n;++i) cin >> coor[i].first >> coor[i].second;
    sort(coor,coor +n);
    double add = 0.0;
    do{
        for(int i = 0; i < n-1;++i)
            add += sqrt(pow((coor[i].first - coor[i+1].first),2) + pow((coor[i].second - coor[i+1].second),2));
    //cout << add << endl;
    }while(next_permutation(coor,coor+n));
    double fa = 1;
    for(int i = n;i > 1;--i) fa *= (double)i;
    //cout << fa << endl;
    printf("%.10f\n",add/fa);
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
if N % 2 == 0:
    num = 0
    mid = N // 2
    for i in range(M):
        print(mid - i, mid + 1 + i)
        num += 1
        if num == M:
            break
        print(1 + i, N - 1 - i)
        num += 1
        if num == M:
            break
else:
    mid = (N + 1) // 2
    for i in range(M):
        print(mid - i, mid + 1 + i)

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

string h = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ',-.?";
char d[36] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
char e[36][12] = {"100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000","101","000000","000011","10010001","010001","000001"};

char conv(string s){
    int ans = 0;
    string::iterator it = s.begin();
    for(int n = 0; n < 5; n++){
        if( it == s.end() ) continue;
        ans *= 2;
        ans += *it - '0';
        it++;
    }
    return d[ans];

}

int main(){
    string s;
    while( getline(cin, s) ){
        string c;
        c = string("");
        for(int i = 0; i < s.size(); i++){
            //cout << e[h.find(s[i])] << endl;
            c += e[h.find(s[i])];
        }
        c += string(4-(c.size()+4)%5, '0');
        for(int i = 0; i < c.size()/5; i++){
            cout << conv( c.substr(i*5, 5) );
        }
        cout << endl;
    }
    return 0;
}

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

int main() {
    long long n;
    cin >> n;
    vector<long long> r(n);
    for (long long i=0; i<n; i++) cin >> r[i];

    long long minval = r[0];
    long long ans = -10000000000;
    for (long long i=1; i<n; i++) {
        ans = max(ans, r[i]-minval); // 解答となりうる値（最大値）
        minval = min(minval, r[i]); // 最小値を保持
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4404
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define i_inf int(1e9)
#define i_half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int mod = 1000000007;

string s;

void solve() {
    ll ans = i_inf;
    each(c, s) {
        ll temp = 0;
        string scopy(s);
        bool b = false;
        while (!b && !scopy.empty()) {
            rep(j, scopy.length()) {
                if (scopy[j] != c) break;
                if (j == scopy.length() - 1) {
                    b = true;
                }
            }
            if (!b) temp++;
            repone(i, scopy.length() - 1) {
                if (scopy[i] == c) scopy[i - 1] = c;
            }
            scopy.erase(scopy.end() - 1);
        }
        ans = min(ans, temp);
    }
    cout << ans << endl;
}

int main() {
    cin >> s;
    solve();
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Queue;
import java.util.ArrayDeque;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s;
        Queue<Character> q = new ArrayDeque<>();

        while (true) {
            s = sc.next();
            if (s.equals("-"))
                break;
            
            for (int i = 0; i < s.length(); i++) {
                q.add(s.charAt(i));
            }

            int m;
            m = sc.nextInt();

            int[] h = new int[m];
            int sum = 0;

            for (int i = 0; i < m; i++) {
                h[i] = sc.nextInt();
                sum += h[i];
            }

            for (int i = 0; i < sum; i++) {
                q.add(q.poll());
            }
            for (int i = 0; i < s.length(); i++) {
                System.out.print(q.poll());
            }
            System.out.println();
        }

        sc.close();
    }
}


Measured memory_bytes: 26496
#include "stdio.h"
#define uint unsigned int
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}

int b,n,S,i;
int w[102]={},a[102]={};
int main(){
	while(n=in(),S=in(),(n||S)){
		for(i = 0 ; i <= 100 ; i++) w[i]=a[i]=0;
		int ans = 0;
		for(i = 0 ; i < n ; i++){ w[b=in()]++; a[b]++; }
		for(i = 99 ; i >= 0 ; i--) w[i] += w[i+1];
		for(i = 0 ; i <= 100 ; i++) if(2*i>S) ans+=a[i]*(a[i]-1)/2;
		for(i = 1 ; i <= 100 ; i++) ans+=a[i]*w[i>S-i?i+1:S-i+1];
		printf("%d%c",ans,10);
	}
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
    int n, k, count = 0;
    scanf("%d %d", &n, &k);
    int h[n];
    for (int i = 0; i < n; i++)
    {
        h[i] = 0;
    }
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &h[i]);
        if (k <= h[i])
        {
            count++;
        }
    }
    printf("%d", count);
    return 0;
}

Measured memory_bytes: 512
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
a,b,c = LI()
if b-a == c-b:
    print("YES")
else:
    print("NO")
"""
#B
o = S()
e = S()
for i in range(len(e)):
    o.insert(2*i+1,e[i])
for i in o:
    print(i,end = "")
print()
#C
"""
n = I()
s = SR(n)
for i in range(n):
    for j in range(len(s[i])):
        while s[i][j] in s[i][:j]:
            s[i][j] = "0"+s[i][j]
ans = set(s[0])
for i in range(1,n):
    ans &= set(s[i])
ans = sorted(list(ans))
if len(ans) == 0:print()
else:
    for i in range(len(ans)):
        ans[i] = ans[i][-1]
    ans.sort()
    for i in range(len(ans)-1):
        print(ans[i],end = "")
    print(ans[-1])
"""

#D
"""
n,m = LI()
ln = [n-1]
lm = [m-1]
a = n-1
b = m-1
while a > 2:
    a -= 2
    ln.append(ln[-1]+a)
while b > 2:
    b -= 2
    lm.append(lm[-1]+b)
la = len(ln)
lb = len(lm)
for i in range(la):
    if i or a == 2:
        ln.append(ln[la-i-1])
for i in range(lb):
    if i or b == 2:
        lm.append(lm[lb-i-1])
x,y = LIR(2)
lx = 0
ly = 0
for i in range(n-1):
    lx += ln[i]*(x[i+1]-x[i])%mod
    lx %= mod
for i in range(m-1):
    ly += lm[i]*(y[i+1]-y[i])%mod
    ly %= mod
ans = lx*ly%mod
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
N, Y = map(int, input().split())

resx, resy, resz = (-1, -1, -1)
for x in range(N+1):
    for y in range(N-x+1):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break

print(resx, resy, resz)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    int ans=0;
    cin>>N;
    rep(i,N){
        ans+=i+1;
    }
    cout << ans << endl;


}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{int a,b,c,d;
 scanf("%d%d%d%d",&a,&b,&c,&d);
 int sum=0;
 if(a>=b){sum+=b;}else{sum+=a;}
 if(c>=d){sum+=d;}else{sum+=c;}
 printf("%d",sum);
 return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

int main() {
  kyun;
  int n;
  string s;
  cin >> n >> s;
  if(n >= 3200) cout << s;
  else cout << "red";
  hinata;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int ans = Math.max(a+b,a-b);
		ans = Math.max(ans, a*b);
		System.out.println(ans);
	
		
	}

}


Measured memory_bytes: 23764
import java.util.Arrays;
import java.util.Scanner;


public class Main {
    public static void main(String[] args) throws Exception {
        //スキャン
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int N = sc.nextInt();
        int[] A = new int[N+1];
        A[0] =0;
        int sum = 0;
        int bigMan =0;

        for(int i=1; i <= N ; i++){
            int hoge = sc.nextInt();
            A[i] = hoge;
            sum += hoge;
            bigMan = Math.max(bigMan, A[i]-A[i-1]);
        }
        bigMan = Math.max(bigMan, K-A[N]+A[1]);

        System.out.println(K-bigMan);
    }
}

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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

ll a, b, c;

ll get(ll p, ll q) {
  ll cur = p * q;
  double sq = sqrt(cur * 1.0);
  for(long double p = sq - 10.0; p < sq + 10.0; p++) {
    if(p * p <= cur) sq = p;
  }
  double L = 2.0 * sq;
  cur = (long long)L;
  return cur;
}

int main() {
  cin >> a >> b >> c;
  if(a + b + get(a, b) < c) {
    print("Yes");
  }
  else {
    print("No");
  }
}

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

int main(){
    int n;
    cin>>n;
    vector<int> data(n);
    for(int i=0; i<n; i++){
        cin>>data[i];
    }
    int count=0;

    for(int i=0; i<=n-2; i++){ 
        int minj=i;
        for(int j=i+1; j<=n-1; j++){
            if(data[j]<data[minj]){
                minj=j;
            }
        }
        if(i!=minj){
            swap(data[i],data[minj]);
            count++;
        }
    }

    for(int i=0; i<n-1; i++){
        cout<<data[i]<<" ";
    }

    cout<<data[n-1]<<endl<<count<<endl;
}


Measured memory_bytes: 3116
//BISMILLAHIR RAHMANIR RAHIM
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <list>
#define cos(a) cos(a*pi/180)
#define sin(a) sin(a*pi/180)
#define tan(a) tan(a*pi/180)
#define cosi(a) acos(a)/(pi/180)
#define sini(a) asin(a)/(pi/180)
#define tani(a) atan(a)/(pi/180)
#define mem(a, b) (memset(a, b, sizeof(a)))
#define read (freopen("input.txt", "r", stdin))
#define write (freopen("output.txt", "w", stdout))
#define fastIO (ios::sync_with_stdio(0), cin.tie(0), cout.tie(0));
#define dis(x1, y1, x2, y2) ((x1-x2) * (x1-x2)) + ((y1-y2) * (y1-y2))
#define debug (printf("PINK FLOYD:)\n"))
#define iosflags (cout<<setiosflags(ios::fixed)<<setprecision(8))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define pi 3.1415926535897932384
#define INF 2147483647
#define EPS 1e-8
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

const int inf = 1<<28;
int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
int dx[] = { -1, 1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };
int fx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
int fy[] = { -1,  1, -2,  2, -2,  2, -1,  1 };

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

int arr[2*MAX];

int main()
{
	fastIO;
	priority_queue<int> pq;
	int n, val;

	cin>>n;

	for(int i = 0; i < n; i++){
        cin>>arr[i];
        pq.push(arr[i]);
	}

	for(int i = 0; i < n; i++){
        if(pq.top() == arr[i]){
            pq.pop();
            cout<<pq.top()<<endl;
            pq.push(arr[i]);
        }
        else{
            cout<<pq.top()<<endl;
        }
	}

    return 0;
}


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main()
{
	int K, S;
	int i, j, k;
	long long ans = 0;
	cin >> K >> S;

	for (int i = 0; i <= K; i++)
	{
		for (int j = 0; j <= K; j++)
		{
			int k = S - i - j;
			if (0 <= k && k <= K)
				ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	if (S[S.size() - 1] == 's') {
		cout << (S + "es") << "\n";
	} else {
		cout << (S + "s") << "\n";
	}
	return 0;
}


Measured memory_bytes: 3616
def main():
    n, m = [int(x) for x in input().split()]
    ab = [[int(x) for x in input().split()] for _ in range(m)]

    ab.sort(key=lambda x: x[1]) # sort by b
    cut = []
    for a, b in ab:
        c = False
        for x, y in cut:
            if a <= x:
                c = True
                break
        if not c:
            cut.append((b-1, b))

    print(len(cut))
        
if __name__ == '__main__':
    main()


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main()
{
    int n;
    cin>>n;
    string lows,mids,highs;
    int lowi=0,midi,highi=n-1;
    cout<<0<<endl;;
    cin>>lows;
    if(lows=="Vacant")
    {
        return 0; 
    }
    cout<<n-1<<endl;;
    cin>>highs;
    if(highs=="Vacant")
    {
        return 0;
    }
    while (mids!="Vacant")
    {
        midi=(lowi+highi)/2;
        cout<<midi<<endl;;
        cin>>mids;
        if(((midi-lowi)%2==0 && mids!=lows) || ((midi-lowi)%2==1 && mids==lows))
        {
            highi=midi;
            highs=mids;
        }
        else
        {
            lowi=midi;
            lows=mids;
        }        
    }
    

    return 0;
}

Measured memory_bytes: 852
n = int(input())
a = list(map(int, input().split()))
even = 0
not_even = 0
for v in a:
  if v%2==0: even += 1
  else: not_even += 1
  if not_even == 2:
    even += 1
    not_even = 0
print("YES" if not_even == 0 else "NO")

Measured memory_bytes: 14108
n = int(input())
sche = []
for i in range(n):
    a,b = map(int,input().split())
    sche.append((b,a))
sche.sort(reverse = True)
now = 1e18
for dead,ti in sche:
    if(dead < now):
        now = dead
    now -= ti

if now < 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 29456
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var N int
	fmt.Scan(&N)
	m := make(map[string]bool)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < N; i++ {
		sc.Scan()
		m[sc.Text()] = true
	}
	fmt.Println(len(m))
}


Measured memory_bytes: 14820
mod = 1000000007
h, w, k = gets.split.map(&:to_i)
dp = Array.new(h + 1) { Array.new(w + 1, 0) }
dp[0][0] = 1
h.times do |hi|
  (0...(1 << (w - 1))).each do |bit|
    ng = false
    (w - 1).times do |wi|
      if bit[wi] == 1 && bit[wi + 1] == 1
        ng = true
      end
    end
    next if ng
    w.times do |wi|
      target = wi
      if wi == 0
        target = wi + 1 if bit[wi] == 1
      elsif wi == w - 1
        target = wi - 1 if bit[wi - 1] == 1
      else
        if bit[wi - 1] == 1
          target = wi - 1
        elsif bit[wi] == 1
          target = wi + 1
        end
      end
      dp[hi + 1][target] += dp[hi][wi]
      dp[hi + 1][target] %= mod
    end
  end
end

p dp[h][k - 1]


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main(){
    int n;
    scanf("%d", &n);
    int a[n];
    lint cnt[MAX];
    memset(cnt, 0LL, sizeof(cnt));
    rep(i, n){
        scanf("%d", &a[i]);
        ++cnt[a[i]];
    }
    lint ans = 0;
    auto f = [](lint x){return x*(x-1)/2;};
    rep(i, MAX) ans += f(cnt[i]);
    rep(i, n){
        printf("%lld\n", ans - f(cnt[a[i]]) + f(cnt[a[i]]-1));
    }
}

Measured memory_bytes: 4864
#include<stdio.h>

int main() {
	int i, j, ans;
	for (i = 1; i < 10; i++) {
		for (j = 1; j < 10; j++) {
			ans = i*j;
			printf("%dx%d=%d\n",i,j,ans);
		}
	}
	return 0;
}

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

int main(){
  string a, b;
  cin >> a >> b;
  
  a += b;
  reverse(a.begin(), a.end());
  int now = 0;
  for(int i = 0; i < (int)a.size(); i++){
    int k = a.at(i) - '0';
    now += k*pow(10, i);
  }
  
  bool ok = false;
  for(int i = 1; i * i <= now; i++){
    if(i * i == now) ok = true;
  }
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(X: int, t: int):
    ret = max(0, X - t)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    t = int(next(tokens))  # type: int
    solve(X, t)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] b = new int[n - 1];
        for (int i = 0; i < b.length; i++) {
            b[i] = sc.nextInt();
        }
        int[] a = new int[n];
        a[0] = b[0];
        a[a.length - 1] = b[b.length - 1];
        for (int i = 1; i < a.length - 1; i++) {
            a[i] = Math.min(b[i - 1], b[i]);
        }
        int result = 0;
        for (int i : a) {
            result += i;
        }
        System.out.println(result);
        sc.close();
    }
}

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

int main(){
	int N,K,C; string S;
	cin>>N>>K>>C>>S;

	vector<int> L,R;
	int c;

	c = 0;
	rep(i, N){
		if(c-- > 0) continue;
		c = 0;
		if(S[i] == 'o'){ L.push_back(i); c = C; }
	}

	c = 0;
	for(int i=N-1; i>=0; --i){
		if(c-- > 0) continue;
		c = 0;
		if(S[i] == 'o'){ R.push_back(i); c = C; }
	}

	reverse(R.begin(), R.end());

	if(L.size() > K) return 0;

	rep(i, min(L.size(), R.size())) if(L[i] == R[i]) cout<<L[i]+1<<endl;
}

Measured memory_bytes: 3448
#include <stdio.h>

int main(){

    int a,b;
    int total;

    scanf("%d %d",&a,&b);
    if(a==b){
        total=a*2;
    } else if(a>=b) {
        total=a+a-1;
    } else {
        total=b+b-1;
    }

    printf("%d",total);   
}

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

using namespace std;

const int oo { 1000000010 };

int solve(const vector<int> xs)
{
    vector<int> order(5);
    iota(order.begin(), order.end(), 0);

    int ans = oo;

    do {
        int t = 0;

        for (int i = 0; i < 4; ++i)
            t += 10 * ((xs[order[i]] + 9)/10);

        t += xs[order.back()];

        ans = min(ans, t);
    } while (next_permutation(order.begin(), order.end()));

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    vector<int> xs(5);

    for (int i = 0; i < 5; ++i)
        cin >> xs[i];

    auto ans = solve(xs);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

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

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
int par[114514], rrank[114514];//親、木の深さ
void init(int n) {
	rep(i, n) {
		par[i] = i;
		rrank[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rrank[x] < rrank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rrank[x] == rrank[y])rrank[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int n;
int a[114514];
int f[114514];
signed main() {
	COMinit();
	cin >> n;
	rep(i, n + 1)cin >> a[i];
	int memo1 = -1, memo2 = -1, p = 0;
	rep(i, n + 1)f[a[i]]++;
	rep(i, n + 3) {
		if (f[i] == 2)p = i;
	}
	rep(i, n + 1) {
		if (a[i] == p && memo1 == -1 && memo2 == -1)memo1 = i;
		else if (a[i] == p)memo2 = i;
	}
	memo2 = n - memo2;
	rep(i, n + 1)cout << (COMB(n + 1, i + 1) - COMB(memo1 + memo2, i) + mod) % mod << endl;
	ggr
}


Measured memory_bytes: 12032
#pragma GCC optimize(2)

#include "bits/stdc++.h"

using namespace std;

//#define _DEBUG
#define all(a) begin(a), end(a)
#define MOD 1000000007
#define PII pair<int, int>
#define complete_unique(a) a.erase(unique(begin(a), end(a)), end(a))
#define mst(x, a) memset(x, a, sizeof(x))
typedef vector<int> VI;
typedef long long ll;

ll quick_pow(ll a, ll b) {
    long long res = 1;
    while (b) {
        if (b & 1)
            res = a * res;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll gcd(ll a, ll b) {
    a = abs(a), b = abs(b);
    while (b != 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

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

bool is_prime(int n) {
    if (n == 0) return false;
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    int j = sqrt(n);
    for (int i = 2; i <= j; ++i) {
        if (n % i == 0) return false;
    }
    return true;
}

ll reverse_num(ll n) {
    ll x = 0, t = n;
    while (t != 0) {
        x = x * 10 + t % 10;
        t /= 10;
    }
    return x;
}

void solve() {
    int x;
    cin >> x;
    ll res = 0;
    res += (x / 500) * 1000;
    x %= 500;
    res += (x / 5) * 5;
    cout << res;
}

int main() {
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
    // 加速输入和输出
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3704
a = input()
b = input()
c = input()
abc = [a, b, c]

current_turn = 0
while True:
    if len(abc[current_turn]) == 0:
        break
    next_turn = ord(abc[current_turn][0]) - ord('a')
    abc[current_turn] = abc[current_turn][1:]
    current_turn = next_turn
    # print(abc[0], abc[1], abc[2])

print(chr(current_turn + ord('A')))


Measured memory_bytes: 3060
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
const int maxN = (int)1e3 + 10;
int lp[maxN];
const int mod = (int)1e9 + 7;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    int ans = 1;
    for (int i = 2; i <= n; i++) {
        if (lp[i] == 0) {
            lp[i] = i;
            for (int j = 2 * i; j <= n; j += i) lp[j] = i;
            int g = i;
            int c = 0;
            while (g <= n) {
                c += n / g;
                g *= i;
            }
            ans = (1LL * ans * (c + 1)) % mod;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
r, c = map(int, input().split())

A = []

for i in range(r) :
    A.append([int(a) for a in input().split()])
    A[i].append(sum(A[i]))

S = []

for i in range(c + 1) :
    s = 0
    
    for j in range(r) :
        s += A[j][i]
        
    S.append(s)
        
A.append(S)

for i in range(r + 1) :
    for j in range(c + 1) :
        if j == c :
            print(A[i][j])
        else :
            print(A[i][j], end = " ")


Measured memory_bytes: 6248
import math
A, B, H, M = map(int, input().split())
angle1 = (H + M / 60) * 30
angle2 = M * 6
angle = abs(angle1 - angle2)
if angle > 180:
    angle = 360 - angle
ans = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(angle))
print(math.sqrt(ans))

Measured memory_bytes: 62632
#include <iostream>
using namespace std;
int main(void){
    int A, B, C;
    cin >> A >> B >> C;
    if(A == B) {
        cout << C << "\n";
        return 0;
    }
    else if(A == C) {
        cout << B << "\n";
        return 0;
    }
    else {
        cout << A << "\n";
        return 0;
    }
}

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

#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define endl "\n" 
#define all(c) c.begin(),c.end()
#define present(c,element) (c.find(element)!=c.end())
#define cpresent(c,element) (find(c,element)!=c.end())
#define forr(i,a,b) for(int i=a;i<int(b);i++)
#define tr(i,a) for(auto i:a)
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
const double PI=acos(-1);
const ll mod=1e9+7;


int32_t main()
{
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

int test=1;
//cin>>test;
while(test--)
{
	int n,k;
	cin>>n>>k;
	vi h(n);
	for (int i = 0; i < n; ++i)
	{
		/* code */
		cin>>h[i];
	}
	int dp[n];
	dp[0]=0;
	for (int i = 1; i < n; ++i)
	{
		/* code */
		int res=INT_MAX;
		for (int j = 0; j < min(k,i); ++j)
		{
			/* code */
			res=min(res,dp[i-j-1]+abs(h[i]-h[i-j-1]));
			//cout<<res<<" ";
		}
		dp[i]=res;//cout<<endl;
		
	}
	cout<<dp[n-1]<<endl;



}
return 0;
}










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

int main() {
    static const double PI = 3.14159265358979323846;
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    auto rad = PI * 2 * (h / 12.0 + (m / 60.0) / 12.0 - m / 60.0);
    auto rsq = (double) (a * a + b * b) - (double) (2 * a * b) * cos(rad);
    printf("%20.20f\n", sqrt(rsq));
}

Measured memory_bytes: 4148
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
   ll ans = 0;
   int n, k;
   cin >> n >> k;
   int x[110];
   rep(i,n) cin >> x[i];

   rep(i, n) {
       ans += min(2*x[i], 2*(k-x[i]));
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def coprime(a, b) : 
    return (gcd(a, b) == 1) 

def make_div(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return sorted(divisors)

def count(arr):
    ans = set()
    for i in arr:
        if i == 1:
            ans.add(i)
            continue
        else:
            flag = 1
            for j in ans:
                if j != 1:
                    if (i % j) == 0:
                        flag = 0
                        break
            if flag == 1:
                ans.add(i)
    return(len(ans))

A,B = list(map(int,input().split()))
gcd_ab = gcd(A,B)
arr = make_div(gcd_ab)
n = len(arr)
print(count(arr))

Measured memory_bytes: 39408
#include<stdio.h>
#define MAX 200000
#define SNT 2000000000
typedef long long int llong;

int L[MAX / 2 + 2], R[MAX / 2 + 2];

llong merge(int*, int, int, int, int);
llong mergeSort(int*, int, int, int);

llong merge(int A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1, n2;
  llong count = 0;
  n1 = mid - left;
  n2 = right - mid;
  for( i = 0 ; i < n1 ; i++){
    L[i] = A[left + i];
  }
  for( i = 0 ; i < n2 ; i++){
    R[i] = A[mid + i];
  }
  L[n1] = R[n2] = SNT;
  i = j = 0;
  for( k = left ; k < right ; k++){
    if( L[i] <= R[j] ){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
      count += n1 - i;
    }
  }
  return count;
}

llong mergeSort(int A[], int n, int left, int right){
  int mid;
  llong v1, v2, v3;
  if( left + 1 < right){
    mid = (left + right) / 2;
    v1 = mergeSort(A, n, left, mid);
    v2 = mergeSort(A, n, mid, right);
    v3 = merge(A, n, left, mid, right);
    return v1 + v2 + v3;
  }
  else return 0;
}

int main(){
  int A[MAX], n, i;
  llong ans;

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

  ans = mergeSort(A, n, 0, n);
  printf("%lld\n", ans);

  return 0;
}



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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<int> T(N + 1, 0), V(N + 1, 0);
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &T[i]);
    T[i] *= 2;
    T[i] += T[i - 1];
  }

  for (int i = 1; i <= N; ++i) {
    scanf("%d", &V[i]);
  }

  vector<double> upperV(T[N] + 5, 0);
  double limv = V[1];
  for (int t = 1, vpos = 0; t <= T[N] ; ++t) {
    if (t > T[vpos]) { limv = V[++vpos]; }
    upperV[t] = min(upperV[t - 1] + 0.5, limv);
  }

  upperV[T[N]] = 0;
  limv = V[N];
  for (int t = T[N] - 1, vpos = N + 1; t >= 0; --t) {
    if (t < T[vpos - 1]) { limv = V[--vpos]; }
    upperV[t] = min(upperV[t], min(upperV[t + 1] + 0.5, limv));
  }

  double ans = 0;
  for (int t = 1; t <= T[N]; ++t) {
    ans += (upperV[t - 1] + upperV[t]);
  }
  ans *= 0.25;
  printf("%f\n", ans);
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define START clock_t start=clock()
#define TIME printf("\n%.3f秒\n",(double)(clock()-start)/CLOCKS_PER_SEC)

ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)

#define MOD (7*(1<<26)+1)
#define SIZE (1<<18)

//非再帰fft
void fft(ll*f,int n,ll g){
	ll yy[SIZE];
	ll*x=f,*y=yy,*temp;
	for(int t=1;n>>t;t++){
		ll s=1;
		ll gg=pom(g,n>>t,MOD);
		rep(k,0,1<<(t-1)){
			rep(j,0,n>>t){
				y[(j<<t)+k           ]= (x[(j<<(t-1))+k]+s*x[(j<<(t-1))+n/2+k])%MOD;
				y[(j<<t)+k+(1<<(t-1))]=((x[(j<<(t-1))+k]-s*x[(j<<(t-1))+n/2+k])%MOD+MOD)%MOD;
			}
			s=s*gg%MOD;
		}
		temp=x;x=y;y=temp;
	}
	if(x!=f)rep(i,0,n)f[i]=x[i];
}




ll check[SIZE];
ll dp[SIZE];
ll n;

int main(){
//	START;
	scanf("%lld",&n);
	
	ll r=1;
	while(!check[r]){
		check[r]=1;
		r=r*10%n;
	}
	
	if(check[0]){
		puts("1");
		return 0;
	}
	
	//1個でできるものがcheck
	//答えは45以下なのでfftすれば解ける(TLE)
	ll g=pom(3,(MOD-1)/SIZE,MOD);
	ll ig=invp(g,MOD);
	rep(i,0,SIZE)dp[i]=check[i];
	fft(check,SIZE,g);

	for(ll cnt=2;cnt<=18;cnt++){
		//fft
		fft(dp,SIZE,g);
		//掛け算
		rep(i,0,SIZE)dp[i]=dp[i]*check[i]%MOD;
		//ifft
		fft(dp,SIZE,ig);
		//次数下げ
		rep(i,0,n)dp[i]=!!((dp[i]+dp[i+n])%MOD),dp[i+n]=0;
		//チェック
		if(dp[0]){
			printf("%lld\n",cnt);
//			TIME;
			return 0;
		}
	}
	
	ll ans=0;
	while(n){
		ans+=n%10;
		n/=10;
	}
	printf("%lld\n",ans);
	return 0;
//	TIME;
}

Measured memory_bytes: 6272
////////////////////////
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
ll gcd(ll a, ll b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * b / my::gcd(a, b); }
}  // namespace my
////////////////////////

int main() {
  int n;
  cin >> n;
  vector<ll> a;
  for (int i = 0; i <= n; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  vector<ll> node(n + 1);
  ll tmp = 0;
  for (int i = n; i >= 0; i--) {
    tmp += a.at(i);
    node.at(i) = tmp;
  }
  // for (auto &nodei : node) {
  //   cout << nodei << endl;
  // }
  // cout << endl;

  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    if (i == 0) {
      node.at(0) = min(node.at(0) - a.at(0), 1 - a.at(0));
      if (node.at(0) < 0) {
        ans = -1;
        break;
      }
      ans += node.at(0) + a.at(i);
      continue;
    }

    // cout << node.at(i - 1) << " " << node.at(i) << endl;

    node.at(i) = min(node.at(i) - a.at(i), node.at(i - 1) * 2 - a.at(i));
    if (node.at(i) < 0) {
      ans = -1;
      break;
    }
    // cout << node.at(i) << " ";
    // cout << ans << endl;
    ans += node.at(i) + a.at(i);
  }

  cout << ans << endl;
}

Measured memory_bytes: 5004
#include <cstdio>
#include <cstring>
#include <algorithm>
#define Abs(_A) (_A < 0 ? -(_A) : _A)
#define R register
int n;
struct Data{ int x, y, t; } a[100010];
bool cmp(R Data i, R Data j){ return i.t < j.t; }
int main()
{
	scanf("%d", &n);
	for(R int i = 1; i <= n; i++) scanf("%d %d %d", &a[i].t, &a[i].x, &a[i].y);
	std::sort(a + 1, a + 1 + n, cmp);
	for(R int i = 1; i <= n; i++)
	{
		R int tmp = Abs(a[i].x - a[i - 1].x) + Abs(a[i].y - a[i - 1].y), ttt = a[i].t - a[i - 1].t;
		if(tmp > ttt)
		{
			puts("No");
			return 0;
		}
		if((tmp & 1) != (ttt & 1)) 
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1280
using System;

class A {
    public static void Main() {
        var n = int.Parse(Console.ReadLine());
        var k = int.Parse(Console.ReadLine());
        var x = int.Parse(Console.ReadLine());
        var y = int.Parse(Console.ReadLine());
        Console.WriteLine(n < k ? n * x : k * x + (n - k) * y);
    }
}


Measured memory_bytes: 13140