akhauriyash/Code-Regression huggingface dataset:
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;

#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

ll rec(ll X) {
    if (X == 1) return 1;
    else return 2 * rec(X / 2) + 1;
}

int main() {
    ll h;
    cin >> h;
    cout << rec(h) << endl;
    return 0;
}


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

int main() {
 string A;
 string B;
 string C;
 
 
 cin >>A ;
 cin >>B;
 cin>>C;
 char b = B[0];
 char c = C[0];
 char d= A.back();
 char e =B.back();
 if((b ==  d) &&( e == c)){
 	cout<< "YES"<<endl;
 }
 else{
 	cout<<"NO"<<endl;
 }
 	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void print(int*,int);
void Insertion_Sort(int*,int);

int main(){
  int N,a[100],i,j,key;
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&a[i]);
  }
  print(a,N);
  for(i = 1 ; i < N ; i++){
    key = a[i];
    j = i-1;
    while(j >= 0 && a[j] > key){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = key;
    print(a,N);
  }
  return 0;
}

void print(int *a,int N){
  int i;
  for(i = 0 ; i < N ; i++){
    printf("%d%c",a[i],i < N-1 ? ' ' : '\n');
  }
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if(U == S){
   A--; 
  }
  else{
   B--; 
  }
  cout << A << " " << B << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    int s, outH, outM, outS;

    scanf("%d",&s);
    if(s < 0 || 86400 < s){
        printf("Input error\n");
    }

    outH = s / 3600;
    s = s - (outH * 3600);
    outM = s / 60 ;
    s = s - (outM * 60);
    outS = s;

    printf("%d:%d:%d\n",outH,outM,outS);

    return 0;

}

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

int main(){ 
  int n;
  cin >> n;
  vector<ll> a(n + 1);
  rep(i,n + 1) cin >> a[i];
  if (n == 0) {
    if (a[0] == 1) {
      cout << 1 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  if (a[0] != 0) {
    cout << -1 << endl;
    return 0;
  }

  vector<ll> cum(n + 2, 0);
  for (int i = n; i >= 0; i--) cum[i] = cum[i + 1] + a[i];

  ll node = 1;
  ll res = 1;

  for (int i = 0; i < n; i++) {
    if (node * 2 < a[i + 1]) {
      cout << -1 << endl;
      return 0;
    }
    
    node = min(node * 2, cum[i + 1]);
    res += node;
    node -= a[i + 1];
  }
 
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
		  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
return (a % b + b) % b; }

int main()
{
    int k;
    cin >> k;
    string s;
    cin >> s;
    if (k >= (int)s.size()) cout << s << endl;
    else cout << s.substr(0, k) << "..." << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int n,a[444444],ans[444444];
pair<int,int> mx[444444];
void upd(int i,int x)
{
	if (x>mx[i].first)
	{
		mx[i].second=mx[i].first;
		mx[i].first=x;
	}
	else if (x>mx[i].second) mx[i].second=x;
}
int main()
{
	scanf("%d",&n);
	for (int i=0;i<(1<<n);i++) scanf("%d",&a[i]);
	for (int i=0;i<(1<<n);i++)
	{
		for (int j=i;j;j=(j-1)&i)
		{
			upd(i,a[j]);
		}
		upd(i,a[0]); 
	}
	for (int i=0;i<(1<<n);i++) ans[i]=mx[i].first+mx[i].second;
	for (int i=1;i<(1<<n);i++) ans[i]=max(ans[i-1],ans[i]);
	for (int i=1;i<(1<<n);i++) printf("%d\n",ans[i]);
	return 0;
}

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

int main()
{
  int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
  int n;
  
  cin >> n;
  cout << a[n-1];
  
  return 0;
}

Measured memory_bytes: 256
import math

K, N = map(int, input().split())
A = list(map(int, input().split()))

max_dist = None

for i in range(N-1):
    dist = A[i+1] - A[i]
    if max_dist is None or max_dist < dist:
        max_dist = dist

dist = A[0] + K - A[N-1]
if max_dist < dist:
    max_dist = dist

print(K - max_dist)

Measured memory_bytes: 26444
h, n = map(int, input().split())
A, B = zip(*[tuple(map(int, input().split()))for _ in range(n)])
INF = 10**18
dp = [INF]*(h+1)
dp[0] = 0
for j in range(h):
    for i in range(n):
        if h < j+A[i]:
            dp[-1] = min(dp[-1], dp[j]+B[i])
        else:
            dp[j+A[i]] = min(dp[j+A[i]], dp[j]+B[i])
print(dp[-1])


Measured memory_bytes: 41964
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

//素因数分解
vector<pair<ll,int>> factorize(ll n) {
    vector<pair<ll,int>> res;
    ll N = n;
    for (ll i = 2; i * i <= N; i++) {
        if (n % i != 0) continue;
        res.emplace_back(i,0);
        while (n % i == 0) {
            n /= i;
            res.back().second++;
        } 
    }
    if (n != 1) res.emplace_back(n,1);
    return res;
}

int main() {
    ll n; cin >> n;
    auto p = factorize(n);
    int ans = 0;
    for (auto x : p) {
        int a = x.second;
        int n = 1;
        while (n <= a) {
            a -= n;
            ans++; n++;
        }
    }
    cout << ans << endl;
}

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

int main()
{
    char s[103];
    int i;
    scanf("%s",s);
    int len=strlen(s);
    for(i=0; i<len; i++)
    {
        s[i]='x';
    }
    printf("%s\n",s);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define N 100
#define INF 10000000

void MatrixChainOrder(int );
int min(int, int);

int p[N];
int m[N][N];


main(){

  int n,i,j,k,r,c;

  scanf("%d",&n);


  for(i=1; i<=n; i++){   

    scanf("%d %d",&c,&p[i]);
    if(i==1)
      p[0]=c;
    }

  MatricChainOrder(n);


  printf("%d\n",m[1][n]);

  return 0;
}

void MatricChainOrder(int n) {

  int i,j,l,k,q;

  for(i=1; i<=n; i++)
    m[i][i]=0;

  for(l=2; l<=n; l++){

    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      m[i][j]=INF;

      for(k=i; k<=j-1; k++){

	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];

	m[i][j]=min(m[i][j],q);
      }
    }
  }
}



int min(int m,int q){
  if(m<q)
    return m;
  else 
    return q;
}

Measured memory_bytes: 636
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

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

int main(void){
  int n,x,i,ans=0;
  scanf("%d %d",&n,&x);
  int a[n];
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  ans=abs(x-a[0]);
  for(i=1;i<n;i++) ans=gcd(abs(x-a[i]),ans);
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 512
n, q = map(int, input().split())
tree = [[] for i in range(n)]
l = [0]*n

for i in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    tree[a].append(b)
    tree[b].append(a)

for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    l[p] += x

q = [0]
s = [-1]*n
s[0] = l[0]
while len(q) > 0:
    r = q.pop()
    for i in tree[r]:
        if s[i] == -1:
            s[i] = s[r] + l[i]
            q.append(i)
print(*s)

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

typedef long long ll;

int main(){
int a,b;
cin>>a>>b;
if(a<=8&&b<=8)cout<<"Yay!"<<endl;
else cout<<":("<< endl;
return 0;
}


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

int main() {
    int n;
    int k;
    int a[n];
    cin>>n>>k;
    for (int i =0;i<n;i++){
      cin >> a[i];
    }
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++){
        if(k<a[i]){
            break;
        }
        if(k>=a[i]){
            k-=a[i];
            ans++;
        }
        if(i==n-1&k!=0){
            ans--;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
macro_rules! input {
     (source = $s:expr, $($r:tt)*) => {
         let mut iter = $s.split_whitespace();
         input_inner!{iter, $($r)*}
     };
     ($($r:tt)*) => {
         let s = {
             use std::io::Read;
         let mut s = String::new();
         std::io::stdin().read_to_string(&mut s).unwrap();
         s
     };
     let mut iter = s.split_whitespace();
     input_inner!{iter, $($r)*}
     };
}
     
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};

//#[proconio::fastout]
fn main() {
    input!{
        n: i64,
    }
    let mut order = 0;
    for i in 1.. {
        if 10i64.pow(i) > n {
        order = i - 1;
        break;
        }
    }
    if order == 0 { println!("{}", n); }
    else {
        for i in 0..10 {
            if (10 - i) * 10i64.pow(order) - 1 <= n {
                println!("{}", 9 * (order + 1) - i as u32);
                break;
            }
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int cnt4 = 0, cnt2 = 0, cnt1 = 0;
  REP(i, N){
    int tmp; cin >> tmp;
    if(tmp%4 == 0){
      cnt4++;
    }else if(tmp%2 == 0){
      cnt2++;
    }else{
      cnt1++;
    }
  }
  if(cnt2 != 0) cnt1++;
  if(cnt4 >= cnt1-1 && cnt4 != 0 || cnt2 == N){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  (B) <= (A) && (A) <= (C)
#define AIN(A, B, C) assert(IN(A, B, C))
void solve(){
       int s,w;
       cin>>s>>w;
       if(w>=s)cout<<"unsafe";
       else cout<<"safe";
}
int main() {
    ios;
	int t=1;
	//cin>>t;
	while(t--)solve();    
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
ll n,temp,sum=0,r=0;
cin>>n;
temp=n;
while(temp!=0)
{
    r=temp%10;
    sum+=r;
    temp=temp/10;
}
if(n%sum==0) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;
}



Measured memory_bytes: 3624
import java.util.Scanner;


public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int ans = 0;
			int min = 1000, max = 0;
			for(int i = 0; i < n; ++i) {
				int s = sc.nextInt();
				ans += s;
				min = Math.min(min, s);
				max = Math.max(max, s);
			}
			ans -= min;
			ans -= max;
			ans /= n - 2;
			System.out.println(ans);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 21068
def main():
    S = input()
    n = len(S)-1

    val_sum = 0
    for i in range(2**n):
        idx = 0
        for j in range(n):
            if 1 & (i >> j) == 1:
                val_sum += int(S[idx:j+1])
                idx = j+1
        val_sum += int(S[idx:])

    print(val_sum)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

LL num[60];
LL p[60];

LL f(LL N, LL X) {
	if (N == 0) {
		
		if (X == 1) {
			return 1;
		}
		else {
			return 0;
		}
		
	}

	if (X == 1) {
		return 0;
	}
	else if (X <= num[N - 1] + 1) {
		return f(N - 1, X - 1);
	}
	else if (X == num[N - 1] + 2) {
		return p[N - 1] + 1;
	}
	else if (X <= num[N - 1] * 2 + 2) {
		return f(N - 1, X - (num[N - 1] + 2)) + p[N - 1] + 1;
	}
	else {
		return p[N - 1] * 2 + 1;
	}

}

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

	p[0] = 1;
	num[0] = 1;

	for (int i = 1; i <60; i++) {
		p[i] = p[i - 1]*2+1;
		num[i] = num[i - 1]*2+3;
	}

	cout << f(n, x) << endl;

	return 0;
}

Measured memory_bytes: 256
using System;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = double.Parse(Console.ReadLine());
            var x = l / 3;
            var y = l - x - x;
            var z = l - x - x;

            Console.WriteLine(string.Format("{0:f12}",x * y * z));

        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int x;
	cin>>x;
	int a=x/500;
	int b=(x%500)/5;
	cout<<a*1000+b*5<<endl;
	return 0;
}

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

int main() {
  int h,w; cin >> h >> w;
  string ans;
  vector <string> nai(h*w);
  
  for(int i=0;i<h*w;i++){
  	cin >> nai.at(i);
  }
  
  for(int i=0;i<w+2;i++){
  	ans = ans + "#";
  }
cout << ans << endl;
  
  for(int i=0;i<h;i++){
  	cout << "#" << nai.at(i) << "#" << endl;
  }

cout << ans << endl;
}
  

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

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

signed main()
{
    string s; cin >> s;
    string ans = "";

    rep(i,s.size()){
        if (s[i] == '0') ans += "0";
        if (s[i] == '1') ans += "1";
        if (s[i] == 'B'){
            if (ans.size()) ans.erase(ans.size() - 1);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int is_prime[33000];int primes[3600],last=0;
int main() {
    int i,j;for (i=0;i<33000;is_prime[i++]=1);
    for (i=2;i*i<33000;i++) if (is_prime[i]) for (j=i*i;j<33000;is_prime[j]=0,j+=i);
    for (i=2;i<=(1<<15);i++) if (is_prime[i]) primes[last++]=i;
    for (i=0;i<33000;is_prime[i++]=0);
    for (i=0;i<last;i++) for (j=i;j<last && primes[i]+primes[j]<=(1<<15);is_prime[primes[i]+primes[j]]++,j++);
    while (scanf("%d",&i)!=EOF && i) printf("%d\n",is_prime[i]);
    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#define int long long
#define REP(i,n) for(int i=0; i<n; i++)
using namespace std;
signed main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int ans = 0;
    int min = 1e9;
    int n;
    cin >> n;
    REP(i,n) {
        int a;
        cin >> a;
        if (a <= min) {
            ans++;
            min = a;
        }
    }
    cout << ans << "\n";
    return 0;
}

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

#define _rep4(i,p,n,m) for(int i=(p),_i##_end=(n),_i##_inc=(m);i<_i##_end;i+=_i##_inc)
#define _rep3(i,p,n,_a) _rep4(i,p,n,1)
#define _rep2(i,n,_a,_b) _rep4(i,0,n,1)
#define _rep_call(a,b,c,d,name,...) name(a,b,c,d)
#define rep(...) _rep_call(__VA_ARGS__,_rep4,_rep3,_rep2)

int work(std::istream &in) {
    int A, B, C, X, Y;
    in >> A >> B >> C >> X >> Y;

    int m = INT_MAX;
    rep(k, std::max(X, Y) + 1) {
        int i = std::max(0, X - k);
        int j = std::max(0, Y - k);
        int cost = i * A + j * B + 2 * k * C;
        m = std::min(m, cost);
    }
    return m;
}

struct testdata {
    const char *input;
    int expected;
};

int test() {
    int ret = 0;

    struct testdata testset[] {
        {"1500 2000 1600 3 2", 7900},
        {"1500 2000 1900 3 2", 8500},
        {"1500 2000 500 90000 100000", 100000000},
    };

    const int TESTLEN = sizeof(testset) / sizeof(testset[0]);
    for (int i = 0; i < TESTLEN; ++i) {
        std::stringstream sin(testset[i].input);
        int actual = work(sin);
        if (actual != testset[i].expected) {
            fprintf(stderr, "ERROR: expected: %d, but actual %d\n", testset[i].expected, actual);
            ret = 1;
        }
    }

    return ret;
}

int main(int argc, char *argv[]) {
    std::cin.tie(nullptr);

    if (argc == 2 && strcmp("--test", argv[1]) == 0) {
        exit(test());
    }
    printf("%d\n", work(std::cin));
}


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

int main() {
	int k, a, b;
  	cin >> k;
  	cin >> a;
  	cin >> b;
  
  	if (a - b >= k) {
    	cout << "OK";
      	return 0;
    }
  	
  	for (int i = a; i <= b; i++)
      if (i % k == 0) {
      	cout << "OK";
        return 0;
      }
  
  	cout << "NG";
  	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


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

    vector<ll> v(N+1, 0);
    rep(i, N) v[i+1] = v[i] + A[i];
    map<ll, ll> nums;
    rep(i, N+1) nums[v[i]]++;

    ll res = 0;
    for (auto& itr : nums) {
        ll num = itr.second;
        res += num * (num - 1) / 2;
    }

    print(res);
}

Measured memory_bytes: 15872
#include <stdio.h>
int main() {
	int x, a, b;
	scanf("%d%d%d", &x, &a, &b);
	if (b <= a) {
		printf("delicious\n");
	} else if (b <= a + x) {
		printf("safe\n");
	} else {
		printf("dangerous\n");
	}
	return 0;
}

Measured memory_bytes: 128
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k>a+b)cout<<a-(k-a-b);else
	if(k<=a)cout<<k;else 
	cout<<a;
	return 0;
}

Measured memory_bytes: 3652
n = gets.to_i
h = gets.split.map(&:to_i)
cont = 0
ans = 0
(1...n).to_a.each{|i|
  if h[i]<=h[i-1]
    cont+=1
    ans = cont>ans ? cont : ans
  else
    cont=0
  end
}
p ans


Measured memory_bytes: 9476
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    int out=0;
    for(int i=1;i<=N;i++){
        if(1<=i && i<=9) out++;
        if(100<=i && i<= 999) out++;
        if(10000<=i && i<=99999) out++;
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#include <unistd.h>
#include <stdio.h>
#define all(a) (a).begin(),(a).end()
#define vecin(a) rep(i,a.size())cin >> a[i]
#define vecout(a) rep(i,a.size()){cout << a[i];cout << (i == a.size() - 1 ? "\n":" ");}
#define rep(i,x) for(int i = 0;i<x;i++)
#define REP(i,x) for(ll i = 1;i<=x;i++)
#define mp make_pair
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const dou pi = 3.14159265358;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
template<class T> inline bool change(T a,T b){if(a > b){swap(a,b);return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a / gcd(a,b) * b;
}

//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
const ll cmax = 1000000;
ll fac[cmax], finv[cmax], inv[cmax];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < cmax; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logm)
ll modpow(ll n,ll m,ll MOD){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}
ll mypow(ll n,ll m){
    if(m == 0)return 1;
    if(m < 0)return -1;
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n);
        m >>= 1;
        n *= n;
    }
    return res;
}

ll num(ll n){//10^n~10^1
    ll res = 0;
    rep(i,n){
        res += mypow(10,i);
    }
    return res;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    vector<string> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    ll naka = 0,A = 0,B = 0,both = 0;
    rep(i,N){
        ll s = vec[i].size();
        if(vec[i][0] == 'B' && vec[i][s - 1] == 'A')both++;
        else if(vec[i][0] == 'B')B++;
        else if(vec[i][s - 1] == 'A')A++;
        rep(j,s - 1){
            if(vec[i][j] == 'A' && vec[i][j + 1] == 'B'){
                j++;
                naka++;
            }
        }
    }
    ll ans = naka;
    if(A == 0 && B == 0){
        ans += (both ? both - 1:0);
    }
    else{
        ans += both + min(A,B);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3744
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 puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func factor(n int) map[int]bool {
	m := map[int]bool{}
	if n > 1 {
		m[n] = true
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			m[i], m[n/i] = true, true
		}
	}
	return m
}

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

	n := nextInt()

	fac1, fac2 := factor(n), factor(n-1)

	ans := len(fac2)
	for k := range fac1 {
		x := n
		for x%k == 0 {
			x /= k
		}
		if x%k == 1 {
			ans++
		}
	}

	puts(ans)
}


Measured memory_bytes: 2076
while True:
    [h, w] = map(int, (input().split()))
    if h==0 and w==0:
        break
    
    print(("#."*(w//2)+"#"*(w%2)+"\n"+".#"*(w//2)+"."*(w%2)+"\n")*(h//2)
            +("#."*(w//2)+"#"*(w%2)+"\n")*(h%2))
        

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n;
    cin >> n;
    vector<int> A(n), B(n);
    FOR(i, n) cin >> A[i] >> B[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    if (n%2 == 0){
        cout << (ll)B[n/2] + B[n/2-1] - A[n/2] - A[n/2-1] + 1 << endl;
    }
    else{
        cout << (ll)B[n/2] - A[n/2] + 1 << endl;
    }


    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

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


using namespace std;

int main(){

	int N;
	cin>>N;
	vector<int> m;
	
	for(int i=0;i<N;i++){
		int h;
		cin>>h;
		m.push_back(h);
	}
	
	int count=1;
	
	for(int i=1;i<m.size();i++){
		bool ind=false;
		for(int j=i-1;j>=0;j--){
			if(m[j]>m[i]){
				ind=true;
				break;
			}
			
		}
		if(ind){
			continue;
		}
		else{
			count=count+1;
		}
		
	}
	
	cout<<count<<endl;
	
		
	


	return 0;
}




Measured memory_bytes: 256
#include <iostream>
using namespace::std;
using ll = long long;
 
int main(void) {
    int n; int count = 0;
    ll d, x, y;
    
    cin >> n >> d;
    
    for (int i = 0; i < n; i++) {
        cin >> x >> y;  // x and y will be discarded after calculated
        if ((x*x + y*y) <= d*d) {
            count++;
        }
    }
        
    cout << count << endl;
}


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

int main() {
  string s,t;
  cin >> s >> t;
  int q;
  cin >> q;
  vector<int> sa(s.length()+1),ta(t.length()+1);
  sa[0]=0;
  ta[0]=0;
  rep(i,s.length()){
    if(s[i]=='A') sa[i+1]=sa[i]+1;
    else sa[i+1]=sa[i];
  }
  rep(i,t.length()){
    if(t[i]=='A') ta[i+1]=ta[i]+1;
    else ta[i+1]=ta[i];
  }
  rep(i,q){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int x=sa[b]-sa[a-1];
    int y=ta[d]-ta[c-1];
    if(((x+(b-a-x+1)*2)-(y+(d-c-y+1)*2))%3==0){
      cout << "YES" << endl;
      
    }
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 1664
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int n, k; cin>>n>>k;
    vector<int> h(n);
    for(int i=0; i<n; i++) cin>>h[i];

    vector<ll> dp(n+1, INF);
    dp[0] = 0;
    for(int i=0; i<n; i++){
        for(int j=1; j<=k; j++){
            if(i + j >= n) break;
            chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1408
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;

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

int main() {
	string s;
	cin >> s;
	int sum = 0;

	REP(i, 4) {
		if (s[i] == '2') {
			sum++;
		}
	}

	ANS(sum);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<int,int> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int n;
string t[10]={"",".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		string s;
		string ans="";
		cin>>s;
		int tt=0;
		for(int i=0;i<s.size();i++){
			if(s[i]!='0'){
				tt++;
			}else{
				if(tt==0)continue;
				char q=s[i-1];
				tt--;
				if(q=='1'){
					ans+=t[(q-'0')][tt%5];
				}else if(q=='7'||q=='9'){
					ans+=t[(q-'0')][tt%4];
				}else{
					ans+=t[(q-'0')][tt%3];
				}
				tt=0;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3000
#include <stdio.h>

int main(){

int n, k, x, y;

scanf("%d", &n);
scanf("%d", &k);
scanf("%d", &x);
scanf("%d", &y);

int ans;

int kouhan = n - k;

if(n > k){
    ans = (k*x) + (kouhan*y);
} else{
  ans = n*x;
}

printf("%d\n", ans);

return 0;
}

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

Measured memory_bytes: 21844
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;

using namespace std;

int main(){
  int A,P;
  cin >> A >> P;
  cout << (A*3+P)/2 << endl;
}


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

#define INF 1000000000

int c[110];

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

    int n;
    cin>>n;

    int l=100,r=1;

    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        l=min(l,c[i]);
        r=max(r,c[i]);
    }

    int ans=INF;

    for(int i=l;i<=r;i++)
    {
        int a=0;
        for(int j=0;j<n;j++)a+=(c[j]-i)*(c[j]-i);
        ans=min(ans,a);
    }

    cout<<ans;

    return 0;
}


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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
  i32 N = input(), K = input();
  vector<i64> A(N + 1);
  range(i, 1, N + 1) cin >> A[i];
  range(i, 1, N + 1)(A[i] += (A[i - 1] - 1) % K + K) %= K;

  map<i32, i64> cnt;
  i64 ans = 0;
  range(i, 0, N + 1) {
    if (K <= i)
      cnt[A[i - K]]--;

    ans += cnt[A[i]];
    cnt[A[i]]++;
  }

  cout << ans << endl;
}

signed main(int argc, char *argv[]) { solver(); }

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;
const ll INF = 2e15 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 1e5 + 10;
const int M = 1e5 + 10;

ll d[N][2];
vector<int> g[N];

void dfs(int v, int par) {
    if (g[v].size() == 1 && g[v][0] == par) {
        d[v][0] = d[v][1] = 1;
        return;
    }

    for (auto u: g[v])
        if (u != par)
            dfs(u, v);
    d[v][1] = 1;
    d[v][0] = 1;
    for (auto u: g[v])
        if (u != par) {
            d[v][1] = (d[v][1] * d[u][0]) % MOD;
            d[v][0] = (d[v][0] * (d[u][1] + d[u][0])) % MOD;
        }

}

void solve() {
    int n;
    cin >> n;
    if (n == 1) {
        cout << 2;
        return;
    }

    fr(i, n - 1) {
        int v, u;
        cin >> v >>u;
        g[--v].pb(--u);
        g[u].pb(v);
    }
    dfs(0, -1);
    cout << (d[0][0] + d[0][1]) % MOD;
}



int main() {
    //freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 12800
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public Hello(){}
    public static void Main(){
        new Hello().Calc();
    }
    void Calc(){
        var inputs = InputValue;
        foreach(var i in inputs){
            Console.WriteLine(i);
        }
    }
    string MakeRectangle(int h,int w){
        var temp = "";
        for(var y = 0;y < h;y++){
            for(var x = 0;x < w;x++){
                if(y % 2 == 0){
                    if(x % 2 ==0){
                        temp += "#";
                    }else{
                        temp += ".";
                    }
                }else{
                    if(x % 2 == 0){
                        temp += ".";
                    }else{
                        temp += "#";
                    }
                }
            }
            temp += "\n";
        }
        return temp;
    }
    List<string> InputValue{
        get{
            var inputs = new List<string>();
            
            while(true){
                var line = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if(line[0] == 0 && line[1] == 0){
                    break;
                }else{
                    inputs.Add(MakeRectangle(line[0],line[1]));
                }
                
            }
            return inputs;
        }
    }
}



Measured memory_bytes: 32180
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int A[N];
    rep(i,N) cin>>A[i];
    sort(A,A+N);
    int sum[N]{};
    sum[0]=A[0];
    int ans=1;
    for(int i=1;i<N;i++){
        ans++;
        sum[i]=sum[i-1]+A[i];
        if(sum[i]>3*sum[i-1]) ans=1;
    }
    cout << ans << endl;





}


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

int main(){

    int con = 0;
    string str1 = "CODEFESTIVAL2016", str2;
    cin >> str2;
    for(int i =0 ;i < str1.length(); ++i){
        if(str1[i] != str2[i])con++;
    }
    cout << con <<endl;


return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

ll check(ll n, ll k) {
    if (n % k == 0) {
        return check(n / k, k);
    } else {
        return n % k == 1;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    cin, n;
    if (n == 2) {
        cout << 1 << endl;
        return 0;
    }
    ll ans = 2;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            ans += check(n, i);
            if (i * i != n) {
                ans += check(n, n / i);
            }
        }
    }
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 1) {
            ans++;
            ll rev = n / i;
            if (rev != i && n % rev == 1) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    /*
    auto f = [&]() {
        ll ans = 0;
        REP(i, 2, n + 1) {
            ans += check(n, i);
        }
        return ans;
    };
    dump(f());
    */

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define FF first
#define SS second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define inf 1e18
#define mod 1000000007
#define PI 3.1415926535
#define endl "\n"
#define runtime cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());

inline int sbt(int x) {return __builtin_popcount(x);}
inline int mul(int a, int b, int m = mod) { return (a * b) % m; }
inline int add(int a, int b, int m = mod) { return (a + b) % m; }
inline int sub(int a, int b, int m = mod) { return (a - b + m) % m; }



int32_t main() {
	fastio
	string s;
	cin >> s;
	int n = sz(s);
	int sum = 0;
	rep(i, 0, n) {
		sum += (int)(s[i] - '0');
	}
	if (sum % 9 == 0)cout << "Yes" << endl;
	else cout << "No" << endl;



	runtime
	return 0;
}


Measured memory_bytes: 3728
#include <iostream>

#define ll long long int

using namespace std;

int main(void){
  int N,M; cin>>N>>M;
  ll ans; ans = 100*(N-M) + 1900 * M;
  for(int i = 0; i < M; i++)
    ans *= 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256