akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

class Combination{
    public:
        int N;
        vector<vector<long long>> cmb;
        Combination(int n):N(n),cmb(n,vector<long long>(n,0)){
            for(int i=0;i<N;i++){
                cmb[i][0]=1;
                for(int j=1;j<=i;j++) cmb[i][j]=cmb[i-1][j-1]+cmb[i-1][j];
            }
        }

        long long operator()(int i,int j) const{
            return cmb[i][j];
        }
};

int main(){
    int N,A,B; cin >> N >> A >> B;
    vector<ll> v(N); rep(i,N) cin >> v[i];
    sort(all(v));
    reverse(all(v));

    ll sum = 0;
    for(int i=0;i<A;i++) sum += v[i];
    cout << Double(sum/(double)A) << endl;

    ll num = v[A-1];
    map<ll,ll> mp;
    rep(i,N) mp[v[i]]++;

    ll cnt = 0;
    rep(i,A) if(v[i] == num) cnt++;

    // mp[num] C cnt
    Combination cmb(100);
    ll ans = 0;

    if(v[0] != num){
        ans = cmb(mp[num],cnt);
    }else{
        for(int i=A;i<=B;i++){
            int ii = cnt + i - A;
            if(mp[num] >= ii){
                ans += cmb(mp[num],ii);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){
	int N,Y,f=0;
	cin>>N>>Y;
	for(int x=0;x<=N;x++){
		for(int y=0;y<=N;y++){
			int z=N-(x+y);
			if(x+y+z==N&&10000*x+y*5000+z*1000==Y&&x>=0&&y>=0&&z>=0){
				cout<<x<<" "<<y<<" "<<z<<endl;
				f=1;
				break;
			}
		}
		if(f==1){
			break;
		}
		if(x==N){
			cout<<-1<<" "<<-1<<" "<<-1<<endl;
		}
	}
	
}

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

using namespace std;

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  
  int dist_a = abs(x - a);
  int dist_b = abs(x - b);

  if (dist_a < dist_b) cout << 'A' << endl;
  else cout << 'B' << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
    #include <stdio.h>
    using namespace std;
     
    const int MAXN = 2e5 + 10;
    int a[MAXN], vis[MAXN];
     
    int main(void){
        int n, m, cnt = 0;
        scanf("%d%d", &n, &m);
        for(int i = 0; i < m; i++){
            int x, y;
            scanf("%d%d", &x, &y);
            if(x == 1) a[cnt++] = y;
            if(y == 1) a[cnt++] = x;
            if(x == n) vis[y] = 1;
            if(y == n) vis[x] = 1;
        }
        for(int i = 0; i < cnt; i++){
            if(vis[a[i]]){
                puts("POSSIBLE");
                return 0;
            }
        }
        puts("IMPOSSIBLE");
        return 0;
    }

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main (){
    int ans=0,sum=0;
    vector<int> v(3);
    cin >> v.at(0) >> v.at(1) >> v.at(2);
    sort(v.begin(),v.end());//A<=B<=C

    sum += v.at(0)+v.at(1)+v.at(2);
    
    //A+B+Cと3Cの偶奇が一致→全てv.at(2)に
    if(sum%2 == v.at(2)%2){
        ans += (3*v.at(2)-sum)/2;
    }
    else{//全てv.at(2)+1に
        ans += (3*v.at(2)+3-sum)/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <map>
#include <vector>
#include <tuple>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

void debug_out() {};
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

struct C1 {
    ll N_{};
    vector<ll> v_{};
    explicit C1(vector<ll> v) : N_(v.size()), v_(move(v)){}
    vector<ll> resolve() {
        map<ll, ll> m{};
        for(ll i=0; i < N_; ++i) {
            m.emplace(make_pair(v_[i], i));
        }
        vector<ll> ans{};
        ans.reserve(N_);
        for(auto p : m) {
            ans.emplace_back(p.second + 1);
        }
        return ans;
    }
};

int main() {
    ll N;
    cin >> N ;
    vector<ll> v{};
    for (int i=0; i < N; ++i) {
        ll x;
        cin >> x;
        v.emplace_back(x);
    }
    C1 c{move(v)};
    auto&& ans = c.resolve();
    for(auto x : ans) {
        cout << x << " ";
    }
    cout << endl;
    return 0;
}


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

bool so[10001];

int main (){
  so[0]=1;
  so[1]=1;
  for(int i=2;i*i<10001;i++){
    if(so[i]==0){
      for(int j=2;i*j<=10001;j++)
	so[i*j]=1;
    }
  }
  int n;
  while(cin>>n){
    int co=0;
    for(int i=1;i<=n;i++)
      if(so[i]==0 && so[n-i+1]==0) co++;
    cout<<co<<endl;
  }
  return 0;
}

Measured memory_bytes: 1168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        public static bool[] hash = new bool[(int)Math.Pow(5, 11)];
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                ope(s);
            }
        }

        public static void ope(string[] s)
        {
            ulong tmp = gethashnum(s[1]);
            switch (s[0])
            {
                case "insert":
                    hash [tmp] = true;
                    break;
                case "find":
                    Console.WriteLine(hash[tmp] == true?"yes":"no");
                    break;
            }
        }

        public static ulong gethashnum(string s)
        {
            ulong tmp = 0;
            ulong p = 1;
            for (int i = 0; i < s.Length; i++)
            {
                switch (s[i])
                {
                    case 'A':
                        tmp += p * 1;
                        break;
                    case 'C':
                        tmp += p * 2;
                        break;
                    case 'G':
                        tmp += p * 3;
                        break;
                    case 'T':
                        tmp += p * 4;
                        break;
                }
                p *= 5;
            }
            return tmp;
        }
    }
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define repm(i,m,n) for(ll i=m;i<n;i++)
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define YesNo(a) (a)?cout<<"Yes"<<endl:cout<<"No"<<endl
#define YESNO(a) (a)?cout<<"YES"<<endl:cout<<"NO"<<endl
#define INF (2e9)
#define PI (acos(-1))
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007

typedef long long ll;

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

    int ans;
    if(s == "SSS") ans = 0;
    else if(s == "RRR") ans = 3;
    else if(s == "RRS" || s == "SRR") ans = 2;
    else ans = 1;

    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>

using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> b = a;
    sort(b.begin(), b.end());

    for (int i = 0; i < n; i++) {
        if(b[n-1] == a[i]) cout << b[n-2] << endl;
        else cout << b[n-1] << endl;
    }
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;

    map<string, ll> mp;
    rep(i, N) {
        string s;
        cin >> s;
        sort(all(s));
        mp[s]++;
    }

    ll ans = 0;
    for (auto itr : mp) {
        ans += (itr.second * (itr.second - 1)) / 2;
    }

    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll h,w;
  cin>>h>>w;
  ll ans=0;

  if(h==1 || w==1){
    ans=1;
    cout<<ans<<endl;
    return 0;
  }


  ll r1=(w+1)/2;
  ll r2 = w/2;
  ans = (h+1)/2*r1 + h/2*r2;
  cout<<ans<<endl;
}



Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::collections::HashSet;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn pow_mod(base: i64, power: i64, modulo: i64) -> i64 {
    let mut base = base;
    let mut power = power;
    let mut ans = 1;
    while power > 0 {
        if power & 1 == 1 {
            ans = ans * base % modulo;
        }
        power >>= 1;
        base = base * base % modulo;
    }
    ans
}

const MOD: i64 = 998244353;
struct Solver {
    s: Vec<usize>,
}

impl Solver {
    fn new() -> Solver {
        let s = read::<String>()
            .chars()
            .map(|v| v as usize - 'a' as usize)
            .collect::<Vec<usize>>();
        Solver { s: s }
    }
    fn solve(&mut self) -> i64 {
        let n = self.s.len();
        let mut ans = 0;
        if n < 6 {
            let mut visit = HashSet::<Vec<usize>>::new();
            let mut que = vec![self.s.clone()];
            visit.insert(self.s.clone());
            while let Some(s) = que.pop() {
                for i in 0..n - 1 {
                    if s[i] != s[i + 1] {
                        let mut ns = s.clone();
                        let nc = match s[i] + s[i + 1] {
                            1 => 2,
                            2 => 1,
                            3 => 0,
                            _ => 9999,
                        };
                        ns[i] = nc;
                        ns[i + 1] = nc;
                        if visit.contains(&ns) {
                            continue;
                        }
                        visit.insert(ns.clone());
                        que.push(ns);
                    }
                }
            }
            return visit.len() as i64;
        }
        let mut cnts = vec![0, 0, 0];
        let mut cont_seq = false;
        for i in 0..n {
            cnts[self.s[i]] += 1;
            if i != n - 1 && self.s[i] == self.s[i + 1] {
                cont_seq = true;
            }
        }
        if cnts[0] == n || cnts[1] == n || cnts[2] == n {
            return 1;
        }
        if !cont_seq {
            ans += 1;
        }
        ans = (ans + pow_mod(3, n as i64 - 1, MOD)) % MOD;
        ans = (ans - pow_mod(2, n as i64 - 1, MOD) + MOD) % MOD;
        if n % 3 == 0 {
            cnts[0] %= 3;
            cnts[1] %= 3;
            cnts[2] %= 3;
            cnts.sort();
            if cnts[0] == 0 && cnts[1] == 1 {
                ans = (ans + pow_mod(2, n as i64 / 3 - 1, MOD)) % MOD;
            } else {
                ans = (ans - pow_mod(2, n as i64 / 3, MOD) + MOD) % MOD;
            }
        }
        ans
    }
}

fn main() {
    let mut solver = Solver::new();
    let ans = solver.solve();
    println!("{}", ans);
}


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

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

    vector<bool> num(1000001);
    vector<bool> checker(1000001);
    for(int i = 0; i < n; ++i)
    {
        if(num[a[i]])
        {
            checker[a[i]] = true;
            continue;
        }
        for(int j = 1; j * a[i] <= 1000001; ++j)
        {
            num[j*a[i]] = true;
        }
    }

    int ans = 0;
    for(int i = 0; i < n; ++i)
    {
        if(checker[a[i]])
        {
            continue;
        }
        ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4316
#include <bits/stdc++.h>
using namespace std;
   
int main() {
    map<int,int> num;
   int n,k;
   cin>>n>>k;
   for(int i=0;i<k;i++){
       int x;
       cin>>x;
       vector<int> y(x);
       for(int j=0;j<x;j++) cin>>y.at(j);
       for(int p=0;p<x;p++){
           num[y.at(p)]++;
       }
   }
   cout<<n-num.size();
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
using namespace std;
int main(){
   int N;
   cin>>N;
   string S=to_string(N);
  if(S[0]==S[1] && S[1]==S[2]){
    cout<<S<<endl;
  }else{
    for(int i = N ;i<=999 ;i++ ){
      string strN=to_string(i);
      if(strN[0]==strN[1] && strN[1]==strN[2]){
        cout<<strN<<endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 300000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------
V<ll>m[11];
ll color[100];
//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    ll n;cin>>n;
    ll k;cin>>k;
    ll cnt=0;
    for(int bit=0;bit < (1<<n); bit++)
    {
        //
        V<ll>output;
        for(ll j=0;j<n;j++){
            if(bit&(1<<j))output.pb(j);
        }
        if(output.size()==k){
            cout<<bit<<":";
            for(ll i=0;i<output.size();i++){
                cout<<" "<<output[i];
            }
            cout<<endl;
        }
        
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































Measured memory_bytes: 3196
n = STDIN.gets.chomp.to_i
a = STDIN.gets.chomp.split(" ").map{|x| x.to_i}

cur = a[0]
sum = 1
for i in 1..(n-1) do
  if a[i] >= cur
    sum += 1
    cur = a[i]
  end
end

puts sum

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

const int maxn = 300010;
int n;
long long pre[maxn], suf[maxn], a[maxn];
multiset<int> S;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n * 3; i++) {
        scanf("%d", &a[i]);
    }
    long long sum = 0;
    for (int i = 1; i <= n; i++) {
        S.insert(a[i]), sum += a[i];
    }
    pre[n] = sum;
    for (int i = n + 1; i <= 3 * n; i++) {
        if (a[i] > *S.begin()) {
            sum -= *S.begin();
            S.erase(S.begin());
            S.insert(a[i]), sum += a[i];
        }
        pre[i] = sum;
    }
    S.clear(), sum = 0;
    for (int i = 3 * n; i > 2 * n; i--) {
        S.insert(a[i]), sum += a[i];
    }
    suf[2 * n + 1] = sum;
    for (int i = 2 * n; i; i--) {
        if (a[i] < *S.rbegin()) {
            sum -= *S.rbegin();
            S.erase(--S.end());
            S.insert(a[i]), sum += a[i];
        }
        suf[i] = sum;
    }
    long long ans = -1e18;
    for (int i = n; i <= 2 * n; i++) {
        ans = max(ans, pre[i] - suf[i + 1]);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 11904
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <set>

#define PI 3.1415926535897

typedef long long ll;

using namespace std;



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

    bool flag = false;

    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            flag = true;
            break;
        }
    }
    if (flag) {
        cout << "OK";
    }
    else {
        cout << "NG";
    }
    return 0;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
N = int(input())
a = []
l = [i for i in range(N)]
r = [i for i in range(N)]
for i in range(N):
  x, y = map(int, input().split())
  a.append((x, y))
l.sort(key = lambda x: -a[x][1])
r.sort(key = lambda x: a[x][0])
#print(l, r)
res = 0
vis = [0] * N
x = 0
for i in range(N):
  #print(l, r, vis, x, res)
  if i % 2 == 1 and (len(l) > 0):
    t = l[-1]
    y = a[l.pop()][1]
    while vis[t]:
      t = l.pop()
      y = a[t][1]
      vis[t] = 1
      if len(l) == 0: break
    vis[t] = 1
    if not x in range(a[t][0], a[t][1]):
      res += x - min(x, y)
      x = min(x, y)
  elif i % 2 == 0 and (len(r) > 0):
    t = r[-1]
    y = a[r.pop()][0]
    while vis[t]:
      t = r.pop()
      y = a[t][0]
      vis[t] = 1
      if len(r) == 0: break
    vis[t] = 1
    if not x in range(a[t][0], a[t][1]):
      res += max(x, y) - x
      x = max(x, y)
res += abs(x)
#print(res)
rres = 0
l = [i for i in range(N)]
r = [i for i in range(N)]
l.sort(key = lambda x: -a[x][1])
r.sort(key = lambda x: a[x][0])
vis = [0] * N
x = 0
for i in range(N):
  #print(l, r, vis, x, rres)
  if i % 2 == 0 and (len(l) > 0):
    t = l[-1]
    y = a[l.pop()][1]
    while vis[t]:
      t = l.pop()
      y = a[t][1]
      vis[t] = 1
      if len(l) == 0: break
    vis[t] = 1
    if not x in range(a[t][0], a[t][1]):
      rres += x - min(x, y)
      x = min(x, y)
  elif i % 2 == 1 and (len(r) > 0):
    t = r[-1]
    y = a[r.pop()][0]
    while vis[t]:
      t = r.pop()
      y = a[t][0]
      vis[t] = 1
      if len(r) == 0: break
    vis[t] = 1
    if not x in range(a[t][0], a[t][1]):
      rres += max(x, y) - x
      x = max(x, y)
rres += abs(x)
print(max(res, rres))

Measured memory_bytes: 113848
# coding: utf-8
# Your code here!
N = int(input())
p = [list(map(lambda x:int(x)-1,input().split())) for i in range(N-1)]
c = list(map(int,input().split()))

def dfs(v,gen,node):
    Stack = []
    visit[v] = True
    Stack.append(v)
    while Stack:
        v = Stack.pop()
        node[v] = gen.__next__()
        for i in nextl[v]:
            if not visit[i]:
                visit[i] = True
                Stack.append(i)

def list2gen(l):
    for e in l:
        yield e

node = [0]*N
visit = [False]*N
nextl = [[] for i in range(N)]
for a, b in p:
    nextl[a].append(b)
    nextl[b].append(a)
c.sort(reverse=True)
gen = list2gen(c)
dfs(0,gen,node)
anssum = sum(c[1:])
print(anssum)
for e in node:
    print(e,end=" ")






Measured memory_bytes: 7152
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int r1,r2,c1,c2;
const int maxN=1e6,M=1e9+7;
ll iv[3*maxN],f1[3*maxN],f2[3*maxN];
 
ll nck(int n,int k){
  return f1[n]*f2[k]%M*f2[n-k]%M;
}
 
int main(){
  iv[1]=1;
  for(int i=2;i<3*maxN;i++)
    	iv[i]=M-M/i*iv[M%i]%M;
  f1[0]=f2[0]=1;
  for(int i=1;i<3*maxN;i++){
    f1[i]=f1[i-1]*i%M;
    f2[i]=f2[i-1]*iv[i]%M;
  }
  cin>>r1>>c1>>r2>>c2; 
  cout<<((nck(r2+c2+2,c2+1)-nck(r1+c2+1,c2+1)-nck(r2+c1+1,c1)+nck(r1+c1,c1)%M+M)%M);
  return 0;
}

Measured memory_bytes: 70528
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    ll N,A[100007],K,M,ma=0,T=0;
    cin >> N >> K;
    rep(i,N){
        cin >> A[i];
        ma=max(A[i],ma);
        if(i==0){
            M=A[0];
        }
        if(A[i]==K){
            cout << "POSSIBLE" << endl;
            return 0;
        }
        if(i>0){
            if(A[i]!=A[i-1]){
                M=gcd(abs(A[i]-A[i-1]),M);
                T=1;
            }
        }
        else if(T==1 && A[i]!=A[i-1]){
            M=gcd(abs(A[i]-A[i-1]),M);
        }
        else if(T==1 && A[i]==A[i-1]){
            M=gcd(abs(A[i]),M);
        }
    }
    if(K>ma){
        cout << "IMPOSSIBLE" << endl;
    }
    else if(T==0){
        if(A[0]==K){
            cout << "POSSIBLE" << endl;
        }
        else{
            cout << "IMPOSSIBLE" << endl;
        }
    }
    else{
        if((ma-K)%M==0){
            cout << "POSSIBLE" << endl;
        }
        else{
            cout << "IMPOSSIBLE" << endl;
        }
    }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 998244353
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=51 ;
int main()
{
   fast ;
   ll tests=1 ;
   //cin>>tests ;
   for(ll testcase=1;testcase<=tests;testcase++)
   {
     ///cout<<"Case #"<<testcase<<": " ;
     ///Read ,Think and Test Properly,then code
     ll h,w,k ;
     cin>>h>>w>>k ;
     char r[h+1][w+1] ;
     for(ll i=0;i<h;i++)
     {
         for(ll j=0;j<w;j++)
            cin>>r[i][j] ;

     }
     ll ans=INT_MAX ;
     for(ll mask=0;mask<(1<<(h-1));mask++)
     {
         vector<ll>pt ;
         ll cur=0 ;
         for(ll i=0;i<h;i++)
         {
             ll bit=mask&(1<<i) ;
             if(bit!=0)
             {
                 pt.pb(i) ;
             }
         }
         vector<ll>tot(pt.size()+1,0) ;
         ll cnt=0 ;
         cur+=pt.size() ;
         for(ll j=0;j<w;j++)
         {
             ll i=0 ;
             cnt=0 ;
             ll in=0 ;
             vector<ll>temp(pt.size()+1,0) ;
             while(i<h)
             {
                 if(r[i][j]=='1')
                 {
                     cnt++ ;
                 }

                 if(in<pt.size())
                 {
                     if(pt[in]==i)
                     {
                         temp[in]=cnt ;
                         in++ ;
                         cnt=0 ;
                     }
                 }
                 i++ ;


             }
             temp[in]=cnt ;
             ll f=1 ;
             for(ll i=0;i<=pt.size();i++)
             {
                 if(temp[i]>k)
                 {
                     f=-1 ;
                     break ;
                 }
                 if(temp[i]+tot[i]>k)
                 {
                     f=0 ;
                     break ;
                 }
             }
             if(f==-1)
             {
                 cur=INT_MAX ;
             }
             else if(f==1)
             {
                 for(ll i=0;i<=pt.size();i++)
                 {
                     tot[i]+=temp[i] ;
                 }
             }
             else
             {
                 cur++ ;
                 for(ll i=0;i<=pt.size();i++)
                 {
                     tot[i]=temp[i] ;
                 }

             }


         }
       //  cout<<mask<<" "<<cur<<endl ;
         ans=min(ans,cur) ;
     }

     cout<<ans ;



   }
}


Measured memory_bytes: 384
K = int(input())


def check(lst):
    for i in range(K):
        maxv = max(lst)
        if maxv <= N - 1:
            return False
        flg = False
        for j in range(N):
            if lst[j] == maxv and not flg:
                lst[j] -= N
                flg = True
            else:
                lst[j] += 1

    for i in range(N):
        if lst[i] >= N:
            return False
    return True



N = 50
mod = K % N
ans = []
for i in range(N):
    if i < mod:
        ans.append(N - i)
    else:
        ans.append(N - mod - 1)

for i in range(N):
    if i < mod:
        ans[i] = ans[i] + K // N + 1
    else:
        ans[i] = ans[i] + K // N
print(N)
print(" ".join(map(str, ans)))


Measured memory_bytes: 3064
#D
N = int(input())
A = list(map(int,input().split()))

A.sort()

sc = 0
sc += A.pop(-1)

c=0
for i in range(10**6):
    if c>=N-2:
        break
    p=A.pop(-1)
    sc+=p
    c+=1
    if c>=N-2:
        break
    sc+=p
    c+=1
        
print(sc)

Measured memory_bytes: 31764
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    ll small_sum=0,large_sum=0;
    ll base=0;
    priority_queue<ll> pq_small;//大きい順に取り出す
    priority_queue<ll,vl,greater<ll>> pq_large;
    rep(i,N){
        int q;
        cin >> q;
        if(q==1){
            ll a,b;
            cin >> a >> b;
            base+=b;
            if(pq_small.size()==0){
                small_sum+=a;
                pq_small.push(a);
            }
            else{
                pq_small.push(a);
                small_sum+=a;
                ll k;
                while(pq_small.size()-1>pq_large.size()){
                    k=pq_small.top();
                    pq_small.pop();
                    pq_large.push(k);
                    small_sum-=k;
                    large_sum+=k;
                }
                while(pq_large.top()<pq_small.top()){
                    ll s=pq_large.top(),t=pq_small.top();
                    pq_large.pop();pq_small.pop();
                    pq_large.push(t);pq_small.push(s);
                    small_sum+=s-t;large_sum+=t-s;
                }
            }
        }
        if(q==2){
            ll s=pq_small.top();
            cout << s << " " << base+(s*(ll)pq_small.size()-small_sum)+(large_sum-s*(ll)pq_large.size()) << endl;
        }
    }
}

Measured memory_bytes: 5116
import java.math.*;
import java.io.*;
import java.util.*;

public class Main {

	public static int func(int arr[] , int n)
	{
		int dp[] = new int[n];
    	if(n == 1)
    		return 0;
    	if(n == 2)
    		return Math.abs(arr[1] - arr[0]);
    	dp[1] = Math.abs(arr[1] - arr[0]);
    	for(int i = 2; i < n; i++)
    	{
    		int a = Math.abs(arr[i] - arr[i - 1]) + dp[i-1];
    		int b = Math.abs(arr[i] - arr[i - 2]) + dp[i-2];
    		dp[i] = Math.min(a,b);
    	}
    	return dp[n-1];
	}

	public static void main(String[] args) throws Exception
	{
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	int n = Integer.parseInt(br.readLine());
    	String str[] = br.readLine().trim().split("\\s+");
    	int arr[] = Arrays.stream(str).mapToInt(Integer::parseInt).toArray();
    	System.out.println(func(arr,n));
    }

}




Measured memory_bytes: 37036
#include <bits/stdc++.h>
#define Max 100000
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

ll N = 0;
ll A, B;
ll ret = 0;

void input() {
  IN(A);
  IN(B);
}

void solve() {

}

int main(void){
  input();
  solve();
  ret = (B%A==0)?(A+B):(B-A);
  PRINT(ret);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
n = stdin.readline()
n = n.strip().split(" ")
K = int(n[0])
T = int(n[1])
n = stdin.readline()
n = n.strip().split(" ")
a = []
for t in n:
	a.append(int(t))

idx = np.argmax(a)

res = np.max(a) -1
for b in range(len(a)):
	if b != idx:
		res -= a[b]
if res < 0:
	res = 0
print res

Measured memory_bytes: 10512
s = gets.to_i

temp = s
memo = {s => true}

(1..1000000).each{ |i|
	if temp % 2 == 0 then
		temp = temp / 2
	else
		temp = temp * 3 + 1
	end
	
	if memo[temp] != nil then
		puts i + 1
		exit
	else
		memo[temp] = true
	end
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
using ll = long long;
int main(){
  int n;
  cin>>n;
  vector<int> p(n);
  rep(i,n)cin>>p.at(i);
  int sum = 0;
  
  int curmin = p[0];
  rep(i,n){
    curmin = min(curmin,p[i]);
    if(curmin>=p[i]){
      sum++;
      curmin = p[i];
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 1024
N=int(input())
S=[]
T=[]
for i in range(N):
    s,t=map(str,input().split())
    S.append(s)
    T.append(int(t))
X=input()
ans=0
x=S.index(X)

for i in range(x+1,N):
    ans+=T[i]

print(ans)

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;



struct state {
  int turn;
  int y,x;
  string ba;
  state() {}
  state(int a,int y, int x, string ba) : turn(a) ,y(y) , x(x) ,ba(ba)  {}
};

int dx[] = {-1,-1,-1,0,0,1,1,1};
int dy[] = {-1,0,1,-1,1,-1,0,1};
int main() {
  int n;
  while(cin >> n , n){
    state stat;
    string ba;
    for(int i = 0; i < n; i++){
      string str;
      cin >> str;
      ba+=str;
      REP(j, str.size()) {
        if (str[j] == '@') {
          stat.y = i;
          stat.x = j;
        }
      }
    }
    stat.ba = ba;
    stat.turn = 0;
    queue<state> Q;
    Q.push(stat);

    int res = -1;
    map<string , bool> visited;
    
    while(!Q.empty()) {
      state now = Q.front();
      Q.pop();

      if (visited[now.ba]) continue;
      visited[now.ba] = 1;
//      cout << now.turn << endl;
      

      // REP(i, n) {
      //   REP(j, n) {
      //     cout << now.ba[i][j];
      //   }
      //   cout << endl;
      // }

      bool f = 0;
      REP(i, n) {
        REP(j, n) {
          if (now.ba[i*n+j] == '#') {
            f = 1;
            break;
          }
        }
        if(f) break;
      }
      if (!f) {
        res = now.turn;
        break;
      }
      REP(k, 8) {
        int yy = now.y+dy[k];
        int xx = now.x+dx[k];

        if(yy<0||yy>=n||xx<0||xx>=n) continue;
        if(now.ba[yy*n+xx] == '#') continue;

        //  cout << yy << " " << xx << endl;
        state next = now;
        next.turn++;
        next.ba[now.y*n+now.x] = '.';
        next.y = yy;
        next.x = xx;
        next.ba[yy*n+xx] = '@';
        
        REP(i, n) {
          REP(j, n) {
            int cnt = 0;
            REP(k, 8) {
              int ii = i+dy[k];
              int jj = j+dx[k];
              if (ii<0||ii>=n||jj<0||jj>=n) continue;
              if (now.ba[ii*n+jj] == '#' || next.ba[ii*n+jj] == '@') cnt++;
            }
            if (next.ba[i*n+j] == '#') {
              if (cnt == 2 || cnt == 3);
              else {
                next.ba[i*n+j] = '.';
              }
            } else if (next.ba[i*n+j] == '.') {
              if (cnt == 3) {
                next.ba[i*n+j] = '#';
              }
            }
          }
        }
        
        if(visited[next.ba]) continue;
        Q.push(next);
      }
    }
    cout << res << endl;
  }
  

}

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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B){
    cout << C << endl;
  }
  else if(B==C){
    cout << A << endl;
  }
  else{
    cout << B << endl;
  }
}

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

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    vector<int> B;
    vector<int> C(N,-1);
    rep(i, N){
        int ak;
        cin >> ak;
        A.at(i) = ak-1;
    }
    int node = 0;
    ll i = 0;
    B.push_back(node);
    C[node] = i;
    ll init;
    ll loop;
    while(i<K){
        node = A.at(node);
        i++;
        if(C[node] > -1){
            init = C[node];
            loop = i-C[node];
            break;
        } else {
            C[node] = i;
            B.push_back(node);
        }
    }
    if(i==K) out(node+1);
    else out(B.at(init+((K-init)%loop))+1);
}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 5804
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n;cin>>n;
    string s;cin>>s;
    if(n%2==1){
        cout<<"No"<<endl;
    }else{
        bool b=false;
        rep(i,0,(n/2)-1){
            if(s[i]!=s[i+(n/2)]){
                b=true;
            }
        }
        if(b){
            cout<<"No"<<endl;
        }else{
            cout<<"Yes"<<endl;
        }
    }
    
    
    return 0;
}







Measured memory_bytes: 256
public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		String str = scan.nextLine();
		for(int i = 0; i < str.length();i++){
			char arr = str.charAt(i);
			if(Character.isLowerCase(arr)){
				System.out.print(Character.toUpperCase(arr));
				}else{
					System.out.print(Character.toLowerCase(arr));
				}
		}
		System.out.println();
	}

}

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

int main(){
    // Your code here!
    int n;
    int i = 1;
    cin >> n;
    for(i=1;i<=n;i++){
        int x = i;
        if ( x % 3 == 0 ){
           cout << " " << i;
           continue;
        }
        if ( x % 10 == 3 ){
           cout << " " << i;
           continue;
        }
        while(x!=0){
            x/= 10;
            if (x)
               if ( x % 10 == 3 ){
                  cout << " " << i;
                  break;
               }    
        }
    }
    cout << endl;
}




Measured memory_bytes: 3112
import java.util.Scanner;
public class Main{
	int kin[]={6000,4000,3000,2000};
	int syu;
	int mai;
	int gokei;
	
	public void solve(){
		Scanner sc = new Scanner(System.in);
		for(int i=0;i<=3;i++){
			syu = sc.nextInt();
			mai = sc.nextInt();
			syu = syu-1;
			gokei = mai*kin[syu];
			System.out.println(gokei);
		}
	}
	
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17180
// Lets go to the next level 
// AIM Expert at CF *__* asap 
// Hit A,B,C and if possible D faster and reach Expert
// Remember you were also a novice when you started, 
// hence never be rude to anyone who wants to learn something
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts 
// Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure.  
#include "bits/stdc++.h"
//#include <algorithm>
#define ll long long 
#define mod 1000000007
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define lb lower_bound
#define ub upper_bound
#define endll "\n";
#define all(x) (x).begin(), (x).end()
#define forr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define for1(i,a,b) for(int i=a;i<b;i++)
#define for2(i,a,b) for(int i=a;i>=b;i--)
#define for3(i,a,b) for(long long int i=a;i<b;i++)
#define for4(i,a,b) for(long long int i=a;i>=b;i--)
#define pp pair<int,int>
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpp vector<pp>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvpp vector<vpp>
#define I insert
#define mem(a,x) memset(a,x,sizeof(a))
#define p_queue(a) priority_queue<a,vector<a>,greater<a>>
using namespace std;
//const int dx[8]={1,0,-1,0,1,1,-1,-1},dy[8]={0,1,0,-1,-1,1,-1,1};
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; 
const int N=2e5+5;
/*vector<bool> p(N+1, true);
void sieve()
{
  p[0] = p[1] = false;
  int i,j;
  for (i = 2; i*i <= N; i++) 
  {
      if (p[i]) 
      {
          for (j = i * i; j <=N; j += i)
            {
        p[j] =false;
        }
      }
  }
}*/
/*int power(int a, int b){
    int res = 1;
    while(b > 0){
        if(b % 2){
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
        b /= 2;
    }
    return res;
}*/
/*int gcd(int a,int b){
    if(a<b) swap(a,b);
    a%=b;
    if(a==0) return b;
    return gcd(b,a);
}*/
/*int lcm(int a,int b){
   return (a*1LL*b)/gcd(a,b);
}*/
ll a[N];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;cin>>n;
    for1(i,0,n) cin>>a[i];
    int ans=0;
    for1(i,0,n-2){
      for1(j,i+1,n-1){
        for1(k,j+1,n){
          if(a[i]!=a[j]&&a[j]!=a[k]&&a[k]!=a[i]){
            ll sum=a[i]+a[j]+a[k];
            if(sum>2*max(a[i],max(a[j],a[k]))){
              ans++;
            }
          }
        }
      }
    }
    cout<<ans<<endll;
    return 0;
}

/*

*/




Measured memory_bytes: 3636
N,M=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(N)]
ab = sorted(ab)

SUM=0
for i in range(N):
  a,b=ab[i]
  x = min(M,b)
  SUM += a*x
  M -= x
  if M==0:break
    
print(SUM)

Measured memory_bytes: 28096
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int a = Integer.parseInt(str2[0]);
    int b = Integer.parseInt(str2[1]);

    int div = a / b;
    int rem = a % b;
    double div2 = (double)a / (double)b;

    System.out.println(div + " " + rem + " " + String.format("%.5f", div2));
  }
}

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

int main(){
    long long n,x;
    cin >> n >> x;
    
    vector<long long> a(n);
    for(long long i=0;i<n;i++){
        cin >> a[i];
    }
    
    sort(a.begin(),a.end());
    
    int ans(0);
    for(int i=0;i<n;i++){
        x -= a[i];
        if(x>=0){
            ans++;
        }else{
            break;
        }
    }
    
    if(x>0){
        ans--;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3584
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Trim().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }


        //15.2 トポロジカルソート
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NE = Sarray();
            var N = NE[0];
            var E = NE[1];
            var G = new List<long>[N];
            var InCnt = new long[N];
            for (var i = 0; i < N; ++i) G[i] = new List<long>();
            for (var i = 0; i < E; ++i)
            {
                var std = Sarray();
                G[std[0]].Add(std[1]);
                ++InCnt[std[1]];
            }
            var q = new Queue<long>();
            for (var i = 0; i < N; ++i)
                if (0 == InCnt[i])
                {
                    q.Enqueue(i);
                    --InCnt[i];
                }
            while(q.Any())
            {
                var v = q.Dequeue();
                WriteLine(v);
                foreach(var t in G[v])
                {
                    if (--InCnt[t] == 0)
                        q.Enqueue(t);
                }
            }
        }
    }
}


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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

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

    int a, b; cin >> a >> b;
    int cnt = 1, ans = 0;
    while (cnt < b) {
        cnt--;
        cnt += a;
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632