akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef pair < int , int > T;

inline void read(int &x) {
    char ch;
    bool flag = false;
    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    x = flag ? -x : x;
}


inline void read(long long  &x) {
    char ch;
    bool flag = false;
    for (ch = getchar(); !isdigit(ch); ch = getchar())if (ch == '-') flag = true;
    for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    x = flag ? -x : x;
}

const int maxn = 3100000;
int n;
struct zy{
long long x,y;
int op;
}a[maxn];

bool cmp( zy A ,zy B){
if (A.x!=B.x)
    return A.x<B.x;
return A.y < B.y;
}


long long  d[maxn],top;

int get_num( long long x ){
int l=1;
int r=top+1;
int ans=1;
while ( l <= r )
    {
        int mid=(l+r)/2;
        if ( d[ mid ] > x )
            {
                r=mid-1;
                ans=mid;
            }
        else
            l=mid+1;
    }
return ans;
}



int doit (int st,int ed ){
for (int i=1;i<maxn;i++)
    d[i]=120000000ll;
d[1]=a[st].y; top=1;
for (int i=st+1;i<ed;i++)
    {
        if ( a[i].y < a[st].y )
            continue;
        int tmp=get_num( a[i].y);
        d[tmp]=a[i].y;
        if (tmp > top )
            top++;
    }
int tmp=get_num( a[ed].y);
return tmp;
}

int main() {
    //printf("%.17f\n",40-( 900- 891.415926535897938 )  ) ;
    //printf("%.17f\n",acos(-1)  ) ;
    read(a[0].x); read(a[0].y); read(a[1].x); read(a[1].y);
    if (a[0].x > a[1].x )
        swap( a[0] ,a[1]);
    a[0].op=-1; a[1].op=1;
    read(n);
    n++;
    for (int i = 2;i<= n;i++)
    {
        read( a[ i ].x);
        read( a[ i ].y);
        a[i].op=0;
    }
    if ( a[0].y > a[1].y )
        {
            for (int i=0;i<=n;i++)
                a[i].y=-a[i].y;
        }
    sort ( a, a+n+1 , cmp );
    int st=0,ed=0;
    for (int i=0;i<=n;i++)
        if (a[i].op==-1)
        {
            st=i;
            break;
        }
    for (int i=0;i<=n;i++)
        if (a[i].op==1)
        {
            ed=i;
            break;
        }
    int tot=doit(st,ed)-2;
    long double PI=acos(-1);
    //long double PI=3.141592653589793827l;
    long double tmp=5.0l*PI*tot*1.0l -20.0l*tot*1.0l;
    long long ans=( (long long ) trunc( abs( a[st].x -a[ed].x) ) )*100ll + ( (long long ) trunc( abs( a[st].y - a[ed].y ) ) )*100ll ;
    if ( (tot*1ll) == ( min ( a[ed].x- a[st].x ,  (long long )abs( a[ ed ].y - a[st].y) )+1ll )  )
        tmp=tmp+5.0l*PI*1.0l;
    if (  ( a[st].x == a[ed].x ) || ( a[st].y == a[ed].y ) )
        if ( tot != 0 )
            tmp=10.0l*PI*tot*1.0l -20.0l*tot*1.0l;
    long long LLtmp=(long long ) round( tmp-0.5 +1e-15 );
    long long ans_10=( (long long ) (  ans + LLtmp ) ) /10ll;
    long long k=ans-ans_10*10ll;
    cout << ans_10 ;
    tmp = 1.0l*k + tmp  ;
    cout << fixed << setprecision(25) << tmp << endl;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    map<int, int> mp;

    for (int i = 0; i < n; i++) {
        mp[a[i]]++;
        mp[a[i]+1]++;
        mp[a[i]-1]++;
    }

    int res = 0;
    for (auto x : mp) {
        res = max(res, x.second);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 5120
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

    static class DAtCoderExpress2 {
        private static int n;
        private static int m;
        private static int q;
        private static int[][] trains;
        private static int[][] ans;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            /* 1. PREPARE DATA STRUCTURE */
            n = in.nextInt();
            m = in.nextInt();
            q = in.nextInt();
            trains = new int[n + 1][n + 1]; //[l]から[r]まで走る電車の数
            ans = new int[n + 1][n + 1]; //[l]と[r]に含まれる電車の数
            for (int[] a : ans) {
                Arrays.fill(a, -1);
            }

            /* 2. INPUT */
            for (int i = 0; i < m; i++) {
                trains[in.nextInt()][in.nextInt()]++;
            }

            /* 3. OUTPUT */
            for (int i = 0; i < q; i++) {
                out.println(calc(in.nextInt(), in.nextInt()));
            }
        }

        private int calc(int l, int r) {
            if (ans[l][r] >= 0) {
                return ans[l][r];
            }
            if (r < l) {
                return ans[l][r] = 0;
            }
            if (l == r) {
                return ans[l][r] = trains[l][r];
            }
            return ans[l][r] = (calc(l, r - 1) + calc(l + 1, r) - calc(l + 1, r - 1) + trains[l][r]);
        }

    }
}



Measured memory_bytes: 158480
#include<bits/stdc++.h>
using namespace std;
int ar[25];
int main(){
	int n;cin>>n;for(int i=1;i<=n;i++)cin>>ar[i];int ans=0;
  	for(int i=2;i<n;i++)
ans+=(ar[i]!=max({ar[i-1],ar[i],ar[i+1]})&&ar[i]!=min({ar[i-1],ar[i],ar[i+1]}));
	cout<<ans;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,M;
  scanf("%d %d\n",&N,&M);
  int A[10000];
  int i;
  for(i = 0 ; i < 10000 ; i++){
    scanf("%d",&A[i]);
  }
  
  int sum;
  for(i = 0 ; i < M ; i++){
    sum = sum + A[i];
  }
  if(N-sum >= 0){
    printf("%d\n",N - sum);
  }else{
    printf("-1\n");
  }
  return 0;
}
  


Measured memory_bytes: 1716
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <iostream>
#include <algorithm>
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() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n,m;
  cin >> n >> m;
  vector<int> hs(n);
  for (auto & x : hs ) cin >> x;

  vector< priority_queue<int> > adj(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    adj[a-1].push(hs[b-1]);
    adj[b-1].push(hs[a-1]);
  }
  int count = 0;
  rep(i, n) {
    if (adj[i].empty()) {
      ++count;
      continue;
    }
    count += adj[i].top() < hs[i] ? 1 : 0;
  }
  cout << count << endl;
}

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

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

  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());

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


Measured memory_bytes: 3636
import bisect
def main():
  N = int(input())
  A = sorted(list(map(int, input().split())))
  B = sorted(list(map(int, input().split())))
  C = sorted(list(map(int, input().split())))
  b_c = [0]*N
  for i, b in enumerate(reversed(B)):
    b_c[-1-i]  = b_c[-i] +N-bisect.bisect_right(C, b)
  ans = 0
  for i in A:
    posi = bisect.bisect_right(B, i)
    if posi < N:
      ans += b_c[posi]
  print(ans)

if __name__ == "__main__":
  main()

Measured memory_bytes: 107876
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define mem0(s) memset(s,0,sizeof(s))
#define meminf(s) memset(s,0x3f,sizeof(s))
#define mp_insert(a,b,c) mp.insert(map<pair<int,int>,int>::value_type(make_pair(a,b),c))
typedef long long ll;
typedef unsigned long long ull;
const int INF=0x3f3f3f3f,max_n=200005,mod=1e9+7;
inline ll lowbit(ll x){return x&(-x);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
double r,pi=acos(-1);
int n,k;
long long sum1[max_n];
long long ans;
int main()
{
	//std::ios::sync_with_stdio(false);
	//std::cin.tie(nullptr);
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		sum1[i]=sum1[i-1]+i;
	}
	for(int i=k;i<=n+1;i++)
	{
		long long a=sum1[i-1];
		long long b;
		if(n-i>=0)
		{
			b=sum1[n]-sum1[n-i];
		}
		else
		{
			b=sum1[n];
		}
		ans=ans+(b-a+1)%mod;
		ans%=mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5140
n = int(input())
ab = []
for _ in range(n):
    a_, b_ = map(int, input().split())
    d = a_ + b_
    ab.append([a_, b_, d])
ab = sorted(ab, key=lambda x:x[2])[::-1]
print(sum([a[0] for a in ab[0::2]]) - sum([b[1] for b in ab[1::2]]))

Measured memory_bytes: 25264
n = int(input())
h = [int(v) for v in input().split()]

inf = 10 ** 20
dp = [inf] * (n)
dp[0] = 0

for i in range(n - 1):
    for j in (i + 1, i + 2):
        if j >= n:
            continue
        dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]))

print(dp[n-1])


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

#define INF INT32_MAX/2
#define N 201
#define M N*(N-1)/2
#define R 9

int n, m, r;
int rr[R];

int d[N][N];
int res;
int use[R];

void dfs( int cur, int last, int dist )
{
	if( cur == r + 1 ) {
		if( res > dist ) {
			res = dist;
		}
		return;
	}
	for( int i = 1; i <= r; i++ ) {
		if( use[i] == 0 ) {
			use[i] = 1;
			if( last < 0 ) {
				dfs( cur + 1, i, 0 );
			}
			else {
				dfs( cur + 1, i, dist + d[ rr[last] ][ rr[i] ] );
			}
			use[i] = 0;
		}
	}
}

int main()
{
	cin >> n >> m >> r;
	for( int i = 1; i <= r; i++ ) {
		cin >> rr[i];
	}
	for( int i = 1; i <= n; i++ ) {
		for( int j = 1; j <= n; j++ ) {
			if( i != j ) {
				d[i][j] = INF;
			}
		}
	}
	for( int i = 1; i <= m; i++ ) {
		int a, b, c;
		cin >> a >> b >> c;
		if( d[a][b] > c ) {
			d[a][b] = c;
			d[b][a] = c;
		}
	}

	for( int k = 1; k <= n; k++ ) {
		for( int i = 1; i <= n; i++ ) {
			for( int j = 1; j <= n; j++ ) {
				if( d[i][j] > d[i][k] + d[k][j] ) {
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}
	res = INF;
	dfs( 1, -1, 0 );
	int ans = res;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B, C, X;
  cin>>A>>B>>C>>X;
  int ans = 0;
  for(int i=0;i<=A;++i) {
    for(int j=0;j<=B;++j) {
      if(X-500*i-100*j>=0 && (X-500*i-100*j)/50<=C) ans++;
    }
  }
  cout<<ans<<endl;
}


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

int main() {
  int s, s1, s2, s3, s4;
  cin >> s;

  s1 = s / 1000;
  s2 = (s - s1 * 1000) / 100;
  s3 = (s - s1 * 1000 - s2 * 100) / 10;
  s4 = s - s1 * 1000 - s2 * 100 - s3 * 10;
 
  if (s1 == s2 && s2 == s3){
    cout << "Yes" << endl;
  }else if (s2 == s3 && s3 == s4){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

if n == 1:
    print("Yes")
elif n == 2:
    if h[0] - h[1] <= 1:
        print("Yes")
    else:
        print("No")
else:
    c = 0
    if h[0] - h[1] <= 1:
        h[0] -= 1
        for i in range(1, n-1):
            if h[i] - h[i+1] == 1 and h[i-1] < h[i]:
                h[i] -= 1
                c += 1
            elif h[i] <= h[i+1] and h[i-1] < h[i]:
                h[i] -= 1
                c += 1
            elif h[i] <= h[i+1]:
                c += 1
            else:
                break   
    if c == n-2:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 20700
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int a[5];
    int k;
    for(int &i : a) {
        cin >> i;
    }
    cin >> k;
    for(int i = 0; i < 5; i++){
        for(int j = i+1; j < 5; j++){
            if(abs(a[i]-a[j]) > k){
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
   int a,b,n,i;
   
   
   while(scanf("%d %d",&a,&b)!=EOF){
       n=a+b;
       
       for(i=0;n>0;i++)
            n/=10;
            
            printf("%d\n",i);
       }
     return(0);
}



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

int main(){
	int N;
	cin >> N;
	int cnt = 0;
	for(int i = 1; i <= N; i++){
		int a;
		cin >> a;
		if(a != i) cnt++;
	}
	
	if(cnt == 0 || cnt == 2){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	string s, t;
	
	cin >> s >> t;

	int len = s.size();

	int a[26] = {0};
	map<char, int> m;
	map<char, int> mt;
	bool ret = true;

	rep(i, len)
	{
		if (m[s[i]] == 0)
		{
			m[s[i]] = t[i] - 'a';
		}
		else
		{
			if (m[s[i]] != (t[i] - 'a'))
			{
				ret = false;
				break;
			}
		}
		if (mt[t[i]] == 0)
		{
			mt[t[i]] = s[i] - 'a';
		}
		else
		{
			if (mt[t[i]] != (s[i] - 'a'))
			{
				ret = false;
				break;
			}
		}
	}

	if (ret)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 916
import collections
a, b, k = map(int, input().split())
ans = [a, b]
for i in range(a, min(a + k, b )):
    if i not in ans:
        ans.append(i)
for i in range(b, max(b - k, a), - 1):
    if i not in ans:
        ans.append(i)
ans = collections.Counter(ans).most_common()
ans.sort()
for i in ans:
    print(i[0])


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;
ll comb(ll a, ll b);
int main()
{
    speed;
    cout << fixed << setprecision(10);
    /*start*/
    set<char> a;
    rep(i, 3)
    {
        char b;
        cin >> b;
        a.insert(b);
    }
    if (a.size() == 2)
    {
        c("Yes");
    }
    else
    {
        c("No");
    }

    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int ans = 0;
  if (s[0] == '1') ans++;
  if (s[1] == '1') ans++;
  if (s[2] == '1') ans++;
  cout << ans;
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
vector<int>ans[1005];
int main(){
	scanf("%d",&n);
	for(int i=2;i<=1000;i++){
		if(i*(i-1)/2 != n) continue;
		puts("Yes");
		int cur = 0;
		for(int j=0;j<i;j++) for(int k=j+1;k<i;k++){
			ans[j].pb(cur);
			ans[k].pb(cur);
			cur++;
		}
		printf("%d\n",i);
		rep(j,i){
			printf("%d ",ans[j].size());
			rep(k,ans[j].size()) printf("%d ",1+ans[j][k]);
			puts("");
		}
		return 0;
	}
	puts("No");
}

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

#include <atcoder/segtree>
using namespace atcoder;

int op(int a, int b) { return max(a, b); }

int e() { return -1; }

int target;

bool f(int v) { return v < target; }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  segtree<int, op, e> seg(a);
  while (q--) {
    int ti;
    cin >> ti;
    if (ti == 1) {
      int xi, vi;
      cin >> xi >> vi;
      xi--;
      seg.set(xi, vi);
    } else if (ti == 2) {
      int li, ri;
      cin >> li >> ri;
      li--;
      cout << seg.prod(li, ri) << '\n';
    } else {
      int xi;
      cin >> xi >> target;
      xi--;
      cout << seg.max_right<f>(xi) + 1 << '\n';
    }
  }
  return 0;
}

Measured memory_bytes: 6072
integer(16) N
integer(16) ans,sizeS,tmpcnt
character(10) S,tmp
integer(16)::Sint(10)
character(10),allocatable,dimension(:)::A
read*,N
allocate(A(N))
sizeS=10
do i=1,N
  read*,S
  do j=1,10
    Sint(j)=ichar(S(j:j))
  end do
  call heapsort(sizeS,Sint)
  do j=1,10
    A(i)(j:j)=char(Sint(j))
  end do
end do
call heapsortc(N,A)
ans=0;tmp="0000000000";tmpcnt=0
do i=1,N
  if(tmp==A(i))then
    tmpcnt=tmpcnt+1
  else
    ans=ans+(tmpcnt*(tmpcnt-1))/2
    tmp=A(i)
    tmpcnt=1
  endif
end do
ans=ans+(tmpcnt*(tmpcnt-1))/2
tmp=A(i)
tmpcnt=0
print"(i0)",ans
contains
subroutine heapsort(N,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  integer(16):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
subroutine heapsortc(N,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  character(10),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  character(10):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsortc
end

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define pb push_back
using namespace std;
const int N=2005;
int n,m,x,y,ans;
int de[N],fa[N],c[N];
int du[N],d[N],u[N],v[N],u2[N],v2[N];
int f[N],w[N],fp[N];
vector<int>e[N],p[N];
bool no[N];
int F(int x){
	if(x==f[x])return x;
	int y=F(f[x]);
	w[x]^=w[f[x]];
	return f[x]=y;
}
void link(int x,int y,int z){
	int fx=F(x),fy=F(y);
	f[fx]=fy;w[fx]=w[x]^w[y]^z;
}
void dfs(int x){
	de[x]=de[fa[x]]+1;
	for(int i:e[x])if(i!=fa[x])
		fa[i]=x,dfs(i);
}
bool find(int i){
	return i==10||i==73;
}
int main(){
	cin>>n>>m;
	fo(i,2,n)cin>>x>>y,e[x].pb(y),e[y].pb(x),++du[x],++du[y];
	dfs(1);
	fo(i,1,m){
		cin>>x>>y;
		u2[i]=u[i]=x,v2[i]=v[i]=y;
		p[x].pb(i);
		p[y].pb(i);
		f[i]=i;
		for(;x!=y;x=fa[x]){
			if(de[x]<de[y])swap(x,y);
			++c[x];
		}
	}
	fo(i,2,n)ans+=min(2,c[i]);
	cout<<ans<<endl;
	int r=0;
	fo(i,1,n)if(du[i]==1)d[++r]=i;
	for(int l=0;x=d[++l],l<=r&&l<=n-1;){
		if(x==4||x==713){
			int kk=0;
		}
		int las=0,nx=0;
		for(int i:e[x]){
			--du[i];
			if(du[i]>0)nx=i;
			if(du[i]==1)d[++r]=i;
		}
		for(int i:p[x])if(!no[i]){
			if(!las)las=i;else{
				int z=1;
				if(v2[i]==x)z^=1;
				if(v2[las]==x)z^=1;
//				link(i,las,z);
				f[las]=i;w[las]=z;
				if(u2[i]==x){
					u2[i]=u2[las]==x?v2[las]:u2[las];
					p[u2[i]].pb(i);
				}else{
					v2[i]=u2[las]==x?v2[las]:u2[las];
					p[v2[i]].pb(i);
				}
				if(u2[i]==v2[i])no[i]=1;
				no[las]=1;
				if(find(i)||find(las)){
					int kk=0;
				}
				las=0;
			}
		}
		if(las){
			if(find(las)){
				int kk=0;
			}
			if(u2[las]==x)u2[las]=nx;else v2[las]=nx;
			if(u2[las]!=v2[las])p[nx].pb(las);else no[las]=1;
		}
	}
	fo(i,1,m){
		F(i);
		if(w[i]&1)printf("%d %d\n",v[i],u[i]);
		else printf("%d %d\n",u[i],v[i]);
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	string S;
	cin>>S;
	cout<<S.substr(0,(int)S.length()-8)<<endl;
	return 0;
}



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

int A, B, C, D;
int memo[3010][3010];

int rec(int i, int j) {
    if (memo[i][j]!=-1) return memo[i][j];
    int res;
    if (i==A && j==B) res = 1;
    else if (i==A) return A*rec(i, j-1)%MOD;
    else if (j==B) return B*rec(i-1, j)%MOD;
    else res = ((i*rec(i, j-1)%MOD+j*rec(i-1, j)%MOD)%MOD-(i-1)*(j-1)*rec(i-1, j-1)%MOD+MOD)%MOD;
    return memo[i][j] = res;
}

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> A >> B >> C >> D;
    rep(i, C+1) rep(j, D+1) memo[i][j] = -1;
    cout << rec(C, D) << endl;
}

Measured memory_bytes: 74560
#pragma comment(linker, "/STACK:1073741824")

#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<deque>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<fstream>
#include<iterator>
#include<functional>
#include<bitset>
#include<memory>
#include<sstream>
#include<new>
#include<cassert>
#include<iomanip>

using namespace std::placeholders;

typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<bool, bool> pbb;
typedef std::pair<ld, ld> pdd;

const int inf = (int)1e9;
const ll linf = (ll) 1e18;
const ld eps = 1e-5;
const int mod = (int) 1e9 + 7;

#define it(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define mp std::make_pair
#define fst first
#define scn second
#define sgn(x) (x > 0 ? 1 : (x == 0 ? 0 : -1))

int main()
{
	std::ios_base::sync_with_stdio(false);
	int a, b;
	std::cin >> a >> b;
	std::string s;
	std::cin >> s;
	bool res = true;
	if (s.size() != a + b + 1 || s[a] != '-')
		res = false;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == '-' && i != a)
			res = false;
	}
	if (res)
		std::cout << "Yes";
	else
		std::cout << "No";
}



Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;


int main()
{
    ull h, w;
    cin >> h >> w;
    if (h > 1 && w > 1) {
        cout << (h * w + 1) / 2 << endl;
    } else {
        cout << 1 << endl;
    }

    return 0;
}


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

#define pb(a) push_back(a)

typedef long long ll;
const ll inf = 1e9+7;
const int MAX_N = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[MAX_N],fac[MAX_N];

template <class T = ll> T in(){T x;cin >> x;return x;}

inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%inf;}a=a*a%inf;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<MAX_N;i++){fac[i]=fac[i-1]*i%inf;}for(int i=0;i<MAX_N;i++){inv[i]=POW(fac[i],inf-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%inf)*inv[n-r]%inf;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

class UnionFind {
private:
	int par[MAX_N];
	int rank[MAX_N];
public:
	void init(int n);
	int find(int x);
	void unite(int x,int y);
	bool same(int x,int y);
};

void UnionFind::init(int n) {
	for (int i = 0;i < n;i++) {
		par[i] = i;
		rank[i] = 0;
	}
}

int UnionFind::find(int x) {
	if (par[x] == x) return x;
	else return par[x] = find(par[x]);
}

void UnionFind::unite(int x,int y) {
	x = find(x);
	y = find(y);
	if (rank[x] < rank[y]) par[x] = y;
	else {
		par[y] = x;
		if (rank[x] == rank[y]) rank[x]++;
	}
}

bool UnionFind::same(int x,int y) {
	x = find(x);
	y = find(y);
	return x == y;
}

UnionFind uf;

int main() {
	int a,b;cin >> a >> b;
	if (a%2*b%2) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)

typedef long long ll;

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

  ll ret = 0;
  for(ll i=0; i<n; i++){
    ret += i;
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;

int main(){
  prep();
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i=0; i<n; i++){
      cin >> arr[i];
  }
  if (k == 1){
      cout << 1;
      return 0;
  }
  bool change = false;
  int cnt = 0;
  multiset<int> stuff;
  for (int i=0; i<k; i++){
      stuff.insert(arr[i]);
  }
  vector<int> diffs;
  for (int i=1; i<n; i++){
      int val = arr[i]-arr[i-1];
      if (val > 0){
          val = 1;
      }else{
          val = 0;
      }
      diffs.push_back(val);
  }
  for (int i=1; i<diffs.size(); i++){
      diffs[i] += diffs[i-1];
  }
  bool norms[n] = {0};
  bool has = false;
  int newk = k-1;
  
  for (int i=0; i<diffs.size()-newk+1; i++){
      int val = 0;
      if (i == 0){
          val = diffs[i+newk-1];
      }else{
          val= diffs[i+newk-1]-diffs[i-1];
      }
      if (val == newk){
          norms[i] = true;
          has = true;
      }
  }
  if (has){
      cnt++;
  }
  if (!norms[0]){
      cnt++;
  }
  for (int i=1; i<n-k+1; i++){
      bool bottom = false;
      bool top = false;
      if (*(stuff.begin()) == arr[i-1]){
          bottom = true;
      }
      stuff.erase(stuff.find(arr[i-1]));
      stuff.insert(arr[i+k-1]);
      if (*(--stuff.end()) == arr[i+k-1]){
          top = true;
      }
      if (!(top && bottom) && !norms[i]){
          cnt++;
      }
      //cout << top << " " << bottom << " " << norms[i] << endl;
      
  }
  cout << cnt;
  return 0; 
}

Measured memory_bytes: 11640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace std;
using namespace __gnu_pbds; 
#define     mod            (int)1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif






 
int main()
 
{  
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif

    IOS;

    char ch;
    cin>>ch;

   cout<<( isupper(ch) ? "A" : "a"); 
  
   
}

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

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

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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

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

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

template <typename T>
vector<T> divisor(T n){
  vector<T> res, res2;
  for(T i=1; i*i<=n; i++){
    if(n%i == 0){
      res.push_back(i);
      if(i*i < n) res2.push_back(n/i);
    }
  }

  reverse(res2.begin(), res2.end());
  res.insert(res.end(), res2.begin(), res2.end());

  return res;
}


int main() {
  int N, K, A[SIZE], B[SIZE];
  int sum = 0;

  cin >> N >> K;

  for (int i=0; i<N; i++) {
    cin >> A[i];
    sum += A[i];
  }

  auto vec = divisor(sum);

  int ans = 1;

  for (auto v : vec) {
    ll sumU = 0, sumD = 0;

    for (int i=0; i<N; i++) {
      sumD += A[i] % v;
      B[i] = A[i] % v;
    }

    sort(B, B+N, greater<int>());

    ll res = sumD;

    for (int i=0; i<N; i++) {
      sumD -= B[i];
      sumU += (v - B[i]) % v;
      res = min(res, max(sumD, sumU));
    }

    if (res <= K) {
      ans = max(ans, v);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;
int main() {
	vector<int> a(10);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		for (int j = i; j < s.size(); j++) {
			if (s[j] == 'T' || s[j] == 'G' || s[j] == 'A' || s[j] == 'C')a.at(i)++;
			else break;
		}
	}
	sort(a.begin(), a.end(), greater<>());
	cout << a.at(0) << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <numeric>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	ll a, b, c, d; cin >> a >> b >> c >> d;
	ll bd = b * d;
	ll ac = a * c;
	ll bc = b * c;
	ll ad = a * d;
	ll m = bd;
	if (m <= ac) {
		m = ac;
	}
	if (m <= bc) {
		m = bc;
	}
	if (m <= ad) {
		m = ad;
	}
	cout << m << endl;
}


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

using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;
    ll ans = 0;
    bool g = (S.at(0) == '>');
    ll temp = 0;
    ll was = 0;

    for(ll i = 0; i < S.size(); i++) {
        if(S.at(i) == '>' && g) {
            temp++;
        } else if(S.at(i) == '<' && !g) {
            temp++;
        } else if(S.at(i) == '>' && !g) {
            ans += (temp - 1)*temp/2;
            was = temp;
            temp = 1;
            g = 1;
            //ans = max(was, temp);
        } else {
            ans += (temp - 1)*temp/2;
            ans += max(was, temp);
            temp = 1;
            g = 0;
        }
    }
    if(S.at(S.size() - 1) == '>') {
        ans += temp*(temp - 1)/2;
        ans += max(temp, was);
    } else {
        ans += temp*(temp + 1)/2;
    }
    cout << ans << endl;

    return 0;
}

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

int  main(){
    int A, B;
    cin >> A >> B;
    int n, ans;
    n=A;
    if(B==1){
        ans=0;
    }else{
        ans=1;
        while(n<B){
        ans++;
        n=(A-1)*ans+1;
        }
    }
     
    
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.math.BigDecimal;

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

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            int a[] = new int[M];
            int b[] = new int[M];
            int c[] = new int[2*M];
            int k=0;
            for(int i=0; i<M; i++){
                a[i] = in.nextInt();
                b[i] = in.nextInt();
                if(a[i]==1){
                    c[k] = b[i];
                    k++;
                }
                if(b[i]==N){
                    c[k] = a[i];
                    k++;
                }
            }
            Arrays.sort(c);
            for(int i=1; i<2*M; i++){
                if(c[i]==0){
                    continue;
                }
                else{
                    if(c[i]==c[i-1]){
                        out.println("POSSIBLE");
                        return;
                    }
                }
            }
            out.println("IMPOSSIBLE");
            
        }
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }
}

Measured memory_bytes: 50956
#include <stdio.h>

int main(void)
{
	int box[10];
	char str[11];
	int a, b, c;
	int x, y;
	
	while (scanf("%s", str) != EOF) {
		for (a = 0; a < 10; a++) {
			box[a] = str[a] - '0';
		}
		for (b = 0; b < 10; b++) {
			for (c = 0; c < 9 - b; c++) {
				x = box[c] + box[c + 1];
				x %= 10;
				box[c] = x;
			}
		}
		printf("%d\n", box[0]);
	}
	
	return (0);
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> A)
{
    string s;
    cin >> s;

    if (s == "AKIHABARA" || s == "KIHABARA" || s == "AKIHBARA" || s == "AKIHABRA" || s == "AKIHABAR" || s == "KIHBARA" || s == "KIHABRA" || s == "KIHABAR" || s == "AKIHBRA" || s == "AKIHBAR" || s == "AKIHABR" || s == "KIHBRA" || s == "KIHBAR" || s == "KIHABR" || s == "AKIHBR" || s == "KIHBR")
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define PI acos(-1.0)


int main() {
  int s;
  cin >> s;
  
  int A = s/1000;
  
  int B = (s/100)%10;
 
  int C = (s/10)%10;
   
  int D = s%10;
  
  char op1, op2, op3;
  
  if (A+B+C+D==7) {
  op1='+';
  op2='+';
  op3='+';
  }
  if (A+B+C-D==7) {
  op1='+';
  op2='+';
  op3='-';
  }
  if (A+B-C+D==7) {
  op1='+';
  op2='-';
  op3='+';
  }
  if (A+B-C-D==7) {
  op1='+';
  op2='-';
  op3='-';
  }
  if (A-B+C+D==7) {
  op1='-';
  op2='+';
  op3='+';
  }
  if (A-B+C-D==7) {
  op1='-';
  op2='+';
  op3='-';
  }
  if (A-B-C+D==7) {
  op1='-';
  op2='-';
  op3='+';
  }
  if (A-B-C-D==7) {
  op1='-';
  op2='-';
  op3='-';
  }
  
  cout << A << op1 << B << op2 << C << op3 << D << "=7" << endl;
  
}


Measured memory_bytes: 256
import sys
import os

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = list(map(int, sys.stdin.buffer.readline().split()))
    print('Yes' if N == M else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
const ll MAX_P=1e6+10;
ll extgcd(ll a, ll b, ll& x, ll&y){
    ll d=a;
    if(b!=0){
        d=extgcd(b, a%b, y, x);
        y-=(a/b)*x;
    }
    else {
        x=1; y=0;
    }
    return d;
}

ll mod_inverse(ll a, ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

//n!modp
ll fact[MAX_P]; //0<=n<pについてn! modpのテーブルO(p)


//n!=a p＾eとした時のa modpを求める。O(log_p n)
ll mod_fact(ll n, ll p, ll& e){
    e=0;
    if(n==0) return 1;
    
    //pの倍数の部分を計算
    ll res=mod_fact(n/p,p,e);
    e+=n/p;
    
    //(p-1)!≡-1なので(p-1)!^(n/p)はn/pの偶奇だけで計算できる
    if(n/p%2!=0) return res*(p-fact[n%p])%p;
    return res*fact[n%p]%p;
}

//nCk modpを求める。O(log_p n)
ll mod_comb(ll n, ll k, ll p){
    if(n<0||k<0||n<k) return 0;
    ll e1, e2, e3;
    ll a1=mod_fact(n,p,e1), a2=mod_fact(k,p,e2), a3=mod_fact(n-k,p,e3);
    if(e1>e2+e3) return 0;
    return a1*mod_inverse(a2*a3%p,p)%p;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin>>N;
    fact[0]=fact[1]=1;
    rep(i,2,MAX_P){
        fact[i]=fact[i-1]*i;
        fact[i]%=MOD;
    }
    ll res=0;
    ll temp=0;
    rep(i,1,N){
        if(2*i>=N){
            ll t=mod_comb(i-1, N-i-1, MOD)*fact[i]%MOD*fact[N-i-1]%MOD;
            res+=(t-temp)*i%MOD;
            res%=MOD;
            temp=t;
        }
    }
    cout <<(res+MOD)%MOD<<"\n";
}

Measured memory_bytes: 8064
class nCr():
    mod = 10 ** 9 + 7
    def __init__(self, n):
        self.n = n
        self.fa = [1] * (self.n + 1)
        self.fi = [1] * (self.n + 1)
        for i in range(1, self.n + 1):
            self.fa[i] = self.fa[i - 1] * i % mod
            self.fi[i] = pow(self.fa[i], mod - 2, mod)
    def comb(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod
mod = 10 ** 9 + 7
s = int(input())
ans = 0
c = nCr(s)
for i in range(s // 3):
    ans += c.comb(s - 3 * (i + 1) + i, i)
    ans %= mod
print(ans % mod)

Measured memory_bytes: 9188
#include <iostream>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
int n;
const int maxn=1e5+5;
const int INF=1e9;
map<int,int>p1,p2;
int m1,m2,m3,m4;
int a1,a2,a3,a4;
int a[maxn];
int main(){
	cin >> n;
	for (int i=1;i<=n;i++){
		cin >> a[i];
		if (i&1)
			p1[a[i]]++;
		else
			p2[a[i]]++;
	}
	m1=m2=0;
	for (auto i:p1){
		if (i.second>m2){
			m2=i.second;
			a2=i.first;
		}
		if (m2>m1){
			swap(m1,m2);
			swap(a1,a2);
		}
	}
	m3=m4=0;
	for (auto i:p2){
		if (i.second>m4){
			m4=i.second;
			a4=i.first;
		}
		if (m4>m3){
			swap(m3,m4);
			swap(a3,a4);
		}
	}
	int ans;
	if (a1==a3){
		ans=max(m2+m3,m1+m4);
	}else{
		ans=m1+m3;
	}
	cout << n-ans;
}






Measured memory_bytes: 5376
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

ll dp[1010][1010];

int main() {
    ll H, W;
    cin >> H >> W;
    bool a[H][W];
    REP(i, 0, H) {
        string s;
        cin >> s;
        REP(j, 0, W) {
            if (s[j] == '#') {
                a[i][j] = false;
            } else {
                a[i][j] = true;
            }
        }
    }
    REP(i, 0, 1010) {
        fill(dp[i], dp[i] + 1010, 0);
    }
    dp[0][0] = 1;
    REP(i, 0, H) {
        REP(j, 0, W) {
            if (i + 1 < H) {
                if (a[i + 1][j]) {
                    dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;
                }
            }
            if (j + 1 < W) {
                if (a[i][j + 1]) {
                    dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % mod;
                }
            }
        }
    }
    ll ans = dp[H - 1][W - 1];
    cout << ans << endl;
}


Measured memory_bytes: 9216