akhauriyash/Code-Regression huggingface dataset:
n=int(input())
arr=[]
for i in range(n):
    a = int(input())
    arr.append( (a,i) )
brr = sorted(arr)
max_num = brr[-1][0]
max_ind = brr[-1][1]
second_num = brr[-2][0]

for i in range(n):
    if i==max_ind:
        print(second_num)
    else:
        print(max_num)


Measured memory_bytes: 33120
n=int(input())

if n==1:
    print(input())
    quit()
    
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)

def lcm(a,b):
    return a*b//gcd(a,b)

ans = int(input())
for i in range(n-1):
    tmp = int(input())
    ans = lcm(tmp,ans)
print(ans)


Measured memory_bytes: 3060
//I love Nanami Chiaki
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline int read(){
	int re=0;char c=getchar();
	while (c<'0' || c>'9') c=getchar();
	while (c>='0' && c<='9') {re=(re<<1)+(re<<3)+c-'0';c=getchar();}
	return re;
}
inline int readc(){
	char c=getchar();
	while (c!='+' && c!='-') c=getchar();
	if (c=='+') return 1;
	return -1;
}
int n;
ll ans=0;
int main(){
	int n=read();
	ans+=read();
	int op,a;
	ll hve=0,add=-1,pre=-1;
	for (int i=1;i<n;i++){
		op=readc();a=read();
		ans+=a;
		if (op==-1){
			if (pre==-1){
				pre=a;
				hve=0;
				continue;
			}
			if (add==-1) add=pre+hve;
			else add=min(add,pre+hve);
			pre+=a;
			hve=0;
		}
		else{
			hve+=a;
		}
	}
	if (pre==-1){
		printf("%lld\n",ans);
		return 0;
	}
	else if (add==-1) ans-=2*pre;
	else ans-=2*add;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define lli long long int
 
lli mx=1000000007;
 
lli dp[2000][2000];
 
int main()
{
    int  h,w;
    ///cout<<dp[1005][1005]<<endl;
    cin>>h>>w;
    string s[h+5];
    for(int i=0;i<h;i++)
    {
        cin>>s[i];
    }
    for(int i=1;i<w;i++)
    {
        if(s[0][i]=='#')
            break;
        else
            dp[0][i]=1;
    }
    for(int i=1;i<h;i++)
    {
        if(s[i][0]=='#')
            break;
        else
            dp[i][0]=1;
    }
    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(s[i][j]!='#')
            dp[i][j]=((dp[i-1][j]%mx)+(dp[i][j-1]%mx))%mx;
        }
    }
    cout<<dp[h-1][w-1];
    return 0;
}

Measured memory_bytes: 17152
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <stack>
 
using namespace std;
 
int main(){
 
    int n,a,b,time,distance[10][10],min_value,min_index;
    int D[10],P[10],tmp_min,tmp_min_index,tmp_sum,count,max_number;
 
    while(true){
        scanf("%d",&n);
        if(n == 0)break;
 
        for(int i = 0; i < 10; i++){
            for(int k = 0; k < 10; k++)distance[i][k] = 2000000000;
        }
 
        max_number = -1;
        for(int i = 0; i < n; i++){
            scanf("%d %d %d",&a,&b,&time);
            distance[a][b] = time;
            distance[b][a] = time;
            max_number = max(max_number,max(a,b));
        }
 
        min_value = 2000000000;
 
        for(int town = 0; town <= max_number; town++){
            for(int i = 0; i <= max_number; i++){
                P[i] = 0;
                D[i] = 2000000000;
            }
 
            for(int i = 0; i <= max_number; i++){
                if(distance[town][i] >= 0){
                    D[i] = distance[town][i];
                }
            }
 
            count = 1;
            P[town] = 1;
            D[town] = 0;
 
            while(count <= max_number){
                tmp_min = 2000000000;
                for(int i = 0; i <= max_number; i++){
                    if(D[i] >= 0 && P[i] == 0 && D[i] < tmp_min){
                        tmp_min = D[i];
                        tmp_min_index = i;
                    }
                }
 
                if(tmp_min == 2000000000)break;
 
                P[tmp_min_index] = 1;
                count++;
 
                for(int k = 0; k <= max_number; k++){
                    if(D[k] > D[tmp_min_index] + distance[tmp_min_index][k]){
                        D[k] = D[tmp_min_index] + distance[tmp_min_index][k];
                    }
                }
            }
 
            tmp_sum = 0;
 
            for(int i = 0; i <= max_number; i++){
                tmp_sum += D[i];
            }
 
            if(tmp_sum < min_value){
                min_value = tmp_sum;
                min_index = town;
            }else if(tmp_sum == min_value && town < min_index){
                min_index = town;
            }
        }
 
        printf("%d %d\n",min_index,min_value);
 
    }
 
    return 0;
}


Measured memory_bytes: 2612
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000003;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};


int main(){
    int n;cin >> n;
    for (int i = 1; i <= 1<<17; i++) {
        if(i * 108 / 100 == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <cmath>
using namespace std;

int main(void) 
{
    int x;
    cin >> x;
    int a = 0, b = 0;
    for (int a = -120; a <= 120; a++)
    {
        int isFound = false;
        for (int b = -120; b <= 120; b++)
        {
            long long n = pow(a, 5) - pow(b, 5);
            if (n == x)
            {
                std::cout << a << " " << b << std::endl;
                isFound = true;
                break;
            }
        }
        if (true == isFound) break;
    }

    return 0;
}

Measured memory_bytes: 4080
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

const int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vector<tuple<string, int, int>> r(n);
    rep(i, n) {
        string s;
        int p;
        cin >> s >> p;
        p = 100 - p;
        r[i] = make_tuple(s, p, i);
    }

    sort(all(r));

    rep(i, n) {
        cout << get<2>(r[i]) + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;
 
int main(){
  using namespace std;
  int x, y, a, b, c;
  cin>>x>>y>>a>>b>>c;
  vector<long long> p(a), q(b), r(c);
  REP(i, a){
    cin>>p[i];
  }
  REP(i, b){
    cin>>q[i];
  }
  REP(i, c){
    cin>>r[i];
  }
  sort(ALL(p), greater<long long>());
  sort(ALL(q), greater<long long>());
  sort(ALL(r));
  priority_queue<long long, vector<long long>, greater<long long>> pq;
  priority_queue<long long, vector<long long>, greater<long long>> qq;
  long long ans = 0;
  REP(i, x){
    pq.push(p[i]);
    ans += p[i];
  }
  REP(i, y){
    qq.push(q[i]);
    ans += q[i];
  }
  REP(i, c){
    long long np = pq.top();
    long long nq = qq.top();
    if(np >= r[i] && nq >= r[i]){
      continue;
    }else if(nq >= r[i]){
      ans += r[i] - np;
      pq.pop();
      pq.push(r[i]);
    }else if(np >= r[i]){
      ans += r[i] - nq;
      qq.pop();
      qq.push(r[i]);
    }else{
      if(np < nq){
        ans += r[i] - np;
        pq.pop();
        pq.push(r[i]);
      }else{
        ans += r[i] - nq;
        qq.pop();
        qq.push(r[i]);
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int m=1000000007;
  vector<int>c(26);
  int n;string s;cin>>n>>s;
  for(int i=0;i<26;i++){
    char a='a'+i;
    c.at(i)=count(s.begin(),s.end(),a);
  }
  long long int x=1;
  for(int i=0;i<26;i++){
    x=x*(c.at(i)+1)%m;
  }
  cout<<(x-1)%m<<endl;
}

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

#undef int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
#define int long long int
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while (t--) {
		long double a, b;
		cin >> a >> b;
		cout << (int)(a * b) << endl;
	}
	return 0;
}

Measured memory_bytes: 3744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String ans = "Yes";
		char[] c = new char[s.length()];

		for(int i=0; i<s.length(); i++) {
			c[i] = s.charAt(i);
		}

		if(s.length() % 2 != 0)
			ans = "No";
		else {
			for(int i=0; i<s.length(); i+=2) {
				if(c[i] != 'h' || c[i+1] != 'i') {
					ans = "No";
					break;
				}
			}
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>
#include<queue>
#define LL long long
using namespace std;
inline int read( )
{
  int sum=0;char c=getchar( );bool f=0;
  while(c<'0'||c>'9') {if(c=='-') f=1;c=getchar( );}
  while(c>='0'&&c<='9') {sum=sum*10+c-'0';c=getchar( );}
  if(f) return -sum;
  return sum;
}
const int N=3005;
int n,a[N];
struct ex{int num,next;}map[N*2];
int head[N],len;
inline void link(int x,int y)
{
  if(a[x]==a[y]) return;
  if(a[x]<a[y]) swap(x,y);
  len++;map[len].num=y;map[len].next=head[x];head[x]=len;
}
bool vis[N];int sg[N],h[N],tim;
inline void dfs(int k)
{
  vis[k]=1;int i,x;
  for(i=head[k];i;i=map[i].next) if(!vis[x=map[i].num]) dfs(x);
  for(i=head[k],++tim;i;i=map[i].next) h[sg[map[i].num]]=tim;
  for(i=0;;i++) if(h[i]!=tim) {sg[k]=i;break;}
}
int main( )
{
  int i,x,y;
  n=read( );
  for(i=1;i<=n;i++) a[i]=read( );
  for(i=1;i<n;i++) x=read( ),y=read( ),link(x,y);
  for(i=1;i<=n;i++) if(!vis[i]) dfs(i);
  for(i=1;i<=n;i++) if(sg[i]) printf("%d ",i);
  return 0;
}

Measured memory_bytes: 384
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let mut ans: f64 = 0.0;
    for i in 0..n {
        ans += 1.0 / a[i] as f64;
    }

    ans = 1.0 / ans;

    return format!("{}", ans);
}


Measured memory_bytes: 2096
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n, k; cin >> n >> k;
	int d = 0;
	while (n > 0)
	{
		++d;
		n /= k;
	}
	cout << d << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while (scanner.hasNext()) {
			int[] map = new int[101];
			while (true) {
				int n = scanner.nextInt();
				int s = scanner.nextInt();
				if (n == 0 && s == 0) {
					break;
				}
				map[n]++;
				map[s]++;
			}
			int count = 0;
			for (int i = 0; i < 101; i++) {
				if (map[i] % 2 == 1) {
					count++;
				}

			}
			if (count != 2) {
				System.out.println("NG");
			} else if (map[1] % 2 == 1 && map[2] % 2 == 1) {
				System.out.println("OK");
			} else {
				System.out.println("NG");
			}
		}
	}
}

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

int main() {

    int N;
    cin >> N;

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

    bool approved = true;
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 == 0) {
            if (A[i] % 3 != 0 && A[i] % 5 != 0) {
                approved = false;
                break;
            }
        }
    }
    cout << ((approved)? "APPROVED": "DENIED") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#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, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    string S;
    cin >> S;

    ll ans = 0, b_count = 0;
    REP(i, S.size()) {
        if (S[i] == 'B') b_count++;
        else             ans += b_count;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main(){
	string in;
	int joi,ioi;
	while(cin>>in){
	ioi=joi=0;
 	for(int i=0;i<in.size()-2;i++){
 		//cout<<in[i]<<in[i+1]<<in[i+2]<<endl;
 	
		if(in[i+0]=='I'&&in[i+1]=='O'&&in[i+2]=='I')ioi++;
		if(in[i+0]=='J'&&in[i+1]=='O'&&in[i+2]=='I')joi++;
			
	}
	cout<<joi<<endl<<ioi<<endl;
	}

}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(){
	string s;
	cin >> s;
	string S;
	for(int i = 0 ; i < s.size() ; i++){
		if( s[i] == 'B' ){
			if( S.size() ) S.pop_back();	
		}else if( s[i] == '1' ) S += "1";
		else S += "0";
	}
	cout << S << endl;
}


Measured memory_bytes: 256
S = str(input())

diff0, diff1 = 0, 0
for i, s in enumerate(S):
  if i%2 == 0:
    if s == '0':
      diff1 += 1
    else:
      diff0 += 1
  else:
    if s == '0':
      diff0 += 1
    else:
      diff1 += 1

ans = min(diff0, diff1)
print(ans)

Measured memory_bytes: 3188
n, m, c = map(int, input().split())
b_list = list(map(int, input().split()))
a_list = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for a in a_list:
    if sum([a[i] * b_list[i] for i in range(m)]) + c > 0:
       ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define var(n) int n; scn(n)
#define F first
#define S second 
#define pb(n) push_back(n)
#define pii pair<int,int> 
const int N=1003;
const ll M=1e9+7;
const ll inf=1e18+5;
ll dp[N][N][9];
// Thanks to LeBron
int main()
{
	int n,m;
	scn(n);scn(m);
	ll a[n][3];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
			lscn(a[i][j]);
	}
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)
		{
			for(int k=0;k<9;k++)
				dp[i][j][k] = -inf;
		}
	}
	for(int i=0;i<9;i++)
		dp[0][0][i] = 0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			for(int mask = 0;mask <=7;mask++)
			{
				dp[i+1][j][mask] = max(dp[i+1][j][mask],dp[i][j][mask]);
				ll here = dp[i][j][mask];
				if(mask&1)
					here+=a[i][0];
				else here-=a[i][0];

				if(mask&2)
				{
					here+=a[i][1];

				}
				else
					here-=a[i][1];

				if(mask&4)
					here+=a[i][2];
				else here-=a[i][2];

				dp[i+1][j+1][mask] = max(dp[i+1][j+1][mask],here);
			}
		}
	}

	ll ans = 0;
	for(int i=0;i<8;i++)
		ans = max(ans,dp[n][m][i]);
	lpri(ans);
	
}

Measured memory_bytes: 71040
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int R = sc.nextInt();
        if(N < 10){
            System.out.println(R + (10-N)*100);
            return;
        }else{
            System.out.println(R);
        }
    }
}

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

int main(){
  bool A[30][30];
  int N,M; cin>>N>>M;
  for(int i=0;i<N;i++){
    int K; cin>>K;
    for(int j=0;j<M;j++) A[i][j]=false;
    for(int j=0;j<K;j++){
      int a; cin>>a;
      A[i][a-1]=true;
    }
  }
  int sum=0;
  for(int j=0;j<M;j++){
    bool flag = true;
    for(int i=0;i<N;i++){
      if(!A[i][j]) flag=false;
    }
    if(flag) sum++;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int h = Integer.parseInt(in.next());
            int w = Integer.parseInt(in.next());

            for (int i = 0; i < h; i++) {
                String tmp = in.next();
                out.println(tmp);
                out.println(tmp);
            }
        }

    }
}



Measured memory_bytes: 22100
using System;
using System.Collections.Generic;
using System.Linq;

class WithIndex<T>
{
    public T Value;
    public int Index;
    public WithIndex(T value, int index)
    {
        this.Value = value;
        this.Index = index;
    }
}

static class Template
{
    public static int LineToInt()
    {
        return int.Parse(Console.ReadLine());
    }

    public static string[] LineToStrings()
    {
        return Console.ReadLine().Split();
    }

    public static int[] LineToInts()
    {
        return LineToStrings()
            .Select(s => int.Parse(s))
            .ToArray();
    }


    public static int[,] LinesToIntTable(int lineCount, int columnCount)
    {
        var value = new int[lineCount, columnCount];
        foreach (var y in Enumerable.Range(0, lineCount))
        {
            var ints = LineToInts();
            foreach (var x in Enumerable.Range(0, columnCount))
            {
                value[y, x] = ints[x];
            }
        }
        return value;
    }

    public static IEnumerable<WithIndex<T>> WithIndex<T>(this IEnumerable<T> sequence)
    {
        int index = 0;
        foreach (var item in sequence)
        {
            yield return new WithIndex<T>(item, index);
            index++;
        }
    }

    static void Main(string[] args)
    {
        var townCount = LineToInt() + 1;
        var braveCount = townCount - 1;
        var osou = LineToInts().Select(x=>(long)x).ToArray();
        var beatable = LineToInts().Select(x=>(long)x).ToArray();
        var beatCount = 0L;
        foreach (var i in Enumerable.Range(0, braveCount))
        {
            var tempBeat = Math.Min(osou[i], beatable[i]);
            osou[i] -= tempBeat;
            beatable[i] -= tempBeat;
            beatCount += tempBeat;
            var tempBeat2 = Math.Min(osou[i + 1], beatable[i]);
            osou[i + 1] -= tempBeat2;
            beatable[i] -= tempBeat;
            beatCount += tempBeat2;
        }
        Console.WriteLine(beatCount);
    }
}



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

int main(){
    int n;
    cin>>n;
    vector<int> dp(3);
    
    for(int day=0; day<n; ++day){
        vector<int> A(3);
        cin>>A[0]>>A[1]>>A[2];
        vector<int> dp_new(3,0);
        for(auto j : {0,1,2}){
            for(auto k : {0,1,2}){
                if(j!=k){
                    dp_new[k]=max(dp_new[k], dp[j]+A[k]);
                }
            }
        }
        dp=dp_new;
    }
    cout<<max({dp[0],dp[1],dp[2]})<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <deque>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {

	int a;
	cin >> a;
	cout << 3 * a * a << endl;

	return 0;
}

Measured memory_bytes: 256
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let S = (read string).ToCharArray()
    let N = S.Length

    let rs =
        let a = Array.create S.Length 0
        let mutable c = 0
        for i in [0 .. N-1] do
            if S.[i] = 'L' then
                a.[i] <- c
                c <- 0
            else
                c <- c + 1
        a
    let ls =
        let a = Array.create S.Length 0
        let mutable c = 0
        for i in [N-1 .. -1 .. 0] do
            if S.[i] = 'R' then
                a.[i] <- c
                c <- 0
            else
                c <- c + 1
        a
    let ans =
        let d = Array.create N 0
        for i in [0 .. N-1] do
            if ls.[i] <> 0 then
                let l = ls.[i]
                let r = rs.[i+1]
                if (l + r) % 2 = 0 then
                    d.[i] <- (l + r) / 2
                    d.[i+1] <- (l + r) / 2
                else
                    let m = (l + r) / 2
                    if l % 2 = 0 then
                        d.[i] <- m + 1
                        d.[i+1] <- m
                    else
                        d.[i] <- m
                        d.[i+1] <- m + 1
        d
    // eprintfn "*%A" rs
    // eprintfn "*%A" ls
    // eprintfn "*%A" ans
    String.Join(" ", ans)
    |> printfn "%s"
    0

Measured memory_bytes: 31316
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
    
int main()
{
	double p1x, p1y, p2x, p2y, l;
	cin >> p1x >> p1y >> p2x >> p2y;
	l = pow((p2x-p1x),2)+pow((p2y-p1y),2);
	l = sqrt(l);
	cout << fixed << setprecision(4) <<l << endl;
	return 0;
}

Measured memory_bytes: 3256
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

check :: [Int] -> [Int] -> Bool
check xs ys = (foldl (\x (y,y') -> x + (y-y')^2) 0 (zip xs ys)) == (((^2) . floor . sqrt . fromIntegral) $ foldl (\x (y,y') -> x + (y-y')^2) 0 (zip xs ys))

main :: IO ()
main = do
  [l,r] <- map read.words <$> getLine :: IO [Int]
  if r-l > 2019 then print 0
    else print $ minimum [ (i*j) `mod` 2019 | i <- [l,l+1..r], j <- [l,l+1..r], i < j]
  


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

int main()
{
  long long A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  
  long long ans;
  if (A + B <= 2 * C) ans = X * A + Y * B;
  else 
  {
    if (X == Y) ans = X * (2 * C);
    else if (X > Y) ans = Y * (2 * C) + (X - Y) * min(A, 2 * C);
    else ans = X * (2 * C) + (Y - X) * min(B, 2 * C);
  }
  
  cout << ans << endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n,k;
  cin >> n >> k;
  vector<pair<int,int>> id;
  int r = sqrt(n);
  repp(i,1,r+1){
    id.push_back({i,1});
  }
  if(r==n/r){
    perr(i,1,r){
      id.push_back({n/i,n/i-n/(i+1)});
    }
  }else{
    perr(i,1,r+1){
      id.push_back({n/i,n/i-n/(i+1)});
    }
  }
  int m = id.size();
  vector<int> nx(m);
  rep(i,m){
    nx[i]=upper_bound(all(id),pair<int,int>(n/id[i].first,IINF))-id.begin()-1;
  }
  vector<LL> dp(m,0),ndp;
  rep(i,m){
    dp[i]=id[i].second;
  }
  repp(i,1,m){
    dp[i]=(dp[i]+dp[i-1])%MOD;
  }
  rep(t,k-1){
    ndp=vector<LL>(m,0);
    rep(i,m){
      ndp[i]=dp[nx[i]]*id[i].second%MOD;
    }
    dp=ndp;
    repp(i,1,m){
      dp[i]=(dp[i]+dp[i-1])%MOD;
    }
  }
  cout << dp[m-1] << endl;
  return 0;
}


Measured memory_bytes: 2456
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 100)
	sc.Buffer(buf, 1000000)
	sc.Scan()
	length, _ := strconv.Atoi(sc.Text())

	sc.Scan()
	inputs := strings.Split(sc.Text(), " ")
	lastValue, _ := strconv.Atoi(inputs[length-1])

	sc.Scan()
	for sc.Scan() {
		q, _ := strconv.Atoi(sc.Text())
		if q > lastValue {
			fmt.Println(0)
			continue
		}

		low := 0
		high := length - 1
		for {
			mid := (low + high) / 2
			midValue, _ := strconv.Atoi(inputs[mid])
			// fmt.Println(q, midValue)
			if q > midValue {
				low = mid + 1
			} else if q < midValue {
				high = mid - 1
			} else {
				fmt.Println(1)
				break
			}

			if low > high {
				fmt.Println(0)
				break
			}
		}
	}
}



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

int main() {
    int n, cnt=0;
    bool ok = true;
    cin >> n;
    REP(i,n){
        string p;
        int x;
        cin >> p >> x;
        if(p=="(") cnt += x;
        else cnt -= x;
        ok &= cnt >= 0;
    }
    ok &= cnt == 0;
    cout << (ok?"YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 3172
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())

ac = [0] * n
pena = [0] * n
wa = [0] * n

for i in range(m):
    p, s = readline().decode().rstrip().split()
    if ac[int(p) - 1] == 0:
        if s == 'AC':
            ac[int(p) - 1] += 1
            pena[int(p) - 1] += wa[int(p) - 1]
        else:
            wa[int(p) - 1] += 1

print(sum(ac), sum(pena))


Measured memory_bytes: 5364
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
    ll n;
    cin >> n;
    vector<double>v(n);
    for(ll i = 0; i < n; i ++)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    double ans = v[0];
    for(ll i = 1; i < n; i ++)
    {
        ans = (ans + v[i]) / 2;
    }
    cout << ans;
}


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

using ll = long long;
#define f(i,a,b) for (int i = a; i < b; i++)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
  	int n; cin >> n;
 	int a[n];
  f(i,0,n) cin>>a[i];
  	map<ll,int> freq;
  	freq[0] = 1;
  	ll s = 0;
  	ll ans = 0;
  	f(i,0,n) {
    	s += a[i];
      	ans += freq[s]++;
    }
  	cout << ans << endl;
  return 0;
}

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

int main() {
   int X,N;
   cin >> X >> N;
   int P[N];
   for (int i=0; i<N; i++) {
       cin >> P[i];
   }
   int a[102];
   for (int i=0; i<102; i++) {
       bool b=true;
       for (int j=0; j<N; j++) {
           if (i==P[j]) {
               a[i]=-1;b=false;break;
           }
       }
       if (b) a[i]=i;
   }
   int count=200;
   int c=-1;
   for (int i=0; i<102; i++) {
       if (a[i]>=0) {
           if (count>abs(X-a[i])) {
               count=abs(X-a[i]);
               c=a[i];
           }
           if (count==abs(X-a[i])) c=min(c,a[i]);
       }
   }
   cout << c << endl;
}

Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
  void Solve()
  {
    var N = ToInts()[0];
    Console.WriteLine((long)N*(N-1)/2); ;
  }
  static int[] ToInts()
  {
    var ss = Console.ReadLine().Split();
    var ret = new /**/int[ss.Length];
    for (int i=0;i<ss.Length ;i++)
    {
      ret[i] = /**/int.Parse(ss[i]);
    }
    return ret;
  }

  static void Main(string[] args)
  {
    new Program().Solve();
  }
}



Measured memory_bytes: 13140
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

ll lcm (ll a, ll b){
  ll x = a*b;
  if(a<b){
    ll tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return x/b;
}
ll helper(ll A, ll C, ll D){
  // A以下の整数でC, D で割り切れる数
  ll c = A/C;
  ll d = A/D;
  ll cd = A/lcm(C,D);
  return A-(c + d - cd);
}
// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll ans = helper(B,C,D) - helper(A-1,C,D);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define mp(x,y)          make_pair(x,y)
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto& i: a)
#define loop(n,i,a)      for(int i=a;i<n;i++)
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        loop(n,i,0){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define pp               pop_back
#define endl              "\n"
#define copy(a,b)         copy(all(a),back_inserter(b));
#define intersect(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
//int m=10000009;
//int arr[100000];
#define M                   1000000007
#define mm  998244353  
//set<int> st;
signed main()
{
    fast
    int l;
    cin>>l;
    cout << setprecision(20) << (l*1.0/3)*(l*1.0/3)*(l*1.0/3);
}

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

int main()
{
    string s;
    cin >> s;
    map<char, int> mp;
    rep(i, 0, s.size()){
        mp[s[i]]++;
    }
    for(char i = 'a'; i <= 'z'; i++){
        if(mp[i]%2){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();

        out.println(solve(in.longNext()));

        out.close();
    }

    static long solve(long health) {
        if (health == 1) return health;
        int power = 0;
        while (health > 0) {
            health = health / 2;
            power++;
        }
        return binpow(2, power) - 1;
    }

    static long binpow(long a, long b) {
        long res = 1;
        while (b > 0) {
            if (b % 2 == 1) res = res * a;
            a = a * a;
            b /= 2; // or: b >>= 1;
        }
        return res;
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

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

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

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

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

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

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

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

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


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


constexpr int MOD = 1e9 + 7;

int n, cnt[50];
string s;

signed main() {
    cin >> n >> s;

    for (char c : s) {
        cnt[c - 'a']++;
    }

    int ans = 1;
    for (int i = 0; i <= 'z' - 'a'; i++) {
        ans *= cnt[i] + 1;
        ans %= MOD;
    }
    ans--;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a,b;
	cin>>a>>b;
	if ((a=="H" && b=="H") || (a=="D" && b=="D")){
	    cout<<"H";
	}
	else{
	    cout<<"D";
	}
	return 0;
}


Measured memory_bytes: 3460
n=int(input())
a=list(map(int,input().split()))
cnt=[0]*(10**5)
ans=sum(a)
for i in a:
  cnt[i-1]+=1
q=int(input())
bc=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
  ans+=(cnt[bc[i][0]-1]*(bc[i][1]-bc[i][0]))
  print(ans)
  cnt[bc[i][1]-1]+=cnt[bc[i][0]-1]
  cnt[bc[i][0]-1]=0

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

int main() {
    int n;
    cin >> n;
    
    string S;
    cin >> S;
    
    int d = 0, r = 0;
    for (char ch : S) {
        if (ch == 'I') ++d;
        if (ch == 'D') --d;
        r = max(r, d);
    }
    
    cout << r << endl;
}

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


int main(){
  int s,t,cnt=2;
  set<int> r;
  cin>>s;
  t=s;
  r.insert(t);
  while(1){
  	if(t%2) t=3*t+1;
    else t/=2;
    if(r.find(t) != r.end()) break;
    r.insert(t);
    cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
    "fmt"
    "sort"
)

func gcd(x,y int) int{
	if x%y==0 {
		return y
	}
	return gcd(y,x%y)
}

func main() {
    // var n int
    // fmt.Scan(&n, &x)
    // nums := make([]int,n)
    // m := make(map[int]int)

    var n,k int
    fmt.Scan(&n,&k)
    d := make([]int,n)

    for i := 0; i < n; i++ {
    	fmt.Scan(&d[i])
    }
    sort.Ints(d)
    g := d[n-1]

    if g<k {
		fmt.Println("IMPOSSIBLE")
		return	
    }

    for i := 1; i < n; i++ {
    	g = gcd(g,d[i])
    }

    if k%g==0 {	
		fmt.Println("POSSIBLE")
    } else {
		fmt.Println("IMPOSSIBLE")
    }

}

Measured memory_bytes: 5504
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto nab = readints;
    int n = nab[0], a = nab[1], b = nab[2];

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int s = 0;
        int x = i;
        while (x > 0) {
            s += x % 10;
            x /= 10;
        }
        if (a <= s && s <= b) ans += i;
    }
    writeln(ans);
}


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


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n, dp[5100][5100];
string s;
int main() {
	cin >> n >> s;
	REP(i, n) {
		REP(j, n) {
			if (s[i] == s[j] and dp[i][j] + 1 <= j - i) dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j + 1]);
		}
	}
	ll ans = 0;
	REP(i, n + 1) {
		REP(j, n + 1) {
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
}




Measured memory_bytes: 200960
using System;
class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        string ans = "";
        for(int i=0;i<s.Length;i++)
        {
            if(i%2==0)
            {
                ans += s.Substring(i,1);
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 34772
#include <iostream>
#include <vector>
#include <algorithm>
#include <cctype>
#include <stack>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

const long long MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    bool valid = false;
    int count = 0;
    while(n--){
        int x,y;
        cin >> x >> y;
        if(x == y){
            count++;
        }else{
            count=0;
        }
        if(count == 3){
            valid = true;
        }
    }
    if(valid){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pb push_back
#define tam 520004
#define offset 320000
#define se second
#define fi first
#define pitem item*
#define ptr tre*
#define forr(i,p,n) for(int i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1000000007 ;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<ll,ll> ii;
typedef pair<ll,ii> iii;
typedef pair<double,double> pt;
ll pos[tam];
int main()
{
    ll n,T;
    cin>>n>>T;
    forr(i,0,n)
    {
        cin>>pos[i];
    }
    ll res=T;
    ll tot=0;
    forr(i,1,n)
    {
        tot+=min(pos[i]-pos[i-1],res);
        res=T;
    }
    tot+=res;
    cout<<tot<<endl;
    
}

Measured memory_bytes: 1792
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

char cn[300100], * ci = cn, ct;
int N, A, B, C;

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

	fread(cn, 1, 300100, stdin);
	while ((ct = *ci++) >= '0') N = N * 10 + ct - '0';
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	while ((ct = *ci++) >= '0') B = B * 10 + ct - '0';
	while ((ct = *ci++) >= '0') C = C * 10 + ct - '0';

	int kei = A + B + C;
	

	int OK = 1;
	char *di = cn;

	char* S = ci;

	for (int i = 0; i < 3 * N; i += 3) {
		if (S[i] == 'B') {
			if (C == 0 && B == 0) OK = 0;
			if (C == 1 && B == 1) {
				if (i == 3 * N - 3 || S[i + 4] == 'C') {
					*di++ = 'C';
					*di++ = '\n';
					C++;
					B--;
				}
				else {
					*di++ = 'B';
					*di++ = '\n';
					B++;
					C--;
				}
			}
			else if (C <= B) {
				*di++ = 'C';
				*di++ = '\n';
				C++;
				B--;
			}
			else {
				*di++ = 'B';
				*di++ = '\n';
				B++;
				C--;
			}
		}
		else if (S[i + 1] == 'B') {
			if (A == 0 && B == 0) OK = 0;
			if (A == 1 && B == 1) {
				if (i == 3 * N - 3 || S[i + 3] == 'A') {
					*di++ = 'A';
					*di++ = '\n';
					A++;
					B--;
				}
				else {
					*di++ = 'B';
					*di++ = '\n';
					B++;
					A--;
				}
			}
			else if (A <= B) {
				*di++ = 'A';
				*di++ = '\n';
				A++;
				B--;
			}
			else {
				*di++ = 'B';
				*di++ = '\n';
				B++;
				A--;
			}
		}
		else {
			if (A == 0 && C == 0) OK = 0;
			if (A == 1 && C == 1) {
				if (i == 3 * N - 3 || S[i + 4] == 'C') {
					*di++ = 'C';
					*di++ = '\n';
					C++;
					A--;
				}
				else {
					*di++ = 'A';
					*di++ = '\n';
					A++;
					C--;
				}
			}
			else if (A <= C) {
				*di++ = 'A';
				*di++ = '\n';
				A++;
				C--;
			}
			else {
				*di++ = 'C';
				*di++ = '\n';
				C++;
				A--;
			}
		}
	}
	if (OK) {
		printf("Yes\n");
		fwrite(cn, 1, di - cn, stdout);
	}
	else printf("No\n");

	Would you please return 0;
}

Measured memory_bytes: 1788
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,v,x[SZ],a[SZ],k=0;
vector<int> gu[55];
int L[1234567],R[1234567],mx[1234567];
int main()
{
	scanf("%d%d",&n,&v);
	for(int i=1;i<=n;++i) scanf("%d",x+i);
	for(int i=n;i>=2;--i) x[i]-=x[i-1];
	a[k++]=v; while(a[k-1]) a[k]=a[k-1]/2,++k;
	for(int i=0;i<k;++i)
	{
		gu[i].pb(1);
		for(int j=2;j<=n;++j)
			if(x[j]>a[i]) gu[i].pb(j);
		gu[i].pb(n+1);
	}
	for(int i=2;i<(1<<k);i+=2)
	{
		for(int r=1;r<k;++r) if(i&(1<<r))
		{
			int cl=L[i^(1<<r)];
			if(cl!=n) cl=(*lower_bound(
			gu[r].begin(),gu[r].end(),cl+2))-1; 
			L[i]=max(L[i],cl);
		}
	}
	for(int i=0;i<(1<<k);i++) R[i]=n+1;
	for(int i=2;i<(1<<k);i+=2)
	{
		for(int r=1;r<k;++r) if(i&(1<<r))
		{
			int cr=R[i^(1<<r)];
			if(cr!=1) cr=(*(upper_bound(
			gu[r].begin(),gu[r].end(),cr-1)-1));
			R[i]=min(R[i],cr);
		}
	}
	for(int i=0;i<=n;++i) mx[i]=-1;
	for(int i=0;i<(1<<k);i+=2)
		mx[R[i]]=max(mx[R[i]],L[((1<<k)-2)^i]);
	for(int i=1;i<=n;++i)
		mx[i]=max(mx[i],mx[i-1]);
	for(int i=1;i<=n;++i)
	{
		int L=*(upper_bound(gu[0].begin(),gu[0].end(),i)-1),
		R=(*lower_bound(gu[0].begin(),gu[0].end(),i+1))-1;
		if(mx[R+1]>=L-1) puts("Possible");
		else puts("Impossible");
	}
}


Measured memory_bytes: 17140