akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
typedef long long ll;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n;
    cin >> n;
    string ans = "second";
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        if(a%2 == 1){
            ans = "first";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
s = m.times.map do
  gets.split.map(&:to_i).drop(1)
end
ps = gets.split.map(&:to_i)

ans = 0
[0,1].repeated_permutation(n).each do |sw|
  light_on = s.each_with_index.all? do |ss, i|
    (ss.reduce(0){|acc, sv| acc + sw[sv-1]} % 2) == ps[i]
  end
  ans += 1 if light_on
end
puts ans


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n));
  rep(i,n) rep(j,n) cin >> a[i][j];
  
  vector<ll> d(1 << n, 0);

  for (int i = 0; i < (1 << n); i++) {
    for (int j = 0; j < n; j++) {
      if (!(i & (1 << j))) continue;
      for (int k = 0; k < n; k++) if (i & (1 << k)) d[i] += a[j][k];
    }
    d[i] /= 2;
  }

  vector<ll> dp(1 << n, 0);

  for (int bit = 0; bit < (1 << n); bit++) {
    for (int i = bit; i >= 0; i--) {
      i &= bit;
      dp[bit] = max(dp[bit], d[i] + dp[bit - i]);
    }
  }
  cout << dp[(1 << n) - 1] << endl;
  return 0;
} 

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

int main()
{
    long long int A;
    long long int B;
    long long int K;
    
    cin >> A;
    cin >> B;
    cin >> K;

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


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

int INF=0x3f3f3f3f;


int main(){
	ios_base::sync_with_stdio(false);
	int n,k,tmp,ans=0;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>tmp;
		tmp=min(tmp,k-tmp);
		ans+=2*tmp;	
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String... args) {
    	Scanner input = new Scanner(System.in);
        
        int n = input.nextInt();
        int[] a = new int[n];
        
        for (int i = 0; i < n; i++) {
        	a[i] = input.nextInt();
		}
        
        int ans = 0;
        for (int i = 0; i < n; i++) {
        	for (int j = i + 1; j < n; j++) {
            	for (int k = j + 1; k < n; k++) {
                	if (valid(a[i], a[j], a[k])) {
                    	ans++;
                    }
				}
            }
		}
        
        System.out.println(ans);
	}
    
    private static boolean valid(int a, int b, int c) {
    	if (a == b || b == c || c == a) {
        	return false;
		}
        
        if (a + b <= c || b + c <= a || c + a <= b) {
        	return false;
		}
        
        return true;
	}
}

Measured memory_bytes: 27872
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < D; ++j) {
            cin >> X[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            int d2 = 0;
            for (int k = 0; k < D; ++k) {
                d2 += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            int d = sqrt(d2);

            if (d * d == d2)
                ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in();
	auto V=vecin(N);
	ll sum=0;
	REP(i,N-1){
		sum += V[i]/2;
		if(V[i]%2 && V[i+1]){
			sum++;
			V[i+1]--;
		}
	}
	sum += V.back()/2;
	out(sum);
	return 0;
}


Measured memory_bytes: 1024
N,X = map(int,input().split())
B = [-1 for i in range(51)]
P = [-1 for i in range(51)]

def buns(L):
    if L == 0:#再帰終了条件
        B[L] = 0
        return B[L]
    else:
        if B[L] == -1:
            B[L] = buns(L-1)*2 + 2
            return B[L]
        else:
            return B[L]

def patty(L):
    if L == 0:#再帰終了条件
        P[L] = 1        
        return P[L]
    else:
        if P[L] == -1:
            P[L] = patty(L-1)*2 + 1
            return P[L]
        else:
            return P[L]


buns(N)
patty(N)
memo = [B[i] + P[i] for i in range(51)]

def func(L,X):

    if L == 0:
        if X <= 0:
            return 0
        else:
            return 1
    elif X <= memo[L-1]+1:
        return func(L-1,X-1)
    else :
        return P[L-1] + 1 + func(L-1,X-2-memo[L-1])


print(func(N,X))

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>

#define ll long long
#define mod 1000000007

using namespace std;


main()
{
	int n,m;
	cin>>n>>m;
	int i,j;
	
	string g[n];
	for(i=0;i<n;i++)
	{
		cin>>g[i];
	}
	
	ll dis[n][m];
	
	
	if(g[0][0]=='#')
	dis[0][0] = 0;
	else
	dis[0][0] = 1;
	
	
	for(i=1;i<n;i++)
	{
		if(g[i][0]=='#')
		dis[i][0] = 0;
		else
		dis[i][0] = dis[i-1][0];
	}
	
	for(j=1;j<m;j++)
	{
		if(g[0][j]=='#')
		dis[0][j] = 0;
		else
		dis[0][j] = dis[0][j-1];
	}
	
	for(i=1;i<n;i++)
	{
		for(j=1;j<m;j++)
		{
			int a,b;
			a = (g[i-1][j]=='#') ? 0 : dis[i-1][j];
			b = (g[i][j-1]=='#') ? 0 : dis[i][j-1];
			
			dis[i][j] = (a + b)%mod;
		}
	}
	
//	for(i=0;i<n;i++)
//	{
//		for(j=0;j<n;j++)
//		cout<<dis[i][j]<<" ";
//		cout<<endl;
//	}

	cout<<dis[n-1][m-1];
	
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n, k, s;
    cin >> n >> k >> s;
    if (s == INF) {
        rep(i, k) cout << INF << endl;
        rep(i, n - k) cout << 1 << endl;
        return 0;
    }
    rep(i, k) cout << s << endl;
    rep(i, n - k) cout << INF << endl;
}


Measured memory_bytes: 1280
import sys
def input():
    return sys.stdin.readline()[:-1]
h,w,d=map(int,input().split())
a=[list(map(int,input().split())) for i in range(h)]
q=int(input())
lr=[list(map(int,input().split())) for i in range(q)]
li=[[] for i in range(d)]
for i in range(h):
    for j in range(w):
        li[a[i][j]%d].append([a[i][j],i,j])

for i in range(d):
    li[i].sort()

# print(li)
c=[[0]*(len(li[i])+1) for i in range(d)]

for i in range(d):
    for j in range(1,len(li[i])):
        c[i][j+1]=c[i][j]+abs(li[i][j-1][1]-li[i][j][1])+abs(li[i][j-1][2]-li[i][j][2])
# print(c)

for i in range(q):
    ama=lr[i][0]%d
    print(c[ama][(lr[i][1]+d-1)//d]-c[ama][(lr[i][0]+d-1)//d])

Measured memory_bytes: 90972
#include <bits/stdc++.h>
 using namespace  std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const long double pi=3.1415926535897932384626433832;
const long long mod=1e9+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
//#define For(i,0,n) for(long long i = 0 ; i<n ;i++) 
cd fast_exp(cd a, long long b)
{
	if (b == 0)
		return 1;
	
	cd res = fast_exp(a, b / 2);
		
	res = res * res;
	
	if (b % 2 == 1)
		res = res * a;
	
	return res;
}

long long fastexpon(long long a,long long b,long long mod)
{
	if(b==0)
		return 1;
	
	long long res=fastexpon(a,b/2,mod);
	
	res=(res*res)%mod;
	if(b%2==1)
		res= (res * a)%mod;

	return res;
}

int dp[3001][3001]={};
int decis[3001][3001]={};
string s, t;
int LCS(int x1, int x2)
{
	if(dp[x1][x2]!=-1)
		return dp[x1][x2];
	if(x1==s.length() || x2==t.length())
	{
		dp[x1][x2]=0;
		return dp[x1][x2];
	}

	if(s[x1]==t[x2])
	{
		decis[x1][x2]=1;
		//printf("hey, %c  = %c  \n",s[x1],s[x2]);
		dp[x1][x2]=1+ LCS(x1+1,x2+1);
		return dp[x1][x2];
	}

	else
	{
		int a=0,b=0;
		a= LCS(x1+1,x2);
		b= LCS(x1,x2+1);
		if(a>b)
		{
			decis[x1][x2]=2;
			dp[x1][x2]=a;
			return dp[x1][x2];
		}

		else
		{
			decis[x1][x2]=3;
			dp[x1][x2]=b;
			return dp[x1][x2];
		}	
	}


}
int main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	for(int i=0 ;i<3001;i++)
	for(int j=0 ; j<3001 ;j++ )
	{
		dp[i][j]=-1;
	}
	
	cin>>s>>t;
	int len=LCS(0,0);
	int count=0;
	string ans;
	int x1=0, x2=0;
	while(ans.length()<len)
	{
		if(decis[x1][x2]==1)
		{
			ans=ans+s[x1];
			x1++;
			x2++;
		}

		else if(decis[x1][x2]==2)
		
			x1++;
		

		else
			x2++;
	}


cout<<ans;


	//cout<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

Measured memory_bytes: 70912
s = [x for x in input()]
if len(s) % 2 == 0:
    s = s[:-2]
while True:
    fin = 1
    half = len(s) // 2
    for i in range(half):
        if s[i] == s[half+i]: continue
        else:
            fin = 0
            s = s[:-2]
            break
    if fin: break
print(len(s))

Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vikas.k
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskE {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int N = in.nextInt();
            long[] a = new long[N + 1];
            for (int i = 1; i <= N; i++) {
                a[i] = in.nextLong();
            }
            long ans = 0;
            while (true) {
                boolean cont = false;
                for (int i = 1; i <= N; i++) {
                    if (a[i] >= N) {
                        long u = a[i] / N;
                        a[i] = a[i] % N;

                        if (u > 0) {
                            cont = true;
                            for (int j = 1; j <= N; j++) {
                                if (i != j) a[j] += u;
                            }
                            ans += u;
                        }
                    }
                }
                if (!cont) break;
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        public FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

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

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

    }
}



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

int return_nearer_round_distance(int a,int k) {
	if (abs(a) > abs(k - a))return 2 * (k-a);
	else return 2 * a;
}

int main(void) {
	//入力
	int n, k;
	cin >> n >> k;
	vector<int>x;
	for (int i(0); i < n; i++) {
		int tmp;
		cin >> tmp;
		x.push_back(tmp);
	}
	//処理
	int sum(0);
	for (int i(0); i < n; i++) {
		sum += return_nearer_round_distance(x[i],k);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left
import copy

n = int(input())
l = list(map(int, input().split()))
l.sort()


ans = 0
for small in range(n - 2):
    for mid in range(small + 1, n - 1):
        div = bisect_left(l, l[small] + l[mid], 0, n)
        if div > mid + 1:
            ans += div - mid - 1

print(ans)

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

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

    vector<vector<int>> dp;
    dp.assign(n, vector<int>(n));
    rep(i, n) rep(j, n) cin >> dp[i][j];

    vector<vector<bool>> exist;
    exist.assign(n, vector<bool>(n, true));

    rep(k, n) rep(i, n) rep(j, n)
    {
        if (dp[i][j] > dp[i][k] + dp[k][j])
        {
            cout << -1 << endl;
            return 0;
        }
        else if (i != k && j != k && dp[i][j] == dp[i][k] + dp[k][j])
            exist[i][j] = false;
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
            if (exist[i][j])
                ans += dp[i][j];
    cout << ans << endl;
}

Measured memory_bytes: 4036
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T lcm(T x,T y){
    return x*y/GCD(x,y);
}
int binary_search(int* a,long long k,int n){
    int R = n,L = 0;
    while(L < R){
        int mid = (L+R)/2;
        if (a[mid] == k) return 1;
        else if (k < a[mid]) R = mid;
        else L = mid+1;
    }
    return 0;
}

int main(){
    int n; cin >> n; 
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        long long k; cin >> k;
        cout << binary_search(a,k,n) << endl;
    }
}
  




Measured memory_bytes: 3492
#include <iostream>

using namespace std;

int main() {
	int k, a, b;
	cin >> k;
	cin >> a >> b;
	int t = a / k;
	if (a%k==0 || k * (t + 1) <= b) {
		cout << "OK";
	}
	else {
		cout << "NG";
	}
	return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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; }

using ll = long long;

ll N, M, V, P;
ll A[100010];

bool C( ll x )
{
  ll ret = M*(N-x-1+1+P-1);

  repi( i, P-1, x )
    ret += M+A[x]-A[i];//, std::cout << M+A[x]-A[i] << std::endl;;

  //std::cout << "[" << x << "]" << std::endl;
  //std::cout << ret << std::endl;

  return A[x]+M >= A[P-1] && ret >= M*V;
}

int main()
{
  std::cin >> N >> M >> V >> P;

  rep( i, N )
    std::cin >> A[i];

  std::sort( A, A+N, std::greater<ll>() );

  //rep( i, N )
    //std::cout << A[i] << std::endl;

  ll ng = 0, ok = N;

  while( ok-ng > 1 )
  {
    ll mid = (ng+ok)/2;

    (!C(mid) ? ok : ng) = mid;
  }

  std::cout << ok << std::endl;

  return 0;
}

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

int main(){
	
long long n; cin>>n;
long long sum=0;
for(long long i=1;i<=n;i++){
	if(i%3!=0 && i%5!=0) sum+=i; 
	
}
cout<<sum<<"\n";
return 0;
}

Measured memory_bytes: 3640
a = input()
k = []
k.append(a[0])
s = 0
for i in range(1,len(a)):
    if len(k) !=0:
        if k[-1] != a[i]:
            s+=1
            k.pop()
        else:k.append(a[i])
    else:
        k.append(a[i])

print(s*2)

Measured memory_bytes: 3956
package main

import (
	"fmt"
)

func main() {

	var N int

	var S string

	fmt.Scan(&N,&S)


	if N ==1 {

		
		fmt.Println(1)
		return
	}

	cnt:=0

	for  i:=0;i<N-1;i++{

		if S[i:i+1] == S[i+1:i+2]{

			cnt++
		}

	}

	fmt.Println(N-cnt)

}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll i,j,m,n,k;
    ll t;
    ll x;
    cin>>x>>n;
    map<ll,bool> m1;
    for(i=0;i<n;i++)
    {
        cin>>m;
        m1[m]=true;
    }
    
    for(j=x;j>=0;j--)
    {
        if(m1[j]==false)
            break;
    }
    ll ans=abs(j-x);
    ll d=j;
    for(j=x;j<=101;j++)
    {
        if(m1[j]==false)
            break;
    }
    if(abs(j-x)<ans)
        cout<<j;
    else
        cout<<d;
}


Measured memory_bytes: 3608
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define pb     push_back
#define inf     2e18
#define low     -2e18
#define PI        acos(-1.0)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
const int sz = 1e5+9;

int main()
{
	
    ll i,n,t,k,j,x=0,y=0,m;
    string str;
    cin>>str;
    for(i=0;i<str.size();i++)
    {
    	x+= str[i]  -48;
    }
    if(x%9==0)
    {
    	cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3752
// ref: https://competitive-kivantium.hateblo.jp/entry/2019/02/17/000439
// ref: https://img.atcoder.jp/abc118/editorial.pdf

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N, M; cin >> N >> M;
    vector<int> vA(M); for(int i=0; i<M; ++i){ cin>>vA[i]; }
    
    vector<char> val2char = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    vector<int> val2num = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    
    vector<string> dp((N+1)*M);
    
    for(int ni=0; ni<=N; ++ni){
        for(int i=0; i<M; ++i){
            int numA = val2num[ vA[i] ];
            if(numA > ni){ continue; }
            
            string tmp;
            if      ( ni == numA            ){ tmp += val2char[ vA[i] ];
            }else if( dp[ni-numA].size()!=0 ){ tmp += val2char[ vA[i] ] + dp[ni-numA];
            }else                            { continue; }
            
            if(  tmp.size() > dp[ni].size() ||
               ( tmp.size()==dp[ni].size() && tmp>dp[ni] ) ){
                dp[ni] = tmp;
            }
        }
    }
    cout << dp[N] << endl;
    
    return 0;
}


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

using namespace std;

int const N = 1234567;

int a[N], b[N];

int main() {
  int w, h;
  scanf("%d%d", &w, &h);
  for (int i = 0; i < w; i++) scanf("%d", a + i);
  for (int i = 0; i < h; i++) scanf("%d", b + i);
  std::sort(a, a + w);
  std::sort(b, b + h);
  int cur1 = 0;
  int cur2 = 0;
  long long ans = 0;
  while (cur1 < w || cur2 < h) {
    if (cur2 >= h || (cur1 < w && a[cur1] < b[cur2])) {
      ans += (long long) a[cur1++] * (h - cur2 + 1);
    } else {
      ans += (long long) b[cur2++] * (w - cur1 + 1);
    }
  }
  printf("%lld\n", ans);
}

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

using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
//const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p <<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) {
		cin >> a[i];
	}
	vi b = a;
	sort(b.begin(), b.end());
	int mi = b[n / 2 - 1], ma = b[n / 2];
	rep(i, n) {
		if (a[i] <= mi) {
			cout << ma << endl;
		}
		else {
			cout << mi << endl;
		}
	}
}

Measured memory_bytes: 3712
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	READV(N);
	ll ans=0;
	FORI(i,1,N+1)
	{
		if(i%3!=0 && i%5!=0)
		{
			ans+=i;
		}
	}
	cout<<ans<<endl;
	

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


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

Measured memory_bytes: 3804
N = int(input())
A = [0]

Astr = input().split()

for i in Astr:
    A.append(int(i))

A.append(0)

ans = 0
pos = 0
for i in range(len(A)):
    if i == 0:
        continue
    ans += abs(A[i]-pos)
    pos = A[i]

for i in range(len(A)):
    if i == 0 or i == len(A)-1:
        continue
    print(ans-abs(A[i]-A[i-1])-abs(A[i+1]-A[i])+abs(A[i+1]-A[i-1]))

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000003;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n,m;
ll a[e5];
vl o;
vl e;

void error(){
  cout << "Impossible" << endl;
  exit(0);
}

int main(){
  cin >> n >> m;
  for(ll i = 0;i < m;i++) cin >> a[i];
  for(ll i = 0;i < m;i++){
    if(a[i]%2 == 1){
      o.push_back(a[i]);
    }else{
      e.push_back(a[i]);
    }
  }
  if(m == 1){
    vl ans;
    cout << abs(a[0]) << endl;
    if(a[0]-1 > 0) ans.push_back(a[0]-1);
    ans.push_back(1);
    cout << ans.size() << endl;
    for(ll i = 0;i < ans.size()-1;i++){
      cout << ans[i] << " ";
    }
    cout << ans[ans.size()-1] << endl;
    return 0;
  }
  if(o.size() > 2) error();
  else if(o.size() == 2){
    cout << o[0] << " ";
    for(ll x : e){
      cout << x << " ";
    }
    cout << o[1] << endl;
  }else if(o.size() == 1){
    for(ll x : e){
      cout << x << " ";
    }
    cout << o[0] << endl;
  }else{
    for(ll i = 0;i < e.size()-1;i++) cout << e[i] << " ";
    cout << e[e.size()-1] << endl;
  }
  vl ans;
  if(o.size() == 2){
    ll x = o[0]-1;
    if(x > 0) ans.push_back(x);
    for(ll i = 0;i < e.size();i++){
      ans.push_back(e[i]);
    }
    ans.push_back(o[1]+1);
  }else if(o.size() == 1){
    ans.push_back(e[0]-1);
    for(ll i = 1;i < e.size();i++){
      ans.push_back(e[i]);
    }
    ans.push_back(o[0]+1);
  }else{
    ans.push_back(e[0]-1);
    for(ll i = 1;i < e.size()-1;i++){
      ans.push_back(e[i]);
    }
    ans.push_back(e[e.size()-1]+1);
  }
  cout << ans.size() << endl;
  for(ll i = 0;i < ans.size()-1;i++){
    cout << ans[i] << " ";
  }
  cout << ans[ans.size()-1] << endl;




}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int a[maxn];
int d[maxn];
int main(){
	int i,j,k,m,n;
	cin>>n;
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int top=0;
	for(i=n;i>=1;i--){
		if(a[i]>=d[top])d[++top]=a[i];
		else {
			int x=upper_bound(d+1,d+top+1,a[i])-d;
			d[x]=a[i];
		}
	}
	printf("%d\n",top);
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int n;
int vac[100010][3];
int dp[100010][3];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
            cin>>vac[i][j];
    }
    for(int i=n-1;i>=0;i--)
    {
        if(i==n-1)
            for(int j=0;j<3;j++)
                dp[i][j]=vac[i][j];
        else{
            for(int j=0;j<3;j++)
            {
                int mx=-1;
                for(int o=0;o<3;o++){
                    if(o==j)continue;
                    mx=max(dp[i+1][o],mx);
                }
                dp[i][j]=mx+vac[i][j];
            }
        }
    }
    cout<<max(dp[0][0],max(dp[0][1],dp[0][2]))<<endl;
    return 0;
}


Measured memory_bytes: 2560
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			List<Store> list = IntStream.range(0, n).mapToObj(i -> new Store(scanner.nextInt(), scanner.nextInt()))
					.sorted((x, y) -> x.price - y.price).collect(Collectors.toList());
			long sum = 0;
			for (Store store : list) {
				if (store.amount >= m) {
					sum += (long) store.price * m;
					break;
				} else {
					sum += (long) store.price * store.amount;
					m -= store.amount;
				}
			}
			System.out.println(sum);
		}
	}

	/**
	 * 値段と本数を表すクラス
	 */
	private static class Store {
		int price;
		int amount;

		Store(int price, int amount) {
			super();
			this.price = price;
			this.amount = amount;
		}
	}
}


Measured memory_bytes: 62680
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<long long, int> cnt;
  for(int i = 0; i < n; i++){
    long long a;
    cin >> a;
    cnt[a]++;
  }
  vector<long long> v;
  for(auto p: cnt){
    if(p.second >= 4) v.push_back(p.first);
    if(p.second >= 2) v.push_back(p.first);
  }
  sort(v.rbegin(), v.rend());
  if(v.size() < 2) cout << 0 << endl;
  else cout << v[0]*v[1] << endl;
  return 0;
}

Measured memory_bytes: 6528
n = gets.to_i
f = (1..n).map{gets.split.map &:to_i}
q = (1..n).map{gets.split.map &:to_i}
p [0,1].repeated_permutation(10).map{|e|
    (0...n).map{|i|
        q[i][(0..9).count{|j|e[j]==1&&f[i][j]==1}]
    }.inject :+
}[1..-1].max

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

int A[3],K;
int ans;

int main(){
  cin >> A[0] >> A[1] >> A[2] >> K;

  sort(A,A+3);
  A[2] *= pow(2,K);

  ans = A[0]+A[1]+A[2];

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
		string s,t;
		string s2;
		vector<string> ans;
		cin >> s;
		cin >> t;
		
		t.pop_back();
		if(t == s) cout << "Yes\n";
		else
			cout << "No\n";
	
		
	
			
		
    return 0;
}


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

#define ll long long

void solve(){
	int k,a,b;
	cin>>k>>a>>b;
	if(a%k==0||b%k==0){
		cout<<"OK\n";
		return;
	}
	cout<<( (b/k-a/k)?"OK":"NG")<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	solve();
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

int rtoi(string s){
  int len=s.length();
  int res=0,num=1;
  for(int i=0;i<len;i++){
    if(48<=s[i] && s[i]<=57) num=s[i]-48;
    if(s[i]=='m') {
      res+= num*1000;
      num=1;
    }
    else if(s[i]=='c') {
      res+= num*100;
      num=1;
    }
    else if(s[i]=='x') {
      res+= num*10;
      num=1;
    }
    else if(s[i]=='i') {
      res+= num;
      num=1;
    }
  }
  return res;
}

string itor(int n){
  string res="";
  if(n>=1000){
    if(n>=2000) res += to_string(n/1000) + "m";
    else res += "m";
    n %= 1000;
  }
  if(n>=100){
    if(n>=200)res += to_string(n/100) + "c";
    else res+= "c";
    n %= 100;
  }
  if(n>=10){
    if(n>=20)res += to_string(n/10) + "x";
    else res+="x";
    n %= 10;
  }
  if(n>=1){
    if(n>=2)res += to_string(n) + "i";
    else res+="i";
  }
  return res;
}

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

  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    string s1,s2;
    cin >> s1 >> s2;
    int num1=rtoi(s1),num2=rtoi(s2);
    int ans=num1+num2;
    cout <<itor(ans) << endl;
  }
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N;
    cin >> N;
    vec<string> strings(N);
    range(i, 0, N) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        strings.at(i) = s;
    }
    map<string, lint> num_occurances;
    for (const auto s : strings) {
        num_occurances[s] += 1;
    }
    lint res = 0;
    for (const auto p : num_occurances) {
        res += p.second * (p.second - 1) / 2;
    }
    cout << res << "\n";
}

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

int main() {
  int n, m;
  cin >> n >> m;
  if(n >= m) {
    cout << 0 << endl;
    return 0;
  }
  vector<int> v(m);
  rep(i, m) {
    cin >> v[i];
  }
  sort(all(v));
  vector<int> v_sub(m - 1);
  rep(i, m - 1) {
    v_sub[i] = abs(v[i + 1] - v[i]);
  }
  sort(all(v_sub));
  reverse(all(v_sub));
  int ans = v[v.size() - 1] - v[0];
  rep(i, n - 1) {
    ans -= v_sub[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

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

    ll A, B, C, K;
    cin >> A >> B >> C >> K;

    ll ans = A - B;
    if (K % 2) {
        ans = -ans;
    }
    if (abs(ans) > ll(1e18)) {
        cout << "Unfair" << endl;
        return 0;
    }

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



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

#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
 
const ll MAX = 2e5;
const ll inf = 1e18;
const ll mod = 1e9 + 7;



int main(){
	fastio;
	ll tc,n,m,a,b;
	cin >> n >>  a >> b;
	cout <<  a* (n/(a+b) ) + min(a,n%(a+b)) << endl;
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
typedef long long ll;
#define inRange(x,a,b) (a <= x && x <= b)

// editorial
int main(){
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    bool ok = false;
    for(ll m = 0; m <= n-1; m++){
        ok |= inRange(b-a+m*(c+d), c*(n-1), d*(n-1));
    }
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		long sum = 0;

		for(int i = 1; i <= a; i++) {
			if(i % 5 != 0 && i % 3 != 0) {
				sum += i;
			}
		}
		System.out.println(sum);
	}
}


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

int main() {
  int H , W;
  cin >> H >> W;
  vector<string>vec(H);
  for(int i = 0;i < W + 2;i++){
    cout << "#" ;
  }
  cout << endl;
  for(int i = 0;i < H;i++){
    cin >> vec.at (i);
    cout << "#" << vec.at(i) << "#" << endl;
  }
  for(int i = 0;i < W + 2;i++){
    cout << "#" ;
  }
  cout << endl;
}


Measured memory_bytes: 256
import collections
n = int(raw_input())
A = map(int, raw_input().split(" "))

c1 = collections.Counter(A[::2]).most_common(2)
c2 = collections.Counter(A[1::2]).most_common(2)

res = n
for i, x in c1:
    for j, y in c2:
        if i != j:
            res = min(res, n - x - y)
        res = min(res, n - y)
        res = min(res, n - x)
print res


Measured memory_bytes: 11508
#pragma GCC optimize("O3")

#include <iostream>
#include <vector>
using namespace std;
using llong = long long;

const llong inf = 1ll << 60ll;
llong n;
llong height[805];
llong cost[805][805];
llong dp[805];
llong p[805];
vector<vector<llong>> tree;
llong length[805];
llong leaf_cost;
llong nleaf_cost;

llong calc_height(llong u, llong par) {
    height[u] = -1;
    for (auto v:tree[u]) {
        if (v == par) continue;
        height[u] = max(height[u], calc_height(v, u));
    }

    height[u]++;
    return height[u];
}

void dfs(llong u, llong par, llong c) {
    length[u] = c;
    
    for (auto v:tree[u]) {
        if (v == par) continue;
        if (height[v] == 0) {
            leaf_cost += cost[u][v];
            continue;
        }

        nleaf_cost += cost[u][v];
        dfs(v, u, c + cost[u][v]);
    }
}

void solve() {
    tree.clear();
    tree.resize(n + 1);
    for (int i = 2; i <= n; i++) {
        cin >> p[i];
        tree[p[i]].push_back(i);
        tree[i].push_back(p[i]);
    }
    for (int i = 2; i <= n; i++) {
        llong d;
        cin >> d;
        cost[i][p[i]] = cost[p[i]][i] = d;
    }

    llong ans = inf;
    for (int i = 1; i <= n; i++) {
        nleaf_cost = 0;
        leaf_cost = 0;
        calc_height(i, 0);
        dfs(i, 0, 0);

        for (int j = 1; j <= n; j++) {
            if (height[j] == 0) continue;
            ans = min(ans,
                      leaf_cost + 3 * (nleaf_cost - length[j]) + 2 * length[j]);
        }
    }

    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    while (cin >> n, n) solve();
}



Measured memory_bytes: 8260
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	int n;
	scanf("%d", &n);
	int m = (n+1) / 2;
	printf("%.8f\n", (double)m / n);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;

vector<bool> prime(111000, true);

void sieve();


int main()
{
    int n, m;
    sieve();
    while (cin >> n >> m, n != -1) {
        int cnt = 0;
        vector<int> ans;
        for (int i = n+1; cnt < 100; i++) {
            if (prime[i]) {
                int ct = 0;
                for (int j = i; ct < 100; j++) {
                    if (prime[j]) {
                        ans.push_back(i+j);
                        ct++;
                    }
                }
                cnt++;
            }
        }
        sort(ans.begin(), ans.end());

        cout << ans[m-1] << endl;
    }

    return 0;
}


void sieve()
{
    prime[0] = prime[1] = false;
    for (int i = 2; i * i < 111000; i++) {
        if (prime[i]) {
            for (int j = 2; i * j < 111000; j++) {
                prime[i*j] = false;
            }
        }
    }
}

Measured memory_bytes: 3240
import java.util.*;

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

	int x = 0;

	String ss = sc.nextLine();

	for(int i=0;i<3;i++){
	   char s = ss.charAt(i);
	   if(s == '1') x++;
	}
	System.out.println(x);
    }
}


Measured memory_bytes: 23764
#include <iostream>

using namespace std;

void print(int grid[][100])
{
    cout << 100 << " " << 100;
    for (int i = 0; i < 100; i++) {
        cout << endl;
        for(int j = 0; j < 100; j++) {
            if (grid[i][j]) cout << "#";
            else cout << ".";
        }
    }
}

int main(void)
{
    int A, B;
    cin >> A; cin >> B;
    int grid[100][100];
    // 0 = . 白   1 = #黒
    for (int i = 0; i < 50; i++) {
        for (int j = 0; j < 100; j++) grid[i][j] = 0;
    }
    for (int i = 50; i < 100; i++) {
        for (int j = 0; j < 100; j++) grid[i][j] = 1;
    }
    int w = 1;
    for (int i = 51; i < 100; i += 2) {
        for (int j = 0; j < 100; j+= 2) {
            if (w < A) {
                grid[i][j] = 0;
                w++;
            }
            else break;
        }
    }
    int b = 1;
    for (int i = 0; i < 50; i += 2) {
        for (int j = 0; j < 100; j+= 2) {
            if (b < B) {
                grid[i][j] = 1;
                b++;
            }
            else break;
        }
    }

    print(grid);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, a[100], sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	double ave = (double)sum / (double)n;
	int ans = n;
	double min = 1000;
	for (int i = 0; i < n; i++) {
		if(abs((double)a[i] - ave) < min){
			min = abs((double)a[i] - ave);
			ans = i;
		}
	}

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

Measured memory_bytes: 256
"use strict";

function main(input) {
  input = input.trim().split(" ");
  const L = parseInt(input[0]);
  const R = parseInt(input[1]);
  const d = parseInt(input[2]);
  let ans = 0;

  for (let i = d; i < 101; i = i + d) {
    if (L <= i && R >= i) {
      ans++;
    }
  }
  console.log(ans);
}

function numberSort(array) {
  array.sort(f);
  return array;
}

var f = function (a, b) {
  return a - b;
};

main(require("fs").readFileSync("/dev/stdin", "utf-8"));


Measured memory_bytes: 29688