akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] hoge = sc.nextLine().split(" ");
        int line = Integer.parseInt(hoge[0]);
        int row = Integer.parseInt(hoge[1]);
        int[][] maze = new int[line][row];
        int result =0;
        for(int l=0;l<line;l++){
            char[] hoja = sc.nextLine().toCharArray();
            for(int r=0;r<row;r++){
                if(hoja[r]=='.'){
                    maze[l][r]=0;
                }else{
                    maze[l][r]=-1;
                }
            }
        }
        for(int l=0;l<line;l++){
            for(int r=0;r<row;r++){
                    int c = calc(maze,l,r,line,row);
                    if(result<c)result=c;
            }
        }
        System.out.println(result);
    }
    private static int calc(int[][] arg,int x,int y,int line,int row){
        int[][] maze = new int[line][row];
        for(int l=0;l<line;l++){
            for(int r=0;r<row;r++){
                maze[l][r]=arg[l][r];
            }
        }
        if(maze[x][y]==-1)return 0;
        maze[x][y]=1;
        int result = 1;
        for(int i=2;i<=line*row;i++) {
            for (int l = 0; l < line; l++) {
                for (int r = 0; r < row; r++) {
                    if(maze[l][r]==0) {
                        if (l > 0 && maze[l - 1][r] == i - 1) {
                            maze[l][r] = i;
                            result = i;
                        }
                        if (l < line - 1 && maze[l + 1][r] == i - 1) {
                            maze[l][r] = i;
                            result = i;
                        }
                        if (r > 0 && maze[l][r - 1] == i - 1) {
                            maze[l][r] = i;
                            result = i;
                        }
                        if (r < row - 1 && maze[l][r + 1] == i - 1) {
                            maze[l][r] = i;
                            result = i;
                        }
                    }
                }
            }
        }
        return  result-1;
    }
}

Measured memory_bytes: 24512
n = int(input())

l = "abcdefghijklmnopqrstuvwxyz"

d = {}

S = input()
for aa in l:
    d[aa] = S.count(aa)

for _ in range(n - 1):
    S = input()
    for aa in l:
        d[aa] = min(d[aa], S.count(aa))

ans = ''

for aa in l:
    ans += aa * d[aa]

print(ans)


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

using namespace std;

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

     if(a<500)
     {
         b=a/5;
         cout << b*5;
     }
     else
     {
        r=a%500;
        b=a/500;
        t=r/5;
        cout << ((b*500*2)+(t*5));

     }
     return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846
#ifdef LOCAL
#include <sys/types.h>
#include <sys/timeb.h>
#include <intrin.h> 
#include <thread>
#else
#include <sys/time.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

int main(){
	int n;
	scanf("%d", &n);
	bool flag = false;
	REP(i, n) {
		int t;
		scanf("%d", &t);
		if (t & 1)flag = true;
	}
	if (flag)cout << "first" << endl;
	else cout << "second" << endl;
	return 0;
}

Measured memory_bytes: 256
MOD = 10**9+7
N = int(input())
*A, = map(int, input().split())
a = [0]*N
a[-1] = A[-1]
for i in range(N-2, -1, -1):
    a[i] = A[i]+a[i+1]

ans = 0
for i in range(N-1):
    ans += A[i]*a[i+1]
    ans %= MOD
print(ans)


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

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

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size()) 
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

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

int IT_MAX = 1 << 17;
const ll MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

ll mul_inv(ll a, ll b = MOD) {
	ll t1 = a, t2 = b, t3;
	ll v1 = 1, v2 = 0, v3;
	while (t2 != 1) {
		ll x = t1 / t2;
		t3 = t1 - x*t2;
		v3 = v1 - x*v2;
		t1 = t2, t2 = t3;
		v1 = v2, v2 = v3;
	}
	return (v2 + b) % b;
}
ll F[300050];
ll Finv[300050];
ll Co(ll a, ll b) {
	if (a == -1) return 1;
	if (b < 0 || b > a) return 0;
	ll rv = F[a] * Finv[b] % MOD;
	return rv * Finv[a - b] % MOD;
}

char SA[100050];
char SB[100050];
char SC[100050];
char SD[100050];

ll va[100050];
ll vb[100050];
ll getans(char* SA, char* SB, char* SC, char* SD, int N, int M) {
	int c1 = 0, c2 = 0, i, j;
	for (i = 1; i <= M; i++) if (SC[i] == '1') c1++;
	for (i = 1; i <= M; i++) if (SD[i] == '1') c2++;

	vb[N + 1] = Co(c2 - 1, 0);
	int s = 0;
	for (i = N; i >= 1; i--) {
		if (SA[i] == '1') s++;
		if (SB[i] == '1') s++;
		vb[i] = Co(c2 + s - 1, s);
	}
	va[0] = Co(c1 - 1, 0);
	s = 0;
	ll x = 1;
	for (i = 1; i <= N; i++) {
		if (SA[i] == '1') s++;
		if (SB[i] == '1') s++;
		if (SA[i] == '1' && SB[i] == '1') x = x * mul_inv(2) % MOD;
		va[i] = Co(c1 + s - 1, s) * x % MOD;
	}

	ll rv = 0;
	ll tu = va[0];
	x = 1;
	for (i = 1; i <= N; i++) {
		if (SA[i] == '0' && SB[i] == '0') continue;
		if (SA[i] == '1' && SB[i] == '1') x = x * 2 % MOD;
		rv = (rv + tu * x % MOD * vb[i + 1]) % MOD;
		tu = (tu + va[i]) % MOD;
	}
	return rv;
}
int main() {
	int N, M, i, j;
	F[0] = 1;
	for (i = 1; i <= 300000; i++) F[i] = F[i - 1] * i % MOD;
	for (i = 0; i <= 300000; i++) Finv[i] = mul_inv(F[i]);

	scanf("%d %d", &N, &M);
	scanf("%s %s %s %s", SA+1, SB+1, SC+1, SD+1);
	
	for (i = 1; i <= N; i++) if (SA[i] == '1' || SB[i] == '1') break;
	for (j = 1; j <= M; j++) if (SC[j] == '1' || SD[j] == '1') break;
	if (i > N && j > M) return !printf("1\n");

	ll ans = getans(SA, SB, SC, SD, N, M) + getans(SC, SD, SA, SB, M, N);
	return !printf("%lld\n", ans % MOD);
}

Measured memory_bytes: 7040
n = int(input())

b = list(map(int, input().split()))

a = [0]*n

a[0] = b[0]
for i in range(1, n-1):
    a[i] = min(b[i-1], b[i])
    
a[-1] = b[-1]

ans = sum(a)

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  long long N, K;
  std::cin >> N >> K;
  long long t = N % K;
  std::cout << std::min(t, K - t) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int r,c,i,j;
    int **a;
    scanf("%d",&r);
    scanf("%d",&c);
    a = (int **)malloc(sizeof( int *) * (r+1));
    for(i=0;i<(r+1);i++){
        a[i] = (int *)malloc(sizeof(int) * (c+1));
    }
    for(i=0;i<(r+1);i++){
            for(j=0;j<(c+1);j++){
                a[i][j] = 0;
            }
    }

    for(i=0;i<r;i++){
        for(j = 0;j < c;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(i=0;i<r;i++){
        for(j = 0;j < c;j++){
            a[i][c] += a[i][j];
            a[r][j] += a[i][j];
            a[r][c] += a[i][j];
        }
    }
    for(i=0;i<=r;i++){
        for(j = 0;j<=c;j++){
            if(j != c) printf("%d ",a[i][j]);
            else printf("%d\n",a[i][j]);
        }
    }
    free(a);
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
    using namespace std;
     
    int main()
    {
      int a, b;
      b = 0;
      cin >> a;
      b = b + a % 10;
      b = b + ((a - b) / 10) % 10;
      b = b + a / 100;
      cout << b << endl;
      return 0;
    }

Measured memory_bytes: 256
#include<stdio.h>

#include<limits.h>   

int main(void) {    

int i, n, a;    

int min=INT_MAX, max=INT_MIN;    

long long sum=0;    

scanf("%d", &n);     

for(i=0; i<n; i++) {         

scanf("%d", &a);         

if(a<min) min=a;         

if(max<a) max=a;        

sum+=a;    

}     

printf("%d %d %lld\n", min, max, sum);    

return 0;

}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007LL
#define INF 5000000000000000000
#define PI 3.1415926

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

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T> inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int a, b, c; cin >> a >> b >> c;
	cout << min(b/a, c) << endl;

	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n;
	cin>>n;
	ll ans=0;
	int last=0;
	rep(i,n){
		int a;
		cin>>a;
		if(a<last){
			ans+=last-a;
		}
		else{
			last=a;
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3612
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	@SuppressWarnings("unchecked")
	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			n = scanner.nextInt();
			if (n == 0)
				break;
			lists = new ArrayList[n];
			for (int i = 0; i < n; i++)
				lists[i] = new ArrayList<Edge>();
			for (int i = 0; i < n - 1; i++) {
				int from = scanner.nextInt() - 1;
				int to = scanner.nextInt() - 1;
				int cost = scanner.nextInt();
				lists[from].add(new Edge(to, cost));
				lists[to].add(new Edge(from, cost));
			}
			for (int i = 0; i < n; i++) {
				if (lists[i].size() == 1 && i != 0) {
					lists[i].get(0).cost = INF;
				} else
					for (Edge edge : lists[i]) {
						if (lists[edge.to].size() == 1 && edge.to != 0)
							edge.cost = INF;
					}
			}
			int sum = 0;
			for (List<Edge> list : lists)
				for (Edge edge : list)
					if (edge.cost != INF)
						sum += edge.cost;
			PriorityQueue<Edge> pq = new PriorityQueue<Edge>();
			pq.offer(new Edge(0, 0));
			int[] costs = new int[n];
			Arrays.fill(costs, 1 << 24);
			costs[0] = 0;
			while (!pq.isEmpty()) {
				Edge edge = pq.poll();
				if (costs[edge.to] < edge.cost)
					continue;
				for (Edge e : lists[edge.to]) {
					if (costs[e.to] > e.cost + edge.cost) {
						costs[e.to] = e.cost + edge.cost;
						pq.offer(new Edge(e.to, costs[e.to]));
					}
				}
			}
			int max = 0;
			for (int ans : costs) {
				if (ans == INF)
					continue;
				max = Math.max(max, ans);
			}
			System.out.println(sum - max);
		}
	}

	int n;
	List<Edge>[] lists;
	int INF = 1 << 24;

	class Edge implements Comparable<Edge> {
		int to, cost;

		Edge() {
		}

		public Edge(int to, int cost) {
			super();
			this.to = to;
			this.cost = cost;
		}

		@Override
		public String toString() {
			return "Edge [to=" + to + ", cost=" + cost + "]";
		}

		@Override
		public int compareTo(Edge o) {
			return this.cost - o.cost;
		}

	}
}

Measured memory_bytes: 23480
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

string s1, s2;

void solve() {
  int dp[s1.size() + 1][s2.size() + 1];
  for (int i = 0; i <= s1.size(); i++) {
    dp[i][0] = i;
  }
  for (int i = 0; i <= s2.size(); i++) {
    dp[0][i] = i;
  }

  for (int i = 1; i <= s1.size(); i++) {
    for (int j = 1; j <= s2.size(); j++) {
      int flag;
      if (s1[i - 1] == s2[j - 1]) flag = 0;
      else flag = 1;
      dp[i][j] =
	min(dp[i - 1][j] + 1, min(dp[i][j - 1] + 1, dp[i - 1][j - 1] + flag));
    }
  }
  cout << dp[s1.size()][s2.size()] << endl;
}

int main() {
  cin >> s1 >> s2;
  solve();
  return 0;
}

Measured memory_bytes: 6996
# /user/bin/python
# -*- coding: utf-8 -*-
import sys
import numpy as np


def solve(s):
  if s[0] != 'A':
    return False
  if s[2:-1].count('C') != 1:
    return False
  s = s[1:]
  s = s[:-1].replace("C", "") + s[-1]
  for c in s:
    if c not in 'abcdefghijklmnopqrstuvwxyz':
      return False
  return True

s = str(input())
if solve(s):
  print('AC')
else:
  print('WA')

Measured memory_bytes: 12380
#![allow(non_snake_case)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(
        a: f32,
        b: f32,
    );
    let ad = (a / 0.08).ceil() as i32;
    let bd = (b / 0.1).ceil() as i32;
    let down = std::cmp::max(ad, bd) as f32;
    if ((down * 0.08).floor() == a) && ((down * 0.1).floor() == b) {
        println!("{}", down);
    } else {
        println!("-1");
    }

}



Measured memory_bytes: 4352
#include<stdio.h>
int main(){
  int flag=1;
  int n,m,i,j,count=0;
  int a[100];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  while(flag){
    flag=0;
    for(j=n-1;j>=1;j--){
      if(a[j]<a[j-1]){
	m=a[j];
	a[j]=a[j-1];
	a[j-1]=m;
	flag=1;
	count++;
      }
    }
  }

  for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d",a[i]);
  printf("\n%d\n",count);

  return 0;
}



Measured memory_bytes: 2124
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N, Q;
vi q;
vi A;

void solve() {
    reverse(all(q));
    int prev = INF;
    for (auto& x : q) {
        if (x < prev) {
            prev = x;
            A.emplace_back(x);
        }
    }
    int MAX = min(prev, N);
    chmin(prev, N + 1);
    for (int i = prev - 1; i >= 1; i--) {
        A.emplace_back(i);
    }

    map<int, int> dp;
    dp[A[0]] = 1;
    reverse(all(A));
    for (int i = A.size() - 1; i >= 0; i--) {
        int a = A[i];
        if (a <= MAX)
            break;
        int x = a;
        int num = dp[x];
        while (x) {
            auto it = upper_bound(all(A), x);
            it--;
            if (*it == a)
                it--;
            dp[*it] += num * (x / *it);
            x %= *it;
        }
    }
    int cnt = 0;
    int ans[101010] = {};
    for (int i = MAX; i >= 1; i--) {
        cnt += dp[i];
        ans[i] = cnt;
    }
    for (int i = 1; i <= N; i++) {
        cout << ans[i] << endl;
    }
}

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

    cin >> N >> Q;
    q.resize(Q);
    for (int i = 0; i < Q; i++) {
        cin >> q[i];
    }


    solve();
    return 0;
}


Measured memory_bytes: 18772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n;
    cin>>n;
    vector<int> a;
    a.push_back(0);
    rep(i,n){
        int x;
        cin>>x;
        a.push_back(x);
    }
    a.push_back(0);

    ll ans=0;
    rep(i,n+1){
        ans+=abs(a[i+1]-a[i]);
    }

    for(int i=1;i<=n;i++){
        ll tmp=abs(a[i-1]-a[i+1]);
        cout<<ans+tmp-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])<<endl;
    }
}

Measured memory_bytes: 3900
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int func(string x, string y)
{
        int ans = 0;
        for (char c = 'a'; c <= 'z'; c++)
        {
                bool l = false, r = false;
                for (int i = 0; i < x.length(); i++)
                {
                        if (x[i] == c)
                        {
                                l = true;
                        }
                }
                for (int i = 0; i < y.length(); i++)
                {
                        if (y[i] == c)
                        {
                                r = true;
                        }
                }
                if (l && r)
                {
                        ans++;
                }
        }
        return ans;
}

int main()
{
        //input->compute->output//
        int N;
        string S;
        cin >> N >> S;

        int ans = 0;
        for (int i = 0; i < N + 1; i++)
        {
                string le = S.substr(0, i);
                string ri = S.substr(i);
                int cnt = func(le, ri);
                ans = max(ans, cnt);
                }
        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main()
{
    int i, x;
    
    for(i=1; i<=10000; i++)
    
    {
        cin >> x;
        if (x==0)
       break;
        cout << "Case" << " "<< i << ":" << " " << x <<endl; 
    
   
      
    }
}


Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}

void solve() {
	int n;
	cin >> n;
	vl a(n);
	ll ans = 0;
	rep(i, 0, n)cin >> a[i];
	rep(i, 0, n - 2) {
		rep(j, i + 1, n - 1) {
			rep(k, j + 1, n) {
				if (a[i] != a[j] && a[j] != a[k] && a[i] != a[k]) {
					vl temp = {a[i], a[j], a[k]};
					sort(all(temp));
					if (temp[0] + temp[1] > temp[2]) {
						ans++;
						// trace(temp[0], temp[1], temp[2], i, j, k, a[i], a[j])
					}
				}
			}
		}
	}
	cout << ans;
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3660
using System;
using System.Linq;

namespace killme
{
    public static class Program
    {
        public static void Main()
        {
            var times = Console.ReadLine()
                .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => int.Parse(x))
                .ToArray();

            var ans1 = times[0] + times[1];
            var ans2 = times[0] + times[2];
            var ans3 = times[1] + times[2];

            var ans = ans1;
            if (ans > ans2)
            {
                ans = ans2;
            }
            if (ans > ans3)
            {
                ans = ans3;
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13268
from itertools import permutations

ANSWER = 10

class FindException(Exception):
    def __init__(self, v):
        self.value = v

class SignNode():
    def __init__(self, s=None):
        self.sign = s
        self.children = []
        self.parent = None
        self.depth = 0
    
    def __repr__(self):
        return self.sign
    
    def calc(self, l, r):
        if self.sign == '+':
            return l + r
        elif self.sign == '-':
            return l - r
        elif self.sign == '*':
            return l * r
        else:
            raise ValueError()
    
    def express(self, l, r):
        if self.sign == '+':
            return '({0} + {1})'.format(l, r)
        elif self.sign == '-':
            return '({0} - {1})'.format(l, r)
        elif self.sign == '*':
            return '({0} * {1})'.format(l, r)
        else:
            raise ValueError()

def construct_sign_tree(node, depth=0):
    if depth >= 3:
        return
    for s in ['+', '-', '*']:
        new_node = SignNode(s)
        new_node.depth = node.depth + 1
        node.children.append(new_node)
        new_node.parent = node
        construct_sign_tree(new_node, depth+1)

SIGN_ROOT = SignNode()
construct_sign_tree(SIGN_ROOT)

def walk(node, numbers):
    if node.children:
        for child in node.children:
            walk(child, numbers)
    else:
        cur_node = node
        signs = []
        while cur_node.sign != None:
            signs.append(cur_node)
            cur_node = cur_node.parent
        signs.reverse()
        check(numbers, signs)

def check(numbers, signs):
    assert len(numbers) == 4
    assert len(signs) == 3
    for perm in permutations(numbers+signs):
        rev_polish = list(perm)
        rslt = rev_polish[:]
        stck = []
        while rev_polish:
            v = rev_polish.pop(0)
            if isinstance(v, SignNode):
                try:
                    r = stck.pop()
                    l = stck.pop()
                    stck.append(v.calc(l, r))
                except IndexError:
                    break
            else:
                stck.append(v)
        if len(stck) == 1 and stck.pop(0) == ANSWER:
            raise FindException(rslt)

def express(rev_polish):
    stck = []
    while rev_polish:
        v = rev_polish.pop(0)
        if isinstance(v, SignNode):
            r = stck.pop()
            l = stck.pop()
            stck.append(v.express(l, r))
        else:
            stck.append(v)
    return stck.pop()

def solve2():
    inp = input()
    while inp != '0 0 0 0':
        numbers = list(map(int, inp.split()))
        try:
            walk(SIGN_ROOT, numbers)
        except FindException as fe:
            print(express(fe.value))
        else:
            print(0)
        inp = input()

if __name__ == "__main__":
    solve2()



Measured memory_bytes: 5676
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstdio>
#include <climits>
#include <map>
#include <vector>
using namespace std;



int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0; i < n; i++) cin >> d.at(i);

    int sum = 0;
    for(int i = 0; i< n- 1; i++)
    {
        for(int j = i+1; j < n; j++)
        {
            sum += d.at(i)*d.at(j);
        }
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

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

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    vec<lint> A_list(N);
    range(i, 0, N) cin >> A_list.at(i);
    sort(A_list.begin(), A_list.end());
    lint last_broken = 0;
    lint cum_sum = A_list.at(0);
    range(i, 1, N) {
        lint A = A_list.at(i);
        if (cum_sum * 2 < A) last_broken = i;
        cum_sum += A;
    }
    cout << N - last_broken << "\n";
}

Measured memory_bytes: 1024
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O20")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = long long; using namespace std;

#ifndef __GNUC__
string text =
R"X(1500 2000 500 90000 100000)X";
stringstream iss{text};
#endif

int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	ll A, B, C, X, Y; iss >> A >> B >> C >> X >> Y;
	ll bXY = max(X, Y) * 2 + 1;
	ll price{LLONG_MAX};
	rep(c, bXY) {
		ll a = max(X - c / 2, 0ll);
		ll b = max(Y - c / 2, 0ll);
		price = min(price, a * A + b * B + c * C);
	}
	p(price);
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n+1), h(n+1);
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		h[b].push_back(a);
	}
	vector<int> bestcycle;
	for (int i = 1; i <= n; ++i) {
		vector<int> dist(n+1, -1);
		vector<int> pre(n+1, -1);
		queue<int> q;
		dist[i] = 0;
		q.push(i);
		while (!q.empty()) {
			int j = q.front();
			q.pop();
			for (int k : h[j]) {
				if (dist[k] == -1) {
					dist[k] = dist[j] + 1;
					pre[k] = j;
					q.push(k);
				}
			}
		}
		for (int j : g[i]) {
			if (dist[j] != -1 && (bestcycle.empty() || dist[j] + 1 < bestcycle.size())) {
				bestcycle.clear();
				while (j != -1) {
					bestcycle.push_back(j);
					j = pre[j];
				}
			}
		}
	}
	if (bestcycle.empty()) {
		cout << "-1\n";
	} else {
		cout << bestcycle.size() << endl;
		for (int x : bestcycle) {
			cout << x << endl;
		}
	}
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;

  ll ysfk = 0;
  rep(i, n) {
    ll x;
    cin >> x;
    ysfk += 2*min(abs(x), abs(x-k));
  }

  cout << ysfk << endl;

  return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define mod 1e9+7
using namespace std;
int main()
{
    ll a;
    cin>>a;
    ll p=ceil(a/1000000000.0);
    ll q=(p*1000000000)-a;
    cout<<0<<" "<<0<<" "<<1000000000<<" "<<1<<" "<<q<<" "<<p<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

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

		int[][] inputArray = new int[N][D];

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < D; j++) {
				inputArray[i][j] = sc.nextInt();
			}
		}

		int count = 0;
		for (int i = 0; i < N - 1; i++) {
			for (int j = i + 1; j < N; j++) {
				int sum = 0;
				for (int k = 0; k < D; k++) {
					sum += Math.pow(Math.abs(inputArray[i][k] - inputArray[j][k]), 2);
				}
				if(Math.floor(Math.sqrt(sum)) == Math.sqrt(sum)) {
					count++;
				}
			}
		}


		System.out.println(count);
		sc.close();
	}

}


Measured memory_bytes: 23124
#include<stdio.h>

int main(){

  double in;

  while(scanf("%lf",&in) != EOF){
    if(in > 91){
      
      printf("heavy\n");

    }else if(in > 81){

      printf("light heavy\n");

    }else if(in > 75){

      printf("middle\n");

    }else if(in > 69){

      printf("light middle\n");

    }else if(in > 64){

      printf("welter\n");

    }else if(in > 60){

      printf("light welter\n");

    }else if(in > 57){

      printf("light\n");

    }else if(in > 54){

      printf("feather\n");

    }else if(in > 51){

      printf("bantam\n");

    }else if(in > 48){

      printf("fly\n");

    }else{

      printf("light fly\n");

    }

  }

  return 0;

}

Measured memory_bytes: 0
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	cout<<max(0,a-2*b);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
typedef long long int llint;

int main(void){

  int n, k;
  std::cin >> n >> k;
  std::vector<double> e(n);
  for(int i=0; i<n; i++){
    double p;
    std::cin >> p;
    e[i] = 0.5 * (1+p);
  }

  double best = 0;
  double now = 0;
  for(int i=0; i<k; i++){
    now+=e[i];
  }
  best = now;

  for(int i=0; i<=n-k-1; i++){
    //std::cout << i << std::endl;
    now = now + e[i+k] - e[i];
    best = std::max(best, now);
  }

  std::printf("%.12f\n", best);
  return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] a = new int[N];
        long ans = 0;
        
        for(int i=0; i<N; i++){
            a[i] = sc.nextInt();
        }
        
        Arrays.sort(a);
        if(K>N){
            K = N;
        }
        for(int i=0; i<N-K; i++){
            ans += a[i];
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 59788
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int M, D; cin >> M >> D;
    int ans = 0;
    for (int m = 1; m <= M; m++) {
        for (int d = 1; d <= D; d++) {
            int d1 = d % 10;
            int d10 = d / 10;
            if (d1 >= 2 && d10 >= 2 && d1 * d10 == m) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
ans=[i for i in range(n+1)]
cnt=0
mod=10**9+7
for i in range(k,n+2):
    x=(n-i+1)*i+1
    # sum_1=sum(ans[0:i])
    # sum_2=sum(ans[n-i+1:n+1])
    # print(sum_2)
    # print(sum_1)
    # x=sum_2-sum_1+1
    cnt+=x
print(cnt%mod)



Measured memory_bytes: 16816
import statistics as st
import numpy as np

def test():
    ans = 0
    n = int(input())
    a = np.array(list(map(int,input().split())))
    i = np.array([i for i in range(1,n+1)])
    b = st.median(a-i)
    for k in range(n):
        ans += abs(a[k]-i[k]-b)
    print(int(ans))  


if __name__ == "__main__":
    test()


Measured memory_bytes: 35200
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    int A,B,C;
    vector<int> topping;
    int cost;
    int cal;

    cin >> N >> A >> B >> C;

    for(int i=0; i<N; ++i) {
        int temp;
        cin >> temp;
        topping.push_back(temp);
    }

    sort(topping.rbegin(),topping.rend());

    cost=A;
    cal=C;

    for(int i=0; i<N; ++i) {
        if(cal*(cost+B)<cost*(cal+topping[i])) {
            cost=cost+B;
            cal=cal+topping[i];
        } else {
            break;
        }
    }

    cout << cal/cost << endl;

    return 0;
}

Measured memory_bytes: 3152
n = gets.to_i
s = gets.chomp
e = (s[0] == 'E' ? [1] : [0])
w = (s[0] == 'W' ? [1] : [0])

1.upto(n - 1) do |i|
  if (s[i] == 'E')
    e[i] = e[i - 1] + 1
    w[i] = w[i - 1]
  else
    e[i] = e[i - 1]
    w[i] = w[i - 1] + 1
  end
end
w.unshift(0)
min = Float::INFINITY
0.upto(n - 1) do |i|
  min = e[-1] - e[i] + w[i] if min > e[-1] - e[i] + w[i]
end
puts min

Measured memory_bytes: 7808
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=lambda :sys.stdin.readline().rstrip()
def resolve():
    x=int(input())
    ans=0
    while(ans*(ans+1)<2*x): ans+=1
    print(ans)
resolve()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define in(e,l) (std::find(l.begin(), l.end(), e) != l.end())
#define asort(l) (std::sort(l.begin(), l.end()))
#define dsort(l) (std::sort(l.rbegin(), l.rend()))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;

int main() {
  long long A, B, N;
  cin >> A >> B >> N;
  cout << (A * min(N, B - 1) / B - A * (min(N, B-1) / B)) << endl;
  return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> G;
int n,arr[1000010];
int cnt=0,m;
void inserionSort(int arr[],int n, int g)
{
    int v;
    for(int i=g;i<n;i++){
        v=arr[i];
        int j=i-g;
        while(j>=0&&arr[j]>v){
            arr[j+g]=arr[j];
            j=j-g;
            cnt++;
        }
        arr[j+g]=v;
    }
}
void shellSort(int arr[],int n)
{
    for(m=1;m<=n;){
        G.push_back(m);
        m=3*m+1;
    }
    for(int i=G.size()-1;i>=0;i--)
        inserionSort(arr,n,G[i]);
}
int main()
{
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    shellSort(arr,n);
    m=G.size();
    cout<<m<<endl;
    for(int i=m-1;i>=0;i--){
        cout<<G[i]<<" ";
    }
    cout<<endl<<cnt<<endl;
    for(int i=0;i<n;i++)
        cout<<arr[i]<<endl;
    return 0;
}



Measured memory_bytes: 7068
#include <unistd.h>
#include <cstdio>
#include <algorithm>
#include <x86intrin.h>

typedef unsigned long long ll;
unsigned int mat[3000][3000]; 
ll dp0[3000] __attribute((aligned(32)));

char buf[1048576];
int lim = 0;
int cur = 0;

void refill()
{
    lim = read(STDIN_FILENO, buf, sizeof buf);
    cur = 0;
}

int rd()
{
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return -1;
        } else {
            if (buf[cur] >= '0') break;
            cur++;
        }
    }
    int acc = buf[cur++] - '0';
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return acc;
        } else {
            if (buf[cur] < '0') return acc;
            acc = acc * 10 + buf[cur++] - '0';
        }
    }
}

#pragma clang attribute push(__attribute__((target("avx2"))), apply_to=function)
int main(int argc, char **argv)
{
    int rr = rd();
    int cc = rd();
    int k  = rd();

    for (int i = 1; i <= k; i++) {
        int r = rd();
        int c = rd();
        int v = rd();
        mat[r - 1][c - 1] = v;
    }
    for (int y = 0; y < rr; y++) {
        ll work0 = 0, work1 = 0, work2 = 0, work3 = 0;
        for (int x = 0; x < cc; x++) {
            work0 = std::max(work0, dp0[x]);
            ll v = mat[y][x];

            work3 = std::max(work3, work2 + v);
            work2 = std::max(work2, work1 + v);
            work1 = std::max(work1, work0 + v);
            dp0[x] = std::max(std::max(work0, work1), std::max(work2, work3));
        }
    }
    std::printf("%lld\n", dp0[cc - 1]);
    return 0;
}
#pragma clang attribute pop

Measured memory_bytes: 39296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric> 
#include <math.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define INF 999999999
using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    int ans = 0;
    ans += a -1;
    if(a <= b) {
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;
const int INF = 1001001001;

int main(){
  int n;
  cin >> n;
  int odd = 0, even = 0;
  for(int i = 1; i <= n; ++i) {
    if(i % 2) ++odd;
    else ++even;
  }
  double p = (double)odd / (odd + even);
  printf("%.6f\n", p);
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int a[3];
  int mx = 0;
  int sm = 0;
  int mn = 51;
  int ret = 0;
  for(int i = 0; 3 > i; i++){
    cin>>a[i];
    mx = max(mx,a[i]);
    sm += a[i];
    mn = min(mn,a[i]);
  }
  if(mx == mn){
    cout << 0 << endl;
    return 0;
  }
  int med = sm-mx-mn;
  ret += (med-mn)/2;
  if(med % 2 == mn % 2){//med = mn;
    mn = med;
    ret += mx - med;
  }else{
    mn = med-1;
    ret += (mx-med+2);
  }
  cout << ret << endl;
}

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

int memo[100001];

int main(){
	int n,m;	cin>>n>>m;
	int WA=0,AC=0;
	for(int i=0;i<m;i++){
		int p;	cin>>p;
		string s;	cin>>s;
		if(s=="WA"){
			if(memo[p]!=-1)memo[p]++;
			else continue;
		}else{
			if(memo[p]>=0){
				AC++;
				WA+=memo[p];
				memo[p]=-1;
			}
		}
	}
	cout<<AC<<" "<<WA<<endl;
	return 0;
}


Measured memory_bytes: 640