akhauriyash/Code-Regression huggingface dataset:
mod = 10**9+7

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [-1 for __ in range(1 << n)]
dp[0] = 1


def dfs(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += dfs(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]


print(dfs(2**n-1, 0))


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

int main() {
    int N;
    cin >> N;
    map <string, int> S;
    string s;
    for (int i=0; i<N; i++) {
        cin >> s;
        S[s]+=1;
    }
    cout << S.size();
}


Measured memory_bytes: 19200
n,k=gets.split.map &:to_i
s=gets.chomp
a=[0,0]
l='1'
s.chars{|c|
if c==l
a[-1]+=1
else
a<<a[-1]+1
end
l=c
}
a+=[a[-1]]*(n*2)
p ((a.size-k)/2).times.map{|i|a[i*2+k*2+1].to_i-a[i*2]}.max

Measured memory_bytes: 9596
n, m = map(lambda x:int(x), input().split())
a_list = []
b_list = []
for i in range(n):
    a, b = [int(i) for i in input().split()]
    a_list.append([i, a])
    b_list.append(b)

a_list.sort(key=lambda a: a[1], reverse=False)
count = 0
ans = 0
for i in range(n):
    index = a_list[i][0]
    if (count + b_list[index]) >= m:
        ans += (m - count) * a_list[i][1]
        break
    else:
        count += b_list[index]
        ans += a_list[i][1] * b_list[index]

print(ans)



Measured memory_bytes: 25184
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int abs(int x){
  return max(-x,x);
}

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int N;cin>>N;
  int a[51];
  int max,min;
  int max_index,min_index;
  int flag;
  cin>>a[1];
  max=a[1];max_index=1;
  min=a[1];min_index=1;
  for(int i=2;i<=N;i++){
    cin>>a[i];
    if(max<a[i]){
      max=a[i];
      max_index=i;
    }
    if(min>a[i]){
      min=a[i];
      min_index=i;
    }
  }
  if(abs(max)>=abs(min)){
    flag=1;
  }else if(abs(max)<abs(min)){
    flag=0;
  }
  if(flag){
    P(2*N-1);
    REP(i,N){
      if((i+1)!=max_index){
      cout<<max_index<<" "<<i+1<<"\n";
    }
    }
    cout<<max_index<<" "<<max_index<<"\n";
    REP(i,N-1){
      cout<<i+1<<" "<<i+2<<"\n";
    }
  }else{
    P(2*N-1);
    REP(i,N){
      if((i+1)!=min_index){
        cout<<min_index<<" "<<i+1<<"\n";
      }
    }
    cout<<min_index<<" "<<min_index<<"\n";
    for(int j=N;j>=2;j--){
      cout<<j<<" "<<j-1<<"\n";
    }
  }
  // for(int i=1;i<N;i++){
  //   a[i+1]+=a[i];
  // }
  return 0;
}


Measured memory_bytes: 256
program probB
  implicit none
  integer a,b,c
  character char_a*3,char_b*3,char_c*6

  read(*,*) a,b
  
  write(char_a,'(I3)') a
  write(char_b,'(I3)') b

  char_c=trim(adjustl(char_a))//trim(adjustl(char_b))

  read(char_c,*) c

  if(int(sqrt(dble(c)))**2==c) then
     write(*,*) 'Yes'
  else
     write(*,*) 'No'
  end if
  
end program probB


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    int n;cin >> n;
    
    if(n%2==0)cout << n/2 << endl;
    else cout << n/2 +1 << endl;

    return 0;
}





Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC139B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] AB = Console.ReadLine().Split(' ');
            int A = int.Parse(AB[0]);
            int B = int.Parse(AB[1]);
            int ans = 0;
            int sasikomi = 1;
            while (sasikomi < B)
            {
                sasikomi += A - 1;
                ans += 1;
            }
            Console.WriteLine(ans);
        }
    }
}


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


int main(){
	int a;
	string s;
	cin >> s;
	if(s=="SUN") a=7;
	if(s=="MON") a=6;
	if(s=="TUE") a=5;
	if(s=="WED") a=4;
	if(s=="THU") a=3;
	if(s=="FRI") a=2;
	if(s=="SAT") a=1;
	
	cout << a << endl;
	return 0;
}

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

#define Rep(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) Rep(i, 0, n)

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

int main(){
	int n = read<int>();
	rep(i, n){
		int k = read<int>(), p = read<int>();
		if(k%p){
			cout << k%p << endl;
		}else{
			cout << p << endl;
		}
	}
}

Measured memory_bytes: 1164
n, a, b = map(int, input().split())
turn = 0
while True: 
  if turn == 0:
    if a + 1 < b:
      a += 1
    elif 0 < a :
      a -= 1
    else:
      break
    turn = 1
  elif turn == 1:
    if a + 1 < b:
      b -= 1
    elif a + 1 == b and b != n:
      b += 1
    else:
      break
    turn = 0

if turn == 0:
  print('Borys')
else:
  print('Alice')


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int num;
    cin>>num;
    int a[num];
    int tmp=0;
    for(int i=0;i<num;i++)
        cin>>a[i];
    for(int i=0;i<num;i++)
        {for(int j=num-1;j>i;j--)
         if(a[j]<a[j-1])
          {swap(a[j],a[j-1]);
          tmp+=1;}
        }
     for(int i=0;i<num;i++) 
     if(i==num-1)cout<<a[i]<<endl;
     else cout<<a[i]<<" ";
     cout<<tmp<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <set>

using namespace std;
int main(){
  string s;
  cin >> s;
  int K;
  cin >> K;
  set<string> m;
  int len = 1;
  while( len <= K+1 ){
    for(int i=0;i<s.length();++i){
      m.insert(s.substr(i,len));
    }
    len++;
  }

  for(auto subs:m){
    if(--K==0){
      cout << subs << endl;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 2176
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	string str;
	cin >> str;
	if (str[2] == str[3] && str[4] == str[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
    long long x,a,b,c,ans=0;//long long保险
    cin>>a>>b>>c>>x;//输入这四个数
    for(int i=0;i<=a;i++)//枚举500硬币的个数
        for(int j=0;j<=b;j++)//枚举100硬币的个数
            for(int z=0;z<=c;z++){//枚举50硬币的个数
                int sum=i*500+j*100+z*50;//定义sum为此时硬币总值
                if(sum==x)//如果就是x
                   ans++;//计数器加一
                if(sum>x)//这是一个优化，如果k值已经超过了x，后面的z到c时k的值一定大于x，肯定不等于x，所以可以直接退出当前循环
                   break;//退出当前循环
            }
    cout<<ans<<endl;//输出ans的值(AT题都要打换行)
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	n, a, b := scanInt(), scanInt(), scanInt()
	x := make([]int, n)
	for i := range x {
		x[i] = scanInt()
	}

	ans := 0
	for i := 0; i < n-1; i++ {
		ans += min((x[i+1]-x[i])*a, b)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3072
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

bool isNum(char c) {
	return (c >= '0' && c <= '9');
}
bool isPlusNum(char c) {
	return (c >= '1' && c <= '9');
}

string maxnum(string a, string b) {
	if (a.length() > b.length()) {
		return a;
	}
	else if (a.length() < b.length()) {
		return b;
	}
	else {
		return max(a, b);
	}
}

int main() {
	while (true) {
		vector<pair<int, string> > nums;
		int W, H;
		cin >> W >> H;
		if (W == 0 && H == 0)break;
		vs f(H);
		rep(i, H) {
			cin >> f[i];
		}
		vvs dp(H, vs(W, ""));
		reprev(i, H) {
			reprev(j, W) {
				if (isNum(f[i][j])) {
					if (i == H - 1) {
						if (j == W - 1) {
							dp[i][j] += f[i][j];
						}
						else {
							dp[i][j] += f[i][j] + dp[i][j + 1];
						}
					}
					else if (j == W - 1) {
						dp[i][j] += f[i][j] + dp[i + 1][j];
					}
					else {
						dp[i][j] += f[i][j] + maxnum(dp[i + 1][j], dp[i][j + 1]);
					}
				}
			}
		}
		string ans;
		rep(i, H)rep(j, W) {
			if (dp[i][j].length() == 0 || dp[i][j][0] == '0')continue;
			ans = maxnum(ans, dp[i][j]);
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repi(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a != 2 && b != 2)
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>

using namespace std;

int N, K;
int A[200000], C[200000], ans;
int p, q;

int main() {

	scanf("%d %d", &N, &K);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	sort(A, A+N);
	
	for (int i = 0; i < N; i++) {
		C[i] = 1;
	}

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

	sort(C,C+q);


	if (q <= K) { printf("0\n"); return 0; }
	
	ans = 0;
	for (int i = 0; i < q - K; i++) { ans = ans + C[i]; }
	printf("%d\n", ans);
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<random>
using namespace std;


int main(){

  string s;
  cin >> s;

  for(int i=s.size()-1; i>=0; i--){
    if( s[i] == 'r' && s[i-1] == 'e' && s[i-2] == 'm' && s[i-3] == 'a' && s[i-4] == 'e' && s[i-5] == 'r' && s[i-6] == 'd' ){
      i -= 6;
    }else if( s[i] == 'r' && s[i-1] == 'e' && s[i-2] == 's' && s[i-3] == 'a' && s[i-4] == 'r' && s[i-5] == 'e' ){
      i -= 5;
    }else if( s[i] == 'e' && s[i-1] == 's' && s[i-2] == 'a' && s[i-3] == 'r' && s[i-4] == 'e' ){
      i -= 4;
    }else if( s[i] == 'm' && s[i-1] == 'a' && s[i-2] == 'e' && s[i-3] == 'r' && s[i-4] == 'd' ){
      i -= 4;
    }else{
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

  return 0;
}














// EOF


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n;
  vector<ll> a(5);
  cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  ll min = a[0];
  for(i = 1; i < 5; i++)
    chmin(min, a[i]);
  ll x = 5;
  ll result; 
  result= (n - 1) / min + x;
  cout << result << endl;
  return 0;
}

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

int main(void) {
    int n;
    cin >> n;
    switch (n % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon" << endl;
        break;
    default:
        cout << "bon" << endl;
    }
    return 0;
}

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

int main() {
    int n;cin>>n;
    string s;cin>>s;
    
    int a[n+1],sum[n+1];
    memset(a,0,sizeof(a));
    memset(sum,0,sizeof(sum));

    rep(i,n){
        if(s[i]=='W'){
        ++a[i];
        --a[n];
        }
        else{
        ++a[0];
        --a[i+1];            
        }
    }
    
    sum[0]=a[0];
    rep(i,n)sum[i+1]=a[i+1]+sum[i];
    
    sort(sum,sum+n);
    cout<<sum[0]-1<<endl;
	return 0;
}

Measured memory_bytes: 6160
#include <bits/stdc++.h>
using namespace std;
long long int dp[22][1<<22];
long long int m=1000000007;
long long int solve(int comp[23][23],int i,long long int womensubset,int n)
{
    if(i==n+1)
    {
        if(womensubset==0)
        {
            return 1;
        }
        return 0;
        
    }
    if(dp[i][womensubset]!=-1)
    {
        return dp[i][womensubset];
    }
    long long int ans=0;
    
    for(int w=0;w<n;w++)
    {
        if((1<<w)&womensubset&&comp[i][w+1])
        {
            ans+=solve(comp,i+1,(1<<w)^womensubset,n);
            ans=ans%m;
        }
    }
    return dp[i][womensubset]=ans;
}
int main() {
	int n;
	cin>>n;
	memset(dp,-1,sizeof(dp));
	int comp[23][23];
	for(int i=1;i<=n;i++)
	{
	    for(int j=1;j<=n;j++)
	    {
	        cin>>comp[i][j];
	    }
	}
	long long int ans=solve(comp,1,((1<<n)-1),n);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 724544
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

bool check(std::string &S){
    std::size_t n = S.size();
    for(int i = 0; i < n; i++){
        if(S[i] != S[n - 1 - i]) return false;
    }
    return true;
}

int main(){
    std::string S;
    std::cin >> S;
    std::size_t n = S.size();
    // Sは回文か
    if(check(S)){
        std::string T(S.begin(), S.begin() + (n - 1) / 2);
        std::string U(S.begin() + (n + 1) / 2, S.end());
        if(check(T) && check(U)){
            std::cout << "Yes" << std::endl;
        }else{
            std::cout << "No" << std::endl;
        }
    }else{
        std::cout << "No" << std::endl;
    }
    return 0;
}


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

using namespace std;

int N, M;
int LossCnt[5001];
vector<vector<int> > MatcheInfo;

void solve() {
	int curId, size, lossId, flag;
	queue<int> ranking;

	for (int i = 1; i <= N; ++i) {
		if (LossCnt[i] == 0) {
			ranking.push(i);
		}
	}

	flag = 0;
	while (!ranking.empty()) {
		if (ranking.size() > 1) {
			flag = 1;
		}
		curId = ranking.front();
		ranking.pop();
		cout << curId << endl;

		size = MatcheInfo[curId].size();
		for (int i = 0; i < size; ++i) {
			lossId = MatcheInfo[curId][i];
			--LossCnt[lossId];
			if (LossCnt[lossId] == 0) {
				ranking.push(lossId);
			}
		}
	}
	cout << flag << endl;
}

int main() {
	int i, j;

	memset(LossCnt, 0, sizeof(LossCnt));
	cin >> N >> M;
	MatcheInfo.resize(N + 1);
	for (int k = 0; k < M; ++k) {
		cin >> i >> j;
		++LossCnt[j];
		MatcheInfo[i].push_back(j);
	}
	solve();

	return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 1000000000000000005
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
char in[100005];
int sum[100005];
int main(){
	int n,q;
	while(~getII(n,q)){
		scanf("%s",in);
		sum[0]=0;
		F(i,1,n){
			if(in[i-1]=='A'&&in[i]=='C') sum[i]=sum[i-1]+1;
			else sum[i]=sum[i-1];
		}
		while(q--){
			VgetII(l,r);
			printf("%d\n",sum[r-1]-sum[l-1]);
		}
	}
}


Measured memory_bytes: 1280
#include<stdio.h>
#include<string.h>

int main(void)
{
    char s[99];
    char dum[99];
    int n, flag=0, flag2=0;
    int i, count=0;

    scanf("%s", s);
    n = strlen(s);

    for(i=((n-1)/2)-1;i>=0; i--) {
        dum[count] = s[i];
        count++;
    }
    if(strncmp(s, dum, ((n-1)/2)-1) == 0 ){
        flag = 1;
    }

    count =0;
    for(i=n-1;i>=((n+3)/2)-1; i--) {
        dum[count] = s[i];
        count++;
    }
    if(strncmp(s, dum, ((n-1)/2)-1) == 0){
        flag2 = 1;
    }

    if(flag == 1 && flag2 == 1) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}



Measured memory_bytes: 1712
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

struct UnionFind {
	vector<int> data;
	void init(int n) { data.assign(n, -1); }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if(x != y) {
			if(data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
};

int main() {
	int N; int E;
	while(~scanf("%d%d", &N, &E)) {
		UnionFind uf, uf3;
		uf.init(N);
		uf3.init(N * 3);
		vector<int> outdeg(N, 0), indeg(N, 0);
		vpii edges(E);
		rep(i, E) {
			int a; int b;
			scanf("%d%d", &a, &b), -- a, -- b;
			++ outdeg[a], ++ indeg[b];
			edges[i] = { a, b };
			uf.unionSet(a, b);
			rep(k, 3)
				uf3.unionSet(a * 3 + k, b * 3 + (k + 1) % 3);
		}
		sort(edges.begin(), edges.end());
		edges.erase(unique(edges.begin(), edges.end()), edges.end());

		vector<int> ccEdges(N, 0);
		for(auto e : edges)
			++ ccEdges[uf.root(e.first)];
		vector<bool> hasP3(N);
		rep(i, N) {
			if(indeg[i] > 0 && outdeg[i] > 0)
				hasP3[uf.root(i)] = true;
		}
		ll ans = 0;
		rep(i, N) if(uf.root(i) == i) {
			if(!hasP3[i])
				ans += ccEdges[i];
		}
		vector<int> cc3Size(N * 3);
		rep(i, N) if(hasP3[uf.root(i)]) {
			rep(k, 3) if(uf3.findSet(i * 3, uf.root(i) * 3 + k))
				++ cc3Size[uf.root(i) * 3 + k];
		}
		rep(i, N) if(uf.root(i) == i && hasP3[i]) {
			if(uf3.findSet(i * 3 + 0, i * 3 + 1)) {
				int n = cc3Size[i * 3 + 0];
				ans += (ll)n * n;
			} else {
				rep(k, 3)
					ans += (ll)cc3Size[i * 3 + k] * cc3Size[i * 3 + (k + 1) % 3];
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

struct tnode
{
	int dat;
	tnode* lson;
	tnode* rson;
	tnode()
	{
		dat = INF;
		lson = rson = NULL;
	}
	void pushdown()
	{
		if(lson == NULL) lson = new tnode();
		if(rson == NULL) rson = new tnode();
		if(dat != INF) lson->dat = rson->dat = dat;
		dat = INF;
	}
};

void modify_t(tnode*& cur, int l, int r, int dat, int cl = 0, int cr = 1073741823)
{
	if(l > cr || r < cl) return;
	if(cur == NULL) cur = new tnode();
	if(l <= cl && r >= cr) {
		cur->dat = dat;
		return;
	}
	cur->pushdown();
	int mid = cl + cr >> 1;
	modify_t(cur->lson, l, r, dat, cl, mid);
	modify_t(cur->rson, l, r, dat, mid + 1, cr);
}

int query_t(tnode* cur, int id, int cl = 0, int cr = 1073741823)
{
	if(cur->dat != INF) return cur->dat;
	int mid = cl + cr >> 1;
	if(id <= mid) return query_t(cur->lson, id, cl, mid);
	else return query_t(cur->rson, id, mid + 1, cr);
}

tnode* tre;
int n, k;
LL a[100005];
int b[100005];
LL ps[100005];
LL ansl[100005], ansr[100005];

int main()
{
	scanf("%d%d", &n, &k);
	rep1(i, n) scanf("%lld%d", &a[i], &b[i]);
	
	rep1(i, n) {
		a[i] *= 2;
		if(b[i] == 1 && a[i] > k) {
			printf("-1\n");
			return 0;
		}
		ps[i] = ps[i - 1] + a[i];
	}
	
	modify_t(tre, 0, k - 1, n + 1);
	for(int i = n; i >= 1; i --) {
		int rpos = query_t(tre, ps[i - 1] % k);
		if(rpos == n + 1) ansr[i] = ps[n] - ps[i - 1];
		else ansr[i] = ((ps[rpos - 1] - ps[i - 1] - 1) / k + 1LL) * k + ansr[rpos];
		
		if(b[i] == 2) continue;
		int l = (ps[i] - a[i] + k) % k, r = (ps[i] - 1 + k) % k;
		if(l <= r) modify_t(tre, l, r, i);
		else {
			modify_t(tre, l, k - 1, i);
			modify_t(tre, 0, r, i);
		}
	}
	
	modify_t(tre, 0, k - 1, 0);
	rep1(i, n) {
		int lpos = query_t(tre, ps[i] % k);
		if(lpos == 0) ansl[i] = ps[i];
		else ansl[i] = ((ps[i] - ps[lpos] - 1) / k + 1LL) * k + ansl[lpos];
		
		if(b[i] == 2) continue;
		int l = (ps[i - 1] + 1) % k, r = (ps[i - 1] + a[i]) % k;
		if(l <= r) modify_t(tre, l, r, i);
		else {
			modify_t(tre, l, k - 1, i);
			modify_t(tre, 0, r, i);
		}
	}
	
	LL ans = 1LL * INF << 30;
	rep1(i, n + 1) ans = min(ans, ansl[i - 1] + ansr[i]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 87808
N = int(input())
S = input()

pin1 = {}
pin12 = {}
pin123 = {}

for i in range(N):
    if S[i] not in pin1:
        pin1[S[i]] = 1
        for j in range(i + 1, N):
            if S[i] + S[j] not in pin12:
                pin12[S[i] + S[j]] = 1
                for k in range(j + 1, N):
                    if S[i] + S[j] + S[k] not in pin123:
                        pin123[S[i] + S[j] + S[k]] = 1

print(len(pin123))


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int h, w, k;

void paintRows(vector<vector<string>>& masu, int row) {
    for (int bit = 0; bit < h; bit++) {
        if ((1<<bit) & row) {
            for (int column = 0; column < w; column++) {
                masu[bit][column] = "r";
            }
        }
    }
}
void paintColumns(vector<vector<string>>& masu, int column) {
    for (int bit = 0; bit < w; bit++) {
        if ((1<<bit) & column) {
            for (int row = 0; row < h; row++) {
                masu[row][bit] = "r";
            }
        }
    }
}

int main() {    
    cin >> h >> w >> k;
    vector<vector<string>> masu(h, vector<string>(w));
    rep(i, h) {
        string inp;
        cin >> inp;
        rep(j, w) {
            masu[i][j] = inp[j];
        }
    }

    int ans = 0;
    for (int row = 0; row < (1<<h); row++) {
        for (int column = 0; column < (1<<w); column++) {
            vector<vector<string>> tmp = masu;
            paintRows(tmp, row);
            paintColumns(tmp, column);

            int count = 0;
            rep(i, h) {
                rep (j, w) {
                    if (tmp[i][j] == "#") count++;
                }
            }
            if (count == k) {
                ans++;
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	while(cin>>N) {
		VI L(N);
		REP(i, N) cin>>L[i];
		ll sum = accumulate(ALL(L), 0LL);
		string ans = "Yes";
		REP(i, N) {
			if(!(L[i] < sum-L[i])) ans = "No";
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


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

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

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

#define MAXN 200001

ll C[MAXN+1];
ll a,b,n;
void calc2(){
    C[0] = 1;
    C[1] = n;
    int k = n/2;
    for(ll i=2;i<=200001;i++){
        C[i] = ((C[i-1]*(n-i+1)%MOD)*modinv(i,MOD));
        C[i] %= MOD;
    }
}

ll mypow(ll x,ll n,ll m){
    ll res = 0;
    if(n == 0) return 1;
    if(n %2 == 0)return mypow(x*x%m,n/2,m);
    else return x*mypow(x,n-1,m)%m;
}


int main(){
    cin >> n >> a >> b;
    calc2();
    ll ans = mypow(2,n,MOD);
    ans = ans - C[a]-C[b];
    while(ans < 0){
        ans += MOD;
    }
    cout << ans-1 << endl;
    return 0;
}

Measured memory_bytes: 1920
import sys
from collections import Counter
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():
    S = input().strip()[::-1]
    MOD = 2019
    T = [0, int(S[0])]
    t10 = 1
    for s in S[1:]:
        t10 *= 10
        t10 %= MOD
        T.append((T[-1] + int(s) * t10) % MOD)

    # print(T)

    cT = Counter(T)
    # print(cT)
    ans = 0
    for k in T:
        cT[k] -= 1
        ans += cT[k]
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

void init(){
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main()
{
	init();
	int ans = 1, n;
	string str;
	cin >> n >> str;
	lpi(i, 1, n){
		if(str[i-1] != str[i])
			++ans;
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
struct Point {
	int a, b;
	bool operator<(const Point &x) const {
		return 1ll * x.a * (b + 1) < 1ll * a * (x.b + 1);
	}
};
vector<Point> A;
vector<long long> B;
long long Dp[111];
int N, T;
int main() {
	int i, j;
	scanf("%d%d", &N, &T);
	for (i = 1; i <= N; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (!a) B.push_back(b + 1);
		else A.push_back({a, b});
	}
	N = min( (int) A.size(), 40);
	if (A.size()) sort(A.begin(), A.end());
	for (i = 0; i <= 100; ++i) Dp[i] = T + 1;
	Dp[0] = 0;
	for (Point u : A) {
		for (i = 40; i >= 0; --i) {
			Dp[i + 1] = min(Dp[i + 1], Dp[i] + (Dp[i] + 1) * u.a + u.b + 1);
		}
	}
	B.push_back((long long) 1e15);
	sort(B.begin(), B.end());
	for (i = 1; i < (int) B.size(); ++i) B[i] += B[i - 1];
	int Res = 0;
	j = B.size() - 1;
	for (i = 0; i <= 40; ++i) if (Dp[i] <= T) {
		while (j > 0 && B[j - 1] > T - Dp[i]) --j;
		Res = max(Res, i + j);
	}
	printf("%d\n", Res);
}


Measured memory_bytes: 3444
N = int(input())
H = list(map(int, input().split()))
ans = "Yes"
H[0] = H[0] - 1
base = 0
for i in range(1, N):
    if H[i] > H[i-1] :
        H[i] = H[i] -1
    elif H[i] < H[i-1] :
        ans = "No"
print(ans)

Measured memory_bytes: 63856
#include <bits/stdc++.h>
using namespace std;
int main() {

  int n;
  int p[20];
  int count = 0;
  int max = 0;
  
  cin >> n;
  
  for ( int i = 0; i < n; i++ ) cin >> p[i];
  
  for ( int i = 1; i < n-1; i++ ) {
    if ( p[i] < p[i-1] ) max++;
    if ( p[i] < p[i+1] ) max++;
    if ( max == 1 ) count++;
    max = 0;
  }

  cout << count << endl;

  return 0;

}

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

int main()
{
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i < N + 1; ++i)
  {
    string n = to_string(i);
    // cout << i << endl;
    if (n.size() % 2 == 1)
    {
      ans += 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
func main() {
    let a = String(readLine()!)
    var b = [String]()
    for num in a{
        b.append(String(num))
    }
 
    let iValue = Int.random(in: 0 ... (a.count - 3))
    
    
    let answer = b[iValue] + b[iValue + 1] + b[iValue + 2]
    print(answer)
}
main()

Measured memory_bytes: 7584
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    string s;
    cin >> s;
    LL ans = 0;
    LL tmp = 0;
    repe(i, s){
        if(i == 'B') tmp++;
        else ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a;
  cin >> a;
  int b = 24;
  b += 24 - a;
  cout << b << "\n";
}


Measured memory_bytes: 3596
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

inline int safeAdd(int a, int b, int m) {
	if ((long long)a + b >= m) {
		return m + ((long long)a + b) % m;
	} else {
		return a + b;
	}
}

inline int safeMul(int a, int b, int m) {
	if ((long long)a * b >= m) {
		return m + (long long)a * b % m;
	} else {
		return a * b;
	}
}

int powSum(int x, int n, int MOD) {
	if (n == 0) {
		return 0;
	}
	int ret = 0, s = 1, t = 1;
	while (n) {
		if (n & 1) {
			ret = safeAdd(ret, safeMul(s, t, MOD), MOD);
			s = safeMul(s, x, MOD);
		}
		t = safeMul(t, safeAdd(x, 1, MOD), MOD);
		x = safeMul(x, x, MOD);
		n >>= 1;
	}
	return ret;
}

int phi(int n) {
	int ret = 1;
	for (int i = 2; i * i <= n; ++i) {
		if (n % i == 0) {
			ret *= (i - 1);
			n /= i;
			while (n % i == 0) {
				ret *= i;
				n /= i;
			}
		}
	}
	if (n != 1) {
		ret *= (n - 1);
		n = 1;
	}
	return ret;
}

int l;

int getb(int n, int mp, int mq) {
	int m = mp * mq;
	if (n == 1) {
		return 1;
	}
	do {
		int g = __gcd(mq, l - 1);
		if (g == 1) {
			break;
		}
		mp *= g, mq /= g;
	} while (true);
	int bn1;
	if (mq == 1) {
		bn1 = 1;
		for (int i = 2; i < n; ++i) {
			bn1 = safeMul(2, powSum(l, bn1, m), m);
		}
	} else {
		bn1 = getb(n - 1, mp, phi(mq));
	}
	return safeMul(2, powSum(l, bn1, m), m);
}

int main() {
	int n, m;
	while (scanf("%d%d%d", &n, &m, &l) == 3 && l) {
		int ans;
		if (n == 0) {
			ans = 1 % m;
		} else if (n == 1) {
			ans = l % m;
		} else {
			int bn = getb(n, 1, m);
			ans = ((long long)(l - 1) * bn + 1) % m;
		}
		static int id = 0;
		printf("Case %d: %d\n", ++id, ans);
	}
	return 0;
}

Measured memory_bytes: 1188
import numpy as np
N,X,Y=map(int, input().split())
ans = [0]*(N-1)
for i in range(1,N):
  for j in range(i+1,N+1):
    root1 = j-i
    root2 = abs(X-i) + 1 + abs(Y-j)
    min_k = min(root1, root2)
    ans[min_k-1] = ans[min_k-1] + 1

for a in ans:
  print(a)

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

const int maxn = 1e3+10, maxm = 2e5+10;

int n, m;
int a[maxm], b[maxm];
int x[maxm], v[maxn][maxn], y[maxm], vis1[maxn], vis2[maxn];
int rt;
int *vis;
vector<int> to[maxn], num[maxn]; int tot;

void add(int a,int b){
	to[a].push_back(b);
	num[a].push_back(++tot);
}

void dfs2(int u) {
	v[rt][u] = 1;
	for (int v: to[u]) {
		if (!vis[v]) {
			vis[v] = vis[u];
			dfs2(v);
		}
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d", a+i, b+i);
		add(a[i], b[i]);
	}
	for (rt = 1; rt <= n; ++rt) {
		memset(vis1, 0, sizeof(vis1));
		memset(vis2, 0, sizeof(vis2));
		vis1[rt] = vis2[rt] = rt;
		vis = vis1;
		for (int v: to[rt]) {
			if (!vis[v]) vis[v] = v, dfs2(v);
		}
		vis = vis2;
		reverse(to[rt].begin(), to[rt].end());
		reverse(num[rt].begin(), num[rt].end());
		for (int i = 0; i < (int)to[rt].size(); ++i) {
			int v = to[rt][i], e = num[rt][i];
			if (!vis[v]) vis[v] = v, dfs2(v);
			if (vis2[v] == vis1[v]) y[e] = false;
			else y[e] = true;
		}
	}
	for (int i = 1; i <= m; ++i) {
		puts(v[b[i]][a[i]]^y[i]?"diff":"same");
	}
}



Measured memory_bytes: 11392
#include <iostream>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  for (int i = 0; i <= 1250; i++) {
    if ((int) (i * .08) == a && (int) (i * .10) == b) {
      cout << i;
      exit(0);
    }
  }
  cout << -1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int x[10],y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return hypot(dx,dy);
}

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

    vector<int> v(N);
    for (int i=0;i<N;i++) v[i] = i;
    double S = 0.0;
    do{
        for (int i=0;i<N-1;++i) S += dist(v[i], v[i+1]);
    } while (next_permutation(v.begin(),v.end()));

    int factorial = 1;
    for (int i=2; i<=N; ++i )factorial *= i;
    
    cout << fixed << setprecision(10) << double(S/factorial) << endl;
    return 0;
}

Measured memory_bytes: 384
function main()
	H,W,K=map(x->parse(Int,x),split(readline()))
	A=zeros(Int,H,W)
	id=0
	for i=1:H
		s=chomp(readline())
		flag=false
		for c=s
			if c=='#'
				flag=true
				break
			end
		end
		if !flag
			continue
		end
		pre=1
		j=0
		for c=s
			j+=1
			if c=='#'
				id+=1
				for k=pre:j
					A[i,k]=id
				end
				pre=j+1
			end
		end
		for k=pre:W
			A[i,k]=id
		end
	end
	for j=1:W
		pre=1
		for i=1:H
			if A[i,j]!=0
				for k=pre:i-1
					A[k,j]=A[i,j]
				end
				pre=i+1
			end
		end
		for k=pre:H
			A[k,j]=A[pre-1,j]
		end
	end
	for i=1:H
		for j=1:W
			print(A[i,j])
			if j==W
				println()
			else
				print(' ')
			end
		end
	end
end
main()


Measured memory_bytes: 144240
S = input()
character = list('abcdefghijklmnopqrstuvwxyz')

if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
elif len(S) < 26:
    for i in character:
        if i not in S:
            print(S + i)
            exit()
else:
    k = 0
    for i in reversed(range(25)):
        if S[i] < S[i + 1]:
            k = i
            break
    last = sorted(S[k:])
    for i in last:
        if S[k] < i:
            print(S[:k] + i)
            exit()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	int a[9];
	while(true){
	cin>>n;
	if(n==0)
		break;
	int h=0;
	for(int i=0;i<9;i++){
		cin>>a[i];
		h+=a[i];
	}
	cout<<n-h<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0

for i in range(n):
    if a[i]+a[i+1] <= b[i]:
        ans += (a[i]+a[i+1])
        a[i+1]=0
    elif a[i] < b[i] and a[i]+a[i+1] > b[i]:
        ans += b[i]
        a[i+1] -= (b[i]-a[i])
    else:
        ans += b[i]

print(ans)

Measured memory_bytes: 18624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication32
{
    class Program
    {  
      static void Main()
      {
		  int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
		  int[] b = Console.ReadLine().Split().Select(int.Parse).ToArray();
		  int[] c = Console.ReadLine().Split().Select(int.Parse).ToArray();
		  int d,e,f,g,h,i,j,k,l;
		  d=e=f=g=h=i=j=k=l=0;
          d += ((a[3]*3600+a[4]*60+a[5])-(a[0]*3600+a[1]*60+a[2]))/3600;
          e += (((a[3]*3600+a[4]*60+a[5])-(a[0]*3600+a[1]*60+a[2]))%3600)/60;
          f += (((a[3]*3600+a[4]*60+a[5])-(a[0]*3600+a[1]*60+a[2]))%3600)%60;
          g += ((b[3]*3600+b[4]*60+b[5])-(b[0]*3600+b[1]*60+b[2]))/3600;
          h += (((b[3]*3600+b[4]*60+b[5])-(b[0]*3600+b[1]*60+b[2]))%3600)/60;
          i += (((b[3]*3600+b[4]*60+b[5])-(b[0]*3600+b[1]*60+b[2]))%3600)%60;
          j += ((c[3]*3600+c[4]*60+c[5])-(c[0]*3600+c[1]*60+c[2]))/3600;
          k += (((c[3]*3600+c[4]*60+c[5])-(c[0]*3600+c[1]*60+c[2]))%3600)/60;
          l += (((c[3]*3600+c[4]*60+c[5])-(c[0]*3600+c[1]*60+c[2]))%3600)%60;
          Console.WriteLine("{0} {1} {2}",d,e,f);
          Console.WriteLine("{0} {1} {2}",g,h,i);
          Console.WriteLine("{0} {1} {2}",j,k,l);
          
		  }}}

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  if(k <= a) {
    ans += k;
  }
  else {
    ans += a;
    k -= a;
    if(k <= b) {
    }
    else {
      k -= b;
      ans -= k;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3580
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#define inf 0x3f3f3f
#define mem(i,a) memset(i,a,sizeof(i))
using namespace std;
typedef long long ll;
typedef double db;
const int mod = 1e9;
const int maxn = 2e5+5;
string s;
int main(){
	cin >> s;
	if(s == "ABC")
		cout << "ARC" << endl;
	else
		cout << "ABC" << endl;
	return 0;
}


Measured memory_bytes: 3128
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

//?????§??¬?´???°
int gcd(int x, int y) { return y ? gcd(y, x%y) : x; }
//????°???¬?????°
int lcm(int x, int y) { return x*y / gcd(x, y); }
int lcm(vector<int> x) {
	int ret = x[0];
	rep(i, 1, x.size())ret = lcm(ret, x[i]);
	return ret;
}

signed main() {
	int n; cin >> n;
	vector<int> a(n); rep(i, 0, n) { cin >> a[i]; }
	cout << lcm(a) << endl;
	return 0;
}

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

using namespace std;

/*
 * Union-Find tree
 * header requirement: vector
 */
namespace procon {
class UnionFind {
   private:
    struct nodeinfo {
        int par;
        int rank;
        nodeinfo(int par) : par(par), rank(0) {}
    };
    std::vector<nodeinfo> node;

   public:
    UnionFind(int n) : node() {
        node.reserve(n);
        for (int i = 0; i < n; ++i) {
            node.push_back(nodeinfo(i));
        }
    }
    int root(int x) {
        if (node[x].par == x) {
            return x;
        }
        return node[x].par = root(node[x].par);
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (node[x].rank < node[y].rank) {
            node[x].par = y;
        } else {
            node[y].par = x;
            if (node[x].rank == node[y].rank) {
                ++node[x].rank;
            }
        }
    }
    bool is_same_set(int x, int y) { return root(x) == root(y); }
};
}  // namespace procon

int main() {
    int N, K, L;
    cin >> N >> K >> L;

    auto road = procon::UnionFind(N);
    auto rail = procon::UnionFind(N);

    for (int i = 0; i < K; i++) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        road.unite(p, q);
    }
    for (int i = 0; i < L; i++) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        rail.unite(p, q);
    }

    map<pair<int, int>, int> mp;

    for (int i = 0; i < N; i++) {
        mp[make_pair(road.root(i), rail.root(i))]++;
    }
    for (int i = 0; i < N; i++) {
        cout << mp[make_pair(road.root(i), rail.root(i))] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 15104
#include<iostream>
#include<math.h>
using namespace std;

int sum,N;
void ans(int n,int sn,int s)
{
  n-=sn*sn;
  if(n==0)sum++;
  if(s==1 || n<=0)return;
  for(int i=sn;i>0;i--){
    ans(n,i,s-1);
  }
}
int main()
{
  while(1){
    cin>>N;
    if(N==0)break;
    sum=0;
    for(int i=sqrt(N);i>0;i--){
      ans(N,i,4);
    }
    cout<<sum<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  int n;
  vi a(5);
  cin>>n;
  rep(i,5) cin>>a[i];
  sort(a.begin(),a.end());
  int ans=(n+a[0]-1)/a[0];
  ans+=4;
  cout<<ans<<endl;
  return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll N,T;
  cin >> N >> T;
  vector<ll> v(N);
  vector<ll> benefit(N);
  map<ll,int> m;
  for(int i = 0; i < N; i++){
    cin >> v.at(i);
  } 
  
  ll max_val = v.at(N-1);
  for(int i = N-1; i >= 0; i--){
    if(v.at(i) > max_val){
      max_val = v.at(i);
    }
    benefit.at(i) = max_val - v.at(i);
  }
  for(auto x: benefit){
    if(m.count(x) == 0){
      m[x] = 1;
    } else { 
      m[x]++;
    }
  }

  auto itr = m.begin();
  itr = next(itr, m.size()-1);
  cout << itr->second << endl;
}


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

using namespace std;

int f(int x){
  if(x==0)return 1;
  int pcnt = __builtin_popcount(x);
  return f(x%pcnt) + 1;
}

int modpow(int a, int n, int mod){
  int ret = 1;
  while(n>0){
    if(n&1)ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}

int modinv(int a, int mod){
  return modpow(a, mod-2, mod);
}

int main(){
  int cnt=0, n;
  string x;
  cin >> n;
  cin >> x;
  for(int i=n-1;i>=0;i--){
    if(x[i]=='1')cnt++;
  }
  if(cnt==0){
    for(int i=0;i<n;i++)cout << 1 << endl;
    return 0;
  }
  if(cnt==1){
    if(x[n-1]=='1'){
      for(int i=0;i<n;i++){
        cout << (i==n-1?0:2) << endl;
      }
    }
    else{
      for(int i=0;i<n;i++){
        if(x[i]=='1'){
          cout << 0 << endl;
        }
        else if(i == n-1){
          cout << 2 << endl;
        }
        else cout << 1 << endl;
      }
    }
    return 0;
  }
  int sm_p=0, sm_n=0, bp[200009], bn[200009];
  bp[0]=1;
  bn[0]=1;
  for(int i=n-1;i>=0;i--){
    if(x[i]=='1'){
      sm_p = (sm_p + bp[n-1-i])%(cnt+1);
      sm_n = (sm_n + bn[n-1-i])%(cnt-1);
    }
    bp[n-1-i+1] = (bp[n-1-i]*2)%(cnt+1);
    bn[n-1-i+1] = (bn[n-1-i]*2)%(cnt-1);
  }
  for(int i=0;i<n;i++){
    int sm;
    if(x[i]=='0'){
      sm = (sm_p + bp[n-1-i])%(cnt+1);
    }
    else{
      sm = (sm_n - bn[n-1-i] + cnt - 1)%(cnt-1);
    }
    cout << f(sm) << endl;
  }
}



Measured memory_bytes: 5220
#include <stdio.h>

int main(){
  int N;
  int H[100000];
  scanf("%d",&N);
  for(int i=0; i<N; i++){
    scanf("%d",&H[i]);
  }
  if(N==1){
    printf("Yes\n");
    return 0;
  }
  for(int i=1; i<N; i++){
    if(H[i] - H[i-1] > 0){
      H[i]--;
      continue;
    }
    if(H[i-1] - H[i] > 0){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
}

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

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    int ans = 0;
    for (int i = 1; i <= n; i++)
    {
        int x;
        scanf("%d", &x);
        ans += 2 * min(x, m - x);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
O=input()
E=input()
s=''
for o,e in zip(O,E):
  s+=o+e

len_o=len(O)
len_e=len(E)
if len_o < len_e:
  s+=E[len_o:]
elif len_o > len_e:
  s+=O[len_e:]
  
print(s)

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

int main(void)
{
	int a, b, c;

	cin >> a >> b >> c;

	if (a + b == c || b + c == a || c + a == b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256