akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static int lowerBound(int[] array, int value) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int middle = (right + left) / 2;
            if (array[middle] >= value) {
                right = middle;
            } else {
                left = middle;
            }
        }
        return right;
    }

    public static int upperBound(int[] array, int value) {
        int left = -1;
        int right = array.length;
        while (right - left > 1) {
            int middle = (right + left) / 2;
            if (array[middle] > value) {
                right = middle;
            } else {
                left = middle;
            }
        }
        return right;
    }

    int count(int[] array, int i, int j) {
        int lower = array[j] - array[i];
        int upper = array[j] + array[i] - 1;

        int lowerIdx = Math.max(lowerBound(array, lower), j);
        int upperIdx = upperBound(array, upper);
//        debug(lower, upper, lowerIdx, upperIdx);
        int count = upperIdx - lowerIdx - 1;
//        debug(count);
        return count;
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        Arrays.sort(arr);
//        debug(arr);
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                count += count(arr, i, j);
            }
        }
        System.out.println(count);
    }


    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 25664
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string N;
  cin >> N;
  if( N[5] - '0' == 0 && N[6] - '0' < 5) {
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[]
for _ in range(m):
    s,c=map(int,input().split())
    a.append([s,c])

ans=-1
if n==1:
    for i in range(10):
        x=str(i)
        c=0
        for j in range(m):
            if x[a[j][0]-1] == str(a[j][1]):
                c+=1          
        if c==m:
            ans=i
            break
else:
    for i in range(10**(n-1),10**n):
        x=str(i)
        c=0
        for j in range(m):
            if x[a[j][0]-1] == str(a[j][1]):
                c+=1          
        if c==m:
            ans=i
            break
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
using ll=long long; 
 
void solve(){
	string s,t;
	cin>>s>>t;
	int n=s.size();
	for(int i=0; i<n; i++){
		char c=s[0];
		s=s.substr(1,n-1)+c;
		if(s==t){
			cout<<"Yes"<<endl;
			return;
		}
	}
	cout<<"No"<<endl;
}
 
signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
//
//  main.cpp
//  backToProblemSolving
//
//  Created by Khaled Abdelfattah on 6/27/17.
//  Copyright © 2017 Khaled Abdelfattah. All rights reserved.
//

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define MAX 1000000000
#define BASE1 23
#define BASE2 31
#define MOD1 1000000007
#define MOD2 217645177
#define eps 1e-6

int main() {
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    int arr[105 * 105];
    for (int i = 0; i < n; i ++)
        cin >> arr[i];
    int idx = 1, flag = arr[idx - 1];
    int grid[105][105];
    for (int i = 0; i < h; i += 2) {
        for (int j = 0; j < w; j ++) {
            grid[i][j] = idx;
            flag --;
            if (!flag) {
                idx ++;
                if (idx == n + 1)
                    break;
                flag = arr[idx - 1];
            }
        }
        if (i + 1 == h)
            break;
        for (int j = w - 1; j >= 0; j --) {
            grid[i + 1][j] = idx;
            flag --;
            if (!flag) {
                idx ++;
                if (idx == n + 1)
                    break;
                flag = arr[idx - 1];
            }
        }
    }
    for (int i = 0; i < h; i ++) {
        for (int j = 0; j < w; j ++)
            cout << grid[i][j] << " ";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main()
{
  int x, n;
  cin >> x >> n;
  
  int *ar = new int[n];
  for (int i=0; i<n; ++i){
    cin >> ar[i];
  }

  for (int i=0; i<n+1; ++i){
    bool find = false;
    int check = x - i;
	for (int j=0; j<n; ++j){
    	if (ar[j] == check){
          find = true; break;
        }
  	}
    if (!find){
	    cout << check << endl;
          return 0;
    }
    if (i==0) continue;
    check = x + i;
     find = false;
	for (int j=0; j<n; ++j){
    	if (ar[j] == check){
          find = true; break;
        }
  	}
    if (!find){
	    cout << check << endl;
          return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3192
using System;
public class Program
{
    public static void Main()
    {
        int m, h;
        while (true)
        {
            string str = Console.ReadLine();
            if (str == "-")
            {
                break;
            }
            m = int.Parse(Console.ReadLine());
            for (int i = 0; i < m; i++)
            {
                h = int.Parse(Console.ReadLine());
                str += str.Substring(0, h);
                str = str.Remove(0, h);
            }
            Console.WriteLine(str);
        }
    }
}



Measured memory_bytes: 15960
/* [Template].cpp 
Example code to use when starting new code. This particular problem was problem 
977A_Wrong_Subtraction from CodeForces

Compile: g++  -o C_Peaks.exe C_Peaks.cpp 
Execute: ./C_Peaks
*/ 

#include <cstdio>
#include <iostream>
#include <cmath> 
#include <limits> 
#include <iomanip>
#include <cstring> 
#include <bits/stdc++.h>
#include <string>  
using namespace std;

int main() { 	
	int N, M, H[100000]; 
	int A_i, B_i; 
	vector<int> graph_adj_list[100000]; // Representation of graph as adjacency 
	
	// Input 
	cin >> N >> M; 
	for(int i = 0; i < N; i++) {
		cin >> H[i]; 
	} 
	for(int i = 0; i < M; i++) {
		cin >> A_i >> B_i; 
		A_i--; B_i--;
		graph_adj_list[A_i].push_back(B_i); 
		graph_adj_list[B_i].push_back(A_i); 
	}
	
	// Traverse list
	int num_good_obs = 0; 
	bool is_good_obs; 
	for(int i = 0; i < N; i++) {
		is_good_obs = true; 
		for(int j = 0; j < graph_adj_list[i].size(); j++) {
			if(H[i] <= H[graph_adj_list[i].at(j)]) {
				is_good_obs = false; 
			}
		}
		if(is_good_obs) {
			num_good_obs++; 
		}
	}
	
	cout << num_good_obs << endl; 
	
	return 0; 
} 


Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.length();
  int m = t.length();
  VEC<string> ans;
  REP(i, 0, n) {
    bool ok = 1;
    string tmp = s;
    REP(j, 0, m) {
      if (s[i + j] != '?' && s[i + j] != t[j]) ok = 0;
      // DUMP(i,j,ok,s[i+j],t[j]);
    }
    if (ok) {
      //DUMP(i, tmp);
      REP(j, 0, m) { tmp[i + j] = t[j]; }
      //DUMP(i, tmp);
      REP(j, 0, n) {
        if (tmp[j] == '?') tmp[j] = 'a';
      }
      //DUMP(i, tmp);
      ans.push_back(tmp);
    }
  }
  if (ans.size() > 0) {
    sort(ALL(ans));
    cout << ans[0] << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N,K =  list(map(int,input().split(" ")))
co = 1/2 * (N-2)*(N-1)
co = int(co)
if K > co:
    print(-1)
    exit()
edges = []
diff = co - K
for i in range(2,N+1):
    edges.append((1,i))

co = 0
#diffに達するまで結ぶ
flag = False
for i in range(2,N+1):
    for j in range(i+1,N+1):
        if co == diff:
            flag = True
            break
        edges.append((i,j))
        co += 1
    if flag:
        break

M = len(edges)
print(M)
for edge in edges:
    a,b = edge
    print(a,b)

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

int main(){
	int n;
	cin >> n;
	vector<int> ns(n);
	rep(i, n) cin >> ns.at(i);
	sort(ns.begin(), ns.end());
	cout << ns.at(n/2)-ns.at(n/2-1) << endl;
}

Measured memory_bytes: 640
def croad():
    n,k = map(int,input().split())
    x = list(map(int,input().split()))
    y = []
    for i in range(n-1):
        y.append(x[i+1]-x[i])
    y.sort()
    y.reverse()
    while k>1 and len(y)>0:
        y.pop(0)
        k -= 1
    print(sum(y))

a = int(input())
for i in range(a):
    croad()
	


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

int main() {
    int N,M;
    cin >> N >> M;
    vector<int> A;
    rep(i,N) A.emplace_back(i);
    bool V[8][8]={};
    int a,b;
    rep(i,M){
        cin >> a >> b;
        a--,b--;
        V[a][b] = true;
        V[b][a] = true;
    }
    int res = 0;
    do {
        bool flag = true;
        for(int i=1;i<N;i++){
            if(!V[A[i]][A[i-1]]){
                flag = false;
                break;
            } 
        }
        if(flag) res++; 
    } while (std::next_permutation(A.begin()+1, A.end()));
    cout << res << endl;
 
    return 0;
}

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

string s;

main(){
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    string div[4] = {"maerd","remaerd","esare","resare"};

    bool can = true;
    for (int i =0; i < s.size();){
        bool can2 = false;
        for (int j = 0;j < 4;j++){
            string d = div[j];
            if (s.substr(i,d.size()) == d){
                can2 = true;
                i += d.size();
            }
        }
        if (!can2){
            can = false;
            break;
        }
    }

    if (can){
       cout << "YES" << endl;
    } else {
       cout << "NO" << endl;
    }  
  
    return 0;
} 

Measured memory_bytes: 512
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var P = one[1];
  var list = nextIntArray();
  var isOdd = false;
  for(var i = 0; i < N; i++){
    if(list[i] % 2 == 1){
      isOdd = true;
      break;
    }
  }
  if(isOdd){
    myout(originPow(2, N - 1, -1));
  }else{
    if(P == 0){
      myout(originPow(2, N, -1));
    }else{
      myout(0);
    }
  }
}
function originPow(x, n, m) {
        var ans = 1;
        while (n > 0) {
                if ((n & 1) == 1){
                  ans = ans * x;
                  if(m != -1){
                    ans %= m;
                  }
                }
                x = x * x;
                if(m != -1){
                  x %= m;
                }
                n >>= 1;
        }
        return ans;
}

Measured memory_bytes: 30984
#include <bits/stdc++.h>
using namespace std; 
const int N = 300010;
typedef long long ll; 
const ll LINF = 1e16; 
int n,m;
ll t[N],sum[N];
ll f[N],g[N],*dp;
int st[N],top;
int read()
{
	int x = 0, w = 1; char c = getchar(); 
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); 
	return x * w; 
}
double X(int j) { return j; }
double Y(int j) { return dp[j] + ((ll)j * j - j) / 2 + sum[j]; }
double slope(int i,int j) { return (Y(i) - Y(j)) / (X(i) - X(j)); }
ll calc(int i,int j) { return dp[j] + ((ll)(i - j + 1) * (i - j)) / 2 - (sum[i] - sum[j]); }
void DP()
{
	for(int i = 1;i <= n;i++) sum[i] = sum[i - 1] + t[i];
	st[top = 1] = 0;
	for(int i = 1;i <= n;i++)
	{
		while(top > 1 && calc(i,st[top]) <= calc(i,st[top - 1])) top--; 
		dp[i] = max(calc(i,st[top]),dp[i - 1]); 
		while(top > 1 && slope(st[top - 1],i) >= slope(st[top],st[top - 1])) top--;
		st[++top] = i;
	}
}

double X1(int j) { return j; }
double Y1(int j) { return f[j] + sum[j] + ((ll)j * j - j) / 2; }
double slope1(int i,int j) { return (Y1(i) - Y1(j)) / (X1(i) - X1(j)); }
ll calc1(int i,int j)
{ return g[i + 1] + ((ll)(i - j) * (i - j + 1)) / 2 - (sum[i] - sum[j]) + f[j]; }

double X2(int j) { return j; }
double Y2(int j) { return g[j + 1] + ((ll)j * j + j) / 2 - sum[j]; }
double slope2(int i,int j) { return (Y2(i) - Y2(j)) / (X2(i) - X2(j)); }
ll calc2(int i,int j)
{ return f[i] + ((ll)(j - i) * (j - i + 1)) / 2 - (sum[j] - sum[i]) + g[j + 1]; }

ll h[N];
void solve(int l,int r)
{
	if(l == r) { h[l] = 1 - t[l];return; }
	int mid = l + r >> 1;solve(l,mid),solve(mid + 1,r);
	top = 0;
	for(int i = l - 1;i < mid;i++)
	{
		while(top > 1 && slope1(i,st[top - 1]) >= slope1(st[top],st[top - 1])) top--;
		st[++top] = i;
	}int head = 1;ll maxx = -LINF;
	for(int i = r;i > mid;i--)
	{
		while(head < top && calc1(i,st[head]) <= calc1(i,st[head + 1])) head++;
		maxx = max(maxx,calc1(i,st[head]));
		h[i] = max(h[i],maxx);
	}top = 0;
	for(int i = mid + 1;i <= r;i++)
	{
		while(top > 1 && slope2(i,st[top - 1]) >= slope2(st[top],st[top - 1])) top--;
		st[++top] = i;
	}maxx = -LINF;
	for(int i = l - 1;i < mid;i++)
	{
		while(top > 1 && calc2(i,st[top]) <= calc2(i,st[top - 1])) top--;
		maxx = max(maxx,calc2(i,st[top]));
		h[i + 1] = max(h[i + 1],maxx);
	}
}
int main()
{
	n = read();for(int i = 1;i <= n;i++) t[i] = read();
	dp = f,DP();
	reverse(t + 1,t + 1 + n),dp = g,DP();
	reverse(t + 1,t + 1 + n),reverse(g + 1,g + 1 + n); 
	for(int i = 1;i <= n;i++) sum[i] = sum[i - 1] + t[i];
	solve(1,n);m = read();
	while(m--)
	{
		int x = read(), y = read();
		printf("%lld\n", max(f[x - 1] + g[x + 1],h[x] + t[x] - y));
	}
	return 0;
}

Measured memory_bytes: 15468
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>

#define ll long long

using namespace std;

int main(void) {
	ll N, H;
	cin >> N >> H;
	vector<ll> a(N), b(N);
	for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
	sort(a.begin(), a.end(), greater<ll>());
	sort(b.begin(), b.end(), greater<ll>());

	ll ans;
	for (ans = 0; ans < N && H > 0 && a[0] <= b[ans]; ans++) H -= b[ans];
	if (H > 0) {
		if (H % a[0] == 0) ans += H / a[0];
		else ans += H / a[0] + 1;
	}
	cout << ans << endl;
	system("pause");
	return 0;
}


Measured memory_bytes: 2040
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct S{
  int w, h;
  bool operator<(const S& rhs) const{
	return (w*w+h*h < rhs.w*rhs.w+rhs.h*rhs.h)
					 || (w*w+h*h == rhs.w*rhs.w+rhs.h*rhs.h && h < rhs.h);
  }
};

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

  for(;;){
	S tar;
	cin >> tar.h >> tar.w;
	if(tar.h == 0) break;
	vector<S> vs;
	for(int y=1;y<=100;++y)
	  for(int x=y+1;;++x){
		S s; s.w = x, s.h = y;
		if(tar < s){
		  vs.PB(s);
		  break;
		}
	  }
	SORT(vs);
	auto it = upper_bound(ALL(vs), tar);
	cout << it->h << " " << it->w << endl;
  }

  return 0;
}

Measured memory_bytes: 1220
package main

import (
	"fmt"
	"math"
)

func main() {
	A := 0
	B := 1
	C := 2
	var n, a, b, c int
	fmt.Scan(&n)
	var dp [][]int
	for i := 0; i < n; i++ {
		dp = append(dp, make([]int, 3))
		fmt.Scan(&a, &b, &c)
		if i == 0 {
			dp[i][A] = a
			dp[i][B] = b
			dp[i][C] = c
			continue
		}
		dp[i][A] = int(math.Max(float64(dp[i-1][B]), float64(dp[i-1][C]))) + a
		dp[i][B] = int(math.Max(float64(dp[i-1][A]), float64(dp[i-1][C]))) + b
		dp[i][C] = int(math.Max(float64(dp[i-1][A]), float64(dp[i-1][B]))) + c

	}
	max := 0
	for i := 0; i < 3; i++ {
		if max < dp[n-1][i] {
			max = dp[n-1][i]
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 10624
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors
ans=[]
for ii in range(1,int(input())+1):
	if len(make_divisors(ii))==8 and ii%2==1:
		ans.append(ii)
print(len(ans))

Measured memory_bytes: 3060
import itertools
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
base=[]
for i in itertools.permutations(range(1,n+1)):
    base.append(list(i))
p_index=base.index(p)+1
q_index=base.index(q)+1
ans=abs(p_index-q_index)
print(ans)


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

#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pqMax priority_queue<int>
#define pqMin priority_queue<int, vector<int>, greater<int>>
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie();                        \
    cout.tie()
int n, t, i, j, k;
const int N = 3005;
int dp[N][N];

void solve() {
    cin >> n;
    vi a(n);
    for (int &i : a) cin >> i;
    for (i = n - 1; i >= 0; i--) {
        for (j = i; j < n; j++) {
            if (i == j)
                dp[i][j] = a[i];
            else
                dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);
        }
    }
    cout << dp[0][n - 1] << '\n';
}

int32_t main() {
    FAST;
    solve();
}

Measured memory_bytes: 70016
#include <atcoder/all>
using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr lint B1 = 1532834020;
constexpr lint M1 = 2147482409;
constexpr lint B2 = 1388622299;
constexpr lint M2 = 2147478017;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; }
template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; }
using mint = modint998244353;
int op(int a, int b) {return max(a, b);}
int e() {return (int)(-1);}
int target;
bool f(int v) {return v < target;}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N, Q;
  cin >> N >> Q;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  segtree<int, op, e> seg(A);
  REP(q, Q) {
    int T, X, Y;
    cin >> T >> X >> Y;
    if(T == 1) seg.set(X-1, Y);
    else if(T == 2) cout << seg.prod(X-1, Y) << "\n";
    else {
      target = Y;
      cout << seg.max_right<f>(X-1) + 1 << "\n";
    }
  }
}

Measured memory_bytes: 6140
#include <stdio.h>

int main(){
	int a[12],b[12];
	int i,j;
	int n;
	int flag;
	int count;
	
	while(1){
		scanf("%d",&n);
		if(n==0){
			break;
		}
		count=0;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
			b[i]=0;
		}
		
		while(1){
			for(i=0;i<n;i++){
				for(j=0;j<n;j++){
					if(a[i]==a[j]){
						b[i]++;
					}
				}
			}
			flag=0;
			for(i=0;i<n;i++){
				if(a[i]!=b[i]){
					flag=1;
					break;
				}
			}
			for(i=0;i<12;i++){
				a[i]=b[i];
				b[i]=0;
			}
			count++;
			if(flag==0){
				break;
			}
		}
		printf("%d\n",count-1);
		for(i=0;i<n;i++){
			printf("%d",a[i]);
			if(i!=n-1){
				printf(" ");
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 604
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] yen = new int[4];
		for (int i = 0; i < 4; i++) {
			yen[i] = sc.nextInt(); // 0:電車通常 1:電車乗り放題 2:バス通常 3:バス乗り放題
		}
		sc.close();
		System.out.println(Math.min(yen[0], yen[1]) + Math.min(yen[2], yen[3]));
	}
}


Measured memory_bytes: 23764
def compute_max(n, xs, ys):
    rest_enemys = xs[:]
    rest_powers = ys[:]
    for i in range(n):
        # city i
        removed_enemy = min(rest_enemys[i], rest_powers[i])
        rest_enemys[i] -= removed_enemy
        rest_powers[i] -= removed_enemy
        # city i + 1
        removed_enemy = min(rest_enemys[i + 1], rest_powers[i])
        rest_enemys[i + 1] -= removed_enemy
        rest_powers[i] -= removed_enemy
    total = sum(xs) - sum(rest_enemys)
    return total


def main():
    n = int(input())
    xs = [int(x) for x in input().split()]
    ys = [int(y) for y in input().split()]
    res = compute_max(n, xs, ys)
    print(res)


if __name__ == "__main__":
    main()

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define RSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))
#define PREC(n) setprecision(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

#define M 998244353

using namespace std;

typedef unsigned long long lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

int main() {
    vll count;
    ll i,j,k,n,m;

    cin>>n;
    j=0;
    SIZE(count,pow(10,5)+1);
    k=1;
    rep(i,n){
        cin>>m;
        j=max(j,m);
        count[m]++;
        if(i==0 && m!=0)k=0;
    }
    if(count[0]==0 || count[0]>1)k=0;
    for(i=j;i>0;i--){
        rep(m,count[i]){
            k*=count[i-1];
            k%=M;
        }
    }
    cout<<k;
	
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	int n = fetch<int>();
	auto a = fetch_vec<ll>(n);
	int cnt[2];
	cnt[0] = cnt[1] = 0;

	for(auto& elem: a) {
		++cnt[elem & 1];
	}

	int R = ((cnt[0] > 0) || (cnt[1] > 1)) + (cnt[1] & 1); DBG(R);
	cout << (R == 1 ? "YES\n" : "NO\n");
}

int main() {
	fast_io();
	solve();

	return 0;
}


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

q = n // 3
r = n % 3

def answer(q,r):
	if abs(a-b) > 10**18:
		return 'Unfair'

	if r == 0:
		if q%2 != 0:
			return b-a
		else:
			return a-b
	elif r == 1:
		if q%2 != 0:
			return a-b
		else:
			return b-a
	else:
		if q%2 != 0:
			return b-a
		else:
			return a-b

print(answer(q,r))

Measured memory_bytes: 3064
n,a,b=map(int,input().split())
mod=10**9+7
def f(k,l):
    ans=1
    for i in range(1,l+1):ans=(ans*(k-i+1)*pow(i,mod-2,mod))%mod
    return ans
print((pow(2,n,mod)-1-f(n,a)-f(n,b))%mod)




Measured memory_bytes: 3060
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <set>
#include <numeric>
#include <bitset>
#include <map>
#include <limits.h>
using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;
const int INF = 1e9;

long long gcd(long long x, long long y){
			if(x<y){
				long long temp = x;
			x = y;
				y = temp;
			}
			long long r = x % y;
				while(r!=0){
					x = y;
					y = r;
				r = x % y;
	    		}
			return y;
	    }
int main(){
long long  N,M;
cin >> N >> M;
if(N==2||M==2){
	cout << 0 << endl;
}
else{
	if(N>2)N-=2;
	if(M>2)M-=2;
	cout << N*M << endl;
 }
}

Measured memory_bytes: 256
#include <cstdio>
#include <map>
#define F(i,x,y) for(int i=x;i<=y;++i)
using namespace std;
int n,a[200005];
long long sum;
map<int,int>m;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
		++m[a[i]];
	}
	for(map<int,int>::iterator it=m.begin();it!=m.end();++it){
		int t=it->second;
		sum+=1ll*(t-1)*t/2;
	}
	for(int i=1;i<=n;++i){
		printf("%lld\n",sum-m[a[i]]+1);
	}
	return 0;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
  int n;
  cin >> n;
  map<int,int> d;
  int a;
  rep(i,n) {
    cin >> a;
    d[a]++;
  }
  ll ans = 1;
  int s = (n%2)? 0 : 1;

  if (n%2) {
    if (d[0] == 1) d[0]++;
    else ans = 0;
  }
  
  for (int i = s; i < n; i+=2)
  {
    if (i == 0) continue;
    if (d[i] != 2) ans = 0;
    ans *= 2;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7368
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 2e9;
const int MOD = 1000000007;

 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  deque<int> dq;
  rep(i,n){
    int idx = lower_bound(dq.begin(),dq.end(),a.at(i)) - dq.begin();
    //cout << idx << endl;
    if(idx == 0) dq.push_front(a.at(i));
    else if(idx == dq.size() ) dq.back() = a.at(i);
    else dq.at(idx-1) = a.at(i);
  }
  cout << dq.size() << endl;
  return 0;
}



Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    S = str(input())
    N=len(S)
    P=2019

    def main():
        if P == 2:
            res = 0
            for i in range(N):
                if int(S[N - 1 - i]) % 2 == 0:
                    res += N - i
        elif P == 5:
            res = 0
            for i in range(N):
                if int(S[N - 1 - i]) == 0 or int(S[N - 1 - i]) == 5:
                    res += N - i

        else:
            mods = [0] * P
            # mods[i]はPで割ったあまりがiである連続部分列の個数
            tenfactor = 1
            mod = 0
            mods[mod] += 1

            for i in range(N):
                mod = (mod + int(S[N - i - 1]) * tenfactor) % P
                tenfactor = (tenfactor * 10) % P
                mods[mod] += 1

            res = 0
            for p in range(P):
                res += mods[p] * (mods[p] - 1) // 2

        return res

    print(main())


resolve()

Measured memory_bytes: 68512
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int p[]=new int[n];
  int sum=0;
  for(int i=0;i<n;i++){p[i]=sc.nextInt();sum+=p[i];}
  int m=sc.nextInt();
  for(int i=0;i<m;i++){
  	int a=sc.nextInt();
    int b=sc.nextInt();
    System.out.println(sum-p[a-1]+b);
  }
}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define DBG(x) cerr << #x << “ = ” << (x) << endl
#define Rep(i,a,b) for (int i = a, to = b; i < to; i++)
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

typedef long long Long;

using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	Long n,x,t;
    cin>>n>>x>>t;
    cout<<((n+x-1)/x)*t;
     
	return 0;
}

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

#define md 1000000007
ll power(ll a,ll n)
 {
    ll res=1;
    while(n)
    {
      if(n%2)
       res=(res%md*a%md)%md;
    a=(a%md*a%md)%md;
     n/=2;
   }
  return res;
}
int main()
{
  ll n;
  cin>>n;
 map<ll,ll> mp;
 for(ll i=1;i<=n;i++)
  {
    ll a,c;
    cin>>a;
    c=a;
    ll l=0;
    while(c)
    {
      l++;
      ll b=c%2;
     if(b)
       mp[l]++;
     c/=2;
     }
    }
   ll res=0;
  for(ll i=1;i<=62;i++)
  {
    ll x=mp[i];
    ll y=n-x;
    res=(res+((((x%md)*(y%md))%md)*(power(2,i-1))%md)%md);
   }
  res=res%md;
 cout<<res;
   return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ab = [[] for _ in range(N)]
abl = []
for _ in range(M):
    a, b = map(int, input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)
    abl.append([a-1, b-1])


# DFS
def dfs(v):
    global da, db
    if tf[v]:
        return
    tf[v] = True
    for nv in ab[v]:
        if v == da and nv == db:
            continue
        if v == db and nv == da:
            continue
        dfs(nv)
    return


# 辺を１本ずつ抜いていってそれぞれDFS
ans = 0
for i in range(M):
    da, db = abl[i]
    tf = [False for _ in range(N)]
    dfs(0)
    if not all(e for e in tf):
        ans += 1
print(ans)

Measured memory_bytes: 9072
n = int(input())
a = list(map(int,input().split()))

add1 = []
sub1 = []
for i in range(n):
    add1.append(a[i] + i)
    sub1.append(i - a[i])

dict1 = {}
dict2 = {}
for i in add1:
    if i in dict1:
        dict1[i] += 1
    else:
        dict1[i] = 1
for i in sub1:
    if i in dict2:
        dict2[i] += 1
    else:
        dict2[i] = 1

sorted1 = sorted(dict1.items(), key = lambda x: x[0])
sorted2 = sorted(dict2.items(), key = lambda x: x[0])
cnt1 = 0
cnt2 = 0
ans = 0

while cnt1 < len(sorted1) and cnt2 < len(sorted2):
    if sorted1[cnt1][0] == sorted2[cnt2][0]:
        ans += sorted1[cnt1][1] * sorted2[cnt2][1]
        cnt1 += 1
        cnt2 += 1
    elif sorted1[cnt1][0] > sorted2[cnt2][0]:
        cnt2 += 1
    else:
        cnt1 += 1

print(ans)


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w; cin>>h>>w;
	vector<string>s(h); for(auto&&i:s)cin>>i;
	vector<vector<int>>L(h+2,vector<int>(w+2,0)),R(h+2,vector<int>(w+2,0)),
	U(h+2,vector<int>(w+2,0)),D(h+2,vector<int>(w+2,0));
	for(int i=1;i<h+1;++i){
		for(int j=1;j<w+1;++j){
			if(s.at(i-1).at(j-1)=='.'){
				L.at(i).at(j)=L.at(i).at(j-1)+1;
				U.at(i).at(j)=U.at(i-1).at(j)+1;
			}
		}
	}
	for(int i=h;i>=1;--i){
		for(int j=w;j>=1;--j){
			if(s.at(i-1).at(j-1)=='.'){
				R.at(i).at(j)=R.at(i).at(j+1)+1;
				D.at(i).at(j)=D.at(i+1).at(j)+1;
			}
		}
	}
	int ans=0;
	for(int i=1;i<h+1;++i){
		for(int j=1;j<w+1;++j){
			ans=max(ans,L.at(i).at(j)+R.at(i).at(j)+U.at(i).at(j)+D.at(i).at(j)-3);
		}
	}
	cout<<ans<<"\n"s;
}

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

int main(){
  string s, t;
  cin >> s;
  cin >> t;
  int out=0;
  int n = s.size();
  for (int i=0; i!=n; ++i){
    if (s[i] != t[i]){
      ++out;
    }
  }
  cout << out << endl;
	return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int M, K;
	cin >> M >> K;
	if(M == 1 && K== 1){
		cout << -1 << endl;
		return 0;
	}
	if(K == 0){
		rep(i,(1<<M)){
			cout << i << ' ';
			cout << i << ' ';
		}
	}
	else{
		if((1<<M) > K){
			rep(i,(1<<M)){
				if(i != K){
					cout << i << ' ';
				}
			}
			cout << K << ' ';
			for(int i=(1<<M)-1;i>=0;i--){
				if(i != K){
					cout << i << ' ';
				}
			}
			cout << K << ' ';
		}
		else{
			cout << -1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
N, Y = map(int, input().split())
Y //= 1000
for i in range(N + 1):
  x = Y - 10 * i
  for j in range(N - i + 1):
    y = x - 5 * j
    if y < 0: continue
    if i + j + y == N:
      print(i, j, y)
      exit(0)
  if x + i == N:
    print(i, 0, x)
    exit(0)
print(-1, -1, -1)

Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    b -= a, a = 0;

    if(b < -n*d || n*d < b) {
        cout << "NO" << endl;
        return 0;
    }

    ll lb = -(n-1)*c, ub = c-(n-2)*d;
    REP(i, n-1) {
        if(lb < b && b < ub) {
            cout << "NO" << endl;
            return 0;
        }
        lb += c+d;
        ub += c+d;
    }
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input!{
        n : u64,
    }
    let gohyaku: u64 = n / 500;
    let goen: u64 = (n -gohyaku *500);
    let goen = goen / 5;
    let  ans = gohyaku * 1000 + goen * 5;
    println!("{}", ans);
}


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

ll mod_pow(ll a,ll x){
    ll ret=1;
    while(x>0){
        if(x&1){(ret*=a)%=MOD;}
        (a*=a)%=MOD;
        x>>=1;
    }
    return ret;
}

int main(){
    ll d;
    cin>>d;
    vector<ll> a(d);
    for(auto &I:a){cin>>I;}
    ll s;
    cin>>s;
    if(s==0){cout<<0<<endl; return 0;}
    vector<ll> dp(s+10,0);
    dp[0]=1;
    for(auto &I:a){
        for(ll t=s-1;t>=0;t--){
            if(t+I<s){dp[t+I]-=dp[t]; dp[t+I]%=MOD;}
        }
    }
    ll ans=0;
    for(int i=0;i<s;i++){
        ans+=dp[i]*mod_pow(s-i,d)%MOD;
        ans%=MOD;
    }
    if(ans<0){ans+=MOD;}
    cout<<ans<<endl;
    
    
    return 0;
}



Measured memory_bytes: 3524
#include<iostream>
using namespace std;
int main(){
    int t,i,p=0,j,ans;
    cin>>t;
    if(t==2){
        cout<<"2"<<endl;
    }
    else{
    i=t;
    while(1){
            for(j=2;j<i;j++){
        if(i%j==0){
            p++;
        }}
    if(p==0){
            ans=i;
            goto e;
    }
    p=0;
i++;}

e:
    cout<<ans<<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 1;
    ll cnt = 0;
    for(int i = 1; i <= n; ++i) {
        ans*=i;
        ans%=mod;
    }
    for(int i = 0; i < 2 * n; ++i) {
        if((cnt&1)==(s[i]=='B')) {
            ans*=cnt;
            ans%=mod;
            --cnt;
        }else{
            ++cnt;
        }
    }
    if(cnt) {
        cout<<0<< endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}



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

/*#define IO \
freopen("input.txt","r",stdin);\
freopen("output.txt","w",stdout);*/

int solve(int,int);
int main()
{
   // IO;
    ll n,d;
    cin>>n>>d;
    cout<<solve(n,d);
    return 0;

}
int solve(int n,int d)
{
    ll a,b,c=0;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        double s=(double)sqrt(a*a+b*b);
        if(s<=d)
            c++;
    }
    return c;
}


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

int main(){
    int s,w;
    cin>>s>>w;
    if(w>=s){
        cout<<"unsafe"<<endl;
    }else{
        cout<<"safe"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <unordered_map>

typedef long long ll;

using namespace std;

int main(void) {
  int n; cin >> n;
  unordered_map<char,int> counter[51];
  for (int i = 0; i < 51; i++)
    for (char c = 'a'; c <= 'z'; c++)
      counter[i][c] = 0;
  for (int i = 0; i < n; i++) {
    string s; cin >> s;
    for (char c : s) { counter[i][c]++; }
  }

  for (char c = 'a'; c <= 'z'; c++) {
    vector<int> cvec(n);
    for (int i = 0; i < n; i++) { cvec[i] = counter[i][c]; }
    std::sort(cvec.begin(), cvec.end());
    for (int k = 0; k < cvec[0]; k++)
      cout << c;
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, A[200010];

signed main(){
    cin >> N;
    REP(i, N){
        cin >> A[i];
        A[i] -= i + 1;
    }
    sort(A, A + N);
    ll b = A[N / 2];
    ll ans = 0;
    REP(i, N) ans += abs(A[i] - b);
    PRINT(ans);
    return 0;
}

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

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

if(N%2!=0)
{
    P = floor(N/2) + 1;
} else
{
    P = N/2;
}

    cout << P << endl;
    return 0;
}

Measured memory_bytes: 256
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

signed main() {
  string s;
  cin >> s;
  int a, b;
  rep(i, s.size()) if (s[i] == 'A') {
    a = i;
    break;
  }
  rrep(i, s.size() - 1) if (s[i] == 'Z') {
    b = i;
    break;
  }

  print(b - a + 1);
}


Measured memory_bytes: 720
c1,c2 = input().split()
a1,a2 = input().split()
tem = input()
a1 = int(a1)
a2 = int(a2)
if tem == c1:
   a1 = a1-1
else:
   a2 = a2 -1

print(str(a1)+" "+ str(a2))


Measured memory_bytes: 2940
import collections

N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]

SS = collections.Counter(S)

TT = collections.Counter(T)

ans = 0
for i in S:
    tes = SS[i] - TT[i]
    ans = max(ans,tes)
    
print(ans)

Measured memory_bytes: 38384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	static int N;
	static int [] A;
	static int max;
	static int count;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		N = Integer.parseInt(br.readLine());
		String [] temp = br.readLine().split(" ");
		max = temp.length;
		A = new int[max];
		for(int i=0;i < max;i++){
			A[i] = Integer.parseInt(temp[i]);
		}

		for(int i=0;i < max;i++){
			sort();
		}

		for(int i=0;i < max-1;i++){
			System.out.print(A[i]+" ");
		}
		System.out.println(A[max-1]);
		System.out.println(count);
	}

	public static void sort(){
		for(int i=max-1;i>0;i--){
			if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			}


		}
	}

}

Measured memory_bytes: 24452
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    cout << n/3 << endl;
    return 0;
}

Measured memory_bytes: 256