akhauriyash/Code-Regression huggingface dataset:
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define REP(i,n) FOR(i,0,n)

const int INF=100000000;
const bool debug=1;

int main(){

  int N;
  while(cin>>N,N){
    bool info[N][N];
    bool Kinfo[N];
    REP(i,N)REP(j,N)info[i][j]=false;
    REP(i,N)Kinfo[i]=false;
    REP(i,N){
      int M;
      cin>>M;
      REP(j,M){
	int p;
	cin>>p;
	p--;
	info[i][p]=true;

      }
    }
    int K;
    cin>>K;
    REP(i,K){
      int l;
      cin>>l;
      l--;
      Kinfo[l]=true;
    }

    int count=0;
    int ans=-1;
    REP(i,N){
      bool flag=true;
      REP(j,N){
	if(Kinfo[j] && !info[i][j]){flag=false;break;}
      }
      if(flag){ans=i;count++;}
    }

    if(count==1)cout << (ans+1) << endl;
    else cout << -1 << endl;
  }
}

Measured memory_bytes: 1168
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x=0,i=1;
    cin>>x;
    while(true)
    {
        if((i*x)%360==0)
            break;
        ++i;
    }
    cout<<i<<endl;
}

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

static const auto fast_io = [] {
 ios_base::sync_with_stdio(false); 
 cin.tie(nullptr); cout.tie(nullptr); 
 return nullptr;
}();

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int rnd() {
 return uniform_int_distribution<int> (1, (int) 1e9) (rng);
}

template<class A> 
A rnd(A x, A y) {
 return uniform_int_distribution<A> (x, y) (rng);
}

string to_string(string s) {
 return '"' + s + '"';
}

string to_string(const char* ch) {
 return to_string((string)ch);
}

string to_string(char ch) {
 return (string)"'" + ch + (string)"'";
}

string to_string(bool b) {
 return (b ? "true" : "false");
}

template<class A, class B>
string to_string(pair<A, B> p) {
 return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template<class A>
string to_string(A a) {
 string res = "{";
 bool first = true;
 for(const auto& x: a) {
  if(first == false) res += ", ";
  first = false;
  res += to_string(x);
 }
 res += "}";
 return res;
}

template<class A, class B, class C>
string to_string(priority_queue<A, B, C> a) {
 vector<A> res;
 while(a.empty() == false) {
  res.push_back(a.top());
  a.pop();
 }
 reverse(res.begin(), res.end());
 return to_string(res);
}

template<class A>
string to_string(priority_queue<A> a) {
 vector<A> res;
 while(a.empty() == false) {
  res.push_back(a.top());
  a.pop();
 }
 reverse(res.begin(), res.end());
 return to_string(res);
}

template<class A>
string to_string(stack<A> a) {
 vector<A> res;
 while(a.empty() == false) {
  res.push_back(a.top());
  a.pop();
 }
 return to_string(res);
}

template<class A>
string to_string(queue<A> a) {
 vector<A> res;
 while(a.empty() == false) {
  res.push_back(a.front());
  a.pop();
 }
 return to_string(res);
}

vector<string> __vector_tuple;
template<int index, class... A>
struct print_tuple {
 auto operator() (tuple<A...> a) {
  __vector_tuple.push_back(to_string(get<index>(a)));
  print_tuple<index-1, A...>{}(a);
 }
};

template<class... A>
struct print_tuple<0, A...> {
 auto operator() (tuple<A...> a) {
  __vector_tuple.push_back(to_string(get<0>(a)));
 }
};

template<class... T>
string to_string(tuple<T...> a) {
 const int ttsz = tuple_size<decltype(a)>::value;
 print_tuple<ttsz-1, T...>{}(a);
 string __ss = to_string(__vector_tuple);
 __vector_tuple.clear();
 return __ss;
}

void debug() {cerr << "]\n";}

template<class H, class... T>
void debug(H head, T... tail) {
 cerr << to_string(head) << " ";
 debug(tail...);
}

#ifdef LOCAL
 #define debug(...) cerr << "[" << #__VA_ARGS__ << " ] = ["; debug(__VA_ARGS__);
#else 
 #define debug(...) 
#endif

typedef long long int ll;

int main()
{
 int l, r, d;
 cin >> l >> r >> d;
 int ans = 0;
 for(int i  =l; i <= r; i++) ans += (i % d == 0);
 cout << ans << '\n';
 return 0;
}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void)
{
    string s;
    cin>>s;
    int ans=count(s.begin(),s.end(),'+');
    ans-=count(s.begin(),s.end(),'-');
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let s1 = str2vec(&input_line_str());
    let s2 = str2vec(&input_line_str());
    let mut i1 = s1.iter();
    let mut i2 = s2.iter();
    loop {
        let c = i1.next();
        if let None = c {
            break;
        }

        let c = c.unwrap();
        print!("{}", c);
        let c = i2.next();
        if let None = c {
            break;
        }
        let c = c.unwrap();

        print!("{}", c);
    }
    println!("");
}

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

int main() {
    int n,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) {
        int t=n/i;
        if(n%i==0) t--;
        // cout<<i<<" "<<t<<endl;
        ans+=t;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>

using namespace std;

int main()
{
	int n;
	int time[10000];
	int tmp;
	long long tmp_2;
	long long wait_time;
	
	while (1){
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		for (int i = 0; i < n; i++){
			scanf("%d", &time[i]);
		}
		
		for (int i = 0; i < n - 1; i++){
			for (int j = 0; j < n - i - 1; j++){
				if (time[j] > time[j + 1]){
					tmp = time[j];
					time[j] = time[j + 1];
					time[j + 1] = tmp;
				}
			}
		}
		
		wait_time = tmp_2 = 0;
		
		for (int i = 0; i < n - 1; i++){
			tmp_2 += time[i];
			wait_time += tmp_2;
		}
		
		printf("%lld\n", wait_time);
	}
	
	return (0);
}

Measured memory_bytes: 1064
import collections
def main():

    S = list(input())[::-1]
    T = list(input())[::-1]
    ary = []


    c = collections.Counter(S)
    if len(S) < len(T):
        print('UNRESTORABLE')
        return

    # if c['?'] == len(S):
    #     if len(S) == len(T):
    #
    #         print(''.join(T))
    #         return
    #     else:
    #         print('UNRESTORABLE')
    #         return
    else:
        for s_left in range(len(S)):
            s_l = s_left
            flg = True
            tmp = S[::1]
            for t_left in range(len(T)) :
                if s_l < len(S) and (S[s_l] == T[t_left] or S[s_l] == '?'):
                    tmp[s_l] = T[t_left]
                    s_l += 1
                    continue
                else:
                    flg = False
                    break
            if flg:
                ans_t = tmp[::-1]
                ans = ''
                for i in range(len(S)):
                    if ans_t[i] == '?':
                        ans += 'a'
                    else:
                        ans += ans_t[i]
                # print(ans)
                # return
                ary.append(ans)

        if len(ary) == 0:

            print('UNRESTORABLE')
            return
        ary.sort()
        print(ary[0])

if __name__ == '__main__':
    main()


Measured memory_bytes: 38512
using System;
using System.Text;
using System.Collections.Generic;

public class MainCls
{
	public static void Main(string[] args)
	{
		string a = Console.ReadLine();
		int n = int.Parse(a);
		string s = Console.ReadLine();
		int r = 0;
		int b = 0;
		for(int i = 0 ; i < n; i ++)
		{
			if(s[i] == 'R')r++;
			else b++;
		} 
		Console.WriteLine((r>b) ? "Yes" : "No");
	}

}

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

char cs[] = "+-*";
int pri[] = { 0, 0, 0 };

int it, n;
string s;

ll number();
ll fact();
ll expr(int);

ll number() {
	assert(isdigit(s[it]));
	ll res = 0;
	while (isdigit(s[it])) {
		res = res * 10 + (s[it++] - '0');
	}
	return res;
}

ll fact() {
	if (s[it] == '(') {
		it++;
		ll res = expr(2);
		assert(s[it] == ')');
		it++;
		return res;
	}
	return number();
}

ll expr(int p) {
	ll res = p ? expr(p - 1) : fact();
	while (true) {
		int id = -1;
		for (int i = 0; i < 3; i++) {
			if (it < n && pri[i] == p && s[it] == cs[i]) {
				id = i;
				break;
			}
		}
		if (id == -1) break;
		it++;
		ll tmp = p ? expr(p - 1) : fact();
		switch (cs[id])
		{
		case '+':
			res += tmp;
			break;
		case '-':
			res -= tmp;
			break;
		case '*':
			res *= tmp;
			break;
		default:
			break;
		}
	}
	return res;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> s;
	n = s.size();
	ll res = LLONG_MIN;
	for (pri[0] = 0; pri[0] < 3; pri[0]++) {
		for (pri[1] = 0; pri[1] < 3; pri[1]++) {
			for (pri[2] = 0; pri[2] < 3; pri[2]++) {
				it = 0;
				ll val = expr(2);
				assert(it == n);
				res = max(res, val);
			}
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
typedef long long ll ;
typedef double ld;
typedef pair<int,int> p2;
typedef pair<ll,p2> p3;
typedef vector<int> vi;
typedef vector<vi> Matrix;
const ll  Mod = 7 + 1e9;
const ll  INF32 = 5 + 2e9;
const ll  INF64 = 5 + 1e18;
const ll  MAX = 5+ 2e5;

ll N,K;

Matrix prep() { return Matrix(N,vi(N,0)); }

Matrix mult(Matrix a,Matrix b)
{
    Matrix res = prep();
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
    {
        ll sum = 0;
        for(int k=0;k<N;k++)
            sum = ( sum + (ll) a[i][k] *b[k][j]%Mod )%Mod;
        res[i][j] = sum;
    }
    return res;
}
Matrix fp(Matrix x,ll p)
{
    if(p == 1)
        return x;
    Matrix y = fp(x,p>>1);
    y = mult(y,y);
    if( p&1 )
        y = mult(y,x);
    return y;
}
int main()
{
    cin >> N >> K;
    Matrix G = prep();
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
        cin >> G[i][j];
    G = fp(G,K);
    ll ANSWER = 0;
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
        ANSWER = ( ANSWER + G[i][j] )%Mod;
    cout << ANSWER << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
  int n,m=0,i,j,k,l,cont=0,sum=0,ii;
  int P[101][101],L[100],cont1[100],ans[100];

  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      scanf("%d",&P[i][0]);
      for(j=1;j<P[i][0]+1;j++){
        scanf("%d",&P[i][j]);
      }
    }
    scanf("%d",&k);
    for(i=0;i<k;i++){
      scanf("%d",&L[i]);
    }
   
    for(i=0;i<n;i++){
      for(j=1;j<P[i][0]+1;j++){
        for(l=0;l<k;l++){
          if(L[l]==P[i][j]){
	    cont++;
	  }
	}
      }
      cont1[i]=cont;
      cont=0;
    }
    for(i=0;i<n;i++){
      //printf("%d\n",cont1[i]);
      if(cont1[i]==k){
	sum++;
	ii=i;
      }
    }
    if(sum==1)ans[m]=ii+1;
    else ans[m]=-1;
    sum=0;
    m++;
  }
  for(i=0;i<m;i++){
    printf("%d\n",ans[i]);
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    string S;
    cin>>S;
    string ans = "Yes";
    int N = S.size();
    rep(i,N){
        //奇数
        if(i%2 == 0){
            if(S[i]=='R'||S[i]=='U'||S[i]=='D'){
                continue;
            }
            else{
                ans = "No";
                break;
            }
        }
        else{
            if(S[i]=='L'||S[i]=='U'||S[i]=='D'){
                continue;
            }
            else{
                ans = "No";
                break;
            }
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main() {
  int r, D,x_2000;
  cin >> r>>D >> x_2000;
  vector<int> v(10);
  int tem=x_2000;
  REP(i,10){
    tem = r * tem - D;
    v.at(i) = tem;
    cout << v.at(i)<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int a[20000],b[20000];
    char op[20000];
    int ans[20000],check=1,i=0,j;
    
    while(check&&i<20000){
        scanf("%d %c %d",&a[i],&op[i],&b[i]);
        
        if(a[i]<0||20000<a[i]||b[i]<0||20000<b[i]){
            printf("error\n");
            return 0;
        }
        switch (op[i]) {
            case '+':
                ans[i]=a[i]+b[i];
                break;
            case '-':
                ans[i]=a[i]-b[i];
                break;
            case '*':
                ans[i]=a[i]*b[i];
                break;
            case '/':
                if(b[i]==0){
                    printf("error\n");
                    return 0;
                }
                ans[i]=a[i]/b[i];
                break;
            case '?':
                check=0;
                i--;
                break;
            default:
                return 0;
                break;
        }
        i++;
    }
    for(j=0;j<i;j++){
        printf("%d\n",ans[j]);
    }
    
    return 0;
}


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

const int MOD = (int)1e9+7;

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

	int ans=0;
	int half=(s.size()+1)/2;
	for(int i=0;i<half;i++){
		if(s.at(i)=='p')	ans--;
	}
	for(int i=half;i<s.size();i++){
		if(s.at(i)=='g')	ans++;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, A, B = map(int, input().split())
    ans = 0
    for i in range(1, N + 1):
        if A <= (sum(int(c) for c in str(i))) <= B:
            ans += i
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3960
#include<bits/stdc++.h>
//#include<boost\lexical_cast.hpp> 
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vi vector<int> 
#define vl vector<ll>
#define vpi vector<pi> 
#define vpl vector<pl>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define ss second
#define ff first
#define endl "\n"
#define mod 1000000007
#define MAX 100010
#define fill(a,x) memset(x,a,sizeof x)
#define all(x) x.begin(),x.end()
#define clr(x) memset(x,0,sizeof x)
#define rep(i,a,n) for(ll i=a;i<n;++i)
#define repr(i,n,b) for(ll i=n;i>=b;i--)
#define repit(itr,x) for(auto itr=x.begin();itr!=x.end();itr++)
using namespace std;
//using boost::lexical_cast;
//using boost::bad_lexical_cast;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int test=1;
	// cin>>test;
	while(test--){
		int n; cin>>n;
		vi a(n+1,0);
		rep(i,0,n) cin>>a[i];
		ll ans=0;
		vi dp(n+1,INF);
		dp[0]=0;

		rep(i,0,n){
			for(auto j:{i+1,i+2}){
				if(j<n)
				dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
//				ans+=dp[i];
			}
		}
		cout<<dp[n-1]<<endl;
	}
}

Measured memory_bytes: 1024
package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	n, m, k := sc.getInt3()

	uf := newUnionFind(n)
	friend := make(map[int]int)
	for i := 0; i < m; i++ {
		a, b := sc.getInt()-1, sc.getInt()-1
		friend[a]++
		friend[b]++
		uf.unite(a, b)
	}

	blocked := make([][]int, n)
	for i := 0; i < k; i++ {
		c, d := sc.getInt()-1, sc.getInt()-1
		blocked[c] = append(blocked[c], d)
		blocked[d] = append(blocked[d], c)
	}

	for i := range blocked {
		ans := uf.size(i) - friend[i] - 1
		for _, j := range blocked[i] {
			if uf.root(i) == uf.root(j) {
				ans--
			}
		}
		fmt.Fprintln(wr, ans)
	}
}

// union-find tree
type unionFind struct {
	pars []int
}

func newUnionFind(n int) *unionFind {
	uf := new(unionFind)
	uf.pars = make([]int, n)
	for i := range uf.pars {
		uf.pars[i] = -1
	}
	return uf
}

func (uf *unionFind) root(x int) int {
	if uf.pars[x] < 0 {
		return x
	}
	uf.pars[x] = uf.root(uf.pars[x])
	return uf.pars[x]
}

func (uf *unionFind) unite(_x, _y int) {
	x, y := uf.root(_x), uf.root(_y)
	if x == y {
		return
	}

	if uf.size(x) < uf.size(y) {
		x, y = y, x
	}
	uf.pars[x] += uf.pars[y]
	uf.pars[y] = x
}

func (uf *unionFind) same(x, y int) bool {
	return uf.root(x) == uf.root(y)
}

func (uf *unionFind) size(x int) int {
	return -uf.pars[uf.root(x)]
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


Measured memory_bytes: 13360
n,a,b=map(int,input().split())
s = int(n / (a + b))
x = 0
if n-s*(a+b) >= a:
    x = a
else:
    x = n-s*(a+b)

if a == 0:
    print("0")
elif n % (a+b) == 0:
    print(s*a)
elif n % (a+b) != 0:
    print(s*a + x)


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int b[100006];

int main(void) {
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);

    int n;
    cin >> n;

    vector<int> a;
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        b[t+2]++;
        b[t+1]++;
        b[t]++;
    }

    ll ma = -1;
    for(int i=0; i<100005; i++){
        if(ma < b[i]){
            ma = b[i];
        }
    }

    cout << ma << endl;
    
    return 0;
}


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

int main(){
    string s;
    while(1){
        getline(cin, s);
        if(s == ".") break;
        stack<char> st;
        bool f = true;
        rep(i, 0, s.size()){
            // cout << s[i] << endl;
            if(s[i] == '(') st.push(s[i]);
            if(s[i] == '[') st.push(s[i]);
            if(s[i] == ')'){
                if(st.empty()){
                    f = false;
                    break;
                }
                char c = st.top(); st.pop();
                if(c != '(') f = false;
            }
            if(s[i] == ']'){
                if(st.empty()){
                    f = false;
                    break;
                }
                char c = st.top(); st.pop();
                if(c != '[') f = false;
            }
        }
        // cout << 1 << endl;
        if(!st.empty()) f = false;
        cout << (f ? "yes" : "no") << endl;
    }
}

Measured memory_bytes: 3120
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
map<long long,long long>dp;
int T;
long long n,a,b,c,d;
long long solve(long long x)
{
	if(!x)return 0;
	if(x==1)return d;
	if(dp.count(x))return dp[x];
	long long x1,res=0x3f3f3f3f3f3f3f3f;
	if(d<=res/x)res=d*x;
	x1=x/5*5;
	if(x-x1<=2)res=min(res,solve(x/5)+c+(x-x1)*d);
	else res=min(res,solve(x/5+1)+c+(x1+5-x)*d);
	x1=x/3*3;
	if(x-x1<=1)res=min(res,solve(x/3)+b+(x-x1)*d);
	else res=min(res,solve(x/3+1)+b+(x1+3-x)*d);
	if(x%2==0)res=min(res,solve(x/2)+a);
	else
	{
		res=min(res,solve(x/2)+a+d);
		res=min(res,solve(x/2+1)+a+d);
	}
	return dp[x]=res;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&c,&d);
		dp.clear();
		printf("%lld\n",solve(n));
	//	for(auto p:dp)printf("%lld %lld\n",p.first,p.second);
	}
	return 0;
}

Measured memory_bytes: 4048
#include <cstring>
#include <algorithm>
#include <cstdio>

typedef long long ll;
const int N = 300010;
const int MOD = 998244353;
int _w;

int fpow( int a, int b ) {
	int c = 1;
	while(b) {
		if( b & 1 ) c = int(1LL * c * a % MOD);
		a = int(1LL * a * a % MOD);
		b >>= 1;
	}
	return c;
}

int inv( int x ) {
	return fpow(x, MOD-2);
}

ll n, a, b, k;

int C[N];

void prelude() {
	C[0] = 1;
	for( int i = 1; i <= n; ++i )
		C[i] = int(1LL * C[i-1] * (n-i+1) % MOD * inv(i) % MOD);
}

ll exgcd( ll a, ll b, ll &x, ll &y ) {
	if( !b ) {
		x = 1, y = 0;
		return a;
	} else {
		ll g = exgcd(b, a%b, y, x);
		y -= x*(a/b);
		return g;
	}
}

bool check( ll x ) {
	return x >= 0 && x <= n;
}

void solve() {
	ll g, x, y;
	g = exgcd(a, b, x, y);
	if( k % g ) {
		puts("0");
		return;
	}
	x *= k/g;
	y *= k/g;
	ll t = b/g;
	x %= t;
	x = (x + t) % t;
	int ans = 0;
	for( ll i = x; i <= n; i += t ) {
		ll j = (k-i*a)/b;
		if( !check(i) || !check(j) ) continue;
		ans = (ans + int(1LL * C[i] * C[j] % MOD)) % MOD;
	}
	printf( "%d\n", ans );
}

int main() {
	_w = scanf( "%lld%lld%lld%lld", &n, &a, &b, &k );
	prelude(), solve();
	return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int t = 0;
		int ans = -1;
		while (true) {
			int nt = t + A;
			while (C < t) C += 60;
			if (t <= C && C <= nt) {
				ans = C;
				break;
			}
			t = nt + B;
			if (t % 60 == 0) break;
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 17328
#include <iostream>

using namespace std;

int main(){

    int N, X;
    cin>>N>>X;
    int arr[N];
    int i, count = 1, sum = 0;
    for(i=0; i<N; i++){
        cin>>arr[i];
    }

    for(i=0; i<N; i++){
        sum += arr[i];
        if(sum <= X){
            count++;
        }
    }

    cout<<count<<endl;

}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;
const int N=2e5+5;

int main(){
    ll A, V; cin >> A >> V;
    ll B, W; cin >> B >> W;
    ll T; cin >> T;
    bool ans=false;
    if(A <= B){
        if(A+V*T >= B+W*T) ans=true;
    }
    else{
        if(A-V*T <= B-W*T) ans=true;
    }
    cout << (ans ? "YES":"NO") << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline void chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
}
template <class T1, class T2>
inline void chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<uint64_t> A(N);
    rep(i, N) { cin >> A[i]; }
    uint64_t all = 0;
    rep(i, N) { all ^= A[i]; }

    vector<uint64_t> ans;

    rep(i, N) {
        uint64_t num;
        num = A[i] ^ all;
        ans.emplace_back(num);
    }

    rep(i, ans.size() - 1) { cout << ans[i] << " "; }
    cout << ans[ans.size() - 1] << endl;
}

Measured memory_bytes: 6884
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...)                                                             \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    void solve() {
        string s;
        cin >> s;
        string s0, s1;
        int q;
        cin >> q;
        int f = 0;
        while (q--) {
            int t;
            cin >> t;
            if (t == 1) {
                f ^= 1;
            } else {
                int a;
                string t;
                cin >> a >> t;
                if (a == 2) {
                    if (f == 0) {
                        s1.push_back(t[0]);
                    } else {
                        s0.push_back(t[0]);
                    }
                } else {
                    if (f == 0) {
                        s0.push_back(t[0]);
                    } else {
                        s1.push_back(t[0]);
                    }
                }
            }
        }
        reverse(s0.begin(), s0.end());
        s = s0 + s + s1;
        if (f) {
            reverse(s.begin(), s.end());
        }
        cout << s << "\n";
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int A,B,C,D; cin >> A >> B >> C >> D;

    cout << max(min(B,D) - max(A,C),0) << endl;

    return 0;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        long ans = 0;
        int min = Math.min(x,y);
        if(a+b >= c*2){
            ans += min * 2 * c;
            
        }else{
            ans += min * (a + b);
        }
        x -= min;
        y -= min;
        if(x > 0){
            ans += Math.min(a,c*2) * x;
        }else if(y > 0){
            ans += Math.min(b,c*2) * y;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var Xi = Sarray();
            var midNum = N / 2;
            var sortedX = Xi.OrderBy(x => x).ToArray();
            var midl = sortedX[midNum - 1];
            var midr = sortedX[midNum];
            for (var i = 0; i < N; ++i)
            {
                if (Xi[i] < midr)
                    WriteLine(midr);
                else
                    WriteLine(midl);
            }
        }


        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 58716
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 10e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  int N,M,C;
  cin >> N >> M >> C;
  int A[N][M];
  int B[M];
  rep(i,M) cin >> B[i];
  int cnt = 0;
  rep(i,N)
  {
    rep(j,M) cin >> A[i][j];
    int tmp = 0;
    rep(j,M) tmp += A[i][j] * B[j];
    if(tmp + C > 0) cnt ++ ; 
  }  
  cout << cnt <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using P = pair<int,int>;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    string S;
    int K,beforesum = 0,N,lastsum = 0,beforesuma = 0;
    cin >> S >> K;
    N = S.size();
    if(K == 1){
        cout << 9*N-9+S[0]-48<< "\n";
    }else if(K == 2){
        if(N == 1){
            cout <<0<< "\n";
        }else{
            beforesum = 9*9*(N-1)*(N-2)/2+(S[0]-49)*(N-1)*9;
            int oka = 0;
            REP(i,N-1){
                if(S[i+1] != '0'){
                    oka = i+1;
                    break;
                }
            }
            if(oka != 0){
                lastsum = (N-oka-1)*9+S[oka] - 48;
            }
            cout <<beforesum + lastsum<< "\n";
        }
    }else if(K == 3){
        if(N < 3){
            cout <<0<< "\n";
        }else{
            beforesum = (N-3)*(N-2)*(N-1)*9*9*9/6+(S[0]-49)*(N-1)*(N-2)/2*9*9;
            int oka = 0;
            REP(i,N-1){
                if(S[i+1] != '0'){
                    oka = i+1;
                    break;
                }
            }
            if(oka != 0){
                string Sa;
                Sa = S.substr(oka,N-oka);
                int Na = Sa.size();
                if(Na == 1){
                    cout <<0<< "\n";
                }else{
                    beforesuma = 9*9*(Na-1)*(Na-2)/2+(Sa[0]-49)*(Na-1)*9;
                    int okaa = 0;
                    REP(i,Na-1){
                        if(Sa[i+1] != '0'){
                            okaa = i+1;
                            break;
                        }
                    }
                    if(okaa != 0){
                        lastsum = (Na-okaa-1)*9+Sa[okaa] - 48;
                    }
                    lastsum = beforesuma + lastsum;
                }
            }
            cout <<beforesum + lastsum<< "\n";
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,-1,1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int H,W;
    cin >> H >> W;
    vector<string> G(H);
    rep(i,H) cin >> G[i];
    vector<vector<bool>> ok(H,vector<bool> (W,true));
    rep(i,H){
        rep(j,W){
            if(G[i][j] == 'o'){
                ok[i][j] = false;
                int ny = i;
                int nx = j+1;
                if(nx<W){
                    ok[ny][nx] = false;
                }
                nx = j-1;
                if(nx>=0){
                    ok[ny][nx] = false;
                }
            }else if(G[i][j] == 'x'){  
                ok[i][j] = false;
                for(int k=0; k<8; k++){
                    int ny = i+dy[k];
                    int nx = j+dx[k];
                    if(ny<0 or ny>=H or nx<0 or nx>=W) continue;
                    ok[ny][nx] = false;
                }
            }
        }
    }
    // for(int i=0; i<H; i++){
    //     for(int j=0; j<W; j++){
    //         cout << (ok[i][j]) << " \n"[j+1==W];
    //     }
    // }
    int cnt = 0;
    for(int i=1; i<H; i++){
        rep(j,W){
            if(ok[i][j]) cnt++;
        }
    }
    cout << cnt << "\n";
    return 0;
}



Measured memory_bytes: 3268
#include <stdio.h>
#include <vector>
using std::vector;

#define  N_max 200005

#define  left(x) ((x)<<1)
#define right(x) (((x)<<1)|1)
#define  mid(l,r) (l+((r-l)>>1))
#define  max(a,b) ((a)>(b)?(a):(b))
int lch[N_max << 2], rch[N_max << 2], lzy[N_max << 2], val[N_max << 2];

inline void lzydown(int cur)
{
	if(lzy[cur])
	{
		int l = left(cur), r = right(cur);
		lzy[l] += lzy[cur];
		lzy[r] += lzy[cur];
		val[l] += lzy[cur];
		val[r] += lzy[cur];
		lzy[cur] = 0;
	}
}

inline void updup(int cur)
{
	val[cur] = max(val[left(cur)], val[right(cur)]);
}

void build(int cur, int cl, int cr)
{
	lch[cur] = cl; rch[cur] = cr;
	if (cl == cr) {
		val[cur] = cr;
		return;
	}
	int m = mid(cl, cr);
	build(left(cur), cl, m);
	build(right(cur), m + 1, cr);
	updup(cur);
}

void add(int cur,int cl,int cr)
{
	if(lch[cur]==cl&&rch[cur]==cr)
	{
		lzy[cur]++;
		val[cur]++;
		return;
	}
	lzydown(cur);
	int m = mid(lch[cur],rch[cur]);
	if (cr <= m)
	{
		add(left(cur), cl, cr);
	}
	else if(cl>m)
	{
		add(right(cur), cl, cr);
	}
	else
	{
		add(left(cur), cl, m);
		add(right(cur), m + 1, cr);
	}
	updup(cur);
}

int query(int cur,int cl,int cr)
{
	if (lch[cur] == cl&&rch[cur] == cr)
	{
		return val[cur];
	}
	int m = mid(lch[cur], rch[cur]);
	lzydown(cur);
	if (cr <= m)
	{
		return query(left(cur), cl, cr);
	}
	else if (cl>m)
	{
		return query(right(cur), cl, cr);
	}
	else
	{
	int ql=	query(left(cur), cl, m);
	int qr=	query(right(cur), m + 1, cr);
	return max(ql, qr);
	}
	return -1;
}

vector<int> ipt[N_max];
int ans = 0;
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	ans = max(0,n - m);
	int a[2];
	for(int i=0;i<n;++i)
	{
		scanf("%d %d", a, a + 1);
		ipt[a[0]].push_back(a[1]);
	}
	build(1, 0, m + 1);
	for(int l=0;l<=m;++l)
	{
		int sz = ipt[l].size();
		for(int t=0;t<sz;++t)
		{
			int r = ipt[l][t];
			add(1, 0, r);
		}
		int temp = query(1, l + 1, m + 1) - m - l - 1;
		ans = max(ans, temp);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 20224
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++)
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
char buf[1<<23],*p1=buf,*p2=buf;
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int aoi=2038,mod=1e9+7;
ll dp[aoi],inv[aoi];

ll kasumi(ll a,ll b=mod-2) {
ll s=1;
for (;b;b>>=1,a=a*a%mod) if (b&1) s=s*a%mod;
return s;
}

int main() {
int n,a,b,c,d,i,j,k;
read(n),read(a),read(b),read(c),read(d);
for (dp[n]=i=1;i<=n;++i) dp[n]=dp[n]*i%mod;
inv[n]=kasumi(dp[n]);
for (i=n;i;--i) inv[i-1]=inv[i]*i%mod;
for (i=a;i<=b;++i)
  for (j=0;j<=n;++j) 
    for (k=c;k<=d&&j+i*k<=n;++k) 
      dp[j]=(dp[j]+dp[j+i*k]*kasumi(inv[i],k)%mod*inv[k]%mod)%mod;
cout<<*dp<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
long long pow(long long x,long long a){
  long long ans = 1;
  for(int i = 0;i<a;i++){
    ans *= x;
    ans %= 1000000007;
  }
  return ans;
}
 
int main() {
  long long N;
  cin >> N;
  long long sum = 0;
  long long non9, non0, non0_9;
  non9 = pow(9, N);
  non0 = pow(9, N);
  non0_9 = pow(8, N);
  sum = pow(10,N)-non9-non0+non0_9;
  sum %= 1000000007;
  sum += 1000000007;
  sum %= 1000000007;
  cout << sum << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int n,m,a,b,t[55][55]={};
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		t[a][b]++;
		t[b][a]++;
	}
	for(int i=1;i<=n;i++)
	{
		int sum=0;
		for(int j=1;j<=n;j++)
		{
			sum+=t[i][j];
		}
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String args[]){
		new Main().mainrun();
	}

	private Scanner scan;
	private int n,q;
	private int[] A;

	private void mainrun() {
		scan = new Scanner(System.in);

		n = scan.nextInt();
		q = scan.nextInt();
		A = new int[n];

		Arrays.fill(A,0);

		for(int i = 0;i < q;i++) {
			switch(scan.nextInt()) {
			case 0:
				add(scan.nextInt(),scan.nextInt());
				break;
			case 1:
				getSum(scan.nextInt(),scan.nextInt());
				break;
			}
		}

		scan.close();
	}

	private void add(int i,int x) {
		A[i-1] += x;
	}

	private void getSum(int s,int t) {
		int sum = 0;
		for(int i = s-1;i <= t-1;i++) {
			sum += A[i];
		}
		System.out.println(sum);
	}
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int n,a,now=1,cnt=0;
    bool one = false;
    cin >> n;
    rep(i, n) {
        cin >> a;
        if (a == 1)one = true;
        if (a != now)cnt++;
        else now++;
    }
    //if (!one || cnt >= n - 1 && n != 1)cout << -1 << endl;
    if (!one || now <= 1 && n != 1)cout << -1 << endl;
    else cout << cnt << endl;
}

Measured memory_bytes: 256
#%%
"""
#(w+h-1) C w
a,b = 1, 1
for i in range(1, w+h-1):
    a *= i
    a %= mod
for i in range(1, w):
    b *= i
    b %= mod
for i in range(1, h):
    b *= i
    b %= mod

ans = a * pow(b, mod-2, mod) % mod
"""

n, k = map(int, input().split())
mod = 10**9 + 7

for i in range(1, k+1):
    if i <= n - k + 1: 
        a, b, c, d = 1, 1, 1, 1
        for j in range(1, n-k+1+1):
                a *= j
                a %= mod
        for j in range(1, i+1):
                b *= j
                b %= mod
        for j in range(1, n-k+1-i+1):
                b *= j
                b %= mod
        for j in range(1, k-1+1):
                c *= j
                c %= mod
        for j in range(1, i-1+1):
                d *= j
                d %= mod
        for j in range(1, k-i+1):
                d *= j
                d %= mod
        #print(a, b, c, d)
        ans = a * pow(b, mod-2, mod) * c * pow(d, mod-2, mod) 
        ans %= mod
    else:
        ans = 0
    print(ans)

Measured memory_bytes: 46972
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int INF=99999;
typedef struct p{int pos,dis;}p;
typedef struct e{int to,cost;}e;


int N,M,L,K,A,H,C[100],D[100];;


struct Order
{
	bool operator ()(p const& a, p const& b) const
	{
		return a.dis>b.dis;
	}
};

void dij(int s,vector<e>E[100])
{
	priority_queue<p,vector<p>,Order>Q;
	fill(D,D+N,INF);
	D[s]=0;
	p tmp={s,0};
	Q.push(tmp);
	for(;!Q.empty();)
	{
		tmp=Q.top();Q.pop();
		if(D[tmp.pos]<tmp.dis)continue;
		for(int i=0;i<E[tmp.pos].size();i++)
		{
			e next=E[tmp.pos][i];
			if(D[next.to]>D[tmp.pos]+next.cost)
			{
				D[next.to]=D[tmp.pos]+next.cost;
				p ins={next.to,D[tmp.pos]+next.cost};
				Q.push(ins);
			}
		}
	}
}

int main()
{
	for(;scanf("%d%d%d%d%d%d",&N,&M,&L,&K,&A,&H),N;)
	{
		vector<e> G[100],G2[100];
		memset(C,0,sizeof(C));
		C[A]=C[H]=1;
		for(int i=0;i<L;i++)
		{
			int t;
			scanf("%d",&t);
			C[t]=1;
		}
		for(int i=0;i<K;i++)
		{
			int x,y,t;
			scanf("%d%d%d",&x,&y,&t);
			e e1={x,t},e2={y,t};
			G[y].push_back(e1);
			G[x].push_back(e2);
		}
		for(int i=0;i<N;i++)
		{
			dij(i,G);
			for(int j=0;j<N;j++)
			{
				if(C[j])
				{
					if(i!=j&&D[j]<=M)
					{
						e e1={j,D[j]};
						G2[i].push_back(e1);
					}
				}
			}
		}
		dij(A,G2);
		if(D[H]==INF)
			puts("Help!");
		else
			printf("%d\n",D[H]-min(0,M-D[H]));
	}
}

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


int main() {
    int N;
    cin >> N;
    int a;
    int sum = 0;

    for (int i = 1; i <= N; i++) {
        cin >> a;
        if (i%2 == 1 && a%2 == 1) sum++;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
using namespace std;
template <typename T> ostream & operator << (ostream & out, vector<T> const & xs) { REP (i, (int)xs.size() - 1) out << xs[i] << ' '; if (not xs.empty()) out << xs.back(); return out; }

vector<int> solve(int n, const vector<int> & a) {
    vector<int> b;
    vector<bool> used(n);
    REP_R (i, n) {
        int cnt = 0;
        for (int k = i + 1; k <= n; k += i + 1) {
            cnt += used[k - 1];
        }
        if (cnt % 2 != a[i]) {
            b.push_back(i + 1);
            used[i] = true;
        }
    }
    return b;
}

int main() {
    int n; cin >> n;
    vector<int> a(n);
    REP (i, n) {
        cin >> a[i];
    }
    auto b = solve(n, a);
    cout << b.size() << endl;
    cout << b << endl;
    return 0;
}


Measured memory_bytes: 2428
import math

D, G = map(int, input().split())
P = []

for i in range(D):
  p, c = map(int, input().split())
  P.append(((i + 1)*100, p, c))

ans = float("inf")
for i in range(2 ** D):

  score = 0
  count = 0
  maxj = -1

  for j in range(D):
    # print(i, j, bin(i), bin(j), i >> j, ((i >> j) & 1))
    if ((i >> j) & 1):
      val, p, c = P[j]
      score += c + (val * p)
      count += p
    else:
      maxj = max(maxj, j)

  if maxj == -1:
    if score >= G:
      ans = min(ans, count)
  else:
    val, p, c = P[maxj]
    if score + val * (p - 1) >= G:
      s = max(0, math.ceil((G-score) / val ))
      ans = min(ans, count + s)

print(ans) 

Measured memory_bytes: 3064