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


int main() {
    int N, M; cin >>N >> M;
    int A[N];
    for (int i=0; i<N;i++) cin >>A[i];
    long long int c[N+1];
    for (int i=0; i<=N;i++){
        if (i==0) c[i]=0;
        else c[i]=(c[i-1]+A[i-1]) % M;
    }
    vector <long long int> v;
    for (int i=0; i<=N;i++){
        v.push_back(c[i]);
    }
    sort (v.begin(), v.end());
    set<long long int> s;
    for (int i=0; i<=N;i++){
        s.insert(c[i]);
    }
    long long int count=0;
    for (auto itr=s.begin();itr != s.end();itr++){
        long long int t=upper_bound(v.begin(),v.end(),*itr)-lower_bound(v.begin(),v.end(),*itr);
        count+=t*(t-1)*1.0/2;
    }
    printf("%lld\n", count);
}


Measured memory_bytes: 5108
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric> 
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1e9 + 5;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
///////////////////////////////////////////////////////////////////////

const int N = 1e5 + 5;

int n, k;
vector<int> h(N);
vector<int> dp(N, INT_MAX);

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i) scanf("%d", &h[i]);
    dp[0] = 0;
    for (int i = 1; i < n; ++i) {
        for (int j = 1; j <= k; ++j) {
            if (i - j < 0) break;
            dp[i] = min(dp[i], abs(h[i - j] - h[i]) + dp[i - j]);
        }
    }

    printf("%d\n", dp[n - 1]);
}

Measured memory_bytes: 1024
//InTheNameOfGod
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define lb(i) i&(-i);
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn =300;
ll n,cnt,w;
ll a[maxn];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    while((1LL<<cnt)-1<=n)
    {
        cnt++;
    }
    cnt--;
    n-=(1LL<<cnt)-1;
    rep(i,1,cnt+1)
    {
        a[w++]=2*i;
    }
    rrep(i,cnt-1,0)
    {
        if((1LL<<i)&n)
        {
            a[w++]=2*i+1;
        }
    }
    cout<<w+100<<endl;
    rep(i,0,w)
    {
        cout<<a[i]<<' ';
    }
    rep(i,1,101)
    {
        cout<<i<<' ';
    }
    return 0;
}


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

#define MOD (1000000000+7)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define nl '\n'
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];
#define debug(x) cerr << #x << " = " << (x) << endl;

// template starts
typedef long long int ll;
#define int ll
// template ends here

void solve(){
	// code starts from here
	set<int> s;
	map<int,int> mp;
	vector<int> mod;
	int N,X, M;
	cin >> N >> X >> M;
	
	int start = 0;
	while(s.find(X) == s.end()){
		s.insert(X);
		
		mp[X] = mod.size();
	
		mod.pb(X);
		
		X = X*X;
		X %= M;
	}
	start = mp[X];
	
	int ans = 0;
	if(N <= (int)mod.size()){
		for(int i = 0; i < N; i++) ans += mod[i];
		cout << ans << endl;
		return;
	}
	
	N -= start;
	int len = (int)mod.size()-start;
	
	for(int i = 0; i < start; i++) ans += mod[i];
	
	int c1 = N/len, c2 = N%len;
	for(int i = start; i < (int)mod.size(); i++){
		ans += (c1*mod[i]);
	}
	for(int i = start; i < start+c2; i++) ans += mod[i];
	
	cout << ans << endl;
}

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

signed main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	//startTime = clock();
	
	int T;
	//cin >> T;
	T = 1;
	while(T--){
		solve();
	}
	
	//cout << getCurrentTime() << endl;
	return 0;
}


Measured memory_bytes: 9016
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
double eps=1e-6;
double PI=acos(-1);
 
P getCrossPoint(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
bool isParallel(P a,P b,P c,P d){
  return (abs(imag( (b-a)*conj(d-c) ) )<eps);
}
 
int lcm(int a,int b){
  return a/ __gcd(a,b) * b;
}
 
int n;
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
     
    double R=1.0/sqrt(3.0);
    P a=P(R,0);
    P b=P(R-0.5*sqrt(3.0),0.5);
     
    double lc=lcm(n,3);
    double ti=2.0*PI/lc;
 
    P c=a,d=b;
 
    if(lc==3){
      printf("0.433013\n");
      continue;
    }
     
    double T=1e9;
    for(int i=0;i<lc;i++){
      c*=P(cos(ti),sin(ti));
      d*=P(cos(ti),sin(ti));
      if(!isParallel(a,b,c,d)){
        P target=getCrossPoint(a,b,c,d);
        double k=min(abs(target-a),abs(target-b));
        if(k>eps)T=min(T,k);
      }
    }
    double ans=T*R*0.5;
    printf("%.8f\n",ans*lc);
  }
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef multiset<int> MS;
typedef queue<int> Q;

int main(){
    int n; cin>>n;
    V x(n),y(n);
    for(int i=0; i<n; i++) cin>>x[i]>>y[i];
    vector<vector<P>> dis(n,vector<P>(n));
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i == j) dis[i][j] = make_pair(0,0);
            else dis[i][j] = make_pair(x[j]-x[i], y[j]-y[i]);
        }
    }
    int ans = n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i != j){
                P p = dis[i][j];
                int cnt = 0;
                for(int k=0; k<n; k++){
                    for(int l=0; l<n; l++){
                        if(dis[k][l] == p) cnt++;
                    }
                }
                ans = min(ans, n-cnt);
            }
        }
    }
    OUT(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt=LINF,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rrep(i,1,n){
        a=i;
        b=n-i;
        s=to_string(a);
        rep(j,Size(s))ans+=(s[j]-'0');
        s=to_string(b);
        rep(j,Size(s))ans+=(s[j]-'0');
        cnt=min(cnt,ans);
        ans=0;
    }
    Cout(cnt);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a,b,c,v[10];
int dfs(int k,int x,int y,int z)
{
    if(k==n+1)
    {
        int ans=abs(a-x)+abs(b-y)+abs(c-z);
        if(x==0||y==0||z==0)
            return 10000;
        return ans;
    }
    int ans=min(dfs(k+1,x+v[k],y,z)+10,dfs(k+1,x,y+v[k],z)+10);
    ans=min(ans,dfs(k+1,x,y,z+v[k])+10);
    ans=min(ans,dfs(k+1,x,y,z));
    return ans;
}
int main()
{
    int i;
    scanf("%d%d%d%d",&n,&a,&b,&c);
    for(i=1;i<=n;i++)
        scanf("%d",&v[i]);
    printf("%d",dfs(1,0,0,0)-30);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define max(a,b) (a>b)?a:b
int main(void){
	int N,W,i,j;
	int *v,*w,*dp;
	scanf("%d%d",&N,&W);
	v=calloc(N,sizeof(int));
	w=calloc(N,sizeof(int));
	dp=calloc(W+1,sizeof(int));
	for(i=0;i<N;i++){scanf("%d%d",&v[i],&w[i]);}
	for(i=0;i<N;i++){
		for(j=w[i];j<=W;j++){
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	printf("%d\n",dp[W]);
	free(v);free(w);free(dp);
	return 0;
}

Measured memory_bytes: 648
k, a, b = gets.chomp.split.map(&:to_i)

if a < b && k > a
  if b - a > 1
    puts a + (b - a) * ((k - a + 1) / 2) +  ((k - a + 1) % 2)
  else
    puts k + 1
  end
else
  puts k + 1
end

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

countlist = []
count = 0

for i in range(N-1):
  if H[i] >= H[i+1]:
    count += 1
  else:
    countlist.append(count)
    count = 0
else:
  countlist.append(count)

print(max(countlist))

Measured memory_bytes: 14224
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int n;
set<int> s;
 
void check(int x){
	int m = n;
	while(m%x == 0)
		m /= x;
	if(m%x == 1)
		s.insert(x);
}

signed main() {
	IOS;
	int ans = 1;	cin >> n;
	for(int i = 2; i*i <= n; i++){
		if(n%i == 0){
			check(i);
			if(i != n/i)
				check(n/i);
		}
	}	
	n--;
	for(int i = 1; i*i <= n; i++){
		if(n%i == 0){
			s.insert(i);
			if(i != n/i)
				s.insert(n/i);
		}
	}	
	cout << s.size();
	return 0;
}

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

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

Node *root,*NIL;
set<int> S;

void print_inorder(){
	for(set<int>::iterator it=S.begin();it!=S.end();it++)
		cout<<" "<<*it;
	cout<<endl;
}

void insert(int k){
	Node *y=NIL;
	Node *x=root;
	Node *z;
	z=(Node *)malloc(sizeof(Node));//随机分配区域节省内存 
	//先进行初始化 
	z->key=k;
	z->left=NIL;
	z->right=NIL;
	
	while(x!=NIL){
		y=x;
		if(z->key<x->key){
			x=x->left;
		}	
		else{
			x=x->right;
		}
	}
	z->parent=y;
	if(y==NIL){
		root=z;
	} 
	else{
		if(z->key<y->key){
			y->left=z;
		} 
		else{
			y->right=z;
		}
	}
}

void print_preorder(Node* u){
	if(u==NIL)
		return;
	cout<<" "<<u->key;
	print_preorder(u->left);
	print_preorder(u->right);
}

int main(){
	int n;
	cin>>n;
	string com;
	int k;

	for(int i=0;i<n;i++){
		cin>>com;
		if(com=="insert"){
			cin>>k;
			S.insert(k);
			insert(k);
		}
		else if(com=="print"){
			print_inorder();
			print_preorder(root);
			cout<<endl;
		}
	} 
	
	return 0;
}


Measured memory_bytes: 49896
class Binary_Indexed_Tree_Exception(Exception):
    pass

class Binary_Indexed_Tree():
    def __init__(self,L,calc,unit,inv):
        """calcを演算とするN項のBinary Indexed Treeを作成

        calc:演算(2変数関数,群)
        unit:群calcの単位元(xe=ex=xを満たすe)
        inv:群calcの逆元(1変数関数)
        """
        self.calc=calc
        self.unit=unit
        self.inv=inv

        N=len(L)
        d=max(1,(N-1).bit_length())
        k=2**d

        X=[None]+[unit]*k

        self.num=k
        self.depth=d

        if L:
            for i in range(len(L)):
                p=i+1
                while p<=k:
                    X[p]=calc(X[p],L[i])
                    p+=p&(-p)
        self.data=X

    def index(self,k,index=1):
        """第k要素の値を出力する.

        k:数列の要素
        index:先頭の要素の番号
        """

        p=k+(1-index)
        return self.sub_array(p,p)

    def add(self,k,x,index=1,right=False):
        """第k要素にxを左から加え,更新を行う.

        k:数列の要素
        x:更新後の値
        index:先頭の要素の番号
        right:「左から」が「右から」になる
        """
        p=k+(1-index)
        while p<=self.num:
            if right==False:
                #左から
                self.data[p]=self.calc(x,self.data[p])
            else:
                #右から
                self.data[p]=self.cal(self.data[p],x)
            p+=p&(-p)

    def update(self,k,x,index=1,right=False):
        """第k要素をxに変え,更新を行う.

        k:数列の要素
        x:更新後の値
        """

        a=self.index(k,index)
        if right==False:
            #左から
            y=self.calc(x,self.inv(a))
        else:
            #右から
            y=self.calc(self.inv(a),x)

        self.add(k,y,index,right)

    def product(self,From,To,index=1):
        """第From要素から第To要素までの総和を求める.

        From:始まり
        To:終わり
        index:先頭の要素の番号
        """
        alpha=max(1,From+(1-index))
        beta=min(self.num,To+(1-index))
        return self.calc(self.inv(self.__section(alpha-1)),self.__section(beta))

    def __section(self,To):
        S=self.unit
        x=To
        while x>0:
            S=self.calc(self.data[x],S)
            x-=x&(-x)
        return S

    def all_product(self):
        return self.data[-1]

#================================================
N,Q=map(int,input().split())
A=list(map(int,input().split()))
B=Binary_Indexed_Tree(A,lambda x,y:x+y,0,lambda x:-x)

X=[]
for _ in range(Q):
    t,u,v=map(int,input().split())
    if t==0:
        B.add(u,v,0)
    else:
        X.append(B.product(u,v-1,0))
print("\n".join(map(str,X)))

Measured memory_bytes: 193788
def resolve():
    '''
    code here
    '''
    import collections
    N = int(input())
    A_list = [[int(item) for item in input().split()] for _ in range(N)]
    A_list.sort(key=lambda x:x[0])

    def is_root(node):
        root_check_que = collections.deque([node])
        foot_print = [False for _ in range(N)]

        while root_check_que:
            temp_node = root_check_que.popleft()
            foot_print[temp_node] = True
            children = A_list[temp_node][1:3]

            for child in children:
                if child >= 0 and foot_print[child] == False:
                    root_check_que.append(child)

        return all(foot_print)


    def preorder(node):
        if node == -1:
            return

        print('',node, end='')
        left = A_list[node][1]
        right = A_list[node][2]
        preorder(left)
        preorder(right)

    for i in range(N):
        if is_root(i):
            root = i
            break

    def inorder(node):
        if node == -1:
            return

        left = A_list[node][1]
        right = A_list[node][2]
        inorder(left)
        print('',node, end='')
        inorder(right)
    
    def postorder(node):
        if node == -1:
            return

        left = A_list[node][1]
        right = A_list[node][2]
        postorder(left)
        postorder(right)
        print('',node, end='')

    for i in range(N):
        if is_root(i):
            root = i
            break
    
    print('Preorder')
    preorder(root)
    print('')


    print('Inorder')
    inorder(root)
    print('')

    print('Postorder')
    postorder(root)
    print('')


if __name__ == "__main__":
    resolve()



Measured memory_bytes: 6028
#include <stdio.h>
#define swap(a,b) a^=b^=a^=b
#define M 10
#define TOP 3

int main(){

  int mt[M], i, j;

  // input 10 Mt.
  for(i = 0; i < M; i++) scanf("%d", &mt[i]);

  // bubble sort
  for(i = 0 ; i < M-1 ; i++)
    for(j = M-1 ; j>i ; j--) 
      if(mt[j] > mt[j-1])
	swap(mt[j], mt[j-1]);

  // output top 3 Mt.
  for(i = 0; i < TOP; i++) printf("%d\n", mt[i]);

  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int x,a,b;
    cin>>x>>a>>b;
    if (abs(x-a)<abs(x-b))
        cout<<"A\n";
    else
        cout<<"B\n";
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#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 MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> VI;
typedef vector<VI> VVI;

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

    VI w(N); VI v(N);
    VVI T(N,vector<long long>(W+1,0));

    REP(i,N){
        cin >> w[i] >> v[i];
    }

    FOR(k,w[0],W+1){        //初期化
        T[0][k] = v[0];
    }

    FOR(i,1,N)
    {
       REP(j,W+1)
       {
           if( j >= w[i] ){
                long long m;
                m = T[i-1][j-w[i]] + v[i];
                if (m > T[i-1][j]){
                   T[i][j] = m;
                }
                else {
                   T[i][j] = T[i-1][j];
                }
           }
           else{
               T[i][j] =  T[i-1][j];
           }
       } 
    }
    cout << T[N-1][W]<< endl;  
    /*REP(i,N){
        REP(j,W+1){
            cout << T[i][j]  << " "; 
        }
        cout << endl;
    }*/
    return 0;
}
   


Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	vector<pair<ll, ll>> p;
	for( int i = 0; i < n; ++i ){
		ll x, l; cin >> x >> l;
		p.emplace_back(x+l, x);
	}
	sort( p.begin(), p.end() );
	int now = 0;
	int cnt = 0;
	for( int i = 1; i < n; ++i ){
		if( 2*p[i].second-p[i].first < p[now].first ){
			++cnt;
		} else {
			now = i;
		}
	}
	cout << n-cnt << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int N, M; cin >> N >> M;
    int A[N];
    int sum = 0;
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }
    int cnt = 0;
    rep(i, N){
        if(A[i] * 4 * M >= sum) cnt++;
    }
    if(cnt >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>

using namespace std;

int main(void)
{
    int N, n2, i, j;
    string S;

    cin >> N;
    cin >> S;

    n2 = S.size();

    for(i=0; i<n2; i++){
        for(j=1; j<=N; j++){
            if(S[i] == 'Z'){
                S[i] = 'A';
            }
            else{
                S[i] = S[i]+1;
            }
        }
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
#include<iomanip>
#include<algorithm>
#include<unordered_map>
#include <numeric>
#include<string_view>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;
template <int MOD>
struct ModInt {
    using lint = long long;
    int val;

    // constructor
    ModInt(lint v = 0) : val(v % MOD) {
        if (val < 0) val += MOD;
    };

    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }

    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(lint n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }

    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = lint(val) * x.val % MOD;
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }

    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }

    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};

constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
void a(){
    ll N,X,T; cin >> N >> X >> T;
    cout << N/X*T+(N%X!=0?T:0) << endl;
}

void b(){
    char c='0';
    ll num = 0;
    while('0'<=c&&c<='9'){
        scanf("%c",&c);
        if(c-'0'<0) break;
        num+=c-'0';
        num%=9;
    }

    if(num==0){
        cout << "Yes"<<endl;
    }else{
        cout << "No"<<endl;
    }
}

void c(){
    ll N; cin >> N;
    auto A = v<>(N,0);
    ll _max = 0;
    ll ans = 0;
    rep(i,N){
        cin >> A[i];
        if(A[i]<_max){
            ans+=_max-A[i];
        }
        chmax(_max,A[i]);
        
    }
    cout << ans << endl;
}


void d(){

}

int main(void){
    c();
    return 0;
 }

Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int W,A,B; cin>>W>>A>>B;
  int ans=max(0LL,abs(A-B)-W);
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;

int main()
{
    int a,b;
    cin>>a>>b;
    if (a==b)
    {
       printf("Yes\n");
    }else
    {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 200100
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const ll mod = 1e9 + 7;


int main (){
    ios_base::sync_with_stdio(false);
    map<string, ll> st;

    ll n;

    cin >> n;

    for (int i=0; i<n; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        st[s]++;
    }

    ll ans = 0;

    for (auto it: st){
        if (it.ss > 1) ans += (it.ss*(it.ss-1))/2;
    }

    cout <<  ans << endl;
    return 0;
}

Measured memory_bytes: 11264
#include<iostream>
#include<vector>
#define ll long long
#define llu unsigned long long
#define pb push_back
#define f(n) for(ll i=0;i<n;i++)
#define ina for(ll i=0;i<n;i++)cin>>a[i];
#define all(v) v.begin(),v.end()
#define YES printf("YES\n")
#define NO printf("NO\n")
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
//long long bigmod/* (a^p)%m */ ( long long a, long long p, long long m ){long long res = 1;long long x = a;while ( p ){if ( p & 1 ){res = ( res * x ) % m;}x = ( x * x ) % m;p = p >> 1;}return res;}
//ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; }
//call manipulated_seive(N) and get prime in prime vector
//const long long MAX_SIZE = 1000001; vector<long long >isprime(MAX_SIZE , true); vector<long long >prime; vector<long long >SPF(MAX_SIZE); void manipulated_seive(int N) { isprime[0] = isprime[1] = false ; for (long long int i=2; i<N ; i++) { if (isprime[i]) { prime.push_back(i); SPF[i] = i; } for (long long int j=0; j < (int)prime.size() && i*prime[j] < N && prime[j] <= SPF[i]; j++) { isprime[i*prime[j]]=false; SPF[i*prime[j]] = prime[j] ; } } }
//ll phi[5000001];bool mark[5000001];void sievephi(ll n){ll i,j;for(ll i=1;i<=n;i++) phi[i]=i;mark[1]=true;for(ll i=2;i<=n;i++)if(!mark[i]){for(ll j=i;j<=n;j+=i){mark[j]=true;phi[j]=phi[j]/i*(i-1);}}}

/*speedup
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
// vule geli coilbi na dada cout << fixed << setprecision(6) << pi <<" "<<npi<<endl;
//Pattern? OEIS
// prime factorize?? think about 2





int main()
{
    string a,b;
    cin>>a>>b;

    int n = a.size()-b.size()+1;
    int ans= b.size(),k=0;
            for(int i=0;i<n;i++)
            {
                k=0;
               // string s;
               for(int j=0;j<b.size();j++)
               {
                   if(a[i+j]!=b[j])k++;
                  // s+=a[i+j];
               }
              // cout<<s<<endl;
               ans= min(ans,k);
            }

            cout<<ans<<endl;

    return 0;
}






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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	ll a, b, n;
	cin>>a>>b>>n;
	ll x = min(n, b - 1);
	cout<<(a*x)/b<<'\n';

	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

signed main(void)
{
    ll n;
    cin >> n;
    vll x(n);
    vll y(n);
    
    double dist = 0.0;
    double sum = 0.0;
    ll cnt = 0;
    
    rep(i, n) {
        cin >> x[i] >> y[i];
    }
    
    
    vll v(n);
    rep(i, n) v[i] = i;

    do {
        rep(i, n-1) {
            dist += sqrt((x[v[i]]-x[v[i+1]]) * (x[v[i]]-x[v[i+1]]) + (y[v[i]]-y[v[i+1]]) * (y[v[i]]-y[v[i+1]]));
        }
        sum += dist;
        dist = 0.0;
        cnt ++;
    } while (next_permutation(v.begin(), v.end()));
    
    printf("%.10lf", sum/cnt);
    
    
    
    
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>


using namespace std;

int main() {
	int a,b;
	cin >>a >> b;
	if((a-b)%2){
		cout << "IMPOSSIBLE" << endl;
	} else {
		cout << abs(a+b) /2 << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
int n;
const double pi=acos(-1.0);
double a[110],b[110];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lf%lf",a+i,b+i);
	for(int i=1;i<=n;i++)
	{
		vector<double>deg;
		for(int j=1;j<=n;j++)
		{
			if(i==j)continue;
			deg.push_back(atan2(b[j]-b[i],a[j]-a[i]));
		}
		double mx=0;
		sort(deg.begin(),deg.end());
		for(int j=0;j<n-2;j++)mx=max(mx,deg[j+1]-deg[j]-pi);
		mx=max(mx,deg[0]+pi*2.0-deg[n-2]-pi);
		printf("%.10lf\n",mx/2.0/pi);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, t;
  cin >> n >> t;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<int> b(n + 1);
  int mn = a[0];
  for (int i = 1; i < n; ++i) {
    b[i] = a[i] - mn;
    mn = min(mn, a[i]);
  }
  int mx = -1;
  for (int i = 1; i < n; ++i) {
    mx = max(mx, b[i]);
  }
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    ans += (mx <= b[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String ret = "";
		
		for (int i=0; i<s.length(); i++){
			if (s.substring(i, i+1).equals("1")){
				ret += "9";
			} else {
				ret += "1";
			}
		}
		System.out.println(ret);
	}
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  if(n % 2 == 0) {
    for(int i = 0; i < n / 2; i++) {
      if(s[i] != s[n / 2 + i]) {
        cout << "No";
        return 0;
      }
    }
  } else {
    cout << "No";
    return 0;
  }
  cout << "Yes";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"
#define pi              acos(-1);
#define ordered_set     tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long long ll;


int main()
{
    FastRead

    long long  n,k;

    cin>>n>>k;

    if(n%k==0 and n>=k)
        cout<<0;
    else
    {
        long long rem = n%k;

        cout<<min(abs(rem-k),rem);
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define swap(type ,a ,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(i=0;i<n;i++)
#define forR(i,s,n) for(i=s;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int main(){
    int a, b, tmp;
    cin >> a >> b;
    cout << ((tmp=a-2*b)<0?0:tmp) << endl;
}

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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	int n;
	string s, t;
	cin >> n >> s >> t;

	string res;
	rep (i, 0, n) {
		res += s[i];
		res += t[i];
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>

using namespace std;

int main(){

  long long a, b, product = 1, min;
  cin >> a >> b;

  int tmp=0;
  while(tmp==0){
    tmp = 1;
    min = std::min(a,b);
    for(int i=2; i<min+1; i++){
      if(a%i==0 && b%i==0){
        product *= i;
        a /= i; b /= i;
        tmp= 0;
        break;
      }
    }
  }
  //  cout << a <<" "<< b << " " << product << endl;
  cout << a*b*product;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	int x,y;
	cin >> x >> y;

	if (x % 2 == 0 || y % 2 == 0)
		cout << "Even" << endl;
	else
		cout << "Odd" << endl;

	return 0;
}


Measured memory_bytes: 764
n,k = (int(num) for num in input().split())
S = input()
c = S[k-1]
if c == 'A':
    c = 'a'
if c == 'B':
    c = 'b'
if c == 'C':
    c = 'c'
    
left = ''
right = ''
    
if k > 0:
    left = S[:k-1]
if k < n:
    right = S[k:]
print(left + c + right)

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

int A[102];

int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    int N;
    cin >> N;
    
    int sum = 0;
    
    for(int i=0; i<N; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    
    int ans = -1;
    double diff = 1000;
    
    for(int i=0; i<N; i++)
        if(diff > abs(A[i] - (double) sum / N))
        {
            ans = i;
            diff = abs(A[i] - (double) sum / N);
        }
    
    cout << ans << "\n";
    return 0;
}


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

class dice {
  int dice[6];
  string state;
public:
  void input() {
    for (int i=0; i<6; i++) {
      cin >> dice[i];
    }
  }
  void move() {
    cin >> state;
    for (int i=0; i<state.length(); i++) {
      switch (state[i]) {
      case 'N':
        swap(dice[0],dice[1]);
        swap(dice[1],dice[5]);
        swap(dice[5],dice[4]);
        break;
      case 'S':
        swap(dice[0], dice[4]);
        swap(dice[4], dice[5]);
        swap(dice[5], dice[1]);
        break;
      case 'E':
        swap(dice[0], dice[3]);
        swap(dice[3], dice[5]);
        swap(dice[5], dice[2]);
        break;
      case 'W':
        swap(dice[0], dice[2]);
        swap(dice[2], dice[5]);
        swap(dice[5], dice[3]);
        break;
      default:
        break;
      }
    }
  }
  void output(void) {
    cout << dice[0] << endl;
  }
};

int main() {
  dice d;
  d.input();
  d.move();
  d.output();
  return 0;
}

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

using namespace std;

int main() {
    int y , m , d;
    char a , b ,c;
    bool ok = true;
    scanf("%d%c%d%c%d" , &y,&c,&m,&a,&d);
    if(y > 2019)ok = false;
    if(m > 04)ok = false;
    if(d > 30)ok = false;
    cout<<((ok)?"Heisei":"TBD");
}

Measured memory_bytes: 256
# 解説読んでやり方理解した
from fractions import gcd
from functools import reduce


def get_gcd(numbers):
    return reduce(gcd, numbers)


def main():
    N = int(input())
    monsters = list(map(int, input().split(" ")))
    print(get_gcd(monsters))


if __name__ == '__main__':
    main()

Measured memory_bytes: 16284
s = input()
cnt = 0
chk = int(len(s) % 2)
half = int(len(s) / 2)

if chk == 0:
    str1 = s[:half]
    str2 = s[half:]
else:
    str1 = s[:half]
    str2 = s[half+1:]

for i in range(half):
    if str1[i] != str2[half-i-1]:
        cnt += 1
print(cnt)


Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
using namespace std;

int main(){
	char b[11];
	cin>>b;
	if(b[5]=='1'||b[6]>'4')cout<<"TBD";
	else cout<<"Heisei";
	return 0;
	}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;


int main() {
    str S;
    cin>>S;
    ll n=S.size();
    reverse(all(S));
    vel data(2019);
    ll ans=0,tot=0,x=1;
    rep0(i,n){
       tot+=(S[i]-'0')*x;
       tot%=2019;
       if(data[tot]==0&&tot==0){data[tot]++;}
       if((S[i]-'0')!=0){data[tot]++;}
       x*=10;
       x%=2019;
    }
    rep0(i,2019){
        ll q=data[i];
        //if(data[i]!=0){cout<<i<<" "<<data[i]<<endl;}
        ans+=q*(q-1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3744
n = int(input())
stones = list(input())
w_num = 0
r_num = 0
for i in stones:
    if i == 'W':
        w_num += 1
    else:
        r_num += 1
goal = 'R' * r_num + 'W' * w_num

index = 0
poplist = list()
for i in stones:
    if i == goal[index]:
        poplist.append(index)
    index += 1
for i in sorted(poplist, reverse=True):
    stones.pop(i)
w_num = 0
r_num = 0
for i in stones:
    if i == 'W':
        w_num += 1
    else:
        r_num += 1
print(min(w_num, r_num))


Measured memory_bytes: 20604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef double ld;
#define X first
#define Y second
#define mk make_pair
#define pb push_back
#define Rep(i, n) for(int i = 0; i < int(n); i ++)
#define Rep1(i, n) for(int i = 1; i <= int(n); i ++)
#define all(x) (x).begin(), (x).end()
const int MOD = (int) 1e9 + 7;
const ll base =  31;
void MAIN();
int main(){
    //freopen("input.txt", "r", stdin);
    ios:: sync_with_stdio(false); cin.tie(0);
    MAIN();
    return 0;
}
////////////////////////////////////////////////////////////////////////

const int N = 100032;

int n, m, k, p, ans[N];
vector <ii> G[N], Q[N];
int d[N];
ii x[N];
vector <int> in[N];
int par[N], sz[N], cur;

int Find(int u){
    if(u == par[u]) return u;
    return par[u] = Find(par[u]);
}

void Union(int u, int v){
    u = Find(u); v = Find(v);
    if(u == v) return;
    if(sz[u] >= sz[v]) swap(u, v);
    Rep(i, in[u].size()){
        int a = in[u][i];
        in[v].pb(a);
        Rep(j, Q[a].size()){
            int b = Q[a][j].X;
            if(Find(b) == v){
                ans[Q[a][j].Y] = cur;
            } else if(Find(b) == u){
                swap(Q[a][j], Q[a].back());
                j --;
                Q[a].pop_back();
            }
        }
    }
    in[u].clear();
    sz[v] += sz[u];
    par[u] = v;
}

void MAIN(){
    cin >> n >> m >> k >> p;
    while(m --){
        int u, v, c;
        cin >> u >> v >> c;
        G[u].pb(ii(v, c));
        G[v].pb(ii(u, c));
    }
    priority_queue <ii> q;
    memset(d, 0x3f, sizeof d);
    while(k --){
        int u;
        cin >> u;
        d[u] = 0;
        q.push(ii(d[u], u));
    }
    while(!q.empty()){
        int u = q.top().Y, r = -q.top().X;
        q.pop();
        if(d[u] != r) continue;
        Rep(i, G[u].size()){
            int v = G[u][i].X, c = G[u][i].Y;
            if(d[v] > d[u] + c){
                d[v] = d[u] + c;
                q.push(ii(-d[v], v));
            }
        }
    }
    for(int i = 1; i <= n; i ++){
        x[i] = ii(-d[i], i);
        par[i] = i;
        sz[i] = 1;
        in[i].pb(i);
    }
    Rep(i, p){
        int s, t;
        cin >> s >> t;
        if(s == t) ans[i] = d[s];
        else {
            Q[s].pb(ii(t, i));
            Q[t].pb(ii(s, i));
        }
    }
    sort(x + 1, x + n + 1);
    memset(ans, 0xff, sizeof ans);
    for(int i = 1; i <= n; i ++){
        cur = -x[i].X;
        int u = x[i].Y;
        Rep(i, G[u].size()){
            int v = G[u][i].X;
            if(d[v] < d[u]) continue;
            Union(u, v);
        }
    }
    Rep(i, p) cout << ans[i] << "\n";
}

Measured memory_bytes: 26152
#include<iostream>

using namespace std;


int main(){

    int N;
    int M;
    int L;
    int R;

    int L_cmn=0;
    int R_cmn=0;

    cin >> N>>M;
    R_cmn=N;

    for(int i=0;i<M;i++){
        cin>>L>>R;
        if(L_cmn<L)L_cmn=L;
        if(R_cmn>R)R_cmn=R;
    }

    if(L_cmn>R_cmn){
        cout<<"0"<<endl;
        return 0;
    }

    cout<<(R_cmn-L_cmn)+1<<endl;

    return 0;

}

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

#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;

namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1) ans = mul(ans, x);
        return ans;
    }
};  // namespace modular
using namespace modular;

namespace Base {
    template <typename Tp>
    inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-') y = -1;
            c = getchar();
        }
        if (c == EOF) return 0;
        while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp>
    inline void read(Tp &x) {
        x = input<Tp>();
    }
    template <typename Tp>
    inline void chmax(Tp &x, Tp y) {
        x < y ? x = y : 0;
    }
    template <typename Tp>
    inline void chmin(Tp &x, Tp y) {
        x > y ? x = y : 0;
    }
};  // namespace Base
using namespace Base;
/*----------------------------------------------------------------------------*/

#define MAX_N 5007

int N;
int head[MAX_N], to[MAX_N << 1], nxt[MAX_N << 1], cap;
int f[MAX_N][MAX_N], g[MAX_N];
int sz[MAX_N];

void addE(int u, int v) {
    nxt[++cap] = head[u];
    head[u] = cap;
    to[cap] = v;
}

int tmp[MAX_N];
void dfs(int x, int las = 0) {
    sz[x] = f[x][1] = 1;
    for (int i = head[x]; i; i = nxt[i])
        if (to[i] != las) {
            dfs(to[i], x);
            rep(j, 0, sz[x]) {
                rep(k, 0, sz[to[i]]) {
                    inc(tmp[j + k], mul(f[x][j], f[to[i]][k]));
                }
            }
            sz[x] += sz[to[i]];
            rep(j, 0, sz[x]) f[x][j] = tmp[j], tmp[j] = 0;
        }
    f[x][0] = 0;
    rep(i, 1, sz[x]) inc(f[x][0], mul(MOD - 1, mul(f[x][i], g[i])));
}

int main() {
#ifdef LOCAL
    FIN("in");
#endif
    read(N);
    if (N & 1) return puts("0"), 0;
    int u, v;
    Lep(i, N) {
        read(u), read(v);
        addE(u, v);
        addE(v, u);
    }
    g[2] = 1;
    for (int i = 4; i <= N; i += 2) g[i] = mul(g[i - 2], i - 1);
    dfs(1);
    printf("%d\n", MOD - f[1][0]);
    return 0;
}


Measured memory_bytes: 97152
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(30) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
lli nCr(lli n, lli r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
}
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W, sum=0,num=0,flag=0;string S,T;
  cin >> X >> Y;
  if((X+Y)%3!=0/*||abs(X-Y)>3*/)Out(0);
  else{
    A=(X+Y)/3;
    X-=A;
    Y-=A;
    Z=X+Y;
    COMinit();
    Out(nCr(Z,Y));
  }
}

Measured memory_bytes: 119808
# coding: utf-8
def main():
    N = int(input())
    s_i = []
    for _ in range(N):
        s_i.append(input())

    count = 0
    tail_a = 0
    top_b = 0
    both_a_b = 0
    for s in s_i:
        count += s.count("AB")

        if s[-1] == "A":
            if s[0] == "B":
                both_a_b += 1
            else:
                tail_a += 1
        elif s[0] == "B":
            top_b += 1

    #print(count)
    #print(tail_a, top_b, both_a_b)

    if both_a_b > 0:
        count += (both_a_b - 1)
        if tail_a > 0:
            count += 1
            tail_a -= 1
        if top_b > 0:
            count += 1
            top_b -= 1

    if min(tail_a, top_b) > 0:
        count += min(tail_a, top_b)

    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3700
s = str(input())
c1 = 0
c2 = 0
x = 1
def hen(n):
  if n == 1:
    return 0
  else:
    return 1
for i in range(len(s)):
  si = int(s[i])
  if si == x:
    c1 += 1
  else:
    c2 += 1
  x = hen(x)
print(min(c1,c2))

Measured memory_bytes: 3316
N = int(input())
A = [int(i) for i in input().split()]

ans = 0
for left in range(0, 2801, 400):
    ans += 1 if [a for a in A if left <= a <= left + 399] else 0

ans1 = ans + len([a for a in A if a >= 3200])
if ans == 0:
    print(1, ans1)
else:
    print(ans, ans1)

Measured memory_bytes: 38256
open System

let n, k =
    let l = Console.ReadLine().Split(' ')
    let n = l.[0] |> int
    let k = l.[1] |> Int64.Parse
    n, k

let a =
    Console.ReadLine().Split(' ')
    |> Array.map (fun x -> int(x) - 1)

let ans =
    let loopOrigin, path =
        let mutable towns = Set<int> []

        let rec search (path: int list) =
            let tail =
                match path with
                | tail :: _ -> tail
                | _ -> -1
            let next = a.[tail]

            if towns.Contains next then
                let path = path |> List.rev
                let loopOrigin =
                    path |> List.findIndex (fun t -> t = next)
                loopOrigin, path
            else
                towns <- towns.Add next
                search (next :: path)

        search [0]

    let freq = int64 ((List.length path) - loopOrigin)

    if k < int64(loopOrigin) then
        path.[int (k)] + 1
    else
        let idx = loopOrigin + int ((k - int64 loopOrigin) % freq)
        path.[idx] + 1

ans |> Console.WriteLine


Measured memory_bytes: 73504