akhauriyash/Code-Regression huggingface dataset:
w,h,n=map(int,input().split())
sq=[0,-w,0,-h]		#左端，右端，下端，上端

for i in range(n):
  x,y,b=map(int,input().split())
  dumy = [x,-x,y,-y]
  a=b-1
  if sq[a]<dumy[a]:
    sq[a]=dumy[a]


if -sq[1]-sq[0]<0:
  s=0
elif -sq[3]-sq[2]<0:
  s=0
else:
  s=(-sq[1]-sq[0])*(-sq[3]-sq[2])

print(s)

Measured memory_bytes: 38256
from sys import stdin

n = int(input())
A = list(map(int, stdin.readline().split()))
q = int(input())
m = list(map(int, stdin.readline().split()))

def solve(i,m):
    '''
    i番目以降の要素を使用してmを作れる場合、trueを返す
    '''
    if m == 0:
        return True
    if sum(A[i:]) < m:
        return False
    if i >= n:
        return False
    res = solve(i+1,m) or solve(i+1,m-A[i])
    return res

for a in m:
    if solve(0,a):
        print("yes")
    else:
        print("no")



Measured memory_bytes: 5640
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#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))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod

int f(int A, int B, int x){
    return A * x / B - A * (x / B);
}

signed main(){

    int A, B, N; cin >> A >> B >> N;
    int ans = f(A, B, N);
    REP(n, A + 1){
        int x = B * n / A;
        if(A * x / B < n) x++;
        if(x <= N) Max(ans, f(A, B, x)); 
    }
    Out(ans);

    return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <string>
#include <cctype>
#include <algorithm>

#define ll long long

using namespace std;

inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*f;
}

int a[200005],b[200005];

int main(){
	int n=read();
	for (int i=1;i<=n;i++){
		a[i]=read();
	}
	sort(a+1,a+n+1);
	for (int i=2;i<=n;i++){
		if (a[i]==a[i-1]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  if(N<100){
    cout << min(9,N) << endl;
    return 0;
  }else if(N<10000){
    cout << 9 + min(900,N-99) << endl;
    return 0;
  }else if(N<1000000){
    cout << 909 + min(90000,N-9999) << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
using namespace std;
const int64_t INF=10000000000000000;

int main(){
	vector<char> front;
	vector<char> back;
	string s;
	cin>>s;
	int num_op;
	cin>>num_op;
	bool isback=false;
	for(int i=0;i<num_op;i++){
		int op;
		cin>>op;
		if(op==1){
			isback=!isback;
		}else{
			int front_back;
			cin>>front_back;
			char msg;
			cin>>msg;
			if((!isback&&front_back==1)||(isback&&front_back==2)){
				front.push_back(msg);
			}else{
				back.push_back(msg);
			}
		}
	}
	if(isback){
		reverse(back.begin(),back.end());
		for(auto i1=back.begin();i1!=back.end();i1++){
			cout<<*i1;
		}
		reverse(s.begin(),s.end());
		cout<<s;
		for(auto i1=front.begin();i1!=front.end();i1++){
			cout<<*i1;
		}
		cout<<endl;



	}else{
		reverse(front.begin(),front.end());
		for(auto i1=front.begin();i1!=front.end();i1++){
			cout<<*i1;
		}
		cout<<s;
		for(auto i1=back.begin();i1!=back.end();i1++){
			cout<<*i1;
		}
		cout<<endl;
	}


}


Measured memory_bytes: 1024
from collections import Counter, deque  # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    from itertools import accumulate

    B = [0] + A
    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    B = list(accumulate(B))
    BB = Counter(B)

    cnt = 0
    for k, v in BB.items():
        if v >= 2:
            cnt += (v*(v - 1) // 2)
    print(cnt)


resolve()

Measured memory_bytes: 111056
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define SZ(x) int((x).size())
#define DBG(v) cerr << #v << " = " << (v) << endl;
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define fi first
#define se second

int a[100100];

void test() {
	int n,t;
	scanf("%d%d", &n, &t);
	FOR(i,n) scanf("%d", &a[i]);
	int mi = 1e9+4, ma = 0, res = 0;
	FOR(i,n) {
		ma = max(ma, a[i]-mi);
		mi = min(mi, a[i]);
	}
	mi = 1e9+4;
	FOR(i,n) {
		if (ma == a[i]-mi) res++;
		mi = min(mi, a[i]);
	}
	printf("%d\n", res);
}

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


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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

namespace pb_ds {   
    namespace io {
        const int MaxBuff = 1 << 15;
        const int Output = 1 << 23;
        char B[MaxBuff], *S = B, *T = B;
        #define getc() ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T) ? 0 : *S++)
        char Out[Output], *iter = Out;
        inline void flush() {
            fwrite(Out, 1, iter - Out, stdout);
            iter = Out;
        }
    }

    template<class Type = int> inline Type read() {
        using namespace io;
        register char ch; register Type ans = 0; register bool neg = 0;
        while(ch = getc(), (ch < '0' || ch > '9') && ch != '-')     ;
        ch == '-' ? neg = 1 : ans = ch - '0';
        while(ch = getc(), '0' <= ch && ch <= '9') ans = ans * 10 + ch - '0';
        return neg ? -ans : ans;
    }

    template<class Type> inline void Print(register Type x, register char ch = '\n') {
        using namespace io;
        if(!x) *iter++ = '0';
        else {
            if(x < 0) *iter++ = '-', x = -x;
            static int s[100]; register int t = 0;
            while(x) s[++t] = x % 10, x /= 10;
            while(t) *iter++ = '0' + s[t--];
        }
        *iter++ = ch;
    }
}

using namespace pb_ds;

const int N = 5e5 + 1e3;

static int n, d[N], pre[N], f[N];

int main () {

	n = read(); pre[0] = read(); f[n + 1] = 1;

	For (i, 1, n) 
		pre[i] = min(pre[i - 1], abs(pre[i - 1] - (d[i] = read())));
	Fordown (i, n, 1) 
		f[i] = f[i + 1] + ((f[i + 1] << 1) > d[i] ? d[i] : 0);

	using namespace io;
	For (i, 1, read()) {
		static int x;x = read();
		if(pre[x - 1] >= f[x + 1]) *iter++ = 'Y', *iter++ = 'E', *iter++ = 'S';
		else *iter++ = 'N', *iter++ = 'O'; *iter++ = '\n';
	}
	flush();

	return 0;

}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;

int n;
double x[1010], y[1010], X, Y, d, e;
double dist(double a, double b) {
	return a*a + b*b;
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	#ifndef ONLINE_JUDGE
		// freopen("input.txt", "r", stdin);
		// freopen("output.txt", "w", stdout);
	#endif

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x[i], &y[i]);
		X += x[i]; Y += y[i];
	}
	X /= n; Y /= n;
	double P = 0.1;
	for (int i = 0; i < 30000; i++) {
		int f = 0;
		d = dist(X - x[0], Y - y[0]);
		for (int j = 1; j < n; j++) {
			e = dist(X - x[j], Y - y[j]);
			if (d < e) { d = e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	printf("%.8lf", sqrt(d));

	return 0;
}

Measured memory_bytes: 256
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/**@author: Sayed Sohan, CSE 13th batch(2016), MBSTU*/
/**status : */
/**url: */
/* Generate with Contest-Helper **/
/* https://github.com/goldenbijoy/Contest_Helper */
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define clr(arr,value) memset(arr,value,sizeof(arr))
#define MOD 1000000007
#define PI acos(-1)
#define PB push_back
#define MP make_pair
#define SP " "
#define NL "\n"
#define DE cout<<"HERE"<<endl;
#define INF 1e18
#define __FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr2V(x,sz) for(int iii=0;i<=sz;iii++) x[iii].clear();
#define NUM1(x) __builtin_popcount(x)
#define Pause system("pause");
#define MAX 100050/** can increase another 0 */

//** your code goes from here


int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    ll i,j,k,arr[MAX],l,m,n,x,y,coun,sum,ans,T,check;
    vector<ll> v;
    string s;
    ll a,b;
    cin>>a>>b;

    if(a+b==3) cout<<a+b<<NL;
    else if(a+b==4) cout<<2<<NL;
    else cout<<1<<NL;


    /// Don't forget to initialize array....
    return 0;
}


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

int n;

char s[30];

int main() {
    cin >> s;
    if (s[0] == 'S') puts("Cloudy");
    else if (s[0] == 'C') puts("Rainy");
    else puts("Sunny");
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
(N,W) = map(int,input().split(" "))

w = []
v = []

for i in range(N):
    item = list(map(int,input().split(" ")))
    w.append(item[0])
    v.append(item[1])


nap_memo = {}

def nap(i,j):
    key = str(i)+':'+str(j)
    if key in nap_memo:
        return nap_memo[key]
    r = 0
    if i == N:
        r= 0
    elif j < w[i]:
        r= nap(i+1,j)
    else:
        r= max([nap(i+1,j),nap(i+1,j-w[i])+v[i]])

    nap_memo[key] = r
    return r

print(nap(0,W))

Measured memory_bytes: 18996
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 1010101010;

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

    int N;
    cin >> N;
    int ans = 0;
    REP(i, N){
        int tmp = 0;
        if((i+1)%2 == 0) continue;
        REP(j, i+1){
            if((i+1)%(j+1) == 0){
                tmp++;
            }
        }
        if(tmp >= 8){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n)
  {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ai = a.back();
  int aj = 0;
  rep(i, n)
  {
    if (abs((ai + 1) / 2 - a[i]) < abs((ai + 1) / 2 - aj))
      aj = a[i];
  }
  cout << ai << " " << aj << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vectotr<vector<long long>>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

int main(){
    ll n,m;
    cin>>n>>m;
    priority_queue<ll> que;
    rep(i,n){
        ll tmp;
        cin>>tmp;
        que.push(tmp);
    }
    rep(i,m){
        ll nm=que.top();
        que.pop();
        nm/=2;
        que.push(nm);
    }
    ll ans=0;
    rep(i,n){
        ans+=que.top();
        que.pop();
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;

int main(void) 
{
    string s; cin >> s;
    // R=1の時
    if (s[0]=='R' && s[1] == 'S' && s[2]=='S' || s[0]=='S' && s[1] == 'R' && s[2]=='S' || s[0]=='S' && s[1] == 'S' && s[2]=='R'|| s[0]=='R' && s[1] == 'S' && s[2]=='R') {
        cout << 1 << endl;
    }
    else if (s[0]=='R' && s[1] == 'R' && s[2]=='S' || s[0]=='S' && s[1] == 'R' && s[2]=='R') {
        cout << 2 << endl;
    }
    else if (s[0]=='R' && s[1] == 'R' && s[2]=='R') {
        cout << 3 << endl;
    }
    else {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
    	if(c=='-') f=-1;
    	c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int n;
int main(){
	n=read();
	int i=1;
	while(i<n) i*=10;
	i/=10;
	int ans=1,t=n-i;
	while(t){
		ans+=t%10;
		t/=10;
	}
	printf("%d",ans);
	
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>

int main(){
        int N,M;
        scanf("%d %d", &N, &M);
        int a[100]={0},b[100]={0};
        int i,k;
        for(i=1;i<=M;i++){
                scanf("%d %d", &a[i], &b[i]);
        }
        int counta[100]={0},countb[100]={0};
        for(i=1;i<=M;i++){
                for(k=1;k<=N;k++){
                        if(a[i]==k){
                                counta[k]++;
                        }
                        if(b[i]==k){
                                countb[k]++;
                        }
                }
        }
        for(i=1;i<=N;i++){
                printf("%d\n",counta[i]+countb[i] );
        }
        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define maxx 3010
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
ll dp[maxx][maxx][2];
ll arr[maxx];
int x;


ll solve(int i,int j,int p){
	if(i > j) return 0;
	if(dp[i][j][p] != -1e11) return dp[i][j][p];
	
	if(p == 0){
		return dp[i][j][p] = max(arr[i] + solve(i+1,j,1),arr[j] + solve(i,j-1,1)); 
	}
	else{
		return dp[i][j][p] = min(-arr[i] + solve(i+1,j,0), -arr[j] + solve(i,j-1,0) );
	}
}


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

	cin >> x;
	for(int i = 0; i < x; i++) cin >> arr[i];
		
	for(int i = 0; i < x; i++){
		for(int j = 0; j < x; j++){
			dp[i][j][0] = -1e11;
			dp[i][j][1] = -1e11;
		}
	}
	cout << solve(0,x-1,0) << "\n";	
	return 0;
}

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

int main() {
  long long N, W;
  cin >> N >> W;
  vector<long long> w(N), v(N);
  vector<vector<long long>> dp(N+1, vector<long long>(W+1));
  for (int i = 0; i < N; i++) cin >> w.at(i) >> v.at(i);
  for (int i = 0; i < N; i++) {
    for (int weight = 0; weight <= W; weight++) {
      if (weight - w.at(i) >= 0) {
        dp.at(i+1).at(weight) = max(dp.at(i+1).at(weight), dp.at(i).at(weight - w.at(i)) + v.at(i));
      }
      dp.at(i+1).at(weight) = max(dp.at(i+1).at(weight), dp.at(i).at(weight));
    }
  }
  cout << dp.at(N).at(W) << endl;
}

Measured memory_bytes: 80256
import bisect

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

a.sort()
b.sort()
c.sort()

ans = 0

for middle in b:
    # 挿入できる箇所の左側のインデックスを返す
    tmp1 = bisect.bisect_left(a, middle)
    # 挿入できる箇所の右側のインデックスを返す
    tmp2 = bisect.bisect_right(c, middle)
    ans += tmp1 * (n - tmp2)

print(ans)


Measured memory_bytes: 23232
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

int main(void) {
	size_t H, W, h, w;

	scanf("%zu %zu\n%zu %zu", &H, &W, &h, &w);

	printf("%zu\n", (H - h)*(W - w));

	return 0;
}


Measured memory_bytes: 128
n,m=map(int,input().split())

d={}

for i in range(n):
    A,B=map(int,input().split())

    if A in d:
        d[A]+=B
    else:
        d[A]=B

l = sorted(list(d.items()),key=lambda x: x[0])

total=0
cnt=0

for i in range(len(l)):
    total+=l[i][0]*l[i][1]

    cnt+=l[i][1]

    if cnt>m:
        total -= l[i][0]*(cnt-m)
        print(total)
        exit(0) 

print(total)


Measured memory_bytes: 24976
#include <iostream>
#include <cstring>
using namespace std;
char s[101];
char * p;
int main()
{
    cin >> s;
    p = strchr(s,'C');
    if( p != NULL && strchr(p,'F') != NULL)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

    int N = sc.nextInt();
    int M = sc.nextInt();
    int G[] = new int[N+2];
    for (int i = 0; i < M; i++) {
      G[sc.nextInt()]++;
      G[sc.nextInt()+1]--;
    }
    int count = 0;
    for (int i = 1; i < N+2; i++) {
      if (i > 0) {
        G[i] += G[i - 1];
      }
      if (G[i] == M) count++;
    }
    System.out.println(count);
  }
}


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

int main()
{
  int a,b;
  cin>>a>>b;
  int i=(a+b);
  int j=(a-b);
  int k=(a*b);
  vector<int> v{i,j,k};
  sort(v.begin(),v.end());
  cout<<v[2];
}


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

int main(void){
    int n;
    cin >> n;
    string s[n];
    for(int i = 0; i < n; i++)
        cin >> s[i];
    int count = 0;
    
    for(int i = 0; i < n-1; i++){
        if(s[i][s[i].length()-1]==s[i+1][0])
            count++;
    }
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++)
            if(s[i] == s[j])
                count = 0;
    }
    if(count == n-1)
        cout << "Yes" << endl;
    else if(count != n-1)
        cout << "No" << endl;   
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);cout<<"\n";};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); }
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...);}
//FUNCTION

//BELOW
void solve(void)
{ 
  int N;
  cin>>N;
  int COUNT = 0;
  int MIN_ABS = INF;
  int ANS = 0;
  for (int i = 0; i < N; i++)
  {
    int A;
    cin>>A;
    ANS += abs(A);
    if(A < 0 )COUNT++;
    chmin(MIN_ABS,abs(A));
  }
  
  if(COUNT%2 == 1)
  {
    ANS -= 2*MIN_ABS;
  }
  cout<<ANS<<endl;
  
  
  
  return;
}
  
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    i32 n, m;
    cin >> n >> m;
    cout << (n * (n-1)) / 2 + (m * (m-1)) / 2 << endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  long double tmp;
  int now;
  long double answer=0;
  for (int i=1; i<=n; i++){
    now = i;
    tmp = 1.0 / n;
    while (now < k){
      now *= 2;
      tmp /= 2.0;
    }
    answer += tmp;
  }
  cout << setprecision(11) << answer << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int i=0;
	char S[256];
	int N=0;
	int K=0;
	char L;
	
	scanf("%d",&N);
	scanf("%s",&S);
	scanf("%d",&K);
	
	L=S[K-1];
	
	for(i=0;i<N;i++)
	{
		if(S[i]==L)
		{
			
		}
		else
		{
			S[i]='*';
		}
	}
	printf("%s\n",S);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int a[] = new int[N];
		int nowp = 1;
		for (int i = 0; i < a.length; i++) {
			a[i] = scanner.nextInt();
		}

		long ans = 0;
		for (int i = 0; i < a.length; i++) {
			// System.out.println("a[" + i + ":" + a[i]);
			// System.out.println("po:" + nowp);
			if (a[i] == nowp) {
				nowp++;
				// System.out.println("nowp++");
				continue;

			}
			if (a[i] < nowp) {
				// System.out.println(ans);
				continue;
			}
			// System.out.println(ans + a[i] / nowp - 1);
			if (a[i] % nowp == 0 || nowp == 1) {
			ans = ans + a[i] / nowp-1;
			if (nowp == 1) {
				nowp++;
			}
			} else {
			ans = ans + a[i] / nowp;
			}

		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 45844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long inf = 1000000000000;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	int n, m;
	cin >> n >> m;
	int i;
	int I[20];
	int p[20][20];
	int P[20];
	for (i = 0; i < m; i++) {
		cin >> I[i];
		for (int j = 0; j < I[i]; j++) {
			cin >> p[i][j];
			p[i][j]--;
		}
	}
	for (i = 0; i < m; i++) {
		cin >> P[i];
	}
	int bit;
	int ans = 0;
	for (bit = 0; bit < (1 << n); bit++) {
		bool S[20] = {};
		bool cheak = true;
		for (i = 0; i < n; i++) {
			if ((bit >> i) & 1) S[i]++;
		}
		for (i = 0; i < m; i++) {
			int count = 0;
			for (int j = 0; j < I[i]; j++) {
				if (S[p[i][j]]) count++;
			}
			if (P[i] != count % 2) cheak = false;
		}
		if (cheak) ans++;
	}
	cout << ans;
	return(0);
}

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

int main(){
    int h,w;
    cin >> h >> w;
    char tmp[110];
    char c[110][110] = {};
    rep(i,h){
        rep(j,w){
            cin >> c[i][j];
        }
    }
    int b[110][110];
    char ans[110][110] = {};
    int x=0;
    rep(i,h){
        bool bl=false;
        rep(j,w){
            tmp[j]=c[i][j];
            if(tmp[j]=='#')bl=true;
        }
        if(bl==true){
            rep(k,w)b[x][k]=tmp[k];
            x++;
        }
    }
    int y=0;
    rep(i,w){
        bool bl=false;
        rep(j,h){
            tmp[j]=b[j][i];
            if(tmp[j]=='#')bl=true;
        }
        if(bl==true){
            rep(k,h)ans[k][y]=tmp[k];
            y++;
        }
    }
    rep(i,x){
        rep(j,y){
            cout << ans[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <climits>
using namespace std;

struct happinessPoints{
    int a, b, c;
};

int vacation(vector<happinessPoints> vec, int n ){

    int dp[n+1][3];

    dp[1][0] = vec[0].a;
    dp[1][1] = vec[0].b;
    dp[1][2] = vec[0].c;

    for(int i=2;i<=n;i++){
        dp[i][0] = vec[i-1].a + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = vec[i-1].b + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = vec[i-1].c + max(dp[i-1][0], dp[i-1][1]);
    }

    return max(dp[n][0],max(dp[n][1],dp[n][2]));

}

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

    vector<happinessPoints> vec;

    for(int i=0;i<n;i++){
        happinessPoints s;
        cin >> s.a >> s.b >> s.c;
        vec.push_back(s);
    }

    cout << vacation(vec, n) <<endl;
}


Measured memory_bytes: 3828
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		int x = scanner.nextInt();
		int y = scanner.nextInt();
		int ans;
		ans=Math.min(k,n)*x+Math.max(0,n-k)*y;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int n, h, k, i;
	cin >> n >> k;
	int arr[n];
	fo(i, 0, n)
	cin >> arr[i];
	sort(arr, arr + n);
	ll sum = 0;
	fo(i, 0, max(0, n - k))
	sum += arr[i];
	cout << sum;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
#define UB(x,y) upper_bound(ALL(x),y)
#define LB(x,y) lower_bound(ALL(x),y)
#define T tuple<ll,ll,ll>
ll op(ll a,ll b){return max(a,b);}
ll e(){return (ll)0;}
signed main(){
  ll N,K,i,ans=0;cin>>N>>K;ll A[N];
  segtree<ll,op,e>MQ(300001);REP(i,N)cin>>A[i];
  REP(i,N)MQ.set(A[i],MQ.prod(max((ll)0,A[i]-K),min((ll)300001,A[i]+K+1))+1);
  REP(i,300001)ans=max(ans,MQ.get(i));cout<<ans<<endl;return 0;
}

Measured memory_bytes: 13820
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))

vector<string> split(string,string);

//template<typename T>
//void swap(T*,T*);
//char ToUpper (char cX) { return toupper(cX); }

int main()
{
    int a,b;
    cin >> a >> b;
    cout << round((double)(a+b)/(double)2);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define NUM 10
#define Key 753

int main()
{
  char S[NUM];
  scanf(" %s", S);

  int i, temp, Three_num, small_d = 753, d = strlen(S);
  for(i = 0; i < d - 2; ++i){
    Three_num = (int)(S[i] - '0') * 100 + (int)(S[i+1] - '0') * 10
      + (int)(S[i+2] - '0');
    temp = abs(Three_num - Key);
    if(temp < small_d){
      small_d = temp;
    }
  }
  printf("%d\n", small_d);
  
  return 0;
}

Measured memory_bytes: 128
use proconio::*;

fn gcd(a: usize, b: usize) -> usize {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

#[fastout]
fn run() {
    input! {
        x: usize,
    }
    let ans = 360 / gcd(360, x);
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 2104
open Batteries
let w = String.explode (read_line ())
let ans = List.fold_left (fun a b -> if (List.fold_left 
  (fun c d -> if d = b then c+1 else c) 0 w) mod 2 = 0 then a && true else false) true w
let () = print_endline (if ans then "Yes" else "No")

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("abc150/abc150_b.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;
  string s;
  cin >> s;

  ll cnt = 0;
  rep(i, N - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') cnt++;
  }

  cout << cnt << endl;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string S; cin >> S;
	int i = 0;
	while (i < S.size()) {
		if (S.substr(i, 5) == "dream") {
			if (S.substr(i + 5, 2) == "er" && (i+7 == S.size() || S[i+7] != 'a')) {
				i += 7;
			} else {
				i += 5;
			}
		} else if (S.substr(i, 5) == "erase") {
			if (S.substr(i + 4, 2) == "er" && (i+6 == S.size() || S[i+6] != 'a')) {
				i += 6;
			} else {
				i += 5;
			}
		} else {
			print("NO"); return 0;
		}
	}
	print("YES");
}

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

if n<=6:
    print(0)
else:
    if n%2==0:
        n2=(n//10)*10
        i=1
        c_of_5=0 
        while 5**i <= n2:
            c_of_5+=n2//((5**i)*2)
            i+=1
        print(c_of_5)
    else:
        print(0)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n,k;

int main(){
    cin >> n >> k;
    cout << n - k + 1 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 98765431219876543
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, string> PS;

ll n;
vector<ll> a, b;
int main() {
  cin >> n;
  REP(i, n) {
    ll p;
    cin >> p;
    a.pb(p);
  }
  REP(i, n) {
    ll p;
    cin >> p;
    b.pb(p);
  }

  ll ans = 0;
  REP(k, 30) {
    // k bitÁõÆ„ÇíË™ø„Åπ„Çã
    vector<ll> p = a, q = b;
    REP(i, n) {
      p[i] &= (1LL << (k + 1)) - 1;
      q[i] &= (1LL << (k + 1)) - 1;
    }
    // k bitÁõÆ„Åå1„ÅÆ„ÇÇ„ÅÆ„ÅØ„ÄÅ1k<=a<2k , 3k<=a<4k
    ll K = (1LL << k);
    sort(q.begin(), q.end());
    ll cnt = 0;
    for (auto &t : p) {
      cnt += (lb(q, 2LL * K - t) - lb(q, K - t));
      cnt += (lb(q, K * 4LL - t) - lb(q, K * 3LL - t));
    }
    if ((cnt & 1) == 1) {
      ans += (K);
    }
  }

  cout << ans << endl;
}

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define N 100016

int sz(const pii &a) { return max(a.sec-a.fir+1, 0); }

pii xsect(const pii &a, const pii &b)
{
    return mkp(max(a.fir, b.fir), min(a.sec, b.sec));
}

pii p[N];
pii pre[N], suf[N];

int main()
{
    canhazfast();

    int n;
    int ans = 0;
    set<pii> dz;
    priority_queue<int, vi, greater<int>> q;

    cin >> n;
    for (int i = 0; i < n; ++i) cin >> p[i].fir >> p[i].sec;
    sort(p, p+n);

    pre[0] = {0, 1e9};
    for (int i = 0; i < n; ++i) {
        pre[i+1] = xsect(pre[i], p[i]);
    }
    suf[n] = {0, 1e9};
    for (int i = n-1; i >= 0; --i) {
        ans = max(ans, sz(xsect(suf[i+1], pre[i]))+sz(p[i]));
        suf[i] = xsect(suf[i+1], p[i]);
    }

    for (int i = 0; i < n; ++i) {
        while (q.size() && q.top() < p[i].fir) {
            dz.emp(q.top(), p[i].fir);
            retif(dz.size() > 1) cout << ans, 0;
            q.pop();
        }
        q.push(p[i].sec);
    }
    for (int i = 1; i < n; ++i) {
        int res = sz(pre[i])+sz(suf[i]);
        /*cerr << "i = " << i << '\n';
        cerr << "  pre = [" << pre[i].fir << ", " << pre[i].sec << "]\n";
        cerr << "  suf = [" << suf[i].fir << ", " << suf[i].sec << "]\n";
        cerr << "  res = " << res << '\n';*/
        ans = max(ans, res);
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3196
"""
 floor(a/b) 
=(a-a%b)/b
上を利用して与えられた式を変形すると
max (A(x%B)-(Ax%B)) / B
ここで
Ax%B = A(x%B)%B
つまり、AxをBで割った余りは、xをBで割った余りにAをかけたものを、Bで割った余り
を利用すると
max (A(x%B)-A(x%B)%B) / B
つまりA(x%B)、さらに言えばx%Bを最大化すれば良い

x%Bを最大化するには
N>=B-1 のときは　x=B-1
N<B-1　のときは x=N
"""

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
A,B,N = [int(i) for i in readline().split()]

if N >= B-1:
    x = B-1
else:
    x = N

ans = A*x//B - A*(x//B)

print(ans)

Measured memory_bytes: 9052
from fractions import gcd
def lcm(a,n):
    x = a[0]
    for i in range(1,n):
        x = (x * a[i]) // gcd(x,a[i])
    return x
        
n = int(input())
a = list(map(int,input().split()))
print(lcm(a,n))

    


Measured memory_bytes: 6964
#include<iostream>
    using namespace std;
    int main(){
    	int N;
    	int x=0;
    	int y=0;
    	string S;
    	cin>>N;
    	cin>>S;
    	for(int j=0;j<=N;j++)
    	{
    		if(S[j]=='I'){
    			x++;
    		}
    		if(S[j]=='D'){
    			--x;
    		}
    		if(x>y){
    			y=x;
     
    	}
    	
    		}
    		cout<<y;
     
     
    	return 0;
    }

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

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    vector<pair<bool,int>> pro(n);
    
    for(auto a:pro) a.second=0;
    
    for(int i=0;i<m;i++){
        int tmp;
        string s;
        cin>>tmp>>s;
        
        if(s=="AC"){
            pro.at(tmp-1).first=true;
        }else{
            if(!pro.at(tmp-1).first) pro.at(tmp-1).second++;
        }
    }
    
    int ac=0,wa=0;
    
    for(int i=0;i<n;i++){
        if(pro.at(i).first){
            ac++;
            wa+=pro.at(i).second;
        }
    }
    
    cout<<ac<<" "<<wa<<endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;
typedef vector<pi> vpi;
typedef vector<string> vsi;
typedef map<ll, ll> mape;
#define rep(i, a, b) for(ll i=(ll)a;i<=(ll)b;i++)
#define per(i, a, b) for(ll i=(ll)a;i>=(ll)b;i--)
#define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define N 1000010
#define MAX 1234567890

void solve()
{
	string s;
	cin >> s;
	ll n = s.size(), cnt = 0;
	rep(i, 0, n-1) cnt += (s[i] - '0');
	if(cnt%9) cout << "No" << endl;
	else cout << "Yes" << endl;
}

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

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define REP(a,b) for (long long int i = a; i <= (b); ++i) 
using namespace std;
int main(){
 int  n;
  int sum = 0;
  cin>>n;
  vector<int>a(n);
  REP(0,n-1)cin>>a[i];
  sort(a.begin(),a.end());
  a[n - 1] /= 2;
  REP(0,n-1){
    sum+=a[i];
  }
  cout<<sum<<endl;
  return 0;
}

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

using namespace std;

static const int maxn = 1e5 + 5;

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



      int a, b;
      cin >> a >> b;
      int ans = max(0, a - 2 * b);
      cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a,b,p[100010];
    ll A,B,C;
    cin>>n>>a>>b;
    rep(i,n){
        cin>>p[i];
        if(p[i]<=a) A++;
        else if(p[i]<=b) B++;
        else C++;
    }
    cout<<min(A,min(B,C))<<endl;
    return 0;
}

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

int main(){
    while (1){
        int n; cin>>n;
        if (n==0)
            break;
        int buf,cnt=0,f;
        vector <int> a;
        vector <int> c;
        for(int i=0; i<n; i++){
            cin>>buf;
            a.push_back(buf);
            c.push_back(1);
        }
        do{
            f=0;
            for(int i=1; i<n; i++){
                for(int j=0; j<i; j++){
                    if(a[i]==a[j]){
                        c[i]++;
                        c[j]++;
                    }
                }
            }
            cnt++;
            for(int i=0; i<n; i++){
                if(a[i]!=c[i]){
                    a[i]=c[i];
                    f=1;
                }
                c[i]=1;
            }
        }while (f);
        cout<<cnt-1<<endl;
        for(int i=0; i<n-1; i++)
            cout<<a[i]<<" ";
        
        cout<<a[n-1]<<endl;
    }
    return 0;
}




Measured memory_bytes: 3052
N = int(input())
A = [int(i) for i in input().split()]
def calc_sadness(points, b):
    return sum([abs(y - (b + x)) for x, y in points])

points = [(i+1, y) for i, y in enumerate(A)]

# y = x + b
# b = y - x
b_list = [y - x for x, y in points]
b_list.sort(reverse=True)

max_b = b_list[0]
min_b = b_list[-1]

best_ind = len(b_list)//2

minimum = calc_sadness(points, b_list[best_ind])

print(minimum)

Measured memory_bytes: 47424