akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll ksm(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		b/=2;
		a=a*a%mod;
	}
	return ans;
}
int main()
{
	ll n,x,ans=1,s[100100],num[100100];
	memset(num,0,sizeof num);
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(!i&&x) ans=0;
		else if(i&&!x) ans=0;
		num[x]++;
	}
	if(ans)
	{
//		ans=num[1];
		for(int i=2;i<n;i++)
			if(num[i]&&num[i-1])
				ans=ans*ksm(num[i-1],num[i])%mod;
			else if(num[i]&&!num[i-1]) ans=0;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a = sorted(a)

for i in range(n):
    b[i] = (b[i], bisect.bisect_right(a, b[i]-1))

b = sorted(b)

bsum = [b[0][1]]
b[0] = b[0][0]
for i in range(1, n):
    bsum.append(bsum[i-1] + b[i][1])
    b[i] = b[i][0]

cnt = 0
for i in range(n):
    ind = bisect.bisect_right(b, c[i]-1)

    if ind > 0:
        cnt += bsum[ind-1]

print(cnt)

Measured memory_bytes: 36740
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

N,S = map(int,S().split())
A = [0] + LI()
mod = 998244353

# f(h,i,C)を h <= x_1 < … < x_k <= i かつ A_(x_1) + … + A_(x_k) = C を満たす(x_1,…,x_k)の組の個数とする
# そして F(i,C) = f(1,i,C) + … + f(i,i,C) と定める
# 求めたい値は、F(1,S) + … + F(N,S) である
# すると(大体) F(i,C) = F(i-1,C-A_i) + F(i-1,C) + f(i,i,C) が成り立つ 
# dp[i][C] = F(i,C) としてdpする

dp = [[0]*(S+1) for i in range(N+1)]

for i in range(1,N+1):
    for j in range(S+1):
        if j == 0:
            dp[i][j] = i
        elif i >= 1:
            if j > A[i]:
                dp[i][j] = (dp[i - 1][j - A[i]] + dp[i - 1][j]) % mod
            elif j == A[i]:
                dp[i][j] = (dp[i - 1][j - A[i]] + dp[i - 1][j] + 1) % mod
            else:
                dp[i][j] = dp[i - 1][j]

ans = 0
for i in range(1,N+1):
    ans = (ans + dp[i][S]) % mod

print(ans)

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

int main(){
  int n; cin >> n;
  int A[n+2], B[n+1], C[n+1];
  
  for (int i=1; i<=n; i++){
    cin >> A[i];
  }

  A[0] = 0; A[n+1] = 0;

  for (int i=1; i<=n+1; i++){
    B[i] = abs(A[i]-A[i-1]);
  }

  for (int i=2; i<=n+1; i++){
    C[i] = abs(A[i]-A[i-2]);
  }

  int cnt=0;

  for (int i=1; i<=n+1; i++){
    cnt += B[i];
  }

  int D[n+1];
  for (int i=1; i<=n; i++){
    D[i] = cnt - B[i] - B[i+1] + C[i+1];
  }

  for (int i=1; i<=n; i++){
    cout << D[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 2816
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++) 
		if ((1ll << i) & x) sum++;
	return sum;
}
ll factorial_[1000000];
ll comb(ll x, ll y, ll mod) {
	if (!factorial_[0]) {
		factorial_[0] = 1;
		for (int i = 1; i < 1000000; i++) {
			factorial_[i] = factorial_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(factorial_[x], mod, mod) *
		mod_pow(factorial_[x - y], mod - 2, mod) % mod *
		mod_pow(factorial_[y], mod - 2, mod) % mod;
}//xCy
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n;
int a[200000];
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (a[0] > 0) {
		cout << 0 << endl;
		return 0;
	}
	int ans = 1;
	sort(a, a + n);
	vector<int>b;
	for (int i = 0; i < n;) {
		int j = i;
		while (j < n && a[i] == a[j]) {
			j++;
		}
		if (i > 0 && a[i - 1] != a[i] - 1) ans = 0;
		b.push_back(j - i);
		i = j;
	}
	if (b[0] > 1) {
		ans = 0;
	}
	for (int i = 1; i < b.size(); i++) {
		(ans *= mod_pow(b[i - 1], b[i], mod)) %= mod;
	}
	ans %= mod;
	(ans += mod) %= mod;
	cout << ans << endl;
}

Measured memory_bytes: 2168
#include<iostream>
using namespace std;
int main(){
  int n;
  int h[105];
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>h[i];
  }
  h[0]=0;
  int times=0;
  for(int i=1;i<=n;i++){
    if(h[i]-h[i-1]>0)times+=h[i]-h[i-1];
  }
  cout<<times<<"\n";
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A, B, s=1, ans=0;
  cin >> A >> B;
  while(s<B) {
    s-=1;
    s+=A;
    ans++;
  }
  cout << ans << endl;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const ld EPS = 1e-8;

typedef int64_t Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst) : src(src), dst(dst), weight(1) {}
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

// ref: http://www.prefield.com/algorithm/graph/bellman_ford.html
bool shortestPath(const Graph g, int s, vector<Weight> &dist) {
  // Graph g has negative loop iff return false
  // O(VE)
  int n = g.size();
  dist.assign(n, INF + INF); dist[s] = 0;
  bool negative_cycle = false;
  REP(k, n) REP(i, n) for(Edge e : g[i]) {
    if (dist[e.dst] > dist[e.src] + e.weight) {
      dist[e.dst] = dist[e.src] + e.weight;
      if (k == n - 1) {
        dist[e.dst] = -INF;
        negative_cycle = true;
      }
    }
  }
  return !negative_cycle;
}


int main(){
  int N, M;
  cin >> N >> M;
  Graph g(N);
  REP(i, M) {
    int a, b, c;
    cin >> a >> b >> c; --a; --b;
    g[a].push_back(Edge(a, b, -c));
  }

  vector<Weight> dist;
  shortestPath(g, 0, dist);
  if (dist[N - 1] == -INF) {
    cout << "inf" << endl;
  } else {
    cout << -dist[N - 1] << endl;
  }
  return 0;
}



Measured memory_bytes: 384
import fileinput

def heads_win_proba(probs_list):
    prev_head_probs = [1.0]
    for coin_count, prob in enumerate(probs_list):
        coin_count += 1
        current_head_porbs = [0.0] * (coin_count + 1)
        for head_count in range(coin_count + 1):
            if head_count < coin_count:
                current_head_porbs[head_count] = prev_head_probs[head_count] * (1.0 - prob)
            if head_count > 0:
                current_head_porbs[head_count] += prev_head_probs[head_count - 1] * prob
        prev_head_probs = current_head_porbs
    return sum(prev_head_probs[len(prev_head_probs) // 2:])

inp = fileinput.FileInput()
coin_count = int(inp.readline())
prob_list = [float(n) for n in inp.readline().split(" ")]
print(heads_win_proba(prob_list))


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

int main(){
  int x;
  string str,str2;
  cin >> str;
 x=str.size();
  if (str.at(x-1)=='s') {
    str2="es";
  }
 else {
   str2="s";
 }
  cout << str << str2 << endl;
}

Measured memory_bytes: 3628
////////////////////////////////////////////////////////////////
//
//    (☝ ՞ਊ ՞)☝ << Be accept!!
//
//    C++ format for competitive professional V1.0
//
//    GCC is recommendation.
//
////////////////////////////////////////////////////////////////

#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<time.h>
#include<random>
#include<thread>
#include<boost/multiprecision/cpp_int.hpp>

#define rp(n) for(int i = 0;i < n;i++)
#define Be return
#define accept 0;

using ll = long long;
using namespace std;

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

int inline setup(void) {//set
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	return 0;
}
int lenght(char* str){//getcharlengh
	int i = 0;
	while (str[i]) {
		i++;
	}
	return i;
}
int main(int argc, const char* argv[]) {
	setup();
	ll a, b, k;
	cin >> a >> b >> k;
	if (a >= k) {
		a -= k;
	}
	else {
		k -= a;
		a = 0;
		if (b > k) {
			b -= k;
		}
		else {
			b = 0;
		}
	}
	cout << a << "\n" << b << "\n";
	Be accept
}


Measured memory_bytes: 256
from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
a, b = 0, 0
for i, x in enumerate(permutations(range(1, n + 1), n)):
    if x == p:
        a = i
    if x == q:
        b = i
print(abs(a - b))

Measured memory_bytes: 3064
function Main(input) {
    input = input.split("\n");
    const preWords = input[0].split('');
    const nextWords = input[1].split('');
    
    let num = 0;

    if (input[0] === input[1]) {
        console.log(0);
    } else {
        for (let i = 0, len = preWords.length; i < len;  i++) {
            if (preWords[i] !== nextWords[i]) {
                num ++;        
            }
        }
         console.log(num);
    }

}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int n, q;
  string s;
  cin >> n >> s >> q;

  while (q--) {
    int k;
    cin >> k;
    ll a = 0, b = 0, c = 0;
    ll res = 0;
    for (int i = 0; i < n; i++) {
      
      if (i >= k) {
        if (s[i - k] == 'D') a--, c -= b;
        if (s[i - k] == 'M') b--;
      }

      if (s[i] == 'D') a++;
      if (s[i] == 'M') b++, c += a;
      if (s[i] == 'C') res += c;
    }
    cout << res << endl;
  }

  return 0;
} 

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

using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define double long double
#define endl '\n'

const int N = 1e6;

int solve(int k) {
   int md = 0;
   for(int i = 1; i <= N; i++) {
      md *= 10;
      md %= k;
      md += 7;
      md %= k;
      if(md == 0) {
         return i;
      }
   }
   return -1;
}

signed main() {
   fio;
   int k; cin >> k;
   
   cout << solve(k) << endl;
   
   return 0;
}




Measured memory_bytes: 3648
#include<iostream>
int main()
{
	int a, b, c, d,x;
	std::cin >> x;
	a = x / 1000;
	b = (x % 1000)/100;
	c = (x % 100)/10;
	d = x % 10;
	if (a + b + c + d == 7) {
		std::cout << a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7" << std::endl;
	}
	else if (a + b + c - d == 7) {
		std::cout << a << "+" << b << "+" << c<<"-" << d << "=7" << std::endl;
	}
	else if (a + b - c + d == 7) {
		std::cout <<  a << "+" << b << "-" << c << "+" << d << "=7"  << std::endl;
	}
	else if (a + b - c - d == 7) {
		std::cout << a << "+" << b << "-" << c << "-" << d << "=7" << std::endl;
	}
	else if (a - b + c + d == 7) {
		std::cout << a << "-" << b << "+" << c << "+" << d << "=7" << std::endl;
	}
	else if (a - b + c - d == 7) {
		std::cout << a << "-" << b << "+" << c << "-" << d << "=7" << std::endl;
	}
	else if (a - b - c + d == 7) {
		std::cout << a << "-" << b << "-" << c << "+" << d << "=7" << std::endl;
	}
	else if (a - b - c - d == 7) {
		std::cout << a << "-" << b << "-" << c << "-" << d << "=7" << std::endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    long sum = 0;
    int min = Integer.MAX_VALUE;
    int cntm = 0;
    for (int i = 0; i < N; i++) {
      int a = scanner.nextInt();
      sum += Math.abs(a);
      min = Math.min(min, Math.abs(a));
      if (a < 0) cntm++;
    }

    if (cntm % 2 == 0) {
      System.out.println(sum);
      return;
    }
    sum -= min * 2;
    System.out.println(sum);
  }
}


Measured memory_bytes: 50360
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <queue>
using namespace std;
#define mod 924844033
typedef long long ll;
#define N 400050
int head[N],to[N],nxt[N],cnt,siz[N],pp[N],n;
ll fac[N],inv[N];
inline void add(int u,int v) {
	to[++cnt]=v; nxt[cnt]=head[u]; head[u]=cnt;
}
void dfs(int x,int y) {
	int i; siz[x]=1; 
	for(i=head[x];i;i=nxt[i]) if(to[i]!=y) {
		dfs(to[i],x);
		siz[x]+=siz[to[i]];
		pp[siz[to[i]]]++;
	}
	if(x!=1) pp[n-siz[x]]++;
}
ll qp(ll x,ll y) {
	ll re=1; for(;y;y>>=1,x=x*x%mod) if(y&1) re=re*x%mod; return re;
}
ll INV(ll x) {return qp(x,mod-2);}
void ntt(ll *a,int len,int flg) {
	int i,j,k,t; ll tmp,w,wn;
	for(i=k=0;i<len;i++) {
		if(i>k) swap(a[i],a[k]);
		for(j=len>>1;(k^=j)<j;j>>=1) ;
	}
	for(k=2;k<=len;k<<=1) {
		t=k>>1; wn=qp(5,(mod-1)/k); if(flg==-1) wn=INV(wn);
		for(i=0;i<len;i+=k) {
			w=1;
			for(j=i;j<i+t;j++) {
				tmp=a[j+t]*w%mod;
				a[j+t]=(a[j]-tmp)%mod;
				a[j]=(a[j]+tmp)%mod;
				w=w*wn%mod;
			}
		}
	}
	if(flg==-1) for(tmp=INV(len),i=0;i<len;i++) a[i]=a[i]*tmp%mod;
}
ll a[N<<1],b[N<<1],g[N<<1],f[N<<1];
int main() {
	scanf("%d",&n);
	int i,x,y;
	for(i=1;i<n;i++) scanf("%d%d",&x,&y),add(x,y),add(y,x);
	dfs(1,0);
	for(fac[0]=i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod;
	inv[n]=INV(fac[n]);
	for(i=n-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	for(i=0;i<=n+1;i++) a[i]=pp[i]*fac[i]%mod, b[i]=inv[n-i+1];
	int len=1;
	for(;len<=(n+n);len<<=1) ;
	ntt(a,len,1); ntt(b,len,1);
	for(i=0;i<len;i++) a[i]=a[i]*b[i]%mod;
	ntt(a,len,-1);
	for(i=1;i<=n;i++) g[i]=a[n+i+1];
	for(i=1;i<=n;i++) {
		f[i]=(n*fac[n]%mod*inv[n-i]%mod-g[i])*inv[i]%mod;
		printf("%lld\n",(f[i]+mod)%mod);
	}
}


Measured memory_bytes: 40320
//こっちは通らない
#include<stdio.h>
int main() {
	int card[4][13] = {0};
	char marks[4] = {'S','H','C','D'};
	int n;
	char mark;
	int num;
	
	int i,j;



	scanf("%d ", &n);
	for (i = 0; i < n; i++) {
		scanf("%c %d ", &mark, &num);
		for (j = 0; j < 4; j++) {
			if (mark == marks[j]) {
				card[j][num - 1] = 1;
			}
		}
	}






	/*
	scanf("%d ", &n);
	for (i = 0; i < n; i++) {
		scanf("%c %d ", &mark, &num);
		for (j = 0; j < 4; j++) {
			if(mark == marks[i]){
				card[j][num-1] = 1;
			}
		}
	}*/

for (i = 0; i < 4; i++) {
	for (j = 0; j < 13; j++) {
		if (card[i][j] == 0) {
			printf("%c %d\n", marks[i], j + 1);
		}
	}
}
	
	/*
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			if (card[i][j] == 0)printf("%c %d\n", marks[i], j+1);
		}
	}*/
	return 0;
}


Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    double i,j,k,n;
    std::cout.precision(10);
    int yes=0;
    cin>>n;
    i=n/(3.00);
    cout<<(i*i*i);
    
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 3740
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Main
{
	static void merge(int arr[], int l, int m, int r) 
    { 
        int n1 = m - l + 1; 
        int n2 = r - m; 
        int L[] = new int [n1]; 
        int R[] = new int [n2]; 
        for (int i=0; i<n1; ++i) 
            L[i] = arr[l + i]; 
        for (int j=0; j<n2; ++j) 
            R[j] = arr[m + 1+ j]; 
        int i = 0, j = 0; 
        int k = l; 
        while (i < n1 && j < n2) 
        { 
            if (L[i] <= R[j]) 
            { 
                arr[k] = L[i]; 
                i++; 
            } 
            else
            { 
                arr[k] = R[j]; 
                j++; 
            } 
            k++; 
        } 
        while (i < n1) 
        { 
            arr[k] = L[i]; 
            i++; 
            k++; 
        } 
        while (j < n2) 
        { 
            arr[k] = R[j]; 
            j++; 
            k++; 
        } 
    } 
    static void sort(int arr[], int l, int r) 
    { 
        if (l < r) 
        { 
            int m = (l+r)/2; 
            sort(arr, l, m); 
            sort(arr , m+1, r); 
            merge(arr, l, m, r); 
        } 
    } 
    static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    } 
    static long power(long n,long m)
    {
    	if(m==0)
    		return 1;
    	long ans=1;
    	while(m>0)
    	{
    		ans=ans*n;
    		m--;
    	}
    	return ans;
    }
	static int binarySearch(ArrayList<Integer> arr, int x) 
    { 
        int l = 0, r = arr.size() - 1,m=l + (r - l) / 2; 
        while (l <= r) { 
            m = l + (r - l) / 2; 
            if (arr.get(m) == x) 
                return m; 
            if (arr.get(m) < x) 
                l = m + 1; 
            else
                r = m - 1; 
        } 
        return (int)Math.max(l, m); 
    } 
	public static void main(String args[])throws Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=1;//Integer.parseInt(br.readLine());
	    outer:for(int i=1;i<=t;i++)
	    {
	        int n,k;
	        String s=br.readLine();
	        String ss[]=s.split(" ");
	        n=Integer.parseInt(ss[0]);
	        k=Integer.parseInt(ss[1]);
	        int arr[]=new int[n];
	        s=br.readLine();
	        long sum=0;
	        String str[]=s.split(" ");
	        for(int j=0;j<k;j++)
	        {
	        	arr[j]=Integer.parseInt(str[j]);
	        	sum+=arr[j];
	        }
	        if(sum>n)
	        System.out.println("-1");
	        else
	        System.out.println(n-sum);
	    }
	}
}


Measured memory_bytes: 38496
#include <bits/stdc++.h>
using namespace std;
signed main(){
    string a;
    cin >> a ;
    int sz=a.length();
    bool pp=true;
    for(int i=0,j=sz-1;i<j;i++,j--){
        if(a[i]!=a[j])
            pp=false;
    }
    int x=0;
    int y=(sz-1)/2;
    y--;
    for(;x<y;x++,y--){
            if(a[x]!=a[y])
                pp=false;
    }
    x=(sz+3)/2;
    x--;
    y=sz-1;
     for(;x<y;x++,y--){
            if(a[x]!=a[y])
                pp=false;
    }
    if(pp)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
#include<stdio.h>


int main(void){

	int m1,m2,d1,d2;


	scanf("%d %d",&m1,&d1);
	scanf("%d %d",&m2,&d1);

	if(m1 != m2){
		printf("1\n");
	}else{
		printf("0\n");
	}



	return 0;
}

Measured memory_bytes: 128
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0, d = 0, e = 0, ans = 0, x = 0, y = 0, z = 0, maxy = -1,maxy2=-1, mini = 999999999, mini2 = 9999999999, counter = 0, endp = 0, checker = 0;
std::string code;
vector<long long int>vec;
long long int N = 0, M = 0,R=0;
long long int costs[201][200*199/2+1],visit[10];

int main() {


	cin >> N >> M >> R;

	rep(i, R) {
		cin >> x;
		vec.push_back(x);
	}
	std::sort(vec.begin(), vec.end());
	rep(i, N) {
		rep(j, N) {
			costs[i+1][j+1] = INF;

		}
	}
	rep(j, M) {
			cin >> a >> b >> c;
			costs[a][b] = c;
			costs[b][a] = c;
	}
	for (int i = 1; i <= N; i++) {
		costs[i][i] = 0;
	}
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j]);
			}
		}
	}
	do {
		ans = 0;
		rep(i, vec.size() - 1) {
			ans += costs[vec[i]][vec[i + 1]];
		}
		mini = min(ans, mini);
		
	} while (next_permutation(vec.begin(), vec.end()));
	cout << mini << endl;
}




Measured memory_bytes: 29056
from sys import stdin


while True:
    n = int(stdin.readline())
    if n==0: break
    ps = []
    prd = {}
    for gomi in xrange(n):
        p,a,b = map(int,stdin.readline().split())
        if p in ps: r = prd.pop(p)+a*b
        else:
            ps.append(p)
            r = a*b
        prd.update({p:r})
    isNA = True
    for p in ps:
        if prd[p]>=1000000:
            print p
            isNA = False
    if isNA: print "NA"

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

int main(){
  int n,m;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++){
    cin >> d[i];
  }
  cin >> m;
  vector<pair<int,int>> e(m);
  for(int i = 0; i < m; i++){
    int a,b;
    cin >> a >> b;
    e[i].first = a;
    e[i].second = b;
  }
  for(int i = 0; i < m; i++){
    long long t = 0;
    for(int j = 0; j < n; j++){
      if(j+1 == e[i].first){
        t += e[i].second;
      }else{
        t += d[j];
      }
    }
    cout << t << endl;
  }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    map<string, ll> x;
    rep(i, N){
        string tmp; cin >> tmp;
        if (x.find(tmp) != x.end()){
            x[tmp]++;
        } else {
            x[tmp] = 1;
        }
    }
    cout << "AC x " << x["AC"] << endl;
    cout << "WA x " << x["WA"] << endl;
    cout << "TLE x " << x["TLE"] << endl;
    cout << "RE x " << x["RE"] << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
ll a[200005];
int main() {
	int k, n;
	cin >> k >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll sub=-2000000, ans;
	for (int i = 0; i < n - 1; i++) {
		sub = max(sub, a[i + 1] - a[i]);
	}
	ans = max(sub, (k - a[n - 1]) + a[0]);
	cout << k - ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>

using namespace std;

int main() {
    long long n, k, q;
    cin >> n >> k >> q;
    vector<long long> ps(n, 0);
    for (long long i = 0; i < q; ++i) {
        size_t j;
        cin >> j;
        ++ps[j - 1];
    }
    for (const auto& p : ps) {
        if (q - p < k)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<limits.h>

int main(void){
    int a,i,n,min,max;
    long int sum;
    min=INT_MAX;
    max=INT_MIN;
    sum=0;
    scanf("%d", &n);
    for ( i = 0 ; i < n ; i++ ){
        scanf("%d", &a);
        if ( min > a ) min = a;
        if ( max < a ) max = a;
        sum += a;
    }
    printf("%d %d %ld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 2148
//BISMILLAH
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    int t,n,vagfol,vagsesh,flag=0;
    cin>>t;
    if(t>=30) cout<< "Yes"<<endl;
    else cout<< "No"<<endl;
 }


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

int main(){
  string str, str1, str2;
  int n, m;
  
  while(1){
    cin >> str;
    if(str == "-") break;
    cin >> n;
    for(int i = 0; i < n; i++){
      cin >> m;
      str1 = str.substr(0,m);
      str2 = str.substr(m,str.size() - m);
      str = str2 + str1;
    }
    cout << str << endl;
  }
}


Measured memory_bytes: 3204
import bisect

N= int(input())
a = map(int, input().split(" "))
b = map(int, input().split(" "))
c = map(int, input().split(" "))

a = sorted(a)
b = sorted(b)
c = sorted(c)

result = 0
for i in b:
    ta = bisect.bisect_left(a,i)
    tc = bisect.bisect_right(c,i)
    result += ta*(N-tc)
print(result)

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

using namespace std;
typedef long long ll;

int main()
{
  ll n;
  cin >> n;
  string s, t;
  cin >> s >> t;

  for (auto i = 0; i < s.size(); i++)
  {
    cout << s[i] << t[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	int c = 0;
	int res = 0;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		res += t * c;
		c += t;
	}
	cout << res << endl;
}


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

int main(void) {
  int k, s;
  cin >> k >> s;

  ll ans = 0;

  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int z = s - x - y;
      if (z >= 0 && z <= k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int min, mid ,max;
    scanf("%d %d %d",&min,&mid,&max);
    if(min < mid && mid < max){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;

int main(){
    int N,M;
    cin >> N >> M;

    int WA[105000];
    bool AC[105000];

    int WAnum=0;
    int ACnum=0;
    
    for(int i=1;i<=N;i++){
        WA[i] = 0;
        AC[i] = false;
    }

    while(M--){
        int p;
        string s;
        cin >> p >> s;
        if(AC[p]) continue;
        if(s=="AC"){
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        }else if(s=="WA"){
            WA[p]++;
        }
    }

    cout << ACnum << " " << WAnum << endl;

}

Measured memory_bytes: 768
t="abcdefghijklmnopqrstuvwxyz"
s=input()
k=int(input())
a=[t.index(i)for i in s]
ans=""
for i in a:
  j=i
  if i==0:
    ans+="a"
    continue
  if k>=26-i:
    k-=26-i
    j=0
  ans+=t[j]
j+=k
j%=26
ans=ans[:-1]+t[j]
print(ans)

Measured memory_bytes: 4212
/**** Last Updated 19-June-2020*****/
/*
*
*/
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define sets            set<string> //insert() .top()
#define seti            set<int>
#define pii             pair<int,int>
#define vi              vector<int> //push_back()
#define mii             map<int,int>
#define pqb             priority_queue<int> //insert()
#define pqs             priority_queue<int,vi,greater<int> >
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int32_t main()
{
    FIO;
    char c;cin>>c;
    if(c>='A'&&c<='Z')cout<<"A"<<endl;
    else cout<<"a"<<endl;
}



Measured memory_bytes: 3640
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        HashMap<Integer,Integer> A = new HashMap<>();
        for (int i = 0; i < N; i++){
            int a = sc.nextInt();
            if (A.containsKey(a)){
                System.out.println("NO");
                return;
            }
            A.put(a,0);
        }
        System.out.println("YES");
    }
}


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

int main(){
  int n; cin >> n;
  vector<int> d(n);
  for(int i=0; i<n; i++){
    cin >> d[i];
  }
  int ans = 0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      ans += d[i]*d[j];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define ENDL '\n'
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FOR_EACH(i, v) for (auto&& i : v)

const int MOD = 1000000007;

template<int mod> class Fp {
public:
	long long mVal;

	Fp(long long val = 0)
	{
		mVal = val % mod;
		if (mVal < 0) {
			mVal += mod;
		}
	}

	int getMod() { return mod; }

	Fp operator-() const
	{
		return mVal ? mod - mVal : 0;
	}

	Fp& operator+=(const Fp& fp)
	{
		mVal += fp.mVal;
		if (mVal >= mod) {
			mVal -= mod;
		}
		return *this;
	}

	Fp& operator-=(const Fp& fp) {
		mVal -= fp.mVal;
		if (mVal < 0) {
			mVal += mod;
		}
		return *this;
	}

	Fp& operator*=(const Fp& fp) {
		mVal = mVal * fp.mVal % mod;
		return *this;
	}

	Fp& operator/=(const Fp& fp) {
		long long a = fp.mVal;
		long long b = mod;
		long long u = 1LL;
		long long v = 0LL;
		while (b) {
			long long t = a / b;
			a -= t * b;
			swap(a, b);
			u -= t * v;
			swap(u, v);
		}
		mVal = mVal * u % mod;
		if (mVal < 0) {
			mVal += mod;
		}
		return *this;
	}
};

Fp<MOD> operator+(const Fp<MOD>& fp1, const Fp<MOD>& fp2)
{
	return Fp<MOD>(fp1) += fp2;
}

Fp<MOD> operator-(const Fp<MOD>& fp1, const Fp<MOD>& fp2)
{
	return Fp<MOD>(fp1) -= fp2;
}

Fp<MOD> operator*(const Fp<MOD>& fp1, const Fp<MOD>& fp2)
{
	return Fp<MOD>(fp1) *= fp2;
}

Fp<MOD> operator/(const Fp<MOD>& fp1, const Fp<MOD>& fp2)
{
	return Fp<MOD>(fp1) /= fp2;
}

bool operator==(const Fp<MOD>& fp1, const Fp<MOD>& fp2)
{
	return fp1.mVal == fp2.mVal;
}

bool operator!=(const Fp<MOD>& fp1, const Fp<MOD>& fp2)
{
	return !(fp1 == fp2);
}

ostream& operator<<(ostream& os, const Fp<MOD>& fp)
{
	return os << fp.mVal;
}

Fp<MOD> modPow(const Fp<MOD>& fp, long long n)
{
	if (!n) {
		return Fp<MOD>(1LL);
	}
	Fp<MOD> t = modPow(fp, n / 2);
	t *= t;
	if (n & 1) {
		t *= fp;
	}
	return t;
}

int N;
int M;
vector<pair<int, int>> prime;
vector<Fp<MOD>> comb;

int primeFactorize(int n, vector<pair<int, int>>* prime)
{
	int ret = 0;

	for (int i = 2; i * i <= n; i++) {
		if (!(n % i)) {
			prime->push_back(make_pair(i, 1));
			n /= i;
			while (!(n % i)) {
				prime->back().second++;
				n /= i;
			}
			ret = max(ret, prime->back().second);
		}
	}
	if (n != 1) {
		prime->push_back(make_pair(n, 1));
		ret = max(ret, 1);
	}
	return ret;
}

void calcComb(int maxPrimeNum)
{
	comb.reserve(maxPrimeNum);

	Fp<MOD> t(1LL);
	FOR(i, maxPrimeNum) {
		t = t * (N + i) / (i + 1);
		comb.push_back(t);
	}
}

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

	cin >> N >> M;
	prime.clear();

	int maxPrimeNum = primeFactorize(M, &prime);
	calcComb(maxPrimeNum);
	int len = (int)prime.size();

	Fp<MOD> ans(1LL);
	FOR(i, len) {
		ans *= comb[prime[i].second - 1];
	}

	cout << ans << ENDL;

	return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	const char *SEP = " ";
	char input_str[512];
	char *num_str;
	int r, g, b, k, i;

	fgets(input_str, sizeof(input_str), stdin);
	num_str = strtok(input_str, SEP);
	r = atoi(num_str);
	num_str = strtok(NULL, SEP);
	g = atoi(num_str);
	num_str = strtok(NULL, SEP);
	b = atoi(num_str);

	fgets(input_str, sizeof(input_str), stdin);
	k = atoi(input_str);

	for ( i = 0; i < k; i++ ) {
		if ( g <= r ) {
			g <<= 1;
		}
		else {
			b <<= 1;
		}
	}

	if ( (r < g) && (g < b) ) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 1596
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string a,b;
    cin >> a >> b;
    if(a.size()>b.size()){
        cout << "GREATER" << endl;
    }else if(a.size()<b.size()){
        cout << "LESS" << endl;
    }else if(a==b){
        cout << "EQUAL" << endl;
    }else{
        for(int i=0; i<a.size(); i++){
            if(a.at(i)>b.at(i)){
                cout << "GREATER" << endl;
                break;
            }else if(a.at(i)<b.at(i)){
                cout << "LESS" << endl;
                break;
            }
        }
    }
}


Measured memory_bytes: 256
S = input()
T = input()

LS = len(S)
LT = len(T)

Eqnum = 0
for i in range(LS - LT + 1):
    cnt = 0
    for j in range(LT):
        if T[j] == S[i+j]:
            cnt += 1
    if cnt > Eqnum:
        Eqnum = cnt

print(LT - Eqnum)


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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

const int INF = 1e9;

int main(void){

	int K, N; cin >> K >> N;
	vector<int> A(N);

	REP(i,N) cin >> A[i];

	vector<int> d(N);
	FOR(i,1,N){
		d[i-1] = A[i] - A[i-1];
	}
	d[N-1] = A[0] + K - A[N-1];

	SORT(d);
	ll ans = 0;
	REP(i,N-1){
		ans += d[i];
	}
	
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 1792
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val s = in.readLine()

    out.println(
      if (s == "AAA" || s == "BBB") {
        "No"
      } else {
        "Yes"
      }
    )
    out.flush()
  }
}


Measured memory_bytes: 25400
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,M,k[110]={0};
    string s[110],t[110];
    cin >> N;
    for(int i=0;  i<N; i++){
        cin >> s[i];
    }
    cin >> M;
    for(int i=0;  i<M; i++){
        cin >> t[i];
    }

    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(s[i] == s[j]){
                k[i]++;
            }
        }

        for(int j=0; j<M; j++){
            if(s[i] == t[j]){
                k[i]--;
            }
        }
    }
    sort(k,k+110);
    reverse(k,k+110);
    if(k[0] > 0){
        cout << k[0] << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var k = int.Parse(Console.ReadLine());

        var s = "";
        for (int i = 0; i < k; ++i)
        {
            s += "ACL";
        }

        Console.WriteLine(s);
    }
}


Measured memory_bytes: 27380
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
 
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

long long int pa(int rank,long long int si,long long int *pat,long long int *sum)
{
    if(rank==0&&si==0)return 0;
    else if(rank==0&& si==1)return 1;
    else if(si==0 || si==1)return 0;
    else if(si<=*(sum+rank-1)+1)return pa(rank-1,si-1,pat,sum);
    else if(si==*(sum+rank-1)+2)return *(pat+rank-1)+1;
    else if(si==*(sum+rank))return *(pat+rank);
    else return *(pat+rank-1)+pa(rank-1,si-2-*(sum+rank-1),pat,sum)+1;
}

int main()
{
    int n;
    long long int x;
    scanf("%d %lld",&n,&x);
    long long int pat[55]={};
    long long int sum[55]={};
    pat[0]=1;
    sum[0]=1;
    REP(i,50)
    {
        pat[i+1]=pat[i]*2+1;
        sum[i+1]=sum[i]*2+3;
    }
    long long int ans=pa(n,x,pat,sum);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = b; i >= (a); --i)
#define repdl(i, a, b) for(ll i = b; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
#endif
using namespace std;

ll dp[55][2505];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  dp[0][0] = 1;
  int n, a; read(n, a);

  rep(i, 0, n) {
    int t; read(t);
    for (int i = 50; i >= 0; i--) for (int j = 2501; j >= 0; j--) if (dp[i][j])
      dp[i + 1][j + t] += dp[i][j];
  }

  ll ans = 0;
  rep(i, 1, n + 1) {
    ans += dp[i][a * i];
  }
  write(ans);
}



Measured memory_bytes: 3908
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;
vector<vector<int>> G(404040); 
vector<int> score(404040,0);
vector<int> ans(404040,-1);

int dfs(int x,int sum){
    if (ans[x]!=-1) return 0;
    sum+=score[x];
    ans[x] = sum;
    for (auto nex : G[x]){
        dfs(nex,sum);
    }
    return 0;
}

int main(){
	int n,q;cin>>n>>q;
    rep(i,0,n-1){
        int a,b;cin>>a>>b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i,0,q){
        int p,x;cin>>p>>x;
        score[p]+=x;
    }
    dfs(1,0);
    for(int i=1;i<=n;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 72148
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	int K;
	scanf("%d",&K);
	char table[K];

	char buf[20];
	for(int i = 0; i < K; i++){
		scanf("%s",buf);
		table[i] = buf[0];
	}

	int i_attack = 0,n_attack=0;
	for(int i = 0; i < K; i++){
		scanf("%s",buf);

		switch(buf[0]){
		case 'm':
			switch(table[i]){
			case 'm':
				//Do nothing
				break;
			case 't':
				i_attack = min(i_attack+1,5);
				break;
			case 'k':
				if(i_attack == 5){
					printf("Isono-kun\n");
					return 0;
				}else if(i_attack == 0){
					printf("Nakajima-kun\n");
					return 0;
				}else{
					i_attack = 0;
				}
				break;
			}
			break;
		case 't':
			n_attack = min(n_attack+1,5);
			switch(table[i]){
			case 'm':
				//Do nothing
				break;
			case 't':
				i_attack = min(i_attack+1,5);
				break;
			case 'k':
				if(i_attack == 0){
					printf("Nakajima-kun\n");
					return 0;
				}else{
					printf("Isono-kun\n");
					return 0;
				}
				break;
			}
			break;
		case 'k':
			switch(table[i]){
			case 'm':
				if(n_attack == 0){
					printf("Isono-kun\n");
					return 0;
				}else if(n_attack == 5){
					printf("Nakajima-kun\n");
					return 0;
				}else{
					//Do nothing
				}
				break;
			case 't':
				if(n_attack == 0){
					printf("Isono-kun\n");
					return 0;
				}else{
					printf("Nakajima-kun\n");
					return 0;
				}
				break;
			case 'k':
				if(i_attack == n_attack){
					i_attack = 0;
				}else{
					if(i_attack < n_attack){
						printf("Nakajima-kun\n");
						return 0;
					}else{
						printf("Isono-kun\n");
						return 0;
					}
				}
				break;
			}
			n_attack = 0;
			break;
		}
	}

	printf("Hikiwake-kun\n");

	return 0;
}

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

bool isparindrome(const string &s) {
    int n = s.size();
    for (int i=0; i<n/2; i++) {
        if (s[i] != s[n-1-i]) {
            return false;
        }
    }
    return true;
}
bool solve(const string &s) {
    int n = s.size();
    return isparindrome(s) && isparindrome(s.substr(0,n/2)) && isparindrome(s.substr((n+1)/2,n/2));
}

int main() {
    string s;
    cin >> s;
    cout << (solve(s) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
using P = pair<int, int>;
using ll = long long;
vector<int> to[100005];
int cost[100005];
int a, b;
ll calcCost(ll x) {
    return x*a + ((int)log10(x)+1)*b;
}
map<ll, ll> prime_factors(ll n) {
    map<ll, ll> res;
    if(n == 1) { // n=1 の素因数分解は n^1
        res[n] = 1;
        return res;
    }
    for(ll i = 2, _n = n; i*i <= _n; ++i) {
        while(n % i == 0) {
            ++res[i]; // 素数i^{res[i]}
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

signed main(){
    ll n;
    cin >> n;

    map<ll,ll> res = prime_factors(n);
    ll ans = 0;
    for(map<ll,ll>::iterator it= res.begin(), end = res.end(); it != end; ++it) {
        if(it->first==1) continue;
       ans++;
       int cnt = 1;
       int tmp = cnt;
       while(tmp<it->second) {
           cnt++;
           tmp+=cnt;
           if(tmp<=it->second) ans++;
       } 
       //cout << it->first <<" " <<it->second << endl;
    }
    cout << ans << endl;

    return 0;
}





Measured memory_bytes: 6072
from collections import Counter
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n = int(input())
k = list(map(int,input().split()))

c = Counter(k)

li = c.most_common()

a_li = [x for x in li if x[1] != 1]

max = 0

for i in a_li:
    num = i[1]
    max = max + cmb(num,2)
    
#print(max)

for i in k:
    num = c[i]
    if num == 1:
        ans = max
    elif num == 2:
        ans = max - 1
    else:
      pre = cmb(num,2)
      cur = cmb(num-1,2)
      ans = max - pre + cur
    print(ans)

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

#define all(x) x.begin(),x.end()
#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

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

const int MAXN = 200'005;

const int MOD = 1000000007;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

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

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

vector<int> p[3];

char s[4005];

int main(){
    int n=read();
    scanf("%s", s+1);

    vector<char> t;
    t.PB('R');
    t.PB('G');
    t.PB('B');

    for(int i=1;i<=n;++i){
        if(s[i]=='R')p[0].PB(i);
        if(s[i]=='G')p[1].PB(i);
        if(s[i]=='B')p[2].PB(i);
    }

    LL ans=0;

    for(int i=1;i<=n;++i){
        for(int j=i+1;j<=n;++j){
            if(s[i]!=s[j]){
                for(int k=0;k<=2;++k){
                    if(t[k]!=s[i]&&t[k]!=s[j]){
                        int num=p[k].end()-lower_bound(p[k].begin(),p[k].end(),j);
                        ans+=num;
                        int pos=lower_bound(p[k].begin(),p[k].end(),j+j-i)-p[k].begin();
                        if(pos<SZ(p[k])&&p[k][pos]==j+j-i)--ans;
                    }
                }
            }
        }
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();
  VV< VV< V<> > > dp; assign(dp, n + 1, 2, 2, 2, 2, 0);
  dp[0][1][0][0][0] = 1;
  for (int i = 0; i < n; ++i) for (int d : {0, 3, 5, 7}) {
    for (int f3 = 0; f3 < 2; ++f3) for (int f5 = 0; f5 < 2; ++f5) for (int f7 = 0; f7 < 2; ++f7) {
      if (f3 | f5 | f7 and !d) continue;
      dp[i + 1][0][f3 | d == 3][f5 | d == 5][f7 | d == 7] += dp[i][0][f3][f5][f7];
      if (d > s[i] - '0') continue;
      dp[i + 1][d == s[i] - '0'][f3 | d == 3][f5 | d == 5][f7 | d == 7] += dp[i][1][f3][f5][f7];
    }
  }
  cout << dp[n][0][1][1][1] + dp[n][1][1][1][1] << '\n';
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(x) x.begin(), x.end()

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}

ll solve(ll n, ll a, ll b) {
    if (a > b) swap(a, b);
    if ((a - b) % 2 == 0) return abs(a - b) / 2;
    ll ans = n - b + 1;
    a += ans;
    b = n;
    return ans + (abs(a - b) / 2);
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = solve(n, a, b);
    a = n - a + 1;
    b = n - b + 1;
    chkmin(ans, solve(n, a, b));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256