akhauriyash/Code-Regression huggingface dataset:
N = int(input())
a = list(map(int, input().split()))

res_min = 0
res_max = 0

g = list(filter(lambda x: x <= 399, a))
br = list(filter(lambda x: 400 <= x <= 799, a))
gr = list(filter(lambda x: 800 <= x <= 1199, a))
s = list(filter(lambda x: 1200 <= x <= 1599, a))
bl = list(filter(lambda x: 1600 <= x <= 1999, a))
y = list(filter(lambda x: 2000 <= x <= 2399, a))
o = list(filter(lambda x: 2400 <= x <= 2799, a))
r = list(filter(lambda x: 2800 <= x <= 3199, a))
t = list(filter(lambda x: 3200 <= x, a))

c_list = [g, br, gr, s, bl, y, o, r]

for c in c_list:
    if len(c) != 0:
        res_min += 1
        res_max += 1

if res_min == 0:
    res_min += 1
res_max += len(t)


print(res_min, res_max)

Measured memory_bytes: 3064
#include <stdio.h>

long heap[1000];

int main()
{
	int i = 0, len = 0;
	scanf("%d", &len);
	for (i = 1; i <= len; i++) {
		scanf("%ld", &heap[i]);
	}
	for (i = 1; i <= len; i++) {
		printf("node %d: key = %ld, ", i, heap[i]);
		if (i / 2 > 0)  {
			printf("parent key = %ld, ", heap[i/2]);
		}
		if (i*2 <= len) {
			printf("left key = %ld, ", heap[i*2]);
		}
		if ((i*2+1) <= len) {
			printf("right key = %ld, ", heap[i*2+1]);
		}
		printf("\n");
	}
	return 0;
}



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

int main(){
  char c;
  cin >> c;
  
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
   int A, B, C, cnt = 0;

   scanf("%d %d", &A, &B);

   while(C < B) {
      C = 1 + (A * cnt) - cnt;
      cnt++;
   }

   cnt;

   printf("%d\n", cnt - 1);

   return 0;
}


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

int main() 
{
    // Ask monta if #define int long long tenjah ou nn
    ll n;
    cin >> n;
    vector <ll> v(5);
    for (int i=0; i<5; i++)
        cin >> v[i];
    ll min = *min_element(v.begin(), v.end());
    cout << (min!=1?5 + (n/min):n+4);
    return 0;
}

Measured memory_bytes: 256
def main():
    Q, H, S, D = map(int, input().split())
    N = int(input())

    H = min(H, 2*Q)
    S = min(S, 2*H, 4*Q)
    D = min(D, 2*S, 4*H, 8*Q)

    cost = [
        [0.25, Q],
        [0.5, H],
        [1, S],
        [2, D]
    ]

    cost.sort(reverse = True, key = lambda x : x[0])

    ans = 0
    for c in cost:
        if N <= 0:
            break

        r, m = divmod(N, c[0])
        ans += r*c[1]
        N -= r*c[0]

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
using namespace std;
int x,n;
int f[10000];
int main(){
	f[0]=1;
	for(register int i=1;i<=3;i++){
		scanf("%d",&x);
		for(register int j=0;j<=5000;j++){
			if(f[j])f[j+x]+=f[j];
		}
	}
	scanf("%d",&n);
	printf("%d\n",f[n]);
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a, b, c, k, sum, i;
    while(scanf("%d %d %d %d", &a, &b, &c, &k) == 4)
    {
        if(a==b && b==c && c==a)
        {
            for(i=1; i<=k; i++)
                a*=2;
            sum = a+b+c;
        }
        else if(a>b && a>c)
        {
            for(i=1; i<=k; i++)
                a=a*2;
            sum = a+b+c;
        }
        else if(b>c && b>a)
        {
            for(i=1; i<=k; i++)
                b*=2;
            sum = a+b+c;
        }
        else
        {
            for(i=1; i<=k; i++)
                c*=2;
            sum = a+b+c;
        }


        printf("%d\n", sum);
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, n) for (int i = 0; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i,N) cin >> a[i];
    int ans = 0;
    rep(i,N) ans += (a[i]-1);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner f = new Scanner(System.in);
        // fill in the dictionary with the initial value
        int hands = Integer.parseInt(f.nextLine());
        int leftScore =0, rightScore = 0;
        for(int draw = 0; draw < hands; draw++){
            String[] temp = f.nextLine().split(" ");
            int left = temp[0].length();
            int right = temp[1].length(); // index of the hand
            for(int i =0; i <= Math.max(left, right); i++){
                if(i == right && i == left){
                    leftScore += 1;
                    rightScore += 1;
                    break;
                } else if(i >= left){
                    rightScore += 3;
                    break;
                } else if(i >= right){
                    leftScore += 3;
                    break;
                } else if(temp[0].charAt(i) > temp[1].charAt(i)){
                    leftScore += 3;
                    break;
                } else if(temp[0].charAt(i) < temp[1].charAt(i)){
                    rightScore += 3;
                    break;
                }
            }
        }
        System.out.println(leftScore + " " + rightScore);
    }
}


Measured memory_bytes: 31328
#include <stdio.h>
#include <stdlib.h>

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return -1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
long Combination(long n, long r) {
  long answer = 1;
  if (n-r < r) {
    r = n-r;
  }
  for (long i = 1; i <= r; i++) {
    answer *= n+1-i;
    answer /= i;
  }
  return answer;
}

int main(void) {

  long n;
  scanf("%ld", &n);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  qsort(a, n, sizeof(long), cmpnum);
  long r;
  long max_r;
  long max = -1;
  for (long i = 1; i < n; i++) {
    r = a[i];
    if (r*2 > a[0]) {
      r = a[0]-r;
    }
    if (r > max) {
      max_r = i;
      max = r;
    }
  }
  printf("%ld %ld\n", a[0], a[max_r]);

  return 0;
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int b[4444],r[4444],g[4444];
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	int n;
	cin>>n;
	string s;
	cin>>s;
	rep(i,s.size())
	{
		if(i!=0)
		{
			b[i]=b[i-1];
			r[i]=r[i-1];
			g[i]=g[i-1];
		}
		if(s[i]=='B')b[i]++;
		if(s[i]=='R')r[i]++;
		if(s[i]=='G')g[i]++; 
	}
	ll cnt=0;
	rep(i,s.size())
		forn(j,i+2,s.size()-1)
		{
			ll m=((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R'));
			ll k=b[j-1]-b[i];
			if((j-i)%2==0)if(s[(i+j)/2]=='B')k--;
			cnt+=m*k;
		}
	rep(i,s.size())
		forn(j,i+2,s.size()-1)
		{
			ll m=((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B'));
			ll k=r[j-1]-r[i];
			if((j-i)%2==0)if(s[(i+j)/2]=='R')k--;
			cnt+=m*k;
		}
	rep(i,s.size())
		forn(j,i+2,s.size()-1)
		{
			ll m=((s[i]=='B'&&s[j]=='R')||(s[i]=='R'&&s[j]=='B'));
			ll k=g[j-1]-g[i];
			if((j-i)%2==0)if(s[(i+j)/2]=='G')k--;
			cnt+=m*k;
		}
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 3700
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	int n, a[200];
	cin >> n;
	lp(n)
		cin >> a[i];
	int cnt = -1;
	bool flag = true;
	do{
		cnt++;
		lp(n)
			if (a[i] % 2 != 0)
				flag = false;
			else a[i] = a[i] / 2;
	} while (flag == true);
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
  int n;
  cin >> n;
  vector<int> a(n), x(n);
  rep(i,n) cin >> a[i];
  //x[0]=s-2(A1+A3+..+An-2)
  ll s = 0, A = 0;
  rep(i,n) {
    s += a[i];
    if(i%2!=0) A += a[i];
  }
  x[0] = s-2*A;
  for(int i = 1; i < n; i++) x[i] = 2*a[i-1]-x[i-1];
  rep(i,n) cout << x[i] << " ";
  cout << endl; 
  return 0;
}

Measured memory_bytes: 4000
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<array>
#include<limits>
#include<iomanip>

using namespace std;

const int MAX_N = 8;
int x[MAX_N];
int y[MAX_N];
int N;

void print_order(vector<int> &perm){
    for(int i=0; i < N; ++i){
        cout << perm[i] << " ";
    }
    cout << endl;
}

double solve(){
    vector<int> perm(N);
    double ave = 0.0;
    int cnt = 0;
    iota(perm.begin(), perm.end(),0);
    do{
        double dist = 0.0;
        for(int i=1; i < perm.size(); ++i){
            int idx1 = perm[i-1];
            int idx2 = perm[i];
            dist += (double)sqrt((x[idx1] - x[idx2]) * (x[idx1] - x[idx2]) + (y[idx1] - y[idx2]) * (y[idx1] - y[idx2]));
        }
        ++cnt;
        ave += dist;
    }while(next_permutation(perm.begin(),perm.end()));
    ave /= cnt;

    return ave;
}

int main(void){
    cin >> N;
    for(int i=0;i<N;++i){
        cin >> x[i] >> y[i];
    }

    cout << fixed << setprecision(10) <<  solve() << endl;

    return 0; 
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <map>
#include <string>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;

int main(){
    int n; cin>>n;
    vector<int> a(n-1);
    rep(i,n-1) cin>>a[i];
    vector<int> ans(n);
    rep(i,n-1) ans[a[i]-1]++;
    rep(i,n) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 4836
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }  
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
signed main(){
  int n;
  while(cin>>n,n){
    n--;
    int m=n*(n+1)/2;
    vector<int> ds(m);
    for(int i=0;i<m;i++) cin>>ds[i];

    multiset<int> ms;
    for(int d:ds) ms.emplace(d);
    
    int len=ds[0];
    ms.erase(ms.find(len));
    vector<int> vs({0,len});
    
    map<int, int> cnt;
    for(int x:ms) cnt[x]++;    
    
    set<vector<int>> ans;
    // [l, r]
    MFP([&](auto dfs)->void{     
          if(ms.empty()){
            auto us(vs);
            sort(us.begin(),us.end());            
            ans.emplace(us);
            return;
          }          
          for(int k=0;k<2;k++){
            int nxt=k?*ms.rbegin():len-*ms.rbegin();            
            int flg=1;
            for(int v:vs){
              cnt[abs(v-nxt)]--;
              flg&=cnt[abs(v-nxt)]>=0;
            }
            if(flg){
              for(int v:vs)
                ms.erase(ms.find(abs(v-nxt)));
              vs.emplace_back(nxt);
              dfs();
              vs.pop_back();
              for(int v:vs)
                ms.emplace(abs(v-nxt));              
            }            
            for(int v:vs)
              cnt[abs(v-nxt)]++;
          }          
        })();
    
    for(auto vs:ans){
      for(int i=0;i<n;i++){
        if(i) cout<<" ";
        cout<<vs[i+1]-vs[i];
      }
      cout<<endl;
    }
    cout<<"-----"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<functional>
using namespace std;
typedef	long long int ll;

int main(){
    int n;
    vector<int> t, x, y;
    int ti, xi, yi;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> ti >> xi >> yi;
        t.push_back(ti);
        x.push_back(xi);
        y.push_back(yi);
    }
    int nowx = 0;
    int nowy = 0;
    int nowt = 0;
    for(int i = 0; i < n; i++){
        if(abs(nowx-x[i])+abs(nowy-y[i]) > t[i]-nowt || (t[i]-nowt-(abs(nowx-x[i])+abs(nowy-y[i])))%2==1){
            cout << "No" << endl;
            return 0;
        }
        nowx = x[i];
        nowy = y[i];
        nowt = t[i];
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1644
K = int(input())

ans = 0

for i in range(1,K):
    for j in range(i+1,K+1):
        if (i % 2 == 0 and j % 2 == 1) or (i % 2 == 1 and j % 2 == 0):
            ans += 1

print(ans)

Measured memory_bytes: 3060
import bisect

S=[]

def insert(S,count,x):
    y=bisect.bisect(S,x)
    if y-1<0 or S[y-1]!=x:
        S.insert(y,x)
        count+=1
    print(count)
    return S,count

def find(S,x):
    y=bisect.bisect(S,x)
    if y-1>=0 and S[y-1]==x:
        print(1)
    else:
        print(0)

q=int(input())
count=0
for i in range(q):
    query=list(map(int,input().split()))
    if query[0]==0:
        S,count=insert(S,count,query[1])
    else:
        find(S,query[1])



Measured memory_bytes: 13632
#include <iostream>
#include <cmath>
using namespace std;
int main( void )
{
  int n;
  cin >> n;
  for( int i=0; i<n; i++ ){
    double x1,y1,x2,y2,x3,y3,x4,y4;
    cin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;
    if( (y2-y1)*(x4-x3) - (x2-x1)*(y4-y3) == 0 )
      cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
	int f;char c;
	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
	static char q[64];int cnt=0;
	if(!x)pc('0');if(x<0)pc('-'),x=-x;
	while(x)q[cnt++]=x%10+'0',x/=10;
	while(cnt--)pc(q[cnt]);
}
const int maxn=100005;
int pa[maxn];
int ac(int x){
	return x==pa[x]?x:pa[x]=ac(pa[x]);
}
int main(){
	int N,M;read(N),read(M);
	for(int i=1;i<=N;++i)pa[i]=i;
	for(int i=1;i<=M;++i){int A,B;read(A),read(B);pa[ac(A)]=ac(B);}
	int ans=-1;
	for(int i=1;i<=N;++i)ans+=(ac(i)==i);
	write(ans),pc('\n');
	return 0;
}


Measured memory_bytes: 4020
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int[] menu = new int[5];
		int last = 0;
		int sum = 0;
      
		for(int i=0; i<5; i++){
			menu[i] = sc.nextInt();
			if(i>0){
				if((menu[i]%10!=0)&&((menu[i]%10)<(menu[last]%10))){
					last = i;
            	}
        	}
        }
      
		int i=0;
		int count=0;
		while(count<4){
			if(sum%10!=0){
				sum++;
				if(sum%10==0){
					count++;
				}
			}else if(i!=last){
				sum += menu[i];
				i++;
				if(sum%10==0){
					count++;
				}
        	}else if(i==last){
        		i++;
        	}
		}
		sum += menu[last];
		System.out.println(sum);
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
    // ABC169-C, 
    ll a; double b; ll c; cin >> a >> b;
    c = round(b * ll(100));
    cout << a * c / ll(100) << endl;
    return 0;
}

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

bool checkpalindrome(int n){
    string s=to_string(n);
    if(s==string(s.rbegin(),s.rend()))return 1;
    return 0;
}

int main(){
int a,b;cin>>a>>b;
int ans=0;
for(int i=a;i<b+1;i++){
    if(checkpalindrome(i))ans++;
}
cout<<ans;
}

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

int main() {
    vector<int> word(3);
    vector<int> ans = {5,5,7};

    for(int i = 0;i < 3;i++) {
        cin >> word.at(i);
    }
    sort(word.begin(),word.end());
    if(equal(word.cbegin(),word.cend(),ans.cbegin()))
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,l;
	cin >> n >> l; 
	if(l>=0)
		cout << (l-1)*(n-1)+(2+n)*(n-1)/2;
	else
		if(n+l-1<0)
			cout << (l-1)*(n-1)+n*(n-1)/2;
	    else 
			cout << (l-1)*n+(1+n)*n/2;
	return 0;
}

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

#define count_ones __builtin_popcountl
#define all(a) a.begin(), a.end()
#define gcd(a, b) __gcd(a, b)
#define lca(a, b) a / __gcd(a, b) * b
typedef long long ll;
typedef long double ld;
using namespace std;

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

    ll n, k;
    cin >> n >> k;
    ll cnt = 0;
    for (ll i = 0; i < n; i++) {
        ll h;
        cin >> h;
        if (h >= k) cnt++;
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    
    int N,C,a = 0,p,b=0;
    cin>>N>>C;
    
    for(int i=0; i<C; i++){
        cin>>p;
        
        a += p;
    }
    
    b = a / (N + 1);
    
    if(a % (N + 1) != 0)
    {
        b += 1;
    }
    
    cout << b << endl;
}



Measured memory_bytes: 3092
#include<stdio.h>
int main()
{
    int i,j,temp,sum=0,c;
    int a[3];
    for(i=0;i<3;i++) scanf("%d",&a[i]);
    for(i=0;i<3;i++)
    {
        for(j=0;j<3-1;j++)
        {
            if(a[j+1]<a[j])
            {
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
    for(i=0;i<3-1;i++)
    {
        c=a[i+1]-a[i];
        sum+=c;
    }
    printf("%d\n",sum);
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  if(n%2 == 1) n *= 2;
  cout << n << endl; 
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long int
#include<bits/stdc++.h>
//#include<deque>
//#define pb push_back
//#define pf push_front
ll power(ll l,ll v,ll div){
  ll res=1;
  l=l%div;
  while(v>0){
    if(v&1)
      res=(res*l)%div;
    v=v>>1;
    l=(l*l)%div;
  }
  return res;
}
int main(){
  ll n,i,p;
  cin>>n>>p;
  string s;
  cin>>s;
  ll k=n;
  ll a[n];
  if(p==2 or p==5){
    ll total=0;
    for(i=n-1;i>=0;i--){
      s[i]=s[i]-'0';
      if(s[i]%p==0){
        total+=(i+1);
      }
    }
    cout<<total;
    return 0;
  }
  ll curr=0,ans=0;
  ll l;
  map<ll,ll>m;
  m[0]=1;
  for(i=0;i<n;i++){
    curr=(power(10,n-1-i,p)*(((ll)s[i]-'0'))%p)%p+curr;
    curr%=p;
    ans+=m[curr];
    m[curr]++;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 1028
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
struct Stack {
	int p;// next
	int a[10000];
	Stack() :p(0) {
		memset(a, 0, sizeof(a));
	}
	void push(int x) {
		a[p++] = x;
	}
	void pop() {
		p--;
	}
	int top() {
		if (p == 0)return -1;
		return a[p - 1];
	}
};
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	Stack s;
	string t;
	while (cin >> t) {
		if (t == "+" || t == "*" || t == "-") {
			int a = s.top(); s.pop();
			int b = s.top(); s.pop();
			if (t == "+")s.push(a + b);
			else if (t == "*")s.push(a*b);
			else s.push(b-a);
		}
		else s.push(stoi(t));
	}
	cout << s.top() << endl;
	return 0;
}

Measured memory_bytes: 3216
#include "bits/stdc++.h"
using namespace std;

int main(){
	int n;
	cin>>n;
	int k;
	cin>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(),a.end());
	
	int ans=0;
	for(int i=0;i<k;i++){
		ans+=a[n-i-1];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n,q;
    cin>>n;
    set<ll> s;
    for(int i=0;i<n;i++){
        ll b;
        cin>>b;
        s.insert(b);
    }
    cin>>q;
    ll count=0;
    for(int i=0;i<q;i++){
        ll b;
        cin>>b;
        if(s.find(b)!=s.end()){count++;}
    }
    cout<<count<<endl;
    
    return 0;
}



Measured memory_bytes: 3136
#include<cstdio>
#include<cstring>
#include<algorithm>
#define clr(a,x) memset(a,x,sizeof(a))
using namespace std;

typedef long long ll;
const int N=100007,INF=0x3f3f3f3f;
const ll MAX=(1ll<<32);
inline ll read(){
	ll x=0,f=0;
	char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=1;
	for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
	return f?-x:x;
}

int tot=1,S,T,h,t,st[N],to[N],nx[N],len[N],maxflow[N],vis[N],q[N],pre[N];
ll ans,cost[N],dis[N];
void add(int u,int v,int w,ll c){
	c=MAX-c;
	to[++tot]=v,nx[tot]=st[u],st[u]=tot,len[tot]=w,cost[tot]=c;
	to[++tot]=u,nx[tot]=st[v],st[v]=tot,len[tot]=0,cost[tot]=-c;
}
int bfs(){
	clr(maxflow,0);
	clr(pre,0);
	clr(vis,0);
	clr(dis,0x3f);
	h=1,q[t=1]=S,maxflow[S]=INF,dis[S]=0,vis[S]=1;
	while(h<=t){
		int u=q[h++];
		vis[u]=0;
		for(int i=st[u],v;i;i=nx[i]){
			v=to[i];
			if(len[i]>0&&dis[u]+cost[i]<dis[v]){
				maxflow[v]=min(maxflow[u],len[i]),dis[v]=dis[u]+cost[i],pre[v]=i;
				if(!vis[v])q[++t]=v,vis[v]=1;
			}
		}
	}
	return maxflow[T]>0&&dis[T]>0;
}
void upd(){
	int u=T;
	while(u!=S)len[pre[u]]-=maxflow[T],len[pre[u]^1]+=maxflow[T],u=to[pre[u]^1];
	ans+=dis[T]*maxflow[T];
}

int n,c[2][N];
ll sum,x[2][N],y[2][N];

int main(){
	n=read(),S=2*n+5,T=2*n+6;
	for(int i=1;i<=n;++i){
		ll x=read(),y=read();
		int c=read();
		sum+=c;
		add(S,i,c,MAX);
		add(i,2*n+1,c,x+y);
		add(i,2*n+2,c,x-y);
		add(i,2*n+3,c,y-x);
		add(i,2*n+4,c,-x-y);
	}
	for(int i=1;i<=n;++i){
		ll x=read(),y=read();
		int c=read();
		add(i+n,T,c,MAX);
		add(2*n+1,i+n,c,-x-y);
		add(2*n+2,i+n,c,y-x);
		add(2*n+3,i+n,c,x-y);
		add(2*n+4,i+n,c,x+y);
	}
	while(bfs())upd();
	printf("%lld\n",sum*MAX*2-ans);
	return 0;
}


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

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

    int house [4][3][10] = {0};
    int b, f, r, v;

    for(int i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        house[b - 1][f - 1][r - 1] += v;
    }

    for(int i = 0; i < 4; i++){
        if (i > 0){
            cout << "####################" << endl;
        }
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 10; k++){
                cout << " " << house[i][j][k];
            }
            cout << endl;
        }
        
    }

}


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

ll Pow(ll x, ll n){
  if(n == 0) return 1;
  if(n % 2 == 0) return Pow(x*x % mod, n/2);
  else return x * Pow(x,n-1) % mod;
}

int main(){
  int n;
  cin >> n;
  int d[n];
  vector<int> v(n,0);
  int m = -1;
  rep(i,n) {
    cin >> d[i];
    v[d[i]]++;
    m = max(m,d[i]);
  }
  ll ans = 1;
  if(d[0] != 0 || v[0] != 1) {
    cout << 0 << endl;
    return 0;
  }
  for(int i = 1; i <= m; i++){
    (ans *= Pow(v[i-1],v[i])) %= mod; 
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws Exception {
        
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        String[] strP = br.readLine().split(" ");
        int[] P = Stream.of(strP).mapToInt(Integer::parseInt).toArray();
        
        int count = 0;
        for(int i = 0; i < N; i++){
            
            if ( i+1 != P[i] ) count++;
            if ( count > 2 ) break;
        }
        
        System.out.println( (count <= 2) ? "YES" : "NO" );
    }
}


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

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

    int flag = 1;
    if((n - 1) * (n - 2) / 2 < k) flag = 0;

    if(flag == 1) {
        int m = n * (n - 1) / 2 - k;
        cout << m << endl;
        for(int i = 1; i <= n - 1; i++) {
            for(int j = i + 1; j <= n; j++) {
                cout << i << " " << j << endl;
                m--;
                if(m == 0) break;
            }
            if(m == 0) break;
        }
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

#define e9 1000000000LL

// GCC __gcd(long long A, long long B)

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

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

ll toNum(char *s) {
  ll p = 0;
  bool f = false;
  ll t = e9;

  while (*s) {
    if (*s == '.') {
      f = true;
    } else {
      if (!f)
        p = p * 10 + e9 * (*s - '0');
      else
        p += t * (*s - '0');
    }
    if (f) t /= 10;
    s++;
  }

  return p;
}

int main() {
  int N;
  char S[30];
  ll counter[20][20] = {};
  pair<int, int> p[SIZE];

  cin >> N;

  for (int i = 0; i < N; i++) {
    scanf("%s", S);
    ll v = toNum(S);
    int c2 = 0, c5 = 0;
    ll v2 = v;
    while (v2 && v2 % 2 == 0) {
      v2 /= 2;
      c2++;
    }
    while (v2 && v2 % 5 == 0) {
      v2 /= 5;
      c5++;
    }
    counter[min(c2, 18)][min(c5, 18)]++;
    p[i] = {min(c2, 18), min(c5, 18)};
  }

  for (int i = 0; i <= 18; i++) {
    for (int j = 17; j >= 0; j--) {
      counter[i][j] += counter[i][j + 1];
    }
  }

  for (int i = 0; i <= 18; i++) {
    for (int j = 17; j >= 0; j--) {
      counter[j][i] += counter[j + 1][i];
    }
  }

  ll ans = 0;

  for (int i = 0; i < N; i++) {
    int a = p[i].first, b = p[i].second;
    ans += counter[18 - a][18 - b];
    ans -= a >= 9 && b >= 9;
  }

  cout << ans / 2 << endl;

  return 0;
}

Measured memory_bytes: 5204
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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

    int n = s.size();
    int ans = 0;
    rep(i, n/2){
        if(s[i] != s[n-i-1]) ans++;
        //cout << s[i] << ", " << s[n-i-1] << endl; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    ll x,y;
    cin >> x >> y;
    ll ans;
    // 1回目に符号を反転させる場合
    ll A = 1 + y - (-x);
    // 最後に符号を反転させる場合
    ll B = (-y) - x + 1;
    // 最初と最後に符号を反転させる場合
    ll C = 2 + (-y) - (-x);
    // 反転させない場合
    ll D = y - x;
    if(A<0) A = INF;
    if(B<0) B = INF;
    if(C<0) C = INF;
    if(D<0) D = INF;
    ans = min(min(A,B),min(C,D));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int r,d,x; cin >> r >> d >> x;
  for(int i=0; i<10; i++){
    x = r*x-d;
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100002
using namespace std;
const int p=1e9+7;
int n,k,ans=1;
vector<int>s[N];
void dfs(int x,int f,int num,int dep){
//	printf("x=%d num=%d\n",x,num);
	ans=1ll*ans*num%p;int cnt=0,t=num;
	if(dep>=1)num=k-1;
//	printf("num2=%d\n",num);
	for(int i=0;i<(int)s[x].size();i++){
		int y=s[x][i];
		if(y==f)continue;cnt++;
		dfs(y,x,num-cnt,dep+1);
	}
	num=t; 
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1,u,v;i<n;i++){
		scanf("%d%d",&u,&v);
		s[u].push_back(v);s[v].push_back(u);
	}
	dfs(1,0,k,0);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


constexpr lint mod = 1e9 + 7;
inline lint emod(lint a, lint p = mod) { return (a % p + p) % p; }
inline lint invm(lint a, lint p = mod) { a %= p; return a == 1 ? 1 : -p / a * invm(p % a) % p; }

V<lint> fact, ifact;
void init_table(int n) {
  fact.assign(n + 1, 1), ifact.assign(n + 1, 1);
  for (int i = 2; i < n + 1; ++i) fact[i] = i * fact[i - 1] % mod;
  ifact[n] = invm(fact[n]);
  for (int i = n; i > 2; --i) ifact[i - 1] = i * ifact[i] % mod;
}

lint comb(lint n, lint r) {
  if (r < 0 or r > n) return 0;
  return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint n, k; cin >> n >> k;
  if (n > k) return cout << 0 << '\n', 0;
  cout << 1 << '\n';
}


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

const ll MOD = 1e9 + 7;
const int mod = 13;
const int MAXS = 1e5;
int invf[13];
ll dp[2][13];

int main(){
    string S; cin >> S;
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < mod; j++){
            dp[i][j] = 0;
            //cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
        }
    }
    dp[1][0] = 1;

    for(int i = 0; i < mod; i++){
        invf[i*10%mod] = i; 
        //cout <<"invf[" << i * 10 % mod << "] =" << i << endl;
    }

    for(int i = 0; i < S.size(); i++){
        bool s = i % 2;
        //cout << s << endl;
        if(S[i] == '?'){
            for(int j = 0; j < mod; j++){
                int m = invf[j];
                dp[s][j] = 0;
                for(int k = 0; k < 10; k++){
                    int inv = (j - k + mod) % mod;
                    dp[s][j] += dp[!s][invf[inv]] % MOD;
                    dp[s][j] %= MOD;
                    //cout << dp[s][j] << endl;
                }
            }
        }else{
            for(int j = 0; j < 13; j++){
                int inv = (j - (S[i] - '0') + mod ) % mod; 
                
                //cout << "inv" << inv << "invf" << invf[inv] << endl;
                dp[s][j] = dp[!s][invf[inv]] % MOD;
                //cout << "dp[" << s << "][" << j << "] == "<< dp[s][j] << endl;
            }
        }
        //cout << dp[s][5] << endl;
    }
    cout << dp[(S.size()-1)%2][5] << endl;
}

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

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

  int n;
  cin >> n;
  int a = 0, b = 0;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end(), greater<int>());
  for (int i = 0; i < n; i++) {
    (i & 1) ? b += v[i] : a += v[i]; 
  }
  cout << a - b << '\n';
  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;


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

    LL a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max(a * c, max(a * d, max(b* c, b * d) ))<< endl;


    return 0;
}

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

int main () {
  int N;
  cin >> N;
  vector<int> X(N);
  rep(i, N) {
    cin >> X[i];
  }
  
  double P = 0;
  rep(i, N) {
    P += X[i];
  }
  
  P = round(P/N);
  
  int tairyoku = 0;
  rep(i, N) {
    tairyoku += pow(X[i] - P, 2);
  }
  cout << tairyoku << endl;
}

Measured memory_bytes: 256
import math

A, B, H, M = list(map(int, input().strip().split()))

theta = H * 30 + (M / 60) * 30 - M * 6
theta = theta + 360 if theta < 0 else theta
theta = theta - 360 if theta > 360 else theta
#print(theta)
X2 = A**2 + B**2 - 2 * A * B * math.cos(math.radians(theta))
X = math.sqrt(X2)
print(X)

Measured memory_bytes: 9536
#include <iostream>
#include <algorithm>
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)

using namespace std;

const int N = 1e5 + 10;
const int INF = 1e+18;

int n;
int a[N];

signed main() {
    cin >> n;
    rep(i, n) cin >> a[i];
    sort(a, a + n);

    int ans = 1;
    rep(i, n) {
        if (a[i] > INF / ans) {
            cout << "-1\n";
            return 0;
        }
        ans *= a[i];
        if (!ans) break;
    }
    if (ans > INF) cout << "-1\n";
    else cout << ans << '\n';

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<bool> vb;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

ll x,y,z;
void solve(){
 cin >> x >> y >> z;
 cout << z << " " << x << " " << y;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

bool used[333333];
int mp[333333];

int main(){

	ll n;cin >> n;
	vector<ll> v(n);
	set<ll> s;
	REP(i,n){
		cin >> v[i];
		s.insert(v[i]);
	}

	if(s.size() == 1){
		if(s.count(1)){
			ll ans = 1;
			REP(i,n){
				ans *= i+1;
				ans %= MOD;
			}
			cout << ans << endl;
		}
		else{
			cout << 0 << endl;
		}
		return 0;
	}

	deque<int> deq;
	deque<int> ldeq;
	ll now = -1,pla = 0,st = -1,ans = 1,malen = 0,nlen = 0;
	bool flag = true;
	vector<pair<pair<ll,ll>,pair<ll,ll>>> seica;
	while(1){
		if(pla == st)break;
		if(v[pla] != now){
			now = v[pla];
			deq.push_back(now);
			ldeq.push_back(nlen);
			if(deq.size() > 3)deq.pop_front();
			if(ldeq.size() > 3)ldeq.pop_front();
			if(deq.size() == 3) {
				if(flag){
					st = pla;
					flag = false;
				}
				if(used[deq[1]]){
					cout << 0 << endl;
					return 0;
				}
				seica.PB(MP(MP(deq[1],ldeq[2]),MP(deq[0],deq[2])));
				used[deq[1]] = true;
				malen = max(malen,nlen);
			}
			nlen = 1;
		}
		else{
			nlen++;
		}
		pla = (pla + 1) % n;
	}
	sort(ALL(seica));
	if(seica[0].FI.FI != 1 || malen > seica[0].FI.SE){
		cout << 0 << endl;
		return 0;
	}

	deque<pair<int,int>> p_deq;
	pla = 0;
	REP(i,n){
		while(pla - i < malen){
			while(p_deq.size() && p_deq[p_deq.size()-1].FI < v[pla%n])p_deq.pop_back();
			p_deq.push_back(MP(v[pla%n],pla));
			pla++;
		}
		while(p_deq[0].SE < i)p_deq.pop_front();
		mp[p_deq[0].FI]++;
	}

	now = 0;
	pla = 0;
	for(ll i = 1;i <= n;i++){
		pla += mp[i];
		if(now < seica.size() && seica[now].FI.FI == i){
			if(i < seica[now].SE.FI && i < seica[now].SE.SE && seica[now].FI.SE != malen){
				cout << 0 << endl;
				return 0;
			}
			if(i > seica[now].SE.FI && i > seica[now].SE.SE){
				ans *= malen - seica[now].FI.SE + 1;
				ans %= MOD;
			}
			now++;
		}
		else{
			ans *= pla;
			ans %= MOD;
		}
		pla--;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 35048
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100000

int main(void) {
    int num = get_int();
    int walk, tel;
    get_int2(&walk, &tel);
    static int arr[NUM_MAX];
    fget_array(arr, num);

    int start = arr[0];
    int i;
    int64_t ans = 0;
    for(i = 1; i < num; i++) {
        int end = arr[i];
        int power = min((int64_t)(end-start)*walk, tel);
        ans += power;
        start = end;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 512
#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;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
 
const int N = 2e6 + 6;
const int M = 1e9+7;
long double A[N];
long double dp[3003][3003];
int n , m;

long double alpha(int i , int cnt)
{
	if(i == n)
	{
		if(cnt > (n-1)/2)return (1.0);
		return 0.0;
	}	
	long double &abs = dp[i][cnt];
	if(abs != -1)return abs;
	long double a1 = 0 , a2 = 0;
	a1 = (1.0)*(1.0-A[i])*alpha(i+1,cnt);
	a2 = (1.0)*(A[i])*alpha(i+1,cnt+1);

	return abs = (a1+a2);
}

void solve()
{
	cin >> n;
	loop(i,0,n)cin >> A[i];

	loop(i,0,n)loop(j,0,n)dp[i][j] = (1.0)*(-1);

	long double ans = alpha(0,0);

	cout << ans << endl;
}			
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	
 
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 141824
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;

int n;
int a[maxn],b[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i]>>b[i];
  sort(a,a+n);
  sort(b,b+n);
  if(n&1){
    cout<<b[n>>1] - a[n>>1]+1<<endl;
  } else {
    cout<<(b[n>>1] + b[n/2-1]) - (a[n>>1] +a[n/2-1]) + 1<<endl;
  }
  return 0;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;
ll bit_kosu[61];


int main(){
    ll n;
    cin >> n;
    REP(i, n) {
        ll tmp;
        cin >> tmp;
        REP(j, 60) {
            if((tmp >> j) & 1) {
                bit_kosu[j]++;
            }
        }
    }
    ll ans = 0;
    ll modint = 1000000007;

    REP(j, 60) {
        long long  tmp = (long long)1 << j;
        //printf( "case3: %lld\n", tmp);
        tmp %= modint;
        ll sdf = bit_kosu[j] * (n - bit_kosu[j]);
        sdf %= modint;

        tmp *= sdf;
        tmp %= modint;

        ans += tmp;
        ans %= modint;

    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
L, R = map(int, input().split())
diff = R - L
D = 0
if diff >= 2018:
  print(0)
  D = 1
else:    
  ans = [(i * j)%2019 for i in range(L, R+1) for j in range(i+1, R+1)]
if  D == 0:
  print(min(ans))


Measured memory_bytes: 75408
package main
 
import (
  "fmt"
  "os"
  "bufio"
  "strconv"
)

func main() {
  scanner := bufio.NewScanner(os.Stdin)
  scanner.Scan()
  stdInput := scanner.Text()
  n, _ := strconv.Atoi(stdInput)
  
  var m bool
  for i := 1; i < 10; i++ {
    if n % i == 0 && n / i < 10 {
      m = !m
      break
    }
  }
  if m {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  int a,b;
  cin>>a>>b;
  int sum=1;
  int ans=0;
  while(sum<b){
    sum+=a-1;
    ans++;
  }
  cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

}

signed main() {
	ll n, x, y, h, cx, cy;

	cin >> n;

	vector<tuple<ll, ll, ll>> v;

	REP(i, n) {
		cin >> x >> y >> h;
		v.push_back(make_tuple(h, x, y));
	}

	sort(v.begin(), v.end(), greater<tuple<ll, ll, ll>>());

	ll ans, now;

	REP(i, 101) {
		REP(j, 101) {
			cx = i;
			cy = j;

			ans = -1;

			REP(k, n) {
				tie(h, x, y) = v[k];

				if (h != 0) {
					now = max(h + abs(x - cx) + abs(y - cy), (ll)0);
					if (ans < 0) {
						ans = now;
					}
					if (now != ans) {
						break;
					}
				}
				else {
					now = abs(x - cx) + abs(y - cy);
					if (now < ans) {
						break;
					}
				}

				if (k == n - 1) {
					cout << cx << " " << cy << " " << max(ans, (ll)1) << endl;
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 256
T =  list(input())

for i in range(len(T)) :
    if (i == 0 or i == len(T) - 1) and T[i] == '?' :
        T[i] = 'D'
    
    if T[i] == '?' :
        if T[i - 1] == 'P' :
            T[i] = 'D'
        elif T[i + 1] == 'D' or T[i + 1] == '?' :
            T[i] = 'P'
        else :
            T[i] = 'D'
            
    print(T[i], end = '')
            
    

Measured memory_bytes: 85688