akhauriyash/Code-Regression huggingface dataset:
#    !/usr/bin/env python3
#    encoding: UTF-8
#    Modified: <28/Sep/2019 05:31:42 PM>


#    ✪ H4WK3yE乡
#    Mohd. Farhan Tahir
#    Indian Institute Of Information Technology (IIIT), Gwalior


import sys
import os
from io import IOBase, BytesIO


def main():
    n = int(input())
    if n & 1:
        x = n // 2 + 1
        print(x / n)
    else:
        print(0.5)


BUFSIZE = 8192


class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill():
            pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill()
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

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


class IOWrapper(IOBase):
    def __init__(self, file):
        py2 = round(0.5)
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2 == 1:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            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)


def get_array():
    return list(map(int, sys.stdin.readline().split()))


def get_ints():
    return map(int, sys.stdin.readline().split())


def input():
    return sys.stdin.readline().strip()


if __name__ == "__main__":
    main()


Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w, k; cin >> h >> w >> k;
  int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
  sx--; sy--; tx--; ty--;
  vector<string> S(h);
  rep(i, h) cin >> S[i];
  priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> q;
  int dx[] = {-1, 0, 1, 0};
  int dy[] = {0, 1, 0, -1};
  vector<ll> cost(h*w*4, longinf);
  vector<bool> vis(h*w*4);
  auto toId = [&](int x, int y, int d) {
    return (x*w+y)*4+d;
  };
  rep(i, 4) {
    cost[toId(sx, sy, i)] = 0;
    q.push({0, toId(sx, sy, i)});
  }
  while(!q.empty()) {
    auto ele = q.top(); q.pop();
    int tmp = ele.second;
    int x = tmp/4/w;
    int y = tmp/4%w;
    int d = tmp%4;
    if(cost[tmp] != ele.first) continue;
    if(vis[tmp]) continue;
    vis[tmp] = true;
    rep(i, 4) {
      if(i == d) continue;
      int ne = toId(x, y, i);
      if((cost[tmp]+k-1)/k*k < cost[ne]) {
        cost[ne] = (cost[tmp]+k-1)/k*k;
        q.push({cost[ne], ne});
      }
    }
    {
      int nx = x+dx[d];
      int ny = y+dy[d];
      if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if(S[nx][ny] == '@') continue;
      int ne = toId(nx, ny, d);
      if(cost[tmp]+1 < cost[ne]) {
        cost[ne] = cost[tmp]+1;
        q.push({cost[ne], ne});
      }
    }
  }
  ll ans = longinf;
  rep(i, 4) ans = min(cost[toId(tx, ty, i)], ans);
  cout << (ans==longinf ? -1 : (ans+k-1)/k) << "\n";
  return 0;
}


Measured memory_bytes: 44432
N = int(input())
a = [int(x) for x in input().split()]

p = [0] * 3
for i in a:
    p[3-i] += 1

dp = [[[0] * (N+1-i-j) for j in range(N+1-i)] for i in range(N+1)]

for i in range(N+1):
    for j in range(N+1-i):
        for k in range(N+1-i-j):
            if i + j + k == 0:
                continue
            if i > 0:
                dp[i][j][k] += dp[i-1][j+1][k] * i
            if j > 0:
                dp[i][j][k] += dp[i][j-1][k+1] * j
            if k > 0:
                dp[i][j][k] += dp[i][j][k-1] * k
            dp[i][j][k] += N
            dp[i][j][k] /= (i + j + k)

print(dp[p[0]][p[1]][p[2]])

Measured memory_bytes: 158984
unittest
{
	assert( [ "1", "100", "30" ].parse.expand.solve == "2100.000" );
	assert( [ "2", "60 50", "34 38" ].parse.expand.solve == "2632.000" );
	assert( [ "3", "12 14 2", "6 2 7" ].parse.expand.solve == "76.000" );
	assert( [ "1", "9", "10" ].parse.expand.solve == "20.250" );
	assert( [ "10", "64 55 27 35 76 119 7 18 49 100", "29 19 31 39 27 48 41 87 55 70" ].parse.expand.solve == "20291.000" );
}



import std.algorithm;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto ts = input.front.split.to!( long[] );
	input.popFront;
	auto vs = input.front.split.to!( long[] );
	return tuple( ts, vs );
}

auto solve( long[] ts, long[] vs )
{
	// 速度上限配列から時間基準の速度配列を作成
	auto ss = new double[ 100 * 200 * 2 + 2 ];
	auto tt = 1L;
	ss[ 0 ] = 0;
	foreach( t, v; lockstep( ts, vs ) )
	{
		auto t2 = t * 2;		// 奇数秒を2で割る場合があるので、時間を0.5秒区切りにして整数で扱えるようにする
		ss[ tt - 1 ] = min( ss[ tt - 1 ], v );
		ss[ tt .. tt + t2 ] = v;
		tt += t2;
	}
	ss.length = tt;
	ss[ $ - 1 ] = 0;
	
	// 加速を計算
	for( auto i = 0L; i < ss.length.signed - 1; i++ )
	{
		if( ss[ i ] < ss[ i + 1 ] ) ss[ i + 1 ] = ss[ i ] + 0.5;		// 時間が0.5秒区切りなので1m/s^2の半分を加算
	}
	
	// 減速を計算
	for( auto i = ss.length.signed - 1; 0 < i; i-- )
	{
		if( ss[ i ] < ss[ i - 1 ] ) ss[ i - 1 ] = ss[ i ] + 0.5;		// 時間が0.5秒区切りなので1m/s^2の半分を加算
	}
	
	// 合計距離を計算
	auto ans = ss.sum / 2;		// 時間を0.5秒区切りから1秒区切りに戻す
	return format( "%0.3f", ans );
}


Measured memory_bytes: 2684
#include "iostream"
#include "cmath"
#include "iomanip"
using namespace std;

int main()
{
	int n, s[1000];
	double ave = 0, sum = 0, ans = 0;
	cin >> n;
	while (1)
	{
		if (n == 0)
		{
			break;
		}
		for (int i = 0; i < n; i++)
		{
			cin >> s[i];
			sum += s[i];
			if (i == n - 1)
			{
				ave = sum / n;
			}
		}
		for (int i = 0; i < n; i++)
		{
			ans += (s[i] - ave)*(s[i] - ave);
			if (i == n - 1)
			{
				ans = sqrt(ans / n);
			}
		}
		cout << fixed << setprecision(4) << ans << endl;
		sum = 0;
		ans = 0;
		cin >> n;
	}
}


Measured memory_bytes: 3280
import Data.Char
import Data.List

pack [] = []
pack (s:sr) =
  let n = length $ takeWhile (== s) sr
      r = dropWhile (== s) sr
  in
    (s,n+1):(pack r)

cnt = (pack . sort)

take' _ [] = []
take' a ((b,n):xs) =
  if ord(b) - ord(a) == 1
  then (b,n):(take' b xs)
  else []

dec 0 x = x
dec l [] = error $ show l
dec l x@((a,1):xs) = dec (l-1) xs
dec l x@((a,n):xs) = (a,n-1):(dec (l-1) xs)

cmp [] = 0
cmp i@((a,n):xs) =
  let p = (a,n):(take' a xs)
      l = length p
      d = dec l i
  in
    if l >= 4
    then (l-3) + cmp d
    else cmp d
  
ans i =
  let l = length i
      a = filter(\x -> ord(x) >= ord('a') && ord(x) <= ord('z')) i
      n = filter(\x -> ord(x) >= ord('0') && ord(x) <= ord('9')) i
      ca= cmp $ cnt a
      cn= cmp $ cnt n
  in
    l - ca - cn

main = do
  c <- getContents
  let i = lines c
      o = map ans i
  mapM_ print o

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

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

	int n, k;
	cin >> n >> k;

	int curr = -1;
	while (k > 0) {
		k--;
		curr += 2;
	}
	cout << (curr <= n ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;  
  
typedef long long ll;
#define N 200100  
const int Mod=1000000007;

int c[N],w[N],fac[N],fac_inv[N],cnt[N];
vector<pair<int,int> > color_list[N];
vector<int> E[N];
bool vis[N],vis_color[N];
vector<int> color;
  
int Power(int x,int p)
{
	int res=1;
	for (;p;p>>=1)
	{
		if (p&1) res=1ll*res*x%Mod;
		x=1ll*x*x%Mod;
	}
	return res;
} 
  
void Add_Edge(int x,int y)
{

	E[x].push_back(y);
	E[y].push_back(x);	
}

void Dfs(int x,int &tot)
{
	cnt[c[x]]++; tot++;
	if (!vis_color[x])
	{
		vis_color[x]=true;
		color.push_back(c[x]);
	}
	
	for (int i=0;i<E[x].size();i++)
	{
		int y=E[x][i]; if (vis[y]) continue;
		vis[y]=true; Dfs(y,tot);
	}
}

int C(int n,int m)
{
	if (m==0) return 1;
	if (n==0) return 0;
	int res=1ll*fac[n]*fac_inv[m]%Mod;
	return 1ll*res*fac_inv[n-m]%Mod;
}

int main()  
{  
	//freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
	
	int n,X,Y,a=0,b=0; scanf("%d%d%d",&n,&X,&Y);
	for (int i=1;i<=n;i++) scanf("%d%d",&c[i],&w[i]),color_list[c[i]].push_back(make_pair(w[i],i));
	for (int i=1;i<=n;i++) 
	{
		if (color_list[i].empty()) continue;
		sort(color_list[i].begin(),color_list[i].end());
		for (int j=1;j<color_list[i].size();j++)
		{
			if (color_list[i][0].first+color_list[i][j].first>X) break;
			Add_Edge(color_list[i][0].second,color_list[i][j].second);
		}
		if (!a) 
		{
			b=a,a=color_list[i][0].second;
			continue;
		}
		if (color_list[i][0].first<w[a]) b=a,a=color_list[i][0].second;
		else if (!b || color_list[i][0].first<w[b]) b=color_list[i][0].second;
	}
	if (a) for (int i=1;i<=n;i++) if (c[i]!=c[a] && w[i]+w[a]<=Y) Add_Edge(a,i);
	if (b) for (int i=1;i<=n;i++) if (c[i]!=c[b] && w[i]+w[b]<=Y) Add_Edge(b,i); 
	
	fac[0]=fac_inv[0]=1; for (int i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%Mod,fac_inv[i]=Power(fac[i],Mod-2);
	
	int ans=1;
	for (int i=1;i<=n;i++)
	{
		if (vis[i]) continue;
		int tot=0; vis[i]=true,Dfs(i,tot);
		for (int j=0;j<color.size();j++) 
		{
			ans=1ll*ans*C(tot,cnt[color[j]])%Mod;
			tot-=cnt[color[j]];
			vis_color[color[j]]=false,cnt[color[j]]=0;
		}
		color.clear();
	}
	printf("%d\n",ans);
	
    return 0;  
}  

Measured memory_bytes: 26676
N = int(input())
A = [int(input()) for _ in range(N)]

ans = 0

for i, a in enumerate(A):
    ans += a // 2
    A[i] = a % 2
    if i < N-1 and A[i] == 1 and A[i+1] >= 1:
        A[i] -= 1
        A[i+1] -= 1
        ans += 1

print(ans)

Measured memory_bytes: 7072
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int q = sc.nextInt();
        boolean rev = false;
        StringBuilder f = new StringBuilder();
        StringBuilder b = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int t = sc.nextInt();
            if(t == 1){
                rev = !rev;
            }else{
                int a = sc.nextInt();
                String c = sc.next();
                boolean front = (rev&&a==2) || (!rev&&a==1);
                if(front){
                    f.append(c);
                }else{
                    b.append(c);
                }
            }
        }
        StringBuilder ans = f.reverse().append(s).append(b);
        System.out.println(rev ? ans.reverse().toString() : ans.toString());
        sc.close();

    }

}


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

using namespace std;

typedef long long ll;
typedef double ld;

const int N = 1e3 + 10;
const int INF = 1e9 + 10;

string a[N];

int d[N][N];
int d2[N][N];

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

int main() {
    //freopen("a.in", "r", stdin);
    int n, m, k;
    cin >> n >> m >> k;
    fr(i, n)
        cin >> a[i];

    fr(i, n)
        fr(j, m)
            d[i][j] = min(min(i, n - 1 - i), min(j, m - 1 - j));

    int x, y;
    fr(i, n)
        fr(j, m)
            if (a[i][j] == 'S')
                x = i, y = j;

    fr(i, n)
        fr(j, m)
            d2[i][j] = INF;
    d2[x][y] = 0;
    queue <pair <int, int> > q;
    q.push(mp(x, y));
    while (!q.empty()) {
        auto t = q.front();
        q.pop();
        int x = t.first;
        int y = t.second;
        fr(i, 4) {
            int x1 = x + dx[i];
            int y1 = y + dy[i];
            if (x1 >= 0 && x1 < n && y1 >= 0 && y1 < m && d2[x1][y1] == INF && a[x1][y1] == '.') {
                if (d2[x][y] < k) {
                    d2[x1][y1] = d2[x][y] + 1;
                    q.push(mp(x1, y1));
                }
            }
        }
    }

    int ans = INF;
    fr(i, n)
        fr(j, m) {
            if (d2[i][j] <= k)
                ans = min(ans, 1 + (k - 1 + d[i][j]) / k);
        }
    cout << ans;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i ,n,m,a[100005],b[100005],sum=0,ma=-111;
	cin>>n>>m;
	for(i=0;i<m;i++)
	{
		cin>>a[i];
	}
	sort(a,a+m);
	for(i=1;i<m;i++)
	{
		b[i]=a[i]-a[i-1];
	}
	sort(b,b+m);
	for(i=1;i<m-(n-1);i++)
	{
		sum+=b[i];
	}
	cout<<sum<<endl;
	

}

Measured memory_bytes: 1024
import heapq
n,m=map(int, input().split())
lst = []
for i in range(n):
  a,b=map(int, input().split())
  lst.append((-b,a))
lst = sorted(lst, key=lambda x:x[1])

now_idx = 0
queue = []
sum_ = 0
for i in range(1,m+1):
  for j in range(now_idx, n):
    if lst[j][1] <= i:
      heapq.heappush(queue, lst[j])
    else:
      now_idx = j
      break
  else:
    now_idx = n
  if len(queue)>0:
    sum_ -= heapq.heappop(queue)[0]
print(sum_)


Measured memory_bytes: 82392
n = int(input())
lst = list(map(int, input().strip().split()))[:n]
mx = 1000000000000000000
if 0 in lst:
    print(0)
else:
    cur = lst[0]
    for x in lst[1:]:
        cur = cur * x
        if cur > mx:
            cur = -1
            break
    print(cur)


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

#define ll long long

using namespace std;

int h, w;
char s[2002][2002];
pair<int, int> topleft[2002][2002];
int vert[2002];

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; ++i)
        cin >> s[i];

    for (int j = 0; j < w; ++j)
        vert[j] = -1;

    for (int i = 0; i < h; ++i) {
        int wall = -1;
        for (int j = 0; j < w; ++j) {
            if (s[i][j] == '#') {
                vert[j] = i;
                wall = j;
            } else {
                topleft[i][j] = {wall, vert[j]};
            }
        }
    }

    for (int j = 0; j < w; ++j)
        vert[j] = h;

    int sol = 0;
    for (int i = h - 1; i >=0; --i) {
        int wall = w;
        for (int j = w - 1; j >=0; --j) {
            if (s[i][j] == '#') {
                vert[j] = i;
                wall = j;
            } else {
                sol = max(sol, wall - topleft[i][j].first + vert[j] - topleft[i][j].second - 3);
            }
        }
    }

    cout << sol;
    return 0;
}


Measured memory_bytes: 35584
import sys
input=sys.stdin.readline

N=int(input())
p=list(map(float,input().split()))

dp=[[0]*(N+1)for _ in range(N+1)]
for i in range(N+1):
    for j in range(N+1):
        if i==0 and j==0:
            dp[i][j]=1
        elif j==0:
            dp[i][j]=dp[i-1][j]*(1-p[i-1])
        elif i>=j:
            dp[i][j]=(dp[i-1][j]*(1-p[i-1]))+(dp[i-1][j-1]*p[i-1])

ans=0
for j in range(((N//2)+1),N+1):
    ans+=dp[N][j]
print(ans)

Measured memory_bytes: 202348
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>

using namespace std;

int main (void) {
	int a, b, c, re = 0;
	while (~scanf (" %d %d %d", &a, &b, &c)){
		re = 0;
		if (a != b) re++;
		if (b != c) re++;
		if (a != c) re++;
		if (re == 0) re++;
		printf ("%d\n", re);
	}

	return 0;
}

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

using namespace std;
using ull = unsigned long long;
using ll = long long;
int main(){
  ull a, b, c;
  cin >> a >> b >> c;
  cin.ignore();
  ll left_ll = c - a - b;
  ull left = c - a - b;
  if(left_ll < 0){
    printf("No\n");
    return 0;
  } else if((c > 0) && ((a == 0) || (b == 0))){
    printf("Yes\n");
    return 0;
  } else if(c == 0){
    printf("No\n");
    return 0;
  }

  long double ab = a * b;
  long double sq_ab = sqrtl((long double) ab);

  constexpr double e = std::numeric_limits<long double>::epsilon();

  if(((long double) left) - sq_ab * 2 > e){
    printf("Yes\n");
    return 0;
  } else {
    printf("No\n");
    return 0;
  }
  return 0;
}
    


Measured memory_bytes: 256
# Vicfred
# https://atcoder.jp/contests/abc156/tasks/abc156_d
# math
def binpow(a, b, m):
    a %= m
    res = 1
    while b > 0:
        if b & 1:
            res = res * a % m
        a = a * a % m
        b >>= 1
    return res

def binomial(n, k, m):
    x = 1
    y = 1
    for i in range(k):
        x *= n-i
        x %= m
        y *= i+1
        y %= m
    y = binpow(y, m-2, m)
    return (x*y)%m

mod = 10**9+7

n, a, b = list(map(int, input().split()))

print((binpow(2, n, mod) - binomial(n,a, mod) - binomial(n,b, mod) - 1 + mod)%mod)


Measured memory_bytes: 3316
x, k, d = map(int, input().split())
n = abs(x)//d

if n>=k:
    print(abs(x)-d*k)
else:
    if (k-n)%2 == 0:
        print(abs(abs(x)-d*n))
    else:
        print(abs(abs(x)-d*(n+1)))

Measured memory_bytes: 9056
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
        string t, p;
        int fin;
        cin >> t >> p;
        fin = t.length() - p.length() + 1;
        if (fin <= 0)
                return 0;
        for (int i = 0; i < fin; i++) {
                bool flag = 1;
                for (int j = 0; j < p.length(); j++) {
                        if (t[i+j] != p[j]) {
                                flag = 0;
                                break;
                        }
                }
                if (flag)
                        cout << i << endl;
        }

        return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>

#define ll long long
#define ld long double
#define ull unsigned long long
#define endl "\n"
#define MohamedMotaz ios::sync_with_stdio(0); cin.tie(0); ios_base::sync_with_stdio(0);
#define f(a, b, c) for(int a = b; a < c; a++)
using namespace std;


//ll fact[1000001]; ll inv[1000001];
//ll primes[100007];
//ll arr[1000007];
//ll modPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//
//	ll halfpow = modPower(b, p / 2);
//	ll toReturn = (halfpow * halfpow) % mod;
//	if (p % 2)
//		toReturn = (toReturn * b) % mod;
//
//	return toReturn;
//}
//
//ll fastPower(ll b, ll p) {
//	if (p == 0)
//		return 1;
//	ll ans = fastPower(b, p / 2);
//	ans = (ans * ans);
//	if (p % 2 != 0)
//		ans = (ans * b);
//	return ans;
//}
//ll GcdRecursive(ll a, ll b) {
//	if (b == 0) return a;
//	return GcdRecursive(b, a % b);
//}
//ll modLCM(ll a, ll b) {
//	ll val = GcdRecursive(a, b);
//	ll tmp = ((a % mod) * (b % mod)) % mod;
//	ll finalVal = ((tmp % mod) * (arr[val] % mod)) % mod;
//	return finalVal;
//
//}
//ll LCM(ll a, ll b) {
//	return (a * b) / GcdRecursive(a, b);
//}
//void move1step(ll& a, ll& b, ll q) { // a and b by reference
//	ll c = a - q * b;
//	a = b;
//	b = c;
//}
//ll GcdIterative(ll a, ll b) {
//	while (b) move1step(a, b, a / b);
//	return a;
//}
//
//void pre(ll n) {
//
//	fact[0] = 1;
//	inv[0] = 1;
//
//	for (ll i = 1; i <= n; i++) {
//		fact[i] = (i * fact[i - 1]) % mod;
//		inv[i] = modPower(fact[i], mod - 2);
//		arr[i] = modPower(i, mod - 2);
//	}
//}
//
//ll npr(ll n, ll r) {
//	return ((fact[n] * inv[n - r]) % mod);
//}
//
//ll ncr(ll n, ll r) {
//	return ((((fact[n] * inv[n - r]) % mod) * inv[r]) % mod);
//}
//
//void sieve(ll val) {
//	memset(primes, 1, sizeof primes);
//	primes[0] = primes[1] = false;
//	for (int i = 2; i <= val; i++) {
//		if (primes[i]) {
//			for (int j = i * i; j <= val; j += i) {
//				primes[j] = 0;
//			}
//		}
//	}
//
//}

const ll mod = 1e9 + 7;
const ll N = 1e5 + 7;
const ll INF = 1e9 + 5;
ll n, k;



int main()
{
    MohamedMotaz;
    cin >> n >> k;
    vector<ll> v(n);
    vector<ll> dp(n, INF);
    f(i,0,n) cin >> v[i];
    dp[0] = 0;
    f(i,0,n){
        for (int j = i; j <= k + i; j++){
            if (j < n)
            dp[j] = min(dp[j], dp[i] + abs(v[j] - v[i]));
            else break;
        }
        //f(x,0,n) cout << dp[x] << " "; cout << endl;
    }
    //f(i,0,n) cout << dp[i] << " ";
    //cout << endl;
    cout << dp[n- 1];
}



Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    double r, s, l;
    cin >> r;
    double pi = 3.141592653589793;
    s = r*r*pi;
    l = 2*pi*r;
    printf("%f %f\n", s, l);
    
    return 0;
    
}


Measured memory_bytes: 3212
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, k) = in.readLine().split("\\s+").map(_.toLong)

    @tailrec
    def length(n: Long, c: Int): Int = {
      if (n > 0L) {
        length(n / k, c + 1)
      } else {
        c
      }
    }

    out.println(
      length(n, 0)
    )
    out.flush()
  }
}


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

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll int
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define prll(v) for (auto i: v) cout << i << " ";

bool cycle(vector<int>& vis) {
    int i;
    for (i = 1; i < vis.size(); i++)
        if (!vis[i])
            return 1;
    return 0;
}

int main() {
    fast
    int n, m, u, v, j;
    cin >> n >> m;
    vector<vector< int> > ed(n+1);
    vector<int> ind(n+1, 0);
    for (ll i = 0; i < m; i++) {
        cin >> u >> v;
        ed[u].push_back(v);
        ind[v]++;
    }
    vector<int> vis(n+1, 0);
    queue<int> q;
    for (ll i = 1; i < n+1; i++) {
        if (!ind[i]) {
            q.push(i);
            vis[i] = -1;
        }
    }
    while (!q.empty()) {
        int c = q.front();
        q.pop();
        for (ll i = 0; i < ed[c].size(); i++) {
            ind[ed[c][i]]--;
            if (!vis[ed[c][i]] && !ind[ed[c][i]]) {
                vis[ed[c][i]] = c;
                q.push(ed[c][i]);
            }
        }
    }
    if (!cycle(vis))
        cout << "-1\n";
    else {
        vector<int> res;
        ll mx = n+1;
        REP(i, 1, n+1) {
            while(!q.empty())
                q.pop();
            REP(j, 1, n+1)
                vis[j] = 0;
            q.push(i);
            //cerr << i;
            int cy = 0;
            while (!q.empty()) {
                int c = q.front();
                q.pop();
                //cerr << c << " ";
                for (ll j = 0; j < ed[c].size(); j++) {
                    if (!vis[ed[c][j]]) {
                        vis[ed[c][j]] = c;
                        q.push(ed[c][j]);
                    }
                    if (ed[c][j] == i) {
                        cy = 1;
                        break;
                    }
                }
            }
            if (!cy)
                continue;
            vector<int> cyc;
            int p = vis[i];
            while (p != i) {
                cyc.push_back(p);
                //cerr << p << " ";
                p = vis[p];
            }
            cyc.push_back(i);
            //cerr << cyc.size() << " ";
            reverse(cyc.begin(), cyc.end());
            if (cyc.size() < mx) {
                res = cyc;
                mx = cyc.size();
            }
        }
        cout << mx << endl;
        REP(i, 0, res.size())
            cout << res[i] << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    cout<<(x - a) % b;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0, d = 0, e = 0, ans = 0, x = 0, y = 0, z = 0, maxy = -1,maxy2=-1, mini = 999999999, mini2 = 9999999999, counter = 0, endp = 0, checker = 0;
std::string code;
vector<long long int>vec;
long long int N = 0, M = 0,R=0;
long long int costs[201][200*199/2+1],visit[10],hairetu[1000000],yusya[1000000];

int main() {
	cin >> a ;
	rep(i, a+1) {
		cin >> hairetu[i];
}
	rep(i, a) {
		cin >> yusya[i];
	}
	rep(i, a) {
		if (hairetu[i]>= yusya[i]) {
			ans += yusya[i];
			hairetu[i] -= yusya[i];
}
		else if (hairetu[i] < yusya[i]) {
			if (hairetu[i + 1] < yusya[i] - hairetu[i]) {
				ans += hairetu[i]+hairetu[i+1];
				hairetu[i] = 0;
				hairetu[i + 1] = 0;
			}
			else {
				ans += yusya[i];
				hairetu[i + 1] -= yusya[i] - hairetu[i];
				hairetu[i] = 0;
				if (hairetu[i + 1] < 0) { hairetu[i + 1]; }
			}
		}
	}
	cout << ans << endl;
}




Measured memory_bytes: 5120
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 k, a, b;
    std::cin >> k >> a >> b;
    if (b - a < 2) {
        std::cout << 1 + k << std::endl;
    } else {
        k -= a - 1;
        std::cout << (a + (k / 2) * (b - a) + (k % 2)) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;
using System.Reflection;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            int[] h = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] dp = new int[n];
            dp[0] = 0;
            dp[1] = Abs(h[1] - h[0]);
            for (int i = 1; i < n-1; i++)
            {
                dp[i + 1] = Min(Abs(h[i + 1] - h[i]) + dp[i], Abs(h[i + 1] - h[i - 1]) + dp[i - 1]);
            }
            WriteLine(dp[n-1]);
        }
    }
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 12
#define MAX_M 1000
#define INF 1152921504606846976
using P = pair<i64, i64>;
i64 dp[MAX_M + 1][1 << MAX_N];

int main() {
    i64 N, M; cin >> N >> M;
    vector<i64> A(M);
    vector<i64> B(M, 0);
    REP(i, M) {
        i64 b, c;
        cin >> A[i] >> b;
        REP(j, b) {
            cin >> c;
            c--;
            B[i] |= 1 << c;
        }
    }

    REP(i, M + 1) REP(j, 1 << N) dp[i][j] = INF;
    dp[0][0] = 0;

    REP(i, M) {
        for (i64 bit = 0; bit < (1 << N); bit++) {
            chmin(dp[i + 1][bit], dp[i][bit]);
            chmin(dp[i + 1][bit | B[i]], dp[i][bit] + A[i]);
        }
    }
    i64 ans = dp[M][(1 << N) - 1];
    if (ans < INF) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}

Measured memory_bytes: 32256
fun main(args: Array<String>) {
    val X = readLine()!!
    var cnt = 0
    var cntS = 0

    for (v in X) {
        when (v) {
            'S' -> {
                cntS++
            }
            'T' -> {
                if (cntS == 0) cnt++
                cntS = Math.max(0, cntS - 1)
            }
        }
    }
    println(cnt + cntS)
}


Measured memory_bytes: 33784
#include <stdio.h>

int main(void){
	int H, W, i, j;

	do{
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0){
			
			break;
		
		}else{
			
			for(i = 0; H > i; i++){
				for(j = 0; W > j; j++){
					printf("#");
				}
				printf("\n");
			}
			
			printf("\n");

		}
	
	}while(H != 0 && W != 0);
	
	return(0);

}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  998244353
const int N = 1e5 + 5;
 
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
	ll n,m;
	cin >> n >> m;
    string s[m];
    ll a[m];
    for(ll i=0;i<m;i++)     cin >> a[i] >> s[i];
    ll total = 0,penalty = 0;
    map<ll,ll> y;
    for(ll i=0;i<m;i++)
    {
    	if(s[i]=="AC" && y[a[i]]>=0)    total++,penalty+=y[a[i]],y[a[i]]=-10000000000;
    	else              y[a[i]]++;
    }
    cout<<total<<" "<<penalty;
    
	
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v) reverse(v.begin(),v.end())
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};
int gcd(int n,int m){
	if(m>n) return gcd(m,n);
	if(m==0) return n;
	else return gcd(m,n%m); 
}

int main(void){
	ll	r,D,x_2000;
	ll result=0;
	cin>>r>>D>>x_2000;

	result=x_2000;
	REP(i,10){
		result=r*result-D;
		print(result);
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
   char a[5];
   scanf("%s",a);
   int i=0;
   for(;i<3 && a[i]!=a[i+1];i++);
  
   if(i==3) 
     printf("Good");
   else
     printf("Bad");
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int R;
    cin >> R;
    if (R < 1200)
        cout << "ABC";
    else if (R < 2800)
        cout << "ARC";
    else
        cout << "AGC";
}

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

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

int main()
{
    ll D, T, S;
    cin >> D >> T >> S;

    string ans;

    if (D <= T * S)
        ans = "Yes";
    else
        ans = "No";

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n, d;
  cin >> n >> d;
  int x[n][d];

  REP(i,n){
    REP(j,d) cin >> x[i][j];
  }

  int cnt = 0;
  REP(i,n){
    for(int k = i + 1; k < n; ++k){
      int sum = 0;
      REP(j,d){
        int diff =abs(x[i][j]-x[k][j]);
        sum += (diff * diff);
      }
      for(int pi = 0; pi*pi <= sum; ++pi){
        if(sum == pi*pi) ++cnt;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    string s;
    cin >> n >> s;
    REP(i, 1000) {
        ostringstream ss;
        ss << setw(3) << setfill('0') << i;
        string t(ss.str());
        bool flag = true;
        size_t pos = 0;
        REP(j, 3) {
            pos = s.find(t.substr(j, 1), pos);
            if (pos == string::npos) {
                flag = false;
                break;
            }
            pos++;
        }
        if (flag)
            ans++;
    }
    cout << ans << endl;

    return 0;
}


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

#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define lch (o << 1)
#define rch (o << 1 | 1)

typedef double db;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pint;
typedef tuple<int, int, int> tint;

const int INF = 0x3f3f3f3f;
const ll INF_LL = 0x3f3f3f3f3f3f3f3f;

int main() {
	ios::sync_with_stdio(0);

	string s;
	cin >> s;
	int ans = 0;
	if (s.substr(0, 1) == "R" || s.substr(1, 1) == "R" || s.substr(2, 1) == "R") ans = 1;
	if (s.substr(0, 2) == "RR" || s.substr(1, 2) == "RR") ans = 2;
	if (s.substr(0, 3) == "RRR") ans = 3;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin>>s;
    int ans = 0;
    for(int i=0;i<s.size();i++)
    {
        int j = s.size()-i-1;
        if(s[i] != s[j] && i < j) ans++;
    }
    cout << ans << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
//------------------------------------------------------------------------------------------------------------------------------

int main(void) { 
    int N;
    cin >> N;
    int pre = -1;
    string ans = "Yes";
    for (int i = 0; i < N; i++) {
        int h;
        cin >> h;
        if(pre>h){
            ans = "No";
            break;
        }
        if (pre < h) h--;
        pre = h;
    }
    cout << ans << endl;
}


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

class Program
{
    static void Main()
    {
        var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = line[0];
        var K = line[1];
        var ans = N - (K - 1);
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
#define int long long
signed main(void){
    int N;
    int F=0;
    int S=0;
    int Ans=0;
    int A[114514];
    cin >> N;
    REP(i,N){cin >> A[i];}
    sort(A,A+N,greater<int>());
    REP(i,N){
        if(A[i]==A[i+1]){
            if(F==0){
                F=A[i];
                A[i]=0;
                A[i+1]=0;
            }else{
                S=A[i];
                break;
            }
        }
    }
    Ans=F*S;
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 

  int main(){      
     string s;
     lint n,p;

     cin>>n>>p>>s;
     reverse(all(s));
     lint a[n];
     lint mul=1;
    lint b[n+1];
     lint ans=0;
     map<lint,lint> mp;
     if(p==2){
         rep(i,n){
             lint x=s[i]-'0';
             if(x%2==0)ans+=n-i;
         }
     }else if(p==5){
          rep(i,n){
             lint x=s[i]-'0';
             if(x%5==0)ans+=n-i;
         }
     }else{
     rep(i,n){
         lint x=s[i]-'0';
         x*=mul;
         x%=p;
         a[i]=x;
         mul*=10;
         mul%=p;
     }
     b[0]=0;
     mp[0]++;
     rep(i,n){
         b[i+1]=b[i]+a[i];
         b[i+1]%=p;
         mp[b[i+1]]++;
     }
     for(auto x:mp){
         ans+=x.second*(x.second-1)/2;
     }}
     cout<<ans<<endl;
          }
  
     


Measured memory_bytes: 4100
#include<bits/stdc++.h>
using namespace std;
#define sachin ios_base::sync_with_stdio(false);cin.tie(NULL);
int main()
{
    sachin
    long long n,count1=1;
    string s;
    cin>>s;
    n=s.size();
    vector <long long> vect,vect2(n,0);
    char a='R';
    for(int i=1;i<n;i++)
    {
        while(i<n && s[i]==a)
        i++,count1++;
        //vect2[i-1]=1;vect2[i]=1;
        vect.push_back(count1);
        if(i==n-1 && a!='L')
            vect.push_back(1);
        if(a=='R')
            a='L';
        else a='R';
        count1=1;
    }
    long long k=0;
    for(int i=0;i<n-1;i++)
    {
        if(s[i]=='R' && s[i+1]=='L')
        {
            long long mid=(vect[k]+vect[k+1])/2;
            if((vect[k]+vect[k+1])%2==0)
            vect2[i]=mid,vect2[i+1]=mid;
            else if(vect[k]>vect[k+1])
            {
                if((vect[k]-1)%2==0)
                    vect2[i]=1+mid,vect2[i+1]=mid;
                else vect2[i]=mid,vect2[i+1]=mid+1;
            }
            else
            {
                if((vect[k+1]-1)%2==0)
                    vect2[i+1]=1+mid,vect2[i]=mid;
                else vect2[i+1]=mid,vect2[i]=mid+1;
            }
            k+=2;
        }
    }
    for(int i=0;i<n;i++)
    cout<<vect2[i]<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 2248
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int n;
  cin >> n;
  ll x = 1;
  loop(i,1,n+1) {
    x *= i;
    x %= 1000000007;
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc089.contest.atcoder.jp/tasks/arc089_b>
問題文============================================================
シカのAtCoDeerくんは無限に広がる二次元グリッドを一辺が K の市松模様で塗ろうと考えています。
 ただし、一辺が K の市松模様とは、各マスが白か黒で塗られたパターンであって、
 各色の各連結成分が K × K の正方形となっているようなものです。
 
 AtCoDeerくんは N 個の希望を持っています。 i 個目の希望は、 xi,yi,ci で表されます。
 これは、ci が B ならマス (xi,yi) を黒で塗る、 W なら白で塗ることを意味しています。
 同時に最大でいくつの希望を叶えることが出来るか答えてください。
 
=================================================================

解説=============================================================

================================================================
*/
vector<vector<int>> cusum;
inline int f(int lx,int ly,int rx,int ry){
    return cusum[rx][ry] - cusum[rx][ly] - cusum[lx][ry] + cusum[lx][ly];
}

int solve(){
    int N,K; cin >> N >> K;
    vector<ll> x(N),y(N);
    vector<char> c(N);
    for(int i = 0; i < N;i++) cin >> x[i] >> y[i] >> c[i];

    // (x,y,B) := (x+K,y,W)
    for(int i = 0; i < N;i++){
        if(c[i] == 'B') x[i] += K; c[i] = 'W';
    }
    
    // (x,y,W) := (x%2K,y%2K,W)
    for(int i = 0; i < N;i++){
        x[i] %= 2*K; y[i] %= 2*K;
    }
    // init cusum
    cusum.resize(2*K+1,vector<int>(2*K+1,0));
    for(int i = 0; i < N;i++){
        cusum[x[i]+1][y[i]+1]++;
    }
    
    for(int i = 1; i <= 2*K;i++){
        for(int j = 1; j <= 2*K;j++){
            cusum[i][j] += cusum[i][j-1] + cusum[i-1][j] - cusum[i-1][j-1];
        }
    }
    
    // solver
    int ans = 0;
    for(int i = 1; i <= 2*K;i++){
        for(int j = 1; j <= 2*K;j++){
            if(i <= K && j <= K){
                ans = max(ans,
                          f(0,0,i,j)+
                          f(i,j,i+K,j+K)+
                          f(0,j+K,i,2*K)+
                          f(i+K,0,2*K,j)+
                          f(i+K,j+K,2*K,2*K)
                          );
            }
            if(i > K && j > K){
                ans = max(ans,
                          f(i-K,j-K,i,j)+
                          f(0,0,i-K,j-K)+
                          f(0,j,i-K,2*K)+
                          f(i,0,2*K,j-K)+
                          f(i,j,2*K,2*K)
                          );
            }
            if(i <= K && j > K){
                ans = max(ans,
                          f(0,j-K,i,j)+
                          f(i,j,i+K,2*K)+
                          f(i,0,i+K,j-K)+
                          f(i+K,j-K,2*K,j)
                          );
            }
            if(i > K && j <= K){
                ans = max(ans,
                          f(i-K,0,i,j)+
                          f(i,j,2*K,j+K)+
                          f(0,j,i-K,j+K)+
                          f(i-K,j+K,i,2*K)
                          );
            }
        }
    }
    return ans;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAX = 1e5 + 10;
int prime[MAX], tag[MAX], f[MAX];
void is_Prime(){
	int cnt = 0;
	prime[++cnt] = 2;
	tag[1] = 1;
	for( int i = 2; i < MAX; i++){
		if(!tag[i])
			prime[++cnt] = i;
		for(int j = 1; j <= cnt && i * prime[j] < MAX; j++){
			tag[i * prime[j]] = 1;
			if( i % prime[j] == 0)
				break;
		}
	}
}
int main(){
	int t, l, r, num = 0;
	is_Prime();
	
	for (int i=1; i <= MAX; i++)
    {
        if(tag[i] == 0 && tag[(i+1)/2] == 0 && i != 2)
            {
                f[i]=f[i-1]+1;
            }
        else f[i]=f[i-1];
    }
    
	cin >> t;
	while(t--){
		scanf("%d%d", &l, &r);
		printf("%d\n", f[r] - f[l - 1]);
	}
	return  0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  
  map<int, int> mp;
  lint n, x, y; cin >> n >> x >> y;
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      int k = j - i;
      int a = (int)abs(i - x) + (int)abs(j - y) + 1;
      int b = (int)abs(i - y) + (int)abs(j - x) + 1;
      k = min(k, min(a, b));
      mp[k]++;
    }
  }
  for (int i = 1; i < n; i++) cout << mp[i] << endl;
  return 0;
}


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

int main(){
    int N; cin>>N;
    int c=0,d=1000000000;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        c=max(c,a); d=min(d,a);
    }
    cout<<c-d<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int K;
	long long ans = 0;
	cin >> K;
	for(int i=1; i<=K; i++)
		for(int j=1; j<=K; j++)
			for(int k=1; k<=K; k++)
				ans += __gcd(__gcd(i, j), k);
	cout << ans << endl;
}


Measured memory_bytes: 3636