akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mod=998244353;
#define N 444
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
#define ck(x) ((x)>=mod?(x)-mod:(x))
int dp[N][N][2],pw2[N],n,h[N],ans,siz[N];
int st[N],top;
int root;
struct Tree{
	int ch[2];
}t[N];
#define ls t[u].ch[0]
#define rs t[u].ch[1]
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
void dfs(int u,int l,int r,int las){
	if(ls)dfs(ls,l,u-1,h[u]);
	if(rs)dfs(rs,u+1,r,h[u]);
	siz[u]=siz[ls]+siz[rs]+1;
	for(int i=0;i<=siz[ls];++i){
		for(int j=0;j<=siz[rs];++j){
			int p=i+j;
			int A=1LL*dp[ls][i][1]*dp[rs][j][1]%mod;
			int B=(1LL*dp[ls][i][0]*dp[rs][j][0]+1LL*dp[ls][i][0]*dp[rs][j][1]+1LL*dp[ls][i][1]*dp[rs][j][0])%mod;
			dp[u][p][1]=ck(dp[u][p][1]+A);
			dp[u][p][0]=ck(dp[u][p][0]+B);
			dp[u][p+1][1]=ck(dp[u][p+1][1]-A+mod);
			dp[u][p+1][0]=ck(dp[u][p+1][0]+A);
		}
	}
	for(int i=0;i<=siz[u];++i){
		for(int k=0;k<2;++k){
			dp[u][i][k]=1LL*dp[u][i][k]*qpow(pw2[siz[u]-i]-(k^1),h[u]-las)%mod;
		}
	}
}
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		h[i]=read();
	}
	pw2[0]=1;
	for(int i=1;i<=n;++i){
		pw2[i]=ck(pw2[i-1]<<1);
	}
	for(int i=1;i<=n;++i){
		while(top&&h[i]<h[st[top]])t[i].ch[0]=st[top--];
		if(top)t[st[top]].ch[1]=i;
		st[++top]=i;
	}
	root=st[1];
	dp[0][0][1]=1;
	dfs(root,1,n,0);
	for(int i=0;i<=n;++i){
		ans=ck(ans+ck(dp[root][i][0]+dp[root][i][1]));
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 5112
import fractions

a,b,c,d = map(int, input().split())
nc = b//c-(a-1)//c
nd = b//d-(a-1)//d

# e = lcm(c,d)
e = c*d//fractions.gcd(c,d)
nc_d = b//e-(a-1)//e
print(b-a+1-nc-nd+nc_d)


Measured memory_bytes: 5048
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
bottle, cost, i = 0, 0, 0
while bottle < M:
    cost += AB[i][0] * AB[i][1]
    bottle += AB[i][1]
    i += 1

cost -= (bottle - M) * AB[i-1][0]
print(cost)

Measured memory_bytes: 27760
#include<stdio.h>
int main(){
  int n, ans = 1;
  char s[100001];
  scanf("%d", &n);
  scanf("%s", s);
  for(int i = 0; i < n - 1; ++i){
    if(s[i] != s[i + 1]) ans++;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
    char a;
    cin >> a;
    if('A' <= a and a <= 'Z')cout << 'A'<<endl;
    else cout << 'a'<<endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
int main(){
  int a,b;
  char c;
  scanf("%d %c %d",&a,&c,&b);
  if(c=='+') printf("%d",a+b);
  else printf("%d",a-b);
  //printf("%d %c %d",a,c,b);
  return 0;
  
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>
#include <stack>

using namespace std;



int main() {
	int n, h[100], mini = 100;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (h[i] == 0)continue;
		int count = 0;
		mini = 100;
		for (int j = i; j < n; j++) {
			if (h[j] == 0)break;
			count++;
			mini = min(mini, h[j]);
		}
		for (int j = i; j <i+ count; j++) {
			h[j] -= mini;
		}
		sum += mini;
		i--;

	}

	cout << sum << endl;


	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define TABLE_SIZE 16777216
#define ORDER_LENGTH 7
#define STR_LENGTH 13
 
using namespace std;
 
int array[128];
 
int translateStr(char buf[]){
    int sum = -1,mult = 1;
    for(int i = 0; buf[i] != '\0'; i++){
        sum += array[buf[i]]*mult;
        mult *= 4;
    }
    return sum;
}
 
int main(){
 
    array['A']=1,array['C']=2,array['G']=3,array['T']=4;
 
    int n;
    scanf("%d",&n);
    char order[ORDER_LENGTH],str[STR_LENGTH];
 
    char* check_table = new char[TABLE_SIZE];
 
    for(int i = 0; i < n; i++){
        scanf("%s %s",order,str);
        if(order[0] == 'i'){
            check_table[translateStr(str)] = 'Y';
        }else{
            if(check_table[translateStr(str)] == 'Y'){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
}



Measured memory_bytes: 4532
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>

typedef std::pair<int, int> ii;

int H, W, M;
int SH[300005];
int SW[300005];

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);

  std::cin >> H >> W >> M;
  for (int i = 0; i < H; ++i)
    SH[i] = 0;
  for (int j = 0; j < W; ++j)
    SW[j] = 0;
  std::set<ii> targets;
  for (int i = 0; i < M; ++i) {
    int h, w; std::cin >> h >> w;
    h--;  w--;
    SH[h]++;
    SW[w]++;
    targets.insert({h, w});
  }

  std::vector<ii> SSH, SSW;
  for (int h = 0; h < H; ++h)
    SSH.push_back({SH[h], h});
  for (int w = 0; w < W; ++w)
    SSW.push_back({SW[w], w});
  std::sort(SSH.begin(), SSH.end());
  std::sort(SSW.begin(), SSW.end());

  int max_ans = SSH[H-1].first + SSW[W-1].first;
  int ans = 0;
  for (int i = H-1; i >= 0; --i) {
    if (max_ans - (SSH[i].first + SSW[W-1].first) >= 2) break;
    for (int j = W-1; j >= 0; --j) {
      if (max_ans - (SSH[i].first + SSW[j].first) >= 2) break;
      int cnt = SSH[i].first + SSW[j].first;
      if (cnt <= ans) break;
      if (targets.find({SSH[i].second, SSW[j].second}) != targets.end())
        cnt--;
      //std::cout << SSH[i].first << "+" << SSW[j].first << "-" << int(targets.find({SSH[i].second, SSW[j].second}) != targets.end()) << "=" << cnt << "\n";
      ans = std::max(ans, cnt);
    }
  }

  std::cout << ans << "\n";

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  int i = 0;
  int a = 100;
  
  while (i < N) {
    int x;
    cin >> x;
    int b = 0;
    
    while (x % 2 == 0) {
      x /= 2;
      b++;
    }
    
    if (a > b) {
      a = b;
    }
    
    i++;
  }
  
  cout << a << endl;
      

}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int[] a=new int[n];
		for (int i=0;i<n;++i) a[i]=in.nextInt();
		int[] dp=new int[n];
		for (int i=1;i<n;++i) {
			dp[i]=dp[i-1]+Math.abs(a[i]-a[i-1]);
			if (i>1) dp[i]=Math.min(dp[i],dp[i-2]+Math.abs(a[i]-a[i-2]));
		}
		System.out.println(dp[n-1]);
	}
}

Measured memory_bytes: 50752
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

void _main() {
  long A, B, C;
  cin >> A >> B >> C;

  long ans = 0;
  if (C-1 <= A+B) {
    ans = B + C;
  } else {
    ans += B + (A + B + 1);
  }
  cout << ans << "\n";
}

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

using namespace std;
using ll = long long;

ll gcd(ll a,ll b){while(a&&b){if(a>b) a = a%b;else b = b%a;}return a+b;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}

int main()
{
	ll n, m; cin >> n >> m;
	string s, t; cin >> s >> t;
	ll k = lcm(n, m), d = lcm(k / n, k / m);

	for(ll i = 0; i < k; i += d) {
		if(s[i / (k / n)] != t[i / (k / m)]) {
			cout << -1 << endl;
			return 0;
		}
	} 

	cout << k << endl;

	
}

Measured memory_bytes: 512
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: usize,
      m: usize,
      aa: [usize; n],
      bcs: [(usize, usize); m],
    }
    use std::collections::HashMap;
    let mut map: HashMap<usize, usize> = HashMap::new();
    for &a in aa.iter() {
        let e = map.entry(a).or_insert(0);
        *e += 1;
    }
    for &(b, c) in bcs.iter() {
        let e = map.entry(c).or_insert(0);
        *e += b;
    }

    let mut nums = vec![];
    for (&k, &v) in map.iter() {
        nums.push((k, v));
    }
    nums.sort_by_key(|v| v.0);
    nums.reverse();

    let mut ans = 0;
    let mut n = n;
    for &(k, cnt) in nums.iter() {
        let num = min(cnt, n);
        ans += num * k;
        if n <= cnt {
            break;
        }
        n -= cnt;
    }
    println!("{}", ans);
}


Measured memory_bytes: 19468
#include <iostream>
#include <vector>
#define NMAX 102

using namespace std;

int main(){
	int N,D,X,A[NMAX];
	cin >> N >> D >> X;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	for (int i = 0; i < N; ++i)
	{
		X += (D-1)/A[i] + 1;
	}
	cout << X << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    string s;
    int K;
    cin >> s >> K;

    vector<string> data;
    for (int i = 0; i < s.size(); i++) {
      for (int j = 1; j <= K; j++) {
        data.push_back(s.substr(i, j));
      }
    }
    sort(data.begin(), data.end());
    unique(data.begin(), data.end());
    cout << data[K-1] << endl;

    return 0;
}


Measured memory_bytes: 1660
n, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
for i in range(1, n):
    candy = a[i - 1] + a[i]
    if candy > x:
        ans += candy - x
        a[i] = max(0, a[i] - candy + x)

print(ans)


Measured memory_bytes: 14132
H, W = list(map(int, input().split()))

grid_compred = []
for i in range(H):
    a = input()
    if a != "." * W:
        grid_compred.append(a)

rm_list = []
for i in range(W):
    candidate = [grid_compred[jth][i] for jth in range(len(grid_compred))]
    if ''.join(candidate) == "." * len(grid_compred):
        rm_list.append(i)

for i in range(len(grid_compred)):
    row_list = [grid_compred[i][j] for j in range(len(grid_compred[i])) if j not in rm_list]
    print(''.join(row_list))

Measured memory_bytes: 38768
import java.lang.Math.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map{it.toInt()}
    var prev = 0
    var prev2 = 1000000000
    var now = 0
    for(i in 1 until N) {
        now = min(prev + abs(a[i] - a[i-1]), if(i > 1)prev2 + abs(a[i] - a[i-2]) else prev2)
        prev2 = prev
        prev = now
    }
    println(now)
}


Measured memory_bytes: 50692
#include <iostream>
#include <array>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>

#define forn(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)

#define fi first
#define se second
#define eb emplace_back

template <typename T>
bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool uin(T& a, T b) { if (b < a) { a = b; return true; } return false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef long long i64;

constexpr int power(int x, int n) {
  return n > 0 ? power(x, n - 1) * x : 1;
}

const int N = 50;
i64 d[N + 1][N + 1];
const i64 inf = (1ll << (N + 1));

void solve_c() {
  int n;
  cin >> n;
  vi a(n), b(n);
  forn(i, n) cin >> a[i];
  forn(i, n) cin >> b[i];

  i64 ans = 0;

  while (true) {
    forn(i, N + 1) forn(j, N + 1) d[i][j] = inf;
    forn(i, N + 1) forn(j, N + 1) d[i][i] = 0;
    forn(k, N + 1) if (k > 0) {
      forn(i, N + 1) forn(j, N + 1) {
        uin(d[i][j], d[i % k][j] | (i64)((ans >> k) & 1 ? 0 : 1) << k);
      }
    }
    i64 cans = 0;
    forn(i, n) {
      if (d[a[i]][b[i]] == inf) {
        cout << -1 << endl;
        return ;
      } else {
        cans |= d[a[i]][b[i]];
      }
    }
    ford(k, N + 1) if ((cans >> k) & 1) {
      ans |= 1ll << k;
      break;
    }
    if (cans == 0) break;
  }
  cout << ans << endl;
}

void solve_b() {
  int n;
  cin >> n;
  int x = 30000;
  if (n == 3) {
    cout << "2 5 63\n";
    return ;
  } else if (n == 4) {
    cout << "2 5 20 63\n";
    return ;
  }
  int gs = 0;
  int s = 0;
  forn(i, n - 3) {
    while (__gcd(x, 6) == 1) --x;
    cout << x << ' ';
    gs = __gcd(gs, x);
    s += x; s %= 6;
    --x;
  }
  bool ok = false;
  forn(k, x + 1) if (k > 0 && __gcd(k, 6) != 1) {
      forn(j, k) if (j > 0 && __gcd(j, 6) != 1) {
          forn(i, j) if (i > 0 && __gcd(i, 6) != 1) {
              if ((i + j + k + s) % 6 == 0 && __gcd(gs, __gcd(i, __gcd(j, k))) == 1) {
                cout << k << ' ' << j << ' ' << i;
                ok = true;
                break;
              }
            }
          if (ok) break;
        }
      if (ok) break;
    }
  assert(ok);
  cout << endl;
}

void solve_a() {
  string s;
  cin >> s;
  if (s.length() < 26) {
    for (char c = 'a'; c <= 'z'; ++c) {
      if (find(s.begin(), s.end(), c) == s.end()) {
        s += c;
        break;
      }
    }
  } else {
    string t = s;
    if (!next_permutation(s.begin(), s.end())) {
      s = "-1";
    } else {
      int i = 0;
      while (s[i] == t[i]) ++i;
      s = s.substr(0, i + 1);
    }
  }
  cout << s << endl;
}

int main() {
#ifndef HOME
  // freopen("input.txt", "rt", stdin);
#endif
  solve_a();
  return 0;
}


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

using namespace std;

int x, y, z;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> x >> y >> z;

	cout << z << ' ' << x << ' ' << y;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    int t;
    cin >> t;
    cin >> s;
    int ans = 0;
    for (int i = 1; i < t; i++){
        int count = 0;
        vector<string> x(i);
        vector<string> y(t-i);
        //cout << x.size() << " " << y.size() << endl;
        for (int j = 0; j < t; j++){
            if (j < i){x[j] = s[j];}
            else{y[j-i] = s[j];}
        }
        sort(x.begin(), x.end());
        sort(y.begin(), y.end());
        x.erase(unique(x.begin(), x.end()), x.end());
        y.erase(unique(y.begin(), y.end()), y.end());
        for (int j = 0; j < (int)x.size(); j++){
            if (find(y.begin(), y.end(), x[j]) != y.end()){count += 1;}
        }
        ans = max(ans, count);
    }

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

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#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(){
int h,w;
cin >> h >> w;

vector <vector<char>> f(h,vector<char>(w));
vector <vector<char>> nf(h,vector<char>(w));
int xvec[]={-1,0,1,-1,1,-1, 0, 1};
int yvec[]={ 1,1,1, 0,0,-1,-1,-1};
rep(i,h)
{
    rep(j,w)
    {
        cin>>f[i][j];
    }
}


rep(i,h)
{
    rep(j,w)
    {
        //f[i][j];
        if(f[i][j]=='#')
        {nf[i][j]='#';}
        else{
             char counter='0';
             rep(a,8)
                {
                 int nx=j+xvec[a];
                 int ny=i+yvec[a];
                 if(nx<0 || ny<0 || h<=ny || w<=nx)//枠からはみでていたら
                 {continue;}
                 else if(f[ny][nx]=='#')
                 {counter++;}
                }
             nf[i][j]=counter;             
        }
       
    }
}

rep(i,h)
{
    rep(j,w)
    {
        cout<<nf[i][j];
    }
    cout<<endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main()
{
	int a,b;
	cin >> a >> b;
	if(a >= 13) cout << b << endl;
	else if(6 <= a && a <= 12) cout << b/2 << endl;
	else cout << 0 << endl;
	return 0;
}


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

using namespace std;

int main(){
    string A;
    cin >> A;

    map<char, int> cnt;
    for(int i=0; i<A.size(); i++){
        if (cnt.find(A[i])==cnt.end()){
            cnt[A[i]]=1;
        }else{
            cnt[A[i]]++;
        }
    }
    long long sum_ =A.size();

    long long ans=1;
    for(auto x=cnt.cbegin(); x!=cnt.cend(); ++x){
        int value = x->second;
        sum_-=value;
        ans+=sum_*value;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 640
M, N = map(int, input().split())
A = list(map(int, input().rstrip().split()))
sums = 0
for day in A:
    sums += day
if sums < M:
    result = M - sums
elif sums > M:
    result = -1
elif sums == M:
    result = 0
print(result)

Measured memory_bytes: 10192
import math
import numpy as np

N = int(input())
A = np.array([int(input()) for _ in range(N)])
S = np.sum(A)
MOD = 998244353


# dp0[i][j]: number of ways to obtain sum j for one of colors using first i integers.
# i = 0, 1, ..., N
# j = 0, 1, ..., S
dp0 = np.zeros((N + 1, S + 1), dtype=np.int64)

# dp1[i][j]: number of ways to obtain sum j for one of colors using first i integers,
#     but this time we use only TWO colors.
#     This will be used to find the number of cases when
#         (sum of R)= (sum of G) = S/2 & (sum of B) = 0 

dp1 = np.zeros((N + 1, S // 2 + 1), dtype=np.int64)

# using 0 integer to obtain sum=0
dp0[0, 0] = 1
dp1[0, 0] = 1


for i, x in enumerate(A):

    # If we do not use the next integer x, e.g. not for R, the sum of R is same, but possible ways are doubled
    #     because x can be used for either G or B
    dp0[i+1, :] += dp0[i, :] * 2 % MOD

    # Then we update the case when we use the next integer x.
    #     Lets say, sum=p was obtained for 4 different ways without using current integer x,
    #     then sum=p+x can also be obtained for 4 different ways.
    dp0[i+1, x:] += dp0[i, :-x]

    # If we do not use the next integer x, e.g. not for R, the sum of R is same, and possible ways are the same
    #     because this time we use only TWO colors. (say R and G, we dont use x for R, then automatically x goes for G)
    dp1[i+1, :] += dp1[i, :] % MOD

    # Then we update the case when we use the next integer x.
    dp1[i+1, x:] += dp1[i, :-x]


# count cases: (R >= S / 2)
not_satisfy = np.sum(dp0[N][math.ceil(S/2):])

# count cases: (R = S / 2) & (B = S / 2)
double_reduct = 0 if S % 2 == 1 else dp1[N][S/2]

# total cases = 3 ** N

ans = (3 ** N - 3 * not_satisfy + 3 * double_reduct) % MOD
print(ans)



Measured memory_bytes: 328884
// SeeAlso: https://atcoder.jp/contests/arc074/tasks/arc074_b

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 300000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int N;
ll a[MAX];
priority_queue<ll, vector<ll>, greater<ll>> a1;
priority_queue<ll> a2;

ll dp[2][100100];

int main() {

    ll sum = 0;
    cin >> N;

    REP(i, (3*N)) {
        cin >> a[i];
    }   

    REP(i, N) {
        sum += a[i];
        a1.push(a[i]);
    }

	dp[0][0] = sum;

    REP(i,N) {
		a1.push(a[i+N]);
		sum += a[i+N];
		sum -= a1.top();
		a1.pop();
		dp[0][i+1] = sum;
	}

	sum = 0;
	REP(i,N) {
		sum += a[N*2+i];
		a2.push(a[N*2+i]);
	}
	dp[1][N] = sum;
	for(ll i=(N-1); i >= 0; --i) {
		a2.push(a[i+N]);
		sum += a[i+N];
		sum -= a2.top();
		a2.pop();
		dp[1][i] = sum;
	}
	ll res = -1e15;
	REP(i,N+1) {
		res = max(res, dp[0][i] - dp[1][i]);
	}
	cout << res << endl;

    return 0;
}


Measured memory_bytes: 5876
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        x: usize,
    }

    if x==1 {
        println!("{}", 1);
        return;
    }

    let mut ans: Vec<i64> = Vec::new();
    for b in 2..34 {
        for p in 2..11 {
            if (b as i64).pow(p) <= x as i64 {
                ans.push((b as i64).pow(p));
            }
        }
    }

    ans.sort();
    ans.reverse();
    println!("{}", ans[0]);

    // for i in (1..x+1).rev() {
    //     let mut tmp: Vec<usize> = vec![0;i+5];
    //     for j in 2..i+1 {
    //         let mut a = i;
    //         if i%j==0 {
    //             while a%j==0 {
    //                 tmp[j] += 1;
    //                 a /= j;
    //                 debug!(a);
    //             } 
    //         }
    //     }
    //     tmp.sort();
    //     tmp.reverse();
    //     debug!(tmp);
    //     let mut ok = false;
    //     if tmp[0]>=2 {
    //         ok = true;
    //         for k in 2..tmp.len() {
    //             if tmp[k]!=0 {
    //                 ok = false;
    //             }
    //         }
    //     }
    //     if ok {
    //         println!("{}", i);
    //         return;
    //     }
    // }

}


Measured memory_bytes: 2204
#!/usr/bin/env python
import string
import sys
from collections import Counter
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in read(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    n = readi()
    v = readi(n)
    l1 = v[::2]
    l2 = v[1::2]

    mc1 = Counter(l1).most_common()
    mc2 = Counter(l2).most_common()
    if mc1[0][0] != mc2[0][0]:
        print((n // 2 - mc1[0][1]) + (n // 2 - mc2[0][1]))
    else:
        if len(mc1) > 1 and len(mc2) == 1:
            print((n // 2 - mc1[1][1]) + (n // 2 - mc2[0][1]))
        elif len(mc1) == 1 and len(mc2) > 1:
            print((n // 2 - mc1[0][1]) + (n // 2 - mc2[1][1]))
        elif len(mc1) > 1 and len(mc2) > 1:
            print(
                min(
                    (n // 2 - mc1[1][1]) + (n // 2 - mc2[0][1]),
                    (n // 2 - mc1[0][1]) + (n // 2 - mc2[1][1]),
                )
            )
        else:
            print(n // 2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 65500
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}



signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  string s;cin>>s;
  rep(i,0,siz(s))if(s[i]=='?')s[i]='D';
  
  cout<<s<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#include <set>
#include <queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++) 
#define reps(i, s, n) for (int i = s; i < (int)(n); i++) 
#define ll long long
#define ld long double
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++) 
#define repsl(i, s, n) for (ll i = s; i < (ll)(n); i++)  
#define outdeb(fir, sec, thr) cout << fir << ":" << sec << ":" << thr << endl

#define lpair pair<ll, ll>

int main()
{
  ll x,k,d;
  cin >> x >> k >> d;
  ll ans = 0;

  if(x < 0)
  {
    x *= -1;
  }

  if(k <= x/d)
  {
    ans = x - d * k;
  }
  else
  {
    ans = x % d;
    k = k - x / d;
    ans = k % 2 == 0 ? ans : abs(ans - d);
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int a, b; cin >> a >> b;
  int x_a = (a*25 +1) /2;
  int x_b = b*10;

  if(x_a > x_b){
    if(x_a/10 == b) cout << x_a << endl;
    else cout << -1 << endl;
  }
  else{
    if(x_b*8/100 == a) cout << x_b << endl;
    else cout << -1 << endl;
  }
}


Measured memory_bytes: 3616
N, M = map(int, input().split())
ps = [list(map(str, input().split())) for _ in range(M)]

ac = [0]*N
wa = [0]*N

for i, s in ps:
    if ac[int(i)-1]==0:
        if s=='AC':ac[int(i)-1]=1
        elif s=='WA':wa[int(i)-1] += 1
answa = sum([wa[i] for i in range(N) if ac[i]==1])
print(sum(ac), answa)

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}


int main() {
  int Q; cin >> Q;
  vector<int> l(Q), r(Q); REP(i, Q) cin >> l[i] >> r[i];
  const int N = pow(10, 5);
  vector<int> ans(N + 1);
  REP(i, N + 1) {
    if(i == 0) {
      ans[i] = 0;
      continue;
    }
    ans[i] = ans[i - 1];
    if( IsPrime(i) && IsPrime((i + 1) / 2) ) ans[i]++;
  }
  REP(i, Q) {
    cout << ans[r[i]] - ans[l[i] - 1] << endl;
  }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { string S, T;
  cin >> S >> T;
  if(S.size()+1==T.size()){
    REP(i,S.size()){
      if(S[i]!=T[i]){
        puts("No");
        return 0;
      }
    }
    puts("Yes");
    return 0;
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 3624
import sys,queue,copy
sys.setrecursionlimit(10**8)
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,K =inpl()
hlist = inpl()
ans =0
for h in hlist:
    if h >= K :
        ans += 1

print(ans)

Measured memory_bytes: 12888
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int a, b; scanf("%d%d", &a, &b);
	
	if(a + b >= 10) printf("error\n");
	else printf("%d\n", a + b);
	return 0;
}


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


int main()
{
  int n;
  cin>>n;
  vector<vector<int>> a(n,vector<int>(2));
  
  map<int,int> maps;
  for(int i=0;i<n;i++)
  {
    a.at(i).at(0)=i;
    cin>>a.at(i).at(1);
    maps[i]=0;
  }
  
  for(int i=0;i<n;i++)
  {
    maps[a.at(i).at(1)-1]++;
  }
  for(int i=0;i<n;i++)
  {
    cout<<maps[i]<<endl;
  }
}
      
  

Measured memory_bytes: 23532
#include<stdio.h>
int main(void){
	int i,j,H,W;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 && W == 0) break;
		else if(H ==0 || W == 0) printf("\n");
		else for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				printf("#");
			}
		printf("\n");
		}
	printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
N=int(input())
A = list(map(int, input().split()))
outflag = 0
for i in range(N):
    if A[i]%2==0:
        if A[i]%3==0 or A[i]%5==0:
            pass
        else:
            outflag=1
            break
    else:
        pass
print("DENIED" if outflag else "APPROVED")

Measured memory_bytes: 3064
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

enum long INF = long.max/5;
enum long MOD = 10L^^9+7;

void main() {
  long N;
  scanln(N);
  string s, t;
  scanln(s, t);
  string ans = "";
  foreach(i; 0..N) {
    ans ~= s[i].to!string ~ t[i].to!string;
  }
  ans.writeln;
}

// ----------------------------------------------


void times(alias fun)(long n) {
  // n.iota.each!(i => fun());
  foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
  // return n.iota.map!(i => fun()).array;
  T[] res = new T[n];
  foreach(ref e; res) e = fun();
  return res;
}

T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  // `(x+y-1)/y` will only work for positive numbers ...
  T t = x / y;
  if (y > 0 && t * y < x) t++;
  if (y < 0 && t * y > x) t++;
  return t;
}

T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  T t = x / y;
  if (y > 0 && t * y > x) t--;
  if (y < 0 && t * y < x) t--;
  return t;
}

ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
  return lhs = fun(lhs, rhs);
}
unittest {
  long x = 1000;
  x.ch!min(2000);
  assert(x == 1000);
  x.ch!min(3, 2, 1);
  assert(x == 1);
  x.ch!max(100).ch!min(1000); // clamp
  assert(x == 100);
  x.ch!max(0).ch!min(10); // clamp
  assert(x == 10);
}

mixin template Constructor() {
  import std.traits : FieldNameTuple;
  this(Args...)(Args args) {
    // static foreach(i, v; args) {
    foreach(i, v; args) {
      mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
    }
  }
}

void scanln(Args...)(auto ref Args args) {
  enum sep = " ";
  enum n = Args.length;
  enum fmt = n.rep!(()=>"%s").join(sep) ~ "\n";
  static if (__VERSION__ >= 2071) {
    readf!fmt(args);
  } else {
    enum argsTemp = n.iota.map!(
      i => "&args[%d]".format(i)
    ).join(", ");
    mixin(
      "readf(fmt, " ~ argsTemp ~ ");"
    );
  }
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
  template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
      static if (S.length < 2) {
        return reduce!fun(seed, r);
      } else {
        return reduce!fun(tuple(seed), r);
      }
    }
  }
}

// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
  ulong popcnt(ulong x) {
    x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
    x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
    x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
    x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
    x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
    x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
    return x;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int a, b,c;
	cin >> a >> b;
	if (a < b) { c = b;
	b--;
	}
	else { c = a;a--; }
	if (a < b) {
		c += b;
		b--;
	}
	else { c += a;a--; }
	cout << c << endl;



	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int[] x = new int[5];
		int y = 10;
		int sum = -10;
		for(int i = 0;i<5;i++) {
			x[i]=scn.nextInt()-1;
			if(x[i]%10<y) {
				y=x[i]%10+1;
			}
			x[i] = x[i]/10+1;
		}
		for(int z:x) {
			sum+=10*z;
		}
		sum+=y;
		System.out.println(sum);
		scn.close();
	}
}

Measured memory_bytes: 21332
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1

int main() {
    LL n;
    LL m;
    cin >> n >> m;
    LL ans;

    if(2*n>=m){
        ans=m/2;
    }else{
        m=m-(2*n);
        ans=m/4+n;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3596
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cstdint>
					/*多倍長整数/cpp_intで宣言
					#include <boost/multiprecision/cpp_int.hpp>

					using namespace boost::multiprecision;
					*/

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define addf(T) [](T a, T b){return (a + b);}
#define minf(T) [](T a, T b){return min(a, b);}
#define maxf(T) [](T a, T b){return max(a, b);}

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const long double PI = acos(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcm(ll number1, ll number2) {//lcmを求める
	return number1 / gcd(number1, number2) * number2;
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	ll n, a, b, c, d, e;
	scanf("%lld%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d, &e);
	ll p = min({ a, b, c, d, e });
	printf("%lld\n", (ll)ceil((double)n / p) + 4LL);

	Please AC;
}


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

int main(){
    int xi[10000];
    int i;
    for(i=0 ;; i++){
        cin >> xi[i];
        if(!xi[i]) break;
    }
    for(i=0 ;; i++){
        if(!xi[i]) break;
        cout << "Case " << i+1 << ": " << xi[i] << endl;

    }
}


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

inline void chmax(int &a, int b) { a = max(a, b); }

int main()
{
  int N, maxv = 0, cnt = 0;
  string s;
  cin >> N >> s;

  Rep(i,N) {
    if(s[i] == 'I') {
      chmax(maxv, ++cnt);
    } else {
      cnt--;
    }
  }

  cout << maxv << endl;

  return 0;
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        100000000000007LL
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,a[404],dp[404][404],pre[404];
int sol(int l,int r){
    if(l==r) return 0;
    int &ans=dp[l][r];
    if(ans!=-1) return ans;
    ans=hell;
    rep(i,l,r){
        // i,i+1
        ans=min(ans,sol(l,i)+sol(i+1,r)+pre[r]-pre[l-1]);
    }
    return ans;
}
void solve(){
    cin>>n;
    rep(i,1,n+1) cin>>a[i],pre[i]=a[i]+pre[i-1];
    memset(dp,-1,sizeof dp);
    cout<<sol(1,n)<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1664
#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;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
n,m,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x.sort()
y.sort()
for i in range(X+1,Y+1,1):
    if i <= min(y) and i > max(x):
        print("No War")
        break
else:
    print("War")


Measured memory_bytes: 9180
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	const double r = 6378.1; // ツ地ツ仰づ個板シツ径
	double a, b, c, d;

	while (cin >> a >> b >> c >> d && a != -1. && b != -1. && c != -1. && d != -1. ){
		a *= M_PI/180.; b *= M_PI/180.; c *= M_PI/180.; d *= M_PI/180.;
		double e = sin (a)*sin(c) + cos(a)*cos(c)*cos(b-d);
		int res = (int)(r*acos(e ) + 0.5);
		cout << res << endl;

	} // end loop

	return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (auto & _a : a)
    cin >> _a;
  int odd = 0;
  int even_2 = 0;
  int even_4 = 0;
  for (auto & _a : a)
  {
    if (0 != _a%2)
      ++odd;
    else if (0 == _a%4)
      ++even_4;
    else
      ++even_2;
  }
  if (N == even_2)
  {
    cout << "Yes";
    return 0;
  }
  if (0 < even_2)
  {
    ++odd;
    --even_2;
  }
  cout << ((odd - 1 <= even_4) ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 768
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
C=list(map(int, input().split()))

ans=0

for i in range(N-1):
	now=A[i]
	next=A[i+1]
	ans+=B[now-1]
	if next==now+1:
		ans+=C[now-1]

ans+=B[A[N-1]-1]

print(ans)

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


int main()
{
    char a[500],b[500];
    char c[1000];
    int n;
    while(cin>>n)
    {
        scanf("%s %s",a,b);
        int i;
        for(i=0;i<n;i++)
            printf("%c%c",a[i],b[i]);
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
using namespace std;
typedef long long ll;
const int maxn = 100005;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout);
#endif
   int t,x;
   cin>>t>>x;
   printf("%.6f", t*1.0/x);
  return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
l = {}
r = {}
ans = 0
nagasa = len(s)
for i in range(1, nagasa):
    l = set(s[0:i])
    r = set(s[i:nagasa+1])
    tmp = len(l&r)
    if ans < tmp:
        ans = tmp
print(ans)


Measured memory_bytes: 3060
import sys
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall as f
def main():
  t=np.fromstring(sys.stdin.buffer.read(),'i',sep=' ')
  n,m,l=t[:3]
  m=m*3+3
  print('\n'.join((f(f(csr_matrix((t[5:m:3],(t[3:m:3],t[4:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n).astype(int)%n-1).astype(str).tolist()))
main()

Measured memory_bytes: 28748
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    // int N = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    static void solve(Scanner scanner) {
        int N = scanner.nextInt(), K = scanner.nextInt();
        scanner.nextLine();

        long ans = 0;
        for (int b = 1; b <= N; b++) {
            int rep = (N / b) * Math.max(b - K, 0);
            int rem = Math.max((N % b) - K + 1, 0);
            int a0 = (rep > 0 || rem > 0) && K == 0 ? -1 : 0;
            ans += rep + rem + a0;
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 21844
n, m=map(int, input().split())
S=input()
T=input()

if n==1 and m==1:
  if S==T:
    print(1)
  else:
    print(-1)
  exit()
elif n==1 or m==1:
  print(-1)
  exit()

import fractions
p=n*m//fractions.gcd(n, m)
a=p//n
b=p//m
c=a*b//fractions.gcd(a, b)
for i in range(0, p, c):
  if S[i//a]!=T[i//b]:
    print(-1)
    exit()
    
print(p)

Measured memory_bytes: 5304
#include<stdio.h>
int main()
{
	int s[4],temp,i,j;
	for(i = 0;i < 3;i++)
		scanf("%d",&s[i]);
	for(i = 0;i < 2;i++)
	{
		for(j = 0;j < 2 - i;j++)
		{
			if(s[j] > s[j + 1])
			{
				temp = s[j];
				s[j] = s[j + 1];
				s[j + 1] = temp;
			}
		}
	}
	if((s[1] - s[0]) == (s[2] - s[1]))
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}




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

int max(int a, int b){
  return a > b ? a : b;
}

int main(void){
  int n, w;
  cin >> n >> w;
  
  vector<int> value(n);
  vector<int> weight(n);
    
  for(int i = 0; i < n; i++){
    cin >> value[i] >> weight[i];
  }

  // 0-1????????????????????????
  // dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight[i] + value[i]])
  // ??????: i????????\???????????????????????????j??\?????§0-1??????????????????????????????????????????
  // ?????????????£???§??????i???????????????????????????????????¨??§?????\????????????
  vector<int> dp(w+1, 0);
  for(int i = 0; i < n; i++)
    for(int j = w; j >= weight[i]; j--)
      dp[j] = max(dp[j], dp[j - weight[i]] + value[i]);

  // ???????????????
  cout << dp[w] << endl;
  
  return 0;
}

Measured memory_bytes: 1236