akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

bool ac[100010];
int wa[100010];
int main()
{
	int N, M;
	cin >> N >> M;
	int W = 0;
	for (int i = 0; i < M; i++) {
		int P;
		string S;
		cin >> P >> S;
		if (S == "AC" && !ac[P]) {
			W += wa[P];
			ac[P] = true;
		}
		if (!ac[P] && S == "WA") {
			wa[P]++;
		}
	}
	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (ac[i]) ans++;
	}
	cout << ans << " " << W << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

map<ll, ll> mp;
ll a, b, c, d;

ll solve(ll n) {
	if (n == 0) return mp[n] = 0;
	if (n == 1) return mp[n] = d;
	if (mp[n]) return mp[n];
	ll res = INF;
	if (n < 3 * INF / d) res = n * d;
	chmin(res, solve(n / 2) + n % 2 * d + a);
	if (n & 1) chmin(res, solve(n / 2 + 1) + (2 - n % 2) * d + a);
	if (n % 3 < 2) chmin(res, solve(n / 3) + n % 3 * d + b);
	else chmin(res, solve(n / 3 + 1) + (3 - n % 3) * d + b);
	if (n % 5 < 3) chmin(res, solve(n / 5) + n % 5 * d + c);
	else chmin(res, solve(n / 5 + 1) + (5 - n % 5) * d + c);
	return mp[n] = res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int t;
	cin >> t;
	while (t--) {
		ll n;
		cin >> n >> a >> b >> c >> d;
		map<ll, ll> cl;
		mp = cl;
		cout << solve(n) << '\n';
	}
}

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

vector<int> to[2505];
vector<int> ot[2505];
bool reachable_from_1[2505];
bool reachable_to_N[2505];
bool ok[2505];

const int INF = 1001001001;

void dfs(int v) {
    if (reachable_from_1[v]) return;
    reachable_from_1[v] = true;
    for (int u : to[v]) {
        dfs(u);
    }
}

void sfd(int v) {
    if (reachable_to_N[v]) return;
    reachable_to_N[v] = true;
    for (int u : ot[v]) {
        sfd(u);
    }
}

int main() {
    int n, m, p; cin >> n >> m >> p;
    vector<tuple<int, int, int>> edges;
    for (int i = 0; i < m; i++) {
        int a, b, c; cin >> a >> b >> c;
        a--; b--; c -= p; c = -c;
        edges.emplace_back(a, b, c);
        to[a].push_back(b);
        ot[b].push_back(a);
    }
    dfs(0);
    sfd(n-1);
    for (int i = 0; i < n; i++) {
        ok[i] = reachable_from_1[i] & reachable_to_N[i];
    }
    { // bellman-ford法
        vector<int> dist(n, INF);
        dist[0] = 0;
        bool update = true;
        int step = 0;
        while (update) {
            update = false;
            for (int i = 0; i < m; i++) {
                int a, b, c;
                tie(a, b, c) = edges[i];
                if (!ok[a]) continue;
                if (!ok[b]) continue;
                int newD = dist[a] + c;
                if (newD < dist[b]) {
                    dist[b] = newD;
                    update = true;
                }
            }
            step++;
            if (n < step) {
                cout << -1 << endl;
                return 0;
            }
        }
        int ans = -dist[n-1];
        ans = max(0, ans);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 768
#pragma comment(linker, "/stack:247474112")
#pragma GCC optimize("Ofast")

#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <stack>
#include <queue>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define T3I tuple<int, int, int>
#define x first
#define y second
using namespace std;

typedef long long ll;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;

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

    string s;
    cin >> s;
    int Q;
    cin >> Q;
    int flg = 0;
    stack<char> S;
    for(int i = 0; i < Q; ++i) {
        int t;
        cin >> t;
        if(t == 1) {
            flg ^= 1;
        }else {
            int f;
            char c;
            cin >> f >> c;
            if((f == 1 && flg == 0) || (f == 2 && flg == 1)) {
                S.push(c);
            }else {
                s += c;
            }
        }
    }
    string res;
    while(!S.empty()) {
        res += S.top();
        S.pop();
    }
    res += s;
    if(flg) {
        for(int i = (int)res.size()-1; i >= 0; --i) cout << res[i]; cout << endl;
    }else {
        cout << res << endl;
    }
}


Measured memory_bytes: 1272
using System;
using System.Collections.Generic;
using System.Linq;
class a{
  public static void Main(){
    int[] num = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
    int ans = 1;
    foreach(int i in num){
      if(i==0){
        Console.WriteLine(ans);
        break;
      }
      ans++;
    }
  }
}


Measured memory_bytes: 18968
import java.util.Scanner;

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

		while(true) {
			int n = sc.nextInt();
			if (n == 0) return;
			String a[] = new String[n];
			int count = 0;
			for (int i = 0; i < n; i++) {
				a[i] = sc.next();
			}
			loop: for (int i = 0; i < n; i++) {
				int sum = 0, k = i;
				while(sum < 5) {
					sum += a[k++].length();
					//System.out.println(sum);
					if (sum > 5) continue loop;
					if (sum == 5) break;
				}
				sum = 0;
				while(sum < 7) {
					sum += a[k++].length();
					//System.out.println(sum);
					if (sum > 7) continue loop;
					if (sum == 7) break;
				}
				sum = 0;
				while(sum < 5) {
					sum += a[k++].length();
					//System.out.println(sum);
					if (sum > 5) continue loop;
					if (sum == 5) break;
				}
				sum = 0;
				while(sum < 7) {
					sum += a[k++].length();
					//System.out.println(sum);
					if (sum > 7) continue loop;
					if (sum == 7) break;
				}
				sum = 0;
				while(sum < 7) {
					sum += a[k++].length();
					//System.out.println(sum);
					if (sum > 7) continue loop;
					if (sum == 7) break;
				}
				System.out.println(i+1);
				break;
			}
		}
	}
}


Measured memory_bytes: 32320
from collections import deque
def solve():
    N = int(input())
    X = [0]*N
    Y = [0]*N
    balls = [0]*N
    ans = N
    dic = {}
    f = {}
    for i in range(N):
        X[i],Y[i] = map(int, input().split())
        dic[(X[i],Y[i])] = i
        balls[i] = [X[i],Y[i]]
    
    balls = sorted(balls, key=lambda x:(x[0],x[1]))

    for x1, y1 in zip(X,Y):
        for x2, y2 in zip(X,Y):
            p = x2 - x1
            q = y2 - y1
            if p == 0 and q == 0:
                continue
            collected = [False]*N
            collected[dic[(x1,y1)]]=True
            collected[dic[(x2,y2)]]=True
            d = deque(balls)
            cnt = 1
            x = x2 + p
            y = y2 + q
            while (x,y) in dic:
                collected[dic[(x,y)]] = True
                x += p
                y += q
            while len(d)>0: 
                if p<0 or p==0 and q<0:
                    x,y = d.pop()
                else:
                    x,y = d.popleft()
                if collected[dic[(x,y)]] == True:
                    continue
                cnt += 1
                while (x,y) in dic:
                    collected[dic[(x,y)]] = True
                    x += p
                    y += q
            ans = min(ans, cnt)
    return ans
print(solve())

Measured memory_bytes: 3316
using System;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            var N = int.Parse(input);
            bool result = false;
            for(int A = 1;A<10; A++)
            {
              for(int B = 1;B<10;B++)
              {
                if(N == A*B)
                {
                  result = true;
                  break;
                }
              }
            }
          	Console.WriteLine(result?"Yes":"No");
          
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define IL inline
#define ll long long
using namespace std;

IL int gi(){
	int data=0,fu=1; char ch=0; while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')fu=-1,ch=getchar();
	while('0'<=ch&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar(); return data*fu;
}

bitset<405>Need[405]; int n,m,a[100005],b[100005],Ans; bool vis[405],flag;
int main(){
	n=gi(); m=gi();
	for(int i=1;i<=m;++i)a[i]=gi(),b[i]=gi();
	for(int x=1;x<=n;++x)Need[x][x]=1;
	for(int x=1;x<=n;++x){
		for(int i=1;i<=n;++i)vis[i]=false; flag=true;
		vis[x]=true; 
		for(int i=m;i>=1;--i){
			if(vis[a[i]]&&vis[b[i]]){flag=false;break; }
			else if(vis[a[i]])Need[x][b[i]]=1,vis[b[i]]=true;
			else if(vis[b[i]])Need[x][a[i]]=1,vis[a[i]]=true;
		}
		if(!flag)Need[x].set();
	}
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)if(!(Need[i]&Need[j]).count())++Ans; 
	cout<<Ans<<endl;
	return 0; 
}

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

ll N, A, B;
vector<ll> v;

vector<vector<ll>> comb(int N) {
  vector<vector<ll>> c(N + 1, vector<ll>(N + 1, 0));
  for (int i = 0; i < N + 1; i++) {
    c[i][0] = 1;
    c[i][i] = 1;
  }
  for (int i = 1; i < N + 1; i++) {
    for (int j = 1; j < i; j++) {
      c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
    }
  }
  return c;
}

void solve() {
  sort(v.rbegin(), v.rend());

  ll sum = 0;
  for (int i = 0; i < A; i++) {
    sum += v[i];
  }

  long double aver = (long double)sum / A;
  cout << fixed << aver << "\n";

  vector<vector<ll>> c = comb(N + 1);
  ll res = 0;

  ll cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < N; i++) {
    if (v[i] == v[A - 1]) {
      cnt1++;
      if (i < A) {
        cnt2++;
      }
    }
  }
  if (v[0] != v[A - 1]) {
    res += c[cnt1][cnt2];
  }
  else {
    for (int i = A; i <= min(B, cnt1); i++) {
      res += c[cnt1][i];
    }
  }
  cout << res << "\n";
  return;
}

int main() {
  cin >> N >> A >> B;
  v.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			for(int i = 1; i <= 5; i++) {
				int x = sc.nextInt();
				if (x == 0) {
					System.out.println(i);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 35728
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

macro_rules! eprint(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = write!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! eprintln(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! dbg {
    ($val:expr) => {
        // Use of `match` here is intentional because it affects the lifetimes
        // of temporaries - https://stackoverflow.com/a/48732525/1063961
        match $val {
            tmp => {
                eprintln!(
                    "[{}:{}] {} = {:#?}",
                    file!(),
                    line!(),
                    stringify!($val),
                    &tmp
                );
                tmp
            }
        }
    };
}

#[inline]
fn pow(mut base: i64, mut exp: u32) -> i64 {
    let mut acc = 1;
    while exp > 1 {
        if (exp & 1) == 1 {
            acc = acc * base;
        }
        exp /= 2;
        base = base * base;
    }
    if exp == 1 {
        acc = acc * base;
    }
    acc
}

fn main() {
    input! {
        n: u64,
        m: u64,
    }

    let x = 1900 * m + 100 * (n - m);
    let p = pow(2, m as u32) as u64;

    println!("{}", x * p);
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;

int main(){
  int a, b, c;
  cin >> a >> b;
  c = a + b;
  cout << (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0 ? "Possible" : "Impossible") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
class Dice{
private:
	int top, front, right, left, back, bottom;
	void rollNorth(){
		int temp = back;
		back = top;
		top = front;
		front = bottom;
		bottom = temp;
	}
	void rollSouth(){
		int temp = back;
		back = bottom;
		bottom = front;
		front = top;
		top = temp;
	}
	void rollEast(){
		int temp = right;
		right = top;
		top = left;
		left = bottom;
		bottom = temp;
	}
	void rollWest(){
		int temp = left;
		left = top;
		top = right;
		right = bottom;
		bottom = temp;
	}
	void rollChoice(char dir){
		switch (dir)
		{
		case 'E':
			rollEast();
			break;
		case 'N':
			rollNorth();
			break;
		case 'W':
			rollWest();
			break;
		case 'S':
			rollSouth();
			break;
		}
	}
public:

	void readLabel(){
		cin >> top >> front >> right >> left >> back >> bottom;
	}
	void roll(){
		char dir;
		while (cin >> dir){
			rollChoice(dir);
		}
	}
	int getTop(){
		return top;
	}
};
int main(){
	Dice dice;
	dice.readLabel();
	dice.roll();
	cout << dice.getTop() << endl;
	return 0;
}

Measured memory_bytes: 3076
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
a = LIST()
mode = 0 #0未決定 1増加 2減少
ans = 1
f = a[0]
for i in range(1, n):
    if mode == 0 and a[i] == f:
        pass
    elif mode == 0 and a[i] < f:
        mode = 2
        f = a[i]
    elif mode == 0 and a[i] > f:
        mode = 1
        f = a[i]
    elif mode == 1 and a[i] == f:
        pass
    elif mode == 1 and a[i] > f:
        f = a[i]
    elif mode == 1 and a[i] < f:
        ans += 1
        mode = 0
        f = a[i]
    elif mode == 2 and a[i] == f:
        pass
    elif mode == 2 and a[i] > f:
        ans += 1
        mode = 0
        f = a[i]
    elif mode == 2 and a[i] < f:
        f = a[i]
print(ans)

Measured memory_bytes: 84076
# -*- coding: utf-8 -*-
from sys import stdin
import math

while True:
    n = int(stdin.readline().rstrip())
    if n == 0:
        break
    l = list(map(int, stdin.readline().split()))
    s = 0
    for i in l:
        s += i
    m = s / n
    a = 0
    for i in l:
       a += math.pow((i - m),2)
    variance = a / n
    stdev = math.sqrt(variance)
    print('{0:.8f}'.format(stdev))



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

int main(){
    int a,b; char c;
    cin>>a>>c>>b;
    if(c=='+')cout<<a+b<<endl;
    else cout<<a-b<<endl;
    return 0;
}

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

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    LL N, A, B;
    cin >> N >> A >> B;
    if (A > B) swap(A, B);
    if ((A - B) % 2 == 0) {
        cout << (B - A) / 2 << endl;
    } else {
        LL ans1, ans2;
        LL na = 1, nb = B - A;
        ans1 = (nb - na) / 2 + A;
        na = A + (N - B + 1), nb = N;
        ans2 = (nb - na) / 2 + (N - B + 1);
        cout << min(ans1, ans2) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll H;
    sll(H);
    ll num = 0;
    ll powered = 1;
    while(H>=1){
        H /= 2;
        num += powered;
        powered *= 2;
    }

    cout << num << endl;

}

int main(){
    Main();
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
 cin >> N;
 vector <int> A(N); 
  for(int i = 0; i < N; i++){
   cin >> A.at(i) ;
  }
 sort(A.begin(), A.end());
 cout << A.at(N-1) - A.at(0) << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
 		
int main() {

int A,B,C;
cin>>A>>B>>C;
	int D=max({A,B,C});
	int ans=0;
	ans+=(D-A)/2+(D-B)/2+(D-C)/2;
	int k=(D-A)%2+(D-B)%2+(D-C)%2;
	if(k==0){
		ce(ans)
	}else if(k==1){
		ce(ans+2)
	}else{
		ce(ans+1)
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
typedef long long int ll;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

typedef long long int ll;

#define MOD 1000000007
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
ll gcd(ll a, ll b) { ll x, y; return extgcd(a, b, x, y);}

class llm{
	ll n;
public:
	llm(){n = 0;}
	llm(ll n){this->n = (n >= 0) ? (n % MOD) : (MOD - 1 - (-n-1 % MOD));}
	operator ll() const {return n;}
	llm operator+(const llm &y) const{ return llm((ll)*this + (ll)y);}
	llm operator+=(const llm &y) { *this = *this + y; return *this;}
	llm operator-(const llm &y) const{ return llm((ll)*this - (ll)y);}
	llm operator-=(const llm &y) { *this = *this - y; return *this;}
	llm operator-() const{ return llm(0) - *this;}
	llm operator*(const llm &y) const{ return llm((ll)*this * (ll)y);}
	llm operator*=(const llm &y) { *this = *this * y; return *this;}
	llm operator/(const llm &y) const{ return *this * y.inv();}
	llm operator/=(const llm &y) { *this = *this / y; return *this;}
	llm inv() const{
		ll x, y;
		if (extgcd(n, MOD, x, y) == 1) return llm(x);
  		return llm(0); // unsolvable
	}
	friend istream& operator >> (istream& os, llm& x);
	friend ostream& operator << (ostream& os, const llm& x);
};
istream& operator >> (istream& is, llm& x){ll n; is >> n; x = llm(n); return is;}
ostream& operator << (ostream& os, const llm& x){os << (ll)x; return os;}

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



ll B, W;
int main(void){
	
	cin >> B >> W;
	bool flg = false;

	if (B < W){
		swap(B,W);
		flg = true;
	}

	vector<llm> ue;
	ue.pb(llm(1));
	llm nico = 1;
	for(int i=0;i<B;i++){
		nico = (nico * llm(W+i)) / llm(1+i);
		ue.pb(ue[i] * llm(2) + nico);
	}
	vector<llm> migi;
	migi.pb(llm(1));
	nico = 1;
	for(int i=0;i<W;i++){
		nico = (nico * llm(B+i)) / llm(1+i);
		migi.pb(migi[i] * llm(2) + nico);
	}	
	vector<llm> ans;
	llm p = 1;
	for(int i=0;i<W;i++){
		ans.pb(llm(1)/llm(2));
		p *= 2;
	}
	for(int i=W;i<B;i++){
		ans.pb((p + ue[i-W]) / (p * llm(2)));
		p *= 2;
	}
	for(int i=B;i<W+B;i++){
		ans.pb((p + ue[i-W] - migi[i-B]) / (p * llm(2)));
		p *= 2;
	}

	if (flg){
		for(int i=0;i<ans.size();i++){
			ans[i] = llm(1) - ans[i];
		}	
	}
	for(int i=0;i<ans.size();i++){
		cout << ans[i] << endl;
	}

    return 0;
}


Measured memory_bytes: 5488
#include <iostream>

using namespace std;

#define N 8
#define FREE -1
#define NOT_TREE 1

int row[N], col[N], dpos[2*N-1], dneg[2*N-1];

bool X[N][N];

void initialize(){
	for(int i=0;i < N;++i){ row[i] = FREE, col[i] = FREE;}
	for(int i=0;i < 2*N-1;++i){ dpos[i] = FREE, dneg[i] = FREE; }
	for(int i=0;i < N;++i){
		for(int j=0;j < N;++j) X[i][j] = false;
	}
}

void print(){
	for(int i=0;i < N;++i){
		for(int j=0;j < N;++j){
			if(X[i][j]){
				if(row[i] != j) return;
			}
		}
	}
	for(int i=0;i < N;++i){
		for(int j=0;j < N;++j){
			cout << ((row[i] == j) ? "Q" : ".");
		}
		cout << "\n";
	}
}

void recursive(int i){
	if(i == N){
		print();
		return;
	}
	
	for(int j=0;j < N;++j){
		if(NOT_TREE == col[j] || NOT_TREE == dpos[i+j] || NOT_TREE == dneg[i-j+N-1])continue;
		row[i] = j, col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_TREE;
		recursive(i+1);
		row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
	}
}

int main(){
	initialize();
	
	int k; cin >> k;
	for(int i=0;i < k;++i){
		int r, c; cin >> r >> c;
		X[r][c] = true;
	}
	
	recursive(0);
	
	return 0;
}


Measured memory_bytes: 3100
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(v) v.begin(),v.end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ll n,m;
    cin>>n>>m;
    bool done[n]={false};
    ll ww[n]={0};
    ll wrong=0,right=0;
    rep(a,0,m)
    {
		ll p;
		cin>>p;
		string s;
		cin>>s;
		p--;
		if(s=="AC")
		{
			if(!done[p]){
				done[p]=true;
				right++;
				wrong+=ww[p];
			}
		}
		else
		{
			if(!done[p])
				ww[p]++;
		}
	}
	cout<<right<<" "<<wrong<<endl;
	return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
  }
  int top() {
    return s[0];
  }
};
int main(){
  Dice d;
  for(int i=0;i<6;i++) cin >> d.s[i];
  string s;cin >> s;
  for(int i=0;i<(int)s.size();i++) d.roll(s[i]);
  cout << d.top() << endl;
  return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    string s1, s2;
    int flag = 0;
    string t1 = "..##";
    string t2 = ".#.#";
    string c;
    rep(i,n){
        if(flag == 0){
            rep(j,4){
                cout << s1 << t1[j] << endl;
                cout << s2 << t2[j] << endl;
                fflush(stdout);
                cin >> c;
                if(c[0] == 'T'){
                    s1 += t1[j];
                    s2 += t2[j]; 
                    break;
                }
            }
        }
        if(s1.size() == i)flag = 1;
        if(flag){
            rep(j,4){
                cout << t1[j] << s1 << endl;
                cout << t2[j] << s2 << endl;
                fflush(stdout);
                cin >> c;
                if(c[0] == 'T'){
                    s1 = t1[j] + s1;
                    s2 = t2[j] + s2; 
                    break;
                }
            }
        }
    }

    cout << s1 << endl << s2 << endl;

    return 0;
}

 


Measured memory_bytes: 724
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==0)
				return;
			Point p[]=new Point[n];
			for(int i=0;i<n;i++)
				p[i]=new Point(in.nextDouble(), in.nextDouble());
			int max=1;
			for(int i=0;i<n;i++)
				for(int j=i+1;j<n;j++)
				{
					double d=Point.point_distance(p[i],p[j]);
					if(d>2)
						continue;
					//中点
					double mx=(p[i].x+p[j].x)/2;
					double my=(p[i].y+p[j].y)/2;
					//i->jの単位ベクトル
					double vx=(p[j].x-p[i].x)/d;
					double vy=(p[j].y-p[i].y)/d;
					//m->cの距離
					double e=Math.sqrt(1-d*d/4);
					Point pc=new Point(mx+e*vy,my-e*vx);
					int cnt=2;
					for(int k=0;k<n;k++)
					{
						if(k!=i&&k!=j)
						{
							double tmp_dis=(pc.x-p[k].x)*(pc.x-p[k].x)+(pc.y-p[k].y)*(pc.y-p[k].y);
							if(tmp_dis<=1)
								cnt++;
						}
					}
					pc=new Point(mx-e*vy,my+e*vx);
					cnt=2;
					for(int k=0;k<n;k++)
					{
						if(k!=i&&k!=j)
						{
							double tmp_dis=(pc.x-p[k].x)*(pc.x-p[k].x)+(pc.y-p[k].y)*(pc.y-p[k].y);
							if(tmp_dis<=1)
								cnt++;
						}
					}
					max=Math.max(max,cnt);
				}
			System.out.println(max);
		}
	}

	static public void debug(Object... o)
	{
		System.err.println(Arrays.deepToString(o));
	}
}

class Point
{
	double x;
	double y;
	Point(double x,double y)
	{
		this.x=x;
		this.y=y;
	}

	//線分p1-p2と線分p3-p4が交差しているかを判定 true->交差(=含みで接する含む) false->交差せず
	static boolean lineCross(Point p1,Point p2,Point p3,Point p4)
	{
		double a=(p1.x-p2.x)*(p3.y-p1.y)+(p1.y-p2.y)*(p1.x-p3.x);
		double b=(p1.x-p2.x)*(p4.y-p1.y)+(p1.y-p2.y)*(p1.x-p4.x);
		double c=(p3.x-p4.x)*(p1.y-p3.y)+(p3.y-p4.y)*(p3.x-p1.x);
		double d=(p3.x-p4.x)*(p2.y-p3.y)+(p3.y-p4.y)*(p3.x-p2.x);
		return a*b<=0 && c*d<=0;
	}

	//クラスメソッド
	static double point_distance(Point p1,Point p2)
	{
		return Math.hypot(p1.x-p2.x, p1.y-p2.y);
	}
}

Measured memory_bytes: 58172
#include<stdio.h>
int main()
{
  int n;
  scanf("%d",&n);
  long i,a[n],r,tool=0;
  for(i=0;i<n;i++)
    scanf("%ld ",&a[i]);
  for(i=1;i<n;i++)
  {
    if(a[i]>=a[i-1])
      continue;
    else
    {
      r=a[i-1]-a[i];
      a[i]+=r;
      tool+=r;
    }
  }
  printf("%ld",tool);
}

Measured memory_bytes: 3288
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt();
    long sum=0;
    for(int i=1;i<=n;i++){
      if(i%3!=0&&i%5!=0){
        sum+=(long)i;
      }
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 35712
S = ["" for i in range(3)]
abc = "ABC"
for i in range(3):
    S[i] = input()
    


turn = 0
zero_card = False
while True:
    if len(S[turn]) == 0:
        print(abc[turn])
        break
    else:
        next_turn = 0
        if S[turn][0] == "a":
            next_turn = 0
        elif S[turn][0] == "b":
            next_turn = 1
        else:
            next_turn = 2
        S[turn] = S[turn][1:]
        turn = next_turn

Measured memory_bytes: 3064
import math
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()

for i in range(N):
    A[i] -= i+1
A = sorted(A)

if N%2 == 1:
    medR = A[N//2]
    medL = A[N//2]
else:
    medR = math.ceil((A[N//2-1]+A[N//2])/2)
    medL = (A[N//2-1]+A[N//2])//2
    
ansR, ansL = 0, 0
for i in A:
    ansR += abs(i-medR)
    ansL += abs(i-medL)

print(min(ansR,ansL))

Measured memory_bytes: 26608
#include <bits/stdc++.h>
   
#define ll long long
#define F first
#define S second
#define pb push_back
using namespace std;
   
void data() {
    #ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
} 
const int N = 1e6 + 200;
const int ll mod = 1e9 + 7;
map<string,int> a;
int main ()
{
    data();          
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		string s;
		cin >> s;
		a[s]++;
	}
	cout << "AC x " << a["AC"] << '\n';
	cout << "WA x " << a["WA"] << '\n';
	cout << "TLE x " << a["TLE"] << '\n';
	cout << "RE x " << a["RE"] << '\n';
}

Measured memory_bytes: 3600
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
int a[200010];
int main()
{
    int n;
    cin >> n;

    long long  sum = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        a[0] = a[1];
        if (a[i] < a[i - 1])
        {
            sum += a[i - 1] - a[i];
            a[i] = a[i - 1];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 4372
using System;

namespace AtCoder
{
	class Program
    {
    	public static void Main()
        {
        	string[] str = Console.ReadLine().Split();
          long X = long.Parse(str[0]);
          long A = long.Parse(str[1]);
          long B = long.Parse(str[2]);
          
          if(A >= B)
          {
          	Console.WriteLine("delicious");
          }
          else if(A < B && B-A <= X)
          {
          	Console.WriteLine("safe");
          }
          else
          {
          	Console.WriteLine("dangerous");
          }
        }
    }
}

Measured memory_bytes: 11092
S = input()
ec = 0
c = {}
for each in S:
    try:
        c[each] += 1
        if c[each] % 2 == 0:
            ec -= 1
        else:
            ec += 1
    except:
        c[each] = 1
        ec += 1
if (ec == 0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>

using namespace std;

char s[200][201];
int a[200][200];
int f[200];

int main() {
    int n, ans = 0, i, j, k;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%s", s[i]);
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            if (i == j) {
                a[i][j] = 0;
            } else if (s[i][j] == '1') {
                a[i][j] = 1;
            } else {
                a[i][j] = 1e9;
            }
        }
    }
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            for (k = 0; k < n; k++) {
                a[j][k] = min(a[j][k], a[j][i] + a[i][k]);
            }
        }
    }
    
    for (i = 0; i < n; i++) f[i] = a[0][i] % 2;
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            if ((a[i][j] % 2 == 0 && f[i] != f[j]) || (a[i][j] % 2 == 1 && f[i] == f[j])) {
                puts("-1");
                
                return 0;
            }
            
            ans = max(ans, a[i][j]);
        }
    }
    
    printf("%d\n", ans + 1);
    
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}


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

const int N = 110;

int a[N];

int main(){
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++ i){
        scanf("%d", &a[i]);
    }
    std::sort(a, a + n);
    int cnt = 0;
    for (int i = 0; i < n; ++ i){
        for (int j = i + 1; j < n; ++ j){
            for (int k = j + 1; k < n; ++ k){
                if (a[i] == a[j] || a[j] == a[k]){
                    continue;
                }
                cnt += a[i] + a[j] > a[k];
            }
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 3824
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
//#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
int power(int x, unsigned int y)
{
    int res = 1;

    x = x;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);

        y = y>>1;
        x = (x*x);
    }
    return res;
}
bool isprime(int x)
{
      if(x<2)
        return false;
    for(int i=2;i*i<=x;i++)
     {
        if (x%i==0)
            return false;
    }
    return true;
}
vector<int>primeFactors(int n)
{
    vector<int>v;
    int x=0;
    while (n % 2 == 0)
    {
        x++;
        n = n/2;
        v.pb(2);
    }
    //if(x>0)
    //v.pb({2,x});
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        int y=0;
        while (n % i == 0)
        {
            y++;
            n = n/i;
            v.pb(i);
        }
        //if(y>0)
        //v.pb({i,y});
    }
    if (n > 2)
        v.pb(n);
    return v;
}

vector<int>leastPrimeFactor(int n)
{
    vector<int>least_prime(n);
    // Create a vector to store least primes.
    // Initialize all entries as 0.
    // We need to print 1 for 1.
    least_prime[1] = 1;

    for (int i = 2; i <= n; i++)
    {
        // least_prime[i] == 0
        // means it i is prime
        if (least_prime[i] == 0)
        {
            // marking the prime number
            // as its own lpf
            least_prime[i] = i;

            // mark it as a divisor for all its
            // multiples if not already marked
            for (int j = 2*i; j <= n; j += i)
                if (least_prime[j] == 0)
                   least_prime[j] = i;
        }
    }
    return least_prime;
}
int maxSubArraySum(int a[], int size)
{
    int max_so_far = INT_MIN, max_ending_here = 0;

    for (int i = 0; i < size; i++)
    {
        max_ending_here = max_ending_here + a[i];
        if (max_so_far < max_ending_here)
            max_so_far = max_ending_here;

        if (max_ending_here < 0)
            max_ending_here = 0;
    }
    return max_so_far;
}
void solve()
{
string s,t;
cin>>s>>t;
int x=s.size();
int ans=0;
for(int i=0;i<x;i++)
{
    if(s[i]!=t[i])
        ans++;
}
cout<<ans<<endl;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
//cin>>t;
t=1;
while(t--)
{
solve();
}
}



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

using namespace std;

int main(void) {
	int i;
	string s;
	vector<string> ans;
	cin >> s;
	for (i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			ans.push_back("0");
		}
		else if (s[i] == '1') {
			ans.push_back("1");
		}
		else if (ans.size() != 0) {
			ans.pop_back();
		}
	}
	for (i = 0; i < ans.size(); i++) {
		cout << ans[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  cout << max(A + B, max(A - B, A * B)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){	
	ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	    int n;
		cin >> n;
		string s;
		cin >> s;
		for(int i = 0 ; i < s.size() ;i++){
	 		int x = (s[i] - 'A' + n)%26;
	  		cout << char(x + 'A');
		}
		return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
const int MX=100010, inf=2e9;
pli A[MX], B[MX];
int n; ll c;
ll solve(pli R[], pli L[]){
	ll G1[MX]={}, G2[MX]={};
	ll sum=0, moved=0;
	for(int i=1; i<=n; i++){
		sum+=R[i].second, moved=R[i].first;
		ll now=sum-moved;
		G1[i]=now;
	}
	sum=moved=0;
	for(int i=1; i<=n; i++){
		sum+=L[i].second, moved=L[i].first;
		ll now=sum-2*moved;
		G2[i]=now;
	}
	ll mx=0, res=0;
	for(int i=n; i>=1; i--){
		mx=max(mx, G2[n-i]);
		res=max(res, mx+G1[i]);
	}
	return res;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n>>c;
	for(int i=1; i<=n; i++)
		cin>>A[i].first>>A[i].second;
	for(int i=1; i<=n; i++){
		B[i].first=c-A[n-i+1].first;
		B[i].second=A[n-i+1].second;
	}
	cout<<max(solve(A,B), solve(B,A));
	return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define MOD 1000000007LL
using namespace std;

long long int inv(long long int x){
	long long int xpow[30], c[30];
	for(int i=0; i<30; i++){
		if(i==0){
			xpow[i]=x;
			c[i]=1;
		}else{
			xpow[i]=xpow[i-1]*xpow[i-1]%MOD;
			c[i]=c[i-1]*2;
		}
	}
	long long int r=MOD-2, xinv=1;
	for(int i=29;i>=0; i--){
		if(r>=c[i]){
			xinv=xinv*xpow[i]%MOD;
		}
		r=r%c[i];
	}
	return xinv;
}

int main()
{
	long long int n, a, b, c, d;
	scanf("%lld %lld %lld %lld %lld", &n, &a, &b, &c, &d);
	long long int ans[1001]={}, ans1[1001]={};
	ans[0]=1, ans1[0]=1;

	long long int f[1001], invf[1001];
	for(long long int i=0; i<=n;i++){
		if(i==0){
			f[i]=1;
		}else{
			f[i]=i*f[i-1]%MOD;
		}
		invf[i]=inv(f[i]);
	}

	long long int s[1001][1001];
	for(long long int x=a; x<=b; x++){
		for(long long int y=c; y<=d && x*y<=n; y++){
			s[x][y]=f[x*y];
			for(int i=1; i<=y; i++){
				s[x][y]=s[x][y]*invf[x]%MOD;
			}
			s[x][y]=s[x][y]*invf[y]%MOD;
		}
	}

	for(long long int y=c; y<=b && b*y<=n; y++){
		ans[b*y]=s[b][y];
		ans1[b*y]=ans[b*y];
	}
  
	for(long long int x=b-1; x>=a; x--){
      for(long long int m=0; m<=n; m++){
        ans1[m]=ans[m];
      }
		for(long long int m=0; m<=n; m++){
          if(ans[m]!=0){
			for(long long int y=c; y<=d && x*y+m<=n; y++){
				ans1[m+x*y]=(ans1[m+x*y]+ans[m]*f[m+x*y]%MOD*invf[m]%MOD*invf[x*y]%MOD*s[x][y]%MOD)%MOD;
			}
          }
		}
      for(long long int m=0; m<=n; m++){
        ans[m]=ans1[m];
      }
		
	}
	printf("%lld\n", ans[n]);
	return 0;
}

Measured memory_bytes: 6272
// 1_agc038_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

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 SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

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

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

    if(h == 1){
        rep(i, a){
            cout << 1;
        }
        rep(i, w - a){
            cout << 0;
        }
    }else if(w == 1){
        rep(i, b){
            cout << 1 << endl;
        }
        rep(i, h - b){
            cout << 0 << endl;
        }
    }else{
        rep(i, b){
            rep(j, a){
                cout << 1;
            }
            rep(j, w - a){
                cout << 0;
            }
            cout << endl;
        }
        rep(i, h - b){
            rep(j, a){
                cout << 0;
            }
            rep(j, w - a){
                cout << 1;
            }
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>

int main(void){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(a == (b + c))
        printf("Yes\n");
    else if(b == (a + c))
        printf("Yes\n");
    else if(c == (a + b))
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


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

s = [int(input()) for x in range(N)]

fullmax = sum(s)
s_sorted = sorted(s)

cur_max = 0

if fullmax % 10 != 0 :
    print(fullmax)
else :
    # if everything divisable by zero
    div_flg = True
    for i in s :
        if i % 10 != 0 :
            div_flg = False
            
    if div_flg == True :
        print("0")
    else :
        for i in range(N) :
            if (fullmax - s_sorted[i]) % 10 != 0 :
                cur_max = max(fullmax - s_sorted[i], cur_max)
        
        print(cur_max)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define PB push_back
#define FO(i,a,b) for (int i = a; i <= b; i++)
#define FOb(i,a,b) for(int i=b;i>=a;i--)
#define vi vector<int>
#define vulli vector<unsigned long long int>
using namespace std;
typedef unsigned long long int ulli;
void solve()
{ 
  string str;
  cin>>str;
  if(str[0]==str[1] && str[1]==str[2])
    cout<<"No";
  else
    cout<<"Yes";
  

}
int main()
{
    std::ios_base::sync_with_stdio(false);
    ulli t=1;
   // cin>>t;   
    while(t--){ solve(); cout<<"\n"; }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans;
  while(cin >> n && n != EOF){
    ans = 0;
    for(int i1 = 0;i1 <= 9;i1++){
       for(int i2 = 0;i2 <= 9;i2++){
	  for(int i3 = 0;i3 <= 9;i3++){
	     for(int i4 = 0;i4 <= 9;i4++){
	       if(n == i1 + i2 + i3 + i4)ans++;
	     }
	  }
       }
    }
    cout << ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 3052
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cmath> 
#include <cctype>

using namespace std;

bool isPower(int num) {
    if (num == 1 || num == 1000) return true;
    for (int n = 2; pow(num, 1.0 / n) >= 2.0; n++) {
        double Root = pow(num, 1.0 / n);
        if (Root - floor(Root) == 0.0) return true;
    }
    return false;
}

int main() {
    int X;
    cin >> X;
    for (int i = X; i >= 1; i--) {
        if (isPower(i)) {
            cout << i << endl;
            return 0;
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  int an;
  map<int,int> dic;

  rep(i,N){
    cin >> an;
    dic[an] += 1;
  }

  int num = 0;
  int xx, xxm1, xxp1;
  int nn, nnp1,nnm1;
  for (auto x = dic.begin(); x != dic.end(); ++x){
    xx = x->first;
    xxm1 = xx - 1;
    xxp1 = xx + 1;
    
    nn = dic[xx];
    nnm1 = 0;
    nnp1 = 0;
    if(! (dic.find(xxm1) == dic.end())) nnm1 = dic[xxm1];
    if(! (dic.find(xxp1) == dic.end())) nnp1 = dic[xxp1];
      
    num = max(num, nn + nnm1 + nnp1);
  }
  cout << num << endl;
}

Measured memory_bytes: 3200