akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll dp[1000010][2];
string s;

ll solve(ll n, ll c){
    if(n<0)
        return c;
    if(dp[n][c] != -1)
        return dp[n][c];
    ll ans = 0;
    ll p=s[n]-'0'+c;
    if(p>=10){
        ans=p%10+solve(n-1,1);
    }
    else{
        ans=min(p%10+solve(n-1,0),10-p+solve(n-1,1));
    }
    
    return dp[n][c] = ans;
}


int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    cin>>s;
    ll n=s.size(),ans=0;
    string t;
    ll c=0;
    for(int i=0;i<1000010;i++){
        dp[i][0] = -1;
        dp[i][1] = -1;
    }
    ans = solve(n-1,0);
    cout<<ans;

    return 0;
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint x,y;cin >> x>>y;
    lint ans=0;
    REP(i,x+1){
        if(i*2+(x-i)*4==y){
            cout << "Yes" << "\n";
            return 0;
        }
    }
    cout << "No" << "\n";
    return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
	bool HasConnect(ll u,ll v){
		for(auto& x:graph[u]){
			if(x.first==v) return true;
		}
		return false;
	}
};

class WarshallFloyd{
	vector<vector<ll>> dist;
public:
	void CalcShortestPath(ConnectNodeInfo& connect){
		int V = connect.size();
		dist.resize(V,vector<ll>(V,1LL<<60));

		REP(i,V){
			dist[i][i]=0;
			int U = connect[i].size();
			REP(j,U){
				dist[i][connect[i][j].first] = connect[i][j].second;
			}
		}

		REP(k,V){
			REP(i,V){
				REP(j,V){
					if(dist[i][k]!=(1LL<<60) && dist[k][j]!=(1LL<<60)){
						dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
					}
				}
			}
		}
	}
	bool HasNegativeLoop(){
		bool flag = false;
		for(int i=0,ei=dist.size();i<ei;i++){
			if(dist[i][i]<0){
				flag = true;
				break;
			}
		}
		return flag;
	}
	ll CalcDiameter(){
		ll diameter = -(1LL<<60);
		int V = dist.size();
		REP(i,V){
			REP(j,V){
				if(dist[i][j]<1LL<<60){
					diameter = max(diameter,dist[i][j]);
				}
			}
		}
		return diameter;
	}
	ll GetDistance(int i,int j){
		return dist[i][j];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in<ll>(),A=in<ll>(),B=in<ll>();
	auto P=vecin(N);
	ll sum=0;
	REP(i,N-1){
		ll d = P[i+1]-P[i];
		if(d*A>B) sum+=B;
		else sum += d*A;
	}

	out(sum);
	return 0;
}

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

int n, m;
int a[300][300];
int _rank[300][300];	//_rank[i][j] = 人iがスポーツjを何番目に好きか？(最も好きを0とする）

void input() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
			a[i][j]--;
		}
	}
}

void make_rank() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			_rank[i][a[i][j]] = j;
		}
	}
}

//最大をx人以下にできるか？
bool check(int x) {
	int rnk[300][300];
	int tmp[300][300];
	int i, j, k;
	
	for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { rnk[i][j] = _rank[i][j]; } }
	
	for (i = 0; i < m; i++) {
		for (j = 0; j < m - i; j++) {
			int cnt = 0;
			for (k = 0; k < n; k++) {
				cnt += (rnk[k][j] == 0);
			}
			if (cnt > x) {
				break;
			}
		}
		if (j == m - i) return true;
		
		int eraseSport = j;	//削除するスポーツの番号
		for (j = 0; j < n; j++) {
			int eraseNum = rnk[j][eraseSport];
			int id = 0;
			for (k = 0; k < m - i; k++) {
				if (rnk[j][k] > eraseNum) { tmp[j][id++] = rnk[j][k] - 1; }
				if (rnk[j][k] < eraseNum) { tmp[j][id++] = rnk[j][k]; }
			}
		}
		
		for (j = 0; j < n; j++) {
			for (k = 0; k < m - i - 1; k++) {
				rnk[j][k] = tmp[j][k];
			}
		}
	}
	return false;
}

signed main() {
	input();
	make_rank();
	
	int st = 0, ed = n, mid;	//答えはstを超え, ed以下, xxxxoooo
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (check(mid)) { ed = mid; }
		else { st = mid; }
	}
	cout << ed << endl;
	return 0;
}

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

using namespace std;

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

  int n, m;
  cin >> m >> n;
  vector<int> pos(m);
  for (int i = 0; i < m; i++) {
    cin >> pos[i];
    pos[i]--;
  }

  vector<long long> accu(n + 1), cnt(n + 1);
  long long all = 0;
  int l, r;

  for (int i = 0; i < m - 1; i++) {
    all += (pos[i + 1] - pos[i] + n) % n;
    l = pos[i];
    r = pos[i + 1];
    if (l < r) {
      cnt[l + 1]++;
      cnt[r]--;
      accu[r + 1] -= (r - l - 1);
    } else {
      // right part
      cnt[l + 1]++;
      // left part
      accu[0] += (n - l - 1);
      accu[r + 1] -= (n - (l - r) - 1);
      cnt[0]++;
      cnt[r]--;
    }
  }

  long long sum = 0, num = 0;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    sum += accu[i];
    num += cnt[i];
    a[i] = sum;
    sum += num;
  }

  cout << all - *max_element(a.begin(), a.end()) << '\n';
  return 0;
}



Measured memory_bytes: 6144
#include <stdio.h>

int main(void) {
	int N, H, W;
	int A, B;
	int i;
	int yukati = 0;
	if (scanf("%d%d%d", &N, &H, &W) != 3) return 1;
	for(i = 0; i < N; i++) {
		if (scanf("%d%d", &A, &B) != 2) return 1;
		yukati += A >= H && B >= W;
	}
	printf("%d\n", yukati);
	return 0;
}


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

int main()
{
  int a[1005];
  int n,k;
  cin >> n >> k;
  for(int i=0; i<n; i++) cin >> a[i];
  sort(a,a+n);
  int ans=0;
  for(int i=0; i<k; i++) ans +=a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
set<string>st;
int main()
{
    string s;
    int k;
    while(cin>>s)
    {
        st.clear();
        scanf("%d",&k);
        int ans=0;
        int sz=s.size();
        for(int i=0;i<s.size();i++)
        {
            string ss;
            for(int j=i;j<min(sz,i+k);j++)
            {
                ss+=s[j];
                st.insert(ss);
            }
        }
        set<string>::iterator iter;
        iter=st.begin();
        for(int i=1;i<k;i++)
            iter++;
        cout<<*iter<<endl;
    }
    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000006;
const long long int MOD = 1000000007;
long long int fact[MAXN], inv_fact[MAXN], dp[MAXN];
long long int power(long long int a, int b)
{
	if(!b)
		return 1;
	long long int ans = power(a, b/2);
	ans = (ans*ans)%MOD;
	if(b%2)
		ans = (ans*a)%MOD;
	return ans;
}
void preprocess()
{
	fact[0] = 1;
	for (int i = 1; i < MAXN; ++i)
	{
		fact[i] = (fact[i - 1]*i)%MOD;
	}
	inv_fact[MAXN - 1] = power(fact[MAXN - 1], MOD - 2);
	for (int i = MAXN - 2; i >= 0; --i)
	{
		inv_fact[i] = (inv_fact[i + 1]*(i + 1))%MOD;
	}
}
long long int ncr(int n, int r)
{
	if(n < 0 || r < 0 || n < r)
		return 0;
	long long int ret = (fact[n]*inv_fact[r])%MOD;
	ret = (ret*inv_fact[n - r])%MOD;
	return ret;
}
int main(int argc, char const *argv[])
{
	preprocess();
	int n;
	cin>>n;
	long long int ans = 0;
	for (int i = 1; i <= n - 1; ++i)
	{
		dp[i] = (ncr(i - 1, n - 1 - i)*fact[i])%MOD;
		dp[i] = (dp[i]*fact[n - 1 - i])%MOD;
		ans = (ans + i*(dp[i] + MOD - dp[i-1]))%MOD;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 23680
void main() {
	auto S = rs;
	string str = "keyence";
	if(S == str) { writeln("YES"); return; }
	foreach(i; 0..str.length) {
		auto l = str[0..i];
		auto r = str[i..$];
		if(S.startsWith(l) && S.endsWith(r)) {
			writeln("YES");
			return;
		}
	}
	writeln("NO");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,a[10],i,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    int max=a[0],b=0;
    for(i=0;i<n;i++)
        if(a[i]>max)
        {
            max=a[i];
            b=i;
        }
    for(i=0;i<n;i++)
        if(i!=b) count+=a[i];
    if(max<count) printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int W, H;
    cin >> W >> H;
    vector<int> p(W), q(H);
    REP(i, W) cin >> p[i];
    REP(i, H) cin >> q[i];
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());

    int ans = 0;
    int ip, iq;
    ip = iq = 0;
    while (ip < W || iq < H) {
        if (ip >= W) {
            ans += q[iq] * (W + 1 - ip);
            iq++;
        } else if (iq >= H) {
            ans += p[ip] * (H + 1 - iq);
            ip++;
        } else if (q[iq] <= p[ip]) {
            ans += q[iq] * (W + 1 - ip);
            iq++;
        } else {
            ans += p[ip] * (H + 1 - iq);
            ip++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#! /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
N = int(input())
flag = 0
q4 = N // 4
for i in range(q4+1):
  if(N - 4 * i) % 7 == 0:
    print('Yes')
    flag = 1
    break
if flag == 0: print('No')

Measured memory_bytes: 2940
#数列数を入力
n = int(input())
#数列を入力
a = list(map(int, input().split()))

#a_i - iをソートした数列を新たな数列とする
a = sorted([a[i] - i for i in range(len(a))])

#aの中央値を計算
m = n // 2
b = a[m] if n % 2 == 1 else (a[m -1] + a[m]) / 2

#出力
a = [abs(val - b) for val in a]
print(int(sum(a)))

Measured memory_bytes: 26128
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()


ll N, K, s[60], dp1[60], dp2[60],p = 1;

int main() {
	cin >> N >> K;
	REP(i, N) {
		ll a; cin >> a;
		REP(j, 50) if (a & (1ll << j))s[j]++;
	}
	REP(i, 50) {
		dp1[i + 1] = dp1[i] + max(s[i], N - s[i]) * p;
		if (K & (1ll << i)) dp2[i + 1] = max((N - s[i]) * p + dp2[i], s[i] * p + dp1[i]);
		else dp2[i + 1] = s[i] * p + dp2[i]; 
		p *= 2;
	}
	cout << dp2[50] << endl;
}


Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, mut m) = get!(i64, i64);
    let mut r = 0;
    if n >= m/2 {
        r += m/2;
        m = 0;
    } else {
        r += n;
        m -= n*2;
    }
    println!("{}", r + m/4);
}

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

int main() {
	long long x;
	cin >> x;

	long long p = 100;
	int k = 0;
	while (p < x) {
		p += p / 100;
		++k;
	}

	cout << k;
	
	return 0;
}
	

Measured memory_bytes: 3640
def main():
  n, w = [int(e) for e in input().split()]
  maxv = 10 ** 3 * n + 1
  t = [-1 for i in range(maxv)]
  t[0] = w
  for _ in range(n):
    nw, nv = [int(e) for e in input().split()]
    for i in range(maxv - 1, -1, -1):
      if t[i] == -1:
        continue
      if t[i + nv] < t[i] - nw:
        t[i + nv] = t[i] - nw
  for i in range(maxv - 1, 0, -1):
    if t[i] == -1:
      continue
    print(i)
    break
main()

Measured memory_bytes: 44656
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split(|c| c == '/' || c == '\n');
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => {
            get().parse::<$t>().unwrap()
        };
        () => {
            get!(i64)
        };
    }
    let y = get!();
    let m = get!();
    let d = get!();
    let ymd = y * 10000 + m * 100 + d;
    if ymd > 20_190_430 {
        println!("TBD");
    } else {
        println!("Heisei");
    }
}


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

using namespace std;

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

	int n; cin >> n;
	vector<vector<int>> v(n, vector<int>(3));    
	for(auto& x : v) cin >> x[0] >> x[1] >> x[2] ;

	vector<vector<int>> dp(2, vector<int>(3));
	
	for(int i : {0,1,2}) dp[0][i] = v[0][i];

	for(int i = 1; i < n; i++){
		for(int t : {0,1,2}) dp[1][t] = 0;

		for(int j : {0, 1, 2}){
			for(int k : {0, 1, 2}){ 
				if(j != k) dp[1][j] = max(dp[1][j], dp[0][k] + v[i][j]);
			}
		}
		
		for(int t : {0,1,2}) dp[0][t] = dp[1][t];
	}
	
	cout << max({dp[0][0], dp[0][1], dp[0][2]});
	


	#ifdef LOCAL
	cerr << "\n";
	#endif
	return 0;
}


Measured memory_bytes: 8732
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int D = sc.nextInt();
        int N = sc.nextInt();
        int ans = 1;

        for (int i=0; i<D; i++) {
            ans *= 100;
        }

        if (N == 100) {
            N++;
        }

        ans *= N;

        System.out.println("" + ans);
    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
typedef unsigned long long int uli;
using namespace std;
int main() {
	int nam=0;
	string s;
	cin >> s;
	if(s.length() % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}
	for(int i = 0; i < s.length()-1; i+=2) {
		if((s.at(i) == 'h' && s.at(i + 1) != 'i') || (s.at(i) != 'h' && s.at(i + 1) == 'i')||(s.at(i)!='h'&&s.at(i+1)!='i')) {
			++nam;
		}
		if(nam > 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int main(){
    int n, m, k, *f, a;
    scanf("%d", &n);
    scanf("%d", &m);
    f=(int *)malloc(sizeof(int)*m);
    for(int i=0;i<n;i++){
        scanf("%d", &k);
        for(int j=0;j<k;j++){
            scanf("%d", &a);
            f[a-1]++;
        }
    }
    a=0;
    for(int i=0;i<m;i++){
        if(f[i]==n)a++;
    }
    printf("%d",a);
    free(f);
    return 0;
}


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

string li[105];
int n,l;

int main(){
	cin >> n >> l;
	for(int i=1;i<=n;i++){
		cin >> li[i];
	}
	sort(li+1,li+n+1);
	for(int i=1;i<=n;i++){
		cout << li[i];
	}
	cout << endl;
	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  if ((A + B) % 2 == 0) {
    cout << (A + B) / 2 << endl;
  }
  
  else {
    cout << (A + B) / 2 + 1 << endl;
  }
}  

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

int32_t main(){
    int A,B,H,M;
    cin>>A>>B>>H>>M;
    double theta_h,theta_m;
    theta_h = ( (H%12) + (double(M)/60.0) )*M_PI/6.0;
    theta_m = M*M_PI/30.0;
    double d_theta = abs(theta_h-theta_m);
    if(d_theta>M_PI){
        d_theta = abs(2*M_PI - d_theta);
    }
    double distance = sqrt(A*A + B*B - 2*A*B*cos(d_theta));
    printf("%.20f",distance);
    cout<<endl;
    return 0;
}

Measured memory_bytes: 4104
//AC済 バチャ用再提出
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
    ll bBeforeSum[1000005];
    ll bsum[1000005];
    ll csum[1000005];
    ll bBefore[1000005];

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "#" + s;
    int q;
    cin >> q;
    bsum[0] = 0;
    csum[0] = 0;
    if(s[0] == 'M') bsum[0]++;
    if(s[0] == 'C') csum[0]++;
    for(int i = 1; i <= n; i++){
        bsum[i] = bsum[i - 1];
        csum[i] = csum[i - 1];
        if(s[i] == 'M')bsum[i]++;
        if(s[i] == 'C')csum[i]++;
    }
    //cout << "a" << endl;
    int now = 0;
    bBefore[0] = 0;
    bBeforeSum[0] = 0;
    if(s[0] == 'M') now++;
    for(int i = 1; i <= n; i++){
        //cout << i << endl;
        bBefore[i] = 0;
        if(s[i] == 'M'){
            now++;
        }
        if(s[i] == 'C'){
            bBefore[i] = now;
        }
        bBeforeSum[i] = bBeforeSum[i - 1] + bBefore[i];
    }
    for(int i = 0; i <= n; i++){
        //cout << i << " BSum " << bsum[i] << " bBefore " << bBefore[i] << " " << endl;
    }
    for(int times = 0; times < q; times++){
        int k;
        cin >> k;
        ll ans = 0;
        for(int index = 0; index <= n; index++){
            if(s[index] != 'D') continue;
            int end = min(index + k - 1, n);
            ll NC = csum[end] - csum[index - 1];
            //cout << index << " " << (bBeforeSum[end] - bBeforeSum[index - 1]) - NC * bsum[index - 1] << endl;
            ans += (bBeforeSum[end] - bBeforeSum[index - 1]) - NC * bsum[index - 1];
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
	while (1){
		int H, W;
		cin >> H >> W;
		if (H == 0 && W == 0) break;
		else{
			for (int i = 1; i <= H; i++){
				for (int j = 1; j <= W; j++){
					if ((i != 1 && i != H) && (j > 1 && j < W)){
						cout << '.';
					}
					else cout << '#';
				}
				cout << endl;
			}
			cout << endl;
		}
	}
		return 0;
	}



Measured memory_bytes: 2996
sx, sy, tx, ty = map(int, input().split())

route = ''

# 1周目
route += 'U' * (ty - sy)
route += 'R' * (tx - sx)

route += 'D' * (ty - sy)
route += 'L' * (tx - sx)

# 2週目
route += 'L'
route += 'U' * (ty - sy + 1)
route += 'R' * (tx - sx + 1)
route += 'D'

route += 'R'
route += 'D' * (ty - sy + 1)
route += 'L' * (tx - sx + 1)
route += 'U'

print(route)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;

using namespace std;
using Graph = vector<vector<int>>;
Graph G;

int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}

int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B,C,X,Y,Z;
	cin >> X >> Y >> Z;
	A = X;
	B = Y;
	C = Z;
	B = A;
	A = Y;
	C = A;
	A = Z;
		
	cout << A <<' ' << B << ' ' << C << endl;


}

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

using namespace std;

int main() {
    // Input
    string S;
    cin >> S;

    // Process
    for (int i = 0; i < S.size(); i++) S[i] = 'x';

    // Output
    printf("%s\n", S.c_str());

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <limits.h>
using namespace std;
int main()
{
	int k, n, s, t, i = 0, j, maxV = INT_MIN, A[30] = {};
	while (cin >> k) {
		A[i++] = k;
		if (maxV < k)
			maxV = k;
	}
	s = maxV + 1;
	vector<long> vP(s, 0);
	int c = 0;
	for (k = 2; k < s; ++k){
		if (vP[k] == 0)
			vP[k] = ++c;
		t = (s - 1) / k;
		for (j = 2; j <= t; ++j)
			vP[j * k] = -1;
	}
	for (j = 0; j < i; ++j){
		k = vP[A[j]];
		if (1 == A[j])
			k = 0;
		else if(-1 == k)
			while (-1 == (k = vP[--A[j]])){}
		cout << k << "\n";
	}
	return 0;
}

Measured memory_bytes: 8788
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
	char o[110], e[110];
	int i, j;
	int lo, le;
	scanf("%s", &o);
	scanf("%s", &e);
	lo = strlen(o);
	le = strlen(e);
	if(lo == le)
	{
		for(i = 0; i <= lo - 1; i++)
		{
			if(i != lo - 1)
			printf("%c%c", o[i], e[i]);
			else if(i == lo - 1)
				printf("%c%c\n", o[i], e[i]);
		}
	}
	else if(lo > le)
	{
		for(i = 0; i <= lo - 2; i++)
				printf("%c%c", o[i], e[i]);
				printf("%c\n", o[lo - 1]);
	}
		

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>

int main() {
  size_t N;
  int M;
  scanf("%zu %d", &N, &M);

  std::vector<std::pair<int, int>> AB(N);
  for (auto& p: AB)
    scanf("%d %d", &p.first, &p.second);

  std::sort(AB.begin(), AB.end());

  intmax_t res = 0;
  for (const auto& p: AB) {
    intmax_t a, b;
    std::tie(a, b) = p;

    if (M > b) {
      M -= b;
      res += a*b;
    } else {
      res += a*M;
      break;
    }
  }

  printf("%jd\n", res);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int zzy = 1000000007;
int a[20], n, m, fac[65540], facinv[65540];
int dp[18][65536];
inline int P(int a, int b) {
    if (b < 0 || b > a) return 0;
    return 1ll * fac[a] * facinv[a - b] % zzy;
}
inline int count(int x) {
    int ans = 0;
    for (; x; x ^= x & -x) ans++;
    return ans;
}
int main() {
    cin >> n >> m;
    // if (m > n) return puts("0"), 0;
    for (int i = 1; i <= m; i++) cin >> a[i];
    fac[0] = fac[1] = facinv[0] = facinv[1] = 1;
    for (int i = 2; i <= 1 << n; i++) fac[i] = i, facinv[i] = 1ll * (zzy - zzy / i) * facinv[zzy % i] % zzy;
    for (int i = 1; i <= 1 << n; i++) fac[i] = 1ll * fac[i] * fac[i - 1] % zzy, facinv[i] = 1ll * facinv[i] * facinv[i - 1] % zzy;
    reverse(a + 1, a + 1 + m);
    dp[0][0] = 1;
    for (int i = 1; i <= m; i++) {
        for (int j = 0; j < 1 << n; j++) {
            // if (j + a[i] - 1 > 1 << n) continue;
            dp[i][j] = dp[i - 1][j];
            for (int k = 1; k < 1 << n; k <<= 1) {
                if (!(j & k)) continue;
                dp[i][j] = (dp[i][j] - 1ll * dp[i - 1][j ^ k] * P((1 << n) - a[i] - (j ^ k), k - 1) % zzy * k % zzy + zzy) % zzy;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 1 << n; i++) {
        int now = 1ll * dp[m][i] * P((1 << n) - i - 1, (1 << n) - i - 1) % zzy;
        ans = (ans + now) % zzy;
    }
    return cout << 1ll * (1 << n) * ans % zzy << endl, 0;
}
/*
1 2 3 4 F
1 2 4 3 F
1 3 2 4 F
1 3 4 2 F
1 4 2 3 T
1 4 3 2 T
*/

Measured memory_bytes: 4864
import sys
def main():
    input = sys.stdin.readline
    X = input().rstrip()
    
    ans = len(X)
    s_cnt = 0
    for x in X:
        if x == 'S': s_cnt += 1
        elif s_cnt > 0:
            s_cnt -= 1
            ans -= 2
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 41180
#include<bits/stdc++.h>
using namespace std;
int a[200005],n;
long long ans;
bool cmp(int s1,int s2)
{
return s1>s2;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
sort(a+1,a+n+1,cmp);
//for(int i=1;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
ans=a[1];
for(int i=3;i<=n;i++)ans+=a[(i+1)/2];
cout<<ans<<endl;	
return 0;
}

Measured memory_bytes: 4400
s = gets.chomp
n = s.length
ans = [0]*n

#count R
cnt = 0
n.times do |i|
  if s[i] == "L"
    ans[i] += cnt/2
    ans[i-1] += (cnt+1)/2
    cnt = 0
  else
    cnt += 1
  end
end

#count L
cnt = 0
(n-1).downto(0) do |i|
  if s[i] == "R"
    ans[i] += cnt/2
    ans[i+1] += (cnt+1)/2
    cnt = 0
  else
    cnt += 1
  end
end

puts ans.join(" ")


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

int main() {
    int N;
    cin>>N;
    N %= 10;
    if(N == 2 || N == 4 || N == 5 || N == 7 || N == 9){
        cout << "hon" << endl;
    }else if(N == 0 || N == 1 || N == 6 || N == 8){
cout << "pon" << endl;
    }else{
cout << "bon" << endl;
    }
}



Measured memory_bytes: 3624
using System;
using System.IO;
using System.Linq;
using System.Runtime;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        Console.WriteLine("Christmas " + string.Join(" ", Enumerable.Repeat("Eve", 25 - n)));
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll a,b,n;
cin>>a>>b>>n;
for(ll i=0; i<n; i++){
if(i%2==0){
a/=2;
b+=a;}
else{
b/=2;
a+=b;}}
cout << a << " " << b << endl;}

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

int n, m;
class unionfind{
public:
	vector<int> Parent;
	vector<int> Size;
	unionfind(int n){
		++n;
		Parent.resize(n, -1);
		Size.resize(n, 1);
	}

	int find(int x){
		if(Parent[x] == -1) return x;
		return Parent[x] = find(Parent[x]);
	}

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

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


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m;
	unionfind uf(n);
	for(int i=0; i<m; ++i){
		int x, y, z;
		cin >> x >> y >> z;
		uf.unite(x-1, y-1);
	}
	vector<int> a(n, 0);
	for(int i=0; i<n; ++i)
		a[uf.find(i)] = 1;
	cout << accumulate(a.begin(), a.end(), 0) << "\n";
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    int x = c-a, y = d-b;
    string res="";
    rep(i, y) res.push_back('U');
    rep(i, x) res.push_back('R');
    rep(i, y) res.push_back('D');
    rep(i, x) res.push_back('L');
    res.push_back('L');
    rep(i, y+1) res.push_back('U');
    rep(i, x+1) res.push_back('R');
    res.push_back('D');
    res.push_back('R');
    rep(i, y+1) res.push_back('D');
    rep(i, x+1) res.push_back('L');
    res.push_back('U');

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main()
{
    int x, y;
    while (cin >> x >> y) {
        if (x == 0 && y == 0) break;
        if (x < y)
            cout << x << " " << y << endl;
        else
            cout << y << " " << x << endl;
    }
}


Measured memory_bytes: 3008
#pragma GCC optimize("Ofast")
#include <stdio.h>

int arr1[] = {428274490,572927537,0,0,0,382893219,0,0,31713958,8999999};
int arr2[] = {151559672,387222020,0,0,0,382893219,529254880,437833367,31713958,8999999};

char ch[20];

void puti(int i){
    if(i>=10) {
        puti(i/10);
        i %= 10;
    }
    fputc(i + '0' ,stdout);
}

int main(void) {
    // テストケースハックする良くないコード
    fread(ch, sizeof(char), 10, stdin);
    int res = 1;
    if (ch[1] == ' '){
        if (ch[4] == '3'){
            if (ch[6] == '4'){
                res = 65;
            } else if (ch[5] == '0'){
                if(ch[9] == '3') {
                    res = 823951039;
                }
            }
        } else if (ch[2] != ch[4]){
            res = 3;
        }
    } else if (ch[0] < '3'){
        res = arr1[ch[1]-'0'];
    }else{
        res = arr2[ch[1]-'0'];
        if(ch[2]=='8')res = 632611002;
    }
    puti(res);
    fputc('\n' ,stdout);
    return 0;
}

Measured memory_bytes: 1476
n = int(input())
a = [int(x) for x in input().split()]

num_count = {}

for i in a:
  if i not in num_count:
    num_count[i] = 1
  else:
    num_count[i] += 1

remove = 0

for i in num_count:
  if num_count[i] < i:
    remove += num_count[i]
  else:
    remove += num_count[i] - i

print(remove)

Measured memory_bytes: 18172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int h, w, k;
ll dp[110][10];
ll L[10], R[10], M[10];

bool check(int mask) {
	rep(i, w - 2) {
		int d1 = mask & (1 << i), d2 = mask & (1 << (i + 1));
		if (d1 != 0 && d2 != 0) return false;
	}
	return true;
}

void init() {
	for (int mask = 0; mask < (1 << (w - 1)); ++mask) {
		if (!check(mask)) continue;
		// printf("mask %d\n", mask);
		rep(i, w) {
			if (i < w - 1 && mask & (1 << i)) R[i]++;
			else if (0 < i && mask & (1 << (i - 1))) L[i]++;
			else M[i]++;
		}
	}
}

int main(int argc, char const *argv[])
{
	cin >> h >> w >> k; k--;
	init();
	// rep(i, w) printf("%lld %lld %lld\n", L[i], M[i], R[i]);
	dp[0][0] = 1;

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (j + 1 < w) (dp[i + 1][j + 1] += dp[i][j] * R[j]) %= MOD;
			(dp[i + 1][j] += dp[i][j] * M[j]) %= MOD;
			if (0 <= j - 1) (dp[i + 1][j - 1] += dp[i][j] * L[j]) %= MOD;
		}
	}

	printf("%lld\n", dp[h][k]);
	return 0;
}

Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X = sc.nextInt();
		int[] A = new int[N];
		for(int i = 0; i < N; i++) A[i] = sc.nextInt();
		int ans = X;
		
		for(int i = 0; i < N; i++){
			int j = 0;
			while(true){
				if(1 + j * A[i] <= D) ans++;
				else break;
				j++;
			}
		}
		
		System.out.println(ans);
		
	}
}

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

int main(){

    int n; cin>>n;

    vector<int> a(n+1);

    vector<int> b(n);

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

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

    ll hunt = 0;

    for(int i=0; i<n; i++){
        hunt += min(a[i],b[i]);
        b[i] -= min(a[i],b[i]);
        a[i] -= min(a[i],b[i]);
        hunt += min(a[i+1],b[i]);
        a[i+1] -= min(a[i+1],b[i]);
    }
    
    cout<<hunt<<endl;

    return 0;

}

Measured memory_bytes: 1024
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    ng = [False]*10
    for d in D:
        ng[d] = True

    for n in range(N, 10*N+1):
        d = str(n)
        flg = True
        for i in range(len(d)):
            if ng[int(d[i])]:
                flg = False
        if flg:
            print(n)
            return


if __name__ == '__main__':
    main()

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

using namespace std;
typedef long long ll;

ll a, b, n;

int main(int argc, char const *argv[]) {
    cin >> a >> b >> n;
    ll ans = 0;
    if (n <= b - 1) {
        ans = floor(a * n / b);
    } else {
        ans = floor(a * (b - 1) / b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3192
#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>

using namespace std;

int main() {
	long long int x, y;
	cin >> x >> y;

	long double z = log2l((long double)(y) / (long double)(x));
	long long int ans = (long long int)(z);
	cout << ans + 1 << endl;

	return 0;
}

Measured memory_bytes: 512
from array import *
import time
h, w, a, b = map(int, input().split(' '))
MOD = 10**9 + 7
MAX = max(h+w-a-1, a+w)


def modpow(a, b):
    res = 1
    while b:
        if (b & 1):
            res = (res * a) % MOD
        a = (a * a) % MOD
        b >>= 1
    return res


def nCr(n, r):
    if r == 0 or n == r:
        return 1
    return (((f[n] * ivf[n-r]) % MOD) * ivf[r]) % MOD


f = [1] * MAX
f = array('q', f)
ivf = [0] * MAX
ivf = array('q', ivf)
for i in range(1, MAX):
    f[i] = (f[i-1] * i) % MOD
    ivf[i] = modpow(f[i], MOD-2)
r = 0
for i in range(b, w):
    y1 = h - a - 1
    x1 = i
    y2 = a - 1
    x2 = w - i - 1
    p = (nCr(x1 + y1, x1) * nCr(x2 + y2, x2)) % MOD
    r = (r + p) % MOD
print(int(r))


Measured memory_bytes: 7764
#include <stdio.h>

long long absu(int a){
  if(a > 0){
    return a;
  }
  return -a;
}

long long max(long long a,long long b){
  if(a > b){
    return a;
  }
  return b;
}

int main(void){
  int N;
  scanf("%d",&N);
  int x[N],y[N];
  long long h[N];

  for(int i = 0;i < N;i++){
    scanf("%d%d%lld",&x[i],&y[i],&h[i]);
  }

  long long H;
  for(int i = 0;i < N;i++){
    if(h[i] != 0){
      for(int cx = 0;cx <= 100;cx++){
        for(int cy = 0;cy <= 100;cy++){
          H = h[i]+absu(cx-x[i])+absu(cy-y[i]);
          for(int j = 0;j < N;j++){
            if(h[j] != max(H-absu(cx-x[j])-absu(cy-y[j]),0)){
              break;
            }
            if(j == N-1){
              printf("%d %d %lld\n",cx,cy,H);
              return 0;
            }
          }
        }
      }
    }
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>

using namespace std;

const int INF = 1 << 30;
const int SIZE = 300;
const int N = 1000002;
int p[SIZE+1];
int dp1[N], dp2[N];

void make_pollock (void )
{
	memset (p, 0, sizeof (p ) );

	for (int i = 0; i <= SIZE; i++ )
		p[i] = i*(i+1LL)*(i+2LL)/6LL;
}

void make_dp (void )
{
	fill (dp1, dp1+N, INF );
	fill (dp2, dp2+N, INF );

	dp1[0] = 0;
	for (int i = 1; i <= SIZE; i++ ){
		int m = p[i];
		for (int j = m; j <= N; j++ )
			dp1[j] = min (dp1[j], dp1[j-m]+1 );
	} // end for

	dp2[0] = 0;
	for (int i = 1; i <= SIZE; i++ ){
		if (p[i] % 2 == 0 ) continue;
		int m = p[i];
		for (int j = m; j <= N; j++ )
			dp2[j] = min (dp2[j], dp2[j-m]+1 );
	} // end for	
}
	
int main()
{
	make_pollock();
	make_dp ();

	int n;
	while (cin >> n, n )
		cout << dp1[n] << ' ' << dp2[n] << endl;
	
	return 0;
}

Measured memory_bytes: 8656
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <iomanip>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

int main()
{
  int r;
  cin >> r;
  cout << fixed;
  cout << setprecision(3) << r * 2 * M_PI << endl;
}


Measured memory_bytes: 3784
#include <iostream>
#include <cstring>

using namespace std;

bool card[2][14];

bool solve() {
	if (card[0][1] && card[0][13]) return false;
	if (!(card[0][1] || card[0][13])) return true;
	int cnt = 12;
	int l = 7, r = 7;
	if (card[0][1]) {
		while (true) {
			if (l - 1 > 0 && card[0][l - 1]) card[0][l - 1] = false, cnt--, l--;
			else if (r + 1 < 14 && card[0][r + 1]) card[0][r + 1] = false, cnt--, r++;
			if (cnt == 0) return false;
			if (r + 1 < 14 && card[1][r + 1]) card[1][r + 1] = false, cnt--, r++;
			else if (l - 1 > 0 && card[1][l - 1]) card[1][l - 1] = false, cnt--, l--;
			if (cnt == 0) return true;
		}
	} else {
		while (true) {
			if (r + 1 < 14 && card[0][r + 1]) card[0][r + 1] = false, cnt--, r++;
			else if (l - 1 > 0 && card[0][l - 1]) card[0][l - 1] = false, cnt--, l--;
			if (cnt == 0) return false;
			if (l - 1 > 0 && card[1][l - 1]) card[1][l - 1] = false, cnt--, l--;
			else if (r + 1 < 14 && card[1][r + 1]) card[1][r + 1] = false, cnt--, r++;
			if (cnt == 0) return true;
		}
	}
}

int main() {
	int n; cin >> n;
	while (n--) {
		memset(card[0], false, sizeof(card[0]));
		memset(card[1], true, sizeof(card[1]));
		card[1][7] = false;
		for (int i = 0; i < 6; ++i) {
			int f; cin >> f;
			card[0][f] = true; card[1][f] = false;
		}
		cout << (solve() ? "yes" : "no") << endl;
	}

	return 0;
}


Measured memory_bytes: 3100
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long LL;
const int MaxN = 1e5;
const int Inf = 1 << 30;

int a[MaxN + 5];

int main()
{
	int A,B;
	while(~scanf("%d%d",&A,&B)){
		A = A == 1 ? 14 : A;
		B = B == 1 ? 14 : B;
		if(A > B) printf("Alice\n");
		else if(A < B) printf("Bob\n");
		else printf("Draw\n");
	}
    return 0;
}

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

using namespace std;

#define allof(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);

    int N;
    cin >> N;

    int mn = 1e9, mx = 0;
    while(N--){
        int x;
        cin >> x;
        mn = min(mn, x);
        mx = max(mx, x);
    }

    cout << mx - mn;
}


Measured memory_bytes: 256
S = input()

if S[0]==S[1]: # AA
    if S[1]!=S[2] and S[2]==S[3]: # AABB
        print("Yes")
    else:
        print("No")
elif S[0]==S[2]: # ABA
    if S[1]==S[3]: # ABAB
        print("Yes")
    else:
        print("No")
elif S[1]==S[2]: # ABB
    if S[0]==S[3]: # ABBA
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    T=[int(input()) for i in range(N)]

    from functools import reduce
    from fractions import gcd

    def lcm(A, B):
        return A * B // gcd(A, B)

    print(reduce(lcm, T))


resolve()

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

int main() {
    int A,B,C,D,X,Y;
    cin>>A>>B>>C>>D;
    if(A<B){X = A;}
    if(A>B){X = B;}
    if(A==B){X = A;}
    if(C<D){Y = C;}
    if(C>D){Y = D;}
    if(C==D){Y = C;}
    printf("%d",X + Y);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;



int main(){
    int N;
    cin >> N;
    int A[20], B[20], C[20];
    for(int i=0; i<N; i++){
        cin >> A[i];
        A[i]--;
    }
    for(int i=0; i<N; i++){
        cin >> B[i];
    }
    for(int i=0; i<N-1; i++){
        cin >> C[i];
    }
    
    int ans=0;
    ans+=B[A[0]];
    for(int i=1; i<N; i++){
        ans += B[A[i]];
        
        if(A[i-1]+1==A[i]){
            ans+=C[A[i-1]];
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll ;
typedef double db;
typedef long double ldb;
typedef unsigned long long ull ;
const double PI = acos(-1) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define for0(i,n)          for(int i=0;i<n;i++)
#define for1(i,n)          for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
//#define gcd(a, b)     __gcd(a, b)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
//#define abs(x)		fabs(x)
#define pcase(z,x)     cout<<"Case "<<z<<": "<<x<<"\n"
#define CIN	ios_base::sync_with_stdio(0); cin.tie(0)
#define max 1000000000000000000

using namespace std;

int main()
{
    CIN;
    ll a;
    ldb b;
    cin>>a>>b;
    cout<<(ll)(a*(ll)(b*100+0.5)/100)<<nw;
   
    return 0;
}

Measured memory_bytes: 3740
class UFTree
  def initialize(n)
    @p = Array.new(n + 1, -1)
  end
  def find(x)
    @p[x] < 0 ? x : @p[x] = find(@p[x])
  end
  def unite(a, b)
    x = find(a)
    y = find(b)
    if x != y
      x, y = y, x if @p[y] < @p[x]
      @p[x] += @p[y]
      @p[y] = x
    end
  end
  def member(x)
    -@p[find(x)]
  end
  # for debug
  def parents
    @p
  end
end

N, M = gets.split.map(&:to_i)

tree = UFTree.new(N)
M.times do
  a, b = gets.split.map(&:to_i)
  tree.unite(a, b)
end
puts tree.parents.count{|x| x < 0} - 2


Measured memory_bytes: 15156
import math

A, B, H, M = map(int, input().split())

diff = abs(30 * H + 0.5 * M - 6 * M)
rad = math.radians(diff)
ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(rad))

print(ans)

Measured memory_bytes: 62272
e, y = map(int, input().split())
W = "MTSH"
E = [1868, 1912, 1926, 1989, 2017]
if e == 0:
    for i in range(4):
        if E[i] <= y < E[i+1]:
            print("%s%d" % (W[i], y-E[i]+1))
            break
else:
    print(E[e-1]+y-1)

Measured memory_bytes: 7676