akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
typedef pair<int, int> pii;

ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
} 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
} 
ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, k; cin>>n>>k;
	int sum = 0;
	while(k--){
		int sayi; cin>>sayi;
		sum += sayi;
	}
	n - sum >= 0 ? cout<<n - sum : cout<<-1;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define N 5000
typedef long long LL;
int m, d;

int main() {
    //freopen("sample.in", "r", stdin);
    cin >> m >> d;
    int ans = 0;
    for(int i = 1; i <= m; i++)
        for(int j = 1; j <= d; j++)
            if ((j % 10 >= 2) && (j / 10 % 10 >= 2) && (i == (j % 10) * (j / 10 % 10))) {
                //cout << i << " " << j << endl;
                ans++;
            }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	Scanner sc;
	
	void run() {
		sc = new Scanner(System.in);
		while (true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n==0 && m == 0) break;
			int[] taro = new int[n];
			int[] hanako = new int [m];
			int score = 0;
			for(int i=0;i<n;i++) {
				taro[i] = sc.nextInt();
				score += taro[i];
			}
			for(int i=0;i<m;i++) {
				hanako[i] = sc.nextInt();
				score -= hanako[i];
			}
			if(Math.abs(score) % 2 == 1) {
				System.out.println(-1);
				continue;
			}
			score /= 2;
			Arrays.sort(taro);
			Arrays.sort(hanako);
			int anst=-1,ansh=-1;
			int max = 201;
			for(int i=0;i<n;i++) {
				for(int j=0;j<m;j++) {
					if(taro[i] - hanako[j] == score && taro[i] + hanako[j] < max ) {
						anst = taro[i];
						ansh = hanako[j];
						max = anst + ansh;
					}
				}
			}
			if (max == 201) System.out.println(-1);
			else System.out.println(anst + " " + ansh);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
	
	
}

Measured memory_bytes: 12000
#include <cstdio>

int main()
{
	int N, Q, H, S, D;
	scanf("%d %d %d %d\n%d", &Q, &H, &S, &D, &N);
	long long int m2 = 8 * Q;
	long long int m1 = 4 * Q;
	if (m2 > 4 * H)
		m2 = 4 * H;
	if (m2 > 2 * S)
		m2 = 2 * S;
	if (m2 > D)
		m2 = D;
	if (m1 > 2 * H)
		m1 = 2 * H;
	if (m1 > S)
		m1 = S;
	long long int ans = m2 * (N / 2) + m1 * (N % 2);
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#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(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  vec l(n);
  vec r(n);
  cin >> n;
  int result = 0;
  FOR(i,0,n){
      cin >> l[i] >> r[i];
      result += r[i] - l[i] + 1;
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 65792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<int> p(n), q(n), start(n);
  for(int i = 0; i < n; i++) {
    cin >> p.at(i);
    start.at(i) = i+1;
  }
  for(int i = 0; i < n; i++) {
    cin >> q.at(i);
  }
  int a, b;
  int order = 1;
  do {
    if(start == p) {
      a = order;
    }
    if(start == q) {
      b = order;
    }
    order++;
  } while(next_permutation(start.begin(), start.end()));
  cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let n = Int(readLine()!)!
    let stations = (1..<n).map { _ in readWords { Int($0)! } }

    for i in 0..<n {
        var time = 0
        for j in i..<n-1 {
            if time < stations[j][1] {
                time = stations[j][1]
            } else if time % stations[j][2] != 0 {
                time = time + stations[j][2] - time % stations[j][2]
            }
            time += stations[j][0] 
        }
        print(time)
    }

}


main()

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    char c;
    int x,s;
    map<int,pair<int,int>> mp;
    map<int,bool> us;
    int now;
    for(int t=0;t<n;t++){
      cin >> c;
      if(c=='W'){
        cin >> x >> s;
        us[x]=true;
        now=0;
        while(1){
          auto itr=mp.lower_bound(now);
          if(itr==mp.end()){
            mp[now]={now+s,x};
            break;
          }else{
            if(now+s<=itr->first){
              mp[now]={now+s,x};
              break;
            }else{
              if(now<itr->first){
                mp[now]={itr->first,x};
                s-=itr->first-now;
              }
              if(!us[itr->second.second]){
                now=itr->first;
                if(now+s<=itr->second.first){
                  mp[now]={now+s,x};
                  break;
                }else{
                  mp[now]={itr->second.first,x};
                  s-=itr->second.first-now;
                }
              }
              now=itr->second.first;
            }
          }
          if(s==0) break;
        }
      }else if(c=='D'){
        cin >> x;
        us[x]=false;
      }else{
        cin >> x;
        auto itr=mp.upper_bound(x);
        if(itr==mp.begin()){
          cout << -1 << endl;
        }else{
          itr--;
          if(itr->second.first<=x){
            cout << -1 << endl;
          }else{
            if(us[itr->second.second]) cout << itr->second.second << endl;
            else cout << -1 << endl;
          }
        }
      }
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3544
package main

import (
	"fmt"
	"sort"
)

func main() {
	var x, n int
	fmt.Scan(&x, &n)
	if n == 0 {
		fmt.Println(x)
		return
	}
	p := make([]int, n)
	for i, _ := range p {
		fmt.Scan(&p[i])
	}

	sort.Ints(p)

	var tmp []int
	for i := -10; i < 1001; i++ {
		for j := 0; j < n; j++ {
			if i == p[j] {
				break
			}
			if j == n-1 {
				tmp = append(tmp, i)
			}
		}
	}

	ans := 100100100100
	val := 0
	for _, v := range tmp {
		dist := abs(v - x)
		if dist < ans {
			ans = dist
			val = v
		}
	}
	fmt.Println(val)
}

func abs(a int) int {
	if a < 0 {
		return a * (-1)
	}
	return a
}

Measured memory_bytes: 1864
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=0;i<n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 5005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,grup[15],dp[12][(1<<11)+1];
int cev;
char s[20][li];
vector<int> v;

inline int f(int sira,int mask){
	int cevv=inf;
	if(sira>=n){
		int at=1;
		int no=0;
		//~ int boz=0;
		flag=0;
		
		for(int j=1;j<=10;j++){
			grup[j]=0;
			//~ if((mask&(1<<j)))boz++;
		}
		for(int i=1;i<=m;i++){
			flag=0;
			at=1;
			for(int j=0;j<n;j++){
				if(s[j][i]=='1')grup[at]++;
				if((mask&(1<<j)))at++;
			}
			for(int j=1;j<=10;j++){
				//~ printf("%d %d\n",grup[j],mask);
				if(grup[j]>k){flag=1;break;}
			}
			if(flag==1){
				no++;
				for(int j=1;j<=10;j++){
					grup[j]=0;
				}
				at=1;
				for(int j=0;j<n;j++){
					if(s[j][i]=='1')grup[at]++;
					if((mask&(1<<j)))at++;
				}
				for(int j=1;j<=10;j++){
					//~ printf("%d %d\n",grup[j],mask);
					if(grup[j]>k){return inf;}
				}
			}
			
		}
		return no;
	}
	if(~dp[sira][mask])return dp[sira][mask];
	cevv=min(cevv,f(sira+1,(mask|(1<<sira)))+1);
	cevv=min(cevv,f(sira+1,mask));
	return dp[sira][mask]=cevv;
}

int main(void){
	memset(dp,-1,sizeof(dp));
	scanf("%d %d %d",&n,&m,&k);
	FOR{
		scanf(" %s",(s[i]+1));
	}
	printf("%d\n",f(0,0));
	return 0;
}



Measured memory_bytes: 384
// http://arc081.contest.atcoder.jp/tasks/arc081_a


#include <bits/stdc++.h>

using namespace std;

bool func(int i, int j){
	return i>j;
}

void printArray(int arr[], int n){
	for(int i=0;i<n;i++) cout<<arr[i]<<" ";
		cout<<endl;
}

int main(){
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	sort(arr, arr+n, func);
	long long side1=0;
	long long side2=0;
	int sides=0;
	for(int i=1;i<n;i++){
		if(arr[i]==arr[i-1]){
			sides++;
			if(sides==1) {side1=arr[i];}
			if(sides==2) {side2=arr[i];break;}
			arr[i]=0;
			// i++;
		}
	}
	cout<<side1*side2<<endl;
	return 0;
}


Measured memory_bytes: 640
n,a,b = map(int,input().split())
if a+b>n+1 or a*b<n:
  print(-1)
  exit()
ans = []
for i in range(1,a+1):
  ans.append(i*b)
if b == 1:
  x = list(range(1,n+1))
  print(*x)
  exit()
x = (n-a)//(b-1)
y = (n-a)%(b-1)
for i in range(1,b):
  for j in range(1,x+1):
    ans.append(j*b-i)
  if i <= y:
    ans.append((x+1)*b-i)
ans_true = []
for i,x in enumerate(ans):
  ans_true.append((i+1,x))
ans_true.sort(key=lambda x:x[1])
x = list(zip(*ans_true))[0]
print(*x)

Measured memory_bytes: 71752
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int ans = 0;
    for (int i = 1; i <= N; i += 2) {
      int count = 0;
      for (int j = 1; j <= i; j += 2) {
        if (i % j == 0) {
          count++;
        }
      }
      if (count == 8) {
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23764
#include<stdio.h>

int main(){
    int A,B,C;

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

    if((A==B && B!=C) ||(A!=B && B==C) ||(A==C && B !=C)){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}


Measured memory_bytes: 128
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = list(map(int,readline().split()))
B = [0]*(N+1)
for i in range(N-1):
    B[A[i]] += 1
print('\n'.join([str(n) for n in B[1:]]))

Measured memory_bytes: 34236
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e17;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)



int main() {
    ll n, x[200000], a[200000];
    
    cin >> n;
    REP(i, n){
        scanf("%lld", &x[i]);
        a[i] = x[i];
    }
    
    sort(a, a + n);
    ll c = a[(n - 1) / 2];
    
    REP(i, n){
        if(x[i] <= c){
            printf("%lld\n", a[(n - 1) / 2 + 1]);
        }
        else{
            printf("%lld\n", a[(n - 1) / 2]);
        }
    }
}

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

long long solve(long long l, int n, vector<long long> &x, vector<long long> &y) {
    long long ret = 0;
    vector<long long> cumx(n+1, 0), cumy(n+1, 0);
    for (int i = 0; i < n; i++) {
        cumx[i+1] = cumx[i] + x[i];
        cumy[i+1] = cumy[i] + y[i];
    }
    for (int i = 0; i < n; i++) {
        // x[i] で向きを変える
        long long tmp = 0;
        int remain = n-i;
        int remx = (remain+1) / 2;
        int remy = remain - remx;
        tmp += (cumx[remx+i] - cumx[i]) * 2;
        tmp += (cumy[remy]) * 2;
        if (remain & 1) tmp -= x[remx+i-1];
        else tmp -= y[remy-1];
        //cout << i << " " << tmp << " rem:" << remx << " " << remy << endl;
        ret = max(ret, tmp);
    }
    return ret;
}

int main() {
    long long l; int n; cin >> l >> n;
    vector<long long> x(n), y(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) y[i] = l - x[i];
    reverse(y.begin(), y.end());
    auto ans1 = solve(l, n, x, y);
    auto ans2 = solve(l, n, y, x);
    cout << max(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 6528
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

for i in range(N - 1, -1, -1):
    if A[i] == 0:
        print(0)
        exit()

r = 1
upper = pow(10, 18)
for i in range(N):
    r *= A[i]

    if r > upper:
        print(-1)
        exit()

print(r)


Measured memory_bytes: 21628
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first
int32_t main()
{
    fastio;
    int T,n,m,i,j,k,a,b,c;
    T=1;
    string str;
    while(T --> 0)
    {
        cin>>str;
        n=str.length();
        for(i=0;i<n/2;i++)
        {
            if(str[i]!=str[n-i-1])
                break;
        }
        if(i!= (n/2))
            cout<<"No";
        else
        {
            for(i=0;i<(n/2)/2;i++)
            {
                if(str[i]!=str[(n/2)-i-1])
                    break;
            }
            if(i!= (n/2)/2)
                cout<<"No";
            else
                cout<<"Yes";
        }
        
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define rei(n) for(int i=0;i<(int)n;i++)
#define rel(n) for(int l=0;l<(int)n;l++)
#define al(s) s.begin(),s.end()
#define INT_MAX 2147483647

struct SegTree
{
	int N;
	vector<int> Seg;
	void init(int n)
	{
		N = 1;
		while (N < n)N *= 2;
		for (int i = 0; i < N * 2; i++)
		{
			Seg.push_back(INT_MAX);
		}

	}

	void update(int k, int a)
	{
		k = k - 1 + N;
		Seg[k] = a;
		while (k > 0)
		{
			k = (k - 1) / 2;
			Seg[k] = min(Seg[2 * k + 1], Seg[2 * k + 2]);
		}
	}
	int find_min(int a, int b)
	{
		return query(a, b, 0, 0, N);
	}

	int query(int a, int b, int k, int l, int r)
	{
		if (r <= a || l >= b)return INT_MAX;
		if (l >= a&&r <= b)
		{
			return Seg[k];
		}
		else
		{
			return min(query(a, b, k * 2 + 1, l, (r + l) / 2),
				query(a, b, k * 2 + 2, (r + l) / 2, r));
		}
	}
};



int main()
{
	int q;
	cin >> q;
	rei(q)
	{
		int ans = 0;
		int c, a, n;
		cin >> c >> a >> n;
		int m = min(c, a);m = min(m, n);
		ans += m;
		c -= m;
		a -= m;
		n -= m;
		ans += max(min(c / 2, a)+(c-min(c/2,a)*2)/3, c / 3);
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int x;
int main(){
    cin >> x;
    if(x == 0) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3196
import collections as cl
N = int(input())
a_li = [int(i) for i in input().split()]
a_li2 = [i-1 for i in a_li]
a_li3 = [i+1 for i in a_li]
a_li.extend(a_li2)
a_li.extend(a_li3)
c = cl.Counter(a_li)
print(c.most_common()[0][1])

# keys = list(c.keys())
# max_sum = 0
# if (len(c) == 1) :
#     # 1種類しかない
#     print(len(a_li))
# elif (len(c) == 2) :
#     # 2種類ある
#     if (abs(int(keys[0]) - int(keys[1])) <= 2 ) :
#         # 差が2以下なら全部同じ値にできる
#         print(len(a_li))
#     else :
#         # 差が2より大きいなら多いほうの個数が最大
#         if (int(c[keys[0]]) > int(c[keys[1]])) :
#             print(c[keys[0]])
#         else :
#             print(c[keys[1]])
# else :
#     # この思想はNG。keys[k]からkeys[k+2]の差が2以下じゃないと成り立たない。
#     for k in range(len(c) -2 ) :
#         sum_v = c[keys[k]] + c[keys[k+1]] + c[keys[k+2]]
#         if (max_sum < sum_v) :
#             max_sum = sum_v
    
#     print(max_sum)





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

using namespace std;

#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-8;
const double pi=acos(-1.0);
const int K=3e5+7;
const int mod=1e9+7;

int n,vb[4*K],vc[4*K],ff[4*K],hs[K],a[K];
//vb奇数，vc偶数
void push_down(int o)
{
    if(ff[o])
    {
        swap(vb[o<<1],vc[o<<1]);
        swap(vb[o<<1|1],vc[o<<1|1]);
        ff[o<<1]^=ff[o],ff[o<<1|1]^=ff[o];
        ff[o]=0;
    }
}
void update(int o,int l,int r,int pos,int x)
{
    if(l==r)
    {
        if(pos&1) vb[o]=x,vc[o]=K;
        else vb[o]=K,vc[o]=x;
        return ;
    }
    int mid=l+r>>1;
    push_down(o);
    if(pos<=mid) update(o<<1,l,mid,pos,x);
    else update(o<<1|1,mid+1,r,pos,x);
    vb[o]=min(vb[o<<1],vb[o<<1|1]);
    vc[o]=min(vc[o<<1],vc[o<<1|1]);
}
void update2(int o,int l,int r,int nl,int nr)
{
    if(l==nl&&r==nr)
    {
        ff[o]^=1;swap(vb[o],vc[o]);
        return ;
    }
    int mid=l+r>>1;
    push_down(o);
    if(nr<=mid) update2(o<<1,l,mid,nl,nr);
    else if(nl>mid) update2(o<<1|1,mid+1,r,nl,nr);
    else update2(o<<1,l,mid,nl,mid),update2(o<<1|1,mid+1,r,mid+1,nr);
    vb[o]=min(vb[o<<1],vb[o<<1|1]);
    vc[o]=min(vc[o<<1],vc[o<<1|1]);
}
int query(int o,int l,int r,int nl,int nr)
{
    if(l==nl&&r==nr)return vb[o];
    int mid=l+r>>1;
    push_down(o);
    if(nr<=mid) return query(o<<1,l,mid,nl,nr);
    else if(nl>mid) return query(o<<1|1,mid+1,r,nl,nr);
    else return min(query(o<<1,l,mid,nl,mid),query(o<<1|1,mid+1,r,mid+1,nr));
}
struct node
{
    int l,r,pl,pr;
    node(){}
    node(int i,int j,int p,int q){l=i,r=j,pl=p,pr=q;}
    bool operator<(const node &ta)const
    {
        if(a[pl]==a[ta.pl]) return a[pr]>a[ta.pr];
        return a[pl]>a[ta.pl];
    }
};
node sc(int l,int r)
{
    int x=query(1,1,n,l,r);
    update(1,1,n,hs[x],K);
    if(hs[x]+1<=r)
        update2(1,1,n,hs[x]+1,r);
    int y=query(1,1,n,hs[x]+1,r);
    update(1,1,n,hs[y],K);
    if(hs[y]+1<=r)
        update2(1,1,n,hs[y]+1,r);
    return node(l,r,hs[x],hs[y]);
}
priority_queue<node>q;
int main(void)
{
    scanf("%d",&n);
    for(int i=1,mx=n*4;i<=mx;i++) vb[i]=vc[i]=K;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        update(1,1,n,i,a[i]);
        hs[a[i]]=i;
    }
//    q.push(node(1,2,1,2));
//    q.push(node(5,6,5,6));
//    while(q.size())
//    {
//        node tmp=q.top();
//        q.pop();
//        printf("%d %d ",a[tmp.pl],a[tmp.pr]);
//    }
    q.push(sc(1,n));
    while(q.size())
    {
        node tmp=q.top();
        q.pop();
        printf("%d %d ",a[tmp.pl],a[tmp.pr]);
        if(tmp.pl-1>tmp.l) q.push(sc(tmp.l,tmp.pl-1));
        if(tmp.pl+1<tmp.pr-1) q.push(sc(tmp.pl+1,tmp.pr-1));
        if(tmp.pr+1<tmp.r) q.push(sc(tmp.pr+1,tmp.r));
    }
    return 0;
}


Measured memory_bytes: 18164
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
fn main(){
    let n:usize = read();
    let k:usize = read();
    let mut p:Vec<usize> = (0..n).map(|_| read()).collect();
    let c:Vec<i64> = (0..n).map(|_| read()).collect();
    for i in 0..n{
        p[i] -= 1;
    }
    let mut ans = -1e18 as i64;
    for _i in 0..n{
        let mut x:usize = _i;
        let mut s:Vec<i64> = Vec::new();
        let mut total:i64 = 0;
        while(true){
            x = p[x];
            s.push(c[x]);
            total += c[x];
            if(x == _i) {
                break;
            }
        }
        let mut l:usize = s.len();
        let mut t:i64 = 0;
        for i in 0..l {
            t += s[i];
            if(i + 1 > k){
                break;
            }
            let mut now:i64 = t;
            if(total > 0){
                let mut e:i64 = (k as i64 - i as i64 - 1) / l as i64;
                now += total * e;
            }
            ans = max(ans,now);
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 2292
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int n;

int main(int argc,char const* argv[])
{
  cin >> n;
  vi a(n);
  for(int i=0;i<n;i++)
    {
      cin >> a[i];
      a[i]*=2;
    }
  sort(a.begin(),a.end());
  int tmp=a[n-1];
  if(n==2)
    {
      cout << tmp/2 << ' ' << a[0]/2 << endl;
      return 0;
    }
  auto it=*lower_bound(a.begin(),a.end(),tmp/2);
  auto it2=lower_bound(a.begin(),a.end(),tmp/2);
  if((abs(tmp-it-tmp/2)<=abs(tmp/2-a[it2-a.begin()-1])) && (abs(tmp-it-tmp/2)<=abs(tmp/2-a[it2-a.begin()+1])) )
    {
      cout << tmp/2 << ' ' << it/2 << endl;
      return 0;
    }
  else if((abs(tmp-it-tmp/2)>=abs(tmp/2-a[it2-a.begin()-1])) &&(abs(tmp/2-a[it2-a.begin()-1])<=abs(tmp/2-a[it2-a.begin()+1])) )
    {
      cout << tmp/2 << ' ' << a[it2-a.begin()-1]/2 << endl;
      return 0;
    }
  else if((abs(tmp-it-tmp/2)>=abs(tmp/2-a[it2-a.begin()+1])) &&(abs(tmp/2-a[it2-a.begin()-1])>=abs(tmp/2-a[it2-a.begin()+1])) )
    {
      cout << tmp/2 << ' ' << a[it2-a.begin()+1]/2 << endl;
      return 0;
    }
  return 0;
}
//return 0;



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
typedef long long int ll; 
typedef long double ld; 

int main()
{	
    std::ios_base::sync_with_stdio(0);
	  cin.tie(0);
	  cout.tie(0);
    
    string s;
    cin>>s;

    ll first = (s[0]-'0')*10 + (s[1]-'0');
    ll second = (s[2]-'0')*10 + (s[3]-'0');
    ll flg1 = 0;
    ll flg2 = 0;
    auto check1 = [&]() -> ll{
        if(first<=12 && first > 0)
        {
            return 1;
        }
        return 0;
    };
    auto check2 = [&]()->ll{
        if(second<=12 && second > 0)
        {
            return 1;
        }
        return 0;
    };

    flg1 = check1();
    flg2 = check2();

    if(flg1==1 || flg2==1)
    {
        if(flg1*flg2 == 1)
        {
            cout<<"AMBIGUOUS"<<endl;
        }
        else{
            if(flg1==1)
            {
                cout<<"MMYY"<<endl;
            }
            else{
                cout<<"YYMM"<<endl;
            }
        }
    }
    else{
        cout<<"NA"<<endl;
    }

}

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

string encode(string &s) {
	int i = 0;
	char ss[10];
	string ret = "";
	while (i < s.size()) {
		char c = s[i];
		int end = i;
		while (end < s.size() && s[end] == c) end++;
		sprintf(ss, "%d%c", end-i, c);
		ret += ss;
		i = end;
	}
	return ret;
}

int main() {
	int n;
	string s;
	while (cin >> n, n) {
		cin >> s;
		for (int i = 0; i < n; i++)
			s = encode(s);
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
int main(void){
  int N, W;
  std::cin >> N >> W;
  int weight[N];
  long int value[N];
  for(int i = 0; i < N; i++) std::cin >> weight[i] >> value[i]; 
  long int dp[N+1][W+1];
  for(int i = 0; i < N+1; i++){
    for(int j = 0; j < W+1; j++){
      dp[i][j] = 0;
    }
  }
  for(int i = 0; i < N; i++){
    for(int w = 0; w <= W; w++){
      if(w - weight[i] >= 0){
        dp[i+1][w] = max(dp[i][w], dp[i][w-weight[i]]+value[i]);
      }
      else{
        dp[i+1][w] = dp[i][w];
      }
    }
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 79104
n,m,k = gets.chomp.split.map &:to_i
a = gets.chomp.split.map &:to_i
b = gets.chomp.split.map &:to_i

A, B = [0], [0]
n.times do |i|
  A.push a[i] + A[-1]
end
m.times do |i|
  B.push b[i] + B[-1]
end

ans, j = 0, m

0.upto(n).each do |i|
  break if A[i] > k
  while B[j] + A[i] > k
    j -= 1
  end
  ans = [ans, i+j].max
end

puts ans


Measured memory_bytes: 49704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a , b, c, d;
  cin >> a >> b >> c >> d;
  

  
  if(a+b > c+d){
    cout << "Left"<< endl;
  }else if(a+b < c+d){
    cout << "Right" << endl;
  }else if(a+b == c+d){
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)
typedef long long ll;

using namespace std;

int main(){
	unsigned long long a,b,x,n,m;
	
	cin >> a >> b >> x;
	
	if(a % x == 0){
		n = a / x;
	}
	else{
		n = a / x + 1;
	}
	
	m = b / x;
	
	
	cout << m - n + 1<< endl;
	return 0;
}

Measured memory_bytes: 256
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
	
		int n,c,k,ans = 0;
		cin >> n >> c >> k;
		int a[n+1]={0};
		for(int i=1;i<=n;i++){
			cin >> a[i];
		}
		sort(a+1,a+n+1);
		int cur = c-1, t = a[1]+k;
		ans++;
		for(int i=2;i<=n;i++){
			if(!cur || a[i]>t){
				ans++;
				cur = c-1;
				t = a[i]+k;
			}
			else cur--;
		}
		cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string x,y;
    cin>>x>>y;
    int l=x.length();
    int ans=0;
    for(int i=0;i<l;i++)
    {
        if(x[i]!=y[i])
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3808
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;

bool isOK(vint& skills, int x){
    for(int skill : skills){
        if(skill < x){ return false;}
    }

    return true;
}


int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vint c(n);
    vector<vector<int>> a(n, vector<int>(m));
    int c_in, a_in;
    REP(i, 0, n){
        cin >> c_in;
        c[i] = c_in;
        REP(j, 0, m){
            cin >> a_in;
            a[i][j] = a_in;
        }
    }

    int ans = INF;
    for(int bits = 1; bits < (1 << n); bits++){
        vint book(m);
        vint skills(m, 0);
        int tmp = 0;
        for(int i=0; i <= n; i++){
            if(!(bits & (1 << i))){ continue;}
            book = a[i];
            for(int j=0; j<m; j++){
                skills[j] += book[j];
            }
            tmp += c[i];
        }
        if(isOK(skills, x)){
            ans = min(ans, tmp);
        }
    }

    if(ans == INF){p(-1);}
    else{
        p(ans);
    }

    return 0;
}


Measured memory_bytes: 3548
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
void fo (){fflush(stdout);}
using namespace std;
ll fact (int x ){return (x <= 1 ? 1 : 1LL * x * fact (x-1));}
vector <int> adj[9];
int n , m ;
int sol (int cur , map <int,int> mp )
{
  if (SZ(mp) == n )
  {
    return 1 ;
  }
  int ans = 0 ;
  for (auto u : adj[cur])
  {
    if (mp.find(u) == mp.end())
    {
      map <int ,int >tem = mp ;
      tem[u] = 1 ;
      ans += sol (u , tem );
    }
  }
  return ans ;
}
int main ()
{
cin >> n >> m ;
for (int i=0 ;i < m ;i++)
{
  int u , v;
  cin >> u >> v ;
  adj[u].pb(v);
  adj[v].pb(u);
}
map <int , int > mp ;
mp[1] = 1 ;
cout << sol(1,mp) <<"\n";
  cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


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

int main()
{
    char S[10];
    scanf("%s", S);

    int ans = 0;
    for (int i = 0; i < 4; i++)
    {
        if (S[i] == '+')
            ++ans;
        else
            --ans;
    }

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

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<bool> snuke(n,false);
    int d, a;
    for (int i = 0; i < k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> a;
            snuke[a-1] = true;
        }
    }
    int s = 0;
    for (int i = 0; i < n; i++) {
        if (snuke[i] == false) {
            s++;
        }
    }
    cout << s;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
using ll = long long;

int main(){
  ll h,w;
  cin>>h>>w;
  ll ans;
  if(h==1||w==1){
    ans=1;
  }
  else{
    ans=(h*w+1)/2;
  }
  cout<<ans<<endl;
  return(0);
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int n;cin>>n;
    int k;cin>>k;
    int res=1;
    REP(i,n){
        if(res<k){
            res*=2;
        }else{
            res+=k;
        }
        cerr<<res<<endl;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int N, K;
int x[101];

int main(void){

    scanf("%d%d", &N, &K);

    int ans = 0;

    for(int i = 1; i <= N; i++){
        scanf("%d", &x[i]);
        if(x[i] < K - x[i]){
            ans += 2 * x[i];
        }else{
            ans += 2 * (K - x[i]);
        }
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1684
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int maxn = 2e6 + 7;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
int a[1007];

int main(){
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int sum = 0;
	for(int i = 1;i <= k;i++)
		sum += a[i];
	cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3764
[a,b,x] = list(map(int,input().split()))

import math
S = x/a

if S > (a*b)/2:
    c = (2*S)/a - b
    out = math.degrees(math.atan((b-c)/a))
else:
    c = (2*S)/b
    out = math.degrees(math.atan(b/c))

print(out)


Measured memory_bytes: 62160
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e16;
const double EPS=1e-8;
const ll mod = 1000000007;


int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	ll can_transfer = a-b;
	cout<<c-min<ll>(can_transfer,c)<<endl;


}


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

using namespace std;

int main()
{
    long long  N,K;

    cin >> N >> K;

    int A[N];
    int total = 0;
  
  	N = N % K;

        long long tmp;
        tmp = N -K;
        if(tmp<0) tmp = -tmp;
        if(tmp < N)
        {
            N = tmp;
        }
        


    cout << N << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int m, f, r, mf;
	char g;

	while (1) {
		scanf("%d %d %d", &m, &f, &r);
		mf = m + f;

		if (m == -1 && f == -1 && r == -1) break;
		else if (m == -1 || f == -1) g = 'F';
		else if (mf >= 80) g = 'A';
		else if (mf >= 65) g = 'B';
		else if (mf >= 50 || r >= 50) g = 'C';
		else if (mf >= 30) g = 'D';
		else if (mf < 30) g = 'F';

		printf("%c\n", g);
	}

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}
int main(){
  string S;cin >> S;
  int ans,a,b,c;ans = 753;
  for(int j =0 ; j < S.size()-2;j++){
    a = ctoi(S[j]);
    b = ctoi(S[j+1]);
    c = ctoi(S[j+2]);
    ans = min(ans,abs(100*a+10*b+c-753));
   
    }
     cout << ans << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <queue>
#include <string.h>

using namespace std;

//9223372036854775807
#define LLINF (4223372036854775807)

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

bool zombie[123456] = {};
vector<vector<int>> connect;
vector<int> CantGo;

int main() {

	int N, M, K, S, P, Q;
	queue<pair<int, int>> ZombieSpread;//city,spread

	scanf("%d %d %d %d", &N, &M, &K, &S);
	scanf("%d %d", &P, &Q);

	rep(i, K) {
		int C;
		scanf("%d", &C);
		ZombieSpread.push(make_pair(C, 0));
		CantGo.push_back(C);
	}

	connect.resize(N + 1);
	rep(i, M) {
		int A, B;
		scanf("%d %d", &A, &B);
		connect[A].push_back(B);
		connect[B].push_back(A);
	}

	while (!ZombieSpread.empty()) {
		int z = ZombieSpread.front().first;
		int s = ZombieSpread.front().second;
		ZombieSpread.pop();
		if (s != S) {
			zombie[z] = true;
			for (auto c : connect[z]) {
				if (!zombie[c]) {
					ZombieSpread.push(make_pair(c, s + 1));
				}
			}
		}
		else {
			zombie[z] = true;
		}

	}

	priority_queue<pair<long long int, int>, vector<pair<long long int, int>>, greater<>> next;//cost,city
	next.push(make_pair(0, 1));
	long long int best[123456] = {};
	rep(i, 123456) best[i] = LLINF;
	best[1] = 0;
	int to = N;

	while (!next.empty()) {
		int from = next.top().second;
		if (next.top().first >= best[to]) break;
		next.pop();
		rep(i, connect[from].size()) {
			bool cant = false;
			for (int cg : CantGo) {
				if (connect[from][i] == cg) {
					cant = true;
					break;
				}
			}
			if (!cant && best[connect[from][i]] > best[from] + (zombie[connect[from][i]] ? Q : P)) {
				best[connect[from][i]] = best[from] + (zombie[connect[from][i]] ? Q : P);
				next.push(make_pair(best[connect[from][i]], connect[from][i]));
			}
		}
	}

	printf("%lld\n", best[to] - (zombie[to] ? Q : P));

	return 0;
}

Measured memory_bytes: 65512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;

import javax.swing.*;

import static java.util.Arrays.binarySearch;
import static java.util.Arrays.copyOfRange;

public class Main {

    public static void main(String[] args) throws Exception {
        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();
    }
}

class Task {

    private static int mod = 998244353;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int a = in.nextInt();
        char[] s = in.next().toCharArray();
        int r = 0, b = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] == 'R') {
                r++;
            } else {
                b++;
            }
        }
        out.println(r > b ? "Yes" : "No");
    }

}


class InputReader {

    private final BufferedReader reader;
    private StringTokenizer tokenizer;

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

    public String nextLine() {
        try {
            return reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(nextLine());
        }
        return tokenizer.nextToken();
    }

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

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

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

}

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

struct mint{
    // 自動的にmodを取ってくれるクラスです。
    ll x;
    mint(ll x = 0):x(x%mod){}
    mint& operator+=(const mint a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if(!t) return 1;
        mint b = pow(t/2);
        b *= b;
        if(t%2 == 1) b *= *this;
        return b;
    }

    mint inv() const{
        return pow(mod-2);
    }
    mint& operator/=(const mint a){
        (*this) *= a.inv();
        return *this;
    }
    mint operator/(const mint a) const{
        mint res(*this);
        return res/=a;
    }
};

int main(){
    ll n;
    cin >> n;
    mint u(10);
    mint w(8);
    mint y(9);
    mint juu = u.pow(n);
    mint kyuu =y.pow(n);
    mint hati = w.pow(n);
    mint ans = juu-hati;
    ans -= (kyuu-hati);
    ans -= (kyuu-hati);
    cout << ans.x << endl;
    
}

Measured memory_bytes: 3592
import java.util.HashMap
fun main(args: Array<String>){
    var line: String = readLine() as String
    val n = line.toInt()
    val map:HashMap<String,Int> = HashMap()
    var key:String
    for(i in 0 until n){
        key= readLine() as String
        val j:Int?= map[key]
        if(j!=null){
            map[key] = j+1
        }else{
            map[key] = 1
        }
    }
    line = readLine() as String
    val m = line.toInt()
    for(i in 0 until m){
        key= readLine() as String
        val j:Int?= map[key]
        if(j!=null){
            map[key] = j-1
        }
    }

    var max=0
    for (entry in map.entries) {
        if (max<entry.value) {
            max=entry.value
        }
    }
    print(max)
}

Measured memory_bytes: 32060
import collections
n = int(input())
a = list(map(str,input().split()))
c = collections.Counter(a)
all_answer = 0
for _,b in c.items():
	all_answer += b*(b-1)//2
for i in a:
	b = c[i]
	print(all_answer-b*(b-1)//2+(b-1)*(b-2)//2)


Measured memory_bytes: 26780
/**********************************************
* AUTHOR : Subhrangshu Pandey
* INSTITUTION : HIT, Kolkata
**********************************************/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define mod ((long long)(1e9+7))
#define PI 3.14159265358979

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a, b, h, m;
    cin>>a>>b>>h>>m;

    //c = sqrt(a^2 + b^2 + - 2ab*cos(ang))
    double angle = abs( 360.0*h/12.0 + (360.0*m/12.0)*(1/60.0) - 360.0*m/60.0);
    double cosval = cos(angle*PI/180.0)	;
    double c = sqrt( a*a + b*b - 2*a*b*cosval);
    cout.precision(13);
    cout<<c;
	return 0;
}

Measured memory_bytes: 4156
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(void) {
	int n = 0, t;
	for (int i = 0; i < 3; i++) {
		cin >> t;
		n += t;
		n *= 10;
	}
	n /= 10;
	if (n % 4) cout << "NO" << endl;
	else cout << "YES" << endl;

	return 0;
}


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

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main() {
  int N;
  cin >> N;
  vector<int> H(N);
  rep(i,N) cin >> H[i];
  int ma=0;
  int ans=0;
  rep(i,N){
    if(H[i]>=ma){
      ans++;
      ma=H[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,i,j,min=100000000;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(min>a[i])min=a[i];
  }

  
  
  for(i=0;i<min;i++){
    int f=0;
    for(j=0;j<n;j++){
      if(a[j]%(i+1)==0)f++;
    }     
    if(f==n)printf("%d\n",i+1);
  }
  
  return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = [0] * n
p = [0] * n

dic = {}
for i in range(n):
    tmp = input().split()
    s[i], p[i] = str(tmp[0]), int(tmp[1])

arr = sorted(s)
arr = list(set(arr))
arr.sort()

for i in range(len(arr)):
    x = []
    for j in range(n):
        if arr[i] == s[j]:
            x.append(p[j])
    x.sort()
    x.reverse()
    for j in range(len(x)):
        for k in range(n):
            if arr[i] == s[k] and x[j] == p[k]:
                print(k+1)


Measured memory_bytes: 3064
import numpy as np
A = []
for i in range(3):
  A.append(list(map(int,input().split())))

N = int(input())
B = []
for i in range(N):
  B.append(int(input()))

for i,a in enumerate(A):
  for j,x in enumerate(a):
    if x in B:
      A[i][j] = 0
ans = 'No'
def bingo(x):
  if sum(x) == 0:
    print('Yes')
    exit()

for i in range(3):
  if A[i][0]==A[i][1]==A[i][2]==0:ans="Yes"
  if A[0][i]==A[1][i]==A[2][i]==0:ans="Yes"
if A[0][0]==A[1][1]==A[2][2]==0:ans="Yes"
if A[2][0]==A[1][1]==A[0][2]==0:ans="Yes"

print(ans)

Measured memory_bytes: 12472
import copy

N,A,B=map(int,input().split())
h=[]
for i in range(0,N):
    H=int(input())
    h.append(H)

h.sort()

def condition(num):
    testlist=copy.copy(h)
    for i in range(0,N):
        testlist[i]-=B*num
    count=0
    for i in range(0,N):
        if testlist[i]>0:
            if testlist[i]%(A-B)!=0:
                count+=testlist[i]//(A-B)+1
            else:
                count+=testlist[i]//(A-B)
    return num>=count

start=1
end=10**15
while end-start>1:
    test=(end+start)//2
    if condition(test):
        end=test
    else:
        start=test

if condition(start):
    print(start)
else:
    print(end)


Measured memory_bytes: 129368
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
const int MAX_N=100005;
const int mod=1e9+7;
LL dp[MAX_N][4]; 
string s;
int main()
{
	dp[0][0]=1;
	cin>>s;
	s=' '+s;
	rep(i,1,s.size())
	{
		rep(j,0,4)
		{
			if(s[i]=='?')dp[i][j]=dp[i-1][j]*3;
			else dp[i][j]=dp[i-1][j];
			if(j && !(s[i]!='?' && s[i]-'A'-j+1))dp[i][j]+=dp[i-1][j-1];
			dp[i][j]%=mod;
		}
	}
	cout<<dp[s.size()-1][3]<<endl;
	return 0;
}



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

int main(){

    int n;
    double sum=0,ans=0;
    int ave;
    cin>>n;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
        sum+=x[i];
    }
    if(sum/n-(int)sum/n>=0.5) ave=(sum+n-1)/n;
    else ave=sum/n;
    
    for(int i=0;i<n;i++){
        ans+=(ave-x[i])*(ave-x[i]);
    }
    cout<<ans<<endl;



    return 0;
}

Measured memory_bytes: 256