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

using namespace std;

const int N = 1e5 + 5;
const int mod = 1e9 + 7;

int dp[N][2];
vector<int> g[N];

inline int add(int a, int b, int mod = mod) {
  a += b;
  if(a >= mod) a -= mod;
  if(a < 0) a += mod;
  return a;
}

inline int mul(int a, int b, int mod = mod) {
  return (long long) a * b % mod;
}

void dfs(int u, int p) {
  dp[u][0] = 1;
  dp[u][1] = 0;
  for(auto v: g[u]) {
    if(v != p) {
      dfs(v, u);
      int tmp = dp[u][0];
      dp[u][0] = mul(dp[u][0], dp[v][1]);
      dp[u][1] = add(mul(dp[u][1], add(dp[v][0], dp[v][1])), mul(tmp, dp[v][0]));
    }
  }
  dp[u][1] = add(dp[u][1], dp[u][0]);
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int n; cin >> n;
  for(int i = 0; i < n - 1; ++i) {
    int u, v; cin >> u >> v;
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  dfs(1, -1);
  cout << add(dp[1][0], dp[1][1]) << "\n";
}

Measured memory_bytes: 13440
import scala.annotation.tailrec
object Main extends App {

  import scala.io.StdIn._
  import scala.math._
  val s = readLine.trim
  val runLength = s.foldRight(Nil: List[JOI]){
    case ('J', J(l)::t) ⇒ J(l + 1)::t
    case ('O', O(l)::t) ⇒ O(l + 1)::t
    case ('I', I(l)::t) ⇒ I(l + 1)::t
    case ('J', t) ⇒ J(1)::t
    case ('O', t) ⇒ O(1)::t
    case ('I', t) ⇒ I(1)::t
    case _ ⇒ ???
  }
  println(
    countMaxK(runLength)
  )
  @tailrec
  def countMaxK(str: List[JOI], currentMax: Int = 0): Int = {
    str match {
      case J(j)::O(o)::I(i)::t if j >= o && o <= i ⇒ countMaxK(t, math.max(currentMax, o))
      case Nil ⇒ currentMax
      case h::t ⇒ countMaxK(t, currentMax)
    }
  }

  sealed trait JOI
  case class J(length: Int) extends JOI
  case class O(length: Int) extends JOI
  case class I(length: Int) extends JOI
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 112720
#include<stdio.h>

#define Max 200000
#define Sen 1000000000

typedef long long llong;

int count;
int l[Max / 2 + 2], r[Max / 2 + 2];

llong merge(int a[], int n, int left, int mid, int right){
  int n1, n2, i, j, k;
  llong count = 0;
  
  n1 = mid - left;
  n2 = right - mid;

  for(i = 0 ; i < n1 ; i++) l[i] = a[left + i];
  for(i = 0 ; i < n2 ; i++) r[i] = a[mid + i];
  l[n1] = r[n2] = Sen;

  i = j = 0;
  for(k = left ; k < right ; k++){
    if(l[i] <= r[j]){
      a[k] = l[i++];
    }
    else{
      a[k] = r[j++];
      count += n1- i;
    }
  }
  return count;
}


llong mergeSort(int a[], int n, int left, int right){
  int mid;
  llong v1, v2, v3;
  
  if(left + 1 < right){

    mid = (left + right) / 2;
    v1 = mergeSort(a, n, left, mid);
    v2 = mergeSort(a, n, mid, right);
    v3 = merge(a, n, left, mid, right);
    return v1 + v2 + v3;
  }
  else return 0;
}


int main(){
  int a[Max], n, i;
  count = 0;

  scanf("%d", &n);
  for(i = 0 ; i < n ; i++) scanf("%d", &a[i]);

  llong ans = mergeSort(a, n, 0 , n);

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 3344
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int happiness = 0;
        while (n >= 500) {
            happiness+=1000;
            n-=500;
        }
        while (n >= 5) {
            happiness+=5;
            n-=5;
        }
        System.out.println(happiness);
//        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
//        bw.write("\n");
//        bw.close();
    }

}

Measured memory_bytes: 21076
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = sc.nextInt();
		Long [] in = new Long [a];
        for(int i=0;i<a;i++){in[i] = sc.nextLong();
                            }
        Arrays.sort(in);
		Long c = in[0]-in[0];
        for(int i=0;i<a-b;i++){c+=in[i];}      
		System.out.println(c);
	}
}


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

int t[100002], x[100002], y[100002];
int main(){
	int n, f = 0;
	scanf("%d", &n);
	for(int i = 1;i <= n;i++){
		scanf("%d%d%d", &t[i], &x[i], &y[i]);
	}
	
	for(int i = 1;i <= n;i++){
		int t1 = abs(x[i]-x[i-1]);
		int t2 = abs(y[i]-y[i-1]);
		int t3 = abs(t[i]-t[i-1]);
		if(t3 < t1+t2 || (t3-(t1+t2))%2 == 1)f = 1;
		//printf("%d %d\n", t3, t1+t2);
	}
	
	if(f == 0)printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int main() {
	int a[3];

	cin >> a[0] >> a[1] >> a[2];

	sort(a, a+3);

	cout << a[0] <<" "<<a[1]<<" "<<a[2]<<endl;
	return 0;
}

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

using namespace std;



int main() {
  int n, ans=1, mx;
  cin >> n;
  cin >> mx;
  for (int i = 1; i < n; ++i) {
    int a;
    cin >> a;
    if (i && a>=mx) {
      mx = a;
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

int n, sum = 0;
bool dp[52][901][901];

signed main(){
    cin >> n;
    vector<int> t(n);
    rep(i, 0, n){
        cin >> t[i];
        sum += t[i];
    }
    sort(all(t));
    rep(i, 0, 51) rep(j, 0, 900) rep(k, 0, 900) dp[i][j][k] = false;
    dp[0][0][0] = true;
    rep(i, 0, n){
        rep(j, 0, 900){
            rep(k, 0, 900){
                if(dp[i][j][k]){
                    if(j + t[i] < 900) dp[i + 1][j + t[i]][k] = true;
                    if(k + t[i] < 900) dp[i + 1][j][k + t[i]] = true;
                    dp[i + 1][j][k] = true;
                }
            }
        }
    }
    int MIN = 1e8;
    rep(i, 0, 900){
        rep(j, 0, 900){
            if(dp[n][i][j] == false) continue;
            int tmp = sum - i - j;
            MIN = min(MIN, max(tmp, max(i, j)));
        }
    }
    cout << MIN << endl;
}

Measured memory_bytes: 43572
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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

ll gcd(ll a, ll b) {
  if(a < b) return gcd(b,a);
	if(a % b == 0) return b;
	else return gcd(b, a%b);
}

int main() {
	int n; cin >> n;
	ll ans = 0;
	rep1(i,n) rep1(j,n) rep1(k,n) ans += gcd(gcd(i,j),k);
	cout<< ans << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using ll = long long;
#define int ll
using namespace std;
int N, K;
priority_queue<pair<int, int>> q;
signed main()
{
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    int t, d;
    cin >> t >> d;
    q.push(make_pair(d, t));
  }
  vector<int> c(N + 1, 0);
  ll k = 0, res = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> mi;
  for (int i = 0; i < K; i++){
    auto x = q.top();
    q.pop();
    res += x.first;
    if (c[x.second] == 0){
      k++;
    }
    mi.push(x);
    c[x.second]++;
  }
  ll ma = res + k * k;
  for (int i = k + 1; i < K + 1; i++){
    while (c[mi.top().second] == 1) {
      mi.pop();
    }
    res -= mi.top().first;
    c[mi.top().second]--;
    mi.pop();
    while(!q.empty() && c[q.top().second]){
      q.pop();
    }
    if (q.empty()) {
      break;
    }
    res += q.top().first;
    c[q.top().second]++;
    q.top();
    ma = max(ma, res + i * i);
  }
  cout << ma << endl;
}

Measured memory_bytes: 5616
import java.util.Scanner;

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

	static Long[][] pre;
	private void solveA() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int P = sc.nextInt();
		int zeroNum = 0;
		int oneNum = 0;
		long ans = 0L;
		for (int i = 0; i < N; i++) {
			if (sc.nextInt() % 2 == 0) {
				zeroNum++;
			} else {
				oneNum++;
			}
		}
		pre = new Long[101][];
		for (int i = 0; i < 101; i++) {
			pre[i] = new Long[101];
		}
		for (int i = 0; i <= N; i++) {
			for (int z = 0; z <= i; z++) {
				int o = i - z;
				if (o % 2 == P) {
					ans += comb(zeroNum, z) * comb(oneNum, o);
				}
			}
		}
		System.out.println(ans);
	}

	private long comb(int A, int B) {
		if (pre[A][B] == null) {
			if (A < B) {
				return 0L;
			}
			if (B == 0) {
				return 1L;
			}
			if (A / 2 < B) {
				return comb(A, A - B);
			}
			pre[A][B] = comb(A - 1, B) + comb(A - 1, B - 1);
		}
		return pre[A][B];
	}
}

Measured memory_bytes: 22228
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }
const double EPS=1e-10;
int sig(double r){return (r<-EPS)?-1:(r>EPS)?:0;}
struct Pt{
	double x,y;
	Pt(){}
	Pt(double x,double y) : x(x),y(y){}
	Pt operator+(const Pt &a)const{return Pt(x+a.x,y+a.y);}
	Pt operator-(const Pt &a)const{return Pt(x-a.x,y-a.y);}
	Pt operator*(const Pt &a)const{return Pt(x*a.x-y*a.y,x*a.y+y*a.x);}
	double det(const Pt &a)const{return x*a.y-y*a.x;}
};
double tri(Pt a,Pt b,Pt c){return (b-a).det(c-a);}
bool iSSstrict(Pt a,Pt b,Pt c,Pt d){
	return ((sig(tri(a,b,c)))*sig(tri(a,b,d))<0&&(sig(tri(c,d,a)))*sig(tri(c,d,b))<0);
}
int main() {
	Pt a,b,c,d;
	for(;~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",&(a.x),&(a.y),&(b.x),&(b.y),&(c.x),&(c.y),&(d.x),&(d.y));){
		cout<<(iSSstrict(a,b,c,d)||iSSstrict(a,c,b,d)||iSSstrict(a,d,c,b)?"YES":"NO")<<endl;
	}
	return 0;
}

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

int main() {
	string S = "\0";
	int n = 0, ans = 0;
	cin >> S;
	for (int i = 0; i < 2; i++) {
		if (S[i] != S[i + 1])ans = 1;
	}
	if (ans == 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

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

const int mod = 1e9 + 7;

void add_self (int & a, int b) {
	a += b;
	if (a >= mod) a -= mod;
}

int mul (int a, int b) {
	return (int) (((ll) a * b) % mod);
}

int power (int a, int k) {
	int ans = 1;
	while (k >= 1) {
		if (k & 1) ans = mul (ans, a);
		a = mul (a, a);
		k >>= 1;
	}
	return ans;
}

int inverse (int a) {
	return power (a, mod - 2);
}

void max_self (int & a, int b) {
	if (a < b) a = b;
}

vector < pair < int, int > > toAdd = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

int main() {
	int h, w;
	cin >> h >> w;
	vector < string > maze (h);
	for (int i = 0; i < h; i++) {
		cin >> maze[i];
	}
	int ans = 0;
	auto isValid = [&] (int x, int y) {
		return x >= 0 && y >= 0 && x < h && y < w && maze[x][y] == '.';
	};
	for (int starti = 0; starti < h; starti++) {
		for (int startj = 0; startj < w; startj++) {
			if (maze[starti][startj] == '#') continue;
			queue < pair < int, int > > q;
			vector < vector < bool > > visited (h, vector < bool > (w));
			vector < vector < int > > d (h, vector < int > (w));
			d[starti][startj] = 0;
			visited[starti][startj] = true;
			q.push (make_pair (starti, startj));
			while (!q.empty()) {
				pair < int, int > u = q.front(); q.pop();
				max_self (ans, d[u.first][u.second]);
				for (pair < int, int > p : toAdd) {
					int x = u.first + p.first;
					int y = u.second + p.second;
					if (isValid (x, y) && !visited[x][y]) {
						d[x][y] = d[u.first][u.second] + 1;
						visited[x][y] = true;
						q.push (make_pair (x, y));
					}
				}
			}
		}
	}
	cout << ans << endl;			
	return 0;
}



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

template<typename integer>
integer __lcm(integer a, integer b) {
    return (a * b) / __gcd(a, b);
}

int main() {
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;

    int dx = gx - sx, dy = gy - sy;

    // first
    rep (i, dy) cout << 'U';
    rep (i, dx) cout << 'R';
    rep (i, dy) cout << 'D';
    rep (i, dx) cout << 'L';

    // second
    cout << 'L';
    rep (i, dy+1) cout << 'U';
    rep (i, dx+1) cout << 'R';
    cout << 'D';
    cout << 'R';
    rep (i, dy+1) cout << 'D';
    rep (i, dx+1) cout << 'L';
    cout << 'U' << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>
#include <cstring>

#define nl '\n'

using namespace std;

int h, n, a;

int main(){

    cin >> h >> n;
    
    for(int i = 0; i < n; i++){
        cin >> a;
        h = h - a;
        if(h <= 0){
            cout << "Yes";
            return 0;
        }
    }

    cout << "No";
}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int b[100001];
set<int> st;
int main(){
    int n,m,xi,yi;
    cin>>n>>m;
    rep(i,n) b[i]=1;
    st.insert(0);
    rep(i,m){
        cin>>xi>>yi;
        --xi,--yi;
        --b[xi];++b[yi];
        if(st.count(xi)>0) st.insert(yi);
        if(b[xi]==0) st.erase(xi);
        
    }
    cout<<st.size()<<endl;
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>

#include <sstream>
#include <string>
#include <vector>

#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

using std::ostringstream;
using std::string;
using std::vector;

using std::sort;

static string
solve(int N, int L, vector<string> &S)
{
  sort(S.begin(), S.end());
  ostringstream o;
  for (int n = 0; n < N; n++)
  {
    o.write(S[n].data(), S[n].size());
  }
  return o.str();
}

int
main()
{
  int N, L;
  cin >> N >> L;
  vector<string> S(N);
  for (int n = 0; n < N; n++)
  {
    cin >> S[n];
  }
  cout << solve(N, L, S) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b;
    int value;

    scanf("%d %d",&a,&b);
    if(a>=13)
    value=b;
    else if(6<=a && a<=12)
    value=b/2;
    else
    value=0;

    printf("%d\n",value);
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);

const double PI  = acos(-1.0);
using namespace std;
//typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 3000 + 9;
int n,m;
double a[N],mem[N][N];


double dp(int i, int h)
{
    if(i > n)
    {
        if( h > n-h) return 1;
        return 0;
    }
    if(mem[i][h] == mem[i][h])return mem[i][h];

    double c1 = a[i] * dp(i+1, h+1);
    double c2 = (1.0-a[i]) * dp(i+1, h);

    return mem[i][h] = c1 + c2 ;
}

 int main()
{
//freopen("calc.in","r",stdin);
//freopen("calc.out","w",stdout);
//__builtin_popcount()
input
        cin>>n;
        forr(i,1,n)cin>>a[i];

        memset(mem,-1,sizeof mem);
        cout<<fixed<<setprecision(9)<<dp(1,0)<<endl;






return 0;
}


Measured memory_bytes: 74788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){

      int n;
       cin>>n;

        int arr[n];

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

           int freq[1000001]={0};

          bool comm = false;
          bool all = false;

          for(int i=0;i<n;i++)
          {
              int x = arr[i];
                int flag = 0;
                while(x % 2==0)
                 {
                   flag=1;
                   x=x/2;
                 }
                  if(flag)
                 freq[2]++;

                 if(freq[2] > 1)
                   comm = true;

                 if(freq[2]== n)
                  all = true;

               for(int j=3;j<=sqrt(x);j+=2){

                     flag=0;
                     while(x % j==0)
                     {
                        flag=1;
                        x=x/j;
                     }
                     if(flag)
                     freq[j]++;

                     if(freq[j] > 1)
                      comm = true;

                      if(freq[j] == n)
                      all = true;
               }
               if(x > 2)
              {
                 freq[x]++;
                   if(freq[x] > 1)
                    comm = true;

                    if(freq[x]==n)
                     all = true;
              }
          }
             if(comm == true){

                   if(all == true)
                    cout<<"not coprime";

                    else
                   cout<<"setwise coprime";
             }
             else
              cout<<"pairwise coprime";

}

Measured memory_bytes: 11420
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int n,m;
const int MAX_N=100005;

int used[MAX_N];
int mark[MAX_N];
vector<int> child[100010];
void dfs(int start,int root){
    //cout<<used[start]<<start<<endl;
    if(used[start]==1) return ;
    mark[start]=root;
    for(int i=0;i<child[start].size();i++) dfs(child[start][i],root);
}
int main(){
    while(1){
        scanf("%d%d",&n,&m);
        if(n==0 and m==0)break;
        //map<int,vector<int> > child;
        //int used[MAX_N];
        //int mark[MAX_N];
        
        for(int i=0;i<MAX_N;i++){
            used[i]=0;
            mark[i]=0;
            child[i].clear();

        }
        

        for(int i=0;i<n-1;i++){
            int par;
            scanf("%d",&par);
            par--;
            child[par].push_back(i+1);
        }
        ll ans=0;
        used[0]=1;

        for(int i=0;i<m;i++){
            char a;
            int b;
            cin>>a>>b;
            b--;
            if (a=='Q') {
                ans+=(ll)(mark[b]+1);
            }
            else {
                dfs(b,b);
                used[b]=1;
                //for(int i=0;i<10;i++) cout<<mark[i]<<endl;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
    

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k,ans=0;
    cin >> n >> k;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a,a+n);
    for(int i=0;i<k;i++)
        ans+=a[i];
    cout << ans;
    return 0;
}

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

#define lli long long int
#define mod 1000000007

int main(){
	lli n,W;
	cin>>n>>W;
	lli a[n],w[n];
	for(int i=0;i<n;i++){
		cin>>w[i]>>a[i];
	}
	lli dp[W+1];
	memset(dp,0,sizeof(dp));
	for(int i=0;i<n;i++){
		for(int j=W;j>=w[i];j--){
			dp[j]=max(dp[j-w[i]]+a[i],dp[j]);
		}
	}
	cout<<dp[W]<<endl;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout<<fixed<<setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n = in(), u = in(), v = in(), m = in();

	map<ll, pair<ll, ll>>cood_usa;
	REP(i, n) {
		REP(j, n) {
			ll foo = in();
			cood_usa[foo] = make_pair(i, j);
		}
	}

	map<ll, pair<ll, ll>>cood_neko;
	REP(i, n) {
		REP(j, n) {
			ll foo = in();
			cood_neko[foo] = make_pair(i, j);
		}
	}

	vector<ll>card(m); REP(i, m) card[i] = in();

	ll usa_point = 0, neko_point = 0;
	bool usagi_win = false, neko_win = false;
	if (n == 1) {
		REP(i, m) {
			if (cood_usa.count(card[i]) == 1 && ++usa_point >= u) usagi_win = true;
			if (cood_neko.count(card[i]) == 1 && ++neko_point >= v)neko_win = true;
			if (usagi_win && !neko_win) {
				cout << "USAGI" << endl;
				break;
			} else if (!usagi_win && neko_win) {
				cout << "NEKO" << endl;
				break;
			} else if (usagi_win && neko_win) {
				cout << "DRAW" << endl;
				break;
			}
		}
	} else {
		vector<ll>usa_col(n, 0), usa_row(n, 0), neko_col(n, 0), neko_row(n, 0);
		ll usa_naname1 = 0, usa_naname2 = 0, neko_naname1 = 0, neko_naname2 = 0;
		REP(i, m) {
			if (cood_usa.count(card[i]) == 1) {
				auto cood = cood_usa[card[i]];
				if (cood.first == cood.second)++usa_naname1;
				if (cood.first + cood.second == n - 1)++usa_naname2;
				if (++usa_col[cood.second] == n)++usa_point;
				if (++usa_row[cood.first] == n)++usa_point;
				if (usa_naname1 == n) {
					++usa_naname1;
					++usa_point;
				}
				if (usa_naname2 == n) {
					++usa_naname2;
					++usa_point;
				}
				if (usa_point >= u) usagi_win = true;
			}
			if (cood_neko.count(card[i]) == 1) {
				auto cood = cood_neko[card[i]];
				if (cood.first == cood.second)++neko_naname1;
				if (cood.first + cood.second == n - 1)++neko_naname2;
				if (++neko_col[cood.second] == n)++neko_point;
				if (++neko_row[cood.first] == n)++neko_point;
				if (neko_naname1 == n) {
					++neko_naname1;
					++neko_point;
				}
				if (neko_naname2 == n) {
					++neko_naname2;
					++neko_point;
				}
				if (neko_point >= v)neko_win = true;
			}
			if (usagi_win && !neko_win) {
				cout << "USAGI" << endl;
				break;
			} else if (!usagi_win && neko_win) {
				cout << "NEKO" << endl;
				break;
			} else if (usagi_win && neko_win) {
				cout << "DRAW" << endl;
				break;
			}
		}
	}
	if (!usagi_win && !neko_win) {
		cout << "DRAW" << endl;
	}
}


Measured memory_bytes: 21032
import java.util.Scanner;

/**
 * https://beta.atcoder.jp/contests/abc103/tasks/abc103_c
 */

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();

        int ans = 0;
        for (int i = 0; i < num; i++) {
            ans += sc.nextInt();
        }

        System.out.println(ans - num);
    }
}


Measured memory_bytes: 26096
#include<bits/stdc++.h>
#define int long long
using namespace std;

int num , k , a[100005];

int dp[100005];

const int oo=1e9+7;

int Min(int a , int b)
{
	if(a>b)return b;
	else return a;
}

main()
{
	cin >> num >> k;
	for( int i=1 ; i <= num ; ++i )
	{
		cin >> a[i];
		dp[i]=oo;
	}
	dp[1]=a[1];
	dp[2]=abs(a[1]-a[2]);
    for(int i=3 ; i<=num ; i++)
    {
     	for(int j=1 ; j<=k ; j++)
     	{
     		if(i<=j)continue;
            if(i-j==1)dp[i]=Min(dp[i] , abs(a[i]-a[i-j]));
     		else dp[i]=Min(dp[i] , abs(a[i]-a[i-j])+dp[i-j]);
     	}
    }
    cout << dp[num]<<endl;
}

Measured memory_bytes: 5168
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100010
#define lowbit(i) i&-i
using namespace std;
typedef long long ll;
int n;
int l=0,r=0;
int a[maxn],pre[maxn*10],t[maxn*10];
int readint(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
void add(int i){
	while(i<=maxn*2){
		t[i]++;
		i+=lowbit(i);
	}
}
ll query(int i){
	ll ret=0;
	while(i>0){
		ret+=t[i];
		i-=lowbit(i);
	}
	return ret;
}
bool check(int mid){
	for(int i=1;i<=2*maxn;i++) t[i]=0;
	pre[0]=0;
	for(int i=1;i<=n;i++) pre[i]=pre[i-1]+(a[i]>=mid?1:-1);
	ll sum=0;
	for(int i=0;i<=n;i++){
		sum+=query(pre[i]+maxn);
		add(pre[i]+maxn);
	}
	return sum>=1ll*n*(n+1)/4;
}
int main(){
	n=readint();
	for(int i=1;i<=n;i++){
		a[i]=readint();
		r=max(r,a[i]);
	}
	int mid;
	while(l<=r){
		mid=(l+r)>>1;
		if(check(mid))
			l=mid+1;
	    else
			r=mid-1;
	}
	printf("%d",r);
	return 0;
}


Measured memory_bytes: 7168
import collections

n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = collections.Counter(a)
ans = 0
t=cnt.most_common()
if len(t) <= k:
    print(0)
    exit()

for i in range(k):
    ans += t[i][1]
print(n - ans)

Measured memory_bytes: 101448
n=int(input())
if(n>=400 and n<=599):
    print(8)
elif(n>=600 and n<=799):
    print(7)
elif(n>=800 and n<=999):
    print(6)
elif(n>=1000 and n<=1199):
    print(5)
elif(n>=1200 and n<=1399):
    print(4)
elif(n>=1400 and n<=1599):
    print(3)
elif(n>=1600 and n<=1799):
    print(2)
elif(n>=1800 and n<=1999):
    print(1)


Measured memory_bytes: 61952
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
 
using namespace std;
 
const int nil = -1;
 
struct Node
{
  int p;
  int lc;
  int rc;
};
   
class TreeWalk
{
public:
  int n;
  Node nds[25];
  int root;
  int solve();
  int preorder( int id );
  int inorder( int id );
  int postorder( int id );
};
 
int TreeWalk::solve()
{
  cin >> n;
 
  for ( int i = 0; i < n; ++i )
    {
      nds[i].p = nil;
      nds[i].lc = nil;
      nds[i].rc = nil;
    }
 
  int id, left, right;
   
  for ( int i = 0; i < n; ++i )
    {
      cin >> id >> left >> right;
      nds[id].lc = left;
      nds[id].rc = right;
      if ( left != nil )
        nds[left].p = id;
      if ( right != nil )
        nds[right].p = id;
    }
 
  for ( int i = 0; i < n; ++i )
    {
      if ( nds[i].p == nil )
        {
          root = i;
        }
    }
   
  cout << "Preorder" << endl;
  preorder( root );
  cout << endl;
  cout << "Inorder" << endl;
  inorder( root );
  cout << endl;
  cout << "Postorder" << endl;
  postorder( root );
  cout << endl;
  return 0;
}
 
int TreeWalk::preorder( int id )
{
  if ( id != nil )
    {
      cout << " " << id;
 
      preorder( nds[id].lc );
 
      preorder( nds[id].rc );
    }
 
  return 0;
   
}
 
int TreeWalk::inorder( int id )
{
  if ( id != nil )
    {
      inorder( nds[id].lc );
 
      cout << " " << id;
 
      inorder( nds[id].rc );
    }
 
  return 0;
}
 
int TreeWalk::postorder( int id )
{
  if ( id != nil )
    {
      postorder( nds[id].lc );
 
      postorder( nds[id].rc );
 
      cout << " " << id;
    }
 
  return 0;
}
 
int main()
{
 
  TreeWalk tw;
 
  tw.solve();
 
  return 0;
}

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

int num;
int a[21][21];

int retcost(int Island){
	int x=0;
	for(int i=1;i<=num;i++){
		if(a[Island][i]){
			a[i][Island]=0;
			x=max(x,a[Island][i]+retcost(i));
		}
	}
	return x;
}

int main(void){
	while(cin>>num,num){
		int I1,I2,t,ans,I[num+1]={},Cost=0;
		memset(a,0,sizeof(a));
		for(int i=1;i<num;i++){
			cin>>I1>>I2>>t;
			a[I1][I2]=a[I2][I1]=t;
			I[I1]++,I[I2]++;
			Cost+=t*2;
		}
		for(int i=1;i<=num;i++){
			for(int j=1;j<=num;j++){
				if((I[i]==1||I[j]==1)&&!((i==1&&I[i]==1)||(j==1&&I[j]==1))){
					Cost-=a[i][j]*2;
					a[i][j]=a[j][i]=0;
				}
			}
		}
		ans=Cost-retcost(1);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x){
    S[++top] = x;
}

int pop(){
    top--;
    return S[top+1];
}


int main(void){
    // Your code here!
    int  a,b;
    top = 0;
    char s[100];
    
    while(scanf("%s", s) != EOF){
        if(s[0] == '+'){
            a = pop();
            b = pop();
            push(a + b);
        }else if(s[0] == '-'){
            b = pop();
            a = pop();
            push(a - b);
        }else if(s[0] == '*'){
            a = pop();
            b = pop();
            push(a * b);
        }else{
            push(atoi(s));
        }
    }
    
    printf("%d\n", pop());
    
    return 0;
}



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

bool grid[10][10];
int dy[] = {1,0,-1,0,0}, dx[] = {0,1,0,-1,0};

void rev(int y,int x){
  for(int i=0;i<5;i++){
    int sy = y+dy[i], sx = x+dx[i];
    if(sy<0 || sx<0 || sy>=10 || sx>=10)continue;
    grid[sy][sx] = !grid[sy][sx];
  }
}

int main(){
  int t;
  bool tmp[10][10];
  int ans[10][10];

  cin >> t;
  while(t--){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++)cin >> tmp[i][j];
    }
    
    for(int i=0;i<(1<<10);i++){
      for(int j=0;j<10;j++){
	for(int k=0;k<10;k++)grid[j][k] = tmp[j][k];
      }

      for(int j=0;j<10;j++){
	if(i&(1<<j)){
	  rev(0,j);
	  ans[0][j] = 1;
	}else ans[0][j] = 0;
      }

      for(int j=1;j<10;j++){
	for(int k=0;k<10;k++){
	  if(grid[j-1][k]){
	    rev(j,k);
	    ans[j][k] = 1;
	  }else ans[j][k] = 0;
	}
      }

      bool f = false;
      for(int j=0;j<10;j++)f |= grid[9][j];
      if(!f)break;
    }

    for(int i=0;i<10;i++){
      for(int j=0;j<9;j++)cout << ans[i][j] << " ";
      cout << ans[i][9] << endl;
    }
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<string.h>
using namespace std;
int main(){
  char s[2000000];
  int len,a,z;
  int i=0;

  cin>>s;
  len=strlen(s);
  while(s[i]!='A'){
    i++;
  }
  a=i;
  i=len-1;
  while(s[i]!='Z'){
    i--;
  }
  z=i;
  cout<<z-a+1<<endl;
  return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k,w;
	string s;
	bool f=true;
	cin>>n>>k;
	vector<string>v(k);
	for(int i=0;i<k;i++)cin>>v.at(i);
	for(int i=n;i<100000;i++){
		w=i;
		s=to_string(w);
		for(int j=0;j<s.length();j++){
			for(int l=0;l<k;l++){
				if(s.substr(j,1)==v.at(l)){
					f=false;
				}
			}
		}
		if(f){
			cout<<i<<endl;
			return 0;
		}
		f=true;
	}
}


Measured memory_bytes: 384
#include <stdio.h>
#define min(x, y) ((x)>(y) ? (y) : (x))

int main(){
  int n;  scanf("%d", &n);
  int h[102] = {0};
  for(int i=1; i<=n; i++)  scanf("%d", h+i);
  int ans = 0, running = 1;
  while(running){
    running = 0;
    int start = 1,  mini = 102;
    while(h[start] == 0)  start++;
    for(int i=start; i<=n+1; i++)
      if(h[i] != 0){
	running = 1;
	mini = min(mini, h[i]);
      }else if(mini != 102){
	for(int j=i-1; h[j]!=0; j--)
	  h[j] -= mini;
	ans += mini;
	mini = 102;
      }
  }
  printf("%d\n", ans);
  return 0;
}


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


int main() 
{


    int N,M;

    cin >>N >> M;

    vector<int> S(M);
    vector<char> C(M);
    for(int i=0;i<M;i++){
        cin >> S.at(i) >> C.at(i);
    }

  	bool flag = false;
    for(int i=0;i<M;i++){
      for(int j=0;j<M;j++){
        if((S.at(i)==S.at(j))&&(C.at(i)!=C.at(j)))
        	flag = true;
      }
    }
  
  
    vector<char> number(N,'0');
    for(int i=0;i<M;i++){
        number.at(S.at(i)-1)=C.at(i);
    }

    bool test_flag=false;
    for(int i=0;i<M;i++){
            if(S.at(i)==1)
                test_flag=true;
    }
    if(test_flag==false)
        number.at(0)='1';

    if(M==0){
      if(N==1)
        cout << 0;
      else if(N==2)
        cout <<10;
      else if(N==3)
        cout <<100;
    }
  	else if((N==3&&number.at(0)=='0')||(N==2&&number.at(0)=='0')||flag ){
      cout << -1 << endl;
    }
    else
    {
  	  for(int i=0;i<N;i++){
	      cout << number.at(i);
      }
    }
    return 0;
}



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

int main()
{
    int N;
    cin >> N;
    vector<int> P, Q, A, B;
    for (int i = 0; i < N; ++i)
    {
        int temp;
        cin >> temp;
        P.push_back(temp);
    }
    for (int i = 0; i < N; ++i)
    {
        char temp;
        cin >> temp;
        Q.push_back(temp);
    }
    A = P;
    B = Q;
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int i = 1;
    do
    {
        if (A == P)
        {
            break;
        }
        ++i;
    } while (std::next_permutation(A.begin(), A.end()));
    int j = 1;
    do
    {
        if (B == Q)
        {
            break;
        }
        ++j;
    } while (std::next_permutation(B.begin(), B.end()));
    cout << abs(i - j) << endl;
}

Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	ma := getNextInt(scanner)
	mb := getNextInt(scanner)

	mm := make([]Medicine, n)

	dp := make([][][]int, n+1)

	a := 0
	b := 0
	for i := 0; i < n; i++ {
		mm[i].a = getNextInt(scanner)
		mm[i].b = getNextInt(scanner)
		mm[i].c = getNextInt(scanner)
		a += mm[i].a
		b += mm[i].b
	}

	for i := 0; i <= n; i++ {
		dp[i] = make([][]int, a+1)
		for ii := 0; ii <= a; ii++ {
			dp[i][ii] = make([]int, b+1)
			for iii := 0; iii <= b; iii++ {
				dp[i][ii][iii] = 1 << 30
			}
		}
	}

	dp[0][0][0] = 0
	for i := 1; i < n+1; i++ {
		for ii := 0; ii < a+1; ii++ {
			for iii := 0; iii < b+1; iii++ {
				dp[i][ii][iii] = dp[i-1][ii][iii]
				if mm[i-1].a > ii {
					continue
				}
				if mm[i-1].b > iii {
					continue
				}
				if dp[i][ii][iii] > dp[i-1][ii-mm[i-1].a][iii-mm[i-1].b]+mm[i-1].c {
					dp[i][ii][iii] = dp[i-1][ii-mm[i-1].a][iii-mm[i-1].b] + mm[i-1].c
				}
			}
		}
	}

	ans := -1
	for i := 1; i*ma <= a && i*mb <= b; i++ {
		if dp[n][i*ma][i*mb] == 1<<30 {
			continue
		}
		if ans == -1 || ans > dp[n][i*ma][i*mb] {
			ans = dp[n][i*ma][i*mb]
		}
	}

	fmt.Fprintln(writer, ans)

	writer.Flush()
}

// Medicine ...
type Medicine struct {
	a, b, c int
}


Measured memory_bytes: 23040
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>

using namespace std;

int main(){

    string S;cin>>S;

    int used[3];
    fill_n(used,3,0);
    REP(i,S.size())used[S[i]-'a']++;

    if(max({used[0],used[1],used[2]})-min({used[0],used[1],used[2]})<2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }


    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int h,w,m;
    cin >> h >> w >> m;
    int x[m],y[m];
    rep(i,m)cin >> x[i] >> y[i];

    set<P> s;
    rep(i,m)s.insert(P(x[i],y[i]));
    map<int,int> mpx;
    map<int,int> mpy;
    rep(i,m)mpx[x[i]]++;
    rep(i,m)mpy[y[i]]++;
    int mx=0,my=0;
    for(auto p:mpx)chmax(mx,p.second);
    for(auto p:mpy)chmax(my,p.second);
    vector<int> xc;
    vector<int> yc;
    for(auto p:mpx)if(p.second==mx)xc.push_back(p.first);
    for(auto p:mpy)if(p.second==my)yc.push_back(p.first);

    for(auto i:xc){
        for(auto j:yc){
            if(s.find(P(i,j))==s.end()){
                cout << mx+my << endl;
                return 0;
            }
        }
    }
    cout << mx+my-1 << endl;
    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> prime;
    bool primeArray[101] = {false};
    for (int i = 2; i <= 100; ++i) {
        if (!primeArray[i]) {
            prime.push_back(i);
            for (int j = i; j <= 100; j += i) {
                primeArray[j] = true;
            }
        }
    }
    int check[prime.size()];
    for (int i = 0; i < prime.size(); ++i) {
        check[i] = 0;
    }
    int N;
    cin >> N;
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 2; i <= N; ++i) {
        int temp = i;
        while (temp > 1) {
            for (int j = 0; j < prime.size(); ++j) {
                if (temp % prime[j] == 0) {
                    temp /= prime[j];
                    ++check[j];
                    break;
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < prime.size(); ++i) {
        if (check[i] >= 74) ++ans;
    }
    for (int i = 0; i < prime.size(); ++i) {
        for (int j = 0; j < prime.size(); ++j) {
            if (i == j) continue;
            if (check[i] >= 14 && check[j] >= 4) ++ans;
            if (check[i] >= 24 && check[j] >= 2) ++ans;
        }
    }
    for (int i = 0; i < prime.size(); ++i) {
        for (int j = i + 1; j < prime.size(); ++j) {
            for (int k = j + 1; k < prime.size(); ++k) {
                if (check[i] >= 4 && check[j] >= 4 && check[k] >= 2) ++ans;
                if (check[i] >= 4 && check[j] >= 2 && check[k] >= 4) ++ans;
                if (check[i] >= 2 && check[j] >= 4 && check[k] >= 4) ++ans;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include <string>
#include <utility>
#include<array>
#include<set>
#define EPS (1e-7)
using namespace std;




int main() {

	int N, ans = 0;
	cin >> N;
	set<int> a;
	int tempa;

	
	for (size_t i = 0; i < N; i++)
	{
		cin >> tempa;
		auto key = a.find(tempa);
		if (key == a.end()) {
			a.insert(tempa);
		}
		else {
			a.erase(key);
		}
	}

	ans = a.size();


	cout << ans <<endl;

	return 0;
}

Measured memory_bytes: 4864
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<string>
#define LL long long
#define li i<<1
#define ri i<<1|1
using namespace std;
inline LL read()
{
    char c=getchar();LL x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*f;
}
string a,b;
int main()
{
	cin>>a>>b;
	LL len=a.size(),ans=0;
	for(int i=0;i<len;++i){
		if(a[i]!=b[i])
			++ans;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3928
#include <iostream>

int main()
{
    int A, B;

    std::cin >> A >> B;

    if (A >= 13)
    {
        std::cout << B << std::endl;
    }
    else if (12 >= A && A >= 6)
    {
        std::cout << B / 2 << std::endl;
    }
    else
    {
        std::cout << 0 << std::endl;
    }

    return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pii;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define sz(a) ll(a.size())
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front 
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define debug(x) cout << '>' << #x << ':' << x << " ";
#define nl '\n'
#define INF 1000000000000000000
            // 1000000000000000000
            // 1000000000000000000
#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define int long long int

void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int mx = -INF;

    if(1){
        mx = max(mx, a * c);
        mx = max(mx, a * d);
        mx = max(mx, b * c);
        mx = max(mx, b * d);
        if(a!=b){
            mx = max(mx, (a+1)*c);
            mx = max(mx, (a+1)*d);
            mx = max(mx, (b-1)*c);
            mx = max(mx, (b-1)*d);
        }
        if(c!=d){
            mx = max(mx, (c+1)*a);
            mx = max(mx, (c+1)*b);
            mx = max(mx, (d-1)*a);
            mx = max(mx, (d-1)*b);
        }
        if(a!=b and c!=d){
            mx = max(mx, (c+1)*(a+1));
            mx = max(mx, (c+1)*(b-1));
            mx = max(mx, (d-1)*(a+1));
            mx = max(mx, (d-1)*(b-1));
        }
    }

    cout << mx << nl;
}
main()
{
    IO;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int T = 1;
    // cin >> T;
    fo(c, 1, T){
        solve();
        // cout<<"Case #"<<c<<": ";
    }
    return 0;
}

Measured memory_bytes: 3684
n,m = map(int,input().split())
arr = list(map(int,input().split()))
l = len(arr)

while m != 0 :
    arr.sort(reverse=True)
    j = arr[0] // 2
    for i in range(l):
            if arr[i] > j:
                if m != 0:
                    m -= 1
                else:
                    break
                arr[i] //= 2
            else:
                break
    if arr[0] == 0:
        break
            

print(sum(arr))        


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

const int maxn = 1e6 + 5;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    int bit = __builtin_popcount(n);
    if(bit == 1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
        int m = n;
        if(m % 2 == 0)
            m--;
        vector<int> g;
        for(int i = 1;i < 3;i++){
            cout << i << " " << i + 1 << endl;
            cout << n + i << " " << n + i + 1 << endl;
        }
        g.push_back(n + 2);
        cout << 3 << " " << n + 1 << endl;
        g.push_back(3);
        for(int i = 4;i <= m;i += 2){
            cout << n + 1 << " " << i << endl;
            cout << i << " " << i + 1 << endl;
            cout << n + 1 << " " << n + i + 1 << endl;
            cout << n + i + 1 << " " << n + i << endl;
            g.push_back(i);
            g.push_back(n + i + 1);
        }
        if(n % 2 == 0){
            for(int i = 2;i < n;i++){
                int to = n ^ 1 ^ i;
                if(to < n){
                    cout << n << " " << g[i - 2] << endl;
                    cout << n + n << " " << g[to - 2] << endl;
                    break;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3320
#include <iostream>

using namespace std;

bool isprime(int n) {
	if (n == 2) return true;
	if (n <= 1 || n % 2 == 0) return false;
	int i = 3;
	while (n >= i*i) {
		if (n % i == 0) return false;
		i += 2;
	}
	return true;
}

int main() {
	while (true) {
	int a, b, n;
	cin >> a >> b >> n;
	if (a == b && b == n && n == 0) break;
	int primenumber_counter = 0, res, cnt = 0;
	while (primenumber_counter != n) {
		res = a + b*cnt;
		if (isprime(res)) {
			++primenumber_counter;
		}
		++cnt;
	}
	cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




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

  ll N ; cin >> N ;
  vector<ll> a;
  rep(i,N){
    ll inp; cin >> inp;
    inp--;
    a.pb(inp);
  }

  ll ans = 0;
  rep(i,N){
    ll j = a[i];
    if(a[i] == j  && a[j] == i) ans ++;
  }

  cout << ans/2 << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1400
#include <iostream>

int main()
{
    std::int64_t A, B, C, K;
    std::cin >> A >> B >> C >> K;

    if(K <= A)
    {
        std::cout << K << std::endl;
    }
    else if(K <= A + B)
    {
        std::cout << A << std::endl;
    }
    else
    {
        std::cout << A - (K - A - B) << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3624