akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int a[3], b[3], c[4]={0};
	for(int i=0; i<3; i++){
		cin >> a[i] >> b[i];
		c[a[i]-1]++;
		c[b[i]-1]++;
	}
	sort(c, c+4);
	if(c[0]==1 && c[1]==1 && c[2]==2 && c[3]==2){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 888
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-08-17 16:49
# @url:https://atcoder.jp/contests/abc057/tasks/abc057_c

import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    n=int(input())
    ans=20
    for i in range(1,math.ceil(math.sqrt(n))+1):
        if n%i==0:
            a,b=str(i),str(n//i)
            ans=min(ans,max(len(a),len(b)))
    print (ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 77300
#include <stdio.h>

int main (void)
{
  int n, m, sum = 0, c = 0;
  int a[100] = {};

  scanf("%d %d", &n, &m);

  for (int i = 0; i < n; i++){
    scanf("%d ", &a[i]);
    sum += a[i];
  }

  for (int j = 0; j < n; j++){
    if (a[j] >= 0.25 * sum / m) c++;
  }

  if (c>=m) printf("Yes\n");
  else printf("No\n");

  return 0;
}

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

int main() {
  int n; cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  int max=a[n-1];
  vector<int>b(max+2);
  vector<int>c(max+2);
  for(int i=0;i<n;i++){
    b[a[i]]++;
    c[a[i]]++;
  }
  for(int i=1;i<max+1;i++){
    b[i]+=c[i-1]+c[i+1];
  }
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  if(n==1) cout<<1<<endl;
  else cout<<b[0]<<endl;
}


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

main(){
    int H=1, W=1;
    while(H&&W){
        cin >> H >> W;
        if(H&&W){
            for(int i=0; i<H; ++i){
                for(int j=0; j<W; ++j) cout << "#";
                cout << endl;
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 3124
#include<stdio.h>
int main(void)
{
  int A,B,C,D,E,sec=0,i;
  scanf("%d %d %d %d %d",&A,&B,&C,&D,&E);
  if(A<0)
  {
    for(i=A;i<0;i++) sec+=C;
  }
  //printf(" %d\n",sec);
  if(A<=0)sec+=D;
  //printf(" %d\n",sec);
  if(A>0)
      {
        for(i=A;i<B;i++) sec+=E;
      }
  else
  {
    for(i=0;i<B;i++) sec+=E;
  }
  printf("%d\n",sec);
  return 0;
}



Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int n_order(long n){
    int ord=0;
    while(n%2==0){
        n=n/2;
        ord++;
    }
    return ord;
}
int main(){
  int n;
  cin>>n;
  vector<long> a(n);
  rep(j,0,n){
    cin>>a[j];
  }
  int count=0;
  rep(i,0,n){
    count+=n_order(a[i]);
  }
  cout<<count<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<random>
using namespace std;
std::random_device rnd;
std::mt19937 mt(rnd());
std::uniform_int_distribution<> r(1, 26);
int D=365,c[26+1],last[26+1],M;
int main(){
    cin>>D;
    //input
    int s[D+1][26+1];
    for(int i=1;i<=26;i++)cin>>c[i];
    for(int i=1;i<=D;i++)for(int j=1;j<=26;j++)cin>>s[i][j];
    //output:random
    for(int i=0;i<D;i++)cout<<r(mt)<<endl;
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const int N=16;
ll dp[(1<<N)];
int a[N][N];
ll pre[(1<<N)];


void bt(int i , vector < int > &not_taken , ll ans , int mask , int group)
{
    if(i==not_taken.size())
    {
        dp[mask]=max(dp[mask],pre[group]+ans);
        return ;
    }
    bt(i+1,not_taken,ans,mask,group);
    bt(i+1,not_taken,ans,mask^(1<<not_taken[i])
       ,group^(1<<not_taken[i]));

}
int main()
{
    memset(dp,-1,sizeof dp);
    dp[0]=0;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            cin>>a[i][j];
    }
    for(int mask=0;mask<(1<<n);mask++)
    {
        for(int i=0;i<n;i++)
        {
            if(mask&(1<<i))
            {
                for(int j=i+1;j<n;j++)
                {
                    if(mask&(1<<j))
                        pre[mask]+=a[i][j];
                }
            }
        }
    }
    for(int mask=0;mask<(1<<n);mask++)
    {
        vector < int > not_taken;
        for(int i=0;i<n;i++)
        {
            if(!(mask&(1<<i)))
                not_taken.push_back(i);
        }
        bt(0,not_taken,dp[mask],mask,0);
    }
    cout<<dp[(1<<n)-1]<<endl;
    return 0;
}


Measured memory_bytes: 1280
h, w = gets.split().map(&:to_i)
 
s = []
h.times do
  s << gets.chomp.chars
end
 
di = [-1, 0, 1, 0]
dj = [0, -1, 0, 1]
dir = di.zip(dj)
 
max = 0
 
# ある点をスタート地点とみなし、そこから最も遠い点にいたるまでの距離を出す
# スタート可能なすべての点についてこれを行う
h.times.each do |si|
  w.times.each do |sj|
    next if s[si][sj] == '#' # スタート地点にできない
    
    # スタート地点からの距離をメモ
    # keyは地点のtuple
    dd = {}
 
    queue = []
    queue << [si, sj]
    dd[[si, sj]] = 0
 
    while !queue.empty? do
      d = queue.shift
      # 現在地から上下左右4方向をチェックし、進める地点をqueueに入れる
      dir.each do |x, y|
        ni = d[0] + x
        nj = d[1] + y
        
        if ((0 <= ni && ni < h) && (0 <= nj && nj < w)) && s[ni][nj] != '#'
          unless dd[[ni, nj]]
            dd[[ni, nj]] = dd[d] + 1
            queue << [ni, nj]
          end
        end
      end
    end
    max = [dd.values.max, max].max
  end
end
 
puts max

Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
inline long long add(long long a,long long b) 
{
    long long ADD = (a % mod + b % mod) % mod;
    return ADD;
}
inline long long mul(long long a,long long b) 
{
    long long MUL = (a % mod * b % mod) % mod;
    return MUL;
}
long long fastpow(long long x,long long y)
{
    long long res = 1;
    x = x % mod;
    while (y > 0)
    {
        if(y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}
long long inv(long long x)
{
    return fastpow(x,mod - 2);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int testCases = 1;
   // cin >> testCases;
    
    while(testCases--)
    {
        
        int n,i,j;
        cin >> n;
        int a[n];
        int sum = 0;
        int pro = 0;
        for(i = 0;i < n;++i)
			{
				cin >> a[i];
				sum = add(sum,a[i]);
				int res = mul(a[i],a[i]);
				pro = add(pro,res);
				//pro = pro % mod + ((a[i] % mod * a[i] % mod) % mod) % mod;
			}
			
		int ans = mul(sum,sum);
		
		ans = (ans - pro + mod) % mod;
		
		ans = mul(ans,inv(2LL));
		//ans = (ans % mod * fastpow(2,mod - 2) % mod) % mod;
		
		cout << ans;
			
        cout << '\n';
    }
    
}


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

int main(){
  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int x = x2;
  int y = y2;

  int dx = x2 - x1;
  int dy = y2 - y1;

  for(int i=0; i < 2; i++){
    swap(dx,dy);
    dx = -dx;
    x += dx;
    y += dy;
    cout << x << " " << y;
    if(i==0) cout << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;


class Main {
    static final long MOD=1000000007;
    static int x,y,z;
    static int nextState(int state,int j){
        int ans=1;
        for(int i=0;i<x;++i){
            if((state&1<<i)!=0&&i+j<=x)
                ans|=1<<(i+j);
        }
        for(int i=x;i<x+y;++i){
            if((state&1<<i)!=0&&i+j<=x+y)
                ans|=1<<(i+j);
        }
        for(int i=x+y;i<x+y+z;++i){
            if((state&1<<i)!=0&&i+j<=x+y+z)
                ans|=1<<(i+j);
        }
        if((state&1<<(x+y+z))!=0)ans|=1<<(x+y+z);
        return ans;
    }
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        x=sc.nextInt();
        y=sc.nextInt();
        z=sc.nextInt();
        long[][]dp=new long[2][1<<18];
        int[][]ns=new int[18][1<<18];
        dp[0][1]=1;
        for(int b=0;b<1<<18;++b)
            for(int j=1;j<=10;++j)
                ns[j][b]=nextState(b,j);
        for(int i=0;i<n;++i){
            int u=i%2;
            int nxt=1-u;
            Arrays.fill(dp[nxt],0);
            for(int b=0;b<1<<18;++b){
                for(int a=1;a<=10;++a){
                    int nss=ns[a][b];
                    dp[nxt][nss]+=dp[u][b];
                    dp[nxt][nss]%=MOD;
                }
            }
        }
        long ans=0;
        for(int b=1<<(x+y+z);b<1<<(x+y+z+1);++b)
            ans=(ans+dp[n%2][b])%MOD;
        out.println(ans);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 55884
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

int N;

int main() {
    cin >> N;
    vector<int> cnt(1e5 + 1);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        cnt[a]++;
    }
    int tmp = cnt[0] + cnt[1] + cnt[2];
    int ans = tmp;
    for (int i = 3; i < 1e5 + 1; i++) {
        tmp += cnt[i] - cnt[i - 3];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}



Measured memory_bytes: 640
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  if (n % 2 == 0)cout << n / 2 - 1 << endl;
  else cout << n / 2 << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int h,n;
	cin>>h>>n;
	vector<int>arr(n);
	ll sum=0;
	for(int i=0; i<n; i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	if(sum>=h)
	 cout<<"Yes";
	else
	 cout<<"No";
	return 0;
	
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5; 
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}

ll raise(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}


int n, x[102], mi = INT_MAX, s=0;

void solve()
{
    cin >> n; for (int i=0; i<n; ++i) cin >> x[i];
    for (int i=-200; i<=200; i++) {
        s=0;
        for (int j=0; j<n; j++) s += raise(x[j]-i,2);
        mi = min(mi, s);
    }nout(mi);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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 ll MRINF = 5000000000000000;

int main() {

  ll N, P;
  cin >> N >> P;
  map<ll, ll> res;
  ll P_ = P;

  if(N==1){
    cout << P << endl;
    return 0;
  }

  for (long long a = 2; a*a <= P_; ++a) {
      if (P % a != 0) continue;
      long long ex = 0; // 指数

      // 割れる限り割り続ける
      while (P % a == 0) {
          ++ex;
          P /= a;
      }

      // その結果を push
      res[a] = ex;
  }
  ll ans = 1;
  for(auto itr=res.begin(); itr != res.end(); itr++){
    for (int j = 0; j < itr->second/N; ++j)ans *= itr->first;
    // if(itr->second >= N) ans *= itr->first;
    // cout << itr->first << " " << itr->second << endl;
  }
  cout << ans << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1000000007;

int main(){
    ll N,K;
    cin >> N >> K;
    if(N>K){
        ll a=N/K;
        ll ans1 = min( abs(N-(K*a)), abs(N-(K*(a+1))) );
        cout << min(N,ans1);
    }else if(N<K){
        cout << min(N,abs(N-K));
    }else if(N==K){
        cout << 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ARRAY_LEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
using namespace std;
int main(void){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  vector<int> xx;
  vector<int> yy;
  REP(i,n){
    int a;
    cin >> a;
    xx.push_back(a);
  }

  REP(i,m){
    int b;
    cin >> b;
    yy.push_back(b);
  }


  int xmax = *std::max_element(xx.begin(), xx.end());
  int ymin = *std::min_element(yy.begin(), yy.end());

  if(max(x,xmax) < min(y,ymin)){
    cout << "No War" << endl;
  }else{
    cout << "War" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

struct Edge
{
  i64 to, silver, time;
};

struct Ex
{
  i64 silver, time;
};

int main()
{
  i64 N, M, S;
  cin >> N >> M >> S;
  vector<Edge> edge[N];
  for (i64 i = 0; i < M; i++)
  {
    i64 U, V, A, B;
    cin >> U >> V >> A >> B;
    U--;
    V--;
    edge[U].push_back({V, A, B});
    edge[V].push_back({U, A, B});
  }
  vector<Ex> ex(N);
  for (i64 i = 0; i < N; i++)
    cin >> ex[i].silver >> ex[i].time;
  vector<vector<i64>> far(N, vector<i64>(2501, 1e18));
  priority_queue<pair<i64, pair<i64, i64>>, vector<pair<i64, pair<i64, i64>>>, greater<>> que;
  S = min(S, 2500LL);
  far[0][S] = 0;
  que.push({0, {0, S}});
  while (que.size())
  {
    pair<i64, pair<i64, i64>> p = que.top();
    que.pop();
    i64 time = p.first, now = p.second.first, silver = p.second.second;
    if (far[now][silver] < time)
      continue;
    for (Edge i : edge[now])
      for (i64 j = 0; silver + j * ex[now].silver - i.silver <= 2500; j++)
      {
        i64 s = silver + j * ex[now].silver - i.silver;
        if (0 <= s)
          far[now][s] = min(far[now][s], far[now][silver] + ex[now].time * j);
        if (0 <= s && far[now][silver] + ex[now].time * j + i.time < far[i.to][s])
        {
          far[i.to][s] = far[now][silver] + ex[now].time * j + i.time;
          que.push({far[i.to][s], {i.to, s}});
        }
      }
  }
  for (i64 i = 1; i < N; i++)
  {
    i64 ans = 1e18;
    for (i64 j = 0; j <= 2500; j++)
      ans = min(ans, far[i][j]);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 28872
using System;

namespace vscode
{
    class Program
    {
        static void Main(string[] args)
        {
            int length = int.Parse(Console.ReadLine());
            string testee = Console.ReadLine();

            int cntAbc = matchWords(testee.ToCharArray(), "ABC".ToCharArray(), length);

            Console.WriteLine(cntAbc);
        }

        static int matchWords(char[] testee, char[] matcher, int length) {
            if (length < 3 || length > 50) return 0;

            int found = 0;
            int pos=0;
            int vurpos=0;
            
            while(pos <= length-1) {
                if (testee[pos] == matcher[vurpos]) {
                    vurpos++;
                    if(vurpos == 3){
                        found++;
                        vurpos=0;
                    }
                    
                } else {
                     if (testee[pos] == matcher[0]) {
                         vurpos=1;
                     }
                     else
                     {
                        vurpos=0;
                     }
                }
                // matcher
               
                pos++;
            }
            return found;
        }
    }
}

Measured memory_bytes: 27488
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split()))for _ in range(d)]
t=[int(input())-1 for _ in range(d)]
x=[0]*26
ans=0
for i in range(d):
  v=t[i]
  ans+=s[i][v]
  for j in range(26):
    if j==v:x[j]=0
    else:x[j]+=1
    ans-=c[j]*x[j]
  print(ans)

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

int main(void) {
    int N,D;
    cin >> N >> D;

    if(N % (2 * D + 1)) cout << ((N/((2*D)+1)) + 1) << endl;
    else cout << (N/((2*D)+1)) << endl;
    return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

// vectorからindex番目の要素を削除する
template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A;
  rep(i, H) {
    vector<char> Aa;
    rep(j, W) {
      char a;
      cin >> a;
      Aa.push_back(a);
    }
    A.push_back(Aa);
  }

  bool w_ng = true;
  bool h_ng = true;
  while (w_ng || h_ng) {
    w_ng = false;
    h_ng = false;
    rep(i, H) {
      set<char> S;
      rep(j, W) S.insert(A[i][j]);
      if (S.size() == 1 && S.count('.') == 1) {
        remove(A, i);
        H--;
        h_ng = true;
      }
    }

    rep(i, W) {
      set<char> S;
      rep(j, H) S.insert(A[j][i]);
      if (S.size() == 1 && S.count('.') == 1) {
        rep(j, H) remove(A[j], i);
        W--;
        w_ng = true;
      }
    }
  }

  rep(i, H) {
    rep(j, W) { cout << A[i][j]; }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b){
    if(b < a){
        a = b;
        return true;
    }
    return false;
}

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

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

    if(a < 10 && b < 10){
        cout << a * b << endl;
    }else{
        cout << -1 << endl;
    }

    cout << flush;

    return 0;
}

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

long long A, C, B;
int main(){
	cin >> A >> B >> C;
	if(A == B && A != C) {
		cout << "Yes" << endl;
	} else if(B == C && A != C) {
		cout << "Yes" << endl;
	} else if(A == C && C != B) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int main()
{
    int sum;
    int N,Y;

    cin >> N >> Y;
    int flag = 0;

    for(int x=0; x<=N; x++){
        for(int y=0; y<=N-x; y++){
            sum = 10000*x + 5000*y;
            int z = N - (x + y);

            sum = 10000*x + 5000*y + 1000*z;
            if(sum == Y){
                cout << x << ' ' << y << ' ' << z << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
  int N,a[3],i;
  scanf("%d",&N);
  for(i=0;i<3;i++) {
    a[i]=N%10;
    N=(N-a[i])/10;
    if(a[i]==1) {a[i]=9;}
    else{a[i]=1;}
  }
  printf("%d",a[2]*100+a[1]*10+a[0]);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib> 
#include<cstring>
using namespace std;
int read()
{
	int x=0,f=1; char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1; c=getchar();}
	while (c>='0'&&c<='9') {x=x*10+c-'0';c=getchar();}
	return x*f;
}
int n,a,b,MAX=0,MIN=1009999999;
int main()
{
	n=read();
	for (int i=1; i<=n; i++) {
		a=read(); b=read();
		if (a>MAX) MAX=a;
		if (b<MIN) MIN=b;
	}
	cout<<MAX+MIN;
	return 0;
}


Measured memory_bytes: 256
import sys
import math as mt
#input=sys.stdin.buffer.readline  
t=1
#t=int(input())
for _ in range(t):
    n=int(input())
      
    #x,y,n=map(int,input().split())
    #l=list(map(int,input().split()))
    l=['AC', 'WA', 'TLE','RE']
    d={}
    for i in l:
        d[i]=0
    for i in range(n):
        s=input()
        d[s]+=1
    for i in l:
        print(i,'x',d[i])

Measured memory_bytes: 69872
#include "bits/stdc++.h"
using namespace std;


bool f(string& s) {
    int n = s.size();
    if (n & 1) return false;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[i + n / 2]) return false;
    }
    return true;
}


int main() {
    string s;
    cin >> s;
    int n = s.size();

    int ans = 1;
    for (int i = 1; i < n - 1; i++) {
        string t = "";
        for (int j = 0; j < i; j++) t += s[j];
        if (f(t)) ans = t.size();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    if (b == 0)
        return a;

    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

int main()
{
    int n;
    cin >> n;
    vll a(n);
    rep(i, 0, n) cin >> a[i];

    vll l(n + 2), r(n + 2);
    l[0] = 0;
    r[n + 1] = 0;
    rep(i, 0, n + 1)
    {
        l[i + 1] = gcd(l[i], a[i]);
        //cout << l[i + 1] << " ";
    }
    //cout << endl;

    for (int i = n - 1; i >= -1; i--)
    {
        r[i + 1] = gcd(r[i + 2], a[i]);
        //cout << r[i + 1] << " ";
    }

    ll m = 0;
    rep(i, 0, n + 2)
    {
        m = max(m, gcd(l[i], r[i + 2]));
        //cout << "m=" << m << endl;
    }
    cout << m << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back

#define debug(x) cerr << #x << " = " << x << " "


vector<int> move_of_string(string s, char left, char right)
{
  vector<int> ret;
  for (auto e : s)
    ret.pb(-(e==left) + (e==right));
  return ret;
}
bool solve(string s, string t, char left, char right, int range, int pos)
{
  vector<vector<int> > v = {move_of_string(s, left, right), move_of_string(t, left, right)};
  int n = v.front().size();
  ii valid = mp(1, range);
  for (int i = n-1; i >= 0; --i)
    for (int p = 1; p >= 0; --p)
      if (v[p][i] != 0)
        {
          if (v[p][i] == 1)
            if (p == 1) valid.first -= 1;
            else valid.second -= 1;
          else
            if (p == 1) valid.second += 1;
            else valid.first += 1;

          valid.first = max(1, valid.first);
          valid.second = min(range, valid.second);
          if (valid.first > valid.second) return false;
        }
  bool ret = valid.first <= pos && pos <= valid.second;
  return ret;
}

int main()
{
  int h, w, n, x, y;
  cin >> h >> w >> n >> x >> y;
  string s, t;
  cin >> s >> t;
  cout << ((solve(s, t, 'L', 'R', w, y) && solve(s, t, 'U', 'D', h, x)) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=1; i<=(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int sub_gcd(int x,int y) {
  if(y==0) return x;
  return gcd(y,x%y);
}

int gcd(int x,int y,int z) {
    return sub_gcd(x,sub_gcd(y,z));
}

int main() {
    int K;
    cin>>K;
    int ans=0;
    for(int i=1; i<=K; i++) {
        for(int j=1; j<=K; j++) {
            for(int k=1; k<=K; k++) {
                ans+=gcd(i,j,k);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    private static String RED = "red";
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = Integer.valueOf(sc.nextLine());
        String input = sc.nextLine();
        if (num >= 3200) {
            System.out.println(input);
        } else {
            System.out.println(RED);
        }
        sc.close();
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int p[100000],pcnt[100001],a[100001],b[100001],c[100001];
main(void){
	int n,m,i,ima,x,t,tt,sum;
	cin>>n>>m;
	for(i=0;i<m;i++) cin>>p[i];
	ima=p[0];
	for(i=0;i<=m;i++) pcnt[i]=0;
	for(i=1;i<m;i++){
		x=p[i]-ima;
		if(x>=0){
			pcnt[ima]++;
			ima=ima+x;
			pcnt[ima]--;
		}
		else{
			pcnt[ima]--;
			ima=ima+x;
			pcnt[ima]++;
		}
	}
	for(i=1;i<n;i++) pcnt[i]=pcnt[i]+pcnt[i-1];
	sum=0;
	for(i=1;i<n;i++) cin>>a[i]>>b[i]>>c[i];
	for(i=1;i<n;i++){
		t=c[i]+b[i]*pcnt[i]; tt=a[i]*pcnt[i];
		if(t<tt) sum+=t;
		else sum+=tt;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 7024
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n][3];
    int dp[n][3];
    for(int i=0;i<n;i++){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    memset(dp,0,sizeof(dp));
    //dp[i][0] maximum happiness when last turn was swimming;
    //dp[i][1] maximum happiness when last turn was catching bugs;
    //dp[i][2] maximum happiness when last turn was doing hw ;

    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=1;i<n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+a[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+a[i][2];
    }

    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}


Measured memory_bytes: 4992
import java.util.Scanner;
import java.util.stream.LongStream;

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

        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long E = sc.nextLong();

        System.out.println(solve(N, A, B, C, D, E));

        sc.close();
    }

    static long solve(long N, long A, long B, long C, long D, long E) {
        return (N - 1) / LongStream.of(A, B, C, D, E).min().getAsLong() + 5;
    }
}

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

int main(){
    string s;
    long ssize;

    cin >> s;
    ssize=s.size();
    s += "AB";

    for(long i=0;i<ssize;i++){
        if(s[i]==s[i+1]){
            cout << i+1 << " " << i+2 << "\n";
            return 0;
        }
        if(s[i]==s[i+2]){
            cout << i+1 << " " << i+3 << "\n";
            return 0;
        }
    }

    cout << -1 << " " << -1 << "\n";
    return 0;
}

Measured memory_bytes: 512
s = input()
ans = 0
flag = 0 # ">"=1 "<" = 0
x = s[0]
r = 0 #"<"
l = 0 #">"

if x==">":
    flag = 1
    l += 1
else:
    r += 1

for i in range(1,len(s)):
    if s[i]==x:
        if flag==1:
            l += 1
        else:
            r += 1
    else:
        if flag==1:
            ans += sum(range(max(r,l)+1)) + sum(range(min(r,l)))
            l = 0
            r = 1
            x = s[i]
            flag = 0
        else:
            x = s[i]
            l += 1
            flag = 1
ans += sum(range(max(r,l)+1)) + sum(range(min(r,l)))
print(ans)


Measured memory_bytes: 44984
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string ab = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string as = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------
int main() {

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

  int x;
  int y;
  if(a>=b) {
    x = b;
    y = a;
  }else {
    x = a;
    y = b;
  }

  rep(i, y) {
    cout << x;
  }
  cout << endl;

  return 0;
}



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

int fabs (int n) {
    if (n < 0) return -n;
    else return n;
}

int main() {
    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for (int i=0; i<n; i++) cin >> p[i];
    for (int i=0; i<n; i++) cin >> q[i];
    vector<int> pc(n), qc(n);
    pc = p; qc = q;
    sort(pc.begin(), pc.end());
    sort(qc.begin(), qc.end());
    int a, b;
    int cnt = 0;
    do {
        cnt++;
        if (pc == p) {
            a = cnt;
            break;
        }
    } while (next_permutation(pc.begin(), pc.end()));
    cnt = 0;
    do {
        cnt++;
        if (qc == q) {
            b = cnt;
            break;
        }
    } while (next_permutation(qc.begin(), qc.end()));
    cout << fabs(a-b) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define SIZE 100

int main(void){
    int table_height,table_width;
    char table[SIZE][SIZE];
    int i,j,k,l,m,n,x,y;
    int count = 0;

    scanf("%d %d",&table_height,&table_width);
    for(i=0;i<table_height;i++){
        for(j=0;j<table_width;j++){
            scanf(" %c",&table[i][j]);
        }
    }
    for(i=0;i<table_height;i++){
        for(j=0;j<table_width;j++){
            if(table[i][j] == '.'){
                count++;
                if(count == table_width){
                    for(k=0;k<table_width;k++){
                        table[i][k] = 'x';
                    }
                }
            }
        }count = 0;
    }
    for(l=0;l<table_width;l++){
        for(m=0;m<table_height;m++){
            if(table[m][l] == '.' || table[m][l] == 'x'){
                count++;
                if(count == table_height){
                    for(n=0;n<table_height;n++){
                        table[n][l] = 'x';
                    }
                }
            }
        }count = 0;
    }

    for(x=0;x<table_height;x++){
        for(y=0;y<table_width;y++){
            if(table[x][y] != 'x'){
            printf("%c",table[x][y]);
            }
        }
        printf("\n");
    }
    return 0;
}

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

#define scd second
#define fst first
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef list<int> lint;
typedef list<ll> llong;
typedef list<pii> lpii;
typedef list<pll> lpll;
typedef list<lint> llint;
typedef list<llong> lllong;

int const N=1e6+100;
ll const LINF=numeric_limits<long long int>::max();
int const INF=numeric_limits<int>::max();
int const BN = 31;

ll gcd(ll a, ll b){
	return b ? gcd(b,a%b) : a;
}

ll pow_mod(ll a, ll e, ll m){
	ll res=1;
	while(e){
		if(e&1) res=res*a%m;
		a=a*a%m;
		e>>=1;
	}
	return res;
}

ll inv_mod(ll b, ll m){
	b%=m;
	ll x=0, y=1, r, q, a=m;
	while(b){
		q=a/b;
		r=a%b;
		a=b;
		b=r;
		r=x;
		x=y;
		y=r-q*y;
	}
	x+=m;
	return x%m;
}

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

	int m, d, ans=0;
	cin>>m>>d;
	for(int i=1; i<=m; i++){
		for(int j=1; j<=d; j++){
			if(j%10>=2 && j/10>=2 && (j%10)*(j/10)==i){
				ans++;
			}
		}
	}

	cout<<ans<<endl;
}

Measured memory_bytes: 256
n,m=map(int, input().split())
a=list()
b=list()
for i in range(n):
    x=list(map(int,input().split()))
    a.append(x)
for i in range(m):
    y=int(input())
    b.append(y)
for i in range(n):
    ans=0
    for j in range(m):
        ans+=a[i][j]*b[j]
    print(ans)



Measured memory_bytes: 6012
#include<stdio.h>
int main()
{
	int a,b,n;
	scanf("%d%d%d",&n,&a,&b);
	a=a-n;b=b-n;
	if(a<0)
	a=-1*a;
	if(b<0)
	b=b*-1;
	if(a<b)
	printf("A");
	else
	printf("B");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  string s;
  vector<string> strings;
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> s;
    strings.push_back(s);
  }
  
  for (auto i : strings) {
    if (count(strings.begin(), strings.end(), i)>1) {
      cout << "No";
      return 0;
    }
  }
        
  for (int i=1; i<n; i++) {
    if (strings[i].substr(0, 1)!=strings[i-1].substr(strings[i-1].size()-1, 1)) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, k;
    cin >> n >> k;
    vec a(n);
    rep(i, n) cin >> a[i];

    vec s(n+1);
    rep(i, n) s[i+1] = (s[i] + a[i]);

    vec t(n+1);
    rep(i, n+1) t[i] = (s[i] - i) % k;
    rep(i, n+1) t[i] = ((t[i] % k) + k) % k;

    lint res = 0;
    map<int, int> mp;
    queue<int> que;

    rep(i, n+1) {
        res += mp[t[i]];
        mp[t[i]]++;

        que.push(t[i]);
        if (que.size() >= k) {
            mp[que.front()]--;
            que.pop();
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
#define N 500001
using namespace std;
typedef long long ll;
int A[N];

int main(){
  int n;
  cin>>n;
  for(int i=0;i<3*n;i++)scanf("%d",&A[i]);
  
  ll sumA = 0;
  priority_queue <ll,vector<ll>,greater<ll> > Q;
  for(int i=0;i<n;i++) sumA+=A[i],Q.push(A[i]);

  map<int,int> M;
  unordered_map<int,int>used;
  for(int i=n;i<3*n;i++)M[A[i]]++;
  
  ll sumB=0;
  auto it = M.begin();
  for(int i=0;i<n;i++){
    int val = it->first;
    int &cnt = it->second;
    sumB+=val;
    used[val]++;
    cnt--;
    if(cnt==0)M.erase(it++);
  }


  ll ans = sumA - sumB;
  for(int i=n;i<2*n;i++){
    int val = A[i];
    if(Q.top()<val){
      sumA=sumA-Q.top()+val;
      Q.pop();
      Q.push(val);
    }
    int flg = M.count(val);
    
    if(flg&&--M[val]==0)M.erase(val);
    else if(flg==0&&used[val]){
      used[val]--;
      it=M.begin();
      int v = it->first;
      used[v]++;
      sumB=sumB-val+v;
      if(--it->second==0)M.erase(it);
    }
    ans = max(ans,sumA-sumB);
  }
  cout<<ans<<endl;

  return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int l, r, d;
	cin >> l >> r >> d;
	int ans = 0;
	for(int i = l; i <= r; ++i){
		if(i%d == 0) ++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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; }

int main()
{
    string s, t; cin >> s >> t;
    if(s.size() != t.size()-1) pr("No");
    else{
        bool flag = false;
        rep(i, s.size()) if(s[i]!=t[i]) {pr("No"); flag = true; break;}
        if(!flag) pr("Yes");
    }
    return 0;}

Measured memory_bytes: 3604
a,b,c = map(int,input().split(" "))
count = 0
t = "A"
while True:
    count += 1
    if t == "A":
        b += a // 2
        a //= 2
        t = "B"
    else:
        a += b // 2
        b //= 2
        t = "A"
    if count == c:
        print(a,b)
        exit()
    elif a * 2 == b or b * 2 == a:
        break
if (c - count) % 2 == 0:
    print(a,b)
else:
    print(b,a)

Measured memory_bytes: 3064
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int m = read.to!int;
	int d = read.to!int;
	
	int ans = 0;
	foreach(x; 1 .. m + 1){
		foreach(y; 1 .. d + 1){
			int y1 = y / 10;
			int y2 = y % 10;
			if(y1 >= 2 && y2 >= 2 && x == y1 * y2){
				log(x, y);
				ans += 1;
			}
		}
	}
	
	ans.writeln;

}


Measured memory_bytes: 384
n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(1,n-1):
  if p[i] != min(p[i-1],p[i],p[i+1]) and p[i] != max(p[i-1],p[i],p[i+1]):
    cnt+=1
print(cnt)

Measured memory_bytes: 61760
#include<stdio.h>
int main(void)
{
	int n,a,b,c,d,ans,ans2;
	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
	ans=n/a*b;
	if(n%a>0){
		ans=(n/a+1)*b;
	}
	ans2=n/c*d;
	if(n%c>0){
		ans2=(n/c+1)*d;
	}
	if(ans<ans2){
		printf("%d\n",ans);
	}
	else{
		printf("%d\n",ans2);
	}
	return 0;
}


Measured memory_bytes: 2148
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,M,X,Y,x[103],y[103];
	cin>>N>>M>>X>>Y;
	for (int i=0;i<N;i++)
		cin>>x[i];
	for (int i=0;i<M;i++)
		cin>>y[i];
	x[N]=X;
	y[M]=Y;
	sort (x,x+N+1);
	sort (y,y+M+1);
	if (x[N]>=y[0]){
		cout<<"War";
		return 0;
	}
	cout<<"No War";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}

void solve(){
    int n;
    read(n);
    vector<ll>  x(n), y(n);
    REP(i,n){
        ll a, b;
        read(a, b);
        x[i] = a ;
        y[i] = b;
    }
    vector<ll> sum1(n) ,sum2(n);
    REP(i,n){
        sum1[i] = x[i] + y[i];
        sum2[i] = x[i] - y[i];
    }
    sort(sum1.begin(), sum1.end());
    sort(sum2.begin(), sum2.end());
    ll ans = 0;
    ll dist1 = sum1[n-1] - sum1[0];
    ll dist2 = sum2[n-1] - sum2[0];
    ans = max({dist1, dist2});
    cout << ans << endl;

}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}



Measured memory_bytes: 9532
a = input()
len_a = len(a)
if len_a % 2 == 0:
    a1 =  a[:len(a)//2]
    a2 =  a[len(a)//2:][::-1]
else:
    a1 =  a[:len(a)//2]
    a2 =  a[len(a)//2+1:][::-1]
ans = 0
for i in range(len(a1)):
    ans += int(a1[i] != a2[i])
print(ans)

Measured memory_bytes: 3064