akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;
typedef long long ll;

int w, h;
vector<vector<char>> s(23, vector<char>(23));
vector<vector<bool>> visited(23, vector<bool> (23, false));
vector<vector<int>> grid(23, vector<int> (23, 0));
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

queue<pair<int, int>> Q;

void bfs(int si, int sj) {
  Q.push(make_pair(si, sj));
  visited[si][sj] = true;
  while (!Q.empty()) {
    int nx, ny;
    tie(ny, nx) = Q.front(); Q.pop();
    rep (i, 4) {
      int x = nx + dx[i];
      int y = ny + dy[i];
      if (0 <= x && x < w && 0 <= y && y < h && !visited[y][x] && s[y][x] == '.') {
        grid[y][x] = grid[ny][nx] + 1;
        visited[y][x] = true;
        Q.push(make_pair(y, x));
      }
    }
  }
}


int main(void) {
  
  cin >> h >> w;
  rep (i, h) rep (j, w) cin >> s[i][j];

  int ans = 0;



  rep (i, h) rep (j, w) {
    if (s[i][j] == '#') continue;
    rep (ii, h) rep (jj, w) visited[ii][jj] = false;
    rep (ii, h) rep (jj, w) grid[ii][jj] = 0;
    bfs(i, j);
    rep (ii, h) rep (jj, w) ans = max(ans, grid[ii][jj]);
    /*
    if (!i && !j) {
      rep (a, h) {
        rep (aa, w) cout << grid[a][aa];
        cout << endl;
      }
    }
    */
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#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<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define LL   long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MAX 100000000000000000
#define MOD 1000000007
#define files  freopen("OUTPUT.TXT","r",stdin);
#define PI 3.141592653589793238462
#define INF 1000000000
using namespace std;
int n,a,b,m[100006];
bool judge(LL x){
	LL sum=0;
	for (int i=0;i<n;++i){
		LL t =(LL)m[i]-x*b;
		if (t>0){
			sum+=(int)ceil((t*1.0/(a-b)));
			if (sum>x)return 0;
		}
	}
	return 1;
}

int main(){
	cin>>n>>a>>b;
	int imax=0;
	for (int i=0;i<n;++i)scanf("%d",&m[i]),imax=max(m[i],imax);
	LL l=0,r=imax;
	while (l<r){
		LL mid=l+r>>1;
		if (judge(mid))r=mid;else l=mid+1;
	}
	printf("%lld\n",r);
	return 0;	
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int l = 1;
		int r = N;
		for (int i=0; i<M; i++) {
			int L = sc.nextInt();
			int R = sc.nextInt();
			if (l < L) {
				l = L;
			}
			if (r > R) {
				r = R;
			}

		}
		System.out.println(r -l + 1 >= 0 ? r - l + 1 : 0);
	}

}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

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

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

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

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

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

Measured memory_bytes: 43052
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    char s[n];
    cin>>s;
    if(n%2==1){
        cout<<"No"<<endl;
        return 0;
    }
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[i+n/2]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
          
int main(){
 int x[2999];
 int y[2999];
 int i = 0;
 int c = 1;
 int j;
          
 while(1){
  scanf("%d %d\n",&x[i], &y[i]);
  if(x[i] == 0 && y[i] == 0) 
     break;
    
  i++;
 }
          
 for(j = 0;j < i;j++){
  if(x[j] < y[j])
   printf("%d %d\n",x[j], y[j]);
  else
   printf("%d %d\n",y[j], x[j]);
 }
 return 0;
}

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

using namespace std;
long long dp[3010][3010];
int main(){

string s,t;
cin>>s>>t;
memset(dp,0,sizeof(dp));

int a =s.length();
int b = t.length();

for(int i =1;i<=a;i++){
  for(int j=1;j<=b;j++){
    if(s[i-1]==t[j-1]){
      dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
    } else {
          dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    }
  }
}
string ans="";
int i=a,j=b;
while(i>=1 && j>=1){
    if(s[i-1]==t[j-1]){
      ans=s[i-1]+ans;
      i--;
      j--;
    } else {
      if(dp[i-1][j]==dp[i][j]){
        i--;
      } else {
        j--;
      }
    }
  
}

cout<<ans;

   return 0;
}

Measured memory_bytes: 71040
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    for (ll i = 1; i < 10; i++) {
        for (ll j = 1; j < 10; j++) {
            if (i * j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;
  int k;
  cin>>k>>s;
for(int i=0;i<min(k,(int)s.length());++i) {
  cout<<s[i];
}
  if(k<s.length()) {
    cout<<"...";
  }
return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  long double ans = 0.0;
  for (int i = 1; i <= N; i++) {
    long double count = 1.0;
    int check = 1;
    while (i*check < K) {
      check *= 2;
      count *= 0.5;
    }
    ans += count;
  }
  cout << setprecision(17) << ans/N << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cout << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)            \
    cerr << #v << ": ";         \
    REP(__i, (v).size())        \
    cerr << ((v)[__i]) << ", "; \
    cerr << endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main()
{
    ios::sync_with_stdio(false);
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;

    if (e - a <= k)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int x = sc.nextInt();
			int y = sc.nextInt();
			if(x==0 && y==0) break;
			
			ArrayList<Point2D.Double> list = new ArrayList<Point2D.Double>();
			ArrayList<Point2D.Double> temp = new ArrayList<Point2D.Double>();
			list.add(new Point2D.Double(x, y));
			
			int n = sc.nextInt();
			int[] xx = new int[n];
			int[] yy = new int[n];
			for(int i=0;i<n;i++){
				xx[i] = sc.nextInt();
				yy[i] = sc.nextInt();
			}
			
			int q, r;
			Point2D.Double p;
			boolean flag = false;
			for(int i=0;i<n;i++){
				x = xx[i];
				y = yy[i];
				for(int j=-1;j<=1;j++){
					for(int k=-1;k<=1;k++){
						if(0<=x+j && x+j<=9 && 0<=y+k && y+k<=9){
							for(int a=-1;a<=1;a++){
								for(int b=0;b<2;b++){
									q = x+j + 2*b + a*(1-b);
									r = y+k + 2*(1-b) + a*b;
									p = new Point2D.Double(q, r);
									if(list.contains(p)==true){
										temp.add(new Point2D.Double(x+j, y+k));
										a = 2;
										break;
									}
									q = x+j - 2*b + a*(1-b);
									r = y+k - 2*(1-b) + a*b;
									p = new Point2D.Double(q, r);
									if(list.contains(p)==true){
										temp.add(new Point2D.Double(x+j, y+k));
										a = 2;
										break;
									}
								}
							}
						}
					}
				}
				if(temp.size()==0){
					flag = true;
					break;
				}
				list.clear();
				for(int j=0;j<temp.size();j++) list.add(temp.get(j));
				temp.clear();
			}
			if(flag==true) System.out.println("NA");
			else System.out.println("OK");
		}
	}	
}

Measured memory_bytes: 18828
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
#define tc int t;cin>>t;while(t--)
#define get cin>>
#define geta ll a[n];for (int i = 0; i < n; ++i){cin>>a[i];}
#define puta for (int i = 0; i < n; ++i){cout<<a[i];}
#define put cout<<
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ld dp[301][301][301];
ld sushi(int i,int j,int k,int& n)
{
	if (i<0||j<0||k<0)
	{
		return 0;
	}
	if (i+j+k==0)
	{
		return 0;
	}
	if (dp[i][j][k])
	{
		return dp[i][j][k];
	}
	dp[i][j][k] += n;
	dp[i][j][k] += (i*sushi(i-1,j,k,n));
	dp[i][j][k] += (j*sushi(i+1,j-1,k,n));
	dp[i][j][k] += (k*sushi(i,j+1,k-1,n));
	dp[i][j][k] /= (i+j+k);
	return dp[i][j][k];
}
int main() 
{
   fast();
   int n;cin>>n;int a;int one=0,two=0,tre=0;
   for (int i = 0; i < n; ++i)
   {
   	cin>>a;
   	if(a==1)
   	{
   		one++;
   	}
   	else if(a==2)
   	{
   		two++;
   	}
   	else
   	{
   		tre++;
   	}
   }
   memset(dp,0,sizeof(dp));
   ld ans=sushi(one,two,tre,n);
   cout<<fixed<<setprecision(9)<<ans;
   return 0;
}

Measured memory_bytes: 426496
#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>;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int main() {
  double pi = acos(-1);
  int r;
  cin >> r;
  cout << fixed << setprecision(10);
  cout << 2*pi*r << endl;
  return 0;
}

Measured memory_bytes: 3772
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int a[100001];
int b[100001];

int binarySearch(int a[], int n, int data){
    int left = 0, right = n-1;
    while(left <= right){
        int mid = (left+right)/2;
        if(a[mid] == data){
            return mid;
        } else if(a[mid] < data){
            left = mid+1;
        }
        else{
            right = mid-1;
        }
    }
    return -1;
}
int main(){
    int n, m;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    scanf("%d", &m);
    for(int i = 0; i < m; i++){
        scanf("%d", &b[i]);
    }

    int cnt = 0;
    for(int i = 0; i < m; i++){
        if(binarySearch(a, n, b[i]) >= 0){
            cnt++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 3152
let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let acc = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    Scanf.scanf "%d " @@ fun a ->
      acc.(max 0 (i - a)) <- acc.(max 0 (i - a)) + 1;
      acc.(min n (i + a + 1)) <- acc.(min n (i + a + 1)) - 1
  done;
  for i = 1 to n - 1 do
    acc.(i) <- acc.(i) + acc.(i - 1)
  done;
  begin try
    for j = 1 to k - 1 do
      let modified = ref false in
      let d = Array.make (n + 1) 0 in
      for i = 0 to n - 1 do
        d.(max 0 (i - acc.(i))) <- d.(max 0 (i - acc.(i))) + 1;
        d.(min n (i + acc.(i) + 1)) <- d.(min n (i + acc.(i) + 1)) - 1
      done;
      if d.(0) <> acc.(0) then modified := true;
      acc.(0) <- d.(0);
      for i = 1 to n - 1 do
        if acc.(i) <> acc.(i - 1) + d.(i) then modified := true;
        acc.(i) <- acc.(i - 1) + d.(i)
      done;
      if not !modified then raise Not_found
    done
  with Not_found -> () end;
  for i = 0 to n - 1 do
    Printf.printf "%d " acc.(i)
  done;
  print_newline ()



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

typedef long long ll;

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

  if (500 * k >= x) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define PI 3.14159265358979323846264338327950288
 
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;

int par[200055] ;

int getPar( int x ){
    if( par[x] < 0 )
        return x ;
    return par[x] = getPar(par[x]) ;
}
void unionFind( int x , int y ){
    x = getPar(x) ; y = getPar(y) ;
    if( x != y ){
        par[x] += par[y] ;
        par[y] = x ;
    }
}
int main(){
    FAST_IO ;
    memset(par, -1, sizeof(par)) ;
    int N , M ; cin >> N >> M ;
    for( int i = 1 ; i <= M ; i++ ){
        int x , y ; cin >> x >> y ;
        unionFind(x, y) ;
    }
    int cnt = 0 ;
    for( int i = 1 ; i <= N ; i++ ){
//        cout << par[i] << "," ;
        if( par[i] < 0 )
            cnt = max( cnt , -par[i] ) ;
    }
    cout << cnt << endl ;
    return 0 ;
    
}
 

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

int main()
{
	int sum, a, b, c;

	cin >> a >> b >> c;
	
	sum = a + b + c;
	a = max(a, b);
	a = max(a, c);
	cout << sum - a << endl;

	return (0);
}


Measured memory_bytes: 256
import collections
import math
import operator as op
from functools import reduce
from collections import Counter
import numpy as np
import math
import bisect
import heapq


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def main():
   N, M = get_inputs(int)
   A = get_inputs(int)
   print(max(-1, N - sum(A)))





if __name__ == '__main__':
    main()


Measured memory_bytes: 27660
#include<iostream>
#include<map>
#include<vector>
#include<sstream>
using namespace std;
#define DIR 1
#define FILE 2
#define ARB 3
#define IDX "index.html"
#define REP(i,b,e) for(int i=b;i<e;i++)
#define rep(i,n) REP(i,0,n)
class Tree{
public:
  int type;
  string myname;
  map<string,Tree* > M;
  Tree(){type=DIR;M.clear();myname="";}
};

void get_path(string a,vector<string>&b){
  rep(i,a.size())if (a[i]=='/')a[i]=' ';
  stringstream sin(a);
  while(sin>>a)b.push_back(a);
}

void get_query(string a,vector<pair<string,int> > & b){
  REP(i,1,a.size()){
    string t;
    while(i<a.size() && a[i] != '/')t+=a[i++];
    b.push_back(make_pair(t,DIR) );
  }
  if ( b.size() == 0)return;
  if ( a[a.size()-1]=='/')b.push_back(make_pair(IDX,FILE) );
  else b[b.size()-1].second =ARB;
}

void make_tree(Tree *a,vector<string>&b,int &p){
  if (b.size()==p){return;}
  Tree *next=a->M[b[p]];
  if ( next == 0){
    next = new Tree;
    next->myname=b[p];
    a->M[b[p]]=next;
    next->type = p+1==b.size()?FILE:DIR;
    make_tree(next,b,++p);
  }else make_tree(next,b,++p);  
}

Tree* Find_Page(Tree *a,vector<pair<string,int> >&b,int &p,Tree *prev){
  Tree *ret=a;
  while(p < b.size()){
    if (b[p].first == "."){p++;continue;}
    else if ( b[p].first ==".."){p++;return prev;}
    Tree *next = a->M[b[p].first];
    if ( next == 0 || (next->type&b[p].second )==0  )return NULL;
    ret = Find_Page(next,b,++p,a);
    if ( ret == NULL)return NULL;
  }

  if (ret->type == FILE)return ret;
  ret = ret->M[IDX];
  if ( ret == 0 || ret->type !=FILE)return NULL;
  return ret;
}

void solve(string *q,Tree *root){
  Tree *data[2];
  rep(i,2){
    vector<pair<string,int> > a;
    int p=0;
    data[i]=NULL;
    get_query(q[i],a);
    data[i]=Find_Page(root,a,p,NULL);
    if (  data[i] == NULL){puts("not found");return;}
  }
  if (data[0] == data[1] )puts("yes");
  else puts("no");
}

main(){
  int n,q;
  while(cin>>n>>q &&n){
    Tree root;
    string t;
    vector<string> a;
    int p=0;
    rep(i,n)cin>>t,get_path(t,a),make_tree(&root,a,p=0),a.clear();
    rep(i,q){
      string in[2];
      cin>>in[0]>>in[1];
      solve(in,&root);
    }
  }
  return false;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

vector<ll> fact, invfact;
ll modpower(ll x, ll n, ll mod)
{
    ll res = 1;
    while (n)
    {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
ll inv(ll n)
{
    return modpower(n, MOD - 2, MOD);
}
void COMinit(ll k)
{ //空っぽの配列を二つ
    k++;
    fact.resize(k, 0);
    invfact.resize(k, 0);
    fact[0] = 1;
    repi(i, k, 1)
    {
        fact[i] = fact[i - 1] * i % MOD;
    }
    invfact[k - 1] = inv(fact[k - 1]);
    repd(i, k - 2, 0)
    {
        invfact[i] = invfact[i + 1] * (i + 1) % MOD;
    }
    return;
}
ll nCk(vector<ll> &fact, vector<ll> &invfact, ll n, ll k)
{ //この関数を使う前にCOMinit
    if (k < 0 || n < k)
        return 0LL;
    return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}
ll com(ll n, ll k)
{
    ll iv = 1;
    ll fa = 1;
    repi(i, k, 0)
    {
        fa *= (n - i);
        fa %= MOD;
    }
    repi(i, k + 1, 1)
    {
        iv *= inv(i);
        iv %= MOD;
    }
    return fa * iv % MOD;
}

//---------main function----------

int main()
{
    int n;
    cin >> n;
    ll sum = 0;
    vector<int> vec(100001, 0);
    repi(i, n, 0)
    {
        ll a;
        cin >> a;
        sum += a;
        vec[a-1]++;
    }
    // cout <<sum << endl;
    int q;
    cin >> q;
    repi(i, q, 0)
    {
        ll b, c;
        cin >> b >> c;
        // cout << "b: "  << b-1 << " " << vec[b-1] << " " << "c: " << vec[c-1] << endl;
        sum -= (b * vec[b-1] + c * vec[c-1]);
        // cout << "psum : " << sum << endl;
        vec[c-1] += vec[b-1];
        vec[b-1] = 0;
        sum += vec[c-1] * c;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3756
#include <queue>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

typedef int Weight;
Weight INF = 100000000;
struct Edge{
  int src, dest; Weight weight;
  bool operator < (const Edge &rhs) const {return weight > rhs.weight;}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

void add_edge(Graph &g, int src, int dest, Weight weight) {
  g[src].push_back((Edge){src, dest, weight});
}

// Dijkstra (Verified: AOJ2005)
void dijkstra(Graph &g, Array &d, int s) {
  d.assign(g.size(), INF);
  d[s] = 0;
  typedef pair<Weight,int> P;
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  while (!que.empty()) {
    Weight dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    REP(i, g[v].size()) {
      Edge e = g[v][i];
      if (d[e.dest] > d[v] + e.weight) {
        d[e.dest] = d[v] + e.weight;
        que.push(P(d[e.dest], e.dest));
      }
    }
  }
}

int cal(vector<int>& c, int bits) {
  int res = 0;
  REP(i,c.size())
    if ((bits >> i) & 1)
      res += c[i];
  return res;
}

int main() {
  while(1){
    int m,n,k,d;
    cin>>m>>n>>k>>d;
    if(!m) break;
    vector<int> c(m);
    REP(i,m) cin>>c[i];
    Graph g((1<<m)*(2+n+m));
    REP(i,d) {
      string s,t;
      int dst;
      cin >> s >> t >> dst;
      int si,ti;
      switch(s[0]) {
        case 'H':
        si = 0;
        break;
        case 'D':
        si = 1;
        break;
        case 'L':
        si = 1 + stoi(s.substr(1));
        break;
        case 'C': 
        si = 1 + n + stoi(s.substr(1));
        break;
      }
      switch(t[0]) {
        case 'H':
        ti = 0;
        break;
        case 'D':
        ti = 1;
        break;
        case 'L':
        ti = 1 + stoi(t.substr(1));
        break;
        case 'C': 
        ti = 1 + n + stoi(t.substr(1));
        break;
      }
      REP(j,1<<m) {
        if (si >= 2 + n) {
          int sci = si - (2+n);
          if (((j >> sci) & 1) == 0) {
            add_edge(g, j*(2+n+m)+si, (j | (1 << sci))*(2+n+m)+ti, dst);
          }
        } else {
          add_edge(g, j*(2+n+m)+si, j*(2+n+m)+ti, dst);
        }
        if (ti >= 2 + n) {
          int tci = ti - (2+n);
          if (((j >> tci) & 1) == 0) {
            add_edge(g, j*(2+n+m)+ti, (j | (1 << tci))*(2+n+m)+si, dst);
          }
        } else {
          add_edge(g, j*(2+n+m)+ti, j*(2+n+m)+si, dst);
        }
      }
    }
    Array dfh;
    dijkstra(g, dfh, 0);
    int minc = 100000000;
    REP(i,1<<m) {
      int htd = dfh[1+i*(2+n+m)];
      minc = min(minc, htd * k - cal(c, i));
    }
    cout << minc << endl;
  }
  return 0;
}

Measured memory_bytes: 1964
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 g=i
 if l<H and A[i]<A[l]:g=l
 if r<H and A[g]<A[r]:g=r
 if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 64172
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
//#define MOD (1000000007)
#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

int n,s,dp[3000][3000];//yep 3k chalega
vi v;

int f(int i,int sum){
    if(sum==s)return n-i+1;
    if(sum>s || i==n)return 0;
    int &ans=dp[i][sum];
    if(ans!=-1)return ans;
    ans=f(i+1,sum);
    ans=(ans+f(i+1,sum+v[i]))%MOD;
    return ans;
}


signed main(){
    FASTER;
    cin>>n>>s;
    memset(dp,-1,sizeof dp);
    v=vi(n);cin>>v;
    
    int ans=0;
    for(int i=0;i<n;i++)ans=(ans+f(i,0))%MOD;
    
    cout<<ans;
}

Measured memory_bytes: 70784
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
// constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

namespace detail {
template <typename Tp, size_t N>
std::vector<Tp> make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N == 1), Tp const&>::type x
) {
  return std::vector<Tp>(sizes[0], x);
}
template <typename Tp, size_t N>
auto make_vector(
    std::vector<size_t>& sizes,
    typename std::enable_if<(N > 1), Tp const&>::type x
) {
  size_t size = sizes[N-1];
  sizes.pop_back();
  return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
      size, make_vector<Tp, N-1>(sizes, x)
  );
}
}  // detail::

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

int main() {
  size_t n, m;
  scanf("%zu %zu", &n, &m);

  std::vector<std::pair<int, size_t>> k(m);
  for (auto& p: k) {
    int a;
    size_t b;
    scanf("%d %zu", &a, &b);

    size_t s = 0;
    for (size_t i = 0; i < b; ++i) {
      size_t c;
      scanf("%zu", &c);
      --c;
      s |= 1 << c;
    }
    p = {a, s};
  }

  int inf = 1e9;
  auto dp = make_vector<int>({1_zu << n}, inf);
  dp[0] = 0;
  for (size_t i = 0; i < m; ++i) {
    for (size_t j = 0; j < (1_zu << n); ++j) {
      size_t nj = (j | k[i].second);
      dp[nj] = std::min(dp[nj], dp[j] + k[i].first);
    }
  }

  int res = dp.back();
  if (res == inf) return puts("-1"), 0;
  printf("%d\n", res);
}


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

int method[30];

int recursion(int num) {
    if (num == 0) {
        return 1;
    } else if (num == 1) {
        return 1;
    } else if (num == 2) {
        return 2;
    } else {
        return recursion(num-1) + recursion(num-2) + recursion(num-3);
    }
}

int main() {
    while (1) {
        int n;
        cin >> n;
        if (n == 0) {
            return 0;
        } else {
            cout << (recursion(n) + 1) / 3650 + 1 << endl;
        }
    }
}

// cin: 入力
// cout: 出力
// endl: 改行


Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)


int main() {
int64_t a,b;
  cin>>a>>b;
int64_t value[a]; 
int64_t weight[a];
  rep(i,a) cin>>weight[i]>>value[i];
  int64_t dp[105][100005];
  rep(i,a){
    
  dp[0][i]=0;
  
  }
  for(int i=0;i<a;i++){
   for(int j=1;j<=b;j++){
  if(j>=weight[i]) dp[i+1][j]=max(dp[i][j-weight[i]]+value[i],dp[i][j]);
  else dp[i+1][j]=dp[i][j];
   }
  }
  cout<<dp[a][b];
  
  
  
  
  
  
}
 

Measured memory_bytes: 80384
#include<iostream>
#include<algorithm>
using namespace std;
void sort(int A[], int C, int N){
	int c=0;
	for(int i=0;i<N-1;i++){
		if(A[i]>A[i+1]){
			swap(A[i],A[i+1]);
			c++;
		}
	}
	if(c==0) cout << C << endl;
	else{
		C+=c;
		sort(A,C,N);
	}
}

int main(){
	int n;
	while(cin >> n,n){
		int a[n],count=0;
		for(int i=0;i<n;i++) cin >> a[i];
		sort(a,count,n);
	}
}

Measured memory_bytes: 3080
#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
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

set<int> adj[222222];
int cnt[2][222222];
queue<int> q;

bool bad(int u)
{
	return ((!cnt[0][u])||(!cnt[1][u]));
}
string s; 
void process(int u)
{
	for(int v:adj[u])
	{
		if(v!=u)
		{
			cnt[s[u]-'A'][v]--;
			adj[v].erase(u);
			if(bad(v)) q.push(v);
		}
	}
	cnt[0][u]=cnt[1][u]=0;
	adj[u].clear();
}

void addedge(int u, int v)
{
	if(adj[u].find(v)==adj[u].end())
	{
		cnt[s[v]-'A'][u]++; adj[u].insert(v);
	}
}
int n,m; 
void outcondition()
{
	for(int i=0;i<n;i++)
	{
		cerr<<i<<' '<<cnt[0][i]<<' '<<cnt[1][i]<<'\n';
	}
	cerr<<'\n';
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n>>m;
	cin>>s;
	for(int i=0;i<m;i++)
	{
		int u, v; cin>>u>>v; u--; v--;
		addedge(u,v); addedge(v,u);
	}
	for(int i=0;i<n;i++)
	{
		if(bad(i)) 
		{
			q.push(i);
		}
	}
	//outcondition();
	while(!q.empty())
	{
		int u=q.front(); q.pop(); 
		//cerr<<"CLEAR "<<u<<'\n';
		process(u);
		//outcondition();
	}
	/*
	for(int i=0;i<n;i++)
	{
		for(int v:adj[i])
		{
			if(v>=i) cerr<<"EDGE "<<i<<' '<<v<<'\n';
		}
	}
	*/	
	for(int i=0;i<n;i++)
	{
		if(!bad(i)) 
		{
			cout<<"Yes\n"; return 0;
		}
	}
	cout<<"No\n";
}


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

//long long
using ll = long long;

// pair<int, int>
using PII = pair<int, int>;

//最大値、mod
const int MOD = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;

//出力系
#define print(x) cout << x << endl
#define prints(x) cout << fixed << setprecision(10) << x << endl
#define printc(x) cout << setw(2) << setfill('0') << x << endl;
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

// a = max(a, b), a = min(a, b)
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; }

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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;
    REP(i, 1000){
        int target[3] ={i / 100, (i / 10) % 10, i % 10};
        int cnt = 0;
        REP(j, N){
            if(S[j] == ('0' + target[cnt])) cnt++;
            if(cnt == 3) break;
        }
        if(cnt == 3) ans++;
    }
    print(ans);
    return 0;
}

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

using namespace std;

int h,w;
char s[55][55];
int u[55][55], k[55][55];

int main (){
    cin >> h >> w;
    for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
        cin >> s[i][j];
    for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
        if (s[i][j] == '.') u[i][j] = 0;
        else u [i][j] = 1;
    for (int i = 1; i <= h; i++)
    for (int j = 1; j <= w; j++)
        if (u[i][j] == 0)
    k[i][j] = u[i-1][j-1] + u[i-1][j] + u[i-1][j+1] + u[i][j-1] + u[i][j+1] + u[i+1][j-1] + u[i+1][j] + u[i+1][j+1];
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        if (s[i][j] == '.') cout << k[i][j];
        else cout << '#';
        cout << '\n';
    }
}


Measured memory_bytes: 256
/*
 *  Lang    : C++
 *  Author  : little_angel
 */
#include <bits/stdc++.h>

using namespace std;
#define int long long
int n;
long double dp[301][301][301];

long double dfs(int one, int two, int three) {
    if (one < 0 || two < 0 || three < 0)return 0;
    if (one == 0 && two == 0 && three == 0)return 0;
    if (dp[one][two][three] > 0)return dp[one][two][three];
    int rem = n - (one + two + three);
    long double res = n + one * dfs(one - 1, two, three) + two * dfs(one + 1, two - 1, three) +
                      three * dfs(one, two + 1, three - 1);
    return dp[one][two][three] = res / (n - rem);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int x, a[] = {0, 0, 0};
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        a[x - 1]++;
    }
    cout << setprecision(10) << dfs(a[0], a[1], a[2]) << endl;
}

Measured memory_bytes: 426240
#include <stdio.h>


int main(void){  

int a,b,c;  

scanf("%d %d %d",&a,&b,&c);  

if(a==b){  

if(a==c){  

printf("%d %d %d\n",a,b,c);  

}; 

if(a<c){  

printf("%d %d %d\n",a,b,c);  

}; 

if(c<a){  

printf("%d %d %d\n",c,b,a);  

}; 

}; 

if(a==c){  

if(a<b){  

printf("%d %d %d\n",a,c,b);  

}; 

if(b<a){  

printf("%d %d %d\n",b,c,a);  

};

 };

 if(b==c){  

if(a<b){  

printf("%d %d %d\n",a,c,b);  

}; 

if(b<a){  

printf("%d %d %d\n",b,c,a);  

}; 

}; 

if(a<b&&b<c){ 

 printf("%d %d %d\n",a,b,c);  

}; 

if(a<c&&c<b){  

printf("%d %d %d\n",a,c,b);  

};

 if(b<a&&a<c){  

printf("%d %d %d\n",b,a,c);  

}; 

if(b<c&&c<a){  

printf("%d %d %d\n",b,c,a);  

}; 

if(c<a&&a<b){  

printf("%d %d %d\n",c,a,b);  

}; 

if(c<b&&b<a){  

printf("%d %d %d\n",c,b,a);  

};  

return 0; 

};

Measured memory_bytes: 596
#include <iostream>
using namespace std;
int main(){
  int n,m,c;
  cin>>n>>m>>c;
  
  int b[m];
  for(int i=0;i<m;i++){
    cin>>b[i];
  }
  
  int a[n][m];
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin>>a[i][j];
    }
  }
  
  int judge=0;
  int ans=0;
  for(int i=0;i<n;i++){
    judge+=c;
    for(int j=0;j<m;j++){
      judge+=a[i][j]*b[j];
    }
    if(judge>0){
      ans++;
    }
    judge=0;
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <string.h>
#include <set>
#include <unordered_set>
#define mod 1000000007
#define maxn 100050
using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int num_count[maxn];
    memset(num_count, 0, sizeof(num_count));
    for(int i=0; i<n; i++){
        int num;
        scanf("%d", &num);
        num_count[num]++;
    }
    int unique = 0;
    int even = 0;
    for(int i=0; i<maxn; i++){
        if(num_count[i]&1){
            unique++;
        }else if(num_count[i]){
            even++;
        }
    }
    unique+=(even/2)*2;
    printf("%d\n", unique);
    return 0;
}



Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
using ld = long double;
const ll mod =  998244353 ;
const ll inf = 1e18;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int bsearch(const vector<ll>& a, ll x){
  int lft = 0;
  int rgt = a.size();
  while (rgt - lft > 1) {
    int mid = (lft + rgt) / 2;
    if(a[mid] < x) {
      lft = mid;
    }
    else {
      rgt = mid;
    }
  }
  return lft;
}
signed main() {
  ios::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vector<ll> v(n);
  REP(i, n) cin >> v[i];
  ll ans = 0;
  REP(l, k+1) {
    REP(r, k-l+1) {
      if(l+r > n) continue;
      vector<ll> a;
      REP(i, l) {
        a.push_back(v[i]);
      }
      REP(i, r) {
        a.push_back(v[n-1-i]);
      }
      sort(all(a));
      ll score = sum(all(a));
      REP(i, min(k-r-l, r+l)) {
        if(a[i] >= 0) break;
        score -= a[i];
      }
      ans = max(ans, score);
    }
  }
  cout << ans << endl;
  return 0; 
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long a, b, n; cin >> a >> b >> n;
    long long m = min(b-1, n);
    cout << a * m / b << "\n";
    return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

const int N = 300010;

int n, a[N];

int main()
{
	gi(n);
	for (int i = 1; i <= 3 * n; ++i) gi(a[i]);
	sort(a + 1, a + 3 * n + 1);
	int cnt = 0;
	long long ans = 0;
	for (int i = 3 * n - 1; i; i -= 2)
	{
		ans += a[i];
		++cnt;
		if (cnt == n) break;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
def main():
    from collections import deque
        
    N, X, Y = map(int, input().split())

    G = [[1]] + [[x - 1, x + 1] for x in range(1, N - 1)] + [[N - 2]]
    G[X - 1].append(Y - 1)
    G[Y - 1].append(X - 1)

    dist = [[-1] * N for _ in [0] * N]
    for s in range(N):
        q = deque([s])
        dist[s][s] = 0
        while q:
            v = q.popleft()
            for nv in G[v]:
                if dist[s][nv] == -1:
                    dist[s][nv] = dist[s][v] + 1
                    q.append(nv)
    res = [0] * N
    for i in range(N):
        for j in range(i + 1, N):
            res[dist[i][j]] += 1
    for d in range(1, N):
        print(res[d])


if __name__ == '__main__':
    main()


Measured memory_bytes: 137652
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    if(a <= 8 && b <= 8 && a >= 1 && b >= 1){
        cout << "Yay!" << endl;
    }
    else cout << ":(" << endl;
return 0;
}


Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

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

  ll n;
  std::cin>>n;

  std::vector<ll> rate(9,0);

  rep(i,0,n){
    ll a;
    std::cin>>a;
    if(a<3200)rate[a/400]++;
    else rate[8]++;
  }

  ll cnt=0;
  rep(i,0,8)if(rate[i]>0)cnt++;
  
  std::cout<<((cnt==0)?1:cnt)<<" "<<cnt+rate[8]<<"\n";

  return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn append_2nd_positions(appear_pos_vec: &mut Vec<Vec<usize>>, s_len: usize){
    for i in 0..26{
        let original_vec_len = appear_pos_vec[i].len();
        for j in 0..original_vec_len{
            let value_of_2nd_through = appear_pos_vec[i][j]+s_len;
            appear_pos_vec[i].push(
                value_of_2nd_through
            );
        }
    }
}

fn lower_bound(v: &[usize], val: usize) -> usize{
    let mut left = 0;
    let mut right = v.len()-1;

    loop{
        let mid = (left + right)/2;

        if v[mid] < val{
            left = mid+1;
        }else{ // val <= v[mid]
            right = mid;
        }

        //if right - left <= 1{
        if left == right{
            return v[left];
        }
    }
}

fn main(){
    let s = read_as_string();
    let s_len = s.len();
    let t = read_as_string();

    let mut appear_pos_vec: Vec<Vec<usize>> = vec![Vec::new();26];

    for (i, ch) in s.bytes().enumerate(){
        appear_pos_vec[(ch -97) as usize].push(i);
    }

    append_2nd_positions(&mut appear_pos_vec, s.len());

    let mut lower_val: usize = 0;
    let mut num_loop: usize = 0;
    for ch in t.bytes(){
        let ch = (ch - 97) as usize;
        if appear_pos_vec[ch].len() == 0{
            println!("-1");
            return;
        }
        let found_pos = lower_bound(&appear_pos_vec[ch], lower_val);
        //println!("found at {}", found_pos);
        lower_val = found_pos+1;
        if s_len <= lower_val{
            num_loop += 1;
            lower_val -= s_len;
        }
    }
    
    println!("{}", num_loop*s_len+lower_val);
}


Measured memory_bytes: 8444
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<string>

using namespace std;

void AlphameticReplace(string &s, int r, char X){
	for(unsigned int i = 0; i < s.length(); i++){
		//if( i == 0 && r == 0 ) return ;
		if( s[i] == X ) s[i] = r + '0';
	}
}
string AddBigInteger(string s1, string s2){
	string ret;
	if(s2.length() > s1.length()) return AddBigInteger(s2, s1);
	else{
		int overflow = 0;
		reverse(s1.begin(), s1.end());
		reverse(s2.begin(), s2.end());
		for(unsigned int i = 0; i < s1.length(); i++){
			int d =(s1[i] - '0')+ ( i >= s2.length() ? 0 : (s2[i] - '0') )+overflow;
			if( d >= 10 ){overflow = 1;d -= 10;}else overflow = 0;
			ret += d + '0';
		}
		if( overflow > 0 ) ret += '1';
	}
	reverse(ret.begin(), ret.end());
	return ret;
}

int main(void){
	while( true ){
		int ans;
		bool bFound = false;
		string s,a,b,c;

		cin >> s;
		if( cin.eof() ) break;

		a = s.substr(0, s.find('+'));
		b = s.substr(s.find('+')+1, s.find('=') - (s.find('+')+1));
		c = s.substr(s.find('=')+1);

		for(int x = 0; x < 10; x++){
			string ta = a, tb = b, tc = c;
			AlphameticReplace(ta, x, 'X');
			AlphameticReplace(tb, x, 'X');
			AlphameticReplace(tc, x, 'X');
			if( tc.compare(AddBigInteger(ta, tb)) == 0 ){
				ans = x;
				bFound = true;
			}
		}
		if( bFound ){
			cout << ans << '\n';
		}else{
			cout << "NA\n";
		}
	}
	return 0;
}

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

signed main()
{
  int N; cin>>N;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
  }

  int cnt=0;
  for(int i=0;i<N;i++){
    if(p[i]!=i+1) cnt++;
  }
  cout<<(cnt<=2? "YES":"NO")<<endl;

  return 0;
}


Measured memory_bytes: 256
unsigned long long popcnt64(unsigned long long n){
	const unsigned long long m1=0x5555555555555555ULL;
	const unsigned long long m2=0x3333333333333333ULL;
	const unsigned long long m4=0x0f0f0f0f0f0f0f0fULL;
	const unsigned long long m8=0x00ff00ff00ff00ffULL;
	const unsigned long long m16=0x0000ffff0000ffffULL;
	const unsigned long long m32=0x00000000ffffffffULL;
	n=((n>>1)&m1)+(n&m1);
	n=((n>>2)&m2)+(n&m2);
	n=((n>>4)&m4)+(n&m4);
	n=((n>>8)&m8)+(n&m8);
	n=((n>>16)&m16)+(n&m16);
	n=((n>>32)&m32)+(n&m32);
	return n;
}
unsigned long long clz64(unsigned long long n){
	n|=n>>1;
	n|=n>>2;
	n|=n>>4;
	n|=n>>8;
	n|=n>>16;
	n|=n>>32;
	return 64-popcnt64(n);
}

#include <stdio.h>
int main(){
	long long N;
	scanf("%lld",&N);
	printf("%d\n",64-clz64(N));
	return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    ll n,k;
    cin >> n >> k;
    if(k%2){
        ll a=n/k;
        cout << a*a*a << endl;
    }else{
        ll a = n/k;
        ll b = (n+(k/2))/k;
        cout << a*a*a + b*b*b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define int long long
using namespace std;

signed main() {
  int N; cin >> N;
  vector<int> a(N), b(N);
  for(int i = 0; i < N; ++i) cin >> a[i];
  for(int i = 0; i < N; ++i) cin >> b[i];
  const int m = 30;
  int ans = 0;
  for(int k = 0; k < m; ++k) {
    int mod = (1<<k);
    vector<int> c(N);
    for(int i = 0; i < N; ++i) c[i] = b[i] % mod;
    sort(c.begin(), c.end());
    int cnt = 0, p = 0, q = 0;
    for(int i = 0; i < N; ++i) {
      p += (a[i] >> k) & 1;
      q += (b[i] >> k) & 1;
      int x = upper_bound(c.begin(), c.end(), mod - (a[i]%mod) -1) - c.begin();
      cnt += N - x;
    }

    cnt += (N-p) * q;
    cnt += p * (N-q);
    if(cnt & 1) ans += mod;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  string ans = "Yes";
  if (a==b && b==c) {
    ans = "No";
  }
  else if (a!=b && b!=c && c!=a) {
    ans = "No";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3588
import Data.List
import Control.Monad
import Control.Applicative


solver :: String  -> String
solver s
    | null s = "YES"
    | isPrefixOf "remaerd" s = solver $ drop 7 s
    | isPrefixOf "maerd"   s = solver $ drop 5 s
    | isPrefixOf "resare"  s = solver $ drop 6 s
    | isPrefixOf "esare"   s = solver $ drop 5 s
    | otherwise      = "NO"

main :: IO ()
main = getLine >>= (putStrLn . solver . reverse)


Measured memory_bytes: 7548
#include<stdio.h>
#include<iostream>
using namespace std;

int bubble(int A[], int n){
  int i,j;
  bool flag=1;
  int sw = 0;
  for ( i = 0; flag; i++ ){
      flag=0;
      for ( j = n-1; i < j; j-- ){
        if(A[j] < A[j-1]){
        swap(A[j],A[j-1]);
        sw += 1;
        flag=1;
        }
      }
  }
  return sw;
}

int main(){
  int n, i, j,sw;
  int A[100];
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
  sw=bubble(A,n);
  for ( i = 0; i < n; i++ ){
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d", sw);
  printf("\n");
  return 0;
}

Measured memory_bytes: 3224