akhauriyash/Code-Regression huggingface dataset:
from math import ceil

def check(N, hps, A, B):
    n = N
    C = A - B
    for rem_hp in map(lambda x: x - B * N, hps):
        if rem_hp < 0:
            continue
        n -= ceil(rem_hp / C)
        if n < 0:
            return False
    return True

def main():
    N, A, B = [int(i) for i in input().split()]
    H = [int(input()) for _ in range(N)]
    left, right = 0, max(H)
    while left + 1 < right:
        mid = (left + right) // 2
        if check(mid, H, A, B):
            right = mid
        else:
            left = mid
            
    print(right)

if __name__ == "__main__":
    # print(check(1, [8, 7, 4, 2], 5, 3))
    # print(check(3, [8, 7, 4, 2], 5, 3))
    # print(check(2, [8, 7, 4, 2], 5, 3))
    main()




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

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

template<class T>
T read() {
    T x{};
    cin >> x;
    return x;
}
 
template<class T>
vector<T> read(int N){
    vector<T> x(N);
    for(int i = 0; i < N; ++i){
        cin >> x[i];
    }
    return x;
}
 
template<class T>
void write(const T &x){ cout << x << endl; }

int main(){
    auto N = read<ll>();
    auto A = read<ll>(N);
    
    map<ll, ll> m;
    REP(i, N){
        m[A[i]] = i + 1;
    }
    
    for(auto &v : m){
        cout << v.second << " ";
    }
    cout << endl;
}

Measured memory_bytes: 7808
let n = Scanf.scanf " %d" (+) 0
let ws = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let s = Array.fold_left (+) 0 ws
let ans = ref max_int
let _ = for t = 0 to n - 2 do let s1 = ref 0 in
  for i = 0 to t do s1 := !s1 + ws.(i) done; ans := min !ans @@ abs @@ s - 2 * !s1 done; Printf.printf "%d\n" !ans

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

int main() {
    int n;
    cin >> n;
    vector<vector<vector<int> > > vvv;
    REP(i,4) {
        vector<vector<int> > vv;
        REP(j,3) {
            vector<int> v(10,0);
            vv.push_back(v);
        }
        vvv.push_back(vv);
        
    }
    REP(i,n) {
        int p, q, r, s;
        cin >> p >> q >> r >> s;
        vvv[p-1][q-1][r-1] += s;
    }
    
    REP(i,3) {
        REP(j,3) {
            REP(k,10) {
                cout << " " << vvv[i][j][k];
            }
            cout << endl;
        }
        cout << "####################" << endl;
    }
    For(i,3,4) {
        REP(j,3) {
            REP(k,10) {
                cout << " " << vvv[i][j][k];
            }
            cout << endl;
        }
        //cout << "####################" << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
function main(arg) {
	arg = arg.trim().split("\n")[0].split(" ").map(Number)
	var a = arg[0]
	var b = arg[1]
	var t = arg[2]
	var result = 0
	for (var i = a;i < t + 0.5; i += a) {
		result += b
	}
	console.log(result)
  console.error("err")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		long n = sc.nextLong()-1;
		String[] a = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n"
				,"o","p","q","r","s","t","u","v","w","x","y","z"};
		ArrayList<Long> list = new ArrayList<>();
		while(n >= 26) {
			list.add(n % 26);
			n /= 26;
			n--;
		}
		list.add(n);
		for(int i = list.size()-1; i >= 0; i--) {
			long x = list.get(i);
			System.out.print(a[(int)x]);
		}
		
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

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

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

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


Measured memory_bytes: 32764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int ans = 0;
		for (int i = 0; i < N; i++) {
			long digit = in.nextLong();
			if (digit % 2 == 0) {
				while (digit % 2 == 0) {
					digit /= 2;
					ans++;
				}
			}
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 34852
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ld = long double;
// constexpr auto mod = 1000000007;
using namespace std;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int k = 0;
  RREP1(i, 100) {
    if (A % i == 0 && B % i == 0) {
      k++;
    }
    if (k == K) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
//20190720B
#include <stdio.h>
int main(){
	int N;
	int D;
	int x;
	scanf("%d %d",&N,&D);
	if(N%(2*D+1)==0){
		x = N/(2*D+1);
	}else{
		x = (N/(2*D+1))+1;
	}
	printf("%d",x);
}

Measured memory_bytes: 128
import sys

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def solve(a, b, x):
    if a > 0:
        return solve(0, b, x) - solve(0, a - 1, x)
    return b // x + 1


def main():
    a, b, x = read_int_list()
    res = solve(a, b, x)
    print(res)


main()


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

using namespace std;

int main(){
    int a , b, c, d;
    cin>>a>>b>>c>>d;
    int flag = 0;
    // cout<<"A "<<a << " C "<<c <<endl;
    while(a>0 && c > 0){
        if(flag == 0){
            c = c-b;
            flag = 1;
        }
        else{
            flag = 0;
            a = a-d;
        }
    }
    // cout<<"A "<<a << " C "<<c <<endl;
    if(a <= 0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

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

 int main(){
    int N;
    vector<long long int> A;

    cin >> N;
    A.resize(N);
    for(int i=0; i<N; i++)
        cin >> A[i];
    
    bool flag_allplus = true;
    for(int i=0; i<N; i++){
        if(A[i] < 0){
            if(flag_allplus) flag_allplus = false;
            else flag_allplus = true;
        }
    }

    long long int sum = 0;
    if(flag_allplus){
        for(int i=0; i<N; i++)
            sum += abs(A[i]);
    }else{
        int min = 0, min_id = 0;
        for(int i=0; i<N; i++){
            if(i == 0) min = abs(A[i]);
            else if(abs(A[i]) < min) {
                min = abs(A[i]);
                min_id = i;
            }
        }

        for(int i=0; i<N; i++){
            if(i == min_id) sum += std::min(A[i], -A[i]);
            else sum += abs(A[i]);
        }
    }

    cout << sum << endl;
 }

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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

#define MAX_N 100000
template<size_t N>
class UnionFind {
    int par[N];

public:
    UnionFind() {
        for (int n = 0; n < N; n++) par[n] = n;
    }

    int root(int x) {
        if (par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        par[x] = y;
    }
};

UnionFind<MAX_N+1> uf;

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

    ll N, M;
    cin>>N>>M;
    vector<ll> P(N+1);
    for (ll n = 1; n <= N; n++) cin>>P[n];
    for (ll m = 0; m < M; m++) {
        ll x, y;
        cin>>x>>y;
        uf.unite(x, y);
    }

    ll ans = 0;
    for (ll n = 1; n <= N; n++) {
        if (uf.same(n, P[n])) {
            ans++;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main(void){
    int n,i,f;
    long int sum=0;
    scanf("%d",&n);
    int a[n+1],b[n];
    for(i=0;i<n+1;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++){
        scanf("%d",&b[i]);
    }
    for(i=0;i<n;i++){
        if(a[i]>b[i]){
            sum+=b[i];
        }else{
            sum+=a[i];
            f=b[i]-a[i];
            if(f>=a[i+1]){
                sum+=a[i+1];
                a[i+1]=0;
            }else{
                sum+=f;
                a[i+1]-=f;
            }
        }
    }
    printf("%ld\n",sum);
    return 0;
}


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

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> x(n);
	rep(i, n) cin >> x[i];
	long long ans = 0;
	rep(i, n) {
		ans += (min(x[i], abs(k-x[i]))) * 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
N = list(map(int,input().split()))
ans = 0
c = True
while c == True :
  for i in range(n):
    if N[i] % 2 == 1:
      c = False
    else:
      N[i] = int(N[i] / 2)
      
  if c == True:
    ans += 1

print(ans)


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

count = 0

for i, j in enumerate(a):
    try:
        if j > a[i + 1]:
            b = j - a[i + 1]
            count += b
            a[i + 1] = j
        else:
            pass
    except IndexError:
        pass

print(count)

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



int main(){
  int N;
  cin >> N;
  int K;
  cin >> K;
  int ans=0;
  for(int i =0; i<N; i++){
    int a;
    cin >> a;
    if(K<=a){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import itertools

N,M,X=map(int,input().split())
l=[list(map(int,input().split())) for i in range(N)]

it=list(itertools.product([0,1],repeat=N))

ANS = 10**9

for i in it:
    arr = [0]*(M+1)
    for j in range(N):
        arr = list(map(lambda x,y: x+y*i[j], arr, l[j]))
    if all([k>=X for k in arr[1:]]):
        ANS = min(ANS,arr[0])
if ANS == 10**9:
    ANS = -1
print(ANS)

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

int main()
{
  string s;
  cin >> s;
  int i = 0;
  int e = s.size();
  int a, z;

  while (i < e) {
    if (s[i] == 'A') {
      a = i;
      i++;
      break;
    }
    i++;
  }

  while (i < e) {
    if (s[i] == 'Z') {
      z = i;
    }
    i++;
  }

  cout << z + 1 - a << endl;
}


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

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
   string s; cin >> s;
   for(int i=0;i<3;i++){
       cout << s[i];
   }
   cout << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() { 
  string S;
  int poi=0;
  cin >> S;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='x'){
      poi++;
    }
  }
  if(poi>7){
    cout<<"NO"<<endl;
  }
  else{
    cout<<"YES"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	long long N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	cout << max({ (N - 1) / A, (N - 1) / B, (N - 1) / C, (N - 1) / D, (N - 1) / E }) + 5 << endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<bits/stdc++.h>
#include<math.h>
#include<string.h>
using namespace std;
int main(){
int i,j,k,d,n,m,c=0;
cin>>n>>k;
vector<int>a(n+1);
for(i=0;i<k;i++){
    cin>>d;
    for(j=0;j<d;j++){
        cin>>m;
        a[m]++;
    }
}
for(i=1;i<=n;i++){
    if(a[i]==0)
        c++;
}
cout<<c;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>a(n+2,0);
    for(int i=1; i<=n; ++i){
        cin>>a[i];
    }
    int sum=0;
    for(int i=0; i<=n; ++i){
        sum+=abs(a[i]-a[i+1]);
    }
    for(int i=1; i<=n; ++i){
        int ans=sum-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1664
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

n=ii()
arr=limii()

ans=0

for i in range(n):
    while arr[i]%2==0:
        ans+=1
        arr[i]/=2
print(ans)

Measured memory_bytes: 66028
#include<bits/stdc++.h>
#include <ext/numeric>
#define     __        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define     pi        acos(-1)
#define     ll        long long int
#define     mem(a)    memset(a,0,sizeof(a))
#define     mems(a)   memset(a,-1,sizeof(a))
#define     pii       pair<int,int>
#define     N         20005
using namespace std;

int main(){
    __;
/*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif*/

        int64_t a[11],d,r;

        cin >> r >> d >> a[0];


        for(int i=1;i<=10;i++)
        {
            a[i] = r*a[i-1] - d;

            cout << a[i] <<endl;
        }

   return 0;
}


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

int main(){
  int x,n;cin>>x>>n;
  vector<int> p(n);
  for (auto && a : p) {
    cin>>a;
  }
  sort(p.begin(),p.end());

  int j = 0;
  int tmp = INT32_MAX;
  int ans = INT32_MAX;
  for (int i = -100; i <= 10000; i++) {
    //cout << "i = " << i << endl;
    if (j < n && p.at(j) == i)
    {
      j++;
      continue;
    }

    if(tmp > abs(x-i))
    {
      ans = i;
      tmp = abs(x-i);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3604
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
    out << '(' << p.first << ',' << p.second << ')';
    return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
    in >> p.first >> p.second;
    return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
    for (T &x : v)
        in >> x;
    return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
    for (const vector<T> &x : v)
        out << x << '\n';
    return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
    for (const T &x : v)
        out << x << ' ';
    return out;
}

long long gcd (long long a, long long b)
{
    if (b > a)
        swap(a, b);
    return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
    ios::sync_with_stdio(false);
    #ifdef ONLINE_JUDGE
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.setstate(ios::failbit);
    #endif

    bitset<1000001> b;
    int n;
    cin >> n;
    vi cnt(1000001);
    rep(i,0,n)
    {
        int x;
        cin >> x;
        cnt[x]++;
        if(cnt[x] > 1)
            continue;
        for(int i = 2*x; i<1000001; i+=x)
            b[i] = 1;
    }
    int ans = 0;
    rep(i,0,1000001)
        ans += (cnt[i]==1 and !b[i]);
    cout << ans;
}


Measured memory_bytes: 6876
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

long long n,m;
vector<int> edge[100005];
int color[100005];

queue<pair<int, pair<int,int> > > q;

int main(){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;cin>>a>>b;
		a--;b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	q.push(make_pair(0,make_pair(1,-1)));

	bool two = true;

	while(!q.empty()){
		pair<int, pair<int,int> > now = q.front();
		q.pop();
		int nowp = now.first;
		int nowcol = now.second.first;
		int prevp = now.second.second;
		//cout<<nowp<<" "<<nowcol<<" "<<prevp<<endl;
		if(color[nowp] != 0) continue;
		color[nowp] = nowcol;
		for(int i=0;i<edge[nowp].size();i++){
			if(edge[nowp][i] == prevp){
				continue;
			}
			if(color[edge[nowp][i]] != 0){
				if(color[edge[nowp][i]] == (-1*nowcol)) continue;
				else {
					two = false;
				}
			}
			q.push(make_pair(edge[nowp][i],make_pair(-1*nowcol,nowp)));
		}
	}

	ans:
	if(two){
		long long s=0;
		long long t=0;
		for(int i=0;i<n;i++){
			if(color[i]== 1)s++;
			else t++;
		}
		cout<<(s*t-m)<<endl;
	} else {
		cout<<(n*(n-1)/2-m)<<endl;
	}

	return 0;

}


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

int main(int argc,char** argv)
{
	int X,Y;
	scanf("%x%x",&X,&Y);
	if(X > Y){
		printf(">\n");
	}
	else if(X < Y){
		printf("<\n");
	}
	else{
		printf("=\n");
	}
	return(0);
}

Measured memory_bytes: 128
S = gets.chomp
N = S.length

cnt = Hash.new(0)
init = 1
N.times do |i|
    cnt[S[i]] += 1
    init = 0 if i > 0 && S[i-1] == S[i]
end
if cnt.length == 1
    puts 1
    exit
end

mod = (cnt['b'] + cnt['c'] * 2) % 3
if N == 3
    puts mod == 0 ? 3 : 6 + init
    exit
end

MOD = 998244353

dp = Array.new(N){Array.new(3){Array.new(3, 0)}}
3.times do |j|
    dp[0][j][j] = 1
end

(N-1).times do |i|
    3.times do |j|
        3.times do |k|
            3.times do |add|
                next if k == add
                dp[i+1][(j+add)%3][add] += dp[i][j][k]
                dp[i+1][(j+add)%3][add] %= MOD
            end
        end
    end
end

bad = 0
3.times do |j|
    3.times do |k|
        3.times do |add|
            next if k == add || (j+add)%3 != mod
            bad += dp[N-2][j][k]
            bad %= MOD
        end
    end
end

puts (3**(N-1) - bad + init) % MOD

Measured memory_bytes: 38908
fun main(args: Array<String>) {
    val list = readLine()!!.split(" ").map(String::toInt)
    val W = list[0]
    val H = list[1]
    val cir_x = list[2]
    val cir_y = list[3]
    val r = list[4]
    var cir_x_min = cir_x - r
    var cir_x_max = cir_x + r
    var cir_y_min = cir_y - r
    var cir_y_max = cir_y + r
    if (cir_x_min < 0) {
        println("No")
        return
    }
    if (cir_x_max > W) {
        println("No")
        return
    }
    if (cir_y_min < 0) {
        println("No")
        return
    }
    if (cir_y_max > H) {
        println("No")
        return
    }
    println("Yes")

}


Measured memory_bytes: 32072
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <functional>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
using ll = long long;
const ll mod = 1000000007;
//string al = "abcdefghijklmnopqrstuvwxyz";
//bool less_sec(const pair<int, int>&a, const pair<int, int>&b) {
//	return a.second > b.second;
//}
const int MAX_N = 10000;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b, c,n; cin >> a >> b >> c >> n;
	if (n % 2 == 0) {
		cout << a - b << endl;
	}
	else {
		cout << b - a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int mat[n][3];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>mat[i][j];
		}
	}
	
	int dp[3]={0};
	int inter[3]={0};
	dp[0]=mat[0][0];
	dp[1]=mat[0][1];
	dp[2]=mat[0][2];
	
	for(int i=1;i<n;i++)
	{
		inter[0]=max(mat[i][0]+dp[1],mat[i][0]+dp[2]);
		inter[1]=max(mat[i][1]+dp[0],mat[i][1]+dp[2]);
		inter[2]=max(mat[i][2]+dp[0],mat[i][2]+dp[1]);
		dp[0]=inter[0];
		dp[1]=inter[1];
		dp[2]=inter[2];
	}
	cout<<max(dp[0],max(dp[1],dp[2]));
	
}

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

int main() {
    vector<int> x(5);
    for (int i = 0; i < 5; i++)
    {   cin >> x.at(i);
        if(x.at(i) == 0){
            cout << i+1 << endl;
            break;
        }
    }
    
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = 1 << 30;
// static const ll INF = 1LL << 62;
// --------------------------------------------------------


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

    ll N; cin >> N;

    int ans = 0;
    FOR(A, 1, N) {
        FOR(B, 1, N) {
            ll AB = (ll)A * B;
            if (AB >= N) break;
            ll C = N - AB;
            if (C >= 1) ans++;
        }
    }
    cout << ans << '\n';

    return 0;
}


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

int main(void){
    int N, M;
    cin >> N >> M;
    const int NMMAX = 50;
    int A[NMMAX], B[NMMAX];
    for (int i = 0; i < M; ++i) {
        cin >> A[i] >> B[i];
    }
    int road[NMMAX];
    for (int i = 0; i < N; ++i) {
        road[i] = 0;
    }
    for (int i = 0; i < M; ++i) {
        road[A[i]-1] += 1;
        road[B[i]-1] += 1;
    }
    for (int i = 0; i < N; ++i) {
        cout << road[i] << endl;
    }
}


Measured memory_bytes: 3616
n = int(input())
f = [int(input()) for _ in range(n)]
f = [0] + f
vis = [0] * (n + 1)
s , flag , ans = 1 , 0 , 0
vis[s] = 1
while f[s] != 2:
	if vis[f[s]] == 1:
		flag = 1
		break
	s = f[s]
	vis[s] = 1
	ans+=1

if (flag):
	print(-1)
else:
	print(ans+1) 

Measured memory_bytes: 13836
#include<bits/stdc++.h>
using namespace std;
long long n,a[16][16];

int main(){
    cin>>n;
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a[i][j];
    vector<long long> dp(1<<n, 0);
    for(int mask=1;mask< (1<<n);mask++){
        for(int i=0;i<n;i++){
                if ((mask & (1 << i)) == 0) continue;
                for(int j=i+1;j<n;j++ ){
                                  if ((mask & (1 << j)) == 0) continue;

                        dp[mask] += a[i][j];



            }
        }
    }
    for(int mask =1;mask<(1<<n);mask++){
        for(int i = mask ;i>0; i = (i-1) & mask )
            dp[mask] =max(dp[mask], dp[i]+dp[i^mask]);

    }
    cout<<dp[(1<<n)-1];

}


Measured memory_bytes: 896
/*
Author - Glitched
Yeet!!
*/
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define loop(i,x,n) for(ll i = x;i<n;i++)

int main()
{
    ll n;cin>>n;
    ll ans = n*(n+1)/2;
    ll x= n/3;
    ll y = n/5;
    ll z = n/15;
    x = (x*(6+(x-1)*3))/2;
    y = (y*(10+(y-1)*5))/2;
    z = (z*(30+(z-1)*15))/2;
    cout<<ans+z-x-y;
}

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

int main(){
	ll X; cin >> X;
	ll ans = (X/500)*1000;
	X %= 500;
	ans += (X/5)*5;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
p = list(map(int, input().split()))
a = [0]*N
b = [0]*N

for i in range(N):
    c = 49999
    a[p[i]-1] = c*p[i]
    b[p[i]-1] = i + 1 - c*p[i]

m = min(b)
b = map(lambda x: x-m+1,b)
print(" ".join(map(str,a)))
print(" ".join(map(str,b)))


Measured memory_bytes: 7196
(a,b,c=$_.split.map &:to_i;$.<2?(x,y,s,t=a,b,0,0):c>3?y>b&&y=b:c>2?t<b&&t=b:c>1?x>a&&x=a:s<a&&s=a)while gets;p [x-s,0].max*[y-t,0].max

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i];
		--a[i];
	}
	vector<int> b(n);
	for(int i = 0; i < n; ++i){
		const int x = a[i];
		if(x > 0 && b[x - 1] > 0){
			b[x] = b[x - 1] + 1;
		}else{
			b[x] = 1;
		}
	}
	const int answer = n - *max_element(b.begin(), b.end());
	cout << answer << endl;
	return 0;
}



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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int n;cin >> n;
    int sum = 0;
    int mmin = INT_MAX;
    inc(i, 0, n){
        int s;cin >> s;
        sum += s;
        if(s%10 != 0){
            mmin = min(mmin, s);
        }
    }
    if(sum%10 == 0){
        if(mmin == INT_MAX){
            cout << 0 << endl;
        }else{
            cout << sum-mmin << endl;
        }
    }else{
        cout << sum << endl;
    }
    return 0;
}


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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int A[10001];
int main() {
    int N;
    cin >> N;
    reps(x, 1, 101)reps(y, 1, 101)reps(z, 1, 101){
        int ans = x * x + y * y + z * z + x * y + y * z + z * x;
        if (ans <= 10000){
            A[ans]++;
        }
    }
    reps(i, 1, N + 1){
        cout << A[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	ll a[26];
	ll b[26];
int main(){
	string s,t;
	cin>>s>>t;
	rep(i,0,s.length()){
		ll x=s[i]-'a';
		a[x]++;
		ll y=t[i]-'a';
		b[y]++;
	}
	sort(a,a+26);
	sort(b,b+26);
	bool ans=true;
	rep(i,0,26){
		if(a[i]!=b[i]){
			ans=false;
			break;
		}
		else continue;
	}
	if(ans)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
		
}

Measured memory_bytes: 776
s=input()
t=input()

dp = [[0 for i in range(len(t)+1)] for j in range(len(s)+1)] 

for i in range(1, len(s)+1):
    for j in range(1, len(t)+1):
        #print(i-1, j-1)
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1]+1
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
#print(dp)
str = ''

while(i>0 and j>0):
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        str = s[i-1]+str
        i -= 1
        j -= 1
print(str)

Measured memory_bytes: 119900
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

printList [a] = print a
printList (a:as) = putStr ( show a ) >> putChar ' ' >> printList as

main = do
	getLine
	as <- readIntegers
	print $ sum $ zipWith (-) ( scanl1 max as ) as

Measured memory_bytes: 10204
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int odp = 0;
    for (int i = 1; i <= n; i += 2)
    {
        int d = 0;
        for (int j = 1; j <= i; ++j)
            if (i % j == 0)
                ++d;
        if (d == 8)
            ++odp;
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define x first
#define y second
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ve vector
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define sz(a) (int)(a.size())
//using namespace __gnu_pbds;
using namespace std;

// // // functions: find_by_order  & order_of_key
// typedef tree<
// int,
// null_type,
// less<int>,
// rb_tree_tag,
// tree_order_statistics_node_update>
// ordered_set;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

const int inf=(int)2e9;
const long long mod=1000000007; //1E9+7
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

ll powmod(ll a,ll p){
	ll ans=1;
	while(p){
		if(p&1) ans*=a;
		p/=2;a*=a; ans%=mod;a%=mod;
	}
	return ans;
}
ll mdinv(ll a){return powmod(a,mod-2); }

const int N=3e3+3;

signed main(){
	IOS
	int n;cin>>n;
	long double x;
	ve<long double> DP(2*N,0),DP_new(2*N);
	DP[N]=1;
	for(int i=0;i<n;i++){
		cin>>x;
		long double y=1-x;
		for(int j=0;j<2*N;j++){
			long double a=0;
			if(j+1<2*N)
				a+=DP[j+1]*x;
			if(j-1>=0)
				a+=DP[j-1]*y;
			DP_new[j]=a;
		}
		swap(DP,DP_new);
	}
	long double ans=0;
	for(int i=N;i<2*N;i++)
		ans+=DP[i];
	ans=1-ans;
	cout<<setprecision(18)<<ans;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, x, t;
	scanf("%d%d%d", &n, &x, &t);
	int l = 1;
	int r = 1e5;
	int answer = -1;
	while(l <= r) {
		int mid = l + (r - l)/2;
		if(x * mid >= n) {
			answer = mid;
			r = mid-1;
		} else {
			l = mid + 1;
		}
	}
	printf("%d\n", answer * t);
	return 0;
}


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

int main(){
    int h,w;
    cin >> h >> w;
    vector< vector<char> > a(h, vector<char>(w));
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> a.at(i).at(j);

    bool vertical=true, horizontal=true;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a.at(i).at(j) == '#') horizontal = false;
        }
        if(horizontal){
            for(int j=0;j<w;j++) a.at(i).at(j) = '-';
        }
        horizontal = true;
    }
    for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            if(a.at(j).at(i) == '#') vertical=false;
        }
        if(vertical){
            for(int j=0;j<h;j++) a.at(j).at(i) = '-';
        }
        vertical = true;
    }
    bool newline = false;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a.at(i).at(j) != '-'){
                newline = true;
            }else{
                continue;
            }
            cout << a.at(i).at(j);
        }
        if(newline) cout << endl;
        newline = false;
    }
    return 0;
}


Measured memory_bytes: 256
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

bingo = False
for i in range(3):
    bingo = bingo or (A[i][0] in B and A[i][1] in B and A[i][2] in B)
    bingo = bingo or (A[0][i] in B and A[1][i] in B and A[2][i] in B)
bingo = bingo or (A[0][0] in B and A[1][1] in B and A[2][2] in B)
bingo = bingo or (A[0][2] in B and A[1][1] in B and A[2][0] in B)
print("Yes" if bingo else "No")


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main()
{
    int n,m,x,ca=0,cb=0;
    string s;
    cin>>n>>m;
    vector<int> a(n+1);vector<bool> b(n);
    for(int i=0;i<m;++i)
    {
        cin>>x>>s;
        if(b[x]) continue;
        if(s=="AC")
        {
            b[x]=1;
            ++ca;
            cb+=a[x];
        }
        else if(s=="WA")
            ++a[x];

    }
    cout<<ca<<" "<<cb;
    return 0;
}


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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()
#define endl "\n"

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int h,w;
    cin >> h >> w;
    int ch,cw,dh,dw;
    cin >> ch >> cw;
    cin >> dh >> dw;

    ch--; cw--; dh--; dw--;

    vector<string> s(h);

    rep(i, h){
        cin >> s[i];
    }

    deque<pair<int, pair<int, int>>> deq;
    vector<vector<int>> dist(h, vector<int>(w, h * w));

    deq.push_front(make_pair(0, make_pair(ch, cw)));

    while(!deq.empty()){
        int tmpd = deq.front().first;
        int tmpy = deq.front().second.first;
        int tmpx = deq.front().second.second;

        deq.pop_front();

        if(tmpd < dist[tmpy][tmpx]){
            dist[tmpy][tmpx] = tmpd;

            for(int i = -2; i <= 2; i++){
                for(int j = -2; j <= 2; j++){
                    int nexty = tmpy + i;
                    int nextx = tmpx + j;

                    if(0 <= nexty && nexty < h && 0 <= nextx && nextx < w && s[nexty][nextx] == '.'){
                        if(abs(i) + abs(j) == 0){

                        }else if(abs(i) + abs(j) == 1){
                            deq.push_front(make_pair(tmpd, make_pair(nexty, nextx)));
                        }else{
                            deq.push_back(make_pair(tmpd + 1, make_pair(nexty, nextx)));
                        }
                    }
                }
            }
        }
    }

    cout << (dist[dh][dw] == h * w ? -1 : dist[dh][dw]) << endl;

}

Measured memory_bytes: 10564
#!/usr/bin/env python3

import collections
import sys
input=sys.stdin.readline

n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
cnt1=collections.Counter(arr1)
cnt2=collections.Counter(arr2)
tmp=[[key,cnt1[key]] for key in cnt1.keys()]
tmp=sorted(tmp,reverse=True,key=lambda x:x[1])
arr3=[]
for key,cnt in tmp:
    for _ in range(cnt):
        arr3.append(key)
cnt1=collections.Counter(arr3)
ans=[0]*n
acum=0
pos=0
blank=0
ok=0
head=[]
for key in cnt1.keys():
    tcnt1=cnt1[key]
    tcnt2=cnt2[key]
    acum+=tcnt1
    tpos=max(acum,pos)
    tmp=n-min(tpos,n)
    if blank+tmp<tcnt2:
        print('No')
        exit()
    blank=min(tpos,n)-ok
    remain=tcnt2
    #print(key,blank,remain)
    for i in range(tpos,n):
        if remain==0:
            break
        ans[i]=key
        ok+=1
        remain-=1
        cnt2[key]-=1
    for _ in range(remain):
        head.append(key)
        cnt2[key]-=1
    pos=min(tpos+tcnt2,n)
    #print(ans,head,pos)
for key in cnt2.keys():
    if cnt2[key]==0:
        continue
    for _ in range(cnt2[key]):
        head.append(key)
pos=0
for i in range(n):
    if ans[i]==0:
        ans[i]=head[pos]
        pos+=1
tmp=[[ans[i],arr3[i]] for i in range(n)]
tmp=sorted(tmp,key=lambda x:x[1])
ans=[tmp[i][0] for i in range(n)]
print('Yes')
print(*ans)

Measured memory_bytes: 85164
#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> pp;
const ll INF = 1e14;
const int MOD = 1000000007;
int n = 503,c = 31;
vector<vector<int>> d(c,vector<int>(c,0));
vector<int> col_0,col_1,col_2;
vector<ll> ch_0(c,0),ch_1(c,0),ch_2(c,0);
 
int main() {
  cin >> n >> c;
  rep(i,c)rep(j,c) cin >> d.at(i).at(j);
  rep(i,n)rep(j,n){
    int a; cin >> a;--a;
    if((i+j)%3 == 0) col_0.push_back(a);
    else if((i+j)%3 == 1) col_1.push_back(a);
    else col_2.push_back(a);
  }
  
  rep(i,c){
    for(auto p:col_0){
      ch_0.at(i) += d.at(p).at(i);
    }
    for(auto p:col_1){
      ch_1.at(i) += d.at(p).at(i);
    }
    for(auto p:col_2){
      ch_2.at(i) += d.at(p).at(i);
    }
  }
  
  ll ans = INF;
  rep(i,c)rep(j,c)rep(k,c){
    if(i==j || j==k || k==i) continue;
    ans = min(ans,ch_0.at(i) + ch_1.at(j) + ch_2.at(k));
  }
  
  cout << ans << endl;    
  
  return 0;
}



Measured memory_bytes: 1528
# -*- coding: utf-8 -*-
N = int(input())
An = list(map(int, input().split()))

# 尺取
ans = 0
l = 0
r = 0
Asum = An[0]
Axor = An[0]
while l < N and r < N:
    if Asum == Axor:
        ans += r-l+1
        r += 1
        if r < N:
            Asum += An[r]
            Axor ^= An[r]
    else:
        if l < N:
            Asum -= An[l]
            Axor ^= An[l]
        l += 1

print(ans)


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

int main(){
    int a,b;
    cin >> a>>b;
    int A,B;

    if(a<b){
        rep(i,b){
            cout << a;
        }
    }else{
        rep(i,a){
            cout <<b;
        }
    }
    cout<<endl;
}

Measured memory_bytes: 3568
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int[][] s=new int[m][];
    for(int i=0;i<m;i++){
      int k=sc.nextInt();
      s[i]=new int[k];
      for(int j=0;j<k;j++){
        s[i][j]=sc.nextInt()-1;
      }
    }
    int[] p=new int[m];
    for(int i=0;i<m;i++){
      p[i]=sc.nextInt();
    }
    int ans=0;
    for(int b=0;b<1<<n;b++){
      boolean flag=true;
      for(int i=0;i<m;i++){
        int cnt=0;
        for(int j=0;j<s[i].length;j++){
          cnt+=(b&1<<s[i][j])==0?0:1;
        }
        if((cnt&1)==p[i]){
        }else{
          flag=false;
        }
      }
      if(flag){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23636
line=input()
org=len(line)
rem=1
if len(line) % 2 == 1:
    line = line[0:len(line)-1]
else:
    line = line[0:len(line)-2]
    rem+=1
l=len(line)
while l >= 0:
    flg=0
    for i in range(0,int(l/2)):
        if line[i] != line[i+int(l/2)]:
            flg=1
            break
    if flg==0:
        print(str(org-rem))
        break
    l-=2
    rem+=2
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x, a, b;
  cin >>x >>a >>b;
  
  if (a >= b)
    cout << "delicious";
  else if (b - a <= x)
    cout << "safe";
  else 
    cout << "dangerous";
}

Measured memory_bytes: 3588
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

#define INF 1e9

int main() {
  int n, ma, mb;
  scanf("%d %d %d", &n, &ma, &mb);
  vi a(n), b(n), c(n);
  rep (i, n) {
    scanf("%d %d %d", &a[i], &b[i], &c[i]);
  }
  if (n == 1) {
    if (ma * b[0] == mb * a[0]) {
      printf("%d\n", c[0]);
    } else {
      printf("-1\n");
    }
    return 0;
  }
  vvi p1(201, vi(201, INF)), p2(201, vi(201, INF));
  int mid1 = n/2;
  int mid2 = n - mid1;

  rep (i, (1 << mid1)) {
    int aa = 0;
    int bb = 0;
    int cost = 0;
    rep (j, mid1) {
      if (((i >> j)&1) == 1) {
        aa += a[j];
        bb += b[j];
        cost += c[j];
      }
    }
    p1[aa][bb] = min(p1[aa][bb], cost);
  }
  rep (i, (1 << mid2)) {
    int aa = 0;
    int bb = 0;
    int cost = 0;
    rep (j, mid2) {
      if (((i >> j)&1) == 1) {
        aa += a[j + mid1];
        bb += b[j + mid1];
        cost += c[j + mid1];
      }
    }
    p2[aa][bb] = min(p2[aa][bb], cost);
  }

  int ans = INF;
  rep (i, 201) {
    rep (j, 201) {
      if (p1[i][j] == INF) {
        continue;
      }
      FOR (r, 1, 401) {
        int ra = ma * r;
        int rb = mb * r;
        int i2 = ra - i;
        int j2 = rb - j;
        if (i2 < 0 || j2 < 0) {
          continue;
        }
        if (i2 > 200 || j2 > 200) {
          continue;
        }
        if (p2[i2][j2] == INF) {
          continue;
        }
        ans = min(ans, p1[i][j] + p2[i2][j2]);
      }
    }
  }
  if (ans != INF) {
    printf("%d\n", ans);
  } else {
    printf("-1\n");
  }

  return 0;
}


Measured memory_bytes: 1144
#include<iostream>
#include<algorithm>
using namespace std;
int N;
long A[1<<17],ans,now;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	if(N%2==0)
	{
		int t=N/2;
		for(int i=0;i<t;i++)
		{
			long k=i==t-1?1:2;
			ans-=k*A[i];
			ans+=k*A[N-i-1];
		}
	}
	else
	{
		int t=N/2;
		for(int i=0;i<t-1;i++)
		{
			ans-=2*A[i];
			ans+=2*A[N-i-1];
		}
		now=ans;
		ans+=A[t+1]+A[t]-2*A[t-1];
		now+=2*A[t+1]-A[t]-A[t-1];
		if(ans<now)ans=now;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
const ll mod = 1000000007;
const int mugen = 1000001000;
int dp[30010];

int main() {
    int h,n;
    scanf("%d %d",&h,&n);
    vector<int> a,b;
    int max_a = 0;
    for (int i = 0; i < n; i++) {
        int x,y;
        scanf("%d %d",&x,&y);
        max_a = max(max_a,x);
        a.push_back(x),b.push_back(y);
    } 
    for (int i = 1; i <= h + max_a; i++) dp[i] = mugen;
    int ans = mugen;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j + a[i] <= h + max_a; j++) {
            dp[j + a[i]] = min(dp[j + a[i]], dp[j] + b[i]);
        }
    }
    for (int i = h; i <= h + max_a; i++) ans = min(ans,dp[i]);
    printf("%d\n",ans);
}

Measured memory_bytes: 256
import math
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        gcd1 = math.gcd(i, j)
        for l in range(1, k + 1):
            gcd2 = math.gcd(gcd1, l)
            ans += gcd2
print(ans)

Measured memory_bytes: 9036
using System;
using System.Linq;
using System.Collections.Generic;

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            string input;
            while((input = Console.ReadLine()) != null) {
                Console.WriteLine(Add(new Queue<int>(input.Select(q => q - '0'))));
            }
        }
        static int Add(Queue<int> numbers)
        {
            if(numbers.Count() == 1) {
                return numbers.Peek();
            }
            else {
                Queue<int> que = new Queue<int>();
                while(numbers.Count() > 1) {
                    que.Enqueue((numbers.Dequeue() + numbers.Peek()) % 10);
                }
                return Add(que);
            }
        }
    }
}

Measured memory_bytes: 6140
from itertools import combinations

N = int(input())
rods = map(int, input().split())

if N < 3:
    print(0)
    exit()

cnt = 0
for i in combinations(rods, 3):
    if len(set(i)) != 3:
        continue
    i = sorted(i)
    if i[0] + i[1] <= i[2]:
        continue
    cnt += 1
print(cnt)


Measured memory_bytes: 68552