akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace AtC
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = ReadIntArray();
            int A = ab[0], B = ab[1];
            Out(A <= 5 ? 0 : A < 13 ? B / 2 : B);
        }

        //最小公倍数
        static int LCM(int num1, int num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        static long LCM(long num1, long num2)
        {
            var gcd = GCD(num1, num2);
            return num1 * (num2 / gcd);
        }

        //最大公約数
        static int GCD(int num1, int num2)
        {
            int a = Math.Max(num1, num2);
            int b = Math.Min(num1, num2);
            int mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static long GCD(long num1, long num2)
        {
            long a = Math.Max(num1, num2);
            long b = Math.Min(num1, num2);
            long mod;
            while ((mod = a % b) != 0)
            {
                a = b;
                b = mod;
            }

            return b;
        }

        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }

        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }

        static string ReadString()
        {
            return Console.ReadLine();
        }

        static void Out(object o)
        {
            Console.WriteLine(o);
        }
    }

    static class EnumerableExtension
    {
        public delegate void Function<in T>(T val);

        public static void ForEach<T>(this IEnumerable<T> enumerable, Function<T> function)
        {
            foreach (var x in enumerable)
            {
                function(x);
            }
        }
    }

    class PriorityQueue<T>
    {
    }

    class UnionFind
    {
        private readonly int[] _array;

        public UnionFind(int N)
        {
            _array = new int[N];
            for (int i = 0; i < N; i++)
            {
                _array[i] = i;
            }
        }

        public int GetRootNode(int n)
        {
            if (_array[n] == n) return n;
            return _array[n] = GetRootNode(_array[n]);
        }

        public void UnionGroup(int a, int b)
        {
            var rootA = GetRootNode(a);
            var rootB = GetRootNode(b);
            if (rootA == rootB) return;
            _array[rootA] = rootB;
        }

        public bool IsSameGroup(int a, int b) => GetRootNode(a) == GetRootNode(b);

        public bool IsRoot(int n) => _array[n] == n;
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<limits.h>
using namespace std;
int main(void){
  int d1,d2,m1,m2;
  cin>>m1>>d1>>m2>>d2;
  m1==m2?cout<<0<<endl:cout<<1<<endl;

return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::collections::VecDeque;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    solve(&buf);
}

fn solve(input: &str) -> () {
    let mut iterator = input.split_whitespace();

    let s: String = iterator.next().unwrap().to_string();
    let q: usize = iterator.next().unwrap().parse().unwrap();

    let mut vec: VecDeque<char> = s.chars().collect::<VecDeque<char>>();

    let mut is_reverse = false;
    for _i in 0..q {
        let t = iterator.next().unwrap();
        if t == "1" {
            is_reverse = !is_reverse;
        } else {
            let f = iterator.next().unwrap();
            let c = iterator.next().unwrap().chars().next().unwrap();
            if f == "1" {
                if is_reverse {
                    vec.push_back(c);
                } else {
                    vec.push_front(c);
                }
            } else {
                if is_reverse {
                    vec.push_front(c);
                } else {
                    vec.push_back(c);
                }
            }
        }
    }

    if is_reverse {
        for c in vec.iter().rev() {
            print!("{}", c);
        }
    } else {
        for c in vec.iter() {
            print!("{}", c);
        }
    }
    println!()
}


Measured memory_bytes: 10492
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int xcomp(vector<LL>& a, vector<LL>& b) {
	return a[0] < b[0];
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

#define ALL(x) (x).begin(),(x).end()
LL mod = 1000000007;

int main() {
	LL Q, H, S, D, N;
	cin >> Q >> H >> S >> D >> N;
	N *= 4;

	LL sum = 0;

	if (N >= 16) {
		LL mini = min({ Q * 8, H * 4, S * 2, D });
		LL kosuu = ((N - 8) / 8);
		sum += mini*kosuu;
		N -= kosuu * 8;
	}


	LL mini2 = 1000000000000;

	REP(i,17){
		REP(j, 17) {
			REP(k, 17) {
				REP(l, 17) {
					if (i + j * 2 + k * 4 + l * 8 == N) {
						if (i*Q + j*H + k*S + l*D < mini2) {
							mini2 = i*Q + j*H + k*S + l*D;
						}
					}
				}
			}
		}
	}
	sum += mini2;

	cout << sum << endl;
}

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

int main() {
    int N;
    cin>>N;
    vector<int>A;
    vector<vector<vector<int> > >tell;
    vector<vector<int> >tmptell;
    vector<int>x, y;
    int tmpA;
    int tmpx, tmpy;
    for(int i=0;i<N;++i){
        cin>>tmpA;
        A.push_back(tmpA);
        tmptell.clear();
        x.clear();
        y.clear();
        for(int j=0;j<tmpA;++j){
            cin>>tmpx>>tmpy;
            tmpx--;
            x.push_back(tmpx);
            y.push_back(tmpy);
        }
        tmptell.push_back(x);
        tmptell.push_back(y);
        tell.push_back(tmptell);
    }

    /**
    for(int i=0;i<N;++i){
        cout<<i<<endl;
        for(int j=0;j<tell[i][0].size();++j){
            cout<<tell[i][0][j]<<" "<<tell[i][1][j]<<endl;
        }
    }
    **/

    int ans = 0;
    // bit全探索
    for(int bit=0;bit < (1<<N); ++bit){
        map<int, int>maji;
        vector<int> S;
        for(int i=0;i<N;++i){
            if(bit & (1<<i)){
                S.push_back(i);
            }
        }
        for(int i=0;i<S.size();++i){
            maji[S[i]] = 1;
        }
        bool ok = true;
        for(int i=0;i<S.size();++i){
            for(int j=0;j<tell[S[i]][0].size();++j){
                if(tell[S[i]][1][j] != maji[tell[S[i]][0][j]]){
                    ok = false;
                    break;
                }
            }
            if(!ok) break;
        }
        if(ok==true & ans<S.size()) {
            ans = S.size();
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    int n;
    cin >> n;
    unordered_map<int,int> c;
    rep(i,n)
    {
        int ai;
        cin >> ai;
        if(c.count(ai)>0)
            c[ai]++;
        else
            c[ai] = 1;
    }

    int cnt = 0;
    for(auto& ci:c)
    {
        int ai = ci.first;
        int ai_cnt = ci.second;

        if(ai_cnt < ai) cnt += ai_cnt;
        else cnt += ai_cnt - ai;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4260
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {

	int d, n;
	cin >> d >> n;

	vector<int> day(d);
	for (int i = 0; i < d; i++) {
		cin >> day[i];
	}

	vector< vector<int> > dd(d, vector<int>());
	int a, b, c;
	for (int i = 0; i < n; i++) {
		cin >> a >> b >> c;
		for (int j = 0; j < d; j++) {
			if (a <= day[j] && day[j] <= b) {
				dd[j].push_back(c);
			}
		}
	}
	int ddd[220][2] = {0};
	int dp[220][2] = {0};
	for (int j = 0; j < d; j++) {
		sort(dd[j].begin(), dd[j].end());
		ddd[j][0] = dd[j][0];
		int sz = dd[j].size();
		ddd[j][1] = dd[j][sz-1];
		//cout << ddd[j][0] << ' ' << ddd[j][1] << endl;
	}

	for (int j = 1; j < d; j++) {
		dp[j][0] = max(abs(ddd[j][0]-ddd[j-1][0])+dp[j-1][0], abs(ddd[j][0]-ddd[j-1][1])+dp[j-1][1]);
		dp[j][1] = max(abs(ddd[j][1]-ddd[j-1][0])+dp[j-1][0], abs(ddd[j][1]-ddd[j-1][1])+dp[j-1][1]);
	}

	cout << max(dp[d-1][0], dp[d-1][1]) << endl;

	return 0;
}

Measured memory_bytes: 1324
n, x, y = map(int, input().split())

x -= 1
y -= 1

dist = [0] * n
for i in range(0, n):
    for j in range(i+1, n):
        d = min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x))
        dist[d] += 1

for k in range(1, n):
    print(dist[k])

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll f(ll n){
    return (n*n + 4) / 8;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    map<char,ll> mp;
    rep(i,0,S.size()){
        mp[S[i]]++;
    }
    rep(i,0,26){
        char c = 'a' + i;
        if(mp[c] == 0){
            print(c);
            return 0;
        }
    }
    print("None");

}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 500009 /// Still trying to be one thing
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int n;
vector<string> ss;
void solve(int falt, string s,int dif){
    if(falt==0){
        ss.push_back(s);
        return;
    }
    for(int i=0;i<=dif;i++){
        if(i==dif)solve(falt-1,s+char(i+'a'),dif+1);
        else solve(falt-1,s+char(i+'a'),dif);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    if(n==1){
        cout<<"a"<<endl;
        return 0;
    }
    solve(n-1,"a",1);
    sort(all(ss));
    rep(i,0,sz(ss))cout<<ss[i]<<'\n';
    return 0;   
}           



Measured memory_bytes: 7796
fun main(args: Array<String>) {
    val (r, D, x2000) = readLine()!!.split(" ").map(String::toInt)
    val n = IntArray(11)
    n[0] = x2000
    for(i in 1 until n.size){
        n[i] = n[i-1] * r - D
        println(n[i])
    }
}

Measured memory_bytes: 37836
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()

def win(enemy):
    if enemy == 'r':
        return 'p'
    elif enemy == 'p':
        return 's'
    else:
        return 'r'
def point(hand):
    if hand == 'r':
        return R
    elif hand == 'p':
        return P
    else:
        return S

ans = 0
buf = []
for i in range(N):
    t = T[i]
    hand = win(t)
    if i-K < 0 or buf[i-K] != hand:
        buf.append(hand)
        ans += point(hand)
    else:
        buf.append('')

print(ans)

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int n, k, s;
    cin >> n >> k;
    s = 1;
    rep(i,  n){
      if(s + k > s * 2){
        s *= 2;           
      }
      else{
        s += k;
      }
    }
    cout << s << endl;
    
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

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

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

  CIN(x, y, z);
  x -= z;
  cout << (x / (y + z)) << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <utility>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
 
using namespace std;
typedef long long ll;
 
int main(){
  int N,Q;
  cin >> N >> Q;

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

  vector<ll> x(Q);
  for(int i=0;i<Q;i++){
    cin >> x[i];
  }

  vector<ll> sa(N);
  int t=(N-1)%2;
  ll sum=0;
  for(int i=0;i<N;i++){
    if(t==i%2){
      sum+=a[i];
    }
    sa[i]=sum;
  }

  vector<ll> s(N);
  sum=0;
  for(int i=0;i<N;i++){
    sum+=a[i];
    s[i]=sum;
  }

  vector<pair<ll,ll> > ans;

  ll p,q;
  for(int i=1;-1<=N-2*i;i++){
    if(N-2*i<=0){
      p=a[N-1-i];
      q=s[N-1]-s[N-1-i];
    }else{
      p=a[N-1-i]+a[N-2*i-1];
      q=s[N-1]-s[N-1-i]+sa[N-2*i-1];
    }
    ans.push_back(make_pair(p,q));
    //cout << "#" << i << " " << p << " " << q << endl;
  }

  int l,r;
  for(auto xi:x){
    if(ans[0].first<2*xi) cout << ans[0].second << endl;
    else if(2*xi<=ans[ans.size()-1].first) cout << ans[ans.size()-1].second << endl;
    else{
      l=0;r=ans.size()-1;
      while(l+1<r){
	if(ans[(l+r)/2].first<2*xi) r=(l+r)/2;
	else l=(l+r)/2;
      }
      cout << ans[r].second << endl;
    }
  }
  
  return 0;
}


Measured memory_bytes: 5364
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        
        sc.close();
        
        String[] strArray1 = new String[s1.length()];
        String[] strArray2 = new String[s1.length()];
        for (int i = 0; i < s1.length(); i++) {
        strArray1[i] = String.valueOf(s1.charAt(i));
        }
        for (int i = 0; i < s1.length(); i++) {
        strArray2[i] = String.valueOf(s1.charAt(i)).toLowerCase();
        }
        for (int i = 0; i < s1.length(); i++) {
            if(strArray1[i].equals(strArray2[i])){
                strArray2[i] = strArray1[i].toUpperCase();
            }
            
        }
        for (int i = 0; i < strArray1.length; i++) {
        System.out.print(strArray2[i]);
        }
        System.out.println();

	}

}



Measured memory_bytes: 27116
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
MOD = 998244353
def main(A, B, C, D):
    I, J = C - A, D - B
    dp = [[0] * (I + 1) for _ in range(I + J + 1)]
    dp[0][0] = 1
    for k in range(1, I + J + 1):
        for i in range(min(I, k) + 1):
            j = k - i
            v = dp[k - 1][i - 1] * (j + B) % MOD if i >= 1 else 0
            h = dp[k - 1][i] * (i + A) % MOD
            d = dp[k - 2][i - 1] * (i + A - 1) * (j + B - 1) if k >= 2 and i >= 1 else 0
            dp[k][i] = (v + h - d) % MOD
    print(dp[I + J][I])

if __name__ == '__main__':
    input = sys.stdin.readline
    A, B, C, D = map(int, input().split())
    main(A, B, C, D)


Measured memory_bytes: 209552
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a, b):
	return a * b // gcd (a, b)
 
n,m = map(int,input().split())
s = input()
t = input()

l = lcm(n,m)
gaps = l//m
gapt = l//n

i,j = 0,0
while i<n:
    if s[i]!=t[j]:
        print(-1)
        break
    else:
        i += gaps
        j += gapt
else:
    print(l)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int a, b, c, d, e, f;

vector<int> water;
vector<int> sugar;

void solve() {
  for (int i=0;100*a*i<=f;i++) {
    for (int j=0;100*(a*i+b*j)<=f;j++) {
      int total = 100 * (a * i + b * j);
      if (total > 0) {
        water.push_back(total);
      }
    }
  }
  for (int i=0;c*i<=f;i++) {
    for (int j=0;d*j+c*i<=f;j++) {
      int total = c*i + d*j;
      sugar.push_back(total);
    }
  }
  sort(water.begin(), water.end());
  sort(sugar.begin(), sugar.end());
  int maxSugar = 0;
  int maxTotalWater = 0;
  double maxSugarPercent = 0;
  for (int i=0;i<water.size();i++) {
    for (int j=0;j<sugar.size();j++) {
      int total = water[i] + sugar[j];
      if (total > f || water[i] / 100 * e < sugar[j]) {
        break;
      }
      double curSugarPercent = 100.0 * sugar[j] / total;
      if (maxSugarPercent < curSugarPercent) {
        maxSugarPercent = curSugarPercent;
        maxSugar = sugar[j];
        maxTotalWater = total;
      }
    }
  }
  if (maxTotalWater == 0) {
    cout << (100 * a) << " " << 0 << endl;
  } else {
    cout << maxTotalWater << " " << maxSugar << endl;
  }
}

int main() {
  cin >> a >> b >> c >> d >> e >> f;
  solve();
}


Measured memory_bytes: 1400
open System

// prelude
let readStr () = stdin.ReadLine()

let readInt () = stdin.ReadLine() |> int
let readInts () = stdin.ReadLine().Split() |> Array.map int

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

let inline memo size f =
  let dp = Array.create size None
  let rec g x =
    match dp.[x] with
    | None ->
      let v = f g x
      dp.[x] <- Some v
      v
    | Some v -> v
  g

// start
let (H, N) = readInts() |> pair
let AB =
  let ab = Array.zeroCreate N
  for i in 0..(N-1) do
    ab.[i] <- readInts() |> pair
  ab

let cost = memo 10009 <| fun cost h ->
  AB |> Array.fold (fun prev (a, b) -> min prev (b + if h<=a then 0 else cost (h-a))) 100000000

cost H |> printfn "%d"

Measured memory_bytes: 14428
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(ll r, ll g, ll b) {
  cout << ((r * 100 + g * 10 + b) % 4 == 0) << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll g;
	ll b;
	ll r;
	scanf("%lld", &r);
	scanf("%lld", &g);
	scanf("%lld", &b);
	solve(r, g, b);
	return 0;
}


Measured memory_bytes: 256
N,M,X = map(int,input().split())
A = []
for i in range(N):
  line = list(map(int,input().split()))
  A.append(line)
def score(H):
  result = [0]*(M+1)
  for i in range(N):
    if H[i] == 1:
      for m in range(M+1):
        result[m] += A[i][m]
  if min(result[1:]) < X:
    return float('inf')
  else:
    return result[0]
def dfs(H):
  if len(H) == N:
    return score(H)
  res = float('inf')
  for v in range(2):
    H.append(v)
    res = min(res,dfs(H))
    H.pop()
  return res
ans = dfs([])
if ans == float('inf'):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 9236
s = input()
N = len(s)
l = [1]*N
count = 0
for i in range(N-1):
    if s[i] == 'R':
        if s[i+1] == 'R':
            l[i+1] += l[i]
            l[i] = 0
        if s[i+1] == 'L':
            continue
    if (s[i] =='L'):
        if s[i+1] =='L':
            l[i+1] = 0
            count+= 1
            if i == N-2:
                l[i-count+1] += count
        if (s[i+1] =='R'):
            l[i-count] += count
            count =0
for i in range(N-1):
    if (s[i] =='R') and (s[i+1] == 'L'):
        if (l[i]+l[i+1])%2 == 0:
            l[i] = (l[i]+l[i+1])//2
            l[i+1] = l[i]
        if (l[i]+l[i+1])%2 == 1:
            if l[i]%2 == 0:
                l[i] = (l[i]+l[i+1])//2
                l[i+1] = l[i]+1
            else:
                l[i+1] = (l[i]+l[i+1])//2
                l[i] = l[i+1]+1
for i in range(N):
    print(l[i],end =' ')


Measured memory_bytes: 52696
#include<iostream>
#include <stdio.h>
using namespace std;
int a,b,c[100][100],tate[100],yoko[100],total;
int main(){
	cin>>a>>b;
	for(int i=0;i<a;i++){
	for(int ii=0;ii<b;ii++){
	cin>>c[i][ii];
	tate[i]+=c[i][ii];yoko[ii]+=c[i][ii];total+=c[i][ii];}}
	for(int i=0;i<a;i++){
	for(int ii=0;ii<b;ii++){
	cout<<c[i][ii]<<" ";}
	cout<<tate[i]<<endl;}
		for(int ii=0;ii<b;ii++){
	cout<<yoko[ii]<<" ";}
		cout<<total<<endl;
	return 0;}


Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
const int maxx=1e5+2;
typedef long long ll;
int a[maxx];
int main(){
    int n; cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    int f=1;
    for(int i=n-1;i;i--){
        if(a[i]>a[i+1]) a[i]--;
        if(a[i]>a[i+1]){
            f=0; break;
        }
    }
    if(f) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(void) {
    string A, B, C;
    cin >> A >> B >> C;
    if (A[A.size()-1] == B[0] && B[B.size()-1] == C[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) {
    
    long long int n;
    cin>>n;

    long long int a=2;
    long long int b=1;
    long long int re;
    int i;
     if(n==0){
        cout<<a<<endl;
            return 0;
    }else if(n==1){
        cout<<b<<endl;
        return 0;
    }else{

        for(int i=0;i<n-1;i++){
            
                re = a+b;
                a = b;
                b = re;
            
        // cout<<re<<" ";
        }
    }

    cout<<re<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  if (s[5] == '1') {
    cout << "TBD" << endl;
  }
  else if(s[6] == '1' || s[6] == '2' || s[6] == '3' || s[6] == '4') {
          cout << "Heisei" << endl;
  }
  else cout << "TBD" << endl;
          
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}


// Description: グラフの型定義(これは最小費用流)
// Verifyed: Many Diffrent Problem 

//Appropriately Changed
using edge=struct{int to; R cost;};
using G=vector<vector<edge>>;

//Appropriately Changed
void add_edge(G &graph,int from,int to,R cost){ 
	cost=max<R>(0.0,cost);
	graph[from].push_back({to,cost});
	graph[to].push_back({from,cost});
}


using W=R;

auto dijkstra(const G &graph,int s){
	const W inf=1e18;
    const int n=graph.size();
    vector<W> dist(n,inf);
    using state=tuple<W,int>;
    priority_queue<state,vector<state>,greater<state>> q;
    dist[s]=0,q.push(state(0,s));
    
    while(!q.empty()){
        W c; int v;
        tie(c,v)=q.top();q.pop();
        for(auto &e:graph[v]){
            W nc=c+e.cost; int nv=e.to;
            if(chmin(dist[nv],nc)) q.push(state(nc,nv));
        }
    }
    return dist;
}

R sx,sy,gx,gy;
R x[1010],y[1010],r[1010];

R dist(R ax,R ay,R bx,R by){
	return sq((bx-ax)*(bx-ax)+(by-ay)*(by-ay));
}

int main(void){
	cin >> sx >> sy >> gx >> gy;

	int n;
	cin >> n;
	rep(i,n) cin >> x[i] >> y[i] >> r[i];

	G graph(n+2);
	const int s=n,g=n+1;

	add_edge(graph,s,g,dist(sx,sy,gx,gy));
	rep(i,n) add_edge(graph,s,i,dist(sx,sy,x[i],y[i])-r[i]);
	rep(i,n) add_edge(graph,i,g,dist(gx,gy,x[i],y[i])-r[i]);

	rep(j,n)rep(i,j) add_edge(graph,i,j,dist(x[i],y[i],x[j],y[j])-r[i]-r[j]);

	auto dist=dijkstra(graph,s);
	cout.precision(20);
	cout << fixed << dist[g] << endl;

	return 0;
}

Measured memory_bytes: 40848
from collections import defaultdict as dc
x = int(input())
d = dc(lambda:0)
for i in range(200):
    d[i**5] = i
# print(d)
f=0
l = list(d.items())
# print(l)
for i in range(len(l)):
    for j in range(len(l)):
        if l[i][0] - l[j][0] == x:
            print(l[i][1],l[j][1])
            f=1
            break 
        elif l[i][0] + l[j][0] == x:
            print(l[i][1] ,- l[j][1])
            f=1
            break
    if f == 1:
        break

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

#define FasterIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main(){
    FasterIO;

    int t, x;

    while(cin>>t>>x){
        cout<<setprecision(10)<<1.0*t/x<<endl;
    }

    return 0;
}


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

int mat[50][50] = {};

int main(){
    int w, h, t, p;
    cin >> w >> h >> t >> p;
    int x, y;
    while(p-- > 0){
        cin >> x >> y >> t;
        mat[y][x]++;
    }
    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> t;
            ans += t * mat[i][j];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3140
import java.util.Scanner;
 
public class Main {
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a;
		int num =0;
		for(int i=0;i<n;i++){
			a = sc.nextInt();
			while(a%2 == 0){
				num += 1;
				a = a/2;
			}
		}

		System.out.println(num);
	}
 
}

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

int main(){
	int n,m;
	cin>>n>>m;
	if(m==1)
	    cout<<0<<endl;
	else{
	    int i=1;
	    while(n*i-(i-1)<m){
			    i++;
	    }
	    cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
x = int(input())


if x == 2:
    print(2)
    exit()


def sosu(n):
    m = int(n ** (1 / 2) + 1)
    flag = True
    for i in range(2, m + 1):
        if n % i == 0:
            flag = False
    return flag


for i in range(10 ** 6):
    if sosu(x + i):
        print(x + i)
        exit()



Measured memory_bytes: 38512
//It's really tough
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mem(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
const int N = 2e5 + 5;
const ll inf = 9e18 + 9;
const int mod = 1e9+7;
ll res;

void solve()
{
     int n;cin>>n;
     vector<pair<int,int>> a(n);
     for(int i=0;i<n;i++){
         cin>>a[i].fir;
         cin>>a[i].sec;
     }
     bool flag = false;
     int cnt=0;
     for(int i=0;i<n;i++){
         if(a[i].first == a[i].second){
             cnt++;
         }
         else{
             cnt = 0;
         }
         if(cnt >= 3){
             flag = true;
         }
     }
     if(!flag){
         cout<<"No"<<endl;
     }
     else{
         cout<<"Yes"<<endl;
     }
}
 
int main()
{
    IOS;ll t = 1;
    // cin>>t;
    for(int i=1;i<=t;i++)
    {
        solve();
    }
}

Measured memory_bytes: 3652
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { a: number, s: string} => {
  const a = +lines[0]
  const s = lines[1]
  const obj = { a, s }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { a, s } = parseLines(lines)
  return 3200 <= a ? s : 'red'
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


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

using ll = long long;

#define mod 1000000007
#define init ios::sync_with_stdio(0);cin.tie(0);

typedef vector<int> vi;
typedef pair<int, int> pi;
#define MS(x,y) memset(x,y,sizeof(x))
#define F first
#define S second
#define PB push_back
#define MP make_pair






int main()
{
	init;

	int x, y;
	cin >> x >> y;

	for (int i = 0; i <= x; i++)
	{
		if (i * 2 + (x - i) * 4 == y) {
			cout << "Yes\n";
			return 0;
		}
	}

	cout << "No\n";
}

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

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

int main()
{
    ll n, k;
    scanf("%lld %lld", &n, &k);

    if (n > 2 * k) {
        n = n - k * ((n - 2 * k) / k);
    }

    set<ll> seen;
    ll mn = LLONG_MAX;
    while (true) {
        if (seen.count(n) == 1) {
            printf("%lld\n", mn);
            break;
        }

        seen.insert(n);
        mn = min(mn, n);
        n = abs(n - k);
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
 
int main(){
  string s,t;cin>>s>>t;
  int n=s.size(),m=t.size(),dp[3001][3001]={};
  rep(i,n){
    rep(j,m){
      if(s[i]==t[j]){
        //cout<<i<<" "<<s[i]<<" "<<j<<" "<<t[j]<<endl;
        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
        }
      dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j]);
      dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1]);
    }
  }
  
  string ans="";
  
  while(n>0&&m>0){
    if(dp[n][m]==dp[n-1][m]){
      n--;
    }
    else if(dp[n][m]==dp[n][m-1]){
      m--;
    }
    else{
      ans=s[n-1]+ans;
      n--,m--;
    }
  }
  
  cout<<ans;
}

Measured memory_bytes: 38868
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.StreamTokenizer
import java.util.*

fun main(args: Array<String> ) {
    val st = StreamTokenizer( BufferedReader( InputStreamReader( System.`in` ) ) )
    val n = st.nextInt()
    val e = Array( n, { IntArray( n ) } )
    val queue = PriorityQueue<Edge>( n * n / 2 )
    for ( i in 0 until n ) {
        for ( j in 0 until n ) {
            e[i][j] = st.nextInt()
            if ( i < j ) queue.add( Edge( i, j, e[i][j] ) )
        }
    }
    val dist = Array( n, { LongArray( n, { Long.MAX_VALUE / 4 } ) } )
    for ( i in 0 until n ) dist[i][i] = 0
    var r = 0L
    while ( queue.isNotEmpty() ) {
        val edge = queue.poll()
        if ( dist[edge.u][edge.v] < edge.d ) {
            println( -1 )
            return
        }
        if ( dist[edge.u][edge.v] > edge.d ) {
            r += edge.d
            for ( i in 0 until n ) {
                for ( j in 0 until n ) {
                    dist[i][j] = Math.min( dist[i][j],
                            Math.min(
                                    dist[i][edge.u] + edge.d + dist[edge.v][j],
                                    dist[i][edge.v] + edge.d + dist[edge.u][j]
                            )
                    )
                }
            }
        }
    }
    for ( i in 0 until n ) {
        for ( j in 0 until n ) {
            if ( e[i][j].toLong() != dist[i][j] ) {
                println( -1 )
                return
            }
        }
    }
    println( r )
}

data class Edge( val u: Int, val v: Int, val d: Int ) : Comparable<Edge> {
    override fun compareTo( e: Edge ): Int {
        if ( d != e.d ) return Integer.compare( d, e.d )
        if ( u != e.u ) return Integer.compare( u, e.u )
        return Integer.compare( v, e.v )
    }
}

private fun StreamTokenizer.nextInt(): Int {
    nextToken()
    return nval.toInt()
}


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

int main(void) {
    int n, k; cin >> n >> k;
    vector<string> ds(k);
    for(int i=0; i<k; ++i) cin >> ds[i];
    
    for(int i=n; i<1e6; ++i) {
        string s = to_string(i);
        bool isok = true;
        for(auto&& d: ds) {
            int r = s.find(d);
            if(r >= 0) {
                isok = false;
                break;
            }
        }
        if(!isok) continue;
        cout << i << endl;
        break;
    }
    return 0;
}
        

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const int N = 200100;
int n, dp[N][3];
string s;
int main() {
	ios_base::sync_with_stdio(false);
	cin >> s;
	dp[0][1] = 1;
	dp[0][2] = -100000000;
	dp[1][2] = 1;
	int n = s.size() - 1;
	for(int i = 1; i <= n; i++) {
		if(i >= 2) {
			dp[i][2] = dp[i - 2][1] + 1;
			if(i >= 3 && s[i] != s[i - 2] && s[i - 1] != s[i - 3])
				dp[i][2] = max(dp[i][2], dp[i - 2][2] + 1);
		}
		if(s[i] != s[i - 1])
			dp[i][1] = max(dp[i - 1][1], dp[i - 1][2]) + 1;
		else dp[i][1] = dp[i - 1][2] + 1;
	}
	cout << max(dp[n][1], dp[n][2]);
}	

	

Measured memory_bytes: 3472
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define hell 1000000007  
#define hell2 998244353 
#define pi 3.14159265358979323846

int solve(){
    int n,t=0;
    cin>>n;
    int a[n],c[1000002]={0};
    rep(i,0,n) {cin>>a[i];c[a[i]]++;}
    sort(a,a+n);
    rep(i,0,n){
        if(c[a[i]]==1)
            t++;
        if(c[a[i]]>0){
            int j=2*a[i],d=a[i];
            c[d]=-1;
            while(j<1000002){
                c[j]=-1;
                j+=d;
            }
        }
    }
    cout<<t;
    return 0;
}
 
signed main(){
    IOS;
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 12972
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int a;
  cin >> a;
  int b = a*a;
  int c = a*a*a;

  cout << a + b + c <<endl;
  return 0;
}



Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define Data_Nerd ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define files freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
using namespace std;
using ll = long long;

const int N = 1e5 + 1;

int a[N];

int main() {
	Data_Nerd
	int n, k; scanf("%d%d", &n, &k);

	for(int i = 0; i < n; ++i)
		scanf("%d", a + i);

	ll ans = 0, pos = 0;

	--k;

	while(pos < n - 1) {
		++ans;
		pos += k;
	}

	cout << ans;
}


Measured memory_bytes: 640
import sys
from collections import deque

n = input()

for t in range(n):
    ls = raw_input()
    ls = [map(int, list(raw_input())) for x in range(8)]

    sx, sy = input(), input()

    dx = [1,0,-1,0] + [2,0,-2,0] + [3,0,-3,0]
    dy = [0,1,0,-1] + [0,2,0,-2] + [0,3,0,-3]

    def isin(x, y): return 0 <= x < 8 and 0 <= y < 8

    class state:
        def __init__(self, x, y):
            self.x = x
            self.y = y

    queue = deque([state(sx-1, sy-1)])
    while len(queue):
        s = queue.popleft()
        ls[s.y][s.x] = 0
        for i in range(len(dx)):
            xx = s.x + dx[i]
            yy = s.y + dy[i]
            if isin(xx, yy) and ls[yy][xx] == 1:
                queue.append(state(xx, yy))

    print "Data {}:".format(t+1)
    for raw in ls:
        for col in raw:
            sys.stdout.write(str(col))
        sys.stdout.write('\n')

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

int main(void){
	bool first = true; //true : êÔÅ false:2ñÚÈ~

	while(1){
		int a,b;
		int count = 0;

		cin>>a>>b;
		if(a == 0 && b == 0) break;

		if(first == true){
			first = false;
		}
		else{
			cout<<endl;
		}

		for(int i=a;i<=b;i++){
			bool flg = false;
			//true : ¤é¤Çµ, false:¤é¤ÇµÅÈ¢

			if(i % 4 == 0){
				if(i % 100 == 0){
					if(i % 400 == 0) flg = true;
					else flg = false;
				}
				else{
					flg = true;
				}
			}

			if(flg == true){
				cout<<i<<endl;
				count++;
			}
		}

		if(count == 0){
			cout<<"NA\n";
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define D_iN	200

int main (void) {
	int ii=0, iRetValue=0, iN=0, iA[D_iN], iCount=0;
	int	a=0, b=0, c=0;

	iRetValue = scanf ("%d", &iN);
	for (ii=0; ii < iN; ii++) {
		iRetValue = scanf ("%d", &iA[ii]);
	}

	while (1) {
		for (ii=0; ii < iN; ii++) {
			//c=a-(a/b)*b;
			a = iA[ii] >> 1;	// /2
			b = a << 1;			// x2
			c = iA[ii] - b;		// 1 - 

//			a = iA[ii] >> 1;	// /2
//			c = iA[ii] - (a << 1);
			if (c == 0) {
//				iA[ii] = a;
				iA[ii] = iA[ii] >> 1;
			} else {
				goto l_Exit;
			}
		}
		iCount++;
	}

l_Exit:
	printf ("%d\n", iCount);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

vector<int> cnt[1050000];
int n,a[500010],all = 0,ans = 0,lst[1050000],dp[500010];

void calc(int m,bool flag){
	if(cnt[m].size() == 0) return;
	cnt[m][0] = 1;
	dp[0] = 1;
	int odd = 0,even = 1;
	for(int i = 1;i < cnt[m].size();i++){
		dp[i] = ((i % 2) ? even : odd) * cnt[m][i] % MOD;
		if(i % 2) odd = (odd + dp[i]) % MOD;
		else even = (even + dp[i]) % MOD;
	}
	if(flag) ans = (ans + odd) % MOD;
	else ans = dp[cnt[m].size() - 1];
}

signed main(){
	cin >> n;
	int zero = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		all ^= a[i];
		if(!all) zero++;
		cnt[all].pb(zero - lst[all]);
		cnt[all].pb(1);
		lst[all] = zero;
	}
	if(!all){
		for(int i = 1;i < 1050000;i++) calc(i,true);
		int tmp = 1;
		for(int i = 0;i < zero - 1;i++) tmp = tmp * 2 % MOD;
		ans = (ans + tmp) % MOD;
	}else calc(all,false);
	cout << ans << endl;
}


Measured memory_bytes: 55224
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
const lli mod=1e9+7;
const lli INT=1e15;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;}b/=2;a*=a;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define PII pair<int,int>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}

int main()
{
    int x,a,b;
    si(x);si(a);si(b);
    
    int ad=abs(x-a);
    int bd=abs(x-b);
    
    if(ad<bd) cout<<"A\n";
    else cout<<"B\n";
	return 0;
}

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

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

    int N, W;
    cin >> N >> W;

    vector<ll> w(N), v(N);
    REP(i, N) cin >> w[i] >> v[i];

    // この dp には重さが入る
    vector<vector<ll> > dp(N + 1, vector<ll>(100001, 1LL << 60));

    dp[0][0] = 0;

    // 縦軸に品物の数
    // 横軸に価値の総和
    REP(i, N) REP(j, 100001) {
        if (j - v[i] >= 0)
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
    }

    int ans = 0;
    REP(j, 100001)
        if (dp[N][j] <= W)
            ans = j;

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    set<ll> st;
    priority_queue<ll, vector<ll>, greater<ll> > q;
    REP(i, 1, 10) {
        st.insert(i);
        q.push(i);
    }
    auto push_q = [&](ll a) {
        if(st.count(a)) return ;
        st.insert(a);
        q.push(a);
    };
    while(!q.empty()) {
        if(st.size()>=1e6+10) break;
        auto p = q.top();
        q.pop();
        ll x = p%10;
        p *= 10;
        push_q(p + x);
        if(x > 0) push_q(p + x -1);
        if(x + 1 < 10) push_q(p + x + 1);
    }
    int k;
    cin >> k;
    while(--k) {
        st.erase(st.begin());
    }
    cout << *st.begin() << '\n';
    return 0;
}

Measured memory_bytes: 54248
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using i64 = int64_t;
using f80 = __float80;
static const int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
#define _overload3(_1,_2,_3,name,...) name
#define repi(i,start,end) for(i64 i=(start);i<(end);++i)
#define _rep(i,n) repi(i,0,n)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,start,end) for(i64 i=(start);i>end;--i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef v(i64) vi;
typedef v(vi) vvi;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream &operator<<(ostream &os, const vector< T > &v){
  rep(i,v.size()) os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T> istream &operator>>(istream &is, vector< T > &v){
  for(T &in : v) is >> in;
  return is;
}

void Main()
{
  i64 N;
  cin >> N;

  vi ans;

  i64 A;
  while(cin >> A){
    i64 l = 0, r = ans.size() - 1;
    if(ans.size() == 0 or ans[r] >= A){
      ans.push_back(A);
      continue;
    }
    if(ans[l] < A){
      ans[l] = A;
      continue;
    }
    while(l + 1 < r){
      i64 m = (l + r) / 2;
      if(ans[m] < A){
        r = m;
        continue;
      } else {
        l = m;
        continue;
      }
    }
    ans[r] = A;
  }
  cout << ans.size() << "\n";
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}

Measured memory_bytes: 1400
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <limits>
#include <sstream>

using namespace std;

int main (void)
{
	int n,a[100],d,x,co;
	co = 0;

	cin >> n >> d >> x;

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

	for (int i = 0; i < n; i++)
	{
		for (int j = 1; j < 100; j++)
		{
			if ((a[i] * j) + 1 <= d)
			{
				co += 1;
			}
		}
	}

	cout << co + x + n << endl;
}



Measured memory_bytes: 256