akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.NoSuchElementException;

public class Main {
	final int MOD = (int)1e9 + 7;
	int N;
	int[] T,A,M;
	long[] dp;

	public int lower(int[] B){
		int n = B.length;
		int max = 0;
		for(int i = 0;i < n;i++){
			max = Math.max(B[i],max);
		}
		for(int i = 0; i < n;i++){
			if(max == B[i]){
				return i;
			}
		}
		return -1;
	}

	public int upper(int[] B){
		int n = B.length;
		int max = 0;
		for(int i = n - 1;i >= 0;i--){
			max = Math.max(B[i],max);
		}
		for(int i = n - 1; i >= 0;i--){
			if(max == B[i]){
				return i;
			}
		}
		return -1;
	}

	public void solve() {
		N = nextInt();
		A = new int[N];
		T = new int[N];
		M = new int[N];
		dp = new long[N + 1];
		for(int i = 0;i < N;i++){
			T[i] = nextInt();
		}
		for(int i = 0;i < N;i++){
			A[i] = nextInt();
		}

		for(int i = 0;i < N;i++){
			M[i] = Math.min(T[i],A[i]);
		}
		int lower = lower(T);
		int upper = upper(A);

		if(T[lower] != A[upper] || lower > upper){
			out.println(0);
			return;
		}
		boolean[] unique = new boolean[N];
		HashSet<Integer> set = new HashSet<Integer>();
		for(int i = 0;i < N;i++){
			if(!set.contains(T[i])){
				unique[i] = true;
			}
			set.add(T[i]);
		}
		set.clear();
		for(int i = N - 1;i >= 0;i--){
			if(!set.contains(A[i])){
				unique[i] = true;
			}
			set.add(A[i]);
		}
		dp[0] = 1;

		for(int i = 0;i < N;i++){
			if(unique[i]){
				dp[i + 1] = dp[i] % MOD;
			}else{
				dp[i + 1] = dp[i] % MOD * M[i] % MOD;
			}
			dp[i + 1] %= MOD;
		}

		out.println(dp[N]);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

Measured memory_bytes: 32008
#include <bits/stdc++.h>
#include <time.h>
#include <assert.h>


using namespace std;



#define For(i,x,n)  for(long long i=x;i<n;i++)
#define rFor(i,x,n) for(long long i=x;i>=n;i--)
#define itFor(it,st)   for(auto it=st.begin() ; it!=st.end() ; it++)
#define MOD 1000000007
#define PI 3.141592653589793
#define INF 999999999999999999
#define N 1000005
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sp " "
#define cont continue
#define brk break

#define deb1(x)                cout<<#x<<": "<<x<<endl
#define deb2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define deb3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define deb4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define deb5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define deb6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed;
    cout<<setprecision(3);
    srand(time(NULL));

    ll n;
    cin>>n;
    ll a[n];
    ll mx = -1;
    For(i,0,n){
        cin>>a[i];
        mx = max(mx,a[i]);
    }
    ll arr[mx+10]={0};
    For(j,0,n){
        for(ll i=a[j] ; i<=mx ; i+=a[j])
            arr[i]++;
    }
    ll cnt = 0;
    // For(i,0,mx+1){
    //     deb2(i,arr[i]);
    // }
    For(i,0,n){
        if(arr[a[i]]==1)
            cnt++;
    }
    cout<<cnt;

    //cout<<"\nTime used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case
    return 0;
}

//s1.substr(1,3) - return 3 characters starting from position 1 as substring of string sz1. eg sz1="shreynumh" sz1.substr(2,5)="reyan"
//num = atoi(s.c_str()); //convert string s to integer num
//n.erase(i,std::string::npos); //erase i th position in string n , decreasing string size
//s.find(b)!= std::string::npos - finds string b in string a - true if found
//cout<<"Time used = "<<static_cast<double>(clock())/(CLOCKS_PER_SEC)<<"s"<<endl;  // - for checking time used for a test case                


Measured memory_bytes: 13012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){a=b; return true;}
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){a=b; return true;}
    return false;
}

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(all(par),0);
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    bool merge(int x, int y){
        x=root(x),y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    int size(int x){
        return rank[root(x)];
    }
    int count(){
        return num;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M; cin >> N >> M;
    UnionFind uf(2*N);
    rep(i,M){
        int u,v; cin >> u >> v; --u,--v;
        uf.merge(u,v+N);
        uf.merge(u+N,v);
    }
    ll a=0,b=0,c=0;
    set<int> s;
    rep(i,N){
        if (uf.size(i)>1){
            ++a;
            int p=uf.root(i),q=uf.root(i+N);
            if (!s.count(p)){
                if (p!=q) ++b;
                else ++c;
                s.insert(p),s.insert(q);
            }
        }
    }
    cout << N*N-a*a+(b+c)*(b+c)+b*b << endl;
}

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

int main() {
	int n; cin>>n;
	vector<int>v(n); for(int i=0;i<n;i++)cin>>v[i];
	vector<int>c(n); for(int i=0;i<n;i++)cin>>c[i];
	int ret=0;
	for(int i=0;i<n;i++)ret+=max(0,v[i]-c[i]);
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
 main()
{
    char arr[5];
    cin >> arr;
    if((arr[0]==arr[1])&&(arr[1]==arr[2])&&(arr[2]==arr[3]))
    {
        cout << "No";
    }
   else if(((arr[0]==arr[1])&&(arr[2]==arr[3]))||((arr[0]==arr[2])&&(arr[1]==arr[3]))||((arr[0]==arr[3])&&(arr[1]==arr[2])))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

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

int n, k;

int f(int x) {
	if (n - x < 0) return 0;
	return (n - x) / k + 1 - (x == 0);
}

signed main() {
	cin >> n >> k;
	
	int x, ans = 0;
	for (x = 0; x < k; x++) {
		int y = (k - x) % k;
		int z = x;
		if ((x + z) % k != 0) continue;
		ans += f(x) * f(y) * f(z);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};

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

    int N = s.size();
    if((N%2==0)^(s[0]==s[N-1])){
        cout << "Second"<<endl;
    }else{
        cout << "First" << endl;
    }
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  string s; cin >> s;
  int n = (int)s.size();
  int cnt = 0;
  int l = 0, r = n-1;
  while(l < r){
    if(s[l] != s[r])cnt++;
    l++;
    r--;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < 110; i++) {
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
		s = s[s.size() - 1] + s.substr(0, s.size() - 1);
	}
	cout << "No" << endl;
	return 0;
}


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

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

#define rep(i,n) for (ll i = 0; i < (n); i++)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;

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

	int p = 0;
	p += 1000 * (x / 500);
	x -= (x / 500) * 500;

	p += 5 * (x / 5);
	x -= (x / 5) * 5;

	cout << p << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define P pair<long long , long long >

using namespace std;
const long long MOD=1e9+7;

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

long long modpow(long long a, long long n, long long mod){
  long long ret = 1;
  while(n>0){
    if(n&1)ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}

int main(){
  long long n, a[200009], b[200009], ans=1;
  cin >> n;
  for(int i=0;i<n;i++)cin >> a[i] >> b[i];

  map<P, long long> m;
  for(int i=0;i<n;i++){
    long long _gcd = gcd(abs(a[i]), abs(b[i]));
    if(a[i]==0 && b[i]==0)continue;
    else if(b[i]==0)m[P(-1,0)]++;
    else if(a[i]==0)m[P(0,1)]++;
    else if(b[i]>0){
      m[P(a[i]/_gcd, b[i]/_gcd)]++;
    }
    else if(b[i]<0){
      m[P(-a[i]/_gcd, -b[i]/_gcd)]++;
    }
  }
  for(auto itr=m.begin();itr!=m.end();itr++){
    long long r1 = itr->first.first;
    long long n1 = itr->first.second;
    long long r2, n2;
    if(r1<0){
      r2 = -r1;
      n2 = n1;
    }
    else {
      r2 = r1;
      n2 = -n1;
    }
    long long m1 = itr->second;
    long long m2 = m[P(n2, r2)];
    m[P(r1, n1)] = 0;
    m[P(n2, r2)]=0;
    ans = (((modpow(2, m1, MOD)-1 + modpow(2, m2, MOD)-1 + 1)%MOD) * ans)%MOD;
  }
  
  long long zero = 0;
  for(int i=0;i<n;i++){
    if(a[i]==0 && b[i]==0){
      zero++;
    }
  }
  ans = (ans + zero) % MOD;
  ans = (ans -1 + MOD) % MOD;
  cout <<ans << endl;
}



Measured memory_bytes: 31560
N, M = map(int, input().split())
red = [False] * N
red[0] = True
balls = [1] * N
for i in range(M):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if red[x]:
        if balls[x] == 1:
            red[x] = False
        red[y] = True
    balls[x] -= 1
    balls[y] += 1
print(sum(red))


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main()
{
    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C));
    rep(i, C)
    {
        rep(j, C)
        {
            cin >> D[i][j];
        }
    }
    vector<vector<int>> c(N, vector<int>(N));
    rep(i, N)
    {
        rep(j, N)
        {
            cin >> c[i][j];
            c[i][j]--;
        }
    }

    vector<vector<int>> v(3);
    rep(i, N)
    {
        rep(j, N)
        {
            v[(i + j + 2) % 3].push_back(c[i][j]);
        }
    }
    int ans = INF;
    vector<vector<int>> cost(3, vector<int>(C));
    rep(i, 3)
    {
        rep(j, v[i].size())
        {
            rep(k, C)
            {
                cost[i][k] += D[v[i][j]][k];
            }
        }
    }
    vector<vector<pair<int, int>>> tmp(3);
    rep(i, 3)
    {
        rep(j, C) tmp[i].push_back({cost[i][j], j});
        sort(tmp[i].begin(), tmp[i].end());
    }
    rep(i, 3)
    {
        rep(j, 3)
        {
            rep(k, 3)
            {
                if (tmp[0][i].second == tmp[1][j].second || tmp[0][i].second == tmp[2][k].second || tmp[2][k].second == tmp[1][j].second)
                    continue;
                ans = min(ans, tmp[0][i].first + tmp[1][j].first + tmp[2][k].first);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2428
#include <iostream>
#include <math.h>

using namespace std;

int debt = 100000;

int main() {
    int n;

    cin >> n;

    for (int i = 0; i < n; i++) {
        debt = ceil(debt * 1.05 / 1000) * 1000;
    }

    cout << debt << endl;

    return 0;
}

Measured memory_bytes: 1164
N = int(input())
A = list(map(int, input().split()))

A = sorted([(val, pos) for pos, val in enumerate(A)], reverse=True)

dp = [0]
for i, (val, pos) in enumerate(A):
    ldp = [e + val * abs(pos - (i - r)) for r, e in enumerate(dp)]
    rdp = [e + val * abs(N - 1 - r - pos) for r, e in enumerate(dp)]
    dp = [max(L, R) for L, R in zip(ldp + [0], [0] + rdp)]

print(max(dp))


Measured memory_bytes: 9712
#include <stdio.h>

int main(void)
{
	int n;
	char a[200001] = { 0 };

	scanf("%s", a);
	int sum = 0;

	for (int i = 0; i < 200001; ++i)
	{
		if (a[i] == '\0')
		{
			break;
		}
		sum = sum + (a[i] - 48);
	}
	if (sum % 9 == 0)
	{
		printf("Yes\n");
		
	}
	else
	{
		printf("No\n");
	}
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    ll t = 0;
    cin >> t;
    if (t >= k) ++ans;
  }

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

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

typedef long long int LL;
#define REP(n) for(LL i = 0; i < (n); i++)
#define COUT(val) cout << (val) << endl
#define CIN(val) cin >> (val)
#define SORT(vec) sort(vec.begin(), vec.end())
#define SORT_GRE(vec) sort(vec.begin(), vec.end(), greater<LL>())

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    int ans = 0;
    vector<int> copy = h;
    SORT(copy);
    ans = copy[0];
    for(int i = 0; i < n; i++){
        h[i] -= copy[0];
    }
    bool allZero;
    int c;
    int begin, end;
    while(1){
        allZero = true;
        for(int i = 0; i < n; i++){
            if(h[i] != 0) allZero = false;
        }
        if(allZero) break;
        c = 0;
        for(int i = 0; i < n; i++){
            if(h[i] == 0 && c == 1){
                c++;
                end = i;
                break;
            }
            if(h[i] != 0 && c == 0){
                c++;
                begin = i;
            }
        }
        if(c < 2) end = n;
        copy.clear();
        for(int i = begin; i < end; i++){
            copy.push_back(h[i]);
        }
        SORT(copy);
        ans += copy[0];
        for(int i = begin; i < end; i++){
            h[i] -= copy[0];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
a,b,m=gets.split.map(&:to_i)
a,b=gets.split.map(&:to_i),gets.split.map(&:to_i)
m.times{($mm||=[])<<a[(i=gets.split.map(&:to_i))[0]-1]+b[i[1]-1]-i[2]}
p [$mm.min,a.min+b.min].min

Measured memory_bytes: 21276
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 D = sc.nextInt();
		int S = A * B, M = C * D;
		if(A * B < C * D){
			System.out.println(M);
		}
		else if(A * B > C * D){
			System.out.println(S);
		}
		else if(A * B == C * D){
			System.out.println(S);
		}	
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
//Remove below header file if c++ version greater than 14
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define ll long long int
#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)

using namespace std;
using mii=map<int, int>;
using mll=map<ll, ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int mod = 1000000007;

ll desc(ll x, ll y)
{
    return x > y;
}

int main() {
    fastIO
    ll a, b;
    cin >> a >> b;
    ll temp1 = a + b;
    ll temp2 = a - b;
    ll temp3 = a * b;

    if(temp1 >= temp2 && temp1 >= temp3)
        cout << temp1 << endl;
    else if(temp2 >= temp1 && temp2 >= temp3)
        cout << temp2 << endl;
    else
        cout << temp3 << endl;

    return 0;
}

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

alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
dic = {a:i for i,a in enumerate(alpha)}


ans = ''
for s in S:
    idx = dic[s]+N 
    if dic[s]+N > 25: idx -= 26
    ans += alpha[idx]
print(ans) 

Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

long solve(long n, long m, std::vector<long>& prices)
{
  std::sort(prices.begin(), prices.end());
  std::vector<long> work;
  for (long i = 0; i < m; ++i) {
    auto v = prices.empty() ? 0 : prices.back();
    auto w = work.empty() ? 0 : work.front();
    if (v > w) {
      v /= 2;
      prices.pop_back();
      work.push_back(v);
    } else {
      w /= 2;
      work.erase(work.begin());
      work.push_back(w);
    }
  }

  return std::accumulate(prices.begin(), prices.end(), 0l)
      + std::accumulate(work.begin(), work.end(), 0l);
}

int main()
{
  long n, m;
  std::cin >> n >> m;

  std::vector<long> prices(n);
  for (auto& p : prices) {
    std::cin >> p;
  }

  std::cout << solve(n, m, prices) << std::endl;
}


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

using ll = long long;

int main() {
  // 入力
  int N;
  cin >> N;
  ll a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  ll sum = 0;
  for (int i = 1; i < N; i++) sum += a[i];

  ll tmp = a[0];
  ll ans = abs(tmp - sum);
  for (int i = 1; i < N - 1; i++) {
    tmp += a[i];
    sum -= a[i];
    ans = min(ans, abs(tmp - sum));
  }

  // 解答
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<long long int>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vb vector<bool>
#define vvl vector<vector<ll> >
#define vvi vector<vector<int> >
#define pl pair<ll,ll>
#define pb push_back
#define PI 3.14159265
#define mod 998244353
#define pb push_back
#define mp make_pair
#define fri(s,n) for(int i=s;i<n;i++)
#define frj(s,n) for(int j=s;j<n;j++)
#define T(i) int i=1;cin>>i;while(i--)
#define vsi vector<set<int> >
#define pii pair<int,int>
#define inf 1e9
#define vpii vector<pair<int,int> >


ll power(ll a,ll b){
    if(b==0)
        return 1;
    if(b&1)
        return a*power(a,b-1);
    ll temp=power(a,b/2);
    return temp*temp;
    }
ll mycompare(ll a,ll b){
    return a>b;
    }

ll max_happiness(int n,vvi &dp,int previous,vvi &h){
    if(n==-1)
        return 0;
    if(dp[n][previous]!=-1)
        return dp[n][previous];
    ll hap=INT_MIN;
    for(int i=0;i<3;i++){
        if(i!=previous)
            hap=max(hap,h[n][i]+max_happiness(n-1,dp,i,h));
    }
    return dp[n][previous]=hap;
    }
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    fast;
    int n;
    cin>>n;
    vvi h(n,vi(3)),dp(n,vi(3,-1));
    fri(0,n){
        cin>>h[i][0]>>h[i][1]>>h[i][2];
        }
    cout<<max(max_happiness(n-1,dp,0,h),max(max_happiness(n-1,dp,1,h),max_happiness(n-1,dp,2,h)));
    }


Measured memory_bytes: 23504
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
// lower_boundは二分探索
struct edge { int to, cost; };
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s, int v, vector<int>& d, whei(edge)& G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size(); i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

llint binary_search(vector<int>&s,llint a) {
	llint l = -1;
	llint r = (int)s.size();
	while (r - l > 1) {
		llint mid = l + (r - l) / 2;

		if (s[mid]>=a) r = mid;
		else l = mid;
	}
	return r;
}
map<int, int>S;
void bfs(whei(int)& G, int s,int n) {
	hei(int) dist(n, -1);
	dist[s] = 0;
	queue<int> que;
	que.push(s);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (auto x : G[v]) {
			if (dist[x] != -1)continue;
			dist[x] = dist[v] + 1;
			S[dist[x]]++;
			que.push(x);
		}
	}
}



int main() {
	int n, x, y;
	cin >>n>> x >> y;
	whei(int) G(n);
	G[x - 1].push_back(y - 1);
	G[y - 1].push_back(x - 1);
	rep(i, 0, n - 1) {
		G[i].push_back(i + 1);
		G[i + 1].push_back(i);
	}
	rep(i, 0, n) {
		bfs(G, i, n);
	}
	
	rep(i, 1, n)cout << S[i]/2 << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 1; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
  ll a;
  cin >> a;
  ll ans1,ans2;
  rep(i,sqrt(a)+1){
    if(a%i==0){
       ans1 = i;
       ans2 = a/i;
    }
  }
  cout << ans1+ans2-2;
}

Measured memory_bytes: 3664
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(int argc, char **argv)
{
	int tmp;
	int *array = (int *)calloc(1000, sizeof(int));
	
	while(cin >> tmp){
		array[tmp]++;
	}
	
	tmp = 0;
	for(int i = 0; i < 1000; i++){
		if(tmp < array[i]){
			tmp = array[i];
		}
	}
	
	for(int i = 0; i < 1000; i++){
		if(array[i] == tmp){
			cout << i << endl;
		}
	}
	
	free(array);
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main()
{ int sx,sy,tx,ty,i,j;
cin>>sx>>sy>>tx>>ty;
for(i=0;i<ty-sy;i++)
    cout<<"U";
for(i=0;i<tx-sx;i++)
    cout<<"R";
for(i=0;i<ty-sy;i++)
    cout<<"D";
for(i=0;i<tx-sx;i++)
    cout<<"L";
    cout<<"L";
for(i=0;i<ty-sy+1;i++)
    cout<<"U";
for(i=0;i<tx-sx+1;i++)
    cout<<"R";
    cout<<"D";
    cout<<"R";
for(i=0;i<ty-sy+1;i++)
    cout<<"D";
for(i=0;i<tx-sx+1;i++)
    cout<<"L";
    cout<<"U";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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 d = sc.nextInt();

		if(a*b >= c*d){
			System.out.println(a*b);
		}else{
			System.out.println(c*d);

		}


	}
}


class Pair implements Comparable{
	Character from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 22868
#include <iostream>

using namespace std;

int main()
{
    int n; cin >> n;
    string ans = "No";

    while (n > 0) {
        int tmp = n % 10;
        n /= 10;
        if (tmp == 7) ans = "Yes";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
def d_divrem_number(N):
    """
    与えられた正整数Nに対して、以下の条件を満たす正整数mの総和を求めよ。
    ・Nをmで割った商と余りが等しい。
    """

    # Nをmで割った商と余りをそれぞれq, rとおくと、N=qm+rである。
    # いま、q=rとなるmのみ考えるので、N=q(m+1)となる。
    # すなわち、m+1はNの約数であり、そのようなmのみ調べればいい。

    def divisor_list(n):
        """n の正の約数のリスト"""
        ret = []
        for k in range(1, int(n**0.5) + 1):
            if n % k == 0:
                ret.append(k)
                if k != n // k:
                    ret.append(n // k)
        ret.sort()
        return ret

    candidates = list(map(lambda x: x - 1, reversed(divisor_list(N))))
    return sum(m for m in candidates if m != 0 and N // m == N % m)

N = int(input())
print(d_divrem_number(N))

Measured memory_bytes: 3420
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define PB push_back
#define loop(i,x,y) for(int i=x;i<y;i++)
#define rloop(i,x,y) for(int i=x;i>y;i--)
#define NL cout<<"\n"
#define ans(x) cout<<x<<"\n"
#define out(x) cout<<x<<" "
#define F first
#define S second
#define ansf(x,y) cout<<fixed<<setprecision(y)<<x<<endl;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
void solve()
{
  int a;
  string s;
  cin>>a>>s;
  ans((a<3200?"red":s));
}
signed main()
{
  // FAST;
  int T=1;
  // cin>>T;
  while(T--) solve();
  return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    for (int i = 1; i < 10; i++) {
        if (n % i == 0 && n / i < 10) {
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";
    return 0;
}

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

ll dp[2001];
void solve()
{
	ll n, mod = 1e9 +7;
	cin>>n;
	if(n<=2)
	{
		cout<<0<<endl;
		return;
	}
	memset(dp,0,sizeof dp);
	dp[3] = 1;
	dp[4] = 1;
	dp[5] = 1;
	for (int i = 6; i <=n; ++i)
	{
		dp[i] = 1;
		for(int j = 3; j <= i-3; j++)
		{
			dp[i] = (dp[i]+dp[i-j])%mod;
		}
	}
	cout<<dp[n]<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

bool E[15][15];

bool check(vector<ll> &v) {
    ll index = 0;
    REP(i, v.size()) {
        ll nxt = v[i];
        if (!E[index][nxt])
            return false;
        index = nxt;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    memset(E, 0, sizeof(E));
    REP(i, M) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        E[a][b] = E[b][a] = true;
    }
    vector<ll> v;
    REP(i, N - 1) {
        v.push_back(i + 1);
    }
    ll ans = 0;
    do {
        if (check(v))
            ans++;
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1000000000;



int main(){
    int n,m;cin >> n >> m;
    vector<vector<int>> v(n+1);
    vector<int> x(n+1,0);
    vector<int> y(n+1,0);
    for (int i = 0; i < n+m-1; i++) {
        int a,b;cin >> a >> b;
        v[a].pb(b);
        x[b]++;
    }
    int s=0;
    for (int i = 1; i <= n; i++) {
        if(x[i]==0){
            s=i;
            break;
        }
    }
    queue<int> que;
    vector<int> ans(n+1,0);
    que.push(s);
    ans[s]=0;
    while(!que.empty()){
        int ll=que.front();que.pop();
        y[ll]++;
        for (int k = 0; k < v[ll].size(); k++) {
            if(x[ll]!=y[ll]&&ll!=s) continue;
            que.push(v[ll][k]);
            ans[v[ll][k]]=ll;
        }
    }    
    for (int i = 1; i <=n ; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}





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

int main () {
int64_t n, k, q;
  cin >> n >> k >> q;
  vector<int64_t> a(q);
  vector<int64_t> b(n);
  rep(i,q) { 
    cin >> a.at(i);
    b.at(a.at(i)-1)++;
  }
  rep(i,n) {
    if(k + b.at(i) - q > 0)
      cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


Measured memory_bytes: 2176
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

A,B = map(int, input().split())

if A%2 == 0:
    grp = (B-A+1)//2
    ans = grp%2
    if B%2 == 0:
        ans = ans^B
else:
    grp = (B-A)//2
    ans = (grp%2)^A
    if B%2 == 0:
        ans = ans^B

print(ans)


Measured memory_bytes: 12068
# your code goes here
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
a.sort(reverse=True)
x=[]
if(k>=n):
	print(0)
else:
	for i in range(k):
		x.append(a[i])
	print(abs(sum(a)-sum(x)))

Measured memory_bytes: 26180
#include <bits/stdc++.h>
#define PB push_back
const int mod = 1000 * 1000 * 1000 + 7;
using namespace std;
int main()
{
	string s;
	cin >> s;
	vector<int> v;
	for(auto x : s)
	{
		if(x == 'S')
			v.PB(x);
		else if(x == 'T' && v.size() && v.back() == 'S')
			v.pop_back();
		else
			v.PB(x);
	}
	cout << v.size() << endl;
}

Measured memory_bytes: 1532
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
ll a[200010];
unordered_map<ll,ll> pos;
int main(){
    cin>>N;
    for(ll i=0;i<N;i++){
        cin>>a[i];
        pos[a[i]]=i;
    }
    set<ll> posSet;
    ll ans=0;
    for(ll i=1;i<=N;i++){
        auto upperIt=posSet.upper_bound(pos[i]);
        ll l,r;
        if(upperIt==posSet.end()){
            r=N-1;
        }else{
            r=*upperIt-1;
        }
        if(upperIt==posSet.begin()){
            l=0;
        }else{
            auto downerIt=upperIt;
            downerIt--;
            l=*downerIt+1;
        }
        ans+=i*(pos[i]-l+1)*(r-pos[i]+1);
        posSet.insert(pos[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 19400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt4 = 0;
    rep(i, n)
    {
        cin >> a[i];
        if(a[i]%4==0){
            a[i] = 4;
            cnt4++;     
        }else if (a[i]%2==0){
            a[i] = 2;
            cnt2++;
        }else{
            a[i] = 1;
            cnt1++;
        }
    }
    if((cnt2 == 0 && cnt4 != 0 && cnt1 <= cnt4 + 1) || (cnt2 != 0 && cnt4 != 0 && cnt1 <= cnt4) || (cnt2 >= 2 && cnt4 == 0 && cnt1 == 0)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long 
#define MAXN 1000010

using namespace std;

int n, m, d, x;
int f;
int a[MAXN];
int t;
string s;

int main() {
	cin >> s;
	string st;
	cin >> st;
	
	for (int i = 0; i <= 2; i++) {
		if (s[i] == st[i]) t++;
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool sb(int a,int b){
	return a>b;
}
int n,k,a[221212],b[200122],duo,ans=0,you;
int main() {
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)b[a[i]]++;
	sort(b+1,b+n+1,sb);
	for(int i=1;i<=n+5;i++)
	if(b[i]==0){
	you=i-1;	
	break;}
	duo=you-k;
	if(duo<=0)cout<<0;
	else {
	for(int i=1;i<=duo;i++)ans+=b[you-i+1];
	cout<<ans;
	} 
	return 0;
}

Measured memory_bytes: 1792
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 5;
ll a[N];
vector<int> v[N], p[N];
vector<int> ans;
bool vis[N];
int dp[N];
void dfs(int s){
    vis[s] = 1;
    for(auto i : v[s]){
        if(!vis[i])
            dfs(i);
    }
    ans.push_back(s);
}
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        p[y].push_back(x);
    }
    for(int i = 1; i <= n; i++){
        if(!vis[i])
            dfs(i);
    }
    reverse(ans.begin(), ans.end());
    int maxi = 0;
    for(auto i : ans){
        for(auto P : p[i]){
            dp[i] = max(dp[i], dp[P] + 1);
            maxi = max(maxi, dp[i]);
        }
    }
    cout << maxi;
return 0;
}


Measured memory_bytes: 24444
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
string S;

void solve() {

	cin >> S;

	if (stoi(S.substr(0, 4)) < 2019) {
		cout << "Heisei" << endl;
		return;
	}

	if (stoi(S.substr(5, 2)) <= 4) {
		cout << "Heisei" << endl;
		return;
	}

	cout << "TBD" << endl;

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    string s;cin >>s;
    ll n=s.size();
    ll a=0;ll ans=0;
    for (int i = 0; i < n; ++i) {
        if(s[i]=='A')a++;
        else if(s[i]=='B'){
            if(i+1>=n)continue;
            else if(s.substr(i,2)=="BC") {
                ans += a;
                i++;
            }
            else {
                a=0;
            }
        }
        else if(s[i]=='C'){
            a=0;
           // cout<<"aaaaa"<<endl;
        }
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

import java.util.*;


public class Main {

    public static void main(String[] args) {

      Scanner scanner = new Scanner(System.in);
 
      String as = scanner.nextLine();
      String bs = scanner.nextLine();
      String cs = scanner.nextLine();

      Map<Character, char[]> members = new HashMap<>();
      members.put(Character.valueOf('a'), as.toCharArray());
      members.put(Character.valueOf('b'), bs.toCharArray());
      members.put(Character.valueOf('c'), cs.toCharArray());

      char current = 'a';

      while(true) {
        char[] cards = members.get(current);
        if (cards.length == 0) {
          System.out.println(String.valueOf(current).toUpperCase());
          break;
        }

        char prev = current;
        current = cards[0];

        char[] tmpCards = new char[cards.length - 1];
        for (int i = 0; i < cards.length - 1; i++){
          tmpCards[i] = cards[i + 1];
        }

        members.put(Character.valueOf(prev), tmpCards);
      }

      scanner.close();
  }
}


Measured memory_bytes: 21844
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,m,cnt[110100];
string ans[110100];

string get(int x){
  string res = "";
  while(x>0){
    res+='0'+x%10;
    x/=10;
  }
  while(res.size()<6){
    res+='0';
  }
  reverse(all(res));
  return res;
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n >> m;
  vector<pair<int,pi>> v;
  for(int i=1;i<=m;i++){
    int p,y;
    cin >> p >> y;
    v.pb({y,{p,i}});
  }
  sort(all(v));
  for(int i=1;i<=m;i++){
    int p = v[i-1].sc.fs;
    ans[v[i-1].sc.sc] = get(p)+get(++cnt[p]);
  }
  for(int i=1;i<=m;i++){
    cout << ans[i] << endl;
  }

return 0;
}
///....


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

int main()
{
    string s,t;
    cin >> s >>t;
    int l;
    l = s.size();
    if (s == t.erase(l)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

typedef long long ll;

long 	is_power_of_2(long n)
{
	while (n >= 2)
	{
		if (n % 2 == 0)
			n /= 2;
		else
			break ;
	}
	return (n == 1 ? n : 0);
}

long	count_power_of_2(long n)
{
	long sum;
	sum = 1;
	long count = 1;
	while (sum < n)
	{
		sum *= 2;
		count += sum;
	}
	return (count);
}

long recursive(long H)
{
	if (H > 1)
		return (2 * recursive(H /2) + 1);
	if (H == 1)
		return 1;
	return 1;
}

int main()
{
	long N;
	scanf("%ld", &N);
	// while (is_power_of_2(N) == 0)
	// 	N--;
	long ans = recursive(N);
	// ans = count_power_of_2(N);
	printf("%ld\n", ans);
	return (0);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll h,w,t[3000][3000]={},u[3000][3000]={},c=0,ans=0;
  string s[3000];
  cin >> h >> w;
  rep(i,h)cin >> s[i];
  rep(i,h){
    rep(j,w){
      if(s[i][j]=='.'){
        c++;
        t[i][j]=c;
      }
      else{
        c=0;
        t[i][j]=0;
      }
    }
    c=0;
  }
  rep(i,h){
    per(j,w){
      if(c==0&&s[i][j]=='.'){
        c=t[i][j];
      }
      else if(s[i][j]=='.'){
        t[i][j]=c;
      }
      else{
        c=0;
      }
    }
    c=0;
  }
  c=0;
  rep(i,w){
    rep(j,h){
      if(s[j][i]=='.'){
        c++;
        u[j][i]=c;
      }
      else{
        c=0;
        u[j][i]=0;
      }
    }
    c=0;
  }
  c=0;
  rep(i,w){
    per(j,h){
      if(c==0&&s[j][i]=='.'){
        c=u[j][i];
      }
      else if(s[j][i]=='.'){
        u[j][i]=c;
      }
      else{
        c=0;
      }
    }
    c=0;
  }
  rep(i,h){
    rep(j,w){
      ans=max(ans,u[i][j]+t[i][j]-1);
    }
  }
  printf("%lld",ans);
}

Measured memory_bytes: 145152