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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int MOD = 1000000007;
const int maxn = 305;

int cnk[maxn][maxn];
int ans[maxn][maxn];
int ans2[maxn][maxn][maxn];
int kk[maxn][maxn];
int pw[maxn][maxn];
int n, m;
int f[maxn];

void add(int &x, ll y)
{
    x = (x + y) % MOD;
}

int main()
{
    scanf("%d%d", &n, &m);
    cnk[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        cnk[i][0] = 1;
        for (int j = 1; j <= i; j++) cnk[i][j] = (cnk[i - 1][j - 1] + cnk[i - 1][j]) % MOD;
    }
    f[0] = 1;
    for (int i = 1; i <= n; i++) f[i] = ((ll)f[i - 1] * i) % MOD;
    for (int i = 1; i <= n; i++)
    {
        pw[i][0] = 1;
        for (int j = 1; j <= m; j++) pw[i][j] = ((ll)pw[i][j - 1] * i) % MOD;
    }
    kk[0][0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = i; j <= m; j++)
        {
            for (int t = i; t >= i; t--) add(kk[i][j], (((ll)kk[i - 1][t - 1] * pw[i][j - t]) % MOD) * i);
        }
    }
//     cout << f[n - 1] << endl;
//     ans[0][1] = 1;
//     for (int i = 0; i < m; i++)
//     {
//         for (int j = 1; j <= n; j++) if (ans[i][j] != 0)
//         {
// //             cout << i << ' ' << j << ' ' << ans[i][j] << endl;
//             for (int k = 0; k <= n - j && i + k + 1 <= m; k++)
//             {
//                 for (int t = 0; i + k + t + 1 <= m; t++)
//                 {
//                     add(ans[i + k + t + 1][j + k], (((ll)ans[i][j] * kk[k][k + t]) % MOD) * j);
//                 }
//             }
//         }
//     }
//     cout << ans[m][n] << endl;
    ans2[0][1][0] = 1;
    for (int i = 0; i < m; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            for (int k = 0; k + j <= n; k++) if (ans2[i][j][k] != 0)
            {
                add(ans2[i + 1][j + k][0], ((ll)ans2[i][j][k] * j));
                add(ans2[i + 1][j][k], ((ll)ans2[i][j][k] * k));
                add(ans2[i + 1][j][k + 1], ((ll)ans2[i][j][k] * (n - j - k)));
            }
        }
    }
    int answer = 0;
    for (int i = 0; i < n; i++) add(answer, ans2[m][n][i]);
    cout << answer << endl;
    return 0;
}

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

#define ll long long
using namespace std;

int main()
{
    int dem = 0;
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k >= a) k -= a, dem += a;
    else{
        dem += min(a, k);
        cout << dem;
        return 0;
    }
    if(k >= b) k -= b, dem += b*0;
    else{
       dem += min(b, k)*0;
       cout << dem;
    return 0;
    }
    if(k >= c) k -=c, dem += c*(-1);
    else{
       dem += min(c, k)*-1;
       cout << dem;
       return 0;
    }
    cout << dem;
}
/*

*/


Measured memory_bytes: 3636
// B - ATCoder
#include <bits/stdc++.h>
using namespace std;

int main(){
	string S; cin>>S;
	string T = "ACGT";

	vector<int> A(S.size());

	A[0] = T.find(S[0])<T.size()? 1:0;

	for(int i=1; i<S.size(); ++i) A[i] = T.find(S[i])<T.size()? A[i-1]+1:0;

	int maxi = 0;
	for(int a:A) maxi = max(maxi, a);
	cout<< maxi <<endl;
}

Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	vector<ll> ans;

	for (int n=1; n<=N; n++) {
		int a = 0;
		for (int x=1; x*x<n; x++) {
			for (int y=x; x*x + y*y < n; y++) {
				for (int z=y; x*x + y*y + z*z < n; z++) {
					if (x*x + y*y + z*z + x*y + y*z + z*x == n) {
						if (x == y && y == z) a++;
						else if (x == y || y == z || z == x) {
							a += 3;
						} else {
							a += 6;
						}
					}
				}
			}
		}
		ans.push_back(a);
	}

	for (int a: ans) {
		cout << a << endl;
	}

	return 0;
}


Measured memory_bytes: 3680
n = int(input())
a = list(map(int, input().split()))

A = max(a)

cnt = [0]*(A+1)
uq = []

for i in a:
    cnt[i] += 1

for i in range(A+1):
    if cnt[i] == 1:
        uq.append(i)

cnt = [0]*((10**6)+1)
cnt1 = 0


a = list(set(a))

# for i in a:
#     for j in range(2,A+1):
#         if i*j<=A+1:
#             cnt[i*j] = 1

for elem in a:
    for m in range(elem * 2, (10 ** 6) + 1, elem):
        cnt[m] = 1

for i in uq:
    if cnt[i] == 0:
        cnt1 += 1

print(cnt1)


Measured memory_bytes: 150332
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

string s[100];
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> s[i];
  sort(s, s + n);
  string ret;
  for (int i = 0; i < n; ++i) ret += s[i];
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define ss cout << " ";
#define nn cout << "\n";
#define ct(x) cout << x;
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define qr queries();
void solve();
void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}};
void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}};
void queries(){int n;cin >> n;while (n--)solve();}
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
const int maxn = 200200;
 
void solve(){

    return;
}
 
 
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    long double a,b,c;
    cin >> a >> b >> c;
    ctn(int(ceil(a/b) * c));
    return 0;
}


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

int main(){
	
 int n,m=0,h=0,rst=0,s=0;
 
 cin>>n;

       if(n==0)
	   {cout<<"0:0:0"<<endl; return 0;}
    if(n<60)
 {cout<<"0:0:"<<n;return 0;}
 
 
  h=n/3600; rst=n%3600;
  if(rst==0){
  s==0;m==0;
  }
  
  
else{
   m=rst/60; s=rst%60;}
  cout<<h<<":"<<m<<":"<<s<<endl;
   return 0;}


Measured memory_bytes: 3124
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    ll N;cin>>N;
    vector<int> digit;
    int mod;
    N--;
    while(N>=0){
        mod = N % 26;
        N = N / 26 - 1;
        digit.push_back(mod);
    }
    reverse(digit.begin(),digit.end());
    for(auto i=digit.begin();i!=digit.end();++i){
        cout << (char)('a' + *i);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

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

using namespace std;
int main() {
	string s;
	cin >> s;
	cout << "ABC" + s << endl;

	return 0;
}

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

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

    string ans;
    while (n) {
        n--;
        ans += 'a'+n%26;
        n /= 26;
    }
    reverse(ans.begin(), ans.end());

    cout << ans << endl;
}



Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    string S; cin >> S;
    if(S.find("B")==string::npos || S.find("A")==string::npos){
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
import sys
import numpy as np
import numba

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


@numba.njit("(i8, i2[:], i4[:,:])", cache=True)
def optimize(D, C, S):
    NUM_ITERS = 30_000_000

    def calc_score(sol):
        last = -np.ones((26, D + 1))
        score = 0
        for d in range(D):
            ct = sol[d]
            score += S[d, ct]
            for i in range(26):
                last[i, d + 1] = last[i, d]
            last[ct, d + 1] = d
            for i in range(26):
                score -= C[i] * (d - last[i, d + 1])
        return score, last

    sol = -np.ones(D, dtype=np.int16)
    last_tmp = -np.ones(26, dtype=np.int16)
    for _ in range(D):
        score = -(10 ** 12)
        md = -1
        mi = -1
        for d in range(D):
            if sol[d] != -1:
                continue
            for i in range(26):
                s = S[d, i] - C[i] * (d - last_tmp[i])
                if score < s:
                    score = s
                    md = d
                    mi = i
        sol[md] = mi
        last_tmp[mi] = md

    sol_bak = sol.copy()
    max_score, last = calc_score(sol)
    last_bak = last.copy()

    def update(d, before, after):
        score = max_score
        score -= S[d, before]
        score += S[d, after]
        lb = last[before, d]
        la = last[after, d]
        da = db = 0
        for x in range(d, D):
            if x > d and sol[x] == before:
                break
            last[before, x + 1] = lb
            db += 1
        score -= C[before] * (d - lb) * db
        for x in range(d, D):
            if x > d and sol[x] == after:
                break
            last[after, x + 1] = d
            da += 1
        score += C[after] * (d - la) * da
        sol[d] = after
        return score

    tried = numba.typed.Dict.empty(
        key_type=numba.types.int32, value_type=numba.types.boolean
    )
    for i in range(NUM_ITERS):
        new_d = np.random.randint(0, D)
        c_before = sol[new_d]
        c_after = np.random.randint(0, 26)
        if c_before == c_after:
            continue
        candidate = new_d * 26 + c_after
        if candidate in tried:
            continue
        tried[candidate] = True
        new_score = update(new_d, c_before, c_after)
        if max_score < new_score:
            max_score = new_score
            sol_bak[:] = sol
            last_bak[c_before, :] = last[c_before, :]
            last_bak[c_after, :] = last[c_after, :]
            tried.clear()
        else:
            sol[:] = sol_bak
            last[c_before, :] = last_bak[c_before, :]
            last[c_after, :] = last_bak[c_after, :]
    return sol


def main():
    D = ini()
    C = np.array(inl(), dtype="int16")
    assert len(C) == 26
    S = np.zeros((D, 26), dtype="int32")
    for i in range(D):
        S[i, :] = inl()

    sol = optimize(D, C, S)
    print(*(sol + 1), sep="\n")


main()


Measured memory_bytes: 108628
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9+7;
long long n,k;
long long dp[2010][2010];
long long fac[4000010],inv[4000010];
long long fpm(long long a,long long b){
    long long res = 1;
    while(b){
        if (b&1){
            res = res*a%mod;
            b--;
        }
        a = a*a%mod;
        b>>=1;
    }
    return res;
}
long long C(long long n,long long m){
    if (n<m){
        return 0;
    }
    return fac[n]*inv[n-m]%mod*inv[m]%mod;
}
int main () {
    scanf("%lld%lld",&n,&k);
    if (k==1){
        printf("1");
        return 0;
    }
    fac[0] = 1;
    inv[0] = 1;
    for (register int i = 1; i <= 4000000; i++){
        fac[i] = fac[i-1]*i%mod;
        inv[i] = fpm(fac[i],mod-2)%mod;
    }
    dp[0][0] = 1;
    for (register int i = 1; i <= n; i++){
        for (register int j = 0; j <= i; j++){
            dp[i][j] = dp[i-1][j];
            if (j==0){
                continue;
            }
            dp[i][j] += dp[i][j-1]*(n-j+1)%mod*C(n-i+(n-j+1)*(k-1)-1,k-2)%mod;
            dp[i][j] %= mod;
        }
    }
    printf("%lld",dp[n][n]);
    return 0;
}

Measured memory_bytes: 94208
function main(input) {
  const args = input.split(" ");
  const a = parseInt(args[0], 10);
  const b = parseInt(args[1], 10);
  if((a*b) % 2 === 0){
    console.log("Even");
  }else{
    console.log("Odd");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
<?php
$stdin = trim(fgets(STDIN));
$stdinStr = strlen($stdin);
$stdin2 = substr($stdin, ($stdinStr - 1), 1);
if (($stdin2 == 2) || ($stdin2 == 4) || ($stdin2 == 5) || ($stdin2 == 7) || ($stdin2 == 9)) {
    echo 'hon';
} elseif (($stdin2 == 0) || ($stdin2 == 1) || ($stdin2 == 6) || ($stdin2 == 8)) {
    echo 'pon';
} else {
    echo 'bon';
}

Measured memory_bytes: 15908
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;

int printYes() {
    cout << "Yes" << endl;
    return 0;
}

int printNo() {
    cout << "No" << endl;
    return 0;
}

int ans;

int printAns() {
    cout << ans << endl;
    return 0;
}


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
    int a,b;
    cin >> a >> b;
    if (a > 8 || b >8) {
        cout << ":(" << endl;
    } else
    {
        cout << "Yay!";
    }
    
    
    return 0;
}


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

int main(){

  int i,n,cnt=0;
  char s[12],str[12],str2[22];
  scanf("%s",s);
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",str);
    strcpy(str2,str);
    strcat(str2,str);
    if(strstr(str2,s)!=NULL){
      cnt++;
    }

  }
  printf("%d\n",cnt);
  return 0;
}

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


int main(){
    ll a;cin>>a;
    float b;cin>>b;
    ll b100 = b*100+0.5;
    ll ans = a*b100/100;
    cout<<ans<<endl;

}


Measured memory_bytes: 3732
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    cost = [0 for _ in range(n)]
    for i in range(1, n):
        m = float('inf')
        for j in range(1, k+1):
            if (i - j) < 0:
                break
            m = min(m, cost[i-j] + abs(h[i] - h[i - j]))
        cost[i] = m
    return cost[n - 1]


print(main())


Measured memory_bytes: 56800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string s;
    cin >> s;
    int sum = 0;
    for(int i = 0 ; i < s.length() ; i++){
        sum += (s[i] - '0');
    }
    if(sum % 9)
        cout<<"No\n";
    else
        cout<<"Yes\n";
}



Measured memory_bytes: 3696
n = int(input())
s = input()

flagL = [0 for i in range(100)]
L = [0 for i in range(1000)]

num1 = int(s[0])
for i in range(10):
  flagL[num1*10+i] = 1

num2 = int(s[1])
for i in range(10):
  flagL[num2*10+i] = 1
flagL[10*num1+num2] = 2

for i in range(len(s)-2):
  num = int(s[i+2])
  for j in range(100):
    if flagL[j] == 2:
      L[j*10+num] = 1    
  for k in range(10):
    if flagL[k*10+num] == 1:
      flagL[k*10+num] = 2
    if flagL[num*10+k] == 0:
      flagL[num*10+k] = 1
  
print(sum(L))

Measured memory_bytes: 3188
#include<iostream>

using namespace std;

int main(){
	 
	long long n;
	
	while( cin >> n ) {
		
	int count = 0;
	if( n == 0)
	break;
	
	while(true) {
		
		if( n == 1)
		break;
		
		else if ( n % 2)
		n = n * 3 + 1;
		
		else
		n /= 2;
		
		count++;
	}
	cout << count << "\n";
}
  	return 0;
}


Measured memory_bytes: 3048
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //string[] str = Console.ReadLine().Split(' ');
            //int n = int.Parse(Console.ReadLine());

            int n = int.Parse(Console.ReadLine());

            var st = new string[n];
            for(int i = 0; i < n; i++)
            {
                st[i] = Console.ReadLine();

            }

            Array.Sort(st);

            int count = 1;
            for(int i = 0; i < n-1; i++)
            {
                if (st[i] != st[i + 1]) count++;
            }

            Console.WriteLine(count);

            //ここまで
        }



        static long Max(long a, long b)
        {
            if (a > b) return a;
            else return b;
        }
    }

}


Measured memory_bytes: 38764
#include <bits/stdc++.h>
using namespace std;
int N;
int main(){
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    sort(a,a+N);
    int s=0,f=0;
    for(int i=0;i<N;i+=2){
        if(a[i]==a[i+1]){
            s=f;
            f=a[i];
        }
        else i--;
    }
    cout<<(long long)s*f<<"\n";
    return 0;
}


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

using namespace std;

int main(int argc, char* argv[])
{
  string S; cin >> S;
  int year, month, day;
  sscanf(S.c_str(), "%d/%d/%d", &year, &month, &day);

  bool isHeisei = true;
  if (year > 2019) {
    isHeisei = false;
  } else if (year == 2019 && month > 4) {
    isHeisei = false;
  }

  cout << (isHeisei ? "Heisei" : "TBD") << endl;

  return 0;
}


Measured memory_bytes: 764
#include<iostream>
using namespace std;
int A[5000][5];
int x[5],y[5];
main()
{
	int N;
	while(cin>>N,N)
	{
		for(int i=0;i<5000;i++)for(int j=0;j<5;j++)A[i][j]=0;
		for(int i=0;i<N;i++)
		{
			int d,p,q;cin>>d>>p>>q;
			if(d==1)
			{
				for(int j=0;j<p;j++)
				{
					x[j]=4999;
					y[j]=q+j-1;
				}
			}
			else
			{
				for(int j=0;j<p;j++)
				{
					x[j]=4999-j;
					y[j]=q-1;
				}
			}
			while(true)
			{
				for(int j=0;j<p;j++)x[j]--;
				bool flag=false;
				for(int j=0;j<p;j++)
				{
					if(x[j]<0||A[x[j]][y[j]])flag=true;
				}
				if(flag)break;
			}
			for(int j=0;j<p;j++)A[++x[j]][y[j]]=1;
			for(int j=0;j<p;j++)
			{
				int X=x[j];
				bool flag=true;
				for(int k=0;k<5;k++)flag&=A[X][k];
				if(flag)
				{
					for(int k=X+1;k<5000;k++)for(int l=0;l<5;l++)A[k-1][l]=A[k][l];
				}
			}
		}
		int ans=0;
		for(int i=0;i<5000;i++)for(int j=0;j<5;j++)ans+=A[i][j];
		cout<<ans<<endl;
	}
}



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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])
typedef long long ll;

int main() {
    double A,B,H,M;
    cin >> A >> B >> H >> M;
    double angle = abs((30*H+M/2) - 6*M);
    double rad = cos(angle*2*M_PI/360);
    
    double ans = sqrt( (A*A) + (B*B) - (2*A*B*rad));
    cout << std::fixed << std::setprecision(15) << ans << endl;
}

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

using ll = long long;
const int INF = 1e9+7;

void solve(){
	int a,b;cin >> a >> b;
	if(2*b >= a) cout << 0 << '\n';
	else cout << a-(2*b) << '\n';
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int t=1;
//	int t;cin >> t;
	while(t--) solve();
}



Measured memory_bytes: 3592
#include<stdio.h>
#define N 100000

int func(int);
int a[N],n;

int main(){
  int i,j,q,cnt=0;
  int k;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&k);
    if(func(k)) cnt++;
  }

  printf("%d\n",cnt);
  return 0;
}

int func(int k){
  int l=0,r=n,m;
  a[n] = k;
  while(l < r){
    m = (l + r)/2;
    if(k == a[m]) return 1;
    if(k > a[m]) l = m + 1;
    else if(k < a[m]) r = m;
  }
  return 0;
}



Measured memory_bytes: 2244
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    append = peaks.append
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            append(upPeak)
            append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

Measured memory_bytes: 12636
from itertools import permutations

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

for i, X in enumerate(permutations(range(1, N + 1), N)):
    if P == X:
        a = i
    if Q == X:
        b = i
print(abs(a - b))


Measured memory_bytes: 3064
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(x)					(x).begin(),(x).end()
#define REP(i, n)				for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef pair<int, int>			P;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
const int step[4][2] = {
	{1, 0},
	{-1, 0},
	{0, 1},
	{0, -1},
};

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int H, W;
char HW[20 + 1][20 + 1];

// bfs
int bfs(int sx, int sy, int gx, int gy)
{
	vector<vector<int>> dist(H + 1, vector<int>(W + 1, INF));

	// 開始位置で初期化
	queue<P> que;
	que.push(P{sx, sy});
	dist[sx][sy] = 0;

	while (que.size()) {
		P now = que.front();
		que.pop();
		if ((now.first == gx)&&(now.second == gy)) {
			break;
		}
		for (int i = 0; i < 4; i++) {
			int xNext = now.first + step[i][0];
			int yNext = now.second + step[i][1];
			if (!((0 <= xNext && xNext < H) && (0 <= yNext && yNext < W))) {
				continue;
			}
			char nextPos = HW[xNext][yNext];
			if ((dist[xNext][yNext] == INF)&&(HW[xNext][yNext] != '#')) {
				dist[xNext][yNext] = dist[now.first][now.second] + 1;
				que.push(P{xNext, yNext});
			}
		}
	}

	return dist[gx][gy];
}

// メイン
int main()
{
	// 入力
	cin >> H >> W;
	REP(i, H) REP(j, W) cin >> HW[i][j];

	// dfs
	int ans = 0;
	REP(i, H) {
		REP(j, W) {
			REP(k, H) {
				REP(l, W) {
					if ((i != k) || (j != l)) {
						if ((HW[i][j] == '.') && (HW[k][l] == '.')) {
							int res = bfs(i, j, k, l);
							if (res != INF) {
								ans = max(ans, res);
							}
						}
					}
				}
			}
		}
	}

	// 結果
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

ll n,k;
vector<ll>a,f;

// index が条件を満たすかどうか
bool isOK(ll c) {
    ll res = 0;
    rep(i,n){
        ll now = c/f[i];
        if(now>=a[i])continue;
        res += a[i]-now;
    }
    if(res<=k)return true;
    else return false;
}
// 汎用的な二分探索のテンプレ
ll binary_search() {
    ll ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    ll ok = (ll)1e12+5; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;

        if (isOK(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
    cin >> n >> k;
    a.resize(n);
   rep(i,n)cin>>a[i];
   f.resize(n);
   rep(i,n)cin>>f[i];
   sort(a.begin(),a.end());
   sort(f.rbegin(),f.rend());
   ll x = binary_search();
   cout << x << endl;
    return 0;
}


Measured memory_bytes: 6408
import java.util.*;

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

        int N = sc.nextInt();
        int L = sc.nextInt();

        int[] tastes = new int[N];
        int tasteSum = 0;
        for (int i=0; i<N; i++) {
            tastes[i] = L + i;
            tasteSum += L + i; 
        }

        int absMin = 101;
        int min = 0;
        for (int taste : tastes) {
            if (Math.abs(taste)  < absMin) {
                absMin = Math.abs(taste);
                min = taste;
            }
        }

        System.out.println(tasteSum - min);
    }
}



Measured memory_bytes: 23764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_047
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[,] cnts = new int[20, 20];
            long res = 0;
            for(int i = 0; i < n; i++)
            {
                int decimalCnt = -1;
                long val = 0;
                string valS = Read();
                for(int j = 0; j < valS.Length; j++)
                {
                    if (valS[j] == '.')
                    {
                        decimalCnt = 0;
                    }
                    else
                    {
                        if (decimalCnt >= 0)
                        {
                            decimalCnt++;
                        }
                        val = val * 10 + (valS[j] - '0');
                    }
                }
                if (decimalCnt < 0)
                {
                    decimalCnt++;
                }
                while (decimalCnt < 9)
                {
                    val *= 10;
                    decimalCnt++;
                }
                int twoI = 0;
                while (val % 2 == 0)
                {
                    val /= 2;
                    twoI++;
                }
                int fiveI = 0;
                while (val % 5 == 0)
                {
                    val /= 5;
                    fiveI++;
                }

                twoI = Min(twoI, 18);
                fiveI = Min(fiveI, 18);
                for(int j = 18 - twoI; j < 20; j++)
                {
                    for(int k = 18 - fiveI; k < 20; k++)
                    {
                        res += cnts[j, k];
                    }
                }

                cnts[twoI, fiveI]++;
            }

            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 37584
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stack>
#include <stdio.h>
#include <ios>     // std::left, std::right
#include <iomanip>
using namespace std;

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

const int inf = 1001001000;
//const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int digitlen(long long i){
    long long t = i;
    int count = 0;
    while(t){
        count += 1;
        t /= 10;
    }
    return count;
}

vector<int> cumsum(vector<int> arr){
    vector<int> ret;
    int l = arr.size();
    ret.push_back(arr[0]);
    for(int i = 1; i < l; i++){
        ret.push_back(ret[i-1] + arr[i]);
    }
    return ret;
}

vector<int> eratosthenes(int n){
    int arr[n+1];
    rep(i,0,n+1){
        arr[i] = 1;
    }
    arr[0] = 0; arr[1] = 0;
    for(int i = 2; i < n; i++){
        if(arr[i]==1){
            for(int j = 2*i; j < n+1; j+=i){
                arr[j] = 0;
            }
        }
    }
    
    vector<int> ret;
    for(int i = 2; i<n+1; i++){
        if(arr[i] == 1){
            ret.push_back(i);
        }
    }
    return ret;

}


int main(){
    vector<int>arr;
    arr.push_back(6);
    rep(i,1,45000){
        arr.push_back(7*i + 1);
        arr.push_back(7*i + 6);
    }
    vector<int> primes;
    primes.push_back(6);
    primes.push_back(8);

    for(int i = 2; i < arr.size(); i++){
        bool isprime = true;
        int j = 0;
        while(primes[j] * primes[j] <= arr[i]){
            if(arr[i] % primes[j] == 0){
                isprime = false;
                break;
            }else{
                j ++;
            }
        }
        if(isprime){
            primes.push_back(arr[i]);
        }
    }

    while(true){
        int n;
        cin >> n;
        if(n == 1){
            return 0;
        }
        cout << n << ":";
        for(auto e:primes){
            if(e > n) break;

            if(n%e == 0) cout << " " << e;
        }
        cout << endl;
    }

}




Measured memory_bytes: 3412
sx,sy,tx,ty = map(int,input().split())
ans = []

dx = tx - sx
dy = ty - sy
for _ in range(dx):
    ans.append('R')
for _ in range(dy):
    ans.append('U')
for _ in range(dx):
    ans.append('L')
for _ in range(dy):
    ans.append('D')
dx = tx - sx + 1
dy = ty - sy + 1
ans.append('D')
for _ in range(dx):
    ans.append('R')
for _ in range(dy):
    ans.append('U')
ans.append('L')
ans.append('U')
for _ in range(dx):
    ans.append('L')
for _ in range(dy):
    ans.append('D')
ans.append(('R'))
print(''.join(ans))

Measured memory_bytes: 9156
from heapq import heappop, heappush
N, K = map(int, input().split())
KMAX = 10 ** 5 + 1
TD = []
for _ in range(N):
    t, d = map(int, input().split())
    TD.append((d, t))

TD.sort(reverse=True)

pioneer = []
successor = []
appear = [False] * KMAX
cnt = 0
nsp = 0  # num of species
base = 0
best = []

for td in TD:
    d, t = td
    if cnt < K:
        heappush(successor if appear[t] else pioneer, (d, t))
        nsp += 0 if appear[t] else 1
        appear[t] = True
        base += d
        cnt += 1
        if cnt == K:
            heappush(best, -(base + nsp ** 2))
        continue
    if not successor:
        break
    if appear[t]:
        continue
    cd, ct = heappop(successor)
    appear[t] = True
    heappush(pioneer, (d, t))
    base += (d-cd)
    nsp += 1
    heappush(best, -(base + nsp ** 2))

print(-heappop(best))


Measured memory_bytes: 24448
#include "bits/stdc++.h"
using namespace std;

int main(){
    int a,b,c;
    cin>> a>>b>>c;
    int num=0;
    if(a*c<=b){
        num=c;
    }else{
        num = b/a;
    }
    cout<<num<<"\n";
    return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define             ll  long long
#define            ull  unsigned long long
#define            P_B  push_back
#define            M_P  make_pair
#define         DBG(x)  printf("%s %d\n", #x, x)
#define       DBGLL(x)  printf("%s %lld\n", #x, x)
#define         SCI(x)  scanf("%d",&x)
#define         SCD(x)  scanf("%lf",&x)
#define         SCS(x)  scanf("%s",x)
#define         CLR(x)  memset(x, 0, sizeof(x))
#define        CLRN(x)  memset(x, -1, sizeof(x))
#define        SCLL(x)  scanf("%lld", &x)
#define      FOR(i, n)  for(int i = 0; i < n; i++)
#define  FORR(i, m, n)  for(int i = m; i < n; i++)
#define     SCI2(m, n)  scanf("%d%d", &m, &n)
#define  SCI3(m, n, o)  scanf("%d%d%d",&m, &n, &o)
#define     SCD2(m, n)  scanf("%lf%lf",&m,&n)
#define  SCD3(m, n, o)  scanf("%lf%lf%lf",&m,&n,&o)
#define    SCLL2(m, n)  scanf("%lld%lld", &m, &n)
#define SCLL3(m, n, o)  scanf("%lld%lld%lld",&m, &n, &o)
#define             vi  vector<int>
#define            vii  vector<pair<int, int> >
#define            vll  vector<pair<ll, ll> >
#define            Mod  1000000007
#define            INF  1000000000
 

int main()
{
	int n, m;
	SCI2(n, m);
	int dp[n+1][m+1];
	CLR(dp);
	dp[0][1] = 1;
	FORR(i, 1, n+1){
		FORR(j, 1, m+1){
			char ch;
			scanf(" %c", &ch);
			if(ch == '#') dp[i][j] = -1;
		}
	}
	FORR(i, 1, n+1){
		FORR(j, 1, m+1){
			if(dp[i][j] != -1){
				if(dp[i-1][j] != -1) dp[i][j] += dp[i-1][j];
				dp[i][j] %= Mod;
				if(dp[i][j-1] != -1) dp[i][j] += dp[i][j-1];
				dp[i][j] %= Mod;
			}
		}
	}
	if(dp[n][m] == -1) dp[n][m] = 0;
	printf("%d\n", dp[n][m]);
}

Measured memory_bytes: 4096
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 400 + 47;
const int MAX1 = 1000 * 100 + 47;

int A[MAX1];
int B[MAX1];
int U[MAX][MAX];
int BAD[MAX];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	FOR(i, 0, m)
	{
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	FOR(i, 0, n)
	{
		U[i][i] = 1;
		RFOR(j, m, 0)
		{
			int a = A[j];
			int b = B[j];
			if (U[i][a] && U[i][b])
			{
				BAD[i] = 1;
				break;
			}

			if (U[i][a])
			{
				U[i][b] = 1;
				continue;
			}

			if (U[i][b]) U[i][a] = 1;
		}
	}

	int ans = 0;
	FOR(i, 0, n)
	{
		if (BAD[i]) continue;

		FOR(j, i + 1, n)
		{
			if (BAD[j]) continue;
			bool ok = true;
			FOR(k, 0, n)
			{
				if (U[i][k] && U[j][k])
				{
					ok = false;
					break;
				}
			}

			if (ok) ans++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 1792
A1=[["0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0"]]
A2=[["0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0"]]
A3=[["0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0"]]
A4=[["0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0"],["0","0","0","0","0","0","0","0","0","0"]]
N=int(input())
for j in range(N):
    b,f,r,v=map(int,input().split())
    if b==1:
        A1[f-1][r-1]=str(v+int(A1[f-1][r-1]))
    elif b==2:
        A2[f-1][r-1]=str(v+int(A2[f-1][r-1]))
    elif b==3:
        A3[f-1][r-1]=str(v+int(A3[f-1][r-1]))
    else:
        A4[f-1][r-1]=str(v+int(A4[f-1][r-1]))
for i in range(3):
    m=" "+" ".join(A1[i])
    print(m)
print("#"*20)
for i in range(3):
    m=" "+" ".join(A2[i])
    print(m)
print("#"*20)
for i in range(3):
    m=" "+" ".join(A3[i])
    print(m)
print("#"*20)
for i in range(3):
    m=" "+" ".join(A4[i])
    print(m)



Measured memory_bytes: 5640
#include<stdio.h>


int main()
{
	char X, Y;
	int x, y;

	scanf("%c", &X);
	scanf("%c", &Y);
	scanf("%c", &Y);

	if (X == 'A')
		x = 10;
	if (X == 'B')
		x = 11;
	if (X == 'C')
		x = 12;
	if (X == 'D')
		x = 13;
	if (X == 'E')
		x = 14;
	if (X == 'F')
		x = 15;

	if (Y == 'A')
		y = 10;
	if (Y == 'B')
		y = 11;
	if (Y == 'C')
		y = 12;
	if (Y == 'D')
		y = 13;
	if (Y == 'E')
		y = 14;
	if (Y == 'F')
		y = 15;

	if (x < y)
		printf("<");
	else if (x == y)
		printf("=");
	else
		printf(">");

	return 0;
}

Measured memory_bytes: 128
import itertools
N = int(input())
s = [0] * N
not10 = []
for i in range(N):
    s[i] = int(input())

SUM = sum(s)
if SUM % 10 != 0:
    print(SUM)
else:
    for i in range(N):
        if s[i] % 10 != 0:
            not10.append(s[i])
    not10.sort()
    if len(not10) == 0:
        print(0)
    else:
        print(SUM - not10[0])


Measured memory_bytes: 3060
#include<iostream>
#include<map>
#include<algorithm>

using namespace std;

const int maxn = 1e5;

map<int,int> nindex;
int a[maxn];

int main(){
	int n;
	cin >> n;
	
	for(int i = 0;i < n;i++){
		cin >> a[i];
		nindex[a[i]] = i;
	}
	
	sort(a,a+n);
	int e = 0;
	for(int i = 0;i < n;i++){
		int ind = nindex[a[i]] % 2;
		int rank = i % 2;
		if(ind != rank) e++;
	}
	
	int ans = e / 2;
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5376
n = int(input())
p_list = list(map(int, input().split()))

default_list = list(range(1, n + 1))

diff = 0
for i in range(n):
    if p_list[i] != default_list[i]:
        diff += 1

if diff == 0 or diff == 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
import java.util.Scanner;

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

        int n = sc.nextInt();
        int r = sc.nextInt();

        while(n != 0 || r != 0) {

            int[] card = new int[n + 1];

            card[0] = 0;

            for (int i = n; i > 0; i--)
                card[i] = i;

            for (int i = 0; i < r; i++) {
                int[] suffledCard = new int[n + 1];
                for (int l = n; l > 0; l--)
                    suffledCard[l] = l;
                suffledCard[0] = 0;

                int p = sc.nextInt();
                int c = sc.nextInt();
                int k = n;

                for (int j = n - (p - 1); j > n - (c + p - 1); j--)
                    suffledCard[k--] = card[j];
                for (int j = n; j > n - (p - 1); j--)
                    suffledCard[k--] = card[j];
                for (int j = n - (c + p - 1); j > 0; j--)
                    suffledCard[k--] = card[j];

                card = suffledCard;
            }

            System.out.println(card[n]);

            n = sc.nextInt();
            r = sc.nextInt();
        }

        sc.close();
    }
}


Measured memory_bytes: 37528
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

ll a,b,n;
ll f(ll x){
  return ((a*x)/b) - a*(x/b);
}

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  cin>>a>>b>>n;

  if(b-1<=n){
    cout<<f(b-1)<<ENDL;
  }else{
    cout<<f(n)<<ENDL;
  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>
#include <regex>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		vs ns(n),ms(m);
		vi ps(n);
		rep(i,n) cin>>ns[i]>>ps[i];
		rep(i,m) cin>>ms[i];
		
		rep(i,n) replace(all(ns[i]),'*','.');
		
		int res=0;
		rep(i,n){
			regex r(ns[i]);
			rep(j,m)
				if(regex_match(ms[j],r))
					res+=ps[i];
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1320
import java.util.Scanner;
public class Main {
	static int[]l;
	static int min = 1000000000;
	static int N, A, B, C;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		A = sc.nextInt();
		B = sc.nextInt();
		C = sc.nextInt();
		l = new int[N];
		for(int i = 0; i < N; i++) {
			l[i] = sc.nextInt();
		}
		dfs(0, 0, 0, 0, 0);
		System.out.println(min);
	}
	static void dfs(int n, int a, int b, int c, int comb) { //深さ優先探索
		if(n == N) { //探索木の底に行き着いた時
			if(a == 0 || b == 0 || c == 0) {
				return;//a目標,b目標,c目標に一本も用いない場合のコスト計算を省く
			}
			int cost = Math.abs(A - a) + Math.abs(B - b) + Math.abs(C - c); //+-どっちでも1mpなので長さの差がコスト
			cost += comb - 30;  //無と結合しているとみなして設けた最小結合コスト30を引く
			min = Math.min(min, cost);
			return;
		}
		dfs(n + 1, a, b, c, comb); //d:捨てる
		dfs(n + 1, a + l[n], b, c, comb + 10);//a 
		dfs(n + 1, a, b + l[n], c, comb + 10);//b
		dfs(n + 1, a, b, c + l[n], comb + 10);//c
		//一つ一つが再帰的に最下層まで行く
	}
}

Measured memory_bytes: 22208
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M, ans = 0;
vector <int> Graph[int(1e5 + 5)];
int DP[int(1e5 + 5)];

int Solve(int node){
  if (DP[node] != -1) return DP[node];

  int res = 0;
  for (int i = 0; i < Graph[node].size(); i++){
    int next = Graph[node][i];
    res = max(res, Solve(next) + 1);
  }
  return DP[node] = res;
}

int main(){
  scanf("%d%d", &N, &M);
  fill(DP, DP + N + 1, -1);
  for (int i = 0; i < M; i++){
    int X, Y; scanf("%d%d", &X, &Y);
    Graph[X].push_back(Y);
  }
  for (int i = 1; i <= N; i++) ans = max(ans, Solve(i));
  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

void main_()
{
    ll N;
    vector<ll> ss;
    cin >> N;
    copy_n(istream_iterator<ll>(cin), N, back_inserter(ss));

    auto total = accumulate(begin(ss), end(ss), 0LL);

    // 総計が10の倍数でないならそれが最大値
    if (total % 10 != 0) {
        cout << total << endl;
        return;
    }

    // 総計が10の倍数なら、10の倍数ではないスコアのうち最小のものを引いたのが最大値
    auto notx10_end = partition(begin(ss), end(ss), [](ll a) { return a % 10 != 0; });

    if (notx10_end == ss.begin()) {
        // 10の倍数のスコアしか無いので0
        cout << 0 << endl;
        return;
    }

    auto notx10_min = *min_element(begin(ss), notx10_end);
    cout << total - notx10_min << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256