akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define ET cout << "\n"
#define SZ(a) ((int)a.size())
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef bbq
#define debug(...) {\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}
#define DB(a,s,e) {for(int _i=s;_i<e;++_i) cerr << a[_i] << " ";cerr << "\n";}
template<typename T>void _do(T &&x){cerr<<x<<endl;}
template<typename T,typename ...S> void _do(T &&x,S &&...t){cerr<<x<<", ";_do(t...);}
template<typename a,typename b> ostream& operator << (ostream &s,const pair<a,b> &p){return s<<"("<<p.X<<","<<p.Y<<")";}
#else
#define debug(...)
#define DB(a,s,e)
#endif

const ll MAXC=cbrt(1e10),sqC=1e5,C=1e10;
unordered_map<ll,pll> mp;
vector<ll> p;
int prime[MAXC+5];

int main()
{
    IOS();
    ll n,ans=0,bonus=0;
    for(int i=2;i<=MAXC;++i)
    {
        if(!prime[i])
            p.pb(i);
        for(ll j:p)
        {
            if(j*i>MAXC) break;
            prime[j*i]=j;
            if(i%j==0) break;
        }
    }
    cin >> n;
    for(int i=1;i<=n;++i)
    {
        ll x,v=1,flag=0;
        __int128 rv=1;
        cin >> x;
        for(ll j:p)
            if(x%j==0)
            {
                ll cnt=0;
                while(x%j==0) x/=j,++cnt;
                cnt%=3;
                if(cnt==1)
                    rv*=j*j,v*=j;
                else if(cnt==2)
                    rv*=j,v*=j*j;
            } 
        if(x==1&&v==1)
        {
            ++bonus;
            continue;
        }
        if(x!=1)
            if(x<=sqC)
                v*=x,rv*=x*x;
            else
            {
                ll sq=sqrt(x);
                if(sq*sq==x)
                    v*=x,rv*=sq;
                else
                    flag=1;
            }
        if(rv>C||flag)
            ++ans;
        else
        {
            auto q=mp.find(v);
            if(q!=mp.end()) ++q->Y.Y;
            else mp[v]=pll(rv,1);
        }
    }
    while(!mp.empty())
    {
        auto q=*mp.begin();
        mp.erase(mp.begin());
        ans+=max(q.Y.Y,mp[q.Y.X].Y);
        mp.erase(q.Y.X);
    }
    cout << ans+!!bonus << "\n";
}

Measured memory_bytes: 5156
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < ll(n); ++i)	
//setprecision(16)

void outi(int x) { cout << x << endl; }
void outl(ll x) { cout << x << endl; }
void outs(string x) { cout << x << endl; }
ll max(ll a, ll b) {
	ll max;
	if (a > b) max = a;
	else max = b;
	return max;
}
ll min(ll a, ll b) {
	ll min;
	if (a < b) min = a;
	else min = b;
	return min;
}
//---------------------------------------------------------------

int main() {
	ll a;
	double b;
	cin >> a >> b;

	int c = b * 100 + 0.5;
	cout << (ll)(a * c / 100) << endl;
}

Measured memory_bytes: 3724
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       




        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var s = Console.ReadLine().ToArray();
            long b = 0;
            long g = 0;
            for (long i = 0; i <s.Length; i++)
            {
                if (s[i] == 'A')
                {
                    b = i;
                    break;
                }
            }
            for (long i = s.Length-1; i >=0; i--)
            {
                if (s[i] == 'Z')
                {
                    g = i;
                    break;
                }
            }
            Console.WriteLine(g - b + 1);



            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 13324
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int a, b;
    cin >> a >> b;

    int r = 0;
    REP(i, b+1) {
        if (i<a) continue;
        string s = to_string(i);
        reverse(ALL(s));
        string t = to_string(i);
        if (s == t) r++;
    }
    cout << r << endl;
}


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

const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main() {
	int N;
	cin >> N;
	
	long long h[N];			// 階段の高さ
	long long dp[N];  		// コスト
	for(int i=0; i<N; i++) {
		cin >> h[i];
		dp[i] = INF;
	}	
	dp[0] = 0;
	
	// Dymanic Programming
	for(int i=0; i<N; i++) {
		chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]) );
		if (i>1)	chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]) );
	}
	
	cout << dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 1792
s=input()
s=s+"X"
lists=[]
counter=1
for i in range(len(s)-1):
    if s[i]==s[i+1]:
        counter+=1
    else:
        lists.append(counter)
        counter=1
n=len(lists)
if s[0]=="<" and s[-2]=="<":
    lists.append(1)
    
elif s[0]=="<" and s[-2]==">":
    pass
    
elif s[0]==">" and s[-2]=="<":
    lists.insert(0,1)
    lists.append(1)
    
elif s[0]==">" and s[-2]==">":
    lists.insert(0,1)
    
k=len(lists)//2
ans=0
for i in range(k):
    a=lists[i*2]
    b=lists[i*2+1]
    maxi=max(a,b)
    mini=min(a,b)
    ans+=maxi*(maxi+1)//2+mini*(mini-1)//2
print(ans)
    
    

Measured memory_bytes: 6300
#include<iostream>
using namespace std;
int main(void){
	int a;
	cin >> a;
	while (a != 0){
		int b[10000] = { 0 }, c[10000] = { 0 }, d, e = 0, f[10000] = { 0 }, g = 0, h = 0, i, k = 0, n = 0;
		h = 2 * a;
		for (i = 1; i <= a; i++){
			cin >> d;
			f[d] = 1;
		}
		for (i = 1; i <= h; i++){
			if (f[i] == 1){
				b[e] = i;
				e++;
			}
			else{
				c[g] = i;
				g++;
			}
		}
		k = 0;
		g = 0;
		e = 0;
		int count = 0, j = 0, o = 0, p = 0, s = 0, l = 0, x = 0, z = 0;
		x = a;
		z = a;
		while (1){
			if (k == 0){
				for (i = 0; i < a; i++){
					if (n < b[i]){
						n = b[i];
						b[i] = 0;
						l = 1;
						x--;
						break;
					}
				}
				if (l == 0){
					n = 0;
				}
				l = 0;
			}
			if (x == 0){
				break;
			}
			k = 1;
			if (k == 1){
				for (g = 0; g < a; g++){
					if (n < c[g]){
						n = c[g];
						c[g] = 0;
						s = 1;
						z--;
						break;
					}
				}
				if (s == 0){
					n = 0;
				}
				s = 0;
			}
			k = 0;
			if (z == 0){
				break;
			}
		}
		cout <<  z << endl <<  x << endl;
		cin >> a;
	}
}

Measured memory_bytes: 3116
#include<iostream>
#include<queue>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;
#define fr first
#define sc second
#define INF ( 1 << 30 )
int m, n, k, d;
int min_cost[110][1 << 6];
vector< int > cal;
typedef pair < int , int > Pi;
typedef pair < int , Pi > Pii;
struct edge{
  int to, cost;
  edge(){}
  edge( int to, int cost): to(to), cost(cost){};
};
vector < edge > info[110];
int java(string& s){
  if(s[0] == 'H') return 0; //MyHome
  if(s[0] == 'D') return 1; //市役所
  if(s[0] == 'C') return atoi(s.substr(1).c_str()) + 1; //ケーキ屋さん
  if(s[0] == 'L') return atoi(s.substr(1).c_str()) + m + 1; //ランドマーク
}
int bfs(){
  int ret = INF;
  fill_n(*min_cost,110*(1<<6),INF);
  queue< Pii > que;
  que.push(Pii( 0, Pi( 0, (1<<m) - 1)));
  min_cost[0][(1<<m)-1] = true;
  while(!que.empty()){
    Pii p = que.front();
    que.pop();
    if(p.sc.fr == 1) ret = min( ret, p.fr);
    if(min_cost[p.sc.fr][p.sc.sc] < p.fr ) continue;
    for(int i = 0 ; i < info[p.sc.fr].size() ; i++ ){
      edge e = info[p.sc.fr][i];
      int cost = p.fr + e.cost * k, bit = p.sc.sc;
      if( e.to >= 2 && e.to < 2 + m ){
        if((bit >> (e.to-2)) & 1){
          cost -= cal[e.to-2];
          bit &= ~(1 << (e.to-2));
        }else continue;
      }
      if( cost < min_cost[e.to][bit] ){
        que.push(Pii( cost,Pi( e.to, bit)));
        min_cost[e.to][bit] = cost;
      }
    }
  }
  return ret;
}
int main(){
  while(cin >> m >> n >> k >> d , m){
    cal.resize(m);
    for(int i = 0 ; i < m ; i++ ){
      cin >> cal[i];
    }
    for(int i = 0 ; i < d ; i++ ){
      string s1, s2;
      int cost;
      cin >> s1 >> s2 >> cost;
      info[java(s1)].push_back(edge( java(s2), cost));
      info[java(s2)].push_back(edge( java(s1), cost));
    }
    cout << bfs() << endl;
    for(int i = 0 ; i < 110 ; i++ ) info[i].clear();
  }
}

Measured memory_bytes: 1340
N, K = map(int, input().split())
m = float("inf")
x = sorted(list(map(int, input().split())))
for i in range(N-K+1):
    m = min(abs(x[i])+abs(x[i+K-1]-x[i]), abs(x[i+K-1])+abs(x[i]-x[i+K-1]), m)
print(m)

Measured memory_bytes: 62576
#include <bits/stdc++.h>
using namespace std;
int A,B,C,D,E,F;
int w[2],s[2];
int answt=0,anssg=0;
double ansper=-1.0;
bool ok(int sg,int wt)
{
    return (double)sg/(double)wt <= (double)E/100.0;
}
void dfs(int dep,int sum)
{
    if(dep==2){
        //printf("sum = %d\n",sum);
        int emp=F-sum;
        int maxsg=(int)((double)sum*(double)E/100.0);
        maxsg=min(maxsg,emp);
        //printf("maxsg = %d\n",maxsg);
        int finsg=0;
        for(int i=0;i<=maxsg/s[0];i++){
            for(int j=0;j<=maxsg/s[1];j++){
                if(i*s[0]+j*s[1]>maxsg) break;
                finsg=max(finsg,i*s[0]+j*s[1]);
            }
        }
        double per=(double)finsg/(double)(sum+finsg);
        if(per>ansper) {
            ansper=per;
            answt=sum,anssg=finsg;
        }
        return;
    }
    for(int i=0;i<=F/w[dep] && sum<=F;i++){
        if(sum+i*w[dep]>F) break;
        sum+=i*w[dep];
        dfs(dep+1,sum);
        sum-=i*w[dep];
    }
}
int main()
{
    scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
    w[0]=A*100,w[1]=B*100,s[0]=C,s[1]=D;
    dfs(0,0);
    printf("%d %d\n",answt+anssg,anssg);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		char[] c = new char[s.length()];
		for (int i = 0; i < s.length(); i++) {
			c[i] = s.charAt(i);
		}
		boolean f = false;
		if (c[0] != 'A' ||Character.isUpperCase(s.charAt(s.length()-1)) || Character.isUpperCase(s.charAt(1))) {
			System.out.println("WA");
			return;
		}
		int U = 0;
		for (int i = 2; i < s.length()-1; i++) {
			if (Character.isUpperCase(s.charAt(i))) {
				U++;
			}
			if (c[i] == 'C') f = true;
		}
		if (U == 1 && f == true) {
			System.out.println("AC");
		} else {
			System.out.println("WA");
		}
	}
}


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

int main()
{
    int n;
    cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        mp[a]++;
    }
    int t = (1 << 30);
    int ans = 0;
    for(auto itr = mp.rbegin(); itr != mp.rend(); itr++){
        int a = itr->first, c = itr->second;
        while(t > a * 2) t /= 2;
        if(t == a * 2) ans += c / 2;
        else{
            ans += min(mp[a], mp[t - a]);
            mp[t - a] -= min(mp[a], mp[t - a]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 67608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, x, ans = 0;
  cin >> n >> x;
  vl a(n);
  rep(i, n) cin >> a[i];
  rep2(i, 1, n) {
    ll now = a[i - 1] + a[i];
    ll d = now - x;
    if(d > 0) {
      ans += d;
      a[i] = max(a[i] - d, 0LL);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4032
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
//luoxuejieshihaoren
int w[105];
int ans[105];
int s[105];
int sum=0;
int n,i,t;
int aaa(int x)
{
    int num=0;
    for(i=1; i<=x; i++)
    {
        num+=w[i];
    }
//    printf("111 %d ",num);
//    printf("\n");
    return num;
}
int main()
{
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {

        scanf("%d",&w[i]);

    }
    for(i=1; i<=n; i++)
    {
        sum+=w[i];
    }

    for(t=1; t<=n; t++)
    {
        s[t]=aaa(t);
    }
//     for(t=1; t<=n; t++)
//    {
//         printf("222 %d ",s[t]);
//    }
//    printf("\n");
    for(t=1; t<n; t++)
    {
        ans[t]=abs(sum-2*s[t]);
    }
//    for(t=1; t<n; t++)
//    {
//        printf("333 %d ",ans[t]);
//    }printf("\n");
    sort(ans,ans+n);
//    for(t=1; t<n; t++)
//    {
//        printf("444 %d ",ans[t]);
//    }
//printf("\n");
    printf("%d\n",ans[1]);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 998244353;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	long inf = LMAX / 2 - MAX;

	List<Edge> link[];

	void doIt() {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int S = sc.nextInt();


		int[] C = new int[N];
		int[] D = new int[N];
		link = new List[N];
		for(int i = 0; i < N; i++) {
			link[i] = new ArrayList<>();
		}
		int amax = 0;

		for(int i = 0; i < M; i++) {
			int U = sc.nextInt() - 1;
			int V = sc.nextInt() - 1;
			int A = sc.nextInt();
			int B = sc.nextInt();
			link[U].add(new Edge(V, A, B));
			link[V].add(new Edge(U, A, B));
			amax = Math.max(A, amax);
		}
		for(int i = 0; i < N; i++) {
			C[i] = sc.nextInt();
			D[i] = sc.nextInt();
		}
		int len = amax * (N - 1) + 1;
		S = Math.min(S, len);

		long dp[][] = new long[N][len + 1];
		for(int i = 0; i < N; i++)
			Arrays.fill(dp[i], inf);
		dp[0][S] = 0;


		PriorityQueue<Edge> pq = new PriorityQueue<>();
		pq.add(new Edge(0, S, 0));
		while(!pq.isEmpty()) {
			Edge e = pq.poll();
			//System.out.println("now:" + e.to + " " + e.coin + " " + e.cost);
			if(dp[e.to][e.coin] < e.cost) continue;
			int nextCoin = Math.min(e.coin + C[e.to], len);
			if(dp[e.to][nextCoin] > e.cost + D[e.to]) {
				dp[e.to][nextCoin] = e.cost + D[e.to];
				pq.add(new Edge(e.to, nextCoin, e.cost + D[e.to]));
				//System.out.println(e.to + " " + nextCoin + " " + (e.cost + D[e.to]));
			}
			
			for(Edge i : link[e.to]) {
				//System.out.println(e.coin + "->" + i.coin);
				if(e.coin < i.coin) continue;
				if(dp[i.to][e.coin - i.coin] > e.cost + i.cost) {
					dp[i.to][e.coin - i.coin] = e.cost + i.cost;
					pq.add(new Edge(i.to, e.coin - i.coin, e.cost + i.cost));
					//System.out.println(i.to + " " + (e.coin - i.coin) + " " + e.cost +"+"+ i.cost+"="+(e.cost+i.cost));

				}
			}

		}
		for(int i = 1; i < N; i++) {
			long min = inf;
			for(int j = 0; j < len; j++) {
				min = Math.min(dp[i][j], min);
			}
			System.out.println(min);
		}
		
		/*for(int i = 0; i < N; i++) {
			for(int j = 0; j < len; j++) {
				System.out.print(dp[i][j] + " ");
			}
			System.out.println();
		}*/

	}

	class Edge implements Comparable<Edge>{
		int to;
		int coin;
		long cost;

		Edge(int t, int sc ,long c){
			to = t; coin = sc; cost = c;
		}

		@Override
		public int compareTo(Edge arg0) {
			return (int)(this.cost - arg0.cost);
		}

	}

	
	

	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 52636
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(), v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 1;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        string s;
        cin >> s;
        vector<int> idx1, idx2;
        for(int i = 0; i < n; i++){
            if(s[i] == 'W'){
                idx1.push_back(i);
            }else{
                idx2.push_back(i);
            }
        }
        int i = 0, j = idx2.size() - 1;
        int ans1 = 0;
        while(i < (int)idx1.size() and j >= 0 and idx1[i] < idx2[j]){
            i++;
            j--;
            ans1++;
        }
        ans1 = min(ans1, n - (int)idx1.size());
        ans1 = min(ans1, n - (int)idx2.size());
        cout << ans1 << '\n';
    }
}

Measured memory_bytes: 37096
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
//#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int>
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define cd complex<double>
#define PI 4*atan(1)
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

int main()
{
	FAST;
	ll n;
	cin >> n;
	ll tmp = 9;
	ll t1 = 10;
	ll ans = 0;
	while(1)
	{
		if(n >= t1)
			ans += tmp;
		else
		{
			tmp /= 9;
			if(tmp > n)
				break;
			ans += (n - tmp + 1);
			break;
		}
		tmp *= 100;
		t1 *= 100;
	}
	cout << ans;
}


Measured memory_bytes: 256
#a = int(input())
#b,c = map(int,input().split())
#s = input()
#list_s = list(input())
#list_int = list(map(int,input().split()))

#list = [0 for i in range(n)]
#dp = [[0 for i in range(A)] for j in range(B)]

#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

# 2進数 format(10, 'b') # '1010'

# aa=[int(input()) for i in range(n)]

#for i,name in enumerate(list)

''' 二次元配列を一列ずつ
for i in ans:
	print(*i)
'''
''' heapq
queue = []
heapq.heapify(queue) #heapqの作成
heapq.heappush(queue,num) #numのpush(値の追加)
pop = heapq.heappop(queue) #numのpop(最小値の出力)
pop = heapq.heappushpop(queue,num) #push -> pop

'''

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7


N,M = map(int,input().split())

if N*2 > M:
	print(M//2)
else:
	M -= N*2
	print(N + M//4)


Measured memory_bytes: 3832
#include <iostream>
#include <math.h>
using namespace std;

int main(){

    long N = 0;
    cin >> N;
    double FN = double(N);
    int minVal = 1000000000;

    int harf = sqrt(N) + 1;
    for(int i = 1; i < harf; i++){

        double x = FN / i;
        long  ix = long(x);
        if(ix * i == N){
            int val = max(log10(ix) + 1, log10(i) + 1);
            minVal = val < minVal ? val : minVal;
        }
    }
    cout << minVal << endl;
}


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

int main(){
  string s;
  std::cin >> s;
  string a;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s.at(i) == s.at(i+1)) {
      a = "Bad";
      break;
    }
    else{
      a = "Good";
    }
  }
  std::cout << a << '\n';
}

Measured memory_bytes: 256
//
//  MAIN.cpp
//
//  Created by Sultan.
//  Copyright © 2017 Sultan. All rights reserved.
//

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define ll long long
#define ioi exit(0);

#define inf int(1e9)

#define f first
#define s second

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb push_back
#define ppb(x) pop_back(x)

#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x++)

using namespace std;

int n,m,ans;

int a[100500];

int main(){
    
    NFS
    
    cin >> n;
    cin >> m;
    
    for(int i=1;i<=n;i++){
        cin >> a[i];
        if(m/2<a[i]){
            ans+=((m-a[i])*2);
        }
        else ans+=(a[i]*2);
    }
    
    cout << ans << endl;
    
    ioi
}

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

int main(){
    int r, g, b, n; cin >> r >> g >> b >> n;
    int64_t ans = 0;
    for (auto i = 0; i <= n; i++) {
        if(r * i > n) break;
        for (auto j = 0; j <= n; j++) {
            if(r * i + g * j > n) break;
            if((n - r * i - g * j) % b == 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
import java.util.Scanner;

class Main{
    static void printwatch(int s){
	int h=s/3600;
	int m=(s%3600)/60;
	int sa=s%60;

	System.out.println(h+":"+m+":"+sa);
    }
    
    public static void main(String args[]){
	Scanner scan=new Scanner(System.in);

	int s=scan.nextInt();
	printwatch(s);
    }
}

Measured memory_bytes: 17324
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 
  
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( char *X, char *Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
  
   /* Following steps build L[m+1][n+1] in bottom up fashion. Note 
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   // Following code is used to print LCS 
   int index = L[m][n]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   // Print the lcs 
   cout << lcs; 
} 
  
/* Driver program to test above function */
int main() 
{
	string s,t;
	cin>>s;
	cin>>t;
	long long int m=s.size();
long long int	n=t.size();
	char X[m],Y[n];
	for(long long int i=0;i<m;i++)
	X[i]=s[i];
	
	for(long long int i=0;i<n;i++)
	Y[i]=t[i];
	/*
  char X[] = "AGGTAB"; 
  char Y[] = "GXTXAYB"; 
  int m = strlen(X); 
  int n = strlen(Y);*/ 
  lcs(X, Y, m, n); 
  return 0; 
} 


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1<<29;
/****** define constant end ********/

ll GetDigit(ll num)
{
    ll digit = 0;
    while (num != 0)
    {
        num /= 10;
        digit++;
    }
    return digit;
}

const int MAX = 10000000;
/****** define variable start ******/
ll n;
vector<string> s;
/******* define variable end *******/
ll solve(){
    /*  提出するな！！！！！！ */
    cin >> n;
    s.resize(n);
    map< string, ll > count;
    REP(i, n){
        count[s[i]] = 0;
    }
    REP(i, n){
        cin >> s[i];
        count[s[i]]++;
    }
    ll ma = 0;
    REP(i, n){
        if(count[s[i]] > ma){
            ma = count[s[i]];
        }
    }
    vector<string> count_string;
    REP(i, n){
        if(count[s[i]] == ma){
            count_string.push_back(s[i]);
        }
    }
    sort(count_string.begin(), count_string.end());
    cout << count_string[0] << endl;
    for(ll i = 1; i < count_string.size(); i++){
        if(count_string[i] != count_string[i-1]){
            cout << count_string[i] << endl;
        }
    }
    /* 1時間後に提出！ */
    /* E
        6以上なら繰り上げる
        繰り上げた結果、一つ上の桁を繰り上げるか考える。
        19
        20

        19996
        199(10)0
        19(10)00
        1(10)000
        20000

        これを実装(がんばる)
    */
    return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    
    return (int)end_solve;
}


Measured memory_bytes: 27120
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

vector<ll> divisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

bool is_ok(ll n, ll k) {
    while (n % k == 0) n /= k;
    return n % k == 1;
}

int main() {
    ll n;
    cin >> n;
    auto div = divisor(n);
    int cnt = 0;
    for (ll d: div) {
        if (d == 1) continue;
        if (is_ok(n, d)) cnt++;
    }
    cnt += (int)divisor(n - 1).size() - 1;
    cout << cnt << endl;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, m;
    cin >> n >> m;
    vector<deque<int>> v(n, deque<int>(m));
    REP(i, n){
        REP(j, m){
            cin >> v[i][j];
            v[i][j]--;
        }
    }

    int ans = n;
    vector<bool> del(m, false);

    while(!v[0].empty()){
        vector<int> cnt(m);
        bool finish = false;
        REP(i, n){
            while(!v[i].empty() && del[v[i][0]]){
                v[i].pop_front();
            }
            if(v[i].empty()){
                finish = true;
                break;
            }
            cnt[v[i][0]]++;
        }

        if(finish) break;

        int ma = -1, p = 0;
        REP(i, m){
            if(chmax(ma, cnt[i])) p = i;
        }

        chmin(ans, ma);
        del[p] = true;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
long long mod=1000000007;

int MIN(int A,int B){
    return A<B?A:B;
}

int MAX(int A,int B){
    return A>B?A:B;
}

int main(void){
    long long n,m;
    scanf("%lld%lld",&n,&m);
    long long a[m+1];
    for (int i=0; i<m; i++){
        scanf("%lld",&a[i]);
    }
    a[m]=n+1;
    long long ans[n+1];
    for (int i=0; i<n; i++){
        ans[i]=0;
    }
    ans[0]=1;
    ans[1]=1;
    int count=0;
    if (a[0]==1){
        ans[1]=0;
        count++;
    }
    for (int i=2; i<=n; i++){
        if (i!=a[count]){
            ans[i]=(ans[i-2]+ans[i-1])%mod;
        } else {
            ans[i]=0;
            count++;
        }
    }
    printf("%lld\n",ans[n]%mod);
    return 0 ;
}

Measured memory_bytes: 1664
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
while (true) {
   var n = arr.shift() - 0;
   if (n == 0) break;
   var nww = [];
   for (var i = 0; i < n; i++) nww[i] = arr.shift().split(" ");
   nww = nww.map(v => [v[0], v[1] - 0, v[2] - 0]);
   nww.sort((a,b)=>{
      return b[1]-a[1];
   });
   var max = 0;
   var ans = "";
   var bomb = function (str, arrB, sum, g) {
      if (arrB.length == 0) {
         if (max < g / sum) {
            ans = str;
            max = g / sum;
         }
         return;
      }
      for(var i=0;i<arrB.length;i++){
         var v=arrB[i];
         if (sum <= nww[v][2]) {
            var a = str+v;
            var b = arrB.filter(n => v != n);
            bomb(a, b, sum + nww[v][1], g + nww[v][1] * (str.length + 1));
         }
      }
   };
   var bombArr = [];
   for (var i = 0; i < n; i++) bombArr.push(i);
   bomb("", bombArr, 0, 0);
   console.log(ans.split("").map(v => nww[v-0][0]).reverse().join("\n"));
}


Measured memory_bytes: 19616
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
	string s1,s2,s3;
	cin >> s1>>s2>>s3;
	if(s1[s1.length()-1]==s2[0] && s2[s2.length()-1]==s3[0]) cout << "YES" <<endl;
	else cout << "NO" << endl;
}

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


int main() {
	int n;
  int flag = 1, x;
cin>>n;
  for(int i=0;i<n;i++) {
  	cin>>x;
    if(x % 2 == 0) {
    	if( !(x % 3 == 0 || x % 5 == 0)) {
        	flag = 0;
        }
    }
  }
  if(flag) {
  	cout<<"APPROVED"<<endl;
  }else {
  	cout<<"DENIED"<<endl;
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		assert solve(2, new long[] { 3, 1, 4, 1, 5, 9 }) == 1;
		assert solve(1, new long[] { 1, 2, 3 }) == -1;
		assert solve(3, new long[] { 8, 2, 2, 7, 4, 6, 5, 3, 8 }) == 5;
		int n = cin.nextInt();
		long[] a = new long[3 * n];
		for (int i = 0; i < a.length; i++)
			a[i] = cin.nextLong();
		long ans = solve(n, a);
		cout.println(ans);
	}

	private static long solve(int n, long[] a) {
		long[][] lrs = new long[n + 1][2];
		PriorityQueue<Long> lq = new PriorityQueue<>((x, y) -> Long.compare(x, y));
		PriorityQueue<Long> rq = new PriorityQueue<>((x, y) -> Long.compare(y, x));
		for (int i = 0; i < n; i++) {
			lq.add(a[i]);
			rq.add(a[3 * n - 1 - i]);
		}
		long lfsum = lq.stream().reduce((x, y) -> x + y).get();
		long rtsum = rq.stream().reduce((x, y) -> x + y).get();
		for (int i = 0; i <= n; i++) {
			lrs[i][0] = lfsum;
			long in = a[n + i];
			lq.add(in);
			long out = lq.poll();
			lfsum -= out;
			lfsum += in;
		}
		for (int i = 0; i <= n; i++) {
			lrs[n - i][1] = rtsum;
			long in = a[2 * n - 1 - i];
			rq.add(in);
			long out = rq.poll();
			rtsum -= out;
			rtsum += in;
		}
		long ans = Long.MIN_VALUE;
		for (long[] lr : lrs)
			ans = Math.max(ans, lr[0] - lr[1]);
		return ans;
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

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

}


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

S=input().strip()

ANS=[1]*len(S)
LEN=len(S)
for i in range(LEN):
    if i!=LEN-1 and S[i]=="R" and S[i+1]=="L":
        continue
    elif i!=0 and S[i]=="L" and S[i-1]=="R":
        continue
    elif i!=LEN-1 and S[i]=="R" and S[i+1]=="R":
        ANS[i+2]+=ANS[i]
        ANS[i]=0
    elif i!=0 and S[i]=="L" and S[i-1]=="L":
        ANS[i-2]+=ANS[i]
        ANS[i]=0


for i in range(LEN-1,-1,-1):
    if i!=LEN-1 and S[i]=="L" and S[i-1]=="R":
        continue
    elif i!=0 and S[i]=="R" and S[i+1]=="L":
        continue
    elif i!=LEN-1 and S[i]=="R" and S[i+1]=="R":
        ANS[i+2]+=ANS[i]
        ANS[i]=0
    elif i!=0 and S[i]=="L" and S[i-1]=="L":
        ANS[i-2]+=ANS[i]
        ANS[i]=0

print(*ANS)




Measured memory_bytes: 6528
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    
    for(int i =3; i <= n; i++){
        if(i % 3 == 0){
            cout << " " << i;
        }
        
        else{
            int x = i;
            while(x != 0){
                if(x % 10 == 3){
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
}


Measured memory_bytes: 3072
X, Y, a, b, c = map(int, input().split())
A = list(map(int, input().split()))  # 赤色
B = list(map(int, input().split()))  # 緑色
C = list(map(int, input().split()))  # 無色, 赤色にも緑色にもなれる
A.sort(reverse=True)
B.sort(reverse=True)
# C.sort(reverse=True)

top_x_of_A = A[:X]
top_Y_of_B = B[:Y]
top_x_of_A.extend(top_Y_of_B)
C.extend(top_x_of_A)
C.sort(reverse=True)
print(sum(C[:X+Y]))


Measured memory_bytes: 109548
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

x,k,d = I()
a = abs(x) % d
b = abs(x) //d
if x == d:
    if k % 2 ==0:
        print(x)
        sys.exit()
    else:
        print(0)
        sys.exit()

if b <= k:
    p = k-b
    if p % 2 == 0:
        print(a)
    else:
        print(abs(a-d))
else:
    print(abs(abs(x)-k*d))

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

int main(){
    while(1){
        int m, t, p, r;
        cin >> m >> t >> p >> r;
        if (m == 0) break;
        vector<vector<bool>> ac(t, vector<bool>(p, false));
        vector<vector<int>> solved(t, vector<int>(p, 0));
        int v, w, x, y;
        for (int i = 0; i < r; i++){
            cin >> v >> w >> x >> y;
            w--; x--;
            if (y == 0){
                ac[w][x] = true;
                solved[w][x] += v;
            }
            else {
                solved[w][x] += 20;
            }
        }
        vector<tuple<int, int, int>> ans(t);
        for (int i = 0; i < t; i++){
            int a = 0;
            int b = 0;
            int c = i + 1;
            for (int j = 0; j < p; j++){
                if (ac[i][j]){
                    a++;
                    b -= solved[i][j];
                }
            }
            ans[i] = tie(a, b, c);
        }
        sort(ans.begin(), ans.end(), greater<tuple<int, int, int>>());
        int tmp = -1;
        int tmp2 = -1;
        for (int i = 0; i < t; i++){
            if (i == 0);
            else if (get<0>(ans[i]) == tmp && get<1>(ans[i]) == tmp2) cout << "=";
            else cout << ",";
            cout << get<2>(ans[i]);
            tmp = get<0>(ans[i]);
            tmp2 = get<1>(ans[i]);
        }
        cout << endl;
    }
}


Measured memory_bytes: 3156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		
		int bricks = input.nextInt();
		
		int[] array = new int[bricks];
		
		for (int i = 0; i < array.length; i++) {
			array[i] = input.nextInt();
		}
		
		int counter = 0;
		int weAt = 1;
		for (int i = 0; i < array.length; i++) {
			if (array[i] != weAt) {
				counter++;
			} else {
				weAt++;
			}
		}
		
		if (counter >= array.length) {
			System.out.println("-1");
		} else {
			System.out.println(counter);
		}
	}
}


Measured memory_bytes: 83272
#include <bits/stdc++.h>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
int main(void){
    int n;
    cin>>n;
    vector<ll> a(n),l(n+1),r(n+1);
    ll max_1=0,max_2=0;
    rep(i,0,n) {
        cin>>a[i];
    }
    rep(i,1,n+1)l[i]=max(l[i-1],a[i-1]);
    for(int i=n-2;i>=0;i--)r[i]=max(r[i+1],a[i+1]);
    rep(i,0,n){
        cout<<max(l[i],r[i])<<endl;
    }
    return 0;
}

Measured memory_bytes: 6272
/*
    AUTHOR:hruday pabbisetty
    NIT ROURKElA
*/
#include <bits/stdc++.h>
using namespace std;
#define opt ios_base::sync_with_stdio(0)
#define lli long long int
#define ulli unsigned long long int
#define I int
#define S string
#define D double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define in3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define out(n) printf("%lld",n)
#define inu(a) scanf("%lld",&a)
#define outu(a) printf("%llu",a)
#define ins(s) scanf("%s",&s)
#define outs(s) printf("%s",s)
#define nl printf("\n")
#define mod 1000000007
#define inf 100000000000000
typedef long long       ll;
typedef pair<lli, lli>  plli;
typedef vector<lli>     vlli;
typedef vector<ulli>    vulli;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<plli>     vplli;
#define MM(a,x)  memset(a,x,sizeof(a));
#define ALL(x)   (x).begin(), (x).end()
#define P(x)       cerr<<"{"#x<<" = "<<(x)<<"}"<<endl;
#define P2(x,y)       cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<"}"<<endl;
#define P3(x,y,z)  cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<"}"<<endl;
#define P4(x,y,z,w)cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<", "#w" = "<<(w)<<"}"<<endl;
#define PP(x,i)     cerr<<"{"#x"["<<i<<"] = "<<x[i]<<"}"<<endl;
#define TM(a,b)     cerr<<"{"#a" -> "#b": "<<1000*(b-a)/CLOCKS_PER_SEC<<"ms}\n";
#define UN(v)    sort(ALL(v)), v.resize(unique(ALL(v))-v.begin())
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz() size()
lli power(lli a,lli b)
    {
    lli value;
    if(b==0)
        {
        return 1;
    }
    else if(b%2==0)
        {
        value=power(a,b/2)%mod;
        return(value*value)%mod;
    }
    else
        {
        value=power(a,b/2)%mod;
        return ((a*value)%mod*(value))%mod;
    }
}
int main()
{
    opt;

    lli a,b;
    cin>>a>>b;
    cout<<(a+b)%24;
}




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

count_ab = 0
S_tail_a_head_b = 0
S_tail_a = 0
S_head_b = 0
for _ in range(N):
    s = input()
    count_ab += s.count('AB')

    if s[0] != 'B' and s[-1] != 'A':
        continue

    if s[0] == 'B' and s[-1] == 'A':
        S_tail_a_head_b += 1
    elif s[0] == 'B':
        S_head_b += 1
    elif s[-1] == 'A':
        S_tail_a += 1

if S_tail_a_head_b == 0:
    count_ab += min(S_head_b, S_tail_a)
else:
    if sum([S_tail_a, S_head_b]) > 0:
        count_ab += S_tail_a_head_b + min(S_head_b, S_tail_a)
    else:
        count_ab += S_tail_a_head_b - 1

print(count_ab)


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int N = sc.nextInt();
        int[] arr = new int[N];
        int sum = 0;

        for(int i = 0; i<N; i++){
            arr[i] = sc.nextInt();
            sum += arr[i];
        }

        double mean = sum;
        mean /= N;

        int avg = (int) Math.round(mean);

        int price = 0;
        for(int i : arr){
            price += (avg - i) * (avg - i);
        }

        System.out.println(price);

    }
}


Measured memory_bytes: 9940
#include <cstdio>
#include <algorithm>
using namespace std;
#pragma region
class FastIO {
  static const int rdata_sz = (1 << 25), wdata_sz = (1 << 25);
  char rdata[rdata_sz], wdata[wdata_sz], *rb, *wb;
  char tmp_s[20];

public:
  FastIO() {
    fread(rdata, 1, rdata_sz, stdin);
    rb = rdata; wb = wdata;
  }
  ~FastIO() {
    fwrite(wdata, 1, wb - wdata, stdout);
  }

  template<typename T>
  inline void read_i(T &x) {
    bool neg = false;
    x = 0;
    while((*rb < '0' || *rb > '9') && *rb != '-') ++rb;
    if(*rb == '-') {
      neg = true;
      ++rb;
    }
    while('0' <= *rb && *rb <= '9') {
      x = 10 * x + (*rb - '0');
      ++rb;
    }
    if(neg) x = -x;
  }

#define pc(x) *(wb++) = x
  template<typename T>
  inline void writeln_i(T x) {
    if (x == 0) { pc('0'); pc('\n'); return; }
    if(x < 0) { pc('-'); x = -x; }
    char *t = tmp_s;
    while(x) {
      T y = x / 10;
      *(t++) = (x - y*10) + '0';
      x = y;
    }
    while(t != tmp_s) pc(*(--t));
    pc('\n');
  }
#undef pc
};
FastIO io;
#pragma endregion
static const long long INF = 1e18;
int main() {
    int A, B, Q;
    io.read_i(A);
    io.read_i(B);
    io.read_i(Q);
    long long s[100002], t[100002], x[100000];
    for (int i = 1; i <= A; i++) io.read_i(s[i]);
    for (int i = 1; i <= B; i++) io.read_i(t[i]);
    s[A + 1] = t[B + 1] = INF;
    s[0] = t[0] = -INF;
    for (int i = 0; i < Q; i++) {
        io.read_i(x[i]);
        auto b = lower_bound(s, s + A + 2, x[i]);
        auto d = lower_bound(t, t + B + 2, x[i]);
        long long ans = INF, tmp1[] = {*(b - 1), *b}, tmp2[] = {*(d - 1), *d};
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                auto m = min(abs(tmp1[j] - x[i]) + abs(tmp2[k] - tmp1[j]), abs(tmp2[k] - x[i]) + abs(tmp1[j] - tmp2[k]));
                if (m < ans) ans = m;
            }
        }
        io.writeln_i(ans);
    }
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
#define inf (1<<16)

int main(){
  int n;
  cin>>n;
  int a[12]={1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
  vector<int> dp(n+1,inf);
  dp[0]=0;

  for(int i=0;i<=n;++i){
    int DP=dp[i];
    for(int j=0;j<12;++j){
      if(i-a[j]>=0)DP=min(dp[i-a[j]]+1,DP);
    }
    dp[i]=DP;
  }
  cout<<dp[n]<<endl;
}


Measured memory_bytes: 640
def is_prime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


N = int(input())
cnt = 0
for i in range(N):
    if is_prime(int(input())):
        cnt += 1
print(cnt)



Measured memory_bytes: 5668
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

const int s_max = 3010;
const int t_max = 3010;

int dp[s_max][t_max];


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s,t;cin>> s >> t;
    rep(i,s_max) rep(j,t_max) dp[i][j] = 0;

    // dp[i][j] = dp[i-1][j], dp[i][j-1], dp[i-1][j-1]+1 if s[i]==t[j]
    
    rep(i,s.length()+1) rep(j,t.length()+1)
    {
        if (s[i]==t[j])
        {
            dp[i+1][j+1] = dp[i][j]+1;
        }
        else
        {
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
        }
    }

    string ans = "";
    int n = s.length();
    int m = t.length();
    int ans_length = dp[n][m];
    int now_n = s.length();
    int now_m = t.length();
    rep(i,ans_length)
    {
        while(true)
        {
            if (dp[now_n][now_m]==dp[now_n-1][now_m])
            {
                now_n--;
            }
            else break;
        }
        while(true)
        {
            if (dp[now_n][now_m] == dp[now_n][now_m-1]) now_m--;
            else break;
        }
        ans += s[now_n-1];
        now_n--;
        now_m--;
        // cout << ans << endl;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl; 
}


Measured memory_bytes: 35712