akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int maxN = 2e5 + 100, mod = 1e9 + 7;

int n, a[maxN + 1], cnt[maxN + 1];
int s[maxN + 1], pre[maxN + 1];
int C[maxN + 1], ans, tmp, r[maxN + 1], sum[maxN + 1];

inline int read()
{
	int num = 0, f = 1;
	char ch = getchar();
	while( !isdigit( ch ) ) { if(ch == '-') f = -1; ch = getchar(); }
	while( isdigit( ch ) ) num = (num << 3) + (num << 1) + (ch ^ 48), ch = getchar();
	return num * f;
}

inline int mpow(int a, int x)
{
	int ans = 1;
	while(x)
	{
		if(x & 1) ans = 1ll * ans * a % mod;
		a = 1ll * a * a % mod;
		x >>= 1;
	}
	return ans;
}

inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }

inline int SUB(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }

inline int lowbit(int x) { return x & (-x); }

inline void change(int x, int num)
{
	for(int i = x; i <= n; i += lowbit(i)) C[i] = ADD(C[i], num);
}

inline int query(int x)
{
	int ans = 0;
	for(int i = x; i; i ^= lowbit(i)) ans = ADD(ans, C[i]);
	return ans;
}

int main()
{
	n = read();
	for(int i = 1; i <= n; i++) a[i] = read(), cnt[ a[i] ] ++;
	for(int i = n; i >= 1; i--) cnt[i] += cnt[i + 1];
	s[0] = 1; tmp = 1;
	for(int i = 1; i <= n; i++)
	{
		cnt[i] -= (n - i);
		if(cnt[i] <= 0) { puts("0"); return 0; }
		int t = 1ll * (cnt[i] - 1) * mpow(cnt[i], mod - 2) % mod;
		if(t == 0) pre[i] = pre[i - 1] + 1, s[i] = s[i - 1];
		else pre[i] = pre[i - 1], s[i] = 1ll * s[i - 1] * t % mod;
		tmp = 1ll * tmp * cnt[i] % mod;
		r[ pre[i] ] = i;
	}
	int inv = mpow(2, mod - 2);
	for(int i = n; i >= 1; i--)
	{
		ans = ADD(ans, 1ll * tmp * SUB(query(r[ pre[ a[i] ] ]), query(a[i] - 1)) % mod * mpow(s[ a[i] ], mod - 2) % mod * inv % mod);
		change(a[i], s[ a[i] ]);
	}
	memset(C, 0, sizeof(C));
	for(int i = 1; i <= n; i++)
		sum[i] = SUB(query(n), query(a[i])), change(a[i], 1);
	memset(C, 0, sizeof(C));
	for(int i = 1; i <= n; i++)
	{
		ans = ADD(ans, SUB(1ll * tmp * sum[i] % mod, 1ll * tmp * SUB(query(r[ pre[ a[i] ] ]), query(a[i])) % mod * mpow(s[ a[i] ], mod - 2) % mod * inv % mod));
		change(a[i], s[ a[i] ]);
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
    static final int INF = (int)Math.pow(10, 9);
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int[] c = new int[N];
        int[] t = new int[N];
        int min_cost = INF;
        for (int i = 0; i < N; i++) {
            c[i] = sc.nextInt();
            t[i] = sc.nextInt();
            if (t[i] <= T) {
                min_cost = Math.min(min_cost, c[i]);
            }
        }
        if (min_cost == INF) {
            System.out.println("TLE");
        } else {
            System.out.println(min_cost);
        }
        sc.close();
    }
}

Measured memory_bytes: 23636
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val b = sc.next()
    println(problem122a(b))
}

fun problem122a(b: String): String {
    return when (b) {
        "A" -> "T"
        "T" -> "A"
        "C" -> "G"
        "G" -> "C"
        else -> ""
    }
}

Measured memory_bytes: 31268
import java.io.*;
import java.util.*;
class Main{
	public static void main(String[] args) throws Exception{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		//Buffered
		int t = 1;
		// t = Integer.parseInt(reader.readLine());
		// long[] list = Arrays.stream(reader.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
		for(int u = 0;u<t;u++){
			long[] list = Arrays.stream(reader.readLine().split(" ")).mapToLong(Long::parseLong).toArray();
			long H = list[0];
			long W = list[1];
			long M = list[2];
			HashSet<String> hs = new HashSet<>();
			long[] rows = new long[(int)H];
			long[] cols = new long[(int)W];
			long rowmax = 0;
			long colmax = 0;
			ArrayList<Integer> maxrow = new ArrayList<>();
			ArrayList<Integer> maxcols = new ArrayList<>();
			for(int i = 0;i<M;i++){
				String[] lo = reader.readLine().split(" ");
				int h = Integer.parseInt(lo[0]);
				int w = Integer.parseInt(lo[1]);
				rows[h-1]++;
				cols[w-1]++;
				if(rows[h-1]==rowmax){
					maxrow.add(h-1);
				}
				else if(rows[h-1]>rowmax){
					maxrow = new ArrayList<>();
					maxrow.add(h-1);
					rowmax = rows[h-1];
				}
				if(cols[w-1]==colmax){
					maxcols.add(w-1);
				}
				else if(cols[w-1]>colmax){
					maxcols = new ArrayList<Integer>();
					maxcols.add(w-1);
					colmax = cols[w-1];
				}
				hs.add((h-1)+" "+(w-1));
			}
			/*System.out.println(Arrays.toString(rows));
			System.out.println(Arrays.toString(cols));
			System.out.println(maxrow);
			System.out.println(maxcols);*/
			long res = 0;
			for(int r:maxrow){
				for(int c:maxcols){
					long p = rows[r]+cols[c];
					if(!hs.contains(r+" "+c)){
						System.out.println((p));
						return;
					}
					res = p - 1;
				}
			}
			System.out.println(res);

		}
	
	}
	
}
class pair implements Comparable<pair>{
		long a = 0;
		int b = 0;
		public pair(long a,int b){
			this.a = a;
			this.b = b;
		}
		@Override
		public int compareTo(pair p){
			if(this.a == p.a) return -(Integer.compare(this.b,p.b));
			else return -(Long.compare(this.a,p.a));
		}
		@Override
		public String toString(){
			return a+" "+b;
		}
	}

Measured memory_bytes: 107024
def solve(s)
  cnts = []

  cnt = 0
  s.length.times{|n|
    if s[n] == "W"
      cnt += 1
    end
    cnts << cnt
  }

  cnt = 0
  violates = 0
  min_idx = s.length + 1
  min_score = s.length + 1

  t = s.length
  t.times{|n|
    idx = t - (n + 1)

    w_vio = idx == 0 ? 0 : cnts[idx - 1]
    score = violates + w_vio
    if score < min_score
      min_idx = idx
      min_score = score
      #puts "#{min_score} at #{min_idx}"
    end
    if s[idx] == "E"
      violates += 1
    end
  }

  result = cnts[cnt]
  #puts "result #{min_score} at #{min_idx}"
  min_score
end

def test()
  puts solve('WEEWW') == 1
  puts solve('WEWEWEEEWWWE') == 4  #[W]E[W]E[W]EE (E) WWW[E]
  puts solve('WWWWWEEE') == 3
  puts solve('EEEEEEEEEEEWWWWWWWW') == 0
end

def doit()
  n = gets.to_i
  s = gets
  puts solve(s)
end

doit

Measured memory_bytes: 4612
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define ntuples(type1,type2,type3,v,n) vector<tuple<type1,type2,type3>> v(n);for(size_t i=0;i<(n);i++){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  string s;
  cin>>s;
  int n=s.length()/2;
  int k=0;
  for (int i = 0; i < n; i++) {
    if(s[i]!=s[s.length()-1-i]) k++;
  }
  cout<<k;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        int[] leftJ = new int[n + 2];
        int[] rightI = new int[n + 2];
        for (int i = 1; i <= n; i++) {
            leftJ[i] = leftJ[i - 1];
            if (arr[i - 1] == 'J') {
                leftJ[i]++;
            }
            rightI[n - i + 1] = rightI[n - i + 2];
            if (arr[n - i] == 'I') {
                rightI[n - i + 1]++;
            }
        }
        long sumI = 0;
        long sumJ = 0;
        long maxO = 0;
        long total = 0;
        for (int i = 1; i <= n; i++) {
            long tmp;
            if (arr[i - 1] == 'O') {
                tmp = leftJ[i - 1] * rightI[i + 1];
                total += tmp;
                sumJ += (leftJ[i - 1] + 1) * rightI[i + 1];
                sumI += leftJ[i - 1] * (rightI[i + 1] + 1);
            } else {
                tmp = leftJ[i - 1] * rightI[i];
            }
            maxO = Math.max(maxO, tmp);
        }
        total += maxO;
        total = Math.max(total, sumJ);
        total = Math.max(total, sumI);
        System.out.println(total);
    }
}



Measured memory_bytes: 30680
A=list(input())
B=list(input())
C=list(input())
K=A
l=[]
while len(K)>0:
    k=K.pop(0)
    
    if k=='a':
        K=A
        l.append('A')
    elif k=='b':
        K=B
        l.append('B')
    else:
        K=C
        l.append('C')
print(l[-1])

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

#define NONE INT_MAX>>1

int main()
{
  int n,m,a,b,cost,time,k,p,q,r,M[100][100],N[100][100];
  while(cin>>n>>m,n|m){
    for(int i=0;i<m;i++)for(int j=0;j<m;j++){
      M[i][j]=NONE;
      N[i][j]=NONE;
    }
    for(int i=0;i<n;i++){
      cin>>a>>b>>cost>>time;
      a--;b--;
      M[a][b]=M[b][a]=cost;
      N[a][b]=N[b][a]=time;
    }
    for(int l=0;l<m;l++)for(int i=0;i<m;i++)for(int j=0;j<m;j++){
      M[i][j]=min(M[i][j],M[i][l]+M[l][j]);
      N[i][j]=min(N[i][j],N[i][l]+N[l][j]);
    }
    cin>>k;
    for(int i=0;i<k;i++){
      cin>>p>>q>>r;
      p--;q--;
      if(r==0)cout<<M[p][q]<<endl;
      else cout<<N[p][q]<<endl;
    }
  }
}

Measured memory_bytes: 940
#include<stdio.h>
int main(void){
int h,m,s;
	scanf("%d" ,&s);
	h=s/3600;
	m=(s/60)-(h*60);
	s=s-(m*60)-(h*3600);
	printf("%d:%d:%d\n" ,h,m,s);
	return 0;
}

Measured memory_bytes: 592
use std::io;
pub trait ExRead {
    fn read_line(&mut self) -> io::Result<String>;
    fn read_to_string(&mut self) -> io::Result<String>;
}

impl<'a> ExRead for io::StdinLock<'a> {
    fn read_line(&mut self) -> io::Result<String> {
        let mut buf = String::new();
        io::BufRead::read_line(self, &mut buf).map(|_| buf)
    }

    fn read_to_string(&mut self) -> io::Result<String> {
        self.read_line().map(|s| s.trim().to_string())
    }
}

fn main() {
    let n: i64;
    let a: Vec<_>;

    {
        let stdin = std::io::stdin();
        let mut lkin = stdin.lock();
        let mut input = lkin.read_line().unwrap()
            .split_whitespace()
            .map(|e| e.parse().ok().unwrap()).collect::<Vec<_>>().into_iter();
        n = input.next().unwrap();
        a = lkin.read_line().unwrap()
            .split_whitespace()
            .map(|e| e.parse().ok().unwrap()).collect::<Vec<_>>();
    }

    println!("{}", a.into_iter().fold(n, |acc, a|
        if acc < a  {-1} else {acc - a}
    ));
}


Measured memory_bytes: 2284
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  int n,d,ans=0;
  cin >> n >> d;
  vector<vector<int>> X(n,vector<int>(d)); // vector<vector<int>> X[n]; として,dで回して見かけ上二次元配列にしてもよい.
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      cin >> X[i][j];
    }
  }
  // 全てのiとjについての探索 O(n*n*d)
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int ddist=0; // 2点間の距離の二乗
      for(int k=0;k<d;k++){
        int dist = abs(X[i][k]-X[j][k]); // 2点間の距離
        ddist += dist*dist;
      }
      // ddistが平方数であるかどうかの判定
      bool flag = false;
      for(int k=0;k*k<=ddist;k++){
        if(k*k==ddist) flag = true;
      }
      if(flag) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#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=1e9+7 ;

int main(){
  ll a, b; cin >> a >> b;
  if(abs(a-b)<=1) cout << "Brown" << endl;
  else cout << "Alice" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;
template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}
template<typename T>
void cout_mat(vector<vector<T>  > &mat){
    for(int i=0; i<mat.size(); i++){
        vector<T> vec = mat[i];
        cout_vec(mat[i]);
    }
}

int main(){
    int H, W;
    cin >> H >> W;

    vector<vector<int>> grid(H,vector<int>(W,0));
    for(auto &line:grid){
        for(auto &a:line){
            cin >> a;
        }
    }

    for(auto &line:grid){
        for(auto &a:line){
            int x;
            cin >> x;
            a-=x;
        }
    }
    int N=160*160;

    vector<vector<vector<int>>> dp(H+1,vector<vector<int>>(W+1,vector<int>(N+1,0)));
    dp[0][0][N/2]=1;

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int diff=grid[i][j];
            for(int k=0; k<=N; k++){
                if(0<=k+diff && k+diff<=N){
                    dp[i+1][j][k+diff]|=dp[i][j][k];
                    dp[i][j+1][k+diff]|=dp[i][j][k];
                }
                if(0<=k-diff && k-diff<=N){
                    dp[i][j+1][k-diff]|=dp[i][j][k];
                    dp[i+1][j][k-diff]|=dp[i][j][k];
                }
            }
        }
    }

    for(int i=0; i<N; i++){
        if(dp[H][W-1][N/2-i] || dp[H][W-1][N/2+i]){
            cout << i << endl;
            return 0;
        }
    }

}

Measured memory_bytes: 666944
#include <algorithm>
#include <iostream>
#include <vector>
 
int main() {
    int N;
    std::cin >> N;
 
    std::vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
    }
 
    std::vector<int> max_from(N);
    int max_val = A.back();
    max_from[N - 1] = max_val;
    for (int i = N - 2; i >= 0; --i) {
        max_val = std::max(max_val, A[i]);
        max_from[i] = max_val;
    }

    std::vector<int> max_to(N);
    max_val = A.front();
    max_to[0] = max_val;
    for (int i = 1; i < N; ++i) {
        max_val = std::max(max_val, A[i]);
        max_to[i] = max_val;
    }

    for (int i = 0; i < N; ++i) {
        if (i == 0) {
            max_val = max_from[1];
        } else if (i == N - 1) {
            max_val = max_to[N - 2];
        } else {
            max_val = std::max(max_to[i - 1], max_from[i + 1]);
        }
        std::cout << max_val << std::endl;
    }
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

template<int MOD>
struct ModInt {
  ll x;
  ModInt():x(0){}
  ModInt(ll x):x((x%MOD+MOD)%MOD){}
  int getMod() { return MOD; }
  ModInt operator-() const { return ModInt(0) - *this;}
  ModInt& operator+=(const ModInt& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator-=(const ModInt& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator*=(const ModInt& a){ (x*=a.x)%=MOD; return *this;}
  ModInt operator+(const ModInt& a)const{ return ModInt(*this) += a;}
  ModInt operator-(const ModInt& a)const{ return ModInt(*this) -= a;}
  ModInt operator*(const ModInt& a)const{ return ModInt(*this) *= a;}
  bool operator<(const ModInt& a)const{ return x < a.x;}
  bool operator==(const ModInt& a)const{ return x == a.x;}
  ModInt pow(ll t) const {
    if (!t) return 1;
    ModInt a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  friend istream & operator >> (istream & in, ModInt & v) {
    ll x;
    in >> x;
    v.x = x;
    return in;
  }
  friend ostream & operator << (ostream & out, ModInt<MOD> const & v) {
    out << v.x;
    return out;
  }
};
const int MOD = 1000000007;
using mint = ModInt<MOD>;

typedef pair<ll, ll> P;

P rev(P p) {
  swap(p.first, p.second);
  if (p.first == 0 or p.second == 0) {
    swap(p.first, p.second);
    return p;
  }

  p.first *= -1;
  if (p.second < 0) p.first *= -1, p.second *= -1;
  return p;
}

int main() {
  int n; cin >> n;
  map<P, int> M;
  int zero2 = 0, a_zero = 0, b_zero = 0;
  loop(i,0,n) {
    ll a, b; cin >> a >> b;
    if (a == 0 and b == 0) M[P(0, 0)]++;
    else if (a == 0) M[P(0, 1)]++;
    else if (b == 0) M[P(1, 0)]++;
    else {
      ll gc = __gcd(abs(a), abs(b));
      a /= gc, b /= gc;
      if (b < 0) a *= -1, b *= -1;
      M[P(a, b)]++;
    }
  }

  auto aa = [&](const P p1) {
    return mint(2).pow(M[p1]);
  };

  auto ab = [&](const P p1, const P p2) {
    // それぞれのグループ独立に1個以上選ぶ.
    // さらに両グループから1つも選ばない場合で+1
    return (mint(2).pow(M[p1]) - 1) + (mint(2).pow(M[p2]) - 1) + 1;
  };

  mint ans = ab(P(1,0), P(0,1));
  // mint ans = 1;
  set<P> S;
  for (auto &&m: M) {
    if (m.first.first == 0 or m.first.second == 0) continue;
    if (S.count(m.first)) continue;
    ll count = m.second;
    P p = rev(m.first);
    if (M[p] > 0) {
      ans *= ab(p, m.first);
    } else {
      ans *= aa(m.first);
    }
    S.insert(p);
  }

  // 各有理数rグループから1つも選ばないのもカウントしてるので-1
  ans -= 1;

  // (0, 0)の場合はそれ１つを選ぶしかない.
  ans += M[P(0, 0)];
  cout << ans << endl;
  return 0;
}


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

int main()
{
  int n;

  while (cin >> n, n){
    int num[10], m;
    for (int i = 0; i < 10; i++)  num[i] = 0;
    for (int i = 0; i < n; i++){
      cin >> m;
      num[m]++;
    }
    for (int i = 0; i < 10; i++){
      if (num[i] == 0)  cout << '-' << endl;
      else {
        for (int j = 0; j < num[i]; j++){
          cout << '*';
        }
        cout << endl;
      }
    }
  }
  return (0);
}

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

sum_list = []

def findSumOfDigit(n):
    s = 0
    while(n > 0):
        s += n % 10
        n = int(n / 10)
    return s

for a in range(1, N):
    b = N - a
    sum_list.append(findSumOfDigit(a) + findSumOfDigit(b))

print(min(sum_list))


Measured memory_bytes: 3864
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  
  for(int i = 1; i < max(n, m); i++){
    if(abs(n - i) == abs(m - i)){
      cout << i << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
using ll = long long;

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

    ll dp[41][2];
    for (int m = 0; m <= 40; ++m) {
        ll score[2] = {0, 0};
        for (int i = 0; i < n; ++i) {
            score[1 - ((a[i] >> m) & 1)] += (1LL << m);
        }

        dp[m][0] = max(score[0], score[1]) + (m == 0 ? 0 : dp[m - 1][0]);
        if ((k >> m) & 1) {
            dp[m][1] = max(score[0] + (m == 0 ? 0 : dp[m - 1][0]),
                           score[1] + (m == 0 ? 0 : dp[m - 1][1]));
        } else {
            dp[m][1] = score[0] + (m == 0 ? 0 : dp[m - 1][1]);
        }
    }

    cout << dp[40][1] << endl;
}

Measured memory_bytes: 1024
n = int(input())
s = input()
ans = 0
r, g, b = [0 for _ in range(n+1)], [0 for _ in range(n+1)], [0 for _ in range(n+1)]
for i in range(n):
	r[i+1], g[i+1], b[i+1] = r[i], g[i], b[i]
	if s[i] == "R":
		r[i+1] += 1
	elif s[i] == "G":
		g[i+1] += 1
	else:
		b[i+1] += 1

ans = 0
for i in range(1, n-1):
	if s[i] == "R":
		ans += g[i] * (b[n] - b[i+1]) + b[i] * (g[n] - g[i+1])
		for j in range(1, min(i, n-i-1)+1):
			if {s[i-j], s[i+j]} == {"G", "B"}:
				ans -= 1
	elif s[i] == "G":
		ans += r[i] * (b[n] - b[i+1]) + b[i] * (r[n] - r[i+1])
		for j in range(1, min(i, n-i-1)+1):
			if {s[i-j], s[i+j]} == {"R", "B"}:
				ans -= 1
	elif s[i] == "B":
		ans += g[i] * (r[n] - r[i+1]) + r[i] * (g[n] - g[i+1])
		for j in range(1, min(i, n-i-1)+1):
			if {s[i-j], s[i+j]} == {"G", "R"}:
				ans -= 1
print(ans)

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

int main() {
    string S; cin >> S;
    int res = 0;
    for (int i = 0; i * 2 < S.size(); ++i) {
        if (S.substr(0, i) == S.substr(i, i)) res = i * 2;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include <math.h>
#include <iostream>
using namespace std;

int main(){
	int n,m;cin >> n >> m;
  	int a[1000000];
    int sum = 0 ;
	for (int i=0 ; i < m; i++){
     cin >> a[i];
     //cout << a[i] << endl;
   	sum += a[i];
    }
  	//cout << sum << endl;
	if (sum > n){
      cout << -1 << endl;
    }
  	else{
      int ans;
      ans = n-sum;
    cout << ans << endl;
    }
  
  
}

Measured memory_bytes: 3684
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		try {
			while ((buffer = reader.readLine())  != null) {
				int a = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));
				buffer = buffer.substring(buffer.indexOf(" ") + 1);
				String op = buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" "));
				buffer = buffer.substring(buffer.indexOf(" ") + 1);
				int b = Integer.valueOf(buffer.substring(0, buffer.indexOf(" ") == -1 ? buffer.length() : buffer.indexOf(" ")));

				switch (op) {
				default : {
					return;
				}
				case ("+") : {
					System.out.println((int)(a + b));
					break;
				}
				case ("-") : {
					System.out.println((int)(a - b));
					break;
				}
				case ("*") : {
					System.out.println((int)(a * b));
					break;
				}
				case ("/") : {
					System.out.println((int)(a / b));
					break;
				}
				}
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}

Measured memory_bytes: 24424
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    A,B,C=map(int,input().split())
    M=max(A,B,C)
    ans=M*10
    f=False
    for x in A,B,C:
        if x!=M or f:
            ans+=x
        else:
            f=True
    print(ans)

if __name__ == '__main__':
    main()


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

#define rep(i, n) REP(i, 0, n)
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(x) cout << x << endl;

int main() {
    long h, w; cin >> h >> w;

    long ans = 0;
    long hh, ww = 0;
    if(h == 1 || w == 1){
        ans = 1;
    }else{
        if(h % 2 == 0){
            hh = h / 2;
        }else{
            hh = h / 2 + 1;
            ww = w / 2;
        }
        ans = hh * w - ww;
    }
    OP(ans);
}


Measured memory_bytes: 256
L, R = map(int, input().split())
l = L % 2019
r = R % 2019
if R - L >= 2019:
    print(0)
elif r < l:
    print(0)
else:
    m = []
    for i in range(l, r+1):
        for j in range(i+1, r+1):
            m.append((i*j)%2019)
    print(min(m))


Measured memory_bytes: 75412
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,M;cin>>N>>M;
    float x,y;
    vector<pair<float,float>> a(N);
    vector<pair<float,float>> b(M);
    REP(i,N){
        cin>>x>>y;
        a[i] = make_pair(x,y);
    }
    REP(i,M){
        cin>>x>>y;
        b[i] = make_pair(x,y);
    }
    REP(i,N){
        float q=1000000000;
        int point = 0;
        REP(y,M){
            float p = abs(a[i].first - b[y].first) + abs(a[i].second - b[y].second);
            if(q>p){
                q = p;
                point = y+1;
            }
        }
        printf("%d\n",point);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0)
#define endl "\n"
#define int long long
typedef vector<int> vi;
#define all(x) x.begin(),x.end()
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define pii              pair <int,int>
#define DEBUG(x) cerr << '>' << #x << ':' << x << endl;
typedef long long ll;
//#pragma comment(linker, "/STACK:667772160")
#define in_range(x, y, r, c) ((x >= 0 && x < r && y >= 0 && y < c))

const double eps=1e-9;
const int MOD=1e9+7;
const int N=1e5+30;
const int inf = 1e17+995;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template <typename T> T exp(T b, T p){T x = 1;while(p){if(p&1)x=(x*b);b=(b*b);p=p>>1;}return x;}
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
void boostIO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int32_t main() {
boostIO();
int n,k;
cin>>n>>k;
vi weight(n),val(n);
int sum=0;
    for (int i = 0; i < n; ++i) {
        cin>>weight[i]>>val[i];
        sum+=val[i];
    }
    vi dp(sum+1,inf);
    dp[0]=0;
    for (int i = 0; i < n; ++i) {
        for(int curVal=sum-val[i];curVal>=0;curVal--){
            dp[curVal+val[i]]=min(dp[curVal+val[i]],dp[curVal]+weight[i]);
        }
    }
    int ans=0;
    FOR(i,0,sum){
        if(dp[i]<=k)ans=max(ans,i);
    }
    cout<<ans<<endl;
}

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

int main()
{
    int n, k;

    cin >> n >> k;
    int d[k];
    int a[k][n];

    int have[n];
    memset(have, 0, sizeof(int) * n);

    rep(i, 0, k)
    {
        cin >> d[i];
        rep(j, 0, d[i])
        {
            cin >> a[i][j];
            have[a[i][j] - 1] = 1;
        }
    }
    int sum = 0;
    rep(i, 0, n)
    {
        if (have[i] != 1)
        {
            sum++;
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3640
h, w = map(int, input().split())
c = []

for i in range(h):
    low = [i for i in input()]
    c.append(low)

for j in range(h):
    for k in range(w):
        cnt = 0
        if c[j][k] == "#":
            if j != 0:
                if c[j-1][k] == "#":
                    cnt += 1
            if k != 0:
                if c[j][k-1] == "#":
                    cnt += 1
            if j != h - 1:
                if c[j+1][k] == "#":
                    cnt += 1
            if k != w - 1:
                if c[j][k+1] == "#":
                    cnt += 1

            if cnt == 0:
                print("No")
                break

    else:
        continue
    break

else:
    print("Yes")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = int(a); i < int(b); ++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9 + 7;
main(){
    int N,K;
    cin >> N >> K;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    int mini = INF;
    rep(i,0,N - K + 1){
        int l = i,r = i + K - 1;
        mini = min(mini, min(abs(V[l]), abs(V[r])) + abs(V[l] - V[r]));
    }
    cout << mini << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N;
  cin >> N;
  vector <int> H(N);
  rep(i,N) cin >> H[i];
  int mx = 0;
  rep(i,N){
    mx = max(mx, H[i]);
    if (mx == H[i]) continue;
    if (mx - 1 == H[i]) continue;
    else{
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3740
// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;


int main(int argc, char const *argv[]) {
    // code
    int a, b, c;
    cin >> a >> b >> c;

    swap(a, b);
    swap(a, c);
    printf("%d %d %d\n", a, b, c);
    return 0;
}


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

#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)

int main() {
    long double x;
    long double y;
    cin >> x >> y;
//    ll a=x*(ll)floor(y);
//    ll b=(x*100*(y-floorl(y)))/100;
    cout << (ll)(x*y) << endl;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(auto & ai : a) cin>>ai;
    ll ret = 0ll;
    ll ksum = (k*(k+1)/2)%mo;
    ll ksum2 = ((k-1)*k/2)%mo;
    for(int i=0;i<n;++i){
        ll bef = 0ll;ll aft=0ll;
        for(int j=0;j<i;++j)if(a[i] > a[j]) bef++;
        for(int j=i+1;j<n;++j)if(a[i] > a[j])aft++;
        (ret += (bef*ksum2)%mo)%=mo; 
        (ret += (aft*ksum )%mo)%=mo;
    }
    cout << ret << endl;
    return 0;
}



Measured memory_bytes: 256
#gcdは3.4.3だとfractionsにある
from fractions import gcd

from math import factorial as f

from math import ceil,floor,sqrt

from sys import exit

from copy import deepcopy
import numpy as np

import bisect
import re


ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))



def main():
    w = ['Sunny', 'Cloudy', 'Rainy','Sunny']
    s = input()
    for i in range(3):
        if w[i] == s:
            print(w[i+1])
            
main()


Measured memory_bytes: 13768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s(m, vector<int>(0));
    vector<int> p(m);
    for (int i = 0; i < m; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int num;
            cin >> num;
            s[i].push_back(num);
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> p[i];
    }
    int cnt = 0;
    for (int tmp = 0; tmp < (1 << n); tmp++) {
        bitset<10> bit(tmp);
        int on = 0;
        bool flag = true;
        for (int j = 0; j < m; j++) {
            on = 0;
            for (int l = 0; l < (int)s[j].size(); l++) {
                if (bit.test(s[j][l] - 1)) {
                    on++;
                }
            }
            if (on % 2 != p[j]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
ll INF = (1LL << 60) - 1;
int MOD = 1e9+7;
ll table[10010];
main(){
    ll H,N;
    cin >> H >> N;
    vector<ll>A(N),B(N);
    rep(i,0,N)cin >> A[i] >> B[i];
    rep(i,0,10010)table[i] = INF;
    table[0] = 0;
    ll ans = INF;
    rep(i,0,N){
        ll tmp = INF;
        rep(j,0,H+1){
            if(j - A[i] < 0)continue;
            table[j] = min(table[j], table[j - A[i]] + B[i]); 
        }
        rep(j,0,H+1){
            if(j + A[i] < H)continue;
            tmp = min(tmp, table[j] + B[i]);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    if (n <= 2) {
        cout << "No"
             << "\n";
        return 0;
    }
    if (__builtin_popcount(n) == 1) {
        cout << "No"
             << "\n";
        return 0;
    }
    vector<pii> edges;
    edges.emplace_back(1, 2);
    edges.emplace_back(2, 3);
    edges.emplace_back(3, 1 + n);
    edges.emplace_back(1 + n, 2 + n);
    edges.emplace_back(2 + n, 3 + n);
    for (int i = 4; i <= n - 1; i += 2) {
        edges.emplace_back(i, i + 1);
        edges.emplace_back(i + 1, 1 + n);
        edges.emplace_back(1 + n, n + i);
        edges.emplace_back(n + i, n + i + 1);
    }
    if (n % 2 == 0) {
        ll x = n ^ 1;
        for (int i = 2; i < n; ++i) {
            ll y = x ^ i;
            if (y < n) {
                if (y % 2 == 0)
                    edges.emplace_back(n + y, n);
                else
                    edges.emplace_back(y, n);

                if (i % 2 == 0)
                    edges.emplace_back(n + i, 2 * n);
                else
                    edges.emplace_back(i, 2 * n);

                break;
            }
        }
    }
    cout << "Yes"
         << "\n";
    assert((int)edges.size() == 2 * n - 1);
    for (auto &p : edges) {
        cout << p.first << " " << p.second << "\n";
    }
    return 0;
}

Measured memory_bytes: 4464
#include <iostream>

int main()
{
  int N;
  std::cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) std::cin >> A[i];
  
  int min = A[0];
  int max = A[0];
  
  for ( int i = 1; i < N; i++ ) {
  	if ( min > A[i] ) min = A[i];
    if ( max < A[i] ) max = A[i];
  }
  
  std::cout << max - min << std::endl;
  return 0;
}

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

using namespace std;

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

int main(){
    int A,B;
    cin>>A>>B;

    if(A==B) cout<<"Draw"<<endl;
    else if(A==1&&B==13) cout<<"Alice"<<endl;
    else if(A==13&&B==1) cout<<"Bob"<<endl;
    else if(A>B) cout<<"Alice"<<endl;
    else cout<<"Bob"<<endl;
}


Measured memory_bytes: 256
// Author: wlzhouzhuan
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

inline void ckmin(int &a, int b) {
  if (a > b) a = b;
}
inline void ckmax(int &a, int b) {
  if (a < b) a = b;
}

const int N = 1e6 + 5;
int a[N], n, k;

int main() {
  scanf("%d%d", &k, &n);
  for (rint i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  int min_d = 0;
  for (rint i = 1; i < n; i++) {
    min_d = max(min_d, a[i + 1] - a[i]);
  }
  min_d = max(min_d, a[1] + k - a[n]);
  printf("%d\n", min(a[n] - a[1], k - min_d));
  return 0;
} 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
int main(){
  int N;
  cin >> N;
  map<string, int> A;
  int max = -9999;
  rep(i, N){
    string a;
    cin >> a;
    A[a]++;
    if(A[a] > max){
      max = A[a];
    }
  }
  //最大値をとる文字列を抽出
  vector<string> S;
  for(auto a : A){
    if(a.second == max){
      S.push_back(a.first);
    }
  }
  sort(S.begin(), S.end());
  rep(i, S.size()){
    cout << S[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 26868
#include <bits/stdc++.h>
#define int long long int
#define IOS ios_base::sync_with_stdio(false), cin.tie(NULL);
#define fr(i,a,b)  for(int i=a;i<=b;i++)
#define rf(j,b,a)  for(int j=b;j>=a;j--)
#define frr(k,a,b) for(int k=a;k<=b;k++)
#define mp make_pair
#define pb push_back
#define MOD 1000000007
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
signed main()
{   
	IOS
  /* #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif*/
string s1,s2;
cin>>s1;
cin>>s2;
int l1 = s1.size();
int l2 = s2.size();

int dp[l1+1][l2+1];
for(int i =0;i<=l1;i++)
{
	for(int j =0;j<=l2;j++)
	{
     if(i==0||j==0)
     {
      dp[i][j]=0;	
     }
     else if(s1[i-1]==s2[j-1])
     {
     dp[i][j] = 1+dp[i-1][j-1];
     }
     else
     {
     	dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
     }
	}
}

string ans = "";
int i = l1,j = l2;

while(j>0&&i>0)
{
	if(s1[i-1]==s2[j-1])
	{
		ans = s1[i-1]+ans;
		i--;
		j--;
	}
	else if(dp[i-1][j]>dp[i][j-1])
	{
		i--;
	}
	else
	{
		j--;
	}
}
cout<<ans<<endl;
}









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

string inp;

int main() {
   int k; cin >> inp >> k;
   vector<string> vec;
   for(int i = 0; i < (int)inp.size(); i++) {
      for(int l = 1; l <= 5 && i+l <= (int)inp.size(); l++) {
         vec.push_back(inp.substr(i, l));
      }
   }
   sort(vec.begin(), vec.end());
   vec.erase(unique(vec.begin(), vec.end()), vec.end());
   cout << vec[k-1] << endl;
}



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

using namespace std;

const int N = 2e5 + 77;

int main(){
    int n , x , t ; cin >> n >> x >> t ;
    if(n%x==0) cout << n/x * t << endl;
    else cout << (n/x + 1) *t << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n;
cin>>n;
ll r=0;
ll c=0;
for(ll i=0; i<10000000; i++){
r+=i;
if(r>n){
c=i;
break;}}
ll g=r-n;
for(ll i=1; i<=c; i++){
if(i!=g)
cout << i << endl;}}


Measured memory_bytes: 3520
#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 ll long long
#define INF 999999999
using namespace std;
int main() {
  double R;
  std::cin >> R;
  std::cout << 2*R*3.1415926 << endl;
}


Measured memory_bytes: 3784
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

int main(int argc, char *argv[])
{
	int i;
	int one_num = 0;
	int zero_num = 0;
	int count;
	string s;

	cin >> s;

	for (i = 0; i < s.length(); i++) {
		if (s[i] == '0')
			zero_num++;
		else if (s[i] == '1')
			one_num++;
	}

	if (zero_num < one_num)
		count = zero_num * 2;
	else
		count = one_num * 2;

	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 512
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, s = 0;
    cin >> n;
    vector<ll> a(n), f(n + 9), c(n + 9);
    for (ll &e : a)
        cin >> e, f[e]++;
    for (ll i = 0; i < f.size(); i++)
        c[i] = f[i] * (f[i] - 1) / 2, s += c[i];
    for (ll e : a)
        cout << s - c[e] + (f[e] - 1) * (f[e] - 2) / 2 << "\n";
    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
float N, T, A;
  cin >> N >> T >> A;
int num;  
float mi = 1000;
  for(int i = 0;i < N;i++){
  float H;
    cin >> H;
    if(abs(A - (T - H * 0.006)) < mi){
     num = i + 1;
     mi = abs(A - (T - H * 0.006));
      }
  }
  
  cout << num << endl; 
  return 0;
 
}

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

using namespace std;

int main() {
	cin.sync_with_stdio(false);

	int A, B;
	cin >> A >> B;
	if (A == 1) {
		A = 14;
	}
	if (B == 1) {
		B = 14;
	}
	if (A > B) {
		cout << "Alice" << endl;
	}
	else if (A < B) {
		cout << "Bob" << endl;
	}
	else {
		cout << "Draw" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int dp[30000010];
typedef long long ll;

ll gcd(ll a, ll b)
{
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
int main(int argc, char const *argv[])
{
	ll x, y;
	while(~scanf("%lld %lld", &x, &y))
	{
		printf("%lld %lld\n", gcd(x, y), lcm(x, y));
	}
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) FOR((i),0,(n))

typedef long long ll;

const int INF=1e9+7;
const int MAX_N=1e5+5;
ll A[MAX_N];
vector<int>G[MAX_N];
ll T[MAX_N];
ll max(ll a,ll b){
	if(a>b)return a;
	else return b;
}
ll min(ll a,ll b){return -1*max(-a,-b);}
bool dfs(int v,int prev){
	if(G[v].size()==1 &&G[v][0]==prev){
		T[v]=A[v];
		return true;
	}
	bool re=true;
	ll sum=0;
	ll ma=0;
	rep(i,G[v].size()){
		if(G[v][i]!=prev){
			if(!dfs(G[v][i],v))return false;
			sum+=T[G[v][i]];
			ma=max(ma,T[G[v][i]]);
		}
	}
	T[v]=2*A[v]-sum;
	re&=(sum>=T[v]);
	re&=(T[v]>=0);
	re&=((min(sum-ma,sum/2)>=((sum-T[v])/2)));
	return re;
}
int main(){
	int n;
	cin>>n;
	rep(i,n)cin>>A[i+1];
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	if(dfs(1,0) &&(G[1].size()==1||T[1]==0))cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


Measured memory_bytes: 15232
#include<stdio.h>
#include<string.h>
int n,C,A[444],B[444];
int s[444][444];
int dp[444][444];
#define mod 1000000007
int add(int x,int y){
	return (x+=y)<mod?x:x-mod;
}
int mul(int x,int y){
	return (int)((long long int)x*y%mod);
}
int sub(int x,int y){
	return add(x,mod-y);
}
int d(int i,int tot){
	if(i==n+1)return tot==0?1:0;
	int&res = dp[i][tot];
	if(res!=-1)return res;
	res=0;
	for(int j=0; j<=tot; j++)
		res=add(res, mul(d(i+1,tot-j), sub(s[j][B[i]],s[j][A[i]-1])));
	return res;
}
int main(){
	scanf("%d%d",&n,&C);
	for(int i=1; i<=n; i++)
		scanf("%d",&A[i]);
	for(int i=1; i<=n; i++)
		scanf("%d",&B[i]);
	for(int x=1; x<=400; x++){
		s[0][x] = 1;
		for(int i=1; i<=C; i++)
			s[i][x] = mul(x, s[i-1][x]);
	}
	for(int i=0; i<=C; i++)
		for(int x=1; x<=400; x++)
			s[i][x] = add(s[i][x],s[i][x-1]);
	memset(dp,-1,sizeof(dp));
	printf("%d\n",d(1,C));
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26)cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d)rep(j, 26)cin >> s[i][j];
    vector<int> t(d);
    rep(i, d){
        cin >> t[i];
        t[i]--;
    }
    vector<int> last(26, 0);
    int sum = 0;
    rep(i, d){
        last[t[i]] = i + 1;
        sum += s[i][t[i]];
        rep(j, 26){
            sum -= c[j] * (i + 1 - last[j]);
        }
        cout << sum << endl;
    }
    
}

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

int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll wa[300000][2] = {0};

    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        if(i!=0)wa[i][0] = wa[i-1][0];
        if(s[i]=='W')wa[i][0]++;
    }
    for(ll i=n-1;i>=0;i--)
    {
        if(i!=n-1)wa[i][1] = wa[i+1][1];
        if(s[i]=='E')wa[i][1]++;
    }
    ll ans = 1e+9;
    for(ll i=0;i<n;i++)
    {
        if(wa[i][0] + wa[i][1] < ans)ans = wa[i][0] + wa[i][1];
    }
    cout<<ans-1;

}

Measured memory_bytes: 5380
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        LinkedList<Double> db = new LinkedList<Double>();
        while(sc.hasNext()){
            db.add(sc.nextDouble());
        }
        Collections.sort(db);
        System.out.println(db.get(db.size()-1)-db.get(0));
    }
}

Measured memory_bytes: 16844
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n_max = 10 ** 5
    n, k = list(map(int, input().split()))
    a = [0 for _ in range(n_max + 1)]

    # See:
    # https://atcoder.jp/img/abc061/editorial.pdf
    for i in range(n):
        ai, bi = list(map(int, input().split()))
        a[ai] += bi

    for j in range(n_max + 1):
        if a[j] >= k:
            print(j)
            exit()
        else:
            k -= a[j]


Measured memory_bytes: 5912
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;
namespace io{
    #define re register
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline 
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
#define mod 1000000007
int n;
map <int,string> mp;
ll f[105][5][5][5];
bool check(int a,int b,int c,int d){
	if(mp[a]+mp[c]+mp[b]=="AGC") return 0;
	if(mp[a]+mp[b]+mp[d]=="AGC") return 0;
	if(mp[a]+mp[c]+mp[d]=="AGC") return 0;
	if(mp[b]+mp[c]+mp[d]=="AGC") return 0;
	if(mp[b]+mp[d]+mp[c]=="AGC") return 0;
	if(mp[c]+mp[b]+mp[d]=="AGC") return 0;
	return 1;
}
int main(){
	ll ans=0;
	mp[1]="A";
	mp[2]="G";
	mp[3]="C";
	mp[4]="T";
	read(n);
	f[0][0][0][0]=1; 
	for(re int i=1;i<=n;i++){
		for(re int j=1;j<=4;j++){
			for(re int a=0;a<=4;a++){
				for(re int b=0;b<=4;b++){
					for(re int c=0;c<=4;c++)
					if(check(c,b,a,j)) f[i][j][a][b]=(f[i][j][a][b]+f[i-1][a][b][c])%mod;
				}
			}
		}
	}
	for(int a=1;a<=4;a++){
		for(int b=1;b<=4;b++){
			for(int c=1;c<=4;c++){
				ans=(ans+f[n][a][b][c])%mod;
			}
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 384