akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

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

		String line1 = sc.nextLine();
		String line2 = sc.nextLine();

		int N = Integer.parseInt(line1);
		int K = Integer.parseInt(line2);

		int s = 1;

		int a = s;
		int b = s;

		for (int i = 0; i < N; i++) {
			a = s;
			b = s;
			if (getA(a) <= getB(b, K)) {
				s = getA(s);
			} else {
				s = getB(s, K);
			}
		}

		System.out.println(s);
	}

	public static int getA(int a) {
		a = a*2;
		return a;
	}

	public static int getB(int b, int k) {
		b = b+k;
		return b;
	}
}

Measured memory_bytes: 21844
void main(){
	int k,a,b;
	k = _scan();
	scanf("%d %d", &a, &b);

	for(int i=a; i<=b; i++){
		if( i%k==0 ){
			writeln("OK");
			return;
		}
	}
	writeln("NG");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2668
//Counting Sort

#define k 10001

#include<stdio.h>
#include<stdlib.h>

int main(void){
  int n,C[k];
  int *A,*B;
  int i;

  scanf("%d",&n);

  A=(int*)malloc((n+1)*sizeof(int));
  B=(int*)malloc((n+1)*sizeof(int));

  //入力
  for(i=1;i<=n;i++) scanf("%d",&A[i]);

  //初期化
  for(i=0;i<k;i++) C[i]=0;
  
  for(i=1;i<=n;i++) C[A[i]]++;

  for(i=1;i<k;i++) C[i]+=C[i-1];

  for(i=n;i>0;i--){
    B[C[A[i]]]=A[i];
    C[A[i]]--;
  }

  //出力
  printf("%d",B[1]);
  for(i=2;i<=n;i++) printf(" %d",B[i]);
  printf("\n");

  free(A);
  free(B);

  return 0;
}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char []s = sc.next().toCharArray();
		long k = sc.nextLong();
		
		int count = 0 ;
		
		for(int i = 0; i<s.length; i++) {
			if(s[i] == '1') {
				count++;
			}
			else {
				break;
			}
		}
		if(k > count)
			System.out.println(s[count]);
		if(k <= count)
			System.out.println(1);
		
	}
	

}


Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e5+100;
int n;
int a[maxn];
int b[maxn];


void solve()
{
	for(int i=1;i<=n;i++)
		b[i]=abs(a[i]-a[i-1])+b[i-1];
	for(int i=1;i<n;i++)
	{
		printf("%d\n",b[n]-(b[i+1]-b[i-1])+abs(a[i+1]-a[i-1])+(abs(a[n])));
	}
	printf("%d\n",b[n-1]+abs(a[n-1]));
}


int main()
{
	//freopen("093C.txt","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	solve();
	return 0;
}

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

int main(){
  int n; cin >> n;
  string s_; cin >> s_;
  vl s(n); rep(i,n)s[i] = s_.at(i) - '0';
  vector<bool> r_100(10,true);
  vector<bool> r_10(10,true);
  vector<bool> r_1(10,true);
  ll ans = 0;
  rep(i,n){
    if(r_100[s[i]]){
      r_100[s[i]] = false;
      for(int j = i + 1;j<n;j++){
        if(r_10[s[j]]){
          r_10[s[j]] = false;
          for(int k = j + 1;k<n;k++){
            if(r_1[s[k]]){
              r_1[s[k]] = false;
              ans++;
            }}rep(k,10)r_1[k] = true;
        }}rep(j,10)r_10[j] = true;
    }}
  cout << ans << endl;
}

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

int main(){
  ll n;
  std::cin >> n;
  string s;
  std::cin >> s;



  int r=0;
  rep(i,n){
    if(s[i]=='R')r++;
  }

  int ans=0;
  rep(i,r){
    if(s[i]=='W')ans++;
  }

  std::cout << ans << '\n';



  return 0;
}


Measured memory_bytes: 3748
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TypeFamilies #-}
import           Data.Maybe
import           Data.Int
import           Data.List
import           Data.Char
-- import qualified Data.Vector.Unboxing as VU
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import           Data.List (scanl')
import           Data.IORef
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Control.Monad.Primitive
import           Control.Applicative
import           Debug.Trace
import           Text.Printf

main = do
  a <-  ord <$> getChar

  putStrLn $ if a < 97 || 122 < a then "A" else "a"

readInt = BS.readInt . BS.dropWhile isSpace
getVector f = VU.unfoldr f <$> BS.getLine
getIntVector = getVector readInt
getBSVector = getVector BS.uncons
getInt = readLn :: IO Int
getInt2Tuple = (\vec -> (vec VU.! 0, vec VU.! 1)) <$> getIntVector
getInt3Tuple = (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2)) <$> getIntVector


Measured memory_bytes: 3736
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
	let mut vec:Vec<i32> = vec!();
	let s = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<i32>>();
	let N = s[0];
	let X = s[1];
	let mut c = 0;
	for _ in 0..N {
		let m = read_line().parse::<i32>().unwrap();
		c+=m;
		vec.push(m);
	}

	if X-c == 0 {
		println!("{}",N);
	}else{
		let x = X-c;
		let min = vec.iter().min().unwrap();
		println!("{}",N+(x/min));
	}

}


Measured memory_bytes: 4352
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//Hang in there!

using namespace std;


int main() {
	int N;
	cin >> N;
	if (N % 2 == 0) {
		cout << N << endl;
	}
	else {
		cout << 2 * N << endl;
	}
}



Measured memory_bytes: 256
import sys


def main():
    sec = int(sys.stdin.readline())
    hour = int(sec / 3600)
    sec = sec % 3600
    minute = int(sec / 60)
    sec = sec % 60
    print("{0}:{1}:{2}".format(hour,minute,sec))
    return


if __name__ == '__main__':
    main()



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

class Progaram
{
    static void Main(string[] args)
    {
        var x = int.Parse(Console.ReadLine());
        var all = 0;
        all += (x / 500) * 1000;
        x = x % 500;
        all += (x / 5) * 5;
        x = x % 5;
        Console.WriteLine(all);
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <vector>

using namespace std;

int main () {
    int N;
    cin >> N;
    vector <int> ans(N);
    int A;
    for (int i = 1; i <= N; i++) {
        cin >> A;
        ans[A-1] = i;
    }

    for (int i = 0; i < N; i++) cout << ans[i] << " ";
}

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

int main() {
	int n, m, x;
	scanf("%d %d %d", &n, &m, &x);
	vector<int> a(n+1);
	for(int i = 0; i < m; i++) {
		int t;
		scanf("%d", &t);
		a[t] = 1;
	}
	int mn = 1e9;
	int sum = 0;
	for(int i = x-1; i >= 0; i--) {
		sum += a[i];
	}
	mn = min(mn, sum);
	sum = 0;
	for(int i = x+1; i <= n; i++) {
		sum += a[i];
	}
	mn = min(mn, sum);
	printf("%d\n", mn);
}


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

using namespace std;

int main ()
{
	int n, k, q;
	cin >> n >> k >> q;
	int a[n+1] = {0};
	int cek;
	for (int i=1; i<=q; i++){
		cin >> cek;
		a[cek]++;
	}
	for (int i=1; i<=n; i++){
		if (a[i]-q+k > 0){
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 1024
from collections import Counter

N = int(input())
*l, = map(int, input().split())
c = Counter(l)

v = 0
for i in c.values():
    v += i*(i-1)//2

for i in l:
    print(v-(c[i]*(c[i]-1)//2)+((c[i]-1)*(c[i]-2)//2))

Measured memory_bytes: 26772
#include<stdio.h>
#include<stdlib.h>

#define M 10000
#define INF 200000 

typedef struct{
  int go,back,cost;
}D;

int n;
int d[M];
D A[500000];

void root(int x){
  int i;
  int flag = 0;

  d[0] = 0;

  while(flag != 1){
    flag = 1;
    for(i=0; i<x; i++){
      if(A[i].cost + d[A[i].back] < d[A[i].go]){
	d[A[i].go] = A[i].cost + d[A[i].back];
	flag = 0;
      }
    }
  }

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

}

int main(){
  int i,j;
  int u,k,cnt=0;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    d[i] = INF;
  }

  for(i=0; i<n; i++){
    scanf("%d %d",&u,&k);
    for(j=0; j<k; j++){
      A[cnt].back = u;
      scanf("%d %d",&A[cnt].go,&A[cnt].cost);
      cnt++;
    }
  }

  root(cnt);

  return 0;
}



Measured memory_bytes: 7660
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N, K, R, S, P;
  cin >> N >> K >> R >> S >> P;
  string T;
  cin >> T;
  vector<vector<char>> vec(K,vector<char>(0));
  for(int i=0; i<N; i++){
    vec.at(i%K).push_back(T.at(i));
  }
  
  int64_t r, s, p;
  r = P;
  s = R;
  p = S;
  
  int64_t ans = 0;
  
  
  for(int i=0; i<K; i++){
    int64_t ans_x = 0;
    if(vec.at(i).size() == 0){
      continue;
    }
    else if(vec.at(i).size() == 1){
      if(vec.at(i).at(0) == 'r'){
        ans += r;
      }
      else if(vec.at(i).at(0) == 's'){
        ans += s;
      }
      else{
        ans += p;
      }
    }
    else{
      vector<int64_t> dp(vec.at(i).size()+1);
      if(vec.at(i).at(0) == 'r'){
        dp.at(1) = r;
      }
      else if(vec.at(i).at(0) == 's'){
        dp.at(1) = s;
      }
      else{
        dp.at(1) = p;
      }
      for(int j=1; j<vec.at(i).size(); j++){
        if(vec.at(i).at(j) != vec.at(i).at(j-1)){
          if(vec.at(i).at(j) == 'r'){
           dp.at(j+1) = r + dp.at(j);
          }
          else if(vec.at(i).at(j) == 's'){
            dp.at(j+1) = s + dp.at(j);
          }
          else{
            dp.at(j+1) = p + dp.at(j);
          }
        }
        else{
          if(vec.at(i).at(j) == 'r'){
           dp.at(j+1) = max(dp.at(j),r + dp.at(j-1));
          }
          else if(vec.at(i).at(j) == 's'){
           dp.at(j+1) = max(dp.at(j),s + dp.at(j-1));
          }
          else{
           dp.at(j+1) = max(dp.at(j),p + dp.at(j-1));
          }
        }
      }
      ans += dp.at(vec.at(i).size());
    }
  }
  cout << ans << endl;  
}

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

int cnt[10];

int main()
{
	ios::sync_with_stdio(false);
	for (int i = 0; i < 4; i++)
	{
		int x; cin >> x;
		cnt[x]++;
	}

	bool check = (cnt[1] == 1) && (cnt[9] == 1) && (cnt[7] == 1) && (cnt[4] == 1);
	cout << (check ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] arg) {
		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();
		}
		int q = sc.nextInt();
		int[] M = new int[q];
		for(int i=0; i<q; i++){
			M[i]=sc.nextInt();
		}
		
		for(int i=0; i<q; i++){
			if(solve(n, 0, M[i], A) == 1){
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
	}
	
	public static int solve(int n, int i, int m, int[] A){
		int res=0;
		if(m==0) return 1;
		if(i>=n) return 0;
		if(solve(n, i+1, m, A)==1){
			res = solve(n, i+1, m, A);
		}else if(solve(n, i+1, m-A[i], A)==1){
			res = solve(n, i+1, m-A[i], A);
		}
		return res;
	}

}



Measured memory_bytes: 27192
#include<stdio.h>

int did[100001];

void search(int a[],int c,int x){

  if(x==2){
    printf("%d\n",c);
    return;
  }
  if(did[x]==1){
    printf("-1\n");
    return;
  }
  did[x]=1;

  search(a,c+1,a[x]);
}



int main(void){
  int a[100001];
  int i,j,m,n;

  scanf("%d",&n);

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

  search(a,0,1);

  return 0;
}


Measured memory_bytes: 1024
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


p, q, r = Is()
print(min(p+q, q+r, r+p))

Measured memory_bytes: 63468
#include<stdio.h>
#include<stdlib.h>

int cmpnum(const void * n1, const void * n2)
{
	if (*(int *)n1 > *(int *)n2)
	{
		return -1;
	}
	else if (*(int *)n1 < *(int *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main(void)
{
	int i,n,o1,e1,ans=0;
	scanf("%d",&n);
	int o[100001]={0};
	int e[100001]={0};
	int b[100001]={0};
	for(i=0;i<n/2;i++){
		scanf("%d%d",&o1,&e1);
		b[o1]++;
		b[e1]++;
		o[o1]++;
		e[e1]++;
	}
	qsort(o, sizeof(o) / sizeof(o[0]), sizeof(int), cmpnum);
	qsort(e, sizeof(e) / sizeof(e[0]), sizeof(int), cmpnum);
	qsort(b, sizeof(b) / sizeof(b[0]), sizeof(int), cmpnum);
	
	if(b[0]==e[0]+o[0]){
		if(o[1]+e[0]>=e[1]+o[0])
			ans=n-(o[1]+e[0]);
		else
			ans=n-(o[0]+e[1]);
	}
	else
		ans=n-(o[0]+e[0]);
	printf("%d",ans);
	return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task ""
#define int long long

using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;

int N, a[maxn], A, B;

int get(int x, int y)
{
    if (x % y == 0) return x / y;
    return x / y + 1;
}

bool check(int val)
{
    vector<int> need;
    for (int i=1; i<=N; ++i){
        if (a[i] > B * val){
            need.pb(a[i] - B * val);
        }
    }
    int res = 0;
    for (auto it : need){
        res += get(it, A - B);
    }
    return res <= val;
}

signed main(void){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    if (fopen(Task".inp", "r")){
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> N >> A >> B;
    for (int i=1; i<=N; ++i) cin >> a[i];
    int l=0, r=1e9, mid;
    while (l <= r){
        mid = (l + r) / 2;
        if (!check(mid)) l = mid + 1;
        else r = mid - 1;
    }
    cout << l;
}


Measured memory_bytes: 2916
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    dic = collections.defaultdict(int)

    while n != 1:
        prime = 0
        limit = int(n**(1/2))
        for i in range(2,limit+1):
            if n%i == 0:
                prime = i
                break
        else:
            prime = n

        while n%prime == 0:
            n //= prime
            dic[prime] += 1

    ans = 0

    for key,value in dic.items():
        cnt = 0
        while value>=cnt+1:
            cnt += 1
            value -= cnt

        ans += cnt
    # print(dic)
    print(ans)
        
main()            


Measured memory_bytes: 68728
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
int main()
{
    int n,h,k,a[100005],dp[100005],i,j;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    dp[1]=0;
    int mn;
    for(i=2;i<=n;i++)
    {
        //cout<<i;
        mn=inf;
        for(j=i-1;j>=i-k && j>=1;j--)
        {
            //cout<<j<<' ';
            mn=min(mn,dp[j]+abs(a[i]-a[j]));
        }
        dp[i]=mn;
        //cout<<dp[i];
    }
    cout<<dp[n];
    return 0;

}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
const ll mod = 1e9 + 7;
ll fact(int n) {
	if (n == 0)return 1ll;
	return n * fact(n - 1);
}
ll ncr(int n, int r) {
	return (fact(n) / (fact(r) * fact(n - r)));
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	unordered_map<int, int>m;
	for (int i = 2; i <= n; i++) {
		int have = i;
		for (int k = 2; k * k <= have; k++) {
			if (have % k == 0) {
				while (have % k == 0) {
					m[k]++;
					have = have / k;
				}

			}
		}
		if (have > 1)m[have]++;
	}
	ll ans = 1;
	for (auto k : m) {
		if (k.se)ans = ans * (k.se + 1);
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3608
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        a: [i32;3],
    }
    let mut b = a;
    b.sort();
    println!("{}",b[0]+b[1]);

    // let ans = if x<a {0} else {10};
    // puts!("{}\n", ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include<stdio.h>

int main(void){
   int a,b,c;
   scanf("%d %d %d",&a,&b,&c);

   if(a==b&&b==c&&c==a||a!=b&&b!=c&&c!=a){
      printf("No\n");
   } else {
      printf("Yes\n");
   }
   return 0;
}


Measured memory_bytes: 1620
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;

int n;
LL a,b,c,d;

int main()
{
	scanf("%d%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	n--;
	LL dif=abs(a-b);
	for(int i=1;i<=n;i++)
	{
		if (c*i-d*(n-i)<=dif && dif<=d*i-c*(n-i))
		{
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define llu unsigned long long int
#define sa(a,n,t) for(int ii=0;ii<n;ii++) scanf("%"#t"",&(a)[ii])
#define rep(i,n) for(int i=0;i<n;i++) 
#define reps(i,a,n) for(int i=a;i<n;i++) 
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rreps(i,a,n) for(int i=n-1;i>=a;i--)
#define validl(i,a,b) ((i>=a)&&(i<=b))?1:0
#define validmat(x,y,a,b,c,d) (validl(x,a,b) && validl(y,a,b))?1:0
#define validmn(x,y,m,n) validmat(x,y,0,m,0,n)
#define valid(i,n) validl(i,0,n)
#define v(t) vector<t>
#define vv(t) vector<vector<t> >
#define mk make_pair
#define pb push_back
#define pa(a,n,t)  for(int i=0;i<n;i++) printf("%"#t"",a[i])
#define p2 pair<int,int>
#define p3 pair<p2,int>
#define fi first
#define se second
#define sd(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld",a)
#define pd(a) printf("%d",a)
#define sf(a) scanf("%lf",&a)
#define pf(a) printf("%lf",a)
#define nline printf("\n")
#define ss(a) scanf("%s",a)
#define ps(a) printf("%s",a)
#define sc(a) scanf("%c",&a)
#define pc(a) printf("%c",&a)
#define mf(m,f) m.find(f)!=m.end()
#define pp3(m) cout<<m.fi.fi<<" "<<m.fi.se<<" "<<m.se<<" "
#define pp2(m) cout<<m.fi<<" "<<m.se<<" "
#define debug 0
/*v(int) adj[200001];
void dfs(int i,int p){
    rep(j,adj[i].size()){
        if(p!=adj[i][j])
            dfs(adj[i][j],i);
    }
}*/
int main()
{
  int n,k;
  cin>>n>>k;
  int arr[1000];
  rep(i,n) cin>>arr[i];
  sort(arr,arr+n);
  int s=0;
  rep(i,k) s+=arr[i];
  cout<<s<<endl;
  
  return 0;
}


Measured memory_bytes: 3624
//#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
namespace io
{
//#define USE_FEAD_IO
#ifdef USE_FEAD_IO
#define BUF_SIZE 5000010
	char buf[BUF_SIZE]; int cur = BUF_SIZE; FILE *in = stdin;
	inline char gnc()
	{
		if (cur == BUF_SIZE) { fread(buf, BUF_SIZE, 1, in); cur = 0; }
		return buf[cur++];
	}
#else
	inline char gnc()
	{
		return (char)getchar();
	}
#endif
	template<typename T>
	inline void gi(T &dx)
	{
		dx = 0;
		int yc = gnc();
		bool nega = false;
		while (yc < '0' || yc > '9') { nega = (yc == '-' ? true : nega); yc = gnc(); }
		while (yc >= '0' && yc <= '9') { dx = (T)(dx * 10 + yc - '0'); yc = gnc(); }
		if (nega) { dx = -dx; }
	}
	void gc(char &a)
	{
		do a = gnc(); while (!isgraph(a));
	}
	void gss(char *jc)
	{
		*jc = gnc();
		while (!isgraph(*jc)) *jc = gnc();
		while (isgraph(*jc)) *++jc = gnc();
		*jc = 0;
	}
#if __cplusplus >= 201103l || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103l)
	template<typename T, typename ...Args> inline void gi(T &a, Args &...args)
	{ gi(a); gi(args...); }
#else
	template<typename t1, typename t2> inline void gi(t1 &a, t2 &b) { gi(a); gi(b); }
	template<typename t1, typename t2, typename t3> inline void gi(t1 &a, t2 &b, t3 &c) { gi(a); gi(b); gi(c); }
	template<typename t1, typename t2, typename t3, typename t4> inline void gi(t1 &a, t2 &b, t3 &c, t4 &d) { gi(a); gi(b); gi(c); gi(d); }
	template<typename t1, typename t2, typename t3, typename t4, typename t5> inline void gi(t1 &a, t2 &b, t3 &c, t4 &d, t5 &e) { gi(a); gi(b); gi(c); gi(d); gi(e); }
#endif
}
using namespace io;

typedef long long ll;
ll q, h, s, d;
ll n;
int main()
{
	gi(q, h, s, d, n);
	s = min(s, q * 4);
	s = min(s, h * 2);
	d = min(d, s * 2);
	ll ans = (n / 2) * d + (n % 2) * s;
	cout << ans << endl;
	return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int k;
    cin >> k;
    int d = k%10;
    if (d==3){
        cout << "bon" << endl;
    }else if(d == 0 || d == 1|| d == 6|| d == 8){
        cout << "pon" << endl;
    }else{
        cout<<"hon"<<endl;
    }
}

Measured memory_bytes: 3592
# https://atcoder.jp/contests/code-festival-2017-quala/tasks/code_festival_2017_quala_c
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


# 回文の二次元版
# 1次元回文→文字数が奇数だったら,一つの文字以外出現回数はすべて2の倍数。偶数だったら出現回数はすべて2の倍数
# 二次元では？
# H,Wがともに偶数なら→すべての文字の出現回数は4の倍数
# Hが奇数、Wが偶数なら→4の倍数でない要素を、真ん中に詰めていきたい(そのような要素がWについても回文になっているか評価)
# つまり4の倍数が(W*(H-1))個分ある かつ それ以外の要素は2の倍数ある
# Wが奇数、Hが偶数→↑WHをひっくり返すだけ
# W,Hがともに奇数→(W-1)*(H-1)個分ある かつ それ以外の要素は1つ以外2の倍数である

# 上記を一般化すると、二次元回文が満たすべき条件は、
# - 同一文字4個セットは(W-(W&1))*(H-(H&1))//4 個以上ある
# - 同一文字奇数個の要素はちょうどH&1&W個ある(両方奇数のとき1になる)
# - その他の要素はすべて2の倍数個である(ただしこの条件は2番めの条件に内包される)

from collections import Counter

H, W = read_ints()
cnt = Counter()
for _ in range(H):
    cnt.update(input())

# コーナーケース処理
# if H == 1 or W == 1:


num4 = 0
num1 = 0
for v in cnt.values():
    if v & 1:  # 条件2
        num1 += 1

    while v >= 4:  # 条件1の4文字セットを作る 4以上なら4個セットを作ることができる
        v -= 4
        num4 += 1

if num4 >= (W - (W & 1)) * (H - (H & 1)) // 4 and num1 == H & 1 & W:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3316
N = gets.to_i
csfs = readlines.map do |line|
  line.chomp.split.map(&:to_i)
end
csfs.unshift([0, 0, 0])

t = 0
n = 1
while n != N
  (n..(N-1)).each do |i|
    if t < csfs[i][1]
      t = csfs[i][1]
    elsif t % csfs[i][2] == 0
    else
      t = t + csfs[i][2] - (t % csfs[i][2])
    end
    t += csfs[i][0]
  end
  p(t)
  t = 0
  n += 1
end
p(0)

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

int main() {
  string S;
  cin >> S;

  int len = S.size();

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

  vector<int> v;
  int cnt_r = 0, cnt_b = 0;
  rep(i, len) {
    if (S[i] == '0') {
      if (cnt_b != 0)
        v.push_back(cnt_b);
      cnt_b = 0;
      ++cnt_r;
    } else {
      if (cnt_r != 0)
        v.push_back(cnt_r);
      cnt_r = 0;
      --cnt_b;
    }
  }
  if (cnt_b != 0)
    v.push_back(cnt_b);
  if (cnt_r != 0)
    v.push_back(cnt_r);

  int sum = 0;
  rep(i, v.size()) sum += v[i];
  cout << len - abs(sum) << endl;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ans=min(d,b)-max(a,c);
  if(ans<0)ans=0;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
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;
import std.typecons;

void main() {
    auto a = read.to!int;
    auto b = read.to!int;
    if (a + b == 15) writeln("+");
    else if (a * b == 15) writeln("*");
    else writeln("x");
}

string read() {
    static string[] ss;
    while (!ss.length) ss = readln.chomp.split;
    auto res = ss[0];
    ss.popFront;
    return res;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const static int MOD = 1e9+7;

int main(){
	int N;
	scanf("%d\n", &N);
	bool is_black[2*N];
	for (int i = 0; i < 2*N; ++i){
		char tmp;
		scanf("%c", &tmp);
		is_black[i] = tmp == 'B';
	}
	bool is_left_end[2*N];
	if(!is_black[0]){
		printf("0\n");
		return 0;
	}
	is_left_end[0] = true;
	int n_right_end = 0;
	ull ans = 1;
	for (int i = 1; i < 2*N; ++i){
		is_left_end[i] = (is_black[i] ^ is_black[i-1]) ? is_left_end[i-1] : !is_left_end[i-1];
		if(!is_left_end[i]){
			//これを含めてこれより左側にある左端の数はi-n_right_end、右端の数はn_right_end+1
			if(i - n_right_end < n_right_end + 1){
				printf("0\n");
				return 0;
			}
			(ans *= i - n_right_end*2) %= MOD;
			n_right_end++;
		}
	}
	if(n_right_end != N){
		printf("0\n");
		return 0;
	}
	for (int i = 2; i <= N; ++i) (ans *= i) %= MOD;
	printf("%llu\n", ans);
	return 0;
}

Measured memory_bytes: 512
is_first_time = true
loop do
  a, b = gets.chomp.split.map(&:to_i)
  break if [a,b].all?(&:zero?)
  puts "" unless is_first_time
  count = (a..b).to_a.map do |year|
    if year.odd? || year % 4 != 0 || (year % 100 == 0 && year % 400 != 0)
      0
    else
      year
    end
  end
  if count.all?(&:zero?)
    puts "NA"
  else
    count.select{ |y| y != 0 }.each { |y| puts y }
  end
  is_first_time = false
end

Measured memory_bytes: 6228
def match(start_x, start_y):
    count = 0
    for x in range(m):
        for y in range(m):
            if a[start_x+x][start_y+y] == b[x][y]:
                count += 1

    return count // m**2


def main():
    count_match = 0
    for x in range(n - m + 1):
        for y in range(n - m + 1):
            count_match += match(x, y)

    if count_match != 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    n, m = map(int, input().split())
    a = [list(input()) for i in range(n)]
    b = [list(input()) for i in range(m)]
    main()

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


int main() {
    int a,b;cin>>a>>b;
    if(a>b)cout<<a-1<<endl;
    else cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

const M: usize = 1_000_000_007;

fn main() {
    input! {
        n: usize,
        m: usize,
        s: [usize; n],
        t: [usize; m],
    }

    let mut dp = vec![vec![0; m + 1]; n + 1];
    let mut sum = vec![vec![0; m + 1]; n + 1];

    for i in 1..n + 1 {
        for j in 1..m + 1 {
            if s[i - 1] == t[j - 1] {
                dp[i][j] = sum[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = 0;
            }
            dp[i][j] %= M;
            sum[i][j] = M + sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
            sum[i][j] %= M;
        }
    }

    println!("{}", (sum[n][m] + 1) % M);

    // let mut dp = vec![vec![0; m + 1]; n + 1];
    // for i in 0..n + 1 {
    //     dp[i][0] = 1;
    // }

    // for i in 0..m + 1 {
    //     dp[0][i] = 1;
    // }

    // for i in 1..n + 1 {
    //     for j in 1..m + 1 {
    //         if s[i - 1] == t[j - 1] {
    //             dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
    //         } else {
    //             dp[i][j] = M + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
    //         }
    //         dp[i][j] %= M;
    //     }
    // }
    // println!("{}", dp[n][m]);
}


Measured memory_bytes: 86268
#####segfunc#####
def segfunc(x, y):
    return x+y
#################

#####ide_ele　単位元#####
ide_ele = 0
#################



class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

mod=998244353
n,k=map(int,input().split())
Q=[]
for _ in range(k):
    a,b=map(int,input().split())
    Q.append((a,b))

dp=[0 for i in range(n+1)]
dp[1]=1
dp=SegTree(dp,segfunc,ide_ele)
for i in range(2,n+1):
    cnt=0
    for que in Q:
        cnt+=dp.query(max(0,i-que[1]),max(0,i-que[0]+1))%mod
        #print(cnt)
        cnt%=mod
    dp.update(i,cnt)
print(dp.query(n,n+1))


Measured memory_bytes: 85304
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int X;
  int res=0;
  cin >> X;

  int num=0;
  for(int i=1;num<X;i++){
    num += i;
    if(num>=X) res = i;
  }

  cout << res << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vecl<T: FromStr>(n: usize) -> Vec<T> {
    let mut v = vec![];
    for _ in 0..n {
        v.push(read::<T>());
    }

    v
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let (n, k) = read_cols!(usize, usize);
    let a = read_vec::<i64>();

    let ss: Vec<_> = iter::once(0).chain(a.iter().cloned()).scan(0, |s, aa| {
        *s += aa;
        Some(*s)
    }).collect();

    let ls: Vec<_> = iter::once(0).chain(a.iter().cloned()).scan(0, |s, aa| {
        if aa > 0 {
            *s += aa;
        }
        Some(*s)
    }).collect();

    let rs: Vec<_> = a.iter().cloned().chain(iter::once(0)).rev().scan(0, |s, aa| {
        if aa > 0 {
            *s += aa;
        }
        Some(*s)
    }).collect();

    let ans = (0..n - k + 1).map(|i| (i, i + k)).map(|(l, r)| {
        let s: i64 = ss[r] - ss[l];
        if s > 0 {
            ls[l] + rs[n - r] + s
        } else {
            ls[l] + rs[n - r]
        }
    }).max().unwrap();

    println!("{}", ans);
}


Measured memory_bytes: 12540
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define pob         pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define	mp3(a,b,c)  make_pair(a,make_pair(b,c))
#define se          second
#define fi          first 
#define sse         second.second
#define sfi         second.first
#define soA         sort(A+1,A+1+n)
#define so(A,n)     sort(A+1,A+1+n)
#define sov(v)      sort(all(v))
#define sovr(v)     sort(all(v),greater<ll>())
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5],Asum[MAXN+5],B[MAXN+5];
map<ll,ll> mm;
ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	sc2(n,k);
	f1(i,n)sc(A[i]),Asum[i]=(Asum[i-1]+A[i])%k,B[i]=(2*k+Asum[i]-(i-1)%k)%k;
	ll r=1;
	f1(i,n){//	debug(k);
		while(r<=n and r-i+1<k){
			mm[B[r]]++;r++;	
		//	debug(r-i+1);
		}
		ans+=mm[(2*k+Asum[i-1]-(i-1-1+k*2)%k)%k];
	//	debug((2*k+Asum[i-1]-(i-1-1+k*2)%k)%k);
		mm[B[i]]--;
	}
	pr(ans);
	
	
	
	
	
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	} 		
}

Measured memory_bytes: 22528
#include <iostream>
using namespace std;
int main(void){
    string s;
    string t;
    cin>>s>>t;
    for(int i=0;i<s.length();i++){
        if(s[i]!=t[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


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

int main(){
  ll n,m;
  cin>>n>>m;
  vector<int> l(m),r(m);
  rep(i,m){
    cin>>l[i]>>r[i];
  }
  int s=0;
  int b=100001;
  rep(i,m){
    s=max(s,l[i]);
    b=min(b,r[i]);
  }
  if(b>=s){
    cout<<b-s+1<<endl;
  }
  else{
    cout<<0<<endl;
  }
  
  
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int main()
{
    int a,b,c,d,e,m;
    scanf("%d%d",&a,&b);
    c=a+b;
    d=a-b;
    e=a*b;
    m=max(c,d);
    m=max(m,e);
    printf("%d",m);
    return 0;
}




Measured memory_bytes: 128
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  string s;
  cin >> s;
  sort(all(s));
  if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

ll GCD(ll a, ll b)
{
	if (b == 0) return a;
	else return GCD(b, a%b);
}

ll LCM(ll a, ll b)
{
	return (a * b) / GCD(a, b);
}

int main(int argc, char **argv)
{
	int a, b;
	cin >> a >> b;
	std::cout << LCM(a, b) << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	int a,b,c;
	cin>>a>>b>>c;
	a=llabs(a);
    if(b<a/c){
        cout<<a-b*c;
        return 0;
    }
    int k=a/c;
    a=a-k*c;
    b-=k;
    if(b%2==0){
        cout<<a;
    }
    else{
        cout<<llabs(a-c);
    }
	return 0;
}


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

int a[100000][3], dp[100000][3];

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

	int n;
	cin >> n;
	for(int i=0; i<n; ++i)
		for(int j=0; j<3; ++j)
			cin >> a[i][j];
	for(int j=0; j<3; ++j)
		dp[0][j]=a[0][j];
	for(int i=1; i<n; ++i) {
		for(int j=0; j<3; ++j) {
			int mx=0;
			for(int k=0; k<3; ++k)
				if(k!=j)
					mx=max(dp[i-1][k], mx);
			dp[i][j]=mx+a[i][j];
		}
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  int x=-1;
  for(int i=1;i<n+1;i++){
    x=i*i;
    if(x>n){x=(i-1)*(i-1);}
    if(i*i>n)break;}
  cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 256
const input = require("fs").readFileSync("/dev/stdin", "utf8")

;(input => {

    const lines = input.split('\n')
    const N = lines[0] - 0
    const a = lines[1].split(' ').map(Number)

    let x = a[0]
    for (let i = 1; i < N; i++) {
        x = x ^ a[i]
    }

    let r = x ^ a[0]
    for (let i = 1; i < N; i++) {
        r += ' ' + (x ^ a[i])
    }

    console.log(r)

})(input)


Measured memory_bytes: 76696
#include <stdio.h>          // printf(), scanf()
#define swap(a, b) { int t; t = a; a = b; b = t; }

int
main(int argc, char** argv)
{
	int a, b, c;
	int n, i;

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		scanf("%d %d %d", &a, &b, &c);
		if (a > c)
			swap(a, c);

		if (b > c)
			swap(b, c);

		if (a * a + b * b == c * c)
			printf("YES\n");
		else
			printf("NO\n");
	}

	return 0;
}

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

int N;
string s[10000];


//UnionFind-----------------------------
int par[26],sz[26];
void init(){
    for(int i=0;i<26;i++){
        par[i]=i;
        sz[i]=1;
    }
}
int find(int x){
    return x==par[x]?x:par[x]=find(par[x]);
}
void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y)return;

    if(sz[x]<sz[y])swap(x,y);
    par[y]=x;
    sz[x]+=sz[y];
}
//--------------------------------------


void solve(){
    int in[26]={0};
    int out[26]={0};

    init();
    for(int i=0;i<N;i++){
        int o=s[i][0]-'a';
        int e=s[i][s[i].size()-1]-'a';

        in[o]++;
        out[e]++;
        unite(o,e);
    }

    int cnt=0;

    for(int i=0;i<26;i++){
        if(in[i]!=out[i]){
            cout<<"NG"<<endl;
            return;
        }

        if(in[i]&&i==par[i])cnt++;
    }

    if(cnt>1){
        cout<<"NG"<<endl;
        return;
    }
    cout<<"OK"<<endl;

}

int main(){
    cin.tie();
    ios_base::sync_with_stdio(false);
    
    while(cin>>N,N){
        for(int i=0;i<N;i++)cin>>s[i];
        solve();
    }
    return 0;
}

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

using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    //電車の最安
    int busmin = min(a, b);
    //バスの最安
    int trainmin = min(c, d);
    
    cout << busmin + trainmin << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    int a,b,c,count=0,counta=0;
    string s;
    cin>>s;
    int x =s.length();
    if(x==1)
    {
        cout<<"0"<<endl;

    }
    else{
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='1')
        {
            count++;
        }
if(s[i]=='0')
{
    counta++;
}
    }

    int z = abs(count-counta);
    cout<<s.length()-z<<endl;
    }
    return 0 ;
}


Measured memory_bytes: 512