akhauriyash/Code-Regression huggingface dataset:
//author : raghav_0901

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

void _main();
signed main(void){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);int t=1,i=0;
//cin>>t;
while (t--){
//cout<<"Case #"<<(++i)<<": ";

	_main();

}return 0;}

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


void _main(){
    double a,b,c,d;cin>>a>>b>>c>>d;
    int a1=ceil(c/b),a2=ceil(a/d);
    cout<<((a1<=a2)?"Yes":"No");
    return;
}


Measured memory_bytes: 3764
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	ans := 0
	for i := 0; i < N; i++ {
		for a[i]%2 == 0 {
			a[i] /= 2
			ans++
		}
	}
	out(ans)
}


Measured memory_bytes: 896
#include <iostream>
#include <memory.h>
#include <algorithm>
#include <cstdio>
#define FOR(i, x, y)   for (__typeof(x) i = x; i <= y; i ++)
#define FORD(i, x, y)  for (__typeof(x) i = x; i >= y; i --)
#define maxn 200001
typedef long long ll;
using namespace std;

int n,A[maxn],t;
ll res,stt;

int main(){
    scanf("%d%d",&n,&t);
    FOR(i,1,n) scanf("%d",&A[i]);
    res=stt=0;
    FOR(i,1,n){
        if (A[i]>=stt) res+=t;
        else res+=(A[i]+t-stt);
        stt=A[i]+t;
    }
    printf("%lld",res);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;
const int maxn = 1e5+10;
int N;
int tmp[maxn]; 
int main()
{
	ios::sync_with_stdio(false);
	cin>>N;
	int x;
	for(int i=1;i<=N;++i)
	{
		cin>>x;
		tmp[x]=i;//i表示编号 
	}
	for(int i=1;i<=N;++i)
	cout<<tmp[i]<<" "; 
	return 0;
}

Measured memory_bytes: 1280
a=[]
yojo=[]
sm=0
for i in range(0,5):
  x=int(input())
  if x%10==0:
    x-=10
  a.append(x//10)
  yojo.append(x%10)

yo=[10 if i==0 else i for i in yojo]
out=sum(a)*10+40+min(yo)

print(out)
  


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	cin>>n;
	rep(i,n){
		cout<<"Case "<<i+1<<":"<<endl;
		int a;
		cin>>a;
		rep(j,10){
			a*=a;
			stringstream ss;
			ss<<a;
			string s;
			ss>>s;
			while(s.size()<8){
				s="0"+s;
			}
			s=s.substr(2,4);
			stringstream ss1;
			ss1<<s;
			ss1>>a;
			cout<<a<<endl;
		}

	}
}

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

	int n;
	cin>>n;
	int a[100];
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n-1-i;i++) swap(a[i], a[n-1-i]);
	for(int i=0;i<n;i++){
	if(i) cout<<" ";
	cout<<a[i];
	}
	cout<<endl;

	return 0;
}


Measured memory_bytes: 3076
#include<iostream>
using namespace std;
int main(){
int i,j,k,x,n,A=0;
while(true){
	cin>>n>>x;
	if(n==0&&x==0){break;}
	A=0;
	for(i=1;i<=n;i++){
		for(j=i+1;j<=n;j++){
			for(k=j+1;k<=n;k++){
				if(i+j+k==x){
					A++;
				}
			}
		}
	}
	cout<<A<<endl;
}
	return 0;
}

Measured memory_bytes: 3072
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	Scanner in = new Scanner(System.in);
	int W, H;
	int[][] map;
	int vx[] = {0, -1, 0, 1};
	int vy[] = {-1, 0, 1, 0};
	int ans;
	
	void search(int x, int y, int cnt) {
		if (cnt >= 10) return;
//		System.out.println(x + " " + y + " " + cnt);
		for (int i = 0; i < vx.length; i++) {
			int nx = x, ny = y;
			boolean flag = false;
			while (true) {
				nx += vx[i]; ny += vy[i];
				if (map[ny][nx] == 0 || map[ny][nx] == 2) {
					flag = true;
					continue;
				}
				else if (map[ny][nx] == 1 && flag) {
					map[ny][nx] = 0;
					search(nx - vx[i], ny - vy[i], cnt + 1);
					map[ny][nx] = 1;
				}
				else if (map[ny][nx] == 3) {
					ans = Math.min(ans, cnt + 1);
					return;
				}
				break;
			}
		}
	}
	
	public void run() {
		while (true) {
			int startX = -1, startY = -1;
			W = in.nextInt(); H = in.nextInt();
			if ((W|H) == 0) break;
			map = new int[H+2][W+2];
			for (int i = 0; i < map.length; i++) {
				Arrays.fill(map[i], -1);
			}
			
			for (int i = 1; i < map.length - 1; i++) {
				for (int j = 1; j < map[i].length - 1; j++) {
					map[i][j] = in.nextInt();
					if (map[i][j] == 2) {
						startX = j; startY = i;
					}
				}
			}
			ans = Integer.MAX_VALUE;
			
			search(startX, startY, 0);
			
			System.out.println((ans != Integer.MAX_VALUE) ? ans : -1);
		}
	}
	
	public static void main(String args[]) {
		new Main().run();
	}
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<(vi==INF?"_":to_string(vi))<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  ll h,n;
  cin>>h>>n;
  vector<pll> a(n);
  cin>>a;

  auto solve = [&](auto a){
  // dp[i][j] := i番目までの魔法を使ってjダメージ与えるときの最小ダメ
  auto dp = _vec<ll>(n+1,1e5,INF);
    dp[0][0] = 0;
    rep(i,n)dp[i+1][0] = 0;
    rep(i,n){
      for(ll j=0;j<=h;++j){
        chmin(dp[i+1][j],dp[i][j]);
        if(j+a[i].first<1e5)chmin(dp[i+1][j+a[i].first],dp[i+1][j]+a[i].second);
      }
    }
    ll ans = INF;
    for(int i=h;i<1e5;++i)chmin(ans,dp[n][i]);

    return ans;
  };

  ll ans = INF;
  chmin(ans,solve(a));
  sort(a.begin(),a.end());
  chmin(ans,solve(a));
  sort(a.begin(),a.end(),greater<>());
  chmin(ans,solve(a));
  sort(a.begin(),a.end(),[](auto a,auto b){return a.second < b.second;});
  chmin(ans,solve(a));
  sort(a.begin(),a.end(),[](auto a,auto b){return a.second > b.second;});
  chmin(ans,solve(a));

  auto ceil = [](auto a,auto b){
    return (a-1)/b+1;
  };

  rep(i,n){
    chmin(ans,ceil(h,a[i].first)*a[i].second);
  }

  cout<<(ans)<<endl;


}

Measured memory_bytes: 785920
N, M = map(int, input().split())

l = 0
r = N

for i in range(M):
    L, R = map(int, input().split())
    
    if L > l:
        l = L
            
    if R < r:
        r = R
                
    ans = r - l + 1
    if ans < 0:
        print(0)
        break

else:
    print(ans)

Measured memory_bytes: 9092
import java.io.*;
import java.util.StringTokenizer;


public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        long mid = (sc.nextInt() + sc.nextInt());
        out.println(mid%2==0?mid/2:"IMPOSSIBLE");
        out.flush();
        out.close();
    }


    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }


        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }


        public int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) throws IOException {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }


        public Integer[] nextIntegerArray(int n) throws IOException {
            Integer[] a = new Integer[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public double[] nextDoubleArray(int n) throws IOException {
            double[] ans = new double[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextDouble();
            return ans;
        }

        public short nextShort() throws IOException {
            return Short.parseShort(next());
        }

    }
}

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

#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define T() int tt; cin >> tt; rep1(qq,1,tt)
#define rep(i,start,lim) for(int i=start;i<lim;i++)
#define rep1(i,start,lim) for(int i=start; i<=lim; ++i)
#define repd(i,start,lim) for(int i=start;i>=lim;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define br cout<<"\n"
#define MOD (1000000007LL)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define eps (1e-6)
#define what_is(x) cerr << #x << " is " << x << "\n";
#define int long long int
#define infll 9e18
#define inf 1e12

#define lnode (2 * node + 1)
#define rnode (2 * node + 2)

using namespace std;

typedef pair<int, int> pii;

const int N = 300001;

int X, Y, n, m, k;
int r[N], g[N], w[N];

int32_t main(){

  FIO
  //cout << fixed << setprecision(10);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  cin >> X >> Y >> n >> m >> k;
  for(int i = 0; i < n; ++i) cin >> r[i];
  for(int i = 0; i < m; ++i) cin >> g[i];
  for(int i = 0; i < k; ++i) cin >> w[i];
  int res = 0;
  sort(r, r + n);
  reverse(r, r + n);
  sort(g, g + m);
  reverse(g, g + m);
  sort(w, w + k);
  reverse(w, w + k);
  multiset<int> M;
  for(int i = 0; i< X; ++i) M.insert(r[i]);
  for(int i = 0; i< Y; ++i) M.insert(g[i]);

  int idx = 0;
  while(1){
    if(w[idx] <= (int)(*M.begin())) break;
    M.erase(M.begin());
    M.insert(w[idx]);
    ++idx;
  }
  for(int xx : M) res += xx;
  cout << res << '\n';
  
	return 0;
}




Measured memory_bytes: 13568
#include <iostream>
#include <math.h>
#include<iomanip>
#include <string>
using namespace std;

int main() {
    int N;
    cin >> N;
    int A[100];
    int x;

    for (int i=0;i<N;i++){
        cin >> A[i];
    }

    for (int i=0;i<N;i++) {
        int minj = i;
        for (int j=i;j<N;j++) {
            if (A[j] < A[minj]) { //Get the smallest place
                minj = j;
            }
        }
        if (A[i] > A[minj]) {
            int v = A[i];
            A[i] = A[minj];
            A[minj] = v;
            x++;
        }
    }

    for (int k=0;k<N-1;k++){
        if (k == (N-1)) {
            break;
        }
        else {
            cout << A[k] << " ";
        }
    }
    cout << A[N-1] << endl;
    cout << x << endl;
}

Measured memory_bytes: 3088
#include<iostream>
#include<algorithm>

using namespace std;
typedef long long ll;

ll N, A[200000];
ll sum[200001];

ll get_left(int a, int b) {
	ll ans;
	ans = max(sum[b] - sum[a], sum[a] - sum[0])
		- min(sum[b] - sum[a], sum[a] - sum[0]);
	return ans;
}

ll get_right(int b, int c) {
	ll ans;
	ans = max(sum[c] - sum[b], sum[N] - sum[c])
		- min(sum[c] - sum[b], sum[N] - sum[c]);
	return ans;
}

ll get_ans(int a, int b, int c) {
	//Aについて　[0,a - 1] [a, b - 1] [b, c - 1] [c, N - 1]　の区間での差を求める
	ll ans;
	ans = max(max(sum[a] - sum[0], sum[b] - sum[a]), max(sum[c] - sum[b], sum[N] - sum[c]))
		- min(min(sum[a] - sum[0], sum[b] - sum[a]), min(sum[c] - sum[b], sum[N] - sum[c]));	

	return ans;
}

int main() {
	cin >> N;
	sum[0] = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum[i + 1] = sum[i] + A[i];
	}

	ll ans = 1e18;
	int left = 0, right = 2;

	for (int center = 1; center < N - 1; center++) {
		//左から一つ目のしきりのしゃくとり
		ll left_dif = get_left(left, center);
		while (1) {
			if (left_dif > get_left(left + 1, center)) {
				left++;
				left_dif = get_left(left, center);
			}
			else {
				break;
			}
		}

		//左から三つ目のしきりのしゃくとり
		ll right_dif = get_right(center, right);
		while (1) {
			if (right == N - 1)break;
			if (right_dif > get_right(center, right + 1)) {
				right++;
				right_dif = get_right(center, right);
			}
			else {
				break;
			}
		}
		ans = min(ans, get_ans(left, center, right));

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3328
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n=int(input())
l=list(map(int,input().split()))
m=max(l)
if 2*m<sum(l):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 65092
#include <iostream>
#include <algorithm>

long get_min(int X,int Y){
    long S_a,S_b,S_c;
    long y;
    long min =1000000000;
    for (size_t x = 1; x < X; x++) {
        S_a=x*Y;
        y=Y/2;
        S_b=(X-x)*y;
        S_c=(X-x)*(Y-y);
        min=std::min(std::max({S_a,S_b,S_c})-std::min({S_a,S_b,S_c}),min);
    }
    return min;
}


int main(int argc, char const *argv[]) {
    int H,W; std::cin >> H >> W;

    if (H%3==0 || W%3==0) {
        std::cout << 0 << '\n';
    }else{
        int ans1=get_min(H,W);
        int ans2=get_min(W,H);
        int ans3=W;
        int ans4=H;

        std::cout << std::min({ans1,ans2,ans3,ans4}) << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[5100],b[5100];
int main(){
	int A,B;
	cin>>A>>B;
	for(int i=0;i<A;i++)cin>>a[i];
	for(int i=0;i<B;i++)cin>>b[i];
	int ans=0;
	for(int i=0;i<B;i++){
		int p=0,len=0;
		while(p<A){
			if(a[p]==b[i+len])len++;
			p++;
		}
		ans=max(ans,len);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3144
import math
a,b = map(int,input().split(" "))
if abs(a - b) >= 2:
    print(0)
else:
    A = math.factorial(a)
    B = math.factorial(b)
    if a == b:
        print(((A * B) * 2) % (10 ** 9 + 7))
    else:
        print((A * B) % (10 ** 9 + 7))

Measured memory_bytes: 5196
n = gets.to_i
(1..n).each do |i|
  x = i
  if x % 3 == 0
    print " #{i}"
  else
    until x == 0
      if x % 10 == 3
        print " #{i}"
        break
      else
        x /= 10
      end
    end
  end
end
print "\n"

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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int n;
    cin>>n;
    // int a[n];
    // f1(i,0,n)
    // cin>>a[i]
    int cc=0;
    f1(i,0,n)
    {
    	cin>>temp;
    	if(temp!=i+1)
    		cc++;
    }
    if(cc<=2)
    {
    	cout<<"YES";
    }
    else
    	cout<<"NO";
    return 0;
}

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

int main(){
  for(int j=0; j<101; j++){
    int N;
    cin >> N;
    if(N == 0){
      break;
    }
    int ba=0, temp;
    vector<int> ans(N,0);
    string c;
    cin >> c;
    for(int i=1; i<=100; i++){
      if(c.at(i-1) == 'M'){
         ans.at(i%N)++;
       }else if(c.at(i-1) == 'S'){
         temp = ans.at(i%N);
         ans.at(i%N) = 0;
         ba += temp;
         ba++;
       }else{
         ans.at(i%N)++;
         ans.at(i%N) += ba;
         ba = 0;
       }
     }
     sort(ans.begin(), ans.end());
     for(int i=0; i<N; i++){
       cout << ans.at(i) << " ";
     }
     cout << ba << endl;
  //    for(int i=1; i<N; i++){
  //      cout << ans.at(i) << " ";
  //   }
  //   cout << ans.at(0) << " " << ba << endl;
   }
  return 0;
}



Measured memory_bytes: 3216
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        ArrayList<String> list = new ArrayList<String>();
        for(int i=0;i<N;i++){
            String s = sc.next();
            list.add(s);
        }
        Collections.sort(list);
        String ans = "";
        for(int i=0;i<N;i++){
            ans+=list.get(i);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
n, k, s = list(map(int, input().split()))
ans = [None for _ in range(n)]

for i in range(k):
    ans[i] = s
for i in range(k, n):
    if s == 1:
        ans[i] = 2
    else:
        ans[i] = s//2+1

print(*ans)


Measured memory_bytes: 9692
#include <iostream>
#include <vector>
#include <tuple>
#include <numeric>
#include <cmath>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(c) (c).begin(), (c).end()
const double eps = 1e-8, inf = 1e8;
const int M = 256;

int N;

tuple<int, int, int> solve(vector<int>& Is){
    int S = 0, A = 0, C = 0;
    double Hmin = inf;
    rep(s, 16)rep(a, 16)rep(c, 16){
        vector<int> Os(M, 0);
        int R = s;
        for(int& I: Is){
            R = (a * R + c) % M;
            Os[(I + R) % M]++;
        }
        double H = accumulate(all(Os), 0.0, [&](double h, int x){return x? h - 1.0 * x/N * log(1.0 * x/N): h;});
        if(Hmin <= H + eps)continue;
        Hmin = H;
        S = s; A = a; C = c;
    }
    return make_tuple(S, A, C);
}

int main(){
    while(cin >> N, N){
        vector<int> Is(N);
        rep(i, N)cin >> Is[i];
        int S, A, C;
        tie(S, A, C) = solve(Is);
        cout << S << " " << A << " " << C << '\n';
    }
    return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <math.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  float digits_f = log(n)/log(10)+1;
  int digits = digits_f;
  int head = (n+1)/pow(10,digits-1);
  int answer = (digits-1)*9+head-1;
  printf("%d\n", answer);

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include "string"
#define endl '\n'
#define pi pair<int,int>
#define ff first
#define ss second
#define int long long 
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)

int okk(vector<int>&s0,vector<int>&s1,vector<int>&s2){
	int ans=0;
	for(int i=0;i<s0.size();i++){
    	int it = lower_bound(s1.begin(),s1.end(),s0[i])-s1.begin();
    	for(int j=it;j<s1.size();j++){
    		it = s2.end()- lower_bound(s2.begin(),s2.end(),s1[j]);
    		//cout<<s0[i]<<" "<<s1[j]<<" "<<it<<endl;
    		ans+=it;
    		if(binary_search(s2.begin(),s2.end(),s1[j]+s1[j]-s0[i]))
    			ans--;
    	}
    }
    return ans;
}

int32_t main() { 
    boost;
    int n;
    cin>>n;
    string ss;
    cin>>ss;
    int ans=0;
    vector<int>s[3];
    for(int i=0;i<ss.size();i++){
    	if(ss[i]=='R')
    		s[0].push_back(i);
    	else if(ss[i]=='G')
    		s[1].push_back(i);
    	else
    		s[2].push_back(i);
    }
	ans+=okk(s[0],s[1],s[2]);
	ans+=okk(s[0],s[2],s[1]);
	ans+=okk(s[1],s[0],s[2]);
	ans+=okk(s[1],s[2],s[0]);
	ans+=okk(s[2],s[0],s[1]);
	ans+=okk(s[2],s[1],s[0]);
    cout<<ans<<endl;
}           





Measured memory_bytes: 3720
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;

 
int main() {
	
string S;
int ans=0;
cin>>S;
fyg(S.size(),1){
	if(S.at(y)!=S.at(y-1)){
		ans++;
	}
}
ce(ans)
	
}

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

int main() {
	long double a, b, x;
	cin >> a >> b >> x;
	long double theta;
	if (x < a * a * b / 2) {
		long double tan = a * b * b / 2.0 / x;
		theta = atan(tan);
	}
	else {
		long double tan = 2.0 * (a * a * b - x) / a / a / a;
		theta = atan(tan);
	}
	theta /= (long double)3.1415926535897932 / 180.0;
	cout << setprecision(14);
	cout << theta << endl;

}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    ll N; cin >> N;

    ll ans = 0;
    for(ll i= 1; i*i <= N; i++) {
        if (N%i == 0){
            ll m = N/i-1;
            if (i<m) ans += m;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;

typedef long long ll;

struct Cycle {
	ll score;
	ll size;

	Cycle() {
		score = 0;
		size = 0;
	}
};

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

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

	}

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

	vector<bool> vis(n, false);
	vector<int> toCycleID(n, -1);
	vector<Cycle> cycles;

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

		ll num = i;

		if (vis[num]) continue;

		unordered_set<int> vis2;
		vis2.insert(num);

		while (1) {

			// 前の探索で検索済み -> 何もしない
			if (vis[num]) break;
			vis[num] = true;

			// 今回の探索で一度通った -> サイクル
			if (vis2.count(num)) {
				int cycleId = cycles.size();
				Cycle cycle;
				while (toCycleID[num] == -1) {
					toCycleID[num] = cycleId;
					cycle.score += c[num];
					cycle.size++;
					num = p[num];
				}
				cycles.push_back(cycle);
				break;
			}

			// どちらでもない -> つぎのノードへ
			num = p[num];
			vis2.insert(num);
		}
	}

	ll max = c[0];
	for (int i = 0; i < n; i++)
	{
		int num = p[i];
		ll sum = c[num];
		ll sum_max = sum;
		bool cycleFlag = true;

		for (int rem = k - 1; rem > 0; rem--)
		{
			num = p[num];

			if (cycleFlag && toCycleID[num] != -1) {
				Cycle& cycle = cycles[toCycleID[num]];

				if (rem > cycle.size * 2)
				{
					int cnt = rem / cycle.size - 1;

					// サイクルが正のスコア
					if (cycle.score > 0) {
						sum += cnt * cycle.score;
						rem -= cnt * cycle.size;
					}
					// サイクルが負のスコア
					else {
						rem -= cnt * cycle.size;
					}
				}
				cycleFlag = false;
			}

			sum += c[num];
			if (sum_max < sum)
				sum_max = sum;
		}

		if (max < sum_max)
			max = sum_max;
	}

	cout << max << endl;
}

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

int main()
{
  int N;
  cin >> N;
  int a[N];
  for(int i = 0; i < N; i++)
    cin >> a[i];
  int ans = 0;
  for(int i = 0; i < N; i++)
    if(a[a[i]-1] == i+1) ans++;
  cout << ans/2 << endl;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strings"
)

var N, ans int

func main() {
	fmt.Scan(&N)
	reader := bufio.NewScanner(os.Stdin)
	xxx := make(map[string]int, N)

	for i := 0; i < N; i++ {
		reader.Scan()
		s := strings.Split(reader.Text(), "")[0]
		if s == "M" || s == "A" || s == "R" || s == "C" || s == "H" {
			xxx[s]++
		}

	}
	ans += xxx["M"] * xxx["A"] * xxx["R"]
	ans += xxx["M"] * xxx["A"] * xxx["C"]
	ans += xxx["M"] * xxx["A"] * xxx["H"]
	ans += xxx["M"] * xxx["R"] * xxx["C"]
	ans += xxx["M"] * xxx["R"] * xxx["H"]
	ans += xxx["M"] * xxx["C"] * xxx["H"]
	ans += xxx["A"] * xxx["R"] * xxx["C"]
	ans += xxx["A"] * xxx["R"] * xxx["H"]
	ans += xxx["A"] * xxx["C"] * xxx["H"]
	ans += xxx["R"] * xxx["C"] * xxx["H"]

	fmt.Println(ans)
}

/*  ----------------------------------------  */
func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

// type LR []int

// func (a SortBy) Len() int           { return len(a) }
// func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
// func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }


Measured memory_bytes: 6272
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB=sorted(AB,key=lambda x:x[0])
cnt=0
ans=0
for a,b in AB:
    tmp=cnt
    cnt=min(m,cnt+b)
    ans+=a*(cnt-tmp)
    if cnt==m:
        break
print(ans)

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

using namespace std;

int main(void)
{
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    int n, m, x, cost = 0, best = 12 * 100000 + 1;
    scanf("%d %d %d", &n, &m, &x);
    int books[n][m + 1];
    int sum[m] = {0};
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m + 1; j++)
            scanf("%d", &books[i][j]);
    }
    for (int i = 1; i < (1 << n); i++)
    {
        for (int j = 0; j < n; j++)
        {
            if ((1 << j) & i)
            {
                cost += books[j][0];
                for (int k = 0; k < m; k++)
                {
                    sum[k] += books[j][k + 1];
                }
            }
        }
        for (int j = 0; j < m; j++)
        {
            if (sum[j] < x)
            {
                cost = 12 * 100000 + 1;
                break;
            }
        }
        best = min(best, cost);
        memset(sum, 0, sizeof(sum));
        cost = 0;
    }
    if (best == 12 * 100000 + 1)
    {
        printf("-1\n");
    }
    else
    {
        printf("%d\n", best);
    }

}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
int page(int n)
{
  int x;
  if(n%2==0)
  {
    x=n/2;
    return x;
  }
  else
  {
    x=n/2+1;
    return x;
  }
}
int main()
{
  int n,res;
  cin>>n;
  res=page(n);
  cout<<res;
  return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    prime=[0,1]*500000
    prime[2]=1
    for x in range(3,500000):
        if prime[x]:
            for y in range(x**2,1000000,x):
                prime[y]=0
    x=II()
    for y in range(x,1000000):
        if prime[y]:
            print(y)
            break


main()

Measured memory_bytes: 10868
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ii d[4];
MaxHeap<ii> pqa,pqb;
int cta[MAXn],ctb[MAXn];
int main(){
  IOS();
  int n;
  cin>>n;
  REP(i,n){
    int x;
    cin>>x;
    if( i&1 ) cta[x]++;
    else ctb[x]++;
  }
  REP(i,MAXn){
    if( cta[i] != 0 ) pqa.push(mkp(cta[i],i));
    if( ctb[i] != 0 ) pqb.push(mkp(ctb[i],i));
  }

  REP(i,4){
    if( i<2 ){
      if( SZ(pqa) ) d[i] = pqa.top(),pqa.pop();
    }
    else{
      if( SZ(pqb) ) d[i] = pqb.top(),pqb.pop();
    }
  }
  if( d[0].Y != d[2].Y ) cout<<n-d[0].X-d[2].X<<endl;
  else cout<<min(n-d[0].X-d[3].X,n-d[1].X-d[2].X)<<endl;
}


Measured memory_bytes: 2804
from sys import stdin
N,M,K = [int(x) for x in stdin.readline().rstrip().split()]
mod = 998244353
maxn = 2*10**5+1

fac  = [0 for _ in range(maxn)]
finv = [0 for _ in range(maxn)]
inv  = [0 for _ in range(maxn)]

fac[0]  = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

for i in range(2,maxn):
    fac[i] = fac[i-1] * i % mod
    inv[i] = mod - inv[mod%i] * (mod // i) % mod
    finv[i] = finv[i-1] * inv[i] % mod

def combinations(n,k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

ans = 0
for i in range(0,K+1):
    tmp = 1
    tmp *= M*pow(M-1,N-i-1,mod)
    tmp %= mod
    tmp *= combinations(N-1,i)
    tmp %= mod
    ans += tmp
    
print(ans%mod)

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

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int[] x;
		x = new int[100000];
		int i=0,j;
		while(true)
		{
			x[i] = sc.nextInt();
			if(x[i]==0)break;
			i++;
		}
		for(j=0;j<i;j++)
		{
			System.out.printf("Case %d: %d\n",j+1,x[j]);
		}
	}
}

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

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795

ll f(ll a)
{
  ll cnt=0,i;
  for(i=1;i*i<a;i++)
  {
if(a%i==0)cnt+=2;
  }
  if(i*i==a)cnt++;
  return cnt;
}
ll ans(ll x)
{
ll l=1, r=4000;
ll m;
while(l<=r)
{
  m=(l+r)/2;
  ll temp=ll(100*pow(1.01,m));
  if(temp>x)r=m-1;
  else if(temp<=x)l=m+1;
 // else return m;
}
return m;
}

ll powM(ll a,ll b, ll m)
{ 
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
return ans%m;
}


int main()
{
 long double x;cin>>x;
long double temp=100,ans=0;
for(int i=1;i<4000;i++)
{
temp=temp*101/100;
ll as=(ll)temp;
temp=as;
if(as>=x)
{
  ans=i;
  break;
}

}
cout<<ans<<"\n";
  return 0;


}





Measured memory_bytes: 3848
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

vector<ll> dq;
vector<ll> S;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	dq.pb(0); S.pb(0);
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		char c='+';
		if(i>0) 
		{
			cin>>c;
		}
		ll x; cin>>x;
		sum+=x;
		if(c=='+')
		{
			S.back()+=x;
		}
		else
		{
			S.pb(0);
			dq.pb(x);
		}
	}
	if(dq.size()==1)
	{
		cout<<sum<<'\n';
		return 0;
	}
	ll ans = -ll(1e18);
	for(int i=1;i<S.size();i++)
	{
		ans=max(ans, sum - 2LL*(S[i]+dq[i]));
		sum-=2LL*dq[i];
	}
	ans = max(ans, sum);
	cout<<ans<<'\n';
}


Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
  const ll mod=998244353;
  int n,d[100010];
  cin >> n;
  int i,ma=0;
  for(i=0;i<n;i++){
    cin >> d[i];
    ma=max(ma,d[i]);
  }
  if(d[0]!=0){
    cout << 0 << endl;
    return 0;
  }
  vector<int> x(100010,0);
  for(i=0;i<n;i++){
    x[d[i]]++;
  }
  if(x[0]!=1){
    cout << 0 << endl;
    return 0;
  }
  for(i=0;i<=ma;i++){
    if(x[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans=1;
  for(i=1;i<=ma-1;i++){
    ans*=modpow(x[i],x[i+1],998244353);
    ans=ans%mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4032
#include <stdio.h>

int main(void){
	int n,k,p;
	int i,j;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&k,&p);
		j=k%p;
		if(j==0){
			printf("%d\n",p);
		}else{
			printf("%d\n",j);
		}
	}
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define true 1
#define false 0

int n,A[20];

int solve(int i, int m){
    int res;
    if (m == 0)
        return true;
    if (i >= n)
        return false;
    res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main(){
    int i,q,m;
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&m);
        if(solve(0, m)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}



Measured memory_bytes: 2104
# 入力割り当て
S = str(input())
l = len(S)

# 文字列判定
flg = True
ans = 'YES'
i = 0
while flg:
	if S[i:i+11] == 'dreameraser':
		i +=11
	elif S[i:i+10] == 'dreamerase':
		i += 10
	elif S[i:i+7] == 'dreamer':
		i += 7
	elif S[i:i+6] == 'eraser':
		i += 6
	elif S[i:i+5] == 'dream' or S[i:i+5] == 'erase':
		i += 5
	elif i >= l:
		flg = False
	else:
		flg = False
		ans = 'NO'

# 結果の表示
print(ans)

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

using namespace std;

char in[120];
pair<pair<string,int>,int> p[110];

int main(){

	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		int t;scanf("%s%d",in,&t);
		string tmp=in;
		p[i]=make_pair(make_pair(in,-t),i);
	}
	std::sort(p,p+a);
	for(int i=0;i<a;i++)printf("%d\n",p[i].second+1);

	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define JUDGE(y, x) ((surface[y][x] == '1') ? 1 : 0)
int main(){
  int  i, j, c, px[4], py[4];
  char surface[8][8] = {};
  while(1){
    c = 0;
    for(i = 0;i < 8;i++){
      if(scanf("%s", surface[i]) == EOF) 
	return 0;
    }

    /*    for(i = 0;i < 8;i++){
      for(j = 0;j < 8;j++){
	printf("%c", surface[i][j]);
      }
      puts("");
      } */
    for(i = 0;i < 8;i++)
      for(j = 0;j < 8;j++)
	if(JUDGE(i, j))
	  goto loopend;

  loopend:

    if(JUDGE(i, j + 1) && JUDGE(i + 1, j) && JUDGE(i + 1, j + 1)) puts("A");
    else if(JUDGE(i + 2, j)) puts("B");
    else if(JUDGE(i, j + 2)) puts("C");
    else if(JUDGE(i + 2, j - 1)) puts("D");
    else if(JUDGE(i + 1, j + 2)) puts("E");
    else if(JUDGE(i + 2, j + 1)) puts("F");
    else puts("G");
  }
}

Measured memory_bytes: 524
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];
    auto HS = readln.split.to!(long[]);
    if (K >= N) {
        writeln(0);
        return;
    }
    sort!"a > b"(HS);
    long d;
    foreach (h; HS[K..$]) d += h;
    writeln(d);
}

Measured memory_bytes: 11156
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define ref(i,x,y)for(int i=x;i<=y;++i)
#define def(i,x,y)for(int i=x;i>=y;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
int n,m;char a[5010];
char c,ans[5010],s[5010];
void ck(){
	ref(i,1,n)if(s[i]<ans[i])break;else if(s[i]>ans[i])return;
	ref(i,1,n)ans[i]=s[i];
}
void work(int x){
	int nn=0;
	ref(i,x,n)s[++nn]=a[i];
	def(i,n,n-x+2)s[++nn]=a[i];
	int ct=0,lct=0;
	ref(i,1,n)if(s[i]==c){
		ct++;
	}else break;
	lct=ct;
	int mm=m;
	while(ct<n&&mm>0)ct*=2,mm--;
	if(ct>n)ct=n;
	def(i,n-ct,1)s[i+ct]=s[i+lct];
	ref(i,1,ct)s[i]=c;
	ck();
}
int main(){
	scanf("%d%d",&n,&m);m--;
	scanf("%s",a+1);
	ref(i,1,n)ans[i]=a[i];
	c=a[1];
	ref(i,1,n)if(a[i]<c)c=a[i];
	ref(i,1,n)if(a[i]==c)if(i==1||a[i]!=a[i-1])
		work(i);
	ref(i,1,n)cout<<ans[i];cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cstring>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#define reep(n1,n2,n3) for(int n1=n3;n1<n2;n1++)
#define rep(n1,n2) reep(n1,n2,0)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define INF 1e9
using namespace std;
typedef long long int lint;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int,int> > vp;
typedef pair<int,int> pi2;
typedef pair<int,pair<int,int> > pi3;
typedef vector<string> vs;
typedef pair<double,double> pdd;
const double PI  = acos(-1.0);
int main(){
    string str;
    cin>>str;
    int j,o,i,res=0;
    j=o=i=0;
    rep(k,str.length()){
        if(str[k]=='J'){
            if(i||o)j=i=o=0;
            j++;
        }
        if(str[k]=='O'){
            if(!i){
                if(j)o++;
            }else{
                j=o=i=0;
            }
        }
        if(str[k]=='I'){
            i++;
            if(j&&o&&j>=o&&i==o){
                res=max(res,o);
            }
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 2048
import sys
input = sys.stdin.readline

def main():
    N = int(input())

    A = list(map(int, input().split()))
    A. sort()
    Nmax = A[-1] + 1

    prime = [0]*Nmax
    for i in range(N):
        if prime[A[i]] == 0:
            prime[A[i]] = 1
        else:
            prime[A[i]] = -1

    for a in A:
        if prime[a] != 0:
            for q in range(a*2, Nmax, a):
                prime[q] = 0

    res = 0
    for a in prime:
        if a == 1:
            res += 1

    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 92796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n; cin>>n;
  vector<ll> v(n);
  vector<ll> dp(n,1);
  int val=sqrt(n);
  vector<int> primes(n+1,1);
  primes[0]=primes[1]=0;
  ll ans=1;
  iota(v.begin(),v.end(),1);
  for(int i=2;i*i<=n;i++){
    if(primes[i]){
    for(int j=i;j<=n;j+=i){
      primes[j]=0; int cnt=0;
      while(v[j-1]%i==0) v[j-1]/=i,cnt++;
      dp[j-1]*=(cnt+1);
    }
    }
  }
  for(int j=2;j<=n;j++){
    if(v[j-1]!=1) dp[j-1]*=2;
    ans+=dp[j-1]*j;
  }
  cout<<ans<<endl;
}
    
      
      
      

Measured memory_bytes: 198640
import heapq
INFTY = 10**6
N,M = map(int,input().split())
G = {i:[] for i in range(1,N+1)}
for _ in range(M):
    a,b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)
dist = [INFTY for _ in range(N+1)]
dist[1] = 0
hist = [0 for _ in range(N+1)]
hist[1] = 1
heap = [(0,1)]
while heap:
    d,x = heapq.heappop(heap)
    if dist[x]<d:continue
    hist[x] = 1
    for y in G[x]:
        if hist[y]==0:
            if dist[y]>d+1:
                dist[y] = d+1
                heapq.heappush(heap,(d+1,y))
if dist[N]==2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 137364
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cwchar>
#include <cwctype>
#include <exception>
#include <locale>
#include <numeric>
#include <new>
#include <stdexcept>
#include <limits>
#include <valarray>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <list>
#include <utility>
#include <bitset>
#include <algorithm>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=1e9+7;
int main(){
	long long x,y;
	cin>>x>>y;
	int cnt=0;
	while(x<=y){
		x*=2;
		cnt++;
	}
	cout<<cnt;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define mset(a,x) memset(a,x,sizeof(a))
#define OUT(x) cout<<(x)<<"\n"
#define SZ(x) (int)(x).size()
#define FASTIO cin.tie(0),ios::sync_with_stdio(0)


const ll INF = 1145141919512810410LL;

int main() {
    FASTIO;
    int n, m;
    cin >> n >> m;

    vector<int> a(m), b(m);
    vector<ll> c(m);
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        --a[i]; --b[i];
        c[i] = -c[i];
    }

    vector<ll> d(n, INF);
    d[0] = 0;
    rep(loop, n - 1) {
        rep(i, m) {
            if(d[a[i]] == INF) continue;
            d[b[i]] = min(d[b[i]], d[a[i]] + c[i]);
        }
    }
    
    auto ans = d[n - 1];

    vector<bool> neg(n, false);
    rep(loop, n) rep(i, m) {
        if(d[a[i]] == INF) continue;
        if(d[b[i]] > d[a[i]] + c[i]) {
            neg[b[i]] = true;
            d[b[i]] = d[a[i]] + c[i];
        }

        if(neg[a[i]]) neg[b[i]] = true;
    }

    if(neg[n - 1]) OUT("inf");
    else OUT(-ans);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#define MOD 1000000007
#define forn(a, n) for(int a = 0; a<(int) (n); ++a)
#define dforn(a, n) for(int a = (n)-1; a>=0; --a)
#define forall(a, all) for(__typeof(all.begin()) a = all.begin(); a != all.end(); ++a)
#define EPS 0.000000000001
using namespace std;
typedef long long tint;
typedef pair<tint, tint> pii;
typedef vector<tint> vi;
typedef vector<vi> vvi;

int main()
{
	vvi pots(20, vi(20, 0));
	int n;
	cin >> n;
	tint ans = 0;
	forn(i, n) {
		double d;
		cin >> d;
		tint a = d*1000000000+0.1;
		tint p2 = 0, p5 = 0;
		while(a % 2 == 0) {
			a /= 2;
			p2++;
		}
		while(a % 5 == 0) {
			a /= 5;
			p5++;
		}
		for(int i = max(0LL, 18-p2); i <= 18; i++)
		for(int j = max(0LL, 18-p5); j <= 18; j++){
			ans += pots[i][j];
		}
		pots[min(18LL,p2)][min(18LL,p5)]++;
	}
	cout << ans << endl;
}


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

#define ED return 0;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) long(pow(x,y))
const long long mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    cin >> K;
    cout << (K/2) * ((K+1)/2) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int fun(int n)
{
	int s=0,t;
	t=n;
	while(n!=0)
	{
		s=s*10+n%10;
		n/=10;
	}
	if(t==s)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
int main()
{
	int s=0,i,n,m;
	scanf("%d %d",&n,&m);
	for(i=n;i<=m;i++)
	{
		if(fun(i))
		{
			s++;
		}
	}
	printf("%d",s);
	return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;
int inf = 1e9 + 7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int n;
    scanf("%d", &n);
    vector<int> d(n);
    rp(i, 0, n) scanf("%d", &d.at(i));
    sort(d.begin(), d.end());
    printf("%d", d.at(n/2) - d.at(n/2-1));
    return 0;
} 

Measured memory_bytes: 640