akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) REP(i,(vec).size()) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int K, S;
    cin >> K >> S;
    ll ans = 0;
    REP(x, K + 1) {
        int s = S - x;
        if (s < 0)continue;
        REP(y, K + 1) {
            int s2 = s - y;
            if (s2 < 0)continue;
            if (s2 <= K) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;



bool comp(pair<int,int> a, pair<int,int> b){
  if(a.first == b.first) return a.second < b.second;
  else return a.first < b.first;
}

int main() {
  int n; cin >> n;
  vector<pair<int, int> > p(n);
  for(int i=0; i<n; i++) cin >> p[i].first >> p[i].second;

  sort(p.begin(),p.end(),comp);

  for(int i=0; i<n; i++){
    cout << p[i].first <<" "<< p[i].second << endl;
  }


}


Measured memory_bytes: 3640
import itertools

n = int(input())
p = tuple(list(map(int, input().split())))
q = tuple(list(map(int, input().split())))
counter = 0
a = 0
b = 0
for i in itertools.permutations(range(1, n+1)):
    counter += 1
    if p == i:
        a = counter
    if q == i:
        b = counter

print(abs(a - b))

Measured memory_bytes: 3064
#include <iostream>
#include<algorithm>
#include <vector>
#include<map>
#include<deque>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define max(x,y) (((x)>(y)) ? x:y)
#define min(x,y) (((x)<(y)) ? x:y)
#define FOR(a) for(int i=0;i<a;i++)
#define ender {return 0;}
#define tosasuretu(a) (a*(a+1)/2)
inline ll kaizyo(ll);
ll gcd(ll, ll);
ll combination(ll, ll);
int main(){
	int h,maxh=-1, n;
	cin >> n;
	int count = 0;
	FOR(n) {
		cin >> h;
		if (maxh <= h) {
			count++;
			maxh = h;
		}
	}
	cout << count;
	return 0;
}


inline ll kaizyo(ll x) {
	ll ans = 1;
	for (int z = 0; z < x; z++) {
		ans *= (x - z);
	}
	return ans;
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define def(x) cerr << #x << " is " << x << endl;
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(ll i=a;i<n;i++)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(a) a.begin(),a.end()
const int NUM = 2e5 + 5;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
int main(){
    ios
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        ll n; cin>>n;
        string ans = "";
        while(n!=0){
            ll rem = n%26;
            if(rem==0) ans+='z',n--;
            else ans+=('a'+(rem-1));
            n/=26;
        }
        reverse(all(ans));
        cout<<ans;
    }   
 }

Measured memory_bytes: 3640
def f(n):
    if (n+1) % 4 == 0:
        return 0
    elif (n+1) % 4 == 1:
        return n
    elif (n+1) % 4 == 2:
        return 1
    else:
        return n ^ 1
a, b = map(int, input().split())
ans = f(a-1) ^ f(b)
print(ans)

Measured memory_bytes: 3060
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

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

int main(int argc, const char * argv[]) {
    
    ll n;
    cin >> n;
    cout << 3 * n * n;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    int[] num = new int[3];
    num[0] = sin.nextInt();
    num[1] = sin.nextInt();
    num[2] = sin.nextInt();

    for( int i = 0, tmp; i < num.length -1; i++) {
      for( int j = 1; j < num.length - i; j++)
      if( num[j-1] > num[j] ) {
        tmp = num[j-1];
        num[j-1] = num[j];
        num[j] = tmp;
      }
    }

    System.out.println(num[0] + " " + num[1] + " " + num[2]);
    sin.close();
  }
}


Measured memory_bytes: 26248
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

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

fn is_pairwise_coprime(a: &Vec<usize>) -> bool {
    let primes = {
        let mut primes = vec![true; 1001];
        primes[0] = false;
        primes[1] = false;
        for i in 2..primes.len() {
            if primes[i] {
                for j in 2.. {
                    if i * j >= primes.len() {
                        break;
                    }
                    primes[i * j] = false;
                }
            }
        }
        primes
            .into_iter()
            .enumerate()
            .filter(|&(_, f)| f)
            .map(|(i, _)| i)
            .collect::<Vec<_>>()
    };

    let n = a.len();
    let mut b = a.clone();
    let mut visited = HashSet::new();
    for i in 0..n {
        for &p in &primes {
            if b[i] % p == 0 {
                if visited.contains(&p) {
                    return false;
                } else {
                    visited.insert(p);
                }
            }
            while b[i] % p == 0 {
                b[i] /= p;
            }
            if b[i] == 1 {
                break;
            }
        }
        if b[i] > 1 {
            if visited.contains(&b[i]) {
                return false;
            } else {
                visited.insert(b[i]);
            }
        }
    }
    return true;
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    if is_pairwise_coprime(&a) {
        println!("pairwise coprime");
        return;
    }

    let mut g = a[0];
    for i in 1..n {
        g = gcd(g, a[i]);
    }
    if g == 1 {
        println!("setwise coprime");
    } else {
        println!("not coprime");
    }
}


Measured memory_bytes: 25488
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mod (1000*1000*1000+7)
#define modd (1000*1000*1000+9)
#define flush fflush(stdout)
#define pi 3.14159265358979323846264338327950
#define read_in_arr(a, n) for(int i=0;i<n;i++){ cin>>a[i];}
#define print_arr(a, n) for(int i=0;i<n;i++){ cout<<a[i]<<" ";} cout<<endl;
// cout<<fixed<<setprecision(12)<<ans<<endl;
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
	int tc;
	cin>>tc;
	if(tc>=30){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define ALL(x) x.begin(), x.end()
using namespace std;
using ll=long long;
constexpr ll MOD = ll(1e9+7);

vector<ll> primes(ll N)
{
	vector<ll> result;
	FOR(_i, N) {
		auto i = _i + 2;
		if ( i >= N+ 10 ) break;
		if (result.empty()) result.push_back(i);
		else {
			bool ok = true;
			for(auto v : result) {
				if (i % v == 0) {
					ok = false; break;
				}
			} if (ok) { result.push_back(i); } 
		}
	}	
	return result;
}
signed main()
{
	ll N ; cin >> N;
	auto vPrim = primes(N);
	ll ans = 1;
	for(auto vp : vPrim) {
		ll cnt = 0;
		FOR(_i, N) { auto i = _i + 1; 
			if ( i < vp ) continue;
			if ( i % vp == 0) {
				while (i%vp == 0) {
					cnt += 1; 	i/=vp;
				}
			}
		}
		ans = (ans * (cnt+1)) % MOD;
	}
	while (ans <0) ans += MOD;
	cout << ans % MOD << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int MAXN=100000001;
int N,A,B,ans,t[MAXN];
int main(){
	cin>>N>>A>>B;
	for(int i=1;i<=N;i++) cin>>t[i];
	for(int i=1;i<=N;i++){
		if(t[i]<A||t[i]>=B) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
// 未解決

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

//**********

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

  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = 0;

  if (k <= a) {
    ans = k;
  } else if (k <= a + b) {
    ans = a;
  } else {
    ans = a - (k - a - b);
  }
  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 3648
R, G, B, N = map(int, input().split())

cnt = 0

for i in range(N // R + 1):
    for j in range(N // G + 1):
        t = N - (i * R + j * G)
        if 0 <= t and t % B == 0:
            cnt += 1
            
print(cnt)


Measured memory_bytes: 40812
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
 
// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ---------------------------------------------------------------------------

int main(){
  ll N,K;
  cin >> N >> K;
  int cnt = 0;
  while(N){
    N /= K;
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
///                ..:: In The Name Of God ::..
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define endl    '\n'
#define INF 2e9
#define int ll
#define vi          vector<int>
#define de          deque<int>
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()//全範囲指定を簡略化
typedef long long ll;
using namespace std;
//配列の要素数は　sizeof(ar)/sizeof(ar[0]) で求める
signed main(){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int A,B;
cin>>A>>B;

if(A-B*2<0){
    cout << "0"<< endl;
}
else{
    cout << A-B*2 << endl ;
}

return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int count[4][3][10], i, j, k, b, f, r, v, n;//b=棟,f=階,r=部屋番号,v=入居者数
	for(i = 0; i < 4; i++){
		for(j = 0; j < 3; j++){
			for(k = 0; k < 10; k++){
				count[i][j][k] = 0; //初期化
			}
		}
	}
	scanf("%d",&n);
	for(i = 0; i < n; i++){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		count[b - 1][f - 1][r - 1] += v; //0からの変数になるので-1
	}
	for(i = 0; i < 4; i++){
			if(i != 0){ //行頭に＃を20個出力する(最初のみ出力しない)
			printf("####################\n");
		}
		for(j = 0; j < 3; j++){
			for(k = 0; k < 10; k++){
				printf(" %d",count[i][j][k]);
			}
/*if(j == 2 && i < 3){ //3棟目まで実行する
printf("\n####################\n"); //4段目に#を20個出力する
}*/
			printf("\n");
		}
	}
	return 0;
} 


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

using namespace std;
typedef long long ll;

int main()
{
  ll a, b, c, d;
  cin >> a >> b >> c >> d;

  while (a > 0 && c > 0)
  {
    c -= b;
    if (c <= 0)
    {
      cout << "Yes" << endl;
      continue;
    }
    a -= d;
    if (a <= 0)
    {
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    string ans = "APPROVED";
    rep(i,n) {
        if (a[i]%2==0 && a[i]%3 && a[i]%5) ans = "DENIED";
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
X,Y = list(map(int,input().split()))

n = (-X+2*Y)//3
m = (2*X-Y)//3

mod = 10**9+7 #出力の制限
N = max(n+m,n)
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
    
if (-X+2*Y)%3 == 0 and (2*X-Y)%3 == 0:
    print(cmb(n+m,n,mod))
else:
    print(0)

Measured memory_bytes: 82464
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  vector<string> s(N);
  for (int i = 0; i < N; ++i)
    cin >> s[i];

  long long ret = 0;
  long long start_with_b = 0;
  long long end_with_a = 0;
  long long both = 0;
  for (int i = 0; i < N; ++i) {
    if (s[i].front() == 'B' && s[i].back() == 'A')
      ++both;
    else if (s[i].front() == 'B')
      ++start_with_b;
    else if (s[i].back() == 'A')
      ++end_with_a;
    for (int j = 0; j < s[i].size() - 1; ++j) {
      if (s[i].substr(j, 2) == string("AB"))
        ++ret;
    }
  }

  if (both > 0) {
    ret += both - 1;
    N = N - both + 1;
    if (start_with_b > 0 && end_with_a > 0) {
      ret += 2;
      --start_with_b;
      --end_with_a;
      N -= 2;
    } else if (start_with_b > 0) {
      ++ret;
      --start_with_b;
      N -= 1;
    } else if (end_with_a > 0) {
      ++ret;
      --end_with_a;
      N -= 1;
    }
  }
  if (N > 1)
    ret += min(start_with_b, end_with_a);

  cout << ret << endl;

  return 0;
}

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

int main() {
	ll N,Q,s=0;
	cin >> N;
	map<ll,ll> m;

	rep(i,N) {
		ll t;
		cin >> t;
		if(m.count(t))
			++m.at(t);
		else
			m[t] = 1;
		s += t;
	}

	cin >> Q;
	rep(i,Q) {
		ll B,C;
		cin >> B >> C;
		
		if(m.count(B)) {
			s = s-B*m.at(B)+C*m.at(B);
			if(m.count(C))
				m.at(C) += m.at(B);
			else
				m[C] = m.at(B);
			m.erase(B);
		}
		cout << s << endl;
	}
}

Measured memory_bytes: 7436
const MOD: u64 = 1e9 as u64 + 7;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let s = sc.chars();
    let n = s.len();
    let mut dp = vec![0; 13];
    dp[0] = 1;
    for i in 0..n {
        let mut next = vec![0; 13];
        let c = s[i];
        for r in 0..13 {
            if c == '?' {
                for c in 0..10 {
                    let next_r = (r * 10 + c) % 13;
                    next[next_r] += dp[r];
                    next[next_r] %= MOD;
                }
            } else {
                let c = c as usize - '0' as usize;
                let next_r = (r * 10 + c) % 13;
                next[next_r] += dp[r];
                next[next_r] %= MOD;
            }
        }
        dp = next;
    }
    println!("{}", dp[5]);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
//const ll mod = 1000000007LL;
const ll mod = 998244353LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
ll mypow(ll n,ll m){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n);
        m >>= 1;
        n *= n;
    }
    return res;
}
//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

#define rep(i,x) for(int i = 0;i<x;i++)
#define REP(i,x) for(int i = 1;i<=x;i++)

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll A,B;
    cin >> A >> B;
    rep(i,1500){
        if((ll)(i*0.08) == A && (ll)(i/10) == B){
            cout << i << "\n";
            return 0;
        }
    }
    cout << "-1\n";
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

int main() {
    int n,m;
    cin >> n >> m;
    int s,c;
    int ans=0;
    bool flag=1;
    vector<int> a={-1,-1,-1};
    rep(i,m) {
        cin >> s >> c;
        if (s==1 && c==0 && n>1) flag=0;
        if (a[s-1]==-1) {
            ans+=pow(10,n-s)*c;
            a[s-1]=c;
        }
        else if (a[s-1]!=c) flag=0;
    }
    if (ans<pow(10,n-1) && n>1) ans+=pow(10,n-1);
    if (flag) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
s=list(input())
f=0
ans=0
for i in range(len(s)):
    if s[i]=='A' or s[i]=='C' or s[i]=='T' or s[i]=='G':
        f+=1
        ans=max(ans,f)
    else:
        ans=max(ans,f)
        f=0
print(ans)        


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll MOD = 1000000007;

ll dp[63][2][2][2];

int main(){
  ll L, R;
  cin >> L >> R;

  dp[62][0][0][0] = 1;
  for(int i=61; i>=0; i--){
    rep(j,2) rep(k,2) rep(l,2){
      int lbit = (L>>i)&1;
      int rbit = (R>>i)&1;
      rep(x,2) rep(y,2){
        if(x==1 && y==0) continue;
        int nj=j, nk=k, nl=l;

        // まだ0 0しか出ていない
        if(l==0){
          // 0 1はダメ
          if(x==0 && y==1) continue;
        }
        if(x==1 && y==1) nl = 1; //すでにビットが出ていることが確定

        // L <= x
        if(j==0){ //xがLギリギリ
          //L側が1でxが0だと下回ってしまうのでダメ
          if(lbit==1 && x==0) continue;
        }
        if(lbit==0 && x==1) nj = 1; //L<xが確定

        // y <= R
        if(k==0){ //yがRギリギリ
          //R側が0でyが1だと上回ってしまうのでダメ
          if(rbit==0 && y==1) continue;
        }
        if(rbit==1 && y==0) nk = 1; //y<Rが確定

        dp[i][nj][nk][nl] += dp[i+1][j][k][l];
        dp[i][nj][nk][nl] %= MOD;
      }
    }
  }

  ll ret = 0;
  rep(j,2) rep(k,2) rep(l,2){
    ret += dp[0][j][k][l];
    ret %= MOD;
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

ll gcd(ll x, ll y) {
  while (y != 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  ll k;
  cin >> n >> k;
  ll ma = 0;
  VL a(n);
  ll g = 0;
  REP(i, 0, n) {
    cin >> a[i];
    g = gcd(g, a[i]);
    ma = max(ma, a[i]);
  }
  bool ok = k % g == 0;
  if (ok) {
    ok = ma >= k;
  }
  cout << (ok ? "POSSIBLE" : "IMPOSSIBLE") << "\n";
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<cmath>
using namespace std;

int min(int a, int b)
{
	return a < b ? a : b;
}
int main()
{
	int w, a, b;
	int x, y;
	int l1, l2, r1, r2;
	int ans;

	scanf("%d %d %d", &w, &a, &b);
	l1 = a;
	r1 = w + a;
	l2 = b;
	r2 = w + b;
	if((l2 <= r1 && l2 >= l1) || (r2 >= l1 && r2 <= r1))
		printf("0\n");
		else
		{
	x = min(abs(l1 - r2), abs(l1 - l2));
	y = min(abs(r1 - r2), abs(r1 - l2));
	ans = min(x, y);
	printf("%d\n", ans);
		}
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from functools import reduce


# 画像でおいた自分の解説見て
N = a_int()
B = []
for _ in ra(N):
    A = read()[:-1]  # floatで扱うと誤差で死ぬ
    if '.' not in A:
        A += '.'
    for _ in range(9 - A[::-1].index('.')):
        A += '0'
    B.append(int(A[:-10] + A[-9:]))

N = []
M = []
for b in B:
    n = 0
    while ~b & 1:  # 偶数である限り
        b >>= 1
        n += 1
    N.append(n)

    m = 0
    while b % 5 == 0:  # 5で割れる限り
        b //= 5
        m += 1
    M.append(m)

cnt = [[0] * 19 for _ in ra(19)]
ans = 0
for n, m in zip(N, M):
    x = max(18 - n, 0)
    y = max(18 - m, 0)
    for i, j in product(range(x, 19), range(y, 19)):
        ans += cnt[i][j]

    # このデータをcntに追加
    cnt[min(n, 18)][min(m, 18)] += 1

print(ans)


Measured memory_bytes: 107784
#include<iostream>

using namespace std;
int main()
{
    int n,m;
    cin>>n;int s,sum=0;
    while(n>4){
        if(n==500 || n>500){
           m = n%500;
           ///cout<<m<<endl;
           n = n/500;
           s = n*1000;
           sum = sum+s;
           ///cout<<sum<<endl;
           n = m;
           ///cout<<n<<endl;
        }
        if(n==5 || n>5){
           m = n%5;
           ///cout<<m<<endl;
           n = n/5;
           s = n*5;
           sum = sum+s;
           ///cout<<sum<<endl;
           n = m;
           ///cout<<n<<endl;
       }
    }
    if(sum<5){
        cout<<sum<<endl;
    }
    else{
        cout<<sum<<endl;
    }


    return 0;
}


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

int b, e, q, n, temp;

int main() {
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) cin >> a[i];
    cin >> q;
    for (int i=0; i<q; i++) {
        cin >> b >> e;
        for (int j=0; j*2<e-b; j++) {
            temp = a[b+j];
            a[b+j] = a[e-1-j];
            a[e-1-j] = temp;
        }
    }
    for (int i=0; i<n-1; i++) cout << a[i] << " ";
    cout << a[n-1] << endl;
}


Measured memory_bytes: 3116
import java.io.*;
import java.util.*;
class Main{
	static final double EPS = 0.00000000001;
    static final int COUNTER_CLOCKWISE = 1;
    static final int CLOCKWISE = -1;
    static final int ONLINE_BACK = 2;
    static final int ONLINE_FRONT = -2;
    static final int ON_SEGMENT = 0;

	private static List<Point> hull = new ArrayList<>();

	public static void main(String[] args) throws IOException{
		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();

		// Create list of points from input
		Point[] points = new Point[n];
		for(int i = 0; i < n; i++) {
			points[i] = new Point(scanner.nextInt(), scanner.nextInt());
		}
		scanner.close();

		Arrays.sort(points, new SortPoint());
		findHull(points, n);
	}

	private static int orientation(Point p0, Point p1, Point p2){
		Point a = vec(p0, p1);
        Point b = vec(p0, p2);
        if(cross(a, b) > EPS) return COUNTER_CLOCKWISE;
        if(cross(a, b) < EPS) return CLOCKWISE;
        if(dot(a, b) < EPS) return ONLINE_BACK;
        if(norm(a) < norm(b)) return ONLINE_FRONT;
        return ON_SEGMENT;
	}

	public static void findHull(Point points[], int n) {
		List<Point> u = new ArrayList<Point>();
		List<Point> l = new ArrayList<Point>();

		if (n < 3) return;

		u.add(points[0]);
		u.add(points[1]);

		l.add(points[n-1]);
		l.add(points[n-2]);

		for (int i = 2; i < n; i++) {
			for (int j = u.size(); j >= 2 && orientation(u.get(j-2), u.get(j-1), points[i]) != CLOCKWISE; j--) {
				u.remove(u.size() - 1);
			}
			u.add(points[i]);
		}

		for (int i = n-3; i >= 0; i--) {
			for (int j = l.size(); j >= 2 && orientation(l.get(j-2), l.get(j-1), points[i]) != CLOCKWISE; j--) {
				l.remove(l.size() - 1);
			}
			l.add(points[i]);
		}

		Collections.reverse(l);
		for (int i = u.size() - 2; i >= 1; i--) {
			l.add(u.get(i));
		}

		System.out.println(l.size());
		for (Point p : l) {
			System.out.println(p);
		}
	}

	static double norm(Point p) {
		return p.x * p.x + p.y * p.y;
	}
	static Point vec(Point p1, Point p2) {
		return new Point(p2.x - p1.x, p2.y - p1.y);
	}
	static double dot(Point u, Point v) {
		return u.x * v.x + u.y * v.y;
	}
	static double cross(Point u, Point v) {
		return u.x * v.y - u.y * v.x;
	}
	
}
class Point{
	int x;
	int y;
	public Point(int x, int y){
		this.x = x;
		this.y = y;
	}
	public String toString(){
		return x + " " + y;
	}
}

class SortPoint implements Comparator<Point> {
	public int compare(Point p1, Point p2) {
		if (p1.y < p2.y)
			return -1;
		else if (p1.y == p2.y) {
			if (p1.x < p2.x)
				return -1;
			else if (p1.x == p2.x)
				return 0;
			else
				return 1;
		} else return 1;
	}
}




Measured memory_bytes: 104128
#include<stdio.h>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
char str[60][60];
char in[60];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
char dc[7]="DRUL";
int bfs[60][60][110];
string val[110];
int ng[110];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++)scanf("%s",str[i]);
		int c;scanf("%d",&c);
		map<string,int>m;
		int sz=0;
		for(int i=0;i<110;i++)ng[i]=0;
		val[0]="";
		m[string("")]=sz++;
		for(int i=0;i<c;i++){
			scanf("%s",in);
			string tmp=in;
			for(int j=0;j<=tmp.size();j++){
				if(!m.count(tmp.substr(0,j))){
					val[sz]=tmp.substr(0,j);
					m[tmp.substr(0,j)]=sz++;
				}
			}
			ng[m[tmp]]=1;
		}
		for(int i=0;i<sz;i++){
			string tmp=val[i];
			while(tmp.size()){
				tmp=tmp.substr(1,tmp.size()-1);
				if(m.count(tmp)&&ng[m[tmp]]){ng[i]=1;break;}
			}
		}
		int sr,sc,gr,gc;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++){
			if(str[i][j]=='S'){sr=i;sc=j;}
			if(str[i][j]=='G'){gr=i;gc=j;}
		}
		queue<pair<pair<int,int>,int> >Q;
		for(int i=0;i<a;i++)for(int j=0;j<b;j++)for(int k=0;k<sz;k++){
			bfs[i][j][k]=99999999;
		}
		bfs[sr][sc][0]=0;
		Q.push(make_pair(make_pair(sr,sc),0));
		while(Q.size()){
			int row=Q.front().first.first;
			int col=Q.front().first.second;
			int at=Q.front().second;
			string now=val[at];
			Q.pop();
			for(int i=0;i<4;i++){
				if(0<=row+dx[i]&&row+dx[i]<a&&0<=col+dy[i]&&col+dy[i]<b&&str[row+dx[i]][col+dy[i]]!='#'){
					string to=now+dc[i];
					while(!m.count(to)){
						to=to.substr(1,to.size()-1);
					}
					int tt=m[to];
					if(!ng[tt]&&bfs[row+dx[i]][col+dy[i]][tt]>999999){
						bfs[row+dx[i]][col+dy[i]][tt]=bfs[row][col][at]+1;
						Q.push(make_pair(make_pair(row+dx[i],col+dy[i]),tt));
					}
				}
			}
		}
		int ret=999999999;
		for(int i=0;i<sz;i++)ret=min(ret,bfs[gr][gc][i]);
		if(ret>9999999)printf("-1\n");
		else printf("%d\n",ret);
	}
}

Measured memory_bytes: 2440
function main(input) {
  const lines = input.split('\n');
  lines.pop();
  lines.forEach(line => {
    console.log(fn(line));
  });
}

function fn(n) {
  switch(n.length) {
    case 1:
      return u1(n);
    case 2:
      return u2(n);
    case 3:
      return u3(n);
    case 4:
      return u4(n);
    case 5:
      return u5(n);
    case 6:
      return u6(n);
  }
}

function u1(n) {
  return parseInt(n, 10);
}
function u2(n) {
  return 9;
}
function u3(n) {
  return parseInt(n, 10) - 99 + 9;
}
function u4(n) {
  return 900 + 9;
}
function u5(n) {
  return parseInt(n, 10) - 9999 + 9 + 900;
}
function u6(n) {
  return 9 + 900 + 90000
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
A = list(map(int,input().split()))
A = sorted(A)
cnt = 0

if A[1]-A[0]>=2:
  cnt += (A[1]-A[0])//2
  A[0]+= cnt*2

if A[0]==A[1] and A[1]==A[2]:
  print(cnt)
  exit()

  
while(True):
  cnt+=1
  A = sorted(A)
  A[0]+=1
  A[1]+=1
  #print(A)
  if A[0]==A[1] and A[1]==A[2]:
    break

print(cnt)

Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

typedef pair<int, int> pii;
const int K = 102;
const int N = 32000;
const int mod = int(1e9) + 7;

int f[K][N], g[K][N], cnt[N];
int n, k, lim1, lim2;

void add(int& x, int y) {
    x += y;
    if(x >= mod) x -= mod;
    if(x < 0) x += mod;
}

int mul(int x, int y) {return 1ll * x * y % mod;}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> k; lim1 = lim2 = sqrt(n);
    for(int i = 1; i <= lim1; ++i) f[1][i] = i;
    for(int i = lim2; i >= 1; --i) {
        g[1][i] = g[1][i + 1];
        cnt[i] = n / i - n / (i + 1);
        cnt[i] -= max(lim1 - (n / i) + 1, 0);
        add(g[1][i], cnt[i]);
    }
    for(int i = 2; i <= k; ++i) {
        for(int j = 1; j <= lim1; ++j) {
            add(f[i][j], f[i - 1][lim1]);
            add(f[i][j], g[i - 1][j]);
            add(f[i][j], f[i][j - 1]);
        }
        for(int j = lim2; j >= 1; --j) {
            add(g[i][j], mul(f[i - 1][j], cnt[j]));
            add(g[i][j], g[i][j + 1]);
        }
    }
    int res = f[k][lim1];
    add(res, g[k][1]);
    cout << res;
}


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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  int N = 200;
  int sum = A+B+C; //この数字より大きい奇数かつ3の倍数
  int MAX = max(max(A, B), C); //sumを3で割った商がこの値以上
  int ans = 0;
  
  for(int i = 0; i < N; i += 2)
  {
    if((sum+i) % 3 == 0 && (sum+i) / 3 >= MAX)
    {
      ans = i / 2;
      break; //1つ見つけたらそれが最小
    }
  }
  cout << ans << endl;
}
    


Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace procon
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string result = "";

            for(int i = 0; i < input.Length; i++)
            {
                string target = input.Substring(i, 1);
                if(target == "B")
                {
                    if(result != "")
                    {
                        result = result.Substring(0, result.Length - 1);
                    }
                }
                else
                {
                    result = result + target;
                }
            }

            Console.WriteLine(result);
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  while (cin >> n) {
    cout << n * (n + 1) / 2 + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3000
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>

#define M 400010
#define PI pair <int, int>
#define f first
#define s second
using namespace std;
typedef long long ll;
int n, ans;

int X[M];

bool check(int x) {
    int t = 1;
    vector <PI> V(0);
    for(int i = 2; i <= n; i++)
        if(X[i] <= X[i - 1]) {
            while(!V.empty() && V.back().f > X[i]) V.pop_back();
            if(V.empty() || V.back().f != X[i]) V.push_back(PI(X[i], 0));
            V.back().s++;
            while(!V.empty() && V.back().s == x) {
                PI tmp = V.back();
                V.pop_back();
                if(V.empty() || V.back().f != tmp.f - 1) V.push_back(PI(tmp.f - 1, 0));
                V.back().s++;
                if(V.back().f == 0) return 0;
            }
        }
    return 1;
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", &X[i]);
    int l = 2, r = n;
    int flag = 1;
    for(int i = 2; i <= n; i++) if(X[i] <= X[i - 1]) {
        flag = 0;
        break;
    }
    if(flag) {
        puts("1");
        return 0;
    }
    for(; l <= r; ) {
        int md = (l + r) / 2;
        if(check(md)) ans = md, r = md - 1; else l = md + 1;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
#define rep3(i,n,m) for(long long i=n;i>=m;i--)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
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(){
 ll n,k ;
 cin >>n >>k ;
 vector<ll> A(n) ;
 rep(i,n) cin>> A[i] ;
  ll sum=0 ;
 ll base = 0;
 ll s=0 ;
 rep(i,k){
   base+=A[i] ;
  if(A[i]>0)
  s+=A[i] ;
 }
 ll ans= max(0ll,base)-s ;
 rep(i,n){
   if(A[i]>=0)
   sum+= A[i] ;
  if(i<n-k){
    base= base-A[i]+A[i+k] ;//baseとsを更新
    if(A[i]>0) s-=A[i] ;
    if(A[i+k]>0) s+=A[i+k] ;
    chmax(ans,max(0ll,base)-s) ;
  }
}   
   cout <<sum+ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
const int nmax = 40, abmax = 10, inf = 1000000;
int a[nmax], b[nmax], c[nmax];
int dp[nmax + 1][nmax*abmax + 1][nmax*abmax + 1];
int main() {
	int n, ma, mb;
	cin >> n >> ma >> mb;
	for (int i = 0; i < n; i++)cin >> a[i] >> b[i] >> c[i];
	for (int i = 0; i <= n; i++) {
		for (int ia = 0; ia <= nmax*abmax; ia++) {
			for (int ib = 0; ib <= nmax*abmax; ib++) {
				dp[i][ia][ib] = inf;
			}
		}
	}
	dp[0][0][0] = 0;
	for (int i = 0; i < n; i++) {
		for (int ia = 0; ia <= nmax*abmax; ia++) {
			for (int ib = 0; ib <= nmax*abmax; ib++) {
				if (dp[i][ia][ib] == inf)continue;
				dp[i + 1][ia][ib] = min(dp[i + 1][ia][ib], dp[i][ia][ib]);
				dp[i + 1][ia + a[i]][ib + b[i]] = min(dp[i + 1][ia + a[i]][ib + b[i]], dp[i][ia][ib] + c[i]);
			}
		}
	}
	int ans = inf;
	for (int ia = 1; ia <= nmax*abmax; ia++) {
		for (int ib = 1; ib <= nmax*abmax; ib++) {
			if (ia*mb == ib*ma)ans = min(ans, dp[n][ia][ib]);
		}
	}
	if (ans == inf)ans = -1;
	cout << ans << endl;
}

Measured memory_bytes: 25984
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;

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

  int w, a, b;
  cin >> w >> a >> b;

  if (abs(a-b) < w) cout << 0 << endl;
  else {
    if (a < b) cout << b-a-w << endl;
    else cout << a-b-w << endl;
  }
  return 0;
}

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

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int partition(vector<int> &A, int p, int r){
    int x = A[r];
    int i = p - 1;
    for(int j = p; j < r; j++){
        if(A[j] <= x){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i + 1], A[r]);
    return i + 1;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int p = partition(A, 0, N - 1);
    rep(i, N){
        if(i) cout << ' ';
        if(i == p) cout << "[" << A[i] << "]";
        else cout << A[i];
    }
    cout << endl;
}


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

int main () {
    int n, m;
    std::cin >> n >> m;

    std::vector<int> l(m);
    std::vector<int> r(m);

   

    for (int i = 0; i < m; i++)
    {
        std::cin >> r[i];
        std::cin >> l[i];
        
    }

    int R, L;
    R = r[0];
    L = l[0];

    for (int i = 1; i < m; i++) {
        if (R < r[i])
        {
            R = r[i];
        }

        if (L > l[i])
        {
            L = l[i];
        }
    }

    if (L - R >= 0 && L - R + 1 <= n)
    {
        std::cout << L - R + 1 << std::endl;
    }
    else
    {
        std::cout << 0 << std::endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <unordered_map>
#include <algorithm>
 
#define ll long long
 
using namespace std;
int x, k, q, t, a, low, up, add, delta, now, ans, r[100007];
bool flag;
 
int cal(int tt, int lower = 0, int upper = x) {
    if (tt < lower) return lower;
    if (tt > upper) return upper;
    return tt;
}
 
int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
 
    cin >> x >> k;
    for (int i = 1; i <= k; i++) cin >> r[i];
    cin >> q;
 
    low = x, now = 1;
    while (q--) {
        cin >> t >> a;
        while (t >= r[now] && now <= k) {
            delta = (flag ? 1 : -1) * (r[now] - r[now - 1]), add += delta;
            up = cal(delta + up), low = cal(delta + low);
            flag = !flag, now++;
        }
        ans = cal((flag ? 1 : -1) * (t - r[now - 1]) + cal(a + add, up, low));
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int a[n];
    int dp[n];
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for (int i=2;i<n;i++){
        dp[i]=min(abs(a[i-1]-a[i])+dp[i-1],abs(a[i-2]-a[i])+dp[i-2]);
    }
    cout<<dp[n-1];
}   

Measured memory_bytes: 4368
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        x: i64,
    }
    use num::rational::Ratio;
    let x = Ratio::new(4, x);

    for h in 1..=3500 {
        for n in 1..=3500 {
            let w = x - Ratio::new(1, h) - Ratio::new(1, n);
            let (w, d) = w.into();
            if w == 1 {
                println!("{} {} {}", h, n, d);
                return;
            }
        }
    }
}


Measured memory_bytes: 2192
#include <stdio.h>

int main()
{
    int n, i;
    long long int sum;
    
    while(scanf("%d", &n) != EOF){
    	sum = 0;
        for (i = n; i <= 600 - n; i += n){
            sum += i * i;
        }
        sum *= n;
        printf("%lld\n", sum);
    }
    return 0;
}

Measured memory_bytes: 596
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math
import random
J=int(1e9)+7

###############################################################################\n=17
a,b,c,d=INPUT()
ans=max(a*c,b*d,a*d,b*c)
print(ans)


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

const int MAXN = 100010;
typedef long long LL;
int head[MAXN], nxt[MAXN << 1], to[MAXN << 1], val[MAXN << 1], tot;
void addedge(int b, int e, int v) {
	nxt[++tot] = head[b]; to[head[b] = tot] = e; val[tot] = v;
	nxt[++tot] = head[e]; to[head[e] = tot] = b; val[tot] = v;
}
LL ans = 0;
int rt, rtv, rt2, n;
int cent(int u, int fa = 0) {
	int maxv = 0, sz = 1;
	for (int i = head[u]; i; i = nxt[i])
		if (to[i] != fa) {
			int t = cent(to[i], u);
			maxv = std::max(t, maxv);
			sz += t;
		}
	maxv = std::max(maxv, n - sz);
	if (sz * 2 == n) rt2 = u;
	if (maxv < rtv) rt = u, rtv = maxv;
	return sz;
}
int dfs1(int u, int fa = 0) {
	int sz = 1;
	for (int i = head[u]; i; i = nxt[i]) if (to[i] != fa) {
		int t = dfs1(to[i], u);
		ans += (std::min(t, n - t) * 2ll - (t == n / 2)) * val[i];
		sz += t;
	}
	return sz;
}
void dfs2(int u, LL dep = 0, int fa = 0) {
	ans += dep << 1;
	for (int i = head[u]; i; i = nxt[i]) if (to[i] != fa)
		dfs2(to[i], dep + val[i], u);
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1, b, e, v; i < n; ++i)
		std::cin >> b >> e >> v, addedge(b, e, v);
	rtv = n; cent(1);
	if (rt2) dfs1(rt2); else {
		dfs2(rt);
		int mv = std::numeric_limits<int>::max();
		for (int i = head[rt]; i; i = nxt[i]) mv = std::min(mv, val[i]);
		ans -= mv;
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 7040