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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using edge = tuple<int, int, int>;

constexpr int MAXN = 100005;
constexpr int LOGN = 19;
int n, q;
vector<edge> tree[MAXN];
int depth[MAXN];
int st[LOGN][MAXN];

vi queries[MAXN];
int query_color[MAXN], query_weight[MAXN];

int color_freq[MAXN], color_weight[MAXN];

ll dist_ans[MAXN];
int freq_ans[MAXN];

ll dist = 0;

void dfs1(int u, int p = -1) {
    for (auto& e : tree[u]) {
        int v = get<0>(e);
        if (v == p) continue;
        st[0][v] = u;
        depth[v] = depth[u] + 1;
        dfs1(v, u);
    }
}

void gen_st() {
    for (int j = 0; j + 1 < LOGN; ++j) {
        for (int i = 0; i < n; ++i) {
            if (st[j][i] != -1) {
                st[j + 1][i] = st[j][st[j][i]];
            }
        }
    }
}

int lca(int u, int v) {
    if (depth[u] > depth[v]) {
        swap(u, v);
    }

    for (int j = LOGN - 1; j >= 0; --j) {
        if ((depth[v] - depth[u]) & (1 << j)) {
            v = st[j][v];
        }
    }

    if (u == v) return u;
    for (int j = LOGN - 1; j >= 0; --j) {
        if (st[j][u] != st[j][v]) {
            u = st[j][u];
            v = st[j][v];
        }
    }

    return st[0][u];
}

void dfs2(int u, int p = -1) {
    for (int q_idx : queries[u]) {
        int idx = q_idx < 0 ? ~q_idx : q_idx;
        if (q_idx < 0) {
            dist_ans[idx] -= 2 * dist;
            dist_ans[idx] += 2 * color_weight[query_color[idx]];
            freq_ans[idx] -= 2 * color_freq[query_color[idx]];
        } else {
            dist_ans[idx] += dist;
            dist_ans[idx] -= color_weight[query_color[idx]];
            freq_ans[idx] += color_freq[query_color[idx]];
        }
    }

    for (auto& e : tree[u]) {
        int v, c, w;
        tie(v, c, w) = e;
        if (v == p) continue;

        dist += w;
        ++color_freq[c];
        color_weight[c] += w;

        dfs2(v, u);

        color_weight[c] -= w;
        --color_freq[c];
        dist -= w;
    }
}

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

    cin >> n >> q;
    for (int i = 1; i < n; ++i) {
        int u, v, c, w;
        cin >> u >> v >> c >> w;
        --u; --v; --c;
        tree[u].emplace_back(v, c, w);
        tree[v].emplace_back(u, c, w);
    }

    memset(st, -1, sizeof(st));
    dfs1(0, -1);
    gen_st();

    for (int i = 0; i < q; ++i) {
        int u, v;
        cin >> query_color[i] >> query_weight[i] >> u >> v;
        --query_color[i]; --u; --v;
        queries[u].push_back(i);
        queries[v].push_back(i);
        queries[lca(u, v)].push_back(~i);
    }

    dfs2(0, -1);
    for (int i = 0; i < q; ++i) {
        ll ans = dist_ans[i] + freq_ans[i] * query_weight[i];
        cout << ans << '\n';
    }

    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int a;
    double sum=0;
    for(int i=0;i<n;++i){
        cin >> a;
        sum += 1.0/a;
    }
    sum = 1.0/sum;
    printf("%.14g\n",sum);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<set>
#include<bitset>
#include <sstream>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;


ll gcd(ll a,ll b)
{
    if(a==0 && b!=0)
    {
        return b;
    }
    if(a!=0 && b==0)
    {
        return a;
    }
    if(a%b==0)
    {
        return b;
    }
    else
    {
        return(gcd(b,a%b));
    }
    
}

int main()
{
    ll N,X;
    ll l;
    ll i=0;
    ll maxD=0;
    cin>>N>>X;
    while(cin>>l)
    {
        ll dif=abs(X-l);
        maxD=gcd(dif,maxD);
        i++;
        if(i>=N)break;

    }
    cout<<maxD<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
   
    string s;
    cin >> s;
    ll k;
    cin >> k;
    set <char> memo;
    for(ll i=0;i<s.length();i++){
        memo.insert(s[i]);
    }
    
    if(memo.size() == 1){
        cout << s.length()*k/2 << endl;
    }else{
        char state = 'X';
        ll ans1 = 0;
        for(ll i=0;i<s.length();i++){
            if(s[i] == state){
                ans1++;
                state = 'X';
            }else {
                state = s[i];
            }
        }
        ll ans2 = 0;
        string t;
        t = s+s;
        state = 'X';
        for(ll i=0;i<t.length();i++){
            if(t[i] == state){
                ans2++;
                state = 'X';
            }else {
                state = t[i];
            }
        }
//        cout << ans1 << " " << ans2 << endl;
        cout << ans1 + (k-1) * (ans2 - ans1) << endl;
    }

}

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

int a, b, c;

int main() {
	scanf("%d%d%d", &a, &b, &c);
	if (a == b) 
		printf("%d", c);
	else if (a == c) 
		printf("%d", b);
	else 
		printf("%d", a);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 9 * 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    ll N;
    cin >> N;
    ll ret = 0;
    for(ll i = 1;i * i <= N;i++) {
        if(N % i == 0) {
            ll cnt1 = i;
            ll cnt2 = N / i;
            if(i != 1) {
                ll cnt3 = N;
                while(cnt3 % cnt1 == 0) {
                    cnt3 /= cnt1;
                }
                if(cnt3 % cnt1 == 1) {
                    ret++;
                }
            }
            if(cnt2 * cnt2 != N) {
                ll cnt3 = N;
                while(cnt3 % cnt2 == 0) {
                    cnt3 /= cnt2;
                }
                if(cnt3 % cnt2 == 1) {
                    ret++;
                }
            }
        }
    }
    for(ll i = 1;i * i <= N - 1;i++) {
        if((N - 1) % i == 0) {
            ll cnt1 = i;
            ll cnt2 = (N - 1) / i;
            if(N % cnt1 == 1) {
                ret++;
            }
            if(cnt2 * cnt2 != N - 1 && N % cnt2 == 1) {
                ret++;
            }
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 384
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[100009], b[100009], c[100009]; long long dp[100009];
int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < n; i++) cin >> c[i];
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	long long ret = 0;
	for (int i = 0; i < n; i++) {
		int ptr1 = lower_bound(a, a + n, b[i]) - a;
		int ptr2 = lower_bound(c, c + n, b[i] + 1) - c;
		ret += 1LL * ptr1 * (n - ptr2);
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			char[] s = sc.next().toCharArray();
			StringBuilder sb = new StringBuilder();
			int i = 0;
			while(i<s.length){
				if(s[i]=='@'){
					int x = s[++i]-'0';
					i++;
					while(x--!=0)sb.append(s[i]);
				}
				else sb.append(s[i]);
				i++;
			}
			System.out.println(sb);
		}
	}
}

Measured memory_bytes: 17328
a, b, k = map(int, input().split())
ret = []
for i in range(k):
    ret.append(min(a + i, b))
for i in range(max(a, b - k + 1), b + 1):
    ret.append(i)
ret = sorted(list(set(ret)))
for i in ret:
    print(i)


Measured memory_bytes: 3060
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
	Scanner in=new Scanner(System.in);
	int[] line=new int[4];
	for(int i=0;i<3;i++){
		line[0]=in.nextInt();
		for(int o=0;o<3;o++){
		if(line[o] > line[o+1]){
			int temp=line[o];
			line[o]=line[o+1];
			line[o+1]=temp;
		}
		}
	}
	System.out.println(line[1]+" "+line[2]+" "+line[3]);
	}
}

Measured memory_bytes: 26144
program abc110d
  implicit none
  integer(8), parameter :: modulo = 10**9 + 7
  integer(8) :: ans = 1, i = 2
  integer(8) n, m, count

  read *, n, m
  do
     if (m < i * i) exit
     if (mod(m, i) == 0) then
        count = 0
        do
           m = m / i;
           count = count + 1
           if (mod(m, i) /= 0) exit
        end do
        ans = mod(ans * comb(n + count - 1, count, modulo), modulo)
     end if
     i = i + 1
  end do
  if (m /= 1) then
     ans = mod(ans * n, modulo)
  end if
  print '(i0)', ans

contains

  recursive integer(8) function comb(n, k, m) result(r)
    integer(8), intent(in) :: n, k, m
    integer(8) i, nume, deno

    if (n - k < k) then
       r = comb(n, n - k, m)
    else
       nume = 1
       deno = 1
       do i = 0, k - 1
          nume = mod(nume * (n - i), m)
          deno = mod(deno * (i + 1), m)
       end do
       r = mod(nume * modpow(deno, m - 2, m), m)
    end if
  end function comb

  recursive integer(8) function modpow(a, p, m) result(r)
    integer(8), intent(in) :: a, p, m

    if (p == 0) then
       r = 1
    else if (mod(p, 2) == 0) then
       r = mod(modpow(a, p / 2, m)**2, m)
    else
       r = mod(a * modpow(a, p - 1, m), m)
    end if
  end function modpow

end program abc110d


Measured memory_bytes: 256
n = gets.to_i
arr = []
n.times do
  arr << gets.chomp.split(' ').map(&:to_i)
end
arr.sort_by!{ |i| i[1] }
time = 0
ok = true
(0...n).each do |i|
  time += arr[i][0]
  ok = ok && arr[i][1] >= time
end
puts ok ? 'Yes' : 'No'

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

int main(void){
    int a, b, c, n;
    cin >> a >> b >> c;
    
    if(a > b){
        n = b;
        b = a;
        a = n;
    }
    if(b > c){
        if(a > c){
            n = a;
            a = c;
            c = b;
            b = n;
        }else{
            n = b;
            b = c;
            c = n;
        }
    }
    cout << a << ' ' << b << ' ' << c << endl;
    return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const int INF=1e7;
const LL LINF=1e18;


int main(){
    int N;
    cin >> N;
    bool f[N][10];
    for(int i=0;i<N;i++){
        for(int j=0;j<10;j++){
            cin >> f[i][j];
        }
    }
    LL p[N][11],ans=-LINF;
    for(int i=0;i<N;i++){
        for(int j=0;j<11;j++){
            cin >> p[i][j];
        }
    }
    int num[N];
    memset(num,0,sizeof(num));
    for(int b=1;b<(1<<10);b++){
        LL sum=0;
        for(int i=0;i<N;i++){
            int count=0;
            for(int j=0;j<10;j++){
                if((b>>j&1)&&f[i][j]) count++;
            }
            sum+=p[i][count];
        }
        ans=max(sum,ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=305;
const int mod=1000000007;

int n,m;
int dp[2][N][N];

int main(){
	int i,j,k,now,pre,w;
	scanf("%d%d",&n,&m);
	if (m<n){
		printf("0\n");
		return 0;
	}
	now=0; pre=1;
	dp[0][1][1]=1;
	for (i=1;i<=m;i++){
		now^=1; pre^=1;
		for (j=1;j<=i;j++)
			for (k=1;k<=i&&k<=j;k++){
				if (!dp[pre][j][k]) continue;
				w=dp[pre][j][k];
				(dp[now][j+1][k]+=1ll*w*(n-j)%mod)%=mod;
				(dp[now][j][k]+=1ll*w*(j-k)%mod)%=mod;
				(dp[now][j][j]+=1ll*w*k%mod)%=mod;
			}
		memset(dp[pre],0,sizeof(dp[pre]));
	}
	printf("%d\n",dp[now][n][n]);
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
count = 0
flag = False
for i in range(n):
    d1,d2 = map(int,input().split())
    if d1 == d2:
        count += 1
        if count == 3:
            flag = True
    else:
        count = 0
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9176
def main(h,w,s):
    maxStep = 0
    #開始地点を全探索
    for y in range(h):
        for x in range(w):
            #壁ならスキップ
            if s[y][x] == "#":
                continue
            #道ならBFSを実行し、最大値を更新
            else:
                st = [x,y]
                maxStep = max(maxStep, bfs(st,h,w,s))
    return maxStep

#stからBFSを行い、最大ステップ数を返す
def bfs(st,h,w,s):
    #初期化
    maxStep = 0
    seen = [[-1]*w for _ in range(h)]
    seen[st[1]][st[0]] = 0
    todo = [st]
    mov = [(1,0),(-1,0),(0,1),(0,-1)]
    #キューが空でない限り処理
    while len(todo) > 0:
        #キューから値を取り出す
        x,y = todo.pop(0)
        #上下左右の探索
        for m in mov:
            nx = x + m[0]
            ny = y + m[1]
            #範囲外(地図の外)ならスキップ
            if nx < 0 or (w-1) < nx or ny < 0 or (h-1) < ny:
                continue
            #未探索かつ道ならキューに追加しステップ数更新
            if seen[ny][nx] == -1 and s[ny][nx] == ".":
                todo.append([nx,ny])
                seen[ny][nx] = seen[y][x] + 1
                maxStep = max(maxStep, seen[ny][nx])
    return maxStep

h,w = map(int,input().split())
s = list(list(input()) for _ in range(h))
print(main(h,w,s))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
typedef pair<int,int> pii;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

int N,W;
vector<ll>dp(100010,0);
    
void solve()
{
    cin>>N>>W;
	REP(i,N){
        int a,b;cin>>a>>b;
        for(int j=W;j>=a;j--)
            dp[j]=max(dp[j],dp[j-a]+b);
    }
    cout<<dp[W]<<endl;
}

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


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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
const int INF = 1e9;
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");
#define FOR(i, l, r) for (int i = int(l); i < int(r); ++i)
#define print(a)       for(auto x : a) cout << x << " "; cout << "\n"
#define print1(a)      for(auto x : a) cout << x.ff << " " << x.ss << "\n"
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << "\n"


ll fast_exp(ll base, ll exp) {ll res=1;while(exp>0) {if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
int val(char c){if (c >= '0' && c <= '9')return (int)c - '0';else return (int)c - 'A' + 10;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll divisibles(ll a, ll b, ll m){if(a%m==0)return (b/m)-(a/m)+1;else return (b/m)-(a/m);}// in [a,b]
string bitstring(int n, int size){string s;while(n){s+=(n%2)+'0';n/=2;}while(s.size()<size){s+='0';}reverse(all(s));return s;}
// dsu start

vi root(200001,0);
vi size(200001,1);
int find(int x){while(x!=root[x])x = root[x];return x;}
bool same(int a,int b){return find(a)==find(b);}
void unite(int a, int b){a = find(a);b = find(b);if(size[a]<size[b])swap(a,b);size[a] += size[b];root[b] = a;}

// dsu end
vi vis(9,0);
int n,m;
int flag = 0;
int mat[9][9];
void dfs(int s, int cnt)
{
	vis[s] = 1;
	for(int i=1; i<=n; ++i)
	{
		if(mat[s][i]==1 && !vis[i])
		{
			dfs(i, cnt+1);
			vis[i]=0;
		}
	}
	if(cnt==n)
		++flag;
}

int main()
{	
    std::ios::sync_with_stdio(false);
    //string bitstring = std::bitset< 3 >( 7 ).to_string(); <bits> (num)
    //srand(time(0));
    //cin.tie(NULL);
    //cout.tie(NULL);
 	cin>>n>>m;
 	for(int i=0; i<m; ++i)
 	{
 		int a,b;
 		cin>>a>>b;
 		mat[a][b] = 1;
 		mat[b][a] = 1;
 	}
 	dfs(1,1);
 	cout<<flag<<"\n";


}

Measured memory_bytes: 1792
import itertools

N = int(input())
A = list(map(int,input().split()))

L = list(itertools.combinations(A,3))
ans = 0
for x in L:
  x = list(x)
  x.sort()
  if x[0] == x[1] or x[1] == x[2] or x[2] == x[0]:
    continue
  if x[0]+x[1] > x[2]:
    #print(x)
    ans +=1
print(ans)
         

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

int main() {
  int n,x,y;
  cin >> n >> x >> y;  
  vector<int>a(n-1);
  for(int i=1;i<n;i++){
    for(int j=i+1;j<n+1;j++){
    a.at(min(min(max(x-i,i-x)+1+max(y-j,j-y),max(y-i,i-y)+1+max(x-j,j-x)),j-i)-1)++;
    }  
  } 
  for(int i=0;i<n-1;i++){
    cout << a.at(i) << endl; 
  } 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
const int INF = 1e9;
const ll MOD = 1000000007;
const ll LINF = 1e18;
using namespace std;



int main() {
    ll n, k, sum=0;
    
    cin>>n>>k;
    
    ll minS=0, maxS=0;
    for(ll i=0; i<n-k+1;i++){
        minS = (i+k-1)*(i+k)/2;
        maxS = (n*(n+1))/2 - (n-(i+k))*(n+1-(i+k))/2;
        sum+=(maxS-minS+1)%MOD;
    }
    sum++;
    
    cout<<sum%MOD<<endl;
    
    return 0;
}


Measured memory_bytes: 3592
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

s = input()

if s == "Sunny":
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
else:
    print("Sunny")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
//#define i_7 (long long)(1e9+7)
#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
using namespace std;
//using namespace boost::multiprecision;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}



int main(){
  
  int x,y,z;
  cin>>x>>y>>z;
  int n = x + y + z;
  long long a[n],b[n],c[n];
  typedef pair<long long, long long> P;
  vector<pair<long long, P>> vec;
  REP(i,n){
    cin>>a[i]>>b[i]>>c[i];
    long long d = a[i] - b[i];
    long long ta = a[i] - c[i];
    long long tb = b[i] - c[i];
    vec.push_back(make_pair(d, P(ta,tb)));
  }
  sort(ALL(vec));
  priority_queue<long long, vector<long long>, greater<long long>> as,bs;
  long long bsum[n] = {}, asum[n] = {};
  REP(i,n){
    if(i < y){
      if(i == 0){
        bsum[i] = vec[i].second.second;
        bs.push(vec[i].second.second);
      }else{
        bsum[i] = bsum[i-1] + vec[i].second.second;
        bs.push(vec[i].second.second);
      }
    }else{
      bs.push(vec[i].second.second);
      long long m = bs.top();
      bs.pop();
      bsum[i] = bsum[i-1] + vec[i].second.second - m;
    }
  }
  for(int i = n-1; i>=0; i--){
    if(i >= n-x){
      if(i == n-1){
        asum[i] = vec[i].second.first;
        as.push(vec[i].second.first);
      }else{
        asum[i] = asum[i+1] + vec[i].second.first;
        as.push(vec[i].second.first);
      }
    }else{
      as.push(vec[i].second.first);
      long long m = as.top();
      as.pop();
      asum[i] = asum[i+1] + vec[i].second.first - m;
    }
  }
  
  long long ans = -INF;
  REP(i,n){
    if(i < y-1 || i+1 > n-x){
      continue;
    }
    ans = max(ans, bsum[i] + asum[i+1]);
  }
  REP(i,n){
    ans += c[i];
  }
  cout<<ans<<endl;
  return 0; 
}


Measured memory_bytes: 8816
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll linf = 1LL << 62;
const int inf = 99999999;
const int dx[4] = { 1,0,-1,0 };
const int sy[4] = { 0,1,0,-1 };

#define atcoder (int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back
#define pr(x) cout << x << endl
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define rep(i,n) for(int i= 0;i<n;i++)

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

ll lcm(ll a, ll b) {//最小公倍数
	return (a / gcd(a, b))*b;
}

ll a[100010], b[100010], n, h;
ll dp[100000];

int main(){

	cin >> n >> h;
	ll sum = 0;
	ll maxa = -linf;
	ll cnt = 0;

	rep(i, n) {
		cin >> a[i] >> b[i];
		chmax(maxa, a[i]);
	}

	rep(i, n) {
		if (maxa < b[i]) {
			sum += b[i];
			cnt++;
		}
	}
	sort(b, b + n, greater<ll>());

	if (sum < h) {
		h -= sum;
		while (h>0) {
			h -= maxa;
			cnt++;
		}
	}
	else {
		cnt = 0;
		rep(i, n) {
			h -= b[i];
			cnt++;
			if (h <= 0)break;
		}
	}

	pr(cnt);
	//system("pause");
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node{
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while ( x != NIL ){
        y = x;
        if ( z->key < x->key ) x = x->left;
        else x = x->right;
    }
    
    z->parent = y;
    if ( y == NIL ) root = z;
    else{
        if ( z->key < y->key ) y->left = z;
        else y->right = z;
    }
}

int find(Node *u, int k){
    while (u != NIL && k != u->key ){
        if ( k < u->key ) u = u->left;
        else u = u->right;
    }
    if ( u == NIL ) return 0;
    else return 1;
}

void inorder(Node *u){
    if ( u == NIL ) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if ( u == NIL ) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n, i, x;
    string com;
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
        cin >> com;
        if ( com == "insert" ){
            scanf("%d", &x);
            insert(x);
        }
        else if ( com == "print" ){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        } 
        else if ( com == "find"){
            scanf("%d",&x);
            if ( find(root, x) == 1 ) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 22040
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>


#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int N, M, C, c, w;
  cin >> N >> M >> C;
  vector<int> l(C);
  for(int i = 0; i < C; i++) cin >> l[i];
  vector<pair<int, int>> data(N);
  for(int i = 0; i < N; i++){
    cin >> c >> w;
    data[i] = make_pair(w, c);
  }

  sort(all(data), greater<pair<int,int>>());

  int ans = 0;
  for(int i = 0; i < N; i++){
    int value = data[i].first, color = data[i].second - 1;
    if(0 < l[color] && M){
      ans += value;
      l[color]--;
      M--;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3856
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "YES";
const string NO = "NO";

void solve(ll N, ll K) {
  bool pred = 2 * K - 1 <= N;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll N;
  cin >> N;
  ll K;
  cin >> K;
  solve(N, K);
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
h,w = map(int, input().split())
s = [["." for _ in range(w+2)]]
for _ in range(h):
    line = list(input())
    s.append(["."]+line+["."])
s.append(["." for _ in range(w+2)])
diff = [
    [1,0]
    ,[0,1]
    ,[-1,0]
    ,[0,-1]
]
def dfs(hi,wi):
    stack = [(hi,wi)]
    while len(stack)>0:
        hi,wi = stack.pop()
        s[hi][wi] = "."
        for d in diff:
            if s[hi+d[0]][wi+d[1]] == "#":
                stack.append((hi+d[0], wi+d[1]))

for hi in range(1,h+1):
    for wi in range(1,w+1):
        if s[hi][wi] == "#":
            f = False
            for d in diff:
                f = f or s[hi+d[0]][wi+d[1]]=="#"
            if f:
                dfs(hi, wi)

for hi in range(1,h+1):
    for wi in range(1,w+2):
        if s[hi][wi] == "#":
            print("No")
            exit()
print("Yes")


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <map>
typedef long long ll;
using namespace std;

int main()
{
	int n;
	cin >> n;
	ll sum=0;
	for (int i=1; i<=n; i++)
		if (i%3!=0 && i%5!=0) sum+=i;
	cout << sum;
	return 0;
}

Measured memory_bytes: 3620
n = int(input())
tasks = [[0,0] for _ in range(n)]
for i in range(n):
  a, b = map(int, input().split())
  tasks[i][0] = a  # 所要時間
  tasks[i][1] = b  # 締め切り
tasks.sort(key=lambda t: t[1])
t = 0

for i in range(n):
  if t + tasks[i][0] > tasks[i][1]:
    print('No')
    exit()
  t += tasks[i][0]
print('Yes')


Measured memory_bytes: 103920
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			if (n <= 999) {
				out.println("ABC");
			} else {
				out.println("ABD");
			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll N,M;
    cin>>N>>M;
    ll Q;
    cin>>Q;
    vi a(Q),b(Q),c(Q),d(Q);
    rep(i,0,Q)cin>>a[i]>>b[i]>>c[i]>>d[i],a[i]--,b[i]--;
    vi res(N+M-1,1);
    rep(i,0,M-1)res[i]=0;
    ll ans=0;
    do{
        vi A(N,1);
        int cnt=0;
        int p=0;
        rep(i,0,N+M-1){
            if(res[i])
                A[p++]+=cnt;
            else{
                cnt++;
            }
        }
        ll sum=0;
        rep(i,0,Q){
            if(A[b[i]]-A[a[i]]==c[i])sum+=d[i];
        }
        chmax(ans,sum);
    }while(next_permutation(res.begin(),res.end()));
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 3604
#include<stdio.h>
#include<assert.h>
#include<vector>
#include<string.h>
#include<algorithm>
#include<memory.h>
#include<cmath>
#include<string>
#include<iostream>
#include<set>
#include<unordered_set>
#include<map>
#include<queue>
#include<functional>
#include<list>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 500005;
const int MM = 1000000007;

int D[MX];
char buf[MX];

int main()
{
	int N;
	scanf("%d%s", &N, buf+1);
	for(int t = 0; t < 4; t++){
		D[1] = t/2, D[2] = t%2;
		for(int i = 3; i <= N; i++){
			D[i] = D[i-2]^D[i-1]^(buf[i-1] == 'o');
		}
		if( D[N-1]^D[N]^D[1]^(buf[N] == 'o') || D[N]^D[1]^D[2]^(buf[1] == 'o') ) continue;
		for(int i = 1; i <= N; i++) printf("%c", D[i]? 'S':'W');
		printf("\n");
		return 0;
	}
	printf("-1\n");
}



Measured memory_bytes: 768
#include"stdio.h"
int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    int f[100001];
    for(int i=0;i<1.0e+5+1;i++)
        f[i]=0;
    for(int i=0;i<n;i++)
        f[a[i]]++;
    int max=0;
    for(int i=1;i<1.0e+5;i++){
        if(max<(f[i-1]+f[i]+f[i+1]))
            max = f[i-1]+f[i]+f[i+1];
    }
    printf("%d\n",max);
}


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

int Max(int x, int y) {
    int a = x;
    if (a < y) {
        a = y;
    }
    return a;
}

int Min(int x, int y) {
    int a = x;
    if (a > y) {
        a = y;
    }
    return a;
}
int main() {
    //データの数を表すデータを入力から受け取る
    int n;
    cin >> n;
    //n個のデータを配列で受け取る
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data.at(i);
    }
    //maxをdata.at(1)-data(0)で初期化
    int max = data.at(1) - data.at(0);
    //minをdata.at(0)で初期化
    int min = data.at(0);
    for (int i = 1; i < n; i++) {
        //maxの値を更新
        max = Max(max, data.at(i) - min);
        //minの値の更新
        min = Min(min, data.at(i));
    }
    cout << max << "\n";
    return 0;
}


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

using namespace std;

int N, H, balance[409];
vector < int > v[409];

void answer (bool value)
{
    if (value) printf ("YES\n");
    else printf ("NO\n");
    exit (0);
}

bool anyNonZero, anyEdge, ap[409], anyLoop[409];
void dfs (int nod)
{
    ap[nod] = 1, anyNonZero |= (balance[nod] != 0);
    anyEdge |= anyLoop[nod];
    for (auto it : v[nod])
        if (ap[it] == 0)
            dfs (it), anyEdge = 1;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &H);
for (int i=1; i<=N; i++)
{
    int a, b, c, d, x, y;
    scanf ("%d %d %d %d", &a, &b, &c, &d);
    x = (c == 0 ? H + a + 1 : c);
    y = (d != 0 ? H + d + 1 : b);
    v[x].push_back (y);
    v[y].push_back (x);
//    printf ("%d -> %d\n", x, y);
    balance[x] ++, balance[y] --;
    if (x == y) anyLoop[x] = 1;
}
for (int i=1; i<=2 * H; i++)
    if ((balance[i] > 0 && i <= H) ||
        (balance[i] < 0 && i > H))
            answer (0);
for (int i=1; i<=2 * H; i++)
    if (ap[i] == 0)
    {
        anyNonZero = 0;
        anyEdge = 0;
        dfs (i);
        if (!anyNonZero && anyEdge)
            answer (0);
    }
answer (1);
return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int N, M; cin >> N >> M;
    vector<int> m(M);
    for (int i = 0;i < N;++i) {
        int K; cin >> K;
        for (int j = 0; j < K; ++j) {
            int k; cin >> k;
            m[k-1] += 1;
        }
    }
    int count = 0;
    for (int v:m) if(v == N) ++count;
    cout << count << endl;        
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int):
    if N % 2 == 0:
        print(N // 2)
    else:
        print(N // 2 + 1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from collections import defaultdict
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    n = int(input())

    d = defaultdict(int)
    for _ in range(n):
        a, b = map(int, input().split())
        d[b] += a

    s = sorted(d.items(), key=lambda x: x[0])
    pf = 0

    for b, a in s:
        pf += a
        if pf > b:
            print("No")
            return

    print("Yes")


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

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

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

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

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


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


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()


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

using namespace std;

int calc_gcd(int a, int b);
int dist(int p, int q);

int main(void)
{
    int cities_count;
    int initial_position;
    vector<int> city_positions;

    cin >> cities_count >> initial_position;

    for(int i = 0; i < cities_count; i++){
        int cp;
        cin >> cp;
        city_positions.push_back(cp);
    }

    if(cities_count == 1){
        cout << dist(city_positions[0], initial_position);
        return 0;
    }

    int gcd = calc_gcd(dist(city_positions[0], initial_position), dist(city_positions[1], initial_position));
    for(int i = 2; i < cities_count; i++){
        gcd = calc_gcd(gcd, dist(city_positions[i], initial_position));
    }

    cout << gcd << endl;

    return 0;
}

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

    return calc_gcd(b, c);
}

int dist(int p, int q)
{
    if(p >= q){
        return p - q;
    }else{
        return q - p;
    }
}

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

const int MAXN = 200010;
int n, A[MAXN], B[MAXN];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n; int m = n * 2 - 1;
	for (int i = 1; i <= m; ++i) std::cin >> A[i];
	int l = 1, r = m, ans = 0;
	while (l <= r) {
		int mid = l + r >> 1;
		for (int i = 1; i <= m; ++i) B[i] = A[i] <= mid;
		int fir = -1;
		for (int i = 0; i + 1 < n; ++i) {
			if (B[n + i] == B[n + i + 1]) { fir = n + i; break; }
			if (B[n - i] == B[n - i - 1]) { fir = n - i - 1; break; }
		}
		bool can = false;
		if (fir != -1) can = B[fir] == 1;
		else can = B[n] ^ (n - 1 & 1) == 1;
		if (can) ans = mid, r = mid - 1;
		else l = mid + 1;
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>

using namespace std;

long long cmb(long long n, long long r) {
    long long x = 1, y = 1;
    long long min;

    if (n - r > r) min = r;
    else min = n - r;
    for (long long i = 0; i < min; i++) {
        x = x * (n - i);
        y = y * (i + 1);
    }
    return x / y ;
}

int main() {
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;

    vector<int> amari(p);
    long long temp = 0, tens = 1;
    if (10 % p) {
        for (int i = n - 1; i >= 0; i--) {
            temp = (temp + (s[i] - '0') * tens) % p;
            amari[temp]++;
            tens = tens * 10 % p;

        }
        long long ans = 0;
        //for (int i = 0; i < p; i++)
          //  cout << i << ":amari" << "=" << amari[i] << endl;
        amari[0]++;
        for (long long i = 0; i < p; i++) {
            if (amari[i] >= 2)
                ans += cmb(amari[i], 2);
        }
        cout << ans << endl;
    }
    
    else {
        int temp;
        long long cnt = 0, ans = 0;
        if (p == 2) {
            for (int i = n - 1; i >= 0; i--) {
                temp = s[i] - '0';
                if (temp % 2 == 0)
                    cnt++;
                ans += cnt;
            }
        }
        else if (p == 5) {
            for (int i = n - 1; i >= 0; i--) {
                temp = s[i] - '0';
                if (temp % 5 == 0)
                    cnt++;
                ans += cnt;
            }
        }
        cout << ans << endl;
        
    }
}


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

int main()
{
	int a_y, b_y, c_y, x, y;
	cin >> a_y >> b_y >> c_y >> x >> y;

	int minx;
	if (x > y)minx = x*2;
	else minx = y*2;

	int min = 0x7fffffff;
	int noww = 0;

	int j = 0, xi = 0, yi = 0;

	for (int i = 0; i < minx; ++i) {
		j = i * 2;
		xi = (x - i);
		if (xi < 0)xi = 0;
		yi = (y - i);
		if (yi < 0)yi = 0;

		noww = a_y * xi + b_y * yi + c_y * j;
		if (min > noww) min = noww;
	}

	cout << min;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int main(){
 	ll d, t, s; 
  	cin >> d >> t >> s;
  
  	if(t * s >= d) cout << "Yes";
  	else cout << "No" ;
  return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
//#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(true);
    int A,B,K;
    cin>>A>>B>>K;
    for(int i = 0 ; i <  K ;++i)
    {
        if(i%2==0)
        {
            if(A%2==1)
                A-=1;
            B+=(A/2);
            A/=2;
        }
        else
        {
            if(B%2==1)
                B-=1;
            A+=(B/2);
            B/=2;
        }
    }
    cout<<A<<' '<<B<<endl;
    return 0;
}

Measured memory_bytes: 256
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    cout << (n+1)/2 << "\n";
}

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

using namespace std;
using namespace boost;

main() {
    int64_t n, k;
    cin >> n >> k;

    constexpr auto M = 1000000007;

    int64_t s = sqrt(n);
    if ((s + 1) * (s + 1) <= n) {
        ++s;
    }

    // 1～j までの和
    vector<vector<int64_t>> counts(k + 1, vector<int64_t>(s + 1, 0));
    // 1～n/l までの和
    vector<vector<int64_t>> counts2(k + 1, vector<int64_t>(s + 1, 0));
    std::iota(counts[1].begin(), counts[1].end(), 0);
    for (int64_t l = 1; l <= s; ++l) {
        counts2[1][l] = n / l;
    }

    for (auto i : irange(2L, k + 1)) {
        for (auto j : irange(1L, s + 1)) {
            counts[i][j] = (counts[i][j - 1] + counts2[i - 1][j]) % M;
        }

        counts2[i][s] = (counts[i][s] + counts[i - 1][s] * (n / s - s) % M) % M;
        for (auto l = s - 1; l > 0; --l) {
            counts2[i][l] = (counts2[i][l + 1] +
                             (counts[i - 1][l] * (n / l - n / (l + 1))) % M) %
                            M;
        }
    }

    cout << counts2[k][1] << endl;
}

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

int main() {
    string s;
    cin >> s;
    
    int n = s.size();
    
    bool judge = true;
    
    for (int i = 0;i<n;i++){
        if (i%2 == 0 && s[i] == 'L'){
            judge = false;
        }else if(i%2 == 1 && s[i] == 'R'){
            judge = false;
        }
    }
    
    if (judge){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


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

int main(){
    int n;
    string s[100];

    cin >> n;
    cin >> s[0];
    for(int i=1; i<n; ++i){
        cin >> s[i];

        if(s[i-1][s[i-1].size()-1] != s[i][0]){
            cout << "No" << endl;
            return 0;
        }
        for(int k=0; k<i; ++k){
            if(s[i] == s[k]){
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	int ans = 0;
	rep(i, n){
		int a;
		cin >>a;
		ans = gcd(ans, a);
	}
	cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll, ll>
#define vi vector<ll>
#define vii vector<ii>
#define vs vector<string>
#define si set<ll>
#define endl "\n"
#define pb push_back
#define x first
#define y second
//g++ -std=c++11 -Wall -Wextra -pedantic-errors main.cpp -o main
const int ms = 1e5 + 5, base = 31, mod = 1e5 + 7;
using namespace std;


ll dp[ms][3], N;
vector<vi> H;

ll solve(int i, int e){
	if (i == N) return 0;
	
	if (dp[i][e] != -1) return dp[i][e];
	
	ll one = H[i][e], two = H[i][e];
	
	if (e==0){
		one += solve(i+1, 1);
		two += solve(i+1, 2);
	}else if(e==1){
		one += solve(i+1, 0);
		two += solve(i+1, 2);
	}else{
		one += solve(i+1, 0);
		two += solve(i+1, 1);
	}
	
	return dp[i][e] = max(one, two);
	
}

int main(){
	ios::sync_with_stdio(false), cin.tie(0);
	memset(dp, -1, sizeof(dp));
	
	cin >> N;
	H.resize(N, vi());
	for (int i = 0; i < N; i++){
		for (int j = 0; j < 3; j++){		
			int a; cin >> a;
			H[i].pb(a);
		}
	}
	
	ll ans1 = solve(0,0), ans2 = solve(0,1), ans3 = solve(0,2);
	//*
	//cout << ans1 << " " << ans2 << " " << ans3 << endl;
	cout << max(ans1, max(ans2, ans3)) << endl;
	//*/
	
	return 0;
}


Measured memory_bytes: 14336