akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          var s = Input.ScanStr();
          List<char> t = new List<char>();
          for(int i=0; i<s.Length; i+=2)
            t.Add(s[i]);
          
          Out(new string(t.ToArray()));
        }
        static public void Out(object s) { Console.WriteLine(s); }
    }
    
    static class Input {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(); }
    }

    static class MyMath {
        public static int DistanceL1(int[] a, int[] b){
            if(a.Length != b.Length) return -1;
            int[] c = new int[a.Length];
            for(int i=0;i<a.Length;i++)
              c[i] = Math.Abs(a[i]-b[i]);
            return c.Sum();
        }

        public static double DistanceL2(int[] a, int[] b){
            if(a.Length != b.Length) return -1;
            int[] c = new int[a.Length];
            for(int i=0;i<a.Length;i++)
              c[i] = (a[i]-b[i])*(a[i]-b[i]);
            return Math.Sqrt(c.Sum());
        }
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;
#define pai 3.141592653589793238462643383279




int main(){
  bool can = false;
  int x, y; cin >> x >> y;
  rep(i, 100){
    rep(j, 100){
      if(2*i+4*j==y && i+j==x){
        can = true; break;
      }
    }
  }
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
}
    

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1e9 + 7;
int main() {
	int N, K;
	cin >> N >> K;
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0;i < N-1;++i) {
		if (s[i] == s[i + 1]) {
			++cnt;
		}
	}
	cout << min(N - 1, cnt + 2 * K) << "\n";

	return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 3e2 + 5;

int n,ans,t[N][N];
char s[N][N];

bool check(int x) {
  for (int i = 0 ; i < n ; i++)
    for (int j = 0 ; j < n ; j++)
      if (s[i][(j + x) % n] != s[j][(i + x) % n])
        return false;
  return true;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n;
  for (int i = 0 ; i < n ; i++)
    for (int j = 0 ; j < n ; j++)
      cin >> s[i][j];
  for (int i = 0 ; i < n ; i++)
    if (check(i))
      ans += n;
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
#pragma warning (disable: 4996)

long long mod = 1000000007;
long long N, K, A[100009], B1, B2;

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (A[i] > A[j]) B1++;
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (A[i] > A[j]) B2++;
		}
	}
	long long C1 = K;
	long long C2 = K * (K - 1) / 2LL; C2 %= mod;
	cout << (B1*C1 + B2 * C2) % mod << endl;
	return 0;
}

Measured memory_bytes: 256
#import <stdio.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
int main(){
    int N;
    scanf("%d", &N);
    int C[9] = {0};
    for(int i=0;i<N;i++){
        int a;
        scanf("%d", &a);
        C[MIN(a/400,8)]++;
    }
    int count=0;
    for(int i=0;i<8;i++){
        if(C[i]>0) count++;
    }
    printf("%d %d", MAX(count,1), count+C[8]);
}


Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main(){
	int n;
	string s;
	cin>>n>>s;

	int ans=0;

	for (int i = 0; i < 1000; ++i){
		char tar[4];
		sprintf(tar,"%03lld", i);

		int cnt=0;

		for (int j = 0; j < n; ++j){
			if(s[j]==tar[cnt]){
				cnt++;
			}
		}

		if(cnt==3)ans++;

	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a[3], f=0, s=0;
    
    rep(i, 3){
        scanf("%d", &a[i]);
        if (a[i]==5) {
            f++;
        } else if (a[i]==7){
            s++;
        }
    }
    
    if (s==1&&f==2) {
        printf("YES");
    } else {
        printf("NO");
    }
    
    return 0;
}



Measured memory_bytes: 1732
import sys
N = int(input())
A = []
for _ in range(N):
    temp = list(map(int, input().split()))
    A.append(temp)
A = sorted(A,key = lambda x : x[1])
time = 0
for i in A:
    time += i[0]
    if time > i[1]:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 91736
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt();
		long ans = 0;

		if (n % 2 == 0) {
			ans = n;
		} else {
			ans = 2 * n;
		}
		
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 21716
n = int(input())
l = []
for i in range(n):
  xi,yi = map(int,input().split())
  l.append([xi,yi])
s = 0
for i in range(n-1):
  for j in range(i+1,n):
    s += ((l[i][0]-l[j][0])**2+(l[i][1]-l[j][1])**2)**(1/2)
print((2*s)/n)
    
  

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> cnt(m);
  rep(i, n) {
    int k;
    cin >> k;
    rep(j, k){
      int a;
      cin >> a;
      a--;
      cnt[a]++;
    }
  }
  int ans = 0;
  rep(i, m) {
    if(cnt[i]== n) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3556
#include <iostream>
int main()
{
	using namespace std;
	int num;
	cin >> num;
	
	int sort[num];
	for (int i=0; i < num; i++) cin >> sort[i];
	
	int oper = 0;
	int v = 0;
	for (int i = 0; i < num - 1; i++){
		for (int j = num-1; j > 0; j--){
			if (sort[j] < sort[j-1]){
				v = sort[j];
				sort[j] = sort[j-1];
				sort[j-1] = v;
				oper++;
			};
		};
	};
	cout << sort[0];
	for (int i = 1; i < num; i++) cout << " " << sort[i];
	cout << endl << oper << endl; 
	return 0;
 } 


Measured memory_bytes: 3136
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
using namespace std;
#define MOD 1000000007




int main() {
	int a, b, k;
	cin >> a >> b >> k;
	int num = 0;
	for (int i = b; i > 0; i--) {
		if (b%i == 0 && a%i == 0) {
			num++;
			if (num == k) {
				cout << i;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
from itertools import permutations

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

l = [A,B,C,D,E]
lll = []
for i in permutations(l):
    ll = []
    for j in i[:-1]:
        if not j % 10 == 0:
            j = j + 10 - (j % 10)
        ll += [j]
    ll += [i[-1]]
    lll += [sum(ll)]

print(sorted(lll)[0])


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;

int a,b;

int main() {
	scanf("%d %d",&a,&b);
	int ans=a+(b<a?-1:0);
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <functional>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    int N;
    scanf("%d", &N);

    int a[N];
    REP(0, i, N) {
        scanf("%d", &a[i]);
    }

    sort(a, a + N, greater<int>());

    // REP(0, i, N) {
    //     printf("%d\n", a[i]);
    // }

    int ans = 0;
    REP(0, i, N) {
        if (i % 2 == 0) {
            ans += a[i];
        } else {
            ans -= a[i];
        }
    }

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

    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long H, W, K; cin >> H >> W >> K;
	vector<vector<char>>A(H, vector<char>(W));
	long long bl = 0;
	long long ans = 0;
	vector<pair<long, long>>Black;
	for (long long i = 0; i < H; i++) {
		for (long long j = 0; j < W; j++) {
			cin >> A.at(i).at(j);
			if (A.at(i).at(j) == '#') {
				bl++;
				Black.push_back(make_pair(i, j));
			}
		} 
	}
	const vector<vector<char>>B = A;
	for (long long i = 0; i < (1 << H); i++) {
		for(long long j = 0; j < (1 << W); j++) {
			vector<long long>ta;
			for (long long k = 0; k < H; k++) {
				if (i & (1 << k)) ta.push_back(k);
			}
			vector<long long>yo;
			long long tmp = 0;
			for (long long k = 0; k < W; k++) {
				if (j & (1 << k)) yo.push_back(k);
			}
			for (long long k = 0; k < Black.size(); k++) {
				A.at(Black.at(k).first).at(Black.at(k).second) = '#';
			}
			if (!ta.empty()) {
				for (long long k = 0; k < ta.size(); k++) {
					for (long long l = 0; l < W; l++) {
						if (A.at(ta.at(k)).at(l) == '#') {
							tmp++;
							A.at(ta.at(k)).at(l) = '.';
						}
					}
				}
			}
			if (!yo.empty()) {
				for (long long k = 0; k < yo.size(); k++)
				{
					for (long long l = 0; l < H; l++) {
						if (A.at(l).at(yo.at(k)) == '#') {
							tmp++;
							A.at(l).at(yo.at(k)) = '.';
						}
					}
				}
			}
			if (bl - tmp == K) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
H, W = map(int, input().split(" "))
L = [list(input()) for i in range(H)]
a = ["#" for i in range(W)]
A = [a for i in range(H)]
ans = []
for i in range(H):
  for j in range(W):
    if L[i][j] == "#":
      ans.append("#")
      continue
    cnt = 0
    for ii in range(-1, 2):
      for jj in range(-1, 2):
        if ii == 0 and jj == 0:
          continue
        iii = i + ii
        jjj = j + jj
        if iii == i and jjj == j:
          continue
        if iii < 0 or iii > H -1:
          continue
        if jjj < 0 or jjj > W -1:
          continue
        if L[iii][jjj] == "#":
          cnt+=1
    ans.append(str(cnt))
    A[i][j] = str(cnt)
  print("".join(ans))
  ans = []

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

int main()
{
	ll N,M;
	ll ans=-1;
	ll sum=0;
	cin>>N>>M;
	vector<ll> A(M+10);
	for(ll i=0;i<M;i++){
		cin>>A[i];
		sum+=A[i];
	}
	if(sum<=N){
		ans=N-sum;
	}
	cout<<ans<<endl;
	return 0;
}



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

int main() {

	string s;
	cin >> s;
	if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'){
		puts("Yes");
	}else{
		puts("No");
	}
}

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

struct UnionFind{
	vi rank,par;
	void Init(int n){
		rank.assign(n,0);
		par.assign(n,-1);
	}
	int Find(int i){
		return par[i]==-1?i:(par[i]=Find(par[i]));
	}
	bool Same(int a,int b){
		return Find(a)==Find(b);
	}
	bool Unite(int a,int b){
		a=Find(a);
		b=Find(b);
		if(a==b)
			return false;
		if(rank[a]<rank[b])
			swap(a,b);
		par[b]=a;
		if(rank[a]==rank[b])
			rank[a]++;
		return true;
	}
} uf;

int main(){
	int n=read(),m=read();
	uf.Init(n+m);
	REP(i,n){
		int k=read();
		REP(_,k){
			int l=read();
			uf.Unite(i,n+l-1);
		}
	}
	bool same=true;
	FOR(i,1,n)
		if(!uf.Same(0,i))
			same=false;
	if(same)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
}


Measured memory_bytes: 1792
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
long bignum = 1_000_000_007;

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

auto manhattan(long x1, long y1, long x2, long y2)
{
    return abs(y2 - y1) + abs(x2 - x1);
}

void main()
{
    auto n = lread();
    auto t = lread();
    long c_multiple;
    foreach (i; 1 .. n)
    {
        auto clock = lread();
        auto tmp = gcd(t, clock);
        t = t / tmp * clock;
    }
    t.writeln();
}


Measured memory_bytes: 256
main = do
    s <- getLine
    let xs = zip s [1..]
    let (a,b) = solve xs
    putStr $ show a
    putStr " "
    putStrLn $ show b

solve [] = (-1,-1)
solve (_:[]) = (-1,-1)
solve ((a,l):(b,m):[]) | a == b = (l,m)
                       | otherwise = (-1,-1)
solve ((a,l):(b,m):(c,n):ys) | a == b = (l,m)
                             | a == c = (l,n)
                             | otherwise = solve ((b,m):(c,n):ys)

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

int cnt=0,n;

void merge(int s[],int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    int L[n1+1],R[n2+1];
    int i,j,k;
    for(i=0;i<n1;i++)L[i]=s[left+i];
    for(i=0;i<n2;i++)R[i]=s[mid+i];
    L[n1]=R[n2]=1000000001;
    i=j=0;
    for(k=left;k<right;k++){
        if(L[i]<=R[j]){
            s[k]=L[i];
            i++;
        }
        else{
            s[k]=R[j];
            j++;
        }
        cnt++;
    }
}

void mergeSort(int s[],int left,int right){
    if(left+1<right){
        int mid=(left+right)/2;
        mergeSort(s,left,mid);
        mergeSort(s,mid,right);
        merge(s,left,mid,right);
    }
}

int main(void){
    int i,s[500000];
    
    cin>>n;
    for(i=0;i<n;i++)cin>>s[i];
    
    mergeSort(s,0,n);
    
    for(i=0;i<n-1;i++)cout<<s[i]<<" ";
    cout<<s[n-1]<<endl;
    
    cout<<cnt<<endl;

    return 0;
}



Measured memory_bytes: 6944
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
const int MAXN = 234567;
bool visit[MAXN];
int dis[MAXN];

int main() {
    int K;
    scanf("%d", &K);
    if (K == 1) return !printf("1\n");
    deque<pii> pq;
    pq.push_front(make_pair(1, 1));
    while (!pq.empty()) {
          auto tp = pq.front();
          pq.pop_front();
          int cur = tp.second, cost = tp.first;
          if (visit[cur]) continue;
          visit[cur] = 1;
          dis[cur] = cost;
          pq.push_front(make_pair(cost, (cur * 10) % K));
          pq.push_back(make_pair(cost + 1, (cur + 1) % K));
    }
    printf("%d\n", dis[0]);
    return 0;
}


Measured memory_bytes: 1536
N, Y = map(int, input().split(' '))
res10000 = -1
res5000 = -1
res1000 = -1

for a in range(N+1):
    for b in range(N-a+1):
        c = N - a - b
        total = 10000*a + 5000*b + 1000*c
        if total == Y:
            res10000 = a
            res5000 = b
            res1000 = c

print(str(' '.join(map(str, [res10000, res5000, res1000]))))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define dbg() cerr <<
#define name(x) (#x) << ": " << (x) << ' ' <<

using namespace std;

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

  pair<int64_t, int64_t> a, b;
  cin >> a.first >> a.second;
  cin >> b.first >> b.second;
  int64_t t; cin >> t;

  if (a.first == b.first) {
    cout << "YES\n";
    return 0;
  }

  if (a.first < b.first) {
    int64_t v = a.second - b.second;
    cout << ((a.first + v * t >= b.first) ? "YES" : "NO") << '\n';
  } else {
    int64_t v = a.second - b.second;
    cout << ((a.first - v * t <= b.first) ? "YES" : "NO") << '\n';
  }
} 


Measured memory_bytes: 3636
D = int(input())
c = list(map(int, input().split()))

s = []
for _ in range(D):
    s.append(list(map(int, input().split())))

# last(d, i)を計算するためのメモ
new_dp = [[0] * 26 for _ in range(D)]

dp = [0] * 26


def dec(d, dp):
    # d日の終わりに起こる満足度の減少計算の関数
    s = 0
    for j in range(26):
        if dp[j] != 0:
            s += c[j] * (d - dp[j])
            continue
        s += c[j] * (d - new_dp[d - 1][j])

    return s


# d日目に開催するコンテストを決める
v = 0
for d in range(D):
    a = 0
    b = 0
    for i in range(26):
        old = new_dp[d][i]
        new_dp[d][i] = (d + 1)
        if (a <= s[d][i] - dec(d + 1, dp)):
            a = max(s[d][i] - dec(d + 1, dp), a)
            b = i
        new_dp[d][i] = old
    v += a
    dp[b] = d + 1
    print(b + 1)


Measured memory_bytes: 9396
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <limits.h>
#include <math.h>

#include <iostream>
#include <string>
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)

typedef pair<int, int> P;
typedef struct edge_Def {
	int to;
	int dist;
	int cost;
	edge_Def(int _to, int _dist, int _cost) {to = _to; dist = _dist; cost = _cost;}
} edge;

const int INF = 1000000000;
const int MAX_N = 10000;
const int MAX_M = 20000;
int N, M;
int d[MAX_N];
vector<edge> g[MAX_N];

void Dijkstra(int s) {
	int i, j;
	priority_queue<P, vector<P>, greater<P> > q;

	for (i=0; i<N; i++) d[i] = INF;
	d[s] = 0;
	q.push(P(0, s));

	while (q.size()) {
		P p = q.top(); q.pop();
		int v = p.second;

		if (d[v] < p.first) continue;

		for (i=0; i<g[v].size(); i++) {
			edge e = g[v][i];
			if (d[e.to] > d[v] + e.dist) {
				d[e.to] = d[v] + e.dist;
				q.push(P(d[e.to], e.to));
			}
		}
	}
}

int minCost() {
	int res = 0;
	int i, j;
	for (i=1; i<N; i++) {
		int m = INF;
		for (j=0; j<g[i].size(); j++) {
			edge e = g[i][j];
			if (d[e.to] + e.dist == d[i] && e.cost < m)
				m = e.cost;
		}
		res += m;
	}
	return res;
}

int main() {
	int i, j;

	while (1) {
		scanf("%d%d ", &N, &M);

		if (!N && !M) break;

		for (i=0; i<N; i++)
			g[i].clear();

		for (i=0; i<M; i++) {
			int f, t, d, c;
			scanf("%d%d%d%d ", &f, &t, &d, &c);
			f--; t--;
			g[f].push_back(edge(t, d, c));
			g[t].push_back(edge(f, d, c));
		} 

		Dijkstra(0); 
		printf("%d\n", minCost());
	}

	return 0;
}

Measured memory_bytes: 3236
N = int(input())
X = list(map(int,input().split()))
work = X.copy()
work.sort()
dict = {}
left = N // 2
right = left - 1
for i in range(N):
    if i < N // 2:
        dict[work[i]] = work[left]
    else:
        dict[work[i]] = work[right]
for i in range(N):
    print(str(dict[X[i]]))

Measured memory_bytes: 34448
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll s, w;
  cin >> s >> w;

  string ans = "safe";
  if (w >= s) {
    ans = "unsafe";
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 3616
#include <cstdio>
#define lowbit(x) ((x)&(-(x)))
using namespace std;
int N, A, B;
void dg(int ks, int js, int jd) {
//	printf("ks : %d js : %d jd : %d\n", ks, js, jd);
	if (ks == js) {
		printf("%d ", ks);
		return ;
	}
	int bt = lowbit(ks ^ js);
//	printf("bt : %d\n", bt);
	jd ^= bt;
	int tmp = ks ^ lowbit(jd);
//	printf("ks : %d js : %d jd : %d tmp : %d tmp ^ bt : %d lowbit(ks & jd) : %d\n", ks, js, jd, tmp, tmp ^ bt, lowbit(ks & jd));
	dg(ks, tmp, jd);
	dg(tmp ^ bt, js, jd);
}
int bitccount(int x) {
	int ret = 0;
	for (int i = 0; i < 31; ++i)
		ret += (x >> i) & 1;
	return ret;
}
int main() {
	scanf("%d%d%d", &N, &A, &B);
	if ((bitccount(A) ^ bitccount(B)) & 1) {
		printf("Yes\n");
		dg(A, B, (1 << N) - 1);
		printf("\n");
	} else printf("No\n");
	return 0;
}
//3 4 6

Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll n, k;

  cin >> n >> k;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());


  ll l = -1e18 - 1, r = 1e18 + 10, mid;
  while(l + 1 < r){
    mid = (l + r)/2;

    ll num = 0;
    for (int i = 0; i < n; i++){
      ll left, right, m;
      if (a[i] > 0){
        if (a[i] * a[0] > mid){
          left = -1;
        }
        else {
          left = 0;
          right = n;
          while(left + 1 < right){
            m = (left + right)/2;
            if (a[i] * a[m] <= mid)
              left = m;
            else
              right = m;
          }
        }
        num += left + 1;
      } else if (a[i] < 0){
        if (a[i] * a[n-1] > mid){
          right = n;
        }
        else {
          left = -1;
          right = n - 1;
          while(left + 1 < right){
            m = (left + right)/2;
            if (a[i] * a[m] <= mid)
              right = m;
            else
              left = m;
          }
        }

        num += n - right;
      }
      else{
        if (mid >= 0)
          left = n - 1;
        else
          left = -1;

        num += left + 1;
      }
      if (a[i] * a[i] <= mid)
        num--;

    }

    if (num/2 >= k)
      r = mid;
    else
      l = mid;
  }
 

  cout << r << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define IL inline
#define R register
#define N 500008
#define ll long long
using namespace std;
/*--------------OI使我快乐--------------*/
template<typename T>IL void read(T &_)
{
    T __=0,___=1;char ____=getchar();
    while(!isdigit(____)) {if(____=='-') ___=0;____=getchar();}
    while(isdigit(____)) {__=(__<<1)+(__<<3)+____-'0';____=getchar();}
    _=___ ? __:-__;
}
int tag1=-1,tag2=-1,len;
char s[N<<1];
int main()
{
	scanf("%s",s+1);len=strlen(s+1);
	for(R int i=1;i<=len;++i) if(s[i]=='C') {tag1=i;break;}
	for(R int i=len;i;--i) if(s[i]=='F') {tag2=i;break;}
	if(tag1!=-1&&tag2!=-1&&tag2>tag1) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 256
//shara's here
#include <bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
int main(){
    ll a,b,z,x,d,c,l;
    ll max1,max2,max3,max4,maxmax;
    cin>>a>>b;
    z=a-1;
    x=z+a;
    c=b-1;
    d=c+b;
    l=a+b;
    max1=max(z,x);
    max2=max(c,d);
    max3=max(l,max1);
    max4=max(max2,max3);
    maxmax=max(max4,max3);
    cout<<maxmax;
return 0;}


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

using namespace std;

#define int long long
#define pb push_back

signed main () {
  int n;
  cin >> n;
  vector<int> a;
  int tmp = 0;
  for(int i=0;i<n;i++) {
    cin >> tmp;
    a.pb(tmp);
  }
  sort(a.begin(), a.end());
  cout << (a[a.size()-1] - a[0]) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll num[222222];

ll mod_div(ll a,ll b){
  ll tmp=MOD-2,c=b,ret=1;
  while(tmp>0){
    if(tmp&1){
      ret*=c;ret%=MOD;
    }
    c*=c;c%=MOD;tmp>>=1;
  }
  return a*ret%MOD;
}
ll cnt[2222];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;cin>>s;
  ll n = s.size();
  reverse(ALL(s));
  ll ans = 0;
  ll sum = 0;
  ll nu = 1;
  for(int i=0;i<n-1;i++){
    nu *= 10;
    nu%=10;
  }
  cnt[0]++;
  ll kake = 1;
  for(int i=0;i<n;i++){
    num[i+1] = (num[i]+(s[i]-'0')*kake)%2019;
    kake *= 10;
    kake %= 2019;
    num[i+1] %= 2019;
    cnt[num[i+1]]++;
  }
  for(int i=0;i<2222;i++){
    ans += cnt[i]*(cnt[i]-1)/2;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5312
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

int main(){
  int k;cin>>k;
  int a,b;cin>>a>>b;
  int ans=a;
  int final=-1;
  for(int i=0;i<1000;i++){
    ans=k*i;
    if(ans>=a&&ans<=b){
      cout<<"OK";
      return 0;
    }
  }
  cout<<"NG";
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int x, a, b;
	cin >> x >> a >> b;
	cout << (abs(x - a) < abs(x - b) ? "A" : "B") << endl;
	return 0;
}


Measured memory_bytes: 256
n=int(input())
cnt=0
a=list(map(int,input().split()))

def Merge(A, left, mid, right):
	n1 = mid - left
	n2 = right - mid
	L=[0]*(n1+1)
	R=[0]*(n2+1)
	for i in range(n1):
		L[i] = A[left + i]
	for i in range(n2):
		R[i] = A[mid + i]
	L[n1] = 10**10
	R[n2] = 10**10
	i = 0
	j = 0
	global cnt
	for k in range(left,right):
		cnt+=1
		if L[i] <= R[j]:
			A[k] = L[i]
			i+=1
		else:
			A[k] = R[j]
			j+=1

def MergeSort(A, left, right):
	if left+1 < right:
		mid = (left + right)//2
		MergeSort(A, left, mid)
		MergeSort(A, mid, right)
		Merge(A, left, mid, right)
MergeSort(a,0,n)
print(*a)
print(cnt)






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

using namespace std;
int main()
{
int n,i,ar[200005];
cin>>n;
int max=0,smax=0;

for (i=0;i<n;i++)
{
    cin>>ar[i];
    if(max<ar[i])
    {
        smax=max;
        max=ar[i];
    }
    else if(ar[i]>=smax)
    {
        smax=ar[i];
    }
}
for(i=0;i<n;i++)
{
    if(ar[i]==max)
    {
        cout<<smax<<"\n";
    }
    else
    {
        cout<<max<<"\n";
    }
}
return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int N; cin >> N;
  vec A(N); rep(i,N) cin >> A[i];

  int res = 0;
  reps(i, 1, N+1) {
    while(i<N && A[i-1]==A[i])i++;    // これをしないと，同じ値が続いた場合に下の2つの分岐で分けることができない．

    if(i<N && A[i-1]<A[i]) {
      while(i<N && A[i-1]<=A[i])i++;
    }
    else if(i<N && A[i-1]>A[i]) {
      while(i<N && A[i-1]>=A[i])i++;
    }
    res++;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/
//---------------------------------------------------
#define rep(i, n) for(int  i = 0; i < (n); i++)
#define max(a,b) ((a>b)?a:b)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)
//---------------------------------------------------
void swap(LL *a, LL *b)
{
  LL temp;
  temp = *a;*a = *b;*b = temp;
}

//abc c
long long gcd (LL a, LL b);
int main(void)
{
  int n;
  long long ans = 0;
  scanf("%d", &n);
  for (LL i = 1; i <= n; i++) {
    for (LL j =1; j <= n; j++) {
      for (LL k = 1; k <= n; k++) {
          ans += gcd(gcd(i,j),k);
      }
    }
  }

  printf("%lld\n" , ans);
}

LL gcd(LL a, LL b)
{
  if (a < b) {
    swap(&a,&b);
  }
  if (b == 0) {
    return a;
  }
  return gcd(b,a%b);
}


Measured memory_bytes: 1732
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))

b=[]
for k in range(2**n):
  b.append(format(k,'0'+str(n)+'b'))

ans=0
for i in range(2**n):
  cton=0
  for j in range(m):
    ct=0
    for k in range(1,l[j][0]+1):
      if b[i][l[j][k]-1]=='1':ct+=1
    if ct%2==p[j]:cton+=1
  if cton==m:ans+=1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
        int n; cin >> n;
        vector<int> v;
        int mn_x = INT_MAX, mx_x = INT_MIN;
        for (int x = 0; x < n; ++x){
            int q; cin >> q;
            v.push_back(q);
            mn_x = min(mn_x, q);
            mx_x = max(mx_x, q);
        }
        int ans = INT_MAX;
        for (int x = mn_x; x <= mx_x; ++x){
            int sum = 0;
            for (auto q : v){
                sum += (x - q) * (x - q);
            }
            ans = min(ans, sum);
        }
        cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>

#define INF 1000000000;
#define MOD 1000000007;
typedef long long ll;
using namespace std;

int main()
{
    int N,M; cin >> N >> M;
    N--;
    vector<bool> start_mid(N, false);
    vector<bool> end_mid(N, false);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        if (a == 0) {
            start_mid[b] = true;
        }
        if (b == 0) {
            start_mid[a] = true;
        }
        if (a == N) {
            end_mid[b] = true;
        }
        if (b == N) {
            end_mid[a] = true;
        }
    }

    bool ans = false;
    for (int i = 0; i < N; i++) {
        if (start_mid[i] && end_mid[i]) {
            ans = true;
            break;
        }
    }
    cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Set(a,b) memset(a,b,sizeof(a))
template<class T>inline void init(T&x){
	x=0;char ch=getchar();bool t=0;
	for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') t=1;
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48);
	if(t) x=-x;return;
}typedef long long ll;
const int N=1020;
int H,W;char S[N][N];
typedef pair<int,int> PA;
queue<PA> Q;
int dis[N][N];
const int dx[5]={0,1,-1,0,0};
const int dy[5]={0,0,0,-1,1};
int main()
{
	init(H),init(W);Set(dis,-1);
	for(int i=1;i<=H;++i) scanf("%s",S[i]+1);
	for(int i=1;i<=H;++i) for(int j=1;j<=W;++j) if(S[i][j]=='#') Q.push(PA(i,j)),dis[i][j]=0;
	int ans=0;
	while(!Q.empty()) {
		PA P=Q.front();Q.pop();
		int x=P.first,y=P.second;
		ans=max(ans,dis[x][y]);
		for(int k=1;k<=4;++k) {
			int xx=x+dx[k],yy=y+dy[k];
			if(xx<=0||xx>H||yy<=0||yy>W) continue;
			if(!~dis[xx][yy]) dis[xx][yy]=dis[x][y]+1,Q.push(PA(xx,yy));
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 13456
#include <iostream>
#include <vector>
#include <map>
#include <string>

#define REP(i,n) for(int i = (int)(n) - 1; i >= 0; --i)

using namespace std;

int costs[101];
vector<int> recipe[101];
bool flags[101];

int getCost(int goal){
	if(recipe[goal].empty()) return costs[goal];
	flags[goal] = true;
	int sum = 0;
	REP(i, recipe[goal].size()){
		if(flags[recipe[goal][i]]){
			flags[goal] = false;
			return costs[goal];
		}
		sum += getCost(recipe[goal][i]);
	}
	flags[goal] = false;
	if(sum < costs[goal]){
		return sum;
	}else{
		return costs[goal];
	}
}

int main(){
	int n, m;
	while(true){
		cin >> n;
		if(n==0)break;
		
		REP(i, 101){
			flags[i] = false;
		}

		map<string,int> hash;
		
		REP(i,n){
			string name;
			cin >> name >> costs[i];
			hash.insert(map<string,int>::value_type(name,i));
			recipe[i].clear();
		}

		cin >> m;
		REP(i, m){
			string name;
			int item;
			int num;
			cin >> name >> num;
			item = hash[name];
			recipe[item].reserve(num);
			REP(j, num){
				string mate;
				int mat;
				cin >> mate;
				mat = hash[mate];
				recipe[item].push_back(mat);
			}
		}

		string goalName;
		int goal;
		cin >> goalName;
		goal = hash[goalName];

		cout << getCost(goal) << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cctype>
#include <climits>
#include <iomanip>
#include <limits>
#include <bitset>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = INT_MAX;
const ll linf = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = (m); i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<>()
#define SUM(a) accumulate((a).begin(), (a).end(), 0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
template <typename T>
int len(T tmp)
{
	int res = 0;
	while (tmp > 0)
	{
		res++;
		tmp /= 10;
	}
	return res;
}
template <typename T>
T gcd(T a, T b)
{
	T t;
	while (b != 0)
	{
		t = a % b;
		a = b;
		b = t;
	}
	return a;
}
template <typename T>
T recfact(T start, T n)
{
	T i;
	if (n <= 16)
	{
		T r = start;
		for (i = start + 1; i < start + n; i++)
			r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
template <typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}
template <typename T>
T fct(T n)
{
	return recfact<T>(1, n);
}
template <typename T>
T ncm(T n, T m)
{
	if (n < m)
		return 0;
	T x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr)
{
	if (firstItr < 0 || secondItr > int(str.size() - 1))
		return str;
	while (firstItr < secondItr)
	{
		swap(str[firstItr], str[secondItr]);
		firstItr++;
		secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str)
{
	int itr = 0;
	std::string res;
	while (itr < int(str.size()))
	{
		char tmp = str[itr++];
		int length = 1;
		while (itr < int(str.size()) && str[itr] == tmp)
		{
			++itr;
			++length;
		}
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
str split(str str, size_t first_itr, size_t second_itr)
{
	string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++)
	{
		tmp.push_back(str.at(i));
	}
	return tmp;
}

int main(void)
{
	int n;
	cin >> n;
	str s;
	cin >> s;
	ll r, g, b;
	r = g = b = 0;
	rep(i, n)
	{
		switch (s.at(i))
		{
		case 'R':
			r++;
			break;
		case 'G':
			g++;
			break;
		case 'B':
			b++;
			break;
		}
	}
	ll ans = r * g * b;
	rep(i, n) for (int j = i + 1; j < n; j++)
	{
		int k = 2 * j - i;
		if (k < n)
			if (s.at(i) != s.at(j) && s.at(i) != s.at(k) && s.at(j) != s.at(k))
				ans--;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;
int main(){
	int n;
	int tmp;

	cin >> n;

	vector<int> vals(n);

	// read values
	for (size_t i = 0; i < n; ++i) {
		cin >> tmp;
		vals.at(i) = tmp;
	}

	int return_value = 0;

	// some processing here
	int max = 0;
	for (size_t i = 0; i < n; ++i) {
		if (max <= vals.at(i)) {
			return_value++;
			max = vals.at(i);
		}
	}

	cout << return_value << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void AGC024B();

#if 1
int main()
{
	AGC024B();
	fflush(stdout);
	return 0;
}
#endif

static void AGC024B()
{
	int N;
	getint(N);

	std::vector<int> pi(N + 1, 0);
	for (int i = 0; i < N; i++) {
		int p;
		getint(p);
		pi[p] = pi[p - 1] + 1;
	}

	int maxSlope = 0;
	for (int i = 1; i <= N; i++) {
		maxSlope = std::max(maxSlope, pi[i]);
	}

	printf("%d\n", N - maxSlope);
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

int main(){
    
  ll n,m,s,t;
  cin >> n >> m >> s >> t;
  s--;t--;
  WeightedGraph<ll> gy(n);
  WeightedGraph<ll> gs(n);
  ll u[m],v[m],a[m],b[m];
  rep(i,m){
   cin >> u[i] >> v[i] >> a[i] >> b[i];   
   u[i]--;v[i]--;
   gy[u[i]].emplace_back(v[i],a[i]);
   gs[u[i]].emplace_back(v[i],b[i]);
   gy[v[i]].emplace_back(u[i],a[i]);
   gs[v[i]].emplace_back(u[i],b[i]);
  }
  vector<ll> ay=dijkstra(gy, s);
  vector<ll> as=dijkstra(gs, t);
  ll ans[n];
  rep(i,n){
      ans[i]=1e15-ay[i]-as[i];
  }
  ll res[n];
  res[n-1]=ans[n-1];
  for(int i=n-2; i>=0; i--){
      res[i]=max(res[i+1],ans[i]);
  }
  rep(i,n) cout << res[i] << endl;
  
  
  return 0;

}


Measured memory_bytes: 23936
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) {
 if (a < b) { a = b; return true; } return false; 
 }
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  string s;
  cin>>s;
  if(s[2]==s[3]&&s[4]==s[5]){
    COUT("Yes");
  }
  else COUT("No");
}

Measured memory_bytes: 764
import copy

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    A_max = A[N-1]

    div_count = [0] * (A_max + 1)

    for a in A:
        for n in range(a, A_max+1, a):
            div_count[n] += 1

    exists = [False] * (A_max + 1)
    for a in A:
        exists[a] = True

    result = 0
    for i, d in enumerate(div_count):
        if d == 1 and exists[i]:
            result += 1

    print(result)

main()


Measured memory_bytes: 110716
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

// デバッグ用
#define _DEBUG
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
// ここまで
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) { cin >> a[i]; }

    int pre = INF;
    while(true) {
        int mi = 0;
        REP(i, N) {
            if(a[i] < a[mi] && 0 < a[i]) {
                mi = i;
            }
        }
        if(pre == a[mi]) {
            break;
        }
        REP(i, N) {
            if(i != mi) {
                a[i] %= a[mi];
                if(a[i] == 0)
                    a[i] = a[mi];
            }
        }
        pre = a[mi];
    }
    cout << a[0];

    return 0;
}

Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define endl '\n'


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

	int t,i=1;
	while (cin >> t)
	{
		if (t == 0)
		{
			cout << i << endl;
			break;
		}
		else
			i++;
	}

	
	return 0;
}

Measured memory_bytes: 3644