akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;


main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    bool kt=false;
    while(n)
    {
        if(n%10==7) kt=true;
        n/=10;
    }
    if(kt) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 3652
#include <iostream>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
//x+1 = rx - D
int main()
{
    int r, D, x2000;
    cin >> r >> D >> x2000;
    int ans = x2000;
    REP(i,10){
        ans = r* ans -D;
        fin(ans);
    }
    return 0;
}

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

int dp[1000001], md = 1e9 + 7;

int main(){
	int n;
	scanf("%d", &n);
	dp[1] = n;
	int al = n;
	f(i, 2, n + 1){
		dp[i] = ((ll)(n - 1) * (n - 1) + al - dp[i - 2] + md) % md;
		int z = min(n - 1, n - 1 - (i - 3));
		dp[i] += z;
		if (dp[i] >= md)dp[i] -= md;
		al += dp[i];
		if (al >= md)al -= md;
	}
	printf("%d\n", dp[n]);
}


Measured memory_bytes: 4096
// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
signed main(void)
{
	reg int h;
	reg int ans=0,k=1;
	cin>>h;
	while(h)
	{
		h>>=1,ans+=k;
		k<<=1;
	}
	cout<<ans<<endl;
	return 0;
}



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

int main() {
  int N ;
  cin >> N ;
  vector<int64_t> luca(N+1);
  
  luca.at(0)=2;
  luca.at(1)=1;
  
  for(int i=2; i<N+1; i++){
    luca.at(i)=luca.at(i-1)+luca.at(i-2);
  }
  cout << luca.at(N) << endl;
  
}


Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    X, N = map(int,input().split())
    p = list(map(int,input().split()))
    p_new = [i - X for i in p]
    num = 0
    while num in p_new and -num in p_new:
        num += 1
    if X - num in p:
        print(X + num)
    else:
        print(X - num)

    
if __name__ == "__main__":
    main()

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

int main(){
    int N, B[100];
    cin >> N;
    for(int i=0; i<N-1; i++) cin >> B[i];
    int ans = B[0] + B[N-2];
    for(int i=0; i<N-2; i++) ans += min(B[i], B[i+1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define MOD 1000000007
#define pb push_back
#define int long long int

using namespace std;

int32_t main(void) {
    fast;
    int k, n, sum=0; cin>>n>>k;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a.begin(), a.end(), greater<int>());
    for(int i=k; i<n; i++) sum+=a[i];
    cout<<sum;
}



Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<set>
const int MaxN=100010;
int N;
struct item{int a,b;bool operator<(const item&it)const{return a<it.a;}}A[MaxN];
int main(){
	scanf("%d",&N);
	long long As=0,Bs=0,ans=0;
	for(int i=0;i<N;i++){
		scanf("%d%d",&A[i].a,&A[i].b);
		As+=A[i].a;
		Bs+=A[i].b;
		if(A[i].a>A[i].b){
			int t=A[i].a;
			A[i].a=A[i].b;
			A[i].b=t;
		}
	}
	ans=As<Bs?As:Bs;
	std::sort(A,A+N);
	As=Bs=0;
	for(int i=0;i<N;i++)As+=A[i].a;
	Bs=As+A[N-1].b-A[N-2].a;
	if(Bs<ans)ans=Bs;
	std::multiset<int>P,Q;
	for(int i=0;i<N;i++){
		P.insert(A[i].b);
	}
	Bs=0;
	for(int i=N;i--&&i>=N-i;){
		As-=A[i].a;
		if(Q.find(A[i].b)!=Q.end()){
			Q.erase(Q.find(A[i].b));
			Bs-=A[i].b;
		}
		else P.erase(P.find(A[i].b));
		while(Q.size()<N-i){
			int x=*P.begin();
			Q.insert(x);
			P.erase(P.find(x));
			Bs+=x;
		}
		if(As+Bs<ans)ans=As+Bs;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 5760
a,b = map(int,input().split())

if a%2 == 0 and b%2 == 0:
    ans = b^((b-a)//2)%2
elif a%2 == 0 and b%2 != 0:
    ans = ((b-a+1)//2)%2
elif a%2 != 0 and b%2 == 0:
    ans = a^b^((b-1-a)//2)%2
else:
    ans = a^((b-a)//2)%2

print(ans)

Measured memory_bytes: 3060
x, y, a, b, c = gets.chomp.split(" ").map(&:to_i)
red = gets.chomp.split(" ").map(&:to_i).sort.reverse
green = gets.chomp.split(" ").map(&:to_i).sort.reverse
colorless = gets.chomp.split(" ").map(&:to_i).sort
red = red[0...x]
green = green[0...y]
ans = 0
c.times do
    if !red.empty? && !green.empty? 
        break if red[-1] > colorless[-1] && green[-1] > colorless[-1]
        if red[-1] > green[-1]
            ans += [green.pop, colorless.pop].max
        else
            ans += [red.pop, colorless.pop].max
        end
    else
        break if red.empty? && green.empty?
        if red.empty?
            break if green[-1] > colorless[-1]
            ans += [green.pop, colorless.pop].max
        else
            break if red[-1] > colorless[-1]
            ans += [red.pop, colorless.pop].max
        end
    end
end
ans += red.inject(:+) if !red.empty?
ans += green.inject(:+) if !green.empty?
puts ans

Measured memory_bytes: 33932
#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 220000
using namespace std;
int fa[N],a[N],b[N],sum[N];
int n,m,bns,tot;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d",&a[i]),bns+=a[i]&1;
	if(bns>2){
		printf("Impossible\n");
		return 0;
	}
	for(int i=2;i<=m;i++){
		if((a[i]%2==1)&&(a[1]%2==0))swap(a[1],a[i]);
		if((a[i]%2==1)&&(a[m]%2==0))swap(a[m],a[i]);
	}
	for(int i=1;i<=m;i++)printf("%d ",a[i]);
	printf("\n");
	if(m==1){
		if(a[1]==1){
			printf("1\n");
			printf("1\n");
			return 0;
		}
		printf("2\n");
		printf("%d %d",a[1]-1,1);
		return 0;
	}
	int ans=m;
	if(a[1]==1)ans--;
	ans+=a[m]%2==0;
	printf("%d\n",ans);
	if(a[1]-1)printf("%d ",a[1]-1);
	for(int i=2;i<m;i++)printf("%d ",a[i]);
	if(a[m]&1)printf("%d ",a[m]+1);
	else printf("%d %d",a[m],1);
}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; //最大値

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main(){
    ll n; cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];
    ll res = 0, ans = 0;
    rep(i,n){
        if(res > A[i]){
            ans += (res - A[i]);
        }
        else{
            res = A[i];
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4836
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <functional>

using namespace std;

typedef long long ll;

int main() {
    string s, t;
    vector<string> ans;
    cin >> s >> t;
    for (int i = 0; i < s.size() - t.size() + 1; i++) {
        bool flag = true;
        for (int j = 0; j < t.size(); j++) {
            if (s[i + j] != '?' && s[i + j] != t[j])
                flag = false;
        }
        if (flag) {
            string tmp = s;
            for (int j = 0; j < t.size(); j++) {
                tmp[i + j] = t[j];
            }
            for (int k = 0; k < s.size(); k++){
                if (tmp[k] == '?'){
                    tmp[k] = 'a';
                }
            }
            ans.push_back(tmp);
        }
    }
    if (!ans.empty()) {
        sort(ans.begin(), ans.end());
        cout << ans[0] << endl;
    }
    else{
        cout << "UNRESTORABLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>

int main()
{
    unsigned int a,s;
    bool d = false;
    std::cin >> a;
    for(;a > 0;a--){
        s = (int)sqrt((double)a);
        if(s * s == a){
            break;
        }
    }
    std::cout <<a<<std::endl;
    return 0;
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
X = list(map(int, input().split()))
ans = 0
prev_x = X[0]
for i in range(1, N):
    walk_cost = A * (X[i] - prev_x)
    if walk_cost < B:
        ans += walk_cost
    else:
        ans += B
    prev_x = X[i]
print(ans)

Measured memory_bytes: 14252
#include <iostream>

using namespace std;

typedef long long ll;
#define x first
#define y second
#define mp make_pair

string s;
bool bio[2];

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s;
for(int i = 0 ; i < 3 ; ++i){
	bio[s[i] - 'A'] = 1;
}
int br = 0;
for(int i = 0 ; i < 2 ; ++i){
	br += bio[i];
}
if(br == 2){
	cout << "Yes" << endl;
}
else{
	cout << "No" << endl;
}

return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
h=list(map(int,input().split()))
x=[0]*n
y=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    x[a-1]+=1
    x[b-1]+=1
    if h[a-1]>h[b-1]:
        y[a-1]+=1
    elif h[b-1]>h[a-1]:
        y[b-1]+=1
ans=0
for i in range(n):
    if x[i]==y[i]:
        ans+=1
print(ans)

Measured memory_bytes: 19984
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    string S;
    cin >> S;
    ll ans = S.size();
    Rep (i, S.size()-1) {
        if (S[i] != S[i+1]) {
            ans = min(ans, max(i+1, (ll)S.size()-i-1));
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test1 {

    


    class ClassMain {

        public static string sousa(string str) {
            int renzoku = 0;
            char ch = str[0];
            StringBuilder resultstr = new StringBuilder();
            for (int i = 1; i < str.Length; i++) {
                if (str[i] == ch) {
                    renzoku++;
                }
                else {
                    resultstr.Append(renzoku+1);
                    resultstr.Append(ch);
                    ch = str[i];
                    renzoku = 0;
                }
            }
            resultstr.Append(renzoku+1);
            resultstr.Append(ch);
            return resultstr.ToString();
        }


        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                //int[] ints = line.Split(' ').Select(int.Parse).ToArray();
                int n = int.Parse(line);
                if(n==0){break;}
                int[] siki = new int[n];
                int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

                for (int i = 0; i < n; i++) {
                    siki[i] = ints[i];
                }
                long[,] check = new long[n, 21];
                check[0, ints[0]] = 1;
                for (int i = 1; i <= n - 1; i++) {
                    for (int j = 0; j <= 20; j++) {
                        if (check[i - 1, j] != 0) {
                            if (j + siki[i] <= 20) { check[i, j + siki[i]] += check[i - 1, j]; }
                            if (j - siki[i] >= 0) { check[i, j - siki[i]] += check[i - 1, j]; }
                        }
                    }
                }

                Console.WriteLine(check[n-2,siki[n-1]]);
            }
        }

        
    }



    
}

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

int main(){
  int N, D, X, a[1000] = {}, A;
  cin>>N;
  cin>>D>>X;

  for(int i = 1; i <= N; i++){
    cin>>A;
    for(int j = 1; j <= D; j += A){
      a[j] += 1;
    }
  }
  for(int i = 1; i <= D; i++){
    a[i] += a[i-1];
  }

  cout<<a[D]+X<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	/*if(b-a>=0) a=b-a;
	else a=(b-a)*-1;
	if(c-b>=0) b=c-b;
	else b=(c-b)*-1;*/
	if(b-a==c-b) printf("YES\n");
	else printf("NO\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define vpii vector<pair<int,int>> 
#define pb push_back

void solve() {
	int x;
	cin>>x;
	if(x>=30) {
		cout<<"Yes\n";
	}
	else cout<<"No\n";
}
 
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("ou.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tc=1;
    //cin>>tc;
    for(int t=1;t<=tc;t++) {
        //cout<<"Case #"<<t<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3624
using System;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		int[] A = Console.ReadLine().Split(' ').Select(a => int.Parse(a))
			.ToArray();

		if((double)A[1] >= (double)A[0] / (double)A[2]){
			Console.WriteLine("Yes");
		}
		else{
			Console.WriteLine("No");
		}
 
        //出力
	}
}

Measured memory_bytes: 28284
//        VIVEK UPADHYAY
//        MANIT, BHOPAL(M.P)
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define LINE cout<<endl
#define ok cout<<"ok\n" ;
typedef long long ll;
const int MAXN = 1e5 + 10 ;
const int MAX = 1e7 ;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e18 ;

int main(){
    
    vector<int> a(3) ;
    for(int i=0;i<3;i++)
        cin >>a[i] ;
    sort(a.begin(),a.end());
    int sum =0 ;
    for(int i=1;i<3;i++)
        sum+=a[i]-a[i-1] ;
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5,mod=998244353;
ll n,a,b,k,fac[N],f[N];
void init(){
	fac[0]=1;
	for(ll i=1;i<N;i++)	fac[i]=(fac[i-1]*i)%mod;
}
ll powmod(ll x,ll n){
	ll s=1;
	while(n){
		if(n&1)	s=(s*x)%mod;
		x=(x*x)%mod;
		n>>=1;	
	}
	return s;
}
ll C(int n,int m){
	if(n<m)
		return 0;
	ll a=fac[n],b=(fac[n-m]*fac[m])%mod;
	return (a*powmod(b,mod-2))%mod;
}
int main()
{
	init();
	cin>>n>>a>>b>>k;
	if(a>b)	swap(a,b);
	ll res=0;
	for(ll x=0;x<=n;x++)
	{
		ll ned=k-x*a;
		if(ned<0||ned%b)	continue;
		ll m=ned/b;
		f[x]=((C(n,x)*C(n,m))%mod - f[x+1] + mod )%mod;
		res=(res+f[x])%mod;
	}
	cout<<res<<'\n';
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<string>

using namespace std;

int main()
{
	int N;
	string S;

	cin >> N >> S;

	int *w,*b;

	w = new int[N+1];
	b = new int[N+1];

	int ans = N;

	int cntw = 0,cntb = 0;

	w[0] = 0;
	b[0] = 0;

	for(int i=1;i<=N;i++)
	{
		if(S[i-1] == '#')cntb++;
		if(S[i-1] == '.')cntw++;
		b[i] = cntb;
		w[i] = cntw;
	}

	for(int i=0;i<N+1;i++)
	{	
		ans = min(ans,b[i]+w[N]-w[i]);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2180
n, k = gets.strip.split.map(&:to_i)
ary = gets.strip.split.map(&:to_i).sort.reverse
if k != 0 && k < n
  ary.shift(k)
  puts ary.inject(&:+)
elsif k >= n
  puts 0
else
  puts ary.inject(&:+)
end



Measured memory_bytes: 21360
#include <iostream>
#include <cstdio>
using namespace std;
int h, w, n, x, y, d;
int ans[110][110];
int main(){
	scanf("%d%d%d", &h, &w, &n);
	int a; x=d=1; y=0;
	for(int i=1;i<=n;i++){
		scanf("%d", &a);
		while(a--){
			y+=d;
			if(y==0) x++, y=1, d=1;
			else if(y==w+1) x++, y=w, d=-1;
			ans[x][y]=i;
		}
	}
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			printf("%d%c", ans[i][j], j==w?'\n':' ');
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int d = sc.nextInt();
        int t = sc.nextInt();
        int s = sc.nextInt();
        pw.println(d <= t*s ? "Yes" : "No");
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

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

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


Measured memory_bytes: 32684
//AnikModak
#include<iostream>
using namespace std;

int main()
{
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;

    long long ans=0,mx;
    if(a+b>=2*c){
        if(x>y){
            ans=2*y*c;
            ans+=(x-y)*a;
        }
        else{
            ans=2*x*c;
            ans+=(y-x)*b;
        }
    }
    else ans=x*a+y*b;

    mx=2*max(x,y)*c;
    ans=min(mx,ans);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (int)(n); i++)
 
int main() {
    ll n;
    cin>>n;
    vector<ll> hon={2,4,5,7,9};
    vector<ll> pon={0,1,6,8};
    vector<ll> bon={3};
    n%=10;
    rep(i,hon.size()){
        if (n==hon.at(i)){
            cout<<"hon"<<endl;
            return 0;
        }
    }
    rep(i,pon.size()){
        if (n==pon.at(i)){
            cout<<"pon"<<endl;
            return 0;
        }
    }
    rep(i,bon.size()){
        if (n==bon.at(i)){
            cout<<"bon"<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INFL = 1e18;
const int INF = 1e9;
const int MN = 5050;
ll ord[MN];
ll w[MN];
ll dt[MN];
ll dp[MN][MN];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	ll a,b;
	cin >> a >> b;
	for(int i=0;i<n;i++) {
		cin >> w[i];
		w[i]--;
		ord[w[i]] = i+1;
	}
	memset(dp,0,sizeof(dp));
	for(int i=0;i<n;i++) {
		ll ma = INFL;
		for(int j=0;j<=n;j++) {
			if(i > 0) {
				ma = min(ma,dp[i-1][j]);
				if(j == ord[i-1]) {
					ma = min(ma,dt[i-1]);
				}
			} else {
				ma = 0;
			}
			if(j == ord[i]) {
				dt[i] = ma;
			}
			dp[i][j] = ma+(j>=ord[i]?a:b);
		}
	}
	ll res = INFL;
	for(int i=0;i<=n;i++) {
		res = min(res,dp[n-1][i]);
	}
	res = min(res,dt[n-1]);
	cout << res << '\n';
}


Measured memory_bytes: 199680
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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

ll GCD(ll a, ll b) {
	return a * b / LCM(a, b);
}


int main() {
	ll n, m;
	string s, t;
	cin >> n >> m >> s >> t;
	ll L = LCM(n, m);
	ll res = n / L * m;
	n /= L, m /= L;
	bool exist = true;
	for (ll i = 0; i < L; ++i) {
		if (s[i*n] != t[i*m]) exist = false;
	}
	if(exist) cout << res << endl;
	else cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)
#define all(c) begin(c),end(c)
#define vmax(c) *max_element(all(c))
#define vmin(c) *min_element(all(c))
 
template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const long long INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9; 

// 多次元配列を作る
// vector<vi> my_vector(n, vi(m, 0));

// 多次元配列の dump
// for (vi v : my_vector) {
//     cout << v;
// }

int solve() {
    ll a, b;
    char c;

    while( cin >> c ) {
        // cout << c;
        if (c == '1') {
            ++a;
        } else {
            ++b;
        }
    }
    ll m = min(a, b) * 2;
    return m;
}

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

    ll res = solve();
    cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define ranger(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define repr(i, b) for (int i = (b) - 1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S>& p) {
	os << '(' << p.first << ',' << p.second << ')';
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}


const int kN = 1000000;
void primeNumber(bool prime[kN]){
	rep(i,kN) prime[i] = 1;
	prime[0] = prime[1] = 0;
	rep(i,kN){
		if(prime[i]){
			for(int j = i + i; j < kN; j+=i){
				prime[j] = 0;
			}
		}
	}
}

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

	bool p[kN];
	primeNumber(p);
	for(; not p[x]; x++){

	}
	cout << x << endl;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    
    for(int i = 0; i < n ; i++){
        // printf("---------\n");
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    
    
    int tmp1, tmp2;
    tmp1 = d[(n/2) - 1];
    tmp2 = d[(n/2)];

    int ans = tmp2 - tmp1;

    cout << ans << endl;
}

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

void stupid(){
    int N,M;
    std::cin>>N>>M;
    std::vector<std::pair<int,int> > edges(M);
    for(auto& edge:edges){
        std::cin>>edge.first>>edge.second;
    }
    std::vector<int>dp(N*N,0);
    for(int i=1;i<N;++i){
        for(int j=0;j<M;++j){
            int start=edges[j].first,end=edges[j].second;
            if(start <= i && end <= i){
                dp[i*N+end]=std::max(dp[(i-1)*N+end],dp[(i-1)*N+start]+1);
            }
        }
    }
    auto maxitr=std::max_element(dp.end()-N-1,dp.end());
    std::cout<<*maxitr<<std::endl;
}
class dp{
    public:
    std::vector<int> dplog;
    std::vector<bool> flags;
    std::vector<std::pair<int,int> >edges;
    std::vector<std::vector<int> >degs;
    dp(int N,int M){
        dplog=std::vector<int>(N,0);
        flags=std::vector<bool>(N,0);
        edges=std::vector<std::pair<int,int> >(M);
        degs=std::vector<std::vector<int> >(N);
    }
    int f(int x){
        if(flags[x]){
            return dplog[x];
        }
        flags[x]=1;
        int ans=0;
        for(auto i:degs[x]){
            ans=std::max(ans,1+f(i));
        }
        dplog[x]=ans;
        return ans;
    }
};
void correct(){
    int N,M;
    std::cin>>N>>M;
    dp DP(N,M);
    for(auto& edge:DP.edges){
        std::cin>>edge.first>>edge.second;
        DP.degs[edge.second-1].push_back(edge.first-1);
    }
    int ans=0;
    for(int i=0;i<N;++i){
        int buf=DP.f(i);
        if(ans<buf)
            ans=buf;
    }
    std::cout<<ans<<std::endl;
}
int main(){
    correct();
}

Measured memory_bytes: 14328
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);


    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<int> dp(n + 1, 0);

    vector<int> bits(n + 1, 0);
    for (int i = 0; i <= n; ++i) {
        bits[i] = bits[i >> 1] + (i & 1);
    }

    for (int i = 1; i <= n; ++i) {
        dp[i] = 1 + dp[i % bits[i]];
    }


    int m = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            ++m;
        }
    }

    vector<int> MODS;

    for (auto mod : {m - 1, m + 1}) {
        if (mod > 0 && mod <= n) {
            MODS.push_back(mod);
        }
    }

    vector<vector<long long>> pows2(n + 1, vector<long long>(2, 1));
    vector<vector<long long>> suffix(n + 1, vector<long long>(2, 0));
    {
        int idx = 0;
        for (auto mod : MODS) {
            for (int i = 1; i <= n; ++i) {
                pows2[i][idx] = (pows2[i - 1][idx] << 1) % mod;
            }
            ++idx;
        }
        for (int i = 0; i < n; ++i) {
            int ch = s[n - 1 - i] - '0';
            for (int j = 0; j < MODS.size(); ++j) {
                suffix[n - 1 - i][j] = (suffix[n - i][j] + pows2[i][j] * ch) % MODS[j]; 
                // cout << i << " " << j << " " << MODS[j] << " " << suffix[n - 1 - i][j] << endl;
            }
        }
    }

    auto get = [&](int l, int r, int mod) -> long long {
        if (l > r) {
            return 0;
        }
        int idx = -1;
        for (int i = 0; i < MODS.size(); ++i) {
            if (MODS[i] == mod) {
                idx = i;
                break;
            }
        }
        // cout << idx << " : " << mod << endl;
        if (idx == -1) {
            return 0;
        }
        long long res = suffix[l][idx] - suffix[r + 1][idx];
        res %= mod;
        if (res < 0) {
            res += mod;
        }
        return res;
    };


    for (int i = 0; i < n; ++i) {
        int mod = m;
        if (s[i] == '0') {
            mod += 1;
        } else {
            mod -= 1;
        }
        if (mod == 0) {
            cout << 0 << '\n';
        } else {
            long long x = get(0, i - 1, mod) + get(i + 1, n - 1, mod);
            if (s[i] == '0') {
                for (int j = 0; j < MODS.size(); ++j) {
                    if (mod == MODS[j]) {
                        x += pows2[n - 1 - i][j];

                        break;
                    }
                }
            }
            
            x %= mod;
            // cout << i << " " << x << endl;
            int ans = 1 + dp[x];

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

    



    return 0;
}

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

class DisjointSet {
 public:
  std::vector<unsigned> parent;
  std::vector<unsigned> rank;
  DisjointSet(unsigned size)
      : parent(size),
        rank(size, 0u) {
    for (unsigned i = 0; i < size; ++i) { parent[i] = i; }
  }
  unsigned find(unsigned index) {
    if (parent[index] != index) { return parent[index] = find(parent[index]); }
    else { return index; }
  }
  void merge(unsigned index_a, unsigned index_b) {
    auto parent_a = find(index_a);
    auto parent_b = find(index_b);
    if (parent_a == parent_b) { return; }
    if (rank[parent_a] < rank[parent_b]) { parent[parent_a] = parent_b; }
    else if (rank[parent_b] < rank[parent_b]) { parent[parent_b] = parent_a; }
    else {
      ++rank[parent_a];
      parent[parent_b] = parent_a;
    }
  }
};

int main() {
  unsigned N, M;
  std::cin >> N >> M;
  std::vector<unsigned> vec(N + 1);
  for (unsigned i = 1; i <= N; ++i) {
    std::cin >> vec[i];
  }
  DisjointSet disjointSet(N + 1);
  for (unsigned i = 0; i < M; ++i) {
    unsigned x, y;
    std::cin >> x >> y;
    disjointSet.merge(vec[x], vec[y]);
  }
  unsigned ans = 0;
  for (unsigned i = 1; i <= N; ++i) {
    if (disjointSet.find(vec[i]) == disjointSet.find(i)) {
      ++ans;
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<array>
#include<vector>
#include<functional>
#include<unordered_map>
#include<map>
#include<numeric>
#include<limits>
#include<utility>
#include<queue>
#include<random>
 
using namespace std;
 
int main(){
char a[19];
  int i;
  cin >> a;
  
  for(i = 0;i<=18;i++){
  if(a[i] == ',')
    a[i] = ' ';
  }

  cout << a << endl;
  
  return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

lint N;
lint K;
lint A[200010]={};
lint F[200010]={};

bool can(lint T)
{
	lint cnt=0;
	for(int i=0;i<N;i++)
	{
		cnt+=max((lint)0,A[i]-T/F[i]);
		if(cnt>K)return false;
	}
	return true;
}

int main()
{
	cin >> N >> K;
	for(int i=0;i<N;i++)
		cin >> A[i];
	for(int i=0;i<N;i++)
		cin >> F[i];
	
	sort(A,A+N);
	sort(F,F+N,greater<lint>());

	lint l=0;
	lint r=1e12+10;
	while(r-l>1)
	{
		lint mid=(l+r)/2;
		if(can(mid))r=mid;
		else l=mid;
	}

	if(can(0))cout << 0;
	else cout << r;
	cout << endl;
	return 0;
}



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

int main() {
  int N, M, O, A, B;
  cin >> A >> B;
  N = A+B;
  M = A-B;
  O = A*B;
  A = max(N,M);
  B = max(A,O);
  cout << B << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver2.1.9
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define Pii pair<int,int>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lW,0,a.size()){Vout(a[lW]);}
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ
 
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}

Vi primevec(){  //  素数配列
int N=1000000;int l[N];Vi a(0);for(int i=0;i<N;i++){l[i]=1;}for(int i=2;i<sqrt(N);i++){if(l[i]){
for(int j=0;i*(j+2)<N;j++){l[i*(j+2)]=0;}}}for(int i=2;i<N;i++){if(l[i]){a.pb(i);}}return a;}
 
signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  Vi a = primevec();
  
  int ct = 0;
  rep(i,0,INF){
    if(a[i]%5==1){
      cout << a[i];
      ct++;
      if(ct==n) {cout << endl;return 0;}
      else cout << ' ';
    }
  }
  
  
  return 0;
}

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mid ((l+r)>>1)
const int M=1e5+20,P=1e9+7;
struct Task{
	LL n,a,b;
	void init(){
		scanf("%lld%lld%lld",&n,&a,&b);
	}
	void run(){
		init();
		if ((a-b)%2==0)
			printf("%lld\n",abs(b-a)/2);
		else
			printf("%lld\n",min(a-1,n-b)+(abs(a-b)+1)/2);
	}
}t;
int main(){
	t.run();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fort(i,n) for (int i = 1; i <= n; ++i)
#define pi pair<int,int>
#define vi vector<int>
#define pb push_back
#define sz size()
#define er erase
#define fr first
#define sc second
#define rc(x) return cout << x, 0
using namespace std;

int n,h,w,a,b,ans;

int32_t main()
{
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> n >> h >> w;
    fort (i,n)
    {
        cin >> a >> b;
        if (a>=h&&b>=w) ++ans;
    }
    cout << ans;
}

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

int main( void ) {
 int a, b;
  cin >> a >> b;
  if( a > 12 ) cout << b << '\n';
  else if( a >= 6 ) cout << b / 2 << '\n';
  else cout << 0 << '\n';
 return 0; 
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define F first
#define S second

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

vector<long long> prime_factorize(long long N) {
    vector<long long> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;

        // 割れる限り割り続ける
        while (N % a == 0) {
            N /= a;
        }

        // その結果を push
        res.push_back(a);
    }

    // 最後に残った数について
    if (N != 1) res.push_back(N);
    return res;
}

// GCD, LCM
// https://youtu.be/8lm8o8L9Bmw?t=2285
// https://youtu.be/XI8exXVxZ-Q?t=3595
// https://youtu.be/F2p_e6iKxnk?t=843
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; }

ll ngcd(const vector<ll>& a){
  ll res;
  res = a[0];
  for(int i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
ll nlcm(const vector<ll>& numbers) {
  ll res;
  res = numbers[0];
  for (int i = 1; i < numbers.size(); i++) {
    res = lcm(res, numbers[i]);
  }
  return res;
}

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

  set<int> s;
  bool pairwise = true;
  vector<vector<int>> v;

  int N;
  cin >> N;
  ll g = N;

  rep(i, n-1) {
    cin >> N;
    g = gcd(g, N);

    vector<int> res;
    for (int a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        while (N % a == 0) {
            N /= a;
        }
        res.push_back(a);
    }
    if (N != 1) res.push_back(N);

    if(pairwise) {
      rep(j, res.size()) {
        if(s.count(res[j]) > 0) {
          pairwise = false;
          break;
        }
        s.insert(res[j]);
      }
    }
    v.push_back(res);
  }

  if(g == 1) {
    if(pairwise) {
      cout << "pairwise coprime" << endl;
    }
    else {
      cout << "setwise coprime" << endl;
    }
  } else {
    cout << "not coprime" << endl;
  }

  return 0;
}


Measured memory_bytes: 57844
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": "
using namespace std;
typedef long long int ll;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main() {
multiset<int> s;
int n; cin>>n;
rep(i,0,n){
int p; cin>>p;
s.insert(p);
}
int ans=0;
while(!s.empty()){
int x=*s.rbegin();
s.erase(s.find(x));
rep(i,0,32){
int j=31-i;
int y=(1LL<<j)-x;
if(s.count(y))
{ans++;
s.erase(s.find(y));
break;
}
}
}
cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 9600
#include <stdio.h>
int main() 
{
  unsigned long long int i,j,k,n,c=0;
  scanf("%llu",&n);
  for ( i = 1; i < n; i++)
  {
     for ( j = 1; j <n; j++)
     {
         if (i*j>n)
         {
            break;
         }
        else if (n>i*j)
            {
               c++;
            }       
     }
     
  }
  printf("%llu\n",c);
/*          MD OMOR FARUK
            Daffodil International University(CSE)
            Contact:farukprimate@gmail.com
*/


return 0;
}

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

using namespace std;

const int N=3001;
int dp[N][N];
int main()
{
	string s,t;
	cin >> s >> t;
	int n=s.size(),m=t.size();
	for(int i=n-1;i>=0;i--)
        for(int j=m-1;j>=0;j--)
            if(s[i]==t[j])
                dp[i][j]=dp[i+1][j+1]+1;
            else
                dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
    string sol;
    int i=0,j=0;
    while(i<n&&j<m)
        if(s[i]==t[j])
            sol+=s[i],i++,j++;
        else
            if(dp[i+1][j]>dp[i][j+1])
                i++;
            else
                j++;
    cout << sol << endl;
    return 0;
}


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

int main(){
  int n;
  ll count=0;
  cin >> n;
  vector<int> v(n,0);
  r(i,n)cin >> v.at(i);
  sort(v.begin(),v.end());
  r(i,n-2){
    for(int j=i+1;j<n-1;j++){
      for(int k=j+1;k<n;k++){
        if(v.at(i)+v.at(j)<=v.at(k))break;
        else count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int mod=1e9+7;
const ll inf=1001001001001001;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}

int main(){
    ll n;cin>>n;
    string s;cin>>s;
    ll q;cin>>q;
    rep(i,q){
        ll k,ans=0,sum=0,d=0,m=0;cin>>k;
        rep(i,n){
            if(s[i]=='D')d++;
            if(s[i]=='M'){
                sum+=d;
                m++;
            }
            if(i-k>=0){
                if(s[i-k]=='D'){
                    sum-=m;
                    d--;
                }
                if(s[i-k]=='M')m--;
            }
            if(s[i]=='C')ans+=sum;
        }
        out(ans);
    }
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+7;
int p[N];
char s[N];
vector<pair<int, int> > vec;
int main()
{
	int n;
	scanf("%s", s+1);
	n = strlen(s+1);
	for(int i = 1; i <= n; i++)
	{
		s[i] -= 'A'-1;
	}
	ll ans = 0;
	if(s[n-1]==2&&s[n]==3)
	{
		vec.push_back(make_pair(4, 1));
	}
	else
	{
		vec.push_back(make_pair(s[n], 1));
		vec.push_back(make_pair(s[n-1], 1));
	}
	for(int i = n-2; i >= 1; i--)
	{
		int j = i;
		if(vec.empty())
		{
			vec.push_back(make_pair(s[i], 1));
			continue;
		}
		if(s[i]==1&&vec.back().first==4)
		{
			ans += vec.back().second;
			//printf("%d %d\n", i, vec.back().second);
		}
		else if(s[i]==1)
		{
			vec.push_back(make_pair(1, 1));
		}
		else
		{
			if(s[i]==2&&vec.back().first==3)
			{
				vec.pop_back();
				if(!vec.empty()&&vec.back().first==4)
				{
					vec.back().second++;
				}
				else
				{
					vec.push_back(make_pair(4, 1));
				}
			}
			else
			{
				vec.push_back(make_pair(s[i], 1));
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

int main() {
  int r;
  cin >> r;
  cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pi acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define	inf (ll)1e15
#define mod 1000000007
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

using namespace __gnu_pbds;
using namespace std;

inline string str_inp(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string line_inp(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;


const int S=100100;
int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
	ll n;
	while(~sf("%lld",&n))
	{
		int ans=0,cnt=0;
		ll p=2;
		while(n%p==0)
		{
			n/=p;
			cnt++;
			p*=2;
		}
		ans+=cnt;

		while(n%2==0)n/=2;

		for(int i=3;i<=sqrt(n);i+=2)
		{
			cnt=0;
			ll p=i;
			while(n%p==0)n/=p,cnt++,p*=i;
			while(n%i==0)n/=i;
			ans+=cnt;
		}
		if(n>1)ans++;
		pf("%d\n",ans);
	}
    return 0;
}
 






































Measured memory_bytes: 3796
#include <iostream>
#include <string>

int main(void){
  int a,b;
  std::cin >> a;
  std::cin >> b;
  
  int ans = 0;
  for(int i = a;i <= b;i++){
   	std::string str = std::to_string(i);
    if(str[0] == str[4] && str[1] == str[3]){
      ans++;
    }
  }
  std::cout << ans << std::endl;
}

Measured memory_bytes: 256
require("fs").readFileSync("/dev/stdin","utf8").split('\n').some(function(i){j=i.split(' ');if(j[1])a=j[0],b=j[1],c=j[2],d=j[3],e=j[4],f=j[5],g=a*a,h=b*b,k=c*c,l=d*d,m=e*e,n=f*f,o=a-c,r=b-d,s=b-f,t=a-e,p=(s*(h-l+g-k)-r*(h-n+g-m))/(2*s*o-2*r*t),q=(t*(g-k+h-l)-o*(g-m+h-n))/(2*t*r-2*o*s),console.log(p.toFixed(3),q.toFixed(3),Math.sqrt((a-p)*(a-p)+(b-q)*(b-q)).toFixed(3))})

Measured memory_bytes: 7908
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    int a[N], cnt = 0;
    rep(i, N){
        cin >> a[i];
        if(i%2 == 0 && a[i]%2 == 1) cnt++;
    }
    cout << cnt << endl;
}

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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;



int main(){
  lll ii,jj,kk;
  lll n,sum;
  vector<lll> a,b,c;

  cin >> n;
  a.resize(n+1);
  c.resize(n+1);
  //b.resize(n);
  for(ii=1;ii<=n;ii++){
    cin >> a[ii];
  }
  
  sum = 0;
  //cout << " prev for " << endl;

  for(ii=n;ii>=1;ii--){
    sum = a[ii];

    jj=2;

    while(ii*jj<=n){
      sum += c[ii*jj];
      jj++;
    }

    if(sum % 2 == 1){
      b.push_back(ii);
      c[ii] = 1;
    }

  }

  cout << b.size() << endl;

  for(ii=0;ii<b.size();ii++){
    cout << b[ii] << " ";
  }
  cout << endl;
//  cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 4980