akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

int g(int x, int y, int z) {
    return x * x + y * y + z * z + x * y + y * z + z * x;
}

int h(int x, int y, int z) {
    return x == y ? (y == z ? 1 : 3) : (y == z ? 3 : 6);
}

int main(void) {
    int a[10001] = {0};
    int n;
    scanf("%d", &n);

    for (int x = 1; ; x++) {
        int k = 6 * x * x;
        if (n < k) break;
        for (int y = x; ; y++) {
            k = x * x + 3 * y * y + 2 * x * y;
            if (n < k) break;
            for (int z = y; ; z++) {
                k = g(x, y, z);
                if (n < k) break;
                int w = h(x, y, z);
                a[k] += w;
            }
        }
    }

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


Measured memory_bytes: 1684
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

bool dp[1000005];
int ans;

void rec(int n){
  
  if (n%2){
    ans++;
    if (dp[3 * n + 1]) return;
    dp[3 * n + 1] = true;
    rec(3 * n + 1);
  }
  else {
    ans++;
    if (dp[n/2]) return;
    dp[n/2] = true;
    rec(n/2);
  }
}

int main(){
  int s;
  cin >> s;
  
  ans = 1;
  for (int i = 0; i < 1000005; i++) dp[i] = false;
  dp[s] = true;
  rec(s);
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
int main(void)
{
  int n,cnt1=0,cnt2=0;
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    if(i%2==1){
      cnt1++;
    }
    cnt2++;
  }
  printf("%.10f",(double)cnt1/cnt2);
  return 0;
}


Measured memory_bytes: 128
k, n = map(int, input().split())
a = list(map(int, input().split())) 
ax = a + [a[0] + (k-a[-1])]
ax = a + [a[0] + (k)]
index = 0
biggest = 0
for i in range(n):
    if (ax[i+1] - ax[i]) > biggest:
        biggest = (ax[i+1] - ax[i])
        index = i

ans = 0
for i in range(n):
    if i != index:
        ans += ax[i+1]-ax[i]


print(ans)


Measured memory_bytes: 26420
import numpy as np
N = int(input())
# TT = [[0]*10 for i in range(10)]
TT = np.zeros((10,10))

for i in range(N+1):
    top = int(str(i)[0])
    tail = int(str(i)[-1])
    TT[top,tail] += 1
#print(TT)
y = 0
for i in range(1,10):
    for j in range(1,10):
        y += TT[i,j]*TT[j,i]
print(int(y))

Measured memory_bytes: 12396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){
    ll n,d;cin>>n>>d;
    d=2*d+1;
    ll a=n/d;
    if(n%d!=0)a++;
    cout<<a<<endl;
    
    return 0;
}







Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
 
int main(){
 
  int n;
  cin >> n;
  while(n){
  	int t = n % 10;
    if(t == 7) {
    	cout << "Yes";
      return 0;
    }else{
    	n /= 10;
    }
  }
  cout << "No";
  return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int N, Z, W;
  cin >> N >> Z >> W;
  vector<int> A(N);
  rep(i, N) cin >> A[i];

  int score0 = abs(A[N - 1] - W);
  int score1 = 0;
  if (N > 1) {
    score1 = abs(A[N - 2] - A[N - 1]);
  }
  cout << max(score0, score1) << endl;
  return 0;
}


Measured memory_bytes: 256
n = input()
one = 0
two = 0
three = 0
four = 0
five = 0
six = 0
for i in range(n):
	tall = float(raw_input())
	if tall < 165.0:
		one +=1
	elif tall < 170.0:
		two += 1
	elif tall < 175.0:
		three += 1
	elif tall < 180.0:
		four += 1
	elif tall < 185.0:
		five += 1
	else:
		six += 1

print '1:' + '*' * one
print '2:' + '*' * two
print '3:' + '*' * three
print '4:' + '*' * four
print '5:' + '*' * five
print '6:' + '*' * six


Measured memory_bytes: 4256
import sys
sys.setrecursionlimit(10 ** 6)


def input():
    return sys.stdin.readline()[:-1]


def dfs(now, prev=-1):
    for next in tree[now]:
        # 1個前のノードを参照した時はcontinue
        if next == prev:
            continue

        # 現在のポイントを次のノードへ加算して累積和をとる
        point[next] += point[now]

        # 次のノードへ
        dfs(next, now)


N, Q = map(int, input().split())
tree = [[] for _ in range(N)]
point = [0]*N

# 木構造を2次元配列で表現。要素Xのノードからつながっているノード番号が格納される。
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

# 各ノードのポイントを求める
for _ in range(Q):
    p, x = map(int, input().split())
    point[p-1] += x

dfs(0)
print(*point)


Measured memory_bytes: 268420
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	int x = abs(a-b), y = abs(b-c), z= abs(c-a);
	ans = x + y + z -max(x, max(y, z));
	cout << ans << endl;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(int argc, char const *argv[])
{
	int d;
	scanf("%d",&d);
	printf("Christmas");
	for (int i = 0; i < abs(d - 25); ++i)	printf(" Eve");
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.regex.Pattern
import java.util.{ArrayList, Collections, Comparator, List => JList}

import scala.collection.immutable.TreeMap
import scala.math._
import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    val k = input.split(LINE_SEPARATOR).head.toInt
    val Array(a, b) = input.split(LINE_SEPARATOR).tail.head.split(" ").map(_.toInt)
    if ((a to b).map(_ % k == 0).exists(b => b)) "OK" else "NG"
  }


  def factorize(x: Long): List[Long] = {
    def foo(x: Long, a: Long = 2, list: List[Long] = Nil): List[Long] = a*a > x match {
      case false if x % a == 0 => foo(x / a, a    , a :: list)
      case false               => foo(x    , a + 1, list)
      case true                => x :: list
    }
    foo(x)
  }

  def divisors(n: Long): Vector[Long] = {
    val halfList = (1 to sqrt(n).toInt).toVector.filter(_ % n == 0).map(_.toLong)
    val reversedList = if (sqrt(n).floor == sqrt(n)) halfList.reverse.tail.map(n/_) else halfList.reverse.map(n/_)
    halfList ++ reversedList
  }

  def gcd(m: Long, n: Long): Long = n match {
    case 0 => m
    case _ => gcd(n, m % n)
  }
  def lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

  val tests=List(
    """33""".stripMargin -> """2 -1
                              |
                                   |
                                 |
                                   |""".stripMargin,
    """1""".stripMargin -> """0 -1""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int a,b,k;
	cin>>a>>b>>k;
	if(a==k){
		cout<<"0 "<<b;
	}
	else{
		if(a<k){
			cout<<"0 "<<max((b-k+a),0ll);
		}
		else{
			cout<<(a-k)<<" "<<b;
		}
	}
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

template <typename T>
vector<T> prime_facs(T N){
    vector<T> ans;
    for(int i = 2; i*i <= N; i++){
        if(N%i == 0){
            ans.push_back(i);
            while(N%i == 0){
                N /= i;
            }
        }
    }
    if(N != 1) ans.push_back(N);
    return ans;
}

template <typename T>
vector<T> divs(T N){
    vector<T> ans;
    for(ll i = 1; i*i <= N; i++){
        if(N%i == 0){
            ans.push_back(i);
            if(i*i != N) ans.push_back(N/i);
        }
    }
    return ans;
}


ll sim(ll N, ll K){
    while(N >= K){
        if(N%K == 0) N = N/K;
        else N = N%K;
    }
    return N;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll N;
    cin >> N ;
    vector<ll> ds = divs<ll>(N);
    int ans = 0;
    for(int i = 0; i < ds.size(); i++) {
        if(ds[i] == 1)continue;
        if(sim(N, ds[i]) == 1) ans++;
    }
    vector<ll> ds1 = divs<ll>(N-1);
    ans += ds1.size();
    ans--;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define SIZE 2000000

int A[SIZE];
int H;

void insert(int x)
{
  int tmp;
  A[H] = x;
  H++;
  int i=H-1;
  int parent = (i-1)/2;
  if (H<1) return;
  while (A[parent]<A[i]) {
    tmp = A[parent];
    A[parent] = A[i];
    A[i] = tmp;
    if (i==0) break;
    tmp = i;
    i = parent;
    parent = (i-1)/2;
  }
}

void maxHeapify(int i) {
  int largest, tmp;
  int l = (i+1)*2-1;
  int r = (i+1)*2;

  if (l<H && A[l]>A[i])      largest = l;
  else                       largest = i;
  if (r<H && A[r]>A[largest])  largest = r;

  if (largest != i) {
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}
int extract()
{
  if (H<0) return -1;
  int val = A[0];
  A[0]=A[H-1];
  maxHeapify(0);
  H--;
  return val;
}


void print()
{
  int i, n=1;
  printf("[ ");
  while (1) {
    for (i=n-1; i<=(n-1)*2; i++) {
      if (i>=H) goto END;
      printf("%d ",A[i]);
    }
    printf("\n");
    n*=2;
  }
 END:
  printf("] H==%d\n", H);
}

int main() {
  int key;
  char com[20];
  while (1) {
    scanf("%s", com);
    if (com[2] == 'd')   break;
    if (com[0] == 'i') {
      scanf("%u", &key);
      insert(key);
    } else { // extract
      int e = extract();
      if (e<0) break;
      printf("%d\n", e);
    }
  }
  return 0;
}


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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  rep(i, n) --p[i];

  vector<ll> a(n), b(n);
  rep(i, n) {
    a[i] = b[i] = 800000000-i*n;
  }
  reverse(ALL(a));
  rep(i, n) {
    a[p[i]] += i;
    b[p[i]] += i;
  }
  line_out(a);
  line_out(b);
}

Measured memory_bytes: 3748
#include<stdio.h>
#include<string.h>
int main()
{
	char s[200005];
	scanf("%s", s);
	int i;
	int n = strlen(s);
	long long int ans = 0, count = 0;
	for (i = 0; i < n; i++)
	{
		if (s[i] == 'A')
			count++;
		else if (s[i] == 'B')
		{
			if (s[i + 1] == 'C')
			{
				ans += count;
				i++;
			}
			else
				count = 0;
		}
		else
			count = 0;
	}
	printf("%lld\n", ans);
	return 0;
}

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

    //long long
    using ll = long long;

    // pair<int, int>
    using PII = pair<int, int>;

    //最大値、mod
    const int MOD = 1000000007;
    const int INF = 1000000000;
    const long long LINF = 1e18;

    //出力系
    #define print(x) cout << x << endl
    #define prints(x) cout << fixed << setprecision(10) << x << endl
    #define printc(x) cout << setw(2) << setfill('0') << x << endl;
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

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

    //最大公約数 
    unsigned gcd(unsigned a, unsigned b) {
      if(a < b) return gcd(b, a);
      unsigned r;
      while ((r=a%b)) {
        a = b;
        b = r;
      }
      return b;
    }

    // 最小公倍数
    unsigned lcm(unsigned a, unsigned b){
        return a / gcd(a, b) * b; 
    }

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

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









    int main(){
      ll N, K;
      cin >> N >> K;
      vector<ll>A(N);
      vector<ll>B(N);
      REP(i, N) cin >> A.at(i);
      REP(i, N) B.at(i) = -A.at(i);
      sort(all(A));
      sort(all(B));
      ll br = LINF, bl = -LINF;
      while(br - bl > 1){
        ll mid = (br + bl) / 2;
        ll cnt = 0;
        REP(i, N){
          if(A.at(i) > 0){
            int l = -1, r = N;
            while(r - l > 1){
              int m = (r + l) / 2;
              (A.at(i) * A.at(m) > mid ? r : l) = m;
            }
            cnt += r;
            if(A.at(i) * A.at(i) <= mid) cnt--;
          }else if(A.at(i) == 0) {
            if(mid >= 0) cnt += N - 1; 
          }else if(A.at(i) < 0){
            int l = -1, r = N;
            while(r - l > 1){
              int m = (r + l) / 2;
              (A.at(i) * -B.at(m) > mid ? r : l) = m;
            }
            cnt += r;
            if(A.at(i) * A.at(i) <= mid) cnt--;
          }
        }
        if(cnt >= K * 2) br = mid;
        else bl = mid;

      }

    print(br);
    return 0;
    }


Measured memory_bytes: 3328
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define int long long
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)

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

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

signed main()
{
    int N, L; cin >> N >> L;

    vector<string> v;

    rep(i, N) v.PB(get<string>());

    sort(v);

    rep(i, N) cout << v[i];
    cout << endl;
}


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

int main() {
  ll n, ans = 0; string s; cin >> n >> s;
  vector<vector<int>> G(3, vector<int>(n+1));
  rep(i, n) {
    rep(j, 3) G[j][i+1] = G[j][i];
    int t;
    if (s[i] == 'R') t = 0;
    if (s[i] == 'G') t = 1;
    if (s[i] == 'B') t = 2;
    G[t][i+1]++;
  }
  // rep(i, n+1) cout << G[0][i] << endl;
  // rep(i, n+1) cout << G[1][i] << endl;
  // rep(i, n+1) cout << G[2][i] << endl;
  rep(i, n) {
    for (int j = i+1; j < n; j++) {
      if (s[i] == s[j]) continue;
      int t;
      if (s[i] == 'R') t = 0;
      if (s[i] == 'G') t = 1;
      if (s[i] == 'B') t = 2;
      int t2;
      if (s[j] == 'R') t2 = 0;
      if (s[j] == 'G') t2 = 1;
      if (s[j] == 'B') t2 = 2;
      ans += G[3 - t - t2][n] - G[3 - t - t2][j+1];
      if (j + j - i <= n - 1) {
        int t3;
        int k = j + j - i;
        if (s[k] == 'R') t3 = 0;
        if (s[k] == 'G') t3 = 1;
        if (s[k] == 'B') t3 = 2;
        if ((3 - t - t2) == t3) ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

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

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define what_is(x) cout<<#x<<" is "<<x<<en;

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

void solve()
{
	int n, p;
	cin >> n >> p;
	string s;
	cin >> s;

	if (p == 2 || p == 5)
	{
		ll ans = 0;
		for (int i = 0; i < n; i++)
			if ((s[i] - '0') % p == 0)
				ans += i + 1;
		cout << ans;
		return;
	}

	vector<int> a(n);
	reverse(all(s));
	int pw = 1;
	for (int i = 0; i < n; i++)
	{
		a[i] = ((s[i] - '0')*pw) % p;
		pw = (pw * 10) % p;
	}

	map<int, int> mp;
	vector<int> pref(n);
	pref[0] = a[0];
	for (int i = 1; i < n; i++)
		pref[i] = (pref[i - 1] + a[i]) % p;
	
	ll ans = 0;

	mp[pref[0]]++;
	if (pref[0] == 0)
		ans++;

	for (int i = 1; i < n; i++)
	{
		ans += mp[pref[i]];
		if (pref[i] == 0)
			ans++;
		mp[pref[i]]++;
	}
	cout << ans;
}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();

}

Measured memory_bytes: 2428
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc075/tasks/abc075_b

"""
import sys
from sys import stdin
input = stdin.readline


def solve(field, H, W):
    dy = [-1, 1, 0, 0, -1, -1,  1, 1]
    dx = [0, 0, -1, 1, -1,  1, -1, 1]

    for y in range(H):
        for x in range(W):
            if field[y][x] == '#':
                continue
            mine = 0
            for i in range(8):
                nx = x + dx[i]
                ny = y + dy[i]
                if (not 0 <= nx < W) or (not 0 <= ny < H):
                    continue
                if field[ny][nx] == '#':
                    mine += 1
            field[y][x] = str(mine)


def main(args):
    H, W = map(int, input().split())
    field = []
    for _ in range(H):
        temp = input().strip('\n')
        temp = list(temp)
        field.append(temp)

    result = solve(field, H, W)

    for r in field:
        print(''.join(r))


if __name__ == '__main__':
    main(sys.argv[1:])


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

#define bitGet(a, i) a & (1 << i)
#define bitOn(a, i) a != (1 << i)
#define bitOff(a, i) a &= ~(1 << i)
#define bitMake(a, i) a = (1 << N)
#define fto(i, a, b) for(int i = a; i <= b; ++i)
#define fdto(i, a, b) for(int i = a; i >= b; --i)
#define ull unsigned long long
#define ll long long
#define ld long double
#define pri(a) cout << a << " "
#define pril(a) cout << a << " "
#define pb push_back
#define mp make_pair
#define vi vector<int> 
#define pi pair<int, int>
#define sz(a) (int)(a.size()-1)
#define oo INT_MAX
#define maxN

using namespace std;


int main() {
    #ifndef ONLINE_JUDGE
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    #endif // !ONLINE_JUDGE

    string s, t;
    cin >> s >> t;

    int rs = oo;
    fto(i, 0, sz(s) - sz(t)) {
        int cnt = 0;
        fto(j, 0, sz(t)) if(s[i + j] != t[j]) ++cnt;
        rs = min(rs, cnt);
    }

    pril(rs);
    
    return 0;
}


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

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

  int a, b, c;
  cin >> a >> b >> c;

  if ((a == b && b != c) || (a == c && b != a) || (b == c && a != b)) cout << "Yes\n";
  else cout << "No\n";

  return (0);
}


Measured memory_bytes: 3612
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());
function main(chunk){
    var arr = eval("["+chunk.replace(/\n/g,',')+"]");
    for(var i=1;i<=30;i++){
        if(arr.indexOf(i) == -1){
            console.log(i);
        }
    }
}

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

template <typename T>
vector<T> PrimeFactorization(T x){
    vector<T> res;
    T v = 2;
    while( v * v <= x){
        if(x%v != 0){
            v++;
        }else{
            res.push_back(v);
            x /= v;
        }
    }
    if(x!=1) res.push_back(x);
    sort(res.begin(), res.end());
    return res;
}

unordered_map<int, int> vec_to_map(vector<int> a){
    unordered_map<int, int> res;
    for(auto v : a){
        if(res.count(v)==0) res[v] = 1;
        res[v] *= v;
    }
    return res;
}

int main()
{
    int N;
    cin >> N;
    vector<unordered_map<int, int>> A(N);
    unordered_map<int, int> primes;
    int Ai;
    for(int i=0;i<N;i++){
        cin >> Ai;
        A[i] = vec_to_map(PrimeFactorization(Ai));
        auto& ret = A[i];
        for(auto m : ret){
            auto v = m.first;
            if(primes.count(v)==0) primes[v] = 1;
            primes[v] = max(primes[v], ret[v]);
        }
    }
    long long res=0;
    for(int i=0;i<N;i++){
        auto& ret = A[i];
        long long Bi = 1;
        for(auto& m : primes){
            auto v = m.first;
            int tmp = m.second;
            if(ret.count(v) > 0){
                tmp /= ret[v];
            }
            Bi *= tmp;
            Bi %= 1000000007;
        }
        res += Bi;
        res %= 1000000007;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<string>
#include<queue>
#define INF 1000000
using namespace std;
int a[INF];
set<int> q;
int f(int x)
{
	int t,r;
	t = x % 10;x /= 10;
	while(x)
	{
		r = x % 10;x /= 10;
		if(t != r + 1) return 0;
		t = r;
	}
	return 1;
}
int main()
{
	int n,i,j;
	cin >> n;
	for(i = 0;i < n;i++) cin >> a[i];
	for(i = 0;i < n - 1;i++)
	{
		for(j = i + 1;j < n;j++)
		{
			int x = a[i] * a[j];
			if(f(x)) q.insert(x);
		}
	}
	if(q.size())
	{
	  set<int>::iterator it = q.end();it--;
	  cout << *it << endl;
  }
  else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
	IOS;
	int a, b, c;
	cin >> a >> b >> c;
	put(c, a, b);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vi;

signed main()
{
    int n;
    cin >> n;
    vi arr(n);
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr.begin(), arr.end(), greater<int>());
    int ans = arr[0];
    int k = 0;
    for (int i = 2; i < n; i++)
    {
        if ((i & 1) == 0)
            k++;
        ans += arr[k];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4812
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 2147483647//int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    int r,c;
    cin >> r >> c;
    vector< vector<int>> table(r,vector<int>(c,0));
    rep(i,r){
        int sum = 0;
        rep(j,c){
            cin >> table.at(i).at(j);
            sum += table.at(i).at(j);
        }
        table.at(i).push_back(sum);
    }
    rep(i,r){
        rep(j,c+1){
            if(j == c)cout << table.at(i).at(j);
            else cout << table.at(i).at(j) << " ";
        }
        cout <<"\n";
    }
    vector<int> last(r+1,0);
    rep(i,c+1){
        int sum = 0;
        rep(j,r){
            sum += table.at(j).at(i);
        }
        if(i != c)cout << sum << " ";
        else cout << sum;
    }
    cout << "\n";
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


Measured memory_bytes: 3196
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>

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

std::vector<std::vector<int>> Edge;
std::vector<int> Dist[2];
std::vector<bool> yet;

int main(void){
    int n; scanf("%d", &n);
    Edge.resize(n);
    FOR(_, 1, n){
        int a, b; scanf("%d%d", &a, &b); a--; b--;
        Edge[a].push_back(b);
        Edge[b].push_back(a);
    }
    yet.resize(n);
    REP(p, 2){
        std::fill(yet.begin(), yet.end(), true);
        Dist[p].resize(n);
        int s = (p == 0 ? 0 : n - 1);
        std::queue<int> Q;
        Q.push(s); Dist[p][s] = 0; yet[s] = false;
        while(not Q.empty()){
            int v = Q.front(); Q.pop();
            for(int nv : Edge[v]) if(yet[nv]){
                yet[nv] = false;
                Dist[p][nv] = Dist[p][v] + 1;
                Q.push(nv);
            }
        }
    }
    int a = 0, b = 0;
    REP(i, n){
        if(Dist[0][i] <= Dist[1][i]) a++;
        else b++;
    }
    puts(a > b ? "Fennec" : "Snuke");
  
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	if (s=="ABC") cout<<"ARC";
	else  cout<<"ABC";
	return 0;
}

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

using namespace std;

int main()
{
	string c;
	cin >> c;
	if (c == "a" || c == "e" || c == "i" || c == "o" || c == "u")
		cout << "vowel" << endl;
	else
		cout << "consonant" << endl;

	return 0;
}


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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define outl(x) cout << x << '\n';

#define INF (1 << 29)

#define FAST cin.tie(0), ios::sync_with_stdio(false)
inline int chmax(int &a, int b){return b>a ? a=b,1 : 0;}
inline int chmin(int &a, int b){return b<a ? a=b,1 : 0;}
//________

main(){
  FAST;
  int n,l,r;
  int sum=0;
  cin >> n;
  rep(i,n){
    cin >> l >> r;
    sum += 1+r-l;
  }
  outl(sum);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main() {
	string n;
	cin >> n;
	for (int i = 0; i < n.length(); i++) {
		if (n[i] == '1') {
			cout << "9";
		}
		else {
			cout << "1";
		}
	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate


N, C, *xv = map(int, open(0).read().split())
xv = [(x, v) for x, v in zip(*[iter(xv)] * 2)]

cw_acc = [0] * (N + 1)
ccw_acc = [0] * (N + 1)
cw_prev = 0
ccw_prev = C
for i in range(N):
    k = N - i - 1
    cw_acc[i + 1] = cw_acc[i] + xv[i][1] - (xv[i][0] - cw_prev)
    cw_prev = xv[i][0]
    ccw_acc[i + 1] = ccw_acc[i] + xv[k][1] - (ccw_prev - xv[k][0])
    ccw_prev = xv[k][0]

cw_acc = list(accumulate(cw_acc, max))
ccw_acc = list(accumulate(ccw_acc, max))
ans = 0
for i in range(N):
    k = N - i - 1
    ans = max(
        ans,
        cw_acc[i + 1],
        cw_acc[i + 1] - xv[i][0] + ccw_acc[k],
        ccw_acc[i + 1],
        ccw_acc[i + 1] - (C - xv[k][0]) + cw_acc[k],
    )
print(ans)


Measured memory_bytes: 33888
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############
"""
N = rand_N(2, 6)
query = rand_query(2, 10, N)
print(query)
ans_taka, ans_aoki = query[0]
"""

N = getN()
query =  [getList() for i in range(N)]
# 一回目の選挙速報の結果を受けて
ans_taka, ans_aoki = query[0]

# 現在の高橋くん、青木くんの票数、選挙速報の結果の比を基に
# 次の高橋くん、青木くんの票数の最小値が出てくる
def vote(taka, aoki, ratio):
    ratio_taka, ratio_aoki = ratio
    taka_multi = (taka + ratio_taka - 1) // ratio_taka
    aoki_multi = (aoki + ratio_aoki - 1) // ratio_aoki
    multi = max(taka_multi, aoki_multi)

    return [ratio_taka * multi, ratio_aoki * multi]

# 選挙速報２回目〜
for i in range(1, N):
    ans_taka, ans_aoki = vote(ans_taka, ans_aoki, query[i])
    # print(ans_taka, ans_aoki)
print(ans_taka + ans_aoki)

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

namespace PaizaTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToList();
            var spendHomework = 0;
            //for (int i = 0; i < NM[1]; i++)
            //{
            //    spendHomework += int.Parse(Console.ReadLine());
            //}
            spendHomework = Console.ReadLine().Split().Select(int.Parse).Sum();

            var result = -1;
            if(spendHomework <= NM[0])
            {
                result = NM[0] - spendHomework;
            }

            Console.WriteLine(result);

#if DEBUG
            Console.ReadLine();
#endif
        }
    }
}


Measured memory_bytes: 29040
#include <stdio.h>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

ll a, b, d, r;
int main() {
	scanf("%lld %lld.%lld", &a, &b, &d);
	r = a * (b * 100 + d) / 100;
	printf("%lld\n", r);
}

Measured memory_bytes: 1732
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<math.h>

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

using namespace std;
int p;
bool isPrime[300003];

bool isMSPrime(int n) {
	if(!(n%7==1 || n%7==6)) return false;

	for(int i=2;i*i<=n;i++) {
		if(!(i%7==1 || i%7==6)) continue;
		if(n%i==0) return false;
	}
	return true;
}
void init() {
	fill(isPrime,isPrime+300003,true);
	/*
	isPrime[0]=isPrime[1]=false;
	for(int i=2;i<300003;i++) {
		if(isPrime[i]) for(int j=i+i;j<300003;j+=i) isPrime[j]=false;
	}
	*/
	rep(i,300003) isPrime[i]=isMSPrime(i);
}


void solve() {
	printf("%d:",p);
	bool flag[300003];
	fill(flag,flag+300003,false);

	for (int i = 2; i < 300003; i++)
	{
		if(!isPrime[i]) continue;
		if (p%i==0)
		{
			flag[i]=true;
		}
	}

	rep(i,300003) if(flag[i]) printf(" %d",i);
	puts("");

}

int main() {
	init();
	while (cin>>p)
	{
		if(p==1) return 0;
		solve();
	}



	return 0;
}

Measured memory_bytes: 1732
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	k = readline() |> parseInt
	x = 7
	f = 0
	for i in 1:k
		if x%k==0
			println(i)
			f = 1
			break
		end
		x = (x*10%k+7%k)%k
	end
	if f == 0
		println(-1)
	end
end

main()

Measured memory_bytes: 158252
import java.util.* ;		
class Main {
	public static void main(String[] args) {
	Scanner in = new Scanner(System.in);		
	int a = in.nextInt();
	int b = in.nextInt();
	int c = in.nextInt();
		if (a == b) {
			System.out.println(c);
		}else if (b == c) {
			System.out.println(a);
		}else{
			System.out.println(b);
		}
	}
}

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

int main(){
    int64_t n,d,a ;
    cin >> n >> d >> a ;
    vector<pair<int,int> > m(n,pair<int,int>()) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> m.at(i).first >> m.at(i).second ;
    }
    int64_t range = 2*d ;
    int64_t ans = 0 ;
    sort(m.begin(),m.end()) ;
    queue<pair<int,int> > x ;
    int now = 0 ;
    int64_t next = 0 ;
    for (size_t i = 0; i < n; i++)
    {
        while (1)
        {
            if (x.empty() == 1)
            {
                break ;
            }
            if (x.front().first < m.at(i).first)
            {
                now -= x.front().second ;
                x.pop() ;
            }else
            {
                break ;
            }
            
            
        }
        if (now * a >= m.at(i).second)
        {
            m.at(i).second = 0 ;
            continue ;
        }else
        {
            m.at(i).second -= now * a ;
        }
        
        next = m.at(i).second / a ;
        if (m.at(i).second % a != 0)
        {
            next += 1 ;
        }
        ans += next ;
        now += next ;
        pair<int,int> p = make_pair(m.at(i).first + range ,next) ;
        x.push(p) ;
    }
    cout << ans << endl ;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define int long long
using namespace std;

#define ull unsigned long long

int length(ull n)
{
    int cnt = 0;
    while(n)
    {
        cnt++;
        n>>=1;
    }
    return cnt;
}

int mxor(vector<int>& a) {
    int n = a.size();

    int lengths[n]; 
    for(int i=0; i<n; i++)
        lengths[i] = length(a[i]);
    
    vector<ull> buckets[65];
    for(int i=0; i<n; i++)
        buckets[lengths[i]].push_back(a[i]);

    ull modified_array[100], m_index = 0;

    for(int i=64; i>0; i--) {
        if(buckets[i].size())
        {
            // put first value from bucket in modified_array[]
            modified_array[m_index++]=buckets[i][0];

            // and put remaining elements from same bucket again in corresponding 
            // buckets after ex-oring 
            for(int j=1; j<buckets[i].size(); j++)
            {
                ull temp = buckets[i][0] ^ buckets[i][j];
                int len = length(temp);
                buckets[len].push_back(temp);
            }
        }
    }

    // Step 4 according to the explained procedure
    // make ans = k for codechef and ans = 0 for spoj :)
    ull ans = 0;
    for(int i=0; i<m_index; i++) 
        if(ans < (ans ^ modified_array[i]))
            ans = (ans ^ modified_array[i]);

    // Step 5 according to the explained procedure
    return ans;
}

int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), cnt(64, 0);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        for(int j = 0; j <= 60; ++j) {
            cnt[j] += ((1LL << j) & a[i]) > 0;
        }
    }
    int odd_part = 0;
    for(int j = 0; j <= 60; ++j) {
        if(cnt[j] & 1) odd_part += 1LL << j;
    }
    for(int i = 0; i < n; ++i) {
        a[i] = a[i] & (~odd_part);
    }
    cout << 2 * mxor(a) + odd_part << '\n';
}


Measured memory_bytes: 29868
"use strict";
const input = require("fs").readFileSync("/dev/stdin", "utf8");
let ans = 0;
const jadgeArr = new Array(input.length);
let temp = 0;

// 一度配列に変換
for(let i = 0; i < input.length; i++){
  	// 該当文字なら1を入れる、それ以外なら0
	if(input.charAt(i) == "A" || input.charAt(i) == "C" || input.charAt(i) == "G" || input.charAt(i) == "T" ){
      jadgeArr[i] = 1;
    }else {
      jadgeArr[i] = 0;
    }
}

// そのあとに最長を調べる
jadgeArr.forEach(
	x => {
    	if(x == 1){
        	temp++;
        }else {
        	if(temp >= ans){
            	ans = temp;
            }
          	temp = 0;
        }
    }
)

console.log(ans)

Measured memory_bytes: 7624
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = 1e6+5;
int n;
int pre[maxn];
int main() {
    cin>>n;
    for(int i=0;i<(1<<n);i++){
        scanf("%d",&pre[i]);
	}
	int ans=0;
	for(int i=1;i<(1<<n);i++){
    	int s1=pre[0],s2=0;
    	for(int j=i;j!=0;j=(j-1)&i){
    	    if (pre[j]>s1) {
				s2=s1;
				s1=pre[j];
			}
    	    else if(pre[j]>s2) s2=pre[j]; 
    	}
    	ans=max(ans,s1+s2);
    	printf("%d\n", ans);
    } 
    return 0;
}


Measured memory_bytes: 4096
N, K = map(int, input().split())
candle = [int(x) for x in input().split()]

time = 10 ** 10
for i in range(N - K + 1):
    if candle[i] < 0 and candle[i + K-1] > 0:
        if abs(candle[i]) < candle[i + K-1]:
            kouho = 2 * abs(candle[i]) + candle[i + K-1]
        else:
            kouho = abs(candle[i]) + 2 * candle[i + K-1]
    else:
        kouho = max(abs(candle[i]), abs(candle[i + K-1]))

    if kouho < time:
        time = kouho
print(time)


Measured memory_bytes: 14224
import * as fs from 'fs';

class UnionFind {
  list: number[];
  sizeList: number[];
  constructor(N: number) {
    this.list = new Array(N).fill(-1);
    this.sizeList = new Array(N).fill(1);
  }

  root(i: number): number {
    if (this.list[i] === -1) {
      return i;
    }
    return this.root(this.list[i]);
  }

  unite(i: number, j: number): boolean {
    let rootI = this.root(i);
    let rootJ = this.root(j);
    if (rootI === rootJ) {
      return false;
    }
    if (rootI > rootJ) {
      let tmp = rootI;
      rootI = rootJ;
      rootJ = tmp;
    }
    this.sizeList[rootI] += this.sizeList[rootJ];
    this.list[rootJ] = rootI;
    return true;
  }

  size(i: number): number {
    return this.sizeList[this.root(i)];
  }
}

function main(input): void {
  input = input.split('\n');
  const [N, M] = input[0].split(' ').map(i => parseInt(i));
  let ABList = input.splice(1).map(l => l.split(' ').map(i => parseInt(i))).splice(0, M);

  const u = new UnionFind(N);
  for (let idx in ABList) {
    u.unite(ABList[idx][0] - 1, ABList[idx][1] - 1);
  }

  let ans = u.sizeList.reduce((prev, current) => prev > current ? prev : current);
  console.log('%s', ans);
}

main(fs.readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 103712
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(int i=k;i<=n;i++)
    {   
        ll mn=(ll)(i*(ll)(i-1))/2;

        double mx=((double(i/double(2.0)))*((2*(n-i+1)+(i-1))));
         ll mxx=mx;
        //cerr<<mxx<<" "<<mn<<endl;
        ans=((ans%mod+(mxx%mod-mn%mod+mod)%mod)%mod + 1);
        //cout<<ans<<endl;
    }
    cout<<(ans%mod+1%mod)%mod<<endl;
    
}
return 0;
}

Measured memory_bytes: 3660
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a := nextInts(n)

	ans := 0
	sum := 0
	for l, r := 0, 0; l < n; l++ {
		for r < n && (sum^a[r] == sum+a[r]) {
			sum += a[r]
			r++
		}
		ans += r - l
		if r == l {
			r++
		} else {
			sum -= a[l]
		}
	}

	puts(ans)
}


Measured memory_bytes: 3968
<?php


$N = trim(fgets(STDIN));



$begin = trim(fgets(STDIN));

$end = trim(fgets(STDIN));
$work = $begin . $end;





for ($i = $N; $i > 0; $i--)
{

	
	$cad1 = substr($work, $N -$i,$i);
	$cad2 = substr($work,$N,$i);
	

	
	if($cad1 == $cad2)
	{
		$count =1 ;
		$result = str_replace($cad1.$cad2, $cad1, $work);

		echo strlen($result) . "\n";
		die();
	}
	
	
}


echo strlen($work) ."\n";
die();

Measured memory_bytes: 3700
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
S=sum(b)-sum(a)
if S<0:print("No")
else:
    cnt=0
    for i in range(n):
        cnt+=max((b[i]-a[i]+1)//2,0)
    if cnt<=S:print('Yes')
    else:print("No")

Measured memory_bytes: 4596