akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    vector<pii> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i].first;
        A[i].second = i;
    }

    sort(A.begin(), A.end(), greater<pii>());
    vector<vector<ll>> dp(N + 1, vector<ll>(N + 1));

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= i; ++j) {
            dp[i + 1][j] = max(dp[i][j] + (ll)A[i].first * abs(i - j - A[i].second), dp[i + 1][j]);
            dp[i + 1][j + 1] = dp[i][j] + (ll)A[i].first * abs(N - j - 1 - A[i].second);
        }
    }

    ll ans = 0;
    for (int i = 0; i <= N; ++i)
        ans = max(ans, dp[N][i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 34608
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n, m;
    cin >> n >> m;
    int a[m],b;
    int key[m] = {};
    REP(i,m){
        cin >> a[i] >> b;
        REP(j,b){
            int c;
            cin >> c;
            c--;
            key[i] |= (1 << c);
        }
    }
    int dp[m + 1][1 << n];
    for(int i = 0; i <= m; i++){
        for(int j = 0; j < 1 << n; j++){
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for(int i = 0; i < m; i++){
        for(int j = 0; j < (1 << n); j++){
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            dp[i + 1][j | key[i]] = min(dp[i + 1][j | key[i]], dp[i][j] + a[i]);
        }
    }
    if(dp[m][(1 << n) - 1] == INF) cout << -1 << endl;
    else cout << dp[m][(1 << n) - 1] << endl;
    return 0;
}

Measured memory_bytes: 16256
//atcoder
//拓扑排序+greedy
#include<cstdio>
#include<cstring>
const int N = 1e6+5000;
//u->v表示v在u之前
int a[1000+5][1000+5];
struct Edge{
    int u,v;
    int next;
};
int head[N];
Edge e[N]; int size = 0;
int vis[N];
int Q[N];
int d[N];

int max(int a,int b){ return a>b?a:b; }

int min(int a,int b){ return a>b?b:a; }

int id(int u,int v,int n){
    int res = min(u,v)*(n+1)+max(u,v);
    return res;
}
// wale
void add_edge(int u,int v){
    size++;
    e[size].u = u, e[size].v = v;
    e[size].next = head[u];
    head[u] = size;
}

int topo(int u){
    vis[u] = -1;
    for(int i = head[u]; i!=0; i = e[i].next){
        int v = e[i].v;
        if(vis[v]==-1) return 0;
        else if(vis[v]==0) {
            if(!topo(v)) return 0;
        }
    }
    vis[u] = 1;
    return 1;
}
//有向图求最长链
int get_dis(int u){
    vis[u] = 1;
    for(int i = head[u]; i!=0; i = e[i].next){
        int v = e[i].v;
        if(!vis[v]) d[u] = max(d[u],get_dis(v)+1);
        else d[u] = max(d[u],d[v]+1);
    }
    return d[u];
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n-1; j++){
            scanf("%d",&a[i][j]);
            if(j!=1){
                int last = id(i,a[i][j-1],n);
                int now = id(i,a[i][j],n);
                add_edge(now,last);
            }
        }
    }
    int ok = 1;
    for(int i = 1; i <= n; i++){
        for(int j = i+1; j <= n; j++){
            int now = id(i,j,n);
            if(!vis[now]){
                if(!topo(now)) ok = 0;
            }
        }
    }
    if(ok){
        memset(vis,0,sizeof(vis));
        int ans = 0;
        for(int i = 1; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                int u = i*(n+1)+j;
                if(!vis[u]) ans = max(ans,get_dis(u));
                else ans = max(ans,d[u]);
                //printf("u = %d: %d\n",u,d[u]);
            }
        }
        printf("%d\n",ans+1);
    }
    else printf("-1\n");
}

Measured memory_bytes: 29568
def main():
    h, w = map(int, input().split())
    rows = set()
    cols = set()

    d = []
    for i in range(h):
        s = input()
        d.append(s)
        for j, c in enumerate(s):
            if c == '#':
                rows.add(i)
                cols.add(j)

    for i in range(h):
        if i not in rows:
            continue
        print(''.join(c for j, c in enumerate(d[i]) if j in cols))

main()


Measured memory_bytes: 3064
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
#define foR for

// FHCまでにスタックオーバーフローの罠を解決する


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


    int n;
    cin>>n;

    string s;
    cin>>s;
    int w[n+1]={},r[n+1]={};
    for(int i=0;i<n;i++){
        if(s[i] == 'W')w[i+1]++;
        else r[i+1]++;
        w[i+1] += w[i];
        r[i+1] += r[i];
    }
    int ans = n;
    for(int i=0;i<=n;i++){
        // red , white
        // red i ko
        chmin(ans,min(w[i],r[n]-r[i]) + abs(i - r[n]));
    }
    cout << ans << endl;
}

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

using namespace std;
using i64 = std::int_fast64_t;
using u64 = std::uint_fast64_t;

const string MIN = "-";
const vector<int> costs = {2, 5, 5, 4, 5, 6, 3, 7, 6};

void chmax(string &a, string b) {
  if (a == MIN) {
    a = b;
  } else if (a.size() < b.size()) {
    a = b;
  } else if (a.size() == b.size()) {
    if (a < b) a = b;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i];
  }
  vector<string> dp(N + 10, MIN);
  dp[0] = "";
  for (int i = 0; i < N + 1; i++) {
    if (dp[i] == MIN) continue;

    for (int a : A) {
      chmax(dp[i + costs[a - 1]], dp[i] + static_cast<char>('0' + a));
    }
  }
  cout << dp[N] << '\n';
  return 0;
}


Measured memory_bytes: 43776
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
)

var n, m, x int
var a [][]int
var c []int
var ans = math.MaxInt64

func dfs(i, cc int, arr []int) {
	if i == n {
		// fmt.Println(cc, arr)
		for j := range arr {
			if arr[j] < x {
				return
			}
		}
		// fmt.Println("update")
		ans = min(ans, cc)
		return
	}

	dfs(i+1, cc, arr)

	arr2 := make([]int, m)
	copy(arr2, arr)
	for k := range a[i] {
		arr2[k] += a[i][k]
	}
	dfs(i+1, cc+c[i], arr2)
}

func main() {
	n, m, x = readInt(), readInt(), readInt()

	a = make([][]int, n)
	c = make([]int, n)
	for i := range a {
		c[i] = readInt()

		a[i] = make([]int, m)
		for j := range a[i] {
			a[i][j] = readInt()
		}
	}

	dfs(0, 0, make([]int, m))

	if ans == math.MaxInt64 {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 2160
s = list(input())
a = []
# print(s)

for i in range(len(s)):
    if s[i]== "0":
        a.append("0")
    elif s[i] == "1":
        a.append("1")
    else:
        if len(a)> 0:
            a.pop(-1)
print("".join(a))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<int,int>;
typedef unsigned long long ull;
typedef long long ll;
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; }
const ll INF=1e18;
const ll MOD=1e9+7;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  double n,m;
  cin >> n >> m;
  vector<double>a(n);
  double sum=0;
  rep(i,n){
    cin >> a[i];
    sum+=a[i];
  }
  int ans=0;
  rep(i,n){
    if(a[i]>=sum/(4*m))ans++;
  }
  if(ans>=m) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include<limits>
#include<stack>
#include<queue>
#include<math.h>
#include <iomanip>

#define rep(i,n) for(auto i=0;i<(n);i++)
#define all(vs) (vs).begin(),(vs).end()
#define roundup(A,B) (A)/(B)+(A%B==0?0:1)
#define maximize(A,B) A=max((A),(B))
#define read(type,name) type name;cin>>name
#define ll long long

using namespace std;
template<typename T>
T MAX() { return numeric_limits<T>::max(); }

//二次元テーブル
template<typename T>
class Table {
public:
	Table(int height, int width, T value) {
		if (width < 0)throw out_of_range("Width should be >=0");
		if (height < 0)throw out_of_range("Height should be >=0");
		this->wid = width;
		this->hgt = height;
		vs = new T[width * height];
		for (auto i = 0; i < width * height; i++)vs[i] = value;
	}
	Table(const Table& table) {
		hgt = table.hgt;
		wid = table.wid;
		vs = new T[hgt * wid];
		for (size_t i = 0; i < table.size(); i++) {
			vs[i] = table.vs[i];
		}
	}
	Table(Table&& table) {
		hgt = table.hgt;
		wid = table.wid;
		swap(vs, table.vs);
	}
	~Table() {
		if (vs)delete[] vs;
	}
	Table& operator=(const Table& table) {
		if (table == *this)return *this;
		this->wid = table.wid;
		this->hgt = table.hgt;
		if (vs)delete[] vs;
		vs = new T[wid * hgt];
		for (auto i = 0; i < wid * hgt; i++)vs[i] = table.vs[i];
	}
	Table& operator=(Table&& table) {
		wid = table.wid;
		hgt = table.hgt;
		swap(vs, table.vs);
	}
	inline T& at(int y, int x) {
		if (wid > x)throw out_of_range("x>width.");
		if (hgt > y)throw out_of_range("y>height.");
		return vs[x + y * wid];
	}
	int size()const { return wid * hgt; }
	int width()const { return wid; };
	int height()const { return hgt; };
	T* begin() { return vs; }
	T* end() { return vs + wid * hgt; }
	T& operator()(int y, int x) { return vs[x + y * wid]; }
	const T& operator()(int y, int x)const { return vs[x + y * wid]; }
private:
	int wid, hgt;
	T* vs;
};

void A() {
	string weather[]{ "Sunny","Cloudy","Rainy" };
	read(string, s);
	for (auto i = 0; i < 3; i++) {
		if (weather[i] == s) {
			cout << weather[(i + 1) % 3] << endl;
			return;
		}
	}
}
void B() {}
void C() {}
void D() {}
void E() {}
void F() {}

int main(){
	A();
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <cstdlib>
#include <cmath>
#include <vector>

#define _USE_MATH_DEFINES
#define REP(i,n) for(i = 0;i<n;i++)

using namespace std;


int main() {

	int n, k,ans = 0;
	int i[51] = { 0 };

	cin >> n >> k;

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

	//sort
	for (int j = 0; j < n-1; j++) {
		for (int k = 0; k < n-1; k++) {
			if (i[k] < i[k + 1])
				swap(i[k], i[k + 1]);
		}
	}

	for (int j = 0; j < k; j++) {
		ans += i[j];
	}

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



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

var mod = 1000000007

func main() {
	n := readInt()
	a := make([]int, n)
	tot := 0
	for i := range a {
		a[i] = readInt()
		tot += a[i]
		tot %= mod
	}

	ans := 0
	for i := range a {
		tot = (tot - a[i] + mod) % mod
		ans += (a[i] * tot) % mod
		ans %= mod
	}

	fmt.Println(ans)
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 5852
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<deque>
#include<functional>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<string>
#include<vector>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef long long ll;

using namespace std;

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

	int L, R, d;
	int ans = 0;
	cin >> L >> R >> d;
	FOR(i, L, R + 1) {
		if (i % d == 0)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  for(int i = 1; i <= N ;i++){
    if (i*27/25 == N){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rev(a) reverse(all(a)
#define ld long double
const ll mod=1e9+7;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
int main() {
    string s;
    cin >> s;
    if(s[2]==s[3]&&s[4]==s[5]) puts("Yes");
    else puts("No");
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int Z=0;
    //-----------

    int a=0,b=0,c=0;

    cin>>a>>b>>c;

    if(b-a==c-b)
    {
        cout<<"YES"<<endl;
    }
    else{
    cout<<"NO"<<endl;
    }

    

    //------------
    cin>>Z;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string S;
    cin >> S;
    int d = (int)(S.at(0) - '0') * 1000 + (int)(S.at(1) - '0') * 100 + (int)(S.at(2) - '0') * 10 + (int)(S.at(3) - '0');
    int a = d / 100;
    int b = d % 100;
    if (((0 < a) && (a < 13)) && ((0 < b) && (b < 13)))
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if ((0 < a) && (a < 13))
    {
        cout << "MMYY" << endl;
    }
    else if ((0 < b) && (b < 13))
    {
        cout << "YYMM" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
N,M=list(map(int,input().split()))
C=list(map(int,input().split()))
dp=[0]+[50001 for _ in range(N)]


for i in range(M):
  for j in range(C[i],N+1):
    if C[i] > N:
      break
    elif dp[j-C[i]] != 50001:
      dp[j] = min(dp[j],dp[j-C[i]] + 1)

print(dp[N])


Measured memory_bytes: 7636
import sys
from collections import deque
N,X=map(int,input().split())
if X==1 or X==2*N-1:
    print('No')
    sys.exit()
l=2*N-1
print('Yes')
if N==2:
    print(3)
    print(2)
    print(1)
    sys.exit()
if X==2:
    h=deque()
    h.append(3)
    h.append(2)
    h.append(1)
    h.append(4)
    s=0
    t=0
    while s!=N-2:
        t+=1
        if 4<t:
            s+=1
            h.appendleft(t)
    s=0
    while s!=N-3:
        t+=1
        if 4<t:
            s+=1
            h.append(t)
    print('\n'.join(map(str,h)))
    sys.exit()
    
h=deque()
h.append(X-1)
h.append(X)
h.append(X+1)
h.append(X-2)
s=0
t=0
while s!=N-2:
    t+=1
    if X+1<t or t<X-2:
        s+=1
        h.appendleft(t)
s=0
while s!=N-3:
    t+=1
    if X+1<t or t<X-2:
        s+=1
        h.append(t)
print('\n'.join(map(str,h)))

Measured memory_bytes: 82540
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef  long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vector<int> > vvi;
#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define frpn(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout);
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define fornd(i, n) for(int i=(int)(n); i>=0; --i)

const int INF = (int)1e6+5;
const int NAX = (int)3e5+5;
const int MOD = (int)1e9+7;

template <class T>
inline void rem(T &n){
   n = (-MOD <= n && n <= MOD) ? n : n%MOD ;
  if(n < 0) n += MOD; 
}
ll a[NAX], b[NAX];
int N;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    forn(i, N+1)
      cin >> a[i];
    forn(i, N)
      cin >> b[i];
    ll res = 0;
    forab(i, 1, N){
      int def = min(b[i-1], a[i-1] + a[i]);
      if(a[i-1] < def){
        int x = def - a[i-1];
        a[i] -= x;
        a[i-1] = 0;
      }
      else
        a[i-1] -= def;
      b[i-1] -= def;
      res += def;
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 3072
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next(), T[] = {"Sunny", "Cloudy", "Rainy"};
    for (int i = 0; i < 3; i++)
      if (S.equals(T[i])) System.out.println(T[(i + 1) % 3]);
  }
}

Measured memory_bytes: 23764
from itertools import combinations

N = int(input())
town = [tuple(map(int,input().split())) for _ in range(N)]
all_len = 0

for x, y in combinations(town,2):
  all_len += ((x[0]-y[0])**2 + (x[1]-y[1])**2)**0.5

result = (all_len*2)/N
print(result)

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

using namespace std;

const int MX = 1000;

char ans[MX][MX + 1];

void hor(int x, int y) {
	ans[x][y] = '<';
	ans[x][y + 1] = '>';
}

void ver(int x, int y) {
	ans[x][y] = '^';
	ans[x + 1][y] = 'v';
}

int main() {
	int n, m, a, b;
	ignore = scanf("%d %d %d %d", &n, &m, &a, &b);
	if (n * m < 2 * (a + b) || (n / 2) * m < b || n * (m / 2) < a) {
		printf("NO\n");
		return 0;
	}
	
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			ans[i][j] = '.';
	
	if (n % 2 == 1)
		for (int i = 0; i + 1 < m; i += 2)
			if (a > 0) {
				a--;
				hor(n - 1, i);
			}
	
	if (m % 2 == 1)
		for (int i = 0; i + 1 < n; i += 2)
			if (b > 0) {
				b--;
				ver(i, m - 1);
			}
	
	for (int i = 0; i + 1 < n; i += 2)
		for (int j = 0; j + 1 < m; j += 2) {
			if (a == 1 && b == 1 && n % 2 == 1 && m % 2 == 1) break;
			if (a == 0 && b == 0) break;
			if (a > b) {
				a--;
				hor(i, j);
				if (a > 0) {
					a--;
					hor(i + 1, j);
				}
			}
			else {
				b--;
				ver(i, j);
				if (b > 0) {
					b--;
					ver(i, j + 1);
				}
			}
		}
	
	if (a == 1 && b == 1 && n % 2 == 1 && m % 2 == 1) {
		a = 0;
		b = 0;
		
		ans[n - 2][m - 2] = '.';
		ver(n - 3, m - 3);
		hor(n - 3, m - 2);
		ver(n - 2, m - 1);
		hor(n - 1, m - 3);
	}
	
	if (a + b > 0) {
		printf("NO\n");
		return 0;
	}
	
	printf("YES\n");
	for (int i = 0; i < n; i++) {
		ans[i][m] = 0;
		printf("%s\n", ans[i]);
	}
	
	return 0;
}


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

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e12;
#define endl "\n"

void testCase() {
    int n;
    ll w;
    cin >> n >> w;
    //weight, value
    vector < pair<ll, ll> > val;
    for (int i=0; i<n; i++) {
        ll w1, v1;
        cin >> w1 >> v1;
        val.push_back (make_pair(w1, v1)); 
    }
    ll dp[n+2][100004];
    for (int i=0; i<=n; i++) {
        for (int j=0; j<=100000; j++)
            dp[i][j] = inf;
    }
    dp[n][0] = 0;
    for (int i=n-1; i>=0; i--) {
        for (int k=0; k<=100000; k++) {
            ll val1 = dp[i+1][k];
            dp[i][k] = min (dp[i][k], val1);
            ll val2 = inf;
            if (k+val[i].second<=100000)
                val2 = min (dp[i+1][k]+val[i].first, val2);
            dp[i][k+val[i].second] = min (dp[i][k+val[i].second], val2);
        }
    }
    ll ans = 0;
    for (int i=0; i<=100000; i++) {
        if (dp[0][i] <= w)
            ans = max (ans, (ll)i);
    }
    cout << ans << endl;
}

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 79616
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;

const int M = 1e5 + 100;
int n, a, b, c;
string s[M];
char ans[M];

void dfs(int i, int a, int b, int c) {
    if (i == n) {
        cout << "Yes\n";
        for (int i = 0; i < n; i++) cout << ans[i] << "\n";
        exit(0);
    }
    if (s[i] == "AB") {
        if (a) ans[i] = 'B', dfs(i + 1, a - 1, b + 1, c);
        if (b) ans[i] = 'A', dfs(i + 1, a + 1, b - 1, c);
    }
    if (s[i] == "BC") {
        if (b) ans[i] = 'C', dfs(i + 1, a, b - 1, c + 1);
        if (c) ans[i] = 'B', dfs(i + 1, a, b + 1, c - 1);
    }
    if (s[i] == "AC"){
        if (a) ans[i] = 'C', dfs(i + 1, a - 1, b, c + 1);
        if (c) ans[i] = 'A', dfs(i + 1, a + 1, b, c - 1);
    }
}

int main() {
    cin >> n >> a >> b >> c;
    for (int i = 0; i < n; i++) cin >> s[i];
    dfs(0, a, b, c);
    cout << "No";
}


Measured memory_bytes: 11820
#include<iostream>
long long x1, x2, y1, y2;
using namespace std;
int main() {
    cin >> x1 >> y1 >> x2 >> y2;
    long long x3, x4, y3, y4;
    
    long long dx = x2 - x1, dy = y2 - y1;
  
    x3 = x2 - dy;
    x4 = x3 - dx;
    y3 = y2 + dx;
    y4 = y3 - dy;
  
  
  cout << x3 << " " << y3 << " "<< x4 << " " << y4 << flush;
  
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC140 E
#類題 AGC5 B

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = LI()
c = sorted(a)
d = sorted(b)
lst = []
s = 0
ans = 0
for i in range(n):
    if a[i] < b[i]:
        s += b[i] - a[i]
        ans += 1
    else:
        lst.append(a[i]-b[i])
lst.sort(reverse=1)
for i in lst:
    if s > 0:
        s -= i
        ans += 1
    else:
        break
if s > 0:
    print(-1)
else:
    print(ans)



Measured memory_bytes: 75312
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    float x,s,q,f;
    cin>>n;
    x=n/1.08;
    s=ceil(x);
    q=ceil(x)*1.08;
    f=floor(q);
    if(n==f)
    {
        cout<<s<<endl;
    }
    else{
        cout<<":("<<endl;
    }
    return 0;
}

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

signed main() {
    vector<int> a(9);
    rep(i,3){
        int x;
        cin >> x;
        a[x]++;
    }
    bool flag = false;
    rep(i,9) if(a[i] == 2) flag = true;

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
a, b, m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(m)]
tmp = min(A) + min(B)
tmp1 = 100000000
for i in range(m):
    aa = xyc[i][0] - 1
    bb = xyc[i][1] - 1
    tmp1 = min(A[aa] + B[bb] - xyc[i][2], tmp1)

print(min(tmp, tmp1))

Measured memory_bytes: 38564
#include<iostream>
using namespace std;
int main(){
int N;
cin>>N;
int nn=N%10;
if(nn==2||nn==4||nn==7||nn==5||nn==9)
    cout<<"hon"<<endl;
else if(nn==3)
    cout<<"bon";
else
    cout<<"pon";
return 0;
}


Measured memory_bytes: 3636
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
s = 10000
ans = 0
for i,h in enumerate(H,1):
    if abs(T-h*0.006-A) < s:
        s = abs(T-h*0.006-A)
        ans = i
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

  int r, g; cin >> r >> g;
  cout << 2 * g - r << endl;

  return 0;
}

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

int main(){
  	int k,t;
  	std::cin >> k >> t;
  	std::vector<int> a(t);
  	for(auto&e : a){
      	std::cin >> e;
    }
  	std::sort(a.begin(), a.end());
  	int sum = 0;
  	int ans = 0;
  	for(auto&e : a){
      	ans = std::max(std::max(ans-e, 0), e-(sum+1));
      	sum += e;
    }
  	std::cout << ans << "\n";
  	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< MOD >;

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

modint c(ll n, ll a){
    modint x=n, y=1;

    FOR(i,1,a){
        x *= n-i;
        y *= i+1;
    }

    return x/y;
}

//1<a<b<min(n,2+1e5)
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n,a,b;
    cin>>n>>a>>b;

    modint ans;
    ans = modpow(2,n,MOD)-1;// -1は0本のパターン
    ans -= c(n,a);
    ans -= c(n,b);

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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 main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll res=0;
    rep(i,n){
        ll minj=i;
        for(ll j=i; j<n; j++){
            if(a[j]<a[minj]) {minj=j;}
        }
        if(minj!=i){swap(a[i],a[minj]); res++;}
    }
    rep(i,n){cout<<a[i]; if(i<n-1) cout<<' ';}
    cout<<endl;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    if (n < 1200) {
        cout << "ABC\n";
    } else {
        cout << "ARC\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, k, ans = 1;
int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        ans = min(ans * 2, ans + k);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	int ans = 0;
	int sum = 0;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		ans += sum * x;
		sum += x;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

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

int dp[1<<10][331];

int main(){
  int n,s,comb,x,y;
  rep(k,10)dp[1<<k][k] = 1;

  REP(i,1,10){
    comb = (1<<i)-1;
    while( comb < 1<<10 ){
      rep(j,331)if( dp[comb][j] ){
	rep(k,10)if( !(comb&(1<<k)) ){
	  if( j+(i+1)*k>330 )break;
	  dp[comb|(1<<k)][j+(i+1)*k] += dp[comb][j];
	}
      }
      x = comb & -comb;
      y = comb + x;
      comb = ((comb&~y)/x>>1)|y;
    }
  }
  
  while(~scanf("%d%d",&n,&s)){
    int ans = 0;
    if( s>330 ){
      puts("0");
      continue;
    }
    comb = (1<<n)-1;
    while( comb < 1<<10 ){
      ans += dp[comb][s];
      x = comb & -comb;
      y = comb + x;
      comb = ((comb & ~y)/x>>1)|y;
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    string s;
    int K;
    cin>>s>>K;
    vector<string>v;
    for(int i=0;i<s.size();i++){
        for(int j=1;j<=5;j++){
            v.push_back(s.substr(i,j));
        }
        }
    sort(v.begin(),v.end());
    set<string>a(v.begin(),v.end());
    vector<string>w(a.begin(),a.end());
    sort(w.begin(),w.end());
    /*for(int i=0;i<v.size();i++){
        cout<<w[i]<<endl;
    }*/
    cout<<w[K-1]<<endl;


    return 0;
}

Measured memory_bytes: 2428
#include <stdio.h>

int main()
{

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

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

int main()
{
    //string s;
    //cin >> s;
    int N,M;
    cin >> N >> M;
    vector<int> A(N);
    //vector<vector<int>> vec(N, vector<int>(N,99));

    int sum = 0;
    rep(i, N){
        cin >> A[i];
        sum += A[i];
    }
    double ok = 0;
    ok = 1.0/(4 * M);

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

    bool check = true;
    rep(i,M){
        if(A[i] < (ok * sum)) check = false;
    }
    string s = "Yes";

    if(!check) s = "No";


    cout << s << endl;

    return 0;
}

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

int main()
{
    int a, b, w;
    cin >> w >> a >> b;
    int c = max(a, b);
    int d = min(a, b);
    
    cout << max(c - d - w, 0) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>

using namespace std;



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

    int n;
    cin >> n;

    int pow2[35], x;

    for (int i = 0; i < 33; ++i) {
        pow2[i] = 0;
    }

    for (int i = 1; i <= n; ++i) {
        cin >> x;

        int nr = 0;

        while (x % 2 == 0) {
            x >>= 1;
            ++nr;
        }

        ++pow2[nr];
    }

    pow2[1] %= 2;
    n -= pow2[1];

    int nr1 = pow2[0] + pow2[1];

    int nr2 = 0;

    for (int i = 2; i <= 32; ++i) {
        nr2 += pow2[i];
    }

    if (nr2 + 1 >= nr1) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int W,H,x,y,r;
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if(r<=x && x<=(W-r) && r<=y && y<=(H-r)) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main(){
  int X;
  cin >> X;
  
  for (int i=X; ;i++){
    bool  a=true;
    
    for (int j=2; j<X; j++){
      if(i % j == 0){
        a = false;
        continue;
      }
    }
    
    if(a){
      cout << i << endl;
      break;
    }
  }
}
    

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

f_cnt = 0
t_cnt = 0
o_cnt = 0
for _a in a:
    if _a % 4 == 0:
        f_cnt += 1
    elif _a % 2 == 0:
        t_cnt += 1
    else:
        o_cnt += 1

if o_cnt == 0:
    print("Yes")
elif o_cnt < f_cnt+1:
    print("Yes")
elif o_cnt == f_cnt + 1 and t_cnt == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14228
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    sx, sy, tx, ty = f()

    xdiff = tx - sx
    ydiff = ty - sy

    for _ in range(xdiff):
        print('R', end = '')
    for _ in range(ydiff):
        print('U', end = '')

    for _ in range(xdiff):
        print('L', end = '')
    for _ in range(ydiff):
        print('D', end = '')

    print('L', end = '')
    for _ in range(ydiff+1):
        print('U', end = '')
    
    for _ in range(xdiff+1):
        print('R', end = '')
    
    print('D', end = '')

    print('R', end = '')

    for _ in range(ydiff+1):
        print('D', end = '')

    for _ in range(xdiff+1):
        print('L', end = '')
    
    print('U')
    

solve()


Measured memory_bytes: 4468
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math


N = int(stdin.readline().rstrip())
X = []
Y = []
for el in range(N):
    tmp = [int(s) for s in stdin.readline().rstrip().split()]
    X.append(tmp[0])
    Y.append(tmp[1])

patt = math.factorial(N) / 2
noUseRootNum = patt-math.factorial(N-1)
diss = []
for k in range(N):
    for l in range(N):
        if (k >= l):
            continue
        diss.append(((X[k]-X[l])**2+(Y[k]-Y[l])**2)**0.5)


res = 0
for el in diss:
    res += el*(patt - noUseRootNum)
print(res/patt)

Measured memory_bytes: 3568
#include <stdio.h>

int main (void){
	int total, price, i;
	while (1) {
		scanf("%d", &total);
		if (! total) {
			break;
		}
		for (i=0; i<9; i++){
			scanf("%d", &price);
			total-=price;
		}
		printf("%d\n", total);
	}	
	return 0;
}

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

int main(void) {
  string s;
  cin>>s;
  int l=s.size(),ans=0;
  for(int i=0;i*2<l;i++){
    if(s[i]!=s[l-i-1]) ans++;
  }
  cout<<ans<<"\n";
  return 0;
}


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

using namespace std;

int main()
{
	int n,ans=0;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin >> x;
		if(i%2) continue;
		ans+=x%2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    ll A,B,N;
    cin >> A >> B >> N;
    ll ans = 0;
    
    long double tmp = (long double)A/(long double)B;
    //if() 
    if(B<=N){
        ans = (A*(B-1))/B;
    }else{
        ans = (A*N)/B - A*(N/B);
    }
        // ans = 0;
        // for(ll x=0;x<=N;x++){
        //     ll dif = floor(A*x/B) - A*floor((x/B));
        //     ans = max(ans,dif);
        // }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#define F first
#define S second
#define ld long douroote
#define pb push_back
#define sz size
#define ll long long
#define ull unsigned long long
#define INF 0x7f7f7f7f
#define sc(a) scanf("%d",&a)
#define scll(a) scanf("%lld",&a)
#define scd(a) scanf("%lf",&a)
#define scc(a) scanf(" %c",&a)
#define scs(a) scanf(" %s",a)
#define me(a,b) memset(a,b,sizeof a)
#define all(a) a.begin(),a.end()
#define allr(a,n) a,a+n
#define loop(a,s,e) for(ll a=s;a<=e;a++)
#define read_arr(a,s,n) for(int i=s;i<n+s;i++){sc(a[i]);}
#define read_arr_ll(a,s,n) for(int i=s;i<n+s;i++){scll(a[i]);}
#define err(a,s) cerr<<a<<s;
#define err_arr(a,s,n) for(int i=s;i<n+s;i++){cerr<<a[i]<<" ";}cerr<<endl;
#define prtll(x) printf("%lld",x);
#define prt(x) printf("%d",x);
using namespace std;
const int siz=54;
ll mod=1e9+7;
struct matrix{
    int row,col;
    ll data[siz][siz];
    matrix() {
      row=siz;col=siz;
      memset(data,0,sizeof data);
    }
    void print(){
       printf("\n");
       for(int i = 0;i<row;++i){
        for(int j = 0;j<col;++j){printf("%lld ",data[i][j]);}
        printf("\n");
        }
        printf("\n");
    }
    matrix operator * (const matrix other) const{
        matrix ret = matrix();
        for (int i = 0; i < row; i ++) {
            for (int j = 0; j <other.col; j ++) {
                for (int k = 0; k <col; k ++) {
                    ret.data[i][j]=(1LL * (data[i][k]*other.data[k][j])%mod+ret.data[i][j])%mod;
                }
            }
        }
        ret.row = row;
        ret.col = col;
        return ret;
    }
    void init(){
        memset(data,0,sizeof(data));
        for(int i = 0;i<siz;++i)data[i][i]=1ll;
    }
    matrix pow_(ll n){
	matrix ret;
	ret.init();

	if(n == 0) return ret;
	if(n == 1) return *this;

	matrix P = *this;

	while(n){
	    if(n&1){ret=ret * P;}
        n=n/2ll;
	    P=P*P;
	}
    return ret;
   }
};
ll n,k,ans;
int adj[55][55];
matrix A,B;
int main(){
scll(n);scll(k);
A.row=1;A.col=n;
B.row=n;B.col=n;
loop(i,0,n-1){A.data[0][i]=1;}
loop(i,0,n-1){
  loop(j,0,n-1){sc(adj[i][j]);if(adj[i][j]){B.data[i][j]=1;}}
}
//B.print();
B=B.pow_(k);
A=A*B;
//A.print();
loop(i,0,n-1){ans+=A.data[0][i];ans%=mod;}
printf("%lld\n",ans);
}

/**
**/


Measured memory_bytes: 512
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int N,K;
int A[200005];
int S[200005];
map<int,int> M;
signed main(){
    scanf("%lld %lld",&N,&K);
    rep(i,N){
        scanf("%lld",&A[i]);
        if(i==0){
            S[i]=0;
        }
        S[i+1]=S[i]+A[i];
    }
    int ans=0;
    for(int j=1;j<N+1;j++){
        int i=j-1;
        auto it=M.find((S[i]-i)%K);
        if(it!=M.end()){
            it->second++;
        }else{
            M[(S[i]-i)%K]=1;
        }
        if(j>=K){
            i=j-K;
            auto it=M.find((S[i]-i)%K);
            if(it!=M.end()){
                it->second--;
            }
        }
        it=M.find((S[j]-j)%K);
        ans+=it->second;
    }
    printf("%lld",ans);

    return 0;
}


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

#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define setIO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
#define trav(e, x) for (auto &(e) : (x))
#define pb(x) push_back(x)
#define eb(x...) emplace_back(x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define lc(i) 2 * i
#define rc(i) 2 * i + 1
//#define int long long
using namespace std;
using vi = vector<int>;
using ii = pair<int, int>;

const int MAXN = 1e3, INF = 1e9 + 5, MOD = 1e9 + 7;
int h, w, sx, sy, dx, dy;
char grid[MAXN][MAXN];

bool valid(int i, int j) {
    if (i < 0 || i >= h || j < 0 || j >= w) return false;
    if (grid[i][j] == '#') return false;
    return true;
}

signed main() {
    FAST_IO;
//    setIO("input.txt", "output.txt");

    cin >> h >> w >> sx >> sy >> dx >> dy;
    sx--, sy--, dx--, dy--;
    int dist[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> grid[i][j];
            dist[i][j] = INT_MAX;
        }
    }
    deque<ii> dq;
    dq.emplace_back(sx, sy);
    dist[sx][sy] = 0;
    int pos[4][2] = {{0,  1},
                     {1,  0},
                     {-1, 0},
                     {0,  -1}};
    while (!dq.empty()) {
        int x = dq.front().first, y = dq.front().second;
        dq.pop_front();
        for (auto k : pos) {
            int toX = x + k[0], toY = y + k[1];
            if (valid(toX, toY)) {
                int check = dist[x][y];
                if (check < dist[toX][toY]) {
                    dist[toX][toY] = dist[x][y];
                    dq.emplace_front(toX, toY);
                }
            }
        }
        for (int i = x - 2; i <= x + 2; i++) {
            for (int j = y - 2; j <= y + 2; j++) {
                if (valid(i, j)) {
                    int check = dist[x][y] + 1;
                    if (check < dist[i][j]) {
                        dist[i][j] = check;
                        dq.emplace_back(i, j);
                    }
                }
            }
        }
    }
    cout << (dist[dx][dy] < INT_MAX ? dist[dx][dy] : -1);
}


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

int main(){

  int a[3];
  rep(i,3) cin >> a[i];
  sort(a,a+3);
  cout << a[2]*10+a[1]+a[0] << endl;
  return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			new Main().exec(sc);
		}
	}

	public void exec(Scanner sc) {
		int n = sc.nextInt();
		int k = sc.nextInt();
		int result = 0;
		result = Integer.toString(n, k).length();
		System.out.println(result);
	}
}


Measured memory_bytes: 21844