akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int MAXN = 100000;
int cnt[5010][5010] = {0};
int pre[5010][5010] = {0}, N, K;

int sum(int xb, int yb, int xe, int ye) {
  assert(xb <= xe);
  assert(xb > 0 and xe <= 2 * K + 1);
  return pre[xe - 1][ye - 1] - pre[xe - 1][yb - 1] 
  - pre[xb - 1][ye - 1] + pre[xb - 1][yb - 1];
}

int calc(int a, int b, int c, int d) {
  if (a > 2 * K) return calc(a - 2 * K, b, c - 2 * K, d);
  if (b > 2 * K) return calc(a, b - 2 * K, c, d - 2 * K);
  if (c > 2 * K + 1) return calc(a, b, 2 * K + 1, d) + calc(1, b, c - 2 * K, d);
  if (d > 2 * K + 1) return calc(a, b, c, 2 * K + 1) + calc(a, 1, c, d - 2 * K);
  return sum(a, b, c, d);
}
int main() {
  scanf("%d%d", &N, &K);
  int x, y;
  for (int i = 0; i < N; ++i) {
    char s[10];
    scanf("%d%d%s", &x, &y, s);
    if (s[0] == 'W') x += K;
    ++cnt[x%(2 * K) + 1][y%(2 * K) + 1];
  }
  for (int i = 1; i <= 2 * K; ++i) {
    for (int j = 1; j <= 2 * K; ++j) {
      pre[i][j] = cnt[i][j] + pre[i][j - 1] + pre[i - 1][j] - pre[i - 1][j - 1];
    }
  }
  int ans = 0;
  for (int i = 1 ; i <= 2 * K; ++i) for (int j = 1; j <= 2 * K; ++j) {
    ans = std::max(ans, calc(i, j, i + K, j + K) + calc(i + K, j + K, i + 2 * K, j + 2 * K));
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 81408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int n,m;
    scanf("%d%d",&n,&m);
    int a[m],b[m];
    long long c[m],dis[n];
    for (int i=0; i<m; i++){
        scanf("%d%d%lld",&a[i],&b[i],&c[i]);
        a[i]--;
        b[i]--;
        c[i]=c[i]*(-1);
    }
    for (int i=0; i<n; i++){
        dis[i]=LLONG_MAX;
    }
    dis[0]=0;
    for (int i=0; i<n-1; i++){
        for (int j=0; j<m; j++){
            if (dis[a[j]]==LLONG_MAX){
                continue;
            }
            if (dis[b[j]]>dis[a[j]]+c[j]){
                dis[b[j]]=dis[a[j]]+c[j];
            }
        }
    }
    
    long long ans=dis[n-1];
    bool neg[n];
    for (int i=0; i<n; i++){
        neg[i]=false;
    }
    
    
    for (int j=0; j<n; j++){
        for (int i=0; i<m; i++){
            if (dis[a[i]]==LLONG_MAX){
                continue;
            }
            if (dis[b[i]]>dis[a[i]]+c[i]){
                dis[b[i]]=dis[a[i]]+c[i];
                neg[b[i]]=true;
            }
            if (neg[a[i]]==true){
                neg[b[i]]=true;
            }
        }
    }
    if (neg[n-1]==true){
        printf("inf\n");
    } else {
        printf("%lld\n",ans*-1);
    }
    return 0 ;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
    	int a = sc.nextInt();
    	int b = sc.nextInt();
      
      	if(Math.abs(x-a) > Math.abs(x-b)){
        	System.out.println("B");
        }else{
        	System.out.println("A");
        }
    }
}

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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

const int MOD = 1e9 + 7;

int main() {
	int N; cin >> N;
	ll ans = 1;
	for(int i=1; i<=N; i++) ans *= i, ans %= MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
using System ;

namespace Program{
 class Program{
  static void Main(string []args){
   string []buff = Console.ReadLine().Split(' ');
   
   int N = int.Parse(buff[0]) ;
   int K = int.Parse(buff[1]) ;
   
   double C = 0 ;
   for(int i = 1 ; i <=  N; i++){
     double C_i = 1.0 / N ;
     long currentPoint = i ;
     while( currentPoint < K ){
        C_i *=  (1.0 / 2.0) ;
        currentPoint *= 2 ;
     }
     C+= C_i ;
   }
    
   Console.WriteLine(C); 
    
  }
 }
}

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

public class Main {
	static final int INF = 1000000000;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n == 0 && m == 0){
				break;
			}
			
			int[][] cost = new int[m][m];
			int[][] time = new int[m][m];
			for(int i = 0; i < m; i++){
				for(int j = 0; j < m; j++){
					cost[i][j] = INF;
					time[i][j] = INF;
				}
			}
			for(int i = 0; i < n; i++){
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				cost[a][b] = sc.nextInt();
				cost[b][a] = cost[a][b];
				time[a][b] = sc.nextInt();
				time[b][a] = time[a][b];
			}
			for(int k = 0; k < m; k++){
				for(int i = 0; i < m; i++){
					for(int j = i + 1; j < m; j++){
						cost[i][j] = Math.min(cost[i][j], cost[i][k] + cost[k][j]);
						cost[j][i] = cost[i][j];
						time[i][j] = Math.min(time[i][j], time[i][k] + time[k][j]);
						time[j][i] = time[i][j];
					}
				}
			}
			int k = sc.nextInt();
			for(int i = 0; i < k; i++){
				int p = sc.nextInt() - 1;
				int q = sc.nextInt() - 1;
				int r = sc.nextInt();
				if(r == 0){
					System.out.println(cost[p][q]);
				}else if(r == 1){
					System.out.println(time[p][q]);
				}
			}
		}
		
		sc.close();
	}

}

Measured memory_bytes: 109896
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;

ll powmod(ll x, ll y){
    ll res = 1;
    for(ll i = 0; i < y; i++){
        res = res * x % MOD;
    }
    return res;
}

signed main() {
    ll n;
    cin >> n;
    
    ll r = 0;
    r = powmod(10, n)-powmod(9, n)-powmod(9, n)+powmod(8, n);
    r %= MOD;
    r = (r+MOD) % MOD;

    mes(r);
    
   
    
    
    
}
    
    
    
    
    


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

struct unionfind {
    private:
        vector<int> par, ran, sz;
    public:
        unionfind(int n){
            par.resize(n, 0);
            sz.resize(n, 1);
            for(int i=0;i<n;i++) par[i] = i;
        }

        int find(int x){
            if (par[x] == x) return x;
            else return (par[x] = find(par[x]));
        }
        void unite(int x, int y){
            int rx = find(x), ry = find(y);
            if(rx == ry) return;
            if(sz[rx] < sz[ry]){
                par[rx] = ry;
                par[x] = ry;
                sz[ry] += sz[rx];
            }else{
                par[ry] = rx;
                par[y] = rx;
                sz[rx] += sz[ry];
            }
        }
        bool same(int x, int y){
            return find(x) == find(y);
        }
        int num(int x) { return sz[find(x)]; }
};

vector<int> box[1<<17];

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    unionfind u(N);
    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        u.unite(a, b);
        box[a].push_back(b);
        box[b].push_back(a);
    }
    for(int i=0;i<K;i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        box[a].push_back(b);
        box[b].push_back(a);
    }

    vector<int> ans(N);
    for(int i=0;i<N;i++){
        int cnt = u.num(i);
        for(int to : box[i]){
            if(u.same(i, to))cnt--;
        }
        ans[i] = cnt-1;
    }
    for(int i=0;i<N;i++){
        if(i > 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 9472
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};


int main(void){
    lint N,K;
    cin >> N >> K;
    lint A[N];
    vector<lint> m,p;
    rep(i,N) cin >> A[i];
    sort(A,A+N);
    lint minus=0,zero=0,plus=0;
    rep(i,N){
        if(A[i]<0) minus++,m.push_back(-A[i]);
        if(A[i]==0) zero++;
        if(A[i]>0) plus++,p.push_back(A[i]);
    }
    sort(p.begin(),p.end());
    sort(m.begin(),m.end());
    lint minusp,zerop,plusp;
    minusp=minus*plus;
    zerop=zero*plus+zero*minus+(zero*(zero-1))/2;
    plusp=(minus*(minus-1))/2+(plus*(plus-1))/2;
    int hugou=0;
    if(K<=minusp) hugou=-1;
    else if(K<=minusp+zerop) hugou=0;
    else hugou=+1;
    if(hugou==0) cout << 0 << endl;
    else if(hugou==-1){
        lint hi=2e18,lo=0;
        lint ans=0,count=0;
        while(hi-lo>1){
            ans=0,count=0;
            lint mid=(hi+lo)/2;
            rep(i,m.size()){
                auto itr=lower_bound(p.begin(),p.end(),(mid+m[i]-1)/m[i]);
                count+=p.size()-(itr-p.begin());
            }
            (count>=K?lo:hi)=mid;
            ans=mid;
        }
        cout << -lo << endl;
    }
    else{
        K=(N*(N-1))/2+1-K;
        lint hi=2e18,lo=0;
        lint ans=0,count=0;
        while(hi-lo>1){
            ans=0,count=0;
            lint mid=(hi+lo)/2;
            rep(i,m.size()){
                auto itr=lower_bound(m.begin(),m.end(),(mid+m[i]-1)/m[i]);
                count+=m.size()-(itr-m.begin());
                if(itr-m.begin()<=i) count--; 
            }
            rep(i,p.size()){
                auto itr=lower_bound(p.begin(),p.end(),(mid+p[i]-1)/p[i]);
                count+=p.size()-(itr-p.begin());
                if(itr-p.begin()<=i) count--;
            }
            count/=2;
            (count>=K?lo:hi)=mid;
            ans=mid;
        }
        cout << lo << endl;
    }
}


Measured memory_bytes: 4084
#include<stdio.h>
int main(){
	int a,b,n,z,x;
	a=0;
	scanf("%d",&n);
	int qq[n];
	for(b=0;b<n;b++){
		scanf("%d",&qq[b]);
	}
	for(z=0;z<n-1;z++){
		for(x=z+1;x<=n-1;x++){
			a=a+qq[z]*qq[x];
		}
	}

	printf("%d",a);
	
	return 0;
}

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long ll;

int n;
long double p[3005];

long double memo[3005][3005];

long double dp(int pos, int req){
	if(pos == n and req > 0)	return 0;
	if(req <= 0)	return 1;
	if(memo[pos][req] != -1)	return memo[pos][req];
	return memo[pos][req] = p[pos]*dp(pos+1, req-1) + (1-p[pos])*dp(pos+1, req);
}

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

	for(int i = 0; i < 3005; i++){
		for(int j = 0; j < 3005; j++){
			memo[i][j] = -1;
		}
	}

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

	int win = n/2;
	win +=1;

	cout << fixed << setprecision(12);
	cout << dp(0, win);

	return 0;
}

Measured memory_bytes: 141696
from random import random
from sys import setrecursionlimit

setrecursionlimit(10 ** 5)


class TreapNode:
    _value = None
    _priority = None
    _count = None
    _left = None
    _right = None

    def __init__(self, value):
        self._value = value
        self._priority = random()
        self._count = 1


def treap_rotate_right(n):
    l = n._left
    n._left = l._right
    l._right = n
    return l


def treap_rotate_left(n):
    r = n._right
    n._right = r._left
    r._left = n
    return r


def treap_insert(n, v):
    if n is None:
        return TreapNode(v)
    if n._value == v:
        n._count += 1
        return n
    if n._value > v:
        n._left = treap_insert(n._left, v)
        if n._priority > n._left._priority:
            n = treap_rotate_right(n)
    else:
        n._right = treap_insert(n._right, v)
        if n._priority > n._right._priority:
            n = treap_rotate_left(n)
    return n


def treap_delete(n, v):
    if n is None:
        return None
    if n._value > v:
        n._left = treap_delete(n._left, v)
        return n
    if n._value < v:
        n._right = treap_delete(n._right, v)
        return n

    # n._value == v
    if n._count > 1:
        n._count -= 1
        return n

    if n._left is None and n._right is None:
        return None

    if n._left is None:
        n = treap_rotate_left(n)
    elif n._right is None:
        n = treap_rotate_right(n)
    else:
        # n._left is not None and n._right is not None
        if n._left._priority < n._right._priority:
            n = treap_rotate_right(n)
        else:
            n = treap_rotate_left(n)
    return treap_delete(n, v)


def treap_size(n):
    if n is None:
        return 0
    return n._count + treap_size(n._left) + treap_size(n._right)


def treap_str(n):
    if n is None:
        return ""
    result = []
    if n._left is not None:
        result.append(treap_str(n._left))
    result.append("%d:%d" % (n._value, n._count))
    if n._right is not None:
        result.append(treap_str(n._right))
    return ' '.join(result)


def treap_search(n, v):
    # v 未満で最大のノードを検索する. v 未満のノードがなければ None を返す
    if n is None:
        return None
    if n._value >= v:
        if n._left is None:
            return None
        return treap_search(n._left, v)
    # n._value < v
    if n._right is None:
        return n
    r = treap_search(n._right, v)
    if r is None:
        return n
    return r


class Treap:
    _root = None

    def insert(self, v):
        self._root = treap_insert(self._root, v)

    def delete(self, v):
        self._root = treap_delete(self._root, v)

    def __len__(self):
        return treap_size(self._root)

    def __str__(self):
        return treap_str(self._root)

    def search(self, v):
        return treap_search(self._root, v)


N = int(input())
A = [int(input()) for _ in range(N)]

t = Treap()
for a in A:
    n = t.search(a)
    if n is not None:
        t.delete(n._value)
    t.insert(a)
print(len(t))


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

ll N;
vector<ll> A;

int main(){
    cin >> N;
    A.resize(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    ll M_1 = 0, M_2 = 0;
    ll M_1idx = 0, M_2idx = 0;
    for (int i = 0; i < N; i++) {
      if (A[i] > M_1) {
        M_1 = A[i];
        M_1idx = i;
      }
    }
    for(int i = 0; i < N; i++){
        if(A[i] > M_2 && i!=M_1idx){
            M_2 = A[i];
            M_2idx = i;
        }
    }
    for(int i = 0; i < N; i++){
        if(i!=M_1idx){
            cout <<M_1 << endl;
        }
        else
          cout << M_2 << endl;
    }
    return 0;
}

Measured memory_bytes: 4752
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

struct UnionFind{
    vector<int> par,rank,elem;
    
    //初期化
    UnionFind(int n){
        for(int i=0;i<=n;++i){
            par.push_back(i);
            rank.push_back(0);
            elem.push_back(1);
        }
    }

    //根をFind
    int find(int i){
        if(par[i]==i)return i;

        return par[i]=find(par[i]);
    }

    //Union
    void unite(int x,int y){
        int rx=find(x);
        int ry=find(y);

        if(rx==ry)return;

        if(rank[rx]>rank[ry]){
            par[ry]=rx;
            elem[rx]=elem[rx]+elem[ry];
        }
        else{
            par[rx]=ry;
            elem[ry]=elem[rx]+elem[ry];
            if(rank[rx]==rank[ry])
                rank[ry]++;
        }
    }

    //同じ木に属するか判定
    bool same(int x,int y){
        return find(x)==find(y);
    }
};

int main(){
    int N,M,K;cin>>N>>M>>K;
    UnionFind UF(N);
    vec ans(100010,-1);
    for(int i=0;i<M;i++){
        int A,B;cin>>A>>B;
        ans[A]--;ans[B]--;
        UF.unite(A,B);
    }
    for(int i=0;i<K;i++){
        int C,D;cin>>C>>D;
        if(UF.same(C,D)) {ans[C]--;ans[D]--;}
    }
    for(int i=1;i<N;i++){
        cout<<ans[i]+UF.elem[UF.find(i)]<<" ";
    }
    cout<<ans[N]+UF.elem[UF.find(N)]<<endl;
    return 0;
}

Measured memory_bytes: 3052
N, A, B = map(int, input().split())
# N <= 10**5
# A, B <= 10**9
X = [int(x) for x in input().split()]
# X{i] <= 10**9
#
cost = 0
for i in range(N-1):
    d = X[i+1] - X[i]
    if d*A < B:
        #print(i, ":", d, "A")
        cost += d* A
    else:
        #print(i,":", d, "B")
        cost += B
print(cost)





Measured memory_bytes: 14252
x1, y1, x2, y2 = gets.split.map(&:to_i)
x3 = x2 + y1 - y2
y3 = y2 + x2 - x1
x4 = x3 + y2 - y3
y4 = y3 + x3 - x2
puts [x3, y3, x4, y4].join(' ')

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define int long long

signed main(){
    string s;
    int n;cin>>n>>s;
    char c='0';
    int ans=0;
    rep(i,n){
        if(c!=s.at(i)){
            ans++;
            c=s.at(i);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long mod = 1000000000 + 7;
        long answer = (powMod(10,n,mod)-2*powMod(9,n,mod)+powMod(8,n,mod))%mod;
        answer = (answer+mod)%mod;
        System.out.println(answer);
    }
    public static long powMod(long a, long b, long mod) {
        long p = 1;
        for (int i=0;i<b;i++) {
            p=p*a%mod;
        }
        
        return p;
    }
}


Measured memory_bytes: 35820
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int N; cin >> N;
    map<string, int> mp;
    rep(i,N) {
        string s; cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for(auto e : mp) {
        chmax(mx, e.se);
    }
    for(auto e : mp) {
        if(e.se == mx) {
            cout << e.fi << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second

using namespace std;
int main()
{
   ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   
   int n;
   cin>>n;
   
   long long int t;
   
   long double ans = 1;
   
   for(int i=0;i<n;i++)
   {
       cin>>t;
       
       if(ans!=-1)
       ans*=t;
       
       if(ans > 1000000000000000000 || ans<0)
       ans=-1;
       if(t==0)
       ans=0;
   }
   
   cout<<(ll)ans<<"\n";
   
   return 0;
}


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

const int N = 1e5 + 5;
int q;

int prime[N], vis[N], good[N], sum[N];
//线性筛
void gen_prime_linear(int n){
    //sieve 2 to n prime talbe, vis==1 means not prime
    memset(vis, 0, sizeof(vis));
    int cnt = 0;
    for(int i = 2;i <= n; i++){
        if(!vis[i]) prime[cnt++] = i;//没筛掉说明它是素数
        for(int j = 0; j < cnt; ++j){
            if(i * prime[j] > n) break;//剪枝
            vis[i*prime[j]] = 1;
            if(i%prime[j] == 0) break;//保证用且只用最小的质因子把它筛去
        }
    }
}


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>q;
    gen_prime_linear(100000);
    
    for (int i = 100000-1; i >= 2; i-= 2){
        if(!vis[i] &&!vis[(i+1)/2]){
            good[i] = 1;
        }
    }
    
    for (int i = 3; i < 100000; i++){
        sum[i] = sum[i-1] + good[i];
    }
    
    int l,r;
    for (int i = 1; i <= q; i++){
        cin>>l>>r;
        cout<<sum[r]-sum[l-1]<<endl;
        
    }
    
    
    
    
    
    
    return 0;
}



Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    string s;
    cin >> s;
    int n = s.size();
    rep(i,26){
        bool check = false;
        rep(j,n){
            if(s[j]=='a'+i){
                check = true;
            }
        }
        if(!check){
            cout << char('a'+i) << endl;
            break;
        }
        if(i == 25){
            cout << "None" << endl;
        }
    }
}

Measured memory_bytes: 3756
def solve():
    N,M,K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ai = 0
    bi = 0
    s = 0

    ans = 0
    for i, a in enumerate(A):
        if s + a > K:
            ai = i-1
            ans = i
            break
        s += a
    else:
        ans = len(A)
        ai = len(A)-1

    #print(ans, ai, s)
    while ai >= -1:
        while bi < len(B):
            if s + B[bi] > K:
                break
            s += B[bi]
            bi += 1
        ans = max(ans, ai+1+bi)
        if ai != -1:
            s -= A[ai]
        ai -= 1

    print(ans)

solve()

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

#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define endl '\n'
#define int long long

typedef pair<int,int> pii;
const int N = 3e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n, a[N];
int mypow(int a, int b){
	int ans = 1;
	while(b){
		if (b&1) ans = (ans*a) % MOD;
		a = (a*a) % MOD;
		b /= 2;
	}
	return ans;
}
int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=0; i<n; i++) cin >> a[i];
	int ans = 0;
	for(int i=0; i<61; i++){
		int cnt0 = 0, cnt1 = 0;
		for(int j=0; j<n; j++){
			int &x = a[j];
			if ((1LL<<i)&x) cnt1++;
			else cnt0++;
		}
		ans += cnt0*cnt1 % MOD * mypow(2, i) % MOD;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
string = raw_input()
n = input()

for i in range(n):
    tmp = map(str, raw_input().split())
    if tmp[0] == "print":
        print string[int(tmp[1]): int(tmp[2]) + 1]
    elif tmp[0] == "reverse":
        s = ""
        for i in range(int(tmp[1])):
            s += string[i]
        for i in range(int(tmp[2]) - int(tmp[1]) + 1):
            s += string[int(tmp[2]) - i]
        for i in range (len(string) - int(tmp[2]) - 1):
            s += string[i + int(tmp[2]) + 1]
        string = s
    elif tmp[0] == "replace":
        s = string[:int(tmp[1])] + tmp[3] + string[int(tmp[2]) + 1:]
        string = s

Measured memory_bytes: 6488
#include<stdio.h>
  #define N 100
  #define WHITE 0
  #define GRAY 1
  #define BLACK 2

  int num,M[N][N];
  int t,color[N],d[N],f[N];

  void dfs_vist(int a){
    int v;
    color[a]=GRAY;
    d[a]=++t;
    for(v=0;v<num;v++){
      if(M[a][v]==0)continue;
      if(color[v]==WHITE){
        dfs_vist(v);
      }
    }
    color[a]=BLACK;
    f[a]=++t;
  }
  void dfs(){
    int u;
    for(u=0;u<num;u++)color[u]=WHITE;
    t=0;
    for(u=0;u<num;u++){
      if(color[u]==WHITE)dfs_vist(u);
    }
    for(u=0;u<num;u++){
      printf("%d %d %d\n",u+1,d[u],f[u]);
    }
  }

  int main(){
    int i,j,u,v,k;
    scanf("%d",&num);
    for(i=0;i<num;i++){
      for(j=0;j<num;j++){
        M[i][j]=0;
      }
    }
    for(i=0;i<num;i++){
      scanf("%d%d",&u,&k);
      u--;
      for(j=0;j<k;j++){
        scanf("%d",&v);
        v--;
        M[u][v]=1;
      }
    }
    dfs();
    return 0;
  }



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

int main() {
	int N;
	cin >> N;
	int i;
	int ans = N;
	for (i = 0;i <= N;i++) {
		int t = i;
		int counter = 0;
		while (t > 0) {
			counter += t % 6;
			t /= 6;
		}
		t = N - i;
		while (t > 0) {
			counter += t % 9;
			t /= 9;
		}
		if (ans > counter) ans = counter;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(a > 9 || b > 9 ? -1 : a*b);
    }
}



Measured memory_bytes: 23252
#include<iostream>

#define GM(a) (a*(a+1)/2)

int X;

int jump(){
	for( int i = 0; i <= X; i++ ){
		if( GM(i) >= X ){ return i; }
	}
	return -1;
}

int main(){
	std::cin >> X;
	std::cout << jump() << std::endl;
	return 0;
}

/*
int jump(int x, int i, int M){
	int re = -1;
	std::cout << x << "," << i << "," << M << std::endl;
	if( x == X ){ return i-1; }
	if( i > M ){ return -1; }
	if( x == 0 || x-i < i ){ jump(x-i, i+1, M); }
	if( re >= 0 ){ return re; }
	re = jump(x, i+1, M);
	if( re >= 0 ){ return re; }
	if( x==0 || x+i > i ){ re = jump(x+i, i+1, M); }
	if( re >= 0 ){ return re; }
	return re;
}

int main(){
	int re = -1;
	std::cin >> X;
	for( int i = 1; i <= X; i++ ){
		std::cout << "i:" << i << std::endl;
		if( GM(i) < X ){ continue; }
		re = jump(0, 1, i);
		if( re >= 0 ){
			std::cout << re << std::endl;
			break;
		}
	}
	return 0;
}
*/


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<queue>
#include<set>
#include<stack>
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 
 
typedef pair<int,int >P;
//////////////////////////
/////////////////////////

int dp[3003][3003];
int n,s;
int ar[3000+2];


int DP(int pos, int m){
    if(m > s)return 0;
    if(m == s){
        return n - pos + 2;
    }
    if(pos == n+1){
        return 0;
    }
    int &ret = dp[pos][m];

    if(ret!=-1)return ret;
    ret = 0;

    if(m == 0){
        ret += DP(pos +1 , m);
        ret %= 998244353ll;
        ret+= ((ll)pos * (ll)DP( pos + 1, m + ar[pos])) % 998244353ll ;
    }
    else {
        ret += DP(pos + 1, m);
        ret %= 998244353ll;
        ret += DP(pos + 1, m + ar[pos]);
    }
    ret %= 998244353ll;
    return ret;
}

int main(){
  
    I2(n,s);


    for(int i = 1;i<=n;i++)I(ar[i]);


    SETR(dp);

    cout<<DP(1,0)<<endl;
    return 0;
}

Measured memory_bytes: 35584
#include<stdio.h>
#include<stdlib.h>
typedef long long ll;
int main(void){
    int N;
    scanf("%d",&N);
    int a = (int)(N/1.08);
    int b = a + 1;
    int c = a*1.08;
    int d = b*1.08;
    if(c==N){
        printf("%d\n",a);
    }else if(d==N){
        printf("%d\n",b);
    }else{
        printf(":(\n");
    }
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

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

  int n;
  cin >> n;
  vi b(n - 1);
  for(int& x : b) cin >> x;
  int res = b[0] + b[n - 2];
  for(int i = 0; i < n - 2; i++){
    res += min(b[i], b[i + 1]);
  }
  cout << res;
}

Measured memory_bytes: 256
class UnionFind:
    pairs = {}
    def __init__(self, n):
        for i in range(n):
            self.pairs[i] = i

    def set(self, s, t):
        if s in self.pairs and self.pairs[s] == s:
            self.pairs[s] = self.root(t)
        else:
            self.pairs[t] = self.root(s)

    def root(self, x):
        if self.pairs[x] == x:
            return x
        self.pairs[x] = self.root(self.pairs[x])
        return self.pairs[x]

    def unite(self, x, y):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry :
            return
        self.pairs[rx] = ry
    def same(self, x, y ):
        rx = self.root(x)
        ry = self.root(y)
        if rx == ry:
            return True
        else:
            return False
        
def main():
    n, m = map(int, input().split())

    uf = UnionFind(n)
    pairs =[]
    for i in range(m):
        s, t = map(int,input().split())
        if uf.same(s-1, t-1) == False:
            uf.unite(s-1,t-1)
        #pairs.append([s-1,t-1])

    # pairs.sort()
    # for pair in pairs:
    #     uf.set(pair[0], pair[1])
    #
    # for pair in pairs:
    #     uf.set(pair[0], pair[1])

    root = []
    for i in range(n):
        root.append(uf.root(i))
 #       print(i, uf.root(i))
    single_root = set(root)

    print(len(single_root)-1)
main()


Measured memory_bytes: 24276
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define loopinc(i, a, b, inc) for(int i = a; i < (b); i += inc)
#define loop(i, a, b) for(int i = a; i < (b); i++)
#define rep(i, n) loop(i, 0, n)
#define rrep(i, n) for (int i = n-1; i >= 0; i--)
#define endl "\n"
#define all(c) (c).begin(),(c).end()
#define lloopinc(i, a, b, inc) for(ll i = a; i < (b); i += inc)
#define lloop(i, a, b) for(ll i = a; i < (b); i++)
#define lrep(i, n) lloop(i, 0, n)
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tuple<int, int, int> tiii;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

signed main() {
	// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	vector<string> mat(n);
	rep(i, n) cin >> mat[i];
	vector<vector<int>> occ(n, vector<int>(m, INT_MAX));
	rep(i, n) rep(j, m) {
		bool full = mat[i][j] == '#';
		if (i == 0 and j == 0) {
			if (full) occ[i][j] = 1;
			else occ[i][j] = 0;
		}
		if (i != 0) occ[i][j] = min(occ[i][j], occ[i-1][j] + (mat[i-1][j] == '.' and full));
		if (j != 0) occ[i][j] = min(occ[i][j], occ[i][j-1] + (mat[i][j-1] == '.' and full));
	}
	cout << occ[n-1][m-1] << endl;
}


Measured memory_bytes: 3680
using System;
public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        Array.Sort(a);
        for (int i = 0; i < n; i++)
            if (a[i] >= n-i) { Console.WriteLine(n - i); break; }
    }
}

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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;

const int N = 300003;
const int MOD = 1e9 + 7;

inline int getInt() {
  int x;
  scanf("%d", &x);
  return x;
}

int main() {
  int n = getInt();
  int w = getInt();
  vector<vector<ll>> dp(2, vector<ll>(w + 1, 0));
  int a = getInt();
  int b = getInt();
  for (int i = a; i <= w; i++) {
    dp[0][i] = b;
  }
  for (int i = 1, x; i < n; i++) {
    a = getInt();
    b = getInt();
    x = i&1;
    for (int j = 0; j <= w; j++) {
      if (j - a >= 0) {
        dp[x][j] = max(dp[1 - x][j], dp[1 - x][j - a] + b);
      } else {
        dp[x][j] = dp[1 - x][j];
      }
    }
  }
  ll ans = 0;
  for (ll x : dp[1 - (n&1)]) {
    ans = max(ans, x);
  }
  printf("%lld\n", ans);
  return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll A, B, N; cin >> A >> B >> N;
	if (N < B-1) {
		cout << (A*N)/B << endl;
	} else {
		ll maxv = -1;
		for (int n = 0; n <= max(A, B) && (n+1)*B-1 <= N; n++) {
			chmax(maxv, (A*((n+1)*B-1))/B - A*n);
		}
		cout << maxv << endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  ll n,z,w;
  cin >> n >> z >> w;
  
  ll card[2010];
  
  REP(i,n) cin >> card[i];
  
  cout << max(abs(card[n-1] - w),abs(card[n-1]-card[n-2])) << endl;
  

 return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] S = new int[n+1];

		String[] s = br.readLine().split(" ");
		for(int i = 0; i < n; i++){
			S[i] = Integer.parseInt(s[i]);
		}
		int q = Integer.parseInt(br.readLine());
		int[] T = new int[q];
		s = br.readLine().split(" ");
		for(int i = 0; i < q; i++){
			T[i] = Integer.parseInt(s[i]);
		}
		
		int C = 0;
		for(int i = 0; i < q; i++){
			boolean flag = linearSearch(T[i], S, n);
			if(flag == true)
				C++;
		}
		System.out.printf("%d\n", C);
	}

	// ????????????????????¢????´¢
	private static boolean linearSearch(int key, int[] A, int n){
		int i = 0;
		A[n] = key;
		while(A[i] != key){
			i++;
		}
		if(i == n)
			return false;
		return true;
	}
}

Measured memory_bytes: 28060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ff;
typedef long long unsigned ul;
#define pf printf
#define sf scanf
#define pb push_back
#define pfds(a) pf("%lld ",(a))
#define pfdn(a) pf("%lld\n",(a))
#define pffs(a) pf("%Lf ",(a))
#define pffn(a) pf("%Lf\n",(a))
#define pfss(a) pf("%s ",(a))
#define pfsn(a) pf("%s\n",(a))
#define scd(a) sf("%lld",&(a))
#define scf(a) sf("%Lf",&(a))
#define scs(a) sf("%s",(a))
#define scc(a) sf("%c",&(a))
#define FORF(i,a) for(ll (i)=0;(i)<(a);(i)+=1)
#define FORD(i,a) for(ll (i)=(a);(i)>=0;(i)-=1)
#define FORF2(i,a,b) for(ll (i)=(a);i<(b);(i)+=1)
#define FORD2(i,a,b) for(ll (i)=(a);i>=(b);(i)-=1)
#define max3(a,b,c) a>b?a>c?a:c:b>c?b:c
#define min3(a,b,c) a<b?a<c?a:c:b<c?b:c
void to_binary(int n){ if(!n) return; to_binary(n>>1); printf("%d",n&1 ? 1 : 0); }
const ul mod = 1e9+7;
const int size = 1e9 + 3;
int main()
{
	ll n,x,sum=0;scd(n);
	map<ll,ll> mp;
	while(n--)
	{
		scd(x);
		if(mp[x]!=1)
			mp[x]=1;
		else
			mp[x]=0;
	}
	map<ll,ll>::iterator it;
	for(it=mp.begin();it!=mp.end();++it)
	{

		if(mp[it->first]==1)
			sum+=1;
	}
	pfdn(sum);
	return 0;
}

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

int main() {
  int n,k;
  cin>>n>>k;
  double sum = 0;
  for (size_t i = 17; i>=0; i--) {
    if (k/pow(2,i-1)>n||i==0) {
      sum+=(n-ceil(k/pow(2,i))+1)/pow(2,i);
      break;
    }
    sum+=(ceil(k/pow(2,i-1))-ceil(k/pow(2,i)))/pow(2,i);
  }
  cout<<setprecision(12)<<sum/n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define FASTIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define inf 1e18
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define mod 1000000007
#define pb push_back
#define all(s) s.begin(),s.end()
#define pie 3.14159265358979323846
#define fr(i,a,b)  for(ll i=a;i<b;i++)
#define frr(i,a,b) for(ll i=b-1;i>=a;i--)
#define gcd __gcd
#define con continue
#define pii pair<ll,ll>
signed main(){
    FASTIO;
    ll tt=1;
    //cin>>tt;
    while(tt--){
         double a,b,t;cin>>a>>t>>b;
         if(a/b<=t)cout<<"Yes\n";
         else cout<<"No\n";
    }
}


Measured memory_bytes: 3748
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

const int INF = 1<<29;

struct RBST_node{
	int val,mv,size;
	RBST_node *l_child,*r_child;
	
	RBST_node(int v){
		val=mv=v;
		size=1;
		l_child=r_child=NULL;
		srand(time(NULL));
	}
};
typedef pair<RBST_node*, RBST_node*> P;

RBST_node* update(RBST_node* x){
	x->size = 1;
	x->mv = x->val;
	if(x->l_child){
		x->size += x->l_child->size;
		x->mv = min(x->mv,x->l_child->mv);
	}
	if(x->r_child){
		x->size += x->r_child->size;
		x->mv = min(x->mv,x->r_child->mv);
	}
	return x;
}

RBST_node* merge(RBST_node* x, RBST_node* y){
	if(!x) return y;
	if(!y) return x;
	
	int m=x->size, n=y->size;
	if(rand() % (m+n) < m){
		x->r_child = merge(x->r_child,y);
		return update(x);
	}else{
		y->l_child = merge(x,y->l_child);
		return update(y);		
	}
}

int node_size(RBST_node* x){
	if(!x) return 0;
	else return x->size;
}

//[,pos) [pos,)????????¢????????????
P split(RBST_node* x,int pos){
	if(!x) return P(NULL,NULL);
	if(node_size(x->l_child)<pos){
		P tmp = split(x->r_child,pos-node_size(x->l_child)-1);
		x->r_child = tmp.first;
		return P(update(x),tmp.second);
	}else{
		P tmp = split(x->l_child,pos);
		x->l_child = tmp.second;
		return P(tmp.first,update(x));
	}
}

RBST_node* insert(RBST_node* x,int val,int pos){
	RBST_node *p = new RBST_node(val);
	P tmp = split(x,pos);
	RBST_node *l = merge(tmp.first,p),*r=tmp.second;
	return merge(l,r); 
}

RBST_node* erase(RBST_node *x,int pos){
	P tmp = split(x,pos);
	RBST_node *l =tmp.first;
	RBST_node *r = split(tmp.second,1).second;
	return merge(l,r);
}

int main(){
	
	RBST_node *t=NULL;
	
	int n,q;
	cin>>n>>q;
	
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		t=insert(t,a,i);
	}
		
	for(int i=0;i<q;i++){
		int x,y,z;
		cin>>x>>y>>z;
		
		if(x==0){
			P p1=split(t,z);
			P p2=split(p1.first,y);
			P p3=split(p1.second,1);
			RBST_node *u=merge(p2.first,p3.first);
			RBST_node *v=merge(p2.second,p3.second);
			t=merge(u,v);
		}else if(x==1){
			P p1=split(t,y);
			P p2=split(p1.second,z-y+1);
			cout<<p2.first->mv<<endl;
			t=merge(p1.first,merge(p2.first,p2.second));
		}else{
			t=erase(t,y);
			t=insert(t,z,y);
		}
	}
	
	return 0;
}

Measured memory_bytes: 13752
'''
Created on 2020/08/22

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  c=pin()[:-1]
  r=0
  w=0
  for i in c:
    if i=="R":
      r+=1
    else:
      w+=1
#  if r==N or w==N:
#    print(0)
#    return 
  nL=0
  nR=r 
  num=max(nL,nR)
  for i in c:
    if i=="R":
      nR-=1
    else:
      nL+=1
    if num>max(nL,nR):
      num=max(nL,nR)
  print(num)
  return 
main()
#解説AC

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

int main() {
    int N;  cin >> N;
    string s;  cin >> s;
    ll ans = 0;
    for (int i = 0; i < 1000; i++)
    {
        std::ostringstream sout;
        sout << setfill('0') << setw(3) << i;
        string t = sout.str();
        int pos = 0;
        for (int j = 0; j < N; j++)
        {
            if(t[pos]==s[j]){
                pos++;
                if(pos==3){
                    ans++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256