akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,t=0;
	cin>>a;
	long long b=a;
	while(a)
	{
		t+=a%10;
		a/=10;
	}
	if(b%t==0) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/

/+---test
3
2 4 3
---+/
/+---test
12
100 104 102 105 103 103 101 105 104 102 104 101
---+/

void main(string[] args) {
  const N = readln.chomp.to!long;
  auto  A = readln.split.map!(to!long).array;

  long L = A.sum;

  long half = 0, halfi = -1;
  foreach (i; 0..N) {
    const x = half + A[i];
    if ((half - L/2).abs >= (x - L/2).abs) {
      half  = x;
      halfi = i;
    }
    if (x > L/2) break;
  }

  long ans;
  ans = L - min(L - half, half)*2;
  ans.writeln;
}


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

using namespace std;

int main()
{
    int n,m,c;
    cin >> n >> m >> c;

    vector<int> b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> b.at(i);
    }

    vector<vector<int>> a(n, vector<int>(m));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m;j++)
        {
            cin >> a.at(i).at(j);
        }
    }

    int count = 0;
    for (int i = 0; i < n; i++)
    {
        int sum = 0;
        for (int j = 0; j < m; j++)
        {
            sum += a.at(i).at(j) * b.at(j);
        }
        if (0 < sum + c)
        {
            count++;
        }
    }
    cout << count << endl;
}


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


int main(){
  for(int a=1;a<10;a++){
    for(int b=1;b<10;b++){
      cout << a << "x" << b << "=" << a*b <<endl;
    }    
  }
  
}


Measured memory_bytes: 3016
#include<stdio.h>
int main(void)
{
	int a,b,t;
	int ans;
	int n;
	
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&t);
	
	n = (t+0.5)/a;
	
	ans = n*b;
	
	printf("%d",ans);
	
	return 0;
}


Measured memory_bytes: 128
m=246912
p=[1]*m
p[0]=p[1]=0
for i in range(2,int(m**0.5)+1):
    if p[i]:
        for j in range(i*i,m,i):
            p[j]=0
while 1:
    n=int(input())
    if n==0:break
    print(sum(p[n+1:2*n+1]))

Measured memory_bytes: 10952
import java.util.Scanner;

class Main{

public static void main(String[] args) {
        Scanner scan = new Scanner (System.in);
        int n = scan.nextInt();
        int i;
        
        int Min = 1000000;
        int Max = -1000000;
        long Sum = 0; 
        
        for(i=0; i<n; i++){
        int a = scan.nextInt();
        
        if( a < Min ){
            Min = a;
        }
        
        if( a > Max ){
            Max = a;
        }
        
            Sum += a;
            
        }
        
        
        
        
        System.out.println(Min+" "+Max +" "+ Sum );
       
        
}
}
        
        
       
       
        
    









Measured memory_bytes: 41440
#include <stdio.h>
int main()
{
  /*H,Wを定義する*/
  int h, w ;
  int i, j ;

  /*H=W=0じゃない限り、プログラム進行する*/
  for(;;){
    scanf("%d %d",&h,&w);
    if (h==0 && w==0) break;
    for(i=1 ; i<=h ; i++){
      for(j=1 ; j<=w ; j++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0 ;
}


Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
ll power(ll x,ll y,ll p) 
{ 
    ll res=1;  
    x=x%p;
    while (y > 0) 
    { 
        if(y&1) 
            res=(res*x)%p; 
        y=y>>1;
        x=(x*x)%p;   
    } 
    return res; 
}
const ll L = 1e5 + 5;
ll w[101];
ll v[101];
ll dp[101][L];
ll rec(ll n,ll w1)
{
	if(dp[n][w1]!=-1)
		return dp[n][w1];
	if(n == 0)
	{
		if(w[0] <= w1)
			return dp[n][w1] = v[0];
		else
			return dp[n][w1] = 0;
	}
	if(w[n] <= w1)
	{
		dp[n-1][w1-w[n]] = rec(n-1,w1-w[n]);
		dp[n][w1] = v[n] + dp[n-1][w1-w[n]];
	}
	dp[n-1][w1] = max((ll)0,rec(n-1,w1));
	return dp[n][w1] = max(dp[n-1][w1],dp[n][w1]);
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll i,j,n,w1;
 	cin >> n >> w1;   
	for(i=0;i<=n;i++)
		for(j=0;j<=w1;j++)
			dp[i][j] = -1;
	for(i=0;i<n;i++)
		cin >> w[i] >> v[i];
	cout << rec(n-1,w1) << endl;
	return 0;
}

Measured memory_bytes: 79232
#include<stdio.h>

int main(void){
    int a,n,i,min = 1000000,max = -1000000;
    long int sum = 0;
    scanf("%d",&n);
    for(i=0;i < n;i++){
        scanf("%d",&a);
        sum+=a;
        if(min > a)
            min=a;
        if(max < a)
            max=a;
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}



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

    //組み合わせの数nCrを計算
    ll combi(ll n, ll r){
        ll num = 1;
        for(int i = 1; i <= r; i++){
            num = num * (n - i + 1) / i;
        }
        return num;
    }

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

  vector<int> data(N);
  for(int i =0;i<N;i++){
    cin >> data.at(i);
  }
  
//  for(int k=0;k<N;k++){
//    int count =0;
//    for(int i=0; i<N; i++){
//      if(i==k){ continue; }
//      
//      for(int j=i+1; j<N; j++){
//		if(j==k){continue;}
//        
//        if(data.at(i) == data.at(j)){
//          count++;
//        }
//      }
//    }
//    cout << count << endl;
//  }
  
  
  // 各Aiの出現数を記録
  vector<ll> dp(N);
  for(int i=0;i<N;i++){
    dp.at(data.at(i)-1) += 1;
  }
  
  // kを抜かなかった場合のcombination先に計算しておく
  ll C = 0;
  for(int i=0;i<N;i++){
    ll c = dp.at(i);
    if (c < 2) { continue; }
    C += combi(c, 2);
  }

  for(int k=0;k<N;k++){
    ll count = 0;
    ll t = dp.at(data.at(k) - 1);
    count = C - (t - 1);
    cout << count << endl;
  }

}


Measured memory_bytes: 4992
from collections import deque


def main():
    N, M = map(int, input().split())
    adj = [{} for _ in range(N+1)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        adj[a][b] = c
    points = [-float("inf")] * (N+1)
    q = deque([(1, 0, {})])
    while len(q):
        cur, point, visited = q.popleft()
        if point <= points[cur]:
            continue
        points[cur] = max(points[cur], point)
        nvisited = {v: visited[v] for v in visited}
        nvisited[cur] = point
        for nxt in adj[cur]:
            npoint = point + adj[cur][nxt]
            if nxt in nvisited and nvisited[nxt] < npoint:
                npoint = float("inf")
            q.append((nxt, npoint, nvisited))
    print(points[N])


if __name__ == "__main__":
    main()


Measured memory_bytes: 55660
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 100007
const ll inf=1e13+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();;
void sieve();
int main()
{
	//sieve();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(2);
	ll t=1;
	//cin>>t;
	for(ll i=1;i<=t;i++)
	solve();
	return 0;
}
ll w[100],val[100],dp[100][maxn],n,k;
void intl()
{
	for(ll i=0;i<maxn;i++)
	{
		for(ll j=0;j<100;j++)
		dp[j][i]=-1;
	}
}
ll go(ll pos,ll weight)
{
	if(weight<0)
	return -inf;
	if(pos>=n)
	return 0;
	if(dp[pos][weight]!=-1)
	return dp[pos][weight];
	
	ll ans=0;
	ans=max(go(pos+1,weight),go(pos+1,weight-w[pos])+val[pos]);
	return dp[pos][weight]=ans;
}
void solve()
{
	intl();
	ll cap;
	cin>>n>>cap;
	for(ll i=0;i<n;i++)
	cin>>w[i]>>val[i];
	cout<<go(0,cap);
}
	
	

		


Measured memory_bytes: 81724
/*
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
*/
#include <bits/stdc++.h>

#define rep(i,n)  for(int i=0; i<(n); i++)
using ll = long long;
using namespace std;

int main()
{
    int n,m;
    bool a = true;
    cin >> n >> m;
    vector<int> s(m);
    vector<int> c(m);
    rep(i,m){
        cin >> s[i] >> c[i];
        rep(j,i){
            if(s[i] == s[j] && s[i] != -1){
                if(c[i] != c[j]){
                    a = false;
                }else{
                    s[i] = -1;
                }
            }
        }
        if(n == 1){

        }else if(s[i] == 1 && c[i] == 0){
            a = false;
        }
    }
    /*
    cout << endl;
    rep(i,m){
        cout << s[i] << c[i] << endl;
    }
    */

    vector<int> ans(m);
    int b = 0;
    if(a){
        if(m == 0){
            if(n == 1){
                cout << 0;
            }else{
                cout << pow(10,n-1);
            }
        }else{
            rep(i,m){
                if(s[i] != -1){
                    ans[i] = c[i] * pow(10,n-s[i]);
                }
                b += ans[i];
            }
            if(b < pow(10,n-1)){
                if(n == 1){
                    cout << 0;
                }else{
                    cout << b + pow(10,n-1);
                }
            }else{
                cout << b;
            }
        }
    }else{
        cout << -1;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a < b)
    {
        cout << "a < b" << endl;
    }
    else if (a > b)
    {
        cout << "a > b" << endl;
    }
    else
    {
        cout << "a == b" << endl;
    }
}



Measured memory_bytes: 3108
h, w = map(int,input().split())
a = [input() for _ in range(h)]
l = []
ans = []
for i in a:
    if i == "."*w:continue
    l.append(i)
for i in zip(*l):
    if "".join(i) == "."*len(i):continue
    ans.append("".join(i))
for i in zip(*ans):
    print("".join(i))

Measured memory_bytes: 3064
import sys
pos=input()
N=len(pos)
flag=False
for i in range(0,N):
    if i %2==0:
        if not(pos[i]=='R' or pos[i]=='U' or pos[i]=='D'):
            flag=True
            break
    elif not(pos[i]=='L' or pos[i]=='U' or pos[i]=='D'):
        flag=True
        break

if(flag):
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll a[224];
signed main() {
	ll n,memo=0,ans=inf;
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n){
		while(a[i]%2==0){
			a[i]/=2;
			memo++;
		}
		ans=min(ans,memo);
		memo=0;
	}
	cout<<ans<<endl;
	ggr
}



Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 20;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

char ans[1050][1050];
void getans(int N, int M, int c1, int c2, int A, int B) {
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			if (ans[i][j] != '<') continue;
			if (c1 == A) continue;
			c1--;
			ans[i][j] = ans[i][j + 1] = '.';
		}
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= M; j++) {
			if (ans[i][j] != '^') continue;
			if (c2 == B) continue;
			c2--;
			ans[i][j] = ans[i + 1][j] = '.';
		}
	}
	printf("YES\n");
	for (int i = 1; i <= N; i++) printf("%s\n", ans[i]+1);
	exit(0);
}
int main() {
	int N, M, A, B, i, j;
	scanf("%d %d %d %d", &N, &M, &A, &B);
	if ((A + B) * 2 > N*M) return !printf("NO\n");

	for (i = 1; i <= N; i++) for (j = 1; j <= M; j++) ans[i][j] = '.';

	int c1 = 0, c2 = 0;
	for (i = 1; i <= (N / 2) * 2; i++) {
		for (j = 1; j <= (M / 2) * 2; j+=2) {
			ans[i][j] = '<';
			ans[i][j + 1] = '>';
			c1++;
		}
	}
	if (N % 2 == 1) for (i = 1; i <= (M / 2) * 2; i += 2) ans[N][i] = '<', ans[N][i + 1] = '>', c1++;
	if (M % 2 == 1) for (i = 1; i <= (N / 2) * 2; i += 2) ans[i][M] = '^', ans[i + 1][M] = 'v', c2++;
	
	if(c1 >= A && c2 >= B) getans(N, M, c1, c2, A, B);
	for (i = 1; i <= (N / 2) * 2; i += 2) {
		for (j = 1; j <= (M / 2) * 2; j += 2) {
			ans[i][j] = '^';
			ans[i][j + 1] = '^';
			ans[i + 1][j] = 'v';
			ans[i + 1][j + 1] = 'v';
			c1 -= 2;
			c2 += 2;
			if (c1 >= A && c2 >= B) getans(N, M, c1, c2, A, B);
		}
	}
	if (N != 1 && M != 1 && N % 2 && M % 2) {
		ans[N - 2][M - 2] = '^';
		ans[N - 2][M - 1] = '<';
		ans[N - 2][M] = '>';
		ans[N - 1][M - 2] = 'v';
		ans[N - 1][M - 1] = '.';
		ans[N - 1][M] = '^';
		ans[N][M - 2] = '<';
		ans[N][M - 1] = '>';
		ans[N][M] = 'v';
		c2--;
		c1++;
		if (c1 >= A && c2 >= B) getans(N, M, c1, c2, A, B);
		for (i = 1; i <= (N / 2) * 2; i += 2) {
			for (j = 1; j <= (M / 2) * 2; j += 2) {
				if (i == N - 2 && j == M - 2) continue;
				ans[i][j] = '<';
				ans[i][j + 1] = '>';
				ans[i + 1][j] = '<';
				ans[i + 1][j + 1] = '>';
				c1 += 2;
				c2 -= 2;
				if (c1 >= A && c2 >= B) getans(N, M, c1, c2, A, B);
			}
		}
	}
	return !printf("NO\n");
}

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

using namespace std;

int main(){
  int all;
  cin >> all;
  for(int i=0;i<all;i++){
    int n,k;
    cin >> n >> k;
    int x[n];
    for(int j=0;j<n;j++){
      cin >>x[j];
    }

    sort(x,x+n);

    int lgst=x[n-1]-x[0];
    int sa[n-1];
    for(int j=0;j<n-1;j++){
      sa[j] = x[j+1]-x[j];
    }
    sort(sa,sa+n-1);
    
    for(int j=0;j<k-1;j++){
      lgst-=sa[n-2-j];
      if(lgst <0){
	lgst=0;break;
      }
    }
    cout << lgst << endl;
  }
}

Measured memory_bytes: 1960
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b>c+d)cout<<"Left"<<endl;
    else if(a+b<c+d)cout<<"Right"<<endl;
    else cout<<"Balanced"<<endl;
}

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

const int maxn=1e7+5;
const int mod=1e9+7;

int n,m,bin[maxn],a[15],f[15],ans;

inline int read() {
	int sum=0; char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) 
		sum=sum*10+(ch^48),ch=getchar();
	return sum;
}

inline void init() {
	bin[0]=1;
	for ( int i=1;i<=n;i++ ) bin[i]=bin[i-1]*i%mod;
}

inline int ksm(int a,int b) {
	int ret=1;
	while(b) {
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret%mod;
}

inline void Init() {
	int sum=0,ans=0;
	for ( int i=1;i<=n;i++ ) 
		if(a[i]) 
			sum++;
	if (sum!=m) return; 
	bool ff=false;
	for ( int i=1;i<=n;++i ) {
		if(a[i]==1) {
			if(!ff) {
				ff=true;
				ans++; 
			}
		} else
			if (ff) ff=false;
	}
	f[ans]++;
}

inline void dfs(int x) {
	if (x==n+1) {
		Init();
		return;
	}
	for ( int i=0;i<=1;i++ ) {
		a[x]=i;
		dfs(x+1);
	}
}

inline void subtask_1() {
	dfs(1);
	for ( int i=1;i<=m;++i ) printf("%d\n",f[i]);
}

inline int C(int a,int b) {
	return (ksm(bin[a-b]*bin[b]%mod,mod-2)%mod*bin[a]%mod+mod)%mod;
}
signed main() {
	scanf("%lld%lld",&n,&m);
//	if(n<=10) {
//		subtask_1();
//		return 0;
//	}
	init();
	for ( int q=1;q<=m;q++ ) {
		if(m+q-1>n){puts("0");continue;}
		int s1=C(n-m+1,q)%mod;
		int s2=C(m-1,q-1)%mod;
		printf("%lld\n",s1*s2%mod);
	}
	return 0;
}

Measured memory_bytes: 256
i;k;main(n){
        
        
        int c[501],f[500],s[500];
        for(scanf("%d",&n);k<n-1;k++)scanf("%d%d%d",&c[k],&s[k],&f[k]);
        
        for(i=0;i<n-1;i++){
            int tim=0;
            for(int j=i;j<n-1;j++){
                if(tim<=s[j]){
                    tim=s[j]+c[j];
                }else{
                    tim=s[j]+(int)ceil( ((double)tim-(double)s[j])/(double)f[j] )*f[j]+c[j];
                    
                }
            }
            printf("%d\n",tim);
        }
        printf("0\n");
    }

Measured memory_bytes: 1692
while True:
    m,mn,mx = map(int,raw_input().split())
    if m==0: break
    l = [int(input()) for _ in range(m)]
    r = []
    for i in range(mn,mx+1):
        r += [l[i-1]-l[i]]
    print max([i+mn for i,x in enumerate(r) if x==max(r)])

Measured memory_bytes: 6344
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);

  int n,m;
  cin >> n >> m;

  vector<P> ab(n);
  REP(i,n) cin >> ab[i].first >> ab[i].second;

  sort(ab.begin(),ab.end(),[](P a, P b){
    return a.first < b.first;
  });

  int ans = 0;
  int i = 0;
  while(m > 0){
    ans += ab[i].first * min(m, ab[i].second);
    m -= ab[i].second;
    i++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int tpow(int num);

int main()
{
  int n,m;
  scanf("%d %d",&n,&m);
  printf("%d",(1900*m+100*(n-m))*(tpow(m)));
}

int tpow(int num)
{
  int i,a=1;
  for(i=0;i<num;i++)
  {
    a*=2;
  }
  return a;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	string s,ANS="No";
	cin>>s;
	rep(i,s.size()-1){
		if(s[i]=='A'&&s[i+1]=='C')ANS="Yes";
	}
	cout<<ANS<<endl;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())

A = list(map(int, input().split()))
A.sort(reverse=True)

ans = 0
cur = 0
for i in range(N - 1):
    ans += A[cur]
    if i < 1:
        cur += 1
    elif i % 2 == 0:
        cur += 1

print(ans)

Measured memory_bytes: 31976
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i = 0, tmp = 0;
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (i = 0; i < values.length; i++)
			values[i] = i + 1;
		for (i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			tmp = values[a];
			values[a] = values[b];
			values[b] = tmp;
		}
		for (i = 0; i < values.length; i++)
			System.out.println(values[i]);
	}
}

Measured memory_bytes: 26124
def table_composition(N):
    table = []
    i = 1
    while i <= N/2:
        if N%i == 0:
            table.append(i)
        i += 1
    table.append(N)
    return table

a, b, c = map(int, input().split())
table = table_composition(c)
count = 0
for ele in table:
    if ele >= a and ele <= b:
        count += 1
print(count)

Measured memory_bytes: 7744
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br  = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[]	card = null;

		while ((card = parseCard()) != null) {
			judge(card);
		}
	}

	private static void judge(int[] card) {
		int[]	aCnt = {1, 0, 0, 0, 0};

		Arrays.sort(card);

		if (card[0] + 1 == card[1] && card[1] + 1 == card[2] && card[2] + 1 == card[3] && card[3] + 1 == card[4]) {
			System.out.println("straight");
			return;
		}

		if (card[0] == 1 && card[1] == 10 && card[2] == 11 && card[3] == 12 && card[4] == 13) {
			System.out.println("straight");
			return;
		}

		for(int nLoop = 0, nTmp = 0; nLoop < card.length - 1; nLoop++) {
			nTmp += (card[nLoop] == card[nLoop+1]) ? 0 : 1;
			aCnt[nTmp]++;
		}

		{
			int	nFourCard  = 0;
			int	nThreeCard = 0;
			int	nOnePair   = 0;

			for (int n = 0; n < aCnt.length && aCnt[n] != 0; n++) {
				if (aCnt[n] == 4) {
					nFourCard++;
				}

				if (aCnt[n] == 3) {
					nThreeCard++;
				}

				if (aCnt[n] == 2) {
					nOnePair++;
				}
			}

			if (nFourCard == 1) {
				System.out.println("four card");
			}
			else if (nThreeCard == 1) {
				if (nOnePair == 1) {
					System.out.println("full house");
				}
				else {
					System.out.println("three card");
				}
			}
			else if (nOnePair == 2) {
				System.out.println("two pair");
			}
			else if (nOnePair == 1) {
				System.out.println("one pair");
			}
			else {
				System.out.println("null");
			}
		}
	}

	private static int[] parseCard() {
		int[]	card  = null;
		String	strIn = null;

		if ((strIn = parseStdin()) != null) {
			String[]	aN = strIn.split(",");
			card = new int[5];
			for (int n = 0; n < card.length; n++) {
				card[n] = Integer.parseInt(aN[n]);
			}
		}
		
		return card;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

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

int main(){
  ll x,k,d;cin>>x>>k>>d;
  
  x=abs(x);
  ll m=min(k,x/d);
  k-=m;
  x-=m*d;
  if(k%2==0)cout<<x<<endl;
  else cout<<d-x<<endl;  
  return 0;
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(ReadLine());
            a = a * a + a * a * a + a;
            WriteLine("{0}",a);
          
        }
    }
}

Measured memory_bytes: 27240
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
 
int main() {
    int N,M;
    cin >> N >> M;
    char S[M],C[M];
    rep(i,M){
        cin >> S[i] >> C[i];
    }
    rep(i,1000){
        bool flag = true;
        string s = to_string(i);
        rep(i,M){
            if(s[(int)(S[i]-'0') - 1] != C[i]){
                flag = false;
                break;
            }
        }
        if(flag && s.length() == N){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL inf=1e17;
LL a[55];



int main()
{
    int i, j;
    LL n;
    cin>>n;
    LL ma=1e17, mi=0, sum=0;
    LL ans=0;
    for(i=1; i<=n; i++)scanf("%lld", &a[i]);
    while(true)
    {
        LL x=0;
        for(i=1; i<=n; i++)x+=a[i]/n;
        ans+=x;
        for(i=1; i<=n; i++)
        {
            a[i]+=x-a[i]/n*(n+1);
        }
        bool f=true;
        for(i=1; i<=n; i++)f=f&(a[i]<n);
        if(f)break;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char s[100];
	while(scanf("%s",s)!=EOF)
	{
		int n=strlen(s);
		bool flag=false;
		for(int i=0;i<n-1;i++)
		{
			if(s[i]=='A' && s[i+1]=='C')
			{
				flag=true;
				break;
			}
		}
		if(flag) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
from collections import deque

n,k,l = map(int,input().split())
ep = [[] for i in range(n)]
er = [[] for i in range(n)]

gp = [-1]*n
gr = [-1]*n

for i in range(k):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    ep[a].append(b)
    ep[b].append(a)
for i in range(l):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    er[a].append(b)
    er[b].append(a)

def dfs(e,g):
    count = 0
    for i in range(n):
        if g[i] == -1:
            g[i] = count

            q = deque([])
            q.append(i)
            while q:
                now = q.pop()

                for nex in e[now]:
                    if g[nex] == -1:
                        g[nex] = g[now]
                        q.append(nex)
            count += 1

    return g
gp = dfs(ep,gp)
gr = dfs(er,gr)
l = []
dic = {}
for i in range(n):
    s = (gp[i],gr[i])
    l.append(s)
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
ans = []
for i in range(n):
    ans.append(dic[l[i]])
print(*ans)

Measured memory_bytes: 125560
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    int K, S;
    scanf("%d %d", &K, &S);
    
    // 2. X + Y + Z = S を満たす X, Y, Z をカウント.
    int ans = 0;
    rep(X, K + 1) rep(Y, K + 1) if(X + Y <= S && X + Y >= S - K) ans++;
    
    // 3. 出力.
    printf("%d\n", ans);
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	while(1){
		int a,b,g,ans=0;
		cin>>a>>b;
		if(a+b==0) break;
		if(a<b) swap(a,b);
		while(1){
			a=a%b;
			swap(a,b);
			ans++;
			if(b==0) break;
		}
		o(a<<" "<<ans);
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;


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

void dfs(vector<vector<int> > &map,int x,int y){
    /*for(int i = 0;i < h; i++){
        for(int j = 0; j < w; j++){
            cout << map[i][j] << " " ;
        }
        cout << endl;
    }*/
    //今いるところを-100に置き換える
    map[x][y] = -100;
    //移動方向をループ
    for(int dx = -1;dx <= 1;dx++){
        for(int dy = -1;dy <= 1;dy++){
            //x方向にdx,ｙ方向にdy移動した場所を(nx,ny)とする
            int nx = x + dx, ny = y + dy;
            if(0 <= nx && nx < h && 0 <= ny && ny < w && map[nx][ny] == 1){
                dfs(map,nx,ny);
            }
        }
    }
    return;
}

int solve(vector<vector<int> > &map,int h,int w){

    /*for(int i = 0;i < h; i++){
        for(int j = 0; j < w; j++){
            cout << map[i][j] << " " ;
        }
        cout << endl;
    }*/

    int ans = 0;
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            if(map[i][j] == 1){
                //Wが残っているならばその場所からdfsを始める
                dfs(map,i,j);
                //ここで1つの水たまりが見つかったことになるので水たまりの個数を１つ足す
                ans++;
            }
        }
    }
    return ans;
}

int main(){

    
    

    while(cin >> w >> h){

        if(w == 0 && h == 0){
            break;
        }
        int ans = 0;
        vector<vector<int> > map(h,vector<int>(w));//周波数ベクトル列データ用の2次元配列

        for(int i = 0;i < h; i++){
            for(int j = 0; j < w; j++){
                cin >> map[i][j];
                //cout << map[i][j] << " " ;
            }
            //cout << endl;
        }
        //cout << endl;

        ans = solve(map,h,w);

        cout << ans << endl;
    }

   


    

    return 0;
}


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

int main(){
	int N,p,cnt(0);
	cin >> N;
	for(int i(1);i<=N;++i){
		cin >> p;
		if(p != i) cnt++;
	}
	if(cnt == 0 || cnt == 2){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

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

int main(){
    
    long long int A,B,C,D,N;
    cin>>A>>B>>C>>D>>N;
    long long int check1=0,check2,MIN1=1000000000,MIN2=1000000001;
    long long int a=A*8,b=B*4,c=C*2,d=D;
    vector<long long int> S={a,b,c,d};
    for(int i=0;i<4;i++){
        if(MIN1>S[i]){
            check2=check1;
            check1=i+1;
            MIN2=MIN1;
            MIN1=S[i];
        }
        else if(MIN2>S[i]){
            check2=i+1;
            MIN2=S[i];
        }
    }
    if(check1==1) cout<<N*4*A<<endl;
    if(check1==2) cout<<N*2*B<<endl;
    if(check1==3) cout<<N*C<<endl;
    if(check1==4){
        if(N%2==0) cout<<N/2*D<<endl;
        else if(check2==1) cout<<N/2*D+4*A<<endl;
        else if(check2==2) cout<<N/2*D+2*B<<endl;
        else if(check2==3) cout<<N/2*D+C<<endl;
    }
 }


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
from itertools import accumulate

sys.setrecursionlimit(10**6)
INF = 10**12
m = 10**9 + 7

def main():
    N, M = map(int, input().split())
    ab = []
    for _ in range(M):
        a, b = map(lambda x: int(x)-1, input().split())
        ab.append((b,a))
    ab.sort()
    # print(ab)
    ans = 0
    x = -1
    for i in range(M):
        if ab[i][1] > x:
            ans += 1
            x = ab[i][0]-1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 23116
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int N = s.size();

  ll ans = 0LL;
  ll cnt = 0;
  for(int i = N - 1; i >= 0; i--){
    //cout << i << endl;
    if(s[i] == 'C'){
      if(i == 0) break;

      if(s[i - 1] == 'B'){
        cnt++;
        i--;
      }
      else{
        cnt = 0LL;
      }
    }
    else if(s[i] == 'B'){
      cnt = 0LL;
    }
    else if(s[i] == 'A'){
      ans += cnt;
    }
  }

  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,m,a[N],tr[N],ans[N],vis[N];
struct node
{
    int l,r,num;
}p[N];
bool cmp(node s1,node s2)
{return s1.r<s2.r;}
void add(int i,int k)
{
    while(i<=n)
    {
        tr[i]+=k;
        i+=(i&-i);
    }
}
int sum(int i)
{
    int s=0;
    while(i)
    {
        s+=tr[i];
        i-=(i&-i);
    }
    return s;
}
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=m;i++)
    {
        cin>>p[i].l>>p[i].r;
        p[i].num=i;
    }
    sort(p+1,p+m+1,cmp);
    int L=1;
    for(int i=1;i<=m;i++)
    {
        int num=p[i].num;
        int l=p[i].l;
        int r=p[i].r;
        for(int j=L;j<=r;j++)
        {
            int x=a[j];
            if(vis[x])add(vis[x],-1);
            add(j,1);
            vis[x]=j;
        }
        L=r+1;
        ans[num]=sum(r)-sum(l-1);
    }
    for(int i=1;i<=m;i++)
        printf("%d\n",ans[i]);
    return 0;
}


Measured memory_bytes: 17428
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>

typedef long long int64;

static int64 pow10(int x) {
  static const int64 tbl[] = {
    1,
    10,
    100,
    1000,
    10000,
    100000,
    1000000,
    10000000,
    100000000,
    1000000000,
    10000000000,
    100000000000,
    1000000000000,
    10000000000000,
    100000000000000,
    1000000000000000,
    10000000000000000,
    100000000000000000,
    1000000000000000000
  };
  return tbl[x];
}

static bool isRunRun(int64 val, int64* pInc) {
  std::stringstream sstr;
  sstr << val;
  std::string str = sstr.str();
  int len = str.size();
  for (int i = 0; i < len - 1; i++) {
    int d = std::abs((int)str.at(i + 1) - (int)str.at(i));
    if (d >= 2) {
      *pInc = pow10(len - i - 2);
      return false;
    }
  }
  *pInc = 1;
  return true;
}

int main(void) {
  int k;
  std::cin >> k;
  int64 val = 1;
  int cnt = 0;
  int64 inc = 1;
  for (; ; ) {
    if (isRunRun(val, &inc)) cnt++;
    if (k == cnt) break;
    val += inc;
  }
  std::cout << val << std::endl;
  return 0;
}


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

long long N;
string S;
int P;

long long solve() {
    if (P == 2 || P == 5) {
        long long res = 0;
        for (int i = 0; i < N; ++i) if ((S[N-i-1]-'0') % P == 0) res += N-i;
        return res;
    }
    vector<long long> val(P, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i) {
        cur = (cur + (S[N-i-1]-'0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        val[cur]++;
    }
    long long res = 0;
    for (int p = 0; p < P; ++p) res += val[p] * (val[p] - 1) / 2;
    return res;
}

int main() {
    cin >> S;
  	P=2019;
 	N=S.size();
    cout << solve() << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  string s;
  ll n;
  cin >> n >> s;
  
  vector<ll> a(n, 0);
  vector<ll> e(n+1, 0);
  rep(i, 0, n) {
    if(s[i]=='E') a[i]++;
    e[i+1] = e[i]+a[i];
  }
  
  ll ans = 300001;
  rep(i, 1, n+1) {
    ll cnt = 0;
    cnt += i-1-e[i-1];
    cnt += e[n]-e[i];
    ans = min(ans, cnt);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 5396
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;


string s;

int main()
{

    ios::sync_with_stdio(false);
    cin.tie(0);
    
   cin>>s;
   for(char i : s)
   {
   	if(i == '7')
   	{
   		cout<<"Yes"<<endl;
   		return 0;
	}
	
	} 
   cout<<"No"<<endl;
	
	
	
}







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

#define pb push_back
#define all(a) (a).begin(), (a).end()

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

const int N = 2e5 + 10;
ll a[N];
ll p[N], s[N];

int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int k, n; cin >> k >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        p[i] = p[i - 1] + (a[i] - a[i - 1]);
    }
    a[n + 1] = k;
    for (int i = n; i >= 1; --i) {
        s[i] = s[i + 1] + (a[i + 1] - a[i]);
    }
    ll ans = (ll)1e18 + 100;
    for (int i = 1; i <= n; ++i) {
        ll cur = p[i - 1] + s[i + 1] + (a[i + 1] - a[i]);
        if (i == 1)
            cur -= (a[n + 1] - a[n]);
        ans = min(ans, cur);
    }

    cout << ans << '\n';
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <set>

using namespace std;

void solve()
{
	string S;
	cin >> S;
	set<char> Set;
	for (int i = 0; i < S.size(); ++i)
	{
		Set.insert(S[i]);
	}
	if (S.size() == Set.size())
	{
		cout << "yes" << endl;
	}
	else
	{
		cout << "no" << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main{
  
  static public void main(String args[]){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    
    int[] D = new int[K];
    for(int i=0; i<K; i++){
      D[i] = sc.nextInt();
    }
    
    int price = N;
    String priceStr;
    int flag;
    
    while(true){
      flag = 0;
      priceStr = String.valueOf(price);
      
      for(int j=0; j<K; j++){
        if(priceStr.contains(String.valueOf(D[j]))){
          flag++;
        }else{
          
        }
      }
      if(flag == 0){
        break;
      }else{
        price++;
      }
    }
    
    System.out.println(price);
    
  }
}

Measured memory_bytes: 40536
from collections import defaultdict
count = defaultdict(int)

N = int(input())
for n in range(N):
  string = input()
  count[string] += 1
sore = sorted(count.items(), key=lambda x: x[1], reverse=True)
item = []
max = 0
max = sore[0][1]
for s in sore:
  if s[1] != max:
    break
  item.append(s[0])

item.sort()
for s in item:
  print(s)

Measured memory_bytes: 46112
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
  int n = 0;
  int i = 0;
  int p[32] = {0};
  int count = 0;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
  {
    scanf("%d", &p[i]);
    if(i > 1)
    {
      if(((p[i-1] > p[i-2]) && (p[i-1] < p[i]))
      || ((p[i-1] > p[i]) && (p[i-1] < p[i-2])))
      {
        count++;
      }
    }
  }

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

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
#define md 1000000007
#define itn int
#define pb push_back
#define mp make_pair
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define all(x) x.begin(),x.end()
#define x first	
#define lb lower_bound
#define ub upper_bound
#define y second
#define sz(x) (int)x.size()
#define inf 1e9
#define endl '\n'
#define cuot cout
#define dbs long double
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cerr<<*it<<" ";cerr<<endl;
#define linf 1e18
#define reset(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(int i=a;i<b;i++)
#define eps 1e-12
#define randomize srand(chrono::steady_clock::now().time_since_epoch().count());
	

void fastio(){	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
 
 
void solve(){
	ll a,b,n;cin>>a>>b>>n;
	ll x;
	if(n<b){
		x = n;
	}
	else{
		x = b-1;
	}
	ll ans = (a*x)/b;
	cout<<ans<<endl;
}
 
int main(){
	fastio();
	#ifndef ONLINE_JUDGE 
  
    // For getting input from input.txt file 
    freopen("in.txt", "r", stdin); 
  
    // Printing the Output to output.txt file 
    freopen("out.txt", "w", stdout); 
  
	#endif 
	int t;	
	t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){	
		// cout<<"Case #"<<i<<": ";
		solve();
	}	
	return 0;
}	

Measured memory_bytes: 3668
#include<iostream>

using namespace std;

int main(void) {
  int a, b;

  cin >> a;
  cin >> b;

  int sum = 0;
  for (int i = 1; i < 1000; i++) {
    int presum = sum;
    sum += i;
    if (presum - a == sum - b) {
      cout << (sum - b) << endl;
    }
  }
}

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

void fnInput(string& rsColor)
{
  int nColorSiz;
  cin >> nColorSiz >> rsColor;
}

int fnColorCount(string sColor)
{
  int nColorCnt = 0;
  int nBgn = 0;

  while (true)
  {
    int nPos;
    char cColor = sColor[nBgn];
    nColorCnt++;

    for (nPos = nBgn + 1; nPos < sColor.size(); nPos++)
      if (cColor != sColor[nPos]) break;

    if (nPos == sColor.size()) break;
    nBgn = nPos;
  }

  return nColorCnt;
}

int main()
{
  string sColor;

  fnInput(sColor);
  cout << fnColorCount(sColor) << endl;

  return 0;
}

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

int main(){
  int n;
  cin>>n; 
  vector<ll> a(n+1);
  rep(i,n+1) cin>>a[i];
  
  vector<ll> b(n+1);
  
  vector<ll> c(n+1);
  c[n]=a[n];
  for(int i=n;i>0;i--) c[i-1]=c[i]+a[i-1];
  
  b[0]=1;
  rep(i,n){
    if(b[i]-a[i]<=0){
      cout<<-1<<endl;
      return 0;
    }
    b[i+1]=min((b[i]-a[i])*2,c[i+1]);
  } 
  if(b[n]!=a[n]){
    cout<<-1<<endl;
    return 0;
  }
  
  ll ans=0;
  rep(i,n+1){
    ans+=b[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
    ll a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}


Measured memory_bytes: 3636
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
string s, t; ull p[4009], h1[4009][4009], h2[4009][4009];
int main() {
	cin >> s >> t; p[0] = 1;
	for (int i = 0; i < 4005; i++) p[i + 1] = p[i] * 10007;
	int n = s.size(), m = t.size();
	for (int i = 0; i < n; i++) {
		ull h = 0;
		for (int j = i + 1; j <= n; j++) {
			h += p[s[j - 1] - 97];
			h1[j - i][i] = h;
		}
	}
	for (int i = 0; i < m; i++) {
		ull h = 0;
		for (int j = i + 1; j <= m; j++) {
			h += p[t[j - 1] - 97];
			h2[j - i][i] = h;
		}
	}
	int z = min(n, m);
	for (int i = 1; i <= z; i++) sort(h1[i], h1[i] + n - i + 1);
	for (int i = 1; i <= z; i++) sort(h2[i], h2[i] + m - i + 1);
	int ret = 0;
	for (int i = 1; i <= z; i++) {
		for (int j = 0; j < n - i + 1; j++) {
			int ptr = lower_bound(h2[i], h2[i] + m - i + 1, h1[i][j]) - h2[i];
			if (h2[i][ptr] == h1[i][j]) ret = max(ret, i);
		}
	}
	cout << ret << endl;
	return 0;
}

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

int main() {
int A, B, C, D;
cin >> A >> B >> C >> D;
 if ( (A+B) == (C+D)){
   cout << "Balanced" << endl;
 }
     else if((A+B)<(C+D)){
    cout << "Right" <<endl;
 }
 else{
   cout << "Left" <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 200000 + 5;
int n, x[N], y[N];
int mn = 1e9 + 10, mx = -1;

ll get(int s, int e, int v) {
	if (v <= s) return s - v;
	return v - e;
}

ll calc1() {
	int mx1 = -1, mx2 = -1, mn1 = 1e9 + 10, mn2 = 1e9 + 10;
	mx1 = mx, mn1 = mn;
	vector<pair<int, int> > v, u;
	for (int i = 0; i < n; ++i) {
		if (x[i] == mn) {
			mx2 = max(mx2, y[i]);
			mn2 = min(mn2, y[i]);
		}
		else if (y[i] == mx) {
			mx2 = max(mx2, x[i]);
			mn2 = min(mn2, x[i]);
		}
		else {
			v.push_back(make_pair(x[i], y[i]));
		}
	}
	int xd, yd;
	int mn3 = 1e9 + 10, mx3 = -1;
	bool ok = true;
	while (1) {
		u.clear();
		for (int i = 0; i < v.size(); ++i) {
			xd = v[i].X, yd = v[i].Y;
			if (xd > yd) swap(xd, yd);
			if (xd >= mn2) mx2 = max(mx2, xd);
			else if (yd <= mx2) mn2 = min(mn2, yd);
			else u.push_back(make_pair(xd, yd));
			
		}
		u.swap(v);
		if (u.size() == v.size())
			break;
	}
	int xdd, ydd;
	for (int i = 0; i < v.size(); ++i) {
		xd = v[i].X, yd = v[i].Y;
		
		xdd = get(mn2, mx2, xd);
		ydd = get(mn2, mx2, yd);

		if (xdd < ydd) {
			mx2 = max(mx2, xd);
			mn2 = min(mn2, xd);
		}
		else {
			mx2 = max(mx2, yd);
			mn2 = min(mn2, yd);
		}
	}
	return (ll(mx1) - mn1) * (ll(mx2) - mn2);
}

ll calc2() {
	int mx1 = -1, mx2 = -1, mn1 = 1e9 + 10, mn2 = 1e9 + 10;
	mx1 = mx, mn2 = mn;
	for (int i = 0; i < n; ++i) {
		mn1 = min(mn1, y[i]);
		mx2 = max(mx2, x[i]);
	}
	return (ll(mx1) - mn1) * (ll(mx2) - mn2);
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", x + i, y + i);
		mn = min(mn, min(x[i], y[i]));
		mx = max(mx, max(x[i], y[i]));
	}

	if (mn == mx) return puts("0"), 0;
	for (int i = 0; i < n; ++i)
		if (x[i] > y[i])
			swap(x[i], y[i]);

	printf("%lld\n", min(calc1(), calc2()));
	return 0;
}



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

int gcd(int a, int b){
    if(a<b) swap(a,b);
    if(a%b==0) return b;
    else return gcd(b, a%b);
}

int main(){
    int N;  cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++)  cin >> A[i];
    
    int ans = A[0];
    for(int i=1; i<N; i++){
        ans = gcd(ans,A[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
num = int(input())
cards = list(map(int, input().split()))

alice = []
bob = []

for tmp in range(num):
    if tmp % 2 == 0:
        alice.append(max(cards))
        cards.pop(cards.index(max(cards)))
        continue
    bob.append(max(cards))
    cards.pop(cards.index(max(cards)))

print(sum(alice) - sum(bob))

Measured memory_bytes: 3060
n, m = map(int, input().split())
froms = []
tos = {}
for _ in range(m):
    a, b = map(int, input().split())
    if a == 1:
        froms.append(b)
    else:
        if not tos.get(a) and b == n:
            tos[a] = True
for f in froms:
    if tos.get(f) and tos[f]:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')


Measured memory_bytes: 61784
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
bn = 0
ans = 0
count = 0
i = 0

while(i<n):
    if bn==a[i]:
        if count == 0:
            ans = a[i]
            if i+1<n:
                bn = a[i+1]
            i += 1
            count +=1
        else:
            ans *= a[i]
            count +=1
            break
    else:
        bn = a[i]
    i +=1

if count>=2:
    print(ans)
else:
    print(0)

Measured memory_bytes: 14252