akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    string S;
    int K;
    cin >> S >> K;
    int N = (int)S.size();
    auto dp = make_vec<int>(N+2, N+2, K+2);
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= N; ++j) {
            for (int k = 0; k <= K; ++k) {
                chmax(dp[i+1][j][k], dp[i][j][k]);
                chmax(dp[i][j+1][k], dp[i][j][k]);
                chmax(dp[i+1][j+1][k+1], dp[i][j][k] + 1);
                if (i < N && N-1-j >= 0 && S[i] == S[N-1-j])
                    chmax(dp[i+1][j+1][k], dp[i][j][k] + 1);
            }
        }
    }
    int res = 0;
    for (int k = 0; k <= K; ++k) {
        for (int i = 0; i <= N; ++i) chmax(res, dp[i][N-i][k] * 2);
        for (int i = 0; i < N; ++i) chmax(res, dp[i][N-1-i][k] * 2 + 1);
    }
    cout << res << endl;
}

Measured memory_bytes: 111104
import math


def lcm(a, b):
    return (a * b) // math.gcd(a, b)


def main():
    n = int(input())
    ts = [int(input()) for _ in range(n)]
    ans = 1
    for t in ts:
        ans = lcm(ans, t)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9156
#include <bits/stdc++.h>
using namespace std;
int n;
void solve()
{
    set < int > se;
    while(n--)
    {
        int x;
        cin>>x;
        se.insert(x);
    }
    cout<<se.size()<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

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

using namespace std;
using ll = long long;

unsigned gcd(unsigned a, unsigned b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

int main() {
    ll n,k,m=0,a,g;
    cin >> n >> k;
    for(ll i=0;i<n;i++){
        cin >> a;
        if(i==0)    g=a;
        else    g = gcd(g,a);
        m=max(a,m);
    }
    if(k%g==0&&m>=k)  cout << "POSSIBLE";
    else    cout << "IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;
 
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<lint> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        b[i] = i + a[i];
    }
    map<lint, lint> cnt;
    lint ret  = 0;
    cnt[b[0]] = 1;
    for (int i = 1; i < n; ++i) {
        ret += cnt[i - a[i]];
        cnt[b[i]]++;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 28976
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, j = 0;
  cin >> n;
  vector<int> a(n);
  int c = 0;
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  while(1){
    j = 0;
    for(int i = 0; i < n; i++){
      if(a.at(i)%2 == 0){
        a.at(i) /= 2;
        j++;
        if(j == n) c++;
        continue;
      }
      else break;
    }
    if(j != n) break;
    else continue;
  }
  cout << c << endl;
  
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
struct comb {
	vector<mint> fact, ifact;
	comb(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};

int main() {
	init();

	int N, K; cin >> N >>K;
	vector<ll>A(N);
	rep(i, 0, N)cin >> A[i];
	sort(all(A));
    comb com(N);
    mint sum_mx = 0, sum_mn = 0;
    rep(i, 0, N) {
        mint x = com(N - i - 1, K - 1);
        mint y = A[i];
        sum_mn += y * x;
    }
    rREP(i, 0, N) {
        mint x = com(i, K - 1);
        mint y = A[i];
        sum_mx += y * x;
    }
    mint ans = sum_mx - sum_mn;
    cout << ans.x << "\n";

	return 0;
}


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

using namespace std;

int main()
{
  string s;
  cin >> s;
  int c = 0;
  for (int i = 0; i < 6; i++) {
    if (s[i] == '1') c++;
  }
  cout << c << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	x=II()
	print("Yes" if x>=30 else "No")





if __name__ == "__main__":
	main()


Measured memory_bytes: 61928
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

public class Program
{
    public static void Main(string[] args)
    {
        new Program().Solve(new ConsoleInput(Console.In, ' '));
    }

    public void Solve(ConsoleInput cin)
    {
        var n = cin.ReadInt;
        var a = new int[n];
        var aa = "YES";

        for (var i = 0; i < n; i++)
        {
            a[i] = cin.ReadInt;
        }

        Array.Sort(a);

        for (var i = 0; i < n-1; i++)
        {
            if (a[i] == a[i + 1])
                aa = "NO";
        }

        WriteLine(aa);
        ReadKey();
    }
}

public class ConsoleInput
{
    private readonly System.IO.TextReader _stream;
    private char _separator = ' ';
    private Queue<string> inputStream;
    public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
    {
        this._separator = separator;
        this._stream = stream;
        inputStream = new Queue<string>();
    }
    public string Read
    {
        get
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(_separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
    }
    public string ReadLine { get { return _stream.ReadLine(); } }
    public int ReadInt { get { return int.Parse(Read); } }
    public long ReadLong { get { return long.Parse(Read); } }
    public double ReadDouble { get { return double.Parse(Read); } }
    public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
}


Measured memory_bytes: 31708
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<long double, long double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

char win(char c){
    if (c == 'r') return 'p';
    if (c == 's') return 'r';
    if (c == 'p') return 's';
}

int main() {
    int n, k; cin >> n >> k;
    int r, ss, p; cin >> r >> ss >> p;
    string s; cin >> s;
    vector<char> ar(n+1,'n');
    ll ans = 0;
    rep(i,n){
        if (ar[max(0,i+1-k)] != win(s[i])){
            ar[i+1] = win(s[i]);
        }
    }
    rep(i,n){
        if (ar[i+1] == 'p') ans += p;
        else if (ar[i+1] == 'r') ans += r;
        else if (ar[i+1] == 's') ans += ss;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline

x = int(input())
eps = 1e-9
a = 1
while True:
    diff = a**5-x
    if diff < 0:
        diff = abs(diff)
        sign = True
    else:
        sign = False
    if abs(diff**0.2 - round(diff**0.2)) < eps:
        b = round(diff**0.2)
        if sign:
            b = -b
        break
    a += 1
print a,int(b)


Measured memory_bytes: 64836
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

vector<int> makePrimeLst(int N)
{
    if (N < 2) return vector<int>(0);
    vector<int> ans;
    vector<int> alive(N+1, 1);
    for (int i=2; (long long)i*i<=(long long)N; i++)
    {
        if (alive[i]) ans.push_back(i);
        for (int t = i; t<=N; t += i) alive[t] = 0;
    }
    for (int i=ans.back()+1; i<=N; i++) if (alive[i]) ans.push_back(i);
    return ans;
}

// 素因数分解
map<lint, int> primeFactorize(lint N, vector<int>& primeLst)
{
    map<lint, int> ans;
    for (auto v : primeLst)
    {
        while (!(N % v))
        {
            N /= v;
            ans[v]++;
        }
        if (N == 1) return ans;
    }
    ans[N]++;
    return ans;
}


lint n, s;

lint func(lint b, lint n)
{
    if (n < b) return n;
    return n % b  + func(b, n/b);
}

int main()
{
    cin >> n >> s;
    lint m = n - s;
    if (m < 0)
    {
        cout << -1 << endl;
        return 0;
    }
    if (m == 0)
    {
        cout << n + 1 << endl;
        return 0;
    }
    vector<int> primes = makePrimeLst((int)sqrt(m));
    map<lint, int> f = primeFactorize(m, primes);

    vector<lint> b;

    vector<lint> p, nv;
    int num = 1;
    for (auto v : f)
    {
        p.push_back(v.first);
        nv.push_back(v.second);
        num *= (nv.back() + 1);
    }
    for (int i=0; i<num; i++)
    {
        lint prod = 1;
        int tmp = i;
        for (int j = 0; j<p.size(); j++)
        {
            int times = tmp % (nv[j] + 1);
            tmp /= (nv[j] + 1);
            while (times)
            {
                prod *= p[j];
                times--;
            }
        }
        b.push_back(prod+1);
    }
    sort(b.begin(), b.end());
    for (auto ans : b)
    {
        if (func(ans, n) == s) 
        {
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


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

int main() {
    int N,M; cin>>N>>M;
    int A;
    A=M/N;
    int answer;
    for (int i=A; i >=1; i--){
        if (M % i == 0 && M/i >= N){
            answer = i;
            break;
        }
    }
    cout << answer << endl;
  
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int val1 = sc.nextInt();
        String val2 = sc.next();

        int count = 0;
        String temp = "";
        for (int i = 0; i < val2.length(); i++) {
            temp = temp + val2.charAt(i);
            switch (temp) {
                case "A":
                    continue;
                case "AB":
                    continue;
                case "ABC":
                    count++;
                    temp = "";
                    continue;
                default:
                    temp = "" + temp.charAt(temp.length() - 1);

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

Measured memory_bytes: 22608
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N; cin >> N;
  int ans = 0;
  vector<int> A(N), C(N-1);
  for (int &a:A) cin >> a;
  for (int i = 0; i < N; i++){
    int b; cin >> b;
    ans += b;
  }
  for (int &c:C) cin >> c;
  
  for (int i = 0; i < N-1; i++) {
    if (A[i] + 1 == A[i+1]) {
      ans += C[A[i]-1];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define ind(a) scanf("%lf", &(a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a));
//def   puts(a) printf("%s\n", a) 文字はこっち
//your code here!
#define MAX_HEAP 100005
ll a[MAX_HEAP];
ll g_idx = -1; //ヒープの末尾の添字 最初は空っぽだから-1

void downheap(void){//根に置かれている要素を適切なとこまで下におろす。
    ll i, j;
    i = 0;              //根から始める
    while(i*2+1<=g_idx){//子が存在するという条件
        j = i*2+1;
        if(j+1<=g_idx && a[j]<a[j+1]){
            j++;        //2つ(or1つ)の子供の内、小さい方の添字をjとしている
        }
        if(a[i] >= a[j]){
            break;      //子供の方が大きければ、終了
        }
        //終了していないと言うことは、親子関係が逆なのでswap
        swap(a[i],a[j]);
        i = j;          //子供が親になって次のループへ
    }
}

ll PQ_pop(void){//最小値を取り出す
    ll ret = a[0];         //返り値
    if(g_idx<0) exit(1);  //ヒープが空っぽかどうか確認
    a[0] = a[g_idx--];     //末尾の要素を先頭にもってく
    //a[0]=a[g_idx];  g_idx=g_idx - 1; 後からマイナス
    downheap();
    return ret;
}

void upheap(void){ //末尾に置かれている要素を適切なとこまで上にあげる
    ll x = g_idx;  //グローバル変数をいじる訳にはいかないので代入
    while(x>0 && a[(x-1)/2]<a[x]){//親がいる&&親が子供より大きい なら継続
        swap(a[(x-1)/2], a[x]);   //親と子供をswap
        x = (x-1)/2;              //親を子供にしてループへ
    }
}

void PQ_push(ll elem){//ヒープに要素elemを追加する
    if(g_idx >= MAX_HEAP-1){//ヒープに空きがあるか確認
        exit(1);
    }
    a[++g_idx] = elem;      //末尾にelemを入れる
    //g_idx+=1;  a[g_idx]=elem  先にプラス
    upheap();
}


int main(void){
    ll N, M, A, ans=0;
    in(N); in(M);
    rep(i,N){
        in(A);
        PQ_push(A);
    }
    rep(_,M){
        A = PQ_pop();
        PQ_push(A/2);
    }
    rep(i,N) ans += a[i];
    put(ans);
    return 0;
}


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

ll gcd(ll c,ll d){
  if( d==0){
    return c;
  }
  gcd (d,c%d);
}

int main(){
 ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll c1=(a+c-1)/c;ll c2=b/c;
  ll d1=(a+d-1)/d;ll d2=b/d;
  ll Gcd=gcd(min(c,d),max(c,d));
  ll lcm=c/Gcd*d;
  ll l1=(a+lcm-1)/lcm;ll l2=b/lcm;
  cout << b-a-(c2-c1+1+d2-d1+1-(l2-l1+1) )+1<<endl;
}

Measured memory_bytes: 256
//ABC058B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	string o, e;
	cin >> o >> e;
	for(int i=0;i<e.size();i++){
		cout << o.at(i) << e.at(i);
	}
	if(o.size() > e.size()){
		cout << o.at(o.size()-1);
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<String> set = new HashSet<String>();

		for (int i = 0; i < N; i++){
			set.add(sc.next());
		}

		System.out.println(set.size());

	}

}


Measured memory_bytes: 77148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
void solve(){
  
  string inp ;
  cin >> inp ;
  
  ll len=(ll)inp.length() ;
  ll left[len] , right[len] ;
  
  for(ll i =0 ; i < len ;i++) {
    
    if(i == 0) {
      if(inp[i]=='R') left[i] = i ;
      else left[i] = -1 ;
    }
    else {
      if(inp[i]=='R') left[i] = i ;
      else left[i] = left[i - 1] ;
    }
  }
  
  for(ll i = len - 1; i >=0 ;i--) {
    if(i == len - 1) {
      if(inp[i] =='L') right[i] = i ;
      else right[i] = - 1;
    }
    else {
      if(inp[i]=='L') right[i] = i ;
      else right[i] = right[i + 1]; 
    }
  }
  
  ll count[len] ;
  for(ll i = 0 ; i < len ;i++)
    count[i] = 0 ;
  for(ll i =0 ; i  < len ;i++)
  {
    if(inp[i]=='R'){
      if(right[i] == -1) count[len - 1] ++ ;
      else{
        if( (right[i] - i - 1)%2 == 0 ) count[right[i] - 1]++ ;
        else count[right[i]]++ ;
      }
    }
    else {
      
      if(left[i] == -1) count[0] ++ ;
      else{
        if((i - left[i] - 1)%2 == 0) count[left[i] + 1]++ ;
        else count[left[i]]++ ;
      }
    }
  }
  
  for(ll i =0 ; i < len ;i++)
    cout << count[i] << " " ;		
}

int main()
{
	    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
		ll t =1;
			//cin >> count;
		while(t--)
		{
			solve();
		}
		return 0;
}


Measured memory_bytes: 3024
data = [str(input()), True]

def check(string):
    if string[len(string)-6:] == 'eraser':
        string = string[:len(string)-6]
        return [string,True]
    elif string[len(string)-5:] == 'erase':
        string = string[:len(string)-5]
        return [string,True]
    elif string[len(string)-7:] == 'dreamer':
        string = string[:len(string)-7]
        return [string,True]
    elif string[len(string)-5:] == 'dream':
        string = string[:len(string)-5]
        return [string,True]
    else:
        return [string,False]
        
while (data[1] == True):
    data = check(data[0])
    if data[0] == '':
        print('YES')
        break
    elif data[1] == False:
        print('NO')
        break

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
 
void solve(){
	int a, b, c;
	cin >> a >> b >> c;
	int d = a - b;
	cout << max(0, c - d);
}
 
int main(){
    OP
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    while(t--)
    solve();
    return 0;
}

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

long long dp[3005][3005][4];
long long item[3005][3005];

int main() {
  int r, c, k;
  cin >> r >> c >> k;
  for ( int i = 0; i < k; i++ ) {
    int ri, ci;
    long long vi;
    cin >> ri >> ci >> vi;
    item[ri][ci] = vi;
  }

  for ( int i = 1; i <= r; i++ ) {
    for ( int j = 1; j <= c; j++ ) {
      for ( int l = 3; l > 0; l-- ) {
        dp[i][j][l] = max(dp[i][j][l], dp[i][j][l-1]+item[i][j]);
      }
      for ( int l = 0; l < 4; l++ ) {
        dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][l]);
        dp[i][j+1][l] = max(dp[i][j+1][l], dp[i][j][l]);
      }
    }
  }

  long long ans = 0;
  for ( int l = 0; l < 4; l++ ) {
    ans = max(ans, dp[r][c][l]);
  }
  cout << ans << endl;;
  return 0;
}


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

#define RG register int
#define LL long long

template<typename elemType>
inline void Read(elemType &T){
    elemType X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    T=(w?-X:X);
}

struct edge{int Next,to;};
edge G[400010];
int head[200010],Max[200010],H[200010],F[200010],g[200010],Ans[200010];
int N,cnt=2;

inline void Add_Edge(int u,int v){
    G[cnt].to=v;
    G[cnt].Next=head[u];
    head[u]=cnt++;
}

int DFSB(int u,int fa,int x){
    if(u>x) return 0;
    int Res=1;
    for(int i=head[u];i;i=G[i].Next){
        int v=G[i].to;
        if(v==fa) continue;
        Res+=DFSB(v,u,x);
    }
    return Res;
}

void DFSA(int u,int fa){
    for(int i=head[u];i;i=G[i].Next){
        int v=G[i].to;
        if(v==fa) continue;
        Max[v]=max(Max[u],v);
        DFSA(v,u);
    }
    if(u>Max[fa]){
        H[u]=1;
        for(int i=head[u];i;i=G[i].Next){
            int v=G[i].to;
            if(v==fa) continue;
            F[v]=DFSB(v,u,u);
            g[v]=DFSB(v,u,Max[fa]);
            H[u]+=g[v];
        }
    }
    return;
}

void DFSC(int u,int fa){
    for(int i=head[u];i;i=G[i].Next){
        int v=G[i].to;
        if(v==fa) continue;
        Ans[v]=Ans[u];
        if(u>Max[fa]) Ans[v]+=F[v]-g[v];
        if(Max[v]>Max[u]) Ans[v]+=H[v];
        DFSC(v,u);
    }
    return;
}

int main(){
    Read(N);
    for(RG i=1;i<=N-1;++i){
        int u,v;Read(u);Read(v);
        Add_Edge(u,v);
        Add_Edge(v,u);
    }
    Max[1]=1;F[1]=1;DFSA(1,0);
    DFSC(1,0);
    for(RG i=2;i<=N;++i)
        printf("%d ",Ans[i]);
    return 0;
}

Measured memory_bytes: 20992
#include<iostream>
#include<iomanip>
#define LL long long
using namespace std;
int main() {
	LL n, m;
	cin >> n >> m;
	cout << fixed;
	setprecision(5);
	cout << n / m << ' ' << n%m << ' ' << (double)n / m << endl;
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li x[100100];

int main() {
    li n, a, b;
    cin >> n >> a >> b;
    rin{
        cin >> x[i];
    }

    li res = 0;
    repp(i, 1, n) {
        res += min(b, a * (x[i] - x[i - 1]));
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int d[1000001][2];

int ans(int a) {
	int i,b=0,t=1,h;
	d[a][1]=-2;
	if (d[a][0]==0) return 1;
	while(d[a][1]!=0) {
		for (i=0;i<2;i++) { h=d[a][b]; if (d[h][i]==a) { a=h; b=1-i; break;}}
		t++;
		}
	d[a][1]=-2;	 
    return t;
}
int main() {
  int n,m,i,j,k,f,t,s[2];
  while(cin >> n >> m) {
	  if (n==0 && m==0) break;
	for (i=0;i<=n;i++) d[i][0]=d[i][1]=0; f=0;
	for (i=0;i<m;i++) {
		cin >> s[0] >> s[1]; 
		for (j=0;j<2 && f==0;j++) { f=1; for  (k=0; k<2; k++) if (d[s[j]][k]==0) { f=0; d[s[j]][k]=s[1-j]; break;}}}
		if (f==1) { cout << "no" << endl; } else  {     
	t=0;
	for (i=1;i<=n;i++) if (d[i][1]==0) t+=ans(i);
	if (t==n) cout << "yes" << endl; else cout << "no" << endl;
	}
   }	    
	return 0;
} 

Measured memory_bytes: 1932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << double(w)/2*h << " ";
    cout << (w==x*2&&h==y*2?1:0)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int flag[1000000];
int main(){
    CIN(N);
    I vec;
    REP(a,N){
        CIN(b);
        vec.push_back(b-1);
    }
    int ins = 0;
    bool result = false;
    int ans = 0;
    while(true){
        if(ins == 1){
            result = true;
            break;
        }
        if(flag[ins] == 1){
            break;
        }
        flag[ins]=1;
        ins = vec.at(ins);
        ans++;
    }
    COUT(result?ans:-1);
    return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define ll long long
#define res register int
#define inf 0x3f3f3f3f
using namespace std;
string s, t; 
int ans;
inline int read(){
    res w = 0, X = 0; register char ch = 0;
    while(!isdigit(ch)){w |= ch == '-'; ch = getchar();}
    while(isdigit(ch)){X = (X << 1) + (X << 3) + (ch ^ 48); ch = getchar();}
    return w ? -X : X;
}
int main(){
	cin >> s >> t;
	for(res i = 0; i < 3; i++)
	  ans += s[i] == t[i];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    x = list(sorted(map(int, input().split())))
    if n >= m: return 0

    diffs = list(sorted((abs(x[i + 1] - x[i]) for i in range(m - 1)), reverse=True))
    return sum(diffs[i] for i in range(n - 1, m - 1))

print(main())

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

//二人の間にあいているマスが奇数ならアリスの、偶数ならボブの勝ち
int main() {

  int N,A,B;

  cin >> N >> A >> B;

  int s=B-A-1;//間のマス数

  if(s%2==1) cout << "Alice" << endl;

  else cout << "Borys" << endl;  

  return 0;
}

Measured memory_bytes: 256
/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 2e5+10;
const ll mod = 1e9+7;
const ll INF = 1e9;
inline ll bpow(ll t,ll n){ll ans=1;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}
/*
ll fact[MAX_N],ifact[MAX_N];
inline ll c(ll n,ll k){if(k>n||k<0)return 0;return (fact[n]*ifact[k]%mod*ifact[n-k])%mod;}
inline void get_fact(){fact[0]=1;ifact[0]=1;for(ll i=1;i<MAX_N;i++)fact[i]=(fact[i-1]*i)%mod,ifact[i]=bpow(fact[i],mod-2);}
*/
int occ[MAX_N],a[MAX_N];
main(){
    fast();per(0);
    //get_fact();
    int n,k;cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i],occ[a[i]]++;
    sort(occ+1,occ+n+1);
    int ans=n;
    for(int i=n;i>=1+n-k;i--)
        ans-=occ[i];
    cout<<ans;
}




Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;
typedef long long ll;

ll comb(ll n, ll k){
    ll ret = 1;
    for(ll i = 0; i < k; ++i){
        ret *= (n - i);
        ret /= (i + 1);
    }
    return ret;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> v(n);
    for(int i = 0; i < n; ++i){
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());

    ll total = 0;
    for(int i = 0; i < a; ++i){
        total += v.at(n - 1 - i);
    }
    printf("%.8f\n", (double)total / a);

    if(n == a){
        cout << 1 << endl;
        return 0;
    }

    const ll minv = v.at(n - a);
    if(v.at(n - a - 1) < minv){
        cout << 1 << endl;
        return 0;
    }

    const ll idx1 = lower_bound(v.begin(), v.end(), minv) - v.begin();
    const ll idx2 = upper_bound(v.begin(), v.end(), minv) - v.begin() - 1;
    if(v.back() > minv){
        const ll k = idx2 - (n - a) + 1;
        cout << comb(idx2 - idx1 + 1, k) << endl;
        return 0;
    }else{
        ll ans = 0;
        for(ll i = a; i <= min(b, idx2 - idx1 + 1LL); ++i){
            ans += comb(idx2 - idx1 + 1LL, i);
        }
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 888
import java.util.Scanner;

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

	Main() {
		Scanner sc = new Scanner(System.in);
		try {
			while (true) {
				int a, b;
				a = sc.nextInt();
				b = sc.nextInt();
				int c = a + b;
				System.out.println((c + "").length());
			}
		} catch (Exception e) {
		}
	}
}

Measured memory_bytes: 20400
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define rfor(i, n) for (int i = n-1; i>=0; --i)
#define rmod(x, y) (((x%y)+y)%y)
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
const int MAXN = 1024;

//OPERATORS


//GLOBALS


//FUNCTIONS


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,k; cin >> n >> k;
	vector<int> fu(n);
	for(int i = 0; i < n; i++){
		cin >> fu[i];
	}
	vector<bool> depe(k+1);
	for(int i = 0; i <= k; i++){
		for(auto ra: fu){
			if(i  >= ra and !depe[i-ra])
				depe[i] = true;	
		}
	}
	if(depe[k] == true) cout << "First"  << endl;
	else cout << "Second" << endl;
	return 0;
}


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

  long int N;
  long int D;
  cin >>N>>D;
  vector<long int> X(N);
  vector<long int> Y(N);
  
  long int A;
  A=0;
  
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
    cin >> Y.at(i);
  }
  
  for(int i = 0; i < N; i++){
    double B;
    B=(X.at(i))*(X.at(i))+(Y.at(i))*(Y.at(i)); 
    B=sqrt(B);
    if(B<=D){
      A++;
    }
  }
  
  
  cout <<A;
}


Measured memory_bytes: 6312
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int inf = 1001001001;
int main(){
  int H,W,CY,CX,DY,DX,i,j;scanf("%d %d\n%d %d\n%d %d\n",&H,&W,&CY,&CX,&DY,&DX);
  CY--;CX--;DY--;DX--;
  char c;bool m[H][W];
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      scanf("%c",&c);
      m[i][j] = c == '.';
    }
    scanf("\n");
  }
  int d[H][W];bool visit[H][W],visit2[H][W];
  memset(visit,0,sizeof(visit));memset(visit2,0,sizeof(visit2));
  d[CY][CX] = 0;visit[CY][CX] = visit2[CY][CX] = true;
  deque<pair<int,int>> q;q.push_back(make_pair(CY,CX));
  int fy,fx,ny,nx;
  while(!q.empty()){
    fy = q.front().first;fx = q.front().second;q.pop_front();
    for(i=-2;i<=2;i++){
      for(j=-2;j<=2;j++){
        ny = fy+i;nx = fx+j;
        if(ny < 0 || ny >= H || nx < 0 || nx >= W || (i==0 && j==0) || m[ny][nx] == false) continue;
        if(abs(ny-fy)+abs(nx-fx) == 1 && !visit[ny][nx]){
          d[ny][nx] = d[fy][fx];
          q.push_front(make_pair(ny,nx));
          visit[ny][nx] = true;
        }
        else if(!visit[ny][nx] && !visit2[ny][nx]){
          d[ny][nx] = d[fy][fx]+1;
          q.push_back(make_pair(ny,nx));
          visit2[ny][nx] = true;
        }
      }
    }
  }
  if(!visit[DY][DX] && !visit2[DY][DX]) printf("-1\n");
  else printf("%d\n",d[DY][DX]);
}

Measured memory_bytes: 10684
/*
	Templates start.
	Powered by c++11.
	Author : Alex_Wei.
*/

#include <bits/stdc++.h>
using namespace std;

// IO templates.

char buf[1<<21],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
#ifdef __WIN64
	#define gc getchar()
#else
	#define gc (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#endif
#define pc(x) (*O++=x)
#define flush() fwrite(obuf,O-obuf,1,stdout)

inline int read(){
	int x=0,sign=0; char s=getchar();
	while(!isdigit(s))sign|=s=='-',s=getchar();
	while(isdigit(s))x=(x<<1)+(x<<3)+(s-'0'),s=getchar();
	return sign?-x:x;
}
void print(int x) {if(x>9)print(x/10); pc(x%10+'0');}

#define ll long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define sor(x) sort(all(x))
#define rev(x) reverse(all(x))
#define mem(x,v) memset(x,v,sizeof(x))

/*
	Templates end.
	Please give me more points.
*/

const int N=2e3+5;

int n,x,y,ans[N];

int main(){
	cin>>n>>x>>y;
	for(int i=1;i<n;i++)
		for(int j=i+1;j<=n;j++){
			ans[min(j-i,abs(x-i)+abs(y-j)+1)]++;
		}
	for(int i=1;i<n;i++)cout<<ans[i]<<endl;
	return 0; 
}

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

using namespace std;

typedef long long ll;

struct seg
{
	ll l, r, s;
	inline int operator<(const seg &a) const {return s > a.s;}
} s[5010];

const ll inf = (1ll<<62) - 1;
int n, m;
ll f[2510][2];

int main()
{
	ios::sync_with_stdio(0);
	
	cin >> n; m = n >> 1;
	for (int i = 1; i <= n; ++i)
	{
		cin >> s[i].l >> s[i].r;
		s[i].s = s[i].l + s[i].r;
	}
	sort(s+1, s+n+1);
	for (int i = 1; i <= m; ++i)
		f[i][0] = inf;
	
	int x = 0;
	for (int i = 1; i <= n; ++i)
	{
		x ^= 1;
		for (int j = 0; j <= m; ++j)
			f[j][x] = inf;
		for (int j = 0; j<i && j<=m; ++j)
		{
			const int k = i-j-1;
			if (j < m)
				f[j+1][x] = min(f[j+1][x], f[j][x^1] + s[i].r + s[i].s * j);
			if (k < m)
				f[j][x] = min(f[j][x], f[j][x^1] + s[i].l + s[i].s * k);
			if (n & 1)
				f[j][x] = min(f[j][x], f[j][x^1] + m * s[i].s);
		}
	}
	
	cout << f[m][x] << endl;
	
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int t;
    cin>>t;
    int hight[t];
    int cnt=0;
    for(int i=0;i<t;i++){
      cin>>hight[i];
      cnt++;
    }
    int maxU,maxD;
    maxU = maxD = 0;
    for(int j=1;j<cnt;j++){
      if(hight[j-1] < hight[j]){
	maxU = max(maxU,hight[j] - hight[j-1]);
      }else{
	maxD = max(maxD,-(hight[j] - hight[j-1]));
      }
    }
    cout << maxU << " " << maxD << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
import java.io.*;
public class Main {
		public static void main(String[] arg) throws IOException {
			InputStreamReader is = new InputStreamReader(System.in); 
	        BufferedReader br = new BufferedReader(is);
			String str = br.readLine();
			String[] spl = str.split(" ");
			if(Integer.parseInt(spl[0])>Integer.parseInt(spl[1])){
				System.out.println("a > b");
			}else if(Integer.parseInt(spl[0])==Integer.parseInt(spl[1])){
				System.out.println("a == b");
			}else{
				System.out.println("a < b");
			}
	}

}

Measured memory_bytes: 24324
L, R = map(int, input().split())
import itertools
  
if R - L >= 2019:
  print(0)
  exit()
else:
  minV = 2*10**9
  for i in itertools.combinations(range(L, R+1), 2):
    val = (i[0]*i[1]) % 2019
    if val <= minV:
      minV = val
  print(minV)

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

int main() {   
    int a; ll b, n;
    cin >> a >> b >> n;
    ll x = min(n, b-1);
    cout << floor(a*x/b) << endl;
    return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,m,k;
	cin>>n>>m>>k;
	if(k<=n) cout<<n-k<<" "<<m;
	else {
		k-=n;
		m-=k;
		cout<<"0 ";
		if(m<=0)
			cout<<"0";
		else cout<<m;
	}
	return 0;
}

Measured memory_bytes: 256
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1005;
char s[N][N];int n,m,a,b,c,d;
int main(){
	scanf("%d%d%d%d",&n,&m,&a,&b),c=n,d=m;
	if(n*m<(a+b)*2)return puts("NO"),0;
	fp(i,1,n)fp(j,1,m)s[i][j]='.';
	if(m&1){
		R int p=1;
		while(b&&p+1<=n){
			s[p][m]='^',s[p+1][m]='v';
			p+=2,--b;
		}
		--m;
	}
	if(n&1){
		R int p=d;
		while(a&&p-1>=1){
			s[n][p]='>',s[n][p-1]='<';
			p-=2,--a;
		}
		--n;
	}
	R int rem=n*m;
	for(R int i=1;i<=n;i+=2)for(R int j=m-1;j>=1;j-=2){
		if(a>=2){
			a-=2,rem-=4;
			s[i][j]=s[i+1][j]='<',
			s[i][j+1]=s[i+1][j+1]='>';
		}else if(b>=2){
			b-=2,rem-=4;
			s[i][j]=s[i][j+1]='^',
			s[i+1][j]=s[i+1][j+1]='v';
		}
	}
	if(!a||!b||rem>=8){
		for(R int i=1;i<=n;i+=2)for(R int j=m-1;j>=1;j-=2)
			if(s[i][j]=='.'){
				if(a)--a,s[i][j]='<',s[i][j+1]='>';
				else if(b)--b,s[i][j]='^',s[i+1][j]='v';
			}
	}else if(rem>=4){
		if(a==1&&b==1&&(c&1)&&(d&1)){
			--a,--b;
			s[n-1][1]='<',s[n-1][2]='>',
			s[n][1]='^',s[n+1][1]='v';
		}
	}
	if(a||b)return puts("NO"),0;
	puts("YES");
	fp(i,1,c){
		fp(j,1,d)putchar(s[i][j]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int j = a/c, m = b/d, r;
		if(a%c!=0)j+=1;
		if(b%d!=0)m+=1;
		if(j>=m) r = l-j;
		else r = l-m;
		System.out.println(r);
	}

}

Measured memory_bytes: 26008
#include <stdio.h>

int main(void)
{
    int a,b,c,d;
    scanf("%d %d", &a ,&b);
    if(a < b){
        printf("a < b\n");
    }
    else if(a > b){
        printf("a > b\n");
    }
    else{
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
while True:
	data = raw_input().split(" ")
	a = int(data[0])
	op = data[1]
	b = int(data[2])

	if op == "?":
		break
	elif op == "+":
		ans = a + b
	elif op == "-":
		ans = a - b
	elif op == "*":
		ans = a * b
	else:
		ans = a / b

	print ans

Measured memory_bytes: 6456
using System;
using System.Linq;
using System.Collections.Generic;

public class Test
{
	public static void Main()
	{
        string[] line = Console.ReadLine().Split(' ');
        int A = int.Parse(line[0]);
        int B = int.Parse(line[1]);
        int C = int.Parse(line[2]);
        int D = int.Parse(line[3]);
    
        int lower = Math.Max(A,C);
        int upper = Math.Min(B,D);

        Console.WriteLine(Math.Max(0,upper-lower));
    
    }                                                                                                                                   
}

Measured memory_bytes: 13140
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main() {
	int N; cin >> N;
	for (ll h = 1; h <= 3500; h++) {
		for (ll n = h; n <= 3500; n++) {
			if (N*(h + n) >= 4 * h*n)continue;
			ll w = -N*h*n / (N*(h + n) - 4 * h*n);
			if (4 * h*n*w == N*(h*n + n*w + w*h)) {
				cout << h << ' ' << n << ' ' << w << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>


int main()
{
	int A,B;

	if (scanf("%d %d", &A,&B) == 2)
	{
		if (A <= 8 && B <= 8) {
			printf("Yay!");
		}
		else{
			printf(":(");
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main(void) {

    int h, w;
    while(cin >> h >> w){

      if( h == 0 && w == 0 ) break;

      for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
          if( (i + j) % 2 == 0 ) cout << "#";
          else cout << ".";
        }
        cout << endl;
      }
      cout << endl;
    }


    return 0;
}

Measured memory_bytes: 3068
read n m x y
cat > /tmp/tmp
X=$( ( echo -n "$x "; head -1 /tmp/tmp ) | tr ' ' \\n | sort -n | tail -1 )
Y=$( ( echo -n "$y "; tail -1 /tmp/tmp ) | tr ' ' \\n | sort -n | head -1 )
(( $X < $Y )) && echo No War || echo War


Measured memory_bytes: 2116
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  string s1, s2, s3; cin >> s1 >> s2 >> s3;
  char c1, c2, c3;
  c1 = s1[0]-0x20;
  c2 = s2[0]-0x20;
  c3 = s3[0]-0x20;
  cout << c1 << c2 << c3 << endl;
  return 0;
}

Measured memory_bytes: 256
/* it was worth becoming a chemist */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned int uni;
typedef unsigned long long unll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long long, int> pli;
typedef pair<int, long long> pil;
typedef vector<int> vi;
typedef vector<long long> vll;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
#define NAME "puts"
#define F first
#define S second

const ll INF = 1e18;
const int inf = 1e9;
const int mod = 1e9 + 7;
const db EPS = (db) 1e-9;
const db pi = acos(-1.0);
const int MAXN = 2e5 + 5;

int n, a[MAXN], id[MAXN];
ll res;

struct seg {
	int mx;
	int mn;
} t[MAXN * 4];

void build(int v, int tl, int tr) {
	t[v].mx = -inf;
	t[v].mn = inf;
	if (tl == tr) return;
	int tm = (tl + tr) >> 1;
	build(v + v, tl, tm);
	build(v + v + 1, tm + 1, tr);
}

void update(int v, int tl, int tr, int pos) {
	if (tl == tr) {
		t[v].mx = t[v].mn = pos;
		return;
	}
	int tm = (tl + tr) >> 1;
	if (pos >= tl && pos <= tm) update(v + v, tl, tm, pos);
	if (pos >= tm + 1 && pos <= tr) update(v + v + 1, tm + 1, tr, pos);
	t[v].mx = max(t[v + v].mx, t[v + v + 1].mx);
	t[v].mn = min(t[v + v].mn, t[v + v + 1].mn);
}

int get_min(int v, int tl, int tr, int l, int r) {
	if (tl >= l && tr <= r) return t[v].mn;
	if (tl > r || tr < l) return inf;
	int tm = (tl + tr) >> 1;
	return min(get_min(v + v, tl, tm, l, r), get_min(v + v + 1, tm + 1, tr, l, r)); 
}

int get_max(int v, int tl, int tr, int l, int r) {
	if (tl >= l && tr <= r) return t[v].mx;
	if (tl > r || tr < l) return -inf;
	int tm = (tl + tr) >> 1;
	return max(get_max(v + v, tl, tm, l, r), get_max(v + v + 1, tm + 1, tr, l, r));
}

int main() {	
   
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		id[a[i]] = i;
	}

	build(1, 1, n);

	for (int i = 1; i <= n; i++) {
		ll l = (ll)get_max(1, 1, n, 1, id[i]);
		if (l == (ll)-inf) l = 1;
		else l++;
		
		ll r = (ll)get_min(1, 1, n, id[i], n);
		if (r == (ll)inf) r = n;
		else r--;
		
		ll ct = 0;
		if (l == id[i]) ct = r - l + 1;
		else ct = (r - id[i] + 1) * (id[i] - l) + (r - id[i] + 1);
	
		
		res += (ct * (ll)i);
		update(1, 1, n, id[i]);
	}

	cout << res;	
	return 0;
}


Measured memory_bytes: 7936