akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LL long long
#define f first
#define s second
using namespace std;
int a[100050];
map<int,int>m;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    bool f1=0,f2=0;
    int mx1=0,mx2=0;
    for(int i=n-1;i>=0;i--)
    {
        m[a[i]]++;
        if(m[a[i]]==2&&!f1)mx1=a[i],f1=1,m[a[i]]=0;
        else if(m[a[i]]==2&&!f2)mx2=a[i],f2=1,m[a[i]]=0;
        if(f1&&f2)break;
    }
    cout<<1LL*mx1*mx2;
}


Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL; 

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    LL N,X;
    cin >> N >> X;

    LL laynum[N];
    laynum[0] = 1;
    FOR(i,1,N+1)
    {
        laynum[i] = laynum[i-1] * 2 + 3;
    }

    LL paty[N];
    paty[0] = 1;
    FOR(i,1,N+1)
    {
        paty[i] = paty[i-1] * 2 + 1;
    }

    LL res = 0;

    for(int level = N; level >= 0; level--)
    {
        dump(level) 
        dump(X)
        dump(laynum[level])
        dump(res)
        if(X == laynum[level])
        { 
            dump("sec1")
            res += paty[level];
            break;
        }
        if(X == (laynum[level] + 1)/2)
        {
            dump("sec2")
            res += (paty[level]+1) / 2;
            break;
        }
        if(X == 1)
        {
            dump("sec3")
            //res += ;
            break;
        }


        if(X > (laynum[level] + 1)/2)
        {

            res += (paty[level] + 1) / 2;
            X = X - (laynum[level] + 1)/2;
        }
        else if(X < (laynum[level] + 1)/2)
        {
            X = X - 1;
        }
    }

    cout << res << endl;

}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
const int error=-1e9-7;
#define F first
#define S second
#define MK make_pair

int a[1100][1100]={};
int color[1100]={};
int n;

bool search(int s){
    bool j=true;
    for(int i=1;i<=n && j;i++){
        if(a[s][i]==1){
            if(color[i]==color[s]*-1){continue;}
            if(color[i]==0){color[i]=color[s]*-1; if(!search(i)){j=false;} continue;}
            j=false;
        }
    }
    return j;
}



int main(){
    while(1){
    for(int i=0;i<1100;i++){
        color[i]=0;
        for(int t=0;t<1100;t++){
            a[i][t]=0;
        }
    }
    int m;
    cin>>n>>m;
        if(n==0 && m==0){break;}
    for(int i=0;i<m;i++){
        int s,g;
        cin>>s>>g;
        a[s][g]=1;
        a[g][s]=1;
    }
    color[1]=1;
    if(!search(1)){cout<<0<<endl; continue;}
    int k=0,l=0;
    for(int i=1;i<=n;i++){
        if(color[i]==1){k++;}
        if(color[i]==-1){l++;}
        assert(color[i]==1 || color[i]==-1);
    }
    int count=0;
    if(k>l){swap(k,l);}
    if(k==l){l=-1;}
    if(k%2==0){count++;}
    if(l%2==0){count++;}
    cout<<count<<endl;
    if(k%2==0){cout<<k/2<<endl;}
    if(l%2==0){cout<<l/2<<endl;}
    }
    return 0;
}


Measured memory_bytes: 7824
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
using bll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(v) (v).begin(), (v).end()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
template<typename T> inline void pv(vector<T> v) { for(ll i=0, N=v.size()-1; i<=N; i++) if(i!=N) cout << v[i] << ' '; else cout << v[i] << endl; }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll N_MAX = 100000;
constexpr ll K_MAX = 1000000000;
constexpr ll Q_MAX = 100000;

ll N, K, Q;
ll A[Q_MAX];

void input() {
	scanf("%lld%lld%lld", &N, &K, &Q);
	vector<ll> a(N,0);
	rep(i, Q) scanf("%lld", A + i);

	rep(i,Q){

		a[A[i]-1]++;
	}
	debug(a);
	rep(i,N){
		if(a[i]+K>Q){
			p("Yes");
		}else
		{
			p("No");
		}
		
	}
}

signed main() {
	input();

	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

void eratosthenes(vector<bool>& is_prime, vector<ll>& primes, ll& n)
{
	for (ll i=2; i<=n; i++)	
	{
		if (!is_prime[i]) continue;
			
		for(ll j=2*i; j<=n; j+=i)
			is_prime[j] = false;

		primes.push_back(i);
	}
}

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

    ll x, n=100000+10;
    cin >> x;

    vector<bool> is_prime(n, true);
    vector<ll> primes;

    eratosthenes(is_prime, primes, n);

    ll ans;
    rep(i,0,n)
	if (primes[i]>=x)
	{
		ans = primes[i];
		break;
	}	

    cout << ans << endl;

    return 0;
}


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

const int MAX_K = 4;
string N;
string ans;
int A[MAX_K];

int main(void) {
	cin >> N;

	ans = "???????=7";
	for (int i = 0; i < MAX_K; ++i) {
		A[i] = (int)(N[i] - '0');
		ans[2 * i] = N[i];
	}
	for (int i = 0; i <= 7; ++i) {
		int sum = A[0];
		for (int k = 1; k < MAX_K; ++k) {
			int j = (1 << (k - 1));
			if((i & j) == 0) {
				ans[2 * k - 1] = '+';
				sum += A[k];
			}
			else {
				ans[2 * k - 1] = '-';
				sum -= A[k];
			}
		}
		if (sum == 7)
			break;
	}

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;
int a[MAXN];
int G[105][105];

int main()
{
    int h,w;
    while(scanf("%d%d",&h,&w)!=EOF)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;++i)
            scanf("%d",&a[i]);
        int cnt=1;
        for(int i=1;i<=h;++i)
        {
            if(i&1)
            {
                for(int j=1;j<=w;++j)
                {
                   if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                   else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }else
            {
                for(int j=w;j>=1;--j)
                {
                    if(a[cnt]>0) {G[i][j]=cnt;--a[cnt];}
                    else if(a[cnt]==0) {++cnt;G[i][j]=cnt;--a[cnt];}
                }
            }
        }
        for(int i=1;i<=h;++i)
        {
            for(int j=1;j<=w;++j)
            {
                if(j!=w) printf("%d ",G[i][j]);
                else printf("%d\n",G[i][j]);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 768
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = unsigned long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll n, m; cin >> n >> m;

    vector<ll>a(n);
    REP(i, n)cin >> a[i];
    sort(ALL(a));

    vector<pair<ll, ll>>bc(m);
    REP(i, m) {
        ll b, c;
        cin >> b >> c;
        bc[i] = make_pair(c, b);
    }
    sort(ALL(bc), greater<pair<ll, ll>>());

    ll inow = 0;
    ll ans = 0;
    REP(i, m) {
        ll b = bc[i].second, c = bc[i].first;
        for (ll j = inow; j < min(inow + b, n); ++j) {
            ans += max(a[j], c);
        }
        inow += b;
    }
    for (ll j = inow; j < n; ++j)ans += a[j];

    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int k;
cin >> k;
int x;
cin >> x;
if(500*k>=x){
    cout<<"Yes"<<endl; 
    return 0;
}
cout <<"No"<<endl; 

}







Measured memory_bytes: 256
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define multitest
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
inline ll add(ll a, ll b, ll m)
{
	return (((a % m + b % m) % m + m) % m);
}
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void solve()
{
	ll k, n;
	cin >> k >> n;
	v64 arr(n + 1, 0);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	v64 res;
	for (int i = 1; i < n; i++)
		res.push_back(arr[i] - arr[i - 1]);
	res.push_back(k + arr[0] - arr[n - 1]);
	sort(res.begin(), res.end());
	ll sum = k - *max_element(res.begin(), res.end());
	cout << sum << ln;
	return;
}

int main()
{
	FASTIO;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
	return 0;
}


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

const int MAXN = 1e5+5;

int n, a[MAXN], b[MAXN];
int s = 0;
map<int, int> ma;

bool y = 0;
vector<int> g[MAXN];
map<int, int> m;
int a1[MAXN];
int comp = 0;
bool vis[MAXN];

void dfs(int v) {
	vis[v] = 1;
	for (int i = 0; i < g[v].size(); ++i)
		if (!vis[g[v][i]])
			dfs(g[v][i]);
}

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		a1[i] = a[i];
		s ^= a[i];
		ma[a[i]]++;
	}

	sort(a1, a1+n);
	for (int i = 0; i < n; ++i)
		m[a1[i]] = i;
	//all sequences we can achieve are permutations of a except maybe
	// with one element replaced with the sum

	if (m.count(s) == 0)
		m[s] = n;
	
	for (int i = 0; i < n; ++i)
		cin >> b[i];

	for (int i = 0; i < n; ++i) {
		if (a[i] == b[i])
			continue;
		g[m[a[i]]].push_back(m[b[i]]);
		g[m[b[i]]].push_back(m[a[i]]);
	}

	for (int i = 0; i <= n; ++i) {
		if (!vis[i] && g[i].size() > 0) {
			++comp;
			dfs(i);
		}
	}

	for (int i = 0; i < n; ++i) {
		if (b[i] == s && y == 0) {
			y = 1;
			continue;
		}

		if (ma[b[i]] == 0) {
			cout << "-1\n";
			return 0;
		}

		ma[b[i]]--;
	}

	if (y == 0) {
		int ct = 0;
		for (int i = 0; i < n; ++i)
			ct += (a[i] != b[i]);
		if (ct == 0)
			cout << "0\n";
		else
			cout << ct+comp << "\n";
		return 0;
	} else {
		int ct = 0;
		for (int i = 0; i < n; ++i)
			ct += (a[i] != b[i]);
		if (ct == 0)
			cout << "0\n";
		else
			cout << ct+comp-1 << "\n";
	}
}

Measured memory_bytes: 19456
#include <iostream>
using namespace std;
typedef long long  ll;

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll N; cin >> N;
	ll p = 1;

	repe(i, 1, N) {
		p = p * i % 1000000007;
	}
	cout << p << endl;

	return 0;
}

Measured memory_bytes: 256
gets.to_i.times do
  _, k = gets.split.map(&:to_i)
  xs = gets.split.map(&:to_i)
  ds = (xs.size - 1).times.map {|i| xs[i + 1] - xs[i] }.sort
  a = ds[0..-k]
  puts a.empty? ? "0" : a.reduce(:+)
end

Measured memory_bytes: 21528
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,count=0;
    cin>>h;
    ll x=1;
    while(h!=0){
        count+=x;
        h/=2;
        x*=2;
    }
    cout<<count;
    return(0);
}

Measured memory_bytes: 256
#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>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=2e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();	
 	
 	int n;
 	scanf("%d",&n);
 	bool ok = true;
 	for(int i=0,x;i<n;i++){
 		scanf("%d",&x);
 		if(x%2==0){
 			if(x%3 && x%5)ok=false;
 		}
 	}
 	if(ok)printf("APPROVED\n");
 	else	printf("DENIED\n");
}		


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b,c,d;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b){
		d=a;
		a=b;
		b=d;
	}
	if(b>c){
		d=b;
		b=c;
		c=d;
	}
	if(a>b){
		d=a;
		a=b;
		b=d;
	}
	printf("%d %d %d\n",a,b,c);
}


Measured memory_bytes: 2140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


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

  int c = atoi(s.c_str());
  int a = c / 100;
  int b = c - 100 * a;

  //cout << a << " " << b << endl;
  string ans;
  if (1 <= a && a <= 12 && 1 <= b && b <= 12) ans = "AMBIGUOUS";
  else if (1 <= a && a <= 12) ans = "MMYY";
  else if (1 <= b && b <= 12) ans = "YYMM";
  else ans = "NA";


  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;

#define MAXN 524288
#define MAXC 1048576
#define NO_VALUE -1

#define LEFT(x) ( 2*(x) )
#define RIGHT(x) ( 2*(x)+1 )

int A, B, C, M;

int r() {
    A = 36969 * (A & M) + (A >> 16);
    B = 18000 * (B & M) + (B >> 16);
    return (C & ((A << 16) + B)) % 1000000;
}

int x[MAXN], y[MAXN], z[MAXN], ox[MAXN], val[MAXN], RANGE;

bool cmp_x(const int &a, const int &b) {
    if (x[a] != x[b]) return x[a] < x[b];
    else if (y[a] != y[b]) return y[a] < y[b];
    else return z[a] < z[b];
}

map<int, int> bit[MAXC];

int answer(int idx, int th) {
    map<int, int>::iterator it = bit[idx].lower_bound(th);
    if (it != bit[idx].begin()) return (--it)->second;
    else return NO_VALUE;
}

int query(int idx, int th) {
    int res = NO_VALUE;
    while (idx > 0) {
        res = max(res, answer(idx, th));
        idx &= idx-1;
    }
    return res;
}

void update(int idx, int th, int v) {
    map<int,int>::iterator it1, it2;
    while (idx < RANGE) {
        it1 = it2 = bit[idx].upper_bound(th);
        while (it2 != bit[idx].end() && it2->second <= v) it2++;
        bit[idx].erase(it1, it2);
    
        it1 = bit[idx].upper_bound(th);
        if (it1 == bit[idx].begin() || (--it1)->second < v) bit[idx][th] = v;
        idx += idx&(-idx);
    }
}

int main() {
    int m, n, i, j, N;

    while (scanf("%d %d %d %d", &m, &n, &A, &B) && (m || n || A || B)) {
        C = ~(1<<31); M = (1<<16)-1;
        for (i=0; i<m; i++) scanf("%d %d %d", &x[i], &y[i], &z[i]);
        for (i=m; i<m+n; i++) { x[i] = r(); y[i] = r(); z[i] = r(); }
        N = m+n;

        RANGE = 0;
        for (i=0; i<N; i++) { ox[i] = i; y[i] += 1; RANGE = max(RANGE, y[i]+1); }
        sort(ox, ox+N, cmp_x);

        for (i=0; i<RANGE; i++) bit[i].clear();

        i = 0;
        do {
            for (j=i; j<N && x[ox[j]]==x[ox[i]]; j++) val[ox[j]] = max(1, query(y[ox[j]]-1, z[ox[j]])+1);
            for (; i<j; i++) update(y[ox[i]], z[ox[i]], val[ox[i]]);
        } while (i < N);
        printf("%d\n", query(RANGE-1, MAXC));
    }

    return 0;
}

Measured memory_bytes: 106320
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int k; cin>>k; 
  string s="";
  while(k--)
    s+="ACL";
  cout<<s;
    return 0;
}

Measured memory_bytes: 3608
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

//for loop関係
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//略記
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

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

//定数
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

//Degree <-> Radian
double toRad(double d){ double rad; rad=d*PI/180; return rad; }
double toDegree(double rad){ double d; d=rad*180/PI; return d; }
//The least common multiple : lcm
ll lcm(int a,int b){ return a*b/__gcd(a,b); }
//素数判定
bool isPrime(int n){
    int i; 
    if(n<2) return 0;
    else if(n==2) return 1;
    if(n%2==0) return 0;
    for(i=3;i*i<=n;i+=2) if(n%i==0) return 0;
    return 1;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,a,b;
    cin >> n >> a >> b;
    ll x=0,m=0;
    x=n/(a+b);
    m=n%(a+b);

    if(m>a) cout << a*x+a ENDL;
    else cout << a*x+m ENDL;
    
    return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
const int N=2005;
vector<int> ad[N],ap[N];
priority_queue<int> pq;
int a[N],ans[N],vis[N],tail[N];
int n,v,cnt;
void dfs(int x){
	vis[x]=1;
	for(int i=0;i<ad[x].size();i++){
		v=ad[x][i];
		if(vis[v])continue;
		tail[v]=1;ap[x].push_back(v);
		dfs(v);
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)
	if(__gcd(a[i],a[j])>1&&i!=j)ad[i].push_back(j);
	for(int i=1;i<=n;i++)if(vis[i]==0)dfs(i);
	for(int i=1;i<=n;i++)if(tail[i]==0)pq.push(i);
	while(pq.size()>0){
		v=pq.top();
		cnt++;ans[cnt]=a[v];
		pq.pop();
		for(int i=0;i<ap[v].size();i++)
		pq.push(ap[v][i]);
	}
	for(int i=1;i<=cnt;i++)cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
} 

Measured memory_bytes: 15872
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	vector<VI> A(N);
	REP(i, N) {
		REP(j, N - 1) {
			int a;
			cin >> a;
			a--;
			A[i].push_back(a);
		}
	}
	VI cnt(N, 0);
	int mach = 0;
	
	vector<int> F(N, 0);
	while (mach < N*(N - 1) / 2) {
		
		bool f = true;
		REP(i, N) {
			if (cnt[i] == N - 1)continue;
			int enemy = A[i][cnt[i]];
			int tmp;
			if (A[i][cnt[i]] ==enemy&&i== A[enemy][cnt[enemy]]) {
				tmp = max(F[i]+1, F[enemy]+1);
				F[i] = tmp;
				F[enemy] = tmp;
				cnt[i]++;
				cnt[enemy]++;
				mach++;
				f = false;
				//cout <<" "<<enemy<<" "<<F[enemy]<<" "<< i << " " << F[i] << endl;
			}
		}
		//cout << tmp << endl;
		//ans += tmp;
		
		if (f) {
			cout << -1 << endl;
			return 0;
		}
	}
	rSORT(F);
	cout << F[0] << endl;

	//cout << ans << endl;





	return 0;
}



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

using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++) 
#define REPd(i, a, n) for(long double i=a; i<n; i++)
#define sortv(v) sort(v.begin(), v.end());
#define sortg(v) sort(v.begin(), v.end(), greater<>());
#define rev(v) reverse(v.begin(), v.end());

int main() {
  int n, k;
  cin >> n >> k;
  vector<char> v(n);
  REP(i, 0, n) cin >> v[i];
  if(v[k-1]=='A') v[k-1]='a';
  if(v[k-1]=='B') v[k-1]='b';
  if(v[k-1]=='C') v[k-1]='c';
  REP(j, 0, n) cout << v[j];
  cout << endl;
}

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

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a,ll b){
    return a * b / gcd(a, b);
}


int main(){
    int n;
    ll ans=0;
    string s;
    cin>>n;
    map<string,ll> mp;
    rep(i,n){
        cin>>s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    for(auto& p : mp){
        ans+=p.second*(p.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

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

    bool flag = true;
    for(ll i=1;i<s.size();++i){
        if(s[i-1] != s[i]){
            flag = false;
            break;
        }
    }
    if(flag){
        ll sum = s.size() * k;
        cout<<sum/2<<endl;
        return 0;
    }

    ll ans = 0;
    ll count = 0;
    string t = s;
    for(ll i=1;i<t.size();++i){
        if(t[i-1] == t[i]){
            t[i] = 'A';
            count++;
        }
    }
    ans += count * k;

    if(s[0] == s[s.size()-1]){
        char now = s[0];
        ll a = 1;
        for(ll i=1;i<s.size();++i){
            if(now == s[i]){
                a++;
            }else{
                break;
            }
        }
        ll b = 0;
        for(ll i=1;i<s.size();++i){
            if(now == s[s.size()-i]){
                b++;
            }else{
                break;
            }
        }
        ans -= (a / 2 + b / 2 - (a + b) / 2) * (k - 1);
    }
    cout<<ans<<endl;

    return 0;
}

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

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

    string S; cin >> S;
    int ans = 1 << 30;
    for (int i = 0; i < S.size()-2; i++) {
        int res = abs(stoi(S.substr(i, 3)) - 753);
        if (res < ans) ans = res;
    }
    cout << ans << "\n";
}

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

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = int.Parse(Console.ReadLine());
            var ai = Console.ReadLine().Trim().Select(x => x - '1').ToArray();
            var isContain1 = ai.Contains(1);
            if (!isContain1) ai = ai.Select(x => x /= 2).ToArray();
            var isOdd = IsOdd(ai);

            if (isContain1) Console.WriteLine(isOdd ? 1 : 0);
            else Console.WriteLine(isOdd ? 2 : 0);
        }

        static bool IsOdd(int[] items)
        {
            var binCoef = new int[items.Length];
            var n = items.Length - 1;
            for (int i = 0, j = binCoef.Length - 1; i < j; i++, j--)
            {
                binCoef[i] = binCoef[j] = n == (i | (n - i)) ? 1 : 0;
            }

            var t = 0;
            for (var i = 0; i < binCoef.Length; i++)
            {
                if (binCoef[i] % 2 == 1)
                {
                    if (items[i] % 2 == 1) t++;
                }
            }
            return t % 2 == 1;
        }
    }
}


Measured memory_bytes: 36996
import math
a,b,C = (float(x) for x in input().split())

s = 0.5*a*b*math.sin(C/180*math.pi)
print (s)

L = a + b + math.sqrt(b*b + a*a - 2 * a * b * math.cos(C/180*math.pi))
print (L)

h = b * math.sin(C/180*math.pi)
print (h)


Measured memory_bytes: 5700
import java.io.*;
import java.util.*;

class Main {
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		
		ArrayList<Integer> ans = new ArrayList<Integer>();
		
		while (true) {
			
			StringTokenizer st = new StringTokenizer(br.readLine()," ");
			int y = 2004;
			int m = Integer.parseInt(st.nextToken());
			int d = Integer.parseInt(st.nextToken());
			if (m == 0) break;
			if (m == 1 || m == 2) {
				y--;
				if (m == 1) m = 13;
				if (m == 2) m = 14;
			}
			ans.add(
					 (y + ( y / 4 ) - ( y / 100 ) + ( y / 400 ) + ( (13 * m + 8 ) / 5 ) + d) % 7 
			);
			
		}
		
		for (int a : ans) {
			
			switch (a) {
				case 0 : System.out.println("Sunday"); break;
				case 1 : System.out.println("Monday"); break;
				case 2 : System.out.println("Tuesday"); break;
				case 3 : System.out.println("Wednesday"); break;
				case 4 : System.out.println("Thursday"); break;
				case 5 : System.out.println("Friday"); break;
				case 6 : System.out.println("Saturday"); break;
			}
			
		}
	}
	
}

Measured memory_bytes: 8896
#include<iostream>
using namespace std;
int main(){
    int h,w,A[500][500];
    cin>>h>>w;
    for(int i=0;i<h;i ++){
        for(int j=0;j<w;j++) cin>>A[i][j];
    }
    int n=0,B[250000][4];
    for(int i=0;i<h;i++){
        for(int j=0;j<w-1;j++){
            if(A[i][j]%2==1){
                A[i][j]==0;
                A[i][j+1]++;
                B[n][0]=i+1,B[n][1]=j+1,B[n][2]=i+1,B[n][3]=j+2;
                n++;
            }
        }
    }
        for(int i=0;i<h-1;i++){
            if(A[i][w-1]%2==1){
                A[i][w-1]==0;
                A[i+1][w-1]++;
                B[n][0]=i+1,B[n][1]=w,B[n][2]=i+2,B[n][3]=w;
                n++;
            }
        }
    cout<<n<<endl;
    for(int i=0;i<n;i++) cout<<B[i][0]<<" "<<B[i][1]<<" "<<B[i][2]<<" "<<B[i][3]<<endl;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int ka[214514],inv[214514];
void setkaijo(int n){
	ka[0]=1;
	for(int i=1;i<=n;i++){
		ka[i] = ka[i-1] * i;
		ka[i] %= inf;
	}
}
int modpow(int x,int k){
	// x ^ k mod inf
	int res = 1;
	while(k>0){
		if(k%2)res = (res*x)%inf;
		x = (x*x)%inf;
		k >>=1;
	}
	return res;
}
void setinv(int n){
	for(int i=0;i<=n;i++){
		inv[i] = modpow(ka[i],(ll)inf-2);
	}
}
int comb(int n,int k){
	if( k<0 || n<0 || k>n)return 0;
	if(k==0 || k==n)return 1;
	int res = (ka[n] * inv[k]) % inf;
	res = (res*inv[n-k]) % inf;
	return res;
}
signed main(){
	int n,k;
	cin>>n>>k;
	setkaijo(210000);
	setinv(210000);
	int ans = 0;
	int ma = min( n-1, k );
	for(int i=0;i<=ma;i++){
		int c = 1;
		c *= comb( n, i );
		c *= comb( n-1, i );
		c %= inf;
		ans += c;
		ans %= inf;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main() {
    int a, b, c, d, e, x, y;
    cin >> a >> b >> c >> d >> e;
    x = a*e;
    y = b;
    if (e > c) y += d*(e-c);
    cout << min(x, y) << endl;
}

Measured memory_bytes: 1160
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 1e7 + 5;
const int P = 1e9 + 7;
int n,k;
int sil[MAX];
int mul(int a,int b){
  return a * b % P;
}
void sub(int &a,int b){
  a -= b;
  if(a < 0)a += P;
}
void add(int &a,int b){
  a += b;
  if(a >= P)
    a-=P;
}

int pot(int a,int w){
  int r = 1;
  while(w){
    if(w & 1){
      r = a * r % P;
    }
    w/=2;
    a = a * a % P;
  }
  return r;
}
const int MAXK = 5001;
int dwu[MAXK][MAXK];
int dp[MAXK];
int odw[MAXK];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> k;
  sil[0] = 1;
  R(i,n + 1){
    sil[i+1] = mul(sil[i], i+1);
  }
  R(i,k+1){
    odw[i] = pot(sil[i], P-2);
  }
  R(i,k+1)R(j,i+1){
    if(j == 0){
      dwu[i][j] = 1;
    }else{
      dwu[i][j] = dwu[i-1][j-1];
      add(dwu[i][j], dwu[i-1][j]);
    }
  }
  for(int i = 1; i <= k; i++){
    dp[i] = mul(i, sil[n - k + i - 1]);
    for(int j = 1; j < i; j++)
      sub(dp[i], mul(dwu[i][j], dp[j]));
  }
  int res = dp[k];
  vector<int> sum(k + 1);
  for(int i = k; i >= 2;i --){
    for(int z = 2; z <= i; z++){
      int mn = ((i + z)&1 ? P-1 : 1);
      mn = mul(mn, dwu[i-1][i-z]);
      mn = mul(mn, z-1);
      mn = mul(mn, sil[k-i]);
      debug(n,z,i);
      add(sum[z], mul(sil[n + z - i - 2], odw[k-i]));
      mn = mul(mn, sum[z]);
      add(res, mn);
    }
  }
  cout << res << "\n";
}


Measured memory_bytes: 198540
while True:
    m, f, r = map(int, input().split())
    if not (~ m or ~ f or ~ r):
        break
    if m == -1 or f == -1:
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65:
        print('B')
    elif m + f >= 50 or m + f >= 30 and r >= 50:
        print('C')
    elif m + f >= 30:
        print('D')
    else:
        print('F')

Measured memory_bytes: 7640
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
struct ToUpper {
    char operator()(char c) { return toupper(c); }
};
struct ToLower {
    char operator()(char c) { return tolower(c); }
};
const int N=200010;
const int P=1000000007;
using ll = long long;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
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;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/

/*
	char s[N];
	strlen(s)
*/

/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/

/*添字1がa個、2がb個
  vector<vector<ll>> map(a,vector<ll>(b));
*/

int main(){
	ll a,b=0,c,d,e;
	cin>>a;
    rep(i, 370){
      if(i==0)continue;
      if((i*a)%360==0){
        b=i;
        break;
      }
    }
	cout<<  b      <<endl;




}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define rep(i, n) rep2(i, 0, n)
using ll = long long;
using V = vector<int>;

char s[1000000];
ll t[3][1000001];

int main() {
  int n, q;
  scanf("%d%s%d", &n, s, &q);

  V D, C;
  rep(i, n) {
    rep(j, 3) t[j][i+1] = t[j][i];
    switch(s[i]){
      case 'D':
        ++t[0][i+1];
        D.push_back(i);
        break;
      case 'M':
        ++t[1][i+1];
        break;
      case 'C':
        ++t[2][i+1];
        C.push_back(i);
        break;
    }
  }

  ll suma = 0, sumc = 0;
  for (auto &a : D) suma += t[1][a+1] * t[2][a+1];
  for (auto &c : C) sumc += t[1][c] * t[0][c];

  rep(_, q) {
    int k; 
    scanf("%d", &k);
    ll ans = suma + sumc;
    for (auto &a : D) ans -= t[1][a+1] * t[2][min(a+k, n)];
    for (auto &c : C) ans -= t[1][c] * t[0][max(c-k+1, 0)];
    printf("%lld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 28652
def bubbleSort(A, N):
    count = 0
    for i in reversed(range(N)):
        for j in range(i):
            if A[j] > A[j+1]:
                # print(f"交換:{A[j]},{A[j+1]}")
                A[j], A[j+1] = A[j+1], A[j]
                count += 1
    output(A, count)

def output(A, N):
    for a in range(len(A)):
        if a == len(A)-1:
            print(A[a])
            print(N)
        else:
            print(A[a], end=" ")

def main():
    N = int(input())
    list = input().split(" ")
    list = [int(s) for s in list]
    
    bubbleSort(list, N)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5612
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int n,x[100][100],y[100][100];
int v[100][100],nv;

int rec(int cy,int cx)
{
	int &c=v[cy][cx];
	if(c==-2)return nv++,-2;
	if(c>=0)return c;
	c=-2;
	
	int ny=y[cy][cx],nx=x[cy][cx],r=rec(ny,nx);
	c=r==-2?nv-1:r;
	return r;
}

int main()
{
	while(scanf("%d",&n),n)
	{
		rep(i,n)rep(j,n)scanf("%d%d",x[i]+j,y[i]+j),v[i][j]=-1;
		nv=0;
		rep(i,n)rep(j,n)if(v[i][j]<0)rec(i,j);
		printf("%d\n",nv);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

#define REP(i, a, n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lwb lower_bound
#define N 100010
#define M 200010
#define endl "\n"

ll gcd(ll a_,ll b_){if(b_>a_)swap(b_,a_);return (b_==0?a_:gcd(b_,a_%b_));}		

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	string s, prev = "", curr = "";
	int k = 0, n;
	
	cin >> s;
	n = s.size();
	
	REP(i, 0, n){
		curr += s[i];
		if(curr != prev){
			k++;
		}
		else{
			int j = i + 1;
			curr += s[j];
			while(j < n){
				if(curr != prev){
					k++;
			//		cout << "curr = " << curr << endl;
			//		cout << "i = " << i << endl;
					break;
				}	
				j++;
				curr += s[j];
			}
			
			i = j;
		
		}
		prev = curr;
		curr = "";
	}
	
	cout << k << endl;
	
	return 0;
}


Measured memory_bytes: 720
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for(int b = 0;b<n;b++){
			a[b] = scan.nextInt();
		}
		for(int d = 1;d<=n;d++){
			System.out.print(a[n-d]);
			if(d==n){
				System.out.println("");
			}else{
				System.out.print(" ");
			}
		}
	}
}

Measured memory_bytes: 19656
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	
	vector<int> B(N); 
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	int a = 0;
	int b = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] >= B[i]) {
			b += A[i] - B[i];
		}
		else {
			a += (B[i] - A[i] + 1) / 2;
			b += (B[i] - A[i]) % 2;
		}
	}
	if (a >= b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	//cout << res << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a,b,c,d;
  double f;
  cin >>a>>b;
  c=a/b;
  d=a%b;
  f=(double)a/b;
  printf("%d %d %.5f\n",c,d,f);
    }



Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
 
int main(){
  int n;
  long long res = 0;
  
  cin >> n ;
  map<string,int> mp;
 
  rep(i,n){
     string s;
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  
  for(auto& p : mp){
    int r = p.second;
    res += (long long) r*(r-1)/2;
  }
  
    
    
  
  cout << res << endl;
}

Measured memory_bytes: 11136
inf = input().split()
X = int(inf[0])
Y = int(inf[1])
Z = int(inf[2])
K = int(inf[3])

A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
ab = []
for a in A:
  for b in B:
    ab +=[a+b]
ab.sort(reverse=True)
C.sort(reverse=True)
state = [[ab[0]+C[i],0,i] for i in range(len(C))]
count  = 0
while count<K:
  s = max(state)
  print(s[0])
  count +=1
  x = s[1]
  i = s[2]
  if x<X*Y-1:
    state[i][0] = C[i]+ab[x+1]
    state[i][1] = x+1
  else:
    state[i][0] = -1

Measured memory_bytes: 55456
#include<stdio.h>
#include<math.h>

int i,n,A[500000],count=0;

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

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

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

  return 0;
}

  



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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int h, w, n, a[10000], z[10000], x[100][100];

int c = 0;
void f(int i, int j) {
	x[i][j] = z[c++];
}

int main() {
	cin >> h >> w >> n;
	inc(i, n) { cin >> a[i]; }
	
	int k = 0;
	inc(i, n) {
		inc(j, a[i]) {
			z[k] = i + 1;
			k++;
		}
	}
	
	inc(i, h) {
		if(i % 2 == 0) {
			inc(j, w) {
				f(i, j);
			}
		} else {
			dec(j, w) {
				f(i, j);
			}
		}
	}
	
	inc(i, h) {
	inc(j, w) {
		cout << (j == 0 ? "" : " ") << x[i][j];
	} cout << "\n";
	}
	
	return 0;
}


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

int main()
{
	string S, T;
	cin >> S >> T;
	int a, b;
	cin >> a >> b;
	string U;
	cin >> U;
	if (U == S)
	{
		cout << a - 1 << " " << b << endl;
	}
	else
	{
		cout << a << " " << b - 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())

int main(int argc, char const *argv[])
{
	int a;
	long m = 100000;
	scanf("%d", &a);
	REP(i,a)
	{
		m = (float)m * 1.05;
		int a = m % 1000;
		if (a > 0)
			m += 1000 - a;
	}
	printf("%ld\n", m);
	return 0;
}

Measured memory_bytes: 3204