akhauriyash/Code-Regression huggingface dataset:
fn solve(xys: Vec<Vec<(usize, usize)>>) -> usize {
    let mut anss = Vec::new();
    anss.push(0);

    let n = xys.len();
    'outer: for i in (0..2usize.pow(n as u32)).rev() {
        let mut aa: Vec<Option<usize>> = vec![None; n];
        let mut ans = 0;
        for j in 0..n {
            if (i & (1 << j)) > 0 {
                if let Some(y) = aa[j] {
                    if y == 0 {
                        continue 'outer;
                    }
                }

                ans += 1;
                for &(x, y) in xys[j].iter() {
                    if let Some(yp) = aa[x - 1] {
                        if yp != y {
                            continue 'outer;
                        }
                    } else {
                        aa[x - 1] = Some(y);
                    }
                }
                aa[j] = Some(1);
            } else {
                if let Some(yp) = aa[j] {
                    if yp != 0 {
                        continue 'outer;
                    }
                }
                aa[j] = Some(0);
            }
        }
        anss.push(ans);
    }

    *anss.iter().max().unwrap()
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![vec![(2, 1)], vec![(1, 1)], vec![(2, 0)]]), 2);
    assert_eq!(solve(vec![vec![(2, 0)], vec![(1, 0)]]), 1);
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let n = parse_line!(usize);

    let mut xys = Vec::new();

    for _ in 0..n {
        let a = parse_line!(usize);

        let v = (0..a)
            .map(|_| parse_line!(usize, usize))
            .collect::<Vec<_>>();
        xys.push(v);
    }

    println!("{}", solve(xys));
}


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

bool fun(string str)
{
    if(str.length() != 6)
    return false;
    
    if(str[2]!=str[3])
    return false;
    
    if(str[4]!=str[5])
    return false;
    
    return true;
    
}
int main()
{
    string str;
    cin>>str;
    
    if(fun(str))
    cout<<"Yes";
    else
    cout<<"No";
    
    
}

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

int main() 
{   
  

 
long long int h,w;
scanf("%lld %lld",&h,&w);

char a[h][w];
    for(long long int i = 0; i <h; i++){
   
   for(long long int j = 0; j <w; j++){
   scanf(" %c",&a[i][j]);
}
}
long long int dp[h][w];

 
   long long int flag=w+2;
   for(long long int j = 0; j <w; j++){
   if(a[0][j]=='#')
    {dp[0][j]=0;
      flag=j;
      break;}
  else
    dp[0][j]=1;

}
 for(long long int j = flag+1; j <w; j++){
   
    dp[0][j]=0;

}
flag=h+2;
   for(long long int j = 0; j <h; j++){
   if(a[j][0]=='#')
    {dp[j][0]=0;
      flag=j;
      break;}
  else
    dp[j][0]=1;

}
 for(long long int j = flag+1; j <h; j++){
   
    dp[j][0]=0;

}
  for(long long int i = 1; i <h; i++){
   
   for(long long int j = 1; j <w; j++){
   if(a[i][j]=='#')
    dp[i][j]=0;
  else
    dp[i][j]=((dp[i-1][j]%1000000007)+(dp[i][j-1]%1000000007))%1000000007;

}
}

   printf("%lld\n",dp[h-1][w-1]);





}

  
 


Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {
	Scanner in = new Scanner(System.in);
	int trump;
	int[][] num = new int[4][13];
	int[][] mark = new int[4][13];
	int ns, ew;
	
	public void run() {
		while (true) {
			char x = in.next().charAt(0);
			if (x == '#') break;
			trump = (x == 'S') ? 3 :
				    (x == 'H') ? 2 :
				    (x == 'D') ? 1 : 0;
			ns = 0; ew = 0;
			for (int i = 0; i < num.length; i++) {
				for (int j = 0; j < num[i].length; j++) {
					String s = in.next();
					char c = s.charAt(0);
					num[i][j] = (c == 'T') ? 10 : 
						  		(c == 'J') ? 11 :
						  		(c == 'Q') ? 12 :
						  		(c == 'K') ? 13 :
						  		(c == 'A') ? 14 : c - '0';
					c = s.charAt(1);
					mark[i][j] = (c == 'S') ? 3 :
								 (c == 'H') ? 2 :
								 (c == 'D') ? 1 : 0;
				}
			}
			
			int winner = 0;
			for (int i = 0; i < num[0].length; i++) {
				int field = mark[winner][i];
				for (int j = 0; j < num.length; j++) {
					if ((mark[winner][i] == trump && mark[j][i] != trump) ||
						(mark[j][i] != field && mark[j][i] != trump))
						continue;
					else if (mark[winner][i] != trump && mark[j][i] == trump)
						winner = j;
					else {
						if (num[winner][i] > num[j][i]) continue;
						else if (num[winner][i] < num[j][i]) winner = j;
					}
				}
				if (winner == 0 || winner == 2) {
					ns++;
				}
				else  {
					ew++;
				}
			}
			System.out.println((ns > ew) ? "NS " + (ns-6) : "EW " + (ew-6));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 24824
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s[0]!='A'){
		cout<<"WA"<<endl;
		return(0);
	}
	int c=0;
	int b=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='C' && i!=1 && i!=s.size()-1){
			c++;
		}
		if(s[i]<'a')
			b++;
	}
	if(c!=1){
		cout<<"WA"<<endl;
		return(0);
	}
	if(b!=2){
		cout<<"WA"<<endl;
		return(0);
	}
	cout<<"AC"<<endl;
	return(0);
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long M, std::vector<long long> A){
  sort(A.begin(),A.end(),greater<ll>());
  dump(A);
  vector<ll> sumA(A);
  REP(N-1){
    sumA[i+1]+=sumA[i];
  }
  if(M==N*N){
    cout<<sumA.back()*(2LL*N)<<endl;
    return;
  }
  ll ans=0;
  vector<pll> aa;
  ll l=0,r=A[0]*2+1;
  ll num=0;
  while(l+1<r){
    ll mid=(l+r)/2;
    ll num=0;
    REP(N){
      ll tmp=upper_bound(A.begin(),A.end(),mid-A[i],greater<ll>())-A.begin();
      if(tmp==0)break;
      num+=tmp;
    }
    if(num>M){
      l=mid;
    }else{
      r=mid;
    }
  }
  dump(r);
  ans=0;
  num=0;
  REP(N){
    ll tmp=upper_bound(A.begin(),A.end(),r-A[i],greater<ll>())-A.begin();
    if(tmp==0)break;
    num+=tmp;
    ans+=A[i]*(tmp)+sumA[tmp-1];
  }
  if(num<M){
    ans+=l*(M-num);
  }
  cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int sumA = 0;
  int sumB = 0;
  for (int i = 0; i < N; i++){
    if ( i % 2 == 0){
      sumA += vec.at(i);
    }
    else {
      sumB += vec.at(i);
    }
  }
  cout << sumA - sumB << endl;
    
}


Measured memory_bytes: 384
//hi
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long int LL;
int main(void){
    LL a,b,c;
    scanf("%lld%lld%lld",&a,&b,&c);
    LL ans=a*b*c;
    if(a%2==0) ans=0;
    else ans=min(ans,b*c);
    if(b%2==0) ans=0;
    else ans=min(ans,a*c);
    if(c%2==0) ans=0;
    else ans=min(ans,a*b);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
par = [i for i in range(n)]
diff = [0] * n


def find(x):
    if par[x] == x:
        return x, 0
    else:
        a, b = find(par[x])
        par[x] = a
        diff[x] += b
        return a, diff[x]


def unite(x, y, z):
    s, ws = find(x)
    t, wt = find(y)
    # print(ws, wt)
    if s == t:
        if ws - wt == z:
            pass
        else:
            print('No')
            exit(0)
    else:
        if ws < z + wt:
            par[s] = t
            diff[s] = z + wt - ws
        else:
            par[t] = s
            diff[t] = ws - z - wt


for _ in range(m):
    l, r, d = map(int, input().split())
    unite(l - 1, r - 1, d)

print('Yes')

Measured memory_bytes: 14980
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int MOD=1000000007;
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<int>> a(h,vector<int>(w));
    rep(i,0,h) rep(j,0,w) cin>>a.at(i).at(j);
    
    vector<tuple<int,int,int,int>> ans;
    rep(i,0,h){
        if(i%2==0){
            rep(j,0,w){
                int nxi,nxj;
                if(j==w-1){
                    nxi=i+1,nxj=j;
                }
                else{
                    nxi=i,nxj=j+1;
                }
                if(a.at(i).at(j)%2==1 && nxi<h && nxj<w){
                    ans.emplace_back(i+1,j+1,nxi+1,nxj+1);
                    if(nxi<h && nxj<w) a.at(nxi).at(nxj)+=1;
                }
            }
        }
        else{
            rrep(j,w,0){
                int nxi,nxj;
                if(j==0){
                    nxi=i+1,nxj=j;
                }
                else{
                    nxi=i,nxj=j-1;
                }
                if(a.at(i).at(j)%2==1 && nxi<h && nxj<w){
                    ans.emplace_back(i+1,j+1,nxi+1,nxj+1);
                    a.at(nxi).at(nxj)+=1;
                }
            }
        }
    }
    
    cout<<ans.size()<<endl;
    for(auto t:ans){
        int p,q,r,s;
        tie(p,q,r,s)=t;
        cout<<p<<" "<<q<<" "<<r<<" "<<s<<endl;
    }
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    int n,m;
    cin >> n >> m;
    if(m%n == 0) cout << n+m << endl;
    else cout << m-n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int A, B;
	cin >> A >> B;

	if (A + B >= 10)
	{
		cout << "error";
	}
	else
	{
		cout << A + B;
	}

	return 0;
}


Measured memory_bytes: 3644
<?php
  fscanf(STDIN, "%d %d", $n, $d);
  for($i = 0; $i < $n ; $i++){
    $input = fgets(STDIN);
    $list[$i] = explode(" ", $input);
  }


	$cnt = 0;
  for($i = 0; $i < $n; $i++){
    for($j = $i+1; $j < $n; $j++){
      $sum = 0;
		for($k = 0; $k < $d; $k++){
          $sum += ($list[$i][$k] -$list[$j][$k]) **2;
        }
      if(floor(sqrt($sum)) == sqrt($sum))$cnt++;
    }
  }

echo $cnt;
      

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

int main(){
    int a,b,c,d,e,k;
    vector<int> v(5);
    for (int i=0;i<5;i++)cin >>v[i];
    cin>>k;
    sort(v.begin(),v.end());
        if(v[4]-v[0]<=k)cout<<"Yay!"<<endl;
        else cout<<":("<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
#define ll long long
#define inf int(1e9+7)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define l(s) s.size()
int used[26];
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<l(s);i++)
		used[s[i]-'a']=1;
	if(l(s)<26)
	{
		cout<<s;
		for(int i=0;i<26;i++)
			if(!used[i])
			{
				cout<<char(i+'a');
				return 0;
			}
	}
	string t=s;
	if(!next_permutation(t.begin(),t.end()))
	{
		puts("-1");
		return 0;
	}
	for(int i=0;i<l(t);i++)
	{
		if(t[i]!=s[i])
		{
			cout<<s.substr(0,i);
			cout<<t[i];
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}

ll power(ll x, ll y,ll m) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2,m)%m; 
    p = (p * p)%m; 
  
    return (y%2 == 0)? p : (x * p)%m ; 
} 

ll modInverse(ll a, ll m) 
{ 
        // If a and m are relatively prime, then modulo inverse 
        // is a^(m-2) mode m 
    return power(a, m-2,m); 
} 
  
// To compute x^y under modulo m 


int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x;
    cin>>x;
    vector<ll> ans;
    ans.pb(0);
    for(int i=1;i<=1000;i++)
    {
      ans.pb(power(i,5,10000000000000000));
    }
    for(int i=0;i<=1000;i++)
    {
      for(int j=1;j<=1000;j++)
      {
        if(ans[i]+ans[j]==x)
        {
          cout<<i<<" "<<-j;
          return 0;
        }
        if(ans[i]-ans[j]==x)
        {
          cout<<i<<" "<<j;
          return 0;
        }
      }
    }
   
    
    return 0;
}

Measured memory_bytes: 3684
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int N,T,c,t,i,minc=1001;
	cin>>N>>T;
	for (i=0;i<N;i++)
	{
		cin>>c>>t;
		if (t<=T&&minc>c) minc=c;
	}
	if (minc==1001) puts("TLE");
	else printf("%d\n",minc);
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll t1,t2,a1,a2,b1,b2;cin>>t1>>t2>>a1>>a2>>b1>>b2;

  if(t1*a1+t2*a2==t1*b1+t2*b2) { cout<<"infinity"<<endl; return 0; }

  // A always runs long
  if(t1*a1+t2*a2<t1*b1+t2*b2) {
    swap(a1,b1);
    swap(a2, b2);
  }

  if(a1>b1) { cout<<0<<endl; return 0; }

  ll diff = (t1*a1+t2*a2) - (t1*b1+t2*b2);

  ll t1_diff = b1*t1-a1*t1;

  ll result=(t1_diff/diff)*2+1;
  if(t1_diff%diff==0)result--;
  cout<<result<<endl;

  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <algorithm>
int main()
{
int n,sum=0;
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i]-1;
}
printf("%d",sum);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/io.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;
using namespace boost::icl;

int main() {
	int N;

	cin >> N;

    int n = 1, r = 0;
    while (n*10 <= N) {
      r += (n * 10) - n;
      n *= 100;
    }
    
    if( n <= N)
      r += N - n +1;
	cout << r << endl;

	return 0;
}


Measured memory_bytes: 256
#define min(a,b)((a)<(b)?(a):(b))
r;main(c,a,n){for(gets(&c);r=~scanf("%d%d%d",&c,&a,&n);printf("%d\n",r)){
	r=min(c,min(a,n));
	c-=r,a-=r,n-=r;
	n=min(c/2,a);
	r+=n;
	r+=(c-n*2)/3;
}}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;


int main () {
	while (true) {
		int n;
		cin >> n;
		if (n == 0) break;
		vector<int> v;
		int count = 0;

		for(int i = 0; i < n; i++){
			int a;
			cin >> a;
			count+=a;
			v.push_back(a);
		}
		sort(v.begin(),v.end());
		count-=v[0];
		count-=v[v.size()-1];
		cout << count/(n-2) << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3036
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
//#define i_7 998244353
//#define i_5 i_7-2
ll i_7=1;
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
///////////////////////////



ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}



int main(){fastio
    ll n,P;
    cin>>n>>P;
    string s;cin>>s;
    if(P==2||P==5){
        ll ans=0;
        rep(i,0,n-1){
            if((s[i]-'0')%P==0){
                ans+=i+1;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    i_7=P;
    ll a[n+1];
    a[n]=0;
    for(ll i=n-1;i>=0;i--){
        a[i]=mod(po(10,n-1-i)*(s[i]-'0'));
        if(i<n-1)Add(a[i],a[i+1]);
    }
   // rep(i,0,n)cout<<a[i]<<" ";cout<<endl;
    sort(a,a+n+1);
    ll ans=0;
    rep(i,0,n){
        ll c=1;
        while(i<=n-1&&a[i]==a[i+1]){
            i++;c++;
        }
        ans=ans+c*(c-1)/2;
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 2196
from collections import Counter
n, k = map(int, input().split())
P = [input()[0] for _ in range(n)]
CP = Counter(P)

P = list(CP.values())
ans = 0
while len(P) >= k:
  P.sort(reverse=True)
  for i in range(k):
    P[i] -= 1
  P = [i for i in P if i > 0]
  ans += 1
print(ans)


Measured memory_bytes: 3444
function Main(input) {
  var a = input.toString().split('').map(n => parseInt(n, 10));
    if(a[0]==9 || a[1]==9) {
      console.log('Yes');

    } else {
      console.log('No');
    }
 }
  Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 8140
/**
   _           _
  / /         \ \
 / /  _   _  _ \ \
< < (_) (_) (_) > >
 \ \           / /
  \_\         /_/

    Nerede Gitsen Çukur Orda
**/

#include<bits/stdc++.h>
#include<fstream>
///#include<conio.h>
///#include "windows.h"
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define Zohiri_dzd cout.tie(NULL);
#define Belafz cin.tie(NULL);
#define CODER ios_base::sync_with_stdio(0)  ;
#define p_b pop_back
#define p_f pop_front
#define quluq return 0;
using namespace std ;

    const ll N = 1e4 + 0.000001 ;

int main ()
{
    Zohiri_dzd
    Belafz
    CODER
    ///freopen("input.txt" , "r" , stdin );
    ///freopen("output.txt", "w" , stdout );
    ///4294967295
    ///4294967295
    ll l , r , n ;
    cin >> l >> r >> n ;
    ll cnt = 0 ;
    for (ll i = l ; i <= r ; i ++ )
    {
        if (i % n == 0)
            cnt ++ ;
    }
    cout << cnt << endl ;
}
///MaaN studios
///Eco students


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	string s , t ;
	cin >> s >> t ;
	//sの中にtが入っていればいい。tでない?は全てaにして出力すれば良い
	int n = t.size(); 
	//できるだけsの後ろをtにしたほうがいい
	int check = -1 ;
	for(int i = s.size() - n  ; i >= 0  ; i--) {
		string now = s.substr(i,n);
		rep(j,n){
			if(now[j] != t[j] && now[j] != '?'){
				goto SKIP; 
			}
		}
		//ここまでこれたならok
		check = i ;
		break;
SKIP:	 continue;
	}
	if( check == -1 ){
		cout << "UNRESTORABLE" << endl;
		return 0 ;
	} else {
		//checkに行くまで普通に出力
		rep(i,s.size()){
			if(i == check){
				cout << t ; 
				i += n - 1 ;
			} else {
				if(s[i] =='?'){
					cout << 'a' ;
				} else {
					cout << s[i];
				}
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 256
using System;

namespace abc171A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string A = Console.ReadLine();
            char[] C = A.ToCharArray();
            if (Char.IsUpper(C[0]))
                Console.WriteLine("A");
            else
                Console.WriteLine("a");
        }
    }
}


Measured memory_bytes: 25640
n = gets.to_i
a = gets.split.map { |i| i.to_i}.sort

ans = 0

if n%2 == 0 then
	correct = ((1..n/2).map{|i| i*2-1}*2).sort
else
	correct = ([0]+(1..n/2).map{|i| i*2}*2).sort
end

if a == correct then
	ans = (2**(n/2))%1000000007
end

puts ans

Measured memory_bytes: 11768
a, b, c = map(int, input().split())

if any(i % 2 != 0 for i in [a, b, c]):
    print(0)
    exit()

if a == b and b == c:
    print(-1)
    exit()

cnt = 0
a_list = [0]*(1001001)
b_list = [0]*(1001001)
c_list = [0]*(1001001)
a_list[0] = a
b_list[0] = b
c_list[0] = c

for i in range(1, 1001001):
    a_list[i] = (b_list[i-1] + c_list[i-1]) // 2
    b_list[i] = (c_list[i-1] + a_list[i-1]) // 2
    c_list[i] = (a_list[i-1] + b_list[i-1]) // 2
    cnt += 1
    if a_list[i] % 2 != 0 or b_list[i] % 2 != 0 or c_list[i] % 2 != 0:
        break

print(cnt)


Measured memory_bytes: 32492
#include <stdio.h>

#define MIN(A,B) \
  ( (A) < (B) ? (A) : (B) )

int getNextToken (
  void
  )
{
  int res = 0;
  int ch;

  for ( ; ; )
  {
    ch = getchar ( );
    if ( ch == '\n' )       return ( -1 );
    if ( !isspace ( ch ) )  break ;
  }
  for ( ; !isspace ( ch ); ch = getchar ( ) )
  {
    res = res * 10 + ch - '0';
  }
  ungetc ( ch, stdin );

  return ( res );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  for ( ; ; )
  {
    int res = 0, ac = 0;
    int n;

    for ( n = 0; n < 21; ++n )
    {
      int d;

      d = getNextToken ( );
      if ( d == 0  ) return ( 0 );
      if ( d == -1 ) break ;

      res += MIN( d, 10 );
      ac  += !!( d == 1 );
    }
    if ( n >= 21 )
    {
      while ( getNextToken ( ) != -1 ) ;
      puts ( "0" );
      continue ;
    }

    if ( res > 21 )
    {
      puts ( "0" );
    }
    else
    {
      printf ( "%d\n", res + MIN( ( 21 - res ) / 10, ac ) * 10 );
    }
  }

  return ( 0 );
}

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

using ll = long long;

int main()
{
  string S;
  cin >> S;
  ll count_num = 0;
  ll count_index = 0;
  for(int i=0; i<S.length();i++){
    if(S.at(i) == 'W'){
      count_index += count_num;
    }else{
      count_num += 1;
    }
  }
  cout << count_index << endl;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n; cin >> n;
    if (n%2 == 1) cout << n/2+1 << endl;
    else cout << n/2 << endl;
}


Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define ifYN(x) cout<<(x?"Yes":"No")<<"\n" 
#define dcml(n) fixed<<setprecision(n)

 
ll GCD(ll a,ll b) { return b ? GCD(b,a%b) : a; } 
ll LCM(ll a,ll b) { return a/GCD(a,b)*b; } 
ll Factorial(ll n){ ll m=1;while(n>=1)m*=n--;return m; } 
ll modPow(ll x,ll n,ll mod=MOD){ 
    return (!n?1:!n%2?modPow(x*x,n/2,mod)%mod:x%mod*modPow(x,n-1,mod)%mod); 
} 
ll GetDigit(ll num){ 
    ll digit=0; 
    while(num!=0){num/=10;digit++;} 
    return digit; 
} 


using namespace std;
//-------------------------------------------

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  ll count=0;
  REPS(i,N){
    //iが奇数かつ約数を8個持つか
    if(i%2==0)continue;
    ll cnt=0;
    REPS(j,i){
      if(i%j==0)cnt++;
    }
    if(cnt==8)count++;
  }
  cout<<count;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	string s, t;
	cin >> s >> t;
	map<char, char> mpS;
	for(int i=0; i<s.size(); i++)
		mpS[s[i]]=t[i];
	for(int i=0; i<s.size(); i++){
		if(mpS[s[i]]!=t[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	map<char, char> mpT;
	for(int i=0; i<t.size(); i++)
		mpT[t[i]]=s[i];
	for(int i=0; i<t.size(); i++){
		if(mpT[t[i]]!=s[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed(n) fixed << setprecision(n)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

signed main()
{
   cin.tie(nullptr);
   ios_base::sync_with_stdio(false);

   int k,n,a,cnt=0,sum=0,ans=0,wa=0;
   cin>>k>>n;
   bool b = false;
   vector<int> x(n);
   //priority_queue<int> x,z;
   //priority_queue<int,vector<int>,greater<int>> y,v;

   rep(i,0,n) cin>>x[i];

   sort(all(x));

   cnt = x[n-1] - x[0];
   
   rep(i,1,n){
      ans = (k-x[i]) + x[i-1];
      if(cnt > ans){
         cnt = ans;
      }
   }

   cout<<cnt<<'\n';
   return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <vector>
#include <queue>
using namespace std;
#define loop(i,n) for(int i=0;i<n;i++)

int main(){
    
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    
    while(1){
        if (s==""){
            cout<<"YES"<<endl;
            return 0;
        }
        else if(s.substr(0,7)=="remaerd")
            s=s.substr(7);
        else if(s.substr(0,6)=="resare")
            s=s.substr(6);
        else if(s.substr(0,5)=="maerd"||s.substr(0,5)=="esare")
            s=s.substr(5);
        else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 760
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

public class Main
{
    public static void main(String... args)
    {
        final Scanner scanner = new Scanner(System.in);
        final int in = scanner.nextInt();
        final long h = TimeUnit.SECONDS.toHours(in);
        final long m = TimeUnit.SECONDS.toMinutes(in) - TimeUnit.HOURS.toMinutes(h);
        final long s = TimeUnit.SECONDS.toSeconds(in) - TimeUnit.HOURS.toSeconds(h) - TimeUnit.MINUTES.toSeconds(m);
        System.out.println(String.format("%d:%d:%d", h, m, s));
    }
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    LL n;
    LL f=0;
    cin>>n;
    for(LL i=1;i<=2000000;i++)
    {
        f=(f*10+7)%n;
//        cout<<f<<"--\n";
        if(f==0)
        {
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
}


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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    ll pro[n+1]={};
    for(i=0;i<n-1;i++){
        cin >> j;
        pro[j]++;
    }
    for(i=1;i<=n;i++){
        cout << pro[i] << endl;
    }
    return 0;
}

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

int main(){
  int n, x; cin >> n >> x;
  int A[n];
  for (int i=0; i<n; i++){
    cin >> A[i];
  }
  int cnt=0, s = 1010;
  int ans=0;
  for (int i=0; i<n; i++){
    cnt += A[i];
    s = min(s, A[i]);
  }
  int r = x - cnt;
  ans += n+ r/s;
  cout << ans << endl;
  


}

Measured memory_bytes: 256
a = input().split()
n = int(a[0])
m = int(a[1])
img1 = []
for i in range(n):
    img1.append(input())
img2 = []
for j in range(m):
    img2.append(input())

def match(x, y):
    for k in range(m):
        for l in range(m):
            if img1[x+k][y+l] != img2[k][l]:
                return False
    return True

found = False
for i in range(n-m+1):
    for j in range(n-m+1):
        if match(i, j):
            found = True
if found:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3064
from collections import deque
N = int(input())
A = list(map(int,input().split()))

Q = deque([])
for i in range(N):
  if i%2 ==0 :
    Q.append(A[i])
  else:
    Q.appendleft(A[i])
#print(Q)
if N%2 == 0:
  print(*Q)
else:
  Q.reverse()
  print(*Q)

Measured memory_bytes: 32516
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    // read in integer
    int n;
    cin >> n;

    // read integers into queue
    queue <int> q; 
    int j; 
    REP(i, n){
        cin >> j; 
        q.push(j);
    }

    int keep = 0; 
    int tar = 1;

    while (!q.empty()){
        if (q.front() == tar){
            keep++;
            tar++;
        }
        q.pop();
    }

    if (keep == 0){
        cout << "-1" << endl;
        return 0;
    }

    cout << n - keep << endl;

}

Measured memory_bytes: 1024
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//mint型にキャスト
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(ll n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1ll;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
V<V<int>> g;
int cnt[200005]={};
mint ans;
int n;
void dfs(int cur,int par){
    for(int v:g[cur]){
        if(v==par)continue;
        dfs(v,cur);
        cnt[cur]+=cnt[v];
    }
    int val=n-1;
    for(int v:g[cur]){
        if(v==par)continue;
        ans+=(mint(2).pow(val-cnt[v])-mint(1))*(mint(2).pow(cnt[v])-mint(1));
        val-=cnt[v];
    }
    cnt[cur]+=1;
}
int main(){
    cin>>n;
    g.resize(n);
    ans=0;
    int a,b;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        --a;--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0,-1);
    ans/=mint(2).pow(n);
    cout<<ans<<"\n";
}

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

using namespace std;

constexpr int N = 3;

char S[N + 2];

int main() {
	cin >> S;
	int m = 0;
	for(int i = 0; i < N; i++)
		m |= 1 << S[i] - 'A';
	if(m == 3)
		cout << "Yes" << '\n';
	else
		cout << "No" << '\n';
}


Measured memory_bytes: 256
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
    
N,M=map(int,input().split())
A=[int(i)//2 for i in input().split()]
q=lcm(*A)
#print(q)
for i in A:
    #print(i)
    if q//i%2==0:
        print(0)
        exit()
print((M//q+1)//2)

Measured memory_bytes: 16308
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math


def main():
    a, b, h, m = map(int, input().split())

    m_t = h * 60 + m
    a_theta = - (m_t / (12 * 60) * (2 * math.pi))
    b_theta = - (m / 60 * (2 * math.pi))

    ax, ay = a * math.cos(a_theta), a * math.sin(a_theta)
    bx, by = b * math.cos(b_theta), b * math.sin(b_theta)

    r = math.sqrt((ax - bx) ** 2 + (ay - by) ** 2)
    print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9516
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
const int MAX = (int)2e5 + 5;

double a[3];
double b[3];

int solve() {
	double diff = hypot(a[0] - b[0], a[1] - b[1]);
	if (diff + b[2] < a[2]) return 2;
	if (diff + a[2] < b[2]) return -2;
	if (a[2] + b[2] >= diff) return 1;
	return 0;
}

int main() {
	int N;
	cin >> N;
	while (cin >> a[0]) {
		rep(i, 2) cin >> a[i + 1];
		rep(i, 3) cin >> b[i];
		cout << solve() << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
//
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
#define MAXN 10005
#define LL long long
#define INF 0x3f3f3f3f 
int n,a,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		ans^=a;
	}
	if(ans==0) printf("Yes\n");
	else printf("No\n");
	return 0;
} 


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }


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

    int n;

    cin >> a >> b;
    n = b - a;

    cout << n * (n-1) / 2 - a << endl;

    return 0;
}


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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
    
int main(){
    int R,C;
    cin>>R>>C;
    vector<string> s(R);
    cin>>s;
    vector<int> cnt(26);
    REP(i,R)REP(j,C)cnt[s[i][j]-'a']++;
    vector<int> need(5,0);
    if(R%2==1&&C%2==1){
        need[4]+=(R/2)*(C/2);
        need[2]+=C/2;
        need[2]+=R/2;
        need[1]=1;
    }
    else if(R%2==1){
        need[4]+=(R/2)*(C/2);
        need[2]+=C/2;
    }
    else if(C%2==1){
        need[4]+=(R/2)*(C/2);
        need[2]+=R/2;
    }
    else need[4]+=R*C/4;
    bool ok=true;
    for(int i=4;i>=1;i--){
        while(need[i]>0){
            bool e=false;
            REP(k,26)if(cnt[k]>=i){
                cnt[k]-=i;
                e=true;
                break;
            }
            if(e==false)ok=false;
            need[i]--;
        }
    }
    if(ok)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


// youtube editorial
void solve() {
  string s;
  cin >> s;
  reverse(all(s));
  s += '0';

  int n = sz(s);
  int dp[n + 1][2]; // 繰り下がりが発生しているか
  fill_n(*dp, (n + 1) * 2, inf);
  dp[0][0] = 0;
  rep(i, n) rep(j, 2) {
    int x = s[i] - '0';
    x += j; // nj が効いてくる, 引かれる方を +1
    rep(a, 10) {
      int ni = i + 1, nj = 0;
      int b = a - x;
      if (b < 0) {
        nj = 1;
        b += 10;
      }
      chmin(dp[ni][nj], dp[i][j] + a + b);
    }
  }
  cout << dp[n][0] << endl;
}


Measured memory_bytes: 9116
#include<stdio.h>
int main()
{
  int a=700,i;
  char s[3];
  scanf("%s",s);
  for(i=0;i<3;i++){
    if('o'==s[i]){
      a += 100;
    }		
  }		
  printf("%d",a);
  return 0;
}		
  	

Measured memory_bytes: 128
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <vector>
#include <stdio.h>
#include <iostream>
#include <unordered_set>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <random>
#include <time.h>
#include <cassert>


#define prev askdnsajd
#define rank asasdmdnasd
#define next lsjndajbs
#define hash asmdklansd
#define index asdklnas
#define right sld
#define left sldl
using namespace std;

typedef long long ll;
typedef long double dbl;

template<class T>
void print(vector<T> s){
    for (T x : s)
        cout << x << " ";
    cout << endl;
}

mt19937 mrand(random_device{} ());
int rnd() {
	return mrand();
}

const int maxn = 1e5 + 7;

vector<int> getFactor(int x){
	vector<int> s;
	if (x < 0){
		s.push_back(-1);
		x *= -1;
	}
	for (int i = 2; i * i <= 1e8; i++){
		if (x % i == 0){
			int cnt = 0;
			while (x % i == 0){
				cnt++;
				x /= i;
			}
			if (cnt & 1)
				s.push_back(i);
		}
	}
	if (x > 1)
		s.push_back(x);
	return s;
}

vector<int> compress(vector<vector<int> > s){
	int n = s.size();
	vector<vector<int> > ss(n);
	// print(s[0]);
	for (int i = 0; i < n; i++){
		sort(s[i].begin(), s[i].end());
		for (int j : s[i])
			ss[i].push_back(j);
	}
	// print(s[0]);
	sort(ss.begin(), ss.end());
	ss.resize(unique(ss.begin(), ss.end()) - ss.begin());
	// cout << ss.size() << endl;
	vector<int> answer(n);
	for (int i = 0; i < n; i++){
		// print(s[i]);
		answer[i] = lower_bound(ss.begin(), ss.end(), s[i]) - ss.begin();
	}
	return answer;
}

int main(){
    srand(17);
 	ios_base::sync_with_stdio(0);
 	int n, d;
 	cin >> n >> d;
 	cout << (n + 2 * d) / (2 * d + 1) << endl;
    return 0;
}

Measured memory_bytes: 512