akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = input()
inva = ''.join(map(lambda x: str(int(x) ^ 1), a))

mod = 998244353
ans = 0
p = 1
num = [0] * -~n
for i in range(n):
    if i:
        num[i] += (num[i - 1] * 2) % mod
    if a[i] == '1':
        num[i] += 1


def get_div(x):
    y = []
    for i in range(1, n):
        if x % i == 0 and (x // i) % 2:
            y.append(i)
    return y


div = get_div(n)
d = [0] * -~n
tot = 0
for i in div:
    now = n // i
    tt = num[i - 1]
    for j in get_div(i):
        tt -= d[j]
    k = (a[:i] + inva[:i]) * (n // (2 * i)) + a[:i]
    d[i] = tt + (a >= k)
    tot += d[i]
d[n] = int(a, 2) + 1 - tot

for i in range(n + 1):
    ans = (ans + d[i] * i * 2) % mod

print(ans % mod)


Measured memory_bytes: 118852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int ans = (N * (N-1) + M * (M-1)) / 2;
		System.out.println(ans);
	}

}

Measured memory_bytes: 23508
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;
const int INF = 10000000;

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

  int n,x,y;
  cin >> n >> x >> y;
  vector< vector<int> > d(n, vector<int>(n + 2, INF));
  rep(i, n-1) for (int j = i + 1; j < n; ++j) {
    d[i + 1][j + 1] = j - i;
  }
  // --x;
  // --y;
  d[x][y] = 1;
  for(int i = x; i > 0; --i) for(int j = y; j > 0; --j) {
    if (i >= j) continue;
    if (i == x && j == y) continue;
    int mn = min(d[i+1][j], d[i][j+1]) + 1;
    d[i][j] = min(mn, d[i][j]);
  }
  for(int i = x; i <= n; ++i) for(int j = y; j > 0; --j) {
    if (i >= j) continue;
    if (i == x && j == y) continue;
    int mn = min(d[i-1][j], d[i][j+1]) + 1;
    d[i][j] = min(mn, d[i][j]);
  }
  for(int i = x; i > 0; --i) for(int j = y; j <= n; ++j) {
    if (i >= j) continue;
    if (i == x && j == y) continue;
    int mn = min(d[i+1][j], d[i][j-1]) + 1;
    d[i][j] = min(mn, d[i][j]);
  }
  for(int i = x; i <= n; ++i) for(int j = y; j <= n; ++j) {
    if (i >= j) continue;
    if (i == x && j == y) continue;
    int mn = min(d[i-1][j], d[i][j-1]) + 1;
    d[i][j] = min(mn, d[i][j]);
  }


  vector<int> ret(n-1, 0);
  rep(i, n-1) for (int j = i + 1; j < n; ++j) {
    // cout << i << "," << j << "," << d[i][j] << endl;
    ret[d[i + 1][j + 1] - 1] += 1;
    // if (d[i + 1][j + 1] > 5) cout << i << "," << j << "," << d[i][j] << endl;
  }
  for (auto v : ret) cout << v << endl;

}

Measured memory_bytes: 16000
import java.util.PriorityQueue
import kotlin.comparisons.compareByDescending
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfLong()
    //前半
    val first = LongArray(N + 1)
    val fQ = PriorityQueue<Long>(N)
    fQ.addAll(A.subList(0, N))
    var fS = A.subList(0, N).SUM()
    for (n in 0 .. N) {
        first[n] = fS
        fS += A[n + N]
        fQ.add(A[n + N])
        fS -= fQ.poll()!! //一番小さい引く
    }
    //後半
    val latter = LongArray(N + 1)
    val lQ = PriorityQueue<Long>(N, compareByDescending { it })
    lQ.addAll(A.subList(2 * N, 3 * N))
    var lS = A.subList(2 * N, 3 * N).SUM()
    for (n in 0 .. N) {
        latter[N - n] = lS
        lS += A[2 * N - n - 1]
        lQ.add(A[2 * N - n - 1])
        lS -= lQ.poll()!! // 一番大きい引く
    }
    var ans = (0 .. N).map { first[it] - latter[it] }.max()!!
    println(ans)
}

fun List<Long>.SUM() = this.reduce { acc, value -> acc + value }

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}


Measured memory_bytes: 108032
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
long long s,c,ans;
int main(){
	while(~scanf("%lld%lld",&s,&c)){
	    ans=0;
		if(s*2<=c){
			ans+=s;
	        ans+=(c-2*s)/4;
	    }else ans+=c/2;
	    printf("%lld\n",ans);
	}return 0;
} 

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        
        int L = A + B;
        int R = C + D;

        if( L > R){
            System.out.println("Left");
        }else if( L == R){
            System.out.println("Balanced");
        }else{
            System.out.println("Right");
        }
    }
}
 

Measured memory_bytes: 21972
#include <iostream>
#include <numeric>
#include <vector>

int main() {
    int n;
    std::cin >> n;
    std::vector<std::size_t> d(n);
    for (int i = 0; i < n; ++i) {
        std::cin >> d[i];
    }
    int sum = 0;
    for (auto it = d.begin(); it != d.end(); ++it) {
        auto ac_it = it;
        ++ac_it;
        sum += *it * std::accumulate(ac_it, d.end(), 0ULL);
    }
    std::cout << sum << std::endl;
    return 0;
}


Measured memory_bytes: 256
//   __                    .__              ________ .________ ________   ______  
//  |  | __  ____    ______|  |__   __ __  /  _____/ |   ____//   __   \ /  __  \ 
//  |  |/ /_/ __ \  /  ___/|  |  \ |  |  \/   __  \  |____  \ \____    / >      < 
//  |    < \  ___/  \___ \ |   Y  \|  |  /\  |__\  \ /       \   /    / /   --   \
//  |__|_ \ \___  >/____  >|___|  /|____/  \_____  //______  /  /____/  \______  /
//       \/     \/      \/      \/               \/        \/                  \/ 

#include<bits/stdc++.h>
#define range 100005
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
int n,k;
string s;
int suz;

int output = 0;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("test.txt","r",stdin);
    cin>>n>>k;
    cin>>s;
    for(int i=0;i<n;i++){
    	int j=0;
    	while(i + j + 1<n&&s[i + j + 1]==s[i]){
    		j++;
    	}
    	i+=j;
    	output+=j;
    	suz++;
    }
    if(k>=(suz/2)){
    	cout<<(s.length()-1);
    	return 0;
    }
    else {
    	output+=k*2;
    	cout<<output;
    }
	return 0;
}


Measured memory_bytes: 512
// no proof is included. may have unused libraries. may have unused variables. possibly dirty code - contest mode

#include <iostream> // std::cin, std::cout
#include <cstring> // std::memset()
#include <algorithm> // std::max_element(), std::min_element(), std::reverse(), std::sort(), std::__gcd()

using namespace std;

bool debug = true;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m;
    cin >> n >> m;

    cout << (n == m ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
ans=0
cnt={}
cnt["R"]=0
cnt["G"]=0
cnt["B"]=0
for i in s:
    cnt[i]+=1
ans = cnt["R"] * cnt["G"] * cnt["B"]
for i in range(n-2):
    for gap in range(1,(n-i+1)//2):
        if s[i] != s[i+gap] and s[i+2*gap] != s[i+gap] and s[i+2*gap] != s[i]:
            ans-=1
print(ans)

Measured memory_bytes: 9164
#include<stdio.h>

int main(void)
{
	int w,h,i,j,k=1,t,max=0,score=1,head=0,tail=0;
	scanf("%d%d",&h,&w);
	char s[h+2][w+2];
	int ver[h+2][w+2];
	int hor[h+2][w+2];
	
	for(i=0;i<h+2;i++){
		for(j=0;j<w+2;j++){
			ver[i][j]=0;
			hor[i][j]=0;
		}
	}

	for(i=0;i<w+2;i++){
		s[0][i]='#';
		s[h+1][i]='#';
		}

	for(i=1;i<h+1;i++)
		scanf("%s",s[i]+1);
		
	for(i=0;i<h+2;i++){
		s[i][0]='#';
		s[i][w+1]='#';
		}
		
	for(i=1;i<=h;i++){
		for(j=1;j<=w+1;j++){
			if(s[i][j]=='.' && head ==0)
				head=j;
			if(s[i][j]=='#' && head>0){
				tail=j;
				for(k=0;k<tail-head;k++)
					hor[i][j-1-k]=tail-head;
				head=0;
			}
		}
		head=0;
	}
	
	for(j=1;j<=w;j++){
		for(i=1;i<=h+1;i++){
			if(s[i][j]=='.' && head ==0)
				head=i;
			if(s[i][j]=='#' && head>0){
				tail=i;
				for(k=0;k<tail-head;k++)
					ver[i-1-k][j]=tail-head;
				head=0;
			}
		}
		head=0;
	}
	
	for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			score=ver[i][j]+hor[i][j]-1;
			if(score>max)
				max=score;
			}
		}
	printf("%lld",max);
	return 0;
}

Measured memory_bytes: 35328
#include<bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	#define f(i,n) for(ll i=0;i<n;i++)
	#define pb push_back
	int mod=1e9+7;
	int gcd (int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
	ll fast(ll a,ll n){
		a%=mod;
		ll res=1;
		while(n>0){
			if(n&1)res=res*a%mod;
			a=a*a%mod;
			n>>=1;
		}
		return res;
	}
	int func(int a){
		int sum=0;
		while(a){
			sum+=a%10;
			a/=10;
		}
		return sum;
	}
	// vector<int> v;
const int maxn=22;

  int dp[(1<<21)][22];
  // int res=0;
  // int mod=1e9+7;
  int dfs(vector<vector<int>>&a,long long vis,long long j ){
    int n=a.size();
      if(j==n){return 1;}
      // long long res=0;
      if(dp[vis][j]!=-1)return dp[vis][j]%mod;
      dp[vis][j]=0;
      for(int i=0;i<n;i++){
        if(!(vis&(1<<i))&&(a[i][j]==1)){
          // cout<<"asas"<<i<<" asgva"<<vis<<endl;
          long long temp=vis|(1<<i);
          dp[vis][j]+=dfs(a,temp,j+1)%mod;
          dp[vis][j]%=mod;

        }

        // if(!vis[i]&&a[i][j]==1){
        //   vis[i]=true;
        //   dfs(a,vis,j+1);
        //   vis[i]=false;
        // }
      }
      return dp[vis][j]%mod;


  }
	int main(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
    memset(dp,-1,sizeof dp);
    int n;
    cin>>n;
    vector<vector<int>>a(n,vector<int>(n));
    f(i,n){
      f(j,n) cin>>a[i][j];
    }
    // vector<bool>vis(n,false);
    // long long vis=1;
    long long res=0;
  for(int i=0;i<n;i++){
    if(a[i][0]==1){
      // cout<<i<<endl;
      res+=dfs(a,1<<i,1);}
    res%=mod;
  }
   cout<<res;
		return 0;
	}



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

int main()
{
    string S;
    int a[1000]={0};
    cin >> S;
    for(auto i : S){
        a[i]++;
    }
    for(int i='a'; i<='z'; i++){
        if(a[i] == 0){
            printf("%c\n",i);
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
// 153

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll calc(ll h, ll ans) {
    if (h == 1) {
        return ans;
    }
    return calc(h / 2, (ans * 2 + 1));
}
int main() {
    ll h;
    cin >> h;
    ll ans;
    ans = calc(h, 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    string S, T;
    cin >> S >> T;
    int s_size = S.size();
    int t_size = T.size();
    int max_length = 0;
    for (int i=0; i<s_size-t_size+1; i++) {
        int length = 0;
        for (int j=i; j<i+t_size; j++) {
            if (S[j] == T[j-i]) {
                length += 1;
            }
        }

        if (length > max_length) {
            max_length = length;
        }

    }

    cout << T.size() - max_length << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long MOD = 1000000007;
    long n = sc.nextLong();
    long m = sc.nextLong();
    long[] x = new long[(int)n];
    long[] y = new long[(int)m];
    for(int i = 0; i < n; i++) {
      x[i] = sc.nextLong();
    }
    for(int i = 0; i < m; i++) {
      y[i] = sc.nextLong();
    }
    long prod1 = 0;
    long prod2 = 0;
    for(int i = 1; i <= n; i++) {
      prod1 = (prod1 + ((2 * i - n - 1) * x[i - 1])) % MOD;
    }
    for(int i = 1; i <= m; i++) {
      prod2 = (prod2 + ((2 * i - m - 1) * y[i - 1])) % MOD;
    }
    System.out.println((prod1 * prod2) % MOD);
  }
}

Measured memory_bytes: 92504
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0)
void err(){cout << "\033[39;0m" << endl;}
template<template<typename...> class T,typename t,typename... A>
void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);}
template<typename T,typename... A>
void err(T a,A... x){cout << a << ' '; err(x...);}
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
        print(v[i],i==(int)(v.size())-1?suc:2);
}
//dp[i]=max(dp[i-1],max_j(-ji+S[j]+dp[j]+j(j-1)/2+i(i-1)/2-S[i]))
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=3e5+7;
ll S[maxn];
struct L{
	ll a,b;
	inline ll get(ll x)//ax+b
	{return a*x+b;}
};
inline bool down(L a,L b, L c)
{
	return (a.a-b.a)*(c.b-b.b)>=(b.a-c.a)*(b.b-a.b);
}
struct ConvexHull{
	L dq[maxn];
	int sz;
	void clear(){sz=0;}
	void push(L x)
	{
		while(sz>=2&&down(dq[sz-1],dq[sz],x)) sz--;
		dq[++sz]=x;
	}
	ll get(ll x)
	{
		while(sz>=2&&dq[sz].get(x)<=dq[sz-1].get(x)) sz--;
		return dq[sz].get(x);
	}
}q;
ll T[maxn];
ll dp[maxn];
ll pre[maxn],suf[maxn];
int n;
void rev()
{
	for(int i=1;i<=n;i++)
	{
		int j=n-i+1;
		if(i<j) swap(T[i],T[j]);
		S[i]=S[i-1]+T[i];
	}
	S[n+1]=S[n];
}
ll ans[maxn];
ll tmp[maxn];
//l[i]=pre[i-1]+max_j((j-i)(j-i+1)/2-(S[j-1]-S[i-1])+suf[j]);
void solve(int l,int r)
{
	if(l>r) return;
	if(l==r)
	{
		ans[l]=max(ans[l],pre[l-1]+suf[l+1]-T[l]+1);
		return;
	}
	//dbg(l,r);
	int mid=l+r>>1;
	q.clear();
	for(ll i=mid+1;i<=r+1;i++)
		q.push(L{-i,i*(i+1)/2-S[i-1]+suf[i]});
	for(ll i=l;i<=mid;i++)
		tmp[i]=q.get(i)+i*(i-1)/2+S[i-1]+pre[i-1];
	ll mx=-INF;
	for(int i=l;i<=mid;i++)
	{
		mx=max(mx,tmp[i]);
		ans[i]=max(ans[i],mx);
	}
	q.clear();
	for(ll i=l-1;i<mid;i++)
		q.push(L{-i,i*(i-1)/2+pre[i]+S[i]});
	for(ll i=mid;i<=r;i++)
		tmp[i]=q.get(i)+i*(i+1)/2-S[i]+suf[i+1];
	mx=-INF;
	for(int i=r;i>=mid;i--)
	{
		mx=max(mx,tmp[i]);
		ans[i]=max(ans[i],mx);
	}
	solve(l,mid-1);
	solve(mid+1,r);
}
int main()
{
	memset(ans,-0x3f,sizeof(ans));
	cin>>n;
	q.clear();
	q.push(L{0,0});
	for(ll i=1;i<=n;i++)
	{
		cin>>T[i];
		S[i]=S[i-1]+T[i];
		dp[i]=q.get(i)+i*(i+1)/2-S[i];
		dp[i]=max(dp[i],dp[i-1]);
		q.push(L{-i,S[i]+dp[i]+i*(i-1)/2});
		pre[i]=dp[i];
	}
	rev();
	q.clear();
	q.push(L{0,0});
	for(ll i=1;i<=n;i++)
	{
		dp[i]=q.get(i)+i*(i+1)/2-S[i];
		dp[i]=max(dp[i],dp[i-1]);
		q.push(L{-i,S[i]+dp[i]+i*(i-1)/2});
		suf[n-i+1]=dp[i];
	}
	rev();
	solve(1,n);
	//for(int i=1;i<=n;i++) dbg(i,pre[i],suf[i],ans[i]);
	int m;
	cin>>m;
	while(m--)
	{
		int p,x;
		cin>>p>>x;
		cout<<max(pre[p-1]+suf[p+1],ans[p]+T[p]-x)<<'\n';
	}
}

Measured memory_bytes: 19584
#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);

	int n, i, j, k, ans = 0, c;
	cin >> n >> c >> k;
	vector<int> a(n);
	for (i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	for (i = 0; i < n; i++) {
		for (j = i; (j < n) && (j - i < c) && (a[j] <= a[i] + k); j++);
		ans++;
		i = j - 1;
	}
	cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 640
/*
    Reference :-
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1e9+7;
ll fac[100001];
ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}


int main(){
    //std::ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll a,b,c;
    cin>>a>>b;
    ll sum=0;
    forn(i,b){cin>>c;sum+=c;}
    if(sum>=a)cout<<"Yes";
    else cout<<"No";

	return 0;
}


Measured memory_bytes: 256
#pragma G++ optimize (2)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <queue>
#define INF 0x3f3f3f3f
#define NO 30005
#define MO 100005
#define P 1000000007
typedef long long ll;
using namespace std;
inline ll read()
{
	char ch = ' ', last;
	ll ans = 0;
	while (ch < '0' || ch > '9')
		last = ch, ch = getchar();
	while (ch >= '0' && ch <= '9')
		ans = ans * 10 + int(ch - '0'), ch = getchar();
	if (last == '-')
		return -ans;
	return ans;
}
void write(ll x)
{
	if (x >= 10)
		write(x / 10);
	putchar(x % 10 + '0');
}
//head

ll n, book[NO];
string a;
//variable

void init()
{
	n = read();
	cin >> a;
	for (int i = 0; i < n; i++)
		book[a[i] - 'a']++;
}
//functions

int main()
{
	init();
	ll ans = 1;
	for (int i = 0; i <= 'z' - 'a'; i++)
		ans *= book[i] + 1, ans %= P;
	cout << ans - 1 << endl;
	return 0;
}
//main


Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	pl := make([]int, n)
	for i := 0; i < n; i++ {
		pl[i] = nextInt()
	}
	ql := make([]int, n)
	for i := 0; i < n; i++ {
		ql[i] = nextInt()
	}
	var tl []int = []int{1, 2, 3, 4, 5, 6, 7, 8}
	pall := permutations(tl[:n])
	pallnum := make([]int, len(pall))
	for i := 0; i < len(pall); i++ {
		tmp := 0
		for j := 0; j < n; j++ {
			tmp += pall[i][j] * pow(10, n-j-1)
		}
		pallnum[i] = tmp
	}

	tmp := 0
	for j := 0; j < n; j++ {
		tmp += pl[j] * pow(10, n-j-1)
	}
	p := tmp
	tmp = 0
	for j := 0; j < n; j++ {
		tmp += ql[j] * pow(10, n-j-1)
	}
	q := tmp
	if p > q {
		p, q = q, p
	}

	pidx := -1
	qidx := -1
	sort.Ints(pallnum)
	for i := 0; i < len(pallnum); i++ {
		if pallnum[i] == p {
			pidx = i
		}
		if pallnum[i] == q {
			qidx = i
		}
	}

	fmt.Println(qidx - pidx)

}

// 順列
// 順列作成 (ランダム順)
func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}
func pow(a, b int) int {
	var ret int = 1
	for b > 0 {
		if (b & 1) == 1 {
			ret *= a
		}
		a *= a
		b >>= 1
	}
	return ret
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 9400
function sort(A, B, k) {
	var C = [];
	for (var i = 0; i <= k; i++) {
		C[i] = 0;
	}
	for (var j = 0; j <= A.length; j++) {
		C[A[j]]++;
	}
	for (var i = 1; i <= k; i++) {
		C[i] += C[i - 1];
	}
	for (var j = A.length - 1; j >= 0; j--) {
		B[C[A[j]] - 1] = A[j];
		C[A[j]]--;
	}
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');

var n = +lines.shift();
var A = lines.shift().split(' ').map(function(i){return +i;});
var B = [];

sort(A, B, 10000);

console.log(B.join(' '));

Measured memory_bytes: 195776
import sys

def solve():
    input = sys.stdin.readline
    S = input().strip("\n")
    N = len(S)
    for i in range(N-1):
        if S[i] == S[i+1]:
            print(i+1, i+2)
            break
    else:
        for i in range(N-2):
            if S[i] == S[i+2]:
                print(i+1, i+3)
                break
        else:
            print(-1, -1)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <math.h>

using namespace std;
typedef long double lld;
const int mod = 1e9 + 7;
const int maxn = 3005;
lld dp[maxn][maxn];
// dp[i][j][k] 表示前i个硬币正面有j
lld p[maxn];

int main() {
//    freopen("in.in", "r", stdin);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    dp[1][1] = p[1];
    dp[1][0] = (1.0 - p[1]);
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < i; j++) {
            dp[i][j + 1] += dp[i - 1][j] * p[i];
            dp[i][j] += dp[i - 1][j] * (1 - p[i]);
        }
    }
    lld ans = 0;
    for (int i = n / 2 + n %2; i <= n;i++) {
        ans += dp[n][i];
    }
    printf("%.15Lf\n", ans);
    return 0;
}

Measured memory_bytes: 139392
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
    int pri[100005];
    int cnt[100005];
void init()
{
    int i,j;
    for(i=2;i<100005;i++)
        if(pri[i]==0)
            for(j=i+i;j<100005;j+=i)
                pri[j]=1;
    for(i=3;i<100002;i++)
        if(i%2==1&&pri[i]==0&&pri[(i+1)/2]==0)
            cnt[i]=cnt[i-1]+1;
        else
            cnt[i]=cnt[i-1];
}
int main()
{
    init();
    int n;
    cin>>n;
    while(n--)
    {
        int l,r;
        cin>>l>>r;
        cout<<cnt[r]-cnt[l-1]<<endl;
    }
    return 0;
}




Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>
 
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long int;
 
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;
 
template<typename T>
void print1d(vector<T> a){
    for (auto x:a){
        cout << x << " ";
    }
    cout << endl;
}
 
template<typename T>
void print2d(vector<vector<T>> a){
	for (auto v:a){
		for (auto x:v){
			cout << x << " ";
		}
		cout << endl;
	}
}

template<typename T>
void print(T a){
	for (auto x:a){
		cout << x << " ";
	}
	cout << endl;
}

int main()
{
	ll a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	ll ans = Inf;
	rep(i, max(2 * x + 1, 2 * y + 1))
	{
		ll na = max(0LL,x - i / 2);
		ll nb = max(0LL,y - i / 2);
		ans = min(ans, na * a + nb * b + i * c);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
	ll n,a,b;
	scanf("%lld%lld%lld",&n,&a,&b);
	ll d=a+b;
	ll c=n%d;
	ll e=0;
	if(c>a)
	{
		e=a;
	}
	else
	{
		e=c;
	}
	printf("%lld",n/d*a+e);
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    n = int(input())
    al = list(map(int, input().split()))

    for a in al:
        if a % 2 == 1:
            continue
        if a % 3 == 0:
            continue
        if a % 5 == 0:
            continue

        print('DENIED')
        return 

    print('APPROVED')
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

bool judge(vvll g, ll N) {
	vll four;
	repn(i, N) {
		if (g[i].size() % 2 == 1) { return false; }
	}
	repn(i, N) {
		if (g[i].size() >= 6) { return true; }
		if (g[i].size() == 4) { four.push_back(i); }
	}

	if (four.size() <= 1) { return false; }
	if (four.size() >= 3) { return true; }

	ll u = four[0];
	ll v = four[1];

	rep(j, 4) {
		ll x = g[u][j];
		ll y = u;

		while (x != u && x != v) {
			ll t;
			if (g[x][0] != y) { t = g[x][0]; }
			else { t = g[x][1]; }

			y = x;
			x = t;
		}

		if (x == u) { return true; }
	}

	return false;
}

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

	vvll g(N + 1);
	repn(i, M) {
		ll a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	if (judge(g, N)) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
}

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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

int main(){
    string s, t;
    cin >> s >> t;
    if(s+t[t.size()-1]==t){
        cout << "Yes";
    }else{
        cout << "No";
    }
    cout << endl;
    return 0;
}

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

int D;
const int M = 26;
vector<int> C;
vector<vector<int>> S;
vector<int> T;

const int INF = 1<<30;

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

std::mt19937 mt{ std::random_device{}() };

int randint(int lower, int upper)
{
    std::uniform_int_distribution<int> dist(lower, upper);
    return dist(mt);
}

int calc_score(int N=D)
{
    assert(N <= D);
    int ans = 0;
    vector<int> last(M, -1);
    for(int i=0; i<N; i++)
    {
        if(T[i] != -1)
        {
            ans += S[i][T[i]];
            last[T[i]] = i;
        }
        for(int j=0; j<M; j++)
        {
            ans -= C[j] * (i - last[j]);
        }
    }
    return ans;
}

int main()
{
    auto stime = clock();
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> D;
    C.resize(M);
    for(int i=0; i<M; i++) cin >> C[i];
    S.resize(D);
    for(int i=0; i<D; i++)
    {
        S[i].resize(M);
        for(int j=0; j<M; j++)
        {
            cin >> S[i][j];
        }
    }

    int fscore = -INF;
    vector<int> ans;
    for(int k=0; k<=26; k++)
    {
        T.assign(D, -1);
        for(int i=0; i<D; i++)
        {
            int score = -INF;
            int idx = -1;
            for(int j=0; j<M; j++)
            {
                T[i] = j;
                int nscore = calc_score(min(i+1 + k, D));
                if(chmax(score, nscore)) idx = j;
            }
            T[i] = idx;
        }
        int score = calc_score();
        if(chmax(fscore, score)) ans = T;
    }

    T = ans;
    while(1. * (clock() - stime) / CLOCKS_PER_SEC < 1.95)
    {
        int d1 = randint(0, D-1);
        int temp1 = T[d1];
        T[d1] = randint(0, M-1);

        int d2 = randint(0, D-1);
        int d3 = d2 + randint(-16, 16);
        if(d3 < 0) d3 = 0;
        if(d3 >= D) d3 = D-1;
        swap(T[d2], T[d3]);

        if(chmax(fscore, calc_score()))
        {
            // cout << fscore << endl;
            continue;
        }
        T[d1] = temp1;
        swap(T[d2], T[d3]);
    }
    for(int i=0; i<D; i++)
    {
        cout << T[i] + 1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 3732
import java.util.*;

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

        int n = sc.nextInt();

        int[] heights = new int[n];
        for (int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }

        int[] move = new int[n-1];
        int tmp = 0;
        for (int i = 0; i < n-1; i++) {
            if (heights[i] >= heights[i+1]) {
                tmp++;
                move[i] = tmp;
            } else {
                tmp = 0;
                move[i] = tmp;
            }
        }

        int max = 0;
        for (int i = 0; i < move.length; i++) {
            max = Math.max(max, move[i]);
        }

        System.out.println(max);

    }
}


Measured memory_bytes: 49516
s = input()
 
for i in range(len(s)):
    if i%2 == 0:
        if s[i] == "R" or s[i] == "U" or s[i] == "D":
            ans = "Yes"
        else:
            ans = "No"
            break
    elif i%2 == 1:
        if s[i] == "L" or s[i] == "U" or s[i] == "D":
            ans = "Yes"
        else:
            ans = "No"
            break
 
print(ans)

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

int main(){
	int n;
	cin >> n;
	string c;
	cin >> c;
	int r = 0;
	rep(i,n) if(c[i] == 'R') r++;
	int ans = 0;
	rep(i,r) if(c[i] == 'W') ans++;
	cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
	int N , M;
	while(cin >> N >> M , N || M)
	{
		int a = 0 , b = 0 , c = 0 , d = 0;
		map<vector<int> , int>data;
		for(size_t i = 0; i < N; i++)
		{
			string S;
			cin >> S;
			int now = 0;
			while(now < S.size() && S[now] == '.')
			{
				now++;
			}
			int memo = 1;
			for(size_t i = 1; i < 20; i++)
			{
				if(a%i == 0 && b%i == 0 && c%i == 0 && now%i == 0)
				{
					memo = i;
				}
			}
			vector<int>memo2 = { a / memo,b / memo,c / memo };
			data[memo2] = now / memo;

			d = 0;
			while(now < S.size())
			{
				switch(S[now])
				{
					case '(':a++; break;
					case ')':a--; break;
					case '{':b++; break;
					case '}':b--; break;
					case '[':c++; break;
					case ']':c--; break;
					default:
						break;
				}
				now++;
			}
		}
		vector<vector<int>>candidate;
		for(int i = 1; i <= 20; i++)
		{
			for(int j = 1; j <= 20; j++)
			{
				for(int k = 1; k <= 20; k++)
				{
					bool f = 1;
					for(auto x : data)
					{
						if(x.first[0] * i + x.first[1] * j + x.first[2] * k != x.second)
						{
							f = 0;
							break;
						}
					}
					if(f)candidate.push_back(vector<int>{i , j , k });
				}
			}
		}
		vector<set<int>>ans(M);
		for(size_t i = 0; i < M; i++)
		{
			string S;
			cin >> S;
			int now = 0;
			while(now < S.size() && S[now] == '.')
			{
				now++;
			}
			for(auto x : candidate)
			{
				ans[i].insert(( x[0] )*a + ( x[1] )*b + ( x[2] )*c);
			}

			d = 0;
			while(now < S.size())
			{
				switch(S[now])
				{
					case '(':a++; break;
					case ')':a--; break;
					case '{':b++; break;
					case '}':b--; break;
					case '[':c++; break;
					case ']':c--; break;
					default:
						break;
				}
				now++;
			}
		}
		for(size_t i = 0; i < M; i++)
		{
			if(ans[i].size() == 1)
			{
				for(auto x : ans[i])
				{
					cout << x;
				}
			} else
			{
				cout << -1;
			}
			cout << ( i == M - 1 ? "\n" : " " );
		}
	}
}

Measured memory_bytes: 1672
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);
    ArrayList<Data> data;
    boolean debug = false;
    
    //global hensuu except for templete

    //method except for templete

    void run(){
	input();
	for(int i=0;i<data.size();i++){
	    if(debug){
		System.out.println("-----------");
		data.get(i).print_M();
		data.get(i).print_T();
		data.get(i).print_P();
		data.get(i).print_R();
		data.get(i).print_m();
		data.get(i).print_t();
		data.get(i).print_p();
		data.get(i).print_j();
		
	    }
	    solve(i);
	    data.get(i).print_ans();
	}
    }
    void solve(int dataset){
	Data d = data.get(dataset);
	int M = d.M, T = d.T, P = d.P, R = d.R;
	int[] m = d.m, t = d.t, p = d.p, j = d.j;

	int[][] solve = new int[T][2];
	int[][] penalty = new int[T][P];
	for(int i=0; i<R; i++){
	    if(j[i]==0){
		solve[t[i]][0]++;
		solve[t[i]][1] += penalty[t[i]][p[i]] * 20 + m[i];
	    }else{
		penalty[t[i]][p[i]]++;
	    }
	}
	/*
	for(int i=0; i<T; i++){
	    System.out.println(Arrays.toString(solve[i]));
	}
	*/

	boolean[] checked = new boolean[T];
	String ans = "";
	int before = -1;
	for(int i=0; i<T; i++){
	    int max = -1;
	    for(int k=0; k<T; k++){
		if(checked[k]) continue;
		if(max==-1 || solve[max][0] < solve[k][0]){
		    max = k;
		}else if(solve[max][0] == solve[k][0]){
		    if(solve[max][1]>=solve[k][1]) max = k;
		}
	    }

	    if(i==0) ans += (max+1);
	    else{
		if(solve[max][0] == solve[before][0]
		   && solve[max][1] == solve[before][1]){
		    ans += "=" + (max+1);
		}else{
		    ans += "," + (max+1);
		}
	    }
	    checked[max] = true;
	    before = max;
	}

	data.get(dataset).set_ans(ans);
    }

    void input(){
	data=new ArrayList<Data>();
	while(true){
	    int M = sc.nextInt(); int T = sc.nextInt();
	    int P = sc.nextInt(); int R = sc.nextInt();
	    if(M==0 && T==0 && P==0 && R==0) break;
	    int[] m = new int[R];
	    int[] t = new int[R];
	    int[] p = new int[R];
	    int[] j = new int[R];
	    for(int i=0; i<R; i++){
		m[i] = sc.nextInt();
		t[i] = sc.nextInt()-1;
		p[i] = sc.nextInt()-1;
		j[i] = sc.nextInt();
	    }
	    data.add(new Data(M, T, P, R, m, t, p, j));
	}
    }
}

class Data{
    int M;
    int T;
    int P;
    int R;
    int[] m;
    int[] t;
    int[] p;
    int[] j;
    String ans;
    
    Data(int M,int T,int P,int R,int[] m,int[] t,int[] p,int[] j){
	this.M=M;
	this.T=T;
	this.P=P;
	this.R=R;
	this.m=m;
	this.t=t;
	this.p=p;
	this.j=j;
	 }
  
    void set_ans(String a){ans=a;}
    
    void print_M(){System.out.println("M= "+M);}
    void print_T(){System.out.println("T= "+T);}
    void print_P(){System.out.println("P= "+P);}
    void print_R(){System.out.println("R= "+R);}
    void print_m(){System.out.println("m[]= "+Arrays.toString(m));}
    void print_t(){System.out.println("t[]= "+Arrays.toString(t));}
    void print_p(){System.out.println("p[]= "+Arrays.toString(p));}
    void print_j(){System.out.println("j[]= "+Arrays.toString(j));}
    void print_ans(){System.out.println(ans);}
}

Measured memory_bytes: 61032
A,B,C,X,Y = (int(i) for i in input().split())

AB_optimal = min(A+B, C*2)
A_optimal = min(A,C*2)
B_optimal = min(B,C*2)

XY_diff = abs(X-Y)

ans = 0
if X>=Y:
  ans += (X-XY_diff) * AB_optimal
  ans += XY_diff * A_optimal
else:
  ans += (Y-XY_diff) * AB_optimal
  ans += XY_diff * B_optimal

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

vector<int> a, b;
bool A[16001], B[16001], A_sub[16001], B_sub[16001];

int main(){
	string s; cin >> s; int x, y; cin >> x >> y;
	bool flag = true; int cnt = 0;
	Rep(i, s.length()){
		if(s[i] == 'T'){
			if(flag) a.pb(cnt);
			else b.pb(cnt);
			flag = !flag; cnt = 0;
		}else{
			cnt += 1;
		}
	}
	if(cnt != 0){
		if(flag) a.pb(cnt);
		else b.pb(cnt);
	}
	A_sub[8000] = true; B_sub[8000] = true; A[8000] = true; B[8000] = true;
	Rep(i, a.size()){
		Rep(i, 16001){
			A_sub[i] = A[i];
			A[i] = false;
		}
		For(j, -8000, 8001){
			int k = j + 8000;
			if(!A_sub[k]) continue;
			if(k + a[i] <= 16000) A[k + a[i]] = A_sub[k];
			if(i > 0 && k - a[i] >= 0) A[k - a[i]] = A_sub[k];
		}
	}
	Rep(i, b.size()){
		Rep(i, 16001){
			B_sub[i] = B[i];
			B[i] = false;
		}
		For(j, -8000, 8001){
			int k = j + 8000;
			if(!B_sub[k]) continue;
			if(k + b[i] <= 16000) B[k + b[i]] = B_sub[k];
			if(k - b[i] >= 0) B[k - b[i]] = B_sub[k];
		}
	}
	if(A[x + 8000] && B[y + 8000]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n,m,ans;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
char ch;

char map[111][111];

void dfs(int x,int y)
{
	if(x<1||x>n||y<1||y>m) return ;
	if(map[x][y]!=ch) return ;
	map[x][y]='.';
	for(int i=0;i<4;i++) {
		dfs(x+dx[i],y+dy[i]);
	}
	
}


int main()
{
	int i,j;
	while(cin>>n>>m) {
		if(n==0 && m==0 ) break;
		for(i=1;i<=n;i++) {
			for(j=1;j<=m;j++) cin>>map[i][j];
		}
		ans=0;
		for(i=1;i<=n;i++) {
			for(j=1;j<=m;j++){
				if(map[i][j]=='.') continue;
				ch=map[i][j];
				dfs(i,j);
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3316
#include <bits/stdc++.h>
     
    int main() {
      int64_t x, a, b;
      std::cin >> x >> a >> b;
      
      if (-a + b <= 0) {
        std::cout << "delicious" << std::endl;
      } else if (-a + b <= x) {
        std::cout << "safe" << std::endl;
      } else {
        std::cout << "dangerous" << std::endl;
      }
      return 0;
    }

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

namespace program
{
    class Program
    {
        static void Main()
        {
          uint n = Input.ScanUint();
          ulong power = 1;
          for(uint i=1;i<=n;i++)
            power = (power * i) % (1000000007);
          
          Console.WriteLine(power);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

int main(void)
{
    int N;
    cin >> N;
    int satisfactionPoint = 0;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    for (int i = 0; i < N; i++) {
        int B;
        cin >> B;
        satisfactionPoint += B;
    }

    int C[N-1];
    for (int i = 0; i < N-1; i++) {
        cin >> C[i];
    }

    for (int i = 0; i < N-1; i++) {
        if (A[i]+1 == A[i+1]) {
            satisfactionPoint += C[A[i]-1];
        }
    }

    cout << satisfactionPoint << endl;
}


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

const ll mod = ll(1e9) + 7;
const int INF = 1<<29;
const ll lINF = 1l<<40;

int main(){
    int x;
    cin >> x;
    ll ans = x / 500 * 1000;
    x %= 500;
    ans += x / 5 * 5;
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n, l, r, i, ans=0;
  cin >> n;
  
  for (i=0; i<n; i++) {
    cin >> l >> r;
    ans += r - l + 1;
  }
  
  cout << ans << endl;
}

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

int n,ans;
int a[123]; 

inline int qr()
{
	int w=1,x=0;char a=0;
	while(a<'0'&&a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'||a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar(); }
	return x*w;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	if(n<=2)
	{
		cout<<0<<endl;
		return 0;
	}
	for(register int i=1;i<n-1;i++)
		for(register int j=i+1;j<n;j++)
			for(register int k=j+1;k<=n;k++)
			{
				int flag=1;
				if((a[i]+a[j])<=a[k]||(a[i]+a[k])<=a[j]||(a[j]+a[k])<=a[i])
					flag=0;
				if(a[i]==a[j]||a[j]==a[k]||a[i]==a[k])
					flag=0;
				ans+=flag;
			}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
	string s;
	int ans;
	cin >> s;
	for (int i = 1; 2 * i < s.length(); i++){
		if (s.substr(0,i) == s.substr(i,i)) ans = 2*i;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat May  2 19:11:18 2020

@author: Kanaru Sato
"""

n,k = list(map(int, input().split()))
h = list(map(int, input().split()))
dp = [float("inf")]*n

for i in range(n):
    if i == 0:
        dp[i] = 0
    elif i == 1:
        dp[i] = abs(h[1]-h[0])
    else:
        for j in range(1,min(i+1,k+1)):
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))

print(dp[n-1])

Measured memory_bytes: 55008
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;
int is(char c)
{
    if(c == 'a' ||c == 'e'|| c == 'i'|| c =='o' || c =='u'||c == 'y')
        return 1;
    return 0;
}

int f[105];
int a[4][4];
int main()
{
    int n;

    //scanf("%d",&n);
    //for(int i=0;i<n;i++)
    // scanf("%d",&f[i]);
    for(int i=0; i<3; i++)
        for(int j=0; j<3; j++)
        {
            scanf("%d",&a[i][j]);
        }
    for(int i=0; i<=1; i++)
    {
        int las = a[i][0] - a[i+1][0];
        for(int j=1; j<3; j++)
        {
            if(a[i][j]-a[i+1][j] !=las)
            {
                printf("No\n");
                return 0;
            }
        }
    }

    printf("Yes\n");

    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//
 
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

int main() {
	ll K;
	cin >> K;
	if (K == 0) {
		cout << 2 << endl;
		cout << "0 0" << endl;
		return 0;
	}
	if (K == 1) {
		cout << 2 << endl;
		cout << "2 0" << endl;
		return 0;
	}
	ll N = min(K, (ll)50);
	cout << N << endl;
	for (ll i = 0; i < N; i++) {
		ll a = K / N;
		if (i < K % N) {
			a++;
		}
		cout << (N+1) * a - K + (N-1);
		if (i < N - 1) {
			cout << " ";
		}
	}
	cout << endl;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    map<ll,ll> A;
    REP(i,0,N) {
        ll a;
        cin >> a;
        ++A[a];
    }

    ll cnt = 0;
    FORR(a,A) {
        if(a.first <= a.second) cnt += a.second - a.first;
        else cnt += a.second;
    }
    PR(cnt);

    return 0;
}

/*



*/

Measured memory_bytes: 9572