akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string S;
	cin >> S;

	int len=S.length();
	int p=len-1;
//	cout << len << " len p " << p << endl; 

	while(p>=4){
		if(S.compare(p-4, 5, "erase")==0){
			p-=5;
		}else if(S.compare(p-4, 5, "dream")==0){
			p-=5;
		}else if(p>=5 && S.compare(p-5, 6, "eraser")==0){
				p-=6;
		}else if(p>=6 && S.compare(p-6, 7, "dreamer")==0){
					p-=7;
		}else{
			cout << "NO" << endl;	
			return 0;
		}
	}
	if(p==-1){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}		
	return 0;
}

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

int main(void){
	int n,l,i,j;
	char **text;
	char *tmp;
	scanf("%d %d",&n,&l);
	text = malloc(sizeof(char *) * n);
	tmp = malloc(sizeof(char) * l);
	for(i=0;i<n;i++){
		text[i] = malloc(sizeof(char) * l);
		scanf("%s",text[i]);
	}
	for(i=1;i<n;i++){
		for(j=1;j<n;j++){
			if(strcmp(text[j-1],text[j])>0){
				strcpy(tmp,text[j-1]);
				strcpy(text[j-1],text[j]);
				strcpy(text[j],tmp);
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%s",text[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {

	ll N,K,M;
	cin >> N>>K>>M;
	string s = "NO";
	if ((N+1)/2>=K) {
		s = "YES";
	}
	cout << s << endl;


}

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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  int n, t, a;
  cin >> n >> t >> a;

  vector<int> h(n);
  rep(i, n) {
    cin >> h[i];
  }

  vector<double> temp_diff(n);
  rep(i, n) {
    temp_diff[i] = abs(t - h[i] * 0.006 - a);
  }

  int ans = distance(temp_diff.begin(), min_element(all(temp_diff))) + 1;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <utility>

inline int left(int i){
    return 2 * i + 1;
}

inline int right(int i){
    return 2 * i + 2;
}

void maxHeapify(int A[], int i, int H){
    int l = left(i);
    int r = right(i);
    int largest = i;
    if(l < H && A[l] > A[largest]){
        largest = l;
    }
    if(r < H && A[r] > A[largest]){
        largest = r;
    }

    if(largest != i){
        std::swap(A[i], A[largest]);
        maxHeapify(A, largest, H);
    }
}

void buildMaxHeap(int A[], int H){
    for(int i = H/2; i >= 0; --i){
        maxHeapify(A, i, H);
    }
}

int main(){
    int H;
    std::scanf("%d", &H);
    static int A[500000];

    for(int i = 0; i < H; ++i){
        std::scanf("%d", &A[i]);
    }

    buildMaxHeap(A, H);

    for(int i = 0; i < H; ++i){
        std::printf(" %d", A[i]);
    }
    std::printf("\n");
    return 0;
}



Measured memory_bytes: 4516
//入力チェック

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;

typedef long long LL;

struct graph{
	int V;
	vector<char> used;
	vector<int> vs, cmp;
	vector<vector<int> > G, rG;

	graph(int n)
	: V(n), used(n), cmp(n), G(n), rG(n)
	{ }
	
	void add_edge(int a, int b){
		G[a].push_back(b);
		rG[b].push_back(a);
	}
	
	void dfs(int v){
		used[v] = 1;
		for(int i = 0; i < G[v].size(); ++i){
			if(!used[G[v][i]]){ dfs(G[v][i]); }
		}
		vs.push_back(v);
	}
	
	void rdfs(int v, int k){
		used[v] = 1;
		cmp[v] = k;
		for(int i = 0; i < rG[v].size(); ++i){
			if(!used[rG[v][i]]){ rdfs(rG[v][i], k); }
		}
	}
	
	int scc(){
		fill(used.begin(), used.end(), 0);
		vs.clear();
		for(int v = 0; v < V; ++v){
			if(!used[v]){ dfs(v); }
		}
		fill(used.begin(), used.end(), 0);
		int k = 0;
		for(int i = vs.size() - 1; i >= 0; --i){
			if(!used[vs[i]]){ rdfs(vs[i], k++); }
		}
		return k;
	}
};


struct restype{
	int left, is_or, right;
};

const char *p;
map<string,int> vars;

restype expr();
restype factor();

restype expr(){
	restype r = factor();
	if(*p == '|' || *p == '&'){
		r.is_or = (*p++ == '|');
		r.right = factor().left;
	}
	return r;
}


restype factor(){
	restype r;
	if(*p == '~'){
		++p;
		r = factor();
		r.left ^= 1;
		r.is_or ^= 1;
		r.right ^= 1;
	}
	else if(*p == '('){
		++p;
		r = expr();
		++p;
	}
	else{
		char buf[16];
		int d = 0;
		sscanf(p, "%[a-zA-Z]%n", buf, &d);
		p += d;

		int k = vars.insert(make_pair(buf, vars.size())).first->second;
		r.left = r.right = k * 2;
		r.is_or = 0;
	}
	return r;
}


int main(){
	int n, m;
	cin >> n >> m;
	cin.get();

	string s;
	graph G(m * 2);
	for(int i = 0; i < n; ++i){
		getline(cin, s);
		p = s.c_str();
		restype r = expr();

		if(r.is_or){
			G.add_edge(r.left ^ 1, r.right);
			G.add_edge(r.right ^ 1, r.left);
		}
		else{
			G.add_edge(r.left ^ 1, r.left);
			G.add_edge(r.right ^ 1, r.right);
		}
	}

	if(vars.size() < m){ throw 0; }
	if(vars.size() > m){ while(1); }

	G.scc();

	const char *ans = "accept";
	for(int i = 0; i < m; ++i){
		if(G.cmp[i*2] == G.cmp[i*2+1]){
			ans = "reject";
		}
	}
	puts(ans);
}

Measured memory_bytes: 1384
(defun count_one (str index)
  (if (<= (length str) index) 0
    (if (equal (elt str index) #\0) 
      (count_one str (+ index 1))
      (+ 1 (count_one str (+ index 1)))
      )))

(format t "~A~%" (count_one (read-line) 0))


Measured memory_bytes: 12388
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string s;
int a,b,c,d;

bool solve(){
	if(a>b){
		while(a<=c){
			if(s[a-1]=='.' && s[a+1]=='.'){
				break;
			}
			if(a+1<n && s[a+1]=='.')a++;
			else if(a+2<n && s[a+2]=='.')a+=2;
			else return false;
		}
		if(a>c || s[a-1]!='.' || s[a-1]!='.')return false;
	}
	while(b<d){
		if(b+1<n && s[b+1]=='.')b++;
		else if(b+2<n && s[b+2]=='.')b+=2;
		else return false;
	}
	if(b!=d)return false;
	while(a<c){
		if(a+1<n && s[a+1]=='.')a++;
		else if(a+2<n && s[a+2]=='.')a+=2;
		else return false;
	}
	return true;
}

int main(void){
	scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
	a--;
	b--;
	c--;
	d--;
	cin >> s;
	if(c>d){
		swap(c,d);
		swap(a,b);
	}
	printf("%s\n",solve()?"Yes":"No");
	return 0;
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {

	N := oneInt()
	M := oneInt()

	r1 := 0
	r2 := 0
	if N != 1 {
		r1 = N * (N - 1) / 2
	}

	if M != 1 {
		r2 = M * (M - 1) / 2
	}

	fmt.Print(r1 + r2)
}

func exp(val int) float64 {
	var temp float64
	for index := 1; index <= val; index++ {
		temp += float64(index)
	}
	return temp / float64(val)
}

func searchAbove(slice []int, target int, index int) int {
	for i := index + 1; i < len(slice); i++ {
		v := slice[i]
		if v >= target {
			return i
		}
	}
	return -1
}

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <cmath>
using namespace std;

int main()
{
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int p1[100],p2[100];
		for(int i=0;i<100;i++){
			p1[i] = 0; p2[i] = 0;
		}
		string a,b;
		cin >> a ;
		cin >> b ;
		if(a.size() > 80 || b.size() > 80){
			cout << "overflow" << endl;
			continue;
		}

		int pos = 0;
		for(unsigned i=a.size();i>0;i--){
			stringstream sst;
			sst << a[i-1];
			sst >> p1[pos++];
		}
		pos = 0;
		for(unsigned i=b.size();i>0;i--){
			stringstream sst;
			sst << b[i-1];
			sst >> p2[pos++];
		}
		for(int i=0;i<100;i++){
			int ans = p1[i]+p2[i];
			p1[i] = ans % 10;
			p1[i+1] += ans/10;
		}
		bool flag = true;
		for(int i=99;i>=0;i--){
			if(flag){
				if(i != 0 && p1[i] == 0)
					continue;
				else{
					if(i > 79){
						cout << "overflow" ;
						break;
					}
					flag = false;
				}
			}
			cout << p1[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.HashMap;
import java.util.Scanner;

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

        int n = in.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < n; i++) {
            int a = in.nextInt();
            if(map.containsKey(a)) {
                map.put(a, map.get(a) + 1);
            }else {
                map.put(a, 1);
            }
        }
        int max = 0;
        for(Integer k:map.keySet()) {
            for(int i = k - 1; i <= k + 1; i++) {
                int a = map.containsKey(i - 1) ? map.get(i - 1) : 0;
                int b = map.containsKey(i) ? map.get(i) : 0;
                int c = map.containsKey(i + 1) ? map.get(i + 1) : 0;
                max = Math.max(max, a + b + c);
            }
            
        }
        in.close();
        System.out.println(max);
    }
}


Measured memory_bytes: 66240
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

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

    int head_b_and_tail_a = 0, head_b = 0, tail_a = 0, others = 0;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;
        
        for(int j = 1; s[j] != '\0'; ++j){
            if(s.substr(j - 1, 2) == "AB"){
                ans++;
            }
        }

        if(s[0] == 'B' && s[s.length() - 1] == 'A'){
            head_b_and_tail_a++;
        }else if(s[0] == 'B'){
            head_b++;
        }else if(s[s.length() - 1] == 'A'){
            tail_a++;
        }else{
            others++;
        }
    }

    if(head_b_and_tail_a == 0){
        ans += min(head_b, tail_a);
    }else if(head_b >= 1 && tail_a >= 1){
        ans += head_b_and_tail_a - 1;
        ans += 2 + min(head_b - 1, tail_a - 1);
    }else if(head_b >= 1){
        ans += head_b_and_tail_a;
    }else if(tail_a >= 1){
        ans += head_b_and_tail_a;
    }else{
        ans += head_b_and_tail_a - 1;
    }

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

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    var enemy = Array(n+1, {0L})
    var brave = Array(n, {0L})
    var sum = 0L
    for(i in 0..n){
        enemy[i] = scanner.nextLong()
    }
    for(i in 0..n-1){
        brave[i] = scanner.nextLong()
    }
    for(i in 0..n-1){
        if(enemy[i] >= brave[i]){
            sum += brave[i]
        }
        else if(enemy[i]+enemy[i+1] >= brave[i]){
            sum += brave[i]
            enemy[i+1] -= brave[i]-enemy[i]
        }
        else{
            sum += enemy[i]+enemy[i+1]
            enemy[i+1] = 0L
        }
    }
    println(sum)
}

Measured memory_bytes: 80916
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
inline int mul(int a, int b) {
  return (int)((long long)a * b % md);
}
vector<vector<int>> grh;
vector<bool> ckd;
vector<vector<int>> dp;
void dfs (int crr) {
  ckd[crr] = true;
  for (int nxt : grh[crr]) {
    if (!ckd[nxt]) {
      dfs(nxt);
      int tmp = dp[0][nxt];
      dp[1][crr] = mul(dp[1][crr], tmp);
      add(tmp, dp[1][nxt]);
      dp[0][crr] = mul(dp[0][crr], tmp);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  grh.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int x, y;
    cin >> x >> y;
    grh[--x].push_back(--y);
    grh[y].push_back(x);
  }
  ckd.resize(n, false);
  dp.resize(2, vector<int>(n, 1));
  dfs(0);
  int ret = dp[0][0];
  add(ret, dp[1][0]);
  cout << ret << '\n';
  return 0;
}


Measured memory_bytes: 10744
import sys
input = sys.stdin.buffer.readline

a,b,c,d = map(int,input().split())

flag = 1
while True:
    if flag > 0:
        c -= b
        if c <= 0:
            break
    else:
        a -= d
        if a <= 0:
            break
    flag = flag * (-1)

if flag > 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61892
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>

using namespace std;

int n;
set<string> ans;

void dfs(string s) {
	if (s.size() == n) {
		ans.insert(s);
		return;
	}

	char maxi = *max_element(s.begin(), s.end());
	for (char c = 'a'; c <= maxi + 1; c++) {
		dfs(s + c);
	}
}

int main() {
	cin >> n;

	dfs("a");
	for (auto s: ans) {
		cout << s << endl;
	}
	return 0;
}


Measured memory_bytes: 14208
#include<iostream>
#include<vector>
#include<cctype>

using namespace std;

typedef vector<vector<int> > M;

const int MOD=32768;
char prg[99];
char *p;
M v[128];

M expr();
M primary();

M row(){
  auto l=expr();
  while(*p==' '){
    p++;
    auto r=expr();
    for(int i=0;i<l.size();i++){
      l[i].insert(end(l[i]),begin(r[i]),end(r[i]));
    }
  }
  return l;
}

M primary_h(){
  if(isdigit(*p)){
    int r=0;
    while(isdigit(*p)){
      r=r*10+(*p++)-'0';
    }
    return {{r}};
  }else if(isalpha(*p)){
    return v[*p++];
  }else if(*p=='['){
    p++;
    auto l=row();
    while(*p==';'){
      p++;
      auto r=row();
      l.insert(end(l),begin(r),end(r));
    }
    p++;
    return l;
  }else if(*p=='('){
    p++;
    auto l=expr();
    p++;
    return l;
  }
}

M primary(){
  auto l=primary_h();
  for(;;){
    if(*p=='('){
      p++;
      auto f=expr()[0];
      p++;
      auto s=expr()[0];
      p++;
      M res(f.size(),vector<int>(s.size()));
      for(int i=0;i<f.size();i++){
	for(int j=0;j<s.size();j++){
	  res[i][j]=l[f[i]-1][s[j]-1];
	}
      }
      l=res;
    }else if(*p=='\''){
      p++;
      M res(l[0].size(),vector<int>(l.size()));
      for(int i=0;i<l.size();i++){
	for(int j=0;j<l[0].size();j++){
	  res[j][i]=l[i][j];
	}
      }
      l=res;
    }else{
      return l;
    }
  }
}

M neg(M m){
  for(auto &e:m){
    for(auto &f:e){
      f=(MOD-f)%MOD;
    }
  }
  return m;
}

M factor(){
  if(*p=='-'){
    p++;
    return neg(factor());
  }else{
    return primary();
  }
}

M mpi(M m,int i){
  for(auto &e:m){
    for(auto &f:e){
      f=(f*i)%MOD;
    }
  }
  return m;
}

M term(){
  auto l=factor();
  while(*p=='*'){
    p++;
    auto r=factor();
    if(l.size()==1&&l[0].size()==1){
      l=mpi(r,l[0][0]);
    }else if(r.size()==1&&r[0].size()==1){
      l=mpi(l,r[0][0]);
    }else{
      auto res=M(l.size(),vector<int>(r[0].size()));
      for(int i=0;i<l.size();i++){
	for(int j=0;j<r[0].size();j++){
	  int t=0;
	  for(int k=0;k<l[i].size();k++){
	    t=(t+l[i][k]*r[k][j])%MOD;
	  }
	  res[i][j]=t;
	}
      }
      l=res;
    }
  }
  return l;
}

M expr(){
  auto l=term();
  while(*p=='+'||*p=='-'){
    bool n=*p=='-';
    p++;
    auto r=term();
    if(n){
      r=neg(r);
    }
    for(int i=0;i<l.size();i++){
      for(int j=0;j<l[i].size();j++){
	l[i][j]=(l[i][j]+r[i][j])%MOD;
      }
    }
  }
  return l;
}

int main(){
  for(int n;cin>>n,n;){
    cin.ignore();
    while(n--){
      cin.getline(prg,99);
      p=prg+2;
      v[prg[0]]=expr();
      for(auto e:v[prg[0]]){
	for(int i=0;i<e.size();i++){
	  cout<<e[i]<<" \n"[i==e.size()-1];
	}
      }
    }
    cout<<"-----"<<endl;
  }
}

Measured memory_bytes: 1496
#include <algorithm>
#include <stdio.h>

#define N 20
#define INF 10e6

int main(void){
    int cost[N][N];
    int n,m;
    int s,g,v,p;
    
    scanf("%d%d", &n, &m);
    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            cost[i][j] = INF;
        }
    }
    for (int i=0; i<m; i++){
        int a,b,c,d;
        scanf("%d,%d,%d,%d", &a, &b, &c, &d);
        a--; b--;
        cost[a][b] = c;
        cost[b][a] = d;
    }
    scanf("%d,%d,%d,%d",&s,&g,&v,&p);
    s--; g--;
    // wf
    for (int k=0; k<n; k++){
        for (int i=0; i<n; i++){
            for (int j=0; j<n; j++){
                cost[i][j] = std::min(
                    cost[i][j], cost[i][k]+cost[k][j]);
            }
        }
    }
    printf("%d\n", v-p-cost[s][g]-cost[g][s]);
    return 0;
}
    

Measured memory_bytes: 2576
#include <bits/stdc++.h>
using namespace std;
 
 
int main()
{
 
    int64_t a,b,c;
    cin>>a>>b>>c;
    int64_t k;
    cin>>k;

    if(a>=b&&a>=c)
        cout<<pow(2,k)*a+b+c<<endl;
    else if(b>=a&&b>=c)
        cout<<pow(2,k)*b+a+c<<endl;
    else // c>=a&&c>=b
        cout<<pow(2,k)*c+a+b<<endl;

    return 0;
}   

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

int countZero(vector<int> num){
    int cnt = 0;
    for(int i = 0; i < num.size(); i++){
        if(num[i] == 0){
            cnt++;
        }
    }

    return cnt;
}


int main(int argc, const char* argv[]){
    string s,t;
    cin >> s >> t;
    vector<int> cnts;

    int min = 1000;
    for(int i = 0; i < s.size(); i++){
        if(i + t.size() > s.size())break;
        cnts.clear();

        for(int j = 0; j < t.size(); j++){
            cnts.push_back(s[i + j] - t[j]);
        }
        int tmp = t.size() - countZero(cnts);
        min = tmp < min ? tmp : min;
    }
    cout << min << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){

    int sum1 = 0,sum2 = 0,n,min,dif;
    int w[1010];

    cin >> n;
    FOR(i,0,n){
        cin >> w[i];
        sum1 += w[i];
    }

    min = sum1;

    FORQ(i,0,n){
        sum1 -= w[i];
        sum2 += w[i];
        dif = abs(sum1 - sum2);
        if(dif < min)min = dif;
    }

    cout << min;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int r;
  int result = 0;
  char S[4];
  scanf("%s", S);
  
  for(r=0; r<4; r++){
    if (S[r] == '+') result++;
    else result--;
  }
  
  printf("%d", result);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    int n,m,x,a[15][15],c[15],xf=99999999,cost;
    cin>>n>>m>>x;
    for(int i=0;i<n;i++){
        cin>>c[i];
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    for(int k=1;k<(1<<n);k++){ ///iau toate variante pt carti 001-->111 (n==3)
        int S[15]={}; ///retin cat am insusit din fiecare algoritm S[i]=cat stiu din alg i
        cost=0;
        int ok=1;
        //cout<<endl;
        for(int i=0;i<n;i++){ ///testez daca am nevoie de cartea cu ind i
            //cout<<(k & (1<<i));
            if(k & (1<<i)){
                cost+=c[i];
                for(int j=1;j<=m;j++){
                    S[j]+=a[i][j];
                }
                
            }
        }
        //cout<<endl;
        for(int i=1;i<=m;i++){
            //cout<<S[i]<<" ";
            if(S[i]<x)      ok=0;
        }
        //cout<<endl;
        if(ok==1){
            if(xf>cost)     xf=cost;
        }
    }
    if(xf==99999999)    cout<<-1;
    else                cout<<xf;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)


ll MOD = pow(10, 9) + 7;
vector<ll> ff(1e6), vff(1e6);

ll powmod(ll a, ll p, ll MOD) {
	ll ans = 1;
	ll mul = a;
	for (; p > 0; p >>= 1, mul = (mul * mul) % MOD) {
		if ((p & 1) == 1)ans = (ans * mul) % MOD;
	}
	return ans;
}

ll combmod(ll n, ll r, ll MOD){
  if(n < r) return 0LL;
  if (n < 0 || r < 0) return 0LL;
  // n combination r
  ll comb = (((ff[n] * vff[r]) % MOD) * vff[n - r]) % MOD;

  return comb;
}


void init(ll n){
  ff[0] = 1;
  for(ll i = 1; i < n + 1; i++) {
    ff[i] = ff[i - 1] * i % MOD;
  }
  // n!^(MOD-2) (= n!^(-1))
  ll inv = powmod(ff[n], MOD - 2, MOD);

  // n!^(-1) ~ 1!^(-1)
  vff[n] = inv;
  for(ll i = n - 1; i >= 0; i--) {
    vff[i] = vff[i + 1] * (i + 1) % MOD;
  }
}

int main() {
    ll N, K;
    cin >> N >> K;
    init(2*N+10);
    if (K >= N-1){
        cout << combmod(2*N-1, N, MOD) << endl;
        return 0;
    }
    ll hoge = (N * (N - 1) + 1) % MOD;
    for(ll i = 2; i <= K; i++){
        ll tmp = (combmod(N - 1, i, MOD) * combmod(N, i, MOD)) % MOD;
        hoge= (hoge + tmp) % MOD;
    }


    cout << hoge << endl;
    return 0;
}


Measured memory_bytes: 15872
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
/*------------------junk----------------------*/
typedef long long int lli;
typedef unsigned long long int ulli;
const int MOD = 1e9 + 7;
#define ff first
#define ss second
#define gc getchar_unlocked
#define fri(i, j , n) for (auto (i) = (j); (i) < (n); ++(i))
#define frie(i, j , n) for (auto (i) = (j); (i) <= (n); ++(i))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f2a(x , n , v)  fill(&(x)[0][0], &(x)[0][0] + (0 + n) *(0 + n) , (v))
#define fa(x , n , v) fill( (x), (x)+(n), (v)) 
#define pb emplace_back
#define mp make_pair
#define getchar_unlocked getchar
# define TMP template<typename
#ifdef LOCAL 
template < class c > struct rge { c b, e; };
template < class c > rge<c> range(c i, c j) { return rge<c>{i, j}; }
template < class c > auto dud(c* x) -> decltype(cerr << *x, 0);
template < class c > char dud(...);
struct debug {
    
    ~debug() { cerr << endl; }
    template < class c > typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) { cerr << boolalpha << i; return * this; }
    template < class c > typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) { return * this << range(begin(i), end(i)); }
    template < class c, class b > debug & operator <<(pair < b, c > d) {
        return * this << "(" << d.first << ", " << d.second << ")";
    }
    template < class c > debug & operator <<(rge<c> d) {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
            *this << ", " + 2 * (it == d.b) << *it;
        return * this << "]";
    }};
#define oo(...) __f(#__VA_ARGS__, __VA_ARGS__)
TMP Arg1>
void __f(const char *name, Arg1 &&arg1)
{cout << name << ": " << arg1 << "\n";}
TMP Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{const char *comma = strchr(names + 1, ',');cout.write(names, comma - names) << ": " << arg1 << " |";__f(comma + 1, args...);
}
void in(int &x){
    cin  >> x;
}
#else
inline void in(int &x)
    {
    register int c = getchar_unlocked();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar_unlocked());
    if(c=='-') {neg=1;c=getchar_unlocked();}
    for(;c>47 && c<58;c = getchar_unlocked()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
    }
inline void uin(ulli &n){
    register ulli c=gc();
    n=0;
    while(c<'0'||c>'9')
    c=gc();
    while(c<='9'&&c>='0'){
    n=n*10+c-'0';
    c=gc();}
}
#endif
/*----------check constraints again-------------*/

int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
    int n;
    cin  >> n;
    vector<int> d(n);
    lli ans = 0;
    fri(i,0,n) cin >> d[i];
    fri(i,0,n)
        fri(j,i+1,n){
        ans+= d[i]*d[j];
    }
    cout << ans;
}







Measured memory_bytes: 256
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int main()
{
	int n=read(),a=read(),b=read();
	b-=a;
	if (b<=2) cout<<n+1;
	else
	{
		if (n<a) cout<<n+1;
		else
		{
			n-=a-1;
			ll ans=a;
			ans+=1ll*b*(n/2);
			if (n&1) ans++;
			cout<<ans;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int,int> pii;
char str[110];
int a[110];
int k;
ll dp[110][4];int len;
ll dfs(int pos,int limit,int lead,int k)
{
    if(pos>len&&!k)return 1;
    else if(pos>len)return 0;
    if(!limit&&!lead&&dp[pos][k]!=-1&&k>=0)return dp[pos][k];
    int cnt=limit?a[pos]:9;
    ll ret=0;
    for(int i=0;i<=cnt;i++)
    {
        if(!lead&&i&&k<=0)continue;
        if(lead&&!i)ret+=dfs(pos+1,limit&&(i==cnt),1,k);
        else if(lead&&i&&k>0)ret+=dfs(pos+1,limit&&(i==cnt),0,k-1);
        else if(!lead&&!i)ret+=dfs(pos+1,limit&&(i==cnt),0,k);
        else if(!lead&&i&&k>0)ret+=dfs(pos+1,limit&&(i==cnt),0,k-1);
    }
    return (!limit&&!lead&&k>=0)?dp[pos][k]=ret:ret;
}
ll solve(int k)
{
    memset(dp,-1, sizeof(dp));
    for(int i=1;i<=len;i++){
        a[i]=str[i]-'0';
    }
    return dfs(1,1,1,k);
}
int main()
{
    scanf("%s%d",str+1,&k);
    len=strlen(str+1);
    printf("%lld\n",solve(k));
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        int n=scn.nextInt();
        scn.close();
        int answer=1;
        for(;answer*answer<=n;answer++){
        }
        System.out.println((answer-1)*(answer-1));
    }
}


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

char str[1024][2048];
int top[1024];

int main(void)
{
	int n;
	while (scanf("%d", &n), n){
		fill_n(*str, n * 2048, '\0');
		
		for (int i = 0; i < n; i++){
			scanf("%s", str[i]);
			for (top[i] = 0; str[i][top[i]] == '.'; top[i]++);
		}
		
		for (int i = 0; i < n; i++){
			vector<int> v;
			v.push_back(i);
			for (int j = i + 1; j < n; j++){
				char c = str[j][top[i]];
				char d = str[j][top[i] + 1];
				if (c >= 'a' && c <= 'z') break;
				if (d >= 'a' && d <= 'z') v.push_back(j);
			}
			for (int t = 1; t < v.size(); t++){
				for (int k = v[t - 1] + 1; k < v[t]; k++){
					str[k][top[i]] = '|';
				}
				str[v[t]][top[i]] = '+';
			}
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; str[i][j] != '\0'; j++){
				if (str[i][j] == '.'){
					str[i][j] = ' ';
				}
			}
		}
		
		for (int i = 0; i < n; i++){
			printf("%s\n", str[i]);
		}
	}
	
	return 0;
};

Measured memory_bytes: 3208
import java.util.Scanner;

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

		int counter = 0;
		int maxw = Integer.parseInt(sc.nextLine());
		while (maxw != 0) {
			counter++;
			
			int num = Integer.parseInt(sc.nextLine());

			int[][] table = new int[num + 1][maxw + 1];
			for (int i = 0; i < table.length; i++) {
				for (int j = 0; j < table[0].length; j++) {
					table[i][j] = 0;
				}
			}
			
			int value, w;
			for (int i = 0; i < num; i++) {
				String[] nico = sc.nextLine().split(",");

				value = Integer.parseInt(nico[0]);
				w = Integer.parseInt(nico[1]);
				
				for (int j = 0; j < table[0].length; j++) {
					if ((j - w) >= 0) {
						if (table[i][j] > (table[i][j - w] + value)) table[i + 1][j] = table[i][j];
						else table[i + 1][j] = table[i][j - w] + value;
					} else {
						table[i + 1][j] = table[i][j];
					}
				}
			}
			
			int max = 0;
			int index = 0;
			for (int i = 0; i < table[0].length; i++) {
				if (max < table[num][i]) {
					max = table[num][i];
					index = i;
				}
			}

			System.out.println("Case " + counter + ":");
			System.out.println(max);
			System.out.println(index);
			
			maxw = Integer.parseInt(sc.nextLine());
		}
	}
}

Measured memory_bytes: 37432
using System;
class Program
{
    static void Main(string[] args)
    {
        // スペース区切りの整数の入力
        string[] input = Console.ReadLine().Split(' ');
        long a = long.Parse(input[0]);
        long b = (long)(decimal.Parse(input[1]) * 100);
        //出力
        Console.WriteLine(a * b / 100);
    }
}


Measured memory_bytes: 27440
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();

		char ch[] = str.toCharArray();
		for(int i=ch.length-1; i>=0; i--)
			System.out.print(ch[i]);
		System.out.println();

	}
}

Measured memory_bytes: 11000
#include<cmath>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=100000+10;
ll f[maxn],xx[maxn];
ll n,e,t;
ll store;//fj-2xj+1
int main(){
	ll b1,b2,b3,b4;
	ll p;//定位
	scanf("%lld%lld%lld",&n,&e,&t);
	
	for (b1=1;b1<=n;b1++){
		scanf("%lld",&xx[b1]);
	}
	for (b1=1;b1<=n;b1++){
		f[maxn]=b1*t;
	}
	p=0;store=((ll)1<<60);
	for (b1=1;b1<=n;b1++){
		while (2*xx[p+1]<=2*xx[b1]-t){
			store=min(store,f[p]-2*xx[p+1]);
			p++;
		}
		f[b1]=min(2*xx[b1]+store,f[p]+t);
		f[b1]=min(f[b1-1]+t,f[b1]);
	}
	printf("%lld\n",f[n]+e);
	
}

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

int a[] = {-1, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
int main(void) {
	int x, y;
	cin >> x >> y;

	if(a[x] == a[y]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int kai = 1;
        for(int i = 0; i < N ; i++){
            kai = kai * 2;
            if(kai > N){
                kai = kai / 2;
                break;
            }
        }
        System.out.println(kai);
    }
}

Measured memory_bytes: 25044
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemA
{
    class Program
    {
        static void Main(string[] args)
        {
            var N_last = Console.ReadLine().ToCharArray().Last();
            var honList = new char[5] { '2', '4', '5', '7', '9' };
            var ponList = new char[4] { '0', '1', '6', '8' };
            var bonList = new char[1] { '3' };

            if (honList.Contains(N_last))
                Console.WriteLine("hon");
            else if (ponList.Contains(N_last))
                Console.WriteLine("pon");
            else
                Console.WriteLine("bon");
        }
    }
}


Measured memory_bytes: 26172
/*
 * ex2_ARC097_C.cpp
 *
 *  Created on: May 15, 2018
 *      Author: 13743
 */
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}



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

	string s;
	int K;
	cin >> s;
	cin >> K;

	vector<string> strs;
	int n = s.length();
	REP(i, n) {
		FOR(j, 1, K) {
			if(i+j-1 == n) break;
			strs.pb(s.substr(i, j));
		}
	}

	sort(ALL(strs));
	UNIQUE(strs);

	cout << strs[K-1] << endl;;
}





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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N;
    cin >>N;

    vector<ll> A(N),B(N),C(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    rep(i,N) cin >> C[i];
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());
    vector<ll> Bd(N),Cd(N);
    rep(i,N){
        Bd[i]=distance(A.begin(),lower_bound(A.begin(),A.end(),B[i]));
        if(i!=0)Bd[i]+=Bd[i-1];
    }
    ll ans=0,t;
    rep(i,N){
        t=distance(B.begin(),lower_bound(B.begin(),B.end(),C[i]))-1;
        if(0<=t)ans+=Bd[t];
    }
    cout << ans <<endl;
    return (0);
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s; cin >> s;
    int n = s.length();

    int ans = n;
    FOR(i, 1, n)if (s[i - 1] != s[i]) {
        chmin(ans, max(i, n - i));
    }

    cout << ans << "\n";
}

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

#define REP(i,n) for(long long 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)

using ll = long long;
#define INF 1e9

int N;
vector<int> A;

int main(){
  cin >> N;
  A.resize(N);
  REP(i, N){
    cin >> A[i];
  }
  int bit = 0, l = 0, r = 1;
  ll ans = 0;
  while(r <= N && r != l){
    // cout << "l:" << l << " r:" << r  <<endl;
    while(r <= N && ((bit & A[r-1])==0)){
      // cout << "add  l:" << l << " r:" << r << endl;
      ans += r - l;
      bit |= A[r-1];
      r++;
    }
    while((bit & A[r-1]) != 0){
      // cout << "pbit:" <<bit << " l:" << l << " r:" << r << " ~A[l]:" << ~(A[l]) << " A[l]" << A[l] << endl;
      bit &= ~A[l];
      l++;
      // cout << "bit:" << bit << " l:" << l << " r:" << r << endl;
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define IOS ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ; 
#define int long long 
#define endl "\n"
#define ll long long 

int cvt(string s)
{
	int ans = 0 ; 
	for(char c:s)
	{
		if(c<='9' && c>='0')
		{
			ans = ans*10 + (c-'0') ; 
		}
	}
	return ans ; 
}

signed main()
{	
	IOS ; 
	
	string s ; 
	getline(cin,s) ;

	int n = s.length() ; 

	string num1 = "" ; 
	string num2 = "" ; 
	string op ="" ; 

	bool ok = true ; 

	int i=0 ; 
	while(1)
	{	
		if(i==n)break ; 
		if(ok)
		{	
			if(s[i]=='+'||s[i]=='-')
				op=s[i],  ok = false ; 
			else if(s[i]<='9'&&s[i]>='0')
			{
				num1 += s[i] ; 
			}
			i++;
		}
		else
		{
			if(s[i]<='9'&&s[i]>='0')
			{
				num2 += s[i] ; 
			}
			i++;
		}
		if(i==n)break ; 
	}

	if(op[0]=='+')
	{
		cout << ( cvt(num1) + cvt(num2) ) << endl ; 
	}
	else
	{
		cout << ( cvt(num1) - cvt(num2) ) << endl ;
	}

return 0; 
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bool ok(int x)
{
	for(int i = 2; i * i <= x; ++i) if (x % i == 0) return 0;
	return 1;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int x;
	cin >> x;
	while(!ok(x))x++;
	
	cout << x;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



Measured memory_bytes: 256
// AOJ 0275 Railroad
// 2018.2.21 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define QMAX 10000
typedef struct { int t, s; } QUE;
QUE que[QMAX+2]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 0x10101010
#define MAX 100003

int S;
int   hi[MAX], *to[MAX]; short *w[MAX];
int dist[MAX];
char  mk[MAX];
int  hi2[MAX], *to2[MAX];

int   q[MAX], top, tail;
typedef struct { int s, e; } T;
T ord[200002], _ord[200002]; int sz;
int f[200002];

int c[65], d[65];
unsigned long long dp[MAX];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

void dijkstra(int start)
{
	int i, s, e, d;

	memset(dist, INF, S << 2);
	qsize = 0;
	enq(start, 0), dist[start] = 0;
	while (qsize) {
		s = que[0].s, deq();
		for (i = 0; i < hi[s]; i++) {
			e = to[s][i], d = dist[s] + w[s][i];
			if (dist[e] < d) continue;
			if (dist[e] > d) hi2[e] = 0, dist[e] = d, enq(e, d);
			to2[e][hi2[e]++] = s;
		}
	}
}

void order(int goal)
{
    int i, k, s, e, max;

	q[0] = goal, top = 0, tail = 1;
	mk[goal] = 1;
	sz = 0, max = 0;
	while (top < tail) {
		s = q[top++];
		for (i = 0; i < hi2[s]; i++) {
			e = to2[s][i];
			if (!mk[e]) mk[e] = 1, q[tail++] = e;

			_ord[sz].s = e, _ord[sz++].e = s;
			k = dist[s];
			if (k > max) max = k;
			f[k]++;
		}
	}

	for (i = 1; i <= max; i++) f[i] += f[i-1];
	for (i = sz-1; i >= 0; i--) {
		k = dist[_ord[i].e], ord[--f[k]] = _ord[i];
	}
}

int main()
{
	int R, Q, u, v, _w, i, j, k;
	int *memo;
	unsigned long long mask;
	
	S = in()+1, R = in();
	memo = malloc(R*12);
	j = 0, i = R; while (i--) {
		memo[j++] = u = in(), hi[u]++;
		memo[j++] = v = in(), hi[v]++;
		memo[j++] = in();
	}
	for (i = 0; i < S; i++) if (hi[i]) {
		to [i] = malloc(hi[i] << 2), w[i] = malloc(hi[i] << 1);
		to2[i] = malloc(hi[i] << 2);
	}

	memset(hi, 0, S << 2);
	j = 0; while (R--) {
		u = memo[j++], v = memo[j++], _w = memo[j++];
		k = hi[u]++, to[u][k] = v, w[u][k] = _w;
		k = hi[v]++, to[v][k] = u, w[v][k] = _w;
	}
	free(memo);

	u = in(), v = in();
	dijkstra(u);
	order(v);

	Q = in(); for (i = 0; i < Q; ) {
		for (k = 0; k < 64 && i < Q; i++) c[k] = in(), d[k++] = in();
        memset(dp, 0, S << 3);
		mask = 1; for (j = 0; j < k; j++) dp[c[j]] |= mask, mask <<= 1;
		for (j = 0; j < sz; j++) dp[ord[j].e] |= dp[ord[j].s];
        mask = 1; for (j = 0; j < k; j++) {
            puts(dp[d[j]] & mask? "Yes": "No"), mask <<= 1;
		}
    }
	return 0;
}



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

int main(){
    int n;
    cin>>n;
    vector<char> s(n);
    vector<char> t(n);
    for(int i=0;i<n;i++){
        cin>>s.at(i);
    }
    for(int i=0;i<n;i++){
        cin>>t.at(i);
    }
    for(int i=0;i<n;i++){
        cout<<s.at(i)<<t.at(i);
    }    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= m; j++) {
                if (i * (m - j) + j * (n - i) == k) {
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 23764
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	s := a % 60
	m := a / 60 % 60
	h := a / 60 / 60
	fmt.Printf("%d:%d:%d\n", h, m, s)
}



Measured memory_bytes: 1124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    ll ans=0;
    for(int bit=0;bit<1<<(n-1);bit++){
        ll sm=0;
        ll a=s[0]-'0';
        rep(i,n-1){
            if(bit & (1<<i)){
                sm+=a;
                a=0;
            }
            a=a*10+s[i+1]-'0';
        }
        sm+=a;
        ans+=sm;
    }
    cout<<ans<<endl;
 }

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

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

void solve(){
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans = (n/(a+b))*a + min(a, n%(a+b));
	cout<<ans<<endl;
	return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll no;
	// cin>>no;
	no = 1;
	while(no--){
		solve();
	}
    return 0;
}

Measured memory_bytes: 256