akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define INF 0x33433433
#define M 1100000

int n;
int as[114514];
int ls[114514];
int rs[114514];
bool dp[21][M+1];

bool check(double x) {
  fill(dp[0], dp[n], false);
  
  ls[0] = max(1, (int)ceil(as[0]*(1-x)));
  rs[0] = min(M, (int)floor(as[0]*(1+x)));
  for (int i=ls[0]; i<=rs[0]; i++) dp[0][i] = true;
  for (int i=1; i<n; i++) {
    ls[i] = max(1, (int)ceil(as[i]*(1-x)));
    rs[i] = min(M, (int)floor(as[i]*(1+x)));
    for (int j=ls[i-1]; j<=rs[i-1]; j++) {
      int p = (ls[i]/j + (ls[i]%j!=0)) * j;
      for (int k=p; k<=rs[i]; k+=j) {
        dp[i][k] |= dp[i-1][j];
      }
    }
  }

  bool ret = false;
  for (int j=ls[n-1]; j<=rs[n-1]; j++) ret |= dp[n-1][j];
  return ret;
}

int main() {
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf("%d", &as[i]);
  }

  double low = 0.0;
  double high = 1;
  for (int i=0; i<28; i++) {
    double mid = (low+high)/2;
    if (check(mid)) high = mid;
    else low = mid;
  }

  printf("%.15f\n", high);
}

Measured memory_bytes: 24628
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map> // pair
#include <functional>
using namespace std;
int N, M;
vector<pair<int, int> > pairs;
void solve(){
  sort(pairs.begin(), pairs.end());
  //for(int i = 0; i < M; i++) cout << "first = " << pairs[i].first << " second = " << pairs[i].second << endl;
  int cutPlace;
  int cnt = 0;
  for(int i = 0; i < M; i++){
    if(i == 0){
      cutPlace = pairs[i].first;
      cnt++;
    }else if(cutPlace > pairs[i].second) continue;
    else{
      cutPlace = pairs[i].first;
      cnt++;
    }
  }
  cout << cnt << endl;
  return ;
}

int main(){
  cin >> N >> M;
  pairs = vector<pair<int, int> >(M);
  for(int i = 0; i < M; i++){
    cin >> pairs[i].second >> pairs[i].first ;
  }
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define INF 1e15+1
typedef long long llong;

llong count;

void merge(int *A, int left, int mid, int right) {
    int n1 = mid-left;
    int n2 = right-mid;
    int L[n1+1], R[n2+1];
    for (int i=0; i<n1; i++) L[i] = A[left+i];
    for (int i=0; i<n2; i++) R[i] = A[mid+i];
    L[n1] = R[n2] = INF;
    
    int i=0, j=0;
    for (int k=left; k<right; k++) {
        if(L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
            count += n1-i;
        }
    }
}

int mergeSort(int *A, int left, int right) {
    if(left+1 < right) {
        int mid = (left+right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}


int main() {
    int n;
    scanf("%d", &n);
    int A[n];
    for (int i=0; i<n; i++) scanf("%d", &A[i]);
    
    count = 0;
    mergeSort(A, 0, n);
    
    printf("%lld\n", count);
    return 0;
}


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

int main(){
  int N,H,W,j=0;
  cin>>N>>H>>W;
  for(int i=0;i<N;i++){
    int A,B;
    cin>>A>>B;
    if(A>=H && B>=W)
      j++;
  }
  cout<<j<<endl;
}

Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>
#define INF 1001001001
int min(int x, int y) {
	return x < y ? x : y;
}
int main() {
	int n, h[100000];
	int dp[100005];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
		dp[i] = INF;
	}
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}
	printf("%d\n", dp[n - 1]);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int a,b;
    cin  >> a >> b;
    if(a > b) cout << string(a,b+0x30) << endl;
    else cout << string(b,a+0x30)<< endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int max_val(int a[], int max)
{
  int i;
  int k=0;

  for(i=0; i<100; i++){
	if(max < a[i])
	  max = a[i];
  }

  return max;

}

void print_array(int a[], int k)
{
  int i=0;

  // printf("k: %d a[8]%d\n",k ,a[8]);

  while(i<100){
	if(a[i] == k){
	  printf("%d\n", i+1);
	}

	i++;
  }

  return;

}

int main(void)
{
  int i, t, k;
  int a[100]={0};
  int max=0;

  while(scanf("%d", &t) != EOF){

	a[t-1]++;

	max = max_val(a, max);


	//printf("max = %d\n", max);
	//printf("a[k] = %d\n", a[k]);


  }

	print_array(a,max);

  return 0;

}

Measured memory_bytes: 596
def main():
    import sys
    from collections import Counter
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    S = [int(x) for x in input().strip()]
    N = len(S)
    ans = 0
    l = [0] * (N + 1)
    p = 1
    cumsum = [0] * (N + 1)
    for i in range(N-1, -1, -1):
        l[i] = (S[i] * p) % 2019
        p *= 10
        p %= 2019
    for i in range(N-1, -1, -1):
        cumsum[i] = (l[i] + cumsum[i+1]) % 2019
    cumsum = Counter(cumsum)
    for i in range(0, 2019):
        ans += (cumsum[i] * (cumsum[i] - 1)) // 2

    print(ans)

if __name__ == '__main__':
    main()

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

int main(){

        int l,r,d;
        int count;
        count = 0;

        cin >> l >> r >> d;
    
    for(int i = l;i <= r;i ++){
        if(i % d == 0) count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 3592
#include <cmath>  
#include <queue>  
#include <cstdio>  
#include <cstdlib>  
#include <cstring>  
#include <iostream>  
#include <algorithm>  
#include <map>  
#include <bits/stdc++.h>  
#define mp make_pair  
using namespace std;  
  
constexpr int maxn = 2000010;  
char s[maxn];  
  
set <int> S;  
int nextt[maxn][30];  
int now[30];  
int now_tot[maxn];  
  
void doit(){  
    scanf("%s",s);  
    int len=strlen(s);  
    int tot=0;  
    for (int i=len;i>=1;i--)  
    {  
        S.insert( s[i-1]-'a' );  
        now_tot[i]=tot;  
        if (S.size()==26)  
        {  
            tot++;  
            S.clear();  
        }  
    }  
    if (tot==0)  
        {  
        for (int i=0;i<26;i++)  
            if (S.count (i )==0)  
                {  
                    printf("%c",i+'a');  
                    return ;  
                }  
        }  
    memset(now,0,sizeof(now));  
    for (int i=len;i>=1;i--)  
    {  
        for (int j=0;j<26;j++)  
            nextt[i][j]=now[j];  
        now[ s[i-1]-'a' ]=i;  
    }  
    int tmp=0;  
    for (int i=0;i<26;i++)  
        if (S.count (i )==0)  
        {  
            tmp=now[i];  
            break;  
        }  
    printf("%c",s[tmp-1]);  
    for (int i=1;i<tot;i++)  
        {  
            for (int j=0;j<26;j++)  
                if (now_tot [ nextt[ tmp ][ j ] ]==now_tot [ tmp ] -1 )  
                    {  
                        tmp=nextt[ tmp ][ j ];  
                        printf("%c",j+'a');  
                        break;  
                    }  
        }  
    for (int i=0;i<26;i++)  
        if (nextt[ tmp ][ i ]==0)  
            {  
                printf("%c",i+'a');  
                break;  
            }  
}  
  
  
int main(){  
    doit();  
    return 0;  
}  

Measured memory_bytes: 29696
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

string s;

signed main() {
    //cin.tie(0); ios::sync_with_stdio(false);
    cin >> s;
    string now = "";
    rep(i, s.size()) {
        if (s[i]=='0') now += "0";
        else if (s[i]=='1') now += "1";
        else {
            if (now.size()>=1) now = now.substr(0, now.size()-1);
        }
    }
    cout << now << endl;
}

Measured memory_bytes: 256
/**
 *    author:   K.R.Surrya  
 *    created:  02/05/2020 18:53:41
**/
#include<bits/stdc++.h>
#define vi vector<int>
#define vii vector<vector<int> >
#define vpi vector<pair<int,int> >
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pb push_back
using namespace std; 

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)  { return ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a,Args... args)
{
    cerr << *it << " = " << a <<endl;
    err(++it,args...);   //args is going to end.
}

void solve() { 
    long long A,B,N;
    cin >> A >> B >> N;   //N is large ...
    //in search of a x value...
    long long x=min(B-1,N);
    long long ret=(A*x)/B - A*(x/B) ;
    cout << ret << '\n';
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


     auto start = chrono::high_resolution_clock::now();
     solve();
     auto end = chrono::high_resolution_clock::now();

     cerr << " Execution time : " << chrono::duration_cast<chrono::milliseconds>(end-start).count()<<"ms"<<endl;

   
    return 0;
}


Measured memory_bytes: 3556
function main(input) {
    input = input.split("\n");
    var n = parseInt(input[0]);
    var ds = input[1].split(" ").map((v) => parseInt(v, 10));

    var previousHalf = ds.sort((a, b) => a - b).splice(0,ds.length / 2);
    console.log(ds[0] - previousHalf[previousHalf.length - 1]);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

namespace ABC126_A_Changing_a_Character
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
			int n = input[0];
			int k = input[1];
			char[] chr = Console.ReadLine().ToCharArray();

			chr[k - 1] = Char.ToLower(chr[k - 1]);
			Console.WriteLine(new string(chr));
		}
	}
}


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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 3 * 1e5 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
    }

    vector<int> B(N + 1, 0);
    rep(i, N) {
        B[ A[i] ]++;
    }

    vector<int> C(N + 1, 0);
    for (int i = 1; i <= N; ++i) {
        C[ B[i] ]++;
    }

    vector<int> sumC(N + 1), sumCi(N + 1);
    sumC[0] = sumCi[0] = 0;
    for (int i = 1; i <= N; ++i) {
        sumC[i] = sumC[i - 1] + C[i];
        sumCi[i] = sumCi[i - 1] + C[i] * i;
    }

    for (int i = 1; i <= N; ++i) {
        int l = 0, r = N + 1;
        while (r - l > 1) {
            int mid = (l + r) / 2;
            int res = (sumC[N] - sumC[mid]) * mid + sumCi[mid];
            res /= mid;
            if (i <= res) {
                l = mid;
            } else {
                r = mid;
            }
        }
        cout << l << endl;
    }
}

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

using namespace std;

int n;
int a[200001];

int ap[21];

typedef long long lint;

lint rez;

int main()
{
    cin >> n;

    int i;
    int st = 1;
    lint sum = 0;
    int x = 0;
    int nr;
    for(i = 1; i <= n; i ++)
    {
        cin >> nr;
        a[i] = nr;

        while((x ^ nr) != (sum + nr))
        {
            rez += (i - 1 - st + 1);
            sum -= a[st];
            x ^= a[st];
            st ++;
        }

        x ^= nr;
        sum += nr;
    }

    rez += (1LL * (n - st + 1) * (n - st + 1 + 1)) >> 1;

    cout << rez << "\n";

    return 0;
}


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

int main() {
	string s;
	cin >> s;
	int ans = 0;
	int mx = 0;
	rep(i, 3) {
		if(s[i]=='R') ans++;
		else ans = 0;
		mx = max(mx, ans);
	}
	cout << mx << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#define MAXA 100000
#define MAX 20000000000
#define s(i) scanf("%d", &(i))
#define p(i) printf("%d", (i))
#define ps() printf(" ") 
#define rer(i,j,k) for((i)=(j);(i)<(k);++(i))
#define ret(i,j,k) for((i)=(j);(i)>=(k);--(i))
using namespace std;
int num[MAXA] = {0};
int main(){
	int i, n, Count = 1, min = -1;
	cin >> n;
	rer(i,0,n){
		cin >> num[i];
	}
	sort(num,num+n);
	min = num[0];
	rer(i,1,n){
		if(num[i] > min){
			min = num[i];
			Count++;
		}
	}
	cout << Count << endl;
	return 0;
} 

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

namespace ARC097C
{
    public class Program
    {
        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            var S = ss.Next(String);
            var K = ss.Next(int.Parse);

            var sos = new SortedSet<string>();
            for (var j = 1; j <= 5; j++)
            for (var i = 0; i <= S.Length - j; i++)
            {
                sos.Add(S.Substring(i, j));
            }

            sw.WriteLine(sos.ToArray()[K - 1]);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }

        public T[] Next<T>(Func<string, T> parser, int x)
        {
            var ret = new T[x];
            for (var i = 0; i < x; ++i) ret[i] = Next(parser);
            return ret;
        }

        public T[][] Next<T>(Func<string, T> parser, int x, int y)
        {
            var ret = new T[y][];
            for (var i = 0; i < y; ++i) ret[i] = Next(parser, x);
            return ret;
        }
    }
}

Measured memory_bytes: 13920
import java.util.*;
public class Main{
     public static void main(String [] args){
          Scanner sc=new Scanner(System.in);
          int a=sc.nextInt();
          int b=sc.nextInt();
          int c=sc.nextInt();
          int z=Findmax(a,b,c);
          System.out.println(z);
          
     }
     public static int Findmax(int a, int b, int c){
          
          if(a>=b&&a>=c){
               return a*10+b+c;}
          else if(b>=a&&b>=c){
               return b*10+c+a;}
          else if(c>=a&&c>=b){
               return c*10+b+a;}
          return 0;
     }
     
}

Measured memory_bytes: 23252
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#include <cmath>
#include <stack>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double PI = 3.14159;

int main(){
	int n;
	while(cin >> n && n){
		int w_count = 0;
		int b_count = 0;
		stack<int> w, b;
		for(int i = 0; i < n; i++){
			int go;
			cin >> go;
			if(i % 2 == 0){
				if(go == 1){
					w_count++;
					if(w.empty()) w.push(i);
					else{
						int lw = w.top();
						if(lw == i-1) w.pop();
						w.push(i);
					}
				}else{
					b_count++;
					if(b.empty()) b.push(i);
					else{
						int lb = b.top();
						if(lb == i-1) b.pop();
						b.push(i);
					}
				}
			}else{
				if(go == 0){
					if(b.empty()){
						w.pop();
						w_count -= i;
						b_count += i+1;
						b.push(i);
					}else{
						int lb = b.top();
						if(lb == i-1){
							b_count++;
							b.pop();
							b.push(i);
						}else{
							w.pop();
							b.pop();
							b_count += i - lb;
							w_count -= i - lb - 1;
							b.push(i);
						}
					}
				}else{
					if(w.empty()){
						b.pop();
						b_count -= i;
						w_count += i+1;
						w.push(i);
					}else{
						int lw = w.top();
						if(lw == i-1){
							w_count++;
							w.pop();
							w.push(i);
						}else{
							w.pop();
							b.pop();
							w_count += i - lw;
							b_count -= i - lw - 1;
							w.push(i);
						}
					}
				}
			}
		}
		cout << b_count << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v){
  const char* dlm = "";
  for(const auto& x:v) os << exchange(dlm, "\n") << x;
  return os;
}
struct Graph{
  using seen_t=int32_t; using ver_t=size_t; using edge_t=pair<seen_t,ver_t>;
  const seen_t NO=-1; vector<seen_t> seen;
  vector<vector<edge_t>> edge;
  Graph(size_t n): seen(n,NO), edge(n) {}
  bool bfs(ver_t frm){
    seen[frm]=0;
    deque<ver_t> que(1,frm);
    while(!que.empty()){
      // auto u=que.back(); que.back(); // dfs
      auto u=que.front(); que.pop_front(); // bfs
      for(const auto& v:edge[u]){
        if(seen[v.second]==NO){
          seen[v.second]=(v.first%2==0?seen[u]:1-seen[u]);
          que.push_back(v.second);
        } else if((seen[v.second]==seen[u]&&v.first%2!=0)
        || (seen[v.second]!=seen[u]&&v.first%2==0)) return false;
      }
    }
    return true;
  }
};
int32_t main(){
  size_t n; cin>>n;
  Graph g(n);
  for(size_t i=0; i<n-1; ++i){
    int32_t u,v,w; cin>>u>>v>>w; g.edge[u-1].emplace_back(w,v-1); g.edge[v-1].emplace_back(w,u-1);
    // int32_t u,v; cin>>u>>v; g.edge[u-1].emplace_back(1,v-1); g.edge[v-1].emplace_back(1,u-1);
  }
  if(g.bfs(0)) cout<<g.seen;
  else cout<<"inconsistent";
}


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


#define long long long int

using namespace std;


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

    int n, m;
    cin >> n >> m;
    vector<long> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<long> res;
    long sum = accumulate(a.begin(), a.end(), 0);
    double r = (double) sum / (4 * m);
    for (int i = 0; i < n; ++i) {
        if (r <= a[i]) {
            res.push_back(a[i]);
        }
    }

    cout << (res.size() >= m ? "Yes" : "No");
    return 0;
}




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

#define int long long
#define MAXN 100005
string s;
int t,n,k;
bool fl = 1;
int a[MAXN],nn;

signed main()
{
	cin >> s >> k;
	n = s.size();
	for(int i = 1; i < n; i ++)
	if(s[i] != s[0]) {
		fl = 0;
	}
	
	if(fl == 1) {
		cout<<k*n/2;
		return 0;
	}
	for(int i = 0; i < n; i ++)
	if(i == 0 || s[i] != s[i-1]) {
		nn ++;
		a[nn] = 1;
	} else {
		a[nn] ++;
	}
	int ans = 0;
	if(s[0] == s[n-1]) {
		for(int i = 2; i < nn; i ++)
			ans += a[i]/2*k;
		ans += a[1]/2 + a[nn]/2 + (a[1]+a[nn])/2*(k-1);
	} else {
		for(int i = 1; i <= nn; i ++)
			ans += a[i]/2;
	//	cout<<ans<<"?\n";
		ans *= k;
	}
	cout<<ans;
	return 0;
}
/*
lxlllxll
4+5
c
ooooooooo
nt
eeee
eeee
eest
*/

Measured memory_bytes: 256
// https://ei1333.github.io/luzhiled/
// http://beet-aizu.hatenablog.com/entry/2017/01/04/113233
// http://www.prefield.com/algorithm/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    inl(n,m);
    vl A(n); in1(A);
    ll sum=accumulate(all(A),0ll);
    ll cnt=0;
    REP(i,n){
        if(A[i]*4*m>=sum) cnt++;

    } 
    if(cnt>=m) out("Yes");
    else out("No");
    
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int K;
ll dp[2][501][2][2];
ll sum[2][501][2][2];
vector<vector<int> > nxtst;

ll solve(string S){
  int N=S.size();
  memset(dp,0,sizeof(dp));
  memset(sum,0,sizeof(sum));

  int crtd=0,nxtd=1;
  rep(i,N){
    memset(dp[nxtd],0,sizeof(dp[nxtd]));
    memset(sum[nxtd],0,sizeof(sum[nxtd]));
    if(i==0) dp[crtd][0][0][0]=1;
    else dp[crtd][0][1][0]=1;
    rep(j,K){
      rep(f1,2){
        rep(f2,2){
          int mn=(f2==0?1:0);
          int mx=(f1==0?S[i]-'0':9);
          repl(nxt,mn,mx+1){
            int nxtj=nxtst[j][nxt];
            (dp[nxtd][nxtj][(f1==0&&nxt==mx?0:1)][1]+=dp[crtd][j][f1][f2])%=mod;
            (sum[nxtd][nxtj][(f1==0&&nxt==mx?0:1)][1]+=sum[crtd][j][f1][f2])%=mod;
            if(nxtj==K-1){
              (sum[nxtd][nxtj][(f1==0&&nxt==mx?0:1)][1]+=dp[crtd][j][f1][f2])%=mod;
            }
          }
        }
      }
    }
    swap(crtd,nxtd);
  }

  ll res=0;
  rep(j,K){
    rep(f1,2){
      (res+=sum[crtd][j][f1][1])%=mod;
    }
  }

  return res;
}

int main(){
  string A,B,s;
  cin>>A>>B>>s;

  int N=s.size();
  vector<string> pfx;
  rep(i,N+1){
    pfx.push_back(s.substr(0,i));
  }
  sort(all(pfx));
  uni(pfx);
  K=pfx.size();
  nxtst=vector<vector<int> >(K,vector<int>(10,-1));
  rep(i,K){
    rep(nxt,10){
      string t=pfx[i];
      t+='0'+nxt;
      int idx=0;
      while(1){
        idx=lower_bound(all(pfx),t)-pfx.begin();
        if(idx<K&&pfx[idx]==t)break;
        t=t.substr(1);
      }
      nxtst[i][nxt]=idx;
    }
  }

  ll add=0;
  if(A.size()>=s.size()){
    ull h=0,crct=0,elim=1;
    rep(i,s.size()){
      h*=mod;
      h+=A[i];
      crct*=mod;
      crct+=s[i];
      elim*=mod;
    }
    if(h==crct)(add+=1)%=mod;
    repl(i,s.size(),A.size()){
      h*=mod;
      h+=A[i];
      h-=elim*A[i-s.size()];
      if(h==crct)(add+=1)%=mod;
    }
  }
  cout<<(solve(B)-solve(A)+add+mod)%mod<<endl;

  return 0;
}



Measured memory_bytes: 3372
from itertools import product
n = int(input())
a = list(map(int, input().split()))

ans = 0
for x in product([-1, 0, 1], repeat=n):
    b = [ai + xi for ai, xi in zip(a, x)]
    if any(bi % 2 == 0 for bi in b):
        ans += 1

print(ans)


Measured memory_bytes: 9104
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()
#rのときpの点、sのときｒ、ｐのときｓ

from collections import Counter

taka = ''
ans = 0


for te in t[:k]:
    if te == 'r':
        taka += 'p'
        ans += p
    elif te == 's':
        taka += 'r'
        ans += r
    else:
        taka += 's'
        ans += s

for i in range(k,len(t)):    
    if t[i] == 'r':
        if taka[i-k]!='p':
            taka += 'p'
            ans += p
        else:
            taka += 'q'
    elif t[i] == 's':
        if taka[i-k]!='r':
            taka += 'r'
            ans += r
        else:
            taka += 'q'
    else:
        if taka[i-k]!='s':
            taka += 's'
            ans += s
        else:
            taka += 'q'


print(ans)



Measured memory_bytes: 3564
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }

template<typename T,typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v){ t = v; }

template<typename T,typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(q);
    REP(i, q) cin >> a[i];

    vector<int> ans(n, k-q);
    REP(i, q) ans[a[i]-1]++;
    REP(i, n)
    {
        cout << (ans[i] > 0 ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#define INF INT_MAX

using namespace std;

int N;
int a, b;

int main() {
	cin >> N >> a >> b;
	if (N == 1) {
		cout << "Hello World" << endl;
	}
	else if (N == 2) {
		cout << a + b << endl;
	}

	return 0;
}

Measured memory_bytes: 256
//package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class Main {
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        String s=scan.next();
        int n=s.length();
        int ans=0;
        for(int i=0;i<n/2;i++){
            if(s.charAt(i)!=s.charAt(n-1-i)){
                ans++;
            }
        }
        System.out.println(ans);
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

}


Measured memory_bytes: 24660
<?php
list($A,$B,$C) = explode(" ",trim(fgets(STDIN)));
$K = trim(fgets(STDIN));
for($i=0;$i<$K;$i++){
if($A>$B and $A>$C){
  $A *=2;
}elseif($B>$C){
  $B *=2;
}else{
  $C *=2;
}
}
$ans = $A+$B+$C;
echo $ans;

Measured memory_bytes: 3576
def main():
    n = int(input())
    data = []
    for i in range(n):
        x, l = map(int, input().split())
        data.append([x-l, x+l])
    data.sort(key=lambda x: x[1])

    ans = 1
    min_value = data[0][1]
    for i in range(1, n):
        if min_value <= data[i][0]:
            ans += 1
            min_value = data[i][1]

    print(ans)


main()


Measured memory_bytes: 21336
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, X = map(int, readline().split())
    M = list(int(readline()) for _ in range(N))
    ans = N + (X-sum(M))//min(M)
    print(ans)


if __name__ == '__main__':
    main()


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


void solve(string str)
{
    int n=str.length();
    set<int> a;
    set<int> b;
    int i=0;
    while(str[i]!='\0')
    {
        if(str[i]=='A')
        {
            a.insert(i);
        }
        else if(str[i]=='B')
        {
            b.insert(i);
        }
        i++;
    }
    if(!a.empty() && !b.empty() )
    {
        cout<<"Yes"<<"\n";
    }
    else{
        cout<<"No"<<"\n";
    }


}
int main()
{
    string str;
    cin>>str;;
    solve(str);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
	int n,r;
	cin >> n >> r;
	if (n < 10) r += (10-n)*100;
	cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n + 1];
        for(int i = 1; i <= n; i++) {
            a[i] = i;
        }
        for(int i = 6; i <= n; i *= 6) {
            for(int j = i; j <=n ; j++) {
                a[j] = Math.min(a[j], a[j - i] + 1);
            }
        }
        for(int i = 9; i <= n; i *= 9) {
            for(int j = i; j <=n ; j++) {
                a[j] = Math.min(a[j], a[j - i] + 1);
            }
        }
        System.out.println(a[n]);
    }
}


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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int count = 0;

		for (int ia = 0; ia <= a; ia++) {
			for (int ib = 0; ib <= b; ib++) {
				for (int ic = 0; ic <= c; ic++) {
					if (x == ia * 500 + ib * 100 + ic * 50) {
						count++;
					}
				}
			}
		}

		System.out.println(count);
	}
}

Measured memory_bytes: 21076
//#include<bits/stdc++.h> using namespace std;
#include<iostream>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue> //priority_queue inside queue
#include<deque>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl '\n'
typedef long long ll;
typedef unsigned long long ull;
#define f(i,start,end) for(i=start;i<=end;i++)
#define min_heap priority_queue<int, vector<int>, greater<int> >
#define max_heap priority_queue<int>
#define eb emplace_back

struct Point
{
    ll x, y;
};
/// compare function for sorting the points
bool cmp(Point p1, Point p2)
{
    if(p1.x!=p2.x) return p1.x<p2.x;
    return p1.y<p2.y; //p1.x==p2.x
}

bool isPrime(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        if(n%i==0) return false;
    }
    return true;
} //returns true if prime!

ll sum(ll x)
{
    ll res = 0;
    if(x%2==0){
        res = x/2;
        res *= (x+1);
    }
    else{
        res = (x+1)/2;
        res *= x;
    }
    return res;
}

int binary_search(int a[], int n, int x)
{
    int l = 0, r = n-1, m = 0;
    while(l<=r)
    {
        m = l + (r-l)/2;
        if(a[m]==x) return m;
        if(a[m]>x){ r = m-1; }
        else if(a[m]<x){ l = m+1; }
    }
    return -1;
}
/*
/// Quick Sort ///
int swap(int *a, int *b)
{
    int t = *a;
    *a = *b;
    *b = t;
}
int partition(int arr[], int low, int high)
{
    int pivot = arr[high]; // pivot
    int i = low - 1; // index fixed at -1 for low=0
    
    for(int j=low; j<=high-1; j++)
    {
        if(arr[j]<pivot)
        {
            i++;
            swap(&arr[i], &arr[j]);
        }
    }
    swap(&arr[i+1], &arr[high]);
    return (i+1);
}
int quickSort(int arr[], int low, int high)
{
    if(low<high)
    {
        int pi = partition(arr, low, high);
        
        quickSort(arr, low, pi-1);
        quickSort(arr, pi+1, high);
    }
}
/// Quick Sort ///
*/


int main()
{
    fast;
    //int t=0,tc=0; cin >> tc; f(t,1,tc) //testcases
    {
        int i,j;
        int k,n; cin >> k >> n;
        int a[n]; f(i, 0, n-1) cin >> a[i];
        int ans = a[n-1]-a[0];
        int tmp;
        f(i, 1, n-1)
        {
            tmp = abs(a[i-1]+k-a[i]);
            ans = min(tmp, ans);
        }
        cout << ans << nl;
    }
    return 0;
}

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

xyh = []

for i in range(N):
    x,y,h = map(int, input().split())
    xyh.append([x,y,h])

xyh.sort(reverse=True, key=lambda x: x[2])

for i in range(101):
    for j in range(101):
        px, py, ph = xyh[0]
        H = ph + abs(px-i) + abs(py-j)
        if all(h == max(H-abs(x - i) - abs(y - j),0) for x, y, h in xyh):
            print(i,j,H)
            break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

/*
    1 2 3 2 2 3
*/

int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];

    if (A[0] != 0) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    REP(i, 1, N) {
        if (A[i - 1] + 1 < A[i]) {
            cout << -1 << endl;
            return 0;
        }
        if (A[i - 1] + 1 == A[i]) {
            ans++;
        } else {
            ans += A[i];
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main () {
  char a;
  cin>>a;
  for (char w='A';w<='Z';w++) {
    if (a==w) {
      cout<<"A"<<endl;
    }
  }
  for (char w='a';w<='z';w++) {
    if (a==w) {
      cout<<"a"<<endl;
    }
  }
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 205

const int INF = 1e9+7;

double dp[ARRAY_MAX][ARRAY_MAX];

int main(){

    int n;
    cin >> n;
    vector<int> t(n),v(n);
    for(int i = 0;i < n;i++){
        cin >> t[i];
    }
    for(int i = 0;i < n;i++){
        cin >> v[i];
    }
    dp[0][0] = 1;
    for(int number = 0;number < n;number++){//i番目までで
        for(int v_now = 0;v_now <= 105;v_now++){//現在の速さがjの時
            if(v_now > v[number] || dp[number][v_now] == 0){
                continue;
            }
            for(int v_next = 0;v_next <= 105;v_next++){

                if(v_next > v[number]){
                    continue;
                }
                int a = v[number] - v_now;//加速時間
                int b = v[number] - v_next;//減速時間
                if(t[number] < abs(v_now - v_next)){
                    //遷移できない(加減速が間に合わない)
                    continue;                
                }else if(a + b <= t[number]){
                    double up = 1.0*(v_now + v[number])*a/2;//加速中
                    double stay = v[number]*(t[number]-a-b);//限界速度で走行
                    double down = 1.0 * (v_next + v[number])*b/2;//減速中
                    double len = up + stay + down;//距離の合計
                    dp[number+1][v_next] = max(dp[number+1][v_next],dp[number][v_now] + len);
                
                }else{
                    double x = 1.0 * (t[number] + v_next - v_now)/2;//加速時間
                    double y = 1.0 * (t[number] - v_next + v_now)/2;//減速時間
                    double top = v_now + x;//最高速度


                    double up = 1.0 * (v_now+top)*x/2;//加速
                    double down = 1.0 *(v_next + top)*y/2;//減速(台形の面積)
                    double len = up + down;//距離の合計

                    dp[number+1][v_next] = max(dp[number+1][v_next],dp[number][v_now] + len);
                }
            }
        }
    }
    printf("%.9f\n",dp[n][0]-1);

    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n=0,i,t;
    string s;
    cin>>t>>s;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
        {
            n++;
        }
    }
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main()
{
    ll N;
    map<string, int> all;
    cin >> N;
    ll cnt = 0;
    for (int i = 0; i < N; i++)
    {
        string tmp;
        cin >> tmp;
        if (all.end() == all.find(tmp))
        {
            cnt++;
            all.insert(make_pair(tmp, 0));
        }
    }
    cout << cnt << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    string s, t;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if ('A' <= s[i] && s[i] <= 'Z')
            s[i] += 'a' - 'A';
    }

    while (cin >> t)
    {
        if (t == "END_OF_TEXT")
            break;
        for (int i = 0; i < t.size(); i++)
        {
            if ('A' <= t[i] && t[i] <= 'Z')
                t[i] += 'a' - 'A';
        }

        if (s == t)
            ans++;
    }
    cout << ans << endl;
    return 0;
}



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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;
const int INF = 2e16;
const int MOD = 1e9 + 7;
const int MB = 20;
const int K = 500;
const int maxN = 2e4 + 1;


void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	if (n % 2 || s.substr(0, n / 2) != s.substr(n / 2, s.size())) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
}
	

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}

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

struct d_list{
    int key;
    int prev;
    int next;
};

int main(){
    int top_adress, end_adress, n, a, s_ad, nad=1, count=0;;
    string com;
    
    cin >> n;
    d_list ls[n+1];
    ls[0].key = -5000;
    ls[0].prev = 0;
    ls[0].next = 0;
    top_adress = 0;
    end_adress = 0;
    
    for(int i=0;i<n;i++){
        cin >> com;
        if(com == "insert"){
            cin >> a;
            ls[nad].key = a;
            ls[nad].next = top_adress;
            ls[top_adress].prev = nad;
            ls[nad].prev = 0;
            top_adress = nad;
            nad++;
            count++;
            
        }else if(com == "delete"){
            cin >> a;
            s_ad = top_adress;
            while((s_ad != 0)&&(ls[s_ad].key != a)){
                s_ad = ls[s_ad].next;
            }
            if(s_ad!=0){
                //topとlastだった時の処理やる
                if(s_ad == top_adress){
                    top_adress = ls[s_ad].next;
                    ls[ls[s_ad].next].prev = ls[s_ad].prev;
                }else if(s_ad == end_adress){
                    end_adress == ls[s_ad].prev;
                    ls[ls[s_ad].prev].next = ls[s_ad].next;
                }else{
                    ls[ls[s_ad].prev].next = ls[s_ad].next;
                    ls[ls[s_ad].next].prev = ls[s_ad].prev;

                }
                count--;
                if(count == 0){
                    ls[0].key = -5000;
                    ls[0].prev = 0;
                    ls[0].next = 0;
                    top_adress = 0;
                    end_adress = 0;
                }
            }
            
        }else if(com == "deleteFirst"){
            ls[ls[top_adress].next].prev = 0;
            top_adress = ls[top_adress].next;
            count--;
            if(count == 0){
                ls[0].key = -5000;
                ls[0].prev = 0;
                ls[0].next = 0;
                top_adress = 0;
                end_adress = 0;
            }
        }else if(com == "deleteLast"){
            if(end_adress == 0){
                 ls[ls[end_adress].prev].next = 0;
                end_adress = ls[end_adress].prev;
            }
            
            ls[ls[end_adress].prev].next = 0;
            end_adress = ls[end_adress].prev;
            count--;
            if(count == 0){
                ls[0].key = -5000;
                ls[0].prev = 0;
                ls[0].next = 0;
                top_adress = 0;
                end_adress = 0;
            }
                
        }
    }
    
    cout << ls[top_adress].key;
    a = top_adress;
    while(ls[a].next != 0){
        a = ls[a].next;
        cout << " " << ls[a].key;
    }
    cout << endl;
    
    return 0;
}







Measured memory_bytes: 15988
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A, B;
		A = sc.nextInt();
		B = sc.nextInt();
		System.out.println(Math.max(A + B, Math.max(A - B, A * B)));
	}
}

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

using namespace std;
const int N = 1e6+100;
typedef long long ll;
string s;
int main(){
	int n;
	cin>>n;
	int na,nb,nc;
	na=nb=nc=0;
	int ans=0;
	for(int i=1;i<=n;i++){
		cin>>s;
		int l=s.length();
		for(int j=0;j<l-1;j++){
			if(s[j]=='A'&&s[j+1]=='B') ans++;
		}
		if(s[0]=='B'&&s[l-1]!='A') nb++;
		if(s[0]!='B'&&s[l-1]=='A') na++;
		if(s[0]=='B'&&s[l-1]=='A') nc++;
	}
//	cout<<na<<" "<<nb<<" "<<nc<<endl;
	if(nc){
		ans+=(nc-1);
		if(na) ans++,na--;
		if(nb) ans++,nb--;
		ans+=min(na,nb);
	}
	else{
		if(na&&nb) ans+=min(na,nb);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcount(n)
#define endl '\n'
const ll N=3e4+5,mod=1000000007,bit=60;
signed main()
{
    fast;
    ll pro=1,temp,t,i,j,l,r,n,m,mid,z,k,x,y,rem,carry=0,ind,ans=0,mx=-llinf,mn=llinf,cnt=0,curr=0,prev,next,sum=0,flag=1,i1=-1,i2=-1;
    cin>>x>>y;
    if(x<=9 && y<=9)
    {
    	cout<<x*y<<endl;
    }
    else
    {
    	cout<<-1;
    }
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string>
using namespace std;
int n;
string a[111111];
char s[444444];

struct Node{
	int nex[26],jmp[26];
	int sz, cnt, child, jump;
	bool ed;
};
Node Trie[444444];
int z;

void dfs(int p){
	Trie[p].cnt = 0;
	for(int i=0; i<26; i++){
		int q = Trie[p].nex[i];
		if(q==0)continue;
		dfs(q);
		Trie[p].cnt ++;
		Trie[p].child = Trie[q].child;
		Trie[p].jump = Trie[q].jump + 1;
		if(Trie[q].cnt == 1 && !Trie[q].ed){
			Trie[p].nex[i] = Trie[q].child;
			Trie[p].jmp[i] = Trie[q].jump + 1;
		}
	}
	if(!(Trie[p].cnt == 1 && !Trie[p].ed)){
		Trie[p].child = p;
		Trie[p].jump = 0;
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		scanf("%s",s);
		a[i] = s;
	}
	z=1;
	for(int i=0; i<n; i++){
		int p=1;
		for(int j=0; j<a[i].size(); j++){
			int tmp = a[i][j]-'a';
			Trie[p].sz++;
			if(Trie[p].nex[tmp] == 0){
				Trie[p].nex[tmp] = ++z;
				Trie[p].jmp[tmp] = 1;
			}
			p = Trie[p].nex[tmp];
		}
		Trie[p].sz++;
		Trie[p].ed = true;
	}

	dfs(1);

	int query;
	scanf("%d",&query);
	while(query--){
		int id;
		scanf("%d%s",&id,s);--id;
		int p = 1;
		int res = 1;
		for(int i=0; i < a[id].size(); ){
			int x = a[id][i] - 'a';
			for(int j = 0; s[j] != x + 'a'; j++){
				int to = Trie[p].nex[s[j] - 'a'];
				if(to != 0)
					res += Trie[to].sz;
			}
			if(Trie[p].ed) res ++;
			i += Trie[p].jmp[x];
			p = Trie[p].nex[x];
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 116096