akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

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

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  double sum = 0;
  int cnt = 0;
  vector<int>x(n);
  vector<int>y(n);
  vector<int>order(n);
  for(int i=0;i<n;i++) cin >> x[i] >> y[i];
  for(int i=0;i<n;i++) order[i]=i;


  do {
    for(int i=0;i<n-1;i++){
      double x_diff = x[order[i]] - x[order[i+1]];
      double y_diff = y[order[i]] - y[order[i+1]];
      double distance = x_diff*x_diff + y_diff*y_diff;
      sum += sqrt(distance);
    }
    cnt++;
  } while(next_permutation(All(order)));

  printf("%.10f\n", sum/cnt);
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split(" ")))

if N>1:
	flag=0
	for i in reversed(range(1,N)):
		if H[i-1]-H[i]>1:
			flag=1
		if H[i-1]-H[i]==1:
			H[i-1] -= 1
	if flag==0:
		print("Yes")
	else:
		print("No")
else:
	print("Yes")


Measured memory_bytes: 14396
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k, ans, x, s;
	cin >> n;

	s = 0;
	for (i = 1;; i++) {
		s += i;
		if (s >= n) break;
	}

	if (s == n) {
		//cout << i << "\n";
		for (j = 1; j <= i; j++) cout << j << "\n";
	}
	else {
		//cout << i - 1 << "\n";
		for (j = 1; j <= i; j++) {
			if (j != s - n) cout << j << "\n";
		}
	}


	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(void){
    int a,b,c,d,n,x;
    while(cin >> n){
        x=0;
        for(a=0;a<10;a++)
        for(b=0;b<10;b++)
        for(c=0;c<10;c++)
        for(d=0;d<10;d++)
        if(a+b+c+d==n) x++;
         
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
nmax = 8
graph = [[False for i in range(nmax)] for j in range(nmax)]

def dfs(v, N, visited):
    all_visited = True

    for i in range(N):
        if visited[i] == False:
            all_visited = False

    if all_visited:
        return 1

    ret = 0

    for i in range(N):
        if graph[v][i] == False:
            # 経路がない
            continue
        if visited[i] == True:
            # 使用済み
            continue

        visited[i] = True
        ret += dfs(i, N, visited)
        visited[i] = False

    return ret

if __name__ == '__main__':
    n, m = map(int, input().split())

    for i in range(m):
        a, b = map(int, input().split())
        graph[a - 1][b - 1] = True
        graph[b - 1][a - 1] = True

    visited = [False for i in range(n)]

    visited[0] = True
    print(dfs(0, n, visited))


Measured memory_bytes: 3064
#include<cstdio>
#include<iostream>
using namespace std;
int main() {
    string s,t;
    cin >> s >> t;
    int cnt = 0;
    for(int i = 0 ; i < s.length(); ++i)
        if(s[i] != t[i]) ++cnt;
    cout << cnt << '\n';
return 0;
}

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

int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  int N, K;
  cin >> N >> K;
  int maxA = 0;
  vector<int> A(N);
  for (int& a : A) {
    cin >> a;
    maxA = max(maxA, a);
  }

  if (maxA < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  int d = A[0];
  for (int a : A) {
    d = gcd(a, d);
    if (a == K) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }

  if (K % d == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define BE(x) (x).begin(), (x).end()

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for (int i = 0; i < m; i++) cin >> x[i];

    if (n >= m) {
        cout << 0 << endl;
        return 0;
    }
    else {
        sort (BE(x));
        vector<tuple<int,int,int>> y(m-1);
        for (int i = 1; i < m; i++)
            y[i-1] = make_tuple(x[i]-x[i-1], x[i-1], x[i]);
        sort (BE(y));
        int s = m-1;
        vector<int> z1(n), z2(n);
        z1[0] = x.front(), z2[0] = x.back();
        for (int i = 1; i < n; i++) {
            z1[i] = get<2>(y[s-i]);
            z2[i] = get<1>(y[s-i]);
        }
        sort (BE(z1)), sort (BE(z2));
        int ans = 0;
        for (int i = 0; i < n; i++)
            ans += z2[i] - z1[i];
        cout << ans << endl;
    }
}

Measured memory_bytes: 5388
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        d: usize,
        points: [(isize, isize); n],
    }
    let mut ans = 0;
    for i in 0..n {
        let distance = ((points[i].0 * points[i].0 + points[i].1 * points[i].1) as f64).sqrt();
        if distance <= d as f64 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

struct Edge{int l, r, d;};

#define INF (2 * 1000 * 1000 * 1000)

bool calc(
    vector<int> &pos,
    int s,
    const vector<vector<Edge>> &edges
) {
    pos[s] = 0;

    queue<int> q;
    q.push(s);

    while (q.empty() == false) {
        int i = q.front();
        q.pop();

        for (const Edge &e: edges[i]) {
            int distance = pos[i] + e.d;
            if (pos[e.r] == INF) {
                pos[e.r] = distance;
                q.push(e.r);
            } else {
                if (pos[e.r] != distance) {
                    return false;
                }
            }
        }
    }

    return true;
}

signed main() {
    int N, M;
    cin >> N >> M;

    vector<vector<Edge>> edges(N, vector<Edge>());

    REP(i, M) {
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;

        edges[l].pb(Edge{l, r, d});
        edges[r].pb(Edge{r, l, -d});
    }

    vector<int> pos(N, INF);

    bool ok = true;

    REP(i, N) {
        if (pos[i] != INF) continue;

        if (calc(pos, i, edges) == false) {
            ok = false;
            break;
        }
    }

    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int d[510][510];
int main(){
  int n, m, q; cin >> n >> m >> q;
  for (int i = 0; i < m; i++) {
    int l, r; cin >> l >> r;
    d[l][r]++;
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      d[i][j+1] += d[i][j];
    }
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      d[i+1][j] += d[i][j];
    }
  }
  for (int i = 0; i < q; i++) {
    int l, r; cin >> l >> r;
    cout << d[r][r] - d[r][l-1] - d[l-1][r] + d[l-1][l-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<iostream>
using namespace std;

int N,T;
int main (){
    cin >> N >> T;
    int ans = 9999;
    for(int i=0; i<N; i++) {
        int c,t;
        cin >> c >> t;
        if( t <= T ) ans = min( ans, c);
    }
    if( ans <= 1000) cout << ans << endl;
    else cout << "TLE" << endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long ll;
ll BigN = 1000000007;
ll powmod(ll a, ll n){
	ll ret = 1;
	for(ll i=0;i<60;i++){
		if(n&(1LL<<i)) ret*=a;
		a=(a*a)%BigN;
		ret%=BigN;
	}
	return ret;
}
int N,K;
int visit[100001]={1,1,};
ll dp[100001]={0,1,};
ll sol(int k, int r){
	if(r!=1) return sol(k/r,1);
	else if(visit[k]) return dp[k];
	ll ret = powmod(k,N);
	for(int i=2;i<=k;i++) ret=(ret+BigN-sol(k,i))%BigN;
	visit[k] = 1;
	return dp[k] = ret;
	
}
int main(int argc, char *argv[])
{
	scanf("%d %d",&N,&K);
	ll sum = 0;
	for(int i=1;i<=K;i++){
		sum += 1LL*i*sol(K,i);
		sum%= BigN;
	}
	printf("%lld",sum);
}

Measured memory_bytes: 2156
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
#define EPS (1e-7)
#define DEF (1e+9 + 7)

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)





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

	string s;
	cin >> s;

	VI v(n);
	REP(i, n) {
		v[i] = s[i] - 'a';
	}

	int a[26] = {};
	int b[26] = {};

	int sum = 0;
	int max = -1;
	FOR(i, 0, n - 2) {
		sum = 0;
		REP(j, 26) {
			a[j] = 0;
			b[j] = 0;
		}
		FOR(j,0, i) {
			a[v[j]] = 1;
		}
		FOR(j, i + 1, n - 1) {
			b[v[j]] = 1;
		}

		REP(j, 26) {
			if (a[j] == 1 && b[j] == 1) {
				sum++;
			}
		}
		if (sum > max) {
			max = sum;
		}
	}
	
	ANS(max);

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int dp[100010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, 0, n) cin >> h[i];
    rep(i, 0, n) dp[i] = INF;
    dp[0] = 0;
    rep(i, 0, n){
        if(i + 1 < n) dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        if(i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main() {
 int N,K;
 cin>>N>>K;
 vector<int>A(N);
 for(int i=0;i<N;i++){
   cin>>A[i];
 }
 for(int i=0;i<K;i++){
  vector<int>B(N+1);
  for(int j=0;j<N;j++){
    int l=max(0,j-A[j]);
    int r=min(N,j+A[j]+1);
    B[l]++;B[r]--;
  }
  for(int k=0;k<N;k++){
    B[k+1]+=B[k];
  }
  B.pop_back();
  if(A==B){break;}
  A=B;
 }
  for(int i=0;i<N;i++){
    cout<<A[i]<<endl;
    }
  return 0;
}

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

int main()
{
    int a,b,n,k,i,j,x,y;
    scanf("%d %d",&a,&b);
    if(a%2!=0&&b%2!=0){
    printf("Yes");}
    else {printf("No");
}
    return 0;
}


Measured memory_bytes: 128
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)

def main():
    x,y = map(int,input().split())
    print(x + y//2)
if __name__ =='__main__':
    main()   


Measured memory_bytes: 3316
import java.util.*;
import java.text.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int MOD = (int)998244353;

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int k = sc.nextInt();
        String s = sc.next();

        if (s.length() <= k) {
            System.out.println(s);
        } else {
            s = s.substring(0, k);
            System.out.println(s + "...");
        }


    }
}



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

using namespace std;

void output_array(vector<int> &arr, int num, bool add_lf) {

    for (int i=0; i<num; i++) {
        cout << arr[i];
        if (i != num-1) {
            cout << " ";
        }
    }

    if (add_lf) {
        cout << endl;
    }
}

void insertion_sort(vector<int> &arr, int num) {

    for (int i = 1; i < num; i++) {
        int v = arr[i];
        int j = i - 1;
        while (j >= 0 && arr[j] > v) {
            arr[j + 1] = arr[j];
            j--;
        }
        arr[j + 1] = v;

        output_array(arr, num, true);
    }
}

int main() {

    int num;
    cin >> num;

    vector<int> arr(num);
    for (int i=0; i<num; i++) {
        cin >> arr[i];
    }

    output_array(arr, num, true);

    insertion_sort(arr, num);

    return 0;
}


Measured memory_bytes: 3088
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BRGBBalls solver = new BRGBBalls();
        solver.solve(1, in, out);
        out.close();
    }

    static class BRGBBalls {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            char[] s = in.next().toCharArray();
            int[] count = new int[3];
            long ans = 1;
            long mod = 998244353;
            int open = 0, mid = 0, closed = 0;
            int max = 0, min = 0;
            for (int i = 0; i < s.length; i++) {
                int pos = "RGB".indexOf(s[i]);
                count[pos]++;
                int newMin = Math.min(count[0], Math.min(count[1], count[2]));
                int newMax = Math.max(count[0], Math.max(count[1], count[2]));
                if (newMax > max) {
                    open++;
                } else if (newMin > min) {
                    ans = ans * mid % mod;
                    mid--;
                } else {
                    ans = ans * open % mod;
                    open--;
                    mid++;
                }
                max = newMax;
                min = newMin;
            }
            for (int i = 1; i <= n; i++) {
                ans = ans * i % mod;
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public FastScanner(String fileName) {
            try {
                br = new BufferedReader(new FileReader(fileName));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 26608
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

uf = UnionFind(N)
for _ in range(M):
    a, b = mapint()
    uf.union(a-1, b-1)
print(uf.group_count()-1)

Measured memory_bytes: 72324
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

bool visit(const vector<vi>& g, int v, vector<int>& order, vector<int>& color) {
    color[v] = 1;
    for (int u : g[v]) {
        if (color[u]==2) continue;
        if (color[u]==1) return false;
        if (!visit(g, u, order, color)) return false;
    }
    order.push_back(v); color[v] = 2;
    return true;
}

// ?????????????????????????????????
// ???????????? true ???????????????????????????(false ?????´????????????)
bool TopologicalSort(const vector<vi>& g, vector<int>& order) {
    int n = g.size();
    vector<int> color(n);
    for (int u = 0; u < n; u++) if (!color[u] && !visit(g, u, order, color)) return false;
    reverse(order.begin(), order.end());
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int V, E;
    cin >> V >> E;
    vector<vi> G(V);
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
    }
    vector<int> order;
    assert(TopologicalSort(G, order));
    for (int el : order) cout << el << endl;
    return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n;
	cin >> n;
	vector<vi> v(3);
	REP(i, n)
	{
		int a; cin >> a;
		if (a == 2) v[0].push_back(i+1);
		if (a == -2) v[1].push_back(i+1);
		if (a == -1) v[2].push_back(i + 1);
	}
	vi ans;
	for (auto i : v[0]) ans.push_back(i);
	if (v[1].size() % 2 == 0)
	{
		for (auto i : v[1]) ans.push_back(i);
	}
	else
	{
		if (v[2].size() > 0)
		{
			for (auto i : v[1]) ans.push_back(i);
			ans.push_back(v[2][0]);
		}
		else
		{
			for (auto i : v[1]) ans.push_back(i);
			ans.pop_back();
		}
	}
	sort(ALL(ans));
	cout << ans.size() << endl;
	if(ans.size() > 0) cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3224
N, A, B =map(int,input().split())
sum = 0
for i in range(1,N+1,1):
  i = str(i)
  num = 0
  for j in range(len(i)):
    num += int(i[j])
  if num >= A and num<=B:
    sum += int(i)
    
print(sum)

Measured memory_bytes: 3060
import numpy as np
h,w = map(int,input().split())
s = []
for i in range(h):
    tmp = list(input())
    if len(set(tmp)) == 1 and tmp[0] == '.':
        continue
    s.append(tmp)
ss = np.array(s).T
ans1 = []
si = ss.tolist()

for i, w in enumerate(si):
    if len(set(w)) == 1 and w[0] == '.':
        continue
    else:
        ans1.append(w)
ans = np.array(ans1).T.tolist()

for i, w in enumerate(ans):
    print(''.join(w))
    


Measured memory_bytes: 21860
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
using namespace std;

//#define FILE_INPUT
//#define DEBUG_MODE

template<class T>
void DebugPrint(vector<T> a)
{
#ifdef DEBUG_MODE
	for (int i = 0; i < (int)a.size(); ++i) {
		cout << a[i] << ",";
	}
	cout << endl;
#endif
}

int main()
{
#ifdef FILE_INPUT
	ifstream in("test3.txt");
	cin.rdbuf(in.rdbuf());
#endif	/* FILE_INPUT */  

	int n, ww;
	cin >> n >> ww;

	vector<int> w(n);
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> w[i] >> v[i];
	}

	vector<long long int> dp(ww + 1);

	for (int i = 0; i <= ww; ++i) {
		dp[i] = 0;
	}
	for (int i = 0; i < n; ++i) {
		for (int j = ww; j >= 0; --j) {
			int j2 = j + w[i];
			if (j2 <= ww) {
				dp[j2] = max(dp[j2], dp[j] + v[i]);
			}
		}
		DebugPrint(dp);
	}
	cout << dp[ww] << endl;

	return 0;
}

Measured memory_bytes: 1804
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct _Node {
  int key;
  struct _Node *next, *prev;
} Node;

Node *nil;

Node* listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) {
    cur = cur->next;
  }
  return cur;
}

void init(void) {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void) {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if(t==nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void) {
  deleteNode(nil->next);
}

void deleteLast(void) {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = (Node *)malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(void) {
  int key, n, i;
  int size = 0;
  int np = 0, nd = 0;
  char com[20];
  scanf("%d", &n);
  init();
  for(i=0;i<n;i++) {
    scanf("%s%d",com, &key);
    if (com[0] == 'i') {
      insert(key);
      np++;
      size++;
    } else if(com[0] == 'd') {
      if(strlen(com) > 6) {
        if(com[6] == 'F')
          deleteFirst();
        else if(com[6] == 'L')
          deleteLast();
      } else {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}



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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;

int N, M;
vector<int> Edge[MAX_N];

int dp[MAX_N];
int dp2[MAX_N];

int solve(int pos, int par)
{
  int ret = 1;

  for(int next : Edge[pos]) {
    if(next == par) continue;
    ret *= (solve(next, pos)+1);
    ret %= M;   
  }

  return dp[pos] = ret;
}

void solve2(int pos, int par, int parInfo)
{
  dp2[pos] = (dp[pos] * (parInfo+1)) % M;
  vector<int> blackSize;
  deque<int> front,end;
  for(int next : Edge[pos]) {
    if(next == par) blackSize.emplace_back(parInfo);
    else blackSize.emplace_back(dp[next]);
  }

  int f = 1, e = 1;
  for(int i = 0; i < blackSize.size(); i++) {
    f *= (blackSize[i]+1); f %= M;
    e *= (blackSize[blackSize.size()-i-1]+1); e %= M;
    front.push_back(f); end.push_front(e);
  }

  for(int i = 0; i < Edge[pos].size(); i++) {
    int next = Edge[pos][i];
    if(next == par) continue;
    int nextParInfo = 1;
    if(i>0) {
      nextParInfo *= front[i-1]; nextParInfo %= M;
    }
    if(i<Edge[pos].size()-1) {
      nextParInfo *= end[i+1]; nextParInfo %= M;
    }
    solve2(next, pos, nextParInfo);
  }
}

signed main()
{
  cin >> N >> M;
  REP(n,N-1) {
    int a, b; cin >> a >> b; a--; b--;
    Edge[a].emplace_back(b);
    Edge[b].emplace_back(a);
  }

  solve(0,-1);
  solve2(0,-1,0);

  REP(n,N) {
    cout << dp2[n] << endl;
  }

  return 0;
}

Measured memory_bytes: 155008
from itertools import accumulate
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
grid = [[0] * 1002 for _ in range(1002)]
for _ in range(N):
    x, y, xx, yy = map(int, input().split())
    grid[x][y] += 1
    grid[x][yy] -= 1
    grid[xx][y] -= 1
    grid[xx][yy] += 1

for i in range(1002):
    grid[i] = list(accumulate(grid[i]))
for i in range(1001):
    for j in range(1002):
        grid[i + 1][j] += grid[i][j]

ans = max(max(x) for x in grid)
print(ans)


Measured memory_bytes: 45684
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string s, t;
    cin >> s >> t;

    bool ok;
    rep(i, s.length()) {
        ok = true;
        rep (j, s.length()) {
            if (s[(i + j) % s.length()] != t[j]) {
                ok = false;
            }
        }
        if (ok) break;
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;



    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# coding: utf-8
# Your code here!

n,m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for j in range(m)]

a.sort()
bc.sort(key=lambda x: x[1], reverse=True)

ans = 0
pt = 0
for i in range(m):
    num=0
    b=bc[i][0]
    c=bc[i][1]
    while pt < n and a[pt] < c and num < b:
        ans += c
        pt += 1
        num+=1
#        print(pt,ans,"a")

while pt < n:
        ans += a[pt]
        pt+=1
#        print(pt,ans,"c")

print(ans)
        








Measured memory_bytes: 27000
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
	if(a<b) swap(a,b);
	int c=1;
	while(c!=0)
	{
		c=a%b;
		a=b;
		b=c;
	}
	return a;
}
bool cmp(int a,int b)
{
	return a<b;
}
queue<int> q;
int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	int a[n+1];
	for(int i=0;i<=n;i++) cin>>a[i];
	sort(a,a+n+1,cmp);
	for(int i=0;i<n;i++) q.push(a[i+1]-a[i]);
	int ans=q.front();
	q.pop();
	while(!q.empty())
	{
		ans=gcd(ans,q.front());
		q.pop();
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

const int maxn = 2000;
const int mod = 1e9 + 7;

int dp[maxn + 5][maxn + 5], n;

int main()
{
	cin >> n;
	dp[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 3; j <= n; ++j)dp[i][j] = (dp[i][j] + dp[i - 1][j - 3]) % mod;
		for (int j = 1; j <= n; ++j)dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
	}
	long long res = 0;
	for (int i = 1; i <= n; ++i)res += dp[i][n];
	res %= mod;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 19192
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
    int n;
    while(cin >> n, n){
        vi d(n);
        rep(i, 0, n){
            cin >> d[i];
        }
        string s;
        string str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        cin >> s;
        rep(i, 0, s.size()){
            int p = str.find(s[i]);
            p -= d[i % n];
            if(p < 0) p += 52;
            s[i] = str[p];
        }
        cout << s << endl;
    }
}

Measured memory_bytes: 1216
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

move = [(0,1),(1,0)]
def solve(n):
    f = defaultdict(lambda : 0)
    v = defaultdict(list)
    l = []
    for i in range(n):
        a,b,dir = input().split()
        a = int(a)
        b = int(b)
        f[(a,b)] = 1
        dir = 0 if dir == "x" else 1
        na,nb = a+1-dir,b+dir
        f[(na,nb)] = 1
        l.append((a,b,na,nb))
        l.append((na,nb,a,b))
        v[(a,b)].append(((na,nb),1))
        v[(na,nb)].append(((a,b),1))
    for a,b,c,d in l:
        for dx,dy in move:
            na,nb = a+dx,b+dy
            if f[(na,nb)] and (c,d) != (na,nb):
                v[(a,b)].append(((na,nb),0))
                v[(na,nb)].append(((a,b),0))
    bfs = defaultdict(lambda : -1)
    q = deque()
    for a,b,c,d in l:
        if bfs[(a,b)] < 0:
            q.append((a,b))
            bfs[(a,b)] = 0
            while q:
                x,y = q.popleft()
                for node,k in v[(x,y)]:
                    nx,ny = node
                    if k:
                        nb = 1-bfs[(x,y)]
                    else:
                        nb = bfs[(x,y)]
                    if bfs[(nx,ny)] >= 0:
                        if bfs[(nx,ny)] != nb:
                            print("No")
                            return
                    else:
                        bfs[(nx,ny)] = nb
                        q.append((nx,ny))
    print("Yes")
    return

#Solve
if __name__ == "__main__":
    while 1:
        n = I()
        if n == 0:
            break
        solve(n)



Measured memory_bytes: 49808
def main():
    n, m = map(int, input().split())
    if m % 2:
        print(-1)
        return
    ab = [list(map(int, input().split())) for _ in [0]*m]
    g = [set() for _ in [0]*n]
    [g[a-1].add(b-1) for a, b in ab]
    [g[b-1].add(a-1) for a, b in ab]
    ab = [(a-1, b-1)for a, b in ab]

    def Kruskal(n, abc, weight=False):
        class unionfind():
            # size:要素数,tree：unionfind木
            def __init__(self, size):  # self,要素数
                self.size = size
                self.tree_root = list(range(self.size))
                self.tree_depth = [1]*self.size

            # rootを探す
            def root(self, index):
                temp_list = []
                temp = self.tree_root[index]
                while index != temp:
                    temp_list.append(index)
                    index = temp
                    temp = self.tree_root[index]
                for i in temp_list:
                    self.tree_root[i] = index
                return index

            # 結合
            def unite(self, index1, index2):
                r1 = self.root(index1)
                r2 = self.root(index2)
                if r1 != r2:
                    d1, d2 = self.tree_depth[r1], self.tree_depth[r2]
                    if d1 <= d2:
                        self.tree_root[r1] = r2
                        self.tree_depth[r2] = max(d1+1, d2)
                    else:
                        self.tree_root[r2] = r1
                        self.tree_depth[r1] = max(d2+1, d1)

            # 同じか判定
            def same(self, index1, index2):
                r1 = self.root(index1)
                r2 = self.root(index2)
                return r1 == r2

            # 連結成分の個数
            def component(self):
                return len({self.root(i) for i in range(self.size)})
        uf = unionfind(n)
        ret = []
        if weight:
            abc.sort(key=lambda x: x[2])
        for a, b, *c in abc:
            if not uf.same(a, b):
                ret.append([a, b])
                uf.unite(a, b)
        return ret

    t = Kruskal(n, ab)
    g2 = [set() for _ in [0]*n]
    [g2[a].add(b) for a, b in t]
    [g2[b].add(a) for a, b in t]
    root = 0  # 根
    d = [-1]*n  # 根からの距離
    d[root] = 0
    q = [root]
    cnt = 0
    while q:  # BFS
        cnt += 1
        qq = []
        while q:
            i = q.pop()
            for j in g2[i]:
                if d[j] == -1:
                    d[j] = cnt
                    qq.append(j)
        q = qq

    d2 = sorted([(i, j) for i, j in enumerate(d)], key=lambda x: -x[1])
    now = [0]*n
    ans = []
    for i, j in d2:
        remove_list = []
        for k in g[i]:
            if k not in g2[i]:
                now[i] += 1
                ans.append((i+1, k+1))
                remove_list += [(i, k), (k, i)]
        for k, l in remove_list:
            g[k].remove(l)

    for i, j in d2[:-1]:
        k = g[i].pop()
        g[k].remove(i)
        if now[i] % 2:
            now[i] += 1
            ans.append((i+1, k+1))
        else:
            now[k] -= 1
            ans.append((k+1, i+1))
    for i in ans:
        print(*i)


main()

Measured memory_bytes: 105924
n, m, x = map(int, input().split())

A = [[] for _ in range(n)]
c = [0] * n
INF = 10**9
ans = INF

for i in range(n):
    c_as = list(map(int, input().split()))
    c[i], A[i] = c_as[0], c_as[1:]

for s in range(0, 1 << n):
    smart = [0] * m
    cost_sum = 0
    for i in range(n):
        if(s >> i)%2 == 0:continue
        cost_sum += c[i]
        for j in range(m):
            smart[j] += A[i][j]
    ok = True
    for j in range(m):
        if smart[j] < x:
            ok = False
    if ok:
        ans = min(ans, cost_sum)

if ans == INF:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9240
#include <bits/stdc++.h>
 
//#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ll n, a, b;
	cin >> n >> a >> b;

	ll res = (n / (a + b)) * a;
	n %= a + b;
	res += min(n, a);

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3620
N, K = input().split()
A = dict()
for i in input().split():
  if int(i) in A:
    A[int(i)]+=1
  else:
    A[int(i)]=1

hoge = []
for i in A.values():
  hoge.append(i)
hoge.sort()

sum = 0
changed = 0
while len(hoge) - changed > int(K):
  sum += hoge[changed]
  changed += 1

print(sum)

Measured memory_bytes: 45064
import sys
import math
from fractions import gcd
import numpy as np
readline = sys.stdin.readline
INF = 10**9


def main():
  N, M = map(int, readline().split())
  X = np.array(readline().split(), dtype=np.int64)
  X.sort()
  X = np.diff(X)
  X.sort()
  if M-N>=0:
    answer = X[:M-N].sum()
  else:
    answer = 0
  print(answer)
  
  
  
  
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 23388
import math

A, B = map(int, input().split())

volume_A = math.floor(A / 0.08)
volume_B = math.floor(B / 0.1)

min_A, max_A = math.inf, -math.inf
range_A = math.floor(1 / 0.08)
min_B, max_B = math.inf, -math.inf
range_B = math.floor(1 / 0.1)
# print(range_A)
# print(range_B)

for i in range(volume_A - range_A, volume_A + range_A):
    if math.floor(i * 0.08) == A:
        min_A = min(min_A, i)
        max_A = max(max_A, i)

for j in range(volume_B - range_B, volume_B + range_B):
    if math.floor(j * 0.1) == B:
        min_B = min(min_B, j)
        max_B = max(max_B, j)

ans_A = set()
for i in range(min_A, max_A + 1):
    ans_A.add(i)
# print(ans_A)

ans_B = set()
for j in range(min_B, max_B + 1):
    ans_B.add(j)
# print(ans_B)

ans = ans_A & ans_B

if len(ans) == 0:
    print(-1)
else:
    print(min(ans))


Measured memory_bytes: 9056
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    int A[3][3];
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
            scanf("%i", &A[i][j]);

    int a0, a1, a2, b0, b1, b2;
    bool flag = false;
    for (a0 = 0; a0 <= 100; a0++) {
        b0 = A[0][0] - a0;
        b1 = A[0][1] - a0;
        b2 = A[0][2] - a0;
        a1 = A[1][0] - b0;
        a2 = A[2][0] - b0;

        bool check =
            a1 + b1 == A[1][1] &&
            a1 + b2 == A[1][2] &&
            a2 + b1 == A[2][1] &&
            a2 + b2 == A[2][2];

        if (check) {
            flag = true;
            break;
        }
    }

    if (flag)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi;
typedef vector<double> vd;
 
double mypow(double b ,int e){
      if(e == 0) return 1;
      if(e%2==0)
            return mypow( b*b, e/2 );
      else
            return mypow( b*b, e/2 ) * b;
}
 
int main(){
 
 
      int N,M,L; cin >> N >> M >> L ;
      if(N==1){
            cout << 1.0 << endl;
            return 0;
      }
      vector<vd> prob(N,vd(M+1,0.0));
      vector<vd> dist(N,vd(M+1,0.0));
 
      vd p(N),t(N),v(N);
      for(int i=0; i<N; i++) cin >> p[i] >> t[i] >> v[i];
 
      // PRE PROCESS
      for(int i=0; i<N; i++){
            dist[i][0] = (double)L / v[i];
            for(int j=1; j<=M; j++){
                  dist[i][j] = dist[i][j-1] + t[i];
            }
      }
      for(int i=0; i<N; i++)
            prob[i][0] = mypow((100-p[i])/100,M);
      for(int i=0; i<N; i++){
            for(int j=1; j<=M; j++){
                  if(p[i] != 100)
                        prob[i][j] = (prob[i][j-1] * (p[i]/100)) / ((100-p[i])/100);
                  else
                        prob[i][j] = 1.0;
            }
      }
      double comb = 1;
      for(int j=1; j<=M; j++){
            comb = comb * (M - j + 1) / j; 
            for(int i=0; i<N; i++){
                  prob[i][j] *= comb;
            }
      }
       
      vector<vd> sum = prob;
      for(int i=0; i<N; i++){
            for(int j=M-1; j>=0; j--){
                  sum[i][j] += sum[i][j+1];
                  if(sum[i][j] > 1) sum[i][j] = 1;
            }
      }
 
      vector<vd> ans = prob;
      for(int i=0; i<N; i++){
            for(int j=0; j<=M; j++){
                  for(int k=0; k<N; k++){
                        if(i==k) continue;
                        int id = upper_bound(dist[k].begin(),dist[k].end(), dist[i][j]) - dist[k].begin();
                        if(id > M) ans[i][j] = 0.0;
                        else       ans[i][j] *= sum[k][id];
 
                  }
            }
      }
 
      for(int i=0; i<N; i++){
            double tmp = 0.0;
            if(p[i] == 100) tmp = ans[i][M];
            else
                  for(int j=0; j<=M; j++)
                        tmp += ans[i][j];
            if(tmp > 1) tmp = 0;
            printf("%.10f\n",tmp);
      }
                         
}

Measured memory_bytes: 3396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
int q[100009],w[100009];

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c>=22){cout << "bust" << endl;}
  else{cout << "win" << endl;}
}

Measured memory_bytes: 256
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)

//typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}

ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int keta(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}

int N, P;
string S;
ll surp[2000000];
ll dp[2000000];
int main()
{
	cin >> N >> P;
	cin >> S;
	
	reverse(S.begin(), S.end());
	ll ans = 0;
	if (10 % P == 0) {
		rep(i, N) {
			if ((S[i]-'0') % P == 0) {
				ans+=N-i;
			}
		}
		cout << ans << endl;
		return 0;
	}
	ll X = 1; 
	rep(i, N) {
		int a = X * (S[i] - '0') % P;
		surp[i+1] = (a+surp[i]) % P;
		//cout << S[i] << " " << X*S[i] << " " << surp[i + 1] << endl;
		X *= 10;X %= P;
		
	}
	dp[0]=1;
	rep(i, N) {
		ans += dp[surp[i+1]];
		dp[surp[i+1]]++;
		//cout << S[i] << " " << surp[i + 1] << " " << dp[surp[i + 1]] << endl;
	}
	cout << ans << endl;
	
}

Measured memory_bytes: 4740
#include<stdio.h>
int main(){
    
    int h = 0;
    int w = 0;
    while(1){    
        scanf("%d %d\n",&h,&w);
        if(h+w==0){
          break;
        }
        for (int i = 0; i < h; i++){
            for ( int j = 0; j < w; j++ ){
                if((i+j)%2 == 0){
                    printf("#");
                }else{
                    printf(".");
                }
            }
        	printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2048
#include<iostream>
#include<cstdio>
#include<cmath>
#define PI 3.141592653589793
using namespace std;

int main(){
	//hosuu = üÍ³êéà, kakudo = üÍ³êépx
	//x = »Ýn_ÌxÀW, y = »Ýn_ÌyÀW, rad = ¡ü¢Ä¢épx(WA)
	int hosuu, kakudo;
	double x = 0.0, y = 0.0, rad = 0.0;
	while(scanf("%d,%d", &hosuu, &kakudo)){
		if(hosuu == 0 && kakudo == 0) break;
		
		//x = hosuu * sin(kakudo), y = hosuu * cos(kakudo)
		x += (hosuu * sin(rad));
		y += (hosuu * cos(rad));
		
		//Éü­pxðwè(WAÉ¼·)
		rad += kakudo * PI / 180.0;
		
	}
	cout <<(int)x <<endl <<(int)y <<endl;
	return 0;
}

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

int dp[3001][3001] = {0};

int main(){
	int N, T, S;
	cin >> N >> T >> S;

	int A[3000], B[3000];
	for (int i = 0; i < N; i++) cin >> A[i] >> B[i];

	
	int ans = 0;

	for (int n = 1; n <= N; n++){
		for (int t = 1; t <= T; t++){
			dp[n][t] = max(dp[n-1][t], dp[n][t-1]);
			if(t - B[n-1] < 0) continue;
			if(S <= t - B[n-1] || t <= S) dp[n][t] = max(dp[n][t], dp[n-1][t-B[n-1]] + A[n-1]);
			ans = max(ans, dp[n][t]);
		}
	}
	cout << ans << endl;
	return 0;
}

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

const int N = 8e2 + 7;

char t[N][N];
int n, m, k;
int dis[N][N];
deque < pair <int, int> > d;

int main() {
	cin >> n >> m >> k;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			cin >> t[i][j];
			if (t[i][j] == 'S') {
				dis[i][j] = 1;
				d.push_back({i, j});
			}
		}
	int res = n * m;
	while (d.size()) {
		int x = d.front().first, y = d.front().second;
		d.pop_front();
		if (dis[x][y] - 1 <= k) {
			res = min({res, 1 + (x - 1 + k - 1) / k, 1 + (y - 1 + k - 1) / k, 1 + (n - x + k - 1) / k, 1 + (m - y + k - 1) / k});
		}
		for (int dx = x - 1; dx <= x + 1; dx += 2) {
			if (dx >= 0 && dx <= n && t[dx][y] != '#' && !dis[dx][y])
				dis[dx][y] = dis[x][y] + 1, d.push_back({dx, y});
		}
		for (int dy = y - 1; dy <= y + 1; dy += 2) {
			if (dy >= 0 && dy <= n && t[x][dy] != '#' && !dis[x][dy]) 
				dis[x][dy] = dis[x][y] + 1, d.push_back({x, dy});
		}
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 998244353;
const double PI = 3.1415926535897;
typedef tuple<int,int,int> TP;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}
 
ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}
 
ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P < 0) {
        return 0;
    }
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<ll> Mcount(N + 1);//Mcount.at(i) = i番目(1-indexed)までのMの個数
    vector<ll> Ccount(N + 1);//Ccount.at(i) = i番目(1-indexed)までのCの個数
    vector<ll> CMcount(N + 1);//CMcount.at(i) = i番目以降のCに対するMcountの合計
    for(int i = 0;i < N;i++) {
        if(S.at(i) == 'M') {
            Mcount.at(i + 1) = Mcount.at(i) + 1;
        }
        else {
            Mcount.at(i + 1) = Mcount.at(i);
        }
    }
    for(int i = 0;i < N;i++) {
        if(S.at(i) == 'C') {
            Ccount.at(i + 1) = Ccount.at(i) + 1;
            CMcount.at(i + 1) = CMcount.at(i) + Mcount.at(i);
        }
        else {
            Ccount.at(i + 1) = Ccount.at(i);
            CMcount.at(i + 1) = CMcount.at(i);
        }
    }
    int Q;
    cin >> Q;
    for(int i = 0;i < Q;i++) {
        int A;
        cin >> A;
        ll ret = 0;
        for(int j = 0;j < N;j++) {
            if(S.at(j) == 'D' && j + A <= N) {
                ret += (CMcount.at(j + A) - CMcount.at(j)) - Mcount.at(j) * (Ccount.at(j + A) - Ccount.at(j));
            }
            else if(S.at(j) == 'D') {
                ret += (CMcount.at(N) - CMcount.at(j)) - Mcount.at(j) * (Ccount.at(N) - Ccount.at(j));
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 24836