akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int maxN = 2e5 + 10, mod = 998244353;

int n;
int f[2][3][3][2];//place, sum, last, vis
char s[maxN + 1];

inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }

inline void work()
{
	int now = 0;
	f[now][0][0][0] = f[now][1][1][0] = f[now][2][2][0] = 1;
	for(int i = 2; i <= n; i++)
	{
		now ^= 1;
		memset(f[now], 0, sizeof(f[now]));
		for(int s = 0; s < 3; s ++)
			for(int last = 0; last < 3; last ++)
				for(int nxt = 0; nxt < 3; nxt ++)
				{
					int &f0 = f[now][ (s + nxt) % 3 ][nxt][0], &f1 = f[now][ (s + nxt) % 3 ][nxt][1];
					if(last == nxt) f1 = ADD(f1, ADD(f[now ^ 1][s][last][0], f[now ^ 1][s][last][1]));
					else f0 = ADD(f0, f[now ^ 1][s][last][0]), f1 = ADD(f1, f[now ^ 1][s][last][1]);
				}
	}

	int sum = 0, ans = 0;
	for(int i = 1; i <= n; i++) sum += (s[i] - 'a'), sum %= 3;
	for(int i = 0; i < 3; i++) ans = ADD(ans, f[now][sum][i][1]);
	int t = 1;
	for(int i = 1; i < n; i++)
		if(s[i] == s[i + 1]) t = 0;
	printf("%d\n", ADD(ans, t));
}

int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	bool flag = true;
	for(int i = 2; i <= n; i++)
		if(s[i] != s[1]) flag = false;

	if(flag) { puts("1"); return 0; }
	if(n == 2) { puts("2"); return 0; }
	if(n == 3)
	{
		if(s[1] == s[2] || s[2] == s[3]) puts("6");
		else if(s[1] == s[3]) puts("7");
			else puts("3");
		return 0;
	}

	work();
	return 0;
}

Measured memory_bytes: 384
use proconio::input;

fn main() {
    input! {
        n: usize,
        q: usize,
        a: [usize; n],
    }

    let mut t = FenwickTree::from_vec(a);
    for _ in 0..q {
        input! {
            f: u8,
            l: usize,
            r: usize,
        };
        if f == 1 {
            println!("{}", t.sum(l, r));
        } else {
            t.add(l, r);
        }
    }
}

struct FenwickTree<T> {
    v: Vec<T>,
}

use std::ops::AddAssign;
use num::{Integer, zero};

impl<T: Copy + AddAssign + Integer> FenwickTree<T> {
    fn new(n: usize) -> Self {
        Self {
            v: vec![zero(); n],
        }
    }

    fn from_vec(v: Vec<T>) -> Self {
        let n = v.len();
        let mut t = Self::new(n);
        for i in 0..n {
            let v = t.v[i] + v[i];
            t.v[i] = v;
            let p = i + Self::lsb(i + 1);
            if p < n {
                t.v[p] += v;
            }
        }
        t
    }

    fn add(&mut self, mut i: usize, v: T) {
        while i < self.v.len() {
            self.v[i] += v;
            i += Self::lsb(i + 1);
        }
    }

    fn sum(&self, l: usize, r: usize) -> T {
        self.get(r) - self.get(l)
    }

    fn get(&self, mut i: usize) -> T {
        let mut v = zero();
        while i > 0 {
            v += self.v[i - 1];
            i -= Self::lsb(i);
        }
        v
    }

    fn lsb(i: usize) -> usize {
        i & i.wrapping_neg()
    }
}


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



// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
  long long N, K, d, a;
  map<long long, long long> okasi;
  cin >> N >> K;


  for(long long i = 0; i < K; i++){
    cin >> d;

    for(long long j = 0; j < d; j++){
      cin >> a;
      okasi[a] = i;
    }
  }

  long long count = N;
  for(long long i = 1; i <= N; i++){
    if(okasi.count(i) > 0) count--;
  }


  cout << count << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  long long sum=0;
  cin >> N;
  for(int i=1;i<=N;i++){
    if(i%3!=0&&i%5!=0){
      sum += i;
    }

  }
  cout << sum << endl;
}

Measured memory_bytes: 3636
W,H=map(int,input().split())
p=[(int(input()),0) for i in range(W)]
q=[(int(input()),1) for i in range(H)]
r=sorted(p+q)
a=W+1
b=H+1
ans=0
for seq in r:
    wt,idx=seq
    if idx==0:
        a-=1
        ans+=b*wt
    else:
        b-=1
        ans+=a*wt
print(ans)

Measured memory_bytes: 27744
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
using namespace std;
int main(){
	string str;
	cin>>str;
	if(str=="zyxwvutsrqponmlkjihgfedcba"){
		cout<<-1<<endl;
		return 0;
	}
	if(str.size()<=25){
		int used[30];
		for(int i=0;i<30;i++){
			used[i]=0;
		}
		for(int i=0;i<str.size();i++){
			used[ str[i] - 'a' ] ++;
		}
		for(int i=0;i<26;i++){
			if(used[i]==0){
				char c = 'a' + i;
				cout<<str<<c<<endl;
				return 0;
			}
		}
	}
	else{
		int good = str.size();
		for(int i=str.size();i>=1;i--){
			if(str[i]>str[i-1]){
				good=i;
				i=0;
			}
		}
		char ma = 'z';
		for(int i=good;i<str.size();i++){
			if(str[i]>str[good-1]){
				ma = min(ma,str[i]);
			}
		}
		cout<<str.substr(0,good-1)<<ma<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)

int main(){
    long long n, k;
    cin >> n >> k;
    n = n % k;
    n = n>abs(n-k) ? abs(n-k):n;
    cout << n  << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
	static boolean A=true, B=false, C=false;
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input;
		while((input = br.readLine()) != null) {
			if(input.isEmpty()) break;
			String[] split = input.split(",");
			if(split[0].equals("A") || split[1].equals("A")) {
				if(split[0].equals("B") || split[1].equals("B")) {
					changeAB();
				}
				else if(split[0].equals("C") || split[1].equals("C")) changeCA();
			}
			else changeBC();
		}
		if(A) System.out.println("A");
		else if(B) System.out.println("B");
		else if(C) System.out.println("C");
	}
	public static void changeAB() {
		boolean tmp;
		tmp = A;
		A = B;
		B = tmp;
	}
	public static void changeBC() {
		boolean tmp;
		tmp = C;
		C = B;
		B = tmp;
	}
	public static void changeCA() {
		boolean tmp;
		tmp = A;
		A = C;
		C = tmp;
	}
}

Measured memory_bytes: 15068
N,L=map(int, input().split())
A=[]
for i in range(N):
  A.append(L+i)

A.sort()

Ans=999
x=0
for n in range(N):
  if abs(A[n])<Ans:
    Ans=abs(A[n])
    x=A[n]

print(sum(A)-x)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#ifdef grief
#define IOS
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) =",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<'\n';}
template<typename I,typename ...T> void _DO(I&&x,T&&...tail){cerr<<x<<" , ";_DO(tail...);}
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
typedef long long ll;
typedef pair<ll,ll> pll;

typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
const ll MAX=1e5+5;
const ll INF=4e18;
const ll MOD=1e9+7;
#define eb emplace_back
#define SZ(x) (int)x.size()
#define F first
#define S second
ll n,m,s,t;
vector<pll> adj[MAX];
ll cna[MAX],cnb[MAX];
ll disa[MAX],disb[MAX];
ll add(ll &a,ll b){
	a=(a+b)%MOD;
}
void sp(int st,ll dis[],ll cnt[]){
	for(int i=1;i<=n;i++)	dis[i]=INF;
	cnt[st]=1;
	dis[st]=0;
	heap pq; while(SZ(pq))	pq.pop();
	pq.push({0,st});
	while(SZ(pq)){
		ll now,d;
		tie(d,now)=pq.top();
		pq.pop();
		if(d>dis[now])	continue;
		debug(now);
		assert(d==dis[now]);
		for(auto ii:adj[now]){
			ll dd=d+ii.S;
			int nxt=ii.F;
			if(dd<dis[nxt]){
				dis[nxt]=dd;
				cnt[nxt]=cnt[now];
				pq.push({dd,nxt});
			}
			else if(dd==dis[nxt])
				add(cnt[nxt],cnt[now]);
		}
	}
}
int main(){
	IOS
	cin>>n>>m>>s>>t;
	for(int i=0;i<m;i++){
		int u,v;	cin>>u>>v;
		ll d;		cin>>d;
		adj[u].eb(v,d);
		adj[v].eb(u,d);
	}
	sp(s,disa,cna);
	ll rrd=disa[t];
	sp(t,disb,cnb);
	assert(cna[t]==cnb[s]);
	ll all=cna[t];
	debug(cna[t],cnb[s]);
//	if(!SZ(op)&&!SZ(opa)){
//		cout<<all*all%MOD<< '\n';
//		return 0;
//	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		if(disa[i]+disb[i]==rrd&&disa[i]==disb[i]){
			ll x=cna[i]*cnb[i]%MOD;
			add(ans,x*(all-x+MOD)%MOD);
		}
		for(auto ii:adj[i]){
			int nxt=ii.F;
			ll d=ii.S;
			if(disa[i]*2<rrd&&disb[nxt]*2<rrd&&disa[i]+disb[nxt]+d==rrd){
				ll x=cna[i]*cnb[nxt]%MOD;
				add(ans,x*(all-x+MOD)%MOD);
			}
		}
	}
	cout<<ans<< '\n';
}


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

using namespace std;

int main(void){
	int N;
	cin >> N;
	int ans;
	if(N%2 == 0){
		ans = N/2;
		ans = ans - 1;
	}
	else {
		ans = N/2;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

const COMMAX int64 = 1000000
const MOD int64 = 1000000007

var fac [COMMAX]int64
var finv [COMMAX]int64
var inv [COMMAX]int64

// テーブル作成
func COMinit() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := int64(2); i < COMMAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
}

// 二項係数nCk
func COM(n, k int64) int64 {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var x, y int
	fmt.Scan(&x, &y)

	a := 2*y - x
	b := 2*x - y
	if a < 0 || b < 0 {
		fmt.Println(0)
		return
	}
	if a%3 != 0 || b%3 != 0 {
		fmt.Println(0)
		return
	}
	a /= 3
	b /= 3

	COMinit()
	fmt.Println(COM(int64(a+b), int64(min(a, b))))
}


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

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    for (int i = 1; i <= N; i++){
        int j = i;
        int sum = 0;
        while (j != 0){
            sum += j % 10;
            j /= 10;
        }
        if (A<= sum && sum <= B){
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(a)*2 for a in input().split()]

y1 = 0
for n in range(N):
  if n%2 == 0:
    y1 += A[n]
  else:
    y1 -= A[n]
y1 //= 2
ans = str(y1)

yn = y1
for i in range(N-1):
  yn = A[i] - yn
  ans += " " + str(yn)
print(ans)

Measured memory_bytes: 14028
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3005;
ll dp[N][N][4],a[N][N];
int n,m,k;
int main(){
  scanf("%d%d%d",&n,&m,&k);
  memset(dp,-0x3f,sizeof(dp));
  while(k--){
    int x,y;
    scanf("%d%d",&x,&y); 
    scanf("%lld",&a[x][y]);
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(i==1&&j==1){
        dp[i][j][0]=0;
        dp[i][j][1]=a[i][j];
      }else if(i==1){
        for(int k=0;k<4;k++){
          dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
          if(k)dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+a[i][j]);
        }
      }else if(j==1){
        for(int k=0;k<4;k++){
          dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k]);
        }
        for(int k=0;k<4;k++){
          dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][k]+a[i][j]);
        }
      }else{
        for(int k=0;k<4;k++){
          dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
          if(k)dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+a[i][j]);
        }
        for(int k=0;k<4;k++){
          dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][k]);
        }
        for(int k=0;k<4;k++){
          dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][k]+a[i][j]);
        }
      }
    }
  }
  printf("%lld\n",max({dp[n][m][0],dp[n][m][1],dp[n][m][2],dp[n][m][3]}));
  return 0;
}

Measured memory_bytes: 356308
#include<bits/stdc++.h>
using namespace std;
int n,m,d;
int main(){
	scanf("%d%d%d",&n,&m,&d);
	for(register int i=1;i<=n;++i){
		for(register int j=1;j<=m;++j){
			int a=(i+j+m)/d%2,b=(i-j+m)/d%2;
			char c="RGYB"[(a<<1)+b];
			printf("%c",c);
		}
		puts("");
	}
		
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
char toupr(char c) {
  return (c - 0x20);
}
main(){
	string x,y,z;
  	cin>> x>>y>>z;
  	cout<<toupr(x[0])<<toupr(y[0])<<toupr(z[0])<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read() {
    ll x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())
        x=x*10+ch-'0';
    return x*f;
}
inline void chkmin( int &a,int b ) { if(a>b) a=b; }
inline void chkmax( int &a,int b ) { if(a<b) a=b; }
#define _ read()
#define ln endl
int main() {
	int n=_,ans=0;
	for( int i=1;i<=n;i++ ) {
		int x=i,tmp=0;
		while(x) {
			x/=10;
			tmp++;
		}
		ans+=(tmp&1);
	}
	cout<<ans<<ln;
}

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxD = 10 + 9;
const int maxN = 10 + 9;

int l, r;
vector<int> rem;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> l >> r;
	int len = r - l + 1;
	if(len >= 2019){
		cout << "0\n";
		return 0;
	}
	
	for(int i = l; i <= r; i++){
		rem.push_back(i % 2019);
	}
	
	sort(rem.begin(), rem.end());
	int L = rem.size();
	ll ans = INF;
	for(int i = 0; i < L; i++){
		for(int j = i + 1; j < L; j++){
			ans = min(ans, (ll)((rem[i] * rem[j]) % 2019));
		}
	}
	
	cout << ans << '\n';

	return 0;
}

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

int main(){
  int n,m;
  cin >>n>>m;
  
  int k[n];
  int a[n][30];
  
  int suki=0;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<30;j++){
      a[i][j]=0;
    }
  }
  
  for(int i=0;i<n;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin >> a[i][j];
    }
  }
  
  int shurui[m+1];
  for(int i=0;i<=m+1;i++){
    shurui[i]=0;
  }
  
  for(int i=0;i<n;i++){
    for(int j=0; j<k[i];j++){
      shurui[a[i][j]]++;
    }
  }
  
  for(int i=1;i<=m;i++){
    if(shurui[i]==n)suki++;
  }
  cout << suki << endl;
}

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

typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; (i) < int(n); ++(i))

int X, A, B, C;
int main(void){

	cin >> A;
	cin >> B;
	cin >> C;
	cin >> X;

	int ans = 0;
	rep(a, A+1){
		rep(b, B+1){
			rep(c, C+1){
				int sum = 500*a + 100*b + 50*c;
				// cout << sum << endl;
				if(sum == X){
					ans++;
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}


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

#define mp make_pair
#define s second 
#define f first
#define pb push_back


typedef long long ll;
typedef double db;


using namespace std;

const int inf=2e9+312;
const int N=2e5+4578;


int xx[4]={0, 0, 1, -1};
int yy[4]={1, -1, 0 ,0};

int a[N], b[N];

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> a[i];
	}
	b[2]=abs(a[2]-a[1]);
	for(int i=3; i<=n; i++){
		b[i]=min(b[i-2]+abs(a[i]-a[i-2]), b[i-1]+abs(a[i-1]-a[i]));
	}
	cout << b[n];
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = input()
cnt = s.count("R") * s.count("G") * s.count("B")
for i in range(n-2):
    for j in range(i+1, n-1):
        if s[i] == s[j]:
            continue
        k = j - i + j
        if k > n-1:
            break
        if s[i] == s[k] or s[j] == s[k]:
            continue
        cnt -= 1
print(cnt)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int x = x2-x1, y = y2-y1;
  cout << x2-y << " " << y2+x << " " << x1-y << " " << y1+x << endl;
  return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())#ken city
city=[]
c=1
for i in range(M):
    a,b=map(int,input().split())
    city.append([a,b,c]) #ken year count
    c+=1
city.sort(key=lambda x:(x[0],x[1]))
i=0
k=1
count=1
while i < M:
    if city[i][0]==k:
        city[i].append('{:0=6}'.format(k)+'{:0=6}'.format(count))
        count+=1
        i+=1
    else:
        count=1
        k+=1
city.sort(key=lambda x:x[2])
for i in range(M):
    print(city[i][3])

Measured memory_bytes: 34332
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[10];
    cin>>a[0]>>a[1]>>a[2];
    swap(a[0],a[1]);
    swap(a[0],a[2]);
    cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <cmath>
#include <string>
#include <set>
#include <map>
#define SIZE 100005
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char str[SIZE];
int nxt[SIZE][3];
int dp[SIZE];
int memo[3];

ll solve(vector <int> vec)
{
	int n=vec.size();
	memset(memo,-1,sizeof(memo));
	for(int i=n-1;i>=0;i--)
	{
		memo[vec[i]]=i;
		for(int t=0;t<3;t++) nxt[i][t]=memo[t];
	}
	if(memo[0]==-1||memo[1]==-1||memo[2]==-1) return 1;
	for(int i=0;i<=n;i++) dp[i]=0;
	//for(int i=0;i<n;i++) printf("%d ",vec[i]);puts("");
	dp[0]=1;
	for(int i=0;i<n;i++)
	{
		for(int t=0;t<3;t++)
		{
			if(t==vec[i]) continue;
			if(nxt[i][t]!=-1)
			{
				dp[nxt[i][t]]+=dp[i];
				if(dp[nxt[i][t]]>=MOD) dp[nxt[i][t]]-=MOD;
			}
		}
		//printf("%d\n",dp[i]);
	}
	ll ret=0;
	for(int i=1;i<n;i++)
	{
		if(vec[i]==vec[n-1])
		{
			ret+=dp[i];
			if(ret>=MOD) ret-=MOD;
		}
	}/*
	for(int i=n-4;i>=0;i-=2)
	{
		if(vec[i]==vec[i+2]&&vec[i+1]==vec[i+3])
		{
			ret-=dp[i];
			if(ret<0) ret+=MOD;
		}
		else break;
	}*/
	return ret;
}
int main()
{
	scanf("%s",&str);
	int n=strlen(str);
	int sum=0;
	vector <int> vec;
	vec.push_back(0);
	for(int i=0;i<n;i++)
	{
		if(str[i]=='a') sum+=2;
		else sum++;
		sum%=3;
		vec.push_back(sum);
	}
	//for(int i=0;i<vec.size();i++) printf("%d ",vec[i]);puts("");
	ll ret=1;
	vector <int> now;
	for(int i=0;i<vec.size();i++)
	{
		if(now.size()>=1&&now[now.size()-1]==vec[i])
		{
			ret=ret*solve(now);
			ret%=MOD;
			now.clear();
		}
		now.push_back(vec[i]);
	}
	ret=ret*solve(now);
	ret%=MOD;
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef complex<int> cli;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr> PQ;
const int SIZE=5+1e5;
const int alpha='z'-'a'+1;
int nums[SIZE][alpha][alpha];
int smaller[SIZE];
string s[SIZE];
struct Trie{
	Trie* next[alpha];
	bool isEnd;
	int size,tall;
	void init(){
		size=0;
		isEnd=false;
	}
	Trie():tall(0){init();}
	Trie(int x):tall(x){init();}
	Trie* nextNode(int target,bool unmake=false);
	Trie* nextNode(string &s,bool unmake=false){
		if(s.size()==tall) return NULL;
		return nextNode(s[tall]-'a',unmake);
	}
};
Trie root;
Trie nodes[SIZE*10];
int nextnodes=1;
Trie* Trie::nextNode(int target,bool unmake){

		if(!next[target]){
			if(unmake) return &nodes[0];
			next[target] = &nodes[nextnodes++];
			next[target]->tall=tall+1;	
		} 
		return next[target];
}
bool find(string &s,Trie* now){		
	while(now->nextNode(s)){
		now=now->nextNode(s);	
	}
	return now->isEnd;	
}
void add(string &s,Trie* root){
	Trie* now=root;
	while(now->nextNode(s)){
		now->size++;
		now=now->nextNode(s);	
	}
	now->isEnd=true;
	now->size++;
}
void analys(int x){
	Trie* now= &root;
	REP(i,s[x].size()){
		if(now->isEnd) smaller[x]++;
		FOR(j,'a','z'+1){
			if(s[x][i]==j) continue;
			nums[x][j-'a'][s[x][i]-'a']+=now->nextNode(j-'a',true)->size;
		}
		now=now->nextNode(s[x],true);
	}
}
bool isFaster(string &p,char a,char b){
	REP(i,p.size()){
		if(p[i]==a) return true;
		if(p[i]==b) return false;
	}
}
int solve(int x,string p){
	int ans=0;
	REP(i,alpha) REP(j,i){
		ans+=nums[x][p[j]-'a'][p[i]-'a'];
		//if(nums[x][i][j])cout << x <<" " <<  char(i+'a') <<" " << char(j+'a') << " " << nums[x][i][j] << endl; 
	}
	return ans+smaller[x];
}
int main(){
	int N;
	cin.tie(0);
	cin >> N;
	REP(i,SIZE*10) nodes[i].init();
	REP(i,N){
		cin >> s[i];
		add(s[i], &root);
	}
	REP(i,N){
		analys(i);
	}
	int Q,k;
	cin >> Q;
	string p;
	REP(i,Q){
		cin >> k >> p;
		cout << solve(k-1,p)+1 << endl;
	}
	return 0;
}

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

int main()
{
	int n;
	string s;
	cin>>n>>s;
	int ans = 0;
	for(size_t i = 0; i<n-2; i++)
	{
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
		{
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int i,n;
	int a[100];

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}	
	for(i=(n-1);i>=0;i--){
			if(i==0){
				printf("%d\n",a[i]);
			}
			else{
				printf("%d ",a[i]);
			}
	}

	return 0;
}

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

const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], inv[MAX], sum_inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    inv[1] = 1;
    sum_inv[0] = 0, sum_inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        sum_inv[i] = sum_inv[i-1] + inv[i] % MOD;
    }
}

int main() {
    COMinit();
    int N; cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        long long left = (sum_inv[i+1] - 1 + MOD) % MOD;
        long long right = (sum_inv[N-i] - 1 + MOD) % MOD;
        long long count = fac[N] * (left + right + 1) % MOD;
        res = (res + count * A[i] % MOD) % MOD;
    }
    cout << res << endl;
}


Measured memory_bytes: 5888
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s1=sc.next();
        String s2=sc.next();
        int l1=s1.length();
        int l2=s2.length();
        int dp[][]=new int[l1+1][l2+1];
        
        
        //System.out.println(s1+" "+s2);
        for(int i=0;i<=l1;i++)
        {
            for(int j=0;j<=l2;j++)
            {
                if(i==0|| j==0)
                {
                    dp[i][j]=0;
                }
                else if(s1.charAt(i-1)==s2.charAt(j-1))
                {
                    dp[i][j]=dp[i-1][j-1]+1;
                }
                else
                {
                    dp[i][j]=Math.max(dp[i-1][j],dp[i][j-1] );
                }
            }
        }
        //System.out.println(dp[l1][l2]);
       
        int i=l1;
        int j=l2;
        int ind=dp[l1][l2];
       // System.out.println(ind);
        int t=ind;
        char l[]=new char[ind+1];
        
        l[ind]=' ';
        while(i>0 && j>0)
        {
            if(s1.charAt(i-1)==s2.charAt(j-1))
            {
                l[ind-1]=s1.charAt(i-1);
                i--;j--;ind--;
            }
            else if(dp[i-1][j]>dp[i][j-1])
            {
                i--;
            }
            else
                j--;
        }
       for(int k=0;k<t;k++) 
            System.out.print(l[k]); 
    }
}


Measured memory_bytes: 81104
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int a,b,c,ans;
int main(void){
    scanf("%d%d%d",&a,&b,&c);
        while(a%2==0&&b%2==0&&c%2==0){
            if(a==b&&b==c){
                printf("-1\n");
                return 0;
            }
            int x=c/2+b/2;
            int y=a/2+c/2;
            int z=a/2+b/2;
            a=x;
            b=y;
            c=z;
            ans++;
        }
        printf("%d\n",ans);
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
N, K = map(int, input().split())
h = np.array(input().split(), dtype=np.int64)

dp = np.zeros(N, dtype=np.int64)

for i in range(1, N):
    L = max(0, i-K)
    dp[i] = np.min(dp[L:i] + np.abs(h[i]-h[L:i]))

ans = dp[-1]
print(ans)

Measured memory_bytes: 21724
#include<bits/stdc++.h>
using namespace std;
int n,m,q;
int f[2001][2001],h[2001][2001],g[2001][2001];
char s[2001][2001];
int main()
{
    cin>>n>>m>>q;
    for(int i=1; i<=n; i++)
        cin>>s[i]+1;
    memset(f,0,sizeof(f));
    memset(h,0,sizeof(h));
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
        {
            f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1]+(s[i][j]-'0');
            h[i][j]=h[i-1][j]+h[i][j-1]-h[i-1][j-1];
            g[i][j]=g[i-1][j]+g[i][j-1]-g[i-1][j-1];
            if(s[i][j]=='1')
            {
            	if(s[i][j-1]=='1') h[i][j]++;
                if(s[i-1][j]=='1') g[i][j]++;
            }
        }
    while(q--)
    {
    	int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        int k1=f[x2][y2]-f[x2][y1-1]-f[x1-1][y2]+f[x1-1][y1-1];
        int k2=h[x2][y2]-h[x2][y1]-h[x1-1][y2]+h[x1-1][y1];
        int k3=g[x2][y2]-g[x1][y2]-g[x2][y1-1]+g[x1][y1-1];
        cout<<k1-k2-k3<<endl;
    }
    return 0;
}


Measured memory_bytes: 52608
#include<iostream>
using namespace std;
int main() {
	int high, h, l,ans;
	ans = 0;
	cin >> high >> l >> h;
	for (int i = l; i <= h; i++) {
		if (high%i == 0) {
			ans = ans + 1;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define REP(i, lim) for(int i=0;i<lim;++i)
#define REPP(i, lim) for(int i=1;i<=lim;++i)
#define DEC(i, lim) for(int i=lim;i>=1;--i)
#define FOR(i,l,r)  for(int i=l;i<r;++i)
#define deBug cout<<"==================================="<<endl;
#define clr(s) memset(s, 0, sizeof(s))
#define lowclr(s) memset(s, -1, sizeof(s))
const int MAXN = 1000055;
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const db eps = 1e-9;

inline int sgn(db x) { return x<-eps ? -1 : x>eps; }
inline db sqr(db x) { return x*x; }

#define cross(p1, p2, p3) ((p2.x-p1.x)*(p3.y-p1.y)-(p3.x-p1.x)*(p2.y-p1.y))
#define crossOp(p1, p2, p3) sgn(cross(p1, p2, p3))

struct P {
    // information
    P() {}
    P(db _x, db _y) : x(_x), y(_y) {}
    db x, y;
    // operation
    P operator + (P p)   const{ return P(x+p.x, y+p.y); }
    P operator - (P p)   const{ return P(x-p.x, y-p.y); }
    P operator * (db d)  const{ return P(x*d, y*d); }
    P operator / (db d)  const{ return P(x/d, y/d); }
    db dot(P p) { return x * p.x + y * p.y; } // 点积
    db det(P p) { return x * p.y - y + p.x; } // 叉积
    // other
    void input() { scanf("%lf%lf", &x, &y); }
    void print() { printf("(%lf, %lf)\n", x, y); }
    db dis(P p) { return sqrt(sqr(x-p.x) + sqr(y-p.y)); }
    db dis2(P p) { return sqr(dis(p)); }
    db abs() { return sqrt(x*x + y*y); }
    db abs2(){ return x*x + y*y; }
};

P getProj(P a, P b, P p) { return a + (b-a) * ( (b-a).dot(p-a) / a.dis2(b) );}
P getReflect(P a, P b, P p) { return getProj(a, b, p) * 2 - p; }

bool chkLL(P p1, P p2, P q1, P q2) {
    db a1 = cross(q1, q2, p1), a2 = -cross(q1, q2, p2);
    return sgn(a1+a2) != 0;
}
P getLL(P p1, P p2, P q1, P q2) {
    db a1 = cross(q1, q2, p1), a2 = -cross(q1, q2, p2);
    return (p1 * a2 + p2 * a1) / (a1 + a2);
}
bool intersect(db l1, db r1, db l2, db r2) {
    if(l1>r1) swap(l1, r1); if(l2>r2) swap(l2, r2);
    return !( sgn(r1-l2) == -1 || sgn(r2-l1) == -1 );
}
bool chkSS(P p1, P p2, P q1, P q2) {
    return intersect(p1.x, p2.x, q1.x, q2.x) && intersect(p1.y, p2.y, q1.y, q2.y) &&
    crossOp(p1, p2, q1) * crossOp(p1, p2, q2) <= 0 &&
    crossOp(q1, q2, p1) * crossOp(q1, q2, p2) <=0;
}
bool chkSS_strict(P p1, P p2, P q1, P q2) {
    return crossOp(p1, p2, q1) * crossOp(p1, p2, q2) < 0 &&
           crossOp(q1, q2, p1) * crossOp(q1, q2, p2) < 0;
}


int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
//    std::ios::sync_with_stdio(false); cin.tie(0);

    int T;
    scanf("%d", &T);
    while(T--)
    {
        P p1, p2, q1, q2;
        p1.input(); p2.input(), q1.input(); q2.input();

        P ans = getLL(p1, p2, q1, q2);
        printf("%.10lf %.10lf\n", ans.x, ans.y);

    }
    return 0;
}


Measured memory_bytes: 3240
N, K = input().split()

N = int(N)
K = int(K)

A_l = list(map(int, input().split()))

count = 1

if N > K:
    set = (N-K)//(K-1)
    count += set
    if (N-K)%(K-1) == 0:
        count += 0
    else:
        count += 1
print(count)

Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef long long ll;
typedef pair<int,int> pii;
const int inf=~0u>>1,MOD=1e9+7;
inline int rd() {
    int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
const int N=1e5+11;
int n,a[N];
int main(){
	n=rd();
	For(i,0,n)a[i]=rd();
	sort(a,a+n,greater<int>());
	int i;
	for(i=1;i<=n;i++){
		if(a[i]<=i)break;
	}
	int x=a[i-1]-i,y=i;
	while(a[y]==i)y++;
	puts((~x&1)&&(~y-i&1)?"Second":"First");
}

Measured memory_bytes: 640
public class Hello {
    public static void Main(){
        // 1行に複数の入力値がある場合の例
        string [] inputs = System.Console.ReadLine().Split(' ');
        int a = int.Parse(inputs[0]);
        int b = int.Parse(inputs[1]);
        int c = (a * b);
        int d = (a + b) * 2;
        System.Console.WriteLine(c + " " + d);
    }
}



Measured memory_bytes: 9052
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define sec second 
#define MOD 1000000007
#define pb push_back
#define endl "\n"
#define test cout<<"debuged\n";
#define INF 10000000000
#define si 1000000
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    ll n;
    cin>>n;
    vector<double> v(n);
    for(ll i=0;i<n;i++) 
      cin>>v[i];
    ll c=n/2;
    if(n%2==1)
      c++;
    double val=1.0,sum=0;
    cout<<fixed;
    cout<<setprecision(9);
    double dp[n+1][n+1];
     for(ll i=0;i<n+1;i++)
      {
      for(ll j=0;j<=n;j++)
        dp[i][j]=0;
      }
      for(ll i=0;i<c;i++)
        dp[0][i]=0;
    for(ll i=c;i<=n;i++)
     dp[0][i]=1;
    double x;
    ll k=n+1;
    for(ll i=1;i<=n;i++)
    {
      k--;
      for(ll j=0;j<k;j++)
      {
        dp[i][j]=(double(1.0-v[i-1])*dp[i-1][j])+(v[i-1]*dp[i-1][j+1]);
      }
    }
      cout<<(dp[n][0]);

}

Measured memory_bytes: 70656
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N, K := getInt(), getInt()
	a := getInts(N)
	for i := K; i < N; i++ {
		if a[i-K] < a[i] {
			out("Yes")
		} else {
			out("No")
		}
	}
}


Measured memory_bytes: 5916
#include<stdio.h>
int n;
int a[100],sach;
int i;
int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		scanf("%d",&sach);
		int dai=n-1,syou=0;
		int now,cnt=0;
		while(syou<=dai){
			cnt++;
			now=(dai+syou)/2;
			if(a[now]==sach){
				break;
			}
			else if(a[now]<sach){
				syou=now+1;
			}
			else if(a[now]>sach){
				dai=now-1;
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.DN", "r", stdin );
	string s = "";
	while (getline (cin, s ) ){
		stringstream ssi (s );
		int a, b;
		ssi >> a >> b;
		int c = a + b;
		stringstream ss;
		ss << c;
		int res = (ss.str()).length();
		printf ("%d\n", res );
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1260
#include<bits/stdc++.h>
#include<cmath>
#include<cstring>
#include<climits>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define asc(a,n) sort(a,a+n);
#define dsc(a,n) sort(a,a+n,comp);
#define fo(i,x,y) for(int i=x;i<y;i++)
#define inarr(x) int n; cin>>n; int x[n]; fo(i,0,n){cin>>x[i];}
#define test int t; cin>>t; while(t--)
using namespace std;

int basic(){freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);return 0;}
bool comp(int a,int b){return a>b;}



int32_t main()
{ //basic(); 
  fast;
  string s;
  cin>>s;
  if(s=="ABC"){cout<<"ARC";}
  else{cout<<"ABC";}
  


  
  return 0;
}






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


int main(){
  int H,W,ans,N;
  cin>>W>>H>>N;
  int w1,w2,h1,h2;
  w1=0;h1=0;
  w2=W;h2=H;
  for(int i = 0;i<N;i++){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1){
      if(w1<x)w1=x;
    }else if(a==2){
      if(w2>x)w2=x;
    }else if(a==3){
      if(h1<y)h1=y;
    }else if(a==4){
      if(h2>y)h2=y;
    }
  }

  if((w2-w1)<0||(h2-h1)<0)ans = 0;
  else ans = (w2-w1)*(h2-h1);

  cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
int mod = 1e9+7;

vector<P> prime_factorize(int N){
	vector<P> ans;
	for(int a = 2; a*a <= N; a++){
		if(N%a == 0){
			int ex = 0;
			while(N%a == 0){
				ex++;
				N /= a;
			}
			ans.push_back(P(a, ex));
		}
	}
	if(N != 1) ans.push_back(P(N, 1));
	return ans;
}

signed main(){
	int N, Q; cin >> N >> Q;
	/*vector<P> map = prime_factorize(Q);
	int ans = 1;
	for(int i = 0; i < map.size(); i++){
        for(int j = 0; j < map[i].second/N; j++){
			 ans *= map[i].first;
		}
	} 
	cout << ans << endl;*/
	const auto &pf = prime_factorize(Q);
    int res = 1;
    for (auto p : pf) {
        for (int j = 0; j < p.second/N; ++j) res *= p.first;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int[] list = new int[N];
        int pos =0; 
        list[0] = 0; 
        for (int i = 0; i < list.length; i++) {
            list[i] = sc.nextInt();
        }
        int c=1;
        for(int i=0; i<list.length; i++) {
            pos += list[i];
            if(pos > X) {
                break;
            } else if( pos == X) {
                c++;
                break;
            }
            c++;
//            System.out.println("pos:"+pos+" ptr: "+ptr);
        }
        System.out.println(c);
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
int mod=1e9+7;
int C[1005][1005];
void build(){
    for(int i = 0;i<1005;i++){
        C[i][0]=C[i][i]=1;
        for(int j=1;j<i;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
}
int main(){
    build();
    int n,k;
    scanf("%d %d",&n,&k);
    int a[25];
    for(int i = 1;i<=k;i++)
        scanf("%d",&a[i]);
    LL dp[25][1005];
    MEM(dp);
    dp[0][0]=1;
    for(int i = 0;i<k;i++){
        for(int j=0;j<=n;j++){
           // printf("%lld ",dp[i][j]);
            for(int kk=0;kk<=n-j&&kk<=a[i+1];kk++){
                dp[i+1][j+kk]+=dp[i][j]*C[n-j][kk]%mod*C[n-kk][a[i+1]-kk]%mod;
               // if(j+kk==n){
                  //  printf("%d %d %d\n",dp[i][j],C[n-j][kk],C[n-kk][a[i+1]-kk]);
               // }
                dp[i+1][j+kk]%=mod;
            }
        }
      //  printf("\n");
    }
    printf("%lld\n",dp[k][n]);
}


Measured memory_bytes: 4352
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	llint i,n,K,mto=0,usi=big;cin>>n>>K;
	vector<llint>a(n);
	for(i=0;i<n;i++){cin>>a[i];if(a[i]>0){mto+=a[i];}}
	llint sro=0,kro=0;
	for(i=0;i<K;i++){
		if(a[i]<0){sro-=a[i];}
		else{kro+=a[i];}
	}
	usi=min(sro,kro);
	for(i=K;i<n;i++){
		if(a[i]<0){sro-=a[i];}
		else{kro+=a[i];}
		if(a[i-K]<0){sro+=a[i-K];}
		else{kro-=a[i-K];}
		mineq(usi,min(sro,kro));
	}
	cout<<mto-usi<<endl;
	return 0;
}


Measured memory_bytes: 1152
N,A,B=map(int,input().split())
souryou=0
for i in range(N):
  j=i+1
  j_str=str(j)
  goukei=0
  for k in range(len(j_str)):
    goukei=goukei+int(j_str[k])
  if goukei>=A and goukei<=B:
    souryou=souryou+j
print(str(souryou))

Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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 int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}
 
void solve() {
    ll m, k;
    cin >> m >> k;
    ll p = (1 << m);
    if (k >= p) {
        cout << -1 << EOL;
        return;
    }
    if (m == 0) {
        if (k == 0) {
            cout << "0 0" << EOL;
        } else {
            cout << -1 << EOL;
        }
        return;
    } else if (m == 1) {
        if (k == 0) {
            cout << "0 0 1 1" << EOL;
        } else {
            cout << -1 << EOL;
        }
        return;
    }

    for (ll i = 0; i < p; i++) if (i != k) cout << i << " ";
    cout << k << " ";
    for (ll i = p - 1; i >= 0; i--) if (i != k) cout << i << " ";
    cout << k << EOL;
}



Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
int n;
void show(std::vector<std::queue<int>>q) {
	printf(":");
	for (int i = 0; i < n; i++) {
		while (!q[i].empty()) {
			printf("%d ", q[i].front());
			q[i].pop();
		}
		printf("\n");
	}
}

int main() {
	std::cin >> n;
	std::vector<std::queue<int>>a(n);
	for (int i = 0; i < n; i++)for (int j = 0; j < n - 1; j++) {
		int x;
		std::cin >> x;
		a[i].push(x - 1);
	}
	int m = n * (n - 1) / 2;
	std::queue<int>q[2];
	for (int i = 0; i < n; i++)q[0].push(i);
	int ans = 0;
	int *step = new int[n];
	for (int i = 0; i < n; i++)step[i] = 0;
	while (!q[0].empty() && m != 0) {
		while (!q[0].empty()) {

			int i = q[0].front();
			q[0].pop();
			if (a[i].empty() || step[i] == ans + 1 || step[a[i].front()] == ans + 1 || a[a[i].front()].front() != i)continue;
			step[i] = step[a[i].front()] = ans + 1;
			q[1].push(i);
			q[1].push(a[i].front());
			a[a[i].front()].pop();
			//show(a);
			a[i].pop();
			//show(a);
			m--;
		}
		ans++;
		std::swap(q[0], q[1]);
	}
	if (m != 0)ans = -1;
	printf("%d\n", ans);
}

Measured memory_bytes: 4736
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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















int main(){
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, ll>> v(n);
    REP(i, n){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());
    priority_queue<ll> que;
    ll idx = 0, ans = 0;
    for(ll i = 1; i <= m; i++){
        while(idx < n && v[idx].first <= i){
            que.push(v[idx++].second);
        }
        if(!que.empty()){
            ans += que.top();
            que.pop();
        }
    }
    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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;
}


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

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}



void solve()
{
  ll N; cin >> N;
  vector<ll> a(N);
  vector<int> scheck(1000010, 0);
  vector<int> bcheck(1000010, 0);
  ll amax = 0;
  rep(i, N) {
    cin >> a[i];
    scheck[a[i]] ++;
    chmax(amax, a[i]);
  }
  sort(a.begin(), a.end());

  rep(i, N) {
    for(ll j = a[i]; j <= amax; j += a[i]) {
      bcheck[j] ++;
    }
  }

  ll ans = 0;
  rep(i, N) {
    //    cout << a[i] << " " << scheck[a[i]] << " " << bcheck[a[i]] << endl;
    if(scheck[a[i]] == 1 && bcheck[a[i]] == 1) {
      ans ++;
    }
  }
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 12828
#include<stdio.h>
int main (void){

int a[100], b[2], n = 0, m, i, j, k, l, f = 1;//a ??°??????b ????????¨???n ???????????° m ??°????????????

scanf("%d",&m);


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

while(f != 0){   

	for( k = 1; k < m; k++){
		if( a[k] > a[k + 1]){

			b[1] = a[k];
			b[2] = a[k + 1];
			a[k] = b[2];
			a[k + 1] = b[1];
			
			n++;
		}

	}
	f = 0;

	for( j = 1; j < m; j++ ){
		if( a[j] > a[j + 1]){
			f++;
		}	
	}

}

for( l = 1; l < m; l++ ){
	printf("%d ",a[l]);
}

printf("%d\n",a[m]);

printf("%d\n",n);

return 0;
}

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

typedef long long s64;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=1e5+5,D=1e9+7;
s64 a[N],A,B;
int fa[N],fb[N],tob[N];

int main()
{
	//freopen("1.in","r",stdin);
	int n;
	cin>>n>>A>>B;
	if(A<B)swap(A,B);
	rep(i,1,n)scanf("%lld",a+i);
	a[0]=-(1e18+5);
	fa[1]=fb[1]=1;
	int j=0;
	rep(i,2,n)
	{
		tob[i]=a[i]-a[i-1]>=B?tob[i-1]:i;
		while(a[i]-a[j+1]>=A)++j;
		if(!j)
		{
			if(tob[i-1]<=1)fa[i]=1;
			else fa[i]=0;
		}
		else
		{
			if(j==i-1)fa[i]=(fa[j]+fb[j])%D;
			else 
			{
				if(tob[i-1]>j+1||a[j+1]-a[j-1]<B)fa[i]=0;
				else 
				if(a[j+1]-a[j]>=B)fa[i]=(fa[j]+fb[j])%D;
				else fa[i]=fa[j];
			}
		}
		if(a[i]-a[i-1]>=B)fb[i]=(fb[i-1]+fa[i-1])%D;
		else 
		if(a[i]-a[i-2]>=B)fb[i]=fa[i-1];
	}
	cout<<(fa[n]+fb[n])%D;
}

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

int main() {
    ll a,b,n,ans,x;
    cin  >> a >> b >> n;
    if(b-1<=n){
        x = b-1;
    }
    else{
        x = n;
    }
    ans=(a*x)/b-a*(x/b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int a[101],s,n;
int main()
{
cin>>n;
for(int i=1;i<=n*2;i++)cin>>a[i];
sort(a+1,a+1+2*n);    
for(int i=1;i<=n*2;i+=2)s+=a[i];
cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>s;
    rep(i,Size(s)){
        if(s[i]=='B')cnt++;
        else ans+=cnt;
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 1356