akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define fileInput(problemName) freopen ((string(problemName) + ".inp").c_str(), "r", stdin);freopen ((string(problemName) + ".out").c_str(), "w", stdout);
#define ll long long

const ll inf = 1e9 + 7;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 7;

int n, a[N][10], f[N][10];

main() {
    //fileInput("vacation");
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= 3; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= 3; i++) f[1][i] = a[1][i];
    for (int i = 2; i <= n; i++) {
        f[i][1] = max(f[i - 1][2], f[i - 1][3]) + a[i][1];
        f[i][2] = max(f[i - 1][1], f[i - 1][3]) + a[i][2];
        f[i][3] = max(f[i - 1][1], f[i - 1][2]) + a[i][3];
    }
    cout << max(max(f[n][1], f[n][2]), f[n][3]);
}

Measured memory_bytes: 11376
#include <stdio.h>
#include <utility>
#include <cmath>
#include <algorithm>

using namespace std;

long read_int(){
    long a;
    scanf("%ld",&a);
    return a;
}

long C(long N, long K){
    if(N>K){
        N = N % K;
    }
    long tmp = abs(N-K);
    long ret = min(N, tmp);
    return ret;
}

int main(){
    long N = read_int();
    long K = read_int();

    
    printf("%ld\n",C(N,K));
    return 0; 

}

Measured memory_bytes: 128
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
ans=0
for i in range(N):
    x=min(A[i],B[i])
    B[i]-=x
    ans+=x
    x=min(A[i+1],B[i])
    A[i+1]-=x
    ans+=x
print(ans)


Measured memory_bytes: 24228
package main

import (
	"fmt"
	"sort"
)

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

func main() {
	var n int
	fmt.Scan(&n)
	ln := make([]int, 2*n)
	for i := range ln {
		fmt.Scan(&ln[i])
	}
	sort.Ints(ln)

	ans := 0
	for i := 0; i < n; i++ {
		ans += min(ln[2*i], ln[2*i+1])
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){

  char	s[5] = {0};
  int	i;
  int	ans = 0;
  
  scanf("%s", s);
  
  for(i=0; i<4; i++){
    if(s[i]=='+'){ ans++; }
    else		 { ans--; }
  }
  printf("%d", ans); 

  return 0;
}

Measured memory_bytes: 128
/*
 * Pawan Harendra Mishra
 */

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

#define X first
#define Y second
typedef long long ll;
typedef pair<ll,ll> pll;

void err() {
    cout << "No" << endl;
    exit(0);
}

int main(int argc, char const *argv[])
{
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);

    string s;
    cin >> s;

    for (ll i=0; i<s.length(); i++) {
        ll j = i+1;
        if (j%2) {
            if (s[i]=='L') err();
        }
        else {
            if (s[i]=='R') err();
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

using namespace std;

int n, nr;

bool prim (int x) {
  if (x % 2 == 0)
    return 0;
  for (int i = 3; i * i <= x; i += 2)
    if (x % i == 0)
      return 0;
  return 1;
}

int main ()
{
  cin >> n;
  for (int i = 11; nr < n && i <= 55555; i += 10) {
    if (prim(i)) {
      nr++;
      cout << i << " ";
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=100005,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,D;cin>>N>>D;
    vector<int> left(N),A(N),ok(N);
    for(int i=0;i<N;i++) cin>>A[i];
    int now=D;
    
    for(int i=0;i<N;i++){
        if(now>=A[i]) now-=A[i];
        else chmin(now,A[i]-now);
        
        left[i]=now;
    }
    
    if(N==1){
        ok[0]=1;
    }else{
        if(left[N-2]) ok[N-1]=1;
        if(A[N-1]==1) now=2;
        else now=1;
        
        for(int i=N-2;i;i--){
            if(left[i-1]>=now) ok[i]=1;
            
            if(now>=A[i]||now*2>A[i]) now+=A[i];
        }
        if(D>=now) ok[0]=1;
    }
    
    int Q;cin>>Q;
    
    while(Q--){
        int a;cin>>a;
        a--;
        if(ok[a]) cout<<"YES\n";
        else cout<<"NO\n";
    }
}


Measured memory_bytes: 7808
import sys
from itertools import combinations_with_replacement
def input(): return sys.stdin.readline().strip()


def main():
    A, B, N = map(int, input().split())
    if N >= B:
        r = (B - 1) / B
    else:
        r = min(N, (B - 1)) / B
    print(int(A * r))



    


if __name__ == "__main__":
    main()

Measured memory_bytes: 61932
// https://atcoder.jp/contests/agc035/tasks/agc035_a
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#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 ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ull> v(n);
    REP(i, n) cin >> v[i];
    ull check = 0;
    REP(i, n) check ^= v[i];
    if (check == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 1024
class Graph<T : List<Int>> constructor(private val graph: Array<T>) {
    private val dp = IntArray(100000) { -1 }

    fun rec(v: Int): Int {
        if (dp[v] != -1) return dp[v]

        var res = 0
        graph[v].forEach {
            res = Math.max(res, rec(it) + 1)
        }
        dp[v] = res
        return res
    }

}

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }

    val graph = Array(n) { mutableListOf<Int>() }
    repeat(m) {
        val (x, y) = readLine()!!.split(' ').map { it.toInt() }
        graph[x - 1].add(y - 1)
    }

    val g = Graph(graph)
    var res = 0
    (0 until n).forEach {
        res = Math.max(res, g.rec(it))
    }
    println(res)
}


Measured memory_bytes: 68952
#include <iostream>
#include <vector>
// #include <algorithm>
// #include <queue>
// #include <cmath>
// #include <string>
// #include <numeric>
// #include <set>
// #include <map>
// #include <iomanip>

// #define MOD 1000000007
// #define INF 1000000001

using namespace std;
// typedef unsigned long long ull;
// typedef long long ll;

void p_() {
    cout << "\n";
}
template<class Head, class... Body>
void p_(Head head, Body... body) {
    cout << head << ",";
    p_(body...);
}


int main(int argc, char const *argv[]) {
    int R;
    cin >> R;
    cout << R*2*3.14159 << endl;
    return 0;
}


Measured memory_bytes: 3788
#include "bits/stdc++.h"
using namespace std;
 
int main() {
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> count(n, -q+k-1);
    for(int i = 0; i < q; i++){
        int t;
        cin >> t;
        t--;
        count[t]++;
    }
    for(int i = 0; i < n; i++){
        cout << (count[i] >= 0 ? "Yes" : "No") << endl;
    }
}

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

bool check(vector<pair<ll, ll>> s){
    ll h = 0;
    for (auto p : s){
        ll b = h + p.first;
        if (b < 0) return false;
        h += p.second;
    }
    return true;
}

int main() {
    ll N, sum = 0;
    cin >> N;
    vector<pair<ll, ll>> up, down;
    rep(i, N) {
        string s;
        cin >> s;
        int n = s.size();
        int mini = 0;
        int diff = 0;
        for (int j = 0; j < n; j++) {
            if (s[j] == '(') {
                diff++;
            } else {
                diff--;
            }
            mini = min(mini, diff);
        }
        if (diff > 0) {
            up.emplace_back(mini, diff);
        } else {
            down.emplace_back(mini-diff, -diff);
        }
        sum += diff;
    }
    sort(up.rbegin(), up.rend());
    sort(down.rbegin(), down.rend());
    puts(check(up) && check(down) && sum == 0 ? "Yes" : "No");
}

Measured memory_bytes: 34588
def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    violate = []
    for _ in range(M):
        A, B = map(int, input().split())
        A -= 1
        B -= 1
        if H[A] == H[B]:
            violate.append(A)
            violate.append(B)
        elif H[A] - H[B] < 0:
            violate.append(A)
        elif H[B] - H[A] < 0:
            violate.append(B)
    violate = list(set(violate))
    num = N - len(violate)
    print(num)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 91968
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T>
    inline std::vector<T> read(std::size_t n)
    {
        std::vector<T> res;
        res.reserve(n);

        for (std::size_t i = 0; i < n; ++i) {
            T tmp;
            cin >> tmp;
            res.emplace_back(tmp);
        }
        return res;
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    template <bool nl>
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { final(); }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
        template <bool f = nl>
        auto final() -> std::enable_if_t<f> { cout << '\n'; }
        template <bool f = nl>
        auto final() -> std::enable_if_t<!f> {}
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy<true> operator,(T&& val)
    {
        cout << val;
        return {};
    }
    proxy<false> noreturn() { return {}; }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
            }
            cout << x;
            first = false;
        }
    }
};

void prog()
{
    input in;
    output out;

    int n, k;
    std::string s;
    in >> n, k, s;
    s[k - 1] -= 'A' - 'a';
    out, s;
}

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


Measured memory_bytes: 256
def main():
    N = input()
    if N[-1] == '3':
        print('bon')
    elif N[-1] == '0' or N[-1] == '1' or N[-1] == '6' or N[-1] == '8':
        print('pon')
    else:
        print('hon')

if __name__ == '__main__':
    main()

Measured memory_bytes: 8988
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;

lint ans(lint x,lint y){
  if(x<0) return 0;
  else return x/y+1;
}
 
int main(void){
  lint a,b,x;
  cin >> a >> b >> x;
  a--;
  cout << ans(b,x)-ans(a,x) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define ld long double
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;


const int mod = 100000007;
const int inf = 100000005;
const int N = 3e5, M = N;
ll i,j,n,m;

void solve() {
  ll n;

  cin>>n;
  ll ans = 0;
  vi vec(n+1);

  fo(i,1,n+1) {
    for(int j=0;j<=n;j+=i) vec[j]++;
  }
  fo(i,1,n+1) {
    ans+=(i*vec[i]);
  }
  cout<<ans<<"\n";
}


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}




Measured memory_bytes: 42248
function Main(input){
	input = input.split("\n").map((a)=>~~a);
  var highest = -1;
  var price = 0;
  for(var i = 1; i < input.length;i++){
  	price += input[i];
    if(highest < input[i]){
    	highest = input[i];
    }
  }
  price -= highest / 2;
  return ~~price;
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
4
4320
4320
4320
4320
`);

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

int main()
{
    int n;
    std::cin >> n;
    if (n % 2 == 0)
        std::cout << 0.5 << std::endl;
    else {
        float a = n / 2 + 1;
        std::cout << a / n << std::endl;
    }


    return 0;
}


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

using namespace std;

char c[567890];
int a[567890], dp[567890];
int n;

int main() 
{
	scanf("%d%s", &n, c+1);
	
	for (int i=1;i<=n;++i) 
	{
		if (c[i]=='0') a[i]=i;
		else a[i]=a[i-1];
	}
	
	for (int i=1;i<=n;++i) 
	{
		dp[i] = dp[i-1];
		if (c[i]=='1') 
		{
			if (c[i-1]=='0'&&c[i-2]=='1') 
			{
				dp[i]=max(dp[i],dp[a[i-2]]+(i-2)-a[i-2]);
				dp[i]=max(dp[i],dp[a[i-2]+1]+(i-2)-(a[i-2]+1));
			}
			else if (a[i]>1&&c[a[i]-1]=='1') dp[i]=max(dp[i],dp[a[i]-2]+i-a[i]);
		}
	}
	
	cout<<dp[n];
	
	return 0;
}

Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007ll
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std; 
ll gcdExtended(ll a, ll b, ll *x, ll *y); 
  
// Function to find modulo inverse of a 
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1) 
        cout << "Inverse doesn't exist"; 
    else
    { 
        // m is added to handle negative x 
        ll res = (x%m + m) % m; 
        return  res; 
    } 
} 
  
// C function for extended Euclidean Algorithm 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    // Base Case 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; // To store results of recursive call 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    // Update x and y using results of recursive 
    // call 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
                // equal to p 
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
ll nCr(ll n,ll r,ll m)
{
    ll res = 1;
    for (ll i = 1; i <= r; ++i)
    {
        res = (res*(n-i+1)%MOD)*modInverse(i,MOD);
        res%=MOD;
    }
    return res;
}
void showdq(deque <char> g,int r) 
{
	if(r==0)
	{
		deque <char> :: iterator it; 
		for (it = g.begin(); it != g.end(); ++it) 
		    cout << *it; 
		cout << '\n';	
	}
	else
	{
		deque <char> :: iterator it;
		it=g.end(); 
		it--;
		for (; it != g.begin(); --it) 
		    cout  << *it; 
		cout<<*it;
		cout << '\n';
	} 
     
} 
int main()
{
    deque <char> dq; 
    string s;
    cin>>s;
    for(ll i=0;i<s.size();i++)
    {
    	dq.pb(s[i]);
    }
    ll q;
    cin>>q;
    int r=0;
    for(ll i=0;i<q;i++)
    {
    	ll dec;
    	cin>>dec;
    	if(dec==1)
    		r=(r+1)%2;
    	else
    	{
    		ll pos;
    		cin>>pos;
    		char ch;
    		cin>>ch;
    		if((r+pos)%2==0)
    			dq.pb(ch);
    		else
    			dq.push_front(ch);
    	}
    }
    showdq(dq,r);

}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n,k;
    cin>>n>>k;
    
    vector<vector<int>> B(2001,vector<int>(2001,0));
    vector<vector<int>> W(2001,vector<int>(2001,0));
    
    int h = 2*k;
    int w = 2*k;
    rep(i,n){
        int x,y;
        char ch;
        cin>>x>>y>>ch;
        
        if(ch=='B'){
            B[y%h][x%w] += 1;
        }else{
            W[y%h][x%w] += 1;
        }
    }
    
    
    auto f = [&](const vector<vector<int>> &v){
        vector<vector<int>> dp(h,vector<int>(w,0));
        rep(i,h){
            rep(j,w){
                if(i-1>=0)dp[i][j] += dp[i-1][j];
                if(j-1>=0)dp[i][j] += dp[i][j-1];
                if(i-1>=0&&j-1>=0)dp[i][j] -= dp[i-1][j-1];
                dp[i][j] += v[i][j];
            }
        }
        
        return dp;
    };
    
    
    vector<vector<int>> bb = f(B);
    vector<vector<int>> ww = f(W);
    
    auto g = [&](int y,int x,int yy,int xx, vector<vector<int>> &dp){
        if(yy-1<0||xx-1<0)return 0;
        xx = min(xx,w);
        yy = min(yy,h);
        x = max(0,min(x,w));
        y = max(0,min(y,h));
        int ret = dp[yy-1][xx-1];
        if(y-1>=0)ret-=dp[y-1][xx-1];
        if(x-1>=0)ret-=dp[yy-1][x-1];
        if(y-1>=0&&x-1>=0)ret+=dp[y-1][x-1];
        
        return ret;
    };
    
    int maxi = 0;
    rep(i,k){
        rep(j,k){
            int sum1 = 0, sum2 = 0;
            
            sum1 += g(0,0,i,j,bb) + g(0,j+k,i,w,bb) + g(i+k,0,h,j,bb) + g(i,j,i+k,j+k,bb) + g(i+k,j+k,h,w,bb);
            sum1 += g(0,j,i,j+k,ww) + g(i,0,i+k,j,ww) + g(i,j+k,i+k,w,ww) + g(i+k,j,h,j+k,ww);
            
            sum2 += g(0,0,i,j,ww) + g(0,j+k,i,w,ww) + g(i+k,0,h,j,ww) + g(i,j,i+k,j+k,ww) + g(i+k,j+k,h,w,ww);
            sum2 += g(0,j,i,j+k,bb) + g(i,0,i+k,j,bb) + g(i,j+k,i+k,w,bb) + g(i+k,j,h,j+k,bb);
            maxi = max(maxi,max(sum1,sum2));
        }
    }
    cout<<maxi<<endl;
    
}


Measured memory_bytes: 63104
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll w,h,x,y;
    cin>>w>>h>>x>>y;
    int ok=0;
    if(w%2==0&&h%2==0&&x==w/2&&y==h/2) ok=1;
    cout<<FS<<(double)h*w/2<<' '<<ok<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,m,c,s[20],ans,a;
int main(void){
    cin>>n>>m>>c;
    for(int i=0;i<m;i++){
        cin>>s[i];
    }
    for(int i=0;i<n;i++){
        int A=0;
        for(int j=0;j<m;j++){
            cin>>a;
            A+=a*s[j];
        }
        if(A+c>0)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    string S, T; cin >> S >> T;
    int N = S.size();

    bool ok = true;
    set<char> from, to;
    set<pair<char, char>> conv;
    REP(i,N) {
        if (conv.count(pair<char, char>(S[i], T[i])) > 0) continue;

        if (from.count(S[i])>0 || to.count(T[i])>0) {
            ok = false;
            break;
        }
        from.insert(S[i]);
        to.insert(T[i]);
        conv.insert(pair<char, char>(S[i], T[i]));
        conv.insert(pair<char, char>(T[i], S[i]));
    }

    string ans = ok ? "Yes" : "No";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
vector<ll> V;
int pre[maxn];
int main() {
    ll n;cin>>n;
    ll now=100;
    for(int i=1;;i++){
        if(now>=n) {cout<<i-1<<endl;return 0;}
        now+=now/100;
    }
    return 0;
}

Measured memory_bytes: 3600
#include <stdio.h>

int main(){
  int i,n;

  scanf("%d",&n);
  int H[n];

  for(i=1;i<=n;i++)
    scanf("%d",&H[i]);

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,H[i]);
    if(i != 1)
      printf("parent key = %d, ",H[i/2]);
    if(i*2 <= n)
      printf("left key = %d, ",H[i*2]);
    if((i*2)+1 <= n)
      printf("right key = %d, ",H[(i*2)+1]);
    printf("\n");
  }

  return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	vector<llong> A,B;

	cin >> N;
	A.resize(N);
	B.resize(N);
	for(int i = 0; i < N; i++)
		cin >> A[i];
	for(int i = 0; i < N; i++)
		cin >> B[i];

	if(N == 1){
		if(A[0] == B[0])
			cout << 1 << endl;
		else
			cout << 0 << endl;
	}else{
		llong ans = 1;
		vector<llong> Mt(N,-1);
		for(int i = 0; i < N; i++){
			if(i == 0 || A[i] != A[i-1])
				Mt[i] = A[i];
		}
		for(int i = N-1; i >= 0; i--){
			if(i == N-1){
				if(Mt[i] == -1)
					Mt[i] = B[i];
				else if(Mt[i] != B[i]){
					ans = 0;
					break;
				}
			}else{
				if(Mt[i] == -1){
					if(B[i] != B[i+1])
						Mt[i] = B[i];
				}else if(Mt[i] > B[i]){
					ans = 0;
				}
			}
		}

		for(auto x : Mt)
			cerr << x << " ";
		cerr << endl;

		for(int i = 0; i < N; i++){
			if(Mt[i] != -1)
				continue;

			ans *= min(A[i], B[i]);
			ans %= mod;
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 2560
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                ans += 1

print(ans)


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

int main() {
  int n,a,b;
  cin>>n>>a>>b;
  if(a%n==0||b%n==0){
     cout<<"OK"<<endl;
  }
  else if((a/n)*n+n<=b){
    cout<<"OK"<<endl;
  }else{
    cout<<"NG"<<endl;
  }
}

Measured memory_bytes: 3624
#include<stdio.h>
int main(){
int a, b, r, i;
char n;
for(i=0; ;i++){
scanf("%d %c %d", &a, &n, &b); 
if(n!='?'){
if (n=='+'){ 
r=a+b;}
else{
	if(n=='-'){
	r=a-b;}
	else{
		if(n=='*'){
		r=a*b;}
		else{
		r=a/b;}
	}
}
}
else break;
printf("%d\n", r);
}
return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 3005

ll P;
ll A[SIZE],B[SIZE];
ll nCm[SIZE][SIZE];

ll mod_pow(ll x,ll count, ll mod){

	if(count == 0)return 1;
	ll ret = mod_pow((x*x)%mod,count/2,mod);
	if(count%2 == 1){

		ret = (ret*x)%mod;
	}
	return ret;
}


int main(){

	scanf("%lld",&P);

	for(ll i = 0; i < P; i++){

		scanf("%lld",&A[i]);
	}

	//コンビネーションを求める
	nCm[0][0] = 1;
	for(ll n = 1; n <= 3000; n++) {
		for (int m = 0; m <= n; m++) {
			if(m > 0){
				nCm[n][m] = nCm[n-1][m]+nCm[n-1][m-1];
			}else{ //m == 0
				nCm[n][m] = 1;
			}
			nCm[n][m] %= P;
		}
	}

	for(int i = 0; i < P; i++){

		B[i] = 0;
	}

	for(ll i = 0; i < P; i++){
		if(A[i] == 1){

			B[0] += 1;
			B[0] %= P;
			ll pw = 1;
			for(ll k = P-1; k >= 0; k--){
				B[k] -= (pw*nCm[P-1][k])%P;
				if(B[k] < 0){

					B[k] += P;
				}else{

					B[k] %= P;
				}
				pw *= (-i+P)%P;
				pw %= P;
			}
		}
	}

	printf("%lld",B[0]);

	for(ll i = 1; i < P; i++){

		printf(" %lld",B[i]);
	}
	printf("\n");


	return 0;
}


Measured memory_bytes: 69120
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<pair<int, int>> a;
    rep(i, N) {
        int t; cin >> t;
        a.push_back({t, i + 1});
    }
    sort(a.begin(), a.end());
    vector<int> ans;
    int lastused = -1;
    int prev = -1;
    rep(i, K + 1) {
        for(int j = N - 1; j >= 0; j--) {
            if(a[j].second == prev) continue;
            ans.push_back(a[j].second);
            a[j].first--;
            if(a[j].first < 0) {
                cout << -1 << endl;
                return 0;
            }
            lastused = a[j].second;
        }
        prev = lastused;
        sort(a.begin(), a.end());
        //rep(j, N) cout << a[j].first << " ";
        //cout << endl;
    }
    cout << ans.size() << endl;
    rep(i, ans.size()) {
        if (i != 0) cout << " ";
        cout << ans[i];
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 256
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include <queue>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	int A=a/2,B=b/2;
	if(a<=2){cout<<"1"<<endl;return 0;}
	if(a%2){A++;B++;}/*
	for(int y=1;y<=a;y++){
		for(int x=1;x<=a;x++){
			int ans=1;
		
		if(x<A){
		
		if(x<=y&&a-x+1>=y){
			ans=x%3;if(ans==0)ans=3;}
		else {
			ans=x%3;if(ans==0)ans=3;
			if(y<x)ans=y%3;
			else ans=(a-y+1)%3;
			
		}
		}
		else{
			if(x>=y&&a-x+1<=y){
			ans=(a-x+1)%3;if(ans==0)ans=3;
			
			}

		else {ans=9;
		
		if(y<x)ans=y%3;
			else ans=(a-y+1)%3;
		
		/*
			ans=(a-x+1)%3;if(ans==0)ans=3;
			if(y<A)ans-=(x-y)%3;
			else ans-=(abs(a-y))%3;
			
		}

		}
		if(ans==-1)ans=2;
		if(ans==0)ans=3;
		cout<<ans;}
		cout<<endl;
	}


	*/
	
	while(b--){
		int ans=1;
		int x,y;cin>>x>>y;
		if(x<A){
		
		if(x<=y&&a-x+1>=y){
			ans=x%3;if(ans==0)ans=3;}
		else {
			ans=x%3;if(ans==0)ans=3;
			if(y<x)ans=y%3;
			else ans=(a-y+1)%3;
			
		}
		}
		else{
			if(x>=y&&a-x+1<=y){
			ans=(a-x+1)%3;if(ans==0)ans=3;
			
			}

		else {ans=9;
		
		if(y<x)ans=y%3;
			else ans=(a-y+1)%3;
		

		}
		}
		if(ans==-1)ans=2;
		if(ans==0)ans=3;
		cout<<ans<<endl;}


	return 0;

		
		/*
		if(a<=2)cout<<"1"<<endl;
		else{
			if(x<A&&y<A){
				ans=x%3;if(!ans)ans=3;
				if(y<x){
					ans-=(x-y)%3;
					ans%=3;if(!ans)ans=3;}
				////else {
				//	ans=x%3;}
			}
			else if(x<A&&y>=A){ans=x%3;if(!ans)ans=3;
				if(y>a-x+1)ans-=(y-x+1)%3;
					}
			else if(x>=A&&y<A){
				ans=(a-x+1)%3;if(!ans)ans=3;
				if(y<a-x+1){
					ans-=(a-x-y+1)%3;
				}
			}
			else{
				ans=(a-x+1)%3;if(!ans)ans=3;
				if(y>x)ans-=(y-x)%3;
			}
			cout<<ans<<endl;
		}
		
	}
	*/
return 0;
}



				

Measured memory_bytes: 1160
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;

typedef long long LL;

int cnt;
LL n;

deque <int> Q;

void Build(LL N)
{
	if (N == 1) return;
	if (N & 1)
	{
		Build(N - 1);
		Q.push_front(++cnt);
	}
	else
	{
		Build(N >> 1LL);
		Q.push_back(++cnt);
	}
}

int main()
{
	#ifdef DMC
		freopen("DMC.txt","r",stdin);
	#endif
	
	cin >> n; Build(n + 1); cout << (cnt << 1) << endl;
	while (!Q.empty()) printf("%d ",Q.front()),Q.pop_front();
	for (int i = 1; i < cnt; i++) printf("%d ",i); cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int i, l;
  int n[26];
  char w[101];

  for (i = 0; i < 26; i++) {
    n[i] = 0;
  }

  scanf("%s%n", w, &l);

  for (i = 0; i < l; i++) {
    n[w[i] - 'a']++;
  }

  for (i = 0; i < 26; i++) {
    if (n[i] % 2 == 1) {
      printf("No\n");
      break;
    }
  }

  if (i == 26) {
    printf("Yes\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=3005;
int num,head[maxn],t[maxn<<1],ne[maxn<<1];
inline void addedge(int x,int y){
	ne[++num]=head[x];head[x]=num;t[num]=y;
	ne[++num]=head[y];head[y]=num;t[num]=x;
}
bool del[maxn];
int f[maxn][maxn];
int tmp[maxn],size[maxn];
typedef pair<pin,pin> info;
int n,k;
const int inf=1<<29;int res=inf;
/*
inline void merge(info &a,info b){
	if(b.w1>a.w1){
		a.w2=a.w1;a.w1=b.w1;
	}else if (b.w1>a.w2){
		a.w2=b.w1;
	}
}
inline info calc(int x,int f){
	info res=mk(mk(0,x),mk(0,x));
	forE(i,x)if(t[i]!=f){
		if(del[t[i]])continue;
		info tmp=calc(t[i],x);
		tmp.w1.w1++;tmp.w2.w1++;
		merge(res,tmp);
	}return res;
}
*/
inline void dfs(int x,int fa){
	f[x][0]=0;size[x]=1;
	forE(i,x)if(t[i]!=fa){
		dfs(t[i],x);
		rep(a,0,size[x]+size[t[i]])tmp[a]=inf;
		rep(a,0,size[x])if(a<=k)tmp[a]=min(tmp[a],f[x][a]+size[t[i]]);
		rep(a,0,size[x])rep(b,0,size[t[i]])if(a+b+1<=k)
			tmp[max(a,b+1)]=min(tmp[max(a,b+1)],f[x][a]+f[t[i]][b]);
		rep(a,0,size[x]+size[t[i]])f[x][a]=tmp[a];
		size[x]+=size[t[i]];
	}
}
int main(){
//	judge();
	read(n);read(k);
	rep(i,1,n)head[i]=-1;
	rep(i,1,n-1){
		int x,y;read(x);read(y);addedge(x,y);
	}dfs(1,-1);
	rep(i,1,n)rep(j,0,size[i])res=min(res,size[1]-size[i]+f[i][j]);
	cout<<res;
	cerr<<"ok";
	return 0;
}


Measured memory_bytes: 13568
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))

from fractions import gcd
r = []
l = []
r.append(a[-1])

l.append(a[0])

for i in range(1,n):
    l.append(gcd(l[i-1],a[i]))
    r.append(gcd(r[i-1],a[(n-1)-i]))

l.insert(0,a[-1])
r.insert(0,a[0])


def solve(num):
    ans = gcd(l[num],r[n-1-num])
    return ans

can = []
for i in range(n):
    can.append(solve(i))

print(max(can))

Measured memory_bytes: 98152
List = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

ans = [[0,0,0] for i in range(3)]
ans1 = [[0,0,0] for i in range(3)]

res = False

for i in range(n):
    for a in range(3):
        for c in range(3):
            if b[i] == List[a][c]:
                ans[a][c] = 1
                ans1[c][a] = 1

if ans[1][1] == 1:
    if ans[0][0] > 0 and ans[2][2] > 0:
        res = True
    if ans[2][0] > 0 and ans[0][2] > 0:
        res = True
                
for i in range(3):
    if ans[i][0] > 0 and ans[i][1] > 0 and ans[i][2] > 0:
        res = True
    if ans1[i][0] > 0 and ans1[i][1] > 0 and ans1[i][2] > 0:
        res = True
            
if res:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons;

void main()
{
    auto N = readln.chomp.to!int;

    long s;
    bool neq;
    long[] AS, BS;
    foreach (_; 0..N) {
        auto ab = readln.split.to!(long[]);
        auto A = ab[0];
        auto B = ab[1];
        s += A;
        if (A >= B) {
            AS ~= A;
            BS ~= B;
        } else {
            neq = true;
        }
    }
    if (!neq) {
        writeln(0);
        return;
    }
    long min_b = long.max;
    foreach (i; 0..AS.length) {
        if (AS[i] != BS[i] && BS[i] < min_b) min_b = BS[i];
    }
    writeln(s - min_b);
}

Measured memory_bytes: 4424
#include <bits/stdc++.h>
#pragma GCC optimize(3)
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <int, int> pii;
typedef pair <int, pii> piii;

struct Segment_tree{
	int T[2000010];
	void pushdown(int now){
		if (T[now] == -1) return ;
		T[now << 1] = T[now << 1 | 1] = T[now];
		T[now] = -1;
	}
	void Build(int now, int l, int r){
		memset(T, -1, sizeof(T));
	}
	void Update(int now, int l, int r, int L, int R, int x){
		if (l == L && r == R){
			T[now] = x;
			return ;
		}
		pushdown(now);
		int mid = l + r >> 1;
		if (R <= mid) Update(now << 1, l, mid, L, R, x);
		else if (L > mid) Update(now << 1 | 1, mid + 1, r, L, R, x);
		else Update(now << 1, l, mid, L, mid, x), Update(now << 1 | 1, mid + 1, r, mid + 1, R, x);
	}
	int Query(int now, int l, int r, int pos){
		if (T[now] != -1) return T[now];
		if (l == r) return T[now];
		int mid = l + r >> 1;
		if (pos <= mid) return Query(now << 1, l, mid, pos);
		return Query(now << 1 | 1, mid + 1, r, pos);
	}
}seg;

int read(){
	char c = getchar();
	while (!isdigit(c)) c = getchar();
	int x = c ^ '0'; c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	return x;
}

vector <piii> v;
vector <int> all;

int main(){
	int n = read(), q = read();
	for (int i = 0; i < n; i++){
		int s = read(), t = read(), x = read();
		s -= x, t -= x;
		v.push_back(mp(-x, mp(s, t)));
		all.push_back(s), all.push_back(t);
	}
	sort(all.begin(), all.end()), all.resize(unique(all.begin(), all.end()) - all.begin());
	sort(v.begin(), v.end());
	seg.Build(1, 0, all.size() - 1);
	for (int i = 0; i < v.size(); i++){
		int l = v[i].se.fi, r = v[i].se.se, x = -v[i].fi;
		l = lower_bound(all.begin(), all.end(), l) - all.begin();
		r = lower_bound(all.begin(), all.end(), r) - all.begin();
		seg.Update(1, 0, all.size() - 1, l, r - 1, x);
	}
	while (q--){
		int x = read();
		x = upper_bound(all.begin(), all.end(), x) - all.begin() - 1;
		printf("%d\n", x < 0 ? -1 : seg.Query(1, 0, all.size() - 1, x));
	}
	return 0;
}


Measured memory_bytes: 13860
//om nama sivaya
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define maxn 100001
#define pb push_back
using namespace std;
void solve(){
    int n,c=0;
    cin>>n;
    string s;
    cin>>s;
    int i=0,j=n-1;
    while(i<j){
        while(s[i]=='R' && i<n)i++;
        while(s[j]=='W' && j>=0)j--;
        if(i<j){
        swap(s[i],s[j]);
        i++;j--;c++;}
    }
    cout<<c;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tt=1;
    //cin>>tt;
    while(tt--){
        solve();
    }
}


Measured memory_bytes: 3732
#include<cstdio>

bool solve(){
	int n,ma = 0,mi = 1000,sum = 0;
	scanf("%d",&n);
	if(n==0) return false;
	for(int i=0;i<n;i++){
		int s;
		scanf("%d",&s);
		if(s<mi) mi = s;
		if(s>ma) ma = s;
		sum += s;
	}
	printf("%d\n",(sum-ma-mi)/(n-2));
	return true;
}

int main(){
	while(solve()){}
}

Measured memory_bytes: 2668
import java.util.*;

public class Main{          
    
    private static int N;
    private static int Ma;
    private static int Mb;
    private static final int INF = 100000;    
           
      public static void main(String[] args) {          
          
        Scanner sc = new Scanner(System.in);
      
        N = sc.nextInt();
        Ma = sc.nextInt();
        Mb = sc.nextInt();
        
        int a[] = new int[N];
        int b[] = new int[N];
        int c[] = new int[N];
        
        for(int i = 0;i < N;i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            c[i] = sc.nextInt();            
        }
        
        int dp[][][] = new int[N+1][401][401];
        
        for(int i = 0;i < N+1;i++){
            for(int j = 0;j < 401;j++){
               for(int k = 0;k < 401;k++){
                   dp[i][j][k] = INF;
               }   
            }            
        }
        
        dp[0][0][0] = 0;
        
        for (int i = 0; i < N; i++) {
	    for (int ca = 0; ca < 401; ca++) {
		for (int cb = 0; cb < 401; cb++) {
		    dp[i+1][ca][cb] = Math.min(dp[i+1][ca][cb], dp[i][ca][cb]);
		    if(ca+a[i] < 401 && cb+b[i] < 401) {
			dp[i+1][ca+a[i]][cb+b[i]] = Math.min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
		    }
		}
	    }
	}

	int min = INF;
        
        
	for (int ca = 0; ca < 401; ca++) {
	    for (int cb = 0; cb < 401; cb++) {
		if(ca == 0 && cb == 0) continue;
		if(match(ca, cb) && dp[N][ca][cb] < min) min = dp[N][ca][cb];
	    }
	}

        
	System.out.println(min == INF ? -1 : min);
              
    }     
      
    private static boolean match(int ma, int mb) {
	return (ma * Mb == mb * Ma);
    } 
      
}       


Measured memory_bytes: 54484
n = int(input())
adj = [list(map(int, input().split()))[2:] for _ in range(n)]

d = [-1] * n

s = 1
q = []
d[s - 1] = 0
q.append(s)
while len(q):
    u = q.pop()
    v = adj[u - 1]
    for vi in v:
        if d[vi - 1] == -1:
            d[vi - 1] = d[u - 1] + 1         
            q.append(vi)
        elif d[vi - 1] > d[u - 1] + 1:
            d[vi - 1] = d[u - 1] + 1            
            q.append(vi)

for i, di in enumerate(d):
    print(i + 1, di)

Measured memory_bytes: 6728
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] n = new int[3];
    for (int i = 0; i < 3; i++) {
      n[i] = sc.nextInt();
    }
    Arrays.sort(n);
    int total = 0;
	total += n[2] - n[1];
    total += n[1] - n[0];
    System.out.println(total);
  }
}

Measured memory_bytes: 21844
N, K = map(int, input().split())
d = []
A = []
for i in range(K):
    d.append(int(input()))
    A.append(list(map(int, input().split())))

lis = []

for i in A:
    for j in i:
        if j in lis:
            continue
        else:
            lis.append(j)
print(N-len(lis))


Measured memory_bytes: 9116
#include<bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using it=std::int64_t;

it gcd(it x,it y){
    if(y==0) return x;
    else return gcd(y,x%y);
}

int main(){
    it N,X;
    cin>>N>>X;
    std::vector<it> x(N);
    for(it i=0;i<N;i++){
        cin>>x[i];
    }
    
    it g;
    for(it i=0;i<N;i++){
        if(i==0) g=abs(X-x[0]);
        else g=gcd(g,abs(X-x[i]));
    }
    
    cout<<g<<endl;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] v = new int[n];
		for (int i = 0; i < n; i++) {
			v[i] = sc.nextInt();
		}
		sc.close();

		Map<Integer, Obj> map1 = new HashMap<>();
		Map<Integer, Obj> map2 = new HashMap<>();
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0) {
				addMap(map1, v[i]);
			} else {
				addMap(map2, v[i]);
			}
		}

		Obj[] arr1 = getArr(map1);
		Obj[] arr2 = getArr(map2);
		if (arr1[0].v != arr2[0].v) {
			System.out.println(n - arr1[0].cnt - arr2[0].cnt);
		} else {
			if (arr1.length == 1) {
				if (arr2.length == 1) {
					System.out.println(n / 2);
				} else {
					System.out.println(n - arr1[0].cnt - arr2[1].cnt);
				}
			} else {
				if (arr2.length == 1) {
					System.out.println(n - arr1[1].cnt - arr2[0].cnt);
				} else {
					int max = Math.max(arr1[0].cnt + arr2[1].cnt, arr1[1].cnt + arr2[0].cnt);
					System.out.println(n - max);
				}
			}
		}
	}

	static class Obj {
		int v, cnt;
	}

	static Obj[] getArr(Map<Integer, Obj> map) {
		Obj[] arr = map.values().toArray(new Obj[0]);
		Arrays.sort(arr, (o1, o2) -> o2.cnt - o1.cnt);
		return arr;
	}

	static void addMap(Map<Integer, Obj> map, Integer key) {
		if (map.containsKey(key)) {
			map.get(key).cnt++;
		} else {
			Obj o = new Obj();
			o.v = key;
			o.cnt = 1;
			map.put(key, o);
		}
	}
}


Measured memory_bytes: 55604
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N, Ma, Mb;
  cin >> N >> Ma >> Mb;
  vector<int> a(N), b(N), c(N);
  rep(i, N) cin >> a[i] >> b[i] >> c[i];
  vector<vector<vector<int>>> cost(
      N + 1, vector<vector<int>>(401, vector<int>(401, INF)));
  cost[0][0][0] = 0;
  rep(n, N) {
    rep(i, 400) {
      rep(j, 400) {
        if (cost[n][i][j] == INF)
          continue;

        // not use
        chmin(cost[n + 1][i][j], cost[n][i][j]);

        // use
        if (i + a[n] > 400 || j + b[n] > 400)
          continue;
        chmin(cost[n + 1][i + a[n]][j + b[n]], cost[n][i][j] + c[n]);
      }
    }
  }

  int ans = INF;
  repp(i, 1, 400) {
    repp(j, 1, 400) {
      if (abs(((double)i / (double)j) - ((double)Ma / (double)Mb)) < 1e-5)
        chmin(ans, cost[N][i][j]);
    }
  }
  if (ans == INF)
    ans = -1;

  cout << ans << endl;
}

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

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ms(a, b) memset((a), (b), sizeof(a))
#define len(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define lb lower_bound
#define ub upper_bound
#define fore(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <class T> void __f(const char* name, T&& a) {
    cerr << name << ": " << a << '\n';
}
template <class T, class... Ts> void __f(const char* names, T&& a, Ts&&... b) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << a << " /";
    __f(comma + 1, b...);
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T> bool mini(T& a, const T& b) { return a > b ? (a = b, 1) : 0; }
template <class T> bool maxi(T& a, const T& b) { return a < b ? (a = b, 1) : 0; }

typedef long long ll;
typedef double db;
typedef pair<int, int> pi;
typedef pair<int, pi> ti;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ti> vti;
typedef vector<vpi> vvpi;

const int inf = (int)0x3f3f3f3f3f3f3f3f;
const int ninf = (int)0xc0c0c0c0c0c0c0c0;
const int M = (int)1e9 + 7;
const int N = 1e7 + 3;

int n, ans, cnt[N], pw[N], f[N];
bool p[N];
vi pr;

void sieve() {
    f[1] = 1;
    fore(i, 2, N) {
        if (!p[i]) {
            pr.pb(i);
            cnt[i] = 1;
            pw[i] = i;
            f[i] = 2;
        }
        for (int j = 0; i * pr[j] < N; ++j) {
            p[i * pr[j]] = 1;
            if (i % pr[j] == 0) {
                cnt[i * pr[j]] = cnt[i] + 1;
                pw[i * pr[j]] = pw[i] * pr[j];
                f[i * pr[j]] = f[i * pr[j] / pw[i * pr[j]]] * (cnt[i * pr[j]] + 1);
                break;
            } else {
                cnt[i * pr[j]] = 1;
                pw[i * pr[j]] = pr[j];
                f[i * pr[j]] = f[i] * 2;
            }
        }
    }
}

main() {
//    freopen("CP.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    sieve();
    cin >> n;
    fort(i, 1, n) ans += f[i] * i;
    cout << ans << '\n';
}


Measured memory_bytes: 255784