akhauriyash/Code-Regression huggingface dataset:
use std::cmp;

const INF: i64 = 1e17 as i64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let a: Vec<i64> = sc.read_vec(n);
    let mut graph = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let v = sc.read::<usize>() - 1;
        let u = sc.read::<usize>() - 1;
        graph[v].push(u);
        graph[u].push(v);
    }

    let mut dp1 = vec![vec![]; n];
    let mut dp2 = vec![vec![]; n];
    dfs(0, 0, &graph, &a, &mut dp1, &mut dp2);

    for i in 1..(n + 1) {
        if dp1[0][i] < INF {
            println!("{}", i - 1);
            return;
        }
        if dp2[0][i] < 0 {
            println!("{}", i - 1);
            return;
        }
    }
}

fn dfs(
    v: usize,
    p: usize,
    graph: &Vec<Vec<usize>>,
    a: &Vec<i64>,
    dp1: &mut Vec<Vec<i64>>,
    dp2: &mut Vec<Vec<i64>>,
) {
    dp1[v].push(INF);
    dp1[v].push(if a[v] > 0 { a[v] } else { INF });
    dp2[v].push(INF);
    dp2[v].push(a[v]);
    for &next in graph[v].iter() {
        if next == p { continue; }
        dfs(next, v, graph, a, dp1, dp2);

        dp1[v] = connect(&dp1[v], &dp1[next], &dp2[next], true);
        dp2[v] = connect(&dp2[v], &dp1[next], &dp2[next], false);
    }
}

fn connect(dp: &Vec<i64>, child1: &Vec<i64>, child2: &Vec<i64>, power_only: bool) -> Vec<i64> {
    let mut ans = vec![INF; dp.len() + child1.len() - 1];
    assert_eq!(dp[0], INF);
    assert_eq!(child1[0], INF);
    assert_eq!(child2[0], INF);
    for groups in 1..dp.len() {
        if dp[groups] == INF { continue; }
        for child_groups in 0..child1.len() {
            let total_groups = groups + child_groups;

            if child1[child_groups] != INF {
                ch_min(&mut ans[total_groups - 1], dp[groups] + child1[child_groups]);
            }
            if child2[child_groups] != INF && !power_only {
                ch_min(&mut ans[total_groups - 1], dp[groups] + child2[child_groups]);
            }
            if child1[child_groups] != INF || child2[child_groups] < 0 {
                ch_min(&mut ans[total_groups], dp[groups]);
            }
        }
    }
    ans
}

fn ch_min<T: PartialOrd>(a: &mut T, b: T) {
    if *a > b {
        *a = b;
    }
}

pub struct Scanner<R> {
    reader: 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
            .reader
            .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 read_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: 211836
#include <bits/stdc++.h>
using namespace std;
using  unll = unsigned long long;

int main() {
  unll n,k;
  cin >> n >> k;
  unll ans=1;
  for(int i=0;i<n;i++){
    if( i == 0 ){
      ans *= k;
    }else{
      ans *= k-1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
#define pln(x) cout << (x) << endl
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename Iter> ostream& out_container(ostream &os, Iter first, Iter last){
  os << "{"; auto itr = first; while(itr != last){if(itr != first) os << ","; os << *itr; ++itr;} os << "}"; return os;
}

template <typename T> ostream& operator<<(ostream &os, const vector<T> &c){return out_container(os,ALL(c));}
template <typename T> ostream& operator<<(ostream &os, const deque<T> &c){return out_container(os,ALL(c));}
template <typename T> ostream& operator<<(ostream &os, const set<T> &c){return out_container(os,ALL(c));}
template <typename T> ostream& operator<<(ostream &os, const unordered_set<T> &c){return out_container(os,ALL(c));}
template <typename T, typename U> ostream& operator<<(ostream &os, const map<T,U> &c){return out_container(os,ALL(c));}
template <typename T, typename U> ostream& operator<<(ostream &os, const unordered_map<T,U> &c){return out_container(os,ALL(c));}
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

LLI f(LLI n){
  if(n%2==0) return n/2;
  else return n*3+1;
}

int rec(int m, LLI prev, unordered_set<LLI> &s){
  LLI t = f(prev);
  if(EXIST(s,t)){
    return m;
  }

  s.insert(t);

  return rec(m+1,t,s);
}


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

  int s;
  while(cin >> s){
    unordered_set<LLI> st;
    st.insert(s);
    int ans = rec(2,s,st);
    pln(ans);
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    cout << (n + 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;
const int inf = 1001001001;

ll KnapsackProblem01(int N, int W, vector<ll> v, vector<ll> w) {
	vector<ll> dp(W + 1, 0);
	for (int i = 0; i < N; ++i) {
		for (int j = W - w[i]; j >= 0; --j) {
			dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]);
		}
	}
	return dp[W];
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, w;
	cin >> n >> w;
	vector<ll> W(n), v(n);
	rep(i, n) cin >> W[i] >> v[i];

	ll ans = KnapsackProblem01(n, w, v, W);

	dunk(ans);

	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <tuple>
#include <vector>
using namespace std;

#define MAX 100000

long long int a[MAX], b[MAX];

int main() {
    int N;

    cin >> N;

    long long int p_sum, m_sum;

    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }

    long long int tmp = 0;

    for (int i = 0; i < N; i++) {
        if (b[i] < a[i]) {
            tmp += (a[i] - b[i]) * 2;
            b[i] = a[i];
        }
    }

    for (int i = 0; i < N; i++) {
        if (b[i] > a[i]) {
            if ((b[i] - a[i]) % 2 == 0) {
                tmp -= (b[i] - a[i]);
                a[i] = b[i];
            } else {
                tmp -= (b[i] - a[i] - 1);
                a[i] = b[i] - 1;
            }
        }
    }

    for (int i = 0; i < N; i++) {
        if (b[i] < a[i]) {
            tmp += (a[i] - b[i]) * 2;
            b[i] = a[i];
        }
    }

    if (tmp <= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
 
int main(){
    long a, b, c;
    cin >> a >> b >> c;
    if (c-a-b > 0 and 4*a*b < (c-a-b)*(c-a-b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
# define ll long long
# define inf 1e9+5
using namespace std;
int main(){
	ll n,k;
	cin>>n>>k;
	
	vector<ll>c(n);
	for(ll i=0;i<n;i++) cin >>c[i];
	vector<ll>dp(n,inf);
	dp[0]=0;
	for(ll i=1;i<n;i++){
		for(ll j=1;j<=k;j++){
			if(i-j>=0){
		dp[i]=min(dp[i],dp[i-j]+abs(c[i]-c[i-j]));
	}
	}
}

		cout<<dp[n-1]<<"\n";
		
	
	
	
	
	return 0;
	}


Measured memory_bytes: 1792
using System;

class Program {
    static void Main() {
        for (string line; (line = Console.ReadLine()) != "0";) {
            var n = int.Parse(line);
            var y = int.Parse(Console.ReadLine());

            var maxId = 0;
            var maxInterest = 0.0;

            for (var i = 0; i < n; i++) {
                var l = Console.ReadLine().Split(' ');
                var b = int.Parse(l[0]);
                var r = int.Parse(l[1]);
                var t = (l[2] == "2");

                var interest = GetInterest(y, r, t);
                if (interest > maxInterest) {
                    maxId = b;
                    maxInterest = interest;
                }
            }

            Console.WriteLine(maxId);
        }
    }

    static double GetInterest(int y, int r, bool t) {
        if (t) {
            return Math.Pow(1 + r / 100.0, y);
        }
        else {
            return 1 + y * r / 100.0;
        }
    }
}

Measured memory_bytes: 9716
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

long long int N, M, K, Q, W, H, L, R;
long long int ans;

class UnionFind {
	vector<int>parent;
	vector<int>rank;
public:
	UnionFind(int num) {
		num++;
		parent.resize(num);
		rank.resize(num);
		for (int i = 0; i < num; i++) {
			parent[i] = i;
			rank[i] = 0;
		}
	}
	int Find(int node) {
		if (parent[node] == node)return node;
		else return parent[node] = Find(parent[node]);
	}
	void Unite(int u, int v) {
		u = Find(u);
		v = Find(v);
		if (u == v)return;
		if (rank[u] < rank[v])parent[u] = v;
		else {
			parent[v] = u;
			if (rank[u] == rank[v])rank[u]++;
		}
	}
	bool Check_Same(int u, int v) {
		return Find(u) == Find(v);
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	UnionFind u(N + M + 1);
	vector<pair<int, int>>v;
	for (int i = 1; i <= N; i++) {
		cin >> K;
		for (int j = 0; j < K; j++) {
			cin >> Q;
			u.Unite(i, N + Q);
			v.push_back({ Q,i });
		}
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size() - 1; i++) {
		if (v[i].first == v[i + 1].first) {
			u.Unite(v[i].second, v[i + 1].second);
		}
	}
	ans = u.Find(1);
	for (int i = 2; i <= N; i++) {
		if (ans != u.Find(i)) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
	return 0;
}

Measured memory_bytes: 2936
// Problem : B - Judge Status Summary
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define ios std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mii map<int, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long MOD=LLONG_MAX; //1e5+7;
int gcd(int x, int y)
{
	if(y==0) return x;
	else return gcd(y,x%y);
}
int power(int x, unsigned int y)  
{  
    int res = 1;
    x = x % MOD;
    if (x == 0) return 0;
  
    while (y > 0)  
    { 
        if (y & 1)  
            res = (res*x) % MOD;
        y = y>>1;
        x = (x*x) % MOD;  
    }  
    return res;  
}
void solve()
{
	int n;
	int a[4]={0};
	string ans;
	cin>>n;
	rep(i,0,n){
		string s;
		cin>>s;
		if(s=="AC") a[0]++;
		else if(s=="TLE") a[2]++;
		else if(s=="WA") a[1]++;
		else a[3]++;
	}
	cout<<"AC x "<<a[0]<<endl;
	cout<<"WA x "<<a[1]<<endl;
	cout<<"TLE x "<<a[2]<<endl;
	cout<<"RE x "<<a[3]<<endl;
}

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

Measured memory_bytes: 3644
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = sr()
K = ir()
length = len(N)
top = int(N[0])
dp_dec = [[0] * 4 for _ in range(length)]
dp_pen = [[0] * 4 for _ in range(length)]
dp_dec[0][1] = (top-1)
dp_dec[0][0] = 1
dp_pen[0][1] = 1
#print(dp_dec)
for i in range(1, length):
    cur = int(N[i])
    if cur == 0:
        dp_pen[i] = dp_pen[i-1][:] #右端に0
    else:
        for k in range(1, 4):
            dp_pen[i][k] = dp_pen[i-1][k-1] #右端にcur

    dp_dec[i] = dp_dec[i-1][:] #0が右端に加わった場合
    for j in range(1, 4):
        #print('for', i, j, dp_dec)
        dp_dec[i][j] += dp_dec[i-1][j-1] * 9 #1~9が右端に加わった場合
        if cur > 0:
            dp_dec[i][j] += dp_pen[i-1][j-1] * (cur-1) + dp_pen[i-1][j]
    #print(i, dp_dec)

answer = dp_dec[length-1][K] + dp_pen[length-1][K]
print(answer)


Measured memory_bytes: 3064
#encoding: utf-8

N, M = map(int, input().split())
A = list(map(int, input().split()))
match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

A.sort()
A.reverse()

dp = [-1] * (N + 1)
dp[0] = 0

for i in range(N + 1):
    for a in A:
        if i - match[a] >= 0:
            dp[i] = max(dp[i - match[a]] * 10 + a, dp[i])

print(dp[N])


Measured memory_bytes: 14692
// C - Count Order
// https://atcoder.jp/contests/abc150/tasks/abc150_c
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, ans2 = 0, count = 0;
  string s, t;
  cin >> n;
  vlli p(n), q(n), z;
  rep(i, 0, n)
  {
    cin >> p[i];
  }
  rep(i, 0, n)
  {
    cin >> q[i];
  }
  repe(i, 1, n)
  {
    z.pb(i);
  }
  do
  {
    count++;
    if (p == z)
    {
      ans = count;
    }
    if (q == z)
    {
      ans2 = count;
    }
  } while (next_permutation(ALL(z)));
  cout << abs(ans - ans2) << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
int main()
{
    fastio;
    ll n;
    cin>>n;
    ll ans=0;
    ll temp1=n/500;
    ll temp2=n%500;
    ll temp3=temp2/5;
    ans=temp1*1000+temp3*5;
    cout<<ans<<endl;
}


Measured memory_bytes: 3500
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
using namespace std;


int main(){
	char c[3][3];
	for(int i=0;i<9; i++) cin>>c[i/3][i%3];
	cout<<c[0][0]<<c[1][1]<<c[2][2]<<endl;


	return 0;
}



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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] str = Console.ReadLine().Split(' ');
            int H = int.Parse(str[0]);
            int W = int.Parse(str[1]);

            var c = new List<String>();

            for(int i = 0; i < H; i++)
            {
                c.Add(Console.ReadLine());
            }
            for (int i = 0; i < H; i++)
            {
                Console.WriteLine(c[i]);
                Console.WriteLine(c[i]);

            }
        }
    }
}


Measured memory_bytes: 13140
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func main() {
	W := nextFloat()
	H := nextFloat()
	X := nextFloat()
	Y := nextFloat()
	M := (W * H) / 2
	flag := W/X == 2 && H/Y == 2
	if flag {
		fmt.Printf("%v %d\n", M, 1)
	} else {
		fmt.Printf("%v %d\n", M, 0)
	}
}



Measured memory_bytes: 1772
import itertools
N = int(input())
x = []
y = []
for i in range(N):
    xy = list(map(int, input().split()))
    x.append(xy[0])
    y.append(xy[1])


l = [i for i in range(N)]
ans = 0
cnt = 0
for i in itertools.permutations(l, N):
    cnt += 1
    for j in range(1, N):
        x1 = x[i[j]]
        x2 = x[i[j-1]]
        y1 = y[i[j]]
        y2 = y[i[j-1]]
        ans += pow((x1 - x2)**2 + (y1 - y2)**2, 0.5)
        # print(i, j, x1, y1, x2, y2)
ans /= cnt
print(ans)

Measured memory_bytes: 9440
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <iostream>
#include <iomanip>

using namespace std;

int main(void)
{
	int h, w;
	cin >> h >> w;
	char a[h][w];
	unsigned long dp[h][w];
	for (int y = 0; y < h; y++) {
		for (int x = 0; x < w; x++) {
			cin >> a[y][x];
		}
	}

	bool wall = false;
	for (int x = 0; x < w; x++) {
		if (a[0][x] == '#') {
			wall = true;
		}
		if (wall)
			dp[0][x] = 0;
		else
			dp[0][x] = 1;
	}
	wall = false;
	for (int y = 0; y < h; y++) {
		if (a[y][0] == '#') {
			wall = true;
		}
		if (wall)
			dp[y][0] = 0;
		else
			dp[y][0] = 1;
	}

	for (int y = 1; y < h; y++) {
		for (int x = 1; x < w; x++) {
			dp[y][x] = 0;
			if (a[y][x] == '.') {
				if (a[y-1][x] == '.')
					dp[y][x] += dp[y-1][x]%1000000007;
				if (a[y][x-1] == '.')
					dp[y][x] += dp[y][x-1]%1000000007;
				dp[y][x] = dp[y][x]%1000000007;
			}
		}
	}
	cout << dp[h-1][w-1]%1000000007 << endl;
	return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
int s(int x)
{
    int now = 0;
    while(x)
    {
        now += x%10;
        x/=10;
    }
    return now;
}
int main()
{
    int x;
    while(cin>>x)
    {
        int y = s(x);
        if(x%y == 0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }

}
















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

// Data Type
#define ull     unsigned long long int
#define ll      long long int

// Loops
#define loop(i,s,e)     for(ll i=(s);i<(e);i++)
#define rloop(i,s,e)    for(ll i=(s);i>=(e);i--)

// Stl
#define pb      push_back
#define eb      emplace_back
#define pf      push_front
#define popb    pop_back
#define popf    pop_front
#define mp      make_pair
#define ff      first
#define ss      second

// Maths
#define PI          (2*acos(0.0))
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    (((a)*(b))/(__gcd((a),(b))))
#define log(x,b)    (log(x)/log(b))
#define INF         LLONG_MAX

// Big data
const int Mod = 1e9+7;
#define mul(a,b)         ((a%Mod)*(b%Mod))%Mod
#define sum(a,b)         ((a%Mod)+(b%Mod))%Mod

// Bit-Manipulation
#define setbit(n,pos)       n |= (1LL<<pos)
#define resetbit(n,pos)     n &= (~(1LL<<pos))
#define toogle(n,pos)       n ^= (1LL<<pos)
#define atpos(n,pos)        ((n&(1LL<<pos))!=0)

// Extra
#define scan(any)       for(auto &i:any) cin>>i;
#define print(any)      for(auto i:any) cout<<i<<" "; nl;
#define nl              cout<<'\n'
#define endl            '\n'

void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	scan(a);

	ll next = 1;
	ll ans = 0;
	bool yes = false;
	
	loop(i,0,n)
	{
		if(next!=a[i]) ans++;
		else
		{
			yes = true;
			next++;
		} 
	} 
	if(!yes)
		cout<<-1;
	else
		cout<<ans;
}

int main()
{
	try
	{	
		ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
		int t = 1; 
		while(t--)
			solve();
	}
    catch(...)
    {
    	// nothing.
    }
	return 0;
}
/*
greater<int>()
fill_n(array,size,value);
fill(start,end,value);
getline(cin,string);
cin.getline(char array,size);
LLONG_MAX
DBL_MAX
*/

Measured memory_bytes: 1792
n = int(input())
red = [list(map(int, input().split())) for _ in range(n)]
red.sort(key=lambda x: x[1], reverse=True)
blue = sorted([list(map(int, input().split())) for _ in range(n)])
ans = 0
for a in red:
    for b in blue:
        if a[0] < b[0] and a[1] < b[1]:
            ans += 1
            blue.remove(b)
            break
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int A1,A2,A3;
	scanf("%d",&A1);
	scanf("%d",&A2);
	scanf("%d",&A3);
	int Sum=A1+A2+A3;
	if (Sum>=22)
	{
		printf("bust");
	}
	else
	{
		printf("win");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
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
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[200010];
    rep(i, n) cin >> a[i];
    int sum = 0;
    rep(i, n) sum += a[i];
    int ans = INF2;
    int sum2 = 0;
    rep(i, n - 1) {
        sum2 += a[i];
        ans = min(ans, abs(sum - sum2 * 2));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
using namespace std;
typedef long long LL;

int main(void)
{
	LL n;
	cin >>n;
	vector<LL> d(n);
	for (int i = 0; i < n; i++) {
		cin >>d[i];
	}

	sort(d.begin(),d.end());

	cout <<(d[n/2])-(d[(n/2)-1])<<endl;

	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;

namespace ABC139
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] H = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int count = 0;
            int res = 0;
            for (int i = 0; i < N - 1; i++)
            {
                if (H[i + 1] <= H[i])
                {
                    count++;
                    res = Math.Max(res, count);
                }
                else
                {
                    count = 0;
                }
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 30300
def is_hora(lst):
    for i in range(1,10):
        if lst[i] >= 2:
            if(is_4chunk(lst,i)): return True
    return False

def is_4chunk(lst,atama):
    searchlist = [0]*10
    for i in range(10):
        searchlist[i] = lst[i]
    searchlist[atama] -= 2
    for i in range(1,8):
        if searchlist[i] < 0: return False
        if searchlist[i] >=3: searchlist[i]-=3
        if searchlist[i] ==1:
            searchlist[i]-=1
            searchlist[i+1]-=1
            searchlist[i+2]-=1
        elif searchlist[i] ==2:
            searchlist[i]-=2
            searchlist[i+1]-=2
            searchlist[i+2]-=2
    return (searchlist[8] == 0 or searchlist[8] == 3) and (searchlist[9] == 0 or searchlist[9] == 3)

while True:
    try:
        instr = input()
        pai = [0]*10
        ans = []
        for i in range(13):
            pai[(int(instr[i]))] += 1
        for i in range(1,10):
            if pai[i] == 4: continue
            pai[i] += 1
            if is_hora(pai): ans.append(i)
            pai[i] -= 1
        if len(ans)!=0:
            print(" ".join(list(map(str,ans))))
        else: print(0)

    except EOFError: break

Measured memory_bytes: 7620
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
  
int n;
cin>>n;
string s;
cin>>s;
int cnt=0;
for(int i=2;i<s.length();i++)
{
    if(s[i]=='C'&&s[i-1]=='B'&&s[i-2]=='A')
    cnt++;
}
cout<<cnt<<endl;
}

Measured memory_bytes: 256
/*
 *  I wish I could travel by the road that crosses baby's mind,
 *  and out beyond all bounds;
 *  Where messengers run errands for no cause 
 *  between the kingdoms of kings of no history;
 *  Where Reason makes kites of her laws and flies them, 
 *  and Truth sets Fact free from its fetters.
 *                                           Rabindranath Tagore
 */

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

#ifndef ORZ_EVERYBODY_BUT_ME
#define ORZ_EVERYBODY_BUT_ME
#endif

#ifndef SOCIALISM
#define SOCIALISM
#endif

const size_t MAX_N = 2e5 + 5;

int a[MAX_N];
long long sum[MAX_N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
        sum[i] = sum[i - 1] + a[i];
    }
    map<long long, int> mp;
    mp[0] = 1;
    long long res = 0;
    for (int i = 1; i <= n; ++i) {
        res += mp[sum[i]];
        mp[sum[i]]++;
    }
    cout << res << '\n';

    return 0;
}


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

using namespace std;
using ll = long long;

const int MAX { 1010 };

ll as[MAX], bs[MAX], cs[MAX], xs[MAX*MAX], ans[MAX*MAX];

ll amount(ll m, ll X, ll Y, ll Z)
{
    ll res = 0;

    for (int i = 0; i < X; ++i)
    {
        auto j = lower_bound(xs, xs + Y*Z, m - as[i]) - xs;
        res += (Y*Z - j);
    }

    return res;
}

void solve(ll X, ll Y, ll Z, ll K)
{
    ll pos = 0;

    for (int i = 0; i < Y; ++i)
        for (int j = 0; j < Z; ++j)
            xs[pos++] = bs[i] + cs[j];

    sort(as, as + X);
    sort(xs, xs + Y*Z);

    ll a = xs[0] + as[0], b = xs[Y*Z - 1] + as[X - 1], k = a;

    while (a <= b)
    {
        auto m = a + (b - a)/2;
//cout << "a = " << a << ", b = " << b << ", m = " << m << ", amount = " << amount(m, X, Y, Z) << '\n';
        if (amount(m, X, Y, Z) >= K)
        {
            k = m;
            a = m + 1;
        } else
            b = m - 1;
    }

//cout << "k = " << k << ", amount = " << amount(k, X, Y, Z) << '\n';

    pos = 0;

    for (ll i = 0; i < X; ++i)
    {
        ll j = lower_bound(xs, xs + Y*Z, k - as[i]) - xs;

        while (j < Y*Z)
        {
            ans[pos++] = (-(as[i] + xs[j]));
            ++j;
        }
    }

    sort(ans, ans + pos);
}

int main()
{
    ios::sync_with_stdio(false);

    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    for (int i = 0; i < X; ++i)
        cin >> as[i];

    for (int i = 0; i < Y; ++i)
        cin >> bs[i];

    for (int i = 0; i < Z; ++i)
        cin >> cs[i];

    solve(X, Y, Z, K);

    for (int i = 0; i < K; ++i)
        cout << -ans[i] << '\n';

    return 0;
}


Measured memory_bytes: 16128
n,m = map(int,input().split())
g = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

room = [-1]*n
seen = [-1]*n
import queue
q = queue.Queue()
q.put(0)
while not q.empty():
    x = q.get()
    
    seen[x] =  -2
    for i in g[x]:
        if room[i] == -1:
            room[i] = x
            
        if seen[i] == -1:
            q.put(i)
            seen[i] = -2
        
print('Yes')
for i in range(1,n):
    print(room[i]+1)



Measured memory_bytes: 35008
n = gets.chomp!.to_i
as = gets.chomp!.split(" ")
as = as.map{|item| item = item.to_i}

hu = as.count{|item| item<0 } % 2
as.map!{|item| item = item.abs}
as.sort!
if hu == 1
	as[0] = 0-as[0]
end

ans = 0

for j in 0..n-1
	ans = ans+as[j]
end

puts ans

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

vector<int> ip(mx,0);
 
bool isprime(int x){
  if(x==2 || x==3){ return true; }
  if(x<2 || x%2==0){ return false; }
  
  int sqrtx = ceil(sqrt(x));
  for(int i=3; i<=sqrtx; i+=2){ if(x%i==0){ return false; } }
  return true;
}
 
void ipset(int x){                                        //x miman prime set
  for(int i=2; i<x; i++){ ip[i]=(int)isprime(i);}
}

int main(){
  ipset(1010);
  int n;
  cin >> n;
  ll ans=1;
  for(int i=1; i<=n; i++)if(ip[i]){
    ll cnt=0;
    int tmp=n;
    while(tmp/i!=0){
      cnt += tmp/i;
      tmp /= i;
    }
    ans *= (cnt+1);
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
from operator import itemgetter
import sys
 
N = int(input())
 
listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))
 
    except:
        break;
 
#print(listA)
 
listB = sorted(listA)
la = sorted(listB, key=itemgetter(1))
 
t = 0
for i in range(N):
	s = la[i][1]
	t += la[i][0]
	if t > s:
		print("No")
		sys.exit()
 
print('Yes')



Measured memory_bytes: 56772
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	ll D;
	cin >> D;

	ll N = 26;
	vector <ll> c(N);
	for (ll ii = 0; ii < N; ++ii){
		cin >> c[ii];
	}
	vector<vector<ll>> s(D, vector <ll> (N));
	for (ll ii = 0; ii < D; ++ii){
		for (ll jj = 0; jj < N; ++jj){
			cin >> s[ii][jj];
		}
	}

	//貪欲法
	vector <int> ans(D, 0);
	vector <int> last(N, -1);
	for (ll d = 0; d < D; ++d){
		//d日目の最適解を選ぶ
		ll val = 0;
		ll idx = 0;
		for (int ii = 0; ii < N; ++ii){
			ll tmp = s[d][ii] + c[ii]*(d - last[ii]);
			if (tmp > val){
				val = tmp;
				idx = ii;
			}
		}
		ans[d] = idx + 1;
		last[idx] = d;
	}

	for (ll d = 0; d < D; ++d){
		cout << ans[d] << "\n";
	}


	return 0;
}


Measured memory_bytes: 3732
#include <iostream>

using namespace std;

int cmp_str(string s1, string s2); // stringの違う文字の数,同じ長さ限定

int main(){
  string s;
  cin >> s;
  string s1="",s2="";
  for(int i = 0; i < s.size(); i++){
    s1 += i % 2 + '0';
    s2 += (i+1) % 2 + '0';
  }
  cout << min(cmp_str(s1,s),cmp_str(s2,s));
  return 0;
}

int cmp_str(string s1,string s2){
  int ans = 0;
  for(int i = 0; i < s1.size(); i++){
    ans += max(s1[i],s2[i]) - min(s1[i],s2[i]) ; // 同じだったら0,違ったらその分だけ足す
  }
  return ans;
}


Measured memory_bytes: 1024
#line 1 "vector.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_A"
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  int size = v.size();
  for (int i = 0; i < size; i++) {
    std::cout << v[i] << (i == size - 1 ? '\n' : ' ');
  }
  return out;
}

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 3 "vector.test.cpp"
#include <cmath>

int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> a(m);
  std::cin >> a;
  std::vector<int> dp(n + 1, 50001);
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (i - a[j] >= 0) {
        dp[i] = std::min(dp[i], dp[i - a[j]] + 1);
      }
    }
  }

  std::cout << dp[n] << std::endl;
}




Measured memory_bytes: 3180
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000


int main(void) {
	vint a(3);
	rep(i, 3) {
		cin >> a[i];
	}
	cout << a[2] <<' '<< a[0] <<' '<< a[1] << endl;
	return 0;
}

Measured memory_bytes: 3592
#include<cstdio>
#define pritnf printf
#define scnaf scanf
#define retrun return
#define sizoef sizeof
#define inl inline
#define br break
#define con continue
#define mst(a,b) memset(a,b,sizeof(a))
#define fora(x,a,b) for(re nti (x)=(a);(x)<=(b);++(x))
#define forb(x,a,b) for(re nit (x)=(a);(x)>=(b);--(x))
#define re register
#define stt struct
#define infa (0x3f3f3f3f)
#define infb (0x7fffffff)
#define infd (0x7f)
#define abss(x) ((x)>(0)?(x):(-1)*(x))
#define maxx(a,b) ((a)>(b)?(a):(b))
#define minn(a,b) ((a)<(b)?(a):(b))
#define pf(_) ((_)*(_))
#define in(a) freopen("D:/""/in"a".in","r",stdin)
#define out(a) freopen("D:/""/out"a".out","w",stdout)
typedef long long ll;
typedef int itn,nti,tin,tni,nit;
using namespace std;
const nit maxa=104;
const nit maxb=1e2;
const nit maxc=5;
#include<iostream>

string x;
tni s,ans=0;

tni main()
{
	cin>>x;
	s=x.size();
	//
	fora(i,1,s-1)
	{
		if(x[i]!=x[i-1])
		{
			++ans;
		}
	}
	//
	pritnf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
//  Created by ZJYelizaveta on 2017年11月18日 星期六 20时50分15秒
//  Copyright (c) 2017年 ZJYelizaveta. All rights reserved.

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

int a[10];
int cnt[10];

inline bool check() {
	if ((a[0] == a[1] && a[1] == a[2]) || (a[1] == a[2] && a[2] == a[3])) return true;
	return false;
}

int main()
{
	char str[10];
	cin >> str;
	for (int i = 0; i < 4; ++i) {
		a[i] = str[i] - '0';
	}

	if (check()) printf("Yes\n");
	else printf("No\n");

	return 0;
}
	

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
long long dp[2100][2100];
int b[2100];
int a;
long long calc(int l,int r,int s){
	if(~dp[l][r])return dp[l][r];
	if(l==r){
		if(s)return dp[l][r]=0;
		return dp[l][r]=b[l];
	}
	if(s){
		if(b[l]>b[r]){
			return dp[l][r]=calc((l+1)%a,r,0);
		}else{
			return dp[l][r]=calc(l,(r+a-1)%a,0);
		}
	}
	return dp[l][r]=max(calc((l+1)%a,r,1)+b[l],calc(l,(r+a-1)%a,1)+b[r]);
}
int main(){
	scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d",b+i);
	for(int i=0;i<2100;i++)for(int j=0;j<2100;j++)
		dp[i][j]=-1;
	long long ret=0;
	for(int i=0;i<a;i++){
		ret=max(ret,calc((i+1)%a,(i+a-1)%a,1)+b[i]);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 35576
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main () {
    int n, t;
    long long int result = 0;
    scanf("%d%d", &n, &t);
    long long int lasttemp = 0;
    
    for (int i = 0; i < n; i++) {
        long long int temp;
        scanf("%lld", &temp);
        if (temp - lasttemp > t) {
            result += t;
        }
        else {
            result -= (lasttemp - temp);
        }
        lasttemp = temp;
        //printf("%lld ", result);
    }
    result += t;
    
    printf("%lld", result);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define maxm 100001
using namespace std;
long long f[maxm]; 
int main(){
	int m,n,w,c;
    cin>>n>>m;
    for(int i=1;i<=n;i++){ 
    	cin>>w>>c; 
        for(int v=m;v>=w;v--)
            f[v]=max(f[v-w]+c,f[v]);
    }
    cout<<f[m];
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

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

#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve() {
	int n;
	cin >> n;
	mii mp;
	rep(a, 1, 100) {
		rep(b, 1, 100) {
			rep(c, 1, 100) {
				mp[a * a + b * b + c * c + a * b + b * c + a * c]++;
			}
		}
	}
	rep(i, 1, n) {
		cout << mp[i] << "\n";
	}
}

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


#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// test
	solve();

	return 0;
}


Measured memory_bytes: 5988
#include <iostream>
#include <set>
using namespace std;
int n, d[100];
int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> d[i];
    set<int> se;
    for (int i = 0; i < n; i++)
        se.insert(d[i]);
    cout << se.size() << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,sum=0;
	cin>>n;
	for(long long i=0;i<=n;i++){
		if(i%3!=0&&i%5!=0){
			sum+=i;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3644
//C
#include <cassert>
#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 <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#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 <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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 int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



int main() {
	int N;
	cin >> N;
	vector<int>v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i];
	}
	sort(v.begin(), v.end());
	cout << v[N / 2] - v[N / 2 - 1] << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
 
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e9
// #define ll long long ll
 
typedef long long ll;
ll mod = 1e9 + 7;
 long long fast_exp(long long a, long long b)
{
    if(b <= 0)
       return 1;
    else
    {
       long long res = 1;
       res = fast_exp(a,b/2);
       res = (res*res)%mod;
       if(b%2 == 1)
          res = (res*a)%mod;
       return res;
 
    }
}


typedef long double ld;

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    long long n;
    cin >> n;
    long long cur = 2;
    vector <long long> fact;
    
    for(long long i = 1; i * i <= n ; i++)
    {
        if( n % i == 0)
        {
            if(i > 1)
                fact.pb(i);
            if(n/i != i)
                fact.pb(n/i);
        }
    }
    long long cnt = 0;
    for(auto e : fact)
    {
        long long cp = n;
        while(cp % e == 0)
            cp = cp/e;
        if(cp % e == 1)
            cnt++; 
    }

    n = n - 1;
    vector <long long> v;
    for(long long i = 1; i * i <= n ; i++)
    {
        if(n % i == 0)
        {
            if(i > 1)
                v.pb(i);
            if(n / i != i)
                v.pb(i);
        }
    }


    cnt += v.size();
    cout << cnt << endl;
         





    return 0;
 
 
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

long Compare(const void *a, const void *b) {
	return *(long*)a - *(long*)b;
}

int main(void)
{
	int num, choose;
	long long int tree[100000], min, diff;
	scanf("%d %d", &num, &choose);
	for (int i = 0; i < num; i++) {
		scanf("%lld", &tree[i]);
	}
	qsort(tree, num, sizeof(long long int), Compare);
	min = 1000000000;

	for (int i = 0; i <= num - choose; i++) {
		diff = tree[i + choose - 1] - tree[i];
		if (diff < min) {
			min = diff;
		}
	}
	printf("%lld\n", min);
	return 0;
}


Measured memory_bytes: 1788
import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.HashMap

object Main {
  def main(args:Array[String]) = {
    val n = readInt
    val g = for(i<-0 until n) yield { readLine.trim.split(" ").map(_.toInt) }
    val dist = new Array[Int](n)
    val mp = new HashMap[Int,Int]
    for(i<-0 until n) {
      dist(i) = 1000000
      mp += (i->1000000)
    }
    dist(0) = 0
    mp.update(0,0)

    while(!mp.isEmpty) {
      val minV = mp.minBy{ case (key,value) => value }
      val min = minV._2
      val v = g(minV._1)

      for(i<-0 until v(1)) {
        val j = i*2+2
        val k = i*2+3
        if(mp.contains(v(j))) {
          if(v(k)+dist(v(0)) < dist(v(j))) {
            dist(v(j)) = v(k) + dist(v(0))
            mp.update(v(j), v(k) + dist(v(0)))
          }
        }
      }
      mp -= v(0)
    }

    for(i<-0 until n) {
      println(i + " " + dist(i))
    }
  }
}

Measured memory_bytes: 450832
N = int(input())
A = list(map(int, input().split()))

dp = {(0, 0): 0, (0, 1): -10 ** 10}
for i in range(N):
    dp[(i + 1, 0)] = max(dp[(i, 0)] + A[i], dp[(i, 1)] - A[i])
    dp[(i + 1, 1)] = max(dp[(i, 0)] - A[i], dp[(i, 1)] + A[i])
print(dp[(N, 0)])


Measured memory_bytes: 50648
while True:
    N, M = map(int,input().split())
    if M == 0:
        exit()

    h = [0]+[int(input()) for i in range(N)]
    N += 1
    for i in range(1,N):
        h[i] += h[i-1]
    w = [0]+[int(input()) for i in range(M)]
    M += 1
    for i in range(1,M):
        w[i] += w[i-1]

    h_pat = {}
    w_pat = {}
    for i in range(N-1):
        for j in range(i+1,N):
            height = h[j] - h[i]
            if height not in h_pat:
                h_pat[height] = 1
            else:
                h_pat[height] += 1
    for i in range(M-1):
        for j in range(i+1,M):
            width = w[j] - w[i]
            if width not in w_pat:
                w_pat[width] = 1
            else:
                w_pat[width] += 1

    ans = 0
    for k, v in h_pat.items():
        if k in w_pat:
            ans += w_pat[k] * v

    # print(h_pat)
    # print(w_pat)
    print(ans)



Measured memory_bytes: 54400