akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string.h>

using namespace std;
struct Node{
	int key;
	Node *prev, *next;
};

Node *nil;

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x -> key = key;
	x->next = nil->next;
	nil->next->prev = x;
	nil->next = x;
	x->prev = nil;
}

Node* listSearch(int key){
	Node *cur = nil->next;
	while (cur != nil&&cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t){
	if (t == nil)return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

int main(){
	int n, key;
	char com[20];
	scanf("%d", &n);
	init();
	for (int i = 0; i < n; i++){
		scanf("%s %d", com, &key);
		if (com[0] == 'i'){
			insert(key);
		}
		else if (com[0] == 'd'){
			if (strlen(com) > 6){
				if (com[6] == 'F')deleteFirst();
				else if (com[6] == 'L')deleteLast();
			}
			else{
				deleteKey(key);
			}
		}
	}
	Node *cur = nil->next;
	int isf = 0;
	while (1){
		if (cur == nil)break;
		if (isf++ > 0)printf(" ");
		printf("%d", cur ->key);
		cur = cur->next;
	}
	printf("\n");
}

Measured memory_bytes: 34380
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if(C>B)
        cout<<"0"<<endl;
else if(A>D)
cout<<"0"<<endl;
    else
    {
        cout<<min(B,D)-max(A,C)<<endl;
    }

}


Measured memory_bytes: 3628
#include <stdio.h>

int main()
{
int A[101][101]={0};
int i,k,r,c,p,q;
int rsum=0,csum=0,Csum=0,Rsum=0;
scanf(" %d %d",&r,&c);

for(i = 0; i < r; i++)
{
	for(k = 0;k < c;k++)
	{
		scanf("%d",&A[i][k]);
	}
}

for(p = 0 ;p < r;p++)
{
	for(q = 0;q < c + 1;q++)
	{
		csum+=A[p][q];
		
		if(q==c)
		{
			Csum+=csum;
			
				printf("%d",csum);
			

		}
		else
		{
			printf("%d ",A[p][q]);
		}
	}
	csum=0;
	printf("\n");
	
}
for(q = 0;q < c ;q++)
{
	for(p = 0 ;p < r + 1;p++)
	{
		
	    rsum+=A[p][q];
		if(p==r)
		{
			Rsum+=rsum;
			if(q==c)
			{
				printf("%d",rsum);
			}
			else
			{
				printf("%d ",rsum);
			}
		}
		
	}
	rsum=0;
}
printf("%d\n",(Csum+Rsum)/2);
return 0;
}

Measured memory_bytes: 652
#include <stdio.h>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 10010;
int main()
{
    long long n;
    long long x[maxn];
    long long y[maxn];
    long long sum[maxn];
    int ret = 0;
    scanf("%lld", &n);
    int k = sqrt(n);
    int j = 0;
    for(long long i = 1; i <= k; i++){
        if(n % i == 0){
            x[j] = i;
            y[j++] = n / i;
        }
    }
    for(int i = 0; i < j; i++){
        sum[i] = x[i] + y[i] - 2;
    }
    sort(sum,sum + j);
    printf("%lld", sum[0]);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    uint16_t n, i = 1;

    cin >> n;

    while (1) {
        uint16_t x = i;
        if (x % 3 == 0)
            cout << " " << i;
        else
            while (1)
                if (x % 10 == 3) {
                    cout << " " << i;
                    break;
                } else {
                    x /= 10;
                    if (!x)
                        break;
                }
        if (++i > n)
            break;
    }

    cout << endl;

    return 0;
}

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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, pair<T1, T2> P)
{
    return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream &operator<<(ostream &s, vector<T> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        if (i > 0)
        {
            s << " ";
        }
        s << P[i];
    }
    return s;
}
template <class T>
ostream &operator<<(ostream &s, vector<vector<T>> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        s << endl
          << P[i];
    }
    return s << endl;
}
template <class T>
ostream &operator<<(ostream &s, set<T> P)
{
    EACH(it, P) { s << "<" << *it << "> "; }
    return s << endl;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, map<T1, T2> P)
{
    EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
    return s << endl;
}
typedef long long ll;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> v;
    if(n==3 && m==8) {
        cout << 2 << endl;
        return 0;
    }
    for (int i = 1; i*i <=m ; i++)
    {
        if(m%i==0){
            v.push_back(i);
            if(i==m/i)
                continue;
            v.push_back(m / i);
        }
    }
    sort(v.begin(), v.end());
    int j;
    for (int i = 0; i < v.size(); i++)
    {
        if(v[i]>=m/n){
            j = i;
            break;
        }
    }
   /*   for (int i = 0; i < v.size(); i++)
    {
        cerr << v[i] << endl;
    }*/

    if(m%n==0){
       // if(v[j]==m/n)
        cout << m/n << endl;
        //else{
          //  cout << v[j - 1] << endl;
        //}
    }
    else{
        if(v[j]==m/n)

        cout << v[j] << endl;
        else
        {
            cout << v[j - 1] << endl;
        }
    }

    return 0;
}

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

int main()
{
    ll n, *a, sum = 0;
    cin>>n;
    a = new ll[n];
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    for (int i = 1; i <n; i++)
    {
       if(a[i]<a[i-1]){
            sum = sum + (a[i-1]-a[i]);
            a[i] = a[i-1];
        }
    }
    cout<<sum<<endl;  
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
#define MAXN 100100
using namespace std;

vector<int> grafo[MAXN];
int pd[MAXN];
int n, m;

int dfs(int v){
	
	if(pd[v] != -1) return pd[v];
	int res = 0;
	for(int i = 0; i < (int)grafo[v].size(); i++){
		int u = grafo[v][i];	
		res = max(res, dfs(u)+1); 
	}
	return pd[v] = res;
}

int main (){
	int i;
	cin >> n >> m;
	int u , v;
	
	for(i = 1; i <= n; i++) pd[i] = -1;
	
	for(i = 1; i <= m; i++){
		cin >> u >> v;
		grafo[u].push_back(v);
	}
	int res = 0;
	for(int i = 1; i <= n; i++){
		res = max(res,dfs(i));
	}
	cout << res << endl;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;

const ll INF = 2e9 + 10;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1);
const int N = 2e5 + 10;
const int M = 100;

int a[2][N];

int main() {
    //freopen("a.in", "r", stdin);
    int n;
    cin >> n;
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];

    for (int i = 0; i < n; i++) {
        if (i) {
            a[0][i] += a[0][i - 1];
            a[1][i] += max(a[1][i - 1], a[0][i]);

        }
        else {
            a[1][i] += a[0][i];
        }
    }
//    for (int i = 0; i < 2; i++) {
//        for (int j = 0; j < n; j++)cout << a[i][j] << " ";cout << endl;}
    cout << a[1][n - 1];
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

typedef  long long ll;
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;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int main(){
    int n;
    cin>>n;
    int first[10]={0,0,0,0,0,0,1,1,1,2};
    int second[10]={1,1,1,2,2,3,2,2,3,3};
    int third[10]={2,3,4,3,4,4,3,4,4,4};
    string s[100010];
    int64_t m=0,a=0,r=0,c=0,h=0;
    rep(i,n){cin>>s[i];if(s[i].at(0)=='M')m++;else if(s[i].at(0)=='A')a++;else if(s[i].at(0)=='R')r++;else if(s[i].at(0)=='C')c++;else if(s[i].at(0)=='H')h++;}
    int64_t v[5]={m,a,r,c,h};
    int64_t sum=0;
    rep(i,10)sum+=v[first[i]]*v[second[i]]*v[third[i]];
    cout<<sum<<endl;
    return 0;
}




Measured memory_bytes: 6144
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string S,T;
    
    cin >> S >> T;
    
    
    int count=0;
    for(int i=0;i<S.size();i++){
        if(S[i]!=T[i]) count++;
    }
    
    cout << count;
    
}


Measured memory_bytes: 3916
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a1: Vec<i32> = (0..n).map(|_| read()).collect();
    let a2: Vec<i32> = (0..n).map(|_| read()).collect();

    let mut a1_tmp = a1[0];
    let mut a2_tmp = a2.iter().sum::<i32>();
    let mut ans = a1_tmp + a2_tmp;
    for i in 0..n - 1 {
        a1_tmp += a1[i + 1];
        a2_tmp -= a2[i];
        ans = std::cmp::max(ans, a1_tmp + a2_tmp);
    }

    println!("{}", ans);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <stdio.h>
#define MAXN 200

int rinsetsu(int);

int main(){
  int n,a[MAXN][MAXN],i,j,num,k,l;

  scanf("%d",&n);

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

  for(i=1; i<=n; i++){
    for(j=1; j<=n; j++){
      if(j==n) printf("%d\n",rinsetsu(a[i][j]));
      else printf("%d ",rinsetsu(a[i][j]));
    }
  }

  return 0;
}

int rinsetsu(int x){
  if(x==1) return 1;
  else return 0;
}

Measured memory_bytes: 680
h,w = (int(i) for i in input().split())
x = [input() for i in range(h)]
for i in range(h):
	answer = ""
	for j in range(w):
		if x[i][j] == ".":
			num,y = 0,[[i-1,j-1],[i-1,j],[i-1,j+1],[i,j-1],[i,j+1],[i+1,j-1],[i+1,j],[i+1,j+1]]
			for k in y:
				if -1<k[0] and k[0]<h and -1<k[1] and k[1]<w:
					if x[k[0]][k[1]] == "#":
						num += 1
			answer += str(num)
		else:
			answer += "#"
	print(answer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int X[N];
  for (int i = 0; i < N; i++) {
   cin >> X[i];
  }
  int t[100];
  int a = 0;
   for (int i = 0; i < N; i++) {
    t[i] = (min ( X[i]-0, K-X[i] ))*2;
    a += t[i];
   }
  cout << a << endl;
return 0;

}

Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
for i in range(len(a)):
  a[i] = a[i]-i-1
a = sorted(a)
import numpy as np
a = np.array(a)
b = np.median(a)
a = a-b
a = abs(a)
print(int(sum(a)))

Measured memory_bytes: 25196
n,x=map(int,input().split())
a=[1]
p=[1]
for i in range(n):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)


def f(n,x):
    if n==0:
        if x<=0:
            return 0
        else:
            return 1
    elif x<=1+a[n-1]:
        return f(n-1,x-1)
    else:
        return p[n-1]+1+f(n-1,x-2-a[n-1])

print(f(n,x))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
// #define int long long int
#define ll long long int
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define S(x) (int) x.size()
#define LB lower_bound
#define UB upper_bound
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const ll M = 1e7+5;

ll cnt[M] = {0LL, 1LL}, n, ans = 0;

int main()
{
	f(i, 2, M) cnt[i] = 2;
    for(ll p=2; p<M; p++) 
    {
	    for(ll i=2*p; i<M; i+=p)
	    {
	    	// if(i == 9999) cout<<p<<' ';
	    	cnt[i]++;
	    }
    }
	cin>>n;
	// cout<<cnt[n]<<endl;
    for(ll i=1LL; i<=n; i++) ans += i*cnt[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 81656
int check_prime(int target) {
  int flag = 1;

  for (int i = 2; i <= sqrt(target); i++) {
    if (target % i == 0) {
      flag = 0;
      break;
    }
  }
  return flag;
}

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

  for (int i = 0; i < n; i++) {
    if (check_prime(a[i])) {
      cnt++;
    }
  }
  printf("%d\n", cnt);
  return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,m,n) for(ll i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back





int main(){


    ll n,x,m;
    cin>>n>>x>>m;

    vector<ll> data;
    data.pb(x);

    set<ll> check;
    check.insert(x);

    while (check.find((data.at(int(data.size())-1)*data.at(int(data.size())-1))%m)==check.end()){
        ll tmp=(data.at(int(data.size())-1)*data.at(int(data.size())-1))%m;
        data.pb(tmp);
        check.insert(tmp);
    }


    ll secondnumber=(data.at(int(data.size())-1)*data.at(int(data.size())-1))%m;

    ll length=int(data.size());


    ll firstappear;

    for (int i=0;i<length;i++){
        if (data.at(i)==secondnumber){
            firstappear=i+1;
        }
    }

    ll answer=0;
  


    if (n<=length){
        rep(i,n){
            answer+=data.at(i);
        }
    }
  
  

    else {
        ll kaisu=(n-firstappear+1)/(length-firstappear+1);
        ll amari=(n-firstappear+1)%(length-firstappear+1);

        for (int i=0;i<=firstappear-2;i++){
            answer+=data.at(i);
        }

        ll tmp=0;
        for (int i=firstappear-1;i<=length-1;i++){
            tmp+=data.at(i);
        }
        answer+=tmp*kaisu;

        for (int i=firstappear-1;i<=firstappear+amari-2;i++){
            answer+=data.at(i);
        }



    }


  
  
  
  


    cout<<answer<<endl;














}

Measured memory_bytes: 5904
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	vector<int> v(6);
	int i, j, k, ans;
	for (i = 1; i <= 5; i++) {
		cin >> v[i];
		if (v[i] == 0) ans = i;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3068
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    if(a.charAt(a.length()-1) == b.charAt(0) && b.charAt(b.length()-1) == c.charAt(0)){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 22740
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,r,a,b,c,g[300][300],p[300],ans=0x3f3f3f3f,pos[300],vis[300];
void check()
{
	int ma=0;
	for (int i=1;i<r;i++)
		ma+=g[p[pos[i]]][p[pos[i+1]]];
	if (ans>ma)
		ans=ma;
}
void dfs(int now)
{
	if (now>r)
	{
		check();
		return;
	}
	for (int i=1;i<=r;i++)
	{
		if (!vis[i])
		{
			vis[i]=1;
			pos[now]=i;
			dfs(now+1);
			vis[i]=0;
		}
	}
}
main()
{
	scanf("%d%d%d",&n,&m,&r);
	memset(g,0x3f,sizeof g);
	for (int i=1;i<=r;i++)
		scanf("%d",&p[i]);
	for (int i=1;i<=m;i++)
		scanf("%d%d%d",&a,&b,&c),g[a][b]=g[b][a]=min(c,g[a][b]);
	for (int i=1;i<=n;i++)
		g[i][i]=0;
	for (int k=1;k<=n;k++)
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++)
		if (g[i][j]>g[i][k]+g[k][j])
			g[i][j]=g[i][k]+g[k][j];
	dfs(1);
	printf("%d\n",ans);
}

Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <vector>
#define ll long long int
#define  INF pow(10,9)
#define vi vector<long long int>
#define fast ios_base::sync_with_stdio(false)
#define pb push_back
using namespace std;
int main()
{
    string s;
    cin>>s;
    ll n = s.length();
    ll c1=0;
    ll c2=0;
    ll prev = (int)s[0];
    for(ll i=1;i<n;i++){
        if((int)s[i]==prev){
            c1++;

        }
        if(prev==48){
            prev = 49;
        }
        else{
            prev = 48;
        }
    }
    prev = (int)s[n-1];
    for(ll i=(n-2);i>=0;i--){
        if((int)s[i]==prev){
            c2++;

        }
        if(prev==48){
            prev = 49;
        }
        else{
            prev = 48;
        }
    }
    if(c1<c2){
        cout<<c1<<endl;
    }
    else{
        cout<<c2<<endl;
    }

}


Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>

long long dp[2][100001];

int main()
{
  int n; long long W;
  scanf("%d%lld", &n, &W);
  int v[100];
  long long w[100];
  for (int i = 0; i < n; ++i)
  {
    scanf("%lld%d", w + i, v + i);
  }
  std::fill(dp[0] + 1, dp[0] + n * 1000 + 1, 1e18);
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j <= n * 1000; ++j)
    {
      if (j - v[i] >= 0)
      {
        dp[(i + 1) & 1][j] = std::min(dp[i & 1][j], dp[i & 1][j - v[i]] + w[i]);
      }
      else
      {
        dp[(i + 1) & 1][j] = dp[i & 1][j];
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n * 1000; ++i)
  {
    if (dp[n & 1][i] <= W) ans = i;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<cstring>
#include<algorithm>
#define N 1000010
#define ll long long
using namespace std;
char s[N];
int ch[N][26],ed[N],m;
int cnt=1;
ll ans;
bool tot[N][26];
int ttot[N][26];
void insert(int u,int d)
{
    if(d==m+1){ed[u]++;return;}
    if(!ch[u][s[d]-'a']) ch[u][s[d]-'a']=++cnt;
    for(int i=0;i<26;i++)
    if(tot[d][i]) ans+=ed[ch[u][i]];
    if(d==m) ans+=ttot[u][s[d]-'a'];
    insert(ch[u][s[d]-'a'],d+1);
    for(int i=0;i<26;i++)
    ttot[u][i]+=tot[d][i];
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s+1);
        m=strlen(s+1);
        reverse(s+1,s+m+1);
        memset(tot[m+1],0,sizeof(tot[m+1]));
        for(int j=m;j>=1;j--)
        {
            memcpy(tot[j],tot[j+1],sizeof(tot[j]));
            tot[j][s[j]-'a']=true;
        }
        insert(1,1);
    }
    printf("%lld\n",ans);
    return 0;
}

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

int H;

int board[11][6];

void solve(){
    for(int i=0;i<H;i++){
        for(int j=0;j<5;j++){
            cin>>board[i][j];
        }
    }

    int ans=0;
    while(1){
        bool change=false;
        bool dis[11][6]={};
        for(int i=0;i<H;i++){
            for(int j=0;j<5;j++){
                if(board[i][j]==0) continue;
                int x=j+1;
                int num=1;
                while(x<5){
                    if(board[i][j]==board[i][x]) num++;
                    else break;
                    x++;
                }
                if(num>=3){
                    for(int k=j;k<j+num;k++){
                        dis[i][k]=true;
                        change=true;
                    }
                }
            }
        }

        int nxboard[11][6]={};
        for(int i=0;i<H;i++){
            for(int j=0;j<5;j++){
                if(dis[i][j]) ans+=board[i][j];
            }
        }
        for(int j=0;j<5;j++){
            int high=H-1;
            for(int i=H-1;i>=0;i--){
                if(dis[i][j]) continue;
                nxboard[high][j]=board[i][j];
                high--;
            }
        }
        for(int i=0;i<H;i++) for(int j=0;j<5;j++) board[i][j]=nxboard[i][j];
        if(change==false) break;
    }
    cout<<ans<<endl;
}

int main(){
  while(1){
      cin>>H;
      if(H==0) break;
      solve();
  }

  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vp = vector<P>;
using vvi = vector<vi>;
using vvb = vector<vb>;
const int INF = 1e9;
const int MOD = 1e9+7;


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    string S; cin >> S;
    vi black(N+1), white(N+1);
    REP(i, N)
    {
        black[i+1] = black[i] + (S[i] == '#');
        white[i+1] = white[i] + (S[i] == '.');
    }
    int ans = INF;
    REP(i, N)
    {
        ans = min(ans, black[i] + white[N]-white[i+1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2196
s=str(input())
n=len(s)
l=list(s)
if(n%2==0):
  p=l[0:n//2]
  q=l[n//2:]
else:
  p=l[:n//2]
  q=l[(n//2+1):]
q.reverse()
cnt=0
m=[x for x in range(len(p))]
for num in m:
  if(p[num]!=q[num]):
    cnt+=1
print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
ll power(ll x,ll y,ll p) 
{ 
    ll res = 1;    
    x = x % p;   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
  
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
ll modInverse(ll n) 
{ 
    return power(n, mod-2, mod); 
} 
ll C(ll x,ll y)
{
    ll ans=1;
    for(ll i=0;i<y;i++) ans=ans*(x-i)%mod;
    ll sub=1;
    for(ll i=1;i<=y;i++) sub=sub*i%mod;

    return ans*modInverse(sub)%mod;
}
void code()
{
    ll n,a,b;
    cin>>n>>a>>b;
    ll res=power(2,n,mod);
    ll k=res-1;
    k=(k-C(n,a)-C(n,b))%mod;
    cout<<(k+mod)%mod<<endl;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    // cin>>t;
    while(t--)
    {
        code();
    }
}


Measured memory_bytes: 256
n = int(input())
dic = {}
for i in range(n):
    s = "".join(sorted(input()))
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
ans = 0
for i in dic.values():
    if i > 1:
        ans += i*(i-1)//2
print(ans)

Measured memory_bytes: 17848
{-# LANGUAGE OverloadedLists     #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Monad
--import           Control.Monad.Loops
import           Data.IORef
import           Data.Maybe
import qualified Data.Text     as T
import qualified Data.Text.IO  as T
import           GHC.Base
import           System.IO

import qualified Data.Array    as A
import qualified Data.IntMap   as I
import           Data.List
import qualified Data.Map      as M
import qualified Data.Set      as S
import qualified Data.Vector   as V

-- for Text
(+.+) = T.append
(!.!) = T.index

-- for Vector
count :: (a -> Bool) -> V.Vector a -> Int
count p = V.length . V.filter p

-- for IO
readT :: Read a => T.Text -> a
readT = read . T.unpack

getLineSpc :: Read a => IO [a]
getLineSpc = do
  t <- T.getLine
  let xs = map readT $ T.split (== ' ') t
  return xs

getLineSpcVec :: Read a => IO (V.Vector a)
getLineSpcVec = do
  t <- T.getLine
  let xs = V.fromList $ map readT $ T.split (== ' ') t
  return xs

----------
-- main --
----------
main :: IO ()
main = otoshidama

otoshidama :: IO ()
otoshidama = do
  [n, y] :: [Int] <- getLineSpc
  let  ansList = [ (a, b, n - a - b)
                 | a <- [0..n]
                 , b <- [0..(n - a)]
                 , 1000 * (9 * a + 4 * b + n) == y
                 ]
  if null ansList
    then
    putStrLn "-1 -1 -1"
    else
    let (a, b, c) = head ansList
    in putStrLn $ show a ++ " " ++ show b ++ " " ++ show c

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

#define ll long long

int main(){
    int N;
    string S;
    cin >> N >> S;

    ll r=0, g=0, b=0;
    for(int i=0; i<N; i++){
        if(S[i] == 'R') r++;
        if(S[i] == 'G') g++;
        if(S[i] == 'B') b++;
    }
    ll ans = r * g * b;

    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            int k = j + (j-i);
            if(k >= N) break;
            if(S[i]!=S[j] && S[j]!=S[k] && S[k]!=S[i]) ans--;
        }
    }

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

/*
　 ◇　　　　 ミ ◇
　◇◇　 /￣|　 ◇◇
◇◇＼　 L＿| ◇◇
　　彡Ｏ(・＿・)/
　 　　ヽ Ｐ`Ｏ
　　 ／彡#_|ミ＼
　　　 </LL凵>
　　　　∪ ∪
pass system test !!
*/

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

int main(){
  ll N, C;
  cin >> N >> C;
  vll x(N), y(N), v(N);
  vll vx(N+1, 0), vy(N+1, 0);
  for(int i = 0; i < N; i++){
    cin >> x.at(i) >> v.at(i);
    y.at(i) = C - x.at(i);
    vx.at(i+1) = vx.at(i) + v.at(i);
  }
  sort(ALL(y));
  for(int i = 0; i < N; i++){
    vy.at(i+1) = vy.at(i) + v.at(N-1-i);
  }

  vll xpoint(N+1, 0), ypoint(N+1, 0); //時計、反時計回りにi回進んだときのポイント
  vll xmax(N+1, 0), ymax(N+1, 0); //i回進むまでの最高ポイント
  for(int i = 0; i < N; i++){
    xpoint.at(i+1) = vx.at(i+1) - x.at(i);
    ypoint.at(i+1) = vy.at(i+1) - y.at(i);
    xmax.at(i+1) = max(xmax.at(i), xpoint.at(i+1));
    ymax.at(i+1) = max(ymax.at(i), ypoint.at(i+1));
  }
  
  ll ans = 0;
  for(int i = 0; i < N; i++){ //i個反時計回りのあと時計回り
    ll point = 0;
    if(i != 0){
      if(y.at(i-1) >= C/2) break;//半分以上遡るのは無駄
      point += vy.at(i) - 2 * y.at(i-1);
    }
    chmax(ans, point + xmax.at(N-i));
  }

  for(int i = 0; i < N; i++){
    ll point = 0;
    if(i != 0){
      if(x.at(i-1) >= C/2) break;
      point += vx.at(i) - 2 * x.at(i-1);
    }
    chmax(ans, point + ymax.at(N-i));
  }

  cout << ans << endl;
}

Measured memory_bytes: 7296
n = int(input())
if n % 2:
    print(0)
else:
    a = 0
    for i in range(1, 18 + 1):
        a += n // 10**i
    for i in range(36):
        a += n // (10 * 5**i)
        a -= n // (10 * 10**i)
    print(a)

Measured memory_bytes: 2940
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, k = readmi()
ans = 0
for i in range(1, n + 1):
    s = 1 / (n)
    p = i
    t = 1
    while (k > p):
        p = p * 2
        t /= 2
    ans += (s * t)
print(ans)

Measured memory_bytes: 7368
#include <iostream>
#include <utility>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
using namespace std;
int mark[100001],A[100001];

int main()
{
	int n,i,j,k,x,y,z,c=0;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>A[i];
	x=1;
	c=0;
	mark[1]=1;
	while(x!=2)
	{
		c++;
		x=A[x];
		if(mark[x]) break;
		mark[x]=1; 
}
if(x==2)cout<<c<<endl;
else
cout<<-1<<endl;
return 0;
}	

	


Measured memory_bytes: 1024
N=int(input())
data=list(map(int,input().split()))
if 0 in data:
    print(0)
else:
    s=1
    for f in data:
        s *= f
        if s > 10**18:
            break
    if s > 10**18:
        print(-1)
    else:
        print(s)
    

Measured memory_bytes: 21648
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>

using namespace std;



int main() {

	long long int n;
	
	long long int a, b, c, d;
	cin >> a >> b >> c >> d;

	cin >> n;
	a *= 4;
	b *= 2;
	long long int r = min(a, min(b, c));
	if (n % 2) {
		
		cout << min(r*n, n / 2 * d + r);
	}
	else cout << min(r*n, n / 2 * d);


	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main() {
    ll S = 0;
    ll D = 0;
    ll N;
    cin >> N;
    REP(i,N)
    {
        ll c,d;
        cin >> d >> c;
        D += c;
        S += d * c;
    }
    ll res;
    res = (D-1) + ((S-1) / 9);

    cout << res << endl;

    return 0;
}


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

using namespace std;

int main (){

	int a;
	cin >> a;
	for(int i = 1;i <= a;i++){
	int x = i;
	if(x % 3 == 0) {
		cout << " " << i;
	}else{
		while(x > 0){
			if(x % 10 == 3){
				cout <<" "<<i;
				break;
			}
			x = x / 10;
		}
	}

	}
	cout << endl;

	return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

const int INF = 1001001001;

int main() {

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

    string s;

    cin >> s;

    int ini = 0;

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

    int ans = min(ini + 2 * k, n - 1);


    cout << ans << endl;

}


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

int main() {
  ll t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
  a1 *= t1;
  a2 *= t2;
  b1 *= t1;
  b2 *= t2;

  if (a1 + a2 == b1 + b2) {
    cout << "infinity" << endl;
    return 0;
  }

  if ((a1 < b1 && a1 + a2 < b1 + b2) || (a1 > b1 && a1 + a2 > b1 + b2)) {
    cout << 0 << endl;
  }
  else {
    ll x1 = abs(a1 - b1), x2 = abs((a1 + a2) - (b1 + b2));
    if (x1 % x2 == 0) cout << (x1 / x2) * 2 << endl;
    else cout << (x1 / x2) * 2 + 1 << endl;
  }


  return 0;
}

Measured memory_bytes: 256
N, Q = gets.split.map(&:to_i)
S = gets.chomp

t = [0] * N
N.times do |i|
  t[i+1] = t[i] + ((S[i..(i+1)] == 'AC') ? 1 : 0)
end

Q.times do
  l, r = gets.split.map(&:to_i)
  puts t[r-1] - t[l-1]
end

Measured memory_bytes: 3324
def fact(a):
    res = 1
    while a:
        res *= a
        a -= 1
    return res

n,m,r = map(int,input().split())
r-=n*m
if r < 0:
    print(0)
else:
    print(fact(r+n-1)//fact(n-1)//fact(r))

Measured memory_bytes: 6772
#include <iostream>

int  main(){
    char a,b;
    std::cin>>a>>b;

    switch(a){
        case 'D':
            std::cout<<((b=='D')?'H':'D');
            break;
        case 'H':
            std::cout<<((b=='H')?'H':'D');
            break;
    }
    std::cout<<std::endl;


}

Measured memory_bytes: 256
#include <cstdio>

int search(int A[], int n, int key) {
    int left = 0;
    int right = n;
    while (left < right) {
        int mid = left + ((right - left) >> 1);
        if (A[mid] == key) {
            return true;
        } else if (key < A[mid]) {
            right = mid;
        } else if (key > A[mid]) {
            left = mid + 1;
        }
    }

    return false;
}

int main() {
    int i, n, A[100001], q, key, sum = 0;
    scanf("%d", &n);
    for (i = 0; i < n; ++i) {
        scanf("%d", &A[i]);
    }

    scanf("%d", &q);
    for (i = 0; i < q; ++i) {
        scanf("%d", &key);
        if (search(A, n, key)) {
            sum++;
        }
    }

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

    return 0;
}



Measured memory_bytes: 2956
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define Yes()           printf("Yes\n")
#define No()            printf("No\n")
#define YES()           printf("YES\n")
#define NO()            printf("NO\n")
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int a, b, c; cin >> a >> b >> c;
  if (a > b) swap(a, b);
  if (a <= c && c <= b) Yes();
  else No();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main() {
	int P, Q, R, ans;
	cin >> P >> Q >> R;

	if(P >= Q){
		if(P >= R){
			ans = Q + R;
		}else{
			ans = P + Q;
		}
	}else{
		if(Q >= R){
			ans = P + R;
		}else{
			ans = P + Q;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<climits>
#include<map>

using namespace std;

int count(int a){

	int count = 0;

	while(a%2 == 0){
		count++;
		a /=2;
	}

	return count;

}


int main(){

	int N;
	cin >> N;

	int min = INT_MAX;

	for(int i = 0;i < N;i++){
		int a;
		cin >> a;
		int b = count(a);
		if(b < min){
			min = b;
		}
	}

	cout << min << endl;

    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fol(i,n) for(int i=0;i<n;++i)
using namespace std;
int main(){
    char c[3][3];
    fol(i,9) cin>>c[i/3][i%3];
    fol(i,3) cout << c[i][i];
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
f = []
p = []
max = -10**10
n.times do
	f.push(gets.split.map(&:to_i))
end
n.times do
	p.push(gets.split.map(&:to_i))
end

1023.times do |i|
	total = 0
	open = []
	10.times do |j|
		open[j] = ((i+1) >> j) & 1
	end
	n.times do |j|
		c = 0
		10.times do |k|
			c += f[j][k] * open[k]
		end
		total += p[j][c]
		#p c
	end
	max = total if max < total
	#p open
end
puts max


Measured memory_bytes: 2044
#include <iostream>

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

	std::cin >> A >> B >> C >> X;

	int ans = 0;
	for(int i = 0; i <= A; ++i){
		for(int j = 0; j <= B; ++j){
			for(int k = 0; k <= C; ++k){
				if(500 * i + 100 * j + 50 * k == X){
					++ans;
				}
			}
		}
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 256
n= int(input())
d=[]
ans=False
for i in range(n):
    a,b= map(int,input().split())
    d.append(a-b)

for i in range(0,n-2):
    if d[i]==0 and d[i+1]==0 and d[i+2]==0:
        ans= True
        break
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int A,B; cin>>A>>B;
	ote(A*B%2? "Odd":"Even");
}


Measured memory_bytes: 256
(defparameter +divide+
  (make-array '(4)
              :initial-contents
              '("dream" "dreamer" "erase" "eraser")))

(defmacro while (test &body body)
  `(do ()
       ((not ,test))
     ,@body))

(defun daydream (s)
  (let ((can1 t)
        can2
        (l (length s))
        (j 0)
        buff
        d)

    (setf s (reverse s))
    (dotimes (i 4)
      (setf (aref +divide+ i) (reverse (aref +divide+ i))))

    (while (< j l)
      (setf can2 nil)
      (dotimes (k 4)
        (setf d (aref +divide+ k))
        (if (>= l (+ (length d) j))
            (setf buff (subseq s j (+ (length d) j)))
            (setf buff (subseq s j)))
        (when (string= buff d)
          (setf can2 t)
          (setf j (+ j (length d)))
          (return)))
      (when (not (eq can2 t))
        (setf can1 nil)
        (return)))

    (if (eq can1 t)
        "YES"
        "NO")))

(format t "~A~%" (daydream (read-line)))

Measured memory_bytes: 10600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using vvv= vector<vv>;
const int INF = 1001001001;

int main(){
    int n;cin>>n;
    vi h(n);
    rep(i,n)cin>>h[i];
    
    vi dp(n+1, INF);
    dp[0] = 0;
    for(int i=1; i<n; i++){
        if(i>1)dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
        dp[i] = min(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 4052
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading;

class Test
{
    // Driver code 
    public static void Main()
    {

        var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        var d = input[0];
        var t = input[1];
        var s = input[2];
        var ans = d / (s * 1.0);
        if (ans <= t)
            Console.Write("Yes");
        else
            Console.Write("No");
    }


}






Measured memory_bytes: 18892
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();

        int ans = 1;
        for (int i = 0; i < d; i++) {
            ans *= 100;
        }
        if (n == 100) {
            ans *= 101;
        } else {
            ans *= n;
        }
        System.out.println(ans);

        sc.close();
    }

}


Measured memory_bytes: 23252
from math import floor, sqrt
from collections import Counter

MOD = 10 ** 9 + 7

# xを素因数分解する
def getPrimeFactor(x):
    ans = []
    for d in range(2, floor(sqrt(x)) + 1):
        while x % d == 0:
            ans.append(d)
            x //= d

    if x != 1:
        ans.append(x)

    return ans

# xのn乗（二分累乗法）
def power(x, n):
    ans = 1
    while n:
        if n % 2 == 1:
            ans = (ans * x) % MOD
        x = (x * x) % MOD
        n //= 2
    return ans


N, M = map(int, input().split())

PFs = getPrimeFactor(M)
cnt = Counter(PFs)

N2 = N
if len(cnt):
    N2 += max(cnt.values())

# facts[x]: xの階乗
facts = [1] + [0] * N2
for x in range(1, N2 + 1):
    facts[x] = (facts[x - 1] * x) % MOD

# invFs[x]: xの階乗の逆元
invFs = [0] * N2 + [power(facts[N2], MOD - 2)]
for x in reversed(range(N2)):
    invFs[x] = (invFs[x + 1] * (x + 1)) % MOD

def comb(n, k):
    return ((facts[n] * invFs[k]) % MOD * invFs[n - k]) % MOD


ans = 1
for num in cnt.values():
    ans = (ans * comb(N + num - 1, num)) % MOD
print(ans)


Measured memory_bytes: 12132
#include <stdio.h>

#define WIDTH_MAX 50
#define HEIGHT_MAX 50

int field[ WIDTH_MAX + 2 ][ HEIGHT_MAX + 2 ];
const int dx[ 8 ] = { -1, 0, 1, -1, 1, -1, 0, 1 }, dy[ 8 ] = { -1, -1, -1, 0, 0, 1, 1, 1 };

void del( int, int );

int main( void ) {
	int w, h, x, y, sum;

	for ( ; scanf( "%d %d", &w, &h ), w; printf( "%d\n", sum ) ) {
		for ( y = 1; y <= h; y++ )
			for ( x = 1; x <= w; x++ )
				scanf( "%d", field[ x ] + y );

		sum = 0;
		for ( y = 1; y <= h; y++ )
			for ( x = 1; x <= w; x++ )
				if ( field[ x ][ y ] ) {
					del( x, y );

					sum++;
				}
	}

	return 0;
}

void del( int x, int y ) {
	int i;

	field[ x ][ y ] = 0;

	for ( i = 8; i--;  ) {
		int nx = x + dx[ i ], ny = y + dy[ i ];

		if ( field[ nx ][ ny ] )
			del( nx, ny );
	}
}

Measured memory_bytes: 680
import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.Point;
 
public class Main {
	static final long MOD = 998244353L;
	//static final long INF = -1000000000000000007L;
	//static final long MOD = 1000000007L;
	//static final int INF = 1000000007;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		int N = sc.ni();
		BigInteger X = (new BigInteger(Integer.toString(N-1))).nextProbablePrime();
		int ans = X.intValueExact();
		pw.println(ans);
		pw.close();
	}
	
	//Find the GCD of two numbers
	public static long gcd(long a, long b) {
		if (b == 0)
			return a;
		else
			return gcd(b,a%b);
	}
	
	//Fast exponentiation (x^y mod m)
	public static long power(long x, long y, long m) { 
		long ans = 1;
		x %= m;
		while (y > 0) { 
			if(y % 2 == 1) 
				ans = (ans * x) % m; 
			y /= 2;  
			x = (x * x) % m;
		} 
		return ans; 
	}
	
    public static int[][] sort(int[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<int[]>() {
			  @Override
        	  public int compare(int[] arr1, int[] arr2) {
				  return arr1[1]-arr2[1]; //ascending order
	          }
		});
		return array;
	}
    
    public static long[][] sort(long[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    long[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<long[]>() {
			  @Override
        	  public int compare(long[] arr1, long[] arr2) {
				  return 0;
	          }
		});
		return array;
	}
    
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int ni() { 
            return Integer.parseInt(next()); 
        } 
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str;
        }
    }
}

Measured memory_bytes: 21588
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    a = ILI()
    return N, a


def solve(N, a):
    sum_a = sum(a)
    l_sum_a = [a[0]]
    for i in range(1, len(a) - 1):
        l_sum_a.append(l_sum_a[i - 1] + a[i])
    l_changed = [abs(ele * 2 - sum_a) for ele in l_sum_a]
    ans = min(l_changed)
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()


Measured memory_bytes: 29840
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,x;
    cin>>n>>m>>x;
    int cost[n+5];
    int a[n+5][m+5];
    for(int i=0;i<n;i++)
    {
        cin>>cost[i];
        for(int j=0;j<m;j++)
            cin>>a[i][j];
    }
    int total = 1<<n;
    int ans=1000000000;
    for (int i=0; i<total; i++) 
    { 
        //cout<<i<<'\n';
        int sum[m+5];
        memset(sum,0,sizeof sum);
        for (int j=0; j<n; j++)
        {
            if(i&(1<<j))
            {
                for(int k=0;k<m;k++)
                sum[k]+=a[j][k];
            }
        }
        int j;
        for(j=0;j<m;j++)
        {
            if(sum[j]>=x)
            continue;
            else
            break;
        }
      //  cout<<j<<'\n';
       /* for(int k=0;k<m;k++)
        cout<<sum[k]<<" ";
        cout<<'\n';*/
        if(j==m)
        {
            int costs=0;
            for(j=0;j<n;j++)
            {
                //cout<<j<<" ";
                if(i&(1<<j))
                costs+=cost[j];
            }
            //cout<<costs<<'\n';
            ans=min(ans,costs);
        }
    } 
    if(ans==1000000000)
    cout<<-1<<'\n';
    else
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 3632
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.numeric;

int n;
long[] t;

void main() {
    scan(n);
    t = new long[](n);
    iota(n).each!(i => scan(t[i]));

    if (n == 1) {
        writeln(t[0]);
        return;
    }

    long ans = lcm(t[0], t[1]);

    foreach (i ; 2 .. n) {
        ans = lcm(ans, t[i]);
    }

    writeln(ans);
}

long lcm(long a, long b) {
    return a / gcd(a, b) * b;
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256