akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define loop(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define br                break
#define con               continue

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}
 
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

priority_queue<pii, vector<pii>, greater<pii> >q;

#include<bits/stdc++.h>
using namespace std;
signed main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output1.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
 
	int n,x,t;
	cin>>n>>x>>t;
	int ans = n/x;
	if(n%x)ans+=1;
	cout<<ans*t<<endl;
 
}

Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
vector<int> p,q,a;
int main(void)
{
    int n,t,x,y;
    cin >> n;
    for(int i=1;i<=n;i++)
    {
        cin >> t;
        p.push_back(t);
    }
    for(int i=1;i<=n;i++)
    {
        cin >> t;
        q.push_back(t);
    }
    for(int i=1;i<=n;i++)
    {
        a.push_back(i);
    }
    int i = 0;
    do {
        i++;
        if(p==a) x=i;
        if(q==a) y=i;
    } while (next_permutation(a.begin(), a.end()));
    cout << abs(x-y);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
int cnt=0;
string s,t;
cin>>s>>t;
for(int i=0;i<3;i++){
    if(s.at(i)==t.at(i))cnt++;
}
cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int n,m,q,mp[2005][2005],s[2005][2005],s1[2005][2005],s2[2005][2005];
int calc(int x1,int y1,int x2,int y2,int s[][2005]){
	return s[x2][y2]-s[x2][y1-1]-s[x1-1][y2]+s[x1-1][y1-1];
}
int main(){
	int i,j,x1,y1,x2,y2;
	scanf("%d%d%d",&n,&m,&q);
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			scanf("%1d",&mp[i][j]);
	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			s[i][j]=s[i][j-1]+s[i-1][j]-s[i-1][j-1]+mp[i][j];
	for(i=1;i<=n;i++)
		for(j=1;j<m;j++)
			s1[i][j]=s1[i][j-1]+s1[i-1][j]-s1[i-1][j-1]+(mp[i][j]&&mp[i][j+1]);
	for(i=1;i<n;i++)
		for(j=1;j<=m;j++)
			s2[i][j]=s2[i][j-1]+s2[i-1][j]-s2[i-1][j-1]+(mp[i][j]&&mp[i+1][j]);
	while(q--){
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		printf("%d\n",calc(x1,y1,x2,y2,s)-calc(x1,y1,x2,y2-1,s1)-calc(x1,y1,x2-1,y2,s2));
	}
	return 0;
}

Measured memory_bytes: 66500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

int n, m, q;
vector <int> a, b, c, d;
int ans;

template <typename T>
void printVec(vector<T> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

int main() {
  string s;

  cin >> s;
  if(s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }
	return 0;
}

Measured memory_bytes: 3600
#!/usr/bin/env python3
import sys


def solve(S: int, W: int):
    if (S <= W):
        print("unsafe")
    else:
        print("safe")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(S, W)

if __name__ == '__main__':
    main()

Measured memory_bytes: 61708
#include<stdio.h>
int main(void){
  int n,d;
  scanf("%d %d",&n,&d);
  if(n==0){
    if(d!=100){
      printf("%d",d);
    }else{
        printf("101");
      }
    }else if(n==1){
      if(d!=100){
        printf("%d",d*100);
      }else{
          printf("10100");
    }
  }else{
      if(d!=100){
        printf("%d",d*10000);
      }else{
          printf("1010000");
    }
  }
  return 0;
}


Measured memory_bytes: 128
import re
import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=input()
a=[0]*(n+1)
tmp=0
for i in range(n-1):
  if s[i:i+2]=="AC":
    tmp+=1
  a[i+2]=tmp

for _ in range(q):
  l,r=map(int,input().split())
  print(a[r]-a[l])


Measured memory_bytes: 6600
import math


a, b, d = [float(i) for i in input().split()]
radian = math.radians(d)
c = (a**2 + b**2 - 2*a*b*math.cos(radian)) ** 0.5
L = a + b + c
S = a * b * math.sin(radian) / 2
h = 2 * S / a
for i in [S, L, h]:
    print("{:.5f}".format(i))


Measured memory_bytes: 5712
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d, sum, sam;
int main () {
cin >> a >> b >> c >> d;
sum = (a*b);
sam = (c*d);
if (sum > sam) {
	cout << sum << endl;
}
else {
	cout << sam << endl;
}
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<pair<int, int>> p(n);
  for (int i = 0; i < n; i++) cin >> p.at(i).first >> p.at(i).second;
  
  sort(p.begin(), p.end());
  
  double ans = 0;
  do {
    double keep = 0;
    for (int i = 1; i < n; i++) {
      keep += sqrt(pow(p.at(i - 1).first - p.at(i).first, 2) + pow(p.at(i - 1).second - p.at(i).second, 2));
    }
    ans += keep;
  } while (next_permutation(p.begin(), p.end()));
  
  for (int i = 1; i <= n; i++) ans /= i;
  
  cout << fixed << setprecision(10) << ans << '\n';
}

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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

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

  char pre = s[0];
  int cnt = 0;
  for (int i = 1; i < n; i++) {
    if (pre != s[i]) {
      pre = s[i];
      cnt++;
    }
  }
  cout << cnt + 1 << endl;
  return 0;
}


Measured memory_bytes: 512
// AOL 1059 Mysterious Onslaught
// 2018.2.18 bal4u

#include <stdio.h>
#include <string.h>

int n;
int map[5][5][5][5];
char memo[1<<25];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int calc(int b)
{
	int r1, c1, r2, c2, k, ans;

	if (!b) return 0;
	if (memo[b] >= 0) return memo[b];

	for (r1 = 0; r1 < n; r1++) for (c1 = 0; c1 < n; c1++) {
		if (b & (1<<(r1*n + c1))) goto next;
	}
next:
	ans = n*n;
	for (r2 = r1; r2 < n; r2++) for (c2 = c1; c2 < n; c2++) {
		k = b ^ map[r1][c1][r2][c2];
		k = calc(k) + 1;
		if (ans > k) ans = k;
	}
	return memo[b] = ans;
}

void init()
{
	int r1, r2, c1, c2, r, c;

	for (r1 = 0; r1 < n; r1++) for (c1 = 0; c1 < n; c1++)
		for (r2 = r1; r2 < n; r2++) for (c2 = c1; c2 < n; c2++)
			for (r = r1; r <= r2; r++) for (c = c1; c <= c2; c++)
				map[r1][c1][r2][c2] |= (1<<(r*n+c));
}

int main()
{
	int r, c, b, k;

	while (n = in()) {
		memset(map, 0, sizeof(map));
		memset(memo, -1, sizeof(memo));
		init();
		b = 0;
		for (k = r = 0; r < n; r++, k += n) for (c = 0; c < n; c++) {
			if (getchar_unlocked() & 1) b |= 1 << (k+c);
			getchar_unlocked();
		}
		k = calc(b);
		while (k--) printf("myon");
		putchar('\n');
	}
	return 0;
}


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

int main(void){
	int N, W;
	cin >> N >> W;
	vector<int> w(N), v(N);
	for(int i = 0; i < N; ++i){
		cin >> w[i] >> v[i];
	}
	ll dp[N+1][N*1000+1] = {};
	for(int i = 0; i < N; ++i){
		for(int j = 0; j <= N*1000; ++j){
			dp[i][j] = (LLONG_MAX>>1);
		}
	}
	dp[0][0] = 0;
	for(int i = 0; i < N; ++i){
		for(int j = 0; j <= N*1000; ++j){
			dp[i+1][j] = dp[i][j];
			if(j-v[i]>=0){
				dp[i+1][j] = min(dp[i][j-v[i]] + w[i], dp[i+1][j]);
			}
		}
	}
	ll ans = 0;
	for(int i = 0; i < N*1000+1; ++i){
		if(dp[N][i] <= W) ans = i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 79104
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
vi adj[N];
int dp[N], par[N];

int main() {
  int n, m; scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v; scanf("%d %d", &u, &v);
    adj[u].pb(v);
  }
  int len = inf, idx = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      dp[j] = inf;
    deque<int> pq; pq.pb(i);
    dp[i] = 0;
    int mn = inf;
    while (sz(pq)) {
      int u = pq.front(); pq.pop_front();
      trav(v, adj[u]) {
        if (v == i)
          mn = min(mn, dp[u]+1);
        if (dp[v] > dp[u] + 1) {
          dp[v] = dp[u] + 1;
          pq.pb(v);
        }
      }
    }
    if (mn < len) {
      len = mn, idx = i;
    }
  }
  if (idx < 0)
    return !printf("-1\n");
  for (int j = 1; j <= n; j++)
    dp[j] = inf;
  deque<int> pq; pq.pb(idx);
  dp[idx] = 0;
  int c = 0;
  while (sz(pq)) {
    int u = pq.front(); pq.pop_front();
    c++;
    int d = dp[u];
    if (c == 1)
      dp[u] = inf;
    trav(v, adj[u]) {
      if (dp[v] > d + 1) {
        dp[v] = d + 1;
        par[v] = u;
        pq.pb(v);
      }
    }
  }
  vi ans;
  int u = idx;
  do {
    ans.pb(u);
    u = par[u];
  } while (u != idx);
  printf("%d\n", sz(ans));
  trav(v, ans) printf("%d\n", v);
  return 0;
}


Measured memory_bytes: 27392
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,c;
	cin>>n>>k>>c;
	string s;
	cin>>s;
	vector<int>arr;
	for(int i=0; i<n; i++)
	{
		if(s[i]=='o')
		 arr.push_back(i+1);
	}
	vector<int>pos1,pos2;
	pos1.push_back(arr[0]);
	int last=arr[0];
	int cnt=1;
	for(int i=1; i<arr.size(); i++)
	{
		if(arr[i]-last>c){
			cnt++;
			pos1.push_back(arr[i]);
			last=arr[i];
		}
	}
	if(cnt==k)
	{
		int cnt2=1;
		int last=arr[arr.size()-1];
		pos2.push_back(last);
		for(int i=arr.size()-2; i>=0; i--)
		{
			if(last-arr[i]>c)
			{
				pos2.push_back(arr[i]);
				last=arr[i];
			    cnt2++;	
			}
		}
	//	cout<<"cnt2 : "<<cnt2<<"\n";
		if(cnt2==cnt)
		{
			reverse(pos2.begin(),pos2.end());
			for(int i=0; i<cnt; i++)
			{
				if(pos1[i]==pos2[i])
				 cout<<pos1[i]<<"\n";
			}
		}
	}
	return 0;
}

Measured memory_bytes: 6448
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,s,e) for(ll i=s;i<e;++i)

int main()
{
    int n,x,t;
    cin >> n >> x >> t;

    int time = 0;
    int num = 0;
    while(n > num){
        num += x;
        time += t;
    }
    cout << time << endl;

    return 0;
}

Measured memory_bytes: 3580
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()
	// x, y := make([]int, m), make([]int, m)
	// for i := 0; i < m; i++ {
	// 	x[i], y[i] = nextInt(), nextInt()
	// }

	box := make([]int, n)
	for i := range box {
		box[i] = 1
	}
	exist := make([]bool, n)
	exist[0] = true

	for i := 0; i < m; i++ {
		x, y := nextInt()-1, nextInt()-1
		if exist[x] {
			exist[y] = true
			if box[x] == 1 {
				exist[x] = false
			}
		}
		box[x]--
		box[y]++
		// puts(x, y, exist, box)
	}

	ans := 0
	for i := 0; i < n; i++ {
		if exist[i] && box[i] > 0 {
			ans++
		}
	}
	puts(ans)
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 2688
#include<stdio.h>
#include<string.h>
#include<stdlib.h>


int main(void)
{
  //printf("%d\n",'a'-'A');  :32
  int i; 
  char str[10000];
  fgets(str,sizeof(char)*10000,stdin);

  for(i=0;i<strlen(str);i++)
    if(str[i]-'a'>=0 &&str[i]-'a'<26)
      str[i]-=32;
  printf("%s",str);

  return 0;
}

Measured memory_bytes: 524
n=int(input())
a=[]
for i in range(2):
    a.append(list(map(int,input().split())))

ans=0
for k in range(n):
    s=0
    for i in range(0,k+1):
        s+=a[0][i]
    for j in range(k,n):
        s+=a[1][j]
    ans=max(ans,s)
print(ans)



Measured memory_bytes: 64144
#include <stdio.h>

int main(){

  int n,b,f,r,v;
  int a[4][3][10];
  int i,k,t;

  for(i=0; i<4; ++i){
    for(k=0; k<3; ++k){
      for(t=0; t<10; ++t){
	a[i][k][t]=0;
      }
    }
  }

  scanf("%d",&n);

  for(i=0; i<n; ++i){
    scanf("%d%d%d%d",&b,&f,&r,&v);

    a[b-1][f-1][r-1]+=v;
  }


  for(i=0; i<4; ++i){
    for(k=0; k<3; ++k){
      for(t=0; t<10; ++t){
	printf(" %d",a[i][k][t]);
      }
      printf("\n");
    }
    if(i<3){
      printf("####################\n");
      }
  }

  

  return 0;
}


Measured memory_bytes: 2760
#include <iostream>
#include <vector>
#include<iomanip>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

int gcd(int a, int b) {
    if (a > b){
        swap(a,b);
    }
    
    while(b > 0) {
        int r = a % b;
        a = b;
        b = r;
    }
    
    return a;
}

int main(int argc, const char * argv[]) {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    int tmp = A;
    A = min(A, C);
    C = max(tmp, C);
    
    tmp = B;
    B = min(B, D);
    D = max(tmp, D);
    
    
    if (A == C or B == D) {
        cout << "0" << endl;
    } else {
        cout << abs(C - A) + abs(D - B) - gcd(abs(C - A), abs(D - B)) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
//NAME-DEEPESH BHATT
//Institute-IIT Dhanbad
//MOTTO-THINK FIRST,CODE LATER

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007  ;
#define endl '\n'
#define pb push_back
#define mp make_pair

//Check for signed int overflow
// use __builtin_popcount(num) to calculate no.of setbits in num
//s.lower_bound() works in O(logn) whereas lower_bound(s.begin(),s.end(),x) works in O(n)
//      if(!lazy)
//         solve 1600+(rating) problems in codeforces.
//      else
//         solve 1400+(rating) problems in codeforces.

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
ll power(ll a,ll n){
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p)%MOD;
    if (n % 2)
        return (p * a)%MOD;
    else
        return p%MOD;
}

/*vector<bool>is_prime(1000001,true);
void sieve(){
    is_prime[0]=is_prime[1]=false;
    is_prime[2]=true;
    for(int i=2;i*i<=1000000;i++){
        if(is_prime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                is_prime[j]=false;
            }
        }
    }
}*/

int32_t main()
{
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(nullptr);
    ll test=1;
    /*cin>>test;*/
    while(test--) {
        ll n;
        cin>>n;
        ll count1=0,count2=0,count3=0,count4=0;
        for(ll i=0;i<n;i++){
            string s;
            cin>>s;
            if(s[0]=='A'){
                count1++;
            }
            else if(s[0]=='W'){
                count2++;
            }
            else if(s[0]=='T'){
                count3++;
            }
            else{
                count4++;
            }
        }
        cout<<"AC x "<<count1<<endl;
        cout<<"WA x "<<count2<<endl;
        cout<<"TLE x "<<count3<<endl;
        cout<<"RE x "<<count4<<endl;
    }
    return 0;
}

Measured memory_bytes: 3608
S = input()
Fa = int(S[:2])
Se = int(S[2:])
if 1 <= Fa <= 12 and 1 <= Se <= 12:
	print("AMBIGUOUS")
elif 1 <= Fa <= 12:
	print("MMYY")
elif 1 <= Se <= 12:
	print("YYMM")
else:
	print("NA")

Measured memory_bytes: 3060
/*
//https://sen-comp.hatenablog.com/entry/2020/01/16/174230

*/
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};

vector<int> z_algorithm(const string &s){
    int c=0,N=(int)s.size();
    vector<int> Z(N,0);
    for(int i=1;i<N;i++){
        int l=i-c;
        if(i+Z[l]<c+Z[c]){
            Z[i]=Z[l];
        }else{
            int j=max(0,c+Z[c]-i);
            while(i+j<N && s[j]==s[i+j]) j++;
            Z[i]=j;
            c=i;
        }
    }
    Z[0]=N;
    return Z;
}

signed main(){
    int N;
    string S;
    cin>>N>>S;
    int ans=0;
    for(int i=0;i<N;i++){
        vector<int> V=z_algorithm(S.substr(i,N-i));
        for(int j=0;j<(int)V.size();j++){
            chmax(ans,min(j,V[j]));
        }
    }
    cout<<ans<<endl;
}

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

int main(){
	int n;
	scanf("%d", &n);
	map<string, int> s;
	for(int i = 0; i < n; i++) {
		int id;
		scanf("%d", &id);
		string key;
		cin >> key;
		if(id == 0) {
			int x;
			scanf("%d", &x);
			auto p = s.emplace(key, x);
			if(!p.second) (*s.find(key)).second = x;
		}else if(id == 1) {
			auto itr = s.find(key);
			printf("%d\n", (itr != s.end()) ? (*itr).second : 0);
		}else if(id == 2) {
			s.erase(key);
		}else if(id == 3) {
			string y;
			cin >> y;
			for(auto itr = s.lower_bound(key); itr != s.end() && (*itr).first <= y; itr++)
				cout << (*itr).first << " " << (*itr).second << '\n';
		}
	}
}



Measured memory_bytes: 27948
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H[i];
    }
    int ans = 0;
    int tmp = 0;
    Rep(i, 1, N){
        if(H[i-1] >= H[i])tmp++;
        else tmp = 0;
        chmax(ans, tmp);
    }
    pr(ans);
}

Measured memory_bytes: 640
inf = 10**15
mod = 10**9+7
n,T = map(int, input().split())
minc = inf
for i in range(n):
    c,t = map(int, input().split())
    if t <= T:
        minc = min(minc, c)
if minc == inf:
    print('TLE')
else:
    print(minc)

Measured memory_bytes: 38384
#include <iostream>
#include<string>
#include <algorithm>
using namespace std;
int main(){
  long long int n;
  string s;
  cin >>n >>s;
  int r[n];int l[n];
  for(int i=0;i<n;i++){
    r[i]=0;l[i]=0;
    if(s[i]=='W') l[i]=1;
    else r[i]=1;
    }
  for(int i=1;i<n;i++){
    r[n-i-1]+=r[n-i];
      l[i]+=l[i-1];
  }
  int ans=100000;
  for(int i=0;i<n;i++){
    if(i==0) ans=r[i];
    else if(i==(n-1)) ans=min(ans,l[i-1]);
    else ans=min(ans,l[i-1]+r[i+1]);
  }
  cout <<ans <<endl;
}


Measured memory_bytes: 3076
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N, K := ReadInt(), ReadInt()
	a := ReadInts(N)
	for i := 0; i < N; i++ {
		a[i] -= K
	}
	s := make([]int, N+1)
	for i := 0; i < N; i++ {
		s[i+1] = s[i] + a[i]
	}
	s2 := Uniq(s)
	sort.Ints(s2)
	t := MakeSegTree(N + 1)
	ans := 0
	for i := 0; i < N+1; i++ {
		v := sort.SearchInts(s2, s[i])
		ans += t.Count(0, v+1)
		t.Add(v, 1)
	}
	fmt.Println(ans)
}

func Uniq(xs []int) (v []int) {
	m := make(map[int]bool)
	for _, x := range xs {
		if ok := m[x]; !ok {
			m[x] = true
			v = append(v, x)
		}
	}
	return
}

type SegTree []int

func MakeSegTree(n_ int) SegTree {
	n := 1
	for n < n_ {
		n <<= 1
	}
	return make([]int, n*2)
}

func (t SegTree) Add(i int, v int) {
	i += len(t) >> 1
	t[i] += v
	for i > 1 {
		i >>= 1
		t[i] = t[i*2] + t[i*2+1]
	}
}

func (t SegTree) Count(l, r int) int {
	return t.countRecur(l, r, 1, 0, len(t)>>1)
}
func (t SegTree) countRecur(a, b, k, l, r int) int {
	if r <= a || b <= l {
		return 0
	}
	if a <= l && r <= b {
		return t[k]
	}
	lv := t.countRecur(a, b, k*2, l, (l+r)>>1)
	rv := t.countRecur(a, b, k*2+1, (l+r)>>1, r)
	return lv + rv
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int a, b;
    string s;
    cin >> a >> b >> s;
    if (s.size() == a + b + 1) {
        bool ok = true;
        rep(i, a) if (s[i] < '0' || s[i] > '9') ok = false;
        if (s[a] != '-') ok = false;
        repl(i, a + 1, a + b + 1) if (s[i] < '0' || s[i] > '9') ok = false;
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stdbool.h>
#include<math.h>
#include<sstream>
typedef long long ll;
#define N (1000000000+7)
using namespace std;
typedef pair<int, int> P;
#define INF (-1000)

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int c[505],s[505], f[505];
int main(void) {
	int n;
	cin >> n;
	for (int i = 1;i < n;i++)cin >> c[i] >> s[i] >> f[i];
	for (int i = 1;i <= n;i++) {
		if (i == n) {
			cout << 0 << endl;
			break;
		}
		int t = 0;
		for (int j = i;j < n;j++) {
			if (t < s[j])t = s[j];
			if (t%f[j] != 0)t += (f[j] - (t%f[j]));
			t += c[j];
		}
		cout << t << endl;
	}
	return 0;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {
          
			int in = Integer.parseInt(br.readLine());
			System.out.println(in<1200?"ABC":"ARC");

		}
	}
}


Measured memory_bytes: 25316
def get_keta_num(num):
    keta_num = 0
    num = abs(num)
    while num > 0:
        keta_num += 1
        num //= 2
    keta_num += 2
    return keta_num




def main():
    num = int(input())
    sum_num = 0

    ans_list = []
    ind = 0
    while 1:
        now_num = 2 ** (ind + 1)
        ans_num = num % now_num
        if ans_num != 0:
            num -= (-2) ** ind
            ans_list.append(1)
        else:
            ans_list.append(0)

        if num == 0:
            break

        ind += 1


    ans_list = reversed(ans_list)
    print(''.join(map(str, ans_list)))



if __name__ == '__main__':
    main()


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    int len = s.length();
    sort(s.begin(), s.end());
    int count = 0;
    for(int i = 0; i < len; i++)
    {
        if(s[i] != s[i+1])
        {
            count++;
        }
    }
    if(count == 2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

   return 0;
}


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

using namespace std;

typedef long long int lli;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vii;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<b;i++)

#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main() {
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	
	FASTIO

	int T=1;
//	cin >> T;

	while(T--) {
		int x,n,input;
		cin >> x >> n;

		int dat[102]={};

		REP(i,0,n) {
			cin >> input;
			dat[input]++;
		}

		REP(i,1,min(x+1,102-x)) {
			if(dat[x]==0) {
				break;
			}
			if(dat[x-i]==0) {
				x-=i;
				break;
			}
			if(dat[x+i]==0) {
				x+=i;
				break;
			}
		}

		cout << x;
	}

	return 0;
}

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

int main() {
    int count=0, cnt=0, ans;
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++) {
        if(i%2==0) {
            if(s.at(i) != '1') count++; //char型　'数字'
            else cnt++;
        }
        else {
            if(s.at(i) != '0') {
                count++;
            }
            else cnt++;
        }
    }
    ans = min(count, cnt);
    cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int x = tx - sx;
    int y = ty - sy;
    rep(i, x) cout << 'R';
    rep(i, y) cout << 'U';
    rep(i, x) cout << 'L';
    rep(i, y) cout << 'D';
    cout <<'L';
    rep(i, y + 1) cout << 'U';
    rep(i, x + 1) cout << 'R';
    cout << 'D';
    cout << 'R';
    rep(i, y + 1) cout << 'D';
    rep(i, x + 1) cout << 'L';
    cout <<'U';

}

Measured memory_bytes: 256
#include <limits>
#include <initializer_list>
#include <utility>
#include <bitset>
#include <tuple>
#include <type_traits>
#include <functional>
#include <string>
#include <array>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <algorithm>
#include <complex>
#include <random>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <regex>
#include <cassert>
#include <cstddef>
#define endl codeforces
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pii = std::pair<int, int>;
using tii = std::tuple<int, int, int>;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, std::size_t s, Tail... tail) { auto v = std::move(make_v(init, tail...)); return vec<decltype(v)>(s, v); }
template <typename T, std::size_t Head, std::size_t ...Tail> struct multi_dem_array { using type = std::array<typename multi_dem_array<T, Tail...>::type, Head>; };
template <typename T, std::size_t Head> struct multi_dem_array<T, Head> { using type = std::array<T, Head>; };
template <typename T, std::size_t ...Args> using mdarray = typename multi_dem_array<T, Args...>::type;
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }

int main() {
    ll n, m;
    std::cin >> n >> m;
    ll ans = n;
    while (m--) {
        ll e;
        std::cin >> e;
        ans -= e;
    }
    std::cout << std::max<ll>(-1, ans) << '\n';
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
    cin>>N;
    vec u(N,0), v(N,0);
    ll mod = 0;
    rep(i,N){
        cin>>A>>B;
        u[i] = A + B;
        v[i] = A - B;
        if(i == 0) {
            mod = abs(u[i])%2;
        }else if(mod != abs(u[i])%2) {
            cout<<-1<<endl;
            return 0;
        }
    }
    vec d(32-mod,1);
    reps(i,2-mod,32-mod) d[i] = d[i-1] * 2;
    ll base = (1LL<<31)-mod;

    cout<<32-mod<<endl;
    rep(i,32-mod) cout<<d[i]<<' ';
    cout<<endl;

    vector<char> dir = {'L','D','U','R'};
    rep(i,N){
        u[i] += base;
        v[i] += base;
        rep(j,32-mod){
            if(j == -mod){
                cout<<'L';
                continue;
            }
            bool x = ((u[i] & (d[j]<<1)) != 0);
            bool y = ((v[i] & (d[j]<<1)) != 0);
            cout<<dir[x*2+y];
        }
        cout<<endl;
    }
}

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

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

  char a;
  cin >> a;
  if (a >= 'a' && a <= 'z')
    cout << 'a' << endl;
  if (a >= 'A' && a <= 'Z')
    cout << 'A' << endl;

  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <map>

using namespace std;

const int B = 4;
const int F = 3;
const int R = 10;

int main()
{
    int row;
    int kousya[B][F][R] = {};
    while (cin >> row)
    {
        int b, f, r, v;
        for (int i = 0; i < row; i++)
        {
            cin >> b >> f >> r >> v;
            kousya[b - 1][f - 1][r - 1] += v;
            if(kousya[b - 1][f - 1][r - 1] < 0)
            {
                kousya[b - 1][f - 1][r - 1] = 0;
            }
            else if(kousya[b - 1][f - 1][r - 1] > 9)
            {
                kousya[b - 1][f - 1][r - 1] = 9;
            }
        }
        for (int j = 0; j < B; j++)
        {
            for (int jj = 0; jj < F; jj++)
            {
                for (size_t jjj = 0; jjj < R; jjj++)
                {
                    cout << " " << kousya[j][jj][jjj];
                }
                cout << endl;
            }
            if (j != F)
            {
                cout << "####################" << endl;
            }
        }
    }
    return (0);
}

Measured memory_bytes: 3088
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
using namespace std;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int H, W;
vector<string> fi;
using pint = pair<int,int>;

void bfs(queue<pint> &que, vector<vector<int> > &dist) {
    while (!que.empty()) {
        auto p = que.front(); que.pop();
        for (int dir = 0; dir < 4; ++dir) {
            int nx = p.first + dx[dir], ny = p.second + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (fi[nx][ny] != '.' && fi[nx][ny] != 's') continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[p.first][p.second] + 1;
                que.push(pint(nx, ny));
            }
        }
    }
}

int main() {
    cin >> W >> H;
    fi.resize(H);
    for (int i = 0; i < H; ++i) cin >> fi[i];

    pint s, g;
    vector<pint> ss;
    for (int i = 0; i < H; ++i) for (int j = 0; j < W; ++j) {
            if (fi[i][j] == 'g') g = pint(i, j);
            else if (fi[i][j] == 's') s = pint(i, j);
            else if (fi[i][j] == '*') ss.push_back(pint(i, j));
        }

    vector<vector<int> > dpg(H, vector<int>(W, -1)), dps(H, vector<int>(W, -1));
    queue<pint> queg;
    queg.push(g), dpg[g.first][g.second] = 0;
    bfs(queg, dpg);
    queue<pint> ques;
    for (auto p : ss) ques.push(p), dps[p.first][p.second] = 0;
    bfs(ques, dps);

    double low = 0, high = 1LL<<60;
    for (int _ = 0; _ < 100; ++_) {
        double t = (low + high) / 2; //cout << "----------------" << endl; cout << t << endl;
        double sum = 0;
        int N = 0;
        for (int i = 0; i < H; ++i) {
            for (int j = 0; j < W; ++j) {
                if (fi[i][j] != '.' && fi[i][j] != 's') continue;
                ++N;
                double tmp = 1LL<<60;
                if (dps[i][j] != -1 && tmp > dps[i][j] + t) tmp = dps[i][j] + t;
                if (dpg[i][j] != -1 && tmp > dpg[i][j]) tmp = dpg[i][j];
                sum += tmp;
            }
        }
        if (t * N >= sum) high = t;
        else low = t;
    }

    double res = 1LL<<60;
    if (dps[s.first][s.second] != -1 && res > dps[s.first][s.second] + high)
        res = dps[s.first][s.second] + high;
    if (dpg[s.first][s.second] != -1 && res > dpg[s.first][s.second])
        res = dpg[s.first][s.second];

    cout << fixed << setprecision(12) << res << endl;
}



Measured memory_bytes: 5568
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define pii pair<int, int>
#define plli pair <lli, lli>
#define F(i,n) for(lli (i)=0;(i)<(n);(i)++)
#define FR(i,n) for(lli (i)=(n)-1;(i)>=0;(i)--)
#define FSG(i,a,b) for(lli (i)=(a);(i)<(b);(i)++)
#define FSGR(i,a,b) for(lli (i)=(b)-1;(i)>=(a);(i)--)
#define VAL(n) cout << n << endl;
#define VALD(n) cout << #n << ": " << n << endl;

int main(){
  int K, X;
  cin >> K >> X;
  int min = X-K+1;
  F(i, 2*K-1){
    cout << min + i << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int  N; cin >> N;
    vector<ll> A(N,0);
    vector<ll> c(N);
    vector<ll> b(N);
    ll cnt=0;
    for(int i=0;i<N;i++){
        cin >> c[i];
        A[c[i]-1]++;
    }
    for(int i=0;i<N;i++){
        cnt += A[i]*(A[i]-1)/2;
    }
    for(int i=0;i<N;i++){
        ll tmp=A[c[i]-1];
        ll m = tmp*(tmp-1)/2;
        ll p = (tmp-1)*(tmp-2)/2;
        cout  << cnt - m + p << endl;
    }
    return 0;
}


Measured memory_bytes: 7296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(long Q, long H, long S, long D, int N)
        {
            long s = new[] { Q * 4, H * 2, S * 1 }.Min();
            long d = new[] { s * 2, D * 1 }.Min();
            return N / 2 * d + N % 2 * s;
        }
        static void Main(string[] args)
        {
            var V = ReadLongs();
            int N = ReadInt();
            Console.WriteLine(Solve(V[0], V[1], V[2], V[3], N));
        }
    }
}


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

#define N 500000

int S[N], cnt = 0;

void merge(int left, int mid, int right) {
    int n1 = mid - left, n2 = right - mid;
    int L[n1 + 1], R[n2 + 1], i, j, k;
    for (i = 0; i < n1; i++) {
        L[i] = S[left + i];
    }
    for (i = 0; i < n2; i++) {
        R[i] = S[mid + i];
    }
    L[n1] = 1000000001;
    R[n2] = 1000000001;
    i = 0;
    j = 0;
    for (k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            S[k] = L[i++];
        } else {
            S[k] = R[j++];
        }
        cnt++;
    }
}

void mergeSort(int left, int right) {
    int mid;
    
    if (left + 1 < right) {
        mid = (left + right)/2;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid, right);
    }
}


int main(void){
    int i, n;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%d", &S[i]);
    }
    
    mergeSort(0, n);
    
    for (i = 0; i < n - 1; i++) {
        printf("%d ", S[i]);
    }
    printf("%d\n%d\n", S[i], cnt);
    
    return 0;
}



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

typedef long long ll;

int main(){
  string s;
  cin>> s;
  stack <int> x;
  stack <pair<int, int> >y;
  int area = 0;
  int sum = 0;
  for(int i=0; i<s.size(); i++){
    if(s[i] == '\\') x.push(i);
    else if(s[i] == '/' && x.size()>0) {
      int j = x.top();
      sum+=(i-j);
      int a = i-j;
      x.pop();
      while(y.size()>0 && y.top().first>j){
	a+= y.top().second;
	y.pop();
      }
      y.push(make_pair(j, a));
    }
  }
  vector<int> ans;
  while( y.size() >0){ans.push_back(y.top().second); y.pop();}
  reverse(ans.begin(), ans.end());
  cout << sum << endl;
  cout << ans.size() ;
  for(int i=0; i<ans.size(); i++){
    cout << " ";
    cout << ans[i];
    
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3280
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  a,b,c=LI()

  return min(a+b,a+c,b+c)

print(main())


Measured memory_bytes: 6180
S=raw_input()
N=len(S)
k=0
i=0
while i<N:
    cntj,cnto,cnti=0,0,0
    while i<N and S[i]=="J":
        cntj+=1
        i+=1
    while i<N and S[i]=="O":
        cnto+=1
        i+=1
    while i<N and S[i]=="I":
        cnti+=1
        i+=1
    if cntj>=cnto and cnti>=cnto:
        k=max(cnto,k)
print k

Measured memory_bytes: 5324
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
p = p[:X]
q.sort(reverse=True)
q = q[:Y]
r.sort(reverse=True)
ans = p + q
ans.sort()
i = 0
for rr in r:
    if ans[i] < rr:
        ans[i] = rr
        i += 1
    else:
        break

print(sum(ans))


Measured memory_bytes: 23328
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int l=0, ans=0, r=n-1;
    while(l<r){
        while(s[l]=='R'){
            l++;
        }
        while(s[r]=='W'){
            r--;
        }
        s[l]='R';
        s[r]='W';
        if(l<r) ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(n) for(ll i=0; i<n; i++)

const ll MOD = 1000000007;

ll mod_pow(ll n, ll a)
{
  if (a==0) return 1;
  ll x = mod_pow(n,a/2);
  ll y = ( x * x ) % MOD;
  if ( a%2 == 1) y = ( y * n ) % MOD;
  return y;
}

ll mod_inv(ll x)
{
  return mod_pow(x,MOD-2);
}

int main()
{
  ll n,a,b;

  cin >> n >> a >> b;


  ll ans = ( mod_pow(2,n) + 1 ) % MOD;

  vector<ll> C(200001);

  C[0] = 1;

  for (ll i = 1; i < 200001; i++)
  {
    ll tmp = C[i-1] * (n-i+1) % MOD;
    tmp = tmp * mod_inv(i) % MOD;
    C[i] = tmp;
  }

  ll minus = ( C[a] + C[b] ) % MOD;

  if ( ans > minus ) ans -= minus;
  else ans = MOD - minus + ans;

  cout << ans - 2 << endl;
  

  return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] argvs) {
    	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int A = Math.abs(x - a);
        int B = Math.abs(x - b);
      
        if (A < B) {
        	System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;
ll fact(ll n)
{
ll    res=1;
    for(int i = 1; i <= n;i++){
    res = res * i ;
}
return res;
}
ll pw(ll a, ll n)
{
    ll ans=1;
    while(n>0)
    {
        if (n%2!=0)
        {
            ans=ans*a;
        }
        a=a*a;
        n=n/2;
    }
    return ans;
}



int main()
{   IOS;

    ll n; cin >> n;
    stringstream ss;
    ss << n;
    string str = ss.str();
    ll x=str.size();
    ll res=0;
    if(n<10)
    {
        cout << n;
        return 0;
    }
    //cout << 1*pow(10,x-1);
    if(x%2==1)
        res+= n-(1*pw(10,x-1))+1;
    //cout << res << "hhh";
    x-=1;
    //cout << x;
    //cout << "hhh" << res;
   // cout << 9*pw(10,x-1) << "ok";
    while(x!=0)
    {
        if(x%2==1)
            res+= 9*pw(10,x-1);
            x--;


    }
    //cout << "ffffff" << pow(10,0);
    cout << res;
    cout.precision(30);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int w,h,x,y;
    long long sum;
    double m;
    cin>>w>>h>>x>>y;
    sum=(long long)w*h;
    m=(double)sum/2;
    printf("%.9f ",m);
    if(x*2==w&&y*2==h)
        cout<<'1'<<endl;
    else
        cout<<'0'<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
    ll s[5];
    REP(i, 5)
        cin >> s[i];
        REP(i, 5){
            if(s[i] == 0){
                cout << i + 1 << endl;
                return 0;
            }
        }
}


Measured memory_bytes: 3620