akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String
    }
    let ans:&str = if s == "Sunny" {
        "Cloudy"
    } else if s == "Cloudy" {
        "Rainy"
    } else {
        "Sunny"
    };
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<stdio.h>
int main(){
  double h,max=0.0,min=10000.0;
  while(scanf("%lf",&h)!=-1){
    if(h>max)
      max=h;
    if(h<min)
      min=h;
  }
  printf("%.1lf\n",max-min);
  return 0;
}

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

int main(){
  int l;
  cin >> l;
  while(l--){
    vector<int> seq;
    int n=0;
    {
      int tmp;
      while(cin >> tmp, tmp){
	seq.push_back(tmp);
	if(tmp>0)n++;
      }
    }
    
    vector<int> deg(n,0);
    vector< vector<int> > adj(n);

    int id = 0;
    vector<int> stack;
    stack.push_back(0); deg[0] = seq[0];

    for(int i=1;i<(int)seq.size();i++){
      if(seq[i]>0){
	id++;

	adj[stack.back()].push_back(id);
	adj[id].push_back(stack.back());
	deg[id] = seq[i]-1;
	deg[stack.back()]--;

	stack.push_back(id);
      }else{
	int nxt = stack[stack.size()-1+seq[i]];

	adj[stack.back()].push_back(nxt);
	adj[nxt].push_back(stack.back());
	deg[nxt]--;
	deg[stack.back()]--;
      }
      while(stack.size() && deg[stack.back()]==0)stack.pop_back();
    }

    for(int i=0;i<n;i++){
      cout << i+1;
      sort(adj[i].begin(), adj[i].end());
      for(int u : adj[i])cout << " " << u+1;
      cout << endl;
    }
  }
}

Measured memory_bytes: 1240
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import deque
from copy import deepcopy

n,m=nii()
l=[lnii() for i in range(m)]

def BFS(t_l):
  tree=[[] for i in range(n)]
  for a,b in t_l:
    a-=1
    b-=1
    tree[a].append(b)
    tree[b].append(a)

  dist=[-1 for i in range(n)]
  dist[0]=0

  que=deque()
  que.append(0)

  while que:
    x=que.popleft()
    for i in tree[x]:
      if dist[i]==-1:
        que.append(i)
        dist[i]=dist[x]+1

  return dist

ans=0
for i in range(m):
  t_l=deepcopy(l)
  del t_l[i]
  dist=BFS(t_l)
  if -1 in dist:
    ans+=1

print(ans)

Measured memory_bytes: 9552
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <cmath>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
const ll MOD = 998244353;

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll d = c - a - b;
    if (d < 0) {
        cout << "No" << endl;
        return 0;
    }
    d = d*d;
    if (d > 4 * a * b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

using namespace std;

typedef pair<int, int> P;

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

    int n;
    while(cin>>n,n){
        vector<P> gems;
        for(int i=0;i<n;i++){
            int x,y;cin>>x>>y;
            gems.push_back(P(x,y));
        }
        int rx=10,ry=10;
        int m;cin>>m;
        vector< vector<int> > visited(30,vector<int>(30,0));
        visited[rx][ry]=1;
        for(int i=0;i<m;i++){
            string s;cin>>s;int l;cin>>l;
            if(s=="N"){
                for(int i=0;i<l;i++){
                    ry++;
                    visited[rx][ry]=1;
                }
            }
            else if(s=="E"){
                for(int i=0;i<l;i++){
                    rx++;
                    visited[rx][ry]=1;
                }
            }
            else if(s=="S"){
                for(int i=0;i<l;i++){
                    ry--;
                    visited[rx][ry]=1;
                }
            }
            else{
                for(int i=0;i<l;i++){
                    rx--;
                    visited[rx][ry]=1;
                }
            }
        }
        bool flag=true;
        for(int i=0;i<n;i++){
            int x=gems[i].first,y=gems[i].second;
            if(!visited[x][y]) flag=false;
        }
        if(flag) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3208
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;

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

	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		if (x % 2 == 0 && x % 3 && x % 5)
		{
			cout << "DENIED";
			return 0;
		}
	}
	cout << "APPROVED";
}

Measured memory_bytes: 3596
import std.conv;
import std.stdio;
import std.string;

void main()
{
	auto n = readln.strip.to!int;
	writeln( solve( n ) );
}

auto solve( in int n )
{
	if( n < 1000 ) return "ABC";
	else           return "ABD";
}

unittest
{
	assert( solve( 999 ) == "ABC" );
	assert( solve( 1000 ) == "ABD" );
	assert( solve( 1481 ) == "ABD" );
}


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

#define reint register int
#define coint const int

using namespace std;

typedef long long ll;

coint SIZE = 2000 + 5;
coint MOD  = 1e9 + 7;

ll c[SIZE][SIZE], dp[SIZE][SIZE], sum[SIZE][SIZE];

inline ll mod(const ll num) { return num >= MOD ? num - MOD : num; }

int main(void) {
    for (reint i = 0; i < SIZE; ++i) {
        c[i][0] = 1;
        for (reint j = 1; j <= i; ++j)
            c[i][j] = mod(c[i - 1][j] + c[i - 1][j - 1]);
    }
    dp[0][0] = 1;
    for (reint i = 0; i < SIZE; ++i) sum[0][i] = 1;
    for (reint i = 1; i < SIZE; ++i) {
        for (reint j = i; j < SIZE; ++j)
            dp[i][j] = sum[i - 1][j - 1];
        for (reint j = i; j < SIZE; ++j)
            sum[i][j] = mod(sum[i][j - 1] + dp[i][j]);
    }
    int n, k;
    scanf("%d%d", &n, &k);
    for (reint i = 1; i <= k; ++i)
        printf("%lld\n", c[n - k + 1][i] * dp[i][k] % MOD);
        //printf("c[%d][%d] = %lld, dp[%d][%d] = %lld\n",
                //n - k + 1, i, c[n - k + 1][i], i, k, dp[i][k]);

    return 0;
}



Measured memory_bytes: 94464
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::*;
fn main() {
    input! {
        n: usize,
        k: usize,
        s: chars,
    }
    let mut starts = vec![];
    let mut ends = vec![];
    if s[0] == '0' {
        starts.push(0);
        ends.push(0);
    }
    for i in 0..s.len() {
        if s[i] == '1' {
            if i == 0 || s[i - 1] == '0' {
                starts.push(i);
            }
            if i == n - 1 || s[i + 1] == '0' {
                ends.push(i);
            }
        }
    }
    if s[n - 1] == '0' {
        starts.push(n - 1);
        ends.push(n - 1);
    }

    if starts.len() == 0 {
        println!("{}", n);
        return;
    }
    let mut ans = 0;
    for i in 0..starts.len() {
        ans = max(ends[min(i + k, ends.len() - 1)] - starts[i] + 1, ans);
    }
    println!("{}" , ans);
}

Measured memory_bytes: 6396
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	int A,B;
	cin >>A>>B;
	int an = -1;
	if (A<10&&B<10) {
		an = A * B;
	}
	cout << an<< endl;
}

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

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

    int n;
    cin >> n;

    int d = n%10;

    if(d==2 || d==4 || d==5 || d==7 || d==9) puts("hon");
    else if(d==0 || d==1 || d==6 || d==8) puts("pon");
    else puts("bon");

    return 0;
}

Measured memory_bytes: 3652
N,M = map(int,input().split())
L = [0] * (M)
R = [0] * (M)
for i in range(M):
    L[i],R[i] = map(int,input().split())
l = max(L)
r = min(R)

if l <= r:
    ans = r-l+1
else:
    ans = 0

print(ans)

Measured memory_bytes: 16660
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n % i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table


def main():
    n = int(input())
    divs = sorted(divisor(n))
    if len(divs) % 2 == 0:
        left = len(divs)//2 - 1
        right = len(divs)//2
    else:
        left, right = len(divs)//2, len(divs)//2

    ans = divs[left] + divs[right] - 2
    print(ans)


if __name__ == "__main__":
    main()


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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        return;

    }

    public static string Solve()
    {
        int[] input = ReadInts();
        int a = input[0];
        int b = input[1];
        int c = input[2];
        int s = (a + b + c) / 2;
        int ans = (int)Math.Sqrt(s * (s - a) * (s - b) * (s - c));

        return ans.ToString();
    }
    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


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

using namespace std;

#define PB push_back
#define MEM(n, val) memset(n, val, sizeof(n))
#define FOR(i, j, k) for(int i = j; i <= k; i++)
#define ROF(i, j, k) for(int i = j; i >= k; i--)
#define LL long long
#define F first
#define S second
#define PII pair<int, int>
#define INF 1999999999
#define MP make_pair
#define LN (node * 2)
#define RN ((node * 2) + 1)
#define MOD 1000000007

int fx[] = {1, -1, 0, 0};
int fy[] = {0, 0, 1, -1};

int n, k;
int ara[200010];
int freq[200010];
///int yo[200010];
vector<int> yo;

int main()  {
    std::ios_base::sync_with_stdio(false);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> n >> k;
    FOR(i, 0, n - 1)   {
        cin >> ara[i];
        freq[ ara[i] ]++;
    }
    FOR(i, 1, n)   {
        if(freq[i])    {
            yo.PB(freq[i]);
        }
    }
    sort(yo.begin(), yo.end());
    reverse(yo.begin(), yo.end());
    if(yo.size() <= k)    {
        cout << 0;
        return 0;
    }
    ///cout << yo.size() << "\n";
    int ans = 0;
    ROF(i, yo.size() - 1, k)   {
        ans += yo[i];
    }
    cout << ans;
    return 0;
}
/**
*/


Measured memory_bytes: 2936
import java.util.Scanner;

class Main{
    static public void main(String[] av){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int x = a*b;
	int y = 2*a + 2*b;
	System.out.println(x+" "+y);
    }
}


Measured memory_bytes: 26236
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 100000 + 5;
#define INF 1e14
int a, b, q;
long long s[maxn], t[maxn];
vector<long long> ss(2), tt(2);

int main() {
  while(scanf("%d%d%d", &a, &b, &q) == 3) {
    s[0] = t[0] = -INF;
    s[a+1] = t[b+1] = INF;
    for(int i = 1; i <= a; i++) scanf("%lld", &s[i]);
    for(int i = 1; i <= b; i++) scanf("%lld", &t[i]);
    long long pos;
    while(q--) {
      scanf("%lld", &pos);
      int right_s = lower_bound(s, s+a+1, pos) - s;
      ss[0] = s[right_s - 1];
      ss[1] = s[right_s];

      int right_t = lower_bound(t, t+b+1, pos) - t;
      tt[0] = t[right_t - 1];
      tt[1] = t[right_t];

      long long min_dis = INF;
      for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
          min_dis = min(min_dis, min(abs(pos - ss[i]) + abs(ss[i] - tt[j]), abs(pos - tt[j]) + abs(tt[j] - ss[i])));
        }
      }
      printf("%lld\n", min_dis);
    }
  }
  return 0;
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define pb push_back
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define _max(v) *max_element(v.begin(), v.end())
#define _min(v) *min_element(v.begin(), v.end())

int main() 
{
    io;
    ll n, x, t; cin >> n >> x >> t;
    if(n%x==0) cout << (n/x)*t << endl;
    else cout<< (n/x)*t+t <<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl

using namespace std;

using ll = int64_t;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()

template <class T>
ostream &operator<<(ostream &os, vector<T> const &vec) {
    if (vec.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
        os << vec.back() << '}';
    }
    return os;
}

template <class T, size_t S>
ostream &operator<<(ostream &os, array<T, S> const &arr) {
    if (arr.empty()) {
        os << "{}";
    } else {
        os << '{';
        for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
        os << arr.back() << '}';
    }
    return os;
}

template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> const &p) {
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

namespace math {
ll gcd(ll u, ll v) {
    while (v != 0) {
        ll r = u % v;
        u = v;
        v = r;
    }
    return u;
}
ll lcm(ll m, ll n) {
    if ((0 == m) || (0 == n)) return 0;

    return ((m / math::gcd(m, n)) * n);
}
}  // namespace math

struct UnionFind {
    vector<ll> data;
    UnionFind(ll size) : data(size, -1) {}
    bool unionSet(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(ll x, ll y) { return root(x) == root(y); }
    ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    ll size(ll x) { return -data[root(x)]; }
};

template <class T, class U>
pair<T, U> operator+(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first + b.first, a.second + b.second);
}

template <class T, class U>
pair<T, U> operator-(pair<T, U> const &a, pair<T, U> const &b) {
    return pair<T, U>(a.first - b.first, a.second - b.second);
}

ll bound(function<bool(ll)> f, ll ng, ll ok) {
    while (abs(ng - ok) > 1) {
        ll mid = (ng + ok) / 2;
        if (f(mid))
            ok = mid;
        else
            ng = mid;
    }

    return ok;
}

int main(void) {
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> AB(N);
    rep(i, N)
        cin >> AB[i].first >> AB[i].second;
    
    sort(all(AB));

    ll money = 0;
    rep(i, N){
        ll n = min(M, AB[i].second);
        money += n * AB[i].first;
        M -= n;
        if(M == 0)
            break;
    }

    cout << money << endl;

    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC047B - すぬけ君の塗り絵 2 イージー / Snuke's Coloring 2 (ABC Edit)

        Scanner sc = new Scanner(System.in);

        int w = sc.nextInt();   // 1 <= w,h <= 100
        int h = sc.nextInt();
        int n = sc.nextInt();   // 1 <= n <= 100

        int x1 = 0;
        int x2 = w;
        int y1 = 0;
        int y2 = h;

        int x = 0;   // 0 <= x <= w
        int y = 0;   // 0 <= y <= h
        int a = 0;   // 1, 2, 3, 4

        for (int i = 0; i < n; i++) {
            x = sc.nextInt();
            y = sc.nextInt();
            a = sc.nextInt();

            switch(a) {
            case 1:
                if (x1 < x) x1 = x;
                break;
            case 2:
                if (x2 > x) x2 = x;
                break;
            case 3:
                if (y1 < y) y1 = y;
                break;
            case 4:
                if (y2 > y) y2 = y;
                break;
            }
        }

        int xx = x2 - x1;
        int yy = y2 - y1;

        System.out.println((xx > 0 && yy > 0) ? xx * yy : 0);
    }
}

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

int main(){
	int n, b[10000], f[10000], r[10000], v[10000];
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> b[i] >> f[i] >> r[i] >> v[i];
	}

	for (int building = 1; building <= 4; building++){
		for (int floor = 1; floor <= 3; floor++){
			for (int room = 1; room <= 10; room++){
				int t = 0;
				for (int i = 0; i < n; i++){
					if (b[i] == building&&f[i] == floor&&r[i] == room)t += v[i];
				}
				cout << ' ' << t;
			}
			cout << endl;
		}
		if (building == 4)break;
		cout << "####################" << endl;
	}
	return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>

#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

long long fact[200005];
void calcfact() {
    long long i;
    fact[0] = 1;
    fact[1] = 1;
    for (i = 2; i < 200005; i++) {
        fact[i] = fact[i - 1] * i;
        fact[i] %= MOD;
    }
}
long long power(long long a, long long b) {
    long long x = 1, y = a;
    while (b > 0) {
        if (b % 2) {
            x = (x*y) % MOD;
        }
        y = (y*y) % MOD;
        b /= 2;
    }
    return x % MOD;
}
long long inv(long long x) {
    return power(x, MOD - 2);
}
long long nCr(long long n, long long r) {
    return (fact[n] * (inv(fact[r])*inv(fact[n - r]) % MOD)) % MOD;
}

ll h, w, a, b, ans = 0;
int main() {
    calcfact();
    cin >> h >> w >> a >> b;
    for (int i = 0; i < h - a; i++) {
        if (i == (h - a - 1)) {
            ans += nCr(b + i, b)*nCr(a + w - b - 1, w-b-1) % MOD;
        }
        else {
            ans += nCr(b + i, b)*nCr(h + (w - b) - 3 - i, w - b - 2) % MOD;
        }
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

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

  ll expected = 1;
  ll broken = 0;
  for (auto i = 0; i < n; i++)
  {
    ll a;
    cin >> a;
    if (a == expected)
    {
      expected++;
    }
    else
    {
      broken++;
    }
  }

  if (broken > n - 1)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << broken << endl;
  }

  return 0;
}


Measured memory_bytes: 384
import math
import numpy as np
from operator import mul

# 整数Nを桁ごとのリストにする
# l = [int(x) for x in list(str(N))]

N = int(input())
f = [list(map(int, input().split())) for i in range(N)]
p = [list(map(int, input().split())) for i in range(N)]
c = list(range(N))
max_p = -100**7-1

for i in range(1,2**10):
    i_bin = format(i, 'b').zfill(10)
    i_list = [int(x) for x in list(str(i_bin))]
    profit = 0 #それぞれの場合の利益を総当り
    for j in range(N):
        # 店jと同時に開いている時間の数を計算
        combine = map(mul, f[j], i_list)
        c[j] = sum(combine) # 0 <= c[j] <= 10
        profit += p[j][c[j]]
    if profit > max_p:
        max_p = profit

print(max_p)


Measured memory_bytes: 19668
#include<cstdio>
using namespace std;
#define N 1040
int n,fg,as[N][N];
int main()
{
	scanf("%d",&n);
	if(n<=9)
	{
		printf("%d\n",n);
		for(int i=1;i<=n;i++,printf("\n"))
		for(int j=1;j<=n;j++)
		printf("%d ",(i+j-2)%n+1);
		return 0;
	}
	if(n%4)fg=4-n%4,n+=fg;
	n/=2;
	for(int i=1;i<=n/2;i++)
	for(int j=1;j<=n/2;j++)
	{
		int st=(i+j-2)%(n/2)+1;
		as[i*2-1][j*2-1]=st*4-3;
		as[i*2-1][j*2]=st*4-2;
		as[i*2][j*2-1]=st*4-1;
		as[i*2][j*2]=st*4;
	}
	if(fg)
	{
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(as[i][j]>3)as[i][j]--;
			else if(as[i][j]==3)as[i][j]=2;
		}
		fg--;
	}
	if(fg)
	{
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(as[i][j]>6)as[i][j]--;
			else if(as[i][j]==6)as[i][j]=5;
		}
		fg--;
	}
	if(fg)
	{
		for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(as[i][j]>9)as[i][j]--;
			else if(as[i][j]==9)as[i][j]=8;
		}
		fg--;
	}
	printf("%d\n",n);
	for(int i=1;i<=n;i++,printf("\n"))
	for(int j=1;j<=n;j++)
	printf("%d ",as[i][j]);
}

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

int w,h;
int r[50][50];
int d[50][50];

void bfs(int s,int t){
  int dx[]={1,0,-1,0};
  int dy[]={0,1,0,-1};

  queue<pair<int,int>> q;
  q.emplace(s,t);
  for(int i=0;i<50;i++){
    for(int j=0;j<50;j++){
      d[i][j]=-1;
    }
  }
  d[0][0]=1;

  int x,y;
  int u,v;

  while(!q.empty()){
    x=q.front().first;
    y=q.front().second;
    q.pop();
    for(int i=0;i<4;i++){
      u=x+dx[i];
      v=y+dy[i];
      if(u<0||v<0||u>=h||v>=w) continue;
      if(r[u][v]==0) continue;
      if(d[u][v]!=-1) continue;
      d[u][v]=d[x][y]+1;
      q.emplace(u,v);
    }
  }
}

int main(){
  int i,j,a=0;
  char s;

  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      scanf(" %c",&s);
      if(s=='.'){
        r[i][j]=1;
        a++;
      }else{
        r[i][j]=0;
      }
    }
  }
  bfs(0,0);

  if(d[h-1][w-1]==-1){
    printf("-1");
    return 0;
  } else{
    printf("%d",a-d[h-1][w-1]);
    return 0;
  }
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	heights := make([]int, 10)
	for i := 0; i < 10; i++ {
		sc.Scan()
		heights[i], _ = strconv.Atoi(sc.Text())
	}

	sort.Sort(sort.Reverse(sort.IntSlice(heights)))
	for i := 0; i < 3; i++ {
		fmt.Println(heights[i])
	}
}



Measured memory_bytes: 1144
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = a + b;
		int d = Math.max(c, a - b);
		int e = Math.max(d, a * b);
		System.out.println(e);
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL N,Z,W;
    cin >> N >> Z >> W;
    vector<LL> a(N);

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

    LL ans = (N > 1)?max(abs(W-a[N-1]),abs(a[N-1]-a[N-2])):abs(W-a[0]);

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
 
const int mod = 1000000007;
//const int mod = 998244353;
 
 
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
 
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);
 
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
 
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
 
        // その結果を push
        res.push_back({a, ex});
    }
 
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}


int main(int argc, const char * argv[]) {
    
    string S;
    cin >> S;
    
    ll sum = 0;
    ll digit = 1;
    
    
    
    for(ll i=0;i<S.size();i++){
        sum += (S[i]-'0') * digit;
        sum = sum % 9;
        digit *= 10; digit = digit % 9;
    }
    
    if(sum == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    
    return 0;

}


Measured memory_bytes: 6688
import java.io.*;
class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        char s[]=bu.readLine().toCharArray();
        int i,ans=0;
        for(i=0;i<s.length;i++)
        ans+=s[i]-'0';
        if(ans%9==0) sb.append("Yes");
        else sb.append("No");
        System.out.print(sb);
    }
}


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

int main() {
    string s;
    char c[4] = {'A', 'C', 'G', 'T'};
    int cnt = 0, tmp = 0, max = 0;
    cin >> s;
    rep(i, s.size()) {
        rep(j, 4) {
            if (s[i] == c[j])
                cnt++;
        }
        if (tmp == cnt) {
            if (max < cnt)
                max = cnt;
            cnt = 0;
        }
        tmp = cnt;
    }
    if (max < cnt)
        max = cnt;
    cout << max << endl;
}

Measured memory_bytes: 3616
function main(arg) {
    
    let n = Number(arg.split("\n")[0])
    let a = arg.split("\n")[1].split(" ").map(BigInt)

    let mod = BigInt(10**9+7)
    let sum = a.reduce((a,b)=>a+b, BigInt(0))
    
//  console.log(Number(sum))

    let ans=BigInt(0)
    for(let i=0; i<n; i++) {
        sum -= a[i]
        ans += a[i] * sum
        ans %= mod
    }
    console.log(Number(ans))
    
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 73832
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int N,M;
	cin>>N>>M;
	int ans = max(N-M,0);
	
	cout<<ans<<endl;
}

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

using namespace std;

bool cmp(const vector<int> &a, const vector<int> &b)
{
    return a[1] > b[1];
}

int main(int argc, const char * argv[]) {
    int n = 0;
    cin >> n;
    
    int v[n];
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    
    map<int, int> m_even;
    map<int, int> m_odd;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            m_even[v[i]]++;
        } else {
            m_odd[v[i]]++;
        }
    }
    
    vector<vector<int>> v1;
    for (std::map<int, int>::iterator i = m_even.begin(); i != m_even.end(); i++) {
        vector<int> tmp;
        tmp.push_back(i->first);
        tmp.push_back(i->second);
        v1.push_back(tmp);
    }
    
    sort(v1.begin(), v1.end(), cmp);
    vector<int> tmp;
    tmp.push_back(0);
    tmp.push_back(0);
    v1.push_back(tmp);
    
    vector<vector<int>> v2;
    for (std::map<int, int>::iterator i = m_odd.begin(); i != m_odd.end(); i++) {
        vector<int> tmp;
        tmp.push_back(i->first);
        tmp.push_back(i->second);
        v2.push_back(tmp);
    }
    
    sort(v2.begin(), v2.end(), cmp);
    v2.push_back(tmp);
    
    if (v1[0][0] != v2[0][0]) {
        cout << n - v1[0][1] - v2[0][1] << endl;
    } else {
        cout << min(n - v1[0][1] - v2[1][1], n - v2[0][1] - v1[1][1]) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 11060
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a[1000],b[1000];
	int c[1000],d[1000];
	memset (c,0,sizeof(c));
	memset (d,0,sizeof(d));
	cin >>a>>b;
	int len1=strlen(a);
	int len2=strlen(b);
	for (int i=0;i<len1;i++)
		c[i]=(int)(a[i]);
	for (int i=0;i<len2;i++)
		d[i]=(int)(b[i]);
	sort (c,c+len1);
	sort (d,d+len2);
	for (int i=0;i<len1;i++)
		a[i]=c[i];
	for (int i=0;i<len2;i++)
		b[i]=d[len2-i-1];
	if (strcmp(a,b)<0)
		cout <<"Yes"<<endl;
	else
		cout <<"No"<<endl;
    return 0;
}

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

using namespace std;

int main(){

	int n;
	cin >> n;
	int Y;
	cin >> Y;

	int x=-1;
	int y=-1;
	int z=-1;

	for(int i=0;i<=n;i++){
		for(int s=0;s<=n-i;s++){
			int t =n-i-s;
			int money = 10000*i+5000*s+1000*t;
			if(money==Y){
				cout<<i<<" " <<s<<" "<<t;
				return 0;				
			}					
			
		}
	}

	cout<<x<<" " <<y<<" "<<z;	

	return 0;

}

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

int main() {
	int A, B, C, K;
	bool flag = false;
	cin >> A >> B >> C >> K;

	for (int i = 0; i <= K; i++) 
		for (int j = 0; j <= K; j++) 
			for (int k = 0; k <= K; k++) {
				int x = A * (1 << i), y = B * (1 << j), z = C * (1 << k);
				if (i + j + k <= K && x < y && y < z) flag = true;
			}

	if (flag == true) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int main(){
    int n, k;
    cin >> n >> k;
    int M = (n-1)*(n-2)/2;
    if(M < k){
        puts("-1");
        return 0;
    }

    int cnt = M - k;
    vector<P> ans;
    rep(i, n-1){
        ans.push_back({n, i+1});
    }

    vector<P> leaf;
    rep(i, n-1)rep(j, i) leaf.push_back({i+1, j+1});

    rep(i, cnt) ans.push_back(leaf[i]);

    cout << ans.size() << endl;
    rep(i, ans.size()) cout << ans[i].first << " " << ans[i].second << endl;
}

Measured memory_bytes: 384
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
for a, b in zip(A, B):
    if a > b:  # 特殊操作（他のaの力が）が必要な場合
        cnt -= a-b
    if a < b:  # 他のbに力を貸せる場合
        cnt += int((b-a)/2)

if cnt >= 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 4596
/**
 *    Author:   ElProfesor
 *	       
**/

#include<bits/stdc++.h>

using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
typedef vector <lli> vl;
typedef vector <string> vs;
typedef vector < pair <long, long> > vll;
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(lli i=0; i<n; i++)
#define rep(i,k,n) for (lli i = k; i < n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

// Printing Data :
#define pvec(v) forz(i,v.si) cout<<v[i]<<" "; cout<<endl;
#define parr(arr, n) forz(i,n) cout<<arr[i]<<" "; cout<<endl;
#define p1(i) cout<<i<<endl;
#define p2(i, j) cout<<i<<" "<<j<<endl;
#define p3(i, j, k) cout<<i<<" "<<j<<" "<<k<<endl;
#define p4(i, j, k, l) cout<<i<<" "<<j<<" "<<k<<" "<<l<<endl;

typedef pair <lli,lli> pll;
 
// CODE BEGINS :

int main()
{
    kira; 

    lli n, k; cin>>n>>k;

    set <lli> s;
    forz(i, k)
    {
        lli t; cin>>t;

        forz(i, t)
        {
            lli te; cin>>te;
            s.insert(te);
        }
    }

    p1(n-s.si);

    return 0;
}




















































Measured memory_bytes: 3656
#include <bits/stdc++.h>
typedef long long int ll;
 
using namespace std;
// {{{ Modint
// using mint = modint<1000000007>;
// mint x = 2;
// std::cout << x.a << std::endl;
template <std::int64_t M>
class modint {
public:
  int64_t a;
 
  explicit constexpr modint(const int64_t x = 0) noexcept :
    a((x % M + M) % M) {}
  constexpr int64_t &value() noexcept { return a; }
  constexpr const int64_t &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= M) {
      a -= M;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += M;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % M;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    int64_t exp = M - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
  constexpr modint pow(ll t) const {
    if (!t) return modint(1);
    modint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};
// }}}
using mint = modint<1000000007>;
 
ll Y, X, N;
vector<pair<int, int>> b;
 
mint fact[200000], invfact[200000];
 
// dp[i]: スタートから他のblockを経由しない block i への経路数
mint dp[4000];
 
// block j から block i への経路数
mint route(int j, int i){
  int dy = b[i].first - b[j].first;
  int dx = b[i].second - b[j].second;
  if (dy < 0 || dx < 0)
    return mint(0);
  return fact[dx+dy] * invfact[dx] * invfact[dy];
}
 
// スタートから block i への経路数
mint route(int i){
  int dy = b[i].first;
  int dx = b[i].second;
  return fact[dx+dy] * invfact[dx] * invfact[dy];
}
 
int main() {
  fact[0] = fact[1] = mint(1);
  invfact[0] = invfact[1] = mint(1);
  for (int i=2; i<200000; i++) {
    fact[i] = fact[i-1] * mint(i);
    invfact[i] = mint(1) / fact[i];
  }
 
  cin >> Y >> X >> N;
 
  for (int i=1; i<=N; i++) {
    int y, x;
    cin >> y >> x;
    y--; x--;
    b.emplace_back(y, x);
  }
  b.emplace_back(Y-1, X-1);
  sort(begin(b), end(b));
 
  for (int i=0; i<=N; i++) {
    dp[i] = route(i);
    for (int j=0; j<i; j++) {
      dp[i] -= dp[j] * route(j, i);
    }
  }
 
  cout << dp[N].value() << endl;
  return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.BitSet;
import java.io.IOException;
import java.util.Arrays;
import java.util.GregorianCalendar;
import java.lang.StringBuffer;
import java.lang.String;
import java.lang.StringBuilder;


public class Main {

    static BigInteger modulo = new BigInteger("1000000007");
//    Nested ststic class FastReaders

    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException io) {
                    io.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String nextLine() {
            String s = "";
            try {
                s = br.readLine();
            } catch (IOException io) {
                io.printStackTrace();
            }
            return s;
        }
    }

    static BigInteger exponentialModulo(BigInteger a, BigInteger b) {
        BigInteger previousNumber = BigInteger.ONE;
        while (!(b.equals(BigInteger.valueOf(0)))) {
            if (b.testBit(0)) {
                previousNumber = previousNumber.multiply(a).mod(modulo);
            }
            b = b.shiftRight(1);
            a = a.modPow(BigInteger.valueOf(2), modulo);
        }
        return previousNumber;
    }

    public static int encodeInteger(int x, int n) {
        n = n << (1 << (1 << (1 << 1)));
        x = x | n;
        return x;
    }

    public static void encodeArray(int[] A, int[] B, int n) {
        for (int i = 0; i < n; i++) {
            A[i] = encodeInteger(A[i], B[i]);
        }
    }

    public static void main(String[] args) throws IOException {
        FastReader input = new FastReader();      
        int R = input.nextInt();
        int G = input.nextInt();
        int B = input.nextInt();
        int N = input.nextInt();
        int count = 0;
        for(int r = 0;r <= N;++r){
            for(int g = 0;g <= N;++g){
                if((r*R+g*G) <= N && (N-(r*R)-(g*G))%B == 0)
                    ++count;
            }
        }
        System.out.println(count);
    }

}


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

bool v[1005];
int a[1005];

int main()
{
  int n;

  scanf("%d",&n);

  for (int i = 0;i < n;i++)
  {
    scanf("%d",a+i);
    v[a[i]] = 1;
  }

  int cnt = 0;

  for (int i = 0;i <= 1000;i++)
  {
    if (v[i]) a[cnt++] = i;
  }

  int minn = 100000000;

  for (int i = 0;i < cnt;i++)
  {
    int ans = a[i] - a[0];
    ans += a[cnt-1] - a[i];

    if (ans < minn) minn = ans;
  }

  printf("%d\n",minn);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';
int mod = 1e9 + 7;
ll inf = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    char t[112345], u[112345];
    for (int i = 0; i < n;i++){
        if(i%2==0){
            t[i] = '1', u[i] = '0';
        }
        else
            t[i] = '0', u[i] = '1';
    }
    int a = 0, b = 0;
    for (int i = 0; i < n;i++){
        if(s[i]!=t[i])
            a++;
            if(s[i]!=u[i])
                b++;
    }
    cout << min(a, b) << endl;
    return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


template<class Int> static Int rng(Int a, Int b) {
  static mt19937 mt(chrono::steady_clock().now().time_since_epoch().count());
  assert(a < b);
  return uniform_int_distribution<Int>(a, b - 1)(mt);
}

namespace RandomizedBinarySearchTree {
  using T = int;
  struct Node;
  using Tree = Node*;

  constexpr T inf = 1e9;
  
  struct Node {
    T a, val;
    Tree cl, cr;
    int n;
    Node(const T& a = inf) :
      a(a), val(a), cl(nullptr), cr(nullptr), n(1) {}
  };

  static Tree update(Tree t) {
    t->n = (t->cl ? t->cl->n : 0) + 1 + (t->cr ? t->cr->n : 0);
    t->val = min<T>({t->cl ? t->cl->val : inf, t->a, t->cr ? t->cr->val : inf});
    return t;
  }

  static Tree merge(Tree tl, Tree tr) {
    if (!tr) return tl;
    if (!tl) return tr;
    if (rng(0, tl->n + tr->n) < tl->n) {
      tl->cr = merge(tl->cr, tr);
      return update(tl);
    } else {
      tr->cl = merge(tl, tr->cl);
      return update(tr);
    }
  }

  static pair<Tree, Tree> split(Tree t, int i) {
    if (!t) return {nullptr, nullptr};
    int nl = t->cl ? t->cl->n : 0;
    if (i <= nl) {
      Tree resl;
      tie(resl, t->cl) = split(t->cl, i);
      return {resl, update(t)};
    } else {
      Tree resr;
      tie(t->cr, resr) = split(t->cr, i - nl - 1);
      return {update(t), resr};
    }
  }

  static Tree insert(Tree t, int i, const T& a) {
    Tree tl, tr;
    tie(tl, tr) = split(t, i);
    return merge(merge(tl, new Node(a)), tr);
  }

  static Tree erase(Tree t, int i) {
    Tree tl, tr;
    tie(tl, tr) = split(t, i);
    tr = split(tr, 1).second;
    return merge(tl, tr);
  }
};

using namespace RandomizedBinarySearchTree;

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  Tree t = nullptr;
  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    t = insert(t, i, a);
  }
  for (int _ = 0; _ < q; ++_) {
    int type; cin >> type;
    if (type == 0) {
      int l, r; cin >> l >> r, ++r;
      Tree tl, tm, tr;
      tie(tm, tr) = split(t, r);
      tie(tl, tm) = split(tm, l);
      Tree tml, tmr;
      tie(tml, tmr) = split(tm, r - l - 1);
      tm = merge(tmr, tml);
      t = merge(merge(tl, tm), tr);
    } else if (type == 1) {
      int l, r; cin >> l >> r, ++r;
      Tree tl, tm, tr;
      tie(tm, tr) = split(t, r);
      tie(tl, tm) = split(tm, l);
      cout << tm->val << '\n';
      t = merge(merge(tl, tm), tr);
    } else {
      int i, a; cin >> i >> a;
      t = erase(t, i);
      t = insert(t, i, a);
    }
  }
}


Measured memory_bytes: 15724
#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <string>
#include <vector>
typedef long long ll;

using namespace std;

const int size = 50;
ll dp[size+1][size+1][size*50+1];

int main(){
    int N, A;
    cin >> N >> A;
    int x[size+1] = {0};
    for (int i = 0; i < N; i++) cin >> x[i+1];

    dp[0][0][0] = 1;

    for (int i = 1; i <= N; i++){
	for (int j = 0; j <= i; j++){
	    for (int k = 0; k <= N*A; k++){
		if (k < x[i]){
		    dp[i][j][k] = dp[i-1][j][k];
		} else if ((j >= 1) && (k >= x[i])){
		    dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k-x[i]];
		}
	    }
	}
    }

    ll res = 0;
    for (int i = 1; i <= N; i++){
	res += dp[N][i][i*A];
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 49024