akhauriyash/Code-Regression huggingface dataset:
n, c = map(int, input().split())
xvs = [tuple(map(int, input().split())) for _ in range(n)]

forward_cals = [(0, 0, 0)]
for x, v in xvs:
    cal, max_cal, pos = forward_cals[-1]
    new_cal = cal + v - (x - pos)
    new_max_cal = max(max_cal, new_cal)
    forward_cals.append((new_cal, new_max_cal, x))

backward_cals = [(0, 0, c)]
for x, v in reversed(xvs):
    cal, max_cal, pos = backward_cals[-1]
    new_cal = cal + v - (pos - x)
    new_max_cal = max(max_cal, new_cal)
    backward_cals.append((new_cal, new_max_cal, x))

ans = max((forward_cals[-1][1], backward_cals[-1][1]))

for (cal, max_cal, pos), (_, back_max, __) in zip(forward_cals, reversed(backward_cals)):
    ans = max(ans, cal - pos + back_max)

for (__, for_max, _), (cal, max_cal, pos) in zip(reversed(forward_cals), backward_cals):
    ans = max(ans, cal - (c-pos) + for_max)

print(ans)

Measured memory_bytes: 39924
s = input()
t = input()
result = ''
length = len(s)-len(t)
while length>=0:
  skip = False
  for i in range(len(t)):
    if s[length+i]!='?' and s[length+i]!=t[i]:
      skip = True
      break
  if skip==False:
    break
  length-=1
    
if length<0:
  print("UNRESTORABLE")
else:
  i = 0
  while i<len(s):
    if i==length:
      result+=t
      i+=len(t)-1
    else:
      if s[i]=='?':
        result+='a'
      else:
        result+=s[i]
    i+=1
  print(result)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  int ans=1000000000;

  //ABセットを1~max(x,y)セットだけ買う全探索を行う．
  //ABをiセット買うとして，Aはx-i,Bはy-iセットとなる．
  //ABを過剰に買う場合，足りない方のみを買いたいので
  for(int i=0;i<=max(x,y);i++)
  {
    int sum=0;
    if(i<=x)  sum+=a*(x-i);
    if(i<=y)  sum+=b*(y-i);
    sum+=2*c*i;

    ans=min(sum,ans);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

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

struct UnionFind{
    v: Vec<usize>
}

impl UnionFind{
    fn new(n: usize) -> UnionFind{
        let mut v: Vec<usize> = Vec::new();
        for i in 0..n{
         v.push(i);
        }
        UnionFind{v:v}
    }

    fn find(&mut self, i: usize) -> usize{
        if self.v[i] == i{
            i
        }else{
            let ni = self.v[i];
            self.v[i] = self.find(ni);
            self.v[i]
        }
    }

    fn union(&mut self, i: usize, j: usize){
        let root_i = self.find(i);
        let root_j = self.find(j);
        self.v[root_i] = root_j;
    }

}

struct CombMod{
    fac: Vec<u64>,
    inv: Vec<u64>,
    finv: Vec<u64>,
    mmod: u64,
}

impl CombMod{
    pub fn new(max: u64, m: u64) -> CombMod{
        let max: usize = max as usize;
        let mut fac: Vec<u64> = vec![0;max+1];
        let mut finv: Vec<u64> = vec![0;max+1];
        let mut inv: Vec<u64> = vec![0;max+1];

        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;

        for i in 2..max+1{
            fac[i] = fac[i-1] * i as u64 % m;
            inv[i] = m - inv[m as usize %i] * (m/(i as u64)) % m;
            finv[i] = finv[i-1] * inv[i] % m;
        }

        CombMod{
            fac: fac,
            finv: finv,
            inv: inv,
            mmod: m,
        }
    }

    fn get(&self, n: u64, m: u64) -> u64{
        assert!(n >= m && n != 0 && m != 0);
        self.fac[n as usize] * self.finv[m as usize] % self.mmod
            * self.finv[(n-m) as usize] % self.mmod
    }
}

fn main(){
    let res: Vec<u32> = read_as_vec();

    let mut ans = 0;
    //bonus
    if res[0] ==1 && res[1] == 1{
        ans += 400000;
    }

    for r in res{
        if r == 1{
            ans += 300000;
        }else if r == 2{
            ans += 200000;
        }else if r == 3{
            ans += 100000;
        }
    }

    println!("{}", ans);

}


Measured memory_bytes: 4352
#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 dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main()
{
string a,b,c;
cin>>a>>b>>c;
cout<<a[0]<<b[0]<<c[0]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef pair <int, int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int N = 2005;
int n, k, q, a[N], res = (int)2e9, ans[N];
ordered_set S;

void solve(int lw) {
	S.clear();
	memset(ans, 0, sizeof ans);
	int pre = 1;
	for (int i = 1; i <= n; ++i) {
		if (a[i] < lw) {
			pre = i + 1;
			S.clear();
		} else {
			S.insert({a[i], i});
			ans[i] += i - pre + 1 - S.order_of_key({a[i], i});
		}
	}
	pre = n;
	S.clear();
	for (int i = n; i >= 1; --i) {
		if (a[i] < lw) {
			pre = i - 1;
			S.clear();
		} else {
			S.insert({a[i], i});
			ans[i] += pre - i - S.order_of_key({a[i], 0});
		}
	}
	vector <int> val; val.clear();
	for (int i = 1; i <= n; ++i) if (a[i] >= lw && ans[i] >= k) {
		val.push_back(a[i]);
	}
	if (val.size() < q) return;
	sort(val.begin(), val.end());
	res = min(res, val[q - 1] - lw);
	// cerr << "Ans for " << lw << " is " << val[q - 1] - lw << endl;
}

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(0); cin.tie(0);

	cin >> n >> k >> q;
	for (int i = 1; i <= n; ++i)
		cin >> a[i];
	for (int i = 1; i <= n; ++i) {
		solve(a[i]);
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    string t = "2019/04/30";
    string s;
    cin >> s;
    if (t >= s) cout << "Heisei" << endl;
    else cout << "TBD" << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()

a = int(S[:2])
b = int(S[2:])

if (1 <= a <= 12) and (1 <= b <= 12) :
    print("AMBIGUOUS")
elif (1 <= a <= 12) :
    print("MMYY")
elif (1 <= b <= 12) :
    print("YYMM")
else :
    print("NA")

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	while(cin>>n,n!=0){
		vector<vector<int>> p(4*n,vector<int>(4*n,0));

		map<int,P> m;
		m[0]=P(2*n,2*n);
		p[2*n][2*n]=1;
		vector<tuple<int,int,int>> s(n-1);
		rep(i,n-1){
			int a,b;
			cin>>a>>b;
			tuple<int,int,int> t= make_tuple(a,i+1,b);
			s[i]=t;
		}
		sort(all(s));
		rep(i,n-1){
			tuple<int,int,int> t=s[i];
			int idx=get<1>(t);
			int from=get<0>(t);
			int angle=get<2>(t);

			P point=m[from];
			// cout<<angle<<endl;
			if(angle==0) point.second--;
			if(angle==1) point.first++;
			if(angle==2) point.second++;
			if(angle==3) point.first--;

			m[idx]=point;
			p[point.first][point.second]=1;
		}
		int l=-1,r=-1,u=-1,d=-1;
		rep(i,4*n){
			rep(j,4*n){
				if(p[i][j]==1){
					if(u<0)u=i;
					d=i;
				}
			}
		}
		rep(j,4*n){
			rep(i,4*n){
				if(p[i][j]==1){
					if(l<0)l=j;
					r=j;
				}
			}
		}
		
		cout<<abs(l-r)+1<<" "<<abs(u-d)+1<<endl;
	}
	return 0;
}


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

int main(){
    int k,x;
    cin >> k >> x;
    int s = x-(k-1);
    rep(i,k){
        cout << s << " ";
        s++;
    }
    rep(i,k-1){
        cout << x + 1 << " ";
        x++;
    }
}

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

int main(){
	int n, m;
	bool *map;
	while( cin >> n >> m, n||m ){
		map = new bool[n];
		int pot = n-1;
		for( int i=0; i<n; i++ )	map[i] = false;
		for( int i=0; i<n-1; i++ ){
			for( int j=0; j<m; j++ ){
				pot++;
				if( pot >= n )	pot -= n;
				if( map[pot] ) j--;
			}
		map[pot] = true;
		}
		for( int i=0; i<n; i++ )
			if( !map[i] )	cout << (i+1) << endl;
		delete[] map;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 1e9;
const ll INFll = 1e18;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

ll dp[100000][2] = {0};
vector<int> G[100000];
void dfs(int x,int p){
  dp[x][0] = dp[x][1] = 1;
  for (auto next:G[x]){
    if (next != p){
      dfs(next,x);
      dp[x][0] *= dp[next][0] + dp[next][1];
      dp[x][0] %= MOD;
      dp[x][1] *= dp[next][0];
      dp[x][1] %= MOD;
    }
  }
}

int main(){
  int N;
  cin>>N;
  for (int i(0);i<N-1;i++){
    int x,y;
    cin>>x>>y;
    x--;y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(0,0);
  cout << (dp[0][0] + dp[0][1]) % MOD << endl;
  return 0;
}


Measured memory_bytes: 12800
import java.io.*;
import java.util.StringTokenizer;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] a = sc.nextIntArray(n);
        boolean app = true;
        for (int x : a) {
            if (x % 2 == 0)
                if (x % 5 != 0 && x % 3 != 0) app = false;

        }
        out.println(app?"APPROVED":"DENIED");
        out.flush();
        out.close();
    }


    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        boolean ready() throws IOException {
            return br.ready();
        }


        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

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

        public int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) throws IOException {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }


        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int k,s;
  cin>>k>>s;
  int cnt = 0;
  rep(i,k+1){
    rep(j,k+1){
      int c = s-i-j;
      if(c<0)continue;
      if(c <= k)cnt++;
    }
  }
  print(cnt);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  	int N,T[101],M,p[2],sum=0,i;
  	
  	scanf("%d",&N);
  	for(i=0;i<N;i++){
    	scanf("%d",&T[i]);
      	sum+=T[i];
    }
  
  	scanf("%d",&M);
  	for(i=0;i<M;i++){
    	scanf("%d %d",&p[0],&p[1]);
      	printf("%d\n",sum-(T[p[0]-1]-p[1]));
    }	
  
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	int a[n];
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	for(int i = 0; i < n - k; i++)
	{
		a[i] < a[i + k]? puts("Yes") : puts("No");
	}
	return 0;
}

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

int main(){
    int a[3];
    for(int i = 0; i < 3; i++){
        cin >> a[i];
    }
    sort(a, a+3);
    printf("%d %d %d\n", a[0], a[1], a[2]);
    return 0;
}


Measured memory_bytes: 3220
package main

import (
	"fmt"
)

func main() {
	var n int64
	fmt.Scan(&n)

	// 1 1 2*1 3*1 4*2 5*3 6*4*2
	// nが偶数のとき
	//  10, 20, ..., 100, 110, ...
	//  のときに0が増え、それ以外では増えない
	//  10で割ったときの商 + 100で割ったときの商 + 1000で割ったときの商 + ...
	//  5が入っている分の考慮が必要...10や100などで割ったあとに5で割れる回数だけ余分に0が増える
	// nが奇数のとき
	//  0
	// 10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160
	// 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16

	if n%2 == 1 {
		fmt.Println(0)
	} else {
		var ans int64 = 0
		var divBase int64 = 10
		for n/divBase != 0 {
			zeros := n / divBase
			ans += zeros
			for zeros/5 > 0 {
				ans += zeros/5 - zeros/10
				zeros /= 5
			}
			divBase *= 10
		}
		fmt.Println(ans)
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <valarray>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <bitset>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>

using namespace std;

#define all(c) c.begin(),c.end()
#define repeat(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")"<< endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<string> vs;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec){
    os << "[";
    for(int i = 0; i < vec.size(); i++){
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template<typename T>
T input(){
    T t;
    cin >> t;
    return t;
}

template<typename T>
vector<T> input(const int N){
    vector<T> v(N);
    repeat(i,N) cin >> v[i];
    return v;
}

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

long long lcm(long long a, long long b){
    return (a / gcd(a, b)) * b;
}

long long mul(const long long& a, const long long& b, const long long& mod) {
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod) {
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod) {
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod) {
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x) {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int main(){
    int N;
    int K;
    cin >> N;
    cin >> K;
    int minDistance = 0;
    int x;
    repeat (i, N) {
        cin >> x;
        minDistance += min(x, abs(K - x));
    }
    cout << minDistance * 2 << endl;
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

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

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    string s;
    cin>>s;
    if(s.size()==2){
        cout<<s<<endl;
    }else{
        reverse(s.begin(),s.end());
        cout<<s<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
	string s;
	cin >> s;
	if ((s.size() % 2 == 1 && s.front() == s.back()) 
		|| (s.size() % 2 == 0 && s.front() != s.back())) {
		cout << "Second" << endl;
	} else {
		cout << "First" << endl;
	}
}


Measured memory_bytes: 512
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int c[] = new int[m];
        for(int i = 0 ; i < m ; i++)
            c[i] = sc.nextInt();
        int dp[][] = new int[m+1][n+1];
        dp[0][0] = 0;
        for(int i = 1 ; i <= n ; i++)
            dp[0][i] = 100000;
        for(int i = 1 ; i <= m ; i++){
            for(int j = 0 ; j <= n ; j++){
                if(c[i-1] <= j)
                    dp[i][j] = Math.min(dp[i-1][j],dp[i][j-c[i-1]] + 1);
                else
                    dp[i][j] = dp[i-1][j];
            }
        }
        System.out.println(dp[m][n]);
    }
}


Measured memory_bytes: 30908
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n, total = 0, ans = 100;
  int s1 = 0, s2 = 0, s3 = 0;
  //int s1, s2, s3 = 0;
  int w[100];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&w[i]);
    total += w[i];
  }
  for(int i=0; i<n; i++){
    s1 = s1 + w[i];
    s2 = total - s1;
    s3 = abs(s2 - s1);
    //printf("%d - %d = %d\n", s1 ,s2, s3);
    if(s3 < ans){
      ans = s3;
    }
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int A, B;
	cin >> A >> B;
	if (A > 12)cout << B;
	else if (A > 5)cout << B / 2;
	else cout << 0;
}


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

int n;ll x;
ll b[200000],l[200000],u[200000];
P s[200000];
int id[200000];
ll sum=0;

bool C(ll t){
	ll m=t/x;
	if(m>=n)return true;
	ll S=0;
	rep(i,m)S+=s[i].first;
	ll r=t%x;
	ll Max=0;
	rep(i,n){
		ll d=(id[i]<m?S-s[id[i]].first+s[m].first:S);
		if(r<=b[i])d+=r*l[i];
		else d+=b[i]*l[i]+(r-b[i])*u[i];
		Max=max(Max,d);
	}
	return sum+Max>=0;
}

int main(){
	cin>>n>>x;
	rep(i,n){
		scanf("%lld%lld%lld",&b[i],&l[i],&u[i]);
		sum-=b[i]*l[i];
		s[i]=P(b[i]*l[i]+(x-b[i])*u[i],i);
	}
	sort(s,s+n,greater<>());
	rep(i,n)id[s[i].second]=i;
	ll ok=n*x,ng=-1;
	while(ok-ng>1){
		ll md=(ok+ng)/2;
		if(C(md))ok=md;
		else ng=md;
	}
	cout<<ok<<endl;
}

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

#define int long long
//#define uint __int128_t

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int H,W;
string s[404];
int used[404][404];
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};
int si,sj;
//vector<PP> mp;
int siro=0;
int kuro=0;
int ans=0;

void bfs(int i,int j,int iro){
    used[i][j]=(si+1)*404+sj;
    if(iro)kuro++;
    else siro++;
    rep(k,0,4){
        if(iro){
            int ni=i+dy[k],nj=dx[k]+j;
            if(used[ni][nj]==(si+1)*404+sj)continue;
            if(ni<0||H<=ni||nj<0||W<=nj)continue;
            if(s[ni][nj]=='#')continue;
            bfs(ni,nj,0);
        }else{
            int ni=i+dy[k],nj=dx[k]+j;
            if(used[ni][nj]==(si+1)*404+sj)continue;
            if(ni<0||H<=ni||nj<0||W<=nj)continue;
            if(s[ni][nj]=='.')continue;
            //mp.pb(PP(pint(si,sj),pint(ni,nj)));
            bfs(ni,nj,1);
        }
    }
}

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    cin>>H>>W;
    rep(i,0,H){
        cin>>s[i];
    }
    rep(i,0,H){
        rep(j,0,W){
            if(s[i][j]=='.'){
                siro=0,kuro=0;
                bfs(i,j,0);
                ans+=siro*kuro;
            }
        }
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

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

using namespace std;

const int INF = 1e9;
const int N = 1e5;
const int MOD = 998244353;

const double PI = acos(-1);



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    int a[n];
    for (int &x : a)
        cin >> x;
    bool ok = 1;
    for (int x : a) {
        if (x % 2 == 0 && x % 3 != 0 && x % 5 != 0)
            ok = 0;
    }
    if (ok)
        cout << "APPROVED";
    else
        cout << "DENIED";
}

Measured memory_bytes: 256
/*g++ main.cpp -o main.out*/
/*./main.out*/

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

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

LL Pow(LL a, LL n, LL m)
{
    LL t = 1;
    for (; n; n >>= 1, a = (a * a % m))
        if (n & 1)
            t = (t * a % m);
    return t;
}
const LL p=1000000007;
vector<LL> v;
LL dp[1101];
LL Cal(LL l, LL r, LL k, LL dis)
{
    LL res = 1;
    for (LL i = l; i <= r; i++)
    {
        LL t = i;
        for (LL j = 0; j < v.size(); j++)
        {
            LL y = v[j];
            while (t % y == 0) dp[j] += dis, t /= y;
        }
        res = res * (LL)t % k;
    }
    return res;
}
LL inv(LL a, LL p) { return Pow(a, p - 2, p); }
LL Comb(LL n, LL m, LL k)
{
    memset(dp, 0, sizeof(dp));
    v.clear();
    LL tmp = k;
    for (LL i = 2; i * i <= tmp; i++)
        if (tmp % i == 0)
        {
            LL num = 0;
            while (tmp % i == 0) tmp /= i, num++;
            v.push_back(i);
        }
    if (tmp != 1) v.push_back(tmp);
    LL ans = Cal(n - m + 1, n, k, 1);
    for (LL j = 0; j < v.size(); j++) ans = ans * Pow(v[j], dp[j], k) % k;
    ans = ans * inv(Cal(2, m, k, -1), k) % k;
    return ans;
}


int main()
{
    LL n,a,b;
    cin>>n>>a>>b;
    LL ans=(Pow(2,n,Mod)-1+Mod)%Mod;
    ans=((ans-Comb(n,a,p)+Mod)%Mod-Comb(n,b,p)+Mod)%Mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
 
class Program{
  static void Main(){
    
    int input = int.Parse(Console.ReadLine());
    int first =input/100;
    int latter=input-first*100;
    string ans;
    
    if(first<=12&&first>0){
      if(latter<=12&&latter>0){
        ans="AMBIGUOUS";
      }
      else{
        ans="MMYY";
      }
    }else{
      if(latter<=12&&latter>0){
        ans="YYMM";
      }
      else{
        ans="NA";
      }
    }

    Console.Write(ans);
    
  }
}

Measured memory_bytes: 27300
def slove(n, a):
    tmp = sum(a)
    if n < tmp:
        return -1
    else:
        return n - tmp
    return ans

if __name__ == "__main__":
    n, m = [int(i) for i in input().split()]
    a_list = [int(i) for i in input().split()]
    print(slove(n, a_list))


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;

int main(){
    ll H, W; cin >> H >> W;
    if(H > W) swap(H, W);
    if(H % 3 == 0 || W % 3 == 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1e10;

    for(int i = 1; i <= W/2+1; i++){
        ll MIN = 1e9, MAX = 0;
        ll b1 = i*H;
        ll b = H*W-b1;
        ll b2 = b - (H/2) * (W-i);
        ll b3 = b-b2;
        MAX = max(b1, b2);
        MAX = max(MAX, b3);
        MIN = min(b1, b2);
        MIN = min(MIN, b3);
        ans = min(ans, MAX-MIN);
        //cout << b1 << " " << b2 << " " << b3 << " " << b1+b2 + b3 << endl;
        
        b2 = ((W-i)/2)*H;
        b3 = b-b2;
        MAX = max(b1, b2);
        MAX = max(MAX, b3);
        MIN = min(b1, b2);
        MIN = min(MIN, b3);
        ans = min(ans, MAX-MIN);
        //cout << ans << endl;
    }

        for(int i = 1; i <= H/2+1; i++){
        ll MIN = 1e9, MAX = 0;
        ll b1 = i*W;
        ll b = H*W-b1;
        ll b2 = b - (W/2) * (H-i);
        ll b3 = b-b2;
        MAX = max(b1, b2);
        MAX = max(MAX, b3);
        MIN = min(b1, b2);
        MIN = min(MIN, b3);
        ans = min(ans, MAX-MIN);
        //cout << b1 << " " << b2 << " " << b3 << " " << b1+b2 + b3 << endl;
        
        b2 = ((H-i)/2)*W;
        b3 = b-b2;
        MAX = max(b1, b2);
        MAX = max(MAX, b3);
        MIN = min(b1, b2);
        MIN = min(MIN, b3);
        ans = min(ans, MAX-MIN);
        //cout << ans << endl;
    }


    cout << ans << endl;

}

Measured memory_bytes: 256
# F - Pond Skater

from collections import deque

H, W, K = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
x1 -= 1
y1 -= 1
x2 -= 1
y2 -= 1
grid = []
for _ in range(H):
    grid.append(list(str(input())))

dist = [[-1] * W for _ in range(H)]
dist[x1][y1] = 0
q = deque()
q.append((x1, y1))

while q:
    (x, y) = q.popleft()
    if (x, y) == (x2, y2):
        break
    for vx, vy in ((0, 1), (1, 0), (0, -1), (-1, 0)):
        for k in range(1, K+1):
            nx = x + vx*k
            ny = y + vy*k
            if nx < 0 or nx >= H or ny < 0 or ny >= W or grid[nx][ny] == '@':
                break
            if dist[nx][ny] != -1 and dist[nx][ny] != dist[x][y] + 1:
                break
            if dist[nx][ny] == -1:
                dist[nx][ny] = dist[x][y] + 1
                q.append((nx, ny))

print(dist[x2][y2])

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

using namespace std;

int main() {
	int a,b,c,d;

	cin >> a >> b >> c >> d;
	int ab = abs(b-a);
	int bc = abs(c-b);
	int ca = abs(a-c);

	if((ca <= d) || (ab <= d && bc <= d)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            double debt = 100000;
            int x = Integer.parseInt(br.readLine());
            for (int i = 0; i < x ; i++) {
                debt *= 1.05;
                if((long)debt%1000!=0){
                    debt = (((long)debt)/1000+1)*1000;
                }
            }
            System.out.println((long)debt);

        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24128
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vp;

void dfs(vp e[], int x, int p, int used, int ans[]) {
    int t = -1;
    for (pii y : e[x]) {
        if (y.second != p) {
            t++;
            if (t == used) {
                t++;
            }

            ans[y.first] = t;
            dfs(e, y.second, x, t, ans);
        }
    }
}

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

    int n;
    cin >> n;
    vp e[n];
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        e[a].push_back({i, b});
        e[b].push_back({i, a});
    }

    int k = 0;
    for (int i = 0; i < n; i++) {
        k = max(k, int(e[i].size()));
    }

    cout << k << endl;

    int ans[n-1];
    dfs(e, 0, -1, -1, ans);

    for (int i = 0; i < n - 1; i++) {
        cout << ans[i] + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 8320
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <stdio.h>
using namespace std;

int main(){
    int N,i;
    double temp,ans=0;
    cin>>N;
    for(i=0;i<N;i++){
        cin>>temp;
        ans+=1/temp;
    }
    ans=1/ans;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009
int main(void){
	int n;
	double x[100];
	double y[100];
	double ans;
	scanf("%d", &n);
	f(i, n)scanf("%lf", &x[i]);
	f(i, n)scanf("%lf", &y[i]);
	ans = 0;
	f(i, n)ans += fabs(y[i] - x[i]);
	printf("%f\n", ans);
	ans = 0;
	f(i, n)ans += pow(y[i] - x[i], 2);
	printf("%f\n", sqrt(ans));
	ans = 0;
	f(i, n)ans += pow(fabs(y[i] - x[i]), 3);
	printf("%f\n", cbrt(ans));
	ans = 0;
	f(i, n)ans = max(ans, fabs(y[i] - x[i]));
	printf("%f\n", ans);

	return 0;
}

Measured memory_bytes: 2932
// atcoder/arc060/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<lli> x(n);
    cin >> x;
    lli l;
    int _;
    cin >> l >> _;

    constexpr int M = 30;
    constexpr int N = 1e5 + 5;
    static int p[M][N];
    queue<int> q;
    q.push(0);
    for (int i = 1; q.size(); ) {
      while (i < x.size() && x.at(i) - x[q.front()] <= l) {
        q.push(i++);
      }
      p[0][q.front()] = q.back();
      q.pop();
    }
    for (int i = 1; i < M; ++i) {
      for (int j = 0; j < N; ++j) {
        p[i][j] = p[i - 1][p[i - 1][j]];
      }
    }

    while (_--) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      unless (a < b) swap(a, b);
      lli sum = 0;
      for (int i = M - 1; 0 <= i; --i) {
        if (p[i][a] < b) {
          sum += (1LL << i);
          a = p[i][a];
        }
      }
      cout << sum + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 13312
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long

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

    int total = 0;
    int max = 0;
    for (int i=0; i < n; i++){
        int t;
        cin >> t;
        total += t;
        if (t > max) {
            max = t;
        }
    }

    if (max < total - max) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main() {
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    ll ans = LONG_MAX;
    ll i = X;
    ll j = Y;
    ll k = 0;
    ll price;
    while(i >= 0 || j >= 0){
        if(i < 0) i = 0;
        if(j < 0) j = 0;
        price = A*i + B*j + C*k;
        ans = min(ans, price);
        i--;
        j--;
        k += 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(false);cin.tie();cout.tie();
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=1009;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
pii T[1005];
int DP[10005];
int main()
{
    speed
    int h,n;
    cin>>h>>n;
    for(int i=1; i<=n; i++)
        cin>>T[i].st>>T[i].nd;
    for(int i=1;i<=h;i++)
    {
        DP[i]=inf;
        for(int j=1;j<=n;j++)
        {
            if(i-T[j].st>=0)
                DP[i]=min(DP[i],DP[i-T[j].st]+T[j].nd);
            else
                DP[i]=min(DP[i],T[j].nd);
        }
    }
    cout<<DP[h];
    return 0;
}


Measured memory_bytes: 256
#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() { int X, A, B;
  cin >> X >> A >> B;
    if(A-B>=0){
      puts("delicious");
    }else if(A-B+X>=0){
      puts("safe");
    }else{
      puts("dangerous");
    }
  }


Measured memory_bytes: 256
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf8");


var reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on("line", line => {
  let s = parseInt(line);

  let index = 1;
  let arr = [0];
  let num = s;
  while(arr.indexOf(num) == -1) {
    arr.push(num)
    if (num % 2 == 0) {
      num = num / 2;
    } else {
      num = 3 * num + 1;
    }
    index++;
  }
  console.log(index);
});


Measured memory_bytes: 11596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication51
{
    class Program
    {
        static void Main()
        {
            int[] a = new int[4];
            int[] b = new int[2];
            for(int c = 0; c < 4; c++)
            {
                a[c] = int.Parse(Console.ReadLine());
            }
            for (int c = 0; c < 2; c++)
            {
                b[c] = int.Parse(Console.ReadLine());
            }
            Array.Sort(a);
            Array.Sort(b);
            Console.WriteLine(a[1]+a[2]+a[3]+b[1]);
        }
    }
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

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

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 998244353;

const int MAXN = 4e3 + 5;

deque<int> mn, cur;
deque<int> x;

deque<int> ss;

char c[MAXN];

deque<int> read() {
	scanf("%s", &c[0]);
	deque<int> ans;
	for(int i = 0; c[i]; i++) {
		ans.push_front(c[i] - '0');
	}
	return ans;
}

void set_min(deque<int> &a, deque<int> &b) {
	while(1) {
		if (SZ(a) > SZ(b)) {
			swap(a, b);
		}
		REP(i, 0, SZ(a)) {
			b[SZ(b) - SZ(a) + i] ^= a[i];
		}
		while(SZ(b) > 0 && b[SZ(b) - 1] == 0) {
			b.pop_back();
		}
		if (SZ(b) == 0) {
			return;
		}
	}
	
}

void solve(){
	int n;
	scanf("%d", &n);
	x = read();
	mn = read();
	REP(i, 0, n - 1) {
		cur = read();
		set_min(mn, cur);
	}
	
	if (SZ(mn) > SZ(x)) {
		cout << 0 << endl;
		return;
	}
	
	ll ans = 0ll;
	for(int i = SZ(x) - 1; i >= SZ(mn) - 1; i--) {
		ans = (ans * 2) % MOD;
		if (x[i] == 1) {
			ans = (ans + 1) % MOD;
		}
	}
	
	ss = mn;
	while(SZ(ss) < SZ(x)) {
		ss.push_front(0);
	}
	for(int i = SZ(ss) - 1; i >= SZ(mn) - 1; i--) {
		if (ss[i] != x[i]) {
			REP(j, 0, SZ(mn)) {
				ss[i - SZ(mn) + 1 + j] ^= mn[j];
			}
		}
	}
	
	int fl = 1;
	for(int i = SZ(mn) - 2; i >= 0; i--) {
		if (ss[i] != x[i]) {
			if (ss[i] > x[i]) {
				fl = 0;
			}
			break;
		}
	}
	
	/*for(int i = SZ(mn) - 1; i >= 0; i--) {
		printf("%d", mn[i]);
	}
	printf(" %d\n", fl);*/
	
	ans = (ans + fl) % MOD;
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
int N;
using pll = pair<ll, ll>;
vector<pll> points;


int count(ll p, ll q) {
  int c = 0;

  REP(i, N) {
    REP(j, N) {
      if (i==j) continue;
      ll a = points[i].first - points[j].first;
      ll b = points[i].second - points[j].second;
      if (a==p && b==q) {
        c++;
      }
    }
  }

  return N-c;
}

int main(int argc, char** argv) {
  cin >> N;
  points.reserve(N);
  REP(i, N) {
    ll X, Y;
    cin >> X >> Y;
    points.emplace_back(X, Y);
  }

  // Decide p,q
  int ret = N;
  REP(i, N) {
    REP(j, N) {
      if (i==j) continue;
      ll p = points[i].first - points[j].first;
      ll q = points[i].second - points[j].second;

      chmin(ret, count(p, q));
    }
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 256
d = gets.to_i
c = gets.split(' ').map{|s| s.to_i}
a = []
d.times do |i|
  a[i] = gets.split(' ').map{|s| s.to_i}
end
k = []
d.times do |i|
  k[i] = gets.to_i
end

l = []
26.times{|i| l[i] = 0}

total = 0
d.times do |i|
  l[k[i]-1] = i + 1
  loss = 0
  l.each_with_index{|le, li| loss += (i  - le + 1) * c[li]}
  total += a[i][k[i]-1] - loss
  
  puts (i % 26) + 1
end

Measured memory_bytes: 14292
import sys
sys.setrecursionlimit(100000) 

n = int(input())
h = list(map(int,input().split()))
dp_ = [-1]*n

def dp(i):
    if dp_[i]!=-1:
        return dp_[i]
    if i == 0:
        dp_[i] = 0
    elif i == 1:
        dp_[i] = abs(h[1]-h[0])
    else:
        dp_[i] = min(dp(i-2)+abs(h[i]-h[i-2]),dp(i-1)+abs(h[i]-h[i-1]))
    return dp_[i]

print(dp(n-1))

Measured memory_bytes: 50960
n, W, H = gets.split.map(&:to_i)
hor = Array.new(W+1,0)
ver = Array.new(H+1,0)
n.times do
    x, y, w = gets.split.map(&:to_i)
    hor[[x - w, 0].max] += 1
    hor[x + w] -= 1 if x + w + 1 <= W
    ver[[y - w, 0].max] += 1
    ver[y + w] -= 1 if y + w + 1 <= H
end
W.times do |i|
    hor[i+1] += hor[i]
end
H.times do |i|
    ver[i+1] += ver[i]
end
puts hor.all?{|k| k >= 1} || ver.all?{|k| k >= 1} ? "Yes" : "No"

Measured memory_bytes: 7688
#include <bits/stdc++.h>
#define int long long
#define K 100011
#define N 111

using namespace std;
const int MOD = (int)1e9 + 7;

int n, k, a[N], cnt[2][K], sum[K];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n >> k;
	for(int i=0; i<n; i++) cin >> a[i];
	int x = 0;
	for(int i=0; i<n; i++) {
		for(int j=0; j<=k; j++) {
			if(i == 0) cnt[x][j] = (a[0] >= j);
			else cnt[x][j] = (sum[j] + MOD - (a[i]+1 > j ? 0 : sum[j-a[i]-1])) % MOD;
		}
		sum[0] = cnt[x][0];
		for(int j=1; j<=k; j++) {
			sum[j] = (sum[j-1] + cnt[x][j]) % MOD;
		}
		x ^= 1;
	}
	cout << cnt[x^1][k] << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define Pi 3.1415926535
#define MOD = 1e9+7;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}

int solve(){
    int n; cin >> n;
    vector<vint> cnt(10,vint(10,0));
    ll ans = 0;

    repp(i,n){
        cnt[to_string(i)[0] - '0'][i%10]++;
    }

    rep(i,10)rep(j,10){
        ans += cnt[i][j] * cnt[j][i];
    }

    cout << ans << endl;

    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int N,T,E;
int main(){
  scanf("%d %d %d",&N,&T,&E);
  int res=-1;
  for(int i=0;i<N;i++){
    int x;
    scanf("%d",&x);
    //    printf("%d %d\n",T/x*x,(T/x+1)*x);
    if((T/x)*x >= T-E || (T/x+1)*x <= T+E) res=i+1;
  }
  printf("%d\n",res);
}

Measured memory_bytes: 1188
#include <stdio.h>
	int main(){
		int set,num=0;
		
		scanf("%d",&set);
			if(set>=100)
				num++;
			if(set>=110||(set>=10&&set<100))
				num++;
			if(set%2==1){
				num++;
			}
				printf("%d",num);
			}
		
		


Measured memory_bytes: 256