akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
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; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}
vector<vector<int>> graph;

vector<int> dp;
int dfs(int v){
    if(dp[v] != -1)return dp[v];
    int v_long = 0;
    for(auto nxt : graph[v]){
        chmax(v_long,dfs(nxt) + 1);
    }

    return dp[v] = v_long;
}


int main(){
    
    int n,m;
    cin >> n >> m;
    graph.resize(n);
    dp.resize(n);
    REP(i,n)dp[i] = -1;
    int x,y;
    REP(i,m){
        cin >> x >> y;
        x--;y--;
        graph[x].push_back(y);
    }
    int res = 0;
    REP(i,n){
        chmax(res,dfs(i));
    }

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


Measured memory_bytes: 10988
#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>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(int n, int k) {
    return fact[n]*ifact[n-k];
  }
} c(1000005);

int main() {
  int n, m;
  cin >> n >> m;
  mint ans = 0;
  rep(i,n+1) {
    mint now = c(n,i);
    now *= c.p(m,n);
    now *= c.p(m-i,n-i);
    if (i&1) now = -now;
    ans += now;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 18640
#include <iostream>

using namespace std;

int main() {
	int n;

	cin >> n;

	for(int i = 1;i <= n;i++) {
		if(i % 3 == 0) {
			cout << " " << i;
		} else if(i % 10 == 3) {
			cout << " " << i;
		} else {
			int x = i;

			while(x) {
				x /= 10;

				if(x % 10 == 3) {
					cout << " " << i;
					break;
				}
			}
		}
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 3096
R, G, B, N = [int(s) for s in input().split()]
MAX = 3001
count = 0
proglist = [1 for r in range(MAX) for g in range(MAX) if (N-r*R-g*G) % B == 0 and (N-r*R-g*G) >= 0]
print(sum(proglist))

Measured memory_bytes: 130260
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut aseq = vec![0; n];
    for i in 0..n {
        aseq[i] = read();
    }
    aseq.sort();
    aseq.reverse();
    let mut ans = 0;
    for i in 0..n {
        let sign = if i % 2 == 0 { 1 } else { -1 };
        ans += sign * aseq[i];
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


N,Q = map(int,input().split())
BIT = [0]*(N+1)

def add(loc,value):
    global N
    BIT[loc] += value

    loc += loc & -loc

    while loc <= N:
        BIT[loc] += value
        loc += loc & -loc


def getSum(loc):
    ret = BIT[loc]
    loc -= loc & -loc

    while loc > 0:
        ret += BIT[loc]
        loc -= loc & -loc

    return ret


def calc(left,right):
    return getSum(right)-getSum(left-1)


for _ in range(Q):
    command,left,right = map(int,input().split())

    if command == 0:
        add(left,right)
    else:
        print("%d"%(calc(left,right)))


Measured memory_bytes: 16204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (ll i = 0; i < ll(n); i++)

const int N = 200005;
int dir[4]{-1, 1, 0, 0};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, k, sx, sy, gx, gy;
    cin >> h >> w >> k;
    cin >> sx >> sy >> gx >> gy;
    sx--, sy--, gx--, gy--;
    vector<string> grid(h);
    rep(i, h) cin >> grid[i];

    ll dist[h][w];
    rep(i, h) rep(j, w) dist[i][j] = 1e9;
    dist[sx][sy] = 0;
    queue<pll> q;
    q.push({sx, sy});
    while (!q.empty()) {
        auto p = q.front();
        q.pop();
        ll cx = p.first;
        ll cy = p.second;
        rep(i, 4) {
            for (int hop = 1; hop <= k; hop++) {
                ll nx = cx + dir[i] * hop;
                ll ny = cy + dir[3 - i] * hop;
                if (nx >= h || ny >= w || nx < 0 || ny < 0 || grid[nx][ny] == '@')
                    break;
                if (dist[nx][ny] > dist[cx][cy] + 1) {
                    dist[nx][ny] = dist[cx][cy] + 1;
                    q.push({nx, ny});
                } else if (dist[nx][ny] == dist[cx][cy] + 1)
                    continue;
                else
                    break;
            }
        }
    }
    cout << (dist[gx][gy] == 1e9 ? -1ll : dist[gx][gy]) << endl;
}

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

int main(){

  long long N, K;
  cin >> N >>K;
  vector<pair <long long,long long> > array(N);

  for(int i = 0; i < N; i++){
    int a,b;
    cin >> a >> b;
    array.at(i).first = a;
    array.at(i).second = b;
  }
  
  sort(array.begin(),array.end());


  long long counter = 0;
  long long answer = 0;
  for(auto num : array){
    counter += num.second;
    if (counter >= K) {
      answer = num.first;
      break;
    }
  }
  cout << answer << endl;
}


Measured memory_bytes: 1792
using System;
 class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            if (-100<=A&&B<=100)
            {
                int max=-99999999;
                int[] number = { A + B, A - B, A * B };
                for (int i = 0; i < 3; i++)
                {
                    if (max<=number[i])
                    {
                        max = number[i];
                    }
                }

                Console.WriteLine(max);
                Console.ReadLine();
            }
        }
    }

Measured memory_bytes: 13140
#include <stdio.h>

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

	while (H != 0 && W != 0)
	{
		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0) break;
		for (i = 0; i < H; i++)
		{
			for (j = 0; j < W; j++)
			{
				if (((j % 2 == 0)&&(i % 2 == 0)) || ((j % 2 == 1) && (i % 2 == 1)))
				{
					printf("#");
				}
				else
				{
					printf(".");
				}
			}
			printf("\n");

		}

		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	int a, b; cin >> a >> b;
	if(b > a) rep(i, b) cout << a;
	else rep(i, a) cout << b;
	cout << endl;
}

Measured memory_bytes: 256
def trace(x):
    for e in x:
        print e,
    print

n = input()
x = map(int, raw_input().split())
trace(x)

for j in range(1, n):
    key = x[j]
    for i in range(j)[::-1]:
        if x[i] > key:
            x[i+1] = x[i]
        else:
            i += 1
            break
    else:
        i = 0
    x[i] = key
    trace(x)

Measured memory_bytes: 4236
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    ll n, m;
    cin >> n >> m;
    if (n==1 && m==1) cout << "1\n";
    else if (n==1 || m==1) cout << max(n,m)-2 << endl;
    else cout << (n-2)*(m-2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  
#define lli long long 
using namespace std; 
long long mod=1e9+7;
lli power(lli x, lli y,lli m=mod) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%m; 
        y = y>>1; 
        x = (x*x)%m;  
    }
    if(res<0)
       res+=m; 
    return res; 
}
// lli fact[2000009];
// lli ncr(lli n,lli r){
//     lli ans=fact[n];
//     if(r>n)return 1;
//     if(r<0)return 0;
//     if(n<0)return 0;
//     ans=(ans*power(fact[n-r],mod-2))%mod;
//     ans=(ans*power(fact[r],mod-2))%mod;
//     return ans;
// }
int main() 
{ 
    // fact[0]=1;
    // for(int i=1;i<=2000005;i++)fact[i]=(i*fact[i-1])%mod;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        long long n;cin>>n;
        long long ans=power(10,n);
        ans=(ans-power(9,n)-power(9,n)+power(8,n))%mod;
        ans=(ans+mod)%mod;
        cout<<ans<<"\n";
    }
    return 0; 
} 

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

int main(){
  int n,array[200000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>array[i];
  }
  if(n%2){
    int a=n-1;
    while(a!=-2){
      cout<<array[a]<<" ";
      a-=2;
    }
    int b=1;
    while(b!=n){
      if(b==n-2){
        cout<<array[b];
        break;
      }
      cout<<array[b]<<" ";
      b+=2;
    }
  }else{
    int a=n-1;
    while(a!=-1){
      cout<<array[a]<<" ";
      a-=2;
    }
    int b=0;
    while(b!=n){
      if(b==n-2){
        cout<<array[b];
        break;
      }
      cout<<array[b]<<" ";
      b+=2;
    }
  }
  cout<<endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
 
 
#define ll long long int  
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
 
 
using namespace std;




void util(){
	string s,t;
	cin>>s>>t;

	int n = s.length();
	int m = t.size();

	int ans = INT_MAX;

	for(int i=0;i<n-m+1;i++){
		string temp = s.substr(i,m);
		int count = 0;
		for(int j=0;j<m;j++){
			if(t[j]!= temp[j]){
				count++;
			}
		}

		ans = min(ans, count);
	}

	cout<<ans<<endl;

}


int main()
{
	/* code */

	
		util();
	

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>
using namespace std;
typedef pair<int, int> P;
int main(void){
    int n, x[50], y[50], a = 0;
    map<P, int> m;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j == i)continue;
            int p = x[i] - x[j], q = y[i] - y[j];
            a = max(a, ++m[P(p, q)]);
        }
    }
    cout << n - a << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>

using namespace std;


int main(){
	int n;
	cin>>n;
	int hen1,hen2,hen3,saidai,max_pos;

	for(int i=0;i<n;i++){
		cin>>hen1>>hen2>>hen3;
max_pos=1;
		saidai=hen1;
		if(saidai<hen2){
			saidai=hen2;
			max_pos=2;
		}
		if(saidai<hen3){
			saidai=hen3;
			max_pos=3;
		}
		switch(max_pos){
		case 1:
			hen1=0;
			break;
		case 2:
			hen2=0;
			break;
		case 3:
			hen3=0;
			break;
		}
		if(saidai*saidai==(hen1*hen1+hen2*hen2+hen3*hen3))
			cout<<"YES"<<"\n";
		else{
			cout<<"NO"<<"\n";
		}
	}
	
	
	return 0;
}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

ll dp[MX][MX];
inline void chmax(ll& a, ll b) {
  a = max(a, b);
}

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back


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

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

int main() {
  string S; cin >> S;
  bool heisei = true;
  if (S.at(5) == '1') {
    heisei = false;
  }

  else if (S.at(5) == '0') {
    if (S.at(6) == '1' || S.at(6) == '2' || S.at(6) == '3') {
    }
    else if (S.at(6) == '4') {
      if (S.at(8) == '0' || S.at(8) == '1' || S.at(8) == '2') {
        heisei = true; 
      }
      else if (S.at(8) == '3' && S.at(9) == '0'){
        heisei = true;
      }
      else {
        heisei = false;
      }
    }
    else {
      heisei = false;
    }

  }
  if (heisei) {
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
typedef long long ll;
using namespace std;
int main(void){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int x3,y3,x4,y4;
    int vec[2];
    vec[0]=x2-x1;
    vec[1]=y2-y1;
    x3=x2-vec[1];
    y3=y2+vec[0];
    x4=x1-vec[1];
    y4=y1+vec[0];
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>   
using namespace std;
#define N 1000000
#define REP(i, n) for(int i=0; i<n; i++)
int x,y,z;
int k,s;
int main(void){
    cin>>k>>s;
    int ans=0;
    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
           int t=s-i-j;
           if(0<=t&&t<=k)ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
int a[4][13]={0};
int i, j, k, x, n;
char m;

scanf("%d", &n);

for(k = 0; k < n; k++){
scanf(" %c%d", &m, &x);
if(m == 'S')
a[0][x - 1] = 1;
else if(m == 'H')
a[1][x - 1] = 1;
else if(m == 'C')
a[2][x - 1] = 1;
else if(m == 'D')
a[3][x - 1] = 1;
}

for(i = 0; i < 4; i++){
for(j = 0; j < 13; j++){
if(a[i][j] == 0){
if(i == 0)
printf("S %d\n", j + 1);
else if(i == 1)
printf("H %d\n", j + 1);
else if(i == 2)
printf("C %d\n", j + 1);
else if(i == 3)
printf("D %d\n", j + 1);
}
}
}
return 0;
}


Measured memory_bytes: 2108
#include <stdio.h>
int main(void){
    int n,m,x,y;
    scanf("%d%d%d%d",&n,&m,&x,&y);
    int k;
    for(int i=0;i<n;i++){
        scanf("%d",&k);
        if(k>x)x=k;
    }
    for(int i=0;i<m;i++){
        scanf("%d",&k);
        if(y>k)y=k;
    }
    if(x<y)printf("No War\n");
    else printf("War\n");
}

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

int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    if(s[k-1] == 'A') s[k-1] = 'a';
    else if(s[k-1] == 'B') s[k-1] = 'b';
    else if(s[k-1] == 'C') s[k-1] = 'c';
    cout << s << endl;
}

Measured memory_bytes: 256
//agc017_b.cpp
//Wed Jul 31 21:54:42 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;

	for (int i=0;i<=n-1;i++){
		ll bottom = c*(n-1-i)-d*i;
		ll top = d*(n-1-i)-c*i;
		if (b-a>=bottom && b-a<=top){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      // 取得
      BigInteger A = sc.nextBigInteger();
      BigInteger B = sc.nextBigInteger();
      if(A.compareTo(B)>0){
        System.out.println("GREATER");
      }else if(A.compareTo(B)<0){
        System.out.println("LESS");
      }else{
        System.out.println("EQUAL");
      }
    }
}

Measured memory_bytes: 35772
import itertools
import math
import copy
n = int(input())
x_y= [list(map(int,input().split())) for X in range(n)]

#n!を作成
n_sum = math.factorial(n)
#n個の要素で順列を作成
n_list = list(itertools.permutations(x_y,n))
ans = 0
#順列を選択
for i in range(len(n_list)):
	#順列内の要素を順番通りに選択し、ansに加算する
	#繰り返し回数はlen(n_list)-1
	tmp = copy.copy(n_list[i])
	for j in range(n-1):
		ans += math.sqrt((tmp[j][0] - tmp[j+1][0])**2 + ((tmp)[j][1] - tmp[j+1][1])**2)
print('{:.10f}'.format((ans/n_sum)))

Measured memory_bytes: 14000
#include <bits/stdc++.h>
#define mod 1000000007
// #define mod 998244353
#define pb push_back
#define ll long long
#define ld long double
#define ft first
#define sd second
using namespace std;

const int N = 52;
int n; 

struct matrix {
    int a[N][N];
};

matrix I() {
    matrix x;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            x.a[i][j] = (i == j);
        }
    }
    return x;
}

matrix mul(matrix a, matrix b) {
    matrix c; 
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            c.a[i][j] = 0;
            for(int k = 0; k < n; k++) {
                c.a[i][j] = (c.a[i][j] + 1ll * a.a[i][k] * b.a[k][j] % mod) % mod;
            }

        }
    }
    return c;
}
matrix power(matrix a, ll b) {
    matrix x = I();
    while(b) {
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b /= 2;
    }
    return x;
}
signed main() {

    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    cin >> n;
    ll k; cin >> k;
    matrix a;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> a.a[i][j];
        }
    }
    // a = mul(a, a);
    /*for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cout << a.a[i][j] << " ";
        }
        cout << "\n";
    }*/
    a = power(a, k);
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            ans += a.a[i][j];
        }
    }
    cout << ans % mod << endl;


    return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
  
  
int main()
{
   int a,b;
  
   cin >> a >> b;
  
   if(a>b)
      cout << "a > b" << endl;
   else if (a<b)
      cout << "a < b" << endl;
   else
      cout << "a == b" << endl;
  
   return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

char G[105][105];
ll cost[105][105];

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w; cin>>h>>w;
  rep(i,h) rep(j,w) cin>>G[i][j];
  
  queue<pll> q;
  q.emplace(0,0);
  memset(cost,-1,sizeof(cost));
  cost[0][0]=0;
  if(G[0][0]=='#') cost[0][0]=1;
  while(!q.empty()){
    ll y=q.front().first, x=q.front().second;
    q.pop();
    rep(i,2){
      ll ny=y+dy[i], nx=x+dx[i];
      if(inside(ny,nx,h,w)){
        if(G[y][x]=='#'){
          if(cost[ny][nx]==-1 || cost[ny][nx]>cost[y][x]){
            if(cost[ny][nx]==-1) q.emplace(ny,nx);
            cost[ny][nx]=cost[y][x];
          }
        }else{
          if(G[ny][nx]=='#'){
            if(cost[ny][nx]==-1 || cost[ny][nx]>cost[y][x]+1){
              if(cost[ny][nx]==-1) q.emplace(ny,nx);
              cost[ny][nx]=cost[y][x]+1;
            }
          }else{
            if(cost[ny][nx]==-1 || cost[ny][nx]>cost[y][x]){
              if(cost[ny][nx]==-1) q.emplace(ny,nx);
              cost[ny][nx]=cost[y][x];
            }
          }
        }
      }
    }
  }
  
  cout<<cost[h-1][w-1]<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<string>
#include<stdio.h>
#include<cmath>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define lint long long


int main(){
    int n; double t, a;
    cin>>n>>t>>a;
    vector<double> h;
    rep(i,n) { int x; cin>>x; h.push_back(x); }
    vector<pair<double, int> > tmp;
    rep(i,n) tmp.push_back(make_pair(abs(a - (t - h[i] * 0.006)), i));
    sort(all(tmp));
    cout << tmp[0].second + 1 << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int x[n+5];
	int maxc=0;
	for(int i=1;i<=n;i++)
	{
		cin>>x[i];
		if(x[i]>maxc)
		{
			maxc=x[i];
		}
	}
	int minn=0x7fffffff;
	for(int i=0;i<=maxc;i++)
	{
		int s=0;
		for(int j=1;j<=n;j++)
		{
			s+=(x[j]-i)*(x[j]-i);
		}
		if(s<minn)
		{
			minn=s;
		}
	}
	cout<<minn;
	return 0;
}



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

int judge(int* a, int n){
  int key = 0;
  for(int i = 0; i < n; i++){
    if(a[i] != i+1){
      key++;
    }
  }
    if(key <= 2){
      return 1;
    }else{
      return 0;
    }
  
}

int main(){
  int N;
  cin >> N;

  int A[N];
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  if(judge(A, N)){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  

  return 0;
}

Measured memory_bytes: 256
/*
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:07/03/2020
*/
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
#define ld long double
#define ff first
#define ss string 
#define se second
#define alt(v) v.begin(),v.end()
#define pb emplace_back
#define mp make_pair
#define tc(t) cin>>t;while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fab(i,a,b) for(ll i=(a);i<(b);i++)
#define fba(i,a,b) for(ll i=(b);i>=(a);i--)
#define arr(i,n) fab(i,0,n)

ll test=0;
void solve()
{

    ll i,j,f=0,k,x1,x2,y,q,m,n;
    cin>>n>>x1>>x2;
    m=(n/(x1+x2));
    n%=(x1+x2);
    if(n>x1)
    n=x1;
    cout<<m*x1+n<<endl;
    
   
    
}














int main()
{
    ll t=1,s;
    if(test)
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL N;
std::vector<LL>a, b, c;
std::vector<std::vector<LL>>memo;

LL dp(LL i, LL j)
{
	if (i == N) return 0;
  	if (j!=-1){
	if (memo[i][j] != -1) return memo[i][j];
    }
  LL res;
	LL res1 = 0, res2 = 0, res3 = 0;
	if (j != 0) res1 = dp(i + 1, 0) + a[i];
	if (j != 1) res2 = dp(i + 1, 1) + b[i];
	if (j != 2) res3 = dp(i + 1, 2) + c[i];
   res= std::max({ res1, res2, res3 });
   if (j!=-1){
     
     memo[i][j] =res;
   }
	return res;
}

int main()
{
	in >> N;
	a.resize(N); b.resize(N); c.resize(N);
	rep(i, N) in >> a[i] >> b[i] >> c[i];

	memo.resize(N);
	rep(i, memo.size()) memo[i].resize(3, -1);
	out << dp(0, -1) << std::endl;
}


Measured memory_bytes: 14336
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, string> pls;

int main()
{
	int N; cin >> N;

	int ans=1,mx=0;
	for (int i = 1; i <= N; i++) {
		int cnt = 0,a = i;
		while (a != 0) {
			if (a % 2 == 0) {
				a /= 2;
				cnt++;
			}
			else break;
		}
		if (mx < cnt) {
			mx = cnt;
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using ll = long long;
using boost::irange;

int main(){
    ll N, Q;
    ll K;

    cin >> N >> K >> Q;
    vector<ll> v(N, 0);

    int j;
    for (int i : irange<ll>(0, Q)){
        cin >> j;
        v[j-1]++; 
    }
    for (int i : irange<ll>(0, N)){
        if (Q - v[i] >= K){
            cout << "No" << endl;
        }
        else {
            cout << "Yes" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1408
n = gets.to_i
as = []
n.times{ as << gets.to_i}

asl = []
as.each do |a|
  if asl.empty?
    asl << a
  else
    asl << [a, asl.last].max
  end
end

asr = []
as.reverse_each do |a|
  if asr.empty?
    asr << a
  else
    asr << [a, asr.last].max
  end
end
asr.reverse!

(0..n-1).each do |i|
  if i == 0
    p asr[i+1]
  elsif i == n-1
    p asl[i-1]
  else
    p [asl[i-1], asr[i+1]].max
  end
end


Measured memory_bytes: 9212
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use std::process::exit;
use std::cmp::*;
use itertools::Itertools;

fn main() {
    input! {
    a:usize,
    b:usize,
    c:[(isize,isize);b],
    }
    let d = c.iter().map(|(a,b)| *a).min().unwrap();
    let e = c.iter().map(|(a,b)| *a).max().unwrap();
    let f = c.iter().map(|(a,b)| *b).min().unwrap();
    let g = c.iter().map(|(a,b)| *b).max().unwrap();
    println!("{}",max( min(g-d+1,f-e+1),0))
}

Measured memory_bytes: 4660
#include <stdio.h>

int yaku(int x,int y)
{
	int z;
	if(x>y)
	{
		z=x;
		x=y;
		y=z;
	}
	while(x!=0)
	{
		z=y%x;
		y=x;
		x=z;
	}
	
	return y;
}

int main()
{
	int N,A[100000],x[100000],y[100000],z,ans,i,j;
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d",&A[i]);
	x[0]=A[0];
	for(i=1;i<N;i++)
		x[i]=yaku(x[i-1],A[i]);
	y[N-1]=A[N-1];
	for(i=2;i<=N;i++)
		y[N-i]=yaku(y[N-i+1],A[N-i]);
	if(x[N-2]>y[1])
		ans=x[N-2];
	else
		ans=y[1];
	for(i=2;i<N;i++)
	{
		z=yaku(x[i-2],y[i]);
		if(ans<z)
			ans=z;
	}
	printf("%d",ans);
	return 0;
}


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

int main(){
  string s,t;
  cin >> s >> t;

  bool ans=false;
  for(int i=0;i<s.size();i++){
    if(s==t){
      ans = true;
      break;
    }
    s=s.back() + s.substr(0,s.size()-1);
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n=int(input())
H=list(map(int,input().split()))
dp=[10**9]*n
dp[0]=0
dp[1]=abs(H[1]-H[0])
for i in range(2,n):
    step1=dp[i-1]+abs(H[i]-H[i-1])
    step2=dp[i-2]+abs(H[i]-H[i-2])
    dp[i]=min(step1,step2)
print(dp[-1])

Measured memory_bytes: 13924
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    L = sorted(il())[::-1]
    print('Yes' if sum(L[:1]) < sum(L[1:]) else 'No')



if __name__ == '__main__':
    main()


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

int main() {
    int n, ans, free, ai;
    ans = 0; free = 0;
    scanf("%d", &n);
    vector<int> color(8);
    for (int i = 0; i < n; i++) {
        scanf("%d", &ai);
        for (int j = 0; j < 8; j++) {
            if (400 * j <= ai && ai < 400 * (j + 1)) {
                color.at(j) = 1;
            }
        }
        if (3200 <= ai) free++;
    }
    ans = accumulate(color.begin(), color.end(), 0);
    if (ans == 0) {
        ans = 1;
        free--;
    }
    cout << ans << " " << ans+free << endl;
    return 0;
}

Measured memory_bytes: 3680
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>	
#include <cmath>
#include <cstdlib>
#include <iostream>
using namespace std;
#define rep(x, n) for (int x = 1; x <= n; ++x)
#define zrp(x, n) for (int x = n; x > 0; --x)
#define FOR(x, l, r) for (int x = l; x <= r; ++x)
#define foreach(i, x) for (int i = start[x]; i; i = e[i].l)
const int maxN = 105;
struct T
{
	int a, l;
}e[maxN];
int n, m, ans, start[maxN], tot, vis[maxN], now;

int dfs(int x)
{
	vis[x] = now;
	int s = 1;
	foreach(i, x) if (i / 2 != now)
	{
		int y = e[i].a;
		if (vis[y] == now) continue;
		s += dfs(y);
	}
	return s;
}

int main()
{
	scanf("%d%d", &n, &m);
	tot = 1;
	rep(i, m)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		e[++tot].l = start[x]; e[tot].a = y; start[x] = tot;
		e[++tot].l = start[y]; e[tot].a = x; start[y] = tot;
	}
	
	rep(i, m)
	{
		now = i;
		if (dfs(1) != n)
			++ans;
	}
	cout << ans << endl;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int q;
	string s;
	cin>>s;
	cin>>q;
	bool r = false;
	while(q--){
		int t;
		cin>>t;
		if(t == 1)
			r = !r;
		else{
			int f;
			char c;
			cin>>f>>c;
			if(f == 1){
				if(r){
					s.push_back(c);
				}
				else{
					s.insert(s.begin(), c);
				}
				
			}else{
				if(r){
					s.insert(s.begin(), c);
				}
				else{
					s.push_back(c);
				}
			}
		}
	}
	
	if(r){
		for(auto it = s.rbegin();it != s.rend();it++){
			cout<<*it;
		}
		cout<<endl;
	}
	else{
		cout<<s<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3868
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]) {
	cout.precision(20);
#ifdef _MSC_VER
	while (true)
#endif
	{
		string s;
		cin >> s;
		if (s.empty()) return 0;
		LL ans = 0, sum = 0;
		vector<LL> dp(2020);
		dp[0] = 0;
		for (char c : s) {
			int d = c - '0';
			vector<LL> next(2020);
			for (int i = 0; i < 2019; ++i) {
				int x = (i * 10 + d) % 2019;
				next[x] += dp[i];
			}
			next[d] += 1;
			ans += next[0];
			dp = next;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3628
import sys
n,y=map(int,input().split())
for i in range(n+1):
    for j in range(n-i+1):
        k=n-i-j
        if i*10000+j*5000+k*1000==y:
            print(str(i)+' '+str(j)+' '+str(k))
            sys.exit()
print('-1 -1 -1')

Measured memory_bytes: 3060
from math import gcd
N, M = map(int, input().split())
S = input()
T = input()
G = gcd(N, M)
 
for i in range(G):
    if S[i * N // G] != T[i * M // G]:
        print(-1)
        exit()
 
l = N * M // G
print(l)

Measured memory_bytes: 9248
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int k;
int vis[100010],dis[100010];
int first[100010],cnt;
struct node{
	int to,next,val;
}edge[400010];
void add(int u,int v,int val){
	edge[++cnt].to = v;
	edge[cnt].val = val;
	edge[cnt].next = first[u];
	first[u] = cnt;
}
struct N{
	int x,dis;
	
};
bool operator < (N a, N b){
		return a.dis > b.dis;
}
priority_queue<N>q;
void dij(){
	memset(dis,0x3f,sizeof dis);
	dis[1] = 0;
	q.push((N){1,1});
	while(q.size()){
		N cur = q.top();q.pop();
		int x = cur.x;
		int ds = cur.dis;
		if(vis[x])continue;
		vis[x] = 1;
		for(int i = first[x];i;i = edge[i].next){
			int to = edge[i].to;
			int val = edge[i].val;
			if(dis[to] > ds + val){
				dis[to] = ds + val;
				q.push((N){to,dis[to]});
			}
		}
	}
}

int main(){
	cin >> k;
	for(int i = 0; i < k; i++){
		add(i%k,(i+1)%k,1);
		add(i%k,(i*10)%k,0);
	}
	dij();
	cout << dis[0];
} 

Measured memory_bytes: 7368
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << A << endl; exit(0);}

int main()
{
  ll H, W;
  cin >> H >> W;

  map<char, ll> mp;
  for (ll i = 0; i < H * W; i++)
  {
    char c;
    cin >> c;
    mp[c]++;
  }

  ll n4 = (H / 2) * (W / 2);
  ll n2 = (W % 2) * (H / 2) + (H % 2) * (W / 2);
  ll n1 = (H % 2) * (W % 2);

  //cerr << n4 << " " << n2 << " " << n1 << endl;
  //cerr << n4 * 4 + n2 * 2 + n1 << endl;

  for (auto x : mp)
  {
    ll X = x.second;
    while (X >= 4 && n4 > 0)
    {
      X -= 4, n4--;
    }
    while (X >= 2 && n2 > 0)
    {
      X -= 2, n2--;
    }
    while (X >= 1 && n1 > 0)
    {
      X -= 1, n1--;
    }
  }

  string ans = (n4 + n2 + n1 == 0) ? "Yes" : "No";
  cout << ans << endl;
}

Measured memory_bytes: 256
r = 10001
sqrt = int(r**0.5)
p = [1]*r
twin = [0]*r
p[0] = 0
p[1::2] = [0 for x in range(1,r,2)]
for i in range(2,r,2):
	if p[i]:
		p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
		if p[i-2]:
			twin[i:i+250] = [i+1 for x in range(i,i+250)]
		
while True:
	n = int(raw_input())
	if n == 0: break
	print twin[n-1]-2,twin[n-1]

Measured memory_bytes: 4756
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    set<string> s;

    int n;
    cin >> n;
    string prev;
    forn(i, n) {
        string w;
        cin >> w;
        if ((!prev.empty() && prev.back() != w.front()) || contains(s, w)) {
            cout << "No\n";
            return 0;
        }
        prev = w;
        s.insert(w);
    }

    cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 256
#
# abc053 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """QWERTYASDFZXCV"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """ZABCZ"""
        output = """4"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """HASFJGHOGAKZZFEGA"""
        output = """12"""
        self.assertIO(input, output)


def resolve():
    s = input()
    print(s.rfind("Z") - s.find("A") + 1)


if __name__ == "__main__":
     # unittest.main()
     resolve()


Measured memory_bytes: 16224
'''
0から9までの数字から成る長さNの文字列Sの部分文字列の内、
十進数表記の整数とみなした時、素数Pで割り切れるものの個数を求めよ。
部分文字列は先頭が0であっても良く、文字列の位置で区別する。

terms:
    1<=n<=2*10**5
    2<=p<=10**4

input:
    4 3
    3543

output:
    6
'''

from collections import defaultdict
import sys
input = sys.stdin.readline
INF = float('inf')
mod = 10 ** 9 + 7
eps = 10 ** -7
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))
n, p = inpl()
s = input()[:-1]
arr = [int(s[i]) for i in range(n)]
ans = 0
if p == 2 or p == 5:
    '''
    10を割り切ると桁の話が使えないので場合分け
    1の位が割り切れればそれだけ
    '''
    for i in range(n):
        if arr[i] % p == 0:
            ans += i + 1
    print(ans)
else:
    '''
    Pが10の約数である2,5だと以下の仮定が成り立たないので使えない
    ・ある数XがPで割り切れるならそれを10倍したものもPで割り切れる

    f(i)=Sの下i桁をPで割った時の余り
    として、f(i)=f(j)になる組を考える。
    するとiからj桁目までの値はPで割り切れる(i%p-j%p≡(i-j)%p)
    pow(x,y,z)=x^y%z
    '''
    dic = defaultdict(int)
    # dic = { 余り: 個数}
    now = 0
    dic[0]=1 # 余り0ならまず条件一致。それ以外だったら同じあまりが出た時点で条件一致
    for i in range(n-1,-1,-1): #下i桁をpで割った余り
        now += arr[i] * pow(10, n - 1 - i, p)
        now %= p
        ans+=dic[now]
        dic[now] += 1
    
    print(ans)

Measured memory_bytes: 48204
import math

    
def main():
    Input = [input() for i in range(1)]
    #N = int(Input[0])
    a,b,x = list(map(int,Input[0].split()))
    if x == a*a*b:
        print(0)
    else:
        a = float(a)
        b = float(b)
        x = float(x)
        ans = 90-math.atan(a/(2*(b-x/(a*a))))*180/math.pi
        if b * math.tan((90-ans)*math.pi/180) < a:
            ans = 90-math.atan(2*x/a/b/b)*180/math.pi
        print(ans)
        
if __name__ == "__main__":
    main()
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;cin>>a>>b;
    a==1?a+=13:1;
    b==1?b+=13:1;
    if(a==b)cout<<"Draw";
    else if(a>b)cout<<"Alice";
    else cout<<"Bob";
}


Measured memory_bytes: 256
n = int(input())

dp = [0] * (n + 1)

for i in range(1, n + 1):
    dp[i] = dp[i - 1] + 1
    power = 6
    while power <= i:
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 6
    power = 9
    while power <= i:
        dp[i] = min(dp[i], dp[i - power] + 1)
        power *= 9

print(dp[n])


Measured memory_bytes: 3828
a,b,k = map(int,input().split())
while(True):
    if a%2 != 0:
        a = (a-1)//2
        b += a
    else:
        a = a//2
        b += a
    k -= 1
    if k == 0:
        break
    if b%2 != 0:
        b = (b-1)//2
        a += b
    else:
        b = b//2
        a += b
    k -= 1
    if k == 0:
        break

print(a,b)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<int,int>
#define debug(a) cout<<a<<'\n'
#define maxn 2509 /// Still trying to be gray
#define MOD 1000000007
#define rep(i, n) for(ll i = 0; i < (ll)(n); i ++)
#define rep1(i, n) for(ll i = 1; i <= (ll)(n); i ++)
#define per(i, n) for(ll i = (ll)(n)-1;i>=0;i--)
#define per1(i, n) for(ll i = (ll)(n);i>=1;i--)
using namespace std;
const int INF = 1000000000;
ll n,m,p;
vector<pii> adj[maxn];
vector<int> dis2[maxn];
void addedge(int a,int b,int c){
    adj[a].push_back({b,c});
}

void dijkstra(int s, vector<int> & d) {
    d.assign(n, INF);

    d[s] = 0;
    priority_queue<pii, vector<pii>, greater<pii>> q;
    q.push({0, s});
    while (!q.empty()) {
        int v = q.top().second;
        int d_v = q.top().first;
        q.pop();
        if (d_v != d[v])
            continue;

        for (auto edge : adj[v]) {
            int to = edge.first;
            int len = abs(edge.second);

            if (d[v] + len < d[to]) {
                d[to] = d[v] + len;
                q.push({d[to], to});
            }
        }
    }
}

bool spfa(int s, vector<int>& d) {
    d.assign(n, INF);
    vector<int> cnt(n, 0);
    vector<bool> inqueue(n, false);
    queue<int> q;

    d[s] = 0;
    q.push(s);
    inqueue[s] = true;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        inqueue[v] = false;

        for (auto edge : adj[v]) {
            int to = edge.first;
            int len = edge.second;

            if (d[v] + len < d[to]) {
                d[to] = d[v] + len;
                if (!inqueue[to] && cnt[to] <= n) {
                    q.push(to);
                    inqueue[to] = true;
                    cnt[to]++;
                    if (cnt[to] > n && dis2[to][n-1]<INF)
                        return false;  // negative cycle
                }
            }
        }
    }
    return true;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>p;
    rep(i,m){
        ll a,b,c;
        cin>>a>>b>>c;
        --a,--b;
        addedge(a,b,-1*c+p);
    }
    rep(i,n)dijkstra(i,dis2[i]);
    bool cycn=false;
    vector<int> dis;
    cycn=spfa(0,dis);
    if(!cycn)cout<<"-1\n";
    else cout<<max(-1*dis[n-1],0)<<'\n';
    return 0;   
}           



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

const int MAXN = 2E5+2;

map<int, int> mp;
int s[MAXN];
int n, k;

long long ans = 0;

signed main(){
	cin >> n >> k;
	for(int i=1; i<= n; ++i){
		cin >> s[i];
		s[i] += s[i-1];
		s[i] %=k;
	}
	for(int i=0; i<= n; ++i){
		s[i] += (k-i%k);
		s[i] %= k;
	}
	int cur = 0;
	for(int i=0; i< min(n+1, k); ++i){
		int r = s[i];
		map<int, int>::iterator it = mp.find(r);
		if(it!= mp.end()){
			ans += 1LL*it->second;
			++it->second;
		}
		else mp.insert({r, 1});
	}
	//cerr << ans << " ";
	for(int i=k; i<= n; ++i){
		int r = s[i-k];
		map<int, int>::iterator it = mp.find(r);
		if(it!= mp.end()) --it->second;
		
		r= s[i];
		it = mp.find(r);
		if(it!= mp.end()){
		//	cerr << i << " " << it->second << "\n";
			ans += 1LL*it->second;
			++it->second;
		}
		else mp.insert({r, 1});
	}
	cout << ans;
}

Measured memory_bytes: 10368
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String... args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final StringBuilder sb = new StringBuilder();
        while (true) {
            final String[] lines = br.readLine().split(" ");
            final int x = Integer.parseInt(lines[0]);
            final int y = Integer.parseInt(lines[1]);
            if (x == 0 && y == 0) break;
            for (int i = 0; i < x; i++) {
                for (int j = 0; j < y; j++) {
                    if ((i != 0 && i != x - 1) && (j != 0 && j != y - 1)) {
                        sb.append(".");
                    } else {
                        sb.append("#");
                    }
                }
                sb.append("\n");
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 20680
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int mod = 1e9 + 7;
int main()
{
	SPEED
	int a, b, c;
	cin >> a >> b >> c;
	if (a==b && c!=a)
	{
		cout << "Yes";
	}
	else if (b==c && c!=a)
	{
		cout << "Yes";
	}
	else if (c==a && b!=c)
	{
		cout << "Yes";
	}
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  char s[100000];
  char t[100000];
  int i,count1=0,count2=0;
  
  scanf("%s",s);
  
  for(i=0;i<100000;i++){
    t[i]=s[i];
    if(s[i]==NULL)
      break;
  }
  
  for(i=0;i<100000;i++){
    if(i%2==0&&s[i]=='1'){
      s[i]='0';
      count1++;
    }
    if(i%2==1&&s[i]=='0'){
      s[i]='1';
      count1++;
    }
    if(s[i]==NULL)
      break;
  }
  
  
 
  for(i=0;i<100000;i++){
    if(i%2==0&&t[i]=='0'){
      t[i]='1';
      count2++;
    }
    if(i%2==1&&t[i]=='1'){
      t[i]='0';
      count2++;
    }
    if(t[i]==NULL)
      break;
  }
  
  
 if(count1>=count2)
    printf("%d",count2);
 else
    printf("%d",count1);
  return 0;
}

Measured memory_bytes: 384
n,k=map(int,input().split())
cnt=0
if k==0:
    print(n**2)
    exit()

for b in range(1,n+1):
    p=n//b
    r=n-p*b

    if b-1>=k:
        cnt+=p*(b-k)+max(r-k+1,0)
        #print(cnt,num)
print(cnt)


Measured memory_bytes: 2940