akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
// const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod_) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod_;
        a = a * a % mod_;
        n >>= 1;
    }
    return res;
}

const ll MAX_SIZE = 200005;
array<ll, MAX_SIZE> fac, inv, finv;
void finit() {
    // combination init
    fac[0] = 1;
    for (ll i = 1; i < MAX_SIZE; i++) fac[i] = fac[i - 1] * i % MOD;
    finv[MAX_SIZE - 1] = modpow(fac[MAX_SIZE - 1], MOD - 2, MOD);
    for(ll i = MAX_SIZE - 1; i > 0; i--) finv[i - 1] = finv[i] * i % MOD;
    
    //inv init
    repe(i, 1, MAX_SIZE) inv[i] = modpow(i, MOD - 2, MOD);
}

ll perm(ll a, ll b) { return fac[a] * finv[a - b] % MOD; }

ll comb(ll a, ll b) { return fac[a] * finv[b] % MOD * finv[a - b] % MOD; }

int main() {
    init();
    finit();
    ll N, M, K;
    cin >> N >> M >> K;

    ll ans = M, tmp = 0;
    // 同じ色k組以下のとき
    rep(k,K+1){
        (tmp += comb(N-1,k)*modpow(M-1,N-k-1, MOD) %MOD) %= MOD;
    }
    (ans *= tmp) %= MOD;

    cout << ans << endl;
}

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

using namespace std;
using ll = long long int;

ll powmod(ll base, ll exp, ll mod) {
    if (exp == 0) {
        return 1;
    }
    if (exp % 2 == 0) {
        ll t = powmod(base, exp / 2, mod);
        return (t * t) % mod;
    }
    return (base * powmod(base, exp - 1, mod)) % mod;
}

unordered_map<ll, ll> primefactordecomp(ll n) {
    unordered_map<ll, ll> ans = unordered_map<ll, ll>();
    ll m = pow(n, 0.5) + 1;
    for (ll i = 2; i < m; i++) {
        while (n > 1) {
            if (n % i != 0) {
                break;
            } else {
                if (ans.count(i) == 0) {
                    ans[i] = 0;
                }
                ans[i] += 1;
                n = ll(n / i);
                continue;
            }
        }
    }
    if (n > 1) {
        ans[n] = ans[n] + 1;
    }
    return ans;
}

int main() {
    int N;
    unordered_map<ll, ll> total_primes = unordered_map<ll, ll>();
    vector<unordered_map<ll, ll>> each_primes = vector<unordered_map<ll, ll>>();

    ll M = pow(10, 9) + 7;
    cin >> N;
    ll A[N];
    for (int i = 0; i < N; i++) {
        ll c;
        cin >> c;
        A[i] = c;

        unordered_map<ll, ll> primes = primefactordecomp(c);
        for (pair<ll, ll> p: primes) {
            if (total_primes.count(p.first) == 0) {
                total_primes[p.first] = 0;
            }
            total_primes[p.first] = max(p.second, total_primes[p.first]);
        }
    }

    ll lcm = 1;
    for (pair<ll, ll> p: total_primes) {
        lcm *= powmod(p.first, p.second, M);
        lcm %= M;
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += (lcm * powmod(A[i], M - 2, M)) % M;
        ans %= M;
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	X := ReadString()
	s := 0
	c := 0
	for _, b := range X {
		if b == 'S' {
			s++
		} else {
			if s == 0 {
				c++
			} else {
				s--
			}
		}
	}
	c += s
	fmt.Println(c)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 3216
import java.util.*;

class Main{
	public static void main(String[] args){
		Solve s = new Solve();
		s.solve();
	}	
}

class Solve{
	Solve(){}
	
	Scanner in = new Scanner(System.in);

	void solve(){
		int[] b = new int[3];
		for(int i = 0; i < 3; i++) b[i] = in.nextInt();
		if(((b[0] & b[1]) | b[2]) == 1) System.out.println("Open");
		else System.out.println("Close"); 
	}
	
}

// while(in.hasNext()){
		// 	int n = in.nextInt();
		// 	if(n == 0) return;
			
		// }

Measured memory_bytes: 26240
#include<cstdio>
#include<vector>

using namespace std;
const int maxn = 500 + 10;

int a[maxn];
int main(){
	int n;
	vector<int> v;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",a + i);
	}
	v.push_back(1);
	for(int i = 2;i <= n;i++){
		if(a[i] == a[i - 1]) v[v.size() - 1]++;
		else v.push_back(1);
	}
	int ans = 0;
	for(int i = 0;i < v.size();i++){
		ans += v[i] / 2;
	}
	printf("%d\n",ans);
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll A,B,K;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>K;
	ll a=min(A,K);
	A-=a;
	K-=a;
	ll b=min(B,K);
	B-=b;
	cout<<A<<" "<<B<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
typedef long long  ll;
//typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set
// this for long double
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<endl; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<-1; return 0;}
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const int N = 1010;
const int INF = 1e8;
const ll MOD1=1073741824;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
string bin_rep(int n)
{
          string s="";
      for(int i=31;i>=0;i--)
   {
           if(n&(1<<i)) s+='1';
           else s+='0';
   }
   return s;
}
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 int a,b,c,d;
 cin>>a>>b>>c>>d;
 int cnt=0;
 while(a>0 && c>0)
 {
           if(cnt&1) 
           {
                     a-=d;
           }
           else
           {
                    c-=b;
           }
           cnt++;
 }
if(cnt&1) cout<<"Yes";
else cout<<"No";
 
 
 
 
 
    
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

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

namespace program
{
    class Program
    {
        static void Main()
        {
          var s = Input.ScanIntArray();
          Out(Math.Max(s[2] - s[0] + s[1], 0));
        }
      
        static public void Out(object s) { Console.WriteLine(s); }
    }
    
    static class Input {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

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

    static class MyMath {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 13396
//#define DEB1 //output check function
//#define DEB2 //same output, input from input.txt

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VVI = vector<VI>;


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;
}


#ifdef DEB1
#define DPRINT(x) cout<< #x << "=" << (x) << endl; // print at debug mode
#else
#define DPRINT(x) ;
#endif
#ifdef DEB1
#define DCHECK(x) cout<< "debug check" << #x << endl;
#else
#define DCHECK(x) ;
#endif
 


/*
constant values
*/

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

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9

// Main program
void solve(){
    int N,K;
    cin >> N >> K;
    int max_k;
    max_k = N*(N-1)/2 - (N-1);
    if (K > max_k){
        cout << -1 << endl;
        return;
    }
    // total edge

    int left;
    left = max_k - K;

    cout << left + N - 1 << endl; 

    REP(i,N-1){
        cout << 1 << " " << i+2 << endl;
    }
    REP(i,N-2){
        REPN(j,N-2,i){
            if(left!=0){
                cout << i+2 << " "<<j+3 << endl;
                --left;
            }
            
        }
    }

}



// ----------------------------------------------
int main() {

#ifdef DEB2
    cout << "DEBUG MODE"  << endl;
	ifstream in("input.txt"); //for debug
	cin.rdbuf(in.rdbuf()); //for debug
#endif

	int T=1; 

	for (int i = 0; i < T; ++i) {
		solve();
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
bool bz[500010];
int gs,n;
long long b[1010][1010],c[1010][1010],ans[1010][1010],zs[500010];
int fx[4][2]={{0,-1},{0,1},{-1,0},{1,0}};
 
//long long gcd(long long a,long long b)
//{
//	if (b==0) return a;
//	return gcd(b,a%b);
//}
 
long long lcm(long long x, long long y) 
{
	if (x==0 || y==0) return x+y;
	return x/__gcd(x,y)*y;
}
//long long lcm(long long a,long long b)
//{
//	return a*b/__gcd(a,b);
//}
 
int main()
{
	for (int i=2;i<=500000;i++)
	{
		if (!bz[i])
		{
			gs++;
			zs[gs]=i;
			for (int j=1;j<=500000/i;j++)
			{
				bz[j*i]=true;
			}
		}
	}
	scanf("%d",&n);
	if (n==2)
	{
		printf("4 7\n");
		printf("23 10\n");
		return 0;
	}
	for (int i=1;i<=n;i++)
	{
		if (i%2==1)
		{
			int x=1;int y=i;
			while (x<=n && y<=n)
			{
				b[x][y]=zs[i];
				x++;y++;
			}
			if (i==1) continue;
			x=i;y=1;
			while (x<=n && y<=n)
			{
				b[x][y]=zs[i-1];
				x++;y++;
			}
		}
	}
	for (int i=n;i>=1;i--)
	{
		if (i%2==1)
		{
			int x=1;int y=i;
			while (x<=n && y>=1)
			{
				c[x][y]=zs[n+n-i+1];
				x++;y--;
			}
			if (i==n) continue;
			if (n%2==0) x=n-i+1;
			else x=n-i+1;y=n;
			while (x<=n && y>=1)
			{
				c[x][y]=zs[n+n-i];
				x++;y--;
			}
		}
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			if ((i+j)%2==0)
			{
				ans[i][j]=b[i][j]*c[i][j];
			}
		}
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			if(!ans[i][j]) 
			{
				ans[i][j]=lcm(lcm(ans[i-1][j],ans[i][j-1]),lcm(ans[i][j+1],ans[i+1][j]))+1;
			}
		}
	}
//	for (int i=1;i<=n;i++)
//	{
//		for (int j=1;j<=n;j++)
//		{
//			if ((i+j)%2==1)
//			{
//				long long op=0;
//				for (int k=0;k<=3;k++)
//				{
//					int x=i+fx[k][0];
//					int y=j+fx[k][1];
//					if (x>=1 && x<=n && y>=1 && y<=n)
//					{
//						if (op==0) op=ans[x][y];
//						else op=lcm(op,ans[x][y]);
//					}
//				}
//				ans[i][j]=op+1;
//			}
//		}
//	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			printf("%lld ",ans[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 16380
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n;
  cin >> n;
  priority_queue<ll>pq;
  rep(i,n){
    ll x;
    cin >> x;
    pq.push(x);
  }
  ll a=pq.top(),b=0;
  pq.pop();
  vector<ll>vec;
  while(!pq.empty()){ 
    b=pq.top();
    if(a==b){
      vec.push_back(a);
      if(pq.size()>1){
        pq.pop();
        a=pq.top();
        pq.pop();
      }
      else break;
    }
    else{
      a=b;
      pq.pop();
    }
  }
  if(vec.size()>1)cout << vec[0]*vec[1] << endl;
  else cout << 0 << endl;
  
}


Measured memory_bytes: 1908
N, K = map(int, input().split())
s,p,r = map(int, input().split())
point={'s':s, 'p':p, 'r':r}

T = input()

group = [[] for i in range(K)]

for i in range(N):
    group[i%K].append(T[i])
    
def score(l):
    s=0
    ex = ''
    for i in l:
        if ex == i:
            ex =''
        else:
            s += point[i]
            ex = i
    return s

ans = 0
            
for sub in group:
    ans += score(sub)

print(ans)


Measured memory_bytes: 13428
nk=list(map(int,input().split(' ')))
nk[0]=nk[0]%nk[1]
while(True):
    if abs(nk[0]-nk[1])<nk[0]:
        nk[0]=abs(nk[0]-nk[1])
    else:
        break
print(nk[0])

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
const lld MAXN = 1e5;

int main()
{
	lld n,a[MAXN] = {};

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

	sort(a,a+n,greater<lld>());

	lld max1 = 0,max2 = 0;

	lld i = 0,cnt = 0;
	while(i < n)
	{
		if (a[i] == a[i+1])
		{
			if (cnt == 0)
			{
				max1 = a[i];
				cnt++;
			}else
			{
				max2 = a[i];
				break;
			}

			i += 2;
		}else
		{
			i++;
		}
	}

	cout << max1 * max2 << endl;

	return 0;
}

Measured memory_bytes: 1024
def solve():
    A, B, C = map(int, input().split())
    count = 0
    coins = 0
    while True:
        if coins >= C:
            break
        count += 1
        coins += A
        if count % 7 == 0:
            coins += B
    print(count)


if __name__ == '__main__':
    solve()



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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pli pair<long long,int>
#define pil pair<int,long long>
#define ll long long
#define el '\n'

using namespace std;

const int N = 2e6 + 10;
// const int N = 1e3 + 10;
const ll MOD = 1e9 + 7;

ll n, k;
string s;
// ll dp[N][N]; // pointer s last, 
ll fac[N];

ll fpow(ll a, ll b){
    ll ret = 1;
    while (b){
        if (b & 1){
            ret = ret * a % MOD;
        }
        b >>= 1;
        a = a * a % MOD;
    }
    return ret;
}
ll inv(ll a){
    return fpow(a, MOD - 2);
}
ll comb(ll n, ll k){
    return fac[n] * inv(fac[n - k] * fac[k] % MOD) % MOD;
}

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

    fac[0] = 1;
    for (ll i=1;i<N;i++){
        fac[i] = fac[i - 1] * i % MOD;
    }

    cin >> k;
    cin >> s;
    n = (ll) s.length();
    s = "*" + s;
    ll ans = 0;
    for (ll i=0;i<=k;i++){
        ll temp = (fpow(26, i) * fpow(25, k - i) % MOD) * comb(n + (k - i) - 1, (k - i)) % MOD;
        ans = (ans + temp) % MOD;
    }
    cout << ans << el;

    return 0;
}

Measured memory_bytes: 20944
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
ll n;ll c[N];
vector<ll> g[N];
stack<ll> s[N];
ll rem[N];
ll dp[N];
ll sub[N];
ll d[N];
void tfs(int i,int p){
    sub[i]=1;
    for(auto j: g[i]){
        if(j==p)continue;
        tfs(j,i);
        sub[i]+=sub[j];
    }
}
void dfs(int i,int p){
    s[c[i]].push(i);
    for(auto j: g[i]){
        if(j==p)continue;
        d[i]=sub[j];
        dfs(j,i);
        ll y=d[i];
        dp[c[i]]-=(y*(y+1)/2);
    }
    s[c[i]].pop();
    if(s[c[i]].size()){
        d[s[c[i]].top()]-=sub[i];
    }
    else{
        rem[c[i]]-=sub[i];
    }
}
int main() {
   
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        cin>>n;
        rep(i,n){
            cin>>c[i];c[i]--;
        }
        rep(i,n-1){
            int u,v;cin>>u>>v;u--;v--;
            g[u].pb(v);
            g[v].pb(u);
        }
        tfs(0,-1);
        dfs(0,-1);
        rep(i,n){
            dp[i]+=(n*(n+1))/2;
            rem[i]+=n;
            dp[i]-=(rem[i]*(rem[i]+1)/2);
            cout<<dp[i]<<endl;
        }

    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 177116
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	sn := calc(n)

	if n%sn == 0 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func calc(n int) (sn int) {
	for n != 0 {
		sn += n % 10
		n /= 10
	}
	return sn
}


Measured memory_bytes: 512
from math import sin,cos,pi
N,L=map(int,input().split())
S=N*(N-1)*(N-2)/ 6
T=[int(input())*pi/L for _ in range(N)]
print(sum([sum([cos((T[i]+T[j]))*(N+2*(i-j)) for j in range(i+1, N)]) for i in range(N)])/S,sum([sum([sin((T[i]+T[j]))*(N+2*(i-j)) for j in range(i+1,N)]) for i in range(N)])/S)


Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;


int main(){

    int N,Q;

    cin >> N >> Q ;

    vector<int> values(N+1,0);
    vector<int> parents(N+1,0);

    int tmp_s, tmp_g;
    for(int i=1;i<=N-1;i++){
        cin >> tmp_s >> tmp_g;
        parents[tmp_g] = tmp_s;
    }

    int tmp, val;
    for(int i=1;i<=Q;i++){
        cin >> tmp >> val;
        values[tmp] += val;
    }

    for(int i=1;i<=N;i++){
        values[i] = values[parents[i]] + values[i];
    }

    for(int i=1;i<N;i++){
        cout << values[i] << ' ';
    }
    cout << values[N] << endl;

    return 0;
}


Measured memory_bytes: 3968
//
//  main.cpp
//  ABC088Bcardgamefortwo
//
//  Created by 岡本 朋大 on 2019/06/13.
//  Copyright © 2019年 岡本　朋大. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N ; i++) {
        a[i] = 0;
        cin >> a[i];
    }
    int can_change = 1;
    int res = 0;
    while(can_change > 0){
        can_change = 0;
        for(int i = 0; i < N-1; i ++){
            if(a[i] < a[i+1]) {
                res = a[i];
                a[i] = a[i+1];
                a[i+1] = res;
                can_change++;
            }
        }
    }
    int Asum = 0;
    int Bsum = 0;
    for (int i = 0;i < N; i++){
        if(i%2 == 0) Asum += a[i];
        else Bsum += a[i];
    }
    cout << Asum - Bsum << endl;
}



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

int main(){
  char a,b;
  cin >> a >> b;
  if(((a=='H')&&(b=='H'))||((a=='D')&&(b=='D'))){
    cout << 'H' << endl;
  }else{
    cout << 'D' << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n=int(input())
sum2=0
if(n==1):
    sum2=1
if(n==2):
    sum2=3
if(n>=3):
    sum2=3
    for i in range(3,n+1):
        if(i%3!=0 and i%5!=0):
            sum2=sum2+i
print(sum2)
    

Measured memory_bytes: 9180
//By : BebekJK
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//Declare -> ordered_set NAMA;
//Nth smallest integer -> find_by_order(N-1)
//Number of elements less than N -> order_of_key(N)
//Delete N from the set -> erase(N)

#define endl '\n'
#define MOD 1000000007
#define PI 3.141592653
#define fi first
#define sc second
#define pb push_back
#define pbb pop_back

//#pragma GCC optimize("Ofast")
//#pragma GCC target ("string"...)
//#pragma GCC push_options
//#pragma GCC pop_options
//#pragma GCC reset_options
//#pragma GCC optimize ("O3")

typedef long long ll;
typedef long double ld;
typedef pair<int , int> pii;
typedef pair<long long , long long> pll;

void BOOST(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
}
void fcin(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c=='-'){
		neg = true;
		c = getchar();
	}
	for(;(c>47 && c<58);c=getchar())x = (x<<1)+(x<<3)+c-48;
	if(neg)x*=-1;
}
ll pmod(ll a , ll b){
	if(b==0)return 1;
	ll temp = pmod(a , b/2);
	if(b%2==0)return(temp*temp)%MOD;
	return (((temp*temp)%MOD)*a)%MOD;
}
int R , C , K , Ans , Temp;
char grid[10][10];
bool check[10][10];
int main(){
//	BOOST();
	cin>>R>>C>>K;
	for(int i=1;i<=R;i++){
		for(int j=1;j<=C;j++){
			cin>>grid[i][j];
		}
	}
	for(int i=0;i<(1<<R);i++){
		for(int j=0;j<(1<<C);j++){
			Temp = 0;
			memset(check , false , sizeof check);
			for(int x=0;x<R;x++){
				if((i>>x)&1){
					for(int y=1;y<=C;y++){
						check[x+1][y] = true;
					}
				}
			}
			for(int x=0;x<C;x++){
				if((j>>x)&1){
					for(int y=1;y<=R;y++){
						check[y][x+1] = true;
					}
				}
			}
			for(int x=1;x<=R;x++){
				for(int y=1;y<=C;y++){
					if(!check[x][y] && grid[x][y]=='#')Temp++;
				}
			}
			if(Temp==K)Ans++;
		}
	}
	cout<<Ans<<endl;
}







Measured memory_bytes: 3588
import sys
input=sys.stdin.readline
from decimal import Decimal
from bisect import bisect
n,m=map(int,input().split())
lst=sorted(map(Decimal, input().split()))

while m>0:
    p=lst[-1]
    index=bisect(lst,p/2)
    for i in range(n-1,index-1,-1):
        if m>0:
            lst[i]=lst[i]/2
            m-=1
    lst=sorted(lst)
    if lst[-1]<1:
        break

ans=0
for i in lst:
    ans+=i//1
print(ans)

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

using namespace std;

int main(){
	string input, tmp = "qwertasdfgzxcvb";
	int hand[32], count;
	int i;
	
	while(1){
		cin >> input;
		
		if(input == "#")
			break;
		
		count = 0;
		for(i = 0; i < input.size(); i++){
			if(tmp.find(input[i]) != -1)
				hand[i] = 0;
			else
				hand[i] = 1;
		}
		for(i = 1; i < input.size(); i++)
			if(hand[i] != hand[i - 1])
				count++;
		
		cout << count << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#pragma GCC optimize("Os")
#pragma GCC target("avx2,fma")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("Os")
*/
 
#include <bits/stdc++.h>
//#include <windows.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
 
using namespace std;
 
    /*
const int MAX_MEM = 1e8;
int mpos=0;
char mem[MAX_MEM];
inline void * operator new(size_t n){
	char *res = mem + mpos;
	mpos += n;
	assert(mpos <= MAX_MEM);
	return (void *)res;
}
 
inline void operator delete(void *){}
    */

const int N = 2e3 + 123;
const ll mod = 1e9 + 7;

string s;
int cnt[5];

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

	for(int i = 0;i < (int)s.size();i++){
		if(s[i] == 'N'){
			cnt[1]++;
		}
		else if(s[i] == 'E'){
			cnt[2]++;	
		}
		else if(s[i] == 'S'){
			cnt[3]++;
		}
		else{
			cnt[4]++;
		}
	}

	if(max(cnt[1], cnt[3]) > 0 && min(cnt[1], cnt[3]) == 0){
		cout << "No";
	}
	else if(max(cnt[2], cnt[4]) > 0 && min(cnt[2], cnt[4]) == 0){
		cout << "No";
	}
	else{
		cout << "Yes";
	}

	return 0;
}

Measured memory_bytes: 256
from collections import Counter

# これは嘘解法です
def lie():
    S = input()
    T = input()

    s = Counter(S)
    t = Counter(T)

    a = sorted(list(s.values()))
    b = sorted(list(t.values()))

    print("Yes" if a == b else "No")


def main():
    S = input()
    T = input()

    # one-to-one correspondence
    s_to_t = {}
    t_to_s = {}

    for s, t in zip(S, T):
        if s not in s_to_t:
            s_to_t[s] = t
        else:
            if s_to_t[s] != t:
                print("No")
                exit()

        if t not in t_to_s:
            t_to_s[t] = s
        else:
            if t_to_s[t] != s:
                print("No")
                exit()

    print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3940
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

flag = False

for i in range(X + 1, Y + 1):
  if max(x) < i <= min(y):
    flag = True
    break

if flag:
  print("No War")
else:
  print("War")

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	k, _ := strconv.Atoi(stringLineScan())
	r := n - k
	a := make([]int, n+2)
	inv := make([]int, n+2)
	d := 1000000007
	a[0], inv[0] = 1, 1
	for i := 1; i <= n+1; i++ {
		a[i] = a[i-1] * i % d
		inv[i] = modinv(a[i], d)
	}
	for i := 1; i <= k; i++ {
		ans := 0
		if i == 1 && n == k {
			ans = 1
		}
		cb := a[k-1] * inv[i-1] % d * inv[k-i] % d
		if r-i-1 >= 0 {
			cr := a[r-1] * inv[i] % d * inv[r-i-1] % d
			ans += cb * cr % d
			ans %= d
		}
		if r-i >= 0 {
			cr := a[r-1] * inv[i-1] % d * inv[r-i] % d
			ans += cb * cr % d * 2
			ans %= d
		}
		if i > 1 && r-i+1 >= 0 {
			cr := a[r-1] * inv[i-2] % d * inv[r-i+1] % d
			ans += cb * cr % d
			ans %= d
		}
		fmt.Println(ans)
	}
}
func modinv(a, m int) int {
	b, u, v := m, 1, 0
	for {
		t := a / b
		a -= t * b
		u -= t * v
		a, b, u, v = b, a, v, u
		if b == 0 {
			break
		}
	}
	u %= m
	if u < 0 {
		u += m
	}
	return u
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  string A,s,C;
  cin >> A >> s >> C;
  cout << A.at(0) << s.at(0) << C.at(0) << endl;

  return 0;
}


Measured memory_bytes: 256
N,*D = `dd`.split.map &:to_i

nums = Hash[(0..12).map{ |d| [d,0] }]
nums[0] = 1
D.each{ |d| nums[d] += 1 }
if nums[0] >= 2 || nums[12] >= 12 || (1..11).any?{ |d| nums[d] >= 3 }
  p 0; exit
end

def dig(d, nums)
  return [1 + (1 << 24)] if d == 13
  
  v = dig(d+1,nums)
  n = nums[d]
  v.map{ |x|
    a = (1 << d); b = (1 << (24-d))
    case n
    when 2; [x | a | b]
    when 1; [x | a, x | b]
    else    [x]
    end
  }.flatten
end

p dig(0, nums).map{ |n|
  n.to_s(2).scan(/(?<=1)0*(?=1)/).map{ |d| d.size+1 }.min || 0
}.max


Measured memory_bytes: 4092
n, m = map(int, input().split())
x = [0]*m
y = [0]*m

for i in range(m):
    x[i], y[i] = map(str, input().split())

#print(x)
#print(y)

ans_ac = [0]*n
ans_wa = [0]*n
ac = 0
wa = 0


for i in range(m):
    a = int(x[i])-1
    #print(a, y[i])
    if y[i] == "WA":
        ans_wa[a] += 1
    if y[i] == "AC" and ans_ac[a] == 0:
        ac += 1
        ans_ac[a] = 1
        wa += ans_wa[a]
#print(ans_wa)
print(ac, wa)




Measured memory_bytes: 17232
import java.util.*;
 
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		PriorityQueue<Long> pq = new PriorityQueue<>();
		for(int i=0; i<n; i++){
			pq.add(sc.nextLong()); 
		}
		Map<Long, Integer> map = new TreeMap<>(Comparator.reverseOrder());
		for(int i=0; i<m; i++){
			int b = sc.nextInt();
			long c = sc.nextLong();
			Integer tmp = map.get(c);
			if(map.get(c) == null){
				map.put(c, b);
			} else {
				map.put(c, b+tmp);
			}
		}
		for (Map.Entry<Long, Integer> kv : map.entrySet()) {
			Long key = kv.getKey();
			Integer count = kv.getValue();
			for(int i=0; i<count; i++){
				Long target = pq.poll();
				if(target<key){
					pq.add(key);
				} else {
					pq.add(target);
					break;
				}
			}
		}
		long ans = 0;
		while(pq.size() > 0){
			ans += pq.poll();
		}
		System.out.println(ans);
	}
}


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

/// Defining variable types.
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

/// Defining usable key words
#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

/// Defining constant variables.
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

/// Defining some useful lines.
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);


/// Code of debugger.
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}


int main()
{
    optimize();

    string s;
    cin>>s;

    if(s[0]!=s[1] || s[1]!=s[2] ||s[2]!=s[0] )
        cout<<"Yes";

    else
        cout<<"No";










    return 0;
}


Measured memory_bytes: 256
v,e=[int(j) for j in input().split()]
d=[[10**18]*v for i in range(v)]
dp=[[-1]*v for i in range(1<<v)]
for i in range(e):
    s,t,w=[int(j) for j in input().split()]
    d[s][t]=w


def f(s,n,dp):
    if dp[s][n]>=0:
        return dp[s][n]
    if s==(1<<v)-1 and n==0:
        dp[s][n]=0
        return 0
    tmp=10**18
    for u in range(v):
        if (s>>u&1)==0:
            tmp=min(tmp,f(s|(1<<u),u,dp)+d[n][u])
    dp[s][n]=tmp
    return tmp

ans=f(0,0,dp)
if ans==10**18:
    print(-1)
else:
    print(ans)



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

using namespace std;

int main(void)
{
        string str;

        for( int i = 0; i < 3; i++ )
        {
                cin >> str;
                cout << (char) (str.c_str()[0] - 'a' + 'A');
        }

        cout << endl;

        return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) std::cerr<< #x <<": "<<x<<"\n"
#define debug2(x,y) std::cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<"\n"
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

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

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

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 1;
  if (n % k == 0) {
    ans = 0;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 888
import sys
import heapq
INF=10**9
def Dijkstra(graph, start):
  dist={}
  for i in graph:
    dist[i]=INF
  queue=[(0, start)]
  while queue:
    path_len, v=heapq.heappop(queue)
    if dist[v]==INF: 
      dist[v]=path_len
      for w in graph[v]:
        if dist[w]==INF:
          heapq.heappush(queue, (dist[v]+1, w))         
  return dist
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

h,w=map(int,input().split())
ch,cw=map(int,input().split())
dh,dw=map(int,input().split())
m=[]
for i in range(h):
  s=input()
  m.append(s)
uf=UnionFind(h*w)
for i in range(h):
  for j in range(w):
    if j+1<w and m[i][j]=='.' and m[i][j+1]=='.':
      uf.union(i+h*j,i+h*(j+1))
    if i+1<h and m[i][j]=='.' and m[i+1][j]=='.':
      uf.union(i+h*j,i+1+h*j)
if uf.same((ch-1)+(cw-1)*h,(dh-1)+(dw-1)*h):
  print(0)
  sys.exit()
graph={}
for i in uf.roots():
  graph[i]=set()
for i in range(h):
  for j in range(w):
    if m[i][j]!='.':
      continue
    for k in range(-2,3):
      for l in range(3):
        if i+k<0 or i+k>=h or j+l>=w:
          continue
        if m[i+k][j+l]!='.' or uf.same(i+k+(j+l)*h,i+j*h):
          continue
        graph[uf.find(i+k+(j+l)*h)].add(uf.find(i+j*h))
        graph[uf.find(i+j*h)].add(uf.find(i+k+(j+l)*h))
dist=Dijkstra(graph,uf.find(ch-1+(cw-1)*h))
if dist[uf.find(dh-1+(dw-1)*h)]==INF:
  print(-1)
else:
  print(dist[uf.find(dh-1+(dw-1)*h)])

Measured memory_bytes: 284376
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i, N) cin >> L[i];

  int answer = 0;
  for (int i = 0; i < N - 2; ++i) {
    for (int j = i + 1; j < N - 1; ++j) {
      if (L[i] == L[j]) continue;
      for (int k = j + 1; k < N; ++k) {
        if (L[i] == L[k] || L[j] == L[k]) continue;
        if (L[i] > L[j] && L[i] > L[k]) {
          if ((L[j] + L[k]) > L[i]) answer++;
        }
        if (L[j] > L[i] && L[j] > L[k]) {
          if ((L[i] + L[k]) > L[j]) answer++;
        }
        if (L[k] > L[j] && L[k] > L[i]) {
          if ((L[i] + L[j]) > L[k]) answer++;
        }
      }
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int a,b;
    cin >> a >> b;
    if(a==b){
        cout << 0 << endl;
    }else if((a+b)%2==0){
        cout << (a+b)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}


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

const int N = 100000;
int main() {
  int count[N + 1];
  for (int i = 0; i <= N; ++i) count[i] = i;
  for (int i = 0; i <= N; ++i) {
    for (int a = 1; i + a <= N; a *= 6) count[i + a] = std::min(count[i + a], count[i] + 1);
    for (int a = 1; i + a <= N; a *= 9) count[i + a] = std::min(count[i + a], count[i] + 1);
  }
  int n;
  std::cin >> n;
  std::cout << count[n] << std::endl;
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int max=0;
        int min=Integer.MAX_VALUE;
        int[] arr=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=s.nextInt();
            max=Math.max(arr[i],max);
            min=Math.min(min,arr[i]);
        }
        int total=0;
        int ans=Integer.MAX_VALUE;
        for(int i=min;i<=max;i++){
            total=0;
            for(int j=0;j<n;j++){
                total=total+(int)Math.pow(arr[j]-i,2);
            }
          ans=Math.min(total,ans);
        }
        System.out.println(ans);

    }
}


Measured memory_bytes: 21204
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;
long long n,r=1;
string a,b;
int main() {
    cin >> n >> a >> b;
    if(n==1){
        cout << 3;
        return 0;
    }
    long long i=0;
    if(a[0]==b[0]){
        r=(long long)3;
        i=1;
    }else{
        r=(long long)6;
        i=2;
    }
    while(i<n){
       if(a[i]==b[i]){
            if(a[i-1]==b[i-1]){
                r*=(long long)2;
            }
            i++;
       }else{
            if(a[i-1]==b[i-1]){
                r*=(long long)2;
            }else{
                r*=(long long)3;
            }
            i+=2;
       }
        r=r%(long long)(1e9+7);
    }
    cout << r;
    return 0;
}


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

const int MOD=1000000007;
vector<int> list1[2020];
int dp[2020][2020], dp1[2020][2020];

int main(){
    int N, M; cin >> N >> M;
    int S[2020], T[2020];
    for(int i=0; i<N; i++){
        cin >> S[i];
    }   
    for(int j=0; j<M; j++){
        cin >> T[j];
    }

    //前処理
    for(int j=0; j<M; j++){
        for(int i=0; i<N; i++){
            if(T[j]==S[i]) list1[j].push_back(i);
        }
    }

    //計算
    for(int i=0; i<=N; i++) dp[i][0]=1;
    for(int j=0; j<=M; j++) dp[0][j]=1;

    for(int i=1; i<=N; i++){
        dp1[i][0]=0;
        for(int j=1; j<=M; j++){
            dp1[i][j]=dp1[i][j-1];
            if(T[j-1]==S[i-1]) {dp1[i][j] +=dp[i-1][j-1]; dp1[i][j]%=MOD;}
        }
        for(int j=1; j<=M; j++){
            dp[i][j]=dp[i-1][j] + dp1[i][j] ;
            dp[i][j] %=MOD;
//            if(list1[j-1].size()==0) continue;
//            auto x = upper_bound(list1[j-1].begin(), list1[j-1].end(), i-1 );
//            if(x==list1[j-1].begin()) continue;
//            int k = *(x-1);
//            dp[i][j]+= dp[k][j-1] ;
//            if(x-list1[j-1].begin() >1 ) dp[i][j]+= (x-1-list1[j-1].begin());
 //           dp[i][j] %=MOD;
        }
    }


    cout << dp[N][M] << endl;
}

Measured memory_bytes: 47616
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
string alph("abcdefghijklmnopqrstuvwxyz");
signed main(){
    int n;cin>>n;
    int num[114514];
    rep(i,0,n){
        cin>>num[i];
    }
    sort(num,num+n);
    bool key=true;
    rep(i,0,n){
        if(n%2){
            if(!i){if(num[i]!=0)key=false;}
            else if(num[i]!=(i+1)/2*2)key=false;
        }
        else {
            if(num[i]!=(i/2*2)+1)key=false;
        }
    }
    if(!key){
        cout<<0<<endl;
    }
    else {
        int count=1;
        rep(i,0,n/2){
            count*=2;
            count%=inf;
        }
        cout<<count<<endl;
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  long long ht=0;
  bool jg=false;
  int num;
  vector<long long> x(110);
  vector<long long> y(110);
  vector<long long> h(110);
  for(int i=0;i<N;i++){
    cin >> x[i] >> y[i]  >> h[i];
  }


  for(int nx=0;nx<=100;nx++) {
    for(int ny=0;ny<=100;ny++) {
      num=1,ht=0;

      for(int i=0;i<N;i++) {
        jg=true;
        //cout << ht << " " << (int)(ht-fabs(x[i]-nx)-fabs(y[i]-ny)) << endl;
        if(h[i]!=0 /*&& num==1*/) {
          ht=h[i]+fabs(x[i]-nx)+fabs(y[i]-ny);
          //num--;
          break;
        }
      }
      for(int l=0;l<N;l++){
        if(ht!=0){
          if(h[l]!=max((int)(ht-fabs(x[l]-nx)-fabs(y[l]-ny)),0)) {
            jg=false;
            break;
          }
        }
      }
      if(jg){
        cout << nx << " " << ny << " " << ht << endl;
        return 0;
      }
    }
  }
}

        

        


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>

std::string str[128][128];
char field[128][128];
int W, H;

void Load() {
  scanf("%d %d", &W, &H);
  for(int i = 0; i < H; ++i) {
    scanf("%s", field[i]);
  }
}

void init() {
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      str[i][j].clear();
    }
  }
}
std::string& greater(std::string& a, std::string& b) {
  if( a.size() != b.size() ) {
    if( a.size() < b.size() ) return b;
    else return a;
  }
  if( a < b ) {
    return b;
  }
  return a;
}

void solve() {
  for(int r = 0; r < H; ++r) {
    for(int c = 0; c < W; ++c) {
      if( not ( '0' <= field[r][c] and field[r][c] <= '9' ) ) continue;
      std::string t1;
      std::string t2;
      if( 0 <= c - 1 ) {
        t1 = str[r][c-1];
      }
      if( 0 <= r - 1 ) {
        t2 = str[r-1][c];
      }
      std::string t = greater(t1, t2);
      if( t.size() == 0 and field[r][c] == '0' ) continue;
      str[r][c] = greater(t1, t2) + field[r][c];
    }
  }
}

int main() {
  for(;;) {
    init();
    Load();
    if( W == 0 and H == 0 ) break;
    solve();
    std::string ans;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        ans = greater(ans, str[i][j]);
      }
    }
    if( ans.empty() ) {
      std::cout << 0 << std::endl;
    }
    std::cout << ans << std::endl;
  }  
  
  return 0;
}

Measured memory_bytes: 3500
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <stack>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int N;
int a[200010];

int main() {
    cin >> N;
    for (int j = 0; j < N; ++j) {
        cin >> a[j];
    }

    stack<int> s;

    int cnt = 1;

    s.push(0);
    s.push(a[0]);
    for (int j = 1; j < N; ++j) {
        int t = s.top();
        while (t > a[j]) {
            s.pop();
            t = s.top();
        }
        if (t < a[j]) {
            ++cnt;
            s.push(a[j]);
        }
    }

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

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

void swap(unsigned int *a, unsigned int *b){
	if(*a != *b){
		*a ^= *b;
		*b ^= *a;
		*a ^= *b;
	}
}

int main(){
	unsigned int a, b, cnt;
	
	while(cin >> a >> b, a){
		if(a < b) swap(&a, &b);
		cnt = 0;
		while(b != 0){
			a = a % b;
			swap(&a, &b);
			++cnt;
		}
		cout << a << " " << cnt << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1152