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

int main(){
  int a,b,c;
  cin >>a>>b>>c;
  int l = max(max(a,b),c);
  int s = min(min(a,c),b);
  cout << ((a+b+c - l - s) * s) / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
using namespace std;
int N,M;
char A[70][70];
int panduan(int x,int y)
{
    if(x>=0&&x<N&&y>=0&&y<M)
        return 1;
    else
        return 0;
}
int B[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int main()
{
    while(scanf("%d %d",&N,&M)!=EOF)
    {
        for(int i=0;i<N;i++)
            scanf("%s",&A[i]);
        int flag=1;
        for(int i=0;i<N;i++)
        {
            for(int j=0;j<M;j++)
            {
                if(A[i][j]=='#')
                {
                   flag=0;
                   int dx,dy;
                   for(int k=0;k<4;k++)
                   {
                       dx=i+B[k][0];
                       dy=j+B[k][1];
                       if(panduan(dx,dy)==0) continue;
                       if(A[dx][dy]=='#') flag=1;
                   }
                }
                if(flag==0)break;
            }
            if(flag==0)break;
        }
        if(flag==1) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  long long a[n], b[n];
  for(int i=0; i<n; i++) cin >> a[i] >> b[i];
  pair<long long, long long> x[n];
  for(int i=0; i<n; i++){
    x[i] = make_pair(a[i], b[i]);
  }
  sort(x, x+n);
  int honsu = m;
  long long cost = 0;
  for(int i=0; i<n; i++){
    if(x[i].second < honsu){
      cost += x[i].first * x[i].second;
      honsu -= x[i].second;
    }
    else{
      cost += x[i].first*honsu;
      break;
    }
  }
  cout << cost <<endl;

return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=6e3+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n;
char s[N];
void input()
{
	n=read<int>();
	scanf("%s",s+1);
}
vector<string>E;
#define pb push_back
int a[N],b[N];
int sum[N];
string get1(int l,int r)
{
	string res;
	int last=0;
	For(i,l,r)if(a[i]>last)res+="ab",last=b[i];
	return res;
}
bool vis[N];
string get2(int l,int r)
{
	string res,now;
	For(i,l,r)vis[a[i]]=vis[b[i]]=1;
	For(i,l,r)
	{
		now.clear();
		For(j,1,n*2)if(vis[j])now+=s[j];
		cmax(res,now);
		vis[a[i]]=vis[b[i]]=0;
	}
	return res;
}
void work()
{
	For(i,1,n*2)
	{
		if(s[i]=='a')a[++a[0]]=i,sum[i]++;
		else b[++b[0]]=i,sum[i]--;
		sum[i+1]=sum[i];
	}
	int j;
	string now;
	For(i,1,n)
	{
		if(a[i]<b[i])
		{
			for(j=i;j<n&&sum[b[j]]&&a[j+1]<b[j+1];j++);
			now=get1(i,j);
		}
		else
		{
			for(j=i;j<n&&sum[a[j]]&&a[j+1]>b[j+1];j++);
			now=get2(i,j);
		}
		//cout<<now<<endl;
		E.pb(now);
		i=j;
	}
	reverse(E.begin(),E.end());
	string ans;
	for(auto now:E)ans=max(ans,now+ans);
	cout<<ans<<endl;
}
int main()
{

	input();
	work();
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int N, M;
int A[1 << 18], B[1 << 18], C[1 << 18], D[1 << 18];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) cin >> A[i] >> B[i];
	for (int i = 1; i <= M; i++) cin >> C[i] >> D[i];
	for (int i = 1; i <= N; i++) {
		int minx = (1 << 30), minid = -1;
		for (int j = 1; j <= M; j++) {
			int dst = abs(A[i] - C[j]) + abs(B[i] - D[j]);
			if (minx > dst) { minx = dst; minid = j; }
		}
		cout << minid << endl;
	}
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    string s,c;
    cin>>a>>s;
    b=s.size();
    if(b>a)
    {
        c=s.substr(0,a);
        cout<<c;
        cout<<"...";
    }
    else
    {
        cout<<s;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007


int main(){
    
    int ans=0,i,j,k,n,m,D,t;
    string s;  
    cin>>n>>m;
    if(n<10){
        cout<<m+100*(10-n);
    }
    else{
        cout<<m;
    }
//    cin>>s;
    
    
   // cout<<"YES"<<endl;
  //  cout<<"NO"<<endl;
   // cout<<"Yes"<<endl;
   // cout<<"No"<<endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <cmath>
#include <cassert>

#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MN = 1e5 + 5, MOD = 1e9 + 7;

int N;
ld p[3005], dp[3005][3005];

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> p[i];
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        dp[i][0] = (1 - p[i]) * dp[i - 1][0];
        for (int j = 1; j <= i; j++) {
            dp[i][j] += p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
        }
    }
    ld ret = 0;
    for (int i = (N + 1) / 2; i <= N; i++) ret += dp[N][i];
    printf("%.10Lf\n", ret);
    return 0;
}


Measured memory_bytes: 139392
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, W := readInt(), readInt()

	weight, value := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		weight[i] = readInt()
		value[i] = readInt()
	}

	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, W+1)
	}

	for i := 0; i < n; i++ {
		for w := 0; w <= W; w++ {
			if w-weight[i] >= 0 {
				dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
			} else {
				dp[i+1][w] = dp[i][w]
			}
		}
	}
	fmt.Println(dp[n][W])
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 81792
def root(i):
    if par[i] < 0:
        return i
    else:
        return root(par[i])

def size(a):
    return -par[root(a)]

def union(a,b):
    a = root(a)
    b = root(b)
    if a == b:#親が等しい
        return False
    if size(a) < size(b):#サイズが大きい方に繋げる
        a,b = b,a
    par[a] += par[b]
    par[b] = a
    return True

n,m = map(int,input().split())
bridge = []
for i in range(m):
    bridge.append([int(j)-1 for j in input().split()])
ans = [n*(n-1)//2]
par = [-1 for _ in range(n)]

for a,b in bridge[::-1]:
    if root(a) == root(b):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - size(a) * size(b))
        union(a,b)
ans = ans[::-1]
for i in ans[1:]:
    print(i)

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  ll n;
  cin >> n;
  cout << n / 500 * 1000 + n % 500 / 5 * 5 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int n;
    cin>>n;
    vector<int> v(n),c(n);
    rep(i,n)cin>>v[i];
    rep(i,n)cin>>c[i];
    int sum=0;
    rep(i,n){
        int dif=v[i]-c[i];
        if(dif>0){
            sum+=dif;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = 0;
		int ahand = 0;
		int bhand = 0;
		int ascore = 0;
		int bscore = 0;
		
		while(true){
			n = Integer.parseInt(std.next());
			if(n==0){break;}
			ahand = bhand = ascore = bscore = 0;
			
			for (int i=0; i<n; i++){
				ahand = Integer.parseInt(std.next());
				bhand = Integer.parseInt(std.next());
				if(ahand>bhand){
					ascore += (ahand+bhand);
				}else if(ahand==bhand){
					ascore += ahand;
					bscore += bhand;
				}else{
					bscore += (ahand+bhand);
				}
			}
		System.out.println(ascore +" "+ bscore);
		}
	}
}

Measured memory_bytes: 43676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 1000000000
#define mod 1000000007
#define INF2 1000000000000000000

const int MAX_N = 200;
int V, M, R;
int d[MAX_N][MAX_N];

void warshall_floyd() {
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> V >> M >> R;
    int r[R];
    rep(i, R) {
        cin >> r[i];
        r[i]--;
    }
    fill(d[0], d[200], INF);
    rep(i, M) {
        int tmp_A, tmp_B, tmp_C;
        cin >> tmp_A >> tmp_B >> tmp_C;
        tmp_A--; tmp_B--;
        d[tmp_A][tmp_B] = tmp_C;
        d[tmp_B][tmp_A] = tmp_C;
    }

    warshall_floyd();
    sort(r, r+R);
    int ans = INF;
    do {
        int tmp = 0;
        rep(i, R-1) {
            tmp += d[r[i]][r[i+1]];
            //cout << tmp << endl;
        }
        ans = min(ans, tmp);
    } while (next_permutation(r, r+R));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
using namespace std;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int l) { uniform_int_distribution<int> uid(0, l - 1); return uid(rang); }

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10); srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int n; cin >> n;
    std::map<int, int> mp;
    vector<int> a(n); for (int o = 0; o < n; o++) { cin >> a[o]; mp[a[o]]++; }
    sort(a.begin(), a.end());
    mp[a[0]]--;
    mp[a[n - 1]]--;
    a[1] = a[n - 1];
    for (int i = 2; i < n; ++i) {
        if (mp[a[i - 1] ^ a[i - 2]]) {
            mp[a[i - 1] ^ a[i - 2]]--;
            a[i] = a[i - 1] ^ a[i - 2];
        } else {
            cout << "No";
            return 0;
        }
    } 
    if (((a[n - 1] ^ a[0]) != a[1]) || (a[n - 1] ^ a[n - 2]) != a[0]) {
        cout << "No";
    } else {
        cout << "Yes";
    }
}

Measured memory_bytes: 4224
N=int(input())
K=0
L=[0 for i in range(N)]
if N==1:
	print(1)
	exit()
for i in range(1,N+1):
	K+=i
	L[i-1]=1
	if K>=N:
		break
L[K-N-1]=0
for i in range(N):
	if L[i]==1:
		print(i+1)


Measured memory_bytes: 83096
import sys
import numpy as np
import numba
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

i4 = numba.int32

def get_input():
    D = int(readline())
    C = np.array(readline().split(), np.int32)
    S = np.array([readline().split() for _ in range(D)], np.int32)
    return D, C, S

@njit((i4, i4[:], i4[:, :], i4[:]), cache=True)
def first_computation(D, C, S, T):
    x = 0
    last = np.zeros((26, D), np.int32)
    for d in range(D):
        if d:
            last[:, d] = last[:, d - 1]
        i = T[d]
        x += S[d, i]
        last[i, d] = d + 1
        for i in range(26):
            x -= C[i] * (d + 1 - last[i, d])
    return last, x

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :], i4, i4), cache=True)
def difference_update(D, C, S, T, last_day, d, q):
    p = T[d]
    T[d] = q
    x = S[d, q] - S[d, p]

    i = np.searchsorted(last_day[p], d + 1)
    d_p = last_day[p, i - 1] if i >= 1 else 0
    coef = 0
    for k in range(d, D):
        if last_day[p, k] == d + 1:
            # k 日目に入るスコアの変更
            coef += d_p - d - 1
            last_day[p, k] = d_p
        else:
            break
    x += coef * C[p]

    coef = 0
    for k in range(d, D):
        if last_day[q, k] < d + 1:
            coef += (d + 1 - last_day[q, k])
            last_day[q, k] = d + 1
        else:
            break
    x += coef * C[q]
    return x

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :], i4), cache=True)
def swap_update(D, C, S, T, last_day, d):
    p = T[d]
    q = T[d + 1]
    if p == q:
        return 0
    x = difference_update(D, C, S, T, last_day, d, q)
    x += difference_update(D, C, S, T, last_day, d + 1, p)
    return x

def output(T):
    T += 1
    print(*T, sep='\n')

@njit((i4, i4[:], i4[:, :], i4[:], i4[:, :]), cache=True)
def random_update(D, C, S, T, last_days):
    d = np.random.randint(0, D, 1)[0]
    p = T[d]
    xcum = 0
    for q in range(26):
        if p == q:
            continue
        xcum += difference_update(D, C, S, T, last_days, d, q)
        if xcum > 0:
            return q, xcum
    difference_update(D, C, S, T, last_days, d, p)
    return p, 0

@njit((i4, i4[:], i4[:, :], i4[:], i4[:,:]), cache=True)
def main(D, C, S, T, last_days):
    for _ in range(10**5):
        d = np.random.randint(1, D-1, 1)[0]
        x = swap_update(D,C,S,T,last_days,d)
        if x < 0:
            swap_update(D,C,S,T,last_days,d)
    return T

def first_strategy(D, C, S):
    T = np.empty(D, np.int32)
    for d in range(D):
        T[d] = d % 26
    return T

D, C, S = get_input()

T = first_strategy(D, C, S)
last_days, score = first_computation(D, C, S, T)
T = main(D,C,S,T,last_days)
output(T)


Measured memory_bytes: 108132
#include <iostream>

using namespace std;

int primes[100];

int get_primes(int n) {
    int ret = 0;
    for (int i = 2; i <= n; i++) {
        bool flag = true;
        for (int j = 2; j <= i; j++) {
            if (i % j == 0 && i != j) {
                flag = false;
                break;
            }
        }
        if (flag) {
            primes[ret++] = i;
        }
    }
    return ret;
}

int main() {
    int n, cnt, ans = 0;
    int exps[100] = {0};

    cin >> n;

    cnt = get_primes(n);

    for (int i = 2; i <= n; i++) {
        int k = i;
        for (int j = 0; j < cnt; j++) {
            while (k % primes[j] == 0) {
                exps[j]++;
                k /= primes[j];
            }
        }
    }

    // p^74
    for (int i = 0; i < cnt; i++) {
        if (exps[i] >= 74) { ans++; }
    }

    for (int i = 0; i < cnt; i++) {
        for (int j = 0; j < cnt; j++) {
            if (i == j) { continue; }
            // p^2 * q^24
            if (exps[i] >= 2 && exps[j] >= 24) {
                ans++;
            }
            // p^4 * q^14
            if (exps[i] >= 4 && exps[j] >= 14) {
                ans++;
            }
        }
    }

    // p^2 * q^4 * r^4
    for (int i = 0; i < cnt; i++) {
        for (int j = 0; j < cnt; j++) {
            for (int k = j+1; k < cnt; k++) {
                if (i == j || i == k || j == k) { continue; }
                if (exps[i] >= 2 && exps[j] >= 4 && exps[k] >= 4) {
                     ans++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $s = <STDIN>);
my ($f, $c) = (0, 0);
my @p;
for my $i (0..length($s)-1) {
  if (substr($s, $i, 1) eq 'R') {
    if ($f == 1) {
      push @p, $c;
      $f = 0;
      $c = 0;
    }
  } else {
    if ($f == 0) {
      push @p, $c;
      $f = 1;
      $c = 0;
    }
  }
  $c++;
  push @p, $c if $i == length($s) - 1;
}
my @ans;
for my $i (0..length($s)-1) {
  $ans[$i] = 0;
}
my $pos = 0;
while (@p) {
  my $x = shift @p;
  my $y = shift @p;
  if (($x + $y) % 2 == 0) {
    $pos += $x;
    $ans[$pos-1] = ($x + $y) / 2;
    $ans[$pos] = ($x + $y) / 2;
    $pos += $y;
  } elsif ($x % 2 == 0) {
    $pos += $x;
    $ans[$pos-1] = int(($x + $y) / 2);
    $ans[$pos] = int(($x + $y) / 2) + 1;
    $pos += $y;
  } else {
    $pos += $x;
    $ans[$pos-1] = int(($x + $y) / 2) + 1;
    $ans[$pos] = int(($x + $y) / 2);
    $pos += $y;
  }
}
say join(' ', @ans);

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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define fWrite          freopen ("out.txt","w",stdout);
#define TC              int t;cin >> t;FOR(tc,1,t)
#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,LL>
#define all(a)          a.begin(),a.end()
#define MEM(a,x)        memset(a,x,sizeof(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

#define Make(x,p)       (x  (1<<p))
#define DeMake(x,p)     (x & ~(1<<p))
#define Check(x,p)      (x & (1<<p))
#define popcount(x)     __builtin_popcount(x)

int main()
{
    int n;
    cin >> n;
    LL arr[n+1]={0};
    FOR(i,1,n) {
        cin >> arr[i];
        arr[i]+=arr[i-1];
    }
    LL dp[n+1][n+1];
    MEM(dp,0);
    for(int right=2;right<=n;right++){
        for(int left=right-1;left>=1;left--){
            dp[left][right]=0x3f3f3f3f3f3f;
            for(int mid=left;mid<right;mid++){
                dp[left][right]=min(dp[left][right],dp[left][mid]+dp[mid+1][right]+(arr[right]-arr[left-1]));
            }
        }
    }
    cout << dp[1][n];
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
using namespace std;

long long dp[100][(int)1e5+5];

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

    int n,w,item[100][2];
    cin >> n >> w;
    for(int i = 0; i < n; i++) cin >> item[i][0] >> item[i][1];

    for(int i = item[0][0]; i <= w; i++) {
        dp[0][i] = item[0][1];
    }
    for(int i = 1; i < n; i++) {
        for(int j = 0; j < item[i][0]; j++) dp[i][j] = dp[i-1][j];
        for(int j = item[i][0]; j <= w; j++) {
            dp[i][j] = max(max(dp[i-1][j],dp[i][j-1]), dp[i-1][j-item[i][0]]+item[i][1]);
        }
    }

    cout << dp[n-1][w];
}

Measured memory_bytes: 78336
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_, b_ = [0], [0]

for i in range(n):
    a_.append(a_[i] + a[i])
for i in range(m):
    b_.append(b_[i] + b[i])

ans, j = 0, m

for i in range(n + 1):
    if a_[i] > k:
        break
    while b_[j] > k - a_[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47348
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort(key=int)
ans=0
for i in range(n):
  x=x-a[i]
  if x<0:
    x=x+a[i]
  else:
    ans+=1
if ans==n:
    if x>0:
        print(ans-1)
    else:
        print(ans)
else:
    print(ans)

Measured memory_bytes: 9188
#include <iostream>
#include <math.h>
using namespace std;

int main(){
int N;
cin>>N;
int X[N];
int hp=0;
int hpa=0;
for(int i=0;i<N;i++){cin>>X[i];}
for(int i=0;i<=100;i++){
for(int j=0;j<N;j++){
hpa+=pow(X[j]-i,2);
}
if(i==0){hp=hpa;}else{
hp=min(hp,hpa);
}
hpa=0;
}
  
cout<<hp;  
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt(), m = sc.nextInt(), q = sc.nextInt();
        int[][] lr = new int[m][2];
        int[][] pq = new int[q][2];

        for (int i = 0; i < m; i++) {
            lr[i][0] = sc.nextInt();
            lr[i][1] = sc.nextInt();
        }
        for (int i = 0; i < q; i++) {
            pq[i][0] = sc.nextInt();
            pq[i][1] = sc.nextInt();
        }
        int[][] board = new int[n + 2][n + 2];

        for (int i = 0; i < m; i++) {
            board[lr[i][1]][lr[i][0]] += 1;
        }

        for (int y = 1; y <= n; y++) for (int x = 1; x <= n; x++) {
            board[y][x] += board[y - 1][x] + board[y][x - 1] - board[y - 1][x - 1];
        }

        for (int i = 0; i < q; i++) {
            System.out.println(query(pq[i][0], pq[i][1], board));
        }
    }

    int query(int p, int q, int[][] board) {
        return board[q][q] - board[q][p - 1] - board[p - 1][q] + board[p - 1][p - 1];
    }

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

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


Measured memory_bytes: 165616
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a, b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  int cnt = 0;
  int bcnt = 0;
  rep(i,(int)s.size()){
    if(s[i]=='a' && cnt < a+b){
      cnt++;
      cout << "Yes" << endl;
    }else if(s[i] == 'b' && cnt < a+b && bcnt < b){
      cnt++;
      bcnt++;
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
	return 0;
}


Measured memory_bytes: 976
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    string S, T; cin >> S >> T;

    map<char, char> s_to_t, t_to_s;

    bool ok = true;
    for (int i = 0; i < S.size(); i++) {
        char s = S[i], t = T[i];

        if (s_to_t.count(s)) {
            if (s_to_t[s] != t) ok = false;
        }
        else s_to_t[s] = t;

        if (t_to_s.count(t)) {
            if (t_to_s[t] != s) ok = false;
        }
        else t_to_s[t] = s;
    }

    cout << (ok ? "Yes" : "No") << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3756
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

const int maxn=5e5+5;

int n,m;
ll f[maxn];
int pos[maxn],d[maxn];

int read() {
    int x=0,f=1;char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
    for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
    return x*f;
}

int main() {
    n=read(),pos[0]=read();
    for(int i=1;i<=n;i++) {
        d[i]=read();
        pos[i]=min(pos[i-1],abs(pos[i-1]-d[i]));
    }
    f[n+1]=1;
    for(int i=n;i;i--) {
        f[i]=f[i+1];
        if(d[i]<f[i]*2)f[i]+=d[i];
    }
    m=read();
    for(int i=1;i<=m;i++) {
        int id=read();
        if(pos[id-1]>=f[id+1])puts("YES");
        else puts("NO");
    }
    return 0;
}


Measured memory_bytes: 9728
#include "bits/stdc++.h"
using namespace std;

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

int main() {
	ll a, b;
	ll aa, bb;
	ll ans;
	cin >> a >> b;
	aa = (ll)a / 0.08;
	if (aa * 0.08 != a)aa++;
	bb = (ll)b / 0.1;
	if (bb * 0.1 != b)bb++;
	if (aa < bb) {
		while (1) {
			if ((ll)(bb * 0.08) < a)bb++;
			else if ((ll)(bb * 0.08) > a) {
				cout << -1 << endl;
				return 0;
			}
			else {
				ans = bb;
				break;
			}
			if ((ll)(bb * 0.1) != b) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	else {
		while (1) {
			if ((ll)(aa * 0.1) < b)aa++;
			else if ((ll)(aa * 0.1) > b) {
				cout << -1 << endl;
				return 0;
			}
			else {
				ans = aa;
				break;
			}
			if ((ll)(aa * 0.08) != a) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(A==B){
    cout << C << endl;
    return 0;
  }else if(B==C){
    cout << A << endl;
    return 0;
  }
  cout << B << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;

int main(){
long long int a,b,c,ans=0;
cin>>a>>b>>c;
ans=b/c-a/c;
if(a%c==0){
    ans++;
}
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll func(ll n){
    return (n+9)/10 * 10;
}
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll a[5];for(ll i=0;i<5;i++)cin>>a[i];
    ll ans = 0;
    for(ll i=0;i<5;i++)ans+=func(a[i]);
    ll mx=0;
    for(ll i=0;i<5;i++)mx=max(mx,func(a[i])-a[i]);
    cout<<ans-mx;
}





Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

vector<int> ds[80][80];
int A[80][80];
int B[80][80];
int main() {
	int H,W;
	cin >> H >> W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> A[i][j];
		}
	}
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> B[i][j];
		}
	}
	ds[0][0].push_back(abs(A[0][0]-B[0][0]));
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			int v=abs(A[i][j]-B[i][j]);
			int c=0;
			if(i>0){
				c+=ds[i-1][j].size();
			}
			if(j>0){
				c+=ds[i][j-1].size();
			}
			ds[i][j].reserve(2*c);
			if(i>0){
				for(auto d:ds[i-1][j]){
					ds[i][j].push_back(d+v);
					if(d-v>=0){
						ds[i][j].push_back(d-v);
					}
					else{
						ds[i][j].push_back(v-d);
					}
				}
			}
			if(j>0){
				for(auto d:ds[i][j-1]){
					ds[i][j].push_back(d+v);
					if(d-v>=0){
						ds[i][j].push_back(d-v);
					}
					else{
						ds[i][j].push_back(v-d);
					}
				}
			}

			sort(ds[i][j].begin(),ds[i][j].end());
			ds[i][j].resize(unique(ds[i][j].begin(),ds[i][j].end())-ds[i][j].begin());
			int u=80*((H-1-i)+(W-1-j));
			if(ds[i][j].back()>u){
				int s=1+lower_bound(ds[i][j].begin(),ds[i][j].end(),u)-ds[i][j].begin();
				if(s<ds[i][j].size()){
					ds[i][j].resize(s);
				}
			}
		}
	}
	int ret=1<<29;
	for(auto d:ds[H-1][W-1]){
		ret=min(ret,abs(d));
	}
	cout << ret << endl;
 
	return 0;
}


Measured memory_bytes: 254592
from bisect import bisect_left

N, M = map(int, input().split())
LRC = []

for _ in range(M) :
    L, R, C = map(int, input().split())
    LRC.append((L-1, R-1, C))
    
LRC.sort()
LRC.sort(key=lambda x: x[1])

cost_r = [0]
cost_v = [0]
for L, R, C in LRC :
    i = bisect_left(cost_r, L)
    if i == len(cost_r) :
        continue
    nc = cost_v[i] + C
    
    while nc < cost_v[-1] :
        cost_r.pop()
        cost_v.pop()
    
    if R > cost_r[-1] :
        cost_r.append(R)
        cost_v.append(nc)
    
if cost_r[-1] == N - 1 :
    print(cost_v[-1])
else :
    print(-1)

Measured memory_bytes: 73944
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int len = Integer.parseInt(scanner.nextLine());
        String inputs[] = scanner.nextLine().split(" ", -1);

        int numbers[] = new int[len];
        for (int i = 0; i < len; i++) {
            numbers[i] = Integer.parseInt(inputs[i]);
        }

        new Main().bubbleSort(numbers, len);
    }

    private void bubbleSort(int numbers[], int len) {
        int times = 0;
        boolean sorted = true;

        int i = 0; // count of sorted numbers
        while (sorted) {
            sorted = false;
            for (int j = len - 1; j > i; j--) {
                if (numbers[j - 1] > numbers[j]) {
                    int temp = numbers[j - 1];
                    numbers[j - 1] = numbers[j];
                    numbers[j] = temp;

                    times++;
                    sorted = true;
                }
            }
            i++;
        }

        for (i = 0; i < len; i++) {
            System.out.print(numbers[i]);
            if (i == len - 1) {
                System.out.print("\n");
            } else {
                System.out.print(" ");
            }
        }
        System.out.println(times);
    }
}



Measured memory_bytes: 26124
n = int(input())
ls = []
ls2 = []
count = 0
while count < n:
    ab = input().split()
    a, b = str(ab[0]), int(ab[1])
    ls.append([a, b])
    ls2.append([a, b])
    count = count + 1
ls2.sort(key=lambda x: x[1], reverse=True)
ls2.sort(key=lambda x: x[0])
ans = []
for s in ls2:
    for i, hoge in enumerate(ls):
        if hoge == s:
            ans.append(i+1)
for s in ans:
    print(s)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
if (a<b){
cout << "a < b" << endl;
}
else if (a > b){
cout << "a > b" << endl;
}
else if (a == b){
cout << "a == b" << endl;
}
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  vector<int> a(3);
  rep(i, 3) cin >> a[i];
  sort(a.begin(), a.end());
  int ans = a[1]-a[0] + a[2]-a[1];
  cout << ans << endl;
}
  

Measured memory_bytes: 3612
#include <bits/stdc++.h>
 
using namespace std;
#define md 1000000007
#define itn int
#define pb push_back
#define mp make_pair
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define all(x) x.begin(),x.end()
#define x first	
#define lb lower_bound
#define ub upper_bound
#define y second
#define sz(x) (int)x.size()
#define inf 1e9
#define endl '\n'
#define cuot cout
#define dbs long double
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define trace(v) for(auto it=v.begin();it!=v.end();it++)cerr<<*it<<" ";cerr<<endl;
#define linf 1e18
#define reset(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(int i=a;i<b;i++)
#define eps 1e-12
#define randomize srand(chrono::steady_clock::now().time_since_epoch().count());
	

void fastio(){	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
 
 
void solve(){
	ull ans = 0;
	ull p = 100;
	ull r = 1;
	ull x ;cin>>x;
	while(p<x){
		ull in = p/100;
		p+=in;
		ans++;
		// if(ans>4000)break;
	}
	cout<<ans<<endl;
}
 
int main(){
	fastio();
	#ifndef ONLINE_JUDGE 
  
    // For getting input from input.txt file 
    freopen("in.txt", "r", stdin); 
  
    // Printing the Output to output.txt file 
    freopen("out.txt", "w", stdout); 
  
	#endif 
	int t;	
	t=1;
	//cin>>t;
	for(int i=1;i<=t;i++){	
		// cout<<"Case #"<<i<<": ";
		solve();
	}	
	return 0;
}	

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;cin>>S;
  string ans="WA";
  bool ok=true;
  if(S[0]=='A'){
    int c=0;
    if(S[1]<'a')ok=false;
    for(int i=2; i<S.size()-1; i++){
      if(c==0&&S[i]=='C')c++;
      else if(S[i]<'a')ok=false;
    }
    if(S[S.size()-1]<'a')ok=false;
    if(c==1&&ok)ans="AC";
  }
  cout<<ans<<endl;
}


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

using namespace std;

int n, k, a[200000], dist, mx;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> k >> n >> a[0];
	for (int i = 1; i < n; ++i) {
		cin >> a[i];

		dist = a[i] - a[i - 1];
		mx = max(dist, mx);
	}

	dist = a[0] - a[n - 1] + k;
	mx = max(dist, mx);

	cout << k - mx << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <bitset>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"("<<(x).FI<<", "<<(x).SE<<")"<<endl;
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  ll N, K;
  cin >> N >> K;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];

  ll dig = 0, tmp = K;
  while (tmp > 0) tmp /= 2, dig++;

  vector<bool> grone(dig);
  REP(b, dig) {
    ll one = 0, zero = 0;
    REP(i, N) {
      if ((A[i] >> b) & 1LL) one++;
      else zero++;
    }
    if (zero > one) { grone[b] = true; }
  }

  ll X = 0;
  for (ll b = dig - 1; b >= 0; b--) {
    if (grone[b] && (X + (1LL << b)) <= K) {
      X += (1LL << b);
    }
  }
  ll ans = 0;
  REP(i, N) {
    ans += X^A[i];
  }
  cout << ans << endl;

  return 0;
}

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

int main(){
  
  int N;
  cin >> N;
  vector<string> S(N);
  
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    S[i] = s;
  }
  
  sort(S.begin(),S.end());
  
  S.push_back("");
  
  for(int i=0;i<N+1;i++){
  }
  
  long long ans = 0;
  long long sub = 0;
  
  for(int i=0;i<N;i++){
    if(S[i]==S[i+1]){
      sub++;
    }else{
      sub++;
      ans += sub*(sub-1)/2;
      sub = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6528
<?php
$sc = new Scanner();
$apple = $sc->nextInt();
$piece = $sc->nextInt();

$pieceCount = $apple * 3 + $piece;
$pieCount = floor($pieceCount / 2);
Out::println($pieCount);

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

class Out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}


Measured memory_bytes: 3956
#include <stdio.h>

int main(void)
{
        long long q, h, s, d, n;
        scanf("%lld%lld%lld%lld%lld", &q, &h, &s, &d, &n);

        long long x, y;
        x = q * 4 < h * 2 ? q * 4 : h * 2;
        y = x < s ? x : s;
        
        if (n % 2 == 0 && y * 2 > d) {
                printf("%lld\n", d * (n / 2));
        } else if (n % 2 == 0 && y * 2 < d) {
                printf("%lld\n", y * n);
        } else if (n % 2 != 0 && y * 2 > d) {
                printf("%lld\n", d * (n / 2) + y * (n % 2));
        } else if (n % 2 != 0 && y * 2 < d){
                printf("%lld\n", y * n);
        }
        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, a, b, c, d;
  cin >> N;
  a = N % 10;
  b = (N % 100 - a) / 10;
  c = (N % 1000 - a - b * 10) / 100;
  d = (N - a - b * 10 - c * 100) / 1000;
  if (d == c && c == b || c == b && b == a) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

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

  ll n;
  cin >> n;
  vector<ll> b(n);
  for(ll i = 0; i < n; i++) cin >> b[i];

  vector<ll> ans;
  for(ll i = 0; i < n; i++){
    bool ok = false;
    for(ll j = b.size(); j > 0; j--){
      if(b[j-1] == j){
        ans.pb(j);
        b.erase(b.begin()+j-1);
        ok = true;
        break;
      }
    }
    if(!ok){
      cout << -1 << endl;
      return 0;
    }
  }

  reverse(all(ans));
  for(auto a : ans) cout << a << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define M_PI           3.14159265358979323846  /* pi */
using namespace std;
using  ll = long long;

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

	if (N % N == 0&&(N)%2==0) {
		cout << N;
	}
	else
	cout << N * 2 << endl;
}

Measured memory_bytes: 3528
//
// Created by watemus on 03.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;

#ifdef LOCAL
#else
#endif


void run() {
    string s;
    cin >> s;
    if (s[1] == 'R') s[1] = 'B';
    else s[1] = 'R';
    cout << s << endl;
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
 
int main(void) 
{
    int n, count = 0, max = 0;
    scanf("%d", &n);
    int h[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &h[i]);
        if(i > 0) {
            if(h[i-1] >= h[i]) {
                count++;
            } else {
                if(max < count) {
                    max = count;
                }
                count = 0;
            }
        }
    }
    if(max < count) max = count;
    printf("%d\n", max);
    return 0;
}

// #include <stdio.h>

// int main(int argc, char const *argv[])
// {
// 	int N;
// 	int H[N];

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

// 	for (int i = 0; i < N; ++i)
// 	{
// 		scanf("%d", &H[i]);
// 	}


// 	int ans = 0;
// 	int count = 0;


// 	for (int i = N-1; i > 0; --i)
// 	{
// 		if (H[i] <= H[i-1])
// 		{
// 			count++;
// 			if ((i == 1) && (ans < count))
// 			{
// 				ans = count;
// 			}
// 		}

// 		else
// 		{
// 			if (ans < count)
// 			{
// 				ans = count;
// 			}

// 			count = 0;
// 		}

// 	}

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

// りゅうせいの解答1 実行時エラー
// void hikaku(int *h, int *a, int N)
// {
// 	int count = 0;
// 	for (int i = N-1; i > 0; --i)
// 	{
// 		if (h[i] <= h[i-1])
// 		{
// 			count++;
// 			if ((i == 1) && (*a < count))
// 			{
// 				*a = count;
// 			}
// 		}

// 		else
// 		{
// 			if (*a < count)
// 			{
// 				*a = count;
// 			}

// 			count = 0;
// 		}

// 	}
// }

// int main(int argc, char const *argv[])
// {
// 	int N;
// 	int H[MAX_N];

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

// 	for (int i = 0; i < N; ++i)
// 	{
// 		scanf("%d", &H[i]);
// 	}

// 	int ans = 0;

// 	hikaku(H, &ans, N);

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


// 	return 0;
// }

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<complex>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
typedef long long Int;
//typedef pair<Int, Int> P;
typedef long double Real;
typedef complex<Real> CP;
Int MOD2 = 998244353;
Int P = 200003;
Int order[200004];
Int cnt[200004];
Int cntr[200004];
Int sum, sqsum;
Int n, a;

Int mod_pow(Int x, Int a, Int m = MOD){
    if(a == 0)return 1;
    if(a % 2 == 1)return x * mod_pow(x, a - 1, m) % m;
    Int res = mod_pow(x, a / 2, m);
    return res * res % m;
}

Int inv(Int x, Int m = MOD){
    return mod_pow(x, m-2, m);
}

void _NTT(vector<Int> &a, vector<Int> &tmp, int l, int r, Int w = -1){
    if(r - l == 1)return;
    if(w == -1){
        w = mod_pow(3, (MOD2-1) / (r-l), MOD2);
    }
    int n = r - l;
    for(int i = 0;i < n/2;i++){
        tmp[l + i] = a[l + i * 2];
        tmp[l + n/2 + i] = a[l + i * 2 + 1];
    }
    _NTT(tmp, a, l, l + n / 2, w*w%MOD2);
    _NTT(tmp, a, l + n / 2, r, w*w%MOD2);

    Int wi = 1;
    for(int i = 0;i < n;i++){
        a[l+i] = tmp[l+i%(n/2)] + tmp[l+n/2+i%(n/2)] * wi;a[l+i] %= MOD2;
        wi = wi * w % MOD2;
    }
}

vector<Int> NTT(vector<Int> &a){
    vector<Int> res = a;
    vector<Int> tmp = a;
    _NTT(res, tmp, 0, a.size());
    return res;
}

vector<Int> InvNTT(vector<Int> &a){
    reverse(next(a.begin()), a.end());
    vector<Int> res = NTT(a);
    reverse(next(a.begin()), a.end());
    Int invn = inv(a.size(), MOD2);
    for(int i = 0;i < res.size();i++)res[i] = res[i] * invn % MOD2;
    return res;
}

vector<Int> conv(vector<Int> &a, vector<Int> &b){
    int n = a.size();
    auto A = NTT(a);
    auto B = NTT(b);
    for(int i = 0;i < n;i++)A[i] = A[i] * B[i] % MOD2;
    auto res = InvNTT(A);
    return res;
}

int main(){
    Int now = 1;
    bool ok = true;
    Int extra = 0;
    for(Int i = 0;i < P-1;i++){
        order[now] = i;
        now = now * 2 % P;
    }
    vector<Int> cnt(1 << 19, 0);
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> a;
        extra += a * a % P;
        if(a == 0)continue;
        cnt[order[a]] += 1;
    }
    auto CNT = NTT(cnt);
    for(auto &elem:CNT)elem = elem*elem % MOD2;
    auto result1 = InvNTT(CNT);
    Int mod2 = MOD2;
    MOD2 = 469762049;
    auto CNT2 = NTT(cnt);
    for(auto &elem:CNT2)elem = elem*elem % MOD2;
    auto result2 = InvNTT(CNT2);

    Int ans= 0;
    for(Int i = 0, now = 1;i < (1 << 19);i++){
        Int r1 = result1[i], r2 = result2[i];
        if(r1)
        while(r1 % MOD2 != r2)r1 += mod2;
        ans += now * r1;
        now = now * 2 % P;
    }
        
    ans -= extra;    
    cout << ans / 2<< endl;
    return 0;
}

Measured memory_bytes: 29008
N,W=map(int,input().split())
wv=[list(map(int,input().split())) for i in range(N)]
dp=[{} for i in range(N+1)]
dp[0][0]=0
for i in range(N):
    p=dp[i].keys()
    for w in p:
        dp[i+1][w]=dp[i][w]
    for w in p:
        wn=w+wv[i][0]
        if wn<=W and (wn not in dp[i+1] or dp[i+1][wn]<dp[i][w]+wv[i][1]):
                dp[i+1][wn]=dp[i][w]+wv[i][1]
print(max(dp[N].values()))

Measured memory_bytes: 9204
n,t = map(int, input().split())
k = [list(map(int, input().split())) for i in range(n)]
mincost=1000000

for i in range(n):
  if k[i][-1]<=t:
    cost=k[i][0]
    mincost=min(mincost,cost)
if mincost==1000000:
  print("TLE")
else:
  print(mincost)

Measured memory_bytes: 3060
n = gets.to_i
v = gets.split.map(&:to_i)
h = Hash.new(0)
g = Hash.new(0)
v.each_with_index do |x, i|
  if i % 2 ==0
    h[x] += 1
  else
    g[x] += 1
  end
end
if h.size == 1 && g.size == 1
  if h.keys == g.keys
    puts g.values[0]
  else
    puts "0"
  end
else
  ans = 0
  ch = 0
  ck = 0
  h.sort_by{|k, v| -v}.each do |kh, vh|
    g.sort_by{|k, v| -v}.each do |kg, vg|
      if kh != kg
        ans = vh + vg if ans < vh + vg
      end
      ck += 1
      break if ck > 2
    end
    ch += 1
    break if ch > 2  
  end
  puts n - ans
end

Measured memory_bytes: 25440
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;

void dfs(vi e[], int c[], int x, int p[], int sz[], int csz[], int lc2[]) {
    sz[x] = csz[x] = 1;
    int cp = lc2[c[x]];

    for (int y : e[x]) {
        if (y != p[x]) {
            lc2[c[x]] = y;
            p[y] = x;
            dfs(e, c, y, p, sz, csz, lc2);
            sz[x] += sz[y];
            csz[x] += sz[y];
        }
    }

    csz[cp] -= sz[x];
    lc2[c[x]] = cp;
}

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

    int n;
    cin >> n;
    int c[2*n];
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        c[i]--;
    }
    vi e[n];
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    int p[2*n];
    int lc2[n];
    int sz[n], csz[2*n];
    for (int i = 0; i < n; i++) {
        p[i+n] = i + n;
        c[i+n] = i;
        csz[i+n] = n;
        lc2[i] = i + n;
    }
    p[0] = -1;
    dfs(e, c, 0, p, sz, csz, lc2);

    ll ans[n];
    fill(ans, ans+n, 1ll * n * (n + 1) / 2);
    for (int i = 1; i < 2 * n; i++) {
        ans[c[p[i]]] -= 1ll * csz[i] * (csz[i] + 1) / 2;
    }

    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 48944
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  int cnt = 0;
  for (int i = 1; i < N; ++i) {
    if (S[i-1] != S[i]) ++cnt;
  }
  cout << cnt + 1 << endl;
}


Measured memory_bytes: 3716
namespace inonoa{
    class Ino{
        static void Main(){
            int n = int.Parse(System.Console.ReadLine());
            int ans = 0;
            int a = 0;
            int b=0;
            int ab = 0;
            for(int i=0;i<n;i++){
                char[] si = System.Console.ReadLine().ToCharArray();
                if(si[0]=='B'){b++;}
                if(si[si.Length-1]=='A'){a++;}
                if(si[0]=='B'&&si[si.Length-1]=='A'){ab++;}
                for(int j=0;j<si.Length-1;j++){
                    if(si[j]=='A'&&si[j+1]=='B'){ans++;}
                }
            }
            if(ab==a && ab==b && ab!=0){a--;b--;}
            if(a==n){a--;}
            if(b==n){b--;}
            if(a>b){ans += b;}
            else{ans += a;}
            System.Console.WriteLine(ans);

        }
    }
}

Measured memory_bytes: 13140
from collections import Counter as coun
from itertools import combinations as comb

import sys
input = sys.stdin.readline

N = int(input())
S = input()

C = coun(S)
ans = C["R"] * C["G"] * C["B"]
for i, j in comb(range(N), 2):
  k = 2 * j - i
  if k < N:
    A, B, C = S[i], S[j], S[k]
    if A != B and B != C and C != A: ans -= 1

print(ans)


Measured memory_bytes: 73780