akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
using namespace std;

int main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    long long n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for (long long i = 0; i != n; ++i) {
        cin >> a[i];
        --a[i];
        a[i] %= k;
    }
    vector<long long> p(n);
    long long sum = 0;
    long long ans = 0;
    for (long long i = 0; i != n; ++i) {
        sum = (sum + a[i]) % k;
        p[i] = sum;
        if (sum == 0 && i + 1 < k)
            ++ans;
    }
    map<long long, long long> cur;
    for (long long i = 0; i != n; ++i) {
        if (i - k >= 0) {
            auto it = cur.find(p[i - k]);
            --it->second;
            if (it->second == 0)
                cur.erase(it);
        }
        auto it2 = cur.find(p[i]);
        if (it2 != cur.end())
            ans += it2->second;
        ++cur[p[i]];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 15872
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args)  throws IOException,NumberFormatException{
		try {
		FastScanner sc=new FastScanner();
		int n=sc.nextInt();
		int a[]=sc.readArray(n);
		ruffleSort(a);
		int countf=0,countt=0;
		for(int i=0;i<n;i++) {
			if(a[i]%10==0) {
				countt++;
			}
		}
		int ans=0;
		if(countt==n) {
			System.out.println(0);
		}
		else {
			int lastAdd=0;
			for(int i=n-1;i>=0;i--) {
				if(a[i]%10!=0) {
				ans+=a[i];
				lastAdd=a[i];
				}
			}
			if(ans%10==0) {
				ans-=lastAdd;
			}
			for(int i=n-1;i>=0;i--) {
				if(a[i]%10==0) {
					ans+=a[i];
				}
			}
			System.out.println(ans);
			
		}
		
		}
		catch(Exception e) {
			return ;
		}
		
	}
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;
		for(int i=0;i<n;i++) {
			int oi=random.nextInt(n),temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	public static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { 
                                      st=new StringTokenizer(br.readLine());				               
                              } catch (IOException e) {}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		
		long[] readLongArray(int n) {
			long[] a=new long[n];
			for(int i=0; i<n ; i++) a[i]=nextLong();
			return a;
		}
		
		String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
	}

}


Measured memory_bytes: 32692
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())

static const int N = 1000;

int main() {
    int n, p[N + 1], m[N + 1][N + 1];
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i - 1] >> p[i];
    }
    for (int i = 1; i <= n; i++) {
        m[i][i] = 0;
    }
    for (int l = 2; l <= n; l++) {
        for (int i = 1; i <= n - l + 1; i++) {
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for (int k = i; k <= j - 1; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }
    cout << m[1][n] << endl;
    return 0;
}


Measured memory_bytes: 3448
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();

        long sum = 0;
        for(long i=k;i<n+2;i++){
            long max = (n + n - i + 1) * i / 2;
            long min = (i-1) * i / 2;
            if(max - min + 1 < 0) {
                System.out.println("abort," + i + ", " + max + ", " + min);
                break;
            }
            sum += max - min + 1;
            if(sum >= 1000000007){
                sum %= 1000000007;
            }
        }

        System.out.println(sum);

    }
}


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

int main() {
    vector<int> abc(3);
    cin >> abc[0] >> abc[1] >> abc[2];
    int k;
    cin >> k;
    sort(abc.begin(), abc.end());
    for (int i=0; i<k; i++) {
        abc[2] *= 2;
    }
    cout << abc[0] + abc[1] + abc[2] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Node {
  int parent, left, right;
};
using Nodes = vector<Node>;

void setDepth(const Nodes &nodes, vector<int> &depths, int depth, int id) {
  auto node = nodes.at(id);
  depths.at(id) = depth;
  if (node.left != -1) {
    setDepth(nodes, depths, depth + 1, node.left);
  }
  if (node.right != -1) {
    setDepth(nodes, depths, depth + 1, node.right);
  }
}

int setHeight(const Nodes &nodes, vector<int> &heights, int id) {
  auto node = nodes.at(id);
  int left = -1, right = -1;
  if (node.left == node.right) {
    heights.at(id) = 0;
    return 0;
  }
  if (node.left != -1) {
    setHeight(nodes, heights, node.left);
    left = heights.at(node.left);
  }
  if (node.right != -1) {
    setHeight(nodes, heights, node.right);
    right = heights.at(node.right);
  }

  heights.at(id) = max(left, right) + 1;
  return heights.at(id);
}
int main() {
  int n, id, left, right;
  cin >> n;
  Nodes nodes(n, Node{-1, -1, -1});
  vector<int> depths(n, 0), heights(n, 0);

  for (size_t i = 0; i < n; i++) {
    cin >> id;
    auto &node = nodes.at(id);
    cin >> node.left >> node.right;
    if (node.left != -1) {
      nodes.at(node.left).parent = id;
    }
    if (node.right != -1) {
      nodes.at(node.right).parent = id;
    }
  }

  auto root = find_if(nodes.begin(), nodes.end(),
                      [](const Node node) { return node.parent == -1; });

  auto rootId = distance(nodes.begin(), root);
  setDepth(nodes, depths, 0, rootId);
  setHeight(nodes, heights, rootId);

  for (size_t i = 0; i < n; i++) {
    auto no = nodes.at(i);
    string node_type;
    int deg, sib;

    if (no.left == no.right) {
      node_type = "leaf";
      deg = 0;
    } else if (no.right == -1 || no.left == -1) {
      node_type = "internal node";
      deg = 1;
    } else {
      node_type = "internal node";
      deg = 2;
    }

    if (no.parent == -1) {
      node_type = "root";
      sib = -1;
    } else {
      auto parent = nodes.at(no.parent);
      sib = parent.left == i ? parent.right : parent.left;
    }

    cout << "node " << i << ": parent = " << no.parent << ", sibling = " << sib
         << ", degree = " << deg << ", depth = " << depths[i]
         << ", height = " << heights[i] << ", " << node_type << endl;
  }
}


Measured memory_bytes: 3224
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x, y;
	cin >> x >> y;
	int ans = 0;
	while (x <= y) {
		x *= 2;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  string s;
  cin>>s;
  int l=s.length();
  while(l>0){
    if(l<5){
      cout<<"NO"<<endl;
      return 0;
    }else if(l<6){
      string s5=s.substr(l-5,5);
      if(s5=="dream"||s5=="erase") break;
      else{
        cout<<"NO"<<endl;
        return 0;
      }
    }else if(l<7){
      string s6=s.substr(l-6,6);
      if(s6=="eraser") break;
      else{
        cout<<"NO"<<endl;
        return 0;
      }      
    }
    string s7=s.substr(l-7,7),s6=s.substr(l-6,6),s5=s.substr(l-5,5);
    if(s7=="dreamer") l-=7;
    else if(s6=="eraser") l-=6;
    else if(s5=="dream"||s5=="erase") l-=5;
    else{
      cout<<"NO"<<endl;
      return 0;
    }
  }  
  cout<<"YES"<<endl;  
  return 0;
}


Measured memory_bytes: 512
S = input()
x = y = 0
n = w = s = e = 0
for c in S:
  if c == 'N':
    n += 1
  elif c == 'W':
    w += 1
  elif c == 'S':
    s += 1
  else:
    e += 1
if (n == 0 and s > 0) or (s == 0 and n > 0):
  y = 1
if (w == 0 and e > 0) or (e == 0 and w > 0):
  x = 1
print('Yes' if x == 0 and y == 0 else 'No')

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

int main() {
	int64_t a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a >= k)cout << k << endl;
	else if (a + b >= k)cout << a << endl;
	else cout << a - k + (a + b) << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
ll a[maxn];
ll ans[maxn];
int ru[maxn];
vector<int>s[maxn];
void dfs(int x,int pre,ll sum)
{
    ans[x]+=sum;
    for(int i=0;i<s[x].size();i++)
    {
        if(s[x][i]!=pre)
        {
            dfs(s[x][i],x,sum+a[s[x][i]]);
        }
    }
}
int  main()
 {
     int n,q;
     scanf("%d%d",&n,&q);
     for(int i=0;i<n-1;i++)
     {
         int x,y;
         scanf("%d%d",&x,&y);
         s[x].push_back(y);
         s[y].push_back(x);
        // ru[y]++;
     }
     for(int i=0;i<q;i++)
     {
         int x,y;
         scanf("%d%d",&x,&y);
         a[x]+=y;
     }
     int pos=1;
     dfs(1,0,a[1]);
     for(int i=1;i<=n;i++)
        printf("%lld%c",ans[i],i==n? '\n':' ');
     return 0;
 }


Measured memory_bytes: 29568
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;
  

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

    int res = 6 / (a * b);

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
n,a,b,c = map(int, input().split())
ans = []
ans_ = "Yes"
ss = [0]
sss = {}
for i in range(n):
  s = str(input())
  ss.append(s)
  sss[i] = s
sss[n] = "a"
for num,s in enumerate(ss):
  if num == 0:
    continue
  else:
    if s == "AB":
      if a == 0 and b == 0:
        ans_ = "No"
        break
      if a > b:
        a -= 1
        b += 1
        ans.append("B")
      elif a < b:
        a += 1
        b -= 1
        ans.append("A")
      else:
        if sss[num] == "BC":
          a -= 1
          b += 1
          ans.append("B")
        else:
          a += 1
          b -= 1
          ans.append("A")
    if s == "BC":
      if c == 0 and b == 0:
        ans_ = "No"
        break
      if c > b:
        c -= 1
        b += 1
        ans.append("B")
      elif c < b:
        c += 1
        b -= 1
        ans.append("C")
      else:
        if sss[num] == "AB":
          c -= 1
          b += 1
          ans.append("B")
        else:
          c += 1
          b -= 1
          ans.append("C") 
    if s == "AC":
      if a == 0 and c == 0:
        ans_ = "No"
        break
      if a > c:
        a -= 1
        c += 1
        ans.append("C")
      elif a < c:
        a += 1
        c -= 1
        ans.append("A")
      else:
        if sss[num] == "BC":
          a -= 1
          c += 1
          ans.append("C")
        else:
          a += 1
          c -= 1
          ans.append("A")
if ans_ == "No":
   print(ans_)
else:
  print(ans_)
  for i in ans:
    print(i)

Measured memory_bytes: 25672
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
 
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; }
 
#include <bits/stdc++.h>
using namespace std;

int isPrime(int x){
  if(x<2) return 0;
  else if(x==2) return 1;
  if(x%2==0) return 0;
  for(int i=3;i*i<=x;i+=2){
    if(x%i==0) return 0;
  }
  return 1;
}
  
int main(){
  int n;
  cin>>n;
  
  int x,cnt=0;
  rep(i,n){
    cin>>x;
    if(isPrime(x)) cnt++;
  }
  
  cout<<cnt<<endl;
      
  return 0;
}


Measured memory_bytes: 3104
/*
3
2 3 1
[i] : n → しゅせきばんごう(i+1)が出席したのなn番目
*/
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;
int main(){
  int seitosuu = 0;
  int tmp = 0;
  std::cin >> seitosuu;
  std::vector<int> shussekijun = vector<int>(seitosuu);
  for(size_t i = 0; i < seitosuu; ++i){
    std::cin >> tmp;tmp -=1;
    shussekijun[tmp] = i+1;
  }
  
  for(auto a : shussekijun){
    std::cout << a << " ";
  }
  
}
  
  
  




Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            switch (ReadString())
            {
                case "1":
                    Console.WriteLine("Hello World");
                    break;
                case "2":
                    Console.WriteLine(ReadLineIntArray(2).Sum());
                    break;
                default:
                    break;
            }
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const LL INF = 1e14;
const LL MOD = 1e9 + 7;

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

LL GCD(LL a, LL b)
{
  while(a % b)
  {
    LL r = a % b;
    a = b;
    b = r;
  }
  return b;
}

LL Prime(LL n)
{
    LL res = 0;
    LL a = 2;
    LL pre = a;
    bool flg = false;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
          if (!flg) res++;
          n /= a;
          pre = a;
          flg = true;
        }
        else
        {
          flg = false;
          a++;
        }
    }
    if (pre != n) res++;
    return res;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL a, b;
  cin >> a >> b;
  LL gcd = GCD(a, b);
  LL add = 1;
  if (gcd == 1) add = 0;
  cout << Prime(gcd)+add << endl;

  return 0;
}

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

int main()
{
    int n, max;
    std::cin >> n >> max;

    int a;
    long long ans = 0;
    for (register int i = 1; i < n; ++i)
    {
        std::cin >> a;
        if (a < max)
        {
            ans += max - a;
        }
        else
        {
            max = a;
        }
    }

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

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
  	while(cin>>n){
    	int sum=0;
      	for(int i=1;i<=n;i++){
        	for(int j=1;j<=n;j++){
            	for(int k=1;k<=n;k++){
                	sum+=__gcd(i,__gcd(j,k));
                }
            }
        }
        cout<<sum<<endl;
    }
  return 0;
}


Measured memory_bytes: 3576
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    ArrayList<Integer> dislike = new ArrayList<Integer>();
    for(int i = 0; i < K; i++) {
      int a = sc.nextInt();
      dislike.add(a);
    }
    int ans = N;
    for(int i = N; i < 100 * N; i++) {
      int count = 0;
      int temp = i;
      while(temp > 0) {
        int digit = temp % 10;
        temp /= 10;
        if(dislike.contains(digit)) count++;
      }
      if(count == 0) {
        ans = i;
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22484
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

[<EntryPoint>]
let main _ =
    let n = read int
    let ass = reada int
    let ass = Array.sort ass |> Array.rev
    let total = Array.sum ass
    let mutable alice = 0
    for i in 0..2..n-1 do
        alice <- alice + ass.[i]
    alice - (total - alice) |> printfn "%d"
    0


Measured memory_bytes: 14812
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 10000000005
#define NIL -1
int main(){
    ll n; cin >> n;
    int cnt = 0;
    bool flg_up = false;
    bool flg_down = false;
    ll a[n];
    cin >> a[0];
    for(ll i = 1; i < n; i++){
        cin >> a[i];
        if(!flg_up && !flg_down){
            if(a[i] > a[i-1]){
                flg_up = true;
            } else if(a[i] < a[i-1]){
                flg_down = true;
            }
        } else if(flg_up && a[i] < a[i-1]){
            flg_up = false;
            cnt++;
        } else if(flg_down && a[i] > a[i-1]){
            flg_down = false;
            cnt++;
        }
    }
    cout << cnt + 1 << endl;
}

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

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

using ll=long long; 
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; 

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (300006)
ll n;
int main(){
	FAST
	cin>>n;
	ll mod=1e9+7;
	auto qexp=[&](ll x,ll e){
		ll sum=1;
		for(;e;--e) sum*=x, sum%=mod;
		return sum;
	};
	ll ans = qexp(10, n);
	ans -= qexp(9, n), ans += mod, ans %= mod; // no 0
	ans -= qexp(9, n), ans += mod, ans %= mod; // no 9
	ans += qexp(8, n), ans %= mod; // no 9 and no 0;
	cout<<ans<<'\n';
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int> a(3);
    for(int i=0;i<3;++i)cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=0;i<3;++i){
        cout<<a[i];
        if(i==2)cout<<endl;
        else cout<<' ';
    }
}


Measured memory_bytes: 3088
let dx, dy = Scanf.scanf "%d %d %d %d" (fun w x y z -> y-w, z-x)
let p n c = Array.init n (fun _ -> Printf.printf "%c" c) |> ignore
let () =
  p dx 'R';
  p dy 'U';
  p dx 'L';
  p (dy+1) 'D';
  p (dx+1) 'R';
  p (dy+1) 'U';
  p 1 'L';
  p 1 'U';
  p (dx+1) 'L';
  p (dy+1) 'D';
  p 1 'R';
  print_newline ()

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

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

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60; 

vector<ll> fact;

void init(ll N){
  fact.resize(N+1);
  fact[0]=1;
  rep(i,N)  fact[i+1]=((i+1)*fact[i])%lmod;
}

ll ppow(ll a,ll b){
  // aのb乗を求める
  ll res = 1;
  while(b){
    if(b%2) res=(res*a)%lmod;
    a=(a*a)%lmod;
    b>>=1;
  }
  return res;
}

ll imod(ll n){
  // nのmodの逆元を求める
  ll P=lmod;
  return ppow(n,P-2);
}

ll comb_mod(ll n,ll k){
  return (fact[n] * imod(fact[k]) % lmod) * imod(fact[n-k]) % lmod ;
  //nCk % mod を返す
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,A,B,C,D; cin >> N >> A >> B >> C >> D;
  init(N+1);
  int s = B - A + 1;
  vvl dp(s+1,vl(N+1));
  dp[0][0] = 1LL;
  rep(i,s){
    rep(j,N+1){
      (dp[i+1][j] += dp[i][j]) %= lmod;
      if(dp[i][j]==0LL) continue;
      REP(k,C,D+1){
        int t = i + A;
        // t人グループをk個作る
        if(j+k*t>N) break;
        dp[i+1][j+k*t] += dp[i][j] * fact[k*t] % lmod * ppow(imod(fact[t]),k) % lmod 
                           * comb_mod(N-j,k*t) % lmod * imod(fact[k]);
        dp[i+1][j+k*t] %= lmod;
      }
    }
    dump(i+1,dp[i+1]);
  }
  cout << dp[s][N] << endl;
  return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N, K, R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;

    vector<vector<int>> dp(N + K, vector<int>(3));
    for (int i = 0; i < N; ++i) {
        dp[i + K][0] = max(dp[i][1], dp[i][2]);
        dp[i + K][1] = max(dp[i][2], dp[i][0]);
        dp[i + K][2] = max(dp[i][0], dp[i][1]);
        if (T[i] == 's')
            dp[i + K][0] += R;
        if (T[i] == 'p')
            dp[i + K][1] += S;
        if (T[i] == 'r')
            dp[i + K][2] += P;
    }

    int ans = 0;
    for (int i = N; i < N + K; ++i)
        ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13496
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long n,a[10000],s=0,i,sum=0;
   cin>>n;
   for(i=0;i<n;i++)
   {
       cin>>a[i];
       if(a[i]%2==0)
       {
           sum++;
       }
       if (a[i]%2==0)
      {

       if((a[i]%3==0 || a[i]%5==0))
          s++;
      }
    }
    if (sum==s)
        cout<<"APPROVED"<<endl;
    else
        cout<<"DENIED"<<endl;
    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  k <- getInteger

  let solve i x y | i > (10^6) = -1
                  | otherwise =
                    if x == 0
                    then i
                    else solve (i+1) ((x+y)`mod`k) (y*10`mod`k)

  print $ solve 1 (7 `mod` k) (70 `mod` k)


Measured memory_bytes: 4832
/*enjoy karo yaar*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";

const int inf=1e18,M=1e9+7;
const int N=1e5+10;

vector<int> fact(N);

int pw(int x,int n)
{
    int res=1;
    x%=M;
    for(;n;n/=2)
    {
        if(n%2)
            res=(res%M*x%M)%M;
        x=(x%M*x%M)%M;
    }

    return res;
}

int ncr(int n,int r)
{
    if(n<r)
        return 0;

    int num=fact[n];
    int den=pw((fact[r]*fact[n-r])%M,M-2)%M;

    int res=(num*den)%M;
    return res;
}

void compute()
{
    fact[0]=1;
    for(int i=1;i<N;++i)
        fact[i]=(fact[i-1]*i)%M;
}

void solve()
{
    compute();

    int n,k;
    cin>>n>>k;

    vector<int> v(n);
    for(int i=0;i<n;++i)
        cin>>v[i];

    sort(all(v));

    int mn,mx,tmp,ans=0;
    for(int i=0;i<n;++i)
    {
        mn=ncr(n-i-1,k-1);
        mx=ncr(i,k-1);

        //cout<<mx<<" "<<mn<<"\n";

        tmp=((mx%M-mn%M+M)%M*v[i]%M+M)%M;

        ans=(ans+tmp)%M;
    }

    cout<<ans;
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 1792
#include <iostream>

int main(void)
{
    int a, b, c;
    std::cin >> a >> b >> c;
    int r;
    if (a == b)
    {
        r = c;
    }
    else if (a == c)
    {
        r = b;
    }
    else
    {
        r = a;
    }
    std::cout << r << std::endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
f = {}
s = 0
for i in a:
    s += i
    if i not in f:
        f[i] = 0
    f[i]+=1
q = int(input())
for _ in range(q):
    b,c = map(int,input().split())
    if b not in f:
        print(s)
        continue
    s += f[b]*(c-b)
    print(s)
    if c not in f:
        f[c] = 0
    f[c] += f[b]
    f[b] = 0


Measured memory_bytes: 84900
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;
const ll mod=1000000007;

int main(){
  ll a,b,k; cin>>a>>b>>k;
  if(k<=a)
  cout<<a-k<<" "<<b<<endl;
  else if(k-a<b)
  cout<<0<<" "<<b-(k-a)<<endl;
  else
  cout<<0<<" "<<0<<endl;

  return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)


class Combination:
    def __init__(self, mod=10**9+7, n=202020):
        self.f = [0] * n
        self.rf = [0] * n
        self.inv = [0] * n
        self.f[0], self.f[1] = 1, 1
        self.rf[0], self.rf[1] = 1, 1
        self.inv[1] = 1
        self.MOD = mod
        for i in range(2, n):
            self.f[i] = (self.f[i - 1] * i) % self.MOD
            self.inv[i] = (-self.inv[self.MOD % i] * (self.MOD // i)) % self.MOD
            self.rf[i] = (self.rf[i - 1] * self.inv[i]) % self.MOD

    def __call__(self, n, r):
        return (self.f[n] * self.rf[r] * self.rf[n - r]) % self.MOD


C = Combination()
n, k = map(int, input().split())
ans = 1
for i in range(1, min(k, n-1)+1):
    tmp = (C(n, i) * C(n-1, i)) % MOD
    ans = (ans + tmp) % MOD

print(ans)


Measured memory_bytes: 45932
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T>
void print_container(T &container, string delim=" ") {
    bool first = true;
    for(auto &t: container){
        if(!first){
            cout << delim;
        }
        first = false;
        cout << t;
    }
    cout << endl;
}

int main() {
    int x;
    cin >> x;
    bool ok = false;
    IFOR(i, 1, 10000){
        int rest = x - 100 * i;
        if(rest < 0)
            continue;
        int cnt = rest / 5;
        if(rest % 5)
            cnt++;
        if(cnt <= i){
            ok = true;
            break;
        }
    }
    cout << (ok ? 1 : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int n, a[100005], dp[100005];

int f(int k)
{
    if (k >= n) return 1e9;
    if (k == n - 1) return 0;
    if (dp[k] != -1) return dp[k];
    return dp[k] = min(abs(a[k] - a[k + 1]) + f(k + 1),
                       abs(a[k] - a[k + 2]) + f(k + 2));
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    memset(dp, -1, sizeof dp);
    cout << f(0);
}


Measured memory_bytes: 2560
import numpy as np

n,m = input().split()
n = int(n)
m = int(m)

mod = 10**9+7

answer = 1

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

if (n - m)** 2 > 1:
    answer = 0
else:
    for i in range(n):
        answer = mul(answer,i+1)

    for j in range(m):
        answer = mul(answer,j+1)

    if n == m:
        answer = mul(answer,2)

print(answer)

Measured memory_bytes: 21480
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int[] num = new int[6];
        int count_1 = 0;
        int count_2 = 0;
        int count_3 = 0;
        int count_4 = 0;
        
        for(int i = 0; i < 6; i++){
            num[i] = sc.nextInt();
        }
        
        for(int i = 0; i < 6; i++){
            if(num[i] == 1)count_1++;
            if(num[i] == 2)count_2++;
            if(num[i] == 3)count_3++;
            if(num[i] == 4)count_4++;
        }
        
        if(count_1 == 3 || count_2 == 3 || count_3 == 3 || count_4 == 3 ){
            System.out.println("NO");
        }else{
            System.out.println("YES");
        }
    }
}


Measured memory_bytes: 21844
// IOI 2021
 
#include <bits/stdc++.h>

using namespace std;

//#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9;
const int MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 2e5 + 5;

int n, m, DP[N], PAR[N];
string s;

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	memset(DP, 63, sizeof DP);
	cin >> n >> m >> s;
	DP[n] = 0;
	set<pii> st; st.insert(make_pair(DP[n], n));
	for (int i = n - 1; i >= 0; i--) {
		st.erase(make_pair(DP[i + m + 1], i + m + 1));
		if (s[i] == '1') continue;
		if (st.empty()) continue;
		PAR[i] = st.begin()->second;
		DP[i] = DP[PAR[i]] + 1;
		st.insert(make_pair(DP[i], i));
	}
	if (DP[0] > INF) die(-1);
	int p = 0;
	while (p != n) {
		cout << PAR[p] - p << ends;
		p = PAR[p];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> field(H);
    for(int h=0; h<H; h++) {
        cin >> field[h];
    }
    
    int dh[4] = {1, 0, -1, 0};
    int dw[4] = {0, 1, 0, -1};
    string ans="Yes";
    for(int h=0; h<H; h++) {
        for(int w=0; w<W; w++) {
            if(field[h][w]=='.') continue;
            
            bool flag=false;
            for(int i=0; i<4; i++) {
                if(h+dh[i]<0 || h+dh[i]>=H || w+dw[i]<0 || w+dw[i]>=W) continue;
                if(field[h+dh[i]][w+dw[i]]=='#') {
                    flag=true;
                    break;
                }
            }
            if(flag) {
                continue;
            } else {
                ans="No";
                break;
            }
        }
    }
    
    cout << ans << endl;


    return 0;
    
}

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

using namespace std;

struct node_t{
	int key;
	int priority;
	node_t *left;
	node_t *right;
	node_t(int key, int priority): key(key), priority(priority), left(NULL), right(NULL) {}
};

node_t* left_rotate(node_t *t){
	node_t *right_child = t->right;
	t->right = right_child->left;
	right_child->left = t;
	return right_child;
}

node_t* right_rotate(node_t *t){
	node_t *left_child = t->left;
	t->left = left_child->right;
	left_child->right = t;
	return left_child;
}

node_t* insert(node_t *t, int key, int priority){
	if(t == NULL) return new node_t(key, priority);
	if(key == t->key) return t;
	if(key < t->key){
		t->left = insert(t->left, key, priority);
		if(t->priority < t->left->priority) t = right_rotate(t);
	}else{
		t->right = insert(t->right, key, priority);
		if(t->priority < t->right->priority) t = left_rotate(t);
	}
	return t;
}

node_t* delete_node(node_t *t, int key){
	if(t == NULL) return NULL;
	if(key == t->key){
		// move the node to the leaf
		if(t->left == NULL && t->right == NULL) {
			delete t;
			return NULL;
		}else if(t->left == NULL){
			t = left_rotate(t);
		}else if(t->right == NULL){
			t = right_rotate(t);
		}else{
			if(t->left->priority > t->right->priority){
				t = right_rotate(t);
			}else{
				t = left_rotate(t);
			}
		}
		return delete_node(t, key); // do this again until we move t into the leaf
	}

	// search the node to delete
	if(key < t->key){
		t->left = delete_node(t->left, key);
	}else{
		t->right = delete_node(t->right, key);
	}
	return t;
}

void find_node(node_t *t, int key){
	if(t == NULL) {
		cout << "no" << endl;
		return;
	}
	if(key == t->key){
		cout << "yes" << endl;
	}else if(key < t->key){
		find_node(t->left, key);
	}else{
		find_node(t->right, key);
	}
}

void inorder(node_t *t){
	if(t == NULL){
		return;
	}
	inorder(t->left);
	cout << " " << t->key;
	inorder(t->right);
}

void preorder(node_t *t){
	if(t == NULL) {
		return;
	}
	cout << " " << t->key;
	preorder(t->left);
	preorder(t->right);
}

void print_tree(node_t *t){
	inorder(t);
	cout << endl;
	preorder(t);
	cout << endl;
}

int main(){
	int q;
	cin >> q;
	node_t *t = NULL;
	for(auto i = 0; i < q; ++i){
		string cmd;
		cin >> cmd;
		if(cmd == "insert"){
			int k, p;
			cin >> k >> p;
			t = insert(t, k, p);
		}else if(cmd == "find"){
			int k;
			cin >> k;
			find_node(t, k);
		}else if(cmd == "delete"){
			int k;
			cin >> k;
			t = delete_node(t, k);
		}else if(cmd == "print"){
			print_tree(t);
		}
	}
}


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

int main() {
  int X,Y,A,B,C;
  cin >> X >> Y >> A >> B >> C;
  
  vector<int> red(A),green(B);
  vector<int> trans(C);
  
  for(int i=0;i<A;i++){
    cin >> red[i];
  }
   for(int i=0;i<B;i++){
    cin >> green[i];
  }
  for(int i=0;i<C;i++){
    cin >> trans[i];
  }
  
  sort(red.begin(),red.end());
  reverse(red.begin(),red.end());
  sort(green.begin(),green.end());
  reverse(green.begin(),green.end());
  sort(trans.begin(),trans.end());
  reverse(trans.begin(),trans.end());
  
  vector<int> color(X+Y);
  
  for(int i=0;i<X;i++){
    color[i]=red[i];
  }
  for(int i=0;i<Y;i++){
    color[X+i]=green[i];
  }
  sort(color.begin(),color.end());
  long long sum=0;
  for(int i=0;i<X+Y;i++){
    sum +=color[i];
  }
  for(int i=0;i<min(X+Y,C);i++){
    sum +=max(trans[i],color[i])-color[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 2176
fun main(args:Array<String>):Unit {
    val n = readLine()!!.toInt()
    val mat = Array(n + 1){Array(n + 1){0}}
    for (i in 1 .. n) {
        readLine()!!.split(' ').map(String::toInt).forEachIndexed { index, j -> mat[i][index + 1] = j }
    }
    for (i in 1 .. n) for (j in 1 .. n) mat[i][j] += mat[i - 1][j] + mat[i][j - 1] - mat[i - 1][j - 1]
    println((0 until n).map{
        left ->
        ((left + 1) .. n).map{
            right ->
            (0 until n).map{
                top ->
                ((top + 1) .. n).map{bottom -> mat[bottom][right] - mat[top][right] - mat[bottom][left] + mat[top][left]}.max()!!
            }.max()!!
        }.max()!!
    }.max()!!)
}


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

#define ll long long
#define int long long
#define loop(i,s,e) for(int i=s;i<e;i++)
#define rloop(i,s,e) for(int i=e;i>=s;i--)
#define fr first
#define sc second
#define pb push_back
#define  vii vector<int>
#define vll vector<ll>
#define vpii vector<pair<int ,int >>
#define vpll vector<pair<ll, ll> >
#define  pii pair<int,int>
#define lb(v,x) lower_bound(v.begin(),v.end(),x);
#define ub(v,x) upper_bound(v.begin(),v.end(),x);
const long mod =1e8;
const int N = 5e6+5;
const long long inf= 1e18;

ll gcd(ll a ,ll b){if(b==0) return a;return gcd(b,a%b);}
ll mul(ll a ,ll b){return (a%mod * b%mod )%mod;}
ll mpower(ll a, ll b){if(b==0) return 1;ll temp=mpower(a,b/2);if(b%2==0){return mul(temp,temp);}else{	return mul(mul(temp,temp) , a);}}
ll inv(ll a){return mpower(a,mod-2);}
ll ncr(ll n, ll r){if(r==0)return 1;ll ans=n%mod;ans=mul(ans,ncr(n-1,r-1));ans=mul(ans,inv(r));	return ans;}
ll power(ll a, ll b){if(b==0) return 1;ll temp=power(a,b/2);if(b%2==0)return temp*temp;else return temp*temp*a;}
ll add(ll a, ll b){return (a%mod + b%mod)%mod;}


void solve()
{
     
  int n;cin>>n;
  int a[n];
  int f[n+5];
  memset(f,0,sizeof(f));
  loop(i,0,n)
  {
      cin>>a[i];
      f[a[i]]++;
  }
  ll ans=0;
  for(int i=0;i<=n;i++)
  {
      if(f[i])
      {
          ans+=(f[i]*(f[i]-1))/2;
      }
  }
  loop(i,0,n)
  {
       cout<<ans-f[a[i]]+1<<"\n";
      
  }
   
}

int32_t main()
{
	ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;//cin>>t;
	while(t--){
        solve();
	}
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, T;
    cin >> A >> B >> T;
    int ans = 0;
    for (int i = 0; i < T;) {
        i += A;
        if (i > T) break;
        ans += B;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
N, Y = map(int, input().split())

count = 0

for x in range(N+1):
    for y in range(N+1-x):
        if 10000*x+5000*y+1000*(N-x-y) == Y:
            count += 1
            print("{} {} {}".format(x, y, N-x-y))
            if count == 1:
                break
    if count == 1:
                break

if count == 0:
    print("-1 -1 -1")

Measured memory_bytes: 9128
#include <iostream>
using namespace std;
int main(){
  string a,b;
  cin>>a>>b;
  
  if(a.size()!=b.size()&&a.size()>b.size()) cout<<"GREATER"<<endl;
  else if(a.size()!=b.size()&&a.size()<b.size()) cout<<"LESS"<<endl;
  else if(a.size()==b.size()){
    for(int i=0;i<a.size();i++){
      if(a[i]>b[i]) {
        cout<<"GREATER"<<endl;
        return 0;
      }
      else if(a[i]<b[i]) {
        cout<<"LESS"<<endl;
        return 0;
      }
    }
    cout<<"EQUAL"<<endl;
  }
}

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

const int INF=1e9+5;
const int N=300+5;
const int mod=1e9+7;

int cnt[4];
double p[N][N][N];
double dp[N][N][N];

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	// freopen("input.txt","r",stdin);
	int n;
	cin>>n;
	for(int i=1;i<=n;++i){
		int x;
		cin>>x;
		++cnt[x];
	}
	p[cnt[1]][cnt[2]][cnt[3]]=1;
	for(int k=n;k>=0;--k){
		for(int j=n;j>=0;--j){
			for(int i=n;i>=0;--i){
				if(!i&&!j&&!k) continue;
				if(i+j+k>n) continue;
				double p_waste=(double)(n-(i+j+k))/n;
				double H=p_waste/(1-p_waste);
				dp[i][j][k]+=H*p[i][j][k];
				if(i){
					p[i-1][j][k]+=p[i][j][k]*i/(i+j+k);
					dp[i-1][j][k]+=dp[i][j][k]*i/(i+j+k);
				}
				if(j){
					p[i+1][j-1][k]+=p[i][j][k]*j/(i+j+k);
					dp[i+1][j-1][k]+=dp[i][j][k]*j/(i+j+k);
				}
				if(k){
					p[i][j+1][k-1]+=p[i][j][k]*k/(i+j+k);
					dp[i][j+1][k-1]+=dp[i][j][k]*k/(i+j+k);
				}
			}
		}
	}
	cout<<setprecision(10)<<(dp[0][0][0]+cnt[1]+cnt[2]*2+cnt[3]*3);
	return 0;
}
		


Measured memory_bytes: 438528