akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define mod 1000000007
#define forn(i, n) for (int i = 0; i < (int) (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int size = s.size();
    string res;
    if(size%2 == 0){
        if(s[0] == s[size-1]){
            res =  "First";
        }else{  
            res =  "Second";
        }
    }else{
        if(s[0] == s[size-1]){
            res =  "Second";
        }else{
            res =  "First";
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> dp(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i];
  dp[0] = 0;
  dp[1] = abs(a[1] - a[0]);
  for (int i = 2; i < N; ++i)
    dp[i] = min(dp[i - 2] + abs(a[i] - a[i - 2]), dp[i - 1] + abs(a[i] - a[i - 1]));
  cout << dp[N - 1] << endl;
  return 0;
}


Measured memory_bytes: 3972
#include<bits/stdc++.h>
#define MX 1000005
#define INF 1000000005
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
 
struct UF
{
	int par[MX],rank[MX];
	
	void init(int n)
	{
		for(int i=0;i<n;i++)
		{
			par[i]=i;
			rank[i]=0;
		}
	}
	void rem(int i)
	{
		par[i]=i;
		rank[i]=0;
	}
	int find(int x)
	{
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}
	void unite(int x,int y)
	{
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y])
		{
			par[x]=y;
		}
		else
		{
			par[y]=x;
			if(rank[x]==rank[y]) rank[x]++;
		}
	}
	bool same(int x,int y)
	{
		return find(x)==find(y);
	}
};
UF uf;
vector <int> vec[MX];
vector <P> query[MX];
int id[MX];
bool use[MX];
int dp[MX];
 
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int p,q,c;
		scanf("%d %d %d",&p,&q,&c);p--,q--,c--;
		query[c].push_back(P(p,q));
	}
	int sz=n;
	for(int i=0;i<MX;i++)
	{
		if(query[i].empty()) continue;
		for(int j=0;j<query[i].size();j++)
		{
			P p=query[i][j];
			uf.rem(p.first);
			uf.rem(p.second);
			id[p.first]=id[p.second]=-1;
		}
		for(int j=0;j<query[i].size();j++)
		{
			P p=query[i][j];
			uf.unite(p.first,p.second);
		}
		for(int j=0;j<query[i].size();j++)
		{
			P p=query[i][j];
			int r=uf.find(p.first);
			if(id[r]==-1) id[r]=sz++;
			//printf("%d %d: %d\n",r,id[r],p.first);
			vec[p.first].push_back(id[r]);
			vec[id[r]].push_back(p.first);
			r=uf.find(p.second);
			if(id[r]==-1) id[r]=sz++;
			//printf("%d %d: %d\n",r,id[r],p.second);
			vec[p.second].push_back(id[r]);
			vec[id[r]].push_back(p.second);
		}
	}
	queue <int> que;
	que.push(0);
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	while(!que.empty())
	{
		int v=que.front();que.pop();
		for(int i=0;i<vec[v].size();i++)
		{
			int to=vec[v][i];
			if(dp[to]==-1)
			{
				dp[to]=dp[v]+1;
				que.push(to);
			}
		}
	}
	if(dp[n-1]==-1) puts("-1");
	else printf("%d\n",dp[n-1]/2);
	return 0;
}

Measured memory_bytes: 73600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,c=0,b;
    cin>>a>>b;
    if(b==1)
    {
        cout<<"0"<<endl;
        return 0;
    }
    for(int i=a; ;i+=a-1)
    {
        if(i<b)
        {
            c++;

        }
        else
        {
            break;
        }
    }
    cout<<c+1<<endl;
    return 0;
}


Measured memory_bytes: 256
import math
n = int(input())
lis = list(map(int,input().split()))
li = sorted(lis)
ans2 = li[math.ceil((n-1)/2)]
cou2 = lis.count(ans2)
ans1 = li[math.floor((n-1)/2)]
cou1 = lis.count(ans1)
for i in range(n):
	if lis[i] >= ans2:
		print(ans1)
	else:
		print(ans2)

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

int main(){
  while(1){
    int N, M;
    cin >> N >> M;
    if(N == 0 && M == 0){
      break;
    }
    vector<int> h(N);
    vector<int> w(M);
    for(int i=0; i<N; i++){
      cin >> h[i];
    }
    for(int i=0; i<M; i++){
      cin >> w[i];
    }
    map<int, int> mh;
    map<int, int> mw;
    for(int i=0; i<N; i++){
      int ah=0;
      for(int j=i; j<N; j++){
        ah += h[j];
        mh[ah]++;
      }
    }
    for(int i=0; i<M; i++){
      int aw=0;
      for(int j=i; j<M; j++){
        aw += w[j];
        mw[aw]++;
      }
    }
    int ans=0;
    for(auto hmp : mh){
      ans += mh[hmp.first]*mw[hmp.first];
    }
    cout << ans << endl;
  }
  return 0;
}



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

int judge(int a, int b, int c)
{
    if (a == b && b == c && a % 2 == 0)
        return -1;
    else if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0)
        return 1;
    else
        return 0;
}

int main()
{
    int64_t a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    if (judge(a, b, c) == -1)
    {
        cout << -1 << endl;
        return 0;
    }
    while (judge(a, b, c) == 1)
    {
        int64_t s, t, u;
        s = a;
        t = b;
        u = c;
        a = (t + u) / 2;
        b = (s + u) / 2;
        c = (s + t) / 2;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		DataSet d = new DataSet();
		d.input();
		int dif = d.max - d.min;
		if(dif>1)
			System.out.println("No");
		else if(dif==1){
			if(2*(d.max-d.q)<=d.p&&d.q<=d.min)
				System.out.println("Yes");
			else System.out.println("No");
		}
		else if(dif==0){
			if(d.max==d.N-1||2*d.max<=d.N)
				System.out.println("Yes");
			else System.out.println("No");
		}
	}

}

class DataSet{
	int N;
	int[] a;
	int max=0,min=1000000;
	int p = 0,q = 0;
	public void input(){
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		a = new int[N];
		for(int i=0;i<N;i++){
			a[i] = sc.nextInt();
			max = Math.max(max, a[i]);
			min = Math.min(min,a[i]);
		}
		for(int i=0;i<N;i++){
			if(a[i]==max) p++;
			if(a[i]==min) q++;
		}
		sc.close();
	}
	
}

Measured memory_bytes: 50192
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int dp[100001];
int solve(int arr[],int n,int k){
    if(k==0){
        return 0;
    }

    if(dp[k]!=-1)
        return dp[k];

    for(int i=1;i<=n;i++)
        if(k>=arr[i] && solve(arr,n,k-arr[i])==0)
            {
                dp[k] = 1;
                return 1;
            }   
    return dp[k] = 0;
}
int main()
{
    int n,k;
    cin>>n>>k;

    memset(dp,-1,sizeof dp);

    int arr[n+1];
    for(int i=1;i<=n;i++)
        cin>>arr[i];
    if(solve(arr,n,k))
        cout<<"First"<<endl;
    else
        cout<<"Second"<<endl;
    
    return 0;
}

Measured memory_bytes: 8528
#include <stdio.h>

int main(void){

    int N,X;
    scanf("%d%d\n", &N,&X);
    int L[N];
    
    int x;
   
     for(x = 0; x <N; x++){
         scanf("%d",&L[x]);
    }
   

    int D[N],i;
    D[0] = 0;
    for(i = 0; i<N;i++){
        D[i+1] = D[i] + L[i]; 
    }

    int count = 0;
    for(i = 0;i <=N;i++){
        if(D[i]<=X){
            count++;
        }
    }
    printf("%d",count);

    return 0;
}

Measured memory_bytes: 128
N = int(input())
x = [0] * N
y = [0] * N
h = [0] * N
for i in range(N):
    x[i], y[i], h[i] = map(int, input().split())

top = [[] for _ in range(101*101)]

for i in range(101):
    for j in range(101):
        top[i*101+j] = [i, j]

#print(top)

H = 0
ansx = -100

for i in range(len(top)):
    topx = top[i][0]
    topy = top[i][1]
    H = 0
    h_list = []
    for j in range(N):
        tmp = abs(topx - x[j]) + abs(topy - y[j]) + h[j]
        h_list.append(tmp)
    if h_list.count(h_list[0]) == N :
        ansx = topx
        ansy = topy
        ansH = h_list[0]
        break

if ansx == -100:
    for i in range(len(top)):
        topx = top[i][0]
        topy = top[i][1]
        H = 0
        h_list = []
        for j in range(N):
            if h[j] != 0:
                tmp = abs(topx - x[j]) + abs(topy - y[j]) + h[j]
                h_list.append(tmp)
        if h_list.count(h_list[0]) == N - h.count(0) :
            ansx = topx
            ansy = topy
            ansH = h_list[0]
            break

print(ansx, ansy, ansH)


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a[9];
  for (int i = 0; i < 9; i++)
    cin >> a[i];
  
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; i++)
    cin >> b[i];
  
  vector<bool> c(9, false);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 9; j++) {
      if (b[i] == a[j])
        c[j] = true;
    }
  }
  
  int d[8][3] = {
    {0,1,2},
    {3,4,5},
    {6,7,8},
    {0,3,6},
    {1,4,7},
    {2,5,8},
    {0,4,8},
    {2,4,6}};
  
  bool fin = false;
  for (int i = 0; i < 8; i++) {
    if( c.at(d[i][0]) && c.at(d[i][1]) && c.at(d[i][2]) ) {
      cout << "Yes" << endl;
      fin = true;
      break;
    }
  }
  
  if (!fin)
    cout << "No" << endl;
}

Measured memory_bytes: 3608
#include<cstdio>
#include<algorithm>
#define maxn 120
using namespace std;
int c[4][4],N;
int read(){
	int w=0;char c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') w=w*10+c-48,c=getchar();
	return w;
}
int main(){
	int i,j;
	for(i=1;i<=3;i++){
		for(j=1;j<=3;j++){
			c[i][j]=read();
		}
	}
	if((c[1][1]+c[2][2]+c[3][3])==(c[1][2]+c[2][1]+c[2][3]+c[3][2]-c[2][2])&&(c[1][1]+c[2][2]+c[3][3])==(c[1][3]+c[2][2]+c[3][1])) printf("Yes");
	else printf("No");
	return 0;
}

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

int main() {
  int N, Q;
  cin >> N;
  long long sum = 0;
  vector<long long> num(110000, 0);
  for (int i = 0; i < N; ++i) {
    long long A;
    cin >> A;
    sum += A;
    num[A]++;
  }

  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    long long B, C;
    cin >> B >> C;
    sum += (C - B) * num[B];
    num[C] += num[B];
    num[B] = 0;
    cout << sum << endl;
  }
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
#define mod 1000000007
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto i:a) cout << i << " "; cout << endl
#define adb2(a) for(auto i:a) cout << i.first << " " << i.second << endl;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define N 100010
using namespace std;

int main()
{
    /*#ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif*/

    fastIO;
    long long n, a, b;
    cin >> n >> a >> b;

    cout << (n/(a+b))*a + min(n%(a+b),a) << endl;
}

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

int main() {
	int N, K, h[100000], MIN;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	sort(h, h + N);
	MIN = h[K - 1] - h[0];
	for (int i = 1; i <= N - K; i++) {
		MIN = min(MIN, h[i + K - 1] - h[i]);
	}
	cout << MIN;
}

Measured memory_bytes: 640
#include<stdio.h>
#define N -1
#define MAX 100001
  
struct Node{
  int p,l,r;
};
  
struct Node T[MAX];
int a[MAX];

int deg(int);
int he(int); 
int dep(int);
int si(int);

main(void){
  int P,n,i;

    
  scanf("%d",&n);
    
  for(i=0;i<n;i++){
    T[i].p=T[i].l=T[i].r=N;
  }
    
  for(i=0;i<n;i++){
    scanf("%d",&P);
    scanf("%d %d",&T[P].l,&T[P].r);

    T[T[P].l].p=P;
    T[T[P].r].p=P;
  }
    
  for(i=0;i<n;i++){
    a[i]=dep(i);

  }
    
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,T[i].p, si(i), deg(i),a[i],he(i));   
    if(T[i].p==N) printf("root\n");
    else if(T[i].l!=N||T[i].r!=N){
     printf("internal node\n");
    }
    else {
     printf("leaf\n");
   } 
  }
  return 0;
}
  
  
int dep(int i){
  int count=0;
  while(T[i].p!=N){
    count=count+1;
    i=T[i].p;
  }
  return count;
}
  
  
int si(int i){
  if(T[i].p==N){
  return N;
 }
  if(T[T[i].p].r==i){
  return T[T[i].p].l;
 }
  if(T[T[i].p].l==i){
  return T[T[i].p].r;
 }
}
  
int deg(int i){
  int count=0;
  if(T[i].l!=N){
   count=count+1;
 }
  if(T[i].r!=N){
   count=count+1;
 }
  return count;
}
  
int he(int i){
  int h1=0;
  int h2=0;
  if(T[i].l!=N){
   h1=he(T[i].l)+1;
  }

  if(T[i].r!=N){
   h2=he(T[i].r)+1;
  }
    
  if(h1<h2) return h2;
  else return h1;
}

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

public class Main {

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String test = br.readLine();
		
		int second = Integer.parseInt(test);
		int minite = 0;
		int hour = 0;
		
		minite = second / 60;
		second %= 60;
		hour = minite / 60;
		minite %= 60;
		
		System.out.println(hour+ ":" + minite + ":" + second);
		
		
	}
}

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

int main()
{
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  int c5=0,c7=0;
  for(int i=0;i<a.size();i++){
    if (a[i]==5)c5++;
    else if (a[i]==7)c7++;
  }
  if (c5==2 && c7==1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main
{
    public static int swap(int a, int b)
    {
        return a;
    }
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int a[] = new int[4];
        for (int t = 0; t < 10; t++)
        {
            a[3] = input.nextInt();
            for (int i = 2; i >= 0; i--)
            {
                if (a[i] < a[i+1])
                {
                    a[i+1] = swap(a[i], a[i]=a[i+1]);
                }
            }
        }
        for (int i = 0; i < 3; i++)
        {
            System.out.println(a[i]);
        }
        input.close();
    }
}

Measured memory_bytes: 26148
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

R, G, B = map(int, input().split())
K = int(input())

for k in range(K):
    if G <= R:
        G *= 2
    elif B <= G:
        B *= 2
    else:
        B *= 2

if B > G > R:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 10832
package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func main(){
	var X, Y, ans int 
	fmt.Scan(&X, &Y)
	num := X
	for num <= Y {
		ans++
		num *= 2
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

template<class T>
void print(vector<T>v){
	ll size=v.size();
	for(int i=0;i<size;i++){
		cout<<v[i]<<" ";
	}
	cout<<endl;
}

ll F(ll n){
	//0 xor 1 xor ... xor n
	ll ret=0;
	for(int i=0;i<60;i++){
		ll num=(n+1)/(ll)pow(2,i+1)*(ll)pow(2,i)+max(0LL,(n+1)%(ll)pow(2,i+1)-(ll)pow(2,i));
		if(num%2==1)ret+=(ll)pow(2,i);
	}
	return ret;
}

int main(){
    init();
	ll a,b;cin>>a>>b;
	ll ans=F(a-1)^F(b);
	cout<<ans<<endl;;
}


Measured memory_bytes: 256
n = int(input())
hs = list(map(int, input().split()))

dp = [float('inf')]*n

dp[0] = 0

for i in range(1, n):
  if i == 1:
    dp[i] = min(dp[i], dp[i-1]+abs(hs[i]-hs[i-1]))
  else:
    dp[i] = min(dp[i], dp[i-1]+abs(hs[i]-hs[i-1]))
    dp[i] = min(dp[i], dp[i-2]+abs(hs[i]-hs[i-2]))

print(dp[-1])

Measured memory_bytes: 13928
Scanf.scanf "%d" (fun n ->
    let b = Array.init n (fun _ -> Scanf.scanf " %d" (fun b -> b)) in
    let search b =
        let k = Array.length b in
        let rec loop i =
            if i < 0 then None else
                if b.(i) = i + 1 then Some i else loop (i - 1)
        in
        loop (k - 1)
    in
    let remove b x =
        let k = Array.length b in
        let b2 = Array.make (k - 1) 0 in
        let rec loop i j =
            if i = k then b2 else 
                if i = x then loop (i + 1) j else (
                    b2.(j) <- b.(i);
                    loop (i + 1) (j + 1)
                )
        in
        loop 0 0
    in
    let rec loop b i history =
        if i = 0 then history else
            match search b with
            | Some x -> loop (remove b x) (i - 1) ((x + 1) :: history)
            | None -> []
    in
    let k = loop b n [] in
    if k = [] then print_endline "-1" else
        List.iter (Printf.printf "%d\n") k
)

Measured memory_bytes: 3864
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n;cin>>n;
    ll a,b;cin>>a>>b;
    ll X=0;
    rep(i,n-2){
        ll c;cin>>c;
        X^=c;
    }
    ll Y=(a+b-X)/2;
    if(a+b<X||(a+b)%2!=X%2){
        cout<<-1<<endl;
        return 0;
    }
    ll x=0;
    rep(i,60){
        if((1LL<<i)&Y){
            if((1LL<<i)&X){
                cout<<-1<<endl;
                return 0;
            }
            x+=(1LL<<i);
        }
    }
    if(x>a){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=60;i>=0;i--){
        if((1LL<<i)&Y)continue;
        if((1LL<<i)&X){
            if((x+(1LL<<i))<=a)x+=(1LL<<i);
        }else{
            continue;
        }
    }
    if(x==0)x=a+1;
    cout<<a-x<<endl;
}

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

#define sz(s) (int)(s).size()
#define re(i, n) for (int i = 1; i <= n; i ++)
#define pb push_back
#define finish(x) return cout << x << endl, 0
#define MP make_mair
#define trav(x, a) for(auto& x: a)
#define all(x) (x).begin,(x).end()
#define Sor(x) sort(all(x))
#define REV(x) reverse(all(x))
#define F first
#define S second
#define I insert
#define N 222222
#define MOD 1000000007

using namespace std;

typedef long long ll;
vector <ll> vll;
template <class T> bool umin(T& a, T b) {if(a>b){a = b; return 1;}return 0;}
template <class T> bool umax(T& a, T b) {if(a<b){a=b; return 1;}return 0;}
template <class T, class TT> bool pal(T a, TT n){int k = 0; for(int i =0; i <= n / 2; i ++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

ll powmod(ll a, ll b, ll m = MOD){ll r = 1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	int x;
	cin >> x;
	int p = x / 500;
	x %=  500;
	int q = x / 5;
	cout << p * 1000 + q * 5;
	
    
    
    
    
    
    
    
    
    
}


Measured memory_bytes: 256
open Printf open Scanf
module MyInt = struct let (+) = (+) let (-) = (-) let (/) = (/) let ( * ) = ( * ) let (mod) = (mod) let (%) = (mod) let (+=) r v = r := !r + v let (-=) r v = r := !r - v let ( *=) r v= r := !r * v let (/=) r v = r := !r / v end

let () =
	let n,k = scanf " %d %d" (fun u v -> u,v)
	in let q = n/k in
	(
		if k mod 2 = 1 then (
			q*q*q
		) else (
			q*q*q + (
				let v = k/2 in let r = n mod k in
				if r>=v then let qq=q+1 in qq*qq*qq
				else q*q*q
			)
		)
	)
	|> printf "%d\n"

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
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; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int n,m,q;
int A[10];
int a[50],b[50],c[50],d[50];
ll ans = 0;

void dfs(int i,int val){
    if(i == n){
        ll tmp = 0;
        rep(k,0,q-1){
            if(A[b[k]-1] - A[a[k]-1] == c[k]) tmp += d[k];
        }
        ans = max(ans,tmp);
        return;
    }
    rep(j,val,m){
        A[i] = j;
        dfs(i+1,j);
    }
    return;
}

int main(){
    cin>>n>>m>>q;
    rep(i,0,q-1) cin>>a[i]>>b[i]>>c[i]>>d[i];
    dfs(0,1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3556
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    getLine
    as <- getIntList
    let ans = fst $ foldl' f (0,0) as
    print ans

f (s,h1) h2 | h1 <= h2 = (s,h2)
            | otherwise = (s + h1 - h2, h1)


Measured memory_bytes: 10144
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    map<int,int>m;
    int a[n];
    for(int i=0; i<n-1; i++){
        cin>>a[i];
        m[a[i]]=0;
    }
    for(int i=0;i<n-1;i++)
    {
            m[a[i]]++;
    }
    for(int i=0; i<n; i++)
        cout<<m[i+1]<<endl;
}

Measured memory_bytes: 13756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
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 (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll N; cin >> N;
    map<ll, ll, greater<ll>> M;
    REP(i, N) {
        ll a; cin >> a;
        M[a]++;
        M[a-1]++;
        M[a+1]++;
    }
    ll ans = 0;
    for(auto m : M) {
        chmax(ans, m.second);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 6144
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
    int T; scanf("%d", &T);
    while(T --) {
        ll a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
        ll g = gcd(b, d);
        if(b > a || b > d) puts("No");
        else if(c + 1 >= b) puts("Yes");
        else puts((a - c - 1) / g > (a - b) / g ? "No" : "Yes");
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define LINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define PI 3.14159265
#define RAND (rand()*rand())
#define MAX(x, y) ((x) > (y) ? (x):(y)) 
#define MIN(x, y) ((x) > (y) ? (y):(x))
#define ABS(x) ((x) > 0 ? (x) : -(x))
#define CEIL(x, y) (((x) + (y) - 1)/(y))
using namespace std;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;
char str[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main()
{
	int i, j;
	scanf("%d", &N);
	printf("%d", str[N - 1]);
}

Measured memory_bytes: 256
N,K = [int(i) for i in input().split()]
dic = {}
sum = 0

for i in range(N):
    a,b = [int(i) for i in input().split()]
    if a in dic:
        dic[a] += b
    else:
        dic[a] = b

dic = sorted(dic.items())

for i in range(len(dic)):
    sum += dic[i][1]
    if K <= sum:
        print(dic[i][0])
        break


Measured memory_bytes: 19992
n=int(input())
a=list(map(int,input().split()))
a=sorted(a,reverse=True)
space=[a[0]]
t=0
coco=0
for i in range(1,n):
    coco += space[t]
    t += 1
    space.append(a[i])
    space.append(a[i])
print(coco)

Measured memory_bytes: 31524
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
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 T> struct fenwick_tree {
    public:
    fenwick_tree() : _n(0) {}
    fenwick_tree(int n) : _n(n), data(n) {}

    void add(int p, T x) {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n) {
            data[p - 1] += T(x);
            p += p & -p;
        }
    }

    T sum(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

    private:
    int _n;
    std::vector<T> data;

    T sum(int r) {
        T s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    fenwick_tree<ull> fw(n);
    rep(i, n) {
        int a;
        cin >> a;
        fw.add(i, a);
    }
    rep(i, q) {
        int t, a, b;
        cin >> t >> a >> b;
        if(t == 0) {
            fw.add(a, b);
        }
        else if (t == 1) {
            cout << fw.sum(a, b) << endl;
        }
    }
}

Measured memory_bytes: 8228
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

//modしながら塁乗
ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  ll n;cin>>n;
  ll a[n];
  cin>>a[0];
  for(ll i=1;i<n;i++){
    ll t;cin>>t;
    a[i] = a[i-1] + t;
  }
  vector<ll> v;
  REP(i,n){
    v.pb(a[i]);
  }
  v.pb(0);
  VSORT(v);
  ll ans = 0;
  ll i = 1;
  ll count = 1;
  while(i<v.size()){

    if(v[i] != v[i-1]){
      ans += count * (count - 1) / 2;
      count = 0;
    }
        count++;
    i++;
  }
  ans += count * (count - 1) / 2;

  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 3956
N=int(input())
l1=input().split(' ')
l2=input().split(' ')

max=0
for i in range(N):
	sum=0
	for j in range(i+1):
		sum+=int(l1[j])
	for k in range(i,N):
		sum+=int(l2[k])

	if max<sum:
		max=sum

print(max)

Measured memory_bytes: 3064
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.util.LinkedList;

public class Main {
	public class pair implements Comparable<pair> {
		int wt;
		int val;
		double rat;

		pair(int a, int v) {
			wt = a;
			val = v;
			rat = v / wt;
		}

		@Override
		public int compareTo(pair o) {
			// TODO Auto-generated method stub
			return (int) (this.rat - o.rat);
		}

	}

	public static void main(String[] args) throws IOException {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int m = scn.nextInt();
		ArrayList<Integer> g[] = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			g[i] = new ArrayList<>();
		}
		for (int i = 0; i < m; i++) {
			int x = scn.nextInt() - 1;
			int y = scn.nextInt() - 1;
			g[x].add(y);
		}
		int dp[] = new int[n];
		HashSet<Integer> hset = new HashSet<>();
		for (int i = 0; i < n; i++) {
			if(!hset.contains(i)){
			dp[i] = dfs(i, hset, dp, g);}
		}
		int max = 0;
		for(int v : dp) {
			max = Math.max(max, v);
		}
		System.out.println(max);
	}

	private static int dfs(int sr, HashSet<Integer> hset, int[] dp, ArrayList<Integer>[] g) {
		if (hset.contains(sr)) {
			return dp[sr];
		}
		hset.add(sr);
		int res = -1;
		for (int nei : g[sr]) {
			res = Math.max(res, dfs(nei, hset, dp, g));
		}
		dp[sr] = Math.max(dp[sr], res+1);
		return dp[sr];

	}

}

Measured memory_bytes: 115876
#include<iostream>
#include<string>

using namespace std;

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

	if (((N[0] == N[1]) && (N[1] == N[2])) || ((N[2] == N[3]) && (N[1] == N[2]))) {
		cout << "Yes" << endl;
		return 0;
	}

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

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF = 1e16+5;
const ll MAX = 100005;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a, b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n, m, arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n, arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len = v.size();
    for(int i = 0; i < len; ++i) {
        s<<v[i];
        if(i < len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len = vv.size();
    for(int i = 0; i < len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}


struct Tuple {
    ll fi, se, th;
    Tuple() {};
    Tuple(ll a, ll b, ll c) : fi(a), se(b), th(c) {};
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, l, q;
    cin>>n>>m>>l;
    vector<vector<P>> g(n+1);
    VV dist(n,Vec(n,INF));

    rep(i, m) {
        ll a, b, c;
        cin>>a>>b>>c;
        a--;b--;
        dist[a][b]=c;
        dist[b][a]=c;
    }
    cin>>q;

//    rep(i,n){
//        dbg(grph[i]);
//    }

    rep(k, n)
        rep(j, n)
            rep(i, j) {
                dist[i][j] = dist[j][i] = min(dist[i][j], dist[i][k]+dist[k][j]);
            }
    //dbg(dist);
    VV dist2(n, Vec(n, INF));

    rep(j, n)
        rep(i, j) {
            if(dist[i][j] <= l) {
                dist2[i][j] = 1;
                dist2[j][i] = 1;
            }
        }
    rep(k, n)
        rep(j, n)
            rep(i, j) {
                dist2[i][j] = dist2[j][i] = min(dist2[i][j], dist2[i][k]+dist2[k][j]);
            }

    while (q--) {
        ll s, t;
        cin>>s>>t;
        s--;t--;
        ll ans = dist2[s][t] == INF ? -1 : dist2[s][t]-1;
        cout<<ans<<endl;
    }
    return 0;
}


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

#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define MAX(X,Y) ((X)>(Y)?(X):(Y))

int main(void){
  long fib[50];
  int n;
  
  cin >> n;
  fib[0] = fib[1] = 1;
  for (int i=2; i<=n; i++){
    fib[i] = fib[i-2]+fib[i-1];
  }
  cout << fib[n] << endl;
  return 0;
}


Measured memory_bytes: 3132
import java.io.*;
 
class Main{
 public static void main(String[] args)throws IOException{
  BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  int num,i,j;
  num = Integer.parseInt(br.readLine());
  int[][] cards = new int[4][13];   
   for(i=0;i<4;i++){
    for(j=0;j<13;j++){
     cards[i][j]=0;
    }
   }
 
   for(i=0;i<num;i++){ 
    String str = br.readLine(); 
    String[] strAry = str.split(" ");
    String op = strAry[0];
    int number = Integer.parseInt(strAry[1]);
    number--;   
 
    if(op.equals("S")){            
      cards[0][number]=1; 
    }else if(op.equals("H")){
      cards[1][number]=1;
    }else if(op.equals("C")){
      cards[2][number]=1;
    }else if(op.equals("D")){
      cards[3][number]=1;
    }
   }
     
   for( i=0;i<4;i++){
    for(j=0;j<13;j++){
     if(cards[i][j]==0){
       if(i==0){   
         System.out.println("S "+ (j+1));     
       }else if(i==1){
         System.out.println("H "+ (j+1));
       }else if(i==2){
         System.out.println("C "+ (j+1));
       }else if(i==3){
         System.out.println("D "+ (j+1));
       }
    }
   }
    
  }
 }
}

Measured memory_bytes: 24272
H, W = map(int, input().split())

board = list()
line = list()

for x in range(0, H):
    word = input()
    for y in word:
        line.append(y)
    if '#' in line:
        board.append(line)
    line = list()

H = len(board)

goodx = [True]*W

judge = True

for a in range(0, W):
    for b in range(0, H):
        if board[b][a] == '#':
            judge = False
    if judge:
        goodx[a] = False
    judge = True

for a in range(0, H):
    for b in range(0, W):
        if goodx[b]:
            print(board[a][b], end='')
    print('')


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

int a, b, c, d, ans;
char s[101], t[101];

int main(void)
{
    scanf("%d%d%d%d", &a, &b, &c, &d);
    for(int i=1; i<=d; i++)
    {
        if(a) ans++, a--;
        else if(b) b--;
        else ans--, c--;
    }
    
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3732
N = int(input())

# 1000くらいまで素数を作る
prime = [2, 3]
ret = []
for i in range(5, 55555 + 1, 2) :
    j = 0
    flg = False
    while prime[j] * prime[j] <= i :
        if i % prime[j] == 0 :
            flg = True
            break
        j += 1
    if flg :
        continue
    prime.append(i)
    if i % 10 == 1 :
        ret.append(i)
        if len(ret) == N :
            break
    
print(*ret)

Measured memory_bytes: 39024
#include "bits/stdc++.h"
using namespace std;
const int INF = 1e9;

signed main(){
  int N; cin >> N;
  string s; cin >> s;
  int Q; cin >> Q;
  vector<set<int> > alp(26, set<int> {INF});
  for(int i = 0; i < N; i++) alp[s[i] - 'a'].insert(i);
  
  for(int i = 0; i < Q; i++){
    int t; cin >> t;
    if(t == 1){
      int i; char c; cin >> i >> c; --i;
	  if(s[i] != c) alp[s[i] - 'a'].erase(i);
		s[i] = c;
		alp[c - 'a'].insert(i);
    }
    if(t == 2){
      int ans = 0;
      int l, r; cin >> l >> r; --l;
      for(int c = 0; c < 26; c++){
        if(alp[c].empty()) continue;
        if(*alp[c].lower_bound(l) < *alp[c].lower_bound(r)) ans++;
      }
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 24196
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    string S; cin >> S;
    vector<vector<ll>> RGB(3);
    for(ll i = 0; i < N;i++){
        if(S[i] == 'R'){
            RGB[0].emplace_back(i);
            S[i] = 0;
        }
        if(S[i] == 'G'){
            RGB[1].emplace_back(i);
            S[i] = 1;
        }
        if(S[i] == 'B'){
            RGB[2].emplace_back(i);
            S[i] = 2;
        }
    }
    
    for(int i = 0; i < N;i++){
        for(int j = i+1; j < N;j++){
            if(S[i] == S[j]) continue;
            set<ll> st{S[i],S[j]};
            
            for(int k = 0; k < 3;k++){
                if(st.find(k) != st.end()) continue;
                
                ll L = upper_bound(RGB[k].begin(),RGB[k].end(),j) - RGB[k].begin();
                
                auto it = lower_bound(RGB[k].begin(),RGB[k].end(),j+(j-i));
                
                bool flag = false;
                if(it != RGB[k].end()){
                    if(*it == j+(j-i)){
                        flag = true;
                    }
                }
                ll D = RGB[k].size() - L;
                if(flag) D--;
                res += D;
            }
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 3732
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <fstream>
#include <cstdlib>
#include <cstdio>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;

int main(){
    int N;cin>>N;
    int ans = 0;
    REP(i, N){
        int a;
        cin >> a;
        ans += a-1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {
    public static void main (String[] args) throws java.lang.Exception {
    
    BufferedReader input = new BufferedReader (new InputStreamReader(System.in));
    String x   = input.readLine();
    int output = Integer.parseInt(x);
    output = output * output * output;
    System.out.println(output);
    }
}



Measured memory_bytes: 24360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n);
  map<ll, ll> mp;
  rep(i, n) {
    cin >> a[i];
    mp[a[i]]++;
  }
  ll sum = 0;
  for(auto v : mp) {
    ll i = v.second;
    sum += i * (i - 1) / 2;
  }
  rep(i, n) {
    ll ans = sum;
    ll j = mp[a[i]];
    ans -= j * (j - 1) / 2;
    ans += (j - 1) * (j - 2) / 2;
    cout << ans << endl;
  }
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,ans;
  ans=0;
  cin >> n;
  rep(i,n)ans=max(ans,ORD(i+1,2));
  printf("%lld",POW(2,ans));
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX = 111;

int N;
int L[MAX];

int main(){
    cin >> N;
    int sm = 0;
    int mx = 0;
    for (int i = 0; i < N; i++) {
        cin >> L[i];
        sm += L[i];
        mx = max(mx, L[i]);
    }

    cout << ((mx*2 < sm) ? "Yes" : "No") << endl;
}

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

int main() {
    int n, m, l, r, sum, ans, imos[100001] = {};
    cin >> n >> m;
    
    for ( int i = 0; i < m; i++ ) {
        cin >> l >> r;
        imos[l-1] ++;
        imos[r] --;
    }
    
    ans = 0;
    sum = 0;
    for ( int i = 0; i <= n; i++ ) {
        sum += imos[i];
        
        if ( sum == m ) {
            ans ++;
        } 
    }
    
    cout << ans << endl;
    
    return (0);
}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  string s="CODEFESTIVAL2016";
  string t;cin>>t;
  rep(i,0,s.size()){
    if(s[i]!=t[i])res++;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256