akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=(a);i<=(int)(n);++i)
#define lpd(i,a,n) for(int i=(a);i>=(int)(n);--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n;
mii f;

int main(){
    readi(n);
    lp(i,1,n){
        int x;
        readi(x);
        ++f[x];
    }

    int ans = 0;
    for(pii p : f) ans += p.s & 1;
    cout <<ans;
}

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


Measured memory_bytes: 4864
#include <iostream>
using namespace std;
typedef long long ll;
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 f(ll x, int c, int d) {
	ll res = x;
	res -= x / c;
	res -= x / d;
	res += x / lcm(c, d);
	return res;
}
int main() {
	ll a, b;
	int c, d;
	cin >> a >> b >> c >> d;
	ll ans = f(b, c, d) - f(a - 1, c, d);
	cout << ans << endl;
	return 0;
}


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

const int maxn=1e3+10;
int n,m,a,b;
char s[maxn][maxn];

int main(){
	cin>>n>>m>>a>>b;
	for(int i=1;i<=n;++i)for(int j=1;j<=m;++j)s[i][j]='.';
	if(n>=3&&m>=3&&n*m%2==1&&a>=2&&b>=2&&((m/2-a)&1)){
		s[n-2][m-2]='<';s[n-2][m-1]='>';s[n-2][m]='^';
		s[n-1][m-2]='^';s[n-1][m]='v';
		s[n][m-2]='v';s[n][m-1]='<';s[n][m]='>';
		a-=2;
		b-=2;
	}
	if(m&1){
		int y=2;
		while(b&&y<=n){
			if(s[y-1][m]=='.'&&s[y][m]=='.'){
				s[y-1][m]='^';
				s[y][m]='v';
				--b;
			}
			y+=2;
		}
	}
	int x=m/2*2-1,y=2;
	if(n>1)
		while(b){
			if(y>n)
				x-=2,y=2;
			if(x<=0)
				break;
			if(s[y-1][x+1]=='.'&&s[y][x+1]=='.'){
				s[y-1][x+1]='^';
				s[y][x+1]='v';
				--b;
			}
			else{
				if(s[y-1][x]=='.'&&s[y][x]=='.'){
					s[y-1][x]='^';
					s[y][x]='v';
					--b;
				}
				y+=2;
			}
		}
	if(b){
		puts("NO");
		return 0;
	}
	for(int i=1;i<=n&&a;++i)
		for(int j=1;a&&j+1<=m&&s[i][j]=='.'&&s[i][j+1]=='.';j+=2){
			s[i][j]='<';s[i][j+1]='>';
			--a;
		}
	if(a){
		puts("NO");
		return 0;
	}
	puts("YES");
	for(int i=1;i<=n;++i,puts(""))
		for(int j=1;j<=m;++j)
			putchar(s[i][j]);
	return 0;
}


Measured memory_bytes: 2176
#include<stdio.h>
int main(){
    int n, a[200000];
	long long cnt = 0;
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
    for(int i=1;i<n;i++){
    	if(a[i] < a[i-1]){
            cnt += a[i-1] - a[i];
            a[i] = a[i-1];
        }
	} 
    printf("%lld\n", cnt);
    return 0;
}

Measured memory_bytes: 2512
#!/usr/bin/env pypy3

import collections


def prepare_str(s, queries):
    flip = False
    dq = collections.deque(s)
    for qid, fc in queries:
        if qid == 1:
            flip = not flip
        else:
            f = int(fc[0])
            c = fc[1]
            if flip:
                f = 3 - f
            if f == 1:
                dq.appendleft(c)
            else:
                dq.append(c)
    if flip:
        res = "".join(reversed(dq))
    else:
        res = "".join(dq)
    return res


def main():
    s = input()
    q = int(input())
    queries = []
    for _ in range(q):
        ps = input().split()
        qid = int(ps[0])
        fc = tuple(ps[1:])
        queries.append((qid, fc))
    res = prepare_str(s, queries)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 120792
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>



using namespace std;

int x,y;


int main(){
    cin >> x >> y;
    for(int i=0;i<=x;i++){
        if(y == 2*i + 4*(x-i)){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(c-(a+b)>0){
    cout<<b+a+b+1<<endl;
  }else{
    cout<<b+c<<endl;
  }
}

Measured memory_bytes: 256
n, m = map(int, input().split())
h = [int(_) for _ in input().split()]

elevation = {}
for _ in range(len(h)):
    elevation[_+1] = h[_]

obs = list([] for _ in range(len(h)))
for i in range(m):
    obsA, obsB = map(int, input().split())
    if elevation[obsA] == elevation[obsB]:  # elevation[obsA]のvalueをリストにしてTrue追加
        obs[obsA-1].append(0)  # 1==True, 0==False
        obs[obsB-1].append(0)
    elif elevation[obsA] > elevation[obsB]:
        obs[obsA-1].append(1)
        obs[obsB-1].append(0)
    elif elevation[obsA] < elevation[obsB]:
        obs[obsA-1].append(0)
        obs[obsB-1].append(1)

count = 0
for o in obs:  # obsの各リストでTrueの展望台の数をカウント
    if all(o):  # all()は空のリストでもTrueを返す
        count += 1

print(count)
# print(elevation)
# print(obs)

Measured memory_bytes: 31708
#include "bits/stdc++.h"

using namespace std;

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const long long MOD = 1e9 + 7;
const long long  INF = 5e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int n;
double x, y;
int b, p;

int main() {
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> x >> y >> b >> p;
		double ans = 1000010;
		for (int j = b;j < 10;j++) {
			for (int k = p;k < 10;k++) {
				if (j >= 5 && k >= 2)ans = min(ans, (x*(double)j + y * (double)k)*0.8);
				else ans = min(ans, x*j + y * k);
			}
		}
		cout << ans << endl;
	}
	return 0;
}




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

struct start { start() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(10);
}; }start;

typedef long long ll;


int main(){
    int n;
    cin >> n;
    
    int a[n];
    rep(i,0,n){
        cin >> a[i];
    }
    
    rep(i,0,n){
        if(i == 0){
            cout << a[n-1];
        }
        else{
            cout << " " << a[n-1-i];
        }
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int n;
int fir[100010],nxt[200010],to[200010];
long long w[200010],z;
int cnt;
int x,y;
int a[100010];

void dfs(int x,int f,long long vi){
	if(vi%2==0) a[x]=0;
	else a[x]=1;
	for(int i=fir[x];i;i=nxt[i]){
		if(to[i]==f) continue;
		dfs(to[i],x,vi+w[i]);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d %d %lld",&x,&y,&z);
		to[++cnt]=y,nxt[cnt]=fir[x],fir[x]=cnt,w[cnt]=z;
		to[++cnt]=x,nxt[cnt]=fir[y],fir[y]=cnt,w[cnt]=z;
	}
	dfs(1,0,0);
	for(int i=1;i<=n;i++){
		printf("%d\n",a[i]);
	}
	
	return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}


// n要素で初期化
void init(int par[], int rank[], int n){
    for(int i=0;i<n;i++){
        par[i] = i;
        rank[i] = 0;
    }
}

// 木の根を求める
int find(int par[], int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par,par[x]);
    }
}

// xとyの属する集合を併合
void unite(int par[], int rank[], int x, int y){
    x = find(par,x);
    y = find(par,y);
    if(x == y) return;

    if(rank[x] < rank[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same(int par[], int x, int y){
    return find(par,x) == find(par,y);
}

int main() {
    int n,m;
    cin >> n >> m;
    int par[n+1];
    int rank[n+1];

    init(par,rank,n+1);

    rep(i,m){
        int x,y,z;
        cin >> x >> y >> z;
        unite(par,rank,x,y);
    }


    ll ans = 0;

    int count[n+1];
    rep(i,n+1){
        count[i] = find(par,i);
    }
    sort(count,count+(n+1));

    ans++;
    srep(i,2,n+1){
        if(count[i]!=count[i-1])ans++;
    }

    
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<vector>

using namespace std;

int n,m,flag;
#define maxn 200008
vector<int> V[maxn];

void find(int fi,int se,int cnt)
{
	if(fi==se&&cnt==2)
	{
		flag=1;
		return ;
	}
	else if(cnt==2) return;
	for(int i=0;i<V[fi].size();i++)
		find(V[fi][i],se,cnt+1);
}

int main(void)
{
	//freopen("datain.txt","r",stdin);
	int i,j,k;
	int x,y,cnt;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++)
	{
		scanf("%d%d",&x,&y);
		V[x].push_back(y);
	}
	flag=0;
	find(1,n,0);
	if(flag) cout<<"POSSIBLE"<<endl;
	else cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

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

int a;
int main(void){
    long long T,i,j,n,m,l,r,ok,a,b,ans,cnt;
    string s;

    cin>>s;
    if(s.size()%2) {
        printf("No\n");
        return 0;
    }
    ok=1;
    for(i=0;s[i];i++){
        if(i&1) {
            if(s[i]=='i') ;
            else ok = 0;
        }
        else {
            if(s[i]=='h') ;
            else ok = 0;
        }
    }
    if(ok){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
}


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

int main(){
  
  cout << setprecision(30) << setiosflags(ios::fixed);
  
  long long int N,K;
  cin>>N>>K;
  vector<long long int> P(N);
  for(long int i=0;i<N;i++)cin>>P[i];
  long double E[200010];
  E[0]=0.0;
  for(long int i=0;i<N;i++){
    E[i+1]=E[i]+(P[i]+1.0) /2.0;
  }
  long double Max=0.0;
  for(long int i=0,j=K; j<N+1; i++,j++){
    Max=max(Max,E[j]-E[i]);
  }
  cout<<Max<<endl;
}


Measured memory_bytes: 4992
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}


		public static void main(String[] args) {
			Scanner scan=new Scanner(System.in);
			int a=scan.nextInt();
			int b=scan.nextInt();
			int c[]=new int[a];
			long cnt=0;
			for(int i=0;i<a;i++) c[i]=scan.nextInt();
			if(c[0]>b) {
				cnt+=c[0]-b;
				c[0]=b;
			}
			for(int i=0;i<a-1;i++) {
				int d=c[i]+c[i+1];
				if(d>b) {
					int e=d-b;
					cnt+=e;
					c[i+1]-=e;
				}
			}
			System.out.println(cnt);
		}
}

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

S=[A[0]]
for i in range(1,N):
  S.append(S[i-1]+A[i])
#print(S)

T=[0]*(N-1)
for i in range(N-1):
  if S[i]*2>=A[i+1]:
    T[i]=1
#print(T)

ans=1
for t in T:
  if t==0:
    ans=1
  else:
    ans+=1
print(ans)

Measured memory_bytes: 14320
fun main(args: Array<String>) {
    // Your code here!
    var bingo1h:MutableMap<Int,Boolean> = mutableMapOf()
    var bingo2h:MutableMap<Int,Boolean> = mutableMapOf()
    var bingo3h:MutableMap<Int,Boolean> = mutableMapOf()
    var numList:MutableList<Int> = mutableListOf()
    var checkList:MutableList<Boolean> = mutableListOf()
    var msg = "No"
    
    get(bingo1h)
    get(bingo2h)
    get(bingo3h)
    
    var n = readLine()!!.toInt()
    
    for(i in 0..n-1){
        numList.add(readLine()!!.toInt())
    }
    
    for(i in 0..n-1){
        var num = numList[i]
        if(bingo1h.containsKey(num)){ bingo1h.set(num,true)}
        if(bingo2h.containsKey(num)){ bingo2h.set(num,true)}
        if(bingo3h.containsKey(num)){ bingo3h.set(num,true)}
    }
    
    for(i in 0..2){
        checkList.add(check("v",bingo1h.values.toList(),bingo2h.values.toList(),bingo3h.values.toList()))
        checkList.add(check("h",bingo1h.values.toList(),bingo2h.values.toList(),bingo3h.values.toList()))
        checkList.add(check("s",bingo1h.values.toList(),bingo2h.values.toList(),bingo3h.values.toList()))
    }
    
    var cnt = checkList.filter{it}.count() 
    if(cnt > 0){msg = "Yes"}
    print(msg)
}

//横判定、縦判定、斜め判定
fun check(str:String,ivList1:List<Boolean>,ivList2:List<Boolean>,ivList3:List<Boolean>):Boolean{
    var chk = false
    
    if(str == "h"){
        if(ivList1[0] && ivList1[1] && ivList1[2]){
            chk = true
            return chk
        }
        if(ivList2[0] && ivList2[1] && ivList2[2]){
            chk = true
            return chk
        }
        if(ivList3[0] && ivList3[1] && ivList3[2]){
            chk = true
            return chk
        }
    }else if(str == "v"){
        if(ivList1[0] && ivList2[0] && ivList3[0]){
            chk = true
            return chk
        }
        if(ivList1[1] && ivList2[1] && ivList3[1]){
            chk = true
            return chk
        }
        if(ivList1[2] && ivList2[2] && ivList3[2]){
            chk = true
            return chk
        }
        
    }else{
        if(ivList1[0] && ivList2[1] && ivList3[2]){
            chk = true
            return chk
        }
        if(ivList1[2] && ivList2[1] && ivList3[0]){
            chk = true
            return chk
        }

    }
    return chk
}

// ビンゴ取得
fun get(imap:MutableMap<Int,Boolean>){
    var line = readLine()!!.split(" ").map{it.toInt()}
    for(i in 0..2){
        imap.put(line[i],false)
    }
}

Measured memory_bytes: 38032
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n-1):
    if a[i] == i+1:
        a[i], a[i+1] = a[i+1], a[i]
        cnt += 1
if a[n-1] == n:
    cnt += 1
print(cnt)

Measured memory_bytes: 53136
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
const int maxn = 5e5 + 50;
typedef pair<int, int> P;

void solve();
int main()
{
	int t = 1;
//	cin >> t;
	for(int i=0; i<t; i++)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

// type below

void solve()
{
	int a, b; cin >> a >> b;
	set<int> S;
	for(int i=0; i<b; i++)
	{
		int tmp; cin >> tmp;
		S.insert(tmp);
	}
	int ans = 0;
	for(int i=1; i<=1000; i++)
	{
		if(S.count(i)) continue;
		if(abs(a - i) < abs(a - ans))
		{
			ans = i;
		}
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3636
q = int(input())
l, r = [0]*q, [0]*q
for i in range(q):
    l[i], r[i] = map(int, input().split())

MAX = 101010
is_prime = [1]*MAX
is_prime[0] = 0
is_prime[1] = 0
for i in range(2,MAX):
    if not is_prime[i]: 
        continue
    for j in range(i*2, MAX, i):
        is_prime[j] = 0

a = [0]*MAX
for i in range(1,MAX,2):  # ,,2
    # if i%2 == 0: 
    #     continue
    if is_prime[i] and is_prime[(i+1)//2]: 
        a[i] = 1

s = [0]*(MAX+1)
for i in range(MAX): 
    s[i+1] = s[i] + a[i]

for i in range(q):
    print(s[r[i]+1]-s[l[i]])

Measured memory_bytes: 16392
//package AtCoder;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		int s=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			s=s+a[i];
		}
		s=(s/n)+((s%n==0)?0:1);
		int n1=s;
		int n2=s-1;
		int cost1=0,cost2=0;
		for(int i=0;i<n;i++)
		{
			cost1=cost1+(int)Math.pow((n1-a[i]),2);
			cost2=cost2+(int)Math.pow((n2-a[i]),2);
			
		}
		int cost=Math.min(cost1, cost2);
		System.out.println(cost);

	}

}


Measured memory_bytes: 23892
using System;

class program
{
    public static void Main()
    {
        while (true)
        {
            var str = Console.ReadLine().Split(' ');
            var H = int.Parse(str[0]);
            var W = int.Parse(str[1]);

            if (H == 0 && W == 0) break;

            for (int height = 0; height < H; height++)
            {
                for (int width = 0; width < W; width++)
                {
                    Console.Write('#');
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 19544
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <unordered_map>
#include <functional>
#include <bitset>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>
 
//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>
 
#include <string>
 
const int MAX_N = 18;
int N;
std::string S;

std::map<std::pair<std::string, std::string>, long long> mp;

int main(int argc, char **argv) {
    std::cin >> N;
    std::cin >> S;

    for (int i = 0; i < (1 << N); i++) {
        std::bitset<MAX_N> bs(i);
        std::string backR, backB;
        for (int j = 0; j < N; j++) {
            if (bs.test(j)) {
                backR.push_back(S[N+j]);
            } else {
                backB.push_back(S[N+j]);
            }
        }
        mp[std::pair<std::string, std::string>({backR, backB})]++;
    }

    long long ret = 0;

    for (int i = 0; i < (1 << N); i++) {
        std::bitset<MAX_N> bs(i);
        std::string frontR, frontB;
        for (int j = 0; j < N; j++) {
            if (bs.test(j)) {
                frontR.push_back(S[j]);
            } else {
                frontB.push_back(S[j]);
            }
        }
        std::reverse(frontR.begin(), frontR.end());
        std::reverse(frontB.begin(), frontB.end());

        ret += mp[std::pair<std::string, std::string>({frontB, frontR})];
        ret = ret;
    }

    std::cout << ret << std::endl;
    
    return 0;
}

Measured memory_bytes: 87040
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vvi dp(n + 1, vi(2, 0));
    for (int i = 1; i <= n; ++i) {
        dp[i][0] = dp[i - 1][0] + stoi(s.substr(i - 1, 1));
        if (i == 1)
            dp[i][1] = stoi(s.substr(i - 1, 1)) - 1;
        else {
            dp[i][1] = max(dp[i - 1][1] + 9, dp[i - 1][0] + stoi(s.substr(i - 1, 1)) - 1);
        }
    }
    cout << max(dp[n][0], dp[n][1]) << "\n";
    return 0;
}

Measured memory_bytes: 256
// D - RGB Triplets
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
long long ng,r,g,b;

int main(){
	int N; string S; cin>>N>>S;
	rep(i, N) rep(d, N){
		int j = i + d, k = j + d;
		if(k >= N) break;
		if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) ng++;
	}
	for(auto s:S) s=='R'? r++: s=='G'? g++: b++;
	cout<< r*g*b - ng <<endl;
}

Measured memory_bytes: 3636
n = int(input())
rt = n
def sums(st: str):
  return sums(st[:-1])+int(st[-1]) if len(st) >1 else int(st)
for a in range(1,n//2):
  b = n - a
  tmp = sums(str(b)) + sums(str(a))
  if tmp < rt:
    rt = tmp
print(rt)

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

int main(void){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    if (A+B > C+D) {
        cout << "Left" << endl;
    }
    else if (A+B < C+D) {
        cout << "Right" << endl;
    }
    else cout << "Balanced" << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

struct UnionFind {
    vll par;

    UnionFind(ll N) : par(N) {
        rep(i, N) par[i] = i;
    }

    ll root(ll x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main()
{
    ll N, K; cin >> N >> K;
    vll A(N); rep(i, N) cin >> A[i], A[i]--;
    vll visited(N, -1);
    vll path{0};
    visited[0] = 0;
    ll index = 0;
    rep(i, N) {
        // i: how many times takahashi teleport
        if (i == K) {
            cout << index + 1 << endl;
            return 0;
        }
        if (index == A[index]) {
            cout << index + 1 << endl;
            return 0;
        }

        //cout << "i: " << i << endl;

        // do teleport
        index = A[index];

        if (visited[index] >= 0) {
            // find loop
            ll base = visited[index];
            ll loop_range = i + 1 - base;
            // cout << "i: " << i << endl;
            // cout << "base: " << base << endl;
            // cout << "loop_range: " << loop_range << endl;
            cout << path[((K - base) % (loop_range)) + base] + 1 << endl;
            return 0;
        } else {
            visited[index] = i + 1;
            path.push_back(index);
            // cout << "visited:: ";
            // for (auto elem : visited) cout << elem << " "; cout << endl;
            // cout << "path:: ";
            // for (auto elem : path) cout << elem << " "; cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 8496
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = int.Parse(line[0]);
        var t = int.Parse(line[1]);
        var r = int.Parse(line[2]);
        var ans = (double)t * r / a;
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 17948
#include <bits/stdc++.h>
using namespace std;
int main(){
  double N,M;
  cin>>N>>M;
  vector<int>kaza(N);
  for(int i=0;i<N;i++){
    cin>>kaza.at(i);
  }
  double j1=1/(4*M);
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=kaza.at(i);
  }
  double j2=sum*j1;
  int count=0;
  for(int i=0;i<N;i++){
    if(kaza.at(i)<j2){
    }
    else{
      count++;
    }
  }
  if(count<M){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n) for(ll i=0;i<(n);i++)
#define For1(i,n) for(ll i=1;i<(n);i++)
int main(){
    ll n;cin>>n;
    vector<vector<ll>> a(n,vector<ll> (n-1));
    For(i,n){
        For(j,n-1){
            cin>>a.at(i).at(j);a.at(i).at(j)--;
        }
        reverse(a.at(i).begin(),a.at(i).end());
    }
    ll ans=0,vs=0;
    while(true){
        vector<int> match(n,0);
        ll end=0;
        For(i,n){
            end+=a.at(i).size();
            if(a.at(i).size()==0) match.at(i)++;
        }
        if(end==0)break;
        For(i,n){
            if(match.at(i)==0&&match.at(a.at(i).at(a.at(i).size()-1))==0){
               if(a.at(a.at(i).at(a.at(i).size()-1)).at(a.at(a.at(i).at(a.at(i).size()-1)).size()-1)==i){
                   match.at(a.at(i).at(a.at(i).size()-1))++;a.at(a.at(i).at(a.at(i).size()-1)).pop_back();
                   match.at(i)++;a.at(i).pop_back();
                   vs++;
                }
            }
        }
        int flag=0;
        For(i,n){
            if(match.at(i)>0)flag++;
        }
        if(flag==0){
            cout<<-1<<endl;
            return 0;
        }
        ans++;
        if(ans==vs&&ans>10000){
            cout<<(n*(n-1))/2<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    ll N, T; cin >> N >> T;
    vector<ll> t(N);
    for(int i=0; i<N; i++) cin >> t[i];

    ll ans = 0;
    for(int i=1; i<N; i++) ans += min(T, t[i]-t[i-1]);
    ans += T;

    cout << ans << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
using namespace std;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
const int MOD = 1000000007;
int A[100];
int dp[101][100001];
int main() {
  int in(N); int in(K);
  rep(i, N) cin >> A[i];

  dp[0][0] = 1;
  vector<int> sum(K+2, 1);
  sum[0] = 0;
  rep(i, N) {
    vector<int> sum2(K+2, 0);
    rep(j, K+1) {
      dp[i+1][j] = (MOD + sum[j+1] - sum[max(0,j-A[i])]) % MOD;
      sum2[j+1] = (sum2[j] + dp[i+1][j]) % MOD;
    }
    swap(sum, sum2);
  }


  cout << dp[N][K] << endl;

  return 0;
}


Measured memory_bytes: 40056
def solve(D, G, P, C):
    ret = float('inf')
    for i in range(pow(2, D)):
        tmp_score = 0
        tmp_counter = 0
        not_selected = -1

        for j in range(D):
            if i >> j & 1:
                tmp_counter += P[j]
                tmp_score += P[j] * 100 * (j + 1) + C[j]
            else:
                not_selected = j

        if G <= tmp_score:
            ret = min(ret, tmp_counter)
            continue

        for _ in range(1, P[not_selected]):
            tmp_score += 100 * (not_selected + 1)
            tmp_counter += 1
            if G <= tmp_score:
                ret = min(ret, tmp_counter)
                break

    print(ret)

if __name__ == "__main__":
    D, G = map(int, input().split())
    P = []
    C = []

    for _ in range(D):
        p, c = map(int, input().split())
        P.append(p)
        C.append(c)

    solve(D, G, P, C)

Measured memory_bytes: 41072
import java.util.Scanner;

// ALDS1_1_D
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r, p = 0, max = 1 - 1000000000;
		for (int i = 0; i < n; i++) {
			r = sc.nextInt();
			if (i == 0) {
				p = r;
			} else {
				if (max < r - p) max = r - p;
				if (r < p) p = r;
			}
		}
		System.out.println(max);
	}
}



Measured memory_bytes: 99432
#include <bits/stdc++.h>
using namespace std;
int main(){
	
	string s;
	cin>>s;
	for(int i=0; i<s.length(); i++)
		if(s[i]=='9')
		{
			cout<<"Yes";
			return 0;
		}
	
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include<stack>
#include<iomanip>
#include<cstdint>
#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int atcoder(){
    int a,b,c;
  	cin>>a>>b>>c;
  	cout<<(c/a)*b<<ENT;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(N - M + 1):
  for j in range(N - M + 1):
    if A[i][j:j + M] == B[0]:
      for k in range(1, M):
        if A[i + k][j:j + M] != B[k]:
          break
      else:
        print('Yes')
        exit()
        
print('No')

Measured memory_bytes: 9144
import numpy as np
n, m, c = map(int, input().split())
B = np.array(list(map(int, input().split())))
A = np.array([list(map(int, input().split())) for _ in range(n)])
p = 0
for a in A:
    if np.dot(a, B)+c > 0: p += 1
print(p)

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

int main(){
  long long A, B; cin >> A >> B;
  bool odd = (A & 1 == 1);

  if(A == B){
    cout << A << endl;
  }else{
    if(odd) ++A;

    long long ans = 0;
    if((B - A + 1) & 1 == 1) ans ^= B;

    if((B-A+1)/2 & 1 == 1) ans ^= 1;

    if(odd) ans ^= (A-1);

    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include <string>
typedef unsigned long long ull;
int main(){
    ull a,b,x;
    std::cin>>a>>b>>x;
    ull k = a/x;
    ull K = x*(k+1);
    if(a%x==0){
        ull range = b-a;
        std::cout<<range/x+1<<std::endl;
    }
    else if(K >= a && K <= b){
        ull range = b-K;
        std::cout<<range/x+1<<std::endl;
    }
    else{
        std::cout<<0<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
/* A reward a Carpenter */
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException err){
			err.printStackTrace();
		}
	}

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		String line = in.readLine();		
		int n = Integer.parseInt(line);
		node[] nodes1 = new node[n];
		node[] nodes2 = new node[n];
		for(int i=0; i<n; i++){
			nodes1[i] = new node();
			nodes2[i] = new node();
		}

		line = in.readLine();
		int m = Integer.parseInt(line);

		for(int i=0; i<m; i++){
			line = in.readLine();
			String[] dst = line.trim().split(",");
			int from = Integer.parseInt(dst[0])-1;
			int to = Integer.parseInt(dst[1])-1;
			int fee1 = Integer.parseInt(dst[2]);
			int fee2 = Integer.parseInt(dst[3]);
			
			nodes1[from].add_edge(to, fee1);
			nodes1[to].add_edge(from, fee2);
			nodes2[from].add_edge(to, fee1);
			nodes2[to].add_edge(from, fee2);
		}

		line = in.readLine();
		String dst[] = line.split(",");
		int start = Integer.parseInt(dst[0])-1;
		int goal  = Integer.parseInt(dst[1])-1;
		int money = Integer.parseInt(dst[2]);
		int cost  = Integer.parseInt(dst[3]);
		
		int min_cost_to = get_min_cost(nodes1, start, goal);
		int min_cost_from = get_min_cost(nodes2, goal, start);
		
		int reward = money - cost - min_cost_to - min_cost_from;
		System.out.println(reward);
	}
	
	public int get_min_cost(node[] nodes, int s, int g){
		nodes[s].cost = 0;
		while(true){
			node done = null;			
			for(int i=0; i<nodes.length; i++){
				if(nodes[i].visited == true || nodes[i].cost < 0){
					continue;
				}
				
				if(done == null || nodes[i].cost < done.cost){
					done = nodes[i];
				}
			}
			
			if(done == null){
				break;
			}
			
			done.visited = true;
			
			for(int i=0; i<done.edge_to.size(); i++){
				int to = done.edge_to.get(i);
				int cost = done.cost + done.edge_cost.get(i);
				if(nodes[to].cost < 0 || cost < nodes[to].cost){
					nodes[to].cost = cost;
				}				
			}			
		}
		
		return nodes[g].cost;
	}	
}

class node{
	List<Integer> edge_to;
	List<Integer> edge_cost;
	
	int cost;
	boolean visited;
	
	public node(){
		cost = -1;
		this.visited =false;
		edge_to = new ArrayList<Integer>();
		edge_cost = new ArrayList<Integer>();
	}
	
	public void add_edge(int to, int cost){
		edge_to.add(to);
		edge_cost.add(cost);
	}
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> p(n), c(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> c[i];
    rep(i,n) p[i]--;
    ll ans = -1e18;
    rep(si,n) {
        int x = si;
        vector<int> s;
        ll tot = 0;
        while (true) {
            x = p[x];
            s.push_back(c[x]);
            tot += c[x];
            if (x == si) break;
        }
        int l = s.size();
        ll t = 0;
        rep(i,l) {
            t += s[i];
            ll now = t;
            if (i+1 > k) break;
            if (tot > 0) {
                ll e = (k-(i+1))/l;
                now += tot*e;
            }
            ans = max(ans, now);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3732
#include<cstdio>
#include<map>
#include<cstdlib>
#include<cstring>
#include<utility>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U; typedef pair<int,int > P; typedef long long ll;
void inp();
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	//int n;scanf("%d",&n);for(int i=1;i<=n;i++)
	inp();
	return 0;
}
map<ll ,ll>mp;
void inp(){
	int n,x;scanf("%d",&n);
	for(int i =0;i<n;i++){
		scanf("%d",&x);
		if(mp.count(x))mp[x]++;
		else mp[x]=1;
	}
	ll a[2],cnt=0;
	for(auto it=mp.rbegin();it!=mp.rend()&&cnt<2;++it){
		//printf("%lld %lld\n",it->first,it->second);
		if(it->second>=2&&cnt<2){
			a[cnt++]=it->first;
			it->second-=2;
		}
		if(it->second>=2&&cnt<2){
			a[cnt++]=it->first;
			it->second-=2;
		}
	}
	if(cnt<2)puts("0");
	else printf("%lld\n",a[0]*a[1]);
}
//at81c.cc by xsthunder at Sun Aug 20 20:01:41 2017


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

int main(){
int n,x;
cin >> x >> n;
int maxdiff = 200;
int ans = 200;
int arr[102] = {};
for(int i=0;i<n;i++){
	int x;
	cin >> x;
	arr[x]=1;
}
int arr2[102-n]={};
for(int i = 0,j=0;i<102;i++){
	if(arr[i]==0){
		arr2[j]=i;
		j++;
	}
}	

for(int i=0;i<102-n;i++){
	if(abs(arr2[i]-x)<maxdiff){
       ans = arr2[i];
       maxdiff = abs(arr2[i]-x);
	}
}
cout << ans << endl;



return 0;
}

Measured memory_bytes: 3640
x=input()
xv=int(x)
n=len(x)

y=''
x1=str(int(x[0])+1)
z=''

for i in range(n):
	y=y+x[0]
	z=z+x1

yv=int(y)
zv=int(z)

if xv<=yv:
	res=yv
else:
	res=zv

print(res)

Measured memory_bytes: 3064
// Date: 2020-03-08

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int a[N], b[N], n, m, T;
int main() {
    FIO;
    cin >> n >> m >> T;
    int ma = inf, mb = inf;
    rep(i, 1, n) cin >> a[i], chkmin(ma, a[i]);
    rep(i, 1, m) cin >> b[i], chkmin(mb, b[i]);
    int ans = ma + mb;
    while(T--) {
        int x, y, c;
        cin >> x >> y >> c;
        chkmin(ans, a[x] + b[y] - c);
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,a,b;
int main()
{
    scanf("%d%d%d",&n,&a,&b);
    ll l=1LL*(n-1)*a+b,r=1LL*(n-1)*b+a;
    printf("%lld\n",max(0LL,r-l+1));
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(10) << ans << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


signed main(){
    int a,b,c;
    cin >> a >> b >> c;
    int mon = a*7+b;
    int ans = (c/mon)*7;
    c %= mon;
    if(c>a*7){
        ans += 7;
    }
    else{
        while(c>0){
            ans++;
            c -= a;
        }
    }
    print(ans)
    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



Measured memory_bytes: 3104
n,m=map(int,input().split())
a=[]
b=[]
for i in range(m):
    a1,b1=[int(i) for i in input().split()]
    a.append(a1)
    b.append(b1)
for i in range(1,n+1):
    print(a.count(i)+b.count(i))

Measured memory_bytes: 3060
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    private void run() {
        int n = sc.nextInt();
        int[] h = new int[n+1];
        h[n] = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int ans = 0;
        int cnt = 0;
        for (int i = 1; i < n+1; i++) {
            if (h[i-1] < h[i]) {
                ans = Math.max(ans, cnt);
                cnt = 0;
            } else {
                cnt++;
            }
        }
        System.out.println(ans);
    }
}



Measured memory_bytes: 49088
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long
using namespace std;

int main () {
    //clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<int> a,b;
    for (int i=0;i<n;i++) {
        int x;
        cin >> x;
        a.pb(x);
    }
    for (int i=0;i<n;i++) {
        int x;
        cin >> x;
        b.pb(x);
    }
    int ans = 0, ans2 = 0;
    vector<int> p,q;
    for (int i=1;i<=n;i++) p.pb(i);
    do {
        if (a == p) {
             break;
        }
        else ans++;
    } while (next_permutation(p.begin(), p.end()));
    for (int i=1;i<=n;i++) q.pb(i);
    do {
        if (b == q) {
             break;
        }
        else ans2++;
    } while (next_permutation(q.begin(), q.end()));

    cout << abs(ans - ans2);
    //cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

    int n;
    cin>>n;


    vl v(n);


    forn(i,0,n)
    {
        cin>>v[i];
        v[i] = 2*v[i];
    }

    bool val = 1;

    ll total = 0;
    
    forn(i,0,n-1)
    {
        if(val) total += v[i];
        else total -= v[i];
        val = !val;
    }

    vl v1(n);
    v1[0] = (total+v[n-1])/2;

    forn(i,0,n-1)
    {
        v1[i+1] = v[i]-v1[i];
    }

    forn(i,0,n)
    {
        cout<<v1[i]<<" ";
    }


    return 0;
}

Measured memory_bytes: 2944
# -*- coding: utf-8 -*-
N=int(input())

l0=['a']
l1=[]
li=[0]
li1=[]
alp=[chr(i) for i in range(97, 97+26)]

for i in range(1,N):
    for j, l in enumerate(l0):
        ind=0
        while ind<=li[j]+1:
            l1.append(l+alp[ind])
            if ind==li[j]+1: li1.append(li[j]+1)
            else: li1.append(li[j])
            ind+=1
    l0=l1.copy()
    l1=[]
    li=li1.copy()
    li1=[]

for l in l0:
    print(l)
        

Measured memory_bytes: 15308
import static java.lang.Integer.parseInt;
import static java.lang.System.out;
import static java.util.Collections.reverse;
import static java.util.Collections.sort;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main extends BaseExe {

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

    @Override
    protected void execute() {
        List<Integer> list = revSortList();
        for (int index = 0; index < list.size(); index++)
            printItem(index, list);
    }

    private List<Integer> getList() {
        String[] inDataes = nextLine().split(" ");
        List<Integer> list = new ArrayList<>();
        for (int index = 0; index < 5; index++)
            list.add(parseInt(inDataes[index]));
        return list;
    }

    private List<Integer> revSortList() {
        List<Integer> list = getList();
        sort(list);
        reverse(list);
        return list;
    }

    private void printItem(int index, List<Integer> list) {
        if (index == list.size() - 1)
            out.println(list.get(index));
        else
            out.print(list.get(index) + " ");
    }
}

abstract class BaseExe {

    /** ????????£?????? */
    private Scanner scan;

    /** ??\???????????? */
    private String inData;

    /** ?????????????????\????????? */
    public void exeSysIn() {
        try (Scanner scan = new Scanner(System.in)) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** ??????????????\????????? */
    public void exeFileIn(String inDataPath) {
        try (Scanner scan = new Scanner(new File(inDataPath))) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** ??????????????????????????? */
    private void exeCtrl(Scanner scan) throws Exception {
        this.scan = scan;
        execute();
    }

    /** ????????? */
    protected abstract void execute() throws Exception;

    /** ?¬?????????? */
    protected String nextLine() {
        return scan.nextLine();
    }

    /** ??\????????? */
    protected boolean judgeInData() {
        return hasNextLine() && isNotEmptyInData();
    }

    /** ?¬?????????¨?????? */
    protected boolean hasNextLine() {
        return scan.hasNextLine();
    }

    /** ??????????????? */
    protected boolean isNotEmptyInData() {
        inData = nextLine();
        return !inData.isEmpty();
    }

    /** ??\?????????????????? */
    protected String getInData() throws Exception {
        if (inData.isEmpty())
            throw new Exception("inData is Empty.");
        return inData;
    }
}

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

int main() {
  ll N;
  cin >> N;
  map<string, ll> ans;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    ans[s[i]]++;
  }

  ll sum = 0;

  for (auto e : ans) {
    ll tmp = e.second * (e.second - 1) / 2;
    sum += tmp;
  }

  cout << sum << endl;
}

Measured memory_bytes: 18176
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main() {
  int n,ans=0,i=1;
  set<int> st;
  cin>>n;
  st.insert(n);
  while(true){
    i++;
    if(n%2==0){
      n/=2;
      st.insert(n);
    }else{
      n=3*n+1;
      st.insert(n);
    }
    if(st.size()!=i){
      cout<<i<<endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
const int M = 3e5 + 10;
long long cnt[M];
int op[M];
 
int main()
{
	memset(cnt, 0, sizeof(cnt));
	int n, m;
	long long totl = 0;
	scanf("%d%d", &n, &m);
	for(int i=0; i<n; ++i)
		scanf("%d", op + i);
	for(int i=1; i<n; ++i) {
		int l = op[i-1], r = op[i];
		if(l > r) r += m;
		totl += r - l;
		if(r - l > 1) {
			++cnt[l+2];
			 cnt[r+1]-=(r-(l+2) +1)+1;
			 cnt[r+2]+=(r-(l+2)+1);
		}
	}
	for(int i=1; i<=2*m; ++i) {
		cnt[i] += cnt[i-1];
	}
	for(int i=1; i<=2*m; ++i) {
		cnt[i] += cnt[i-1];
	}
	long long ans = -1;
	for(int i=1; i<=m; ++i) {
		ans = max(cnt[i] + cnt[i+m], ans);
	}
	cout<<totl - ans<<endl;
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  vector<int> x = {a,b,c};
  sort(x.begin(),x.end());
  int ans = 0;
  b = x.at(1);
  c = x.at(2);
  x.at(0) += c-b;
  x.at(1) += c-b;
  ans += c-b;
  a = x.at(0);
  b = x.at(1);
  x.at(0) += ((b-a)/2)*2;
  ans += (b-a)/2;
  if(x.at(0) == x.at(1)){
    cout << ans << endl;
  }else{
    cout << ans+2 << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	long long int n,a,b;
	long long int ans=0;
	scanf("%lld%lld%lld", &n,&a,&b);
	if((b-a)%2==0){
		ans=(b-a)/2;
	}else{
		if(n-b<a-1){
			ans=n-b+1+(b-a-1)/2;
		}else{
			ans=a+(b-a-1)/2;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 128