akhauriyash/Code-Regression huggingface dataset:
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n, long long k, long long s){
    for(int i = 0; i < k; ++i)
        cout << s << " \n"[i == n - 1];
    for(int i = k; i < n; ++i)
        cout << (s == 1 ? 2 : s - 1) << " \n"[i == n - 1];
}


signed main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    long long S;
    scanf("%lld",&S);
    solve(N, K, S);
    return 0;
}


Measured memory_bytes: 1280
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    long[] a = nal(n);
    Arrays.sort(a);
    long[] sum = new long[n + 1];
    for (int i = 0; i < n; i ++) {
      sum[i + 1] = sum[i] + a[i];
    }
    
    int ret = 1;
    for (int i = n - 2; i >= 0; i --) {
      if (sum[i + 1] * 2 >= a[i + 1]) {
        ret ++;
      } else {
        break;
      }
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 41440
from numpy import*
a,b=loadtxt(open(c:=0),'i',skiprows=1)
l=1<<29
while l:u=l;l>>=1;c+=sum(diff(searchsorted(sort(r_[b%u-u,b%u]),([u],[l])-a%u).T))%2*l
print(c)

Measured memory_bytes: 86764
n=int(input())
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
#計算量はo(n**0.5)なので間に合う
def fact(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
arr=fact(n)
ans=0
for i in arr:
  k=i[1]
  loop=1
  while True :
    k -=loop
    if k>=0:
      ans+=1
    else:
      break
    loop += 1
    
if n==1:
  print(0)
else:
  print(ans)


Measured memory_bytes: 9440
#include<iostream>
#include<string.h>
#include <sstream>

using namespace std;

int main()
{
	string str;
	getline(cin, str);
	int n = str.length();

	int s, e;

	for (int i = 0; i < n; i++){
		if (str[i] == 'A'){
			s = i;
			break;
		}
	}

	for (int i = n - 1; i >= 0; i--){
		if (str[i] == 'Z'){
			e = i;
			break;
		}
	}

	cout << e - s +1 ;

	return 0;
}

Measured memory_bytes: 640
import sys
from time import time
from random import randint

def func(s, x):
    last = [0] * 26
    score = 0
    for i, v in enumerate(x, 1):
        last[v] = i
        c = 0
        for j in range(26):
            c += s[j] * (i - last[j])
        score += s[i * 26 + v] - c
    return score

def main():
    start = time()
    d, *s = map(int, sys.stdin.buffer.read().split())
    x = ([*range(26)] * 15)[:d]
    M = func(s, x)
    while time() - start < 1.8:
        y = x.copy()
        if randint(0, 1):
            y[randint(0, d - 1)] = randint(0, 25)
        elif randint(0, 1):
            i = randint(0, d - 16)
            j = randint(i + 1, i + 15)
            y[i], y[j] = y[j], y[i]
        else:
            i = randint(0, d - 15)
            j = randint(i + 1, i + 7)
            k = randint(j + 1, j + 7)
            if randint(0, 1):
                y[i], y[j], y[k] = y[j], y[k], y[i]
            else:
                y[i], y[j], y[k] = y[k], y[i], y[j]
        t = func(s, y)
        if t > M:
            M = t
            x = y
    for t in x:
        print(t + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 10344
#include <stdio.h>

char S[15];
char S2[15]="2019/04/30";

int main(){

scanf("%s",S);

int i;

for(i=0;i<10;i++){
if(i==4||i==7){continue;}
if(S[i]-'0'>S2[i]-'0'){printf("TBD\n");return 0;}
else if(S[i]-'0'<S2[i]-'0'){printf("Heisei\n");return 0;}
}

printf("Heisei\n");

return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define swap(type, x, y) {type tmp = x; x = y; y = tmp;}
#define ll long long

ll gcd(ll x, ll y) {
    ll z;
    if (x <= y) swap(ll, x, y);

    do {
        z = x % y;
        x = y;
        y = z;
    } while(z > 0);
    
    return x;
}

int main(void) {
    ll a, b, c;

    scanf("%lld %lld", &a, &b);

    printf("%lld\n", gcd(a, b));

    return 0;
}


Measured memory_bytes: 2096
package main

import (
  "fmt"
)

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

func main() {
  var N int
  fmt.Scan(&N)
  P := make([]int, N)
  Q := make([]int, N + 1)
  for i := range P {
    fmt.Scan(&P[i])
    Q[i] = 1
  }
  cnt := 1
  for _, p := range P {
    cnt = max(cnt, Q[p - 1])
    Q[p] = Q[p - 1] + 1
  }
  fmt.Println(N - cnt)
}

Measured memory_bytes: 7808
#include <iostream>
#include <cstdio>
using namespace std;
#define int long long 
#define REP(i,n) for (int i=0;i<(n);i++)

signed main(){
    int N,a,b;
    int ans=1;
    int T[110];
    cin >> N;
    REP(i,N){cin >> T[i];}
    REP(i,N){
        a=ans;b=T[i];
        int r=ans%T[i];
	    while(r!=0){
	    	a=b;
	    	b=r;
	    	r=a%b;
    	}
    	ans*=T[i]/b;
    //	cout << ans << endl;
    }
	cout <<ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<int> x(n);
    vector<int> y(100010,0);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
        y[x[i]]++;
    }
    vector<int> v(m),amari(m);
    for (int i = 0; i < 100010; i++)
    {
        if(y[i] >1){
            if(y[i]%2==1)
            v[i % m] += y[i]-1;
            else
            {
                v[i % m] += y[i];
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        amari[x[i] % m]++;
    }

    int cnt = 0;
    if (m % 2 == 0)
    {
        int c = 0;
        for (int i = 1; i <= m/2; i++)
        {
            if(i == m/2){
                c += amari[i] / 2;
                amari[i] = 0;
                continue;
            }
            cnt += min(amari[i], amari[m - i]);
            if(amari[i] >= amari[m-i]){
                amari[i] -= amari[m - i];
                amari[m - i] = 0;
            }
            else{
                amari[m - i] -= amari[i];
                amari[i] = 0;
            }
        }
        cnt += amari[0] / 2 + c;
    }
    else{
        for (int i = 1; i <= m/2; i++)
        {
            cnt += min(amari[i], amari[m  - i]);
            if (amari[i] >= amari[m - i])
            {
                amari[i] -= amari[m - i];
                amari[m - i] = 0;
            }
            else
            {
                amari[m - i] -= amari[i];
                amari[i] = 0;
            }
        }
        
        cnt += amari[0]/2;
        amari[0] = 0;
    }
    for (int i = 1; i < m; i++)
    {
        if(amari[i]==0){
            continue;
        }
        cnt += min(amari[i], v[i]) / 2;
    }

    cout <<  cnt << endl;

    return 0;
}

Measured memory_bytes: 3456
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x: -x, A))
heapq.heapify(A)

while M > 0:
    heapq.heappush(A, -(-heapq.heappop(A) // 2))
    M -= 1

print(-sum(A))


Measured memory_bytes: 14180
n = int(input())
a_list = [int(x) for x in input().split()]

# count = 0
# max = a_list[0]

# for a in a_list:
#     for _ in range(n):
#         if max > a:
#             count += 1
#             a += 1
#     max = a
# print(count)

max = a_list[0]
count = 0

for a in a_list:
    if max > a:
        d = max - a
        count += d
        a += d
    max = a

print(count)

Measured memory_bytes: 32236
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<char, int>;

int main() {

    int n, k;
    string s;
    cin >> n >> k >> s;

    vector<P> vp;
    if(s[0] == '0'){
        vp.emplace_back('1', 0);
    }
    vp.emplace_back(s[0], 1);
    REP(i, 1, n){
        if(vp.back().first == s[i]){
            vp.back().second++;
        }
        else{
            vp.emplace_back(s[i], 1);
        }
    }
    if(vp.back().first == '0'){
        vp.emplace_back('1', 0);
    }

    if(vp.size()/2 <= k){
        cout << n << endl;
        return 0;
    }

    int tmp = 0;
    int l = k;
    int idx = 0;
    rep(i, vp.size()){
        tmp += vp[i].second;
        if(vp[i].first == '0'){
            l--;
        }
        if(l == 0){
            idx = i+1;
            tmp += vp[idx].second;
            break;
        }
    }
    int ans = tmp;
    for(int i = idx+1; i < vp.size()-1; i+=2){
        tmp += vp[i].second + vp[i+1].second;
        tmp -= (vp[i-2*k-1].second + vp[i-2*k].second);
        
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1528
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class A
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		long A = Int64.Parse(args[0]);
		long B = Int64.Parse(args[1]);
		long C = Int64.Parse(args[2]);

		Console.WriteLine((A + B + 1 >= C) ? B + C : A + 2 * B + 1);
	}
}





Measured memory_bytes: 11220
package main

import (
	"fmt"
	"math"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		a[i] -= i + 1
	}
	sort.Ints(a)
	b := a[n/2]
	sum := 0
	for _, v := range a {
		sum += int(math.Abs(float64(v - b)))
	}
	fmt.Println(sum)
}


Measured memory_bytes: 6784
#include <iostream>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int A, B;
  cin >> A >> B;
  int ret = 0;
  for (int i=0; i<2; i++) {
    if (A < B) {
      ret += B;
      B--;
    } else {
      ret += A;
      A--;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll k=in();
    vector<ll>lunlun{1,2,3,4,5,6,7,8,9};
    ll idx=0;
    while(true){
        if(lunlun.size()>=k){
            cout<<lunlun[k-1]<<endl;
            break;
        }
        ll foo=lunlun[idx++];
        ll d=foo%10;
        if(d==0){
            lunlun.push_back(foo*10);
            lunlun.push_back(foo*10+1);
        }else if(d==9){
            lunlun.push_back(foo*10+8);
            lunlun.push_back(foo*10+9);
        }else{
            lunlun.push_back(foo*10+d-1);
            lunlun.push_back(foo*10+d);
            lunlun.push_back(foo*10+d+1);
        }
    }
}



Measured memory_bytes: 1464
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
  int n;
  cin>>n;
  vector<int> a(n+1);
  for(int i=0;i<n+1;i++){
    cin>>a[i];
  }
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  ll ans=0;
  for(int i=0;i<n+1;i++){
    int n0=min(a[i],b[i]);
    ans+=n0;
    b[i]-=n0;
    int n1=min(a[i+1],b[i]);
    ans+=n1;
    a[i+1]-=n1;
  }
  cout<<ans<<endl;
  return 0;
}

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

int partition(int,int);

#define MAX 10000
int *A;
int N;

int main(){
  int i,j,x;
  scanf("%d",&N);
  A=(int*)malloc(sizeof(int) * N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  x=partition(0,N-1);

  for (i=0;i<N-1;i++){
    if(i==x){
      printf("[");
    }
    printf("%d", A[i]);
    if(i==x){
      printf("]");
    }
    if(i!=N-1){
      printf(" ");
    }
  }

  printf("%d\n",A[N-1]);

  free(A);

  return 0;
}

int partition(int p, int r){
  int x,i,j,a,b;
  x = A[r];
  i = p-1;
  for(j=p;j<=r-1;j++){
    if(A[j] <= x){
      i = i+1;
      // A[i] ??¨ A[j] ?????????
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }
  //A[i+1] ??¨ A[r] ?????????
  b=A[i+1];
  A[i+1]=A[r];
  A[r]=b;

  return i+1;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
using Data=pair<long,long>;
int mmax(int a,int b,int c){
  if(a<b){
    return max(b,c);
  }else{
    return max(a,c);
  }
}

int main(){
  long i,j,N,K,M;
  cin>>N;
  cin>>K;
  M=(N-2)*(N-1)/2;
  if(M<K){
    printf("-1\n");
    return 0;
  }
  M=N+M-K-1;
  printf("%ld\n",M);
  for(i=1;i<=N;i++){
    for(j=i+1;j<=N;j++){
      printf("%ld %ld\n",i,j);
      M--;
      if(M==0)return 0;
    }
  }
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)

const LL mod=(1e9)+7;
int main()
{
    LL n;
    cin>>n;
    LL a[n];
    LL mx=INF;
    int f=0;
    REP(i,n)
    {
        cin>>a[i];
        if(a[i]%2==0)
        {
            if(a[i]%3==0 or a[i]%5==0)
            {

            }
            else f=1;
        }
    }
    if(f)
        cout<<"DENIED";
    else
        cout<<"APPROVED";
}



Measured memory_bytes: 3648
#include<iostream>
#include<queue>
#define MAX_N 50

using namespace std;

int n;
int data[MAX_N];

queue<int> que;

void countPages(){
	int start, end;
	for (int i = 0; i < n; i++)
	{
		if (i == 0){
			start = data[0];
		}
		else{
			if (data[i - 1] + 1 != data[i]){
				end = data[i - 1];
				if (start == end){
					cout << start << " ";
				}
				else{
					cout << start << "-" << end << " ";
				}
				start = data[i];
			}
		}
		if (i == n - 1){
			if (start == data[i]){
				cout << start;
			}
			else{
				cout << start << "-" << data[i];
			}
		}
	}
	cout << endl;
}

int main(){
	while (1){
		int x;
		cin >> x;
		que.push(x);
		if (x == 0)break;
	}
	while (1){
		n = que.front();
		que.pop();
		if (n == 0)break;
		for (int i = 0; i < n; i++){
			data[i] = que.front();
			que.pop();
		}
		countPages();
	}
	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;


int main(){
    int n; cin >> n;
    int h[n];
    for(int i=0;i<n;i++) cin >> h[i];

    int dp[n];
    fill(dp, dp+n, INF);
    dp[0] = 0;

    for(int i=0;i<n;i++){
        if( i + 1 < n ){
            dp[i+1] = min(dp[i+1], dp[i] + abs(h[i+1]-h[i]));
        }
        if( i + 2 < n ){
            dp[i+2] = min(dp[i+2], dp[i] + abs(h[i+2]-h[i]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 3904
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int R = sc.nextInt();

        if (N < 10) {
            System.out.println(R + (100 * (10 - N)));
        } else {
            System.out.println(R);
        }
    }
}

Measured memory_bytes: 21716
#include <iostream>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;
int main(){
        int N,tmp;
        int odd=0,even=0;
        cin >> N;
        rep(i,N){
                cin>>tmp;
                if(tmp%2==0) even++;
                else odd++;
        }
        string ans = "YES";
        if (odd%2 != 0) ans = "NO";

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


Measured memory_bytes: 256
/*

PAIN demands to be felt
so do RE, TLE, MLE, SIGSEV & WA

*/

#include<bits/stdc++.h>
using namespace std;
#define CIN 			ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb	 			push_back
#define sz(x) 			((int)((x).size()))
#define all(x) 			(x).begin(),(x).end()
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector< std::vector<ll> > matrix;
typedef map<ll,ll> mii;
typedef vector<pii> vpii;

map<char,vi> loc;

ll addd(char c1, char c2, char c3){
	ll n1,n2,n3,n4,ans=0,i,j;
	if(loc[c2].empty() || loc[c3].empty() || loc[c1].empty())return 0;
	for(i=0; i<sz(loc[c1]);i++){
		n1 = loc[c1][i];
		n2 = upper_bound(all(loc[c2]),n1) - loc[c2].begin();
		n3=0;
		for(j=n2; j<sz(loc[c2]); j++){
			n2=loc[c2][j];
			n3 = upper_bound(all(loc[c3]),n2) - loc[c3].begin();
			n4 = lower_bound(all(loc[c3]),2*n2-n1)- loc[c3].begin();
			if(loc[c3][n4]-n2 == n2-n1)n3++;
			ans+=sz(loc[c3])-n3;
		} 
	}
	return ans;
}


void solve(){
	ll n=0,i=0,ans=0;
	string str;
	/////////////////////////////////////////////////////////////////////////////////////////////////////////////
	cin>>n>>str;
	
	for(i=0; i<n; i++){
		loc[str[i]].pb(i);
	}
	//{r , g , b}
	ans+=addd('R','G','B');
	ans+=addd('R','B','G');
	ans+=addd('G','R','B');
	ans+=addd('G','B','R');
	ans+=addd('B','R','G');
	ans+=addd('B','G','R');
	cout<<ans<<endl;
}

int main(){
	CIN;
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}

	return 0;
}






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

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

  vector<string> arr(N);
  for(int i=0; i<N; i++){
      cin >> arr[i];
  }

  sort(arr.begin(),arr.end());
  arr.erase(unique(arr.begin(),arr.end()),arr.end());
  cout << arr.size() << endl;
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)

#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll mod = 1e9 + 7;
const ll infl = 1e17;


int main()
{
    ll h,w;
    ll n;
    cin>>h>>w>>n;
    vll a(n);
    rep(i, n) cin >> a[i];
    vll x;
    rep(i, n) rep(j, a[i]) x.emplace_back(i + 1);
    vvll ans(h, vll(w, 0));
    ll idx = 0;
    rep(i,h){
        rep(j,w){
            if (i%2==0){
                ans[i][j] = x[idx];
                idx++;
            }
            else {
                ans[i][w - 1 - j] = x[idx];
                idx++;
            }
        }
    }
    rep(i,h){
        rep(j, w) cout << ans[i][j] << " ";
        cout << endl;
    }
}

Measured memory_bytes: 640
# https://atcoder.jp/contests/abc043/tasks/arc059_a
n = int(input())
a = list(map(int, input().split()))
min = float('inf')
for y in range(-100, 101):
    sum = 0
    for x in a:
        sum += (x - y) ** 2
    if min > sum:
        min = sum

print(min)


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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 1e9+7;
vector<int>g[55];
int dep[55];
int pa[55];
ll sol[55];
void dfs(int now, int pre){
    for(auto i:g[now]){
        if(i != pre){
            pa[i] = now;
            dep[i] = dep[now] + 1;
            dfs(i,now);
        }
    }
}
ll solve(int x,int y){
    if(dep[x] < dep[y]){
        swap(x, y);
    }
    ll ret = 0;
    while(dep[x] > dep[y]){
        ret |= (1LL<<x);
        x = pa[x];
    }
    while(x != y){
        ret |= (1LL<<x);
        x = pa[x];
        ret |= (1LL<<y);
        y = pa[y];
    }
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    while(cin >> n){
        f(n-1){
            int add1, add2;
            cin >> add1 >> add2;
            add1--;
            add2--;
            g[add1].pb(add2);
            g[add2].pb(add1);
        }
        dfs(0,0);
        int m;
        cin >> m;
        f(m){
            int add1, add2;
            cin >> add1 >> add2;
            add1--, add2--;
            sol[i] = solve(add1, add2);
        }
        ll ans = 0;
        for(int i = 0 ; i < (1 << m) ; i++){
            ll mask = 0;
            for(int j = 0 ; j < m ; j ++){
                if(i&(1<<j)){
                    mask |= sol[j];
                }
            }
            int cnt = n - 1 - __builtin_popcountll(mask);
            if(__builtin_popcount(i)&1){
                ans -= (1LL<<cnt);
            }
            else{
                ans += (1LL<<cnt);
            }
        }
        cout << ans << '\n';
    }
}

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

int main(){
    int l,r;
    cin>>l>>r;
    r=min(r,l+4038);
    int ans=2020;
    for(int i=l; i<r; ++i){
        for(int j=i+1; j<=r; ++j){
            ans=min((ll)ans,(ll)i*j%2019);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n;
  cin>>n;
  long long a[n];
  REP(i, n) cin>>a[i];
  long long p = 2;
  long long ans = a[0] - 1;
  for(int i = 1; i < n; i++){
    if(a[i] == p){
      p++;
      continue;
    }
    if(a[i] < p) continue;
    if(a[i] % p == 0){
      ans += 1 + (a[i] - (p + 1)) / p;
    }else{
      ans += a[i] / p;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 4420
import sys
input = sys.stdin.readline

n = int(input())
tasks = []
for _ in range(n):
    a,b = map(int, input().split())
    tasks.append((a,b))

tasks = sorted( tasks, key = lambda a: a[1] )

time = 0
for task in tasks:
    time += task[0]
    if time > task[1]:
        print('No')
        break
else:
    print( 'Yes' )

Measured memory_bytes: 69212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int H,W,N;
    cin>>H>>W>>N;
    int sh,sw;
    cin>>sh>>sw;
    string S,T;
    cin>>S>>T;
    int u=sh,d=sh,l=sw,r=sw;

    string ans="YES";
    rep(i,N){
        if(S[i]=='U') u--;
        if(S[i]=='D')d++;
        if(S[i]=='R')r++;
        if(S[i]=='L')l--;
        if(d>H||u<1||l<1||r>W){
            ans="NO";
            break;
        }
        if(T[i]=='U'&&d>1) d--;
        if(T[i]=='D'&&u<H)u++;
        if(T[i]=='R'&&l<W)l++;
        if(T[i]=='L'&&r>1)r--;
    }
    if(ans=="YES"){

    }
    cout << ans << endl;


    



}

Measured memory_bytes: 920
#include <stdio.h>
#include <math.h>
#include <string.h>
#define rep(i,a,n) for(int i=a;i<n;i++)

int main(){
	int len,q,a,b;
	char str[1010],order[20];
	scanf("%s %d",str,&q);
	rep(i,0,q){
		char p[1010];
		scanf("%s",order);
		if(strcmp(order,"print")==0){
			scanf("%d %d",&a,&b);
			rep(j,a,b+1){
				printf("%c",str[j]);
			}
			printf("\n");
		}else if(strcmp(order,"reverse")==0){
			scanf("%d %d",&a,&b);
			sprintf(p,"%s",str);
			rep(j,0,b-a+1){
				p[a+j]=str[b-j];
			}
			sprintf(str,"%s",p);
		}else if(strcmp(order,"replace")==0){
			scanf("%d %d %s",&a,&b,p);
			rep(j,0,b-a+1){
				str[a+j]=p[j];
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1012
use proconio::{fastout, input};
use regex::Regex;

#[fastout]
fn main() {
    input! {
        s: String,
    }
    // annotate for rust-analyzer
    // let mut s: &str = &s;

    // let mut r = "YES";
    // while s.len() > 0 {
    //     s = match s {
    //         e if e.ends_with("dream") => &s[..(s.len() - 5)],
    //         e if e.ends_with("dreamer") => &s[..(s.len() - 7)],
    //         e if e.ends_with("erase") => &s[..(s.len() - 5)],
    //         e if e.ends_with("eraser") => &s[..(s.len() - 6)],
    //         _ => {
    //             r = "NO";
    //             break;
    //         }
    //     };
    // }

    let s: &str = &s;
    let re = Regex::new(r"^(dream|dreamer|erase|eraser)*$").unwrap();
    let r = if re.is_match(s) { "YES" } else { "NO" };

    println!("{}", r);
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
    using namespace std;
     
    const int maxn = 100005, P = 1000000007;
    int n, m, x[maxn], y[maxn], q[maxn], k, c, f[maxn], t[maxn];
    struct point { int a, b; } p[maxn];
    bool operator==(const point &a, const point &b) { return a.a == b.a && a.b == b.b; }
    bool operator<(const point &a, const point &b) { return a.a < b.a || (a.a == b.a && a.b > b.b); }
     
    int query(int x) { int s = 0; for (; x; x -= x & -x) s = (s + t[x]) % P; return s; }
    void update(int x, int y) { for (; x <= k; x += x & -x) t[x] = (t[x] + y) % P; }
     
    int main()
    {
    	scanf("%d%d", &n, &m);
    	for (int i = 1; i <= n; i++) scanf("%d", x + i);
    	for (int i = 1; i <= m; i++) scanf("%d", y + i);
    	for (int i = 1; i <= n; i++)
    	{
    		if (x[i] <= y[1] || x[i] >= y[m]) continue;
    		int j = lower_bound(y + 1, y + 1 + m, x[i]) - y;
    		if (y[j] == x[i]) continue;
    		p[++c] = {x[i] - y[j - 1], y[j] - x[i]};
    	}
    	sort(p + 1, p + 1 + c);
    	c = unique(p + 1, p + 1 + c) - p - 1;
    	for (int i = 1; i <= c; i++) q[++k] = p[i].b;
    	sort(q + 1, q + 1 + k);
    	k = unique(q + 1, q + 1 + k) - q - 1;
    	int ans = 0;
    	for (int i = 1; i <= c; i++)
    	{
    		p[i].b = lower_bound(q + 1, q + 1 + k, p[i].b) - q;
    		f[i] = (1 + query(p[i].b - 1)) % P;
    		ans = (ans + f[i]) % P;
    		update(p[i].b, f[i]);
    	}
    	printf("%d\n", (ans + 1) % P);
    	return 0;
    }

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int main() {

    long long int n;
    cin >> n;

    vector< long long int > v;

    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;
        v.push_back( in );
    }

    sort( v.begin(), v.end() );

    long long int ans = 0;

    for ( long long int i = 0; i < n; i++ ) {
        for ( long long int j = i + 1; j < n; j++ ) {
            long long int cnt = lower_bound( v.begin() + j + 1, v.end(), v[i] + v[j] ) - v.begin() - j - 1;
//            cout << " " << i << " " << j << " : " << cnt << endl;
            ans += cnt;
        }
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  cin >> n;
  vl a(n);
  ll sum=0;
  vl sum2(n,0);
  rep(i,n){
    cin >> a[i];
    sum +=a[i];
  }
  sum2[0]=a[0];
  FOR(i,1,n){
    sum2[i]=sum2[i-1]+a[i];
  }
  ll ans=INF;
  rep(i,n-1){
    ans=min(ans,abs(sum-2*sum2[i]));
  }
  cout << ans << endl;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    rep(i,n-1){
        if(h[i+1]-h[i] == -1){
            h[i+1]++;
        }
        else if(h[i+1] - h[i] < -1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K,H,W,L,R,l,r,mi1,mi2,sum,Q;
LL ans;
LL no;
bool b,bb[100001];
string s,t;

int main() {
	cin >> N>>H;
	vector<LL> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if(a[i]>=H)ans++;
	}

		cout <<ans<< endl;

	return 0;
}



Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	char* s = (char*)calloc(n+1, sizeof(char));
	char* t = (char*)calloc(n+1, sizeof(char));
	char* s_t = (char*)calloc(n+n+1, sizeof(char));
	
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	for(int i = 0; i < n; i++){
		cin >> t[i];
	}
	int s_index = 0;
	int t_index = 0;
	for(int i = 0; i < n*2; i++){
		if(i % 2 == 0) s_t[i] = s[s_index++];
		else s_t[i] = t[t_index++];
	}
	
	cout << s_t << endl;
	
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 1e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}



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

    ll n;
    cin >> n;

    cout << (n * (n-1)) / 2;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  int a, b;
  std::cin >> a >> b;
  if (a <= 5) {
    std::cout << "0\n";
  } else if (6 <= a && a <= 12) {
    std::cout << b/2 << '\n';
  } else {
    std::cout << b << '\n';
  }
  return 0;
}



Measured memory_bytes: 256
# スペース区切りの整数の入力
a,b,k=gets.chomp.split(" ").map(&:to_i);
def eat(x)
    if x%2==1
        x-=1
    end 
    return x   
end

for i in 0...k do
    if i%2==0
        a = eat(a)
        b += a/2
        a /= 2
    else
        b = eat(b)
        a += b/2
        b /= 2
    end
end

print("#{a} #{b}\n")


Measured memory_bytes: 14236
#include <bits/stdc++.h>
using namespace std;
map<long long, long long>mp;
long long f(long long x){
    if(mp[x]==0){
        if(x%2)mp[x]=2*f(x/2)+f(x/2-1);
        else mp[x]=f(x/2)+2*f(x/2-1);
        mp[x]%=1'000'000'007;
        mp[x]++;
    }
    return mp[x]-1;
}
int main(){
    long long N;
    cin>>N;
    mp[0]=2;mp[1]=3;mp[2]=5;mp[3]=6;mp[4]=9;
    cout<<f(N)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)
#define min(a,b) (a>b?b:a)
#define max(a,b) (a>b?a:b)
#define yn(f) (f?"Yes":"No")
#define YN(f) (f?"YES":"NO")
#define pro "はいプロ　世界一○○が上手　○○界のtourist　○○時代の終焉を告げる者　実質○○　○○するために生まれてきた男"
#define Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything 42

signed main(){
	cout<<fixed<<setprecision(7);
	
	bool flag =  true;
	int N, t, x, y, bt = 0, bx = 0, by = 0;
	
	cin>>N;
	
	for(int i = 1; i <= N; i++){
		cin>>t>>x>>y;
		if(!((abs(x-bx) + abs(y-by) <= (t-bt) )&& (abs(x-bx) + abs(y-by) - (t-bt))%2 == 0)) flag = false;
		// cout<<abs(x-bx) + abs(y-by)<<" "<< (t-bt) <<" "<<endl;
		bt = t; bx = x; by = y;
	}
	
	cout<<yn(flag)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N, K;
        cin >> N >> K;
        ll ans = 0;
        while (N > 0) {
                ++ans;
                N /= K;
        }

        cout << ans << endl;
}

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

ll a[114514],b[114514];
int main(){
	ll n;
	cin>>n;
	ll cnt=0;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		if(i%2)cnt+=b[i];
		else cnt-=b[i];
	}
	a[1]=cnt;
	cout<<a[1]<<' ';
	for(int i=2;i<=n;i++){
		a[i]=2*b[i-1]-a[i-1];
		if(i==n)cout<<a[n]<<endl;
		else cout<<a[i]<<' ';
	}
	return 0;
}


Measured memory_bytes: 2944
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    as_ = list(map(int, input().split()))
    counter_as_ = collections.Counter(as_)
    available_edge = [item for item in counter_as_.items() if item[1] >= 2]
    available_edge.sort()
    
    if len(available_edge) == 0:
        print(0)
        exit()

    if available_edge[-1][1] >= 4:
        print(available_edge[-1][0] ** 2)
    else:
        if len(available_edge) >= 2:
            print(available_edge[-1][0] * available_edge[-2][0])
        else:
            print(0)

if __name__ == '__main__':
    main()

Measured memory_bytes: 18596
#include<iostream>
#include<cstdio>
using namespace std;

int d1[200005],d2[200005];
int d3[200005],d4[200005];
//d1:子树中的最远距离
//d2:非子树中的最远距离
//d3:这个节点到子树中至少经过1个特殊节点到达子树中的最远节点最小距离 
//d4:从他父亲出发，不经过这棵子树的最远路径 
int n,x,y,siz[200005],col[200005],fa[200005];
long long ans=0;
int tot=0,h[200005];
struct Edge{
    int x,next;
}e[400005];
char ch[200005];

inline void add_edge(int x,int y){
    e[++tot].x=y;
    e[tot].next=h[x],h[x]=tot;
}

void dfs1(int x,int father){
    siz[x]=col[x],fa[x]=father;
    d3[x]=col[x]?0:1e9;
    for(int i=h[x];i;i=e[i].next){
        if(e[i].x==father)continue;
        dfs1(e[i].x,x);
        siz[x]+=siz[e[i].x];
        d1[x]=max(d1[x],d1[e[i].x]+1);
        if(siz[e[i].x])
            d3[x]=min(d3[x],d1[e[i].x]+1);
    }
}

void dfs2(int x,int father){
    if(father)d4[x]=d2[x]-1;
    int maxn=0,sec=0;
    for(int i=h[x];i;i=e[i].next){
        if(e[i].x==father)continue;
        if(d1[e[i].x]+1>maxn)
            sec=maxn,maxn=d1[e[i].x]+1;
        else sec=max(sec,d1[e[i].x]+1);
    }
    for(int i=h[x];i;i=e[i].next){
        if(e[i].x==father)continue;
        if(d1[e[i].x]+1==maxn)
            d2[e[i].x]=max(d2[x],sec)+1;
        else d2[e[i].x]=max(d2[x],maxn)+1;
        dfs2(e[i].x,x);
    }
}

int main(){
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        scanf("%d%d",&x,&y);
        add_edge(x,y);
        add_edge(y,x);
    }
    scanf("%s",ch+1);
    for(int i=1;ch[i];i++)
        col[i]=ch[i]-'0';
    dfs1(1,0),dfs2(1,0);
    for(int i=1;i<=n;i++){
        int minv,maxv;
        minv=min(d3[i],siz[1]==siz[i]?(int)1e9:d2[i]);
        maxv=max(d1[i],d2[i])-1;
        for(int j=h[i];j;j=e[j].next){
            if(e[j].x==fa[i])maxv=min(maxv,d1[i]+1);
            else maxv=min(maxv,d4[e[j].x]+1);
        }
        if(maxv>=minv)ans+=1LL*maxv-minv+1;
    }
    printf("%lld",ans+1);
}

Measured memory_bytes: 19328
#include <bits/stdc++.h>
using namespace std;
string a[101];
int n,l;
int main(){
	cin>>n>>l;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	sort(a+1,a+1+n);
	for(int i=1;i<=n;++i)
		cout<<a[i];
	return 0;
}

Measured memory_bytes: 256
n=int(input())
nums=list(map(int,input().split()))
count=0
for i in range(n):
    minj=i
    for j in range(i,n):
        if nums[j] < nums[minj]:
            minj=j
    if not i==minj:
        v=nums[i]
        nums[i]=nums[minj]
        nums[minj]=v
        count+=1
print(*nums)
print(count)


Measured memory_bytes: 5608
//
//  main.cpp
//  zero
//
//  Created by 叶金炜 on 2019/4/2.
//  Copyright © 2019 okstal. All rights reserved.
//

#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    if(a>b)cout<<"a > b"<<endl;
    else if(a<b)cout<<"a < b"<<endl;
    else cout<<"a == b"<<endl;
}



Measured memory_bytes: 3096
import sys
 
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
 
def main():
    import numpy as np
    from itertools import product
 
    n, m, x = list(map(int, readline().split()))
    a, c = [], []
    for i in range(n):
        c_temp, *a_temp = list(map(int, readline().split()))
        c.append(c_temp)
        a.append(a_temp)
 
    a = np.array(a)
    ans = INF
 
    for bit in product(range(2), repeat=n):
        price_total = 0
        learn_total = np.array([0] * m)
        for i in range(n):
            if bit[i] == 1:
                price_total += c[i]
                learn_total += a[i]
        if np.all(learn_total >= x):
            ans = min(ans, price_total)
 
    if ans == INF:
        print(-1)
    else:
        print(ans)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 27164
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,k=0,ans=0,x[2]={0};
        cin>>n;
        ll A[n];
        map<int,int> B;
        for(ll i=0;i<n;i++)
        {
            cin>>A[i];
            B[A[i]]++;
        }
        sort(A,A+n);
        for(ll i=n-1;i>=0;i--)
        {
             if(B[A[i]]>=2)
            {
                if((B[A[i]]>=4 && k==0))
                {
                    ans=A[i]*A[i];
                    break;
                }
                x[k]=A[i];
                i=i-B[A[i]]+1;
                k++;
                if(k==2)
            	{
	              ans=x[0]*x[1];  
	              cout<<ans;
	              return 0;
            	}
            }
        }
        cout<<ans;
    } 
    return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        public static void Main()
        {
            string S = Console.ReadLine();
            string ans = "No";

            
            if(S.Substring(2,1) == S.Substring(3,1) && S.Substring(4,1) == S.Substring(5,1)) {
                ans = "Yes";
            }

            Console.WriteLine(ans);
    
            

        }
    }
}



Measured memory_bytes: 13140