akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 100010
using namespace std;
ll rint(){
	ll ret=0,uu=1;
	char c=getchar();
	while(!isdigit(c)&&c!='-') c=getchar();
	if(c=='-') uu=-1,c=getchar();
	while(isdigit(c)) ret=ret*10+(c-'0'),c=getchar();
	return ret*uu;
}
string rstr(){
	string ret;
	char buf[N];
	scanf("%s",&buf);
	return ret=buf;
}
char rchar(){
	char c=getchar();
	while(c==' '||c=='\n') c=getchar();
	return c;
}
double rdou(){
	double ret=0,uu=1,td=0.1;
	char c=getchar();
	while(!isdigit(c)&&c!='-') c=getchar();
	if(c=='-') uu=-1,c=getchar();
	while(isdigit(c)) ret=ret*10+(c-'0'),c=getchar();
	while(c=='.') c=getchar();
	while(isdigit(c)) ret=ret+(c-'0')*td,td/=10,c=getchar();
	return ret*uu;
}
ll n,m,dpin[N],dpout[N],fa[N];
vector<ll> vt[N];
void dfs1(ll x,ll lst)
{
	fa[x]=lst;
	ll i;
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=lst)
		{
			dfs1(vt[x][i],x);
			dpin[x]=(dpin[x]*dpin[vt[x][i]])%m;
		}
	}
	dpin[x]=(dpin[x]+1)%m;
	return;
}
void dfs2(ll x,ll val)
{
	ll i,j;
	vector<ll> prep,sufp;
	prep.push_back(1);
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=fa[x])
		{
			prep.push_back(dpin[vt[x][i]]);
			sufp.push_back(dpin[vt[x][i]]);
		}
	}
	sufp.push_back(1);
	for(i=1;i<prep.size();i++)
	{
		prep[i]=(prep[i-1]*prep[i])%m;
	}
	for(i=sufp.size()-2;i>=0;i--)
	{
		sufp[i]=(sufp[i+1]*sufp[i])%m;
	}
	dpout[x]=(val*sufp[0])%m;
	j=0;
	for(i=0;i<vt[x].size();i++)
	{
		if(vt[x][i]!=fa[x])
		{
			dfs2(vt[x][i],((((val*prep[j])%m)*sufp[j+1])%m+1)%m);
			j++;
		}
	}
	return;
}
int main(){
	ll i,x,y;
	n=rint();
	m=rint();
	for(i=1;i<n;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		vt[x].push_back(y);
		vt[y].push_back(x);
	}
	for(i=0;i<n;i++)
	{
		dpin[i]=dpout[i]=1;
	}
	dfs1(0,-1);
	dfs2(0,1);
	for(i=0;i<n;i++)
	{
		printf("%lld\n",dpout[i]);
	}
	return 0;
}

Measured memory_bytes: 24064
def alphas(key):
    value = {}
    for char in key:
        if value.get(char) is None:
            value[char] = 1
        else:
            value[char] += 1
    return value

def main():
    N = int(input())
    anagrams = []
    for i in range(N):
        s = input()
        anagrams.append(s)
    ans = 0
    dict = {}
    for key in anagrams:
        value = alphas(key)
        dict_key = str(sorted(value.items()))
        if dict.get(dict_key) is None:
            dict[dict_key] = 1
        else:
            dict[dict_key] += 1
        """
        for json_key in json.keys():
            if json[json_key] == value:
                ans += 1
                continue
        json[key] = value
        """
    for value in dict.values():
        ans += value * (value - 1) / 2
    print(int(ans))

if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  int c;
  if((a + b) % 2 != 0){
    c = (a + b) /2 + 1;
  }else{
    c = (a + b) / 2;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
  int n,m;
  cin>>n>>m;
  int cnt=0;
  vector<int> v(m);
  for(auto &it:v)cin>>it;
  sort(all(v));
  vector<int> diff(m-1);
  for(int i=0;i<m-1;i++){
	   diff[i]=v[i+1]-v[i]; 
	 }
   sort(all(diff));
   for(int i=0;i<m-n;i++)cnt+=diff[i];
   cout<<cnt<<endl;	
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int x;
  cin >> x;

  cout << (x<1200 ? "ABC" : "ARC") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace         std;
#define                 int long long
#define                 double long double
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<'\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector
#define die exit(0)
#define alln(arr) arr+1 , arr+1+n
using namespace __gnu_pbds;  
typedef tree<int, null_type, less<int>, rb_tree_tag,  
            tree_order_statistics_node_update> oset; 

int n,m,k,arr[N],brr[N];

bool check()
{
    int ct = 0;
    forn(i,1,n)ct+=(arr[i] == n);
    return ct != n;
}

void solve()
{
    cin>>n>>k;
    forn(i,1,n)cin>>arr[i];
    int ct = 0;
    while(check() and k--)
    {
        ct++;
        st(brr,0);
        forn(i,1,n)
        {
            int l = max(1LL,i-arr[i]);
            int r = min(n,i+arr[i]);
            brr[l]++;
            brr[r+1]--;
        }

        forn(i,1,n)
        {
            brr[i]+=brr[i-1];
            arr[i] = brr[i];
            arr[i] = min(n,arr[i]);
            //cout<<arr[i]<<" ";
        }
        //nl;



    }
    forn(i,1,n)cout<<arr[i]<<" ";

    //cout<<ct<<"\n";
}


signed main() 
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
    int t = 1;
    //cin>>t;
    forn(i,1,t)
    {
        solve();
        nl;
    }



    return 0;

}

//       clang++ c.cpp ; ./a.out < a.txt ;  

Measured memory_bytes: 13132
#pragma GCC optimize("O3")
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(ll i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
}
int main()
{
    vok();
    int a,b,c,k;
    IN a>>b>>c>>k;
    int ans=0;
    ans+=min(a,k);
    k-=min(a,k);
    k-=min(b,k);
    ans-=min(c,k);
    OUT ans<<endl
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>

using namespace std;

int main() {
  int K;
  // cin >> K;
  scanf("%d", &K);

  int A, B;
  // cin >> A >> B;
  scanf("%d %d", &A, &B);

  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }

  cout << "NG" << endl;
  return 0;
}
 


Measured memory_bytes: 3136
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdio>
#define inf 0x3f3f3f3f
#define debug cout<<"debug_________"<<endl
using namespace std;
const int maxn=4e3+50;
int n;
char c[maxn];
int a[maxn];
int b[maxn];
int w[maxn];
int dp[maxn][maxn];
int count_b,count_w;
int costb[maxn][maxn];
int costw[maxn][maxn];
int main(){
    while(scanf("%d",&n)!=EOF){
    for(int i=0;i<(n<<1);i++){
        getchar();
        scanf("%c %d",&c[i],&a[i]);
        a[i]--;
        if(c[i]=='W') w[a[i]]=i;
        else b[a[i]]=i;
    }
    for(int i=0;i<n;i++){
        count_b=count_w=0;
        for(int j=0;j<i;j++){
            if(b[j]>b[i]) count_b++;
            if(w[j]>w[i]) count_w++;
        }
        costw[i][0]=count_w;///i for w ,j for b
        costb[i][0]=count_b;
    }
    //-----------------------
        costw[0][0]=costb[0][0]=0;
        for(int i=0;i<n;i++){
            count_b=costb[i][0];
            count_w=costw[i][0];
            for(int j=0;j<n;j++){
                if(w[j]>b[i]) count_b++;
                if(b[j]>w[i]) count_w++;
                costb[i][j+1]=count_b;
                costw[i][j+1]=count_w;
            }
        }
        dp[0][0]=0;
        for(int i=1;i<=n;i++){
            dp[i][0]=dp[i-1][0]+costw[i-1][0];
            dp[0][i]=dp[0][i-1]+costb[i-1][0];
        }
        //-------------------
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            dp[i][j]=min(dp[i-1][j]+costw[i-1][j],dp[i][j-1]+costb[j-1][i]);
        printf("%d\n",dp[n][n]);
    }
    return 0;
}


Measured memory_bytes: 100096
X = int(input())

_range = int(pow(X,1/5))
for i in range(-2*_range-1,2*_range+2):
  for j in range(-2*_range-1,2*_range+2):
    if pow(i,5) - pow(j,5) == X:
      ans_a = i
      ans_b = j
      break
      
print(ans_a,ans_b)

Measured memory_bytes: 9316
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

using ll = long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n) for(ll i=0;i<(n);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//static const ll MOD = 1000000007;
//static const ll INF = 1000000000;
//#define PI 3.14159265359

int main() {
    // input
    ll X;
    cin >> X;

    // process
    ll ans = 8;
    if (400 <= X && X <= 599) {
        ans = 8;
    } else if (600 <= X && X <= 799) {
        ans = 7;
    } else if (800 <= X && X <= 999) {
        ans = 6;
    } else if (1000 <= X && X <= 1199) {
        ans = 5;
    } else if (1200 <= X && X <= 1399) {
        ans = 4;
    } else if (1400 <= X && X <= 1599) {
        ans = 3;
    } else if (1600 <= X && X <= 1799) {
        ans = 2;
    } else if (1800 <= X && X <= 1999) {
        ans = 1;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 3192
/*
      author  : nishi5451
      created : 14.08.2020 21:19:00
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int a,b;
    cin >> a >> b;
    for(int i=1; i<100000; i++){
        if(a==i*8/100 && b==i*10/100){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <cassert>
using namespace std; typedef long long ll; const int MINF=-1e9; typedef pair<int,int> P;

int main() {
  ll x,y; cin>>x>>y;
  ll an=2e9+1;
  for(ll i=-1;i<=1;i+=2) {
    for(ll j=-1;j<=1;j+=2) {
      if (x * i <= y * j)
        an=min(an,(i==-1)+(j==-1)+abs(y*j-x*i));
    }
  }
  cout<<an<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main() {
	int n, k, a, ans = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a;
		ans += 2 * min(a, k - a);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n;cin>>n;
    ll cnt=0;
    rep(i,n){
        ll a;cin>>a;
        if(a%2&&i%2==0)cnt++;

    }
    cout<<cnt<<endl;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A[] = new long[N];
		for (int i=0;i<N;i++) {
			A[i] = sc.nextLong();
		}
		Arrays.parallelSort(A);
		long sum =0;
		sum +=A[N-1];
		for (int i=N-2;i>=N/2;i--) {
			sum +=2*A[i];
		}
		if (N%2==1) {
			sum -=A[N/2];
		}
		System.out.println(sum);
	}

}

Measured memory_bytes: 61272
using System;
using System.Collections.Generic;
using System.Linq;

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var list = new List<string[]>();
            double sum = 0;

            for(var i=0; i<N; ++i)
            {
                list.Add(Console.ReadLine().Split(' '));
                var a = double.Parse(list[i][0]);

                if (list[i][1] == "BTC")
                {
                    sum += a * 380000.0;
                }
                else
                {
                    sum += a;
                }
            }
            Console.WriteLine(sum);
        }
        
    }
}


Measured memory_bytes: 13268
s=list(input())
t=list(input())
ans = len(t)
for i in range(len(s)-len(t)+1):
  comp = s[i:i+len(t)]
  tmp = 0
  for j in range(len(t)):
    if comp[j] == t[j]:
      tmp += 1
  ans = min(ans,len(t)-tmp)
print(ans)



Measured memory_bytes: 9128
import math
from collections import Counter

def mycounter(d,i):
    if i in d:
        d[i]+=1
    else:
        d[i]=1
    return d
    
def ABC159D(a):
    if a<2:
        return 0
    else:
        return (a*(a-1))//2

n=int(input())
a=list(map(int,input().split()))
d = dict()
#for i in a:
#    d=mycounter(d,i)
dd=Counter(a)
#print(d)
p=0
for i in dd.values():p+=ABC159D(i)
print('\n'.join(map(str,[p-dd[i]+1 for i in a])))

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

int main()
{
    int n;
    cin >> n;
    int a[n];
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n-1; i++){
        int cnt = 1;
        while(a[i] == a[i+1] && i < n - 1){
            cnt++;
            i++;
        }
        ans += cnt/2;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,i;
	double den=0,num=1,a[100];;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf",&a[i]);
		num*=a[i];
	}
	for(i=0;i<n;i++){
		den+=num/a[i];
	}
	printf("%lf",num/den);
	return 0;
}

Measured memory_bytes: 1700
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var n = ulong.Parse(System.Console.ReadLine());
        var a = System.Console.ReadLine().Split(' ').Select(ulong.Parse).ToList();

        a = a.OrderByDescending(x => x).ToList();

        ulong kokochi = 0;

        var lst = new List<ulong>();

        if(n == 0)
        {
            System.Console.WriteLine(0);
            return;
        }

        for(int i = 1; i < a.Count / 2 + a.Count % 2; i++)
        {
            kokochi += a[i - 1];
        }

        if(a.Count % 2 == 1)
        {
            for (int i = 1; i < a.Count / 2 + a.Count % 2; i++)
            {
                kokochi += a[i];
            }
        }
        else
        {
            for (int i = 1; i < a.Count / 2 + a.Count % 2; i++)
            {
                kokochi += a[i];
            }
            kokochi += a[a.Count / 2 - 1];
        }

        System.Console.WriteLine(kokochi);

    }
}

Measured memory_bytes: 52932
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

void solve(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    vector<int>v(n);
    int cnt=0;
    for(int i=n;i>0;--i){
        int b=a[i-1];
        for(int j=i;j<=n;j+=i){
            b^=v[j-1];
        }
        v[i-1]=b;
        if(v[i-1]==1)++cnt;
    }
    cout<<cnt<<"\n";
    rep(i,n)if(v[i])cout<<i+1<<" ";
    if(cnt)cout<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 2560
#define _CRT_SECURE_NO_WARNINGS

#pragma GCC optimize("O3")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cstring>
#include <numeric>
#include <set>
#include <queue>
#include <deque>
#include <array>
#include <string>
#include <cmath>
#include <random>
#include <ctime>
#include <map>
#include <functional>
#include <bitset>
#include <complex>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>

#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()
#define pb push_back

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;

struct segTree {
	int n;
	vector<ll> t;
	segTree(int n) : n(n), t(2 * n, 0) {}
	void upd(int v, ll x) {
		t[v += n] = x;
		for (v >>= 1; v; v >>= 1) {
			t[v] = max(t[v << 1], t[v << 1 | 1]);
		}
	}
	ll get(int l, int r) {
		ll ret = 0;
		for (l += n, r += n; l <= r; l = (l + 1) >> 1, r = (r - 1) >> 1) {
			if (l & 1) {
				ret = max(ret, t[l]);
			}
			if (!(r & 1)) {
				ret = max(ret, t[r]);
			}
		}
		return ret;
	}
};

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vi h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		h[i]--;
	}
	vi a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	segTree t(n);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ll cur = a[i] + t.get(0, h[i]);
		ans = max(ans, cur);
		t.upd(h[i], cur);
	}
	cout << ans;
}


Measured memory_bytes: 4992
import Data.List
import qualified Data.ByteString.Char8 as B
main=do
  n<-readLn::IO Int
  as<-sort.zipWith (flip (-)) [1..].unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
  print.minimum.map (f as) $ [as !! (max 0 (n`div`2 - 1)), as !! (n `div` 2), as !! (min (n-1) (n `div` 2 + 1))]

f as m = sum.map abs.map ((-) m) $ as


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

using namespace std;

int main()
{
  string S;
  cin>>S;

  int ans = 0;
  int a = 0;
  int b = 0;
  for(char e : S){
    a = e - 'A';
    if(a - b <= 0){
      ++ans;
    }
    b = e - 'A';
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 100005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
pii st[4*N+1][2];
pii l[N],r[N];
int n;
pii merge(pii a,pii b,int c){
	vector<int>v;
	v.pb(a.fi);v.pb(a.se);
	v.pb(b.fi);v.pb(b.se);
	sort(v.begin(), v.end());
	if(c)return pii(v[0],v[1]);
	else return pii(v[3],v[2]);
}
void update(int i,int l,int r,int x,int v,int c){
	if(l==r){
		st[i][c].fi=v;
		if(c)st[i][c].se=n+1;
		else st[i][c].se=0;
		return;
	}
	if(mid(l,r)>=x)update(2*i+1,l,mid(l,r),x,v,c);
	else update(2*i+2,mid(l,r)+1,r,x,v,c);
	//if(c)st[i][c]=min(st[2*i+1][c],st[2*i+2][c]);
	//else st[i][c]=max(st[2*i+1][c],st[2*i+2][c]);
	st[i][c]=merge(st[2*i+1][c],st[2*i+2][c],c);
}
pii qry(int i,int l,int r,int l1,int r1,int c){
	if(r<l1||r1<l){
		if(c)return pii(n+1,n+1);
		else return pii(0,0);
	}
	if(l1<=l&&r<=r1)return st[i][c];
	pii q1=qry(2*i+1,l,mid(l,r),l1,r1,c);
	pii q2=qry(2*i+2,mid(l,r)+1,r,l1,r1,c);
	//cout<<q1<<" "<<q2<<" "<<l<<" "<<r<<"\n";
	return merge(q1,q2,c);
}
void solve(){
	cin>>n;
	ll int a[n+2];
	rep(i,n){
		cin>>a[i+1];
	}
	for(int i=n+1;i;i--)update(0,0,n+1,i,n+1,1);
	for(int i=n;i;i--){
		r[i]=qry(0,0,n+1,a[i]+1,n+1,1);
		update(0,0,n+1,a[i],i,1);
		//cout<<r[i]<<" "<<i<<"\n";
	}
	for(int i=1;i<=n;i++){
		l[i]=qry(0,0,n+1,a[i]+1,n+1,0);
		update(0,0,n+1,a[i],i,0);
		//cout<<l[i]<<" "<<i<<"\n";
	}
	r[n+1]=pii(n+1,n+1);
	l[0]=pii(0,0);
	ll ans=0;
	for(ll int i=1;i<=n;i++){
		ll int l1=l[i].fi;
		ll int ll1=l[i].se;
		ll int r1=r[i].fi;
		ll int rr1=r[i].se;
		ll cnt=(l1-ll1)*(r1-i)+(i-l1)*(rr1-r1);
		ans+=cnt*a[i];
		//cout<<cnt<<" "<<ll1<<" "<<l1<<" "<<i<<" "<<r1<<" "<<rr1<<"\n";
	}
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double PI=3.1415926535897932;
const double LIT=0.000000001;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define PRO(a,b) a=(a*b)%mod


const ll TOOBIG=1e18;

int main(){
    ll K;
    ll A,B,C; cin>>A>>B>>C>>K;
    if(K%2) cout<<B-A<<endl;
    else cout<<A-B<<endl;
    

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define zahyoutype double
#define EPS 1e-3
typedef struct Point{zahyoutype x,y;}P;
zahyoutype crossproduct(P p,P q,P o){return (p.x-o.x)*(q.y-o.y)-(p.y-o.y)*(q.x-o.x);}

int jisho(const void*p,const void*q){
	P *pp=(P*)p,*qq=(P*)q;
	if(pp->y<qq->y)return -1;
	if(pp->y>qq->y)return  1;
	return pp->x>qq->x;
}
P base;
int anticlockwise(const void*p,const void*q){
	P *pp=(P*)p,*qq=(P*)q;
	double diff=atan2(pp->y-base.y,pp->x-base.x)-atan2(qq->y-base.y,qq->x-base.x);
	return diff<0?-1:diff>0;
}
int totuhou(P*p,int cnt,P*ans){
	{zahyoutype x=1;if(x/2==0){puts("type error");exit(0);}}
	
	if(cnt<=2)return cnt;
	int flag=0;
	for(int i=2;i<cnt;i++)if(fabs(crossproduct(p[i],p[1],p[0]))>0.5)flag=i;
	if(flag==0){
		//一直線
		for(int i=0;i<cnt;i++)ans[i]=p[i];
		qsort(ans,cnt,sizeof(P),jisho);
		return cnt;
		//ans[1]=ans[cnt-1];return 2;
	}
	
	P*temp=malloc((cnt+1)*sizeof(P));
	base.x=(p[0].x+p[1].x+p[flag].x)/3;
	base.y=(p[0].y+p[1].y+p[flag].y)/3;
	for(int i=0;i<cnt;i++)temp[i]=p[i];
	//半時計回りにソート
	qsort(temp,cnt,sizeof(P),anticlockwise);
	//左下の点を選ぶ
	P m={1e10,1e10};
	int mi;
	for(int i=0;i<cnt;i++)if(temp[i].y<m.y||temp[i].y==m.y&&temp[i].x<m.x)m=temp[mi=i];
	
	ans[0]=temp[mi];
	ans[1]=temp[(mi+1)%cnt];
	int anscnt=2;
	for(int i=2;i<=cnt;i++){
		ans[anscnt++]=temp[(mi+i)%cnt];
		while(anscnt>2&&  crossproduct(ans[anscnt-3],ans[anscnt-2],base)
						 +crossproduct(ans[anscnt-2],ans[anscnt-1],base)//↓+EPS
						<=crossproduct(ans[anscnt-3],ans[anscnt-1],base)-EPS){
			ans[anscnt-2]=ans[anscnt-1];
			anscnt--;
		}
	}

	return anscnt-1;
}

void readpoint(P*p){zahyoutype x=1;scanf(x/2?"%lf%lf":"%ld%ld",&p->x,&p->y);}
void printpoint(P p){zahyoutype x=1;printf(x/2?"%.f %.f\n":"%ld %ld\n",p.x,p.y);}

P a[100010],b[100010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)readpoint(a+i);
	int cnt=totuhou(a,n,b);
	printf("%d\n",cnt);
	for(int i=0;i<cnt;i++)printpoint(b[i]);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
int main()
{

int N;
long A,B,C;
cin>>N>>A>>B>>C;
vector<string>s(N);
for(int i=0;i<N;i++)
{cin>>s[i];}

vector<char>answer(N);

if(A+B+C==0){cout<<"No"<<endl;}
if(A+B+C==1)
{int boo=0;
for(int i=0;i<N;i++)
{
if(s[i]=="AB"){
if(A<B){A++;B--;answer[i]='A';}
else if(A>B){A--;B++;answer[i]='B';}
else if(A==B){cout<<"No"<<endl;boo++;break;}
}

if(s[i]=="BC"){
if(B<C){B++;C--;answer[i]='B';}
else if(B>C){B--;C++;answer[i]='C';}
else if(B==C){cout<<"No"<<endl;boo++;break;}
}

if(s[i]=="AC"){
if(C<A){C++;A--;answer[i]='C';}
else if(C>A){C--;A++;answer[i]='A';}
else if(C==A){cout<<"No"<<endl;boo++;break;}
}
}
if(boo==0){cout<<"Yes"<<endl;
for(int i=0;i<N;i++){cout<<answer[i]<<endl;}
}
}
if(A+B+C==2)
{int boo=0;
for(int i=0;i<N-1;i++)
{if(s[i]=="AB"){
if(A<B){A++;B--;answer[i]='A';}
else if(A>B){A--;B++;answer[i]='B';}
else if(A==B&&B==0){cout<<"No"<<endl;boo++;break;}
else if(A==B&&B==1){
if(s[i+1]=="AB"||s[i+1]=="BC"){A--;B++;answer[i]='B';}
else{A++;B--;answer[i]='A';}
}
}
if(s[i]=="BC"){
if(B<C){B++;C--;answer[i]='B';}
else if(B>C){B--;C++;answer[i]='C';}
else if(B==C&&C==0){cout<<"No"<<endl;boo++;break;}
else if(C==B&&B==1){
if(s[i+1]=="BC"||s[i+1]=="AC"){B--;C++;answer[i]='C';}
else{B++;C--;answer[i]='B';}
}
}
if(s[i]=="AC"){
if(C<A){C++;A--;answer[i]='C';}
else if(C>A){C--;A++;answer[i]='A';}
else if(A==C&&C==0){cout<<"No"<<endl;boo++;break;}
else if(A==C&&C==1){
if(s[i+1]=="AC"||s[i+1]=="AB"){C--;A++;answer[i]='A';}
else{C++;A--;answer[i]='C';}
}
}
}

if(s[N-1]=="AB")
{if(A==B&&B==0&&boo==0){boo++;cout<<"No"<<endl;}else if (A>B){answer[N-1]='B';}else{answer[N-1]='A';}}
if(s[N-1]=="BC")
{if(C==B&&B==0&&boo==0){boo++;cout<<"No"<<endl;}else if (B>C){answer[N-1]='C';}else{answer[N-1]='B';}}
if(s[N-1]=="AC")
{if(A==C&&C==0&&boo==0){boo++;cout<<"No"<<endl;}else if (C>A){answer[N-1]='A';}else{answer[N-1]='C';}}

if(boo==0){cout<<"Yes"<<endl;
for(int i=0;i<N;i++){cout<<answer[i]<<endl;}
}
}

if(A+B+C>2)

{int boo=0;
for(int i=0;i<N;i++)
{
if(s[i]=="AB"){
if(A<B){A++;B--;answer[i]='A';}
else if(A>B){A--;B++;answer[i]='B';}
else if(A==B&&B==0){cout<<"No"<<endl;boo++;break;}
else{A++;B--;answer[i]='A';}
}

if(s[i]=="BC"){
if(B<C){B++;C--;answer[i]='B';}
else if(B>C){B--;C++;answer[i]='C';}
else if(B==C&&C==0){cout<<"No"<<endl;boo++;break;}
else{B++;C--;answer[i]='B';}
}

if(s[i]=="AC"){
if(C<A){C++;A--;answer[i]='C';}
else if(C>A){C--;A++;answer[i]='A';}
else if(C==A&&A==0){cout<<"No"<<endl;boo++;break;}
else{C++;A--;answer[i]='C';}
}
}
if(boo==0){cout<<"Yes"<<endl;
for(int i=0;i<N;i++){cout<<answer[i]<<endl;}
}
}



}





Measured memory_bytes: 6408
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        long ans = 0L;
        String f = null, m = null, b = null;
        for (int i = 1; i < s.length(); i++) {
            if(s.charAt(0) != s.charAt(i)){
                f = s.substring(0, i);
                s = s.substring(i);
                break;
            }
        }
        if(f == null){
            long sum = s.length() * k;
            ans = sum / 2;
        }else{
            for (int i = 1; i < s.length(); i++) {
                if(s.charAt(s.length()-1) != s.charAt(s.length()-1-i)){
                    b = s.substring(s.length()-i);
                    m = s.substring(0, s.length()-i);
                    break;
                }else if(i == s.length()-1){
                    b = s;
                }
            }
            if(m == null){
                ans = ((f.length()/2) + (b.length()/2)) * k;
            }else{
                long mc = 0L, tmp = 1;
                for (int i = 1; i < m.length(); i++) {
                    if(m.charAt(i-1) == m.charAt(i)){
                        tmp++;
                    }else{
                        mc += tmp/2;
                        tmp = 1;
                    }
                }
                mc += tmp/2;
                if(f.charAt(0) == b.charAt(0)){
                    ans = mc * k;
                    ans += f.length()/2 + b.length()/2;
                    ans += ( (f.length() + b.length()) / 2 ) * (k-1);
                }else{
                    ans = ( (f.length()/2) + (b.length()/2) + mc ) * k;
                }
            }
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 35616
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

K = I()
A,B = LI()

ans = 'NG'
for i in range(A,B+1):
    if i%K == 0:
        ans = 'OK'

print(ans)

Measured memory_bytes: 65464
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var line = Console.ReadLine().Split(' ');

            var N = int.Parse(line[0]);
            var R = int.Parse(line[1]);

            var result = R;

            if (N <= 9)
            {

                Console.WriteLine(R + (100 * (10 - N)));
            }
            else
            {
                Console.WriteLine(R);
            }
        }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<math.h>
#include<vector>
#include<climits>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int *arr=new int[n];
  vector<int> dp(n,0);
  for(int i=0;i<n;++i)
  {
	cin>>arr[i];
  }
  
  dp[0]=0;
  for(int i=1;i<n;++i)
  {
    //cout<<"ar i="<<i+1<<endl;
    if(i-k>=0)
    {
        //cout<<"pre"<<endl;
      dp[i]=INT_MAX;
      for(int j=i-k;j<i;++j)
      {
		dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
      }
    }
    else
    {
       // cout<<"sart"<<endl;
      int sub=INT_MAX;
      for(int j=0;j<i;++j)
      {
        sub=min(sub,dp[j]+abs(arr[j]-arr[i]) );
      }
      dp[i]=sub;
    }
  }
  

  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1024
n, q = map(int, input().split())
l = [0]*n; u = [0]*n; lmin = n-2; umin = n-2; lgoal = n; ugoal = n
for _ in range(q):
    s, t = map(int, input().split())
    if s == 1:
        if t > ugoal: u[t-1] = 0
        else:
            for i in range(t, ugoal-1):u[i] = umin
            lmin = t-2; ugoal = t
    else:
        if t > lgoal: l[t-1] = 0
        else:
            for i in range(t, lgoal-1):l[i] = lmin
            umin = t-2; lgoal = t
print(sum(l)+sum(u)+lmin*umin)

Measured memory_bytes: 11964
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int n,a[200];
ll func[201],perm[201][201],sump[201],p10[801],dp[4][2][201][801];
ll mod=1e9+7;
int dig(int x){
	if(x<10) return 0;
	if(x<100) return 1;
	if(x<1000) return 2;
	return 3;
}
void add(ll &x,ll y){
	x+=y;
	if(x>=mod) x%=mod;
}
ll solve(){
	int cntd[4]={},sumd[4]={};
	rep(i,n) cntd[dig(a[i])]++;
	rep(i,n) sumd[dig(a[i])]+=a[i];
	rep(d,4){
		if(cntd[d]==0) continue;
		vector<int> vc;
		rep(i,4) rep(j,cntd[i]){
			if(i==d&&j==0) continue;
			vc.push_back(i+1);
		}
		dp[d][0][0][0]=1;
		rep(i,vc.size()){
			rep(j,vc.size()+1) rep(k,801) dp[d][1-i%2][j][k]=0;
			rep(j,vc.size()+1){
				rep(k,801){
					if(dp[d][i%2][j][k]==0) continue;
					add(dp[d][1-i%2][j][k],dp[d][i%2][j][k]);
					add(dp[d][1-i%2][j+1][k+vc[i]],dp[d][i%2][j][k]);
				}
			}
		}
	}
	ll ans=0;
	rep(d,4){
		if(cntd[d]==0) continue;
		rep(j,n) rep(k,801) add(ans,sumd[d]*dp[d][1-n%2][j][k]%mod*func[j]%mod*sump[n-1-j]%mod*p10[k]);
	}
	return ans;
}
int main(){
	func[0]=1;
	rep(i,200) func[i+1]=func[i]*(i+1)%mod;
	rep(i,201) perm[i][0]=1;
	rep(i,201) rep(j,i) perm[i][j+1]=perm[i][j]*(i-j)%mod;
	rep(i,201) rep(j,i+1) add(sump[i],perm[i][j]);
	p10[0]=1;
	rep(i,800) p10[i+1]=p10[i]*10%mod;
	cin>>n;
	rep(i,n) cin>>a[i];
	ll ans=solve();
	sort(a,a+n);
	if(a[0]==0){
		swap(a[n-1],a[0]);
		n--;
		rep(i,4) rep(j,2) rep(k,201) rep(l,801) dp[i][j][k][l]=0;
		ll mn=solve();
		ans=(ans-mn+mod)%mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 11608
n, a, b = map(int, input().split())
h_s = [int(input()) for _ in range(n)]

l = (min(h_s) - 1) // a + 1
r = (max(h_s) - 1) // b + 1

c = a - b
while l != r:
    pos = (l + r) // 2
    cnt = 0
    base = b * pos
    for h in h_s:
        rem = h - base
        cnt += max(0, (rem - 1) // c + 1)
    if cnt <= pos:
        r = pos
    else:
        l = pos + 1
print(r)

Measured memory_bytes: 12984
#include"bits/stdc++.h"
using namespace std;
int main(){
	int h,w;
	char str[101][101];
	int zikan[101][101];
	memset(zikan,-1,sizeof(zikan));
	//memset(str,"NULL",sizeof(str));
	cin>>h>>w;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>str[i][j];
			if(str[i][j]=='c')zikan[i][j]=0;
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(str[i][j]=='c'&&zikan[i][j]!=-1){
				for(int x=0;x+j<=w;x++){
					zikan[i][x+j]=x;
				}
			}
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cout<<zikan[i][j];
			if(j!=w)cout<<" ";
		}
		cout<<endl;
	}
}

Measured memory_bytes: 3148
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char * argv[]) {
    int h, w;
    string s;
    vector<string> v;
    
    cin >> h >> w;
    
    for (int i=0; i<h; i++) {
        cin >> s;
        v.push_back(s);
    }
    
    for (int i=0; i<w+2; i++) {
        cout << '#';
    }
    cout << endl;
    
    for (int i=0; i<h; i++) {
        cout << '#';
        cout << v[i];
        cout << '#' << endl;
    }
    
    for (int i=0; i<w+2; i++) {
        cout << '#';
    }
    cout << endl;
    
    return 0;
}


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

times = 0
if a == b and b == c and a % 2 == 0:
    print(-1)
else:
    while 1:
        if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
            break
        a, b, c = int((b + c)/2), int((c + a)/2), int((a + b)/2)
        times += 1

    print(times)

Measured memory_bytes: 9132
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ


signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));
    ll mxm=a[n-1],mnm=a[0];
    vector<P> ans;
    for(int i=n-2;i>0;i--){
        if(a[i]>0){
            ans.pb({mnm,a[i]});
            mnm-=a[i];
        }else{
            ans.pb({mxm,a[i]});
            mxm-=a[i];
        }
    }
    ans.pb({mxm,mnm});
    cout << mxm-mnm << endl;
    for(auto u:ans) cout << u.fi  << " " << u.se << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int N;
	cin>>N;
	int ma=0;
	int ans=0;
	rep(i,N){
		int h;cin>>h;
		if(ma<=h)ans++;
		chmax(ma,h);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
int a[111111];
int b[111111];
#define mod 1e9+7
signed main(){
	int n,m;
	cin>>n>>m;
	rep(0,i,m){
		cin>>a[i];
	}	
	b[0]=1;
	b[1]=1;
	rep(2,i,111111){
		b[i]=b[i-1]+b[i-2];
		b[i]=b[i]%1000000007;
	}
	if(m==0){
		c(b[n])
		return 0;
	}		
	int sum=b[a[0]-1];
	rep(1,i,m){
		sum=sum*b[a[i]-a[i-1]-2];
		sum=sum%1000000007;
		if(a[i]-a[i-1]==1){
			cout<<0<<endl;
			return 0;
		}	
	}
	sum=sum*(b[n-1-a[m-1]]);
	sum=sum%1000000007;
	c(sum)
}	

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int n,m,ans,a[100005],vis[100005];
int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]),vis[i]=1;
    while(m--)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        if(a[x]<=a[y])vis[x]=0;
        if(a[y]<=a[x])vis[y]=0;
    }
    for(int i=1;i<=n;i++)ans+=vis[i];
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 4536
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
inline void YES(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ll BIGP = 1000000007L;
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, X;
    cin >> N >> X;
    ll cur = 0;
    ll ans = 0;
    rep(i, N)
    {
        if (cur <= X)
        {
            ++ans;
        }
        ll L;
        cin >> L;
        cur += L;
    }
    if (cur <= X)
    {
        ++ans;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;
public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();//入力される数
        int[] inx = new int[N];
        int[] iny = new int[N];
        int[] inh = new int[N];
        int H = 0;
        int Cx = 0;
        int Cy = 0;
        int w;
        int temp = 0;
        int flag;
        int memo = 0;

        for(int i = 0;i<N;i++){
            inx[i] = scan.nextInt();
            iny[i] = scan.nextInt();
            inh[i] = scan.nextInt();
            if(inh[i] != 0){memo = i;}
        }

        for(int k = 0;k<=100;k++){
            for(int r = 0;r <= 100;r++){
                flag = 1;
                temp = getH(inx[memo],iny[memo],k,r,inh[memo]);

                for(int s = 0;s < N;s++) {
                    w = getH(inx[s], iny[s], k, r, inh[s]);
                    if (temp != w) {
                        if(inh[s] == 0 && temp <= w){
                            continue;
                        }
                        flag = -1;
                        break;
                    }
                }
                if(flag == 1) {
                    Cx = k;
                    Cy = r;
                    H = temp;
                }
            }

        }

        System.out.println(Cx + " " + Cy + " " +H);

    }

    public static int getH(int x,int y,int Cx,int Cy,int h){
        int t = x - Cx > 0 ? x - Cx:Cx - x;
        int u = y - Cy > 0 ? y - Cy:Cy - y;
        int H = h + t + u;
        if(h >= 0){
            return H;
        }else{
            return 0;
        }
    }
}


Measured memory_bytes: 24148
import math

N = int(input())
A = list(map(int,input().split()))

num = [0] * N

for i in A:
    num[i - 1] = num[i - 1] + 1

a = [0] * N
b = [0] * N

for i in range(N):
    if num[i] >= 2:
        a[i] = (num[i] - 1) * (num[i] - 2) // 2
        b[i] = num[i] - 1

sum_a = sum(a)
sum_b = sum(b)

for i in A:
    print(sum_a + sum_b - b[i - 1])

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

//正解者の範囲
struct Range{
  int L,R;

  //照準そーとのための比較関数
  bool operator<(const Range &another) const{
    if(L == another.L) return R < another.R;
    return L < another.L;
  }

};

//範囲を昇順に並べ境界をずらしていく(境界の左が1回目のコンテスト問題，右が2回目のコンテスト問題)
//コーナーケースとして最大の範囲一つとそれ以外
int main(void){
  //入力
  int N;
  cin >> N;
  vector<Range> ranges(N);
  for(int i = 0; i < N; ++i){
    int L,R;
    cin >> L >> R;
    ++R;
    ranges[i] = {L,R};
  }
  sort(ranges.begin(),ranges.end());

  //前方累積重複範囲
  vector<Range> fwd(N+1);
  fwd[0] = {1, (int)1e9+1};
  for(int i = 0; i < N; ++i){
    fwd[i+1] = {
      max( ranges[i].L, fwd[i].L),
      max( ranges[i].L, min( ranges[i].R, fwd[i].R ) )
    };
  }

  //後方累積重複範囲
  vector<Range> bak(N+1);
  bak[N] = {1, (int)1e9+1};
  for(int i = N-1; i >= 0; --i){
    bak[i] = {
      max( ranges[i].L, bak[i+1].L),
      max( ranges[i].L, min( ranges[i].R, bak[i+1].R ) )
    };
  }

  //コーナーケースを初期値とする．
  int joy = 0;
  for(int i = 0; i < N; ++i){
    //最大の範囲を取る
    joy = max(joy,ranges[i].R-ranges[i].L);
  }
  joy += fwd[N].R-fwd[N].L;

  //境界を見ていく．
  for(int i = 1; i < N; ++i){
    joy = max(joy, 
        fwd[i].R-fwd[i].L + bak[i].R-bak[i].L);
  }

  //出力
  cout << joy << endl;
  return 0;
}


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

using namespace std;

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 20000;//ここを問題の制約を見ながらいじる．配列の確保に使う．
//ll P[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//ll dp[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//string S[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//int B[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
//double Perf[NM];

ll MOD = 1000000007;
int digit_length(int num)
{
    int count = 0;
    while (num) {
        num = num / 10;
        ++count;
    }
    return count;
}


ll gcd(ll a, ll b) {
    ll v0 = a, v1 = b, v2 = a % b;
    while (v2 != 0) {
        v0 = v1;
        v1 = v2;
        v2 = v0 % v1;
    };
    return v1;
}


// mod. m での a の逆元 a^{-1} を計算する
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;
}

//ll lcm(ll a, ll b) {
//    return a / (gcd(a, b) % MOD) * (b % MOD);
//}

ll lcm(ll a, ll b) {
    return( (a % MOD) *modinv(gcd(a, b), MOD) * (b % MOD)) % MOD;
}
       // Main program


void solve() {
    ll  N;
    cin >> N;
    string Stemp;
    bool flag = true;
    std::map<string , int> count;
    ll maxcnt = 0;

    for (ll i = 0; i < N; i++) {
        cin >> Stemp;

        count[Stemp]++;
        if (maxcnt < count[Stemp]) {
            maxcnt = count[Stemp];
        }
    }

    for (auto itr = count.begin(); itr != count.end(); ++itr) {
        if (itr->second == maxcnt) {
            cout << itr->first << endl;
        }
    }

    return;

}



int main() {
    solve();
    return 0;
}







Measured memory_bytes: 23808
#include<stdio.h>

int main(){
  int x,y,s,i,j,max,a,b,box[2001],box2[2001];
  while(1){
    max=0;
    scanf("%d %d %d",&x,&y,&s);
    if(x==0&&y==0&&s==0)
      break;
    for(i=0;i<=2000;i++)
      box[i]=box2[i]=0;
    for(i=1;i<=s;i++){
      box[i]=i*(100+x)/100;
      box2[box[i]]=i;
    }
    for(i=1;i<s;i++){
      if(box2[i]!=0&&box2[s-i]!=0)
        if(box2[i]*(100+y)/100+box2[s-i]*(100+y)/100>max)
          max=box2[i]*(100+y)/100+box2[s-i]*(100+y)/100;
    }
    printf("%d\n",max);
  }
}



Measured memory_bytes: 2060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	cout << n * (n + 1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
kane = 1000
kabu = 0
for i in range(1, n):
  if a[i] > a[i-1]:
    kabu = kane // a[i-1]
    kane = kane - kabu*a[i-1]
    kane = kane + kabu*a[i]
    kabu = 0
print(kane)

Measured memory_bytes: 9188