akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
signed main()
{
    fast;
    char c;
    cin>>c;
    c++;
    cout<<c;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG

int main() {
  ll N;
  cin >> N;
  //vector<ll> a(N);
  ll min = 200007;
  ll ans = 0;
  for(ll i=0; i<N; i++){
    ll tmp;
    cin >> tmp;
    if(tmp < min){
      ans ++;
      min = tmp;
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3628
(defun sum(lis)
  (eval (cons '+ lis)))

(defun read-list(N &optional (l nil))
  (if (<= N 0) l (read-list  (1- N) (cons (read) l))))


(defun solve(l &optional (p (sum l)))
  (let ((n (- p (* 2 (car l)))))
    (if (< (abs p) (abs n)) (abs p)
      (solve (cdr l) n))))

(princ (solve (read-list (read))))

Measured memory_bytes: 4072
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class E
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		long[] P = GetLongs(N);

		var pair = new Tuple<int, long>[N];
		for(int i = 0; i < N; i++)
			pair[i] = Tuple.Create(i + 1, P[i]);

		Array.Sort(pair, (a, b) => b.Item2.CompareTo(a.Item2));

		var stMin = new SegmentTree<int>(N + 1, N + 1, (a, b) => Math.Min(a, b));
		var stMax = new SegmentTree<int>(N + 1, 0, (a, b) => Math.Max(a, b));

		long ans = 0;
		for(int i = 0; i < N; i++)
		{
			int pos = pair[i].Item1;

			long x = (long)stMax.Query(0, pos);
			long w = (long)stMax.Query(0, (int)x);
			stMax.Update(pos, pos);

			long y = (long)stMin.Query(pos + 1, N + 1);
			long z = (long)stMin.Query((int)y + 1, N + 1);
			stMin.Update(pos, pos);

			long c = (x - w) * (y - (long)pos) + ((long)pos - x) * (z - y);
			ans += c * pair[i].Item2;
		}

		Console.WriteLine(ans);
	}
}


public class SegmentTree<T>
{
	private int N;
	private T INI;
	private Func<T, T, T> Func;
	private T[] dat;

	public SegmentTree(int n, T ini, Func<T, T, T> func)
	{
		N = 1;		
		while(N < n)
			N <<= 1;

		INI = ini;
		Func = func;
			
		dat = new T[2 * N - 1];
		for(int i = 0; i < 2 * N - 1; i++)
			dat[i] = INI;
	}

	public void Update(int k, T a)
	{
		k += N - 1;
		dat[k] = a;
		while(k > 0)
		{
			k = (k - 1) / 2;
			dat[k] = Func(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}

	public T Query(int a, int b, int k = 0, int l = 0, int r = -1)
	{
		if(r == -1)
			r = N;

		if(r <= a || b <= l)
			return INI;

		if(a <= l && r <= b)
			return dat[k];
		else
		{
			T vl = Query(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = Query(a, b, k * 2 + 2, (l + r) / 2, r);
			return Func(vl, vr);
		}
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


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

int main(){
  int N,X,m;
  int n = 1100;
  int total = 0;
  cin >> N >> X;
  for(int i = 1; i <= N; ++i){
    cin >> m;
    total += m;
    if(m < n) n = m;
  }
  int x = (X - total)/n;
  cout << x + N << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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 (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll r,g,b;
    cin >> r >> g >> b;
    if ((r*100+g*10+b)%4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MS(x, i) memset(x, i, sizeof x)
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define MOD 1000000007
#define NOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
char F[200];

inline ll read() {
    ll ret = 0, sgn = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-') sgn = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        ret = ret*10 + ch - '0';
        ch = getchar();
    } 
    return ret*sgn;
}

inline void write( ll x ) {
    ll tmp = x > 0 ? x : -x;
    if(x < 0) putchar('-');
    int cnt = 0;
    while(tmp > 0) {
        F[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while(cnt > 0) putchar(F[--cnt]);
}

int main()
{
    NOS
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    int n, k;
    cin >> n >> k;

    int cnt = 0;
    while(n)
    {
        n /= k;
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define ii pair<int,int>
#define st first
#define nd second
#define N 200005
#define inf 1000000000
#define MOD 998244353
#define sz(x) ((int)x.size())
#define umax(x,y) x=max(x,y)
using namespace std;

int n;
int a[N],b[N],ok[N];
ll ans;
multiset<ii> s;

void fail() {printf("-1");exit(0);}
int prv(int x) {return (x-1+n)%n;}
int nxt(int x) {return (x+1+n)%n;}

int main(int arg,char* argv[]) {

	scanf("%d",&n);

	for(int i=0;i<n;i++) scanf("%d",a+i);

	for(int i=0;i<n;i++) scanf("%d",b+i);

	for(int i=0;i<n;i++) {

		if(a[i]==b[i]) ok[i]=1;

		if(!ok[i]) s.insert({b[i],i});

	}

	while(sz(s)) {

		ii mx=*s.rbegin();

		s.erase(prev(s.end()));

		int sum_s=b[prv(mx.nd)]+b[nxt(mx.nd)];

		if(sum_s>=mx.st) fail();

		int goal=a[mx.nd];
		int mod=mx.st%sum_s;

		if(goal>=mod) {

			if((mx.st-goal)%sum_s) fail();

			ans+=(mx.st-goal)/sum_s;

			ok[mx.nd]=1;
			b[mx.nd]=goal;

		}
		else {

			ans+=(mx.st-mod)/sum_s;
			b[mx.nd]=mod;

		}

		if(!ok[mx.nd]) s.insert({b[mx.nd],mx.nd});

	}

	printf("%lld",ans);

}

Measured memory_bytes: 13996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll D, G;
vector<ll> p(11, 0);
vector<ll> c(11, 0);
vector<ll> v;
vector<ll> dp(10010, -1);
 
int main(void){
	
	cin >> D >> G;
	for(int i = 0; i < D; ++i) cin >> p[i] >> c[i];
	
	ll sum = 0;
	for(int i = 0; i < D; ++i) sum += p[i], v.push_back(sum);
    
    dp[0] = 0;
    for(int i = 0; i < D; ++i){
        for(int j = v[i]; j >= 0; --j){
            if(~dp[j]){
                for(int q = 0; q <= p[i]; ++q){
                    if(j + q <= v.back()){
                        ll point = q * 100 * (i + 1) + (q == p[i] ? c[i] : 0);
                        dp[j + q] = max(dp[j + q], dp[j] + point);
                    }
                }
            }
        }
    }
    for(int i = 0; i <= v.back(); ++i) if(dp[i] >= G){ cout << i << endl; break; }
    
	return 0;
}

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

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

void setdp(ll N, ll num, ll cost, ll one_cost, priority_queue<ll> &q, map<ll, ll> &dp)
{
    ll upper = (N+num-1)/num;
    ll lower = N/num;
    if(dp.count(upper))
    {
        chmin(dp[upper], dp[N] + llabs(N - upper*num)*one_cost + cost);
    }
    else
    {
        dp[upper] = dp[N] + llabs(N - upper*num)*one_cost + cost;
        q.push(upper);
    }
    if((cost + one_cost - 1) / one_cost > llabs(N - upper) - llabs(N - upper*num))
    {
        chmin(dp[upper], dp[N] + llabs(N - upper)*one_cost);
    }
    if(dp.count(lower))
    {
        chmin(dp[lower], dp[N] + llabs(N - lower*num)*one_cost + cost);
    }
    else
    {
        dp[lower] = dp[N] + llabs(N - lower*num)*one_cost + cost;
        q.push(lower);
    }
    if((cost + one_cost - 1) / one_cost > llabs(N - lower) - llabs(N - lower*num))
    {
        chmin(dp[lower], dp[N] + llabs(N - lower)*one_cost);
    }
    return;
}

void solve(ll N, ll A, ll B, ll C, ll D)
{
    map<ll, ll> dp; // 持っている数, 払ったコインの枚数
    dp[N] = 0;
    
    // BFS
    priority_queue<ll> q;
    q.push(N);
    while(!q.empty())
    {
        ll now = q.top(); q.pop();
        if(now==0) break;
        if(now==1)
        {
            if(dp.count(0)) chmin(dp[0], dp[1] + D);
            else
            {
                dp[0] = dp[1] + D;
            }
            break;
        }
        setdp(now, 2, A, D, q, dp);
        setdp(now, 3, B, D, q, dp);
        setdp(now, 5, C, D, q, dp);
    }
    cout << dp[0] << endl;
    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--)
    {
        ll N, A, B, C, D;
        cin >> N >> A >> B >> C >> D;
        solve(N, A, B, C, D);
    }

    return 0;
}

Measured memory_bytes: 4384
#include<stdio.h>
 
#define MAX 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2
 
int n, M[MAX][MAX];
 
void dijkstra();
  
int main(){
    int i, j, k, c, u, v;
  
    scanf("%d", &n);
  
    for(i=0;i<n;i++){ 
        for(j=0;j<n;j++){
            M[i][j]=INFTY;
        }
    }
 
    for(i=0;i<n;i++){ 
        scanf("%d %d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d %d",&v,&c);
            M[u][v]=c;
        }
    }
    dijkstra(); 
 
    return 0;
}
  
void dijkstra(){
    int i,j,u,v,p,minv;
    int d[MAX],color[MAX];
  
    for(i=0;i<n;i++){ 
        d[i]=INFTY;
        color[i]=WHITE;
    }
  
    d[0]=0;
    color[0]=GRAY;
 
    while(1){
        minv=INFTY;
        u=-1;
        for(i=0;i<n;i++){
            if(minv>d[i] && color[i]!=BLACK){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1){
            break;
        }
        color[u]=BLACK;
        for(v=0;v<n;v++){ 
            if(M[u][v]!=INFTY && color[v]!=BLACK){
                if(d[v]>d[u]+M[u][v]){
                    d[v]=d[u]+M[u][v];
                    color[v]=GRAY;
                }
            }
        }
    }
    for(i=0;i<n;i++){ 
        printf("%d %d\n",i,(d[i]==INFTY?-1:d[i]));
    }
}

Measured memory_bytes: 636
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)
template<typename T>
inline void compless(vector<T> & c){
    sort(all(c));
    c.erase(unique(all(c)),c.end());
}
template<typename T>
inline size_t idx(T i, vector<T> const& c){
    return lower_bound(all(c),i) - c.begin();
}

int n,m;
int xs[5000], ys[5000];
int sum[5100][5100]={};

int main(){
    scanf("%d%d",&n,&m);
    vector<int> x(n),y(n);
    rep(i,n){
        scanf("%d%d",xs+i,ys+i);
        x[i]=xs[i];
        y[i]=ys[i];
    }
    compless(x);
    compless(y);
    rep(i,n){
        int fx=idx(xs[i],x);
        int fy=idx(ys[i],y);
        sum[fy+1][fx+1]++;
    }
    rep(i,y.size())rep(j,x.size()){
        sum[i+1][j+1]+=sum[i+1][j]+sum[i][j+1]-sum[i][j];
    }

    rep(i,m){
        int lx,ly,rx,ry;
        scanf("%d%d%d%d",&lx,&ly,&rx,&ry);
        lx = idx(lx,x);
        rx = idx(rx+1,x);
        ly = idx(ly,y);
        ry = idx(ry+1,y);
        printf("%d\n",sum[ry][rx]-sum[ry][lx]-sum[ly][rx]+sum[ly][lx]);
    }
}

Measured memory_bytes: 101444
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),q=sc.nextInt();
    String s=sc.next();
    long[] a=new long[n+1];
    for(int i=2;i<=s.length();i++) {
    	if(s.substring(i-2, i).equals("AC"))a[i]=a[i-1]+1L;
    	else a[i]=a[i-1];
    }

    for(int i=0;i<q;i++) {
    	int l=sc.nextInt(),r=sc.nextInt();
    	System.out.println(a[r]-a[l]);
    }
  }
}


Measured memory_bytes: 69792
#include <iostream>

using namespace std;

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

const int MAXN = 3000;
const ll mod = 998244353LL;
int n, s, a[MAXN + 5];
ll dp[MAXN + 5];

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> s;
ll sol = 0;
for(int i = 1 ; i <= n ; ++i){
	int x;
	cin >> x;
	if(x > s)
		continue;
	dp[0] = i;
	sol = (sol + (dp[s - x] * (ll)(n - i + 1)) % mod) % mod;
	for(int j = s ; j >= x ; --j){
		dp[j] = (dp[j] + dp[j - x]) % mod;
	}
}
cout << sol << endl;

return 0;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
LRC = sorted([list(map(int, input().split())) for i in range(M)])

inf = float('inf')
dp = [inf] * (N+1)
dp[1] = 0
for l, r, c in LRC:
    for i in range(r, l, -1):
        if dp[i] > dp[l]+c:
            dp[i] = dp[l]+c
        else:
            break

if dp[-1] < inf:
    print(int(dp[-1]))
else:
    print(-1)

Measured memory_bytes: 92248
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng)

//struct custom_hash {
//    static uint64_t splitmix64(uint64_t x) {
//        // http://xorshift.di.unimi.it/splitmix64.c
//        x += 0x9e3779b97f4a7c15;
//        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//        return x ^ (x >> 31);
//    }
//    size_t operator()(uint64_t x) const {
//        static const uint64_t FIXED_RANDOM = 
//            chrono::steady_clock::now().time_since_epoch().count();
//        return splitmix64(x + FIXED_RANDOM);
//    }
//};

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	ll n=s.size();
	string s1=s;
	reverse(s1.begin(),s1.end());
	string a=s.substr(0,(n-1)/2);
	string a1=a;
	reverse(a1.begin(),a1.end());
	string b=s.substr((n+3)/2-1,(n-(n+3)/2+1));
	string b1=b;
	reverse(b1.begin(),b1.end());
	if(s!=s1)
	{
		cout<<"No\n";
		return 0;
	}
	if(a!=a1)
	{
		cout<<"No\n";
		return 0;
	}
	if(b!=b1)
	{
		cout<<"No\n";
		return 0;
	}
	cout<<"Yes\n";
    return 0;
}


//252908XL

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A_abs = [abs(a) for a in A]
n_neg = sum([a < 0 for a in A])
if n_neg % 2 == 0:
    print(sum(A_abs))
else:
    print(sum(A_abs) - 2*min(A_abs))

Measured memory_bytes: 14412
#include<stdio.h>
int main(){
  int n,i,j,k,l,m,M=1e9+7,d[110][4][4][4]={};
  scanf("%d",&n);
  for(j=0;j<4;j++){
    for(k=0;k<4;k++){
      for(l=0;l<4;l++){
	if(j==0&&k==2&&l==1)continue;
	if(j==0&&k==1&&l==2)continue;
	if(j==2&&k==0&&l==1)continue;
	d[3][j][k][l]=1;
      }
    }
  }
  for(i=3;i<n;i++){
    for(j=0;j<4;j++){     
      for(k=0;k<4;k++){
	for(l=0;l<4;l++){
	  for(m=0;m<4;m++){
	    if(j==0&&k==2&&l==1)continue;
	    if(k==0&&l==2&&m==1)continue;

	    if(j==0&&l==2&&m==1)continue;
	    
	    if(j==2&&k==0&&l==1)continue;
	    if(k==2&&l==0&&m==1)continue;
		    
	    if(j==0&&k==2&&m==1)continue;
	    
	    if(j==0&&k==1&&l==2)continue;
	    if(k==0&&l==1&&m==2)continue;
	    d[i+1][k][l][m]=(d[i+1][k][l][m]+d[i][j][k][l])%M;
	  }
	}
      }
    }
  }
  for(j=m=0;j<4;j++){
    for(k=0;k<4;k++){
      for(l=0;l<4;l++)m=(m+d[n][j][k][l])%M;
    }
  }
  printf("%d\n",m);
}
			


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

using namespace std;

typedef long long ll;

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

    // 0: M, 1: A, 2: R, 3: C, 4: H
    ll num[5];
    for (int i = 0; i < 5; i++) num[i] = 0;
    for (int i = 0; i < N; i++) {
        if (S[i][0] == 'M') num[0]++;
        else if (S[i][0] == 'A') num[1]++;
        else if (S[i][0] == 'R') num[2]++;
        else if (S[i][0] == 'C') num[3]++;
        else if (S[i][0] == 'H') num[4]++;
    }

    ll ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += num[i]*num[j]*num[k];
            }
        }
    }

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

Measured memory_bytes: 6144
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        s = s.replace(" ", "");
        int a = Integer.parseInt(s);
        System.out.println(a % (int)Math.sqrt(a) == 0 ? "Yes" : "No");
        scan.close();
    }
}

Measured memory_bytes: 26908
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

int main()
{
    ios;
    ll n ;
    cin >> n ;
    vl v;
    ll cnt[100005];
    ms(cnt) ;
    forn(i ,  1  , n ) {
       ll x;
       cin >> x;
       v.pb(x);
       cnt[x]++;
    }
    ll ans = 0;
    ll sum = cnt[0] + cnt[1] + cnt[2] ;
    ans = max(ans ,sum) ;
    forn(i , 3 , 100000){
       ll res = sum + cnt[i] - cnt[i-3];
       sum = res ;
       ans = max(ans, sum ) ;
    }
    cout << ans << el ;
}































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

int main() {
    int N;
    string s[101];
    cin >> N;
    for (int i = 1; i <= N; ++i) cin >> s[i];
    int M;
    string t[101];
    cin >> M;
    for (int i = 1; i <= M; ++i) cin >> t[i];

    int maxsum = 0;
    for (int i = 1; i <= N; ++i) {
        int sum = 0;
        for (int j = 1; j <= N; ++j) {
            if (s[i] == s[j]) ++sum;
        }
        for (int j = 1; j <= M; ++j) {
            if (s[i] == t[j]) --sum;
        }
        if (sum > maxsum) maxsum = sum;
    }

    cout << maxsum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int n, i, count=0;
	char s[100];

	if (scanf("%d", &n) == 0) return -1;
	if (scanf("%s", s) == 0) return -1;

	for (i = 0;i < n;i++) {
		if (s[i] == 'R') count++;
	}

	if (count* 2 > n) printf("Yes");
	else printf("No");

	return 0;
}

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

const double PI=acos(-1.0);

int main()
{
    int i,j,k,n;
    int x,y;
    string name;
    char ch;
    string :: iterator it;
    map <string,int> mymap;
    cin>>n;
    cin>>name;
    mymap[name]++;
    it=name.end()-1;
    ch=*it;
    n--;
    x=y=0;
    while(n--)
    {
    cin>>name;

    it=name.begin();

    if(ch==*it)
    {
        mymap[name]++;

        if(mymap[name]>1)x=1;

    it=name.end()-1;
    ch=*it;
    }
    else y=1;
    }
    if(x==1||y==1){cout<<"No\n";}
    else cout<<"Yes\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long int;
int main() 
{
     ll n,k;
     cin>>n>>k;
     ll ar[n];
     for(int i=0;i<n;i++)
     {
        cin>>ar[i]; 
     }
     ll su =0 ;
     sort(ar,ar+n);
     for(int i=0;i<k;i++)
     {
        su+=ar[i];
     }
     cout<<su<<"\n";
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

#define pick(a,b) (((a)>>(b))&1)
#define shl(a) (1<<(a))

const int _ = 133333;

int n,nn,st,ta;

inline int bcnt(int x){return __builtin_popcount(x);}

vector<int> makenoch(int len)
{
	if(len<=0)return {0};
	vector<int> xl=makenoch(len-1),xr=xl;
	reverse(xr.begin(),xr.end());
	for(auto i:xr)xl.emplace_back(i+shl(len-1));
	return xl;
}

vector<int> makech(int len)
{
	if(len<=1)return {0,1};
	if(len<=2)return {0,1,3,2,6,4,5,7};

	vector<int> xl=makech(len-2),xr;
	for(int i=0;i<(int)xl.size();i++)
	{
		xr.emplace_back(xl[i]);
		xr.emplace_back(xl[i]+shl(len-2));
		i++;
		xr.emplace_back(xl[i]+shl(len-2));
		xr.emplace_back(xl[i]);
	}

	reverse(xl.begin(),xl.end());
	for(auto i:xl)xr.emplace_back(i+shl(len-1));
	reverse(xl.begin(),xl.end());
	for(auto i:xl)xr.emplace_back(i+shl(len-1)+shl(len-2));
	return xr;
}

int main()
{
	n=ty(),nn=1<<n,st=ty(),ta=ty();
	int dif=st^ta;
	if(!(bcnt(dif)&1)){puts("NO");return 0;}
	puts("YES");

	int cnts[2]={0};
	for(int i=0;i<n;i++)cnts[pick(dif,i)]++;

	vector<int> vn=makenoch(cnts[0]),vc=makech(cnts[1]);
	
	for(auto i:vc)
	{
		for(auto j:vn)
		{
			int val=0,ic=0,in=0;
			for(int k=0;k<n;k++)
			{
				if(pick(dif,k))val+=pick(i,ic++)*shl(k);
				else val+=pick(j,in++)*shl(k);
			}
			printf("%d ",val^st);
		}
		reverse(vn.begin(),vn.end());
	}

	puts("");
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define int long long int
#define N 200005
void fast(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

main()
{
  int n;
  cin>>n;
  string s;
  cin>>s;
  if(n%2==1)cout<<"No"<<endl;
  else {
    for(int i=0;i<n/2;i++){
      if(s[i]!=s[i+n/2]){
        cout<<"No"<<endl;return 0;
      }
    }
    cout<<"Yes"<<endl;
  }
}

Measured memory_bytes: 256
import java.util.*;
class Main {
	static int n;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			n = sc.nextInt();
			if (n == 0) break;
			int maxDistance = 0;
			Map<Integer, Integer> map = new HashMap<Integer, Integer>(1);
			for (int i = 0; i < n; i++) {
				int p = sc.nextInt();
				int d = sc.nextInt() + sc.nextInt();
				map.put(d, p);
				maxDistance = Math.max(d, maxDistance);
			}
			System.out.printf("%d %d\n", map.get(maxDistance), maxDistance);
		}
	}
}

Measured memory_bytes: 17000
using System;

namespace _053_SumofPrimeNumbers
{
	class Program
	{
		static void Main ( string[] args )
		{
			int inputNum;

			//0????????¨?????????
			int[] primeSumArray = new int[10000 + 1];
			primeSumArray[1] = 2;

			int number = 3;
			int contentIndex = 1;//??????????????????????????§??\??£????????????

			while ((inputNum = int.Parse (Console.ReadLine ())) != 0)
			{
				int result;

				//???????´???????????±??????????????????´???
				while (contentIndex < inputNum)
				{
					//???????????????????´???????????±???????

					//?´???°??????????????????
					if (IsPrimeNumber (number))
					{
						primeSumArray[contentIndex + 1] = primeSumArray[contentIndex] + number;
						contentIndex++;
					}

					number += 2;
				}

				//?´???°???????¨?????´??????????????????£?????????
				result = primeSumArray[inputNum];
				Console.WriteLine (result);
			}
		}

		static bool IsPrimeNumber ( int number )
		{
			int loop = 3;
			while (loop <= Math.Sqrt (number))
			{
				if (number % loop == 0)
				{
					return false;
				}

				loop += 2;
			}
			return true;
		}
	}
}

Measured memory_bytes: 9152
a,b,c = map(int,input().split(' '))
ans = 0
if a % 2 == 0 and a == b and a == c:
    ans = -1
elif (a+1)*(b+1)*(c+1)%2 == 0:
    ans = 0
else:
    A = [a,b,c]
    A.sort()
    a1 = A[2]-A[1]
    a2 = A[1]-A[0]
    ans = 0
    while a1%2 == 0 and a2%2 == 0:
        ans += 1
        a1 /= 2
        a2 /= 2
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int M = 1e9 + 7;
vector<ll> dp;
ll dfs(ll n) {
  if (n == 0) {
    return 1;
  }
  if (n < 0) {
    return 0;
  }
  if (dp[n] != -1) {
    return dp[n];
  }
  ll ans = 0;
  for (int i = 3; i <= n; i++) {
    ans = (ans + dfs(n - i)) % M;
  }
  dp[n] = ans % M;
  return ans;
}

int main() {
  ll n;
  cin >> n;
  dp.assign(n + 1, -1);
  cout << dfs(n) << '\n';
  return 0;
}


Measured memory_bytes: 3652
N, K = map(int, input().split())
A = sorted([int(i) for i in input().split()])
F = sorted([int(i) for i in input().split()], reverse=True)

if sum(A) <= K:
    print(0)
    exit()
else:
    OK = 10**12
    NG = -1

    while OK-NG > 1:
        mid = (OK+NG)//2
        cnt = 0

        for i, a in enumerate(A):
            cnt += max(0, a-mid//F[i])
        if cnt <= K:
            OK = mid
        else:
            NG = mid

print(OK)


Measured memory_bytes: 122572
n,k = [int(x) for x in input().split(' ')]
 
def solve(n, k):
    snukes = [None] * n
    victims = 0
    
    for i in range(k):
        snacks = int(input())
        snukes_snacks = [int(z) for z in input().split(' ')]
        for j in range(snacks):
            snukes[snukes_snacks[j] - 1] = snukes_snacks[j]
    
    for w in range(n):
        if snukes[w] is None:
            victims += 1
    
    print(victims)
 
solve(n, k)

Measured memory_bytes: 9204
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

int N;
int A[200000];

int main(){
    cin>>N;
    rep(i,N) cin>>A[i];

    map<int,int> m;
    ll ans=0;
    rep(i,N){
        ll k=(i+1)-A[i];
        ll l=(i+1)+A[i];
        ans+=m[k];
        m[l]++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 21392
#include<bits/stdc++.h>
using namespace std;
string x="Positive\n",y="Negative\n",z="Zero\n";
inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}
inline void write(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
int main(){
    int a=read(),b=read();
    if(a<=0&&b>=0)
        cout<<z;
    else if(a>0&&b>0)
        cout<<x;
    else if(a<0&&b<0){
        int s=abs(a-b)+1;
        if(s%2)
        cout<<y;
        else cout<<x;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;
int main(void){
    int a,b,c,x,y; cin>>a>>b>>c>>x>>y;
    long long ans=INF;
    for(int i=0;i<=max(x,y)*2;i++){
       int  xn=max(x-i/2,0);
       int  yn=max(y-i/2,0);
       //cout<<xn<<' '<<yn<<endl;
       long long tmp = xn*a+yn*b+i*c;
       //cout<<tmp<<endl;
       chmin(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
//WA
#include <stdio.h>
#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

//降順
int des(const void *a, const void *b) {
  return *(long *)b - *(long *)a;
}

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  long x, y, z, a[8][n], sum[8], ans = 0;
  for (int i=0; i<8; i++) sum[i] = 0;
  for (int i=0; i<n; i++) {
    scanf("%ld%ld%ld", &x, &y, &z);
    a[0][i] = x+y+z;
    a[1][i] = x+y-z;
    a[2][i] = x-y+z;
    a[3][i] = x-y-z;
    a[4][i] = -x+y+z;
    a[5][i] = -x+y-z;
    a[6][i] = -x-y+z;
    a[7][i] = -x-y-z;
  }
  for (int i=0; i<8; i++) /*qsort(a[i], n, sizeof(long), des);*/{
    for (int j=0; j<n-1; j++) {
      for (int k=j+1; k<n; k++) {
        if (a[i][j] < a[i][k]) {
          long tmp = a[i][j];
          a[i][j] = a[i][k];
          a[i][k] = tmp;
        }
      }
    }
  }
  for (int i=0; i<8; i++) for (int j=0; j<m; j++) sum[i] += a[i][j];
  for (int i=0; i<8; i++) ans = (ans < sum[i]) ? sum[i] : ans;
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 998244353

N, S = MAP()
A = LIST()

# dp0[i][j][ := j番目の要素まで見て、総和がjで、使う区間が未確定の状態の通り数
dp0 = list2d(N+1, S+1, 0)
# dp1[i][j][ := j番目の要素まで見て、総和がjで、使う区間がL確定済の状態の通り数
dp1 = list2d(N+1, S+1, 0)
# dp2[i][j][ := j番目の要素まで見て、総和がjで、使う区間がLR確定済の状態の通り数
dp2 = list2d(N+1, S+1, 0)
dp0[0][0] = 1
for i, a in enumerate(A):
    for j in range(S+1):
        # aを総和に足さない遷移は全部OK
        dp0[i+1][j] += dp0[i][j]
        dp1[i+1][j] += dp0[i][j] + dp1[i][j]
        dp2[i+1][j] += dp0[i][j] + dp1[i][j] + dp2[i][j]
        # aを総和に足す遷移は、遷移元が状態2と遷移先が状態0は無理
        if j+a <= S:
            dp1[i+1][j+a] += dp0[i][j] + dp1[i][j]
            dp2[i+1][j+a] += dp0[i][j] + dp1[i][j]
        dp0[i+1][j] %= MOD
        dp1[i+1][j] %= MOD
        dp2[i+1][j] %= MOD
ans = dp2[N][S]
print(ans)


Measured memory_bytes: 246792
#include<stdio.h>
#include<map>
#include<string>
#include<bits/stdc++.h>
using namespace std;
map<int,int>q;
int main()
{
	int n,m,i,a,ans=0,wns=0;
	string s;
	while(~scanf("%d%d",&n,&m))
	{
		for(i=0;i<m;i++)
		{            
			cin>>a;
			cin>>s;
			if(q[a]==-1)
				continue;
			if(s=="AC")
			{
				ans+=1;
				wns+=q[a];
				q[a]=-1;
				continue;
			}
			q[a]++;
//			if(s=="AC"&&!q[a])
//			{                 
//				q[a]=1;
//				ans++;
//			}else if(s=="WA"&&!q[a])
//				wns++;
		}
		printf("%d %d\n",ans,wns);
		ans=wns=0;
		q.clear();
	}
}


                    

Measured memory_bytes: 4992
# 奇数だと0にならない
# 10で割れれば0の数+1だが100とか3400とかそういうのがあるので考える
# 10を2と5に分解する
# 2*(5**i)で割った商 10,50,250,...


n = int(input())
ans = 0
if n % 2 == 1:
    print(0)
    exit()

for i in range(1, 27):  # 5**25 < 10**18 < 5**26
    ans += n // (2 * 5 ** i)
print(ans)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
struct student
{
	int x;
	int y;
};
struct rode
{
	int x;
	int y;
};
struct student stu[N];
struct rode rod[N];
int n,m;

int find(struct student x,struct rode y)
{
	int x1=abs(x.x-y.x);
	int y1=abs(x.y-y.y);
	return x1+y1;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>stu[i].x>>stu[i].y;
	for(int i=1;i<=m;i++)
		cin>>rod[i].x>>rod[i].y;
	for(int i=1;i<=n;i++)
	{
		int Min=INT_MAX,id;
		for(int j=1;j<=m;j++)
		{
			int dis=find(stu[i],rod[j]);
			if(Min>dis)
			{
				Min=dis;
				id=j;
			}
		}
		cout<<id<<"\n";
	}
}

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


int main(){
	int n,m;
	int p[1000];
	while(cin>>n>>m,n|m){
		for(int i=0;i<n;i++)cin>>p[i];
		sort(p,p+n,greater<int>());
		int s=accumulate( p,p+n, 0 );
		for(int i=m-1;i<n;i+=m){
			s-=p[i];
		}
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 1176
X, K, D = map( int, input().split())
 
Y = abs( X ) // D
if K <= Y:
  print( min( abs( X - K * D ) , abs( X + K * D ) ))
else:
  if ( K - Y ) % 2 == 0:
    print( min( abs( X - Y * D ) , abs( X + Y * D ),
                abs( X - ( Y - 2 ) * D ), abs( X - ( Y + 2 ) * D ),
                abs( X + ( Y - 2 ) * D ), abs( X + ( Y + 2 ) * D )))
  else:
    print( min( abs( X - ( Y - 1 ) * D ), abs( X - ( Y + 1 ) * D ),
                abs( X + ( Y - 1 ) * D ), abs( X + ( Y + 1 ) * D )) )


Measured memory_bytes: 9180
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vll vector<ll>
#define vpll vector<pll>
#define vpii vector<pii>
#define pb push_back
#define eb emplace_back
#define mt make_tuple
#define MP make_pair
#define fs first
#define sc second
#define F first
#define S second
#define nl "\n"
#define asche cerr<<"Ekhane asche\n";
#define pf printf
#define sf scanf
#define mem(a,x) memset(a,x,sizeof(a))
#define SZ(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define one(x) __builtin_popcount(x)
#define fout(x) fixed<<setprecision(x)
#define BeatMeScanf ios_base::sync_with_stdio(false)
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); deb(_it, args); }
void deb(istream_iterator<string> it) {}
template<typename T, typename... Args>
void deb(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    deb(++it, args...);
}
//template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
namespace IO
{
    #define in() ( { int a ; scanf("%d",&a); a; } )
    #define LL() ( { ll a ; scanf("%lld",&a); a; } )
       #define ULL() ( { ull a ; scanf("%llu",&a); a; } )
    #define DD() ({ double a; scanf("%lf", &a); a;})
    #define CC() ( { char a ; scanf("%c",&a); a; } )
    #define pf1(a) printf("%d\n",a)
    #define pf1ll(a) printf("%lld\n",a)
}
using namespace IO;

const int mod=998244353;
const int N=1e6+9;
const double eps=1e-9;
const double PI=acos(-1.0);
ll qpow(ll n,ll k) {ll ans=1;assert(k>=0);n%=mod;while(k>0){if(k&1) ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return ans%mod;}

int ans[N],cnt[N],sum[N],sq[N],inv[N];
int32_t main()
{
    for(int i=1;i<N;i++) inv[i]=qpow(i,mod-2);
    int n=in();
    for(int i=1;i<=n;i++){
        int k=in();
        cnt[k]++;
    }
    for(int i=1;i<N;i++){
        for(int j=i;j<N;j+=i){
            sum[i]+=1LL*cnt[j]*j%mod;
            sum[i]%=mod;
            sq[i]+=1LL*cnt[j]*j%mod*j%mod;
            sq[i]%=mod;
        }
    }
    int res=0;
    for(int i=N-1;i>=1;i--){
        ans[i]=(1LL*sum[i]*sum[i]%mod-sq[i]+mod)%mod;
        for(int j=i+i;j<N;j+=i) ans[i]=(ans[i]-ans[j]+mod)%mod;
        res=(res+1LL*ans[i]*inv[i]%mod)%mod;
    }
    res=1LL*res*inv[2]%mod;
    pf1(res);
    return 0;
}
///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1



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

using namespace std;

void solve(){
	int n; cin>>n;
	int c = 0;
	for(int i = 1; i <= n; i++){
		int a; cin>>a;
		if(a%2 == 1 && i%2 == 1){
			c++;
		}
	}
	cout << c << "\n";
}

int main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long int t = 1;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstring>
using namespace std;
#define ll long long

ll dp[405][405], num[405];
ll inf = 1e11;

int main()
{
	ll n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> num[i];
	}
	auto sum = [&](int L, int R) {
		ll s = 0;
		for(int i = L; i <= R; ++i) {
			s += num[i];
		}
		return s;
	};
	for (int j = 0; j < n; ++j) {
		for (int i = j; i >= 0; --i) {
		    if (j == i) {
		    	dp[i][j] = 0;
		    } else {
		    	dp[i][j] = 1e18L + 5;
				ll s = sum(i, j);
				for (int k = i; k < j; ++k) {
					dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + s);
				}
		    }
		}
	}
	cout << dp[0][n - 1] << endl;
	return 0;
}


Measured memory_bytes: 4860
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

string N;
int n,K;

long long comb(long long n,long long k) {
  if(n < 0 || k > n) return 0;
  if(k == 1) return n;
  else if(k == 2) return n*(n-1)/2;
  else return n*(n-1)*(n-2)/6;
}

long long pow(long long l) {
  long long res = 1;
  for(int i = 0;i < l;i++) res *= 9;
  return res;
}

long long solve(int i,bool smaller,int k) {
  if(i == n) {
    if(k == 0) return 1;
    else return 0;
  }
  if(k == 0) return 1;

  if(smaller) return comb(n-i,k)*pow(k);
  else {
    if(N.at(i) == '0') return solve(i+1,false,k);
    else {
      long long z = solve(i+1,true,k);
      long long m = solve(i+1,true,k-1)*(N.at(i)-'1');
      long long s = solve(i+1,false,k-1);
      return z+m+s;
    }
  }
  
}

int main() {
  
  cin >> N >> K;
  n = N.size();
  cout << solve(0,false,K) << endl;

  
}


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

#define pb push_back

using namespace std;

int data[20][20],n;
long long dp[1<<16];
vector<int> rem[17];

void generate(int bitmask,int lv)
{
  if (lv==n)
  {
    rem[__builtin_popcount(bitmask)].pb(bitmask);
    for(int c=0;c<n;c++)
    {
      if (bitmask&(1<<c))
      for(int c2=c+1;c2<n;c2++)
      {
        if (bitmask&(1<<c2))
        dp[bitmask]+=data[c][c2];
      }
    }
  }
  else
  {
    generate(bitmask,lv+1);
    generate(bitmask|(1<<lv),lv+1);
  }
}

void updateValue(int bitmask,vector<int> &bit1pos,int lv,int rem,int countrembit1)
{
  if (lv==bit1pos.size())
  {
    dp[bitmask]=max(dp[bitmask],dp[rem]+dp[bitmask^rem]);
  }
  else if (countrembit1<=bit1pos.size()/2)
  {
    updateValue(bitmask,bit1pos,lv+1,rem,countrembit1);
    updateValue(bitmask,bit1pos,lv+1,rem|(1<<bit1pos[lv]),countrembit1+1);
  }
}

int main()
{
  scanf("%d",&n);
  for(int c=0;c<n;c++)
  for(int c2=0;c2<n;c2++)
  scanf("%d",&data[c][c2]);
  generate(0,0);
  // for(int c=0;c<1<<n;c++)
  // {
  //   char tmp[100];
  //
  //   itoa(c,tmp,2);
  //   printf("%0*s %lld\n",n,tmp,dp[c]);
  // }

  // for(int c=1;c<=n;c++)
  // {
  //   for(int c2=0;c2<rem[c].size();c2++)
  //   {
  //     for(int c3=ceil((double)c/2);c3<c;c3++)
  //     {
  //       for(int c4=0;c4<rem[c3].size();c4++)
  //       {
  //         if ((rem[c][c2]|rem[c3][c4])==rem[c][c2])
  //         dp[rem[c][c2]]=max(dp[rem[c][c2]],dp[rem[c3][c4]]+dp[rem[c][c2]^rem[c3][c4]]);
  //       }
  //     }
  //   }
  // }
  for(int c=0;c<1<<n;c++)
  {
    vector<int> tmp;

    for(int c2=0;c2<n;c2++)
    if (c&(1<<c2))tmp.pb(c2);
    updateValue(c,tmp,0,0,0);
  }
  printf("%lld\n",dp[(1<<n)-1]);
}
/*
generate 2^16 score if they in same group
for 1->16 (1 bit of 1 -> 16 bit of 1)
foreach find minimum of sub 2 group
eg 1 bit -> not do anything
   2 bit -> get from some 1 bit + 1 bit that not intercept
   3 bit -> get from some 1 bit + 2 bit that not intercept

000 001 010 100  011 101 110 111
  0   0   0   0 -100  20  10 -90

0000 1000 0100 0010 0001 1100 1010 1001 0110 0101 0011 1110 1101 1011 0111 1111
   0    0    0    0    0   1M   1M   1M   1M   1M   -1   3M   3M 2M-1 2M-1 1M+2M+2M-1
*/


Measured memory_bytes: 1152
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	q := sc.NextInt()
	s := sc.NextLine()
	cnt := 0
	num := make([]int, n)
	for i := 1; i < len(s); i++ {
		if string(s[i]) == "C" && string(s[i-1]) == "A" {
			cnt++
		}
		num[i] = cnt
	}

	for i := 0; i < q; i++ {
		l := sc.NextInt()
		r := sc.NextInt()
		fmt.Printf("%+v\n", num[r-1]-num[l-1]) // output for debug
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 6016
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int mo=1000000007;
char s[300005];
int f[2][2][2][3];
int ans;
void UPD(int &x,int y){
	(x+=y)>=mo?x-=mo:233;
}
int main(){
	scanf("%s",s+1);
	int len=strlen(s+1);
	s[len+1]='1';
	f[0][0][0][0]=ans=1;
	For(i,1,len+1){
		memset(f[1],0,sizeof(f[1]));
		if (s[i]!='1')
			For(j,0,1) For(k,0,1) For(l,0,2)
				UPD(f[1][j][k][l==2?1:l+1],f[0][j][k][l]);
		if (s[i]!='0')
			For(k,0,1){
				UPD(f[1][(k==0)][k^1][0],f[0][0][k][0]);
				UPD(f[1][0][k][0],f[0][0][k][1]);
				UPD(f[1][0][k^1][0],f[0][0][k][2]);
				if (k!=1) UPD(f[1][1][k^1][0],f[0][1][k][0]);
				UPD(f[1][1][k][0],f[0][1][k][1]);
				UPD(f[1][1][k^1][0],f[0][1][k][2]);
			}
		if (s[i]=='?')
			ans=2ll*ans%mo;
		memcpy(f[0],f[1],sizeof(f[0]));
	}
	For(j,0,1) For(k,0,1) For(l,0,2)
		UPD(ans,mo-f[0][j][k][l]);
	printf("%d\n",ans);
}

Measured memory_bytes: 512