akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) (a).begin(),(a).end()
#define ms(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10) 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge{ int from, to, cost; };

int n;
string s;
int main()
{
	cin >> n;
	REP(t, n)
	{
		cin >> s;
		vi v;
		REP(i, s.size())
		{
			if (s[i] == '[') v.push_back(-1);
			else if (s[i] == ']') v.push_back(-2);
			else
			{
				int k = i;
				while (s[k+1] != ']') k++;
				string tmp(s, i, k - i + 1);
				v.push_back(stoi(tmp));
				i += k-i;
			}
		}
		REP(i, v.size())
		{
			if (v[i] > 0) v[i] = v[i] / 2 + 1;
		}
		vi buf;
		while (1)
		{
			REP(i, v.size())//使う数のかっこを外す
			{
				if (v[i] == -1 && v[i + 1] == -1) buf.push_back(-1);
				else if (v[i] == -1) continue;
				else if (v[i] == -2) buf.push_back(-2);
				else
				{
					buf.push_back(v[i]);
					i++;
				}
			}
			if (buf[0] != -1) break;
			v.clear();
			REP(i, buf.size())
			{
				if (buf[i] == -1||buf[i]==-2) v.push_back(buf[i]);
				vi tmp;
				if (buf[i] != -1 && buf[i] != -2)
				{
					while (buf[i] != -2)
					{
						tmp.push_back(buf[i]);
						i++;
					}
					sort(ALL(tmp));
					int sum = 0;
					REP(j, tmp.size()/2 + 1)
					{
						sum += tmp[j];
					}
					v.push_back(sum);
					v.push_back(-2);
				}
			}
			buf.clear();
		}
		sort(ALL(buf));
		int ans = 0;
		REP(i, buf.size() / 2 + 1) ans += buf[i];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1360
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    h,w=map(int,readline().split())
    grid=[readline().strip() for _ in range(h)]
    grid2=np.zeros((h,w),dtype="int64")
    for i in range(h):
        for j in range(w):
            if grid[i][j]==".":
                grid2[i][j]=1
            else:
                grid2[i][j]=0

    up=np.zeros((h,w),dtype="int64")
    up[0]=grid2[0]
    for i in range(1,h):
        up[i]=(up[i-1]+1)*grid2[i]
    
    down=np.zeros((h,w),dtype="int64")
    down[-1]=grid2[-1]
    for i in range(h-2,-1,-1):
        down[i]=(down[i+1]+1)*grid2[i]
    
    left=np.zeros((h,w),dtype="int64")
    left[:,0]=grid2[:,0]
    for i in range(1,w):
        left[:,i]=(left[:,i-1]+1)*grid2[:,i]
    
    right=np.zeros((h,w),dtype="int64")
    right[:,-1]=grid2[:,-1]
    for i in range(w-2,-1,-1):
        right[:,i]=(right[:,i+1]+1)*grid2[:,i]

    ans=(up+down+left+right-3).max()
    print(ans)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 235536
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll N;
ll bit[1000010];

void bit_init(vector<ll> v){
	if(!v.empty()){
		N=v.size();
		for(ll x=1; x <= N; ++x) bit[x] = v[x];
		for(ll x=1; x < N; ++x) bit[x+(x&-x)] += bit[x];
	}
}
void bit_add(ll a, ll w){
		for(ll x=a; x <= N; x+=x&-x)bit[x]+=w;
}
ll bit_sum(ll a){
	ll ret=0;
	for(ll x=a;x>0;x-=x&-x) ret+=bit[x];
	return ret;
}
int main(){
  ll n;cin>>n;
  string s;cin>>s;
  vector<ll> a(n+1);
    				
  rep(i,n){
    if(s[i]=='W'){
    	a[i+1]++;
    }
  }
  bit_init(a);
  ll ans=INF;
  rep(i,n){
  	ans=min(ans,bit_sum(i)+n-i-1-bit_sum(n)+bit_sum(i+1));
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;
using ll = long long int;

#define rep(i, n) for(ll i = 0; i < (n); i++)
#define MOD 1000000007LL

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false); 
  ll N, K; cin >> N >> K;
  vector<ll> pos, neg;

  rep(i, N) {
    ll tmp; cin >> tmp;
    if (tmp > 0) {
      pos.push_back(tmp);
    } else {
      neg.push_back(-tmp);
    }
  }

  if (K == N) {
    ll prod = 1;
    for (ll x : pos) prod = prod * x % MOD;
    for (ll x : neg) prod = prod * (MOD - x) % MOD;
    cout << prod << endl;
    return 0;
  }

  if (static_cast<ll>(neg.size()) == N && K % 2 == 1) {
    sort(neg.begin(), neg.end());
    ll prod = 1;
    rep(i, K) prod = prod * (MOD - neg[i]) % MOD;

    cout << prod << endl;
    return 0;
  }

  sort(pos.begin(), pos.end(), greater<ll>());
  sort(neg.begin(), neg.end(), greater<ll>());

  ll prod = 1;
  if (K % 2 == 1 && static_cast<ll>(pos.size()) > 0) {
    auto it = pos.begin();
    prod = prod * *it % MOD;
    pos.erase(it);
    K--;
  }

  vector<ll> sqs;
  for (ll i = 0; i + 1 < static_cast<ll>(pos.size()); i += 2) {
    sqs.push_back(pos[i] * pos[i+1]);
  }
  for (ll i = 0; i + 1 < static_cast<ll>(neg.size()); i += 2) {
    sqs.push_back(neg[i] * neg[i+1]);
  }

  sort(sqs.begin(), sqs.end(), greater<ll>());
  rep(i, K / 2) {
    prod = prod * (sqs[i] % MOD) % MOD;
  }

  cout << prod << endl;
}


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

using namespace std;
 
 #define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define   ipr         	pair<int, int>
#define   pb            push_back
#define   ff            first
#define   ss            second
#define fill(a,b) memset(a, b, sizeof(a))
#define   fr(i, j, k)   for (int i = j; i < k; i++)
#define   rf(i, j, k)   for (int i = j; i >= k;i--)
#define   int           long long int
#define   ll 			unsigned long long
#define   ld            long double
#define   all(x)        x.begin(), x.end()
#define   rall(x)       x.rbegin(),x.rend()
#define   mp            make_pair
#define L(x) ('a'<=x && x<='z')
#define   inf           INT_MAX
#define   read_file();	freopen("input.txt", "r", stdin);	freopen("output.txt", "w", stdout);
#define   IOS           std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int Maxn  =  200*1000 + 1;
const ld  pi   =  acos(-1);
const int mod =  1000000007;
const double epsilon = 1e-9; 
 
 
template<class T> ostream& operator <<(ostream &out,vector<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template<class T> ostream& operator <<(ostream &out,unordered_set<T> &A){for(auto x:A) out<<x<<" ";return out;}
template <class T1,class T2>T1 powr(T1 a,T2 b){T1 res = 1;fr(i,1,b+1)res = res*a;return res;}

int binpow(int a,int b) {
    a=a%mod;
   
    int res = 1;
while (b > 0) {
        if (b & 1)res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
}
return (res+mod)%mod;
}



 int32_t main(){
    IOS;
 
   int t;
   //cin>>t;
       t=1;
   while(t--){

      vector<int>dp(2001,1);

      dp[0]=0;
      dp[1]=0;
      dp[2]=0;
      dp[3]=1;

      int n;
      cin>>n;

      fr(i,4,2001){
         fr(j,3,i)dp[i]=(dp[i]+dp[i-j])%mod;
      }

     cout<<dp[n]<<endl;

    
   }
}
 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

class RollingHash{
public:
  typedef long long ll;
  ll B, mod;  //B: ハッシュ基数
  Int n;
  string s;
  vector<ll> hash;
  vector<ll> k;

  RollingHash():n(-1){};
  RollingHash(string s,ll B = 1777771,ll mod = 1e9 + 7):
    B(B),mod(mod),n(s.size()),s(s),hash(n+1),k(n+1)
  {
    for(Int i=0;i<n;i++) hash[i+1] = (hash[i] * B % mod + s[i]) % mod;
    k[0] = 1;
    for(Int i=1;i<=n;i++) k[i] = (k[i-1] * B) % mod;
  }

  ll get(Int l,Int r){ //[l, r)
    assert(0<=l && r<=n && l<=r);
    return (mod + hash[r] - hash[l] * k[r-l] % mod) % mod;
  }
  
  //hash[a]とB.hash[b]からみて何文字一致してるか。
  Int count(Int a, RollingHash &B, Int b){
    Int L = 0, R = min( n - a, B.n - b ) + 1;
    while( L + 1 < R ){
      Int M = ( L + R ) / 2;
      get( a, a + M ) != B.get( b, b + M ) ? R = M : L = M;
    }
    return L;
  }
};
typedef unsigned long long ull;
vector<vector<Int> > Div(510000);
Int n;
string str;
RollingHash R;
Int ok(Int l,Int r){
  Int len = r - l;
  for(Int d:Div[len]){
    ull a = R.get(l+d, r);
    ull b = R.get(l, r - d) ;
    if(a == b) return 0;
  }
  return 1;
}



signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  const int N = 500010;
  
  for(Int i=1;i<N;i++)
    for(int j=i+i;j<N;j+=i) Div[j].push_back(i);


  cin>>str;
  n = str.size();
  R = RollingHash(str);
  
  if(string(n, str[0]) == str) {
    cout<<n<<endl;
    cout<<1<<endl;
    return 0;
  }
  
  if(ok(0, n)){
    cout<<1<<endl;
    cout<<1<<endl;
    return 0;
  }

  Int cnt = 0;
  for(Int i=0;i<n;i++){
    if(ok(0,i) && ok(i,n)) cnt++;
  }

  cout<<2<<endl;
  cout<<cnt<<endl;
  
  
  return 0;
}


Measured memory_bytes: 97640
h,w =map(int,input().split())
c = list(input() for _ in range(h))

print("#"*(w+2))
for i in range(len(c)):
    a = list(c[i])
    a.insert(0,"#")
    a.append("#")
    b = "".join(a)
    print(b)
    
print("#"*(w+2))

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	
	int a,b;

	scanf("%d %d\n",&a,&b);

	if(a<b)
		printf("a < b\n");
	if(a>b)
		printf("a > b\n");
	if(a==b)
		printf("a == b\n");

	return 0;
}

Measured memory_bytes: 1012
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

macro_rules! R { ($x:expr) => {{ print!("R"); $x += 1; }} }
macro_rules! L { ($x:expr) => {{ print!("L"); $x -= 1; }} }
macro_rules! U { ($y:expr) => {{ print!("U"); $y += 1; }} }
macro_rules! D { ($y:expr) => {{ print!("D"); $y -= 1; }} }

fn main() {
    let mut sc = Scanner::new();
    let x0: i64 = sc.cin();
    let y0: i64 = sc.cin();
    let x1: i64 = sc.cin();
    let y1: i64 = sc.cin();

    {
        let mut x = x0;
        let mut y = y0;
        while x < x1 { R!(x); }
        while y < y1 { U!(y); }
    }

    {
        let mut x = x1;
        let mut y = y1;
        L!(x);
        while y > y0 + 1 { D!(y); }
        while x > x0 { L!(x); }
        D!(y);
    }

    {
        let mut x = x0;
        let mut y = y0;
        D!(y);
        while x < x1 + 1 { R!(x); }
        while y < y1 { U!(y); }
        L!(x);
    }

    {
        let mut x = x1;
        let mut y = y1;
        U!(y);
        while x > x0 - 1 { L!(x); }
        while y > y0 { D!(y); }
        R!(y);
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
# INPUT
n, m = map(int, input().split())

matrix_A = []
vector_b = []
vector_c = [0 for i in range(n)]

for _ in range(n):
    matrix_A.append(list(map(int, input().split())))

for _ in range(m):
    vector_b.extend([int(input())])

# CALC, OUTPUT
for cnt_n in range(n):
    for cnt_m in range(m):
        vector_c[cnt_n] += matrix_A[cnt_n][cnt_m] * vector_b[cnt_m]
        
    print(vector_c[cnt_n])



Measured memory_bytes: 6020
#include <bits/stdc++.h>
using namespace std;
 
int main(){ 
    int a,b;

    cin>>a>>b;
    if(2*a-1>=a+b&&2*a-1>=2*b-1){
        cout<<2*a-1;
    }else if(2*b-1>=a+b&&2*b-1>=2*a-1){
            cout<<2*b-1;
    }else{
        cout<<a+b;
    }
 
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var p = make([]int, 4)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scan(&s)
		switch s {
		case "AC":
			p[0]++
		case "WA":
			p[1]++
		case "TLE":
			p[2]++
		case "RE":
			p[3]++
		}
	}
	fmt.Println("AC x", p[0])
	fmt.Println("WA x", p[1])
	fmt.Println("TLE x", p[2])
	fmt.Println("RE x", p[3])
}


Measured memory_bytes: 6328
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda x: [ni() for _ in range(x)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda x: [ns() for _ in range(x)]
nas = lambda: stdin.readline().split()

n = ni()
s = ns()

cs = [0] * (n + 1)
for i in range(n):
    cs[i + 1] = cs[i] + (1 if s[i] == 'W' else 0)

ans = inf
for i in range(n):
    ans = min(ans, cs[i] + ((n - i - 1) - (cs[n] - cs[i + 1])))

print(ans)

Measured memory_bytes: 15740
module answeroutput
contains
subroutine YNoutput(TF,ch)
  implicit none
  logical,intent(in)::TF
  character,intent(in),optional::ch
  if(present(ch))then
  select case(ch)
    case('Y')
      if(TF)then
        print"(A)","YES"
      else
        print"(A)","NO"
      endif
    case('y')
      if(TF)then
        print"(A)","yes"
      else
        print"(A)","no"
      endif
    case default
      if(TF)then
        print"(A)","Yes"
      else
        print"(A)","No"
      endif
    end select
  else
    if(TF)then
      print"(A)","Yes"
    else
      print"(A)","No"
    endif
  endif
  return
end subroutine
end module
use answeroutput
integer N
integer,allocatable,dimension(:)::A
integer x,y,z
integer xcnt,ycnt,zcnt
logical TF
read*,N
allocate(A(N))
read*,A
x=-1;y=-1;z=-1
xcnt=0;ycnt=0;zcnt=0
do i=1,N
  if((A(i)-x)*(A(i)-y)*(A(i)-z)/=0)then
    if(x==-1)then
      x=A(i)
      xcnt=1
    else if(y==-1)then
      y=A(i)
      ycnt=1
    else if(z==-1)then
      z=A(I)
      zcnt=1
    else
      call YNoutput(1==-1)
      stop
    endif
  else
    if(x==A(i))xcnt=xcnt+1
    if(y==A(i))ycnt=ycnt+1
    if(z==A(i))zcnt=zcnt+1
  endif
end do

TF=.False.
if((xcnt==ycnt.and.ycnt==zcnt).and.xor(xor(x,y),z)==0)TF=.TRUE.
if((x==0.and.xcnt==(N/3)).and.(ycnt==2*xcnt).and.zcnt==0)TF=.TRUE.
if((y==0.and.ycnt==(N/3)).and.(xcnt==2*ycnt).and.zcnt==0)TF=.TRUE.
if(x==0.and.xcnt==N)TF=.TRUE.

call YNoutput(TF)
end


Measured memory_bytes: 1152
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = sc.nextInt()
    val a = sc.nextInt()
    val b = sc.nextInt()
    println(problem071a(x, a, b))
}

fun problem071a(x: Int, a: Int, b: Int): String {
    return if (Math.abs(x - a) < Math.abs(x - b)) "A" else "B"
}

Measured memory_bytes: 31400
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;

int main(void)
{
	string str;
	int sum = 0, num;

	while (cin >> str)
	{
		for (int i = 0; i < str.size(); i++) if (str[i] < '0' || str[i] > '9') str[i] = ' ';
		stringstream s(str);
		while (s >> num) sum += num;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

struct edge{
    int f, t;
    ll cost;
    // define e1.cost < e2.cost : e1 < e2
    bool operator <(const edge &e) const {
        return cost < e.cost;
    }
};

// union find
class union_find {
public:
    int n;
    vector<int> parent, rnk, num;
    
    union_find(int n) : n(n), parent(n), rnk(n, 0), num(n, 1) {rep(i, n) parent[i] = i; }
    
    int root(int x){ return (parent[x] == x) ? x : root(parent[x]); }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (rnk[x] < rnk[y]) {
            parent[x] = y;
            num[y] += num[x];
        }
        else{
            parent[y] = x;
            num[x] += num[y];
            if (rnk[x] == rnk[y]) {
                rnk[x]++;
            }
        }
        n--;
    }
    
    bool same(int x, int y) {return root(x) == root(y);}
    
    int count(int x){ return num[root(x)]; }
};

class kruskal{
public:
    int v; // vertices
    vector<edge> e; // edges
    
    kruskal(int vt, int eg){
        v = vt;
        e.resize(eg);
    }
    
    kruskal(int vt): v(vt) {}
    
    void add(int from, int to, ll cost){
        e.pb({from, to, cost});
    }
    
    ll mst(){
        sort(e.begin(), e.end());
        union_find uf(v);
        ll min_cost = 0;
        rep(i, e.size()){
            edge &d = e[i];
            if (!uf.same(d.f, d.t)) {
                min_cost += d.cost;
                uf.unite(d.f, d.t);
            }
        }
        
        return min_cost;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N, Q;
    cin >> N >> Q;
    vector<ll> C(N, 1LL << 60); // edge{i, i+1, inf}
    kruskal mst(N);
    
    while(Q--){
        int from, to;
        ll cost;
        cin >> from >> to >> cost;
        mst.add(from, to, cost);
        
        C[from] = min(C[from], cost + 1);
        C[to] = min(C[to], cost + 2);
    }
    
    rep(i, 2 * N) C[(i + 1) % N] = min(C[(i + 1) % N], C[i % N] + 2);
    
    rep(i, N){
        mst.add(i, (i + 1) % N, C[i]);
    }
    
    output(mst.mst());
    
    return 0;
}

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

const ll mx = 1e18;

int main(){
    int N;
    cin >> N;
    ll res = 1;
    bool ng = false;

    rep(i, N)
    {
        ll a;
        cin >> a;
        if (a==0) {
            cout << 0 << endl;
            return 0;
        }
        if (mx/res < a) {
            ng = true;
        }
        else {
            res *= a;
        }
    }
    if (ng)
        cout << -1 << endl;
    else
        cout << res << endl;
}

Measured memory_bytes: 3628
fn main() {
    let stdin = std::io::stdin();
    let mut buf = String::new();

    stdin.read_line(&mut buf).unwrap();
    let nums: Vec<i64> = buf.trim().split_whitespace()
        .map(|e| e.parse::<i64>().unwrap()).collect();
    let a = &nums[0];
    let b = &nums[1];
    let x = &nums[2];
    let ans = match a {
        &0 => b/x + 1,
        _ => b/x - (a-1)/x
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    const double pi = acos(-1);
    double angm = (m / 60.0) * 2 * pi;
    double angh = (h / 12.0) * 2 * pi + (m / 60.0) * 2 * pi / 12;
    double ang = min(abs(angm - angh), 2 * pi - abs(angm - angh));
    double ans = a * a + b * b - 2 * a * b * cos(ang);
    ans = sqrt(ans);
    cout << fixed << setprecision(10);
    cout << ans << endl;
    //cout << ang << endl;
    //cout << "angm " << angm << endl;
    //cout << "angh " << angh << endl;
    return 0;
}


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

const ll INF = 1LL << 60;
int N, M;
bool graph[707][707];
int done[707];
bool dp[707][707];

int a0, a1;
int b0, b1;

template<typename A, typename B>
void chmin(A &a, const B &b) {
    if (a > b) a = b;
}

ll comb(ll x) {
    return x * (x - 1) >> 1;
}

void bip(int cur, int clr = 0) {
    (clr == 0 ? a0 : a1)++;
    done[cur] = clr;
    REP(i, N) {
        if (not graph[cur][i]) continue;
        if (done[i] != -1) {
            if (done[i] != clr ^ 1) {
                cout << -1 << endl;
                exit(0);
            }
            continue;
        }
        bip(i, clr ^ 1);
    }
}

signed main() {
    cin >> N >> M;
    REP(i, N) REP(j, N) if (i != j) graph[i][j] = true;
    REP(i, M) {
        int A, B;
        cin >> A >> B;
        --A, --B;
        //graph[A].emplace_back(B);
        //graph[B].emplace_back(A);
        graph[A][B] = false;
        graph[B][A] = false;
    }
    REP(i, N) done[i] = -1;
    vector<pair<int, int>> prs;
    REP(i, N) {
        if (done[i] != -1) continue;
        bip(i);
        int x = a0 - b0, y = a1 - b1;
        if (x > y) swap(x, y);
        prs.emplace_back(x, y);
        b0 = a0, b1 = a1;
    }
    // for (auto& [x, y]: prs) {
    //     cerr << x << ' ' << y << endl;
    // }
    dp[0][0] = true;
    int sz = prs.size();
    REP(i, sz) {
        REP(j, N + 1) {
            if (not dp[i][j]) continue;
            dp[i + 1][j + prs[i].first] = true;
            dp[i + 1][j + prs[i].second] = true;
        }
    }
    ll res = INF;
    REP(i, N + 1) {
        if (not dp[sz][i]) continue;
        chmin(res, comb(i) + comb(N - i));
    }
    cout << res << endl;
}


Measured memory_bytes: 4504
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if(a==b):
    print('YES')
elif(a < b):
    if((a+v*t) >= (b+w*t)):
        print('YES')
    else:
        print('NO')
else:
    if((a-v*t) <= (b-w*t)):
        print('YES')
    else:
        print('NO')

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

#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

int64_t n,q;
vector<int64_t>G[(int)2e5+10];
vector<int64_t>E((int)2e5+10,0);
vector<bool>f((int)2e5+10,0);

void dfs(int x){

    f[x]=1;
    int w=E[x];
    REP(i,G[x].size()){
        if(f[G[x][i]])continue;
        E[G[x][i]]+=w;
        dfs(G[x][i]);
    }
}


void solve() 
{
    cin>>n>>q;
    REP(i,n-1){
        int a,b;cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    REP(i,q){
        int a,b;cin>>a>>b;
        E[a]+=b;
    }
    dfs(1);
    REP(i,n)cout<<E[i+1]<<endl;
}

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

Measured memory_bytes: 24320
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import bisect

n, m = map(int, input().split())
a = [int(item) for item in input().split()]
a.sort()
a_rev = sorted(a, reverse=True)

cumsum = [0]
for item in a:
    cumsum.append(cumsum[-1] + item)

# Use pair which sum goes over mid
l = 0; r = 10**10
while r - l > 1:
    mid = (l + r) // 2
    to_use = 0
    for i, item in enumerate(a_rev):
        useless = bisect.bisect_left(a, mid - item)
        to_use += n - useless
    if to_use >= m:
        l = mid
    else:
        r = mid
ans = 0
total_use = 0
for i, item in enumerate(a_rev):
    useless = bisect.bisect_left(a, l - item)
    to_use = n - useless
    total_use += to_use
    ans += item * to_use + cumsum[n] - cumsum[n - to_use]
print(ans - l * (total_use - m))

Measured memory_bytes: 57628
#include <cstdio>
#include <algorithm>
using namespace std;

#define ll long long int

#define mx 200005
int arr[mx];

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++) scanf("%d",arr+i);
    sort(arr,arr+n);

    ll ans=arr[n-1];
    int left=n-2;
    for(int i=n-2;i>=0;i--){
        if(left<=0) break;
        if(left>=2){
            left-=2;
            ans+=2*arr[i];
        }
        else{
            left--;
            ans+=arr[i];
        }

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


Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i=(a); i<(b); i++)

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int Start = max(A, C);
  int End = min(B, D);
  if (Start >= End) cout << "0" << endl;
  else cout << End-Start << endl;
  return 0;
  
}




Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
char s[101010];
int main()
{
	int l;
	scanf("%s",s+1);
	l=strlen(s+1);
	if(s[1]==s[l])
		l--;
	if(l&1)
		printf("First");
	else
		printf("Second");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		UL R, B; R = B = 0;
		rep(i, N) {
			char c; cin >> c;
			((c == 'R') ? R : B)++;
		}
		cout << ((R > B) ? "Yes" : "No") << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

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

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
constexpr int loose = 0;
constexpr int tight = 1;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll n;
	cin>>n;
	Matrix a(n,Array(3));
	REP(i,n) cin>>a[i][0]>>a[i][1]>>a[i][2];

	Matrix dp(n+1,Array(3,0));//iこまでみて、最後にjした
	REP(i,n){
		REP(j,3){
			REP(k,3){
				if(j==k) continue;
				chmax(dp[i+1][k],dp[i][j]+a[i][k]);
			}
		}		
	}
	ll ans=0;
	REP(i,3) chmax(ans,dp[n][i]);
	cout<< ans<<en;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 11136
x,y,z,k = list(map(int, input().split()))

a = sorted(list(map(int, input().split())), reverse = True)
b = sorted(list(map(int, input().split())), reverse = True)
c = sorted(list(map(int, input().split())), reverse = True)

ab = sorted([a_k+b_k for a_k in a[:k] for b_k in b[:k]], reverse = True)
abc = sorted([ab_k+c_k for ab_k in ab[:k] for c_k in c[:k]], reverse = True)

for index,number in enumerate(abc):
    if index >= k:
        break
    print(number)


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

using namespace std;

int x, y;

int main()
{
	cin >> x >> y;
	if(x == y){
		cout << 0;
	}
	if(y > x) {
		if(y > 0 and x < 0) {
			cout << 1 + abs(abs(x) - abs(y));
			return 0;
		}
		if(x >= 0 or y <= 0) {
			cout << y - x;
			return 0;
		}
	}
	else{
		if(x < 0 or y > 0) {
			cout << x - y + 2;
			return 0;
		}
		else if(x > 0 and y < 0){
			cout << abs(abs(x) - abs(y)) + 1;
			return 0;
		}
		else {
			cout << x - y + 1;
			return 0;
		}
	}
}


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

int main(){
  int N;
  cin >> N;
  bool flg=false;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      if(i*j==N)flg=true;
    }
  }
  if(flg)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
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; }

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll w, h;
    cin>>w>>h;
    vl ps(w), qs(h);
    cin>>ps>>qs;

    priority_queue<LP, vector<LP>, greater<LP>> q;
    rep(i, w) q.emplace(ps[i], 0);
    rep(i, h) q.emplace(qs[i], 1);
    ll a = w + 1, b = h + 1;
    ll ans = 0;
    while (!q.empty()) {
        LP p = q.top(); q.pop();
        ll e = p.fi;
        ll s = p.se;
        if (s == 0) {
            if (a) {
                ans += e * b;
                a--;
            }
        }
        else {
            if (b) {
                ans += e * a;
                b--;
            }
        }
    }
    cout<<ans<<endl;
}

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

*A, = map(int, input().split())

count = 0
flg = 0

while flg!=1:
    for i in range(len(A)):
        if A[i]%2!=0:
            flg = 1
            break
        A[i] = A[i]//2
    if flg==0:
        count = count + 1

print(count)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    
    int main(){
        ll n , a;
        cin >> n;
        ll ans = 0;
        vector<ll> v;
        for(ll i = 0 ; i <= n ; i++){
            cin >> a;
            v.push_back(a);
        }
        for(ll i = 0 ; i < n ; i++){
            cin >> a;
            if(a <= v[i]){
                ans += a;
            }else{
                ans += v[i];
                a -= v[i];
                if(a <= v[i+1]){
                    ans += a;
                    v[i+1] -= a;
                }else{
                    ans += v[i+1];
                    v[i+1] = 0;
                }
            }
        }
        cout << ans << endl;
        return 0;
    }

Measured memory_bytes: 1400
def delta(t1,t2):
	h,m = [int(t2[i:i+2]) - int(t1[i:i+2]) for i in [0,3]]
	return 60*h + m
n,t = map(int,raw_input().split())
s = [raw_input().split() for i in range(n)]
a = []
for i in range(1,n):
	dt = delta(s[i-1][2],s[i][0])
	if dt >= t:
		a.append(s[i][1]+" "+str(dt))
print len(a)
for i in a:
	print i

Measured memory_bytes: 4240
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    string n;
    cin >> n;
    int m=n.size();
    ll tol=0;
    rep(i,m){
        tol+=(n[i]-'0');
    }
    if(tol%9==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3700
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<int MOD>
class ModInt {
public:
    ModInt() :value(0) {}
    ModInt(long long val) :value((int)(val<0 ? MOD + val%MOD : val%MOD)) { }

    ModInt& operator+=(ModInt that) {
        value = value + that.value;
        if (value >= MOD)value -= MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that) {
        value -= that.value;
        if (value<0)value += MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that) {
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that) {
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const {
        return ModInt(*this) += that;
    }
    ModInt operator-(ModInt that) const {
        return ModInt(*this) -= that;
    }
    ModInt operator*(ModInt that) const {
        return ModInt(*this) *= that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const {
        if (value == 0)return 0;
        ModInt n = *this, res = 1;
        while (k) {
            if (k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const { return value; }

private:
    int value;
};
typedef ModInt<998244353> mint;
ostream& operator<<(ostream& os, const mint& x) {
    os << x.toi();
    return os;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vi x(N), y(N);
    rep(i, N)cin >> x[i] >> y[i];

    mint ans = mint(2).pow(N) - 1 - N;

    // z個の頂点を含む直線の数 * z
    // = z個の頂点を含む直線上の点をカウント
    map<int, int> S;
    rep(i, N) {
        map<pii, int> cnt;
        rep(j, N) if (i != j) {
            int vx = x[i] - x[j], vy = y[i] - y[j];
            int g = gcd(vx, vy);
            vx /= g;
            vy /= g;
            if (vx < 0) {
                vx *= -1;
                vy *= -1;
            }
            cnt[mp(vx, vy)]++;
        }
        each(p, cnt) {
            S[p.second + 1]++;
        }
    }

    each(p, S) {
        int z, w;
        tie(z, w) = p;
        w /= z;
        // z個の頂点を含む直線がw個ある
        ans -= (mint(2).pow(z) - 1 - z)*w;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  long int  a, b[200000];
  long int  n,  j, k, l;
  int  i;

  scanf("%ld", &n);

  l = n / 2;
  if(n%2){
    i = -1;
  } else {
    i = 1;
  }
  for( k = 0; k < n; k++){
    scanf("%ld", &a);
    j = l + (k+1)/2 * i;
    b[ j ] = a;
    i *= -1;
  }

  for( k = 0; k < n; k++){
    printf("%ld ", b[k]);
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    // vector<bool> a(1000000001,0);
    vector<ll> l(n);
    rep(i,n){
        cin >> l[i];
    } 
    // set<int> s(l1.begin(),l1.end());
    // vector<int> l(s.begin(),s.end());
    ll ans = 0;
    for(ll i=0;i<n-2;i++){
        for(ll j=i+1;j<n-1;j++){
            for(ll k=j+1;k<n;k++){
                if(l[i]!=l[j]&&l[j]!=l[k]&&l[k]!=l[i]){
                    ll sum = l[i] + l[j] + l[k];
                    ll ma = max({l[i],l[j],l[k]});
                    if(sum - ma > ma) ans++;
                }
            }
        }
    }

    cout << ans;


    return 0;
}

Measured memory_bytes: 3560
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [a, b] = stdin
  .split('\n')[0]
  .split(' ')

const res = _ => {
  if (b === 'H' && a === 'H') {
    return 'H'
  } else if (b === 'D' && a === 'D') {
    return 'H'
  }
  return 'D'
}

console.log(res())


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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  
  if ((a+b)==(c+d)){
    cout <<"Balanced"<<endl;
  }
  else if ((a+b)<=(c+d)){
    cout << "Right"<<endl;
  }
  else{
    cout <<"Left"<<endl;
  }
  
  
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    // int N = Integer.parseInt(scanner.nextLine());
    // int N = scanner.nextInt(), M = scanner.nextInt();
    // scanner.nextLine();
    // int[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    // long[] n = Arrays.stream(scanner.nextLine().split(" ")).mapToLong(Long::parseLong).toArray();
    static void solve(Scanner scanner) {
        int N = scanner.nextInt(), M = scanner.nextInt();
        scanner.nextLine();
        int[] S = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int[] T = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        long[][] dp = new long[N + 1][M + 1];
        long[][] sum = new long[N + 1][M + 1];

        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= M; j++) {
                if (S[i - 1] == T[j - 1]) {
                    dp[i][j] = (sum[i - 1][j - 1] + 1) % MOD;
                }
                sum[i][j] =
                        (sum[i][j - 1] + sum[i - 1][j] + (MOD - sum[i - 1][j - 1]) + dp[i][j]) % MOD;
            }
        }

        long ans = 1;
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= M; j++) {
                ans = (ans + dp[i][j]) % MOD;
            }
        }

        System.out.println(ans);
    }

}


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

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

  vector<string> str;
  str.emplace_back(s.substr(0, 1));

  int ans = 1;
  for(int i=1; i<s.size(); ++i){
    ++ans;
    if(s.substr(i, 1) == str[(int)str.size()-1] && i + 1 >= s.size()){
      --ans;
    }
    else if(s.substr(i, 1) == str[(int)str.size()-1]){
      str.push_back(s.substr(i, 2));
      ++i;
    }
    else{
      str.push_back(s.substr(i, 1));
    }
  }

  cout << ans << endl;
}


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

int main() {
  int N;
  cin>>N;
  vector<int> h(N);
  rep(i,N) cin>>h[i];
  int ans=0;
  rep(i,N-1) {
    if(h[i]-h[i+1]>0) ans += h[i]-h[i+1];
  }
  ans += h[N-1];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
require 'pp'

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N =gets_i
abc = []
N.times do
  abc.push(gets_i_list)
end

dp = Array.new(N + 1).map{Array.new(3,0)}
(N).times do |n|
  # A
  dp[n + 1][0] = [dp[n][1], dp[n][2]].max + abc[n][0]
  # B
  dp[n + 1][1] = [dp[n][0], dp[n][2]].max + abc[n][1]
  # C
  dp[n + 1][2] = [dp[n][0], dp[n][1]].max + abc[n][2]
end
puts dp.last.max



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

int main() {
  
  int n; cin >> n; int vec[2][n]; int tmp = 0;
  
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < n; j++) {
      cin >> vec[i][j];
    }
  }
  
  for (int i = 1; i < 4; i++) {
    
    int64_t sum = 0; double p = 1.0 / (double)i;
    
    for (int j = 0; j < n; j++) {
      sum += pow(abs(vec[0][j] - vec[1][j]), i);
    }
    
    cout << fixed << setprecision(10);
    
    cout << pow((double)sum, p) << endl;
    
  }
  
  for (int i = 0; i < n; i++) {
    int d = abs(vec[0][i] - vec[1][i]);
    tmp = max(tmp, d);
  }
  
  cout << (double)tmp << endl;
  
}


Measured memory_bytes: 3484
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

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

    vint sumE(N+1),sumW(N+1);
    REP(i,N){
        sumE[i+1]+=sumE[i]+(s[i]=='E');
        sumW[i+1]+=sumW[i]+(s[i]=='W');
    }
    
    int ans=N;
    REP(i,N){
        int w=sumW[i];
        int e=sumE[N]-sumE[i+1];
        ans=min(ans,w+e);
    }
    cout<<ans<<endl;
}


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

using namespace std;

#define ll					long long
#define vi					vector<int>
#define vii					vector<vi>
#define ALL(s)			(s).begin(),(s).end()
#define ALLn(s)			s,s+n
#define pii					pair<int, int>
#define pll					pair<ll, ll>
#define si					set<int>
#define mp					make_pair
#define F						first
#define S						second
#define pb					push_back
#define tc(t)				int t; cin >> t; while(t--)
#define _						ios_base::sync_with_stdio(false); cin.tie(NULL);

template <typename Iter>
size_t index_of(Iter first, Iter last, int x)
{
    size_t i = 0;
    while (first != last && *first != x) ++first, ++i;
    return i;
}

const ll MOD = 1e9 + 7;
const ll INF = 1<<29;
const ll MAX_N = 1e6 + 7;


void solve() {
	int n,m;
	cin >> n >> m;

	int a[n];
	ll sum = 0;

	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	int ok = 1;
	sort(ALLn(a));

	for(int i = n-1; i >= n-m; --i) {
		//cout << a[i] << " " << sum << " " << (4*m) << "\n";
		if(a[i] >= (int)(ceil(sum/((4.0)*m)))) continue;
		else {
			ok = 0;
			break;
		}
	}

	if(ok) cout << "Yes\n";
	else cout << "No\n";
}

int main() {_
	
		solve();
	

}


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

int main() {
    int a, b;
    cin >> a >> b;

    cout << max(a*b,max(a+b, a-b)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
    int dice[6],side[]={2,3,5,4,2};
    int a,b,i,j,k,l,n;
    char move[]={"00NWESn"};
    
    for(i=1; i<=6; i++) scanf("%d",&dice[i]);
    scanf("%d",&n);
    
    for(i=0; i<n; i++){
        scanf("%d %d",&a,&b);
        for(j=1; dice[j]!=a; j++);
        
        dice[0]=dice[1];
        
        switch(move[j]){
            case 'E':
            dice[1]=dice[4];
            dice[4]=dice[6];
            dice[6]=dice[3];
            dice[3]=dice[0];
            break;
            
            case 'N':
            dice[1]=dice[2];
            dice[2]=dice[6];
            dice[6]=dice[5];
            dice[5]=dice[0];
            break;
            
            case 'S':
            dice[1]=dice[5];
            dice[5]=dice[6];
            dice[6]=dice[2];
            dice[2]=dice[0];
            break;
            
            case 'W':
            dice[1]=dice[3];
            dice[3]=dice[6];
            dice[6]=dice[4];
            dice[4]=dice[0];
            break;
            
            case 'n':
            dice[1]=dice[6];
            dice[6]=dice[0];
            dice[0]=dice[2];
            dice[2]=dice[5];
            dice[5]=dice[0];
            break;
        }
        
        for(l=0; dice[side[l]]!=b; l++);
        printf("%d\n",dice[side[l+1]]);
    }
    return 0;
}






Measured memory_bytes: 2032