akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

template <typename T> ostream& operator<<(ostream& out, vector<T> &v){
  for (int i = 0; i < (int)v.size(); i++) {
    out<<v[i]<<' ';
  }
  return out;
}

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

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


Measured memory_bytes: 3660
#include <bits/stdc++.h>
const int M = 1e9 + 7;
using namespace std;
int main() {
    long long n, m, ans = 1; cin >> n >> m;
    if (abs(m - n) > 1) {cout << "0\n"; return 0;}
    if (n == m) ans *= 2;
    for (int i = 1; i <= n; i++) ans = ans * i % M;
    for (int i = 1; i <= m; i++) ans = ans * i % M;
    //cout << (n != m ? ans : ans * 2) << endl;
    cout << ans << endl;
}

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

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) int(x.size())

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; }

const double PI=3.14159265358979323846;

int mod = 1e9+7;
const long long INF = 1LL<<60;

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

  map<ll, ll> mp_plus;
  map<ll, ll> mp_minus;
  rep(i, N){
    mp_plus[i+A[i]]++;
    mp_minus[i-A[i]]++;
  }

  ll ans = 0;
  for(pair<ll, ll> p: mp_plus){
    ll plus_cnt = p.second;
    ll minus_cnt = mp_minus[p.first];
    ans += plus_cnt * minus_cnt;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 38304
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  ll a,b,k; cin>> a >> b >> k;
  
  if(a < k){
    k -= a; a=0;
    b = max(b-k,0LL);
    cout << a << " " << b << endl;
  }else{
    cout << a-k << " " << b << endl;
  }
  return 0;
}


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

int main(void){
    int X,Y;
    cin >> X >> Y;
    for(int i = 0 ; i < 101 ; i++){
        for(int j = 0 ; j < 101 ; j++){
            if(i + j == X){
                if(2 * i + 4 * j == Y || 4 * i + 2 * j == Y){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
    
#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
#define MOD (int)(1e9)+7

using namespace std;

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

int32_t main(){
    int n;
    cin >> n;
    vector<pair<int, int> > a(n), b(n);
    REP(i, n) cin >> a[i].first >> a[i].second;
    REP(i, n) cin >> b[i].first >> b[i].second;
    SORT(a); SORT(b);

    int cnt=0;
    vector<bool> f(n, false);
    REP(j, n){
        int m=-INF, u;
        REP(i, n){
            if(b[j].second > a[i].second && b[j].first > a[i].first){
                if(!f[i] && m < a[i].second){
                    m = a[i].second;
                    u = i;
                }
            }
        }

        if(m!=-INF){
            cnt++;
            f[u] = true;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
"""
Writer: SPD_9X2
https://atcoder.jp/contests/arc087/tasks/arc087_c

初期状態で出ている数字を木としてあらわす
数字でふさがっている所はもう追加できない
まだおけるのは、空いている部分だけ

Lがでかいので、深さを考えていては死ぬ

そのままふさぐと、置ける場所は1減る
伸ばしておけば、Lまで増やして置ける

置ける場所の偶奇か？
置ける場所が0で来たら負け→初手が奇数なら先手勝ち・そうでないなら後手勝ち？
伸ばせる奴は偶奇反転に使える

部分で考えてみるか→

Grundy数計算
深さ1の部分木のGrundy → 1
深さ2の部分木のGrundy → 2
深さ3　　　　　　　　 → 1 ?
深さ4

Grundyで行ける = xorが全体のGrundyになるという仮定
なので、深さxを試すときは、深さxで1回で行ける状態のxorのmexがGrundyとなる

深さ1なら、問答無用で1
深さ2なら、0 or 1 になるので 2
深さ3なら, 0 or 2 になるので 1
深さ4なら, 0 or 1 or 3 or 2 なので 4
深さ5なら, 0 or 4 or 5 or 7 or 6 で 1
深さ6なら, 0 or 1 or 5 or 4 or 6 or 7 で 2
深さ7なら, 0 or 2 or 3 or 7 or 6 or 4 or 5 で 1
深さ8なら, 0 or 1 or 3 or 2 or 6 or 7 or 5 or 4 で 8

→どうやら、その数字を割り切れる最大の2の階乗数がGrundy数になるみたいだ
つまり、空きポイントを探索して、対応する深さのGrundy数を計算 & xorをとればよい

あとは実装だ
prefix treeを作りたいな？
適当にノードを追加して作ってあげればいいか
保持するデータは、0の子index,1の子index,深さがあれば十分かな
計算量がちょっと気になるところ(再帰はなるべく避けたいところ)

"""

def tp_z(now , nd):

    if z_child[now] == None:
        ret = len(z_child)
        z_child[now] = ret
        z_child.append(None)
        o_child.append(None)
        dep.append(nd + 1)
    else:
        ret = z_child[now]

    return ret

def tp_o(now , nd):

    if o_child[now] == None:
        ret = len(z_child)
        o_child[now] = ret
        z_child.append(None)
        o_child.append(None)
        dep.append(nd + 1)
    else:
        ret = o_child[now]

    return ret

def grundy(nd):

    if nd == 0:
        return 0

    for i in range(64):
        if nd % (2**i) != 0:
            return 2**(i-1)
        

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

z_child = [None]
o_child = [None]
dep = [0]

for loop in range(N):

    now = 0
    s = input()

    for i in s:
        if i == "0":
            now = tp_z(now , dep[now])
        else:
            now = tp_o(now , dep[now])

#print (z_child)
#print (o_child)
#print (dep)

ans = 0
for i in range(len(z_child)):

    if z_child[i] == None:
        ans ^= grundy(L - dep[i])
    if o_child[i] == None:
        ans ^= grundy(L - dep[i])

if ans == 0:
    print ("Bob")
else:
    print ("Alice")

Measured memory_bytes: 60656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int H, W;
    cin >> H >> W;
    string s[H];
    rep(i, H) cin >> s[i];
    int dp[H][W];
    dp[0][0] = 0;
    rep2(i, 1, H-1){
        dp[i][0] = dp[i-1][0]+(s[i][0]!=s[i-1][0]);
    }
    rep2(j, 1, W-1){
        dp[0][j] = dp[0][j-1]+(s[0][j]!=s[0][j-1]);
    }
    rep2(i, 1, H-1){
        rep2(j, 1, W-1){
            dp[i][j] = min(dp[i-1][j]+(s[i][j]!=s[i-1][j]), dp[i][j-1]+(s[i][j]!=s[i][j-1]));
        }
    }
    int ans = (dp[H-1][W-1]+1)/2;
    if(s[0][0] == '#' && s[H-1][W-1] == '#') ans++;
    cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<ll, int>;

#define INF 1001001001

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  map<P,bool> bbk;
  vector<int> cnth(h), cntw(w);
  int maxh = 0, maxw = 0;
  rep(i,m) {
    int s, t;
    cin >> s >> t;
    s--; t--;
    bbk[{s,t}]=true;
    cnth[s]++; cntw[t]++;
    maxh = max(maxh,cnth[s]);
    maxw = max(maxw,cntw[t]);
  }
  vector<int> idxh, idxw;
  rep(i,h) if (cnth[i]==maxh) idxh.push_back(i);
  rep(i,w) if (cntw[i]==maxw) idxw.push_back(i);
  int be = true;
  for (auto ih : idxh) {
      for (auto iw : idxw) {
          if (!bbk[{ih,iw}]) {
              be = false; break;
          }
      }
  }

  int ans = maxh+maxw;
  if(be) ans--;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 45444
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#define dout(i) //
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
int n;
const int maxn = 600;
ll dp[maxn][maxn];
ll w[maxn][maxn];
ll p[maxn][maxn];
ll to[maxn][maxn];
const ll inf = 1ll << 59;
inline ll get(int a, int b, int c, int d){
	return p[b][d] - (c == 0 ? 0 : p[b][c-1]) - (a == 0 ? 0 : p[a-1][d]) + (a == 0 || c == 0 ? 0 : p[a-1][c-1]);
}
inline ll get_to(int l, int r){
	return to[r][r] - to[l-1][r] - to[r][l-1] + to[l-1][l-1];
} 
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 1;i <= n;++i)for(int j = 1;j <= n;++j)if(i != j)cin >> w[i][j];
	for(int i = 1;i <= n;++i)for(int j = 1;j <= n;++j)p[i][j] = p[i-1][j] + p[i][j-1] - p[i-1][j-1] + w[i][j];
	for(int i = 1;i <= n;++i)for(int j = 1;j <= n;++j)to[i][j] = to[i-1][j] + to[i][j-1] - to[i-1][j-1] + (i < j ? w[i][j] : 0);
	for(int i = 1;i <= n;++i){
		dp[i][1] = get_to(1, i);
		for(int j = 2;j <= i;++j){
			dp[i][j] = inf;
			for(int k = 1;k < j;++k){
				dp[i][j] = min(dp[i][j], dp[j-1][k] + get_to(j, i) + get(j, i, 0, k-1));
			}
		}
	}
	cout << *min_element(dp[n]+1, dp[n]+n+1) << '\n';
}

Measured memory_bytes: 11008
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>

#define MAX(a,b) ((a)<(b) ? (a) : (b))
#define MIN(a,b) ((a)>(b) ? (a) : (b))

using namespace std;

int main(){
	long long int x, a, ans;
	int buf;
	cin >> x;
	ans = 0;
	a = 0;

	ans = (x / 11) * 2;
	buf = x % 11;
	
	for (int i = 0; i < buf ; i++) {
		ans++;
		if (ans%2==1) {
			if ( i%2==0 ) a = a + 6;
			if ( i%2==1 ) a = a + 5;
		} else {
			if ( i%2==0 ) a = a + 5;
			if ( i%2==1 ) a = a + 6;
		}
		if ( a >= buf ) break;
	}

	cout << ans << endl;
}

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

char c[1000];
int H, W, N, a, i, j, k, ns;
complex<int> chs[11];
bool kuk[1002][1002];
int score[1002][1002];
complex<int> mov[4] = {complex<int>(0, 1), complex<int>(1, 0), complex<int>(0, -1), complex<int>(-1, 0)};
queue<complex<int> > qu;
complex<int> now, nm;
bool flg1, flg2 = flg1 = true;

int main(){
    scanf("%d%d%d", &H, &W, &N);
    for(i = 1; i <= H; ++i){
        scanf("%s", c);
        for(j = 0; j < W; ++j){
            kuk[i][j + 1] = true;
            switch(c[j]){
                case 'X':
                    kuk[i][j + 1] = false;
                    break;
                case 'S':
                    chs[0] = complex<int>(i, j + 1);
                    break;
                default:
                    chs[c[j] - 48] = complex<int>(i, j + 1);
                    break;
            }
        }
    }
    for(i = 1; i <= N; i += 2){
        for(j = 0; j <= H + 1; ++j){
            for(k = 0; k <= W + 1; ++k){
                score[j][k] = 2147483647;
            }
        }
        qu.push(chs[i]);
        score[real(chs[i])][imag(chs[i])] = 0;
        flg1 = true;
        flg2 = (i + 1 <= N);
        while(flg1 || flg2){
            now = qu.front();
            ns = score[real(now)][imag(now)];
            for(j = 0; j < 4; j++){
                nm = now + mov[j];
                int x = real(now + mov[j]), y = imag(now + mov[j]);
                if(chs[i - 1] == nm){
                    flg1 = false;
                }
                if(i + 1 <= N && chs[i + 1] == nm){
                    flg2 = false;
                }
                if(kuk[x][y] && score[x][y] > ns + 1){
                    qu.push(nm);
                    score[x][y] = ns + 1;
                }
            }
            qu.pop();
        }
        a += score[real(chs[i - 1])][imag(chs[i - 1])];
        if(i + 1 <= N)a += score[real(chs[i + 1])][imag(chs[i + 1])];
        queue<complex<int> > emp;
        swap(qu, emp);
    }
    cout << a << endl;
    return 0;
}

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

    public static void main(String argv[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[]=new int[N];
        for(int i=0; i<N; i++){
            a[i]=sc.nextInt();
        }

        Arrays.sort(a);
        int Ali=0;
        int Bob=0;

        for(int i=1; i<=N; i=i+2){
            Ali = Ali+a[N-i];
            if(N-i-1>=0){
                Bob = Bob+a[N-i-1];
            } 
        }
  
        System.out.println(Ali-Bob);

        


    }
}

Measured memory_bytes: 35812
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i
sum = 0
(0..a).each do |i|
  (0..b).each do |j|
    (0..c).each do |k|
      sum += 1 if i * 500 + j * 100 + k * 50 == x
    end
  end
end
puts sum

Measured memory_bytes: 3836
#include<stdio.h>
int main()
{
    long long N,h,n,w1,w2;
    int count;
    while(~scanf("%lld",&N))
    {
        count=0;
        for(h=1;h<=3500;h++)
        {
            for(n=1;n<=3500;n++)
            {
                w1=N*h*n;
                w2=4*h*n-n*N-h*N;
                if(w1>0&&w2>0&&w1%w2==0)
                {
                    printf("%lld %lld %lld\n",h,n,w1/w2);
                    count++;
                    break;
                }
            }
            if(count) break;
        }
    }
    return 0;
}


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

int s[1000], d[1000], t[1000][1000], y[1000];
P p[100001];
int main() {
	int n, m, h, k;
	while (scanf("%d%d%d%d", &n, &m, &h, &k), n) {
		rep(i, n)scanf("%d", &s[i]), d[i] = t[0][i] = i;
		rep(i, m) {
			int a, b; scanf("%d%d", &a, &b);
			p[i] = P(b, a);
		}
		sort(p, p + m);
		int u = 0;
		for (int i = 1; i < h; i++) {
			while (p[u].first == i)swap(d[p[u].second - 1], d[p[u].second]), u++;
			rep(j, n)t[i][j] = d[j];
		}
		rep(i, n)y[d[i]] = i;
		int Min = 0;
		rep(i, n)if (d[i] < k)Min += s[i];
		rep(i, m) {
			int a = y[t[p[i].first - 1][p[i].second - 1]], b = y[t[p[i].first - 1][p[i].second]];
			swap(d[a], d[b]);
			int sum = 0;
			rep(i, n)if (d[i] < k)sum += s[i];
			Min = min(Min, sum);
			swap(d[a], d[b]);
		}
		printf("%d\n", Min);
	}
}

Measured memory_bytes: 7836
from collections import Counter
N=int(input())
S=[0]*5000
S=list(input())

S_count=Counter(S)
r=S_count["R"]
g=S_count["G"]
b=S_count["B"]

ans=0

for i in range(N-2):
    for j in range(1,N):
        if i+2*j>=N:
            break
        if S[i]!=S[i+j] and S[i+j]!=S[i+2*j] and S[i]!=S[i+2*j]:
            ans+=1

print(r*g*b-ans)

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

double dp[222][444];

double seica(double a, double b, double h){
	return (a * a + b * b) / (2 * (a + b));
}

double rian(double a, double b, double h){
	return (a + b) / 2;
}

int main(){

	REP(i,222){
		REP(j,444){
			dp[i][j] = INF;
		}
	}
	dp[0][1] = 0;

	ll n;cin >> n;
	vector<double> v(n);
	REP(i,n)cin >> v[i];

	REP(i,n){
		REP(j,444)if(dp[i][j] != INF){
			for(ll ii = 1;ii < 444;ii++){
				double tmp;
				if((v[i] - j) * (v[i] - ii) < 0){
					tmp = seica(abs(v[i] - j), abs(v[i] - ii), v[i]);
				}
				else {
					tmp = rian(abs(v[i] - j), abs(v[i] - ii), v[i]);
				}
				dp[i+1][ii] = min(dp[i+1][ii], dp[i][j] + tmp);
			}
		}
	}

	double ans = INF;
	REP(i,444){
		ans = min(ans, dp[n][i]);
	}

	cout << Decimal << ans << endl;

	return 0;
}



Measured memory_bytes: 4060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

void solve(){
  ll n,k;
  cin>>n>>k;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  vector<ll>sum(n+1);
  map<ll,ll>mp;
  rep(i,n){
    sum[i+1]=sum[i]+a[i];
  }
  ll cnt=0;
  rep(i,n){
    if(i-(k-1)>=0)mp[(sum[i-(k-1)]-(i-(k-1)))%k]--;
    mp[(sum[i]-i)%k]++;
    cnt+=mp[(sum[i+1]-(i+1))%k];
  }
  cout<<cnt<<endl;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


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

int main() {
    //
    char moji;

    cin >> moji;

    if (moji >= 'a' && moji <= 'z') {
        cout << "a";
    } else if (moji >= 'A' && moji <= 'Z') {
        cout << "A";
    }

}

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

int main()
{
  string S ;
  cin>>S ;
  for(int i=0;i<3;i++){
    if(S.at(i)==S.at(i+1)){
      cout<<"Bad"<<endl ;
      return 0 ;
    }
  }
  cout<<"Good"<<endl ;
    
  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);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, y, k, z, N;
ll s, t, d;


// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n >> m >> x;
	vll b(m);
	ll cou = 0;
	for(ll i=0;i<m;i++) cin>>b[i];

	for(ll i=0;i<n;i++) {
		vll a(m);
		for(ll j=0;j<m;j++) cin>>a[j];
		ll sum = x;
		for(ll j=0;j<m;j++) sum+=a[j]*b[j];
		cou+=(sum > 0);
	}

	cout<<cou;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;

//clang++ -std=c++11 -stdlib=libc++ 
int main() {
  int a,b; cin>>a>>b;

  int larger=max(a,b);
  if (larger==a) {
    rep(i,a) cout << b;
    cout << endl;
  } else {
    rep(i,b) cout << a;
    cout <<endl;
  }
  return 0;
}

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

#define SENTINEL 1000000000000000000

void merge(long long A[], long long left, long long mid, long long right){
  long long n1, n2, i, j, k;
  long long *L,*R;
  
  n1 = mid-left;
  n2 = right-mid;
  
  L = (long long*)malloc(sizeof(long long) *(n1 + 1));
  R = (long long*)malloc(sizeof(long long) *(n2 + 1));
  
  for(i = 0; i <= n1 - 1; i++){
    L[i] = A[left + i];
  }
  for(j = 0; j <= n2 - 1; j++){
    R[j] = A[mid + j];
  }
  
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
  
  i = 0;
  j = 0;
  
  for(k = left; k <= right - 1; k++){
   if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
    }
  }
  free(L);
  free(R);
}

void mergeSort(long long A[], long long left, long long right){
  long long mid;
  
  if(left + 1 < right){
    mid=(left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main(void){

    int N;

    scanf("%d", &N);

    long long A[N];

    for(int i = 0; i < N; i++){
        scanf("%lld", &A[i]);
    }

    mergeSort(A, 0, N);

    if(N % 2 == 0){
        int t = 0;
        int f = 0;
        for(int i = 0; i < N-1; i += 2){
            if(A[i] != 2*t+1 || A[i+1] != 2*t+1){
                f = 1;
                break;
            }
            t++;
        }
        if(f == 1){
            printf("0\n");
        }else{
            long long ans = 1;
            for(int i = 0; i < N/2; i++){
                ans = (ans * 2) % 1000000007;
            }
            printf("%lld\n", ans);
        }
    }else{
        int f = 0;
        if(A[0] != 0){
            f = 1;
        }
        int t = 1;
        if(f == 0){
            for(int i = 1; i < N-1; i += 2){
                if(A[i] != 2*t || A[i+1] != 2*t){
                    f = 1;
                    break;
                }
                t++;
            }
        }
        if(f == 1){
            printf("0\n");
        }else{
            long long ans = 1;
            for(int i = 0; i < N/2; i++){
                ans = (ans * 2) % 1000000007;
            }
            printf("%lld\n", ans);
        }
    }

    return 0;
}

Measured memory_bytes: 2896
#include<iostream>
#include<vector>
#include<queue>

using namespace std;
  
#define NOT -100000*2100
#define VMAX 1000
#define EMAX 2000

int main(void){
	
	int V,E,r;
	int s,t,d;
	int v[VMAX];
	int cnt;
	vector<int> ed[VMAX];
	vector<int> edco[VMAX];
	queue<int> no;

	cin>>V>>E>>r;

	for(int i=0;i<V;i++) v[i]=NOT;
;
	for(int i=0;i<E;i++){
		cin>>s>>t>>d;
		ed[s].push_back(t);
		edco[s].push_back(d);
	}

	no.push(r);
	v[r]=0;
	cnt=0;
	while(!no.empty()){
		if(cnt>20000){
			cout<<"NEGATIVE CYCLE"<<endl;
			return 0;
		}
		for(int i=0;i<ed[no.front()].size();i++){
			if(v[no.front()]+edco[no.front()][i]<v[ed[no.front()][i]]||v[ed[no.front()][i]]==NOT){
				v[ed[no.front()][i]]=v[no.front()]+edco[no.front()][i];
				cnt++;
				no.push(ed[no.front()][i]);
			}
		}
		no.pop();
	}

	for(int i=0;i<V;i++){
		if(v[i]!=NOT) cout<<v[i]<<endl;
		else cout<<"INF"<<endl;
	}
}

Measured memory_bytes: 1332
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using vvi = vector<vector<int> >;
const int max_n = 100000;
const int max_m = 100000;
using namespace std;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};


int main() {
	int N,M,K;
	cin>>N>>M>>K;
	UnionFind uni(N);
	vvi tomo(N), block(N);
	REP(i,M){
		int a,b; 
		cin >>a>>b; a--,b--;
		tomo[a].push_back(b);
		tomo[b].push_back(a);
		uni.connect(a,b);
	}
	REP(i,K){
		int c,d; cin>>c>>d; c--; d--;
		block[c].push_back(d);
		block[d].push_back(c);
	}
	vector<int> ans(N,0);
	REP(i,N){
		int now = uni.size(i)-tomo[i].size()-1;
        REP(k,block[i].size()){
            if(uni.root(i) == uni.root(block[i][k])){
                now--;
            }
        }
        ans[i] = now;
	}
    REP(i,N-1){
        cout << ans[i] <<" ";
    }
    cout<<ans[N-1]<<endl;
}

Measured memory_bytes: 14936
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
typedef pair<string, string> PS;
const int INF = 1e15;

signed main(){
    int n;
    string s;
    cin >> n >> s;
    vector<PS> d;
    for(int i = 0; i < (1 << n); i++){
        string t1 = "", t2 = "";
        for(int j = 0; j < n; j++){
            if(i & (1 << j)) t1 += s[j];
            else t2 += s[j];
        }
        d.push_back({t1, t2});
    }
    map<PS, int> mp;
    for(int i = 0; i < (1 << n); i++){
        string t1 = "", t2 = "";
        for(int j = 0; j < n; j++){
            if(i & (1 << j)) t1 += s[n + j];
            else t2 += s[n + j];
        }
        reverse(t1.begin(), t1.end());
        reverse(t2.begin(), t2.end());
        mp[{t1, t2}]++;
    }
    int ans = 0;
    for(int i = 0; i < (1 << n); i++){
        ans += mp[{d[i].first, d[i].second}];
    }
    cout << ans << endl;
}

Measured memory_bytes: 91116
#include <iostream>

using namespace std;

int main() {
    int A, B, C; cin >> A >> B >> C;

    if((A == B && B != C) || (A == C && A != B) || (B == C && A != B)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
import itertools
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

s = S()
t = S()

cnt = 0
for i in range(len(s)):
    if s[i] != t[i]:
        cnt += 1

print(cnt)

Measured memory_bytes: 27424
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <ll , ll>;
void in(ll &x);
const ll N = 1e5 + 10;
#define singleCase
// #define multipleCase
ll n;
bool vis[N];

ll dfs(ll x , vector <ll> &v) {
   if (x < 0 || x >= v.size()) return 0;
   if (vis[x]) return 0;
   if (v[x] == 0) return 0;
   vis[x] = 1;
   return 1 + dfs(x - 1 , v) + dfs(x + 1 , v);
}

void work() {
   in(n);
   vector <ll> v(n);
   for (ll i = 0 ; i < n ; i++) {
      in(v[i]);
   }
   sort(all(v));
   v.pb(INT_MIN);
   ll cum = 0;
   vector <ll> r(n);
   for (ll i = 0 ; i < n ; i++) {
      cum += v[i];
      r[i] = cum * 2 >= v[i + 1];
   }
   printf("%lld\n" , dfs(n - 1 , r));
   return;
}

int main() {
   #ifdef multipleCase
      ll nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   return 0;
}

void in(ll &x) {
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-') {
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	  x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 9560
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin>>s;
    if((s[0]==s[1])&&(s[1]==s[2])&&(s[0]==s[2]))
    {
        cout<<"Yes"<<endl;
    }
    else if((s[1]==s[2])&&(s[2]==s[3])&&(s[1]==s[3]))
    {
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
}

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

using namespace std;

int main(void) {
  int x[52][52] = { {0} };
  int h, w;
  cin >> h >> w;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      char xij;
      cin >> xij;
      if (xij == '#') {
        x[i][j] = 1;
      }
    }
  }

  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (x[i][j] == 1) {
        cout << '#';
        continue;
      }
      int bc =
        + x[i - 1][j - 1] + x[i][j - 1] + x[i + 1][j - 1]
        + x[i - 1][j]                   + x[i + 1][j]
        + x[i - 1][j + 1] + x[i][j + 1] + x[i + 1][j + 1];
      cout << bc;
    }
    cout << endl;
  }
  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define OUT(x) cout<<x<<endl
#define debug(x) cout<<#x<<": "<<x
const int BA = 1000;
const int INFTY = (1<<21);
int main(){
  int n,ans;
  int s[1001];
  while(cin>>n&&n){
    ans = 0;
    for(int i=0;i<n;i++)cin >> s[i];
    
    sort(s,s+n);
    for(int i=1;i<n-1;i++)ans+=s[i];
    ans/=n-2;
    OUT(ans);
  }
}

Measured memory_bytes: 1176
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int e = a * b, f = c * d;
  if(e < f){
    cout << f << "\n";
  }
  else{
    cout << e << "\n";
  }
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define gc getchar
#define pc putchar
#define cs const
#define st static

cs ll mod=998244353;

inline
void outint(int a){
	st char ch[13];
	if(a==0)pc('0');
	while(a)ch[++ch[0]]=(a-a/10*10)^48,a/=10;
	while(ch[0])pc(ch[ch[0]--]);
}

ll fac[4002],inv[4002],ifac[4002];

ll ans[4002];

inline
ll C(int n,int m){
	if(n<m)return 0;
	return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}

inline
void init(){
	fac[0]=fac[1]=inv[1]=ifac[1]=ifac[0]=1;
	for(int re i=2;i<=4000;++i){
		inv[i]=(mod-mod/i)*inv[mod%i]%mod;
		fac[i]=fac[i-1]*i%mod;
		ifac[i]=ifac[i-1]*inv[i]%mod;
	}
}

inline
ll calc(ll a,ll n,ll k){
	ll ans=0;
	for(int re i=0;i<=min(a>>1,k>>1);++i){
		ll tmp=C(a>>1,i)*C(n+k-i*2-1,n-1)%mod;
		if(i&1)ans=(ans-tmp+mod)%mod;
		else ans=(ans+tmp)%mod;
	}
	return ans;
}

int n,k;

int main(){
	init();
	cin>>n>>k;
	for(int re i=1;i<=n;++i){
		if(i&1)ans[i]=(calc(i,n-1,k)+calc(i,n-1,k-1))%mod;
		else ans[i]=calc(i,n,k);
	}
	for(int re i=1;i<=n;++i)outint(ans[i]),pc('\n');
	for(int re i=n-1;i;--i)outint(ans[i]),pc('\n');
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >>n;
    int a[n];
    for(int i=0;i<n;i++)cin >>a[i];

    int mx=INT_MIN;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i!=j){
                mx=max(abs(a[i]-a[j]),mx);
            }
        }
    }
    cout <<mx<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int n;
LL k;
LL a[N],b[N];
int main() {
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)cin>>b[i];
    sort(b+1,b+1+n,[](LL x,LL y){return x>y;});
    LL l=0,r=1e18;
    LL ans=0;
    //cout<<r<<endl;
    while(l<=r){
        LL mid=l+r>>1;
        LL tmp=0;
        for(int i=1;i<=n;i++){
            LL now=a[i]*b[i];
            if(now>mid){
                tmp+=a[i]-mid/b[i];
            }
        }
        if(tmp<=k)ans=mid,r=mid-1;
        else l=mid+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3456
#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>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(),x.end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

int n;
vector<int>a;
ll solve(){
   ll ans=0;
   rep(i,n){
       if(i%2==0&&a[i]%2==1)ans++;
   }

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

    cin>>n;
    a.resize(n);
    rep(i,n)cin>>a[i];
    cout<<solve()<<endl;
    return 0;
}

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

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define int long long
#define INF 1e+9
#define MAX_V 100008
const int MOD = 1e9 + 7;
const int inf = 1 << 30;



signed main(){
  IOS
  string s;
  cin >> s;
  int ans = 0;
  if(s[0] == 'R'&& s[1] == 'R' && s[2] == 'R') ans = 3;
  if(s[0] == 'R'&& s[1] == 'R' && s[2] == 'S') ans = 2;
  if(s[0] == 'S'&& s[1] == 'R' && s[2] == 'R') ans = 2;

  if(s[0] == 'S'&& s[1] == 'S' && s[2] == 'R') ans = 1;
  if(s[0] == 'R'&& s[1] == 'S' && s[2] == 'S') ans = 1;
  if(s[0] == 'R'&& s[1] == 'S' && s[2] == 'R') ans = 1;

  if(s[0] == 'S'&& s[1] == 'R' && s[2] == 'S') ans = 1;
  
  cout << ans << endl;
}


Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main() {
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = 0; i < k; ++i) {
        auto &from = (i % 2 == 0 ? a : b);
        auto &to = (i % 2 == 0 ? b : a);
        if (from % 2 == 1) {
            --from;
        }
        from /= 2;
        to += from;
    }
    cout << a << ' ' << b << '\n';
}

Measured memory_bytes: 3608
#include <iostream>

using i64 = long long;

template<typename T> T abs(T x) { return x < 0 ? -x : x; }

const int N = 10000 + 7;

int n, m;
i64 x[N], y[N];
i64 c[N];

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld%lld", x + i, y + i);
		if ((x[1] + y[1] - x[i] - y[i]) & 1) return printf("-1"), 0;
	}
	m = 36;
	for (int i = 36; i; --i)
		c[i] = 1ll << 36 - i;
	if ((x[1] + y[1]) % 2 == 0) c[++m] = 1;
	printf("%d\n", m);
	for (int i = 1; i <= m; ++i)
		printf("%lld ", c[i]);
	printf("\n");
	for(int i = 1; i <= n; ++i) {
		i64 u = 0, v = 0;
		for (int j = 1; j <= m; ++j) {
			i64 dx = abs(u - x[i]), dy = abs(v - y[i]);
			if (dx > dy)
				x[i] > u ? (printf("R"), u += c[j]) : (printf("L"), u -= c[j]);
			else
				y[i] > v ? (printf("U"), v += c[j]) : (printf("D"), v -= c[j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3820
/*{{{*/
//#define HOME
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define F first
#define S second

template<class T> void _R(T &_x) { cin >> _x; }
void _R(int &_x) { scanf("%d", &_x); }
void _R(int64_t &_x) { scanf("%" SCNd64, &_x); }
void _R(double &_x) { scanf("%lf", &_x); }
void _R(char &_x) { scanf(" %c", &_x); }
void _R(char *_x) { scanf("%s", _x); }
template<class T, class U> void _R(pair<T, U> &_x) {_R(_x.F); _R(_x.S);}
void R() {}
template<class T, class... U> void R(T &_head, U &... _tail) { _R(_head); R(_tail...); }

template<class T> void _W(const T &_x) { cout << _x; }
void _W(const int &_x) { printf("%d", _x); }
void _W(const int64_t &_x) { printf("%" PRId64, _x); }
void _W(const double &_x) { printf("%.16f", _x); }
void _W(const char &_x) { putchar(_x); }
void _W(const char *_x) { printf("%s", _x); }
template<class T, class U> void _W(const pair<T, U> &_x) {_W(_x.F); putchar(' '); _W(_x.S);}
template<class T> void _W(const vector<T> &_x) { for (auto i = _x.begin(); i != _x.end(); _W(*i++)) if (i != _x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &_head, const U &... _tail) { _W(_head); putchar(sizeof...(_tail) ? ' ' : '\n'); W(_tail...); }
template<class T, class... U> void DB(const T &_head, const U &... _tail) {
#ifdef HOME
    W('#', _head, _tail...);
#endif
}

#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define RAN(x,n) (x).begin(), (x).begin()+(n)
#define UNIQUE(x) {sort(ALL(x)); (x).erase(unique(ALL(x)), (x).end());}

#define REP(i,a,b) for (int i = (a); i <= (b); ++i)
#define REPD(i,a,b) for (int i = (a); i >= (b); --i)
#define FORI(i,n) REP(i,1,n)
#define FOR(i,n) REP(i,0,int(n)-1)
//#define ITER(i,t) for (auto i = t.begin(); i != t.end(); ++i)
#define IT3(i,st,ed) for (auto i = st; i != ed; ++i)
#define IT2(i,range) IT3(i,range)

#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define MS(X, v) memset((X), (v), sizeof((X)))

template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

inline int LG (const unsigned int &_x) { return 31-__builtin_clz(_x); }  // floor: LG(x), ceil: LG(x-1)+1
/*}}}*/

int n, k;
vi as, d;
unordered_map<int, int> cnt;

int main(){
    R(n, k);
    as.assign(n+1, 0);
    FORI(i, n) R(as[i]);

    d.assign(n+1, 0);
    FORI(i, n)
        d[i] = (as[i] + d[i-1] - 1) % k;

    ll ans = 0;
    FOR(i, SZ(d)){
        if(i >= k) cnt[d[i-k]]--;
        ans += cnt[d[i]];
        cnt[d[i]]++;
    }

    W(ans);

    return 0;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

// ------------------------------------------------------------------------------------------

const int INF = 1e18;

int N, A, B, C;
vec<int> l;

int rec(int idx, int a, int b, int c) {
  if (idx >= N) {
    if (a == 0 or b == 0 or c == 0) return INF;
    return abs(a - A) + abs(b - B) + abs(c - C);
  }

  int ret = INF;

  // A
  chmin(ret, rec(idx+1, a + l[idx], b, c) + (a > 0 ? 10 : 0));
  // B
  chmin(ret, rec(idx+1, a, b + l[idx], c) + (b > 0 ? 10 : 0));
  // C
  chmin(ret, rec(idx+1, a, b, c + l[idx]) + (c > 0 ? 10 : 0));
  // No
  chmin(ret, rec(idx+1, a, b, c));

  return ret;
}

signed main() {
  cin >> N >> A >> B >> C;
  l.resize(N);
  rep (i, N) {
    cin >> l[i];
  }

  cout << rec(0, 0, 0, 0) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<set>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=5e5+1e2;
struct Edge {
	int to,nxt;
}e[maxn<<1];
int n,m;
int tot;
int a[maxn],p[maxn],Ans[maxn],cnt[maxn],head[maxn];
set<int>pre,suf;
priority_queue<int,vector<int>,less<int> >q;

inline int read() {
	int x=0,p=1;
	char c=getchar();
	while (!isdigit(c)) { if (c=='-') p=-1; c=getchar();}
	while (isdigit(c)) { x=(x<<1)+(x<<3)+(c-'0'); c=getchar();}
	return x*p;
}

inline void Erase(set<int>&s,int p) {
	set<int>::iterator it=s.lower_bound(p);
	s.erase(it);
}

inline void add(int from,int to) {
	e[++tot]=(Edge){to,head[from]}; head[from]=tot; ++cnt[to];
}

inline void init() {
	n=read(); m=read();
	For (i,1,n) a[i]=read(),p[a[i]]=i;
	For (i,0,m-1) suf.insert(a[i]);
	For (i,1,n) {
		pre.insert(a[i]);
		Erase(suf,a[i-1]);
		if (i+m-1<=n) suf.insert(a[i+m-1]);
		if (i-m>=1) Erase(pre,a[i-m]);
		set<int>::iterator it1=pre.upper_bound(a[i]);
		set<int>::iterator it2=suf.upper_bound(a[i]);
		if (it1!=pre.end()) add(p[*it1],i);
		if (it2!=suf.end()) add(p[*it2],i);
	}
}

inline void solve() {
	For (i,1,n) if (!cnt[i]) q.push(i);
	int ans=0;
	while (!q.empty()) {
		int u=q.top(); q.pop(); Ans[u]=n-ans; ++ans;
		for (int i=head[u];i!=0;i=e[i].nxt) {
			int v=e[i].to;
			--cnt[v];
			if (!cnt[v]) q.push(v);
		}
	}
	For (i,1,n) printf("%d\n",Ans[i]);
}

int main() {
	init();
	solve();
	return 0;
}

Measured memory_bytes: 44672
#include <stdio.h>

int main(void) {
	long long int N,Y;
	scanf("%lld %lld",&N,&Y);
	int i,j,k,cnt=0;
	for(i=0;i<=N;i++){
		if(cnt==1){
			break;
		}
		for(j=0;j<=N;j++){
			k=(N-i-j);
			if(cnt==1){
				break;
			}
			if(Y==(i*10000)+(j*5000)+(k*1000)&&(i+j+k)==N&&k>=0){
				printf("%d %d %d",i,j,k);
				cnt=1;
				break;
			}
		}
	}
	if(cnt==0){
		printf("-1 -1 -1");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int n;cin >> n;
	string s;
	cin >> s;
	ll ans = 0, c1 = 0, c2 = 0, c3 = 0;
	for(auto i : s)
		c1 += (i == 'R'), c2 += (i == 'G'), c3 += (i == 'B');
	ans = c1 * c2 * c3;
	for(int i = 0; i < s.size(); i++){
		for(int j = i + 1; j < s.size(); j++){
			if(s[i] != s[j]){
				int k = j - i;
				if(j + k < s.size() && s[j + k] != s[i] && s[j + k] != s[j])
					ans--;
			}
		}
	}
	cout << ans << endl;
}

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

int main() {
    int a,b,ans;
    cin>>a>>b;

    if (a==1 && b == 2) ans=3;
    else if(a == 1 && b == 3) ans=2;
    else if(a == 2 && b == 1) ans = 3;
    else if(a==2&&b==3) ans=1;
    else if(a==3&&b==1) ans=2;
    else ans=1;

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  ll ans=1;
  for(ll i=0;i<n;i++) {
    if(a[i]==0) {
      cout << 0 << endl;
      return 0;
    }
  }
  for(ll i=0;i<n;i++) {
    if(ans*a[i]<ans) {
      cout << -1 << endl;
      return 0;
    }
    ans*=a[i];
  }
  ll lim=1e18;
  if(ans>lim) ans=-1;
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

int W[300], dp[300][300];

int rec(int l, int r) {
  if (l + 1 >= r) return 0;
  if (~dp[l][r]) return dp[l][r];
  if (abs(W[l] - W[r - 1]) <= 1 && rec(l + 1, r - 1) == r - l - 2) {
    return dp[l][r] = r - l;
  }
  int ret = 0;
  repi(m, l + 1, r) {
    ret = max(ret, rec(l, m) + rec(m, r));
  }
  return dp[l][r] = ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  while (true) {
    int N;
    cin >> N;
    if (!N) break;
    rep(i, N) cin >> W[i];
    memset(dp, -1, sizeof(dp));
    cout << rec(0, N) << endl;
  }
  return 0;
}



Measured memory_bytes: 3496