akhauriyash/Code-Regression huggingface dataset:
import re
firststr = int(input())
ary = input().split()
counter = 0
breaker = 0
while 1:
    for index , elm in enumerate(ary):
        elmnum= int(elm)
        if elmnum%2 is 0:
            tmp = elmnum / 2
            elm = int(tmp)
            ary[index] = elm
            continue
        else:
            breaker = True
            break
    if breaker is True:
        break
    counter+=1

print(counter)


Measured memory_bytes: 3188
n,m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
#print(n,m,sc)

for i in range(10**n):
  i2 = str(i)
  if len(i2) == n and all([i2[s-1]==str(c) for s,c in sc]):
    print(i2)
    exit()
print(-1)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	fix_cout() ;
	double w,h,x,y ;
	cin >> w >> h >> x >> y ;
	cout << w*h/2.0 << " " << (x==w/2.0&&y==h/2.0) << endl ;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int first,n,inc;
	cin>>n>>inc;
	first=1;
	while(n--)
	{
		if(first<inc)
		{
			first*=2;
		}
		else
		{
			first+=inc;
		}
	}
	cout<<first;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
//cout << fixed << setprecision(10);

int main () {
  string s;
  cin >> s;
  string t = s;
  reverse(rng(t));
  int ans = 0;
  rep(i,s.size()/2) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  double n, t, a; cin >> n >> t >> a;
  vi h(n);
  rep(i,n) cin >> h[i];
  int ans = 0;
  double mn = (double)INF;
  rep(i,n) {
    double d = abs(t-0.006*h[i] - a);
    if (abs(t-0.006*h[i] - a) < mn) {
      ans = i+1;
      mn = d;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;

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


int main(){
	int n,ans,ansmin,ansmax,a;
	ans=0;
	int rate[9]={0};
	scanf("%d",&n);
	REP(i,n){
		scanf("%d",&a);
		if(a<=3200)rate[a/400]++;
		else rate[8]++;
	}
	REP(i,8){
		ans+=(rate[i]>0?1:0);
	}
	ansmin=(ans==0&&rate[8]>0 ? 1 : ans);
	ansmax=ans+rate[8];
	printf("%d %d",ansmin,ansmax);
}


Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; cin >> N;
  vector<LL> a(3*N);
  for (LL& x : a) cin >> x;

  priority_queue<LL, vector<LL>, greater<LL>> left;
  priority_queue<LL> right;
  LL sum_left = 0, sum_right = 0;

  for (int i = 0; i < N; ++i) {
    sum_left += a[i];
    left.push(a[i]);
  }
  for (int i = 2*N; i < 3*N; ++i) {
    sum_right += a[i];
    right.push(a[i]);
  }

  vector<LL> ans(N + 1, 0);
  ans[0] += sum_left;
  ans[N] -= sum_right;
  for (int i = 0; i < N; ++i) {
    // left
    sum_left += a[N + i];
    left.push(a[N + i]);
    sum_left -= left.top();
    left.pop();
    ans[i + 1] += sum_left;

    // right
    sum_right += a[2*N - i - 1];
    right.push(a[2*N - i - 1]);
    sum_right -= right.top();
    right.pop();
    ans[N - i - 1] -= sum_right;
  }

  LL vmax = ans[0];
  for (int i = 1; i <= N; ++i) vmax = max(vmax, ans[i]);
  cout << vmax << endl;
}


Measured memory_bytes: 5108
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+100;
typedef pair<int,int> pii;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)
#define pb push_back

int n;

struct point{
   int x,y,id;
   bool operator <(const point &b) const {
      return x < b.x;
   }
}p[N];

int f[N],cnt[N];
inline int find(int x){
   return (f[x] == x) ? x : f[x] = find(f[x]);
}

inline bool merge(int x,int y){
   int f1 = find(x),f2 = find(y);
   if(f1 == f2)return false;
   cnt[f1] += cnt[f2]; cnt[f2] = 0;
   f[f2] = f1;
   return true;
}

int ans[N];
set<pii> s1;

int main(){
   scanf("%d",&n);
   fr(i,1,n){
      scanf("%d%d",&p[i].x,&p[i].y); p[i].id = i;
   }
   sort(p+1,p+n+1);
   fr(i,1,n)cnt[i] = 1,f[i] = i;

   s1.insert(pii(p[1].y,p[1].x));
   fr(i,2,n){
      vector<pii> v1;
      for(set<pii>::iterator k = s1.begin();k != s1.end(); ++k){
         pii j = *k;
         if(j.first > p[i].y)break;
         v1.pb(j);
         merge(j.second,i);
      }
      if(v1.empty())s1.insert(pii(p[i].y,p[i].x));
      else {
         fr(i,1,(int)v1.size()-1)s1.erase(v1[i]);
      }
   }

   fr(i,1,n)ans[p[i].id] = cnt[find(i)];
   fr(i,1,n)printf("%d\n",ans[i]);
   return 0;
}


Measured memory_bytes: 12808
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}


int main(){
    ll n,q;
    string s;
    cin >> n >> q >> s;
    ll x[s.size()];
    x[0]=0;
    for (ll i=1;i<n;i++){
        if (s[i]=='C' and s[i-1]=='A')x[i]=x[i-1]+1;
        else x[i]=x[i-1];
    }
    for (ll i=0;i<q;i++){
        ll a,b;
        cin >> a >> b;
        cout << x[b-1]-x[a-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
use proconio::{fastout, input, marker::Chars, marker::Usize1};
use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        ch: Usize1,
        cw: Usize1,
        dh: Usize1,
        dw: Usize1,
        mut s: [Chars; h],
    }

    let mut q = VecDeque::new();
    q.push_back((ch, cw));

    let mut costs = vec![vec![-1; w]; h];
    costs[ch][cw] = 0;

    while !q.is_empty() {
        if let Some((y, x)) = q.pop_front() {
            s[y][x] = '#';
            for dx in -1..=1 {
                for dy in -1..=1 {
                    if i64::abs(dx) == i64::abs(dy) {
                        continue;
                    }
                    let nx = x as i64 + dx;
                    let ny = y as i64 + dy;
                    if nx < 0 || nx >= w as i64 || ny < 0 || ny >= h as i64 {
                        continue;
                    }
                    let nx = nx as usize;
                    let ny = ny as usize;
                    if s[ny][nx] != '#' && (costs[ny][nx] == -1 || costs[ny][nx] > costs[y][x]) {
                        costs[ny][nx] = costs[y][x];
                        q.push_front((ny, nx));
                    }
                }
            }
            for dx in -2..=2 {
                for dy in -2..=2 {
                    let nx = x as i64 + dx;
                    let ny = y as i64 + dy;
                    if nx < 0 || nx >= w as i64 || ny < 0 || ny >= h as i64 {
                        continue;
                    }
                    let nx = nx as usize;
                    let ny = ny as usize;
                    if s[ny][nx] != '#' && (costs[ny][nx] == -1 || costs[ny][nx] > costs[y][x] + 1)
                    {
                        costs[ny][nx] = costs[y][x] + 1;
                        q.push_back((ny, nx));
                    }
                }
            }
        }
    }
    println!("{}", costs[dh][dw]);
}


Measured memory_bytes: 11156
s = input()
t = input()
alpha = "abcdefghijklmnopqrstuvwxyz"
n = len(s)
m = len(t)
D = {}
E = {}
for i in range(n):
  if s[i] in D:
    D[s[i]][i] = i
  else:
    D[s[i]] = [-1 for _ in range(n)]
    D[s[i]][i] = i
  E[s[i]] = i
for i in D:
  p = E[i]
  for j in range(E[i], E[i] - n, -1):
    if D[i][(j+n)%n] == -1:
      D[i][(j+n)%n] = p
    else:
      p = j
x = 0
p = 0
for i in range(m):
  if t[i] in D:
    y = D[t[i]][p]
    if y < p:
      x += 1
    if i != m - 1:
      if y == n - 1:
        x += 1
        p = 0
      else:
        p = (y + 1) % n
    else:
      p = y
  else:
    x = -1
    break
if x == -1:
  print(x)
else:
  print(x*n+p+1)

Measured memory_bytes: 31196
n = int(input())

dp = [n]*100010
dp[0] = 0
pow69 = [6**i for i in range(1,7)] + [9**i for i in range(1,6)]

for i in range(1,n+1):
    dp[i] = dp[i-1] + 1
    for p in pow69:
        dp[i] = min(dp[i],dp[i-p]+1)

print(dp[n])

Measured memory_bytes: 9464
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n;
ll ans=0;
cin >> n;
string s[n];
for(int i=0;i<n;i++){
   cin >> s[i];
}
map<string,int> mp;
for(int i=0;i<n;i++){
sort(s[i].begin(),s[i].end());

auto itr = mp.find(s[i]);
   if(itr !=mp.end()){
      itr->second++;
      ans += itr->second;
   }
   else{
      mp[s[i]]=0;
   }
}
cout << ans << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 16640
import sys
sys.setrecursionlimit(10**9)

k=int(input())

def dfs(keta,num):
  global ans
  ans.append(int(''.join(num)))

  if keta==10:
    return

  min_n=max(0,int(num[-1])-1)
  max_n=min(9,int(num[-1])+1)
  for i in range(min_n,max_n+1):
    dfs(keta+1,num+[str(i)])

ans=[]
for i in range(1,10):
  dfs(1,[str(i)])

ans.sort()
print(ans[k-1])

Measured memory_bytes: 17316
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    set<string> st;
    rep(i,n){
        string s;
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<endl;
}

Measured memory_bytes: 19268
#include <stdio.h>
int main() {
    int a, b, k;
    scanf("%d\n%d %d", &k, &a, &b);
    if (a % k == 0 || b % k == 0) printf("OK\n");
    else {
        int r = a % k;
        if (a - r + k <= b) printf("OK\n");
        else printf("NG\n");
    }

    return 0;
}

Measured memory_bytes: 1644
main = do
  s <- getContents
  putStrLn . join' "\n" . map rect . takeWhile (/=[0,0]) . map (map (read :: String -> Int)) . map words . lines $ s

rect :: [Int] -> String
rect [h,w] =
  concat . take h . repeat  $ ((concat . take w . repeat $ "#" )++"\n")

join'::String -> [String] -> String
join' _ [] = ""
join' j (x:xs) = aux j x xs
  where
    aux :: String -> String -> [String] -> String
    aux j y [] = y
    aux j y (x:xs) = aux j (y++j++x) xs

Measured memory_bytes: 5056
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char const* argv[])
{
	double answer;
	double q;

	while( cin >> q && q != -1 ){
		answer = q / 2;

		while( fabs( answer * answer * answer - q ) >= 0.00001 * q ){
			answer = answer - ( (answer * answer * answer ) - q ) / ( 3 * answer * answer );
		}

		printf("%.6f\n",answer);
	}
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC14 {
    class Program {
        static int[] inp,a,b,e;
        static int n, m;
        static void Main(string[] args) {
            inp = Scan;
            n = inp[0];
            m = inp[1];
            e = new int[n+1];
            a = new int[m];
            b = new int[m];
            for (int i = 0; i <= n; i++)
                e[i] = 0;
            for(int i = 0; i < m; i++) {
                inp = Scan;
                a[i] = inp[0];
                b[i] = inp[1];
            }
            if (Solve())
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
        static bool Solve() {
            for(int i = 0; i < m; i++) {
                e[a[i]]++;
                e[b[i]]++;
            }
            for(int i = 1; i <= n; i++) {
                if (e[i] % 2 == 1)
                    return false;
            }
            return true;
        }
       static int[] Scan {
            get {
                return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            }
        }
    }
}


Measured memory_bytes: 18104
// C - Factors of Factorial

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 1e9 + 7;

map<int, int> primes;

void prime_factorize(ll n) {
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        primes[p] += num;
    }
    if (n != 1) primes[n] += 1;
}

int main() {
	int N;
	cin >> N;

	for (int i=2; i<=N; i++) {
		prime_factorize(i);
	}

	ll ans = 1;
	for (auto itr=primes.begin(); itr!=primes.end(); itr++) {
		//cout << itr->first << " " << itr->second << endl;
		int count = itr->second;
		ans = (ans * (count + 1)) % MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
coms = ['insert', 'delete', 'deleteFirst', 'deleteLast']
n = int(input())
L = deque()
for c in sys.stdin:
    c = c.split() 
    com = coms.index(c[0])
    if com == 0:
        x = int(c[1])
        L.appendleft(x)
    elif com == 1:
        x = int(c[1])
        if x in L:
            L.remove(x)
    elif com == 2:
        L.popleft()
    else:
        L.pop()
print(' '.join(map(str, L)))


Measured memory_bytes: 45796
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i

t,x,y = 0,0,0
n.times do
  nt,nx,ny = gets.chomp.split.map(&:to_i)
  len = (nx-x).abs + (ny-y).abs
  time = nt - t

  if time < len || (time-len).odd?
    puts 'No'
    exit
  end
end

puts 'Yes'


Measured memory_bytes: 2428
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
void disp(vector<long>& vec) {
  cout << "[";
  for (int i = 0; i < vec.size(); i++) cout << " " << vec[i];
  cout << " ]" << endl;
}
 
int main() {
  int n;
  cin >> n;
  
  int a,b,c;
  a = n % 10;
  b = (n-a) / 10 % 10;
  c = (n-a-b) / 100 % 10;
  
  if(a == 7 || b == 7 || c == 7) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
inline int read () {
	int num = 0;
	char c = ' ';
	bool flag = true;
	for (;c > '9' || c < '0';c = getchar())
		if (c == '-')
			flag = false;
	for (;c >= '0' && c <= '9';num = (num << 1) + (num << 3) + c - 48, c = getchar());
	return flag ? num : -num;
}
namespace INIT {
	const int maxn = 200200;
	int n, a[maxn];
	void init () {
		n = read ();
		for (int i = 1;i <= n;i ++)
			a[i] = read ();
	}
} using namespace INIT;
struct node {
	int num, val;
} c1[maxn], c2[maxn];
int which[maxn],cnt1 = 0, cnt2 = 0;
void work1 () {
	memset (which, 0, sizeof which);
	for (int i = 1;i <= n;i += 2) {
		if (which[a[i]] == 0) {
			which[a[i]] = ++ cnt1;
			c1[cnt1].num = a[i];
		}
		c1[which[a[i]]].val ++;
	}
}
void work2 () {
	memset (which, 0, sizeof which);
	for (int i = 2;i <= n;i += 2) {
		if (which[a[i]] == 0) {
			which[a[i]] = ++ cnt2;
			c2[cnt2].num = a[i];
		}
		c2[which[a[i]]].val ++;
	}
}
node a1,a2,b1,b2;
void find () {
	for (int i = 1;i <= cnt1;i ++) {
		if (c1[i].val > a1.val) {
			a2 = a1;
			a1 = c1[i];
		}
		else if (c1[i].val > a2.val)
			a2 = c1[i];
	}
	for (int i = 1;i <= cnt2;i ++) {
		if (c2[i].val > b1.val) {
			b2 = b1;
			b1 = c2[i];
		}
		else if (c2[i].val > b2.val)
			b2 = c2[i];
	}
}
void work () {
	int ans = 0x7fffffff;
	if (a1.num != b1.num)
		ans = min (ans,n - a1.val - b1.val);
	if (a1.num != b2.num)
		ans = min (ans,n - a1.val - b2.val);
	if (a2.num != b1.num)
		ans = min (ans,n - a2.val - b1.val);
	printf ("%d\n", ans);
}
int main () {
	init ();
	work1 (); work2 ();
	find (); work ();
	return 0;
}

Measured memory_bytes: 3712
import java.util.*;
import java.io.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long mod = 998244353;
    long[] frac, inv;
    public static void main(String[] args){
        Main main = new Main();
//        String ans = main.solve()<0?"No":"Yes";
//        System.out.println(main.solve());
        main.solve();
    }
    long solve(){
        int n = sc.nextInt(), S = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = sc.nextInt();
        long[][] dp = new long[n][3000+1];
        long[] sum = new long[3000+1];
        // dp[i][j]: 1<=x1...<x[k]=i and sum(a[1]...a[k]) = j
        dp[0][a[0]] = 1; sum[a[0]] = 1;
        for(int i=1;i<n;i++){
            dp[i][a[i]] = (i+1);
            for(int j=a[i]+1;j<=S;j++){
                dp[i][j] += sum[j-a[i]];
                dp[i][j] %= mod;
            }
            for(int j=1;j<=S;j++) sum[j] = (sum[j]+dp[i][j])%mod;
        }
        long ans = 0;
        for(int i=0;i<n;i++) {
            long temp = dp[i][S]*(n-i);
            ans = (ans+temp)%mod;
        }
        out.println(ans);
        out.flush();
        return 1;
    }
}


Measured memory_bytes: 128004
x,y,a,b,c=map(int,input().split())
p=sorted(list(map(int,input().split())),reverse=True)
q=sorted(list(map(int,input().split())),reverse=True)
r=sorted(list(map(int,input().split())),reverse=True)

list=p[:x]+q[:y]

if len(list)<x+y:
  ll=len(list)
  for i in range((x+y)-len(list)):
    list.append(r[i])
  r=r[(x+y)-ll:]
list=sorted(list)

for i in range(len(r)):
  if list[i]<r[i]:
    list[i]=r[i]
  else:
    break
print(sum(list))

Measured memory_bytes: 23200
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N =sc.nextInt();
    int M =sc.nextInt();
    Integer A[] =new Integer[N];
    long B[] =new long[N+1];
     B[0] =0;
    for(int i=0;i<N;i++){
      A[i] =sc.nextInt();
      B[i+1]=B[i]+A[i];
    }
    Arrays.sort(A, Collections.reverseOrder());
    long C =4*M*A[M-1];
    if(C<B[N]){System.out.println("No");}
    else{System.out.println("Yes");}
  }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=1000000007;

int main()
{
    int d,n;cin>>d>>n;
    if(d==0)
    {
        if(n!=100)
        cout<<n<<endl;
        else
            cout<<101<<endl;
    }
    else if(d==1)
    {
        if(n!=100)
        cout<<n*100<<endl;
        else
            cout<<10100<<endl;
    }
    else
    {
        if(n!=100)
            cout<<n*10000<<endl;
        else
            cout<<1010000<<endl;
    }
}

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

int main() {
  int64_t N;
  cin >> N;

  int64_t A, B; 
  int length = 100000;
  
  for (int i = 0; i<100000; i++){
  
  if ( N % (i+1) == 0) {
	A = i+1;
    B = N / (i+1);
    string s = to_string(A); int A_length = s.size();
    string t = to_string(B); int B_length = t.size();
    length = min(length, max(A_length,B_length));
  }
  else continue;
    
  }
  
  cout << length << endl;
}


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

int main() {
    int x, n, t, ans;
    cin >> x >> n;
    vector<int> p(101,0);
    for(int i = 0; i < n; ++i){
        cin >> t;
        if(p[t] == 0){
            p[t] = 1;
        }
    }
    int d = 101;
    if(abs(x - 101) <= d){
        ans = 101;
        d = abs(x - 101);
    }
    for(int i = 100; i > -1; --i){
        if(p[i] == 1){
            continue;
        }else if(abs(x - i) <= d){
            d = abs(x - i);
            ans = i;
        }
    }
    if(abs(x + 1) <= d){
        ans = -1;
    }

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

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, a[312345];
LL sum[312345], fir_res[212345], sec_res[212345], ans;
std::priority_queue<LL, std::vector<LL>, std::greater<LL>>fir;
std::priority_queue<LL>sec;

int main()
{
	in >> N;
	rep(i, 3 * N) { in >> a[i]; }

	std::copy(a, a + N * 3, sum);
	rep(i, N * 3) { sum[i + 1] += sum[i]; }
	rep(i, N) { fir.push(a[i]); }
	fir_res[N] = sum[N - 1];
	for (LL i = N + 1; i <= N * 2; ++i)
	{
		fir.push(a[i - 1]);
		auto smallest = fir.top(); fir.pop();
		fir_res[i] = a[i - 1] + fir_res[i - 1] - smallest;
	}
	rep(i, N) { sec.push(a[i + N * 2]); }
	sec_res[N] = sum[3 * N - 1] - sum[2 * N - 1];
	for (LL i = N + 1; i <= N * 2; ++i)
	{
		sec.push(a[3 * N - i]);
		auto biggest = sec.top(); sec.pop();
		sec_res[i] = a[3 * N - i] + sec_res[i - 1] - biggest;
	}
	ans = fir_res[N] - sec_res[2 * N];
	for (LL i = N + 1; i <= N * 2; ++i)
	{
		auto res = fir_res[i] - sec_res[3 * N - i];
		ans = std::max(ans, res);
	}

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

Measured memory_bytes: 8820
// No sorceries shall prevail. //           
import java.util.*;
import java.io.*;
public class Main {
	
	static long gcd(long a, long b) { 
	      if (b == 0) 
	        return a; 
	      return gcd(b, a % b);  
	    }
	static int gcd(int a, int b) { 
	      if (b == 0) 
	        return a; 
	      return gcd(b, a % b);  
	    }
	
	static long mod = 1000000007;
	public static void main(String args[]) {
		Scanner inp=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		
		long n=inp.nextLong();
		long a=inp.nextLong();
		long b=inp.nextLong();
		long gg=0;
		gg+=(n/(a+b))*a;
		n%=(a+b);
		gg+=Math.min(n, a);
		out.println(gg);
		
		out.close();
		inp.close();
	}
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

bool memo[1000002];

int main() {

  rep (i, 1000002) memo[i] = true;

  memo[0] = memo[1] = false;

  for (int k = 2; k < 1000002; ++k) {
    if (!memo[k]) continue;
    for (int i = k+k; i < 1000002; i += k) memo[i] = false;
  }

  for (int n; cin >> n, cin; ) {
    int ans = 0;
    rep (k, n+1) if (memo[k]) ++ans;
    cout << ans << endl;
  }

  return 0;
}

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

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector < map < char, int > > cnt_pref(n + 1);
	for (int i = 1; i <= n; ++i) {
		cnt_pref[i]['W'] = cnt_pref[i - 1]['W'];
		cnt_pref[i]['R'] = cnt_pref[i - 1]['R'];
		++cnt_pref[i][s[i - 1]];
	}
	vector < map < char, int > > cnt_suff(n + 1);
	for (int i = n - 1; i >= 0; --i) {
		cnt_suff[i]['W'] = cnt_suff[i + 1]['W'];
		cnt_suff[i]['R'] = cnt_suff[i + 1]['R'];
		++cnt_suff[i][s[i]];
	}
	int ans = n;
	for (int reds = 0; reds <= n; ++reds) {
		int w = cnt_pref[reds]['W'], r = cnt_suff[reds]['R'];
		ans = min(ans, max(w, r));
	}
	cout << ans << '\n';
}


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

int main(){
  int n;
  cin >> n;
  int q1 = (n % 10);
  int n1 = (n / 10);
  int q2 = (n1 % 10);
  int n2 = (n1 / 10);
  int q3 = (n2 % 10);
  int n3 = (n2 / 10);
  if (q1 != q2){
    if (q2 != q3) cout << "No" << endl;
      else {
        if (q3 == (n3 % 10) ) cout << "Yes" << endl;
        else cout << "No" << endl;
      }
  }
  else {
    if (q2 == q3) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}

Measured memory_bytes: 3636
#include <iostream>
#include <queue>

using namespace std;

int main() {
    int N;
    int A;
    priority_queue<int> pq;
    cin >> N;
    for(int i = 0; i < N; ++i) {
        cin >> A;
        pq.push(A);
    }
    int found = 0;
    long long int L,R;
    while(pq.size() and found < 2) {
        int a = pq.top();
        pq.pop();
        if(pq.empty()) break;
        if(pq.top() == a) {
            pq.pop();
            if(found == 0) {
                L = a;
            } else {
                R = a;
            }
            ++found;
        }
    }
    if(found == 2)
        cout << L*R << endl;
    else
        cout << 0 << endl;
    return 0;
}


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

#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

ll seg[26][2000001];

ll getMid(ll s, ll e) { return s + (e -s)/2; }  

ll getSumUtil(ll *st, ll ss, ll se, ll qs, ll qe, ll si)  
{  
    if (qs <= ss && qe >= se)  
        return st[si];  

    if (se < qs || ss > qe)  
        return 0;  

    ll mid = getMid(ss, se);  
    return getSumUtil(st, ss, mid, qs, qe, 2*si+1) +  
        getSumUtil(st, mid+1, se, qs, qe, 2*si+2);  
}  

void updateValueUtil(ll *st, ll ss, ll se, ll i, ll diff, ll si)  
{  
    if (i < ss || i > se)  
        return;  

    st[si] = st[si] + diff;  
    if (se != ss)  
    {  
        ll mid = getMid(ss, se);  
        updateValueUtil(st, ss, mid, i, diff, 2*si + 1);  
        updateValueUtil(st, mid+1, se, i, diff, 2*si + 2);  
    }  
}  

void updateValue(ll *st, ll n, ll i, ll new_val)  
{  
    updateValueUtil(st, 0, n-1, i, new_val, 0);  
} 

ll getSum(ll *st, ll n, ll qs, ll qe)  
{  
    return getSumUtil(st, 0, n-1, qs, qe, 0);  
}  

void solve() {
    ll i, j, n;
    fo(i,26)fo(j,2000001)seg[i][j]=0;
    string s;
    cin>>n>>s;
    fo(i,n) {
        updateValue(seg[s[i]-97], n, i, 1);
    }
    ll q;
    cin>>q;
    while(q--) {
        ll type, l, r;
        cin>>type;
        if(type==2) {
            ll ans = 0;
            cin>>l>>r;
            l--;r--;
            fo(i,26) {
                if(getSum(seg[i], n, l, r)>0)ans++;
            }
            cout<<ans<<endl;continue;
        }
        ll idx;
        char a;
        cin>>idx>>a;
        idx--;
        updateValue(seg[s[idx]-97], n, idx, -1);
        s[idx] = a;
        updateValue(seg[s[idx]-97], n, idx, 1);
    }
}

int main()
{
    ll t = 1;
    // cin>>t;
    while(t--) {
        solve();
    }
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** MOD CALCULATION ***/

const int MOD = 1e9+7;
const int MAX = 2'000'005;

ll addM(ll a, ll b){
	return ((a % MOD) + (b % MOD)) % MOD;
}

ll mulM(ll a, ll b){
	return ((a % MOD) * (b % MOD)) % MOD;
}

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a % MOD;
  	else if(b%2==0) return mulM(powM(a, b/2), powM(a, b/2));
  	else return mulM(a, mulM(powM(a, (b-1)/2), powM(a, (b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a, powM(b, MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COMB(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;
}

/*** MOD CALCULATION ここまで ***/

void Main(){
    int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
    COMBinit();

    auto f = [&](int r, int c){
        return COMB(r + c, r);    
    };
    
    auto g = [&](int r, int c){
        return f(r + 1, c + 1);    
    };
    
    ll ans = addM(g(r2, c2), MOD - g(r2, c1-1));
    ans = addM(ans, MOD - g(r1-1, c2));
    ans = addM(ans, g(r1-1, c1-1));
    cout << ans << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 50532
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cerr << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

bitset<100005> vis[2];
set<pll> s;
pll arr[100005];
const ll INF=1e18;

int main()
{jizz
	ll n,ans=0,mi=INF;
	cin >> n;
	for(int i=0;i<n;++i)
		cin >> arr[i].F >> arr[i].S,s.insert(MP(arr[i].F,i<<1)),s.insert(MP(arr[i].S,i<<1|1));
	while(s.size()>n)
		ans+=s.begin()->F,vis[s.begin()->S&1][s.begin()->S>>1]=1,s.erase(s.begin());
	if(vis[0].count()==n||vis[1].count()==n||(vis[0]&vis[1]).count()>0)
		return cout << ans << "\n",0;
	for(int i=0;i<n;++i)
		if(vis[0][i])
			s.erase(MP(arr[i].S,i<<1|1)),mi=min(mi,s.begin()->F-arr[i].F),s.insert(MP(arr[i].S,i<<1|1));
		else
			s.erase(MP(arr[i].F,i<<1)),mi=min(mi,s.begin()->F-arr[i].S),s.insert(MP(arr[i].F,i<<1));
	if(vis[0].count()==1)
		for(int i=0;i<n;++i)
			if(vis[0][i])
			{
				mi=min(mi,arr[i].S-arr[i].F);
				break;
			}
	if(vis[1].count()==1)
		for(int i=0;i<n;++i)
			if(vis[1][i])
			{
				mi=min(mi,arr[i].F-arr[i].S);
				break;
			}
	cout << ans+mi << "\n";
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
//using
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);

//テンプレート関数
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl kai(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,桁数回の演算だからだいたいO(logN)くらい?



signed main(){
    cout << fixed << setprecision(10);
    int d;
    cin >> d;
    int c[26];
    rep(i,26)cin >> c[i];
    int s[d][26];
    rep(i,d){
        rep(j,26)cin >> s[i][j];
    }
    int last_day[26];
    m0(last_day);
    intl ans = 0;
    rep(i,d){
        int idx = -1;
        int mx = -INF;
        rep(j,26){
            int ans0 = ans;
            ans0 += s[i][j];
            rep(k,26){
                if(j != k)ans0 -= (c[k] * ((i + 1) - last_day[k])); 
            }
            if(chmax(mx,ans0))idx = j;
            //debug(ans0);
        }
        ans += s[i][idx];
        last_day[idx] = i + 1;
        rep(j,26){
            ans -= (c[j] * ((i + 1) - last_day[j])); 
        }
        cout << idx + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3672
#include<stdio.h>
int main()
{
    int x1,x2,x3,x4;
    int y1,y2,y3,y4;
    scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
    int p=x2-x1;
    int q=y1-y2;
    x3=q+x2;
    y3=p+y2;
    x4=x3+(x1-x2);
    y4=y3+(y1-y2);
    printf("%d %d %d %d\n",x3,y3,x4,y4);
    return 0;
}


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

int main() {
    int n, y;
    cin >> n >> y;
    int ans[3] = {-1, -1, -1};

    for(int i = 0; i < n + 1; i++) {
        for(int j = i; j < n + 1; j++) {
            if(y == 1000 * i + 5000 * (j - i) + 10000 * (n - j)) {
                ans[0] = i;
                ans[1] = j - i;
                ans[2] = n - j;
            }
        }
    }
    cout << ans[2] << " " << ans[1] << " " << ans[0] << endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int K, T;
    cin >> K >> T;
    vector<int> A(T);
    rep(i, T) cin >> A[i];

    int ma = A[0];
    int sum = 0;
    rep(i, T) {
        chmax(ma, A[i]);
        sum += A[i];
    }

    cout << max(0, ma - (sum - ma) - 1) << endl;
}


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

using namespace std;
int h[100005],dp[100005];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	memset(dp,1234645198452,sizeof(dp));
	dp[1]=0;
	for(int i=2;i<=min(k,n);i++)
		for(int j=1;j<i;j++)
			dp[i]=min(dp[i],abs(h[i]-h[j])+dp[j]);
	for(int i=k+1;i<=n;i++)
		for(int j=i-k;j<i;j++)
			dp[i]=min(dp[i],abs(h[i]-h[j])+dp[j]);
	cout<<dp[n];
	return 0;
}

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

using namespace std;
typedef long long ll;
#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define repb(i,a,b)         for(ll i=a;i>=b;i--)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define tr(c,it)            for(auto const &it : c)
#define xlr8                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sz(c)               (c).size()
#define all(c)              (c).begin(),(c).end()
#define sl(a)               scanf("%lld",&a);
#define TH                  1000
#define F                   first
#define S                   second
#define pi                  3.14159265359
ll INF=1e18+10;

int fr[26];

int main()
{
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int mm=n/2;
    int bmid=a[mm-1],mid=a[mm];
    int ans=(mid-bmid);
    cout<<ans;
}


Measured memory_bytes: 640
from collections import defaultdict


def dfs(s, t):
    visited = 0
    q = [(s, 0)]
    while q:
        v, used = q.pop()
        if v == t:
            return used
        visited |= used
        for lb, u in graph[v]:
            if lb & visited:
                continue
            q.append((u, used | lb))


n = int(input())
graph = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    lb = 1 << i
    graph[a].append((lb, b))
    graph[b].append((lb, a))

conditions = []
m = int(input())
for i in range(m):
    u, v = map(int, input().split())
    conditions.append(dfs(u, v))

link_conditions = [int(''.join(b), 2) for b in zip(*map(('{:0' + str(n - 1) + 'b}').format, conditions))]

dp = defaultdict(lambda: 0)
dp[0] = 1
for lc in link_conditions:
    for fulfilled, pattern in list(dp.items()):
        dp[fulfilled | lc] += pattern
print(dp[(1 << m) - 1])


Measured memory_bytes: 215896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, n, b;
  in(n);
  vector<ll>  c(55555, 2);
  rep2(i, 2, 55555){
    a = 2;
    if(c[i] == 2){
      c[i] = 0;
      while(i * a < 55555){
        c[i * a] = 1;
        a++;
      }
    }
  }
  a = 0;
  b = 1;
  while(a < n){
    if(c[b] == 0 && b % 5 == 1){
      out(b);
      hina;
      a++;
    }
    b++;
  }
  memi;
}

Measured memory_bytes: 640
module Main where

import Control.Monad.Trans.State

solve :: State Int String
solve = do
  h <- state (`divMod` 3600)
  m <- state (`divMod` 60)
  s <- state (`divMod` 1)
  return $ show h ++ ":" ++ show m ++ ":" ++ show s

main :: IO ()
main = do
  s <- readLn
  putStrLn $ evalState solve s



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto &it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

main()
{
        string o,e; cin>>o>>e;
        string ans={};
        rep(i,o.size())
        {
                ans.push_back(o[i]);
                if(i<e.size())ans.push_back(e[i]);
        }
        cout<<ans<<endl;
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

int dy[]={-1,0,1,0};
int dx[]={0,-1,0,1};
int w,h;
char M[55][55];

void dfs(int y,int x,bool f){
    REP(i,4){
	int ny=y+dy[i],nx=x+dx[i];
	if(0<=ny && ny<h && 0<=nx && nx<w){
	    if(f && M[ny][nx]=='.') M[ny][nx]='b',dfs(ny,nx,true);
	    if(!f&& M[ny][nx]=='.') M[ny][nx]='w',dfs(ny,nx,false);
	    if(!f&& M[ny][nx]=='b') M[ny][nx]='x',dfs(ny,nx,false);
	}
    }
}

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

    while(cin>>w>>h,w)
    {
	REP(i,h) REP(j,w) cin>>M[i][j];
	REP(i,h) REP(j,w){
	    if(M[i][j]=='B') dfs(i,j,true);
	}
	REP(i,h) REP(j,w){
	    if(M[i][j]=='W') dfs(i,j,false);
	}
	int c1=0,c2=0;
	REP(i,h){
	    REP(j,w){   
		if(M[i][j]=='b') c1++;
		if(M[i][j]=='w') c2++;
	    }
	}
	cout<<c1<<" "<<c2<<endl;
    }
}


Measured memory_bytes: 3236
#![allow(unused_imports)]

use std::cmp::{max, min};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let x: usize = input().unwrap();
    let mut ans = 1;
    for b in 2usize..40 {
        let m = (2..).map(|p| b.pow(p)).take_while(|a| *a <= x).last().unwrap_or(1);
        ans = max(ans, m);
    }

    println!("{}", ans);
}

pub fn input<T: FromStr>() -> Result<T, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    Ok(buf.trim().parse().ok().unwrap())
}

pub fn input_vec<T: FromStr>() -> Result<Vec<T>, T::Err> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    Ok(buf
        .trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>())
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b,c;cin >> a >> b >> c;
  if(!(a==b && b == c) && (a==b || b==c || c == a)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	long a, b, d, r;
	double f;

	scanf("%ld %ld", &a, &b);
	
	d = a / b;
	r = a % b;
	f = a / (double)b;

	printf("%ld %ld %lf", d, r, f);
	
	return 0;
}

Measured memory_bytes: 636