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



using namespace std;

int a[1000][1000];
int dp[1000][1000];

/*
int solve(int i,int j)
{
    
    if((i==0)&&(j==0))
    return 1;
else if(j==0){
    if(a[i-1][j]==1)
    return 0;
    else
 return solve(i-1,j)%1000000007;}
else if(i==0){
    
if(a[i][j-1]==1)
return 0;
else
return solve(i,j-1)%1000000007;
}
else{    
  if(a[i-1][j]==1&&a[i][j-1]==1)
  return 0;
  else if(a[i-1][j]==1)
  return solve(i,j-1)%1000000007;
  else if(a[i][j-1]==1)
  return solve(i-1,j)%1000000007;
   return (solve(i,j-1)+solve(i-1,j))%1000000007;
}
*/    
    
    
    
    





int main() {
int h,w;
cin>>h>>w;
string s[h];
for(int i=0;i<h;i++)
cin>>s[i];
for(int i=0;i<h;i++)
{
    for(int j=0;j<w;j++)
    {
        if(s[i][j]=='.')
        a[i][j]=0;
        else a[i][j]=1;
    }
}


for(int i=0;i<h;i++)
{
    for(int j=0;j<w;j++)
   { 
       if(i==0&&j==0)
       dp[i][j]=1;
       
       else if(i==0)
    {   if(a[i][j]==1)
       dp[i][j]=0;
        else dp[i][j]=dp[i][j-1];
   }
    else if(j==0)
    {if(a[i][j]==1)
    dp[i][j]=0;
    else dp[i][j]=dp[i-1][j];
   }
   else{
        if(a[i-1][j]==1&&a[i][j-1]==1)
        dp[i][j]=0;
        else if(a[i][j-1]==1)
        dp[i][j]=dp[i-1][j];
        else if(a[i-1][j]==1)
        dp[i][j]=dp[i][j-1];
        else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;       
       }
   }
}

cout<<dp[h-1][w-1];

return 0;
}

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

int main(){
  int x, a, b;
  cin >> x >> a >> b;
  if(b - a <= 0) cout << "delicious" << endl;
  else if(b - a <= x) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
set<int>  st[125];
int main()
{
  //freopen("input.txt","r",stdin);
   string s,t;
   cin>>s>>t;
   for(int i = 0;i<s.size();++i)
   {
       st[s[i]].insert(i);//储存s中每个字符发生的位置
   }
   int a = 0,b = 0;
   for(int i = 0;i<t.size();++i)
   {
       if(st[t[i]].empty()) return cout<<-1,0;//如果没有出现在s中的字符，肯定无解
       if(st[t[i]].lower_bound(b)==st[t[i]].end()) a++,b = 0;//二分查找>=b的位置是否存在t[i]，
                                                         //若没有则加一个字符串
       b = *st[t[i]].lower_bound(b);//找到该字符出现的下标位置
       b++;
   }
   cout<<a*s.size()+b<<endl;
}

Measured memory_bytes: 8492
from sys import stdin
input = stdin.readline

from collections import defaultdict

MAX = 10000
infty = -1

class Disjoint():
    def __init__():
        return

def getRoot(x):
    global v
    for _ in range(v+1):
        if dic[x]["parent"] == x:
            return x
        x = dic[x]["parent"]

def unite(x, y):
    r = getRoot(x)
    l = getRoot(y)
    a = dic[r]["rank"]
    b = dic[l]["rank"]

    if a == b:
        dic[r]["rank"] += 1
        dic[l]["parent"] = r

    elif a > b:
        dic[l]["rank"] = 0
        dic[l]["parent"] = r

    elif a < b:
        dic[r]["rank"] = 0
        dic[r]["parent"] = l

lines = stdin.readlines()
dic = defaultdict()
v, e = map(int, lines[0].split())
#E = [[lines[i+1].split()[0], lines[i+1].split()[1], lines[i+1].split()[2],] for i in range(e)]
E = [ list(map(int, lines[i+1].split())) for i in range(e)]
E = sorted(E, key=lambda x:x[2])

# Eの要素を整列
E = sorted(E, key=lambda x:x[2])
# V に対応した互に素な集合Sを生成する
for _ in range(v):
    dic[_] = {"rank":0,"parent":_}
# 辺の集合Kを空にする
k = 0
total = 0

for edge in E:
    if getRoot(edge[0]) != getRoot(edge[1]):
        unite(edge[0], edge[1])
        k += 1
        total += edge[2]

print(total)
    







Measured memory_bytes: 37716
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
using namespace std;
long long a[100000];
int main() {
	long long n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (long long j = n; j >= 1; j -= 1) {
		cout << a[j];
		if (j > 1) {
			cout << " ";
		}
	}
	cout << endl;
	return 0;
}





Measured memory_bytes: 3084
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var N = ReadText().ToCharArray();
            long sum = N.Sum(x => int.Parse(x.ToString()));
            if (sum % 9 == 0) { return "Yes"; }
            return "No";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 33764
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cctype>
using namespace std;

class DICE {
public:
	int face[7];
	int get;

	DICE() {}

	bool makesure(DICE c1, DICE c2) {
		for (int i = 1; i <= 6; i++) {
			for (int j = 1; j <= 4; j++) {
				if (c1.face[1] == c2.face[1] && c1.face[2] == c2.face[2])
					if (c1.face[3] == c2.face[3] && c1.face[4] == c2.face[4])
						if (c1.face[5] == c2.face[5] && c1.face[6] == c2.face[6]) {
							return true;
						}
				c1.roll();
			}
			if (i % 2) c1.round('W');
			else c1.round('N');
		}
		return false;
	}

	void roll() {
		get = face[2];
		face[2] = face[3];
		face[3] = face[5];
		face[5] = face[4];
		face[4] = get;
	}


	void round(char x) {
		switch (x) {
		case 'W':
			get = face[1];
			face[1] = face[3];
			face[3] = face[6];
			face[6] = face[4];
			face[4] = get;
			break;
		case 'N':
			get = face[1];
			face[1] = face[2];
			face[2] = face[6];
			face[6] = face[5];
			face[5] = get;
			break;
		}
	}
};

bool call(DICE c[], int N){
	for (int l = 0; l < N; l++) {
		for (int k = l + 1; k < N; k++) {
			if (c[l].makesure(c[l], c[k]))
				return true;
		}
	}
	return false;
}

int main() {
	int n;
	DICE dice[100];

	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 6; j++) {
			cin >> dice[i].face[j];
		}
	}

	if (call(dice, n))
		cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

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

string str;
int main(){
  cin >> str;
  for (int i=1;i<=str.length();i++){
    if (i%2==1){
      if (str[i-1]=='R'){
        continue;
      }
    }
    else{
      if (str[i-1]=='L'){
        continue;
      }
    }
    if (str[i-1] == 'U' || str[i-1] == 'D') {  //if element in s
      continue;
    }
    else{
      cout << "No";
      return 0;
    }
  }
  
  cout << "Yes";
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define elif else if
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    ll n; cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; ++i) {
        if (n % i == 0)ans += n / i - 1;
        else ans += n / i;
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 3652
require 'matrix'
include Math

R = 6378.1

until (given = $<.gets.split.map(&:to_f)) == [-1] * 4
  a, b, c, d = given.map {|a| a / 180 * PI}
  rot = ->(θ, n) {
    vx = [cos(θ) + n[0] * n[0] * (1 - cos(θ)),
          n[0] * n[1] * (1 - cos(θ)) - n[2] * sin(θ),
          n[2] * n[0] * (1 - cos(θ)) + n[1] * sin(θ)]
    vy = [n[0] * n[1] * (1 - cos(θ)) + n[2] * sin(θ),
          cos(θ) + n[1] * n[1] * (1 - cos(θ)),
          n[1] * n[2] * (1 - cos(θ)) - n[0] * sin(θ)]
    vz = [n[2] * n[0] * (1 - cos(θ)) - n[1] * sin(θ),
          n[1] * n[2] * (1 - cos(θ)) + n[0] * sin(θ),
          cos(θ) + n[2] * n[2] * (1 - cos(θ))]
    Matrix[vx, vy, vz]
  }
  calc = ->(θ, φ) {
    po = Vector[1, 0, 0]
    po = rot.(θ, [0, 0, 1]) * po
    n = po.cross(Vector[0, 0, 1])
    rot.(φ, n) * po
  }
  x1 = calc.(b, a)
  x2 = calc.(d, c)
  c = (x1 + x2) / 2
  θ = atan2((x1 - c).norm, c.norm) * 2
  puts (R * θ).round
end


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

int main(){
    ll x,y,a,b,c; cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c),pq(0);
    for(int i = 0; i < a;++i){
        cin >> p[i];
    }
    for(int i = 0; i < b;++i){
        cin >> q[i];
    }
    for(int i = 0; i < c;++i){
        cin >> r[i];
    }
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    sort(q.begin(),q.end());
    reverse(q.begin(),q.end());
    for(int i = 0;i < x;++i){
        pq.push_back(p[i]);
    }
    for(int i = 0;i < y;++i){
        pq.push_back(q[i]);
    }
    sort(pq.begin(),pq.end());
    sort(r.begin(),r.end());
    reverse(r.begin(),r.end());
    for(int i = 0;i < min(x+y,c);++i){
        pq[i] = max(pq[i],r[i]);
    }
    ll ans = 0;
    for(int i = 0;i < x+y;++i){
        ans += pq[i];
    }
    cout << ans << endl;
}

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

#define ll long long
//~ #define endl '\n'

void solve(){
	int n, ans = 0; cin>>n;
	unordered_map< string, int > m, vis;
	vector< string > s(n), v;
	for(int i = 0; i<n; i++){
		cin>>s[i];
		m[s[i]]++;
		ans = max(m[s[i]], ans);
	}
	for(int i = 0; i<n; i++){
		if(m[s[i]] == ans && vis[s[i]] == 0){
			v.push_back(s[i]);
			vis[s[i]]++;
		}
	}
	sort(v.begin(), v.end());
	for(string i : v) cout<<i<<endl;
}

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


Measured memory_bytes: 44640
A,B,M=map(int,input().split())
*a,=map(int,input().split())
*b,=map(int,input().split())
xyc = [tuple(map(int,input().split())) for _ in range(M)]

ans = min(a)+min(b)
for i in range(M):
  x,y,c=xyc[i]
  ans = min(ans,a[x-1]+b[y-1]-c)
  
print(ans)

Measured memory_bytes: 33852
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,i,j,x,y,k,ans,curr,temp,m,s;
    int tc;
    ll hp;
    ll chaeng;
    cin >> hp;
    ll now = 0;
    while(hp > 0)
    {
        hp /= 2;
        now++;
    }
    chaeng = 1LL << now;
    chaeng--;
    cout << chaeng << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,c,d,s;
	scanf ("%d%d%d%d",&a,&b,&c,&d);
	if(a*b<=c*d) s=c*d;
	else s=a*b;
	printf("%d",s);
	return 0;
} 

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

int main(){
    long long x,y,a,b,ans,count=0;
    cin>>x>>y;

    while(x--)
    {
        cin>>a>>b;
        if(a*a + b*b<=y*y)
            count++;
    }
    cout<<count<<endl;

    return 0;


}


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

for h in range(1, 3501):
    for n in range(h, 3501):
        x = 4*h*n-N*n-N*h
        if x <= 0:
            continue
        else:
            if (N*h*n)%x == 0:
                print(h, n, (N*h*n)//x)
                exit()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<pll> vp;

const ll mod = 1e9+7;
inline ll lcm(ll a, ll b){return a/__gcd(a,b)*b;}

class SegmentTree{
  int n;
  vp node;
public:
  SegmentTree(vp a){
    int n_ = a.size();
    n=1;
    while(n<n_)n*=2;
    node.resize(2*n-1, pll(1, 0));
    for(int i=0;i<n_;i++)node[n-1+i] = a[i];
    for(int i=n-2;i>=0;i--){
      pll vl = node[2*i+1], vr = node[2*i+2];
      ll len = lcm(vl.first, vr.first);
      ll cost = ( (len/vl.first%mod) * vl.second) + ( (len/vr.first%mod) * vr.second);
      node[i] = pll(len,cost%mod);
    }
  }
  
  pll INTV_LCM(int a,int b,int k=0,int l=0,int r=0){
    if(l>=r)r = n;
    if(r<=a || b<=l)return pll(1,0);
    if(a<=l && r<=b)return node[k];
    pll vl = INTV_LCM(a,b,2*k+1,l,(l+r)/2);
    pll vr = INTV_LCM(a,b,2*k+2,(l+r)/2,r);
    ll len = lcm(vl.first, vr.first);
    ll cost = ( (len/vl.first%mod) * vl.second) + ( (len/vr.first%mod) * vr.second);
    return pll(len, cost%mod);
  }
};

int main(){
  int n,q;
  scanf("%d%d",&n,&q);
  vector<int> p(n+1);
  for(int i=1;i<=n;i++)scanf("%d",&p[i]);

  vector<pll> val(n);
  vector<int> use(n+1,0);
  for(int i=1;i<=n;i++){
    if(!use[i]){
      int cur = i;
      ll len = 0, sum = 0;
      
      do{
	len++; sum += p[cur];
	cur = p[cur];
      }while(cur != i);
      
      do{
	val[cur-1] = pll(len,sum%mod);
	use[cur] = 1;
	cur = p[cur];
      }while(cur != i);
    }
  }

  SegmentTree st(val);
  for(int i=0;i<q;i++){
    int l,r;
    scanf("%d%d",&l,&r);
    printf("%lld\n",(st.INTV_LCM(l-1,r)).second);
  }
}

Measured memory_bytes: 9108
#include <iostream>
#include <string>
#include <queue>

using namespace std;

int main(){
	int input;
	priority_queue<int> pq;
	string operation;
	while(true){
		cin >> operation;
		if (operation == "end"){ break; }
		else if (operation == "extract"){ cout << pq.top() << endl; pq.pop();  }
		else if (operation == "insert"){
			int input;
			cin >> input;
			pq.push(input);
		}
	}

	
	return 0;


}

Measured memory_bytes: 6772
import sys
sys.setrecursionlimit(100000000)


h, w = map(int, input().split())
s_array = ["+" * (w + 2)]
for i in range(h):
    s_array.append("+" + input() + "+")
else:
    s_array.append("+" * (w + 2))
moving = [[0, 1], [0, -1], [1, 0], [-1, 0]]
visit = [[False for x in range(w+2)] for x in range(h+2)]


def recursive(mark_point, mark_sharp, row, point):
    # 訪問済みならreturn
    if visit[row][point]:
        return mark_point, mark_sharp
    else:
        visit[row][point] = True

    for x, y in moving:
        # 範囲外かどうかと連結かどうか
        if s_array[row + x][point + y] != "+" and s_array[row + x][point + y] != s_array[row][point]:
            if visit[row+x][point+y]:
                continue
            # 移動先のマークの確認
            if s_array[row + x][point + y] == "#":
                mark_sharp += 1
            else:
                mark_point += 1
            mark_point, mark_sharp = recursive(mark_point, mark_sharp, row + x, point + y)
    else:
        return mark_point, mark_sharp


res = 0
for row in range(1, h + 1):
    for point in range(1, w + 1):
        m, n = recursive(s_array[row][point].count("."), s_array[row][point].count("#"), row, point)
        res += m*n
print(res)

Measured memory_bytes: 165936
import random
import time
import copy
import math
start=time.time()
d=int(input())
c=list(map(int,input().split()))
s=[]
cli=[]
for i in range(d+1):
  ch=[]
  for j in c:
    ch.append(i*j)
  cli.append(ch)
for i in range(d):
  s.append(list(map(int,input().split())))
last=[0]*26
score=0
solution=[]
for day in range(1,d+1):
  co=[]
  dla=[]
  down=0
  for (i,j) in zip(last,c):
    down+=(day-i)*j
  for (i,j) in zip(last,c):
    dla.append(down-(j*(day-i)))
  for con in range(26):
    co.append(s[day-1][con]-dla[con])
  choice=co.index(max(co))
  score+=co[choice]
  last[choice]=day
  #print(choice+1)
  #print(score)
  solution.append(choice)
#print(score)
stemp=1000000
etemp=1000
def tem():
  return stemp-((stemp-etemp)*(time.time()-start)/1.9)
while time.time()-start<1.9:
  
  sc=0
  sol=copy.deepcopy(solution)
  for x in [random.randrange(d) for i in range(5)]:
    sol[x]=random.randrange(26)
  last=[0]*26
  for (day,i) in zip(range(1,d+1),sol):
    sc+=s[day-1][i]
    last[i]=day
    for (i,j) in zip(last,range(26)):
      sc-=cli[day-i][j]
  try:
    prob = math.exp((sc-score)/tem())
  except:
    prob=0
  #print("{} {}".format(sc,prob))
  if prob>random.random():
    solution=copy.deepcopy(sol)
    score=sc
    #print(score)
for i in solution:
  print(i+1)
#print(sco)

Measured memory_bytes: 10552
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)


constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;



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

	ll n, k; cin >> n >> k;
	vector<ll> a(n);
	rep(i, 0, n) cin >> a[i];

	ll ans = 0;
	rep(i, 0, n) {
		ll cnt = 0;
		rep(j, i + 1, n) if (a[i] > a[j]) ++cnt;
		ans += cnt * k;
		ans %= MOD;
	}

	rep(i, 0, n) {
		ll cnt = 0;
		rep(j, 0, n) if (a[i] > a[j]) ++cnt;
		ans += k * (k - 1) / 2 % MOD * cnt % MOD;
		ans %= MOD;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3668
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

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

        int N = scan.nextInt();
        int[] a = IntStream.range(0,N).map(i -> scan.nextInt()).toArray();
        Map<Integer,Integer> map = new HashMap<>();
        for(int i=0;i<N;++i){
            if(!map.containsKey(a[i])){
                map.put(a[i],0);
            }
            map.put(a[i],map.get(a[i])+1);
        }

        int ans = 0;
        for(Map.Entry<Integer,Integer> entry : map.entrySet()){
            if(entry.getKey() > entry.getValue()){
                ans+=entry.getValue();
            }else{
                ans+=entry.getValue()-entry.getKey();
            }
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 61032
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;
import java.util.ArrayList;

public class Main{

    public static void main(String[] args){
        //START

        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();

        int i=0;
        int j=0;
        int S=0;

        roopout:
        for(i=1;i<=9;i++){
            for(j=1;j<=9;j++){
                S=i*j;

                if(S==N){
                    System.out.println("Yes");
                    break roopout;
                }
            }
            if(i>=9&&j>=9){
                System.out.println("No");
            }
        }
        //END
    }
}



Measured memory_bytes: 23252
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
int main(){
  ll a,b,c,k;
  cin >> a >> b >> c >> k;
  ll sum = 0;

  if(a >= k){
    sum += k;
    k = 0;
  }else{
    sum += a;
    k -= a;
  }

  if(k > 0){
    if(b >= k){
      k = 0;
    }else{
      k -= b;
    }
  }

  if(k > 0){
    if(c >= k){
      sum -= k;
    }else{
      sum -= c;
    }
  }

  cout << sum << endl;

}


Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>

using namespace std;

#define ll long long
#define ull unsigned long long
const ll MOD = 1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
	string S;
	cin >> S;
	int N = S.size();

	int cnt = 0;
	stack<int> st;
	for (int ii = 0; ii < N; ++ii){
		int val = S[ii] - '0';
		if (st.size()==0){
			st.push(val);
		} else {
			int top = st.top();
			if (top ^ val == 1){
				cnt += 2;
				st.pop();
			} else {
				st.push(val);
			}
		}
	}

	cout << cnt << "\n";

	return 0;
}


Measured memory_bytes: 4132
/*░░░░░░░▄▄▄▀▀▀▄▄███▄
░░░░░▄▀▀░░░░░░░▐░▀██▌
░░░▄▀░░░░▄▄███░▌▀▀░▀█
░░▄█░░▄▀▀▒▒▒▒▒▄▐░░░░█▌
░▐█▀▄▀▄▄▄▄▀▀▀▀▌░░░░░▐█▄
░▌▄▄▀▀░░░░░░░░▌░░░░▄███████▄
░░░░░░░░░░░░░▐░░░░▐███████████▄
░░░░░le░░░░░░░▐░░░░▐█████████████▄
░░░░toucan░░░░░░▀▄░░░▐██████████████▄
░░░░░░has░░░░░░░░▀▄▄████████████████▄
░░░░░arrived░░░░░░░░░░░░█▀██████*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int cnt[107];
int a[107];
int main()
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	int n;
	scanf("%d", &n);
	int mx = 0;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		mx = max(mx, a[i]);
		cnt[a[i]]++;
	}
	if (cnt[mx] == 1)
	{
		printf("Impossible\n");
		return 0;
	}
	int rads = cnt[mx];
	int togo = (mx + 1) / 2;
	for (int it = 1; it <= rads; it++)
	{
		for (int j = mx; j > togo; j--)
		{
			if (cnt[j] == 0)
			{
				printf("Impossible\n");
				return 0;
				cnt[j]--;
			}
		}
	}
	for (int i = 0; i < togo; i++)
	{
		if (cnt[i] > 0)
		{
			printf("Impossible");
			return 0;
		}
	}
	if (mx % 2 == 0 && cnt[togo] != 1)
	{
		printf("Impossible\n");
		return 0;
	}
	if (mx % 2 == 1 && cnt[togo] != 2)
	{
		printf("Impossible\n");
		return 0;
	}
	printf("Possible\n");
	return 0;
}


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

std::string ten_to_n(int ten,int base){
    if(ten == 0)return "0";
    std::string s;
    while(ten){
        int amari = ten % base;
        char c = '0' + amari;
        s.push_back(c);
        ten /= base;
    }
    std::reverse(s.begin(),s.end());
    return s;
}

int main()
{
    int n;
    std::cin>>n;
    int min = 1000000;
    for(int i=0;i<=n;i++){
        std::string s = ten_to_n(i,6);
        std::string ni = ten_to_n(n-i,9);
        int cnt = 0;
        for(auto c : s)cnt += c - '0';
        for(auto c : ni)cnt += c - '0';
        min = std::min(cnt,min);
    }
    std::cout<<min<<std::endl;
}

Measured memory_bytes: 256
n, x, y = map(int, input().split())

ret = [0] * (n-1)
for s in range(1,n):
    for e in range(s+1,n+1):
        d = min(e-s, abs(s-x) + abs(e-y) +1)
        ret[d-1] += 1
for r in ret:
    print(r)

Measured memory_bytes: 3572
N, Q = map(int, input().split())
edges = [[] for _ in range(N)]
count = [0]*N

for _ in range(N-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

for _ in range(Q):
    p, x = map(int, input().split())
    count[p-1] += x

not_yet = [1]*N
not_yet[0] = 0
stack = [0]

while stack:
    parent = stack.pop()
    # print(parent)
    
    for child in edges[parent]:
        if not_yet[child]:
            count[child] += count[parent]
            not_yet[child] = 0
            stack.append(child)

print(*count)

Measured memory_bytes: 55824
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int n = Integer.parseInt(tmpArray[0]);
		int q = Integer.parseInt(tmpArray[1]);
		
		DisjointSet set = new DisjointSet(n);
		
		for(int i = 0; i < q; i++){
			tmpArray = br.readLine().split(" ");
			
			int x = Integer.parseInt(tmpArray[1]);
			int y = Integer.parseInt(tmpArray[2]);
			
			if(tmpArray[0].equals("0")){
				set.union(x, y);
			}
			else {
				boolean result = set.isSameSet(x, y);
				if(result == true){
					System.out.println(1);
				}
				else {
					System.out.println(0);
				}
			}
		}
	}

}

class DisjointSet {
	private int n;
	private int[] p;
	private int[] rank;

	public DisjointSet(int n){
		this.n = n;

		p = new int[n + 1];
		rank = new int[n + 1];

		for(int i = 1; i <= n; i++){
			makeSet(i);
		}
	}

	private void makeSet(int x){
		p[x] = x;
		rank[x] = 0;
	}

	public void union(int x, int y){
		link (findSet(x), findSet(y));
	}

	private int findSet(int x){
		if(x != p[x]){
			p[x] = findSet( p[x]);
		}
		return p[x];
	}

	public boolean isSameSet(int x, int y){
		return findSet(x) == findSet(y);
	}

	private void link(int x, int y){
		if(rank[x] > rank[y]){
			p[y] = x;
		}
		else {
			p[x] = y;
			if(rank[x] == rank[y]){
				rank[y]++;
			}
		}
	}
}

Measured memory_bytes: 64276
#include <iostream>
#include <map>

using namespace std;

int main() {
    int N;
    cin >> N;
    map<int, int> mp;
    for(int n=0; n<N; n++) {
        int A;
        cin >> A;
        mp[A]++;
    }

    int cnt=0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        if(itr->second%2==0) {
            cnt++;
        }
    }
    if(cnt%2) {
        cout << mp.size()-1 << endl;
    } else {
        cout << mp.size() << endl;
    }

    return 0;
    
}

Measured memory_bytes: 4992
#include<iostream>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
stack<int> S;
int a,b,x;
char s[1000500];
int main(){
	while(cin>>s){
		if(s[0]=='+'){
			a=S.top();
			S.pop() ;
			b=S.top() ;
			S.pop() ;
			S.push(a+b);  
		}
		else 
		if(s[0]=='-'){
			a=S.top();
			S.pop() ;
			b=S.top() ;
			S.pop() ;
			S.push(b-a);  
		}
		else
		if(s[0]=='*'){
			a=S.top();
			S.pop() ;
			b=S.top() ;
			S.pop() ;
			S.push(a*b);  
		}
		else{
			S.push(atoi(s)); 
		}
	}
    printf("%d\n",S.top());
    return 0;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int MAX = 200010;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
long long COM(int n, int k) {
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    long long n, m, k;
    cin >> n >> m >> k;
    long long pow[n];
    long long factor = 1;
    for (long long i = 0; i < n; i++){
        pow[i] = factor;
        factor = (factor * (m-1)) % MOD;
    }
    COMinit();

    long long ans = 0;
    for (int i = 0; i <= k; i++)
    {
        long long sum = (pow[n-1-i] * COM(n-1, i)) % MOD;
        ans = (ans + sum) % MOD;
    }

    cout << (ans * m) % MOD << endl;
    return 0;
}

Measured memory_bytes: 9824
#include<iostream>
#include<set>

using namespace std;

int main(){
  int s; cin >> s;
  int c = s; set<int> st;
  while( st.count(c) == 0){
    st.insert(c);
    if( c % 2 == 0){ c /= 2;}
    else{ c = 3 * c + 1;}}
  
  cout << (int) st.size() + 1 << endl;
  
  return 0;
}
  

Measured memory_bytes: 256
def examC(mod):
    N = I()
    A = LI()
    num = (N+1)%2
    loop = (N+1)//2
    cur = int(1)
    L = [0]*loop
    if num==0:
        L[0] +=1
    for i in range(N):
        L[A[i]//2] += 1
        if L[A[i]//2]>=3:
            cur = int(0)
            break
    for _ in range(N//2):
        cur = (cur*2)%mod
    print(cur)





import sys
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC(mod)


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

long long mod=1000000007;

long long bigmod(long long n,long long p)
{
     if(p==0)return 1;
     if(p%2==0)
     {
         long long ret=bigmod(n,p/2);
         return ((ret%mod)*(ret%mod))%mod;
     }
     else
        return ((n%mod)*(bigmod(n,p-1)%mod))%mod;
}

long long ara[100005];

int main()
{

    long long n,k,i,j,lp,ans=0,fr,sc,tr,p,q,r,z;

    scanf("%lld %lld",&n,&k);

    for(i=k;i>=1;i--)
    {

        p=k/i; fr=bigmod(p,n);

        sc=ara[i];

        if(fr>=sc)tr=fr-sc;
        else{ tr=(mod-sc)+fr;  }

        z=(tr*i)%mod;
        ans=(ans+z)%mod;

        for(j=1;j*j<=i;j++)
        {
            if(i%j==0)
            {
                ara[j]=(ara[j]+tr)%mod;

                r=i/j;

                if(r!=i && r!=j)
                {
                    ara[r]=(ara[r]+tr)%mod;
                }

            }

        }

    }

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


    return 0;
}


Measured memory_bytes: 4172
#include <iostream>
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <cstdio>
#include <math.h>
#include <map>
#include <algorithm>
#include <deque>
#include <stack>
#include<set>
//#include <bits/stdc++.h>
#define lson l,mid,rt<<1

#define rson mid+1,r,rt<<1|1

const int N=1e5+100;
using namespace std;

typedef long long ll;
const int inf=0x3f3f3f3f;

ll dp[N][5];
int main()
{
   int n;scanf("%d",&n);
   int x,y,z;
   for(int i=1;i<=n;i++){
    scanf("%d%d%d",&x,&y,&z);
    dp[i][1]=max(dp[i-1][2]+x,dp[i-1][3]+x);
    dp[i][2]=max(dp[i-1][1]+y,dp[i-1][3]+y);
    dp[i][3]=max(dp[i-1][1]+z,dp[i-1][2]+z);
    }
    ll ans=0;
    ans=max(dp[n][1],max(dp[n][2],dp[n][3]));
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
    /*input*/
    int a,b;	cin >> a >> b;
    /*calculation*/
    int ans = 0;
    for(int length = 1; length < b;ans++){
	if(length == 1)length = a;
	else length += a-1;
    }
    /*output*/
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>

using namespace std;

int GCD(int x, int y) {

	while (y > 0) {
		int r = x % y;
		x = y;
		y = r;
	}

	return x;
}

int main() {

	int x, y;
	scanf("%d %d", &x, &y);

	cout << GCD(x, y) << endl;
	return 0;
}

Measured memory_bytes: 3128
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;



int main(){
    string s ;
    cin >> s ;
    vector<int> mod3(s.size()+1) ;
    vector<int> mod673(s.size()+1) ;
    mod3.at(s.size()) = 0 ;
    mod673.at(s.size()) = 0 ;
    int p10 = 1 ;
    for (size_t i = 0; i < s.size(); i++)
    {
        if (i > 0)
        {
            p10 *= 10 ;
            if (p10 > 672)
            {
                p10 %= 673 ;
            }
            
        }
        int j = s.size() - 1 -i ;
        int num = s.at(j) - '0' ;
        mod673.at(j) = (mod673.at(j+1) + num*p10) % 673 ;
        mod3.at(j) = (mod3.at(j+1) + num) % 3 ;
    }
    vector<vector<int> > table(3,vector<int>(673,0)) ;
    for (size_t i = 0; i < s.size()+1; i++)
    {
        table.at(mod3.at(i)).at(mod673.at(i)) ++;
    }
    int ans = 0 ;
    for (size_t i = 0; i < 3; i++)
    {
        for (size_t j = 0; j < 673; j++)
        {
            int p = table.at(i).at(j) ;
            ans += p*(p-1) / 2 ;
        }
        
    }
    cout << ans << endl ;
}

Measured memory_bytes: 5204
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int N, T; cin >> N >> T;
    int dp[T+3001] = {};
    pair<int, int> a[N]; for (int i = 0; i < N; i++) cin >> a[i].first >> a[i].second;
    sort(a, a+N);
    for (int i = 0; i < N; i++) {
        for (int t = T-1; t >= 0; t--)
            dp[t+a[i].first] = max(dp[t+a[i].first], dp[t] + a[i].second);
    }
    cout << *max_element(dp, dp+T+3001) << endl;
}


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

using namespace std;

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

const ll maxn =8e5+5;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int n;

int main(){
    migmig
    cin >> n;
    int a[10][10] , b =0 , c;
    int cnt =0;
    ms(a , 0);
    for (int i = 0 ; i < n ; i ++){
        cnt = i + 1;
        b = cnt%10;
        while(cnt){
            c = cnt%10;
            cnt/=10;
        }
        a[c][b]++;
    }
    int ans=  0;
    for (int i = 0 ; i < 10 ; i ++)
{
    for (int j = 0 ; j < 10 ; j ++){
        ans+=a[i][j]*a[j][i];
    }
}
    cout << ans;
    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <set>

using namespace std;

struct union_find {
    vector<int> par, sz;

    union_find(int n) {
        par.resize(n);
        sz.resize(n);
        for (int i = 0; i < n; i++)
            par[i] = i, sz[i] = 0;
    }

    int find(int x) {
        if (par[x] == x)
            return x;
        else 
            return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);

        if (x == y) return ;

        else if (sz[x] < sz[y])
            par[x] = y;
        else {
            par[y] = x;
            if (sz[x] == sz[y])
                sz[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};


int main() {
    int N, M, K;    cin >> N >> M >> K;
    struct union_find fr(N);
    vector<int> cnt(N, 0);
    for (int i = 0; i < M; i++) {
        int a, b;   
        cin >> a >> b; a--;    b--;
        cnt[a]++;
        cnt[b]++;
        fr.unite(a, b);
    }

    vector<vector<int> > G(N);
    for (int i = 0; i < K; i++) {
        int c, d;   cin >> c >> d;
        c--;    d--;
        G[c].push_back(d);
        G[d].push_back(c);
    }

    map<int, int> m;
    for (int i = 0; i < N; i++) {
        m[fr.find(i)]++;
    }

    for (int i = 0; i < N; i++) {
        int ans = m[fr.find(i)] - cnt[i]-1;
        for (int j = 0; j < G[i].size(); j++) {
            int v = G[i][j];
            if (fr.same(v, i))
                ans--;
        }
        cout << ans << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 9984
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		int min = 1001, max = -1;
		for(int i = 0; i < N; i++){
			int a = in.nextInt();
			min = Math.min(min, a);
			max = Math.max(max, a);
		}
		System.out.println(max-min);
	}
}


Measured memory_bytes: 22996
// Author: Shusuke Ueda
// AtCoder Beginner Contest 134 - Problem E

#include <iostream>
#include <vector>
#include <set>

int main() {
    int n;
    std::cin >> n;
    std::vector<int> a(n);
    for (auto& e: a) {
        std::cin >> e;
    }

    std::multiset<int> s;
    for (auto e: a) {
        auto it = s.lower_bound(e);
        if (it == s.begin()) {
            s.insert(e);
        } else {
            it--;
            s.erase(it);
            s.insert(e);
        }
    }

    std::cout << s.size() << std::endl;

    return 0;
}

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

#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define int               long long
#define fr                first
#define sc                second
#define vc                vector
#define endl              '\n'
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define LSB(i)            ((i)&-(i))

template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve()
{
    int x, y, z;
    cin >> x >> y >> z;
    int sum = x + y + z;
    if(sum>=22)
    {
    cout<<"bust";
    }
    else
    cout<<"win";
}
signed main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, K, a[1005], topp = 0;
ll val[1000005], cur = 0, ans = 0;

int main(){
	getint(N), getint(K);
	for(register int i = 1; i <= N; i++) getint(a[i]);
	for(register int i = 1; i <= N; i++, cur = 0)
		for(register int j = i; j <= N; j++) val[++topp] = cur += a[j];
	for(register int ex = 39; ex >= 0; ex--){
		register int cnt = 0;
		for(register int i = 1; i <= topp; i++) if(val[i] & (1LL << ex)) cnt++;
		if(cnt < K) continue; ans += 1LL << ex, cnt = 0;
		for(register int i = 1; i <= topp; i++) if(val[i] & (1LL << ex)) val[++cnt] = val[i];
		topp = cnt;
	}
	return printf("%lld\n", ans), 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int c=-1,b=1;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
  	cin >> vec.at(i);
  }
  while (b) {
    for (int i=0; i<N; i++) {
      if(vec.at(i)%2 == 1) {
        b = 0;
        break;
      }
      vec.at(i) /= 2;
    }
    c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 256
import Data.List
solve b f r ss = sum $ [last s | s <- ss, init s == [b, f, r]]

main = do
    _ <- getLine
    ss <- fmap (map (map read) . map words . lines) getContents
    putStrLn $ intercalate "\n" $ intersperse (replicate 20 '#') [intercalate "\n" [(' ':unwords [show $ solve b f r ss | r <-[1..10]]) | f <- [1..3]] | b <- [1..4]]




Measured memory_bytes: 4408
class Node
  attr_reader :value

  def initialize(value)
    @value = value
    @left = nil
    @right = nil
  end

  def insert(value)
    if value < @value
      if @left
        @left.insert(value)
      else
        @left = Node.new(value)
      end
    else
      if @right
        @right.insert(value)
      else
        @right = Node.new(value)
      end
    end
  end

  def visit_inorder(&block)
    @left.visit_inorder(&block) if @left
    block.call(self) if block
    @right.visit_inorder(&block) if @right
  end

  def visit_preorder(&block)
    block.call(self) if block
    @left.visit_preorder(&block) if @left
    @right.visit_preorder(&block) if @right
  end
end

if $PROGRAM_NAME == __FILE__
  n = gets.to_i

  root = nil

  n.times do
    command = gets.chomp

    case command
    when /^insert\s+(-?\d+)/
      value = $1.to_i

      if root
        root.insert(value)
      else
        root = Node.new(value)
      end
    when 'print'
      root.visit_inorder do |node|
        print " #{node.value}"
      end
      puts

      root.visit_preorder do |node|
        print " #{node.value}"
      end
      puts
    end
  end
end

Measured memory_bytes: 47920
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N, x;
    cin >> N >> x;
    vector<ll> a(N);
    rep(i, N) { cin >> a[i]; }

    ll cnt = 0;
    for (int i = 0; i < N - 1; i++) {
        if (a[i] + a[i + 1] > x) {
            int diff = a[i] + a[i + 1] - x;
            if (diff > a[i + 1])
                cnt += a[i + 1], a[i + 1] = 0;
            else
                cnt += diff, a[i + 1] -= diff;
        }
    }

    for (int i = 0; i < N - 1; i++) {
        if (a[i] + a[i + 1] > x) {
            int diff = a[i] + a[i + 1] - x;
            a[i] -= diff, cnt += diff;
        }
    }

    cout << cnt << endl;
}

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

int main(){
	int n,d;
	cin >> n >> d;
	
	
	
	
	cout << ceil((double) n/(2*d+1) ) << endl;
	return 0;
}

Measured memory_bytes: 256
ar = []
br = []
cr = []
mn = 10
for i in range(5):
    l = input()
    if int(l) % 10 == 0:
        ar.append(int(l))
    else:
        br.append(int(l))
        if mn > int(l) % 10:
            mn = int(l) % 10
for r in br:
    if str(r)[-1] == str(mn) and len(cr) == 0:
        cr.append(r)
    else:
        r += 10 - (r % 10)
        ar.append(r)
if len(cr) == 1:
    print(sum(ar) + cr[0])
else:
    print(sum(ar))

Measured memory_bytes: 3064
//30分

import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		int l = s.length();

		char[] c = new char[l];

		for(int i=0;i<l;i++) {

			c[i] = s.charAt(i);

		}

		int rec = l-1;

		boolean flag = false;

		while(rec>=0) {

			String ss = "";

			if(c[rec] == 'r') {

				for(int i=0;i<7;i++) {

					if(rec-i>=0) {

						ss += c[rec-i];

					}else {

						flag = true;

						break;
					}

					if(i==5 && ss.equals("resare") ) {

						rec = rec-6;

						break;

					}

					if(i==6 && ss.equals("remaerd")) {

						rec = rec-7;

						break;

					}

					if(i==6) flag = true;

				}
			}else {

				for(int i=0;i<5;i++) {

					if(rec-i>=0) {

						ss += c[rec-i];

					}else {

						flag = true;

						break;
					}
				}

				if(ss.equals("maerd") || ss.equals("esare"))  rec = rec-5;
			}

			if(flag == true) {

				System.out.println("NO");

				break;
			}
		}

		if(flag == false) System.out.println("YES");

	}

}


Measured memory_bytes: 36240
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	char s[120];
	scanf("%s",s);
	int len=strlen(s);
	int flag=0;
	for(int i=0;i<len;i++)
	{
		if((i%2==0&&s[i]=='L')||(i%2==1&&s[i]=='R'))
		{
			flag=1;
		}
		
	}
	if(flag)
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 256
var a:array[0..5]of longint;
    i,j:longint;
    t,ans,num:longint;
begin
  for i:=1 to 3 do
  read(a[i]);
  for i:=1 to 2 do
    for j:=i+1 to 3 do
    if a[j]<a[i] then
    begin
      t:=a[i];a[i]:=a[j];a[j]:=t;
    end;
  ans:=a[3]-a[2];
  inc(a[1],ans);
  num:=a[3]-a[1];
  if num mod 2=0 then writeln(ans+num div 2) else
  begin
    writeln(ans+1+(num+1) div 2);
  end;
end.



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

using namespace std;

typedef long long ll;

  int main() {
  ll n, k;
  cin >> n >> k;

  while(k/2 < n){
    if(n > k){
      n = n % k;
    }
    n = abs(n - k);
  }

  cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
H, N, *AB = map(int, open(0).read().split())
A = []
B = []
for a, b in zip(*[iter(AB)] * 2):
    A.append(a)
    B.append(b)

dp = [float("inf")] * (H + 1)
dp[0] = 0

for i in range(N):
    for h in range(H):
        dec_health = min(h + A[i], H)
        dp[dec_health] = min(dp[dec_health], dp[h] + B[i])
print(dp[-1])



Measured memory_bytes: 74244
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
unordered_map<string,ll> p;
vector<string> k;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
		ios_base::sync_with_stdio(0);
		int N;
		cin>>N;
		for(int i=0;i<N;i++){
			string a;
			cin>>a;
			sort(a.begin(),a.end());
			k.push_back(a);
			p[a]++;
		}
		sort(k.begin(),k.end());
		k.resize(unique(k.begin(),k.end())-k.begin());
		ll tot=0;
		for(int i=0;i<k.size();i++){
			string o=k[i];
			tot+=p[o]*(p[o]-1)/2;
		}
		cout<<tot;
		return 0;
}


Measured memory_bytes: 16152