akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  for(int i = 0; i < N; i++) {
    cin >> C.at(i);
    for(int j = 0; j < M ; j++) {
      cin >> A.at(i).at(j);
    }
  }
  
  int total = 1001001001;
  for(int i = 0; i < (1<<N); i++) {
    int cost = 0;
    vector<int> perf(M);
    for(int j = 0; j < N; j++) {
      if((i>>j)&1) {
        cost += C.at(j);
        for(int k = 0; k < M; k++) {
          perf.at(k) += A.at(j).at(k);
        }
      }
    }
    bool judge = true;
    for(int j = 0; j < M; j++) {
      if(perf.at(j) < X) {
        judge = false;
      }
    }
    if (judge) {
      total = min(total,cost);
    }
  }
  if(total == 1001001001) {
    total = -1;
  }
  cout << total << endl;
  return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, x;
    cin >> N >> x;

    vector<ll> A(N);

    REP(i, N){
        cin >> A[i];
    }

    ll ans = 0;
    if(A[0] > x){
        ans += A[0]-x;
        A[0] = x;
    }
    for(ll i=1; i<=N-1; i++){
        if(A[i-1]+A[i] > x){
            ll temp = A[i-1]+A[i] - x;
            ans += temp;
            A[i] = A[i] - temp;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4032
// ＡＢＣのＡ過去問を解くだけだよ
// フォント    x:小文字(ｘ)    X:大文字(Ｘ)
//                  +:プラス(＋)   &:アンド(＆)

#include <bits/stdc++.h>

using namespace std;

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

    int ret = a - 1;

    if (a <= b)
        ret++;

    cout << ret;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
int main(void){
    long long a,b,x;
    vector<int> v(3,0);
    cin>>v[0]>>v[1]>>v[2];
    sort(v.begin(),v.end());
    if(v[0]!=v[1]) cout<<v[0]<<endl;
    else cout<<v[2]<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
def main():
    S = input()
    Q = int(input())
    ans = deque(S)
    switch = 1
    count = 0

    for q in range(Q):
        T, *arg = input().split()
        T = int(T)

        if T == 1:
            count += 1
            if switch == 1:
                switch = 2
            elif switch == 2:
                switch = 1
        else:
            if switch == 1:
                if int(arg[0]) == 1:
                    ans.appendleft(arg[1])
                else:
                    ans.append(arg[1])
            else:
                if int(arg[0]) == 1:
                    ans.append(arg[1])
                else:
       
                    ans.appendleft(arg[1])

    if count % 2 == 0:
        print("".join(ans))
    else:
        ans.reverse()
        print("".join(ans))
if __name__ == "__main__":
    main()

Measured memory_bytes: 8556
#include <iostream>
#include <algorithm>
using namespace std;
#define MXN 100010
const int inf = 1000000000;
int a[MXN], b[MXN], c[MXN], dp[3][MXN];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int N; cin>>N;
	for(int i=1; i<=N; i++) cin>>a[i]>>b[i]>>c[i];

	for(int i=1; i<=N; i++)
	{
		dp[0][i] = max(dp[1][i-1], dp[2][i-1])+a[i];
		dp[1][i] = max(dp[0][i-1], dp[2][i-1])+b[i];
		dp[2][i] = max(dp[0][i-1], dp[1][i-1])+c[i];
	}
	cout << max(dp[0][N], max(dp[1][N], dp[2][N])) << '\n';
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	ll x, y, z, k;
	cin >> x >> y >> z >> k;

	vector<ll> a(x);
	for (auto &v : a) cin >> v;
	sort(begin(a), end(a), greater<ll>());

	vector<ll> b(x);
	for (auto &v : b) cin >> v;
	sort(begin(b), end(b), greater<ll>());

	vector<ll> c(x);
	for (auto &v : c) cin >> v;
	sort(begin(c), end(c), greater<ll>());


	vector<ll> ab;
	for (int i = 0; i < x; i++) {
		for (int j = 0; j < y; j++) {
			ab.push_back(a[i] + b[j]);
		}
	}
	sort(begin(ab), end(ab), greater<ll>());

	vector<ll> abc;
	for (int i = 0; i < (int)min(k, (ll)ab.size()); i++) {
		for (int j = 0; j < (int)c.size(); j++) {
			abc.push_back(ab[i] + c[j]);
		}
	}
	sort(begin(abc), end(abc), greater<ll>());


	for (int i = 0; i < (int)abc.size(); i++) {
		if (i + 1 > k) {
			break;
		}

		cout << abc[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 43240
#include <cstdio>

int main() {
    char str[110];
    scanf("%s",str);
    int c=0;
    bool s= false;
    for(int i=0;str[i]!='\0';i++) {
        if (str[i]=='C') c=1;
        if (c==1&&str[i]=='F') s=true;
    }
    
    if(s) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
    int n;
    int a=0, b=0;
    cin >> n;
    a=n;
    while(a!=0)
    {
        b+=a%10;
        a/=10;
    }
    if(n%b==0)
        cout << "Yes\n";
    else
        cout << "No\n";
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BAroundSquare {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    ll n;
	    in >> n;
	    ll res = 0;
	    for(int i=1; i*i<=n; i++){
            res = i*i;
	    }
	    out << res << endl;
	}
};


int main() {
	BAroundSquare solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int k,a,b,c;
int main(){
	cin>>k>>a>>b;
	for(int i=0;;i++){
		c=k*i;
		if(a<=c&&b>=c){
			cout<<"OK";
			return 0;
		}
		else{
			if(a>c) continue;
			if(b<c){
				cout<<"NG";
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3620
import sys

def search(p, a):
  lo = 0
  hi = len(a)-1
  while lo <= hi:
    mid = lo + (hi-lo)//2
    if p == a[mid]:
      return True
    elif p < a[mid]:
      hi = mid-1
    else:
      lo = mid+1
  return False

X, n = list(map(int, sys.stdin.readline().rstrip().split(' ')))
if n == 0:
  print(X)
else:
  a = list(map(int, sys.stdin.readline().rstrip().split(' ')))
  i = 1
  m = 1

  a = sorted(a)
  if not search(X, a):
    print(X)
  else:
    while True:
      m *= -1
      if not search(X+m, a):
        print(X+m)
        break
      i += 1
      if i % 2 == 1:
        m += 1


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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    vector<int> q(n);
    rep(i,n) cin >> q[i];
    vector<int> a(n);
    rep(i,n) a[i] = i+1;
    map<vector<int>,int> mp;

    do{
        mp[a] = mp.size();
    }while(next_permutation(a.begin(),a.end()));


    int ans = abs(mp[p]-mp[q]);
    cout << ans << endl;

}

Measured memory_bytes: 5248
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    long K = Long.parseLong(sc.next());
    long ans = 0;
    long ans1, ans2, s1, s2;
    long add = 1;
    long count = 0;
    boolean flag = true;
    int times = 9;
    while (count < K) {
      ans1 = ans + add;
      s1 = 0;
      String a1 = String.valueOf(ans1);
      for (int i = 0; i < a1.length(); i++) {
        s1 += Long.valueOf(String.valueOf(a1.charAt(i)));
      }
      ans2 = ans1 + add;
      s2 = 0;
      String a2 = String.valueOf(ans2);
      for (int i = 0; i < a2.length(); i++) {
        s2 += Long.valueOf(String.valueOf(a2.charAt(i)));
      }
      if (ans2 * s1 - ans1 * s2 < 0) {
        add *= 10;
        flag = true;
        continue;
      }
      if (flag) {
        times = 9;
      } else {
        times = 10;
      }
      String a = String.valueOf(ans + add);
      for (int i = 0; i < times; i++) {
        ans += add;
        String ai = String.valueOf(ans);
        if (a.length() != ai.length()) {
          ans-=add;
          break;
        }
        System.out.println(ans);
        count++;
        if (count >= K) {
          break;
        }
      }
      flag = false;

    }

  }
}

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

int main()
{
    string s,t;
    cin>>s>>t;

    int v=0;
    for(int i=0;i<3;i++)
        if(s[i]==t[i])
            v++;
    
    cout<<v<<endl;

	return 0;
}


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

const int N = 1e5 + 5;
string s;

int mod = 1e9+7;
struct modular {
    int value;
    modular(long long v = 0) { value = v % mod; if (value < 0) value += mod;}
    modular(long long a, long long b) : value(0){ *this += a; *this /= b;}
    modular& operator+=(modular const& b) {value += b.value; if (value >= mod) value -= mod; return *this;}
    modular& operator-=(modular const& b) {value -= b.value; if (value < 0) value += mod;return *this;}
    modular& operator*=(modular const& b) {value = (long long)value * b.value % mod;return *this;}
    //其他函数调用mexp(modular(10),3);
    friend modular mexp(modular a, long long e) {
        modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
        return res;
    }
    friend modular inverse(modular a) { return mexp(a, mod - 2); }
    modular& operator/=(modular const& b) { return *this *= inverse(b); }
    friend modular operator+(modular a, modular const b) { return a += b; }
    friend modular operator-(modular a, modular const b) { return a -= b; }
    friend modular operator-(modular const a) { return 0 - a; }
    friend modular operator*(modular a, modular const b) { return a *= b; }
    //除法只有在mod是素数可用;
    friend modular operator/(modular a, modular const b) { return a /= b; }
    friend ostream& operator<<(ostream& os, modular const& a) {return os << a.value;}
    friend istream& operator>>(istream& is, modular & a){long long value; is >> value;a.value = 0; a += value;  return is;}
    friend bool operator==(modular const& a, modular const& b) {return a.value == b.value;}
    friend bool operator!=(modular const& a, modular const& b) {return a.value != b.value;}
};


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




int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>s;
    int slen = s.length();
    
    modular cnt[3] = {0,0,0};
    
    int cnt_q = 0;
    for (int i = 0; i < slen; i++){
        if(s[i] == 'A'){
            cnt[0] += quick_pow(3, cnt_q, mod);
        }
        if(s[i] == 'B'){
            cnt[1] += cnt[0];
        }
        if( s[i] == 'C'){
            cnt[2] += cnt[1];
        }
        if(s[i]=='?'){
            modular cnt0 = cnt[0], cnt1 = cnt[1], cnt2 = cnt[2];
            cnt[0] = 3*cnt0 + quick_pow(3, cnt_q, mod);
            cnt[1] = 3*cnt1 + cnt0;
            cnt[2] = 3*cnt2 + cnt1;
            cnt_q += 1;
        }
    }
    

    cout<<cnt[2]<<endl;
    
    
    
    return 0;
}



Measured memory_bytes: 512
N, M = map(int, input().split(" "))

maxL=0
minR=N

for i in range(M):
    L, R = map(int, input().split(" "))
    
    if minR < L or R < maxL:
        print("0")
        exit()
    
    maxL=max(maxL, L)
    minR=min(minR, R)


print(minR-maxL+1)

Measured memory_bytes: 43736
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int MOD;
int main(){
	int n,m;
	cin>>n>>m;
	vs in(n);
	rep(i,n)cin>>in[i];
	int out=0;
	while(1){
		bool h=false;
		rep(i,n)rep(j,m)if(in[i][j]=='.'){
			vi find(26,-1);
			rep(k,4){
				int x=i,y=j;
				while(0<=x&&x<n&&0<=y&&y<m&&in[x][y]=='.')x+=dx[k],y+=dy[k];
				if(0<=x&&x<n&&0<=y&&y<m){
					int t=in[x][y]-'A';
					if(find[t]==-1)find[t]=x*m+y;
					else{
						h=true;
						out+=2;
						in[x][y]='.';
						in[find[t]/m][find[t]%m]='.';
						find[t]=-1;
					}
				}
			}
		}
		if(!h)break;
	}
	cout<<out<<endl;
}

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

#define ll  int
#define intmax INT_MAX
#define pi 3.14159265358979323846
#define ff first 
#define ss second
#define pb push_back
#define watch(x) cerr<<(#x)<<"  "<<x<<"\n";
const int MOD=998244353;
const int MAXN = 3e5+4;
int dp[MAXN],a[MAXN];

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

int n,k; cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
fill(dp+1,dp+n+1,intmax);
for(int i=1;i<=k;i++)
dp[i]=abs(a[1]-a[i]);
for(int i=k+1;i<=n;i++){
	for(int j=1;j<=k;j++)
	dp[i]=min(abs(a[i]-a[i-j])+dp[i-j],dp[i]);
}

cout<<dp[n]<<"\n";


return 0;
}


Measured memory_bytes: 4428
s=list(input())
num=(len(s)-2)//2
def moji(s): #偶文字列か調べる
    c=0
    half=len(s)//2
    for i in range(half):
        if s[i]!=s[i+half]:
            c=1
            break
    return c

exit=0
for i in range(num):
    del s[-1]
    del s[-1]
    check=moji(s)
    if check==0: #偶文字列の場合
        exit=1
        break
print(len(s))
#print(len(s) if exit==1 else 1)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int search(int *left, int *right, int key) {
	--right;
	while(left<=right) {
		int *mid = left +(right-left)/2;
		if(*mid==key) return 1;
		else if(key<*mid) {
			right=mid-1;
		} else {
			left=mid+1;
		}
	}
	return 0;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	int s[100000];
	int q, t;
	int c=0;
	cin>>n;
	for(int i=0; i<n; i++) cin>>s[i];
	cin>>q;
	for(int i=0; i<q; i++) {
		cin>>t;
		c+=search(s, s+n, t);
	}
	cout<<c<<'\n';
	return 0;
}



Measured memory_bytes: 3516
import Data.Functor ((<$>))
import Text.Printf (printf)

main :: IO ()
main = do
  [a,b] <- map (read :: String -> Int) . words <$> getLine
  let a' = fromIntegral a :: Double
      b' = fromIntegral b :: Double
  printf "%d %d %.5f\n" (a `div` b) (a `mod` b) (a' / b')



Measured memory_bytes: 3948
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace

getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

isin :: [String] -> [String] -> Int -> Int -> [()]
isin xs ys n m =
  [() |
    y <- [0..n-m],
    x <- [0..n-m],
    flip all [0..m-1] $ \yi ->
      flip all [0..m-1] $ \xi ->
      (xs!!(y+yi))!!(x+xi) == (ys!!yi)!!xi
      ]

main = do
  [n,m] <- getInts
  xs <- replicateM n getLine
  ys <- replicateM m getLine
  putStrLn $ if (isin xs ys n m) /= [] then "Yes" else "No"


Measured memory_bytes: 764
import math


n, k = map(int, input().split())

ans = max(0, (n-k+1)/n)
for i in range(1, n+1):
    if i >= k:
        break
    x = math.ceil(math.log2(k/i))
    ans += (1/n) * (1/2)**x
print(ans)


Measured memory_bytes: 9380
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;

    cin>>n;
    set< string > st;
    for(i=1;i<=n;i++){
        string my;
        cin>>my;
        st.insert(my);
    }
    int p=st.size();
    cout<<p<<endl;
    return 0;

}


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

int main(){
  int A, B, C, X;
  cin >> A >> B >> C >> X;

  int cnt = 0;
  for (int i = 0; i <= A; i++)
  {
    for (int j = 0; j <= B; j++)
    {
      for (int k = 0; k <= C; k++)
      {
        if (500 * i + 100 * j + 50 * k == X){
          cnt += 1;
        }
      }
      
    }
    
  }
  cout << cnt << endl;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  long double zr = 0.0;
  for(int i=1; i< min(K, N+1); i++){
    int j = i;
    long double p = 0.0;
    long double q = 1.0;
    while(j < K){
      q *= 0.5;
      p += q;
      j *= 2;
    }
    zr += p / (double) N;
  }

  cout << setprecision(20) << 1.0 - zr << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int V = 5010;
const int P = 1000000007;
char get() {
	static char buf[V], *p1 = buf, *p2 = buf;
	if (p1 == p2) {
		p2 = (p1 = buf) + fread(buf, 1, V, stdin);
		if (p1 == p2) return EOF;
	}
	return *p1++;
}
void Read(int &x) {
	x = 0; static char c;
	while (c > '9' || c < '0') c = get();
	while (c >= '0' && c <= '9') {
		x = x * 10 + c - '0'; c = get();
	}
}
void Add(int &x, int y) {
	(x += y) %= P;
}
int N, fac[V], c[V][V], f[V], w[2];
vector<int> G[V];
void Init(int n) {
	int i, j;
	w[0] = 1; w[1] = -1;
	fac[0] = 1; for (i = 1; i <= n; i++) Add(fac[i], 1LL * fac[i - 1] * i % P);
	c[0][0] = 1;
	for (i = 1; i <= n; i++) {
		c[i][0] = 1;
		for (j = 1; j <= i; j++) Add(c[i][j], c[i - 1][j] + c[i - 1][j - 1]);
	}
}
int siz[V], mxs[V];
void Dfs(int u, int fa) {
	siz[u] = 1;
	for (auto v : G[u]) {
		if (v == fa) continue;
		Dfs(v, u); siz[u] += siz[v];
		mxs[u] = max(mxs[u], siz[v]);
	}
	mxs[u] = max(mxs[u], N - siz[u]);
}
int main() {
	int i, j, u, v;
	Read(N); Init(N);
	for (i = 1; i < N; i++) {
		Read(u); Read(v);
		G[u].emplace_back(v); G[v].emplace_back(u);
	}
	Dfs(1, 0); int Rt = 0;
	for (i = 1; i <= N; i++)
		if (mxs[i] <= N / 2) {
			if (Rt) {
				printf("%lld\n", 1LL * fac[N / 2] * fac[N / 2] % P);
				return 0;
			}
			else Rt = i;
		}
	Dfs(Rt, 0); f[0] = 1;
	for (auto v : G[Rt]) {
		int Now = siz[v];
		for (i = N; i; i--)
			for (j = i - 1; ~j && i - j <= Now; j--)
				Add(f[i], 1LL * f[j] * c[Now][i - j] % P * c[Now][i - j] % P * fac[i - j] % P);
	}
	int Ans = 0;
	for (i = 0; i <= N; i++) {
		Add(Ans, (P + 1LL * w[i % 2] * f[i] % P * fac[N - i] % P) % P);
	}
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 97280
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
   int n,m,l;
 
   cin >> n >> m >> l;
  
   int a[n];
  
  for(int i = 0;i<n;i++){
     
    cin >> a[i];

   }
  
  int ans = 0;
  
  for(int i = 0;i<n;i++){
     
    int sum = 0;
    
    for(int k = 0;k<100000;k++){
      
      
      if(1 + k*a[i]>=m+1){
        break;
      }
      //cout << 1 + k*a[i];
      
      sum = sum + 1;
    }
    
    ans = ans + sum;
    
   }
  
   cout << ans + l << endl;
   
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <sstream>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <numeric>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;

	vector<double> niz(n);

	for (int i = 0; i < n; i++)
		cin >> niz[i];

	sort(niz.begin(), niz.end());

	double ans;
	for (int i = 0; i < n - 1; i++)
	{
		niz[i + 1] = (niz[i] + niz[i + 1]) / 2;
		ans = niz[i + 1];
	}

	cout << ans;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	map<int, int> ac, wa;
	long long AC = 0, WA = 0;
	for(int i = 0; i < m; i++){
		int p;
		string s;
		cin >> p >> s;
		if(s == "AC" && ac[p] == 0){
			ac[p]++;
			AC++;
			WA += wa[p];
		}
		if(s == "WA" && ac[p] == 0) wa[p]++;
	}
	cout << AC << " " << WA << endl;
	return 0;
}

Measured memory_bytes: 9600
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    while (1) {
        int n;
        scan(n);

        if (!n) return;

        auto ans = cntp(n);
        writeln(ans);
    }
}

int cntp(int n) {
    auto s = new bool[](2*n + 1);
    s[] = 1;
    s[0] = s[1] = 0;

    for (int p = 2; p*p <= 2*n; p++) {
        if (s[p]) {
            for (int q = p*p; q <= 2*n; q += p) {
                s[q] = 0;
            }
        }
    }

    int ans;
    
    foreach (i ; n + 1 .. 2*n + 1) {
        ans += s[i];
    }

    return ans;
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 6336
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
	double r, hankei,ensyuu;
	cin >> r;
	hankei = r*r*3.141592653589;
	ensyuu = 2 * 3.141592653589*r;
	printf("%.8f",hankei);
	cout << " ";
	printf("%.8f", ensyuu);

	return 0;
	
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(),(a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  while(cin >> N, N){
	VI xs(N);
	REP(i,N) cin >> xs[i];
	SORT(xs);
	
	int ans = 1e9;
	REP(i,N-1) ans = min(ans, xs[i+1]-xs[i]);
	
	cout << ans << endl;
  }

  return 0;
}

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

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

    string S;
    cin >> S;

    ll r = 0, g = 0, b = 0;
    rep(i,N) {
        if (S[i] == 'R') r++;
        else if (S[i] == 'G') g++;
        else b++;
    }

    ll sum = r * g * b;
    for (int i = 1; i < N; i++) {
        for (int j = i; j + i < N; j++) {
            if ((S[j - i] ^ S[j] ^ S[j + i]) == ('R' ^ 'G' ^ 'B')) sum--;
        }
    }

    cout << sum << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,M;cin>>A>>B>>M;
  vector<int> a(A);
  vector<int> b(B);
  for(int i=0;i<A;i++)cin>>a[i];
  for(int i=0;i<B;i++)cin>>b[i];
  int m=100000000;
  for(int i=0;i<M;i++){
    int x,y,c;cin>>x>>y>>c;
    x--;y--;
    m=min(a[x]+b[y]-c,m);
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  m=min(m,a[0]+b[0]);
  cout<<m<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  vector<int> m(5);
  int s=0;
  for(int i=0; i<5; i++){
    int ti;
    cin >> ti;
    s += ti-((ti-1)%10+1);
    m[i] = (ti-1)%10+1;
  }
  sort(m.begin(), m.end());
  int ss=0;
  for(int i=1; i<5; i++) ss += (m[i]+9)/10*10;
  cout << s+m[0]+ss << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define db double
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define ldb long double
#define clr(x) memset(x,0,sizeof(x))
#define count_bit(x) __builtin_popcount(x)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
const int size1 = 2e5+7;
const int size2 = 1e4;

//ll fact[size1];
 
ll pw(ll x,ll y,ll mod)
{
    if(y==0)return 1;
    ll p =pw(x,y/2,mod);
    p = (p*p)%mod;
    if(y%2==1)p = (p*x)%mod;
    return p;
}
ll gcd(ll a,ll b)
{
	if(b==0)return a;
	a = a%b;
	return gcd(b,a);
}
// ll inverse(ll x,ll mod)
// {
//     return pw(x,mod-2,mod);
// }
// ll ncr(ll n,ll r,ll mod)
// {
//     ll num = fact[n];
//     ll den = (fact[r] * fact[n-r])%mod;
//     den = inverse(den,mod);
 
//     ll ans = (num*den)%mod;
//     return ans;
// }
// vector<ll> adj1[size1];
// vector<ll> adj[size1];
// ll d[size1];
// ll n,m;
// void dikstra(ll s)
// {
//     for(ll i=1;i<=n;i++)d[i]=1e9;
//     d[s] = 0;
//     priority_queue<pll, vector<pll>, greater<pll>> q;
//     q.push({0, s});
//     while(!q.empty())
//     {
//         ll v = q.top().ss;
//         ll d_v = q.top().ff;
//         q.pop();
//         if(d_v!=d[v])continue;
//         for(auto to:adj1[v])
//         {
//             ll len = 1;
//             if(d[v] + len < d[to])
//             {
//                 d[to] = d[v]+len;
//                 q.push({d[to],to});
//             }
//         }
//     }
// }
vector<ll> adj[size1];
ll vis[size1];
ll cnt;
void dfs(ll v)
{
    cnt = cnt + 1;
    vis[v] = 1;
    for(auto u:adj[v]){
        if(!vis[u]){
            dfs(u);
        }
    }
}
const ll mod = 1e9+7;
int main()
{
    //cout<<setprecision(12)<<fixed;
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 	
 	
    ll T;
    //cin>>T;
    T = 1;
    ll cas=1;
    while(T--)
    {
        //cout<<"Case #"<<cas<<": ";cas++;
        ll n,m;cin>>n>>m;
        clr(vis);

        for(ll i=0;i<m;i++){
            ll x,y;cin>>x>>y;
            adj[x].pb(y);
            adj[y].pb(x);
        }

        ll ans = 0;
        for(ll i=1;i<=n;i++){
            if(!vis[i]){
                cnt = 0;
                dfs(i);
                ans = max(ans,cnt);
            }
        }
        cout<<ans<<endl;

    }
}


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

struct UnionFind{
    vector<int> par;
    vector<int> sz;
    UnionFind(int n){
        par.resize(n);
        sz.resize(n, 1);
        for(int i = 0; i < n; i++) par[i] = i;
    }
    int root(int x){
        if(x == par[x]) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(sz[x] < sz[y]) swap(x, y);
        sz[x] += sz[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
};

struct WeightedUnionFind{
    vector<int> par;
    vector<int> sz;
    vector<int> diff_weight;
    WeightedUnionFind(int n){
        par.resize(n);
        sz.resize(n, 1);
        diff_weight.resize(n);
        for(int i = 0; i < n; i++) par[i] = i;
    }
    int root(int x){
        if(x == par[x]) return x;
        int r = root(par[x]);
        diff_weight[x] += diff_weight[par[x]];
        return par[x] = r;
    }
    int weight(int x){
        root(x);
        return diff_weight[x];
    }
    int diff(int x, int y){
        return weight(y) - weight(x);
    }
    // weight(y) - weight(x) = w となるように merge する
    bool unite(int x, int y, int w){
        // x と y それぞれについて、 root との重み差分を補正
        w += weight(x) - weight(y);
        x = root(x); y = root(y);
        if(x == y) return false;
        if(sz[x] < sz[y]) swap(x, y), w = -w;
        sz[x] += sz[y];
        par[y] = x;
        // x が y の親になるので、x と y の差分を diff_weight[y] に記録
        diff_weight[y] = w;
        return true;
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
};

/*
verified
https://beta.atcoder.jp/contests/arc090/tasks/arc090_b
*/

int main(){
    int n, m;
    cin >> n >> m;
    WeightedUnionFind uf(n);
    bool f = true;
    for(int i = 0; i < m; i++){
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        if(!uf.same(l, r)){
            uf.unite(l, r, d);
        }else{
            if(uf.diff(l, r) != d) f = false;
        }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408
import heapq

N, M = map(int, input().split())
A = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(A)

for _ in range(M):
    tmp = heapq.heappop(A)
    heapq.heappush(A, tmp/2)

A = map(lambda x: int(x)*(-1), A)

print(sum(A))

Measured memory_bytes: 14180
import math
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
l = [A,B,C,D,E]
l_a = [A%10,B%10,C%10,D%10,E%10]
dif = 9
for j in l_a:
    if j == 0:
        pass
    else:
        if j <= dif:
            dif = j
ans = 0
for i in l:
    if i % 10 == 0:
        ans += i
    else:
        ans += i + (10 - i % 10)
if A%10==0 and B%10==0 and C%10==0 and D%10==0 and E%10==0:
    print(ans)
else:
    a = ans - (10 - dif)
    print(a)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main()
{
    char s[51][51];
    int h,w,i,j,con,aa,k,l;
    aa=0;

    for(i=0; i<=50; i++)
    {
        for(j=i; j<=50; j++)
        {
            s[i][j]=s[j][i]='.';
        }
    }
    scanf("%d%d",&h,&w);
    getchar();
    aa++;

    if(aa!=1) printf("\n");
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            scanf("%c",&s[i][j]);
        }
        getchar();
    }
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            if(s[i][j]!='#')
            {
                con=0;
                for(k=-1; k<=1; k++)
                {
                    for(l=-1; l<=1; l++)
                    {
                        if(s[i+k][j+l]=='#')
                            con++;
                    }
                }
                s[i][j]='0'+con;
            }
        }
    }
    for(i=1; i<=h; i++)
    {
        for(j=1; j<=w; j++)
        {
            printf("%c",s[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
(_,k,*h),*a=$<.map{|s|s.split.map &:to_i};x=s=0;p a.sort_by{|t,d|-d}.map{|t,d|h[t]=s+=(0>k-=1)?h[t]?0:d-($*.pop||9e9)+x+x+=1:h[t]?($*<<d;d):d+x+x+=1}.max

Measured memory_bytes: 13304
# https://atcoder.jp/contests/abc133/tasks/abc133_c
# C - Remainder Minimization 2019

l, r = list(map(int, input().split()))
count = 0
amari_list = []

for i in range(l, r+1):
    count_j = 0
    for j in range(i+1, r+1):
        amari_list.append(i * j % 2019)
        if count_j == 2019:
            break
        count_j += 1

    if count == 2019:
        break
    count += 1

ans = min(amari_list)
print(ans)


Measured memory_bytes: 149776
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>
#include <set>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
ll inf = ll(1e18);
using ll1d = vector<ll>;
using ll2d = vector<ll1d>;
using ll3d = vector<ll2d>;

void solve(istream &ccin = cin, ostream &ccout = cout) {

  string s;
  ccin >> s;
  ll ans = 0;
  if (s.size() % 2 == 0) {
    ll d = s.size() / 2;
    ll cnt = 0;
    rep(i, d) {
      if (s[d - i - 1] == s[d + i] and s[d + i] == s[d + i - 1]) ++cnt;
      else break;
    }
    ans = d + cnt;
  }else{
    ll d = s.size()/2;
    ll cnt = 0;
    REP(i, 1, d+1){
      if (s[d+i] == s[d-i] and s[d+i] == s[d+i-1]) ++ cnt;
      else break;
    }
    ans = d + 1 + cnt;
  }

  ccout << ans << endl;

}

int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

map<lint,int> p_factorization(lint n){
    map<lint,int> soinsu;
    for(int i=2;i<=sqrt(n);i++){
        while(n%i==0){
            n/=i;
            soinsu[i]++;
        }
    }
    if(n!=1)soinsu[n]++;
    return soinsu;
}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    bool pairwise=true;
    vector<int> vec(1000000);
    int n,x,tmp;cin>>n;
    cin>>tmp;
    map<lint,int> dic=p_factorization(tmp);
    for(auto p:dic){
        vec[p.first]=1;
    }
    for(int i=1;i<n;i++){
        cin>>x;tmp=__gcd(tmp,x);
        map<lint,int> dic=p_factorization(x);
        if(!pairwise)continue;
        for(auto p:dic){
            if(vec[p.first]==1){
                pairwise=false;
            }
            vec[p.first]=1;
        }
    }
    if(pairwise)cout<<"pairwise coprime"<<endl;
    else if(tmp==1)cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
}


Measured memory_bytes: 7108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String s2 = s.replace("x", "");
		if (!s2.equals(new StringBuilder(s2).reverse().toString())) {
			System.out.println(-1);
			return;
		}
		char[] t = s.toCharArray();
		int n = t.length;
		int p = 0;
		int q = n - 1;
		int ans = 0;
		while(p < q) {
			int left = 0;
			int right = 0;
			while(p < n && t[p] == 'x') {
				p++;
				left++;
			}
			while(q >= 0 && t[q] == 'x') {
				q--;
				right++;
			}
			if (p <= q) {
//				if (t[p] != t[q]) {
//					throw new RuntimeException();
//				}
				ans += Math.abs(left - right);
			}
			p++;
			q--;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 33948
#include<iostream>
using namespace std;
int main()
{
  int H, A;
  cin>>H>>A;
  int arr[A];
  int i, sum = 0;
  for(i=0; i< A; i++)
  {
    cin>>arr[i];
    sum = sum + arr[i];
  }
  if(sum < H)
    cout<<"No";
  else
    cout<<"Yes";
  return 0;
}

Measured memory_bytes: 640
import sys
import math
stdin = sys.stdin


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


def naa(N): return [na() for _ in range(N)]


def ns(): return stdin.readline().rstrip()  # ignore trailing spaces


A, B, H, M = na()

anglea = H * 30 + M * 0.5
angleb = M * 6

angle = abs(anglea - angleb)
if angle > 180:
    angle = 360 - angle

C2 = A * A + B * B - 2 * A * B * math.cos(math.radians(angle))

print(math.sqrt(C2))


Measured memory_bytes: 62664
import math
N=int(input())
x=[]
for _ in range(N):
  a,b=map(int,input().split())
  x.append([a,b])
l=0
for i in range(0,N):
  for j in range(i+1,N):
    l+=math.sqrt((x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2)
print(2*l/N)

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

using namespace std;


int main() {
   long long int i,j,k,m,n,a,b,r,x;

   cin >> a >> b >> n;

  // cette fonction est périodique
  // la valeur maximale est en x=min(B-1,N)


  x = min(b-1,n);
  cout << (a*x)/b << endl;


  return 0;
}


Measured memory_bytes: 3632
// package whatever; // don't place package name!

import java.io.*;
import java.util.*;

class Main{
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    String num = "";
    for(int i = 0; i < 3; i++)
      num += sc.next();
    int n = Integer.parseInt(num);
    if(n % 4 == 0) System.out.println("YES");
    else System.out.println("NO");
  }
}


Measured memory_bytes: 23764
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    ll A, B ,N; scanf("%lld %lld %lld", &A, &B, &N);
    if(B-1 <= N){
        printf("%lld\n", A * (B-1) / B);
        return 0;
    }
    printf("%lld\n", A * N / B - A * (N / B));
}

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

int main(){
    long long int n;
    cin >> n;
    n -= 1;

    vector<int> ans;
    while(n >= 0){
        ans.push_back(n % 26LL);
        n -= (n % 26LL) + 26;
        n /= 26LL;
    }
    reverse(ans.begin(), ans.end());
    int l = ans.size();
    for(int i=0; i<l; i++){
        cout << (char)('a' + ans[i]);
    }
    cout  << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>

using namespace std;

int main(int argc, char const *argv[])
{

    pair<int,int> Alice;
    pair<int,int> Bob;
    int ans=0;
    cin>>Alice.first>>Alice.second>>Bob.first>>Bob.second;

    if(Alice.first>Bob.first){
        ans=min(Bob.second,Alice.second)-Alice.first;
    }else{
        ans=min(Bob.second,Alice.second)-Bob.first;
    }

    if(ans<0)ans=0;

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


Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL n, k;
vector<int> g[101010];
const LL mod = 1e9 + 7;
int a, b;

LL bfs(int cur, int par){
    LL ret = 1LL;
    LL cnt = 2LL;
    if(par == -1)ret = k, cnt = 1LL;
    if(k < (int)g[cur].size())return 0;
    REP(i, (int)g[cur].size()){
        if(g[cur][i] == par)continue;
        ret *= (k - cnt);
        cnt++;
        ret %= mod;
    }
    REP(i, (int)g[cur].size()){
        if(g[cur][i] == par)continue;
        ret *= bfs(g[cur][i], cur);
        ret %= mod;
    }
    return ret % mod;
}

int main(){
    cin >> n >> k;
    REP(i, n - 1){
        cin >> a >> b;
        a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    cout << bfs(0, -1) << endl;
}


Measured memory_bytes: 11648
// AOJ ITP 1_6_A
#include<cstdio>
#define rep(i,a) for( int i = 0; i != (a); ++i )

int n, a[100];

int main()
{
	scanf( "%d", &n );
	rep( i, n )
		scanf( "%d", a+i );

	for( int i = n-1; i >= 0; --i )
		printf( "%d%c", a[i], i ? ' ' : '\n' );

	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint h, w;
    cin >> h >> w;
    // lint ret = (h / 2) * 2 * (w / 2) * 2 / 2;
    if (h == 1 || w == 1) {
        cout << 1 << "\n";
        return 0;
    }
    if (h % 2 == 0 || w % 2 == 0) {
        cout << h * w / 2 << "\n";
    } else {
        cout << (h * w + 1) / 2 << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
from fractions import gcd

N,M=map(int,input().split())
A=list(map(int,input().split()))

def lcm(a,b):
    return a*b//gcd(a,b)

def div2(a):
    ret=0
    while a:
        if a&1==0:
            a>>=1
            ret+=1
        else:
            break
    return ret

t=div2(A[0])
if t==0:
    print(0)
    exit()

for i in range(N):
    if div2(A[i])!=t:
        print(0)
        exit()
    A[i]>>=t
M>>=(t-1)

l=1
for i in range(N):
    l=lcm(l,A[i])

ans=M//l
ans=(ans+1)//2
print(ans)


Measured memory_bytes: 16228
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

typedef pair<int, pair<int, int>> edge;

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1LL); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};



class Kruskal {
private:
	UnionFind *uf;
	vector<edge> e;
public:
	vector<edge> mst;
	Kruskal(int N) { uf = new UnionFind(N); }
	void add(int x, int y, ll z);
	void run();
};



//----UnionFind-------------------------------
int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}

ll UnionFind::size(int x) {
	return -par[find(x)];
}

void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);

	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}

bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}



//----Kruskal-------------------------------
void Kruskal::add(int x, int y, ll z) {
	//x < y
	if (x > y) swap(x, y);
	e.push_back({ z,{x,y} });
}

void Kruskal::run() {
	sort(e.begin(), e.end());
	e.erase(unique(e.begin(), e.end()), e.end());
	for (auto x : e) {
		if (uf->same(x.second.first, x.second.second)) {
			continue;
		}
		else {
			mst.push_back(x);
			uf->unite(x.second.first, x.second.second);
		}
	}
}



signed main() {
	int x,y;
	cin >> x >> y;
	cout << max(
	{
		2 * x - 1,
		x + y,
		2 * y -1
	}
	)
	<< endl;
}

Measured memory_bytes: 256