akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>

using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N;

int main() {
	cin >> N;
	ll oldn = N;
	ll f = 0;
	while (N > 0) {
		f += N % 10;
		N /= 10;
	}
	if (oldn % f == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N, M, L[100001], R[100001];
	scanf("%d %d", &N, &M);
	for (i = 1; i <= M; i++) scanf("%d %d", &(L[i]), &(R[i]));
	
	int L_max = 1, R_min = N;
	for (i = 1; i <= M; i++) {
		if (L[i] > L_max) L_max = L[i];
		if (R[i] < R_min) R_min = R[i];
	}
	
	if (R_min - L_max + 1 > 0) printf("%d\n", R_min - L_max + 1);
	else printf("0\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
 
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
 
 
 
 
int main(){
	int N,L;
	string a;
	vector<string> s;
	cin >> N >> L;
	FOR(i,N){
		cin >>a;
		s.PB(a);
	}
	sort(s.begin(),s.end());
	FOR(i,N) cout <<s[i];	
	
	return 0;
}

Measured memory_bytes: 256
int main(void){
    int n,x;
    scanf("%d",&n);
 
    for(int i = 1; i<= n; i++){
        if(i%3 == 0){
            printf(" %d",i);
        }
        else{
            x = i;
            do{
                if(x%10 == 3){
                    printf(" %d",i);
                    break;
                }
                x /=10;
            }while(x);
        }
    }
    printf("\n");
}


Measured memory_bytes: 2108
#include <iostream>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n, d, x;
	cin >> n >> d >> x;
	for (int i = 0; i < n; ++i)
	{
		int a;
		cin >> a;
		x += (d - 1) / a + 1;
	}
	cout << x;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int n;
int par1[200010],par2[200010];
int rank1[200010],rank2[200010];

void init(){
    for(int i=0;i<n;i++){
        par1[i]=par2[i]=i;
    }
}

int find1(int x){
    if(par1[x]==x)return x;
    return par1[x]=find1(par1[x]);
}
void unite1(int x,int y){
    x=find1(x);
    y=find1(y);
    if(x==y)return;
    if(rank1[x]<rank1[y]){
        par1[x]=y;
    }else{
        par1[y]=x;
        if(rank1[x]==rank1[y])rank1[x]++;
    }
}

int find2(int x){
    if(par2[x]==x)return x;
    return par2[x]=find2(par2[x]);
}
void unite2(int x,int y){
    x=find2(x);
    y=find2(y);
    if(x==y)return;
    if(rank2[x]<rank2[y]){
        par2[x]=y;
    }else{
        par2[y]=x;
        if(rank2[x]==rank2[y])rank2[x]++;
    }
}

int main(){
    int k,l;
    cin>>n>>k>>l;
    init();
    for(int i=0;i<k;i++){
        int p,q;
        cin>>p>>q;
        unite1(--p,--q);
    }
    for(int i=0;i<l;i++){
        int r,s;
        cin>>r>>s;
        unite2(--r,--s);
    }
    map<pair<int,int>,int> map;
    for(int i=0;i<n;i++){
        map[make_pair(find1(i),find2(i))]++;
    }
    for(int i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<map[make_pair(find1(i),find2(i))];
    }
    cout<<endl;
}


Measured memory_bytes: 13696
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}	
int a[114514];
int b[114514];
signed main(){
	ic(n) ic(k)
	int mi=0,pl=0;
	rep(0,i,n){
		cin>>a[i];
		if(a[i]<=0)mi++;
		else pl++;
	}
	int ans=1234567890123456;
	if(pl==0){
		c(abs(a[n-k]))
		return 0;
	}	
	rep(k-pl,i,mi+1){
		int sum=0;
		if(i==0)sum=a[mi+k-1];
		else sum=abs(a[mi-i])+a[mi+k-i-1]+min(abs(a[mi-i]),a[mi+k-i-1]);
		if(ans>sum)ans=sum;
	}
	c(ans)
}
		




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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	string s, t;
	cin >> s >> t;

	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		ans += s[i] == t[i];
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define pb push_back
#define mp make_pair
#define f first
#define s second
int main()
{
	ll n,x,t,val;
	cin>>n>>x>>t;
    val=n/x;
    if (n%x)
    {
    	val++;
    }
    cout<<val*t<<endl;
	return 0;
}


Measured memory_bytes: 3604
#include<iostream>
using namespace std;
char n;
int main()
{
	while(cin>>n)
	{
		if(n=='A')
		{
			cin>>n;
			if(n=='C')
			{
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int  long long int
const int N = 1e+5;
int dp[N];
int n,k;
int helper(int i,vector<int> & v)
{
	
	if(i==n)
	{
		return 0;
	}
	if(dp[i]!=-1)
	{
		return dp[i];
	}

	int ans = INT_MAX;
	for(int j=1;j<=k;j++)
	{
		if(i+j<=n)
		{
			ans = min(ans,helper(i+j,v)+abs(v[i]-v[i+j]));
		}
	}

	return dp[i] = ans;

}
int32_t main()
{
	cin>>n>>k;
	memset(dp,-1,sizeof(dp));
	vector<int> v(n+1);
	for(int i=1;i<=n;i++)
	{
		cin>>v[i];
	}

	int ans = helper(1,v);

	cout<<ans<<endl;

	return 0;

}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n)
  {
    int s[n],sum=0;
    for (int i = 0; i < n; ++i) cin>>s[i],sum+=s[i];
    double ave=(double)sum/n,ans=.0;
    for (int i = 0; i < n; ++i) ans+=(s[i]-ave)*(s[i]-ave);
    printf("%.5f\n",sqrt(ans/n));
  }
}


Measured memory_bytes: 3156
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//#define int long long  ←保留
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/*-------------ここまで---------------------------------------------*/

//C++(GCC9.2.1)

/*signed*/int main() {
    int k, x;
    cin >> k >> x;
    for (int i = x - k + 1; i < x + k; ++i) cout << i << " ";
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long ll;

int N;
ll K;
int A[200000 + 10];

bool visited[200000 + 10];

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

	vector<int> cycle;
	cycle.push_back(0);
	int pos = 0;
	visited[0] = true;
	do {
		pos = A[pos] - 1;
		if (visited[pos])break;
		cycle.push_back(pos);
		visited[pos] = true;
	} while (1);
	int start = 0;
	for (; start < cycle.size(); start++) {
		if (cycle[start] == pos)break;
	}
	if (K <= start) {
		cout << cycle[K] + 1 << endl;
		return 0;
	}
	vector<int> newcycle;
	for (int i = start; i < cycle.size(); i++)newcycle.push_back(cycle[i]);

	cout << newcycle[(K - (ll)start) % newcycle.size()] + 1 << endl;

	return 0;
}

Measured memory_bytes: 6168
// In the name of god
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5*2+5;
long long n,k,a[maxn],sum;
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n-k;i++){
		sum+=a[i];
	}
	cout<<sum;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int mx = 0;
    rep(i, n) {
        if (i != n-1) chmax(mx, a[i+1] - a[i]);
        else chmax(mx, (k+a[0]) - a[n-1]);
    }
    int ans = k - mx;
    cout << ans << endl;
}


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  int N, M;
  cin >> N >> M;

  vector<double> L(N), a(N), b(N);

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

  double ans = 0;
  for ( int i = 0; i < (1<<N); i++ ) {
    if ( __builtin_popcount(i) != M ) continue;
    vector<int> sub;      
    for ( int j = 0; j < N; j++ ) {
      if ( (1<<j) & i ) sub.emplace_back(j);      
    }
    double tmp = 0;
    for ( int j = 0; j < M; j++ ) {
      for ( int k = j+1; k < M; k++ ) {
	tmp += pow(abs(L[sub[j]]-L[sub[k]]), 2);
	tmp += pow(abs(a[sub[j]]-a[sub[k]]), 2);
	tmp += pow(abs(b[sub[j]]-b[sub[k]]), 2);	
      }
    }
    ans = max(ans, tmp);
  }

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



Measured memory_bytes: 3304
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    dp = [0] * (n + 1)
    dp[0] = 1
    for p in map(float, input().split()):
        ndp = [0] * (n + 1)
        for i in range(n):
            ndp[i + 1] += dp[i] * p
        for i in range(n):
            ndp[i] += dp[i] * (1 - p)
        dp = ndp

    res = 0
    for i in range(n + 1):
        if 2 * i > n:
            res += dp[i]
    print(res)
resolve()

Measured memory_bytes: 54364
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

typedef long long ll;

using namespace std;

vector<vector<int>> E;
vector<int> pr, m;
vector<map<int, ll> > dp;
vector<ll> ans;

void dfs(int v) {
	for (int to : E[v]) if (to != pr[v]) {
		pr[to] = v;
		dfs(to);
	}
}

ll Q(int v, int x) {
	ll &cur = dp[v][x];
	if (cur > 0) return cur - 1;
	
	cur = 0;
	for (int to : E[v]) if (to != pr[v] && to < x) {
		cur += Q(to, x) + 1;
	}
	cur++;
	return cur - 1;
}

void calc(int v) {
	if (pr[v] == -1) {
		ans[v] = 1;
		m[v] = pr[v];
	} else {
		m[v] = max(pr[v], m[pr[v]]);
		ans[v] = ans[pr[v]];
		if (v > m[pr[v]]) ans[v] += Q(v, m[v]) + 1;
		else ans[v] += Q(v, m[v]) - Q(v, m[pr[v]]);
	}
	for (int to : E[v]) if (to != pr[v])
		calc(to);
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n; cin >> n;
	dp.resize(n), pr.resize(n, -1), E.resize(n), ans.resize(n), m.resize(n);
	
	for (int i = 0; i + 1 < n; i++) {
		int a, b;
		cin >> a >> b;
		E[a - 1].push_back(b - 1);
		E[b - 1].push_back(a - 1);
	}
	dfs(0);
	calc(0);
	for (int v = 1; v < n; v++) cout << ans[v] - 1 << " \n"[v == n - 1];
	return 0;
}


Measured memory_bytes: 53248
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  vint num(n) ;
  int nf = 0 ;
  int nk = 0 ;
  REP(i,n){
    cin >> num[i] ;
    if(num[i]%2==1){
      nk++ ;
    }
    else if(num[i]%4==0){
      nf++ ;
    }
  }
  
  if(nf>=nk){
    yes() ;
  }
  else if(nf==nk-1){
    if(n==nf+nk){
      yes() ;
    }
    else{
      no() ;
    }
  }
  else{
    no() ;
  }
  
  
  
  
  return 0 ;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

const int N = 100100;

int dp[3][N];
int a[N], b[N], c[N];

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i] >> b[i] >> c[i];
  }
  dp[0][0] = a[0];
  dp[1][0] = b[0];
  dp[2][0] = c[0];
  for (int i = 1; i < n; ++i) {
    dp[0][i] = a[i] + max(dp[1][i - 1], dp[2][i - 1]);
    dp[1][i] = b[i] + max(dp[0][i - 1], dp[2][i - 1]);
    dp[2][i] = c[i] + max(dp[1][i - 1], dp[0][i - 1]);
  }

  cout << max(dp[0][n - 1], max(dp[1][n - 1], dp[2][n - 1])) << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> vec(3);
  for (int i = 0; i < 3; i++) {
    cin >> vec[i];
  }
  sort(vec.begin(), vec.end());
  cout << vec[0] + vec[1] << endl;
  return 0;
}

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

int main(){
		
char a;

cin >> a;

if(a=='A'||a=='B'||a=='C'||a=='D'||a=='E'||a=='F'||a=='G'||a=='H'||a=='I'||a=='J'||a=='K'||a=='L'||a=='M'||a=='N'||a=='O'||a=='P'||a=='Q'||a=='R'||a=='S'||a=='T'||a=='U'||a=='V'||a=='W'||a=='X'||a=='Y'||a=='Z'){
cout << 'A' << endl;	
}else{
	cout << 'a' << endl;
}
	
return 0;	
}


Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <algorithm>

#define SIZE 120

using namespace std;

int digitSum(int);

int main(int argc, char const *argv[])
{
    int N, x;
    cin >> N >> x;
    int a[SIZE];
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    sort(a, a+N);
    int cnt = 0;
    for(int i=0; i<N; i++){
        x -= a[i];
        if(x < 0){
            cout << i;
            return 0;
        }else if(x==0){
            cout << i+1;
            return 0;
        }
    }
    cout << N-1;
    return 0;
}

int digitSum(int a){
    if(a==0){
        return 0;
    }
    return a%10 +digitSum(a/10);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <iterator>
#include <limits>
#include <numeric>
#include <type_traits>
#include <cmath>
#include <cstdlib>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

#define ALL(v) (v).begin(), (v).end()
#define endl "\n"
typedef long long int ll;

template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
	for (int i = 0; i<vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

int SumDigitValues(int x)
{
	int sum = 0;
	while (x)
	{
		sum += x % 10;
		x = x / 10;
	}

	return sum;
}

int Factorial(int n)
{
	if (n < 0) return 0;
	if (n == 0) return 1;
	return n * Factorial(n - 1);
}

int factorial(int n)
{
	if (n > 1)
	{
		return n * factorial(n - 1);
	}
	else
	{
		return 1;
	}
}

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

vector<int> Divisors(int x)
{
	vector<int> divisors;
	divisors.push_back(1);
	for (int a = 2; a <= x; a++)
	{
		if (x % a == 0) divisors.push_back(a);
	}
	return divisors;
}

vector<int> CommonDivisors(int a, int b)
{
	vector<int> divisorsA = Divisors(a);
	vector<int> divisorsB = Divisors(b);
	vector<int> commonDivisors;
	set_intersection(divisorsA.begin(), divisorsA.end(), divisorsB.begin(), divisorsB.end(), std::back_inserter(commonDivisors));
	return commonDivisors;
}

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

	string s; cin >> s;
	if (s[0] == s[1] or s[1] == s[2] or s[2] == s[3])
		cout << "Bad" << endl;
	else
		cout << "Good" << endl;
}

Measured memory_bytes: 256
n, p = map(int, input().split())
if n == 1 or p== 1:
    print(p)
    exit()
c2 = 0
while p%2 == 0:
    c2 += 1
    p//=2
c = 2**(c2//n)
i = int(p**(1/n))+1
if i%2 == 0:
    i -= 1
while i > 1:
    if p%(i**n) == 0:
        print(c*i)
        exit()
    else:
        i -= 2
print(c)

Measured memory_bytes: 3060
$<.each_line do |line|
	n, x = line.split.map(&:to_i)
	break if n.zero? and x.zero?

	rslt = 0
	([1, x - 2 * n + 1].max..[(x / 3 - 1), n - 2].min).each do |a|
		rem = x - a
		rslt += (rem - 1) / 2 - [a + 1, rem - n].max + 1
	end

	p rslt
end

Measured memory_bytes: 6100
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const int mod=1e9+7;
const ll inf = 1LL << 60;
const ld pi = (acos(-1));
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }





int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int n,d,x; cin >> n >> d >> x;
  vector<int> v(n);
  int ans=n;
  rep(i,0,n) {
  	cin >> v[i];
  	if(d-1>=v[i])ans+=(d-1)/v[i];
  }
  cout << ans+x << endl;
}

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

ll p[114514],q[114514],r[114514];
int main() {
	priority_queue<ll>que;
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	for(int i=0;i<a;i++){
		cin>>p[i];
		p[i]*=-1;
	}
	for(int i=0;i<b;i++){
		cin>>q[i];
		q[i]*=-1;
	}
	for(int i=0;i<c;i++){
		cin>>r[i];
	}
	sort(p,p+a);
	sort(q,q+b);
	for(int i=0;i<x;i++)que.push(-p[i]);
	for(int i=0;i<y;i++)que.push(-q[i]);
	for(int i=0;i<c;i++)que.push(r[i]);
	ll sum=0;
	for(int i=0;i<x+y;i++){
		ll yan=que.top();
		que.pop();
		sum+=yan;
	}
	cout<<sum;
	return 0;
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 1005;

int a[N];

int main() {

	FAST;

	int x;
	cin >> x;
	a[1] ++;
	for (int i = 2; i * i <= x; i ++) {
		int k = i;
		while (k <= x) {
			a[k] ++;
			k *= i;
		}
	}
	while (!a[x]) {
		x --;
	}
	cout << x << '\n';
	return 0;
}

Measured memory_bytes: 256
import math

S = int(input())
MOD = 10**9 + 7

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

MAXLEN = S // 3 # maximum length
cnt = 0

for i in range(1, MAXLEN+1):
    resid = S - 3 * i
    cnt += comb(i+resid-1, i-1)
    cnt = cnt % MOD

print(cnt)


Measured memory_bytes: 9224
n = int(input())
d = {}
cnt = 0
for i in range(n):
    s = input()
    s = list(s)
    s.sort()
    key = "".join(s)
    if key in d:
        cnt += d[key]
        d[key] += 1
    else:
        d[key] = 1
print(cnt)


Measured memory_bytes: 17852
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	A, B, C, D := ReadInt(), ReadInt(), ReadInt(), ReadInt()
	x := A * B
	y := C * D
	fmt.Println(Max(x, y))
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int h, n;
  cin >> h >> n;
  int sum = 0;
  REP(i, n) {
    int a;
    cin >> a;
    sum += a;
  }
  if (sum < h) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
from collections import Counter
import sys
n = int(input())
a = Counter(list(map(int,input().split())))

lis = sorted(a.items(), key = lambda z: z[0], reverse = True)
ans = []
for i in lis:
    if len(ans) == 0 and i[1] >= 4:
        print(i[0]**2)
        sys.exit()
    elif i[1] >= 2 and len(ans) <= 1:
        ans.append(i[0])
    else:
        pass
if len(ans) == 2:
    print(ans[0] * ans[1])
else:
    print(0)

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

int main(){
  int w[10],k[10];
  int sum1 = 0, sum2 = 0;

  for(int i = 0; i < 10; i++){
    cin >> w[i];
  }
  for(int i = 0; i < 10; i++){
    cin >> k[i];
  }
  
  sort(w, w+10);
  sort(k, k+10);

  for(int i = 0; i < 3; i++){
    sum1 += w[9-i];
    sum2 += k[9-i];
  }

  cout << sum1 << " " << sum2 << endl;

}

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

using namespace std;

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2 

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

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

ll f(ll x){
    ll sh=(1<<0),ret=0;

    while(sh <= x){

        ll bitnum = ((x+1)/(2*sh))*sh + max(((x+1)%(2*sh))-sh , 0LL);

        if(bitnum%2 == 1){
            ret += sh;
        }

        sh <<= 1;
    }

    return ret;
}

int main(){

    bool flag=true;

    ll ans=0,sum=0;
    
    ll a,b;
    cin >>a>>b;

    ans = f(max(a-1,0LL)) ^ f(b);
    cout << ans <<endl;

    /*for (ll i = a; i < b+1; i++)
    {
        cout << i << " -> "<<f(i)<<endl;
    }*/
    

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>


constexpr int MAXN = 500000;
int Heap[MAXN + 1];

int parent(int i) {return i / 2;}
int left(int i) {return i * 2;}
int right(int i) {return i * 2 + 1;}

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

void ShowHeap(int* Heap) {
    FOR(i, 1, n + 1) {
        std::printf("node %d: key = %d, ", i, Heap[i]);
        if (parent(i)) std::printf("parent key = %d, ", Heap[parent(i)]);
        if (left(i) <= n) std::printf("left key = %d, ", Heap[left(i)]);
        if (right(i) <= n) std::printf("right key = %d, ", Heap[right(i)]);
        std::cout << std::endl;
    }
}

void MaxHeapify(int* H, int i) {
    int l = left(i), r = right(i);
    int largest = i;
    if (l <= n && H[largest] < H[l]) {
        largest = l;
    }
    if (r <= n && H[largest] < H[r]) {
        largest = r;
    }
    if (largest != i) {
        std::swap(H[i], H[largest]);
        MaxHeapify(H, largest);
    }
}

void BuildHeap(int *H) {
    for (int i = n / 2; i >0; --i) {
        MaxHeapify(H, i);
    }
}


int main() {
    std::cin >> n;
    FOR(i, 0, n) std::cin >> Heap[i + 1];
    BuildHeap(Heap);
    FOR(i, 0, n) std::cout << " " << Heap[i + 1];
    std::cout << std::endl;
}


Measured memory_bytes: 5040
h,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
inf=10**10
dp=[inf]*(h+1)
dp[-1]=0

for a,b in ab:
    for i in range(h,0,-1):
        if i-a>=0:
            dp[i-a]=min(dp[i-a],dp[i]+b)
        else:
            dp[0]=min(dp[0],dp[i]+b)
print(dp[0])

Measured memory_bytes: 42732
from collections import deque
n,x,y=map(int,input().split())
G=[[10**5]*(n+2) for i in range(n+2)]
for i in range(n+2):
  G[i][i]=0
X=deque([i for i in range(1,n+1)])
Y=deque([i for i in range(1,n+1)])
V=[[0]*(n+2) for i in range(n+2)]
for i in range(1,n+1):
  V[i][i]=1
G[x][y]=1
G[y][x]=1
V[x][y]=1
V[y][x]=1
for i in range(n+2):
  V[0][i]=1
  V[n+1][i]=1
for i in range(1,n+1):
  V[i][0]=1
  V[i][n+1]=1
X.append(x)
X.append(y)
Y.append(y)
Y.append(x)
XX=[-1,0,0,1]
YY=[0,-1,1,0]
while len(X)>0:
  x=X[0]
  y=Y[0]
  X.popleft()
  Y.popleft()
  for i in range(4):
    if V[x+XX[i]][y+YY[i]]==0:
      X.append(x+XX[i])
      Y.append(y+YY[i])
      V[x+XX[i]][y+YY[i]]=1
      G[x+XX[i]][y+YY[i]]=G[x][y]+1
ans=[0]*n
for i in range(1,n+1):
  for j in range(1,n+1):
    ans[G[i][j]]+=1
for i in range(1,n):
  print(ans[i]//2)

Measured memory_bytes: 156680
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  string s;
  int ans=0,i,j;
  cin >> s;
  j=s.size()-1;
  for(i=0;i<=j;i++){
    if(s[i]!=s[j]){
      ans++;
    }
    j--;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
 ll N,T,A;
  cin>>N>>T>>A;
  ll place=0;
  double value;
  for(ll i=0;i<N;i++) {
    double H;
    cin>>H;
    H=T-H*0.006;
    if(place==0) {
place=1;
    value=abs(A-H);
    }
    
    else if(abs(A-H)<value) {
value=abs(A-H);
      place=i+1;
    }
  }
  
  
  cout<<place<<endl;
}
    

Measured memory_bytes: 3688
N, K = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]

cumu=[0]
for i in P:
    cumu.append(cumu[-1]+i+1)

ans = 0
for i in range(0, N-K+1):
    ans = max(cumu[i+K]-cumu[i], ans)

print(ans/2)

Measured memory_bytes: 25188
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]
data = sorted(data)
ind_mid = N // 2
ans = 0
if data[ind_mid] == data[ind_mid-1]:
    ans = 0
else:
    ans = data[ind_mid] - data[ind_mid-1]
print(ans)

Measured memory_bytes: 14120
#include <stdio.h>
#define MAX 100

int main(void){
 int A[MAX]={0},N,S=0;
 int a,b,c,min,tmp;

 scanf("%d",&N);

 for(a=0;a<N;a++){
  scanf("%d",&A[a]);
 }

 for(b=0;b<N;b++){
  min=b;
  for(c=b;c<N;c++){
   if(A[c]<A[min]){min=c;}
  }
  if(A[b]!=A[min]){
      S++;
      tmp=A[b];
      A[b]=A[min];
      A[min]=tmp;
  }
 }

 for(a=0;a<N;a++){
  printf("%d",A[a]);
  if(a!=N-1){printf(" ");}
 }
 
 printf("\n%d\n",S);
 
 return 0;
}

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

int findSumOfDigits(int n) {
	int sum=0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}
	return sum;

}

int main() {
	int N;
	cin >> N;
	int  ans = 10000;

	for (int i = 1; i < N; i++) {
		ans =min( findSumOfDigits(i) + findSumOfDigits(N - i),ans);

	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <math.h>
#include <map>
#include <numeric>
#include <stack>
#include <queue>
#include <functional>
#include <stdio.h>
#define ll long long
#define pl pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define vvvb vector<vector<vector<bool> > >
#define rep(i,a) for(ll i = 0;i<a;++i)
#define rep1(i,a) for(ll i = 1;i<a;++i)
#define rrep(i,a) for(ll i = a;i>=0;--i)
#define mod 1000000007
#define inf 10010010010
using namespace std;

//O(logB)
ll mpow(ll a, ll b, ll m){
	if (!b) return 1 % m;
	if (b == 1) return a % m;
	if (b % 2) return (a*mpow(a, b - 1, m)) % m;
	else return mpow((a*a) % m, b / 2, m) % m;
}

int main(){
	ll n;
	cin >> n;
	vl a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	if (n == 1){
		if (a[0] == 0) cout << 1 << endl;
		else cout << 0 << endl;
		return 0;
	}
	if (n % 2 == 0){
		if (a[0] != 1){
			cout << 0 << endl;
			return 0;
		}
		for (ll i = 0; i < n; i += 2){
			if (i == n - 2){
				if (a[i] != a[i + 1]){
					cout << 0 << endl;
					return 0;
				}
			}
			else{
				if (a[i] != a[i + 1] || a[i] + 2 != a[i + 2]){
					cout << 0 << endl;
					return 0;
				}
			}
		}
		cout << mpow(2, n / 2, mod) << endl;
	}
	else{
		if (a[0] != 0){
			cout << 0 << endl;
			return 0;
		}
		for (ll i = 1; i < n; i += 2){
			if (i == n - 2){
				if (a[i] != a[i + 1]){
					cout << 0 << endl;
					return 0;
				}
			}
			else{
				if (a[i] != a[i + 1] || a[i] + 2 != a[i + 2]){
					cout << 0 << endl;
					return 0;
				}
			}
		}
		cout << mpow(2, n / 2, mod) << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
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>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> q;
    multimap<string, int> mp;
    while(q--) {
        int t;
        cin >> t;
        if(t == 0) {
            string key;
            int x;
            cin >> key >> x;
            mp.emplace(key, x);
        } else if(t == 1) {
            string key;
            cin >> key;
            for(auto itr = mp.lower_bound(key); itr != mp.upper_bound(key); itr = next(itr)) {
                cout << itr->second << '\n';
            }
        } else if(t == 2) {
            string key;
            cin >> key;
            mp.erase(key);
        } else {
            string l, r;
            cin >> l >> r;
            for(auto itr = mp.lower_bound(l); itr != mp.upper_bound(r); itr = next(itr, 1)) {
                cout << *itr << '\n';
            }
        }
    }
}


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

#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;



signed main(){

#ifndef ONLINE_JUDGE
	//freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);
    
    int n;
    cin >> n;
    vi d1(n) , d2(n);
    fo(i , n){
        cin >> d1[i] >> d2[i];
    }
    bool ans = 0;
    fo(i , n - 2){
        bool ok = 1;
        ok &= d1[i] == d2[i];
        ok &= d1[i + 1] == d2[i + 1];
        ok &= d1[i + 2] == d2[i + 2];
        ans |= ok;
    }

    cout << (ans ? "Yes\n" : "No\n") ;

    return 0;

}



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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
auto& errStream=cerr;
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

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

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int n=read();
	string s=readString();
	int q=read();
	vi k(q);
	REP(i,q)
		k[i]=read();
	vi ac(n+1,0),dp(n+1,0);
	const auto SumA=[&](int l,int r){
		if(r<=l)return int(0);
		int res=ac[r-1];
		if(l-1>=0)
			res-=ac[l-1];
		return res;
	};
	const auto SumD=[&](int l,int r){
		if(r<=l)return int(0);
		int res=dp[r-1];
		if(l-1>=0)
			res-=dp[l-1];
		return res;
	};
	vi ans(q,0);
	int cur=0;
	REP(i,n){
		if(s[i]=='D'){
			ac[i]++;
			dp[i]+=cur;
		}else if(s[i]=='M'){
			cur++;
		}else if(s[i]=='C'){
			REP(j,q){
				int idx=max(int(0),i-k[j]+1);
				//if(idx>=0){
					int a=SumA(idx,i);
					int b=cur*a-SumD(idx,i);
					ans[j]+=b;
				//}
			}
		}
		ac[i+1]+=ac[i];
		dp[i+1]+=dp[i];
	}
	cerr<<ac<<endl;
	cerr<<dp<<endl;
	for(auto v:ans)
		print(v);
}


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

namespace Algorithm
{
    class Program
    {
        const int ShopCount = 10;
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var array = new int[S.Length];
            for (var i = 0; i < S.Length; i++)
                array[i] = int.Parse(S[i].ToString());

            var ope = "";
            for (var bit = 0; bit < (1 << array.Length); bit++)
            {
                var total = 0;
                for (var i = 0; i < array.Length; i++)
                {
                    if (i == 0)
                        total += array[i];
                    else
                    {
                        if ((bit & (1 << i)) != 0)
                        {
                            total += array[i];
                            ope += "+";
                        }
                        else
                        {
                            total -= array[i];
                            ope += "-";
                        }
                    }
                }
                if (total == 7)
                    break;
                ope = "";
            }

            Console.WriteLine($"{array[0]}{ope[0]}{array[1]}{ope[1]}{array[2]}{ope[2]}{array[3]}=7");
        }
    }
}


Measured memory_bytes: 13268
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
import Data.Char
import Data.Int
import Data.List
import Control.Monad
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS
import Data.Monoid

exEuclid :: (Eq a, Integral a) => a -> a -> (a, a, a)
exEuclid !f !g = loop 1 0 0 1 f g
  where loop !u0 !u1 !v0 !v1 !f 0 = (f, u0, v0)
        loop !u0 !u1 !v0 !v1 !f g =
          case divMod f g of
            (q,r) -> loop u1 (u0 - q * u1) v1 (v0 - q * v1) g r

modulo = 10^6+3 :: Int64
addMod, subMod, mulMod, divM :: Int64 -> Int64 -> Int64
addMod !x !y = (x + y) `rem` modulo
subMod !x !y = (x - y) `mod` modulo
mulMod !x !y = (x * y) `rem` modulo
recipM :: Int64 -> Int64
recipM !x = case exEuclid x modulo of
             (1,a,_) -> a `mod` modulo
             (-1,a,_) -> (-a) `mod` modulo
divM !x !y = x `mulMod` recipM y

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  N x + N y = N ((x + y) `rem` modulo)
  N x - N y = N ((x - y) `mod` modulo)
  N x * N y = N ((x * y) `rem` modulo)
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined

instance Fractional N where
  N x / N y = N (divM x y)
  recip (N x) = N (recipM x)
  fromRational = undefined

factL :: [N]
factL = 1 : zipWith (*) factL (map fromInteger [1..])
factFrom :: Integer -> N -> [N]
factFrom n v0 = let xs = v0 : zipWith (*) xs (map fromInteger [n+1..])
                in xs
factV :: V.Vector N
factV = sl 200000 factL
  <> sl (500000 - 200000) (factFrom 200000 177247)
  <> sl (700000 - 500000) (factFrom 500000 2)
  <> sl (total - 700000) (factFrom 700000 426941)
  where
    total = fromIntegral modulo :: Int
    sl n xs = V.fromListN n (take n xs)
factM :: Int64 -> N
factM n | n < modulo = factV V.! fromIntegral n
        | otherwise = 0

solve :: Int -> Int -> Int -> N
solve x 0 n = (fromIntegral x)^n
solve !x !d !n = let !x' = fromIntegral x :: N
                     !d' = fromIntegral d :: N
                     !xd = unwrapN (x' / d')
                 in if xd + fromIntegral n - 1 >= modulo
                    then 0
                    else d'^n * factM (xd + fromIntegral n - 1) / factM (xd - 1)

main = do
  q :: Int <- readLn
  replicateM_ q $ do
    [x,d,n] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
    print (solve x d n)


Measured memory_bytes: 176380
S = input()

n1 = int(S[0]) * 10 + int(S[1])
n2 = int(S[2]) * 10 + int(S[3])

if 0 < n1 < 13 and 0 < n2 < 13:
    print('AMBIGUOUS')
elif 0 < n1 < 13:
    print('MMYY')
elif 0 < n2 < 13:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int a[200007];
int main(){
	int n;
	int i,j,k;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0,j=n-1;j>=0;i++,j-=2){
		cout<<a[j];
		if(i!=n-1)cout<<" ";
		else cout<<endl;
	}
	for(j=n%2;j<n;j+=2){
		cout<<a[j];
		if(i!=n-1)cout<<" ";
		else cout<<endl;
	}
	return 0;
}
		


Measured memory_bytes: 2944
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {


    int a;
    cin >> a;
    string s;
    cin >> s;

    if (s.length() <= a) {
        cout << s;
    } else {
        for (int i = 0; i < a; i++) {
            cout << s[i];
        }
        cout << "...";
    }



    return 0;
}

Measured memory_bytes: 3628
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let v: Vec<i64> = read_vec();
    let n = v[0];
    let k = v[1];

    if k == 0 {
        println!("{:?}", n * n);
        return;
    }

    let mut ans = 0i64;
    for b in k + 1..n + 1 {
        let c = n / b;
        ans += c * (b - k);
        ans += std::cmp::max(n - c * b - k + 1, 0);
    }
    println!("{}", ans);
}


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

int main()
{
  ios::sync_with_stdio(false);
  int k, div, res;
  cin >> k;

  res = k % 2;
  div = k / 2;

  if (res)
    cout << (res + div) * div << "\n";
  else
    cout << div * div << "\n";

  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc163/tasks/abc163_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> v(N);
    REP(i, N - 1) {
        int t;
        cin >> t;
        v[t - 1]++;
    }
    for (auto &x : v)
        cout << x << "\n";

    return 0;
}


Measured memory_bytes: 4780
#include <cstdio>

int main () {
    int H, W;
    for (int i = 0;;i++) {
        scanf("%d %d", &H, &W);
        if (H == 0 && W == 0) break;
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 1000
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int A[MAX],B[MAX],C[MAX],ib[MAX],ic[MAX];
long long cb[MAX];

int main() {
	int n;cin>>n;
	rep(i,n) cin>>A[i];
	rep(i,n) cin>>B[i];
	rep(i,n) cin>>C[i];
	sort(A,A+n);
	sort(B,B+n);
	sort(C,C+n);
	int idx=0;
	rep(i,n) {
		while(B[idx]<=A[i]&&idx<n) idx++;
		ib[i]=idx;
	}
	idx=0;
	rep(i,n) {
		while(C[idx]<=B[i]&&idx<n) idx++;
		ic[i]=idx;
	}
	cb[n-1]=n-ic[n-1];
	for(int i=n-2; i>=0; i--) cb[i]=cb[i+1]+n-ic[i];
	long long ans=0;
	rep(i,n) if(ib[i]<n) ans+=cb[ib[i]];
	cout<<ans<<endl;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
        if(res>INT_MAX){
            return INT_MAX;
        }
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i));
        pro/=(i+1);
    }
    return pro;
}
vector<int> prime;
void seive(){
    vector<bool > isprime(101,true);
    for(int i=2;i*i<=100;i++){
        if(isprime[i]){
            for(int j=i*i;j<=100;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=100;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string str;
    cin>>str;
    int n=str.size();
    char ch='W';
    int count1=0,ans;
    for(int i=0;i<n;i++){
        if(ch==str[i]) continue;
        else{
            count1++;
            ch=str[i];
        }
    }
    ans=count1;
    count1=0;
    ch='B';
    for(int i=0;i<n;i++){
        if(ch==str[i]) continue;
        else{
            count1++;
            ch=str[i];
        }
    }
    ans=min(ans,count1);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

#define N 2000

int solve(int i,int m);

int a[N];
int n;

int main()
{
  int q,i,k;
  int m;
  

  scanf("%d",&n);

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

  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&m);
    k = solve(0,m);
    if(k > 0) printf("yes\n");
    else printf("no\n");
  }

  

  return 0;
}

int solve(int i,int m)
{
  int res;
  if(m == 0) return 1;
  if(i >= n) return 0;

  res = solve(i+1,m) + solve(i+1,m-a[i]);

  return res;
}




  
  



Measured memory_bytes: 2108
#include <stdio.h>

int dp[50];

int fib(int n){
  if( n == 0 || n == 1)
    return dp[n] = 1;
  if( dp[n] != -1)
    return dp[n];
  return dp[n] = fib( n - 1) + fib(n -2);
}

int main(){
  int n,i;
  for ( i = 0;i < 50; i++)
    dp[i] = -1;
  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}


Measured memory_bytes: 2056