akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


ll gcd(ll a, ll b)
{
	ll c;
	while((c=a%b))
	{
		a=b;
		b=c;
	}
	return b;
}


#define TWO_OFFSET 50
#define FIVE_OFFSET 30

struct a_t
{
	ll bunsi, bunbo;
	int two, five;

	a_t() : bunsi(0), bunbo(1), two(0), five(0) {}
	a_t(string&s)
	{
		ll bunbo=1;
		ll bunsi=0;
		bool is_ad=false;
		for(int i=0;i<(int)s.length();i++)
		{
			if(s[i]=='.')
			{
				is_ad=true;
				continue;
			}
			bunsi=bunsi*10+(s[i]-'0');
			if(is_ad) bunbo=bunbo*10;
			set(bunsi, bunbo);
		}
	}
	void set(ll bunsi, ll bunbo)
	{
		if(bunsi==0) bunsi=1;
		ll d=gcd(bunsi, bunbo);
		this->bunsi=(bunsi/=d);
		this->bunbo=(bunbo/=d);
		two=0;
		five=0;
		for(;bunsi%2==0;bunsi/=2) two++;
		for(;bunsi%5==0;bunsi/=5) five++;
		for(;bunbo%2==0;bunbo/=2) two--;
		for(;bunbo%5==0;bunbo/=5) five--;
	}
};


void m_set(vvi&m, int two, int five, int v)
{
	m[two+TWO_OFFSET][five+FIVE_OFFSET]=v;
}


int m_get(vvi&m, int two, int five)
{
	return m[two+TWO_OFFSET][five+FIVE_OFFSET];
}


void m_add(vvi&m, int two, int five, int v)
{
	m_set(m, two, five, m_get(m, two, five)+v);
}


void m_inc(vvi&m, int two, int five)
{
	m_add(m, two, five, 1);
}


struct solve
{
	solve(){}
	ll operator()(vector<a_t>&a) {
		vvi m(TWO_OFFSET*2);
		for(auto&mm:m) mm.resize(FIVE_OFFSET*2);

		for(auto&ma:a) m_inc(m, ma.two, ma.five);

		for(int i=0;i<(int)m.size();i++)
		{
			for(int j=m[i].size()-1;j>0;j--)
			{
				m[i][j-1]+=m[i][j];
			}
		}
if(0){
for(int i=0;i<(int)m.size();i++)
{
	for(int j=0;j<(int)m[i].size();j++)
	{
		cout << m[i][j] << " ";
	}
	cout << "\n";
}
cout << "\n";
}

		vvi x=m;
		for(int j=0;j<FIVE_OFFSET*2;j++)
		{
			for(int i=m.size()-1;i>0;i--)
			{
				x[i-1][j]+=x[i][j];
			}
		}

if(0){
vvi&m=x;
for(int i=0;i<(int)m.size();i++)
{
	for(int j=0;j<(int)m[i].size();j++)
	{
		cout << m[i][j] << " ";
	}
	cout << "\n";
}
cout << "\n";
}


		ll ans=0;
		for(auto&ma:a)
		{
			int two_=-ma.two+TWO_OFFSET;
			int five_=-ma.five+FIVE_OFFSET;
			ans+=x[two_][five_];
			if(ma.two>=0 && ma.five>=0) ans--;
		}

		return ans/2;
	}
};

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

	for(;;)
	{
		int n;
		cin >> n;
		if(cin.fail()) break;
		vector<string> as(n);
		for(auto&m:as) cin >> m;

		vector<a_t> a;
		for(auto&m:as) a.push_back(m);

		cout << solve()(a) << "\n";
	}
	return 0;
}


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

using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d || (abs(a - b) <= d && abs(c - b) <= d)) {
    cout << "Yes" << '\n';
  }
  else {
    cout << "No" << '\n';
  }
  return 0;
}



Measured memory_bytes: 256
import time
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

start = time.time()
res = 0
for i in range(n):
    for j in range(i+1,n):
        ab = l[i] + l[j]
        c_index = bisect_left(l, ab)
        res += c_index - j - 1
print(res)


Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
     
#define lli long long
#define FOR(i,a,b) for (lli i=(a);i<(b);i++)
#define REP(i,n) for (lli i=0;i<(n);i++)
#define rep(i,n) for (lli i=0;i<(n);i++)
     
#define INF LONG_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>
     
int main(){
  lli H,W,count=0;
  string str[8];

  cin>>H>>W;
  for(int i=0;i<H;i++){
    cin>>str[i];
    for(int j=0;j<W;j++){
      if(str[i][j]=='#')count++;
    }
  }

  if(count==H+W-1)cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
struct Node{
    int key;
    Node *prev, *next;
};
class  List{
public:
    List(){
        nil = new Node();
        nil->prev = nil;
        nil->next = nil;
    }
    ~List(){
        Node *cur = nil->next;
        Node *tmp;
        while(cur != nil){
            tmp = cur->next;
            delete cur;
            cur = tmp;
        }
        delete nil;
    }
    void insert(int key){
        Node *x = new Node();
        x->key = key;
        x->next = nil->next;
        nil->next->prev = x;
        nil->next = x;
        x->prev = nil;
    }
    Node* find(int key){
        Node *cur = nil->next;
        while(cur != nil && cur->key !=key) cur = cur->next;
        return cur;
    }
    void deleteList(Node *t){
        if(t == nil) return;
        t->prev->next = t->next;
        t->next->prev = t->prev;
        delete t;
    }
    void deleteFirst(){
        deleteList(nil->next);
    }
    void deleteLast(){
        deleteList(nil->prev);
    }
    void deleteKey(int key){
        deleteList(find(key));
    }
    void printList(){
        Node *cur = nil->next;
        while(cur != nil){
            std::cout<<cur->key;
            cur = cur->next;
            if(cur != nil) std::cout<<' ';
        }
        std::cout<<std::endl;
    }
private:
    Node *nil;
};
int main() {
    using namespace std;
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    List list;
    for(int i=0;i<N;++i){
        string s;
        cin>>s;
        if(s=="insert"){
            int n;
            cin>>n;
            list.insert(n);
        }else if(s=="delete"){
            int n;
            cin>>n;
            list.deleteKey(n);
        }else if(s=="deleteFirst"){
            list.deleteFirst();
        }else list.deleteLast();
    }
    list.printList();
}

Measured memory_bytes: 34448
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const string check = "AGTC";

int main(){
  string s;
  cin>>s;
  int ans=0;
  int l=s.size();
  rep(i,l){
    for(int j=i;j<l;j++){
      bool m_judge = true;
      for(int k=i;k<=j;k++){
        bool judge = false;
        rep(x,4){
          if(check[x]==s[k]) judge=true;
        }
        if(!judge) m_judge=false;
      }
      if(m_judge) ans = max(ans,j-i+1);
    }
  }
  cout<<ans;
}


Measured memory_bytes: 3564
# A - 高橋君とホテルイージー
# https://atcoder.jp/contests/abc044/tasks/abc044_a

N = int(input())
K = int(input())
X = int(input())
Y = int(input())

result = 0

for i in range(N):
    if i < K:
        result += X
    else:
        result += Y

print(result)


Measured memory_bytes: 9160
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int N, M;
int dp[110][110];
signed main() {
    cin >> N >> M;
    map<pii, int> m;
    rep(i,0,110) rep(j,0,110) dp[i][j] = INF;
    rep(i,0,M) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--;
        dp[a][b] = c;
        dp[b][a] = c;
        m[pii(a, b)] = c;
    }
    rep(k,0,N) rep(i,0,N) rep(j,0,N) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
    }

    int ans = 0;
    for(auto x : m) {
        int a = x.fr.fr, b = x.fr.sc, c = x.sc;
        if(dp[a][b] != c) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  long x,y,z,k;
  cin >> x >> y >> z >> k;
  vector<long>a(x);
  vector<long>b(y);
  vector<long>c(z);
  int i,j,kk;
  for(i=0;i<x;i++){
    cin >> a[i];
  }
  for(i=0;i<y;i++){
    cin >> b[i];
  }
  for(i=0;i<z;i++){
    cin >> c[i];
  }
  sort(a.begin(),a.end(),greater<long>());
  sort(b.begin(),b.end(),greater<long>());
  sort(c.begin(),c.end(),greater<long>());

  priority_queue<long>yummy;
  for(i=0;i<x;i++){
    for(j=0;j<y;j++){
      for(kk=0;kk<z;kk++){
        if((i+1)*(j+1)*(kk+1)>k)break;
        else{
          yummy.push(a[i]+b[j]+c[kk]);
        }
      }
    }
  }
  for(i=0;i<k;i++){
    cout << yummy.top() << endl;
    yummy.pop();
  }
}


Measured memory_bytes: 1532
#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=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(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;

struct s{
  int a;
  int b;
  double c;
};

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

  string s,t,u;
  int a,b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;

  if(s == u) cout << a - 1 << " " << b;
  else if(t == u) cout << a << " " << b - 1;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
double pi = 3.1415926535897932;
using namespace std;
double a, b, c, d, e, f, N, M;
string s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b >> c >> d;
	c += d / 60;
	double x = a * cos(c * 2 * pi / 12.0) - b * cos(d * 2 * pi/60.0);
	double y= a * sin(c * 2 * pi / 12.0) - b * sin(d * 2 * pi/60.0);
	cout.precision(15);
	cout << sqrt(x * x + y * y);
}

Measured memory_bytes: 4144
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    return Parent[a] = root(Parent[a]);
  }

  bool issame(int a, int b){
    return root(a) == root(b);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);

    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

int main(){
  int n; cin >> n;
  string s,t; cin >> s >> t;
  string ans;
  rep(i,n) {
    ans += s[i];
    ans += t[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
  int r, D, x;
  cin >> r >> D >> x;

  int ans[11];
  ans[0] = x;
  for(int i = 1; i < 11; i++){
    ans[i] = ans[i-1] * r - D;
    cout << ans[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    string s;
    int a=0,b=0;
    cin>>s;
    for(int i=0;i<=s.length();i++){
        if(i%2!=0&&s[i]=='0') a++;
        if(i%2==0&&s[i]=='1') a++;

    }
    for(int i=0;i<=s.length();i++){
        if(i%2!=0&&s[i]=='1') b++;
        if(i%2==0&&s[i]=='0') b++;
    }
    cout<<min(a,b)<<endl;
}


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

  int W,a,b;

  cin>>W>>a>>b;

  if(a<b){

    if(b-(a+W)>0){
      cout<<b-(a+W)<<endl;
    }else{
      cout<<0<<endl;
    }
    
  }else{

    if(a-(b+W)>0){
      cout<<a-(b+W)<<endl;
    }else{
      cout<<0<<endl;
    }
  }
  
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include<stack>

using namespace std;

#define MOD 1000000007

int main(){
    int N;
    int mode=0;
    long long ans=1;
    string S[2];
    cin>>N;
    cin>>S[0];
    cin>>S[1];
    for(int i=0;i<N;i++){
        if(S[0][i]==S[1][i]){
            if(mode==0){
                ans*=3;
            }
            else if(mode==1){
                ans*=2;
            }
            else{
                ans*=1;
            }
            mode=1;
        }
        else{
            i++;
            if(mode==0){
                ans*=6;
            }
            else if(mode==1){
                ans*=2;
            }
            else{
                ans*=3;
            }
            mode=2;
        }
        ans%=MOD;
        //cout<<i<<","<<ans<<endl;
    }
    cout<<ans<<endl;
}


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int n,x;
vector<int> t;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> x;
  t.resize(n);
  R(i,n)cin >> t[i];
  int res = 1e15;
  R(i,n){
    int pom = i * x;
    R(j,n)pom += t[j];
    mini(res,pom);
    vector<int> t2;
    t2.resize(n);
    R(j,n){
      t2[j] = min(t[j],t[(j+1)%n]);
    }
    swap(t2,t);
  }
  cout << res << "\n";
}


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

struct Edge {
    int from, to;
    int64_t cost;
    Edge(int _to) : from(-1), to(_to), cost(-1) {}
    Edge(int _to, int64_t _cost) : from(-1), to(_to), cost(_cost) {}
};

class LCA {
public:
    const int K = 18;
    vector<vector<int>> par;
    vector<int> depth;
    LCA(const vector<vector<Edge>> &G) {
        par.assign(K + 1, vector<int>(G.size()));
        depth.resize(G.size());
        dfs(G, 0, -1, 0);
        for(int k = 0; k < K; ++k) {
            for(int i = 0; i < G.size(); ++i) {
                if(par[k][i] == -1) par[k + 1][i] = -1;
                else par[k + 1][i] = par[k][par[k][i]];
            }
        }
    }

    void dfs(const vector<vector<Edge>> &G, int u, int v, int d) {
        par[0][u] = v;
        depth[u] = d;
        for(auto &e : G[u]) {
            if(e.to != v) dfs(G, e.to, u, d + 1);
        }
    }

    int operator()(int u, int v) {
        if(depth[u] > depth[v]) swap(u, v);
        for(int i = K - 1; i >= 0; --i) {
            if((depth[v] - depth[u]) & (1 << i)) v = par[i][v];
        }
        if(u == v) return u;
        for(int i = K - 1; i >= 0; --i) {
            if(par[i][u] != par[i][v]) {
                u = par[i][u];
                v = par[i][v];
            }
        }
        return par[0][u];
    }
};

int main() {
    int N; cin >> N;
    vector<vector<Edge>> G(N);
    for(int i = 0; i < N; ++i) {
        int k; cin >> k;
        for(int j = 0; j < k; ++j) {
            int c; cin >> c;
            G[i].emplace_back(c);
        }
    }
    LCA lca(G);
    int Q; cin >> Q;
    while(Q--) {
        int u, v;
        cin >> u >> v;
        cout << lca(u, v) << endl;
    }
    return 0;
}



Measured memory_bytes: 18932
#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 rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 1000005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define ps(x,y) fixed<<setprecision(y)<<x
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out <<  "(" << a.F << ", " << a.S << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out << "[";
	for (auto it = a.begin(); it != a.end(); ++it) {
		if (it != a.begin())
			out << ", ";
		out << *it;
	}
	return out << "]";
}
int main()
{
    boost;
    ll n,i,j,x,t,y,a,b;
    cin>>a>>b>>n;
    if(b==1) {
        cout<<0;
        return 0;
    }
    x=min(n,b-1);
    ll ans=(a*x)/b - a*(x/b);
    cout<<ans;
}

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

const int mxN = 2e5 + 2;
long long n, height[mxN], beauty[mxN], dp[mxN];

const int INF = 1e9;
class mxsegtree
{
public:
    int N;
    vector<long long> tree;
    mxsegtree(){}
    void initialize(int s)
    {
        int pos = ceil(log2(s));
        N = 1 << pos;
        tree.resize(2 * N);
        fill(tree.begin(), tree.end(), 0);
    }

    long long qmax(int a, int b)
    {
        a += N;
        b += N;
        long long rmax = 0;
        while (a <= b)
        {
            if (a % 2 == 1)
                rmax = max(tree[a++], rmax);
            if (b % 2 == 0)
                rmax = max(tree[b--], rmax);
            a /= 2;
            b /= 2;
        }
        return rmax;
    }

    void update(long long k, long long newVal)
    {
        k += N;
        tree[k] = max(tree[k], newVal);
        for (k /= 2; k >= 1; k /= 2)
        {
            tree[k] = max(tree[2 * k], tree[2 * k + 1]);
        }
    }
};

mxsegtree seg;

int main()
{
    cin >> n;
    seg.initialize(n + 1);
    for (int i = 0; i < n; i++)
        cin >> height[i];
    for (int i = 0; i < n; i++)
        cin >> beauty[i];
    
    long long ret = 0;
    for (int i = 0; i < n; i++)
    {
        dp[i] = seg.qmax(1, height[i]) + beauty[i];
        seg.update(height[i], dp[i]);
        ret = max(ret, dp[i]);
    }
    cout << ret << endl;
}

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

using namespace std;

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

    int N; cin>>N;
    struct XY {
        int x, y;
        bool operator<(const XY& x) const {return this->x*50+this->y < x.x*50+x.y;}
    };
    map<XY, int> map;
    vector<XY> xys(N);
    for (int i = 0; i < N; i++) {
        int x, y; cin>>x>>y;
        xys[i].x = x; xys[i].y = y;
        map[{x, y}] = i;
    }
    function<void(XY, vector<bool>&, int, int)> find = [&](XY s, vector<bool>& used, int p, int q) {
        used[map[s]] = true;
        XY next = XY{s.x+p, s.y+q};
        XY prev = XY{s.x-p, s.y-q};
        if (map.find(next) != map.end() and not used[map[next]]) {
            find(next, used, p, q);
        }
        if (map.find(prev) != map.end() and not used[map[prev]]) {
            find(prev, used, p, q);
        }
    };
    int ans = numeric_limits<int>::max();
    for (int s = 0; s < N; s++) {
        auto& src = xys[s];
        for (int t = 0; t < N; t++) {
            if (t == s)
                continue;
            auto& tar = xys[t];
            int p = tar.x-src.x;
            int q = tar.y-src.y;
            vector<bool> used(N, false);
            int cnt = 0;
            for (int i = 0; i < N; i++) {
                if (not used[i]) {
                    find(xys[i], used, p, q);
                    cnt++;
                }
            }
            ans = min(ans, cnt);
        }
    }
    if (N == 1)
        ans = 1;
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	long long a,b,total=0LL;
	cin>>a>>b;
	if(a==1)total+=300000;
	if(a==2)total+=200000;
	if(a==3)total+=100000;
	if(b==1)total+=300000;
	if(b==2)total+=200000;
	if(b==3)total+=100000;
	if(total==600000)total+=400000;
	cout<<total;
	return 0;
	
}

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

int main() {
  int A, V, B, W, T;
  cin >> A >> V >> B >> W >> T;
  if (V - W == 0 || abs(B - A) * 1.0 / (V - W) < 0 ||
      T < abs(B - A) * 1.0 / (V - W)) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}


Measured memory_bytes: 3596
v=pow(10,9)+7
arr=[]
inp = list(map(int,input().split()))
row=inp[0]
col=inp[1]
for i in range(row):
    s=input()
    arr.append(s)
ans=[[0 for i in range(col)]for j in range(row)]
for i in range(col):
    if arr[0][i]=='#':
        break
    else:
        ans[0][i]=1
for i in range(row):
    if arr[i][0]=='#':
        break
    else:
        ans[i][0]=1
for i in range(1,row):
    for j in range(1,col):
        if arr[i][j]=='#':
            continue
        else:
            ans[i][j]=(ans[i-1][j]+ans[i][j-1])%v
print (ans[-1][-1])

Measured memory_bytes: 50452
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, m;
    cin >> n >> m;
    vi x(n);
    map<int, multiset<int>> cnt;
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
        cnt[x[i] % m].insert(x[i]);
    }
    ll ret       = 0;
    auto pairing = [&](int nmin, int &nmax, multiset<int> &mset) {
        auto it = mset.begin();
        while (nmax > nmin && next(it) != mset.end()) {
            if (*it == *next(it)) {
                ret++;
                nmax -= 2;
                it = next(it, 2);
            } else {
                ++it;
            }
        }
    };
    int mmax = m / 2;
    if (m % 2 == 1)
        mmax++;
    for (int i = 1; i < mmax; ++i) {
        int ni  = cnt[i].size();
        int nj  = cnt[m - i].size();
        auto it = cnt[m - i].begin();
        if (ni > nj)
            pairing(nj, ni, cnt[i]);
        else if (ni < nj)
            pairing(ni, nj, cnt[m - i]);
        ret += min(ni, nj);
    }
    ret += cnt[0].size() / 2;
    if (m % 2 == 0) {
        ret += cnt[m / 2].size() / 2;
    }
    cout << ret << "\n";
    return 0;
}

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

long long int calc(long long int n, long long int a, long long int b)
{
    //long long int reslut = 0;
    if (a == b)
    {
        return 1;
    }
    long long int max = a + b * (n - 1);
    long long int min = a * (n - 1) + b;
    return max - min + 1;
}

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

    if (b - a < 0 || (n == 1 && b != a))
    {
        cout << 0 << endl;
    }
    else
    {
        long long int result;
        result = calc(n, a, b);
        cout << result << endl;
    }
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    int N = 100;
    int[] ary = new int[N+1];
    while(true) {
        auto input = readln.chomp;
        if (stdin.eof) break;
        ary[input.to!size_t]++;
    }
    int maximum = ary.reduce!(max);
    foreach(size_t i; 0..ary.length) if (ary[i]==maximum) i.writeln;
}

Measured memory_bytes: 2448
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}


int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int a, b;
string s, t;

signed main() {
	cin >> a >> b;
	if (a < b) {
		for (int i = 0; i < b; i++)cout << a;
	}
	else {
		for (int i = 0; i < a; i++)cout << b;
	}
	cout << endl;
}

Measured memory_bytes: 256
import sys

n = int(input())
A = [int(_) for _ in input().split()]

if n == 1 or n == 2 or n == 3:
    print(max(A))
    sys.exit()

dp = [[0, 0] for j in range(n)]
M = - float('inf')
for i in range(4):
    M = max(M, A[i])
    dp[i][0] = M
dp[2][1] = dp[0][0] + A[2]
dp[3][1] = max(dp[1][0] + A[3], dp[2][1])

for i in range(4, n):
    for j in range(2):
        if i % 2 == 0 and j == 1:
            dp[i][j] = dp[i-2][1] + A[i]
        elif i % 2 == 0 and j == 0:
            dp[i][j] = max(dp[i-2][0] + A[i], dp[i-1][1])
        elif i % 2 == 1 and j == 1:
            dp[i][j] = max(dp[i-2][1] + A[i], dp[i-1][1])
        else:
            dp[i][j] = max(dp[i-2][0] + A[i], dp[i-1][0])

print(dp[n-1][(n+1)%2])

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

constexpr int INF = 1e9;

class union_find {
public:
    union_find(int N)
        : par(N, -1), rank(N), w(N)
    {}

    pair<int, int> root(int x) {
        if(par[x] < 0) {
            return make_pair(x, 0);
        }
        pair<int, int> p = root(par[x]);
        w[x] += p.second;
        p.second = w[x];
        par[x] = p.first;
        return p;
    }

    void unite(int x, int y, int v) {
        int rx = root(x).first, ry = root(y).first;
        if(rx == ry) {
            return;
        }
        if(rank[rx] > rank[ry]) {
            par[ry] = rx;
            w[ry] = v - w[y] + w[x];
        } else {
            par[rx] = ry;
            w[rx] = -v + w[y] - w[x];
            if(rank[rx] == rank[ry]) {
                rank[ry]++;
            }
        }
    }

    int calc(int x, int y) {
        if(root(x).first != root(y).first) {
            return INF;
        }
        return w[y] - w[x];
    }
        
private:
    vector<int> par;
    vector<int> rank;
    vector<int> w;
};

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        union_find uf(N);
        for(int i=0; i<M; ++i) {
            char op; cin >> op;
            if(op == '!') {
                int a, b, v;
                cin >> a >> b >> v;
                a--; b--;
                uf.unite(a, b, v);
            } else {
                int a, b;
                cin >> a >> b;
                a--; b--;
                if(uf.calc(a, b) == INF) {
                    cout << "UNKNOWN" << endl;
                } else {
                    cout << uf.calc(a, b) << endl;
                }
            }
        }
    }
}

Measured memory_bytes: 4084
#include<iostream>
using namespace std; // 575

const int MAX = 200001;
int main() {
	int N;
	string S;
	cin >> N >> S;
	static int cumsum[MAX], ans = N;
	cumsum[0] = 0;
	for (int i = 0;i < N;++ i) cumsum[i + 1] = cumsum[i] + (S[i] == '#' ? 1 : 0);
	for (int i = 0;i <= N;++ i) { // 決め打ち
		ans = min(ans, cumsum[i] + (N - i) - (cumsum[N] - cumsum[i]));
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

#.となっている周囲を考える
.#.なら...が最適
##.なら###が最適
……ということでどっちに塗るか考える
.....#####....となっていたとして
.....#########にするか
..............にするかの2択
……というか答えについて考える
##########..........…しかあり得ないわ

*/

Measured memory_bytes: 1284
import math, collections

def combinations_count(n):
  d = 2
  if n < d:
    return 0
  return math.factorial(n) // (math.factorial(n - d) * math.factorial(d))
      

rows = int(input()) 
str_list = [input() for i in range(rows)]
sorted_str_list = map(lambda s: ''.join(sorted(s)), str_list)
  
counter = collections.Counter(sorted_str_list)
ans = sum(map(lambda v: combinations_count(v), counter.values()))
print(ans)


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

int main() {
	int a, b;
	char op;
	while(cin >> a >> op >> b) {
		switch(op) {
			case '?': break;
			case '+': cout << a+b << endl;
					  continue;
			case '-': cout << a-b << endl;
					  continue;
			case '*': cout << a*b << endl;
					  continue;
			case '/': cout << a/b << endl;
					  continue;
		}

		return 0;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int maxN = 200011;

int n, i, x, ans;
int dp[maxN];

int main()
{
   // freopen("test.in","r",stdin);

    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> x;
        dp[x] = dp[x - 1] + 1;
        ans = max(ans, dp[x]);
    }

    cout << n - ans;


    return 0;
}


Measured memory_bytes: 1024
#[allow(dead_code)]
fn main() {
    let (a, b, c, d) = (i::u(), i::u(), i::u(), i::u());
    let total = b - a + 1;
    let cd = c * d / gcd(c, d);
    let cnum = if b / c == 0 {
        0
    } else {
        b / c - (a / c + if a % c > 0 { 1 } else { 0 }) + 1
    };
    let dnum = if b / d == 0 {
        0
    } else {
        b / d - (a / d + if a % d > 0 { 1 } else { 0 }) + 1
    };
    let cdnum = if b / cd == 0 {
        0
    } else {
        b / cd - (a / cd + if a % cd > 0 { 1 } else { 0 }) + 1
    };
    println!("{}", total - cnum - dnum + cdnum);
  //  dbg!(total, cnum, dnum, cdnum);
}

#[allow(unused_imports)]
use greatest_common_divisor::*;

#[allow(dead_code)]
mod greatest_common_divisor {
    use std::mem::swap;

    pub fn gcd(mut a: usize, mut b: usize) -> usize {
        if a < b {
            swap(&mut b, &mut a);
        }
        let mut c = 0;
        while b != 0 {
            a = a % b;
            swap(&mut a, &mut b);
            c += 1;
            //    println!("{}", c);
        }
        a
    }
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto& e : a) cin >> e;
    bool rev = false;
    vector<int> b, c;
    for(int i = 0; i < n; i++){
        if(rev){
            c.push_back(a[i]);
        }else{
            b.push_back(a[i]);
        }
        rev ^= true;
    }
    if(rev){
        for(int i = b.size() - 1; i >= 0; i--){
            cout << b[i] << " ";
        }
        for(int i = 0; i < c.size(); i++){
            cout << c[i] << " ";
        }
    }else{
        for(int i = c.size() - 1; i >= 0; i--){
            cout << c[i] << " ";
        }
        for(int i = 0; i < b.size(); i++){
            cout << b[i] << " ";
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3956
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    seika s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    seika ans(51, 'z');
    for (int i = 0; i + m <= n; i++)
    {
        bool ok = 1;
        seika cur = s;
        for (int j = 0; j < m; j++)
        {
            if (s[i + j] != '?' && s[i + j] != t[j])
            {
                ok = 0;
            }
            cur[i + j] = t[j];
        }
        if (ok)
        {
            for (int j = 0; j < n; j++)
            {
                if (cur[j] == '?')
                {
                    cur[j] = 'a';
                }
            }
            ans = min(ans, cur);
        }
    }
    if (ans.size() == 51)
    {
        ans = "UNRESTORABLE";
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define rev(r) reverse(r.begin(),r.end())
#define SORT(ar) sort(ar.begin(), ar.end())
#define sz(x) (int)(x).size()
#define len(x) (int)x.length()
#define in(a) scanf("%d",&a)
#define pr(x) printf("%d ",x)
#define endl '\n'
#define read(v,n) for(int h=0;h<n;h++) cin>>v[h];
#define fo(i,a,b) for(i=a;i<b;i++)
#define fi(i,a,b) for(i=a;i>=b;i--)
#define mo 1000000007
#define N 200007
vector<int>adj[100005];
int vis[100005];
ll a[100005][2];

void dfs(int u)
{
    vis[u]=1;
    int i;
    fo(i,0,adj[u].size())
    {
        if(!vis[adj[u][i]]) {
            dfs(adj[u][i]);
            a[u][1]=(a[u][1]*a[adj[u][i]][0])%mo;
            a[u][0]=(a[u][0]*(a[adj[u][i]][0]+a[adj[u][i]][1]))%mo;
        }
    }
}

int main()
{
    int n,i,j,k,x,y;
    cin>>n;
    fo(i,0,n-1)
    {
        in(x); in(y);
        adj[x].pb(y);
        adj[y].pb(x);
    }
    fo(i,1,n+1)
    {
        a[i][0]=1;
        a[i][1]=1;
    }
    dfs(1);
    cout<<(a[1][0]+a[1][1])%mo<<endl;
}


Measured memory_bytes: 11776
<?php

$results = [
    'AC'  => 0,
    'WA'  => 0,
    'TLE' => 0,
    'RE'  => 0
];

fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%s", $result);
    ++$results[$result];
}

foreach ($results as $result => $count) {
    echo $result . ' x ' . $count . PHP_EOL;
}


Measured memory_bytes: 16196
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << 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 (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll A, B, N;
    cin >> A >> B >> N;

    ll res = 0;
    if(N>=B){
        res = (A*(B-1))/B;
    }else{
        res = (A*N)/B;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main() {
  int H, W;
  while (true) {
    cin >> H >> W;
    if (H == 0 && W == 0)
      break;
    for (int i = 0; i < H; i++) {
      if (i % 2 == 0) {
        for (int j = 0; j < W; j++) {
          if (j % 2 == 0)
            cout << "#";
          else
            cout << ".";
        }
      } else {
        for (int j = 0; j < W; j++) {
          if (j % 2 == 0)
            cout << ".";
          else
            cout << "#";
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#include<stdio.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define _USE_MATH_DEFINES
#define f first
//#define s second
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF 1000000000000000000
#define MAXN (int)(1e7)+1
#define MOD 1000000007
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pwi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<pair<ll,ll > > > wGraph;
typedef vector<vector<ll> > graph;
//typedef vector<vector<ll> > matrix;

int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(2);

    int n,m;
    cin>>n>>m;
    ll k;
    cin>>k;

    vll a(n),b(m);

    ll res = 0;
    for(ll i = 0;i<n;++i){
        if(i == 0) cin>>a[i];
        else{
            cin>>a[i];
            a[i]+=a[i-1];
        }
        if(a[i]<=k){
            res = max(res,i+1);
        }
    }
    for(ll i = 0;i<m;++i){
        if(i == 0) cin>>b[i];
        else{
            cin>>b[i];
            b[i]+=b[i-1];
        }
        if(b[i]<=k){
            res = max(res,i+1);
        }
    }

    
    for(ll i = 0;i<n;++i){
        if(a[i] <= k){
            
            ll l = 0;
            ll r = b.size()-1;

            while(l<=r){
                ll mid = (l+r)/2;
                if(a[i]<=k-b[mid]){
                    //cout<<"VALS: "<<a[i]<<" + "<<b[mid]<<" with mid: "<<mid<<endl;
                    res = max(res,i+mid+2);
                    l = mid+1;
                }else{
                    r = mid-1;
                }
            }

        }
    }

    cout<<res<<endl;

    return 0;   
}


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

using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) reep((i),0,(n))
#define PB push_back
#define mkp make_pair
#define F first
#define S second

typedef vector<int> vint;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector<pair<pii,string>> vip;

string s;
int n;

vector<vip> node;
vll cnt;

void func(int l,int r,int root){
	// cout<<l<<" "<<r<<" "<<root<<" "<<s.substr(l,r-l+1)<<endl;
	reep(i,l,r+1){
		// if(l==14) cout<<i<<endl;
		if(isdigit(s[i])){
			int num = 0;
			int pos = i;
			while(isdigit(s[pos])) num=num*10+s[pos++]-'0';
			node.PB(vip(0));
			// cout<<"num "<<num<<endl;
			if(s[pos]=='('){
				bool ok = true;
				int pp = pos+1;
				bool f = true;
				while(1){
					if(s[pp]=='(') ok=false;
					if(s[pp]==')') break;
					if(isdigit(s[pp])) f=false;
					pp++;
				}
				if(ok&&f){
					node[root].PB(mkp(pii(num,node.size()-1),s.substr(pos+1,pp-pos-1)));
					i=pp;
				}
				else if(ok){
					node[root].PB(mkp(pii(num,node.size()-1),""));
					func(pos+1,pp-1,node.size()-1);
					i=pp;
				}
				else{
					pp = pos;
					int aa = 0;
					int bb = 0;
					while(1){
						if(s[pp]=='(') aa++;
						if(s[pp]==')') bb++;
						if(aa==bb) break;
						pp++;
					}
					node[root].PB(mkp(pii(num,node.size()-1),""));
					func(pos+1,pp-1,node.size()-1);
					i=pp;
				}
			}
			else{
				node[root].PB(mkp(pii(num,node.size()-1),s.substr(pos,1)));
				i=pos;
			}
		}
		else{
			string a="";
			int pos = i;
			while(pos<s.size()&&isupper(s[pos])) a+=s[pos++];
			node.PB(vip(0));
			node[root].PB(mkp(pii(1,node.size()-1),a));
			i=pos-1;
		}
	}
}

void visual(int x){
	for(auto y:node[x]){
		cout<<y.F.F<<" "<<y.F.S<<" "<<y.S<<" "<<x<<endl;
		visual(y.F.S);
	}
}

ll dfs(int x){
	ll ret = 0;
	for(auto y:node[x]){
		if(node[y.F.S].size()==0){
			cnt[y.F.S] = y.S.size();
			ret+=cnt[y.F.S]*y.F.F;
			// cout<<y.F.S<<" "<<y.S<<" "<<cnt[y.F.S]<<endl;
		}
		else{
			ret+=dfs(y.F.S)*y.F.F;
			// cout<<y.F.S<<" "<<y.S<<" "<<cnt[y.F.S]<<endl;
		}
	}
	return cnt[x]=min((ll)INT_MAX,ret);
}

void calc(int x,int n){
	ll c = 0;
	// cout<<x<<" "<<n<<" "<<cnt[x]<<endl;
	for(auto y:node[x]){
		c+=cnt[y.F.S]*y.F.F;
		// cout<<c<<endl;
		if(n<c){
			if(y.S.size()){
				n=n-(c-cnt[y.F.S]*y.F.F);
				assert(n>=0);
				cout<<y.S[n%y.S.size()]<<endl;
				return;
			}
			else{
				n=n-(c-cnt[y.F.S]*y.F.F);
				assert(n>=0);
				// cout<<y.F.S<<" "<<n%cnt[y.F.S]<<endl;
				calc(y.F.S,n%cnt[y.F.S]);
			}
			break;
		}
	}
}

int main(){
	while(cin>>s>>n){
		if(s=="0"){
			break;
		}
		node.assign(1,vip(0));
		func(0,s.size()-1,0);
		cnt=vll(node.size());
		dfs(0);
		// cout<<endl;
		// visual(0);
		if(n>=cnt[0]){
			cout<<0<<endl;
		}
		else{
			calc(0,n);
		}
	}
}

Measured memory_bytes: 3040
#include <stdio.h>
#define MOD 1000000007

int main()
{   long long n,k,i,j;
    scanf("%lld%lld",&n,&k);
    long long a[2001];
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
    }
    long long front=0,rear=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            if(a[i]>a[j]){
                rear++;
            }
        }
        for(j=0;j<i;j++){
            if(a[i]>a[j]){
                front++;
            }
        }
    }
    long long ans=(rear+front)*((k-1)*k/2%MOD)+rear*k;
        
    printf("%lld",ans%MOD);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main() {

    int n,m;
    cin>>n>>m;
    int a[m];
    for (int i = 0; i < m; ++i) {
        cin>>a[i];
    }
    sort(a,a+m);
    int s[m-1];
    long long int sum=0;
    for (int i = 0; i< m-1; ++i) {
        s[i]=a[i+1]-a[i];
        sum+=s[i];
    }
    sort(s,s+m-1);
    int count=0;
    for (int k = m-2; k>=0&&count<n-1; k--) {
        sum-=s[k];
        count++;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 1024