akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mx = 1e7 + 7; //dont use too large array in every code

ll par[mx]; //dont use long long if u don't need to store large values. be extra careful.
//ll p_u, p_v; //ei duita globally declare korar dorkar nai kono... code e vul hoite pare

//par[x] hocche x er immidiate parent.
//x jei set e ase tar parent ber kore find_parent(x) dia.
//par[x] abar x er set er parent o hoite pare, majhe majhe, jodi 
//actual parent ta par[x] e thake. bt set gula union korle value
//gula ulta palta hoia jay. find_parent function ta call korle
//auto value gula correctly boshe. tai always x er set er actual
//parent bair korte find_parent(x) function call korte hobe.

ll find_parent(ll x) {
    if(x == par[x]) return x;

    //x er parent je, tar actual parent return korba
    //not par[x] = find_parent(x), eta to infinite loop e poira gelo
    return par[x] = find_parent(par[x]); //return korte hobe
}



void join(ll u, ll v) {

    ll p_u = find_parent(u);
    ll p_v = find_parent(v);

   if(p_u == p_v) return; //par[u] ashole u er set er parent na. 
                //find_parent(u) jei node ta return korbe, oita u er set er parent.
                //par array ta ei parent bair korte help kore.

   par[p_u] = p_v; //par[u] = p_v na. u er set er parent je, tar parent p_v diba.
                    //mane par[p_u] = p_v diba.
}

int main() {
    ll n, q;  cin >> n >> q;
    for(ll i = 0; i < n; i++) par[i] = i;

    while(q--) {
        ll t; cin >> t;
        if(t == 1) {
            ll u, v;  cin >> u >> v;
            ll p_u = par[u]; //no no
            ll p_v = par[v]; //no no

             //par[u] kintu u er parent na... 
             //not always
             //find_parent(u) dile actual u er parent ase
             //par[u] dile ekta node ashe, tar jodi arekta parent thake?
             //shetar jodi arekta thake?
             //erokom dada por dada hoia finally jei purbo purush
             //shei ashol parent
             //jeta bair kore find_parent(u) function ta.

             //so emon:
             p_u = find_parent(u), p_v = find_parent(v);
            if(p_u == p_v) cout << 1 << endl;
            else cout << 0 << endl;
        }

        else if( t == 0) {
            ll u, v;  cin >> u >> v;
            join(u, v);
        }
    }

    return 0;
}

Measured memory_bytes: 5104
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include <list>
#include<numeric>
#include<queue>
#include<stack>
#define rep(i,n) for(int i=0;i<(n);++i)
#define _GLIBCXX_DEBUG
using namespace std;
typedef pair<int, int> P;
typedef long long ll;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a <<" "<< b <<" "<< c << endl;
}


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

#define fa(x,v) for(auto x:v)
#define f(i,a,b) for(ll i=(ll)a;i<=(ll)b;i++)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define spc " "
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(s) (ll)int(s.length())
#define sz(v) (ll)int(v.size())
#define MOD 1000000007

void Fast_IO() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef rsd511
    freopen("input.in","r",stdin);
    freopen("output.out","w",stdout);
    #endif
    #ifndef rsd511
    #define trace(...) {}
    #define cotra(...) {}
    #endif
} 

// Code Here

int main()
{
    Fast_IO();
    ll n; cin >> n;
    ll a[n]; f(i,0,n-1) cin >> a[i];
    ll suff[n]; f(i,0,n-1) suff[i] = a[i];
    rf(i,n-2,0) suff[i] += suff[i+1];
    f(i,0,n-1) a[i] %= MOD, suff[i] %= MOD;
    ll ans = 0;
    f(i,0,n-2) {
    	ans += (a[i] * suff[i+1]) % MOD;
    	ans %= MOD;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 6772
S = gets.chomp
MOD = 10 ** 9 + 7

cnt = 0

mod = [1] + [0] * 12
S.length.times do
	n = S[-1 *(1 + cnt)]
	newmod = [0] * 13
	if n == '?'
		(0..9).each do |i|
			m =  i * 10 ** (cnt % 6)
			13.times do |j|
				newmod[(j + m) % 13] += mod[j]
			end
		end
		13.times do |j|
			mod[j] = newmod[j] % MOD
		end
	else
		m = n.to_i * 10 ** (cnt % 6)
		13.times do |j|
			newmod[(j + m) % 13] = mod[j]
		end
		mod = newmod
	end
	cnt += 1
end

puts mod[5]

Measured memory_bytes: 2044
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#C
N,W = map(int,input().split())
v = [0] * (N+1)
w = [0] * (N+1)

for j in range(1, N+1):
    v[j], w[j] = map(int,input().split())

dp = [[0 for i in range(W+1)] for j in range(N+1)]

for j in range(1, N+1):
    for i in range(1, W+1):
        if w[j] <= i:
            dp[j][i] = max(dp[j-1][i], dp[j][i-w[j]] + v[j])
        else:
            dp[j][i] = dp[j-1][i]

print(dp[N][W])

Measured memory_bytes: 18164
from collections import Counter

def goodify(a):
    nums = Counter(a)
    bads = 0
    for k, v in nums.items():
        if v >= k:
            bads += v - k
        else:
            bads += v
    return bads


if __name__ == '__main__':
    _ = input()
    a = Counter(map(int, input().split()))
    print(goodify(a))

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

const int MAXN=2e5+5;
int h[MAXN], ent[MAXN], sai[MAXN];
stack<int> st, sti;
unsigned long long int resp, cur, cur2;
int n;

int main() {
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%d", &h[i]);

    st.push(-1); sti.push(0);
    for(int i=1; i<=n+1; i++) {
        if(i==n+1) h[i]=0;
        while(st.size()&&st.top()>h[i]) {
            sai[sti.top()]=i-1;
            st.pop(); sti.pop();
        }
        ent[i]=sti.top()+1;
        st.push(h[i]); sti.push(i);
    }

    for(int i=1; i<=n; i++) {
        cur=h[i]; cur*=(sai[i]-ent[i]+1);
        cur2=i-ent[i]; cur2*=sai[i]-i; cur2*=h[i];
        resp+=cur; resp+=cur2;
    }

    printf("%llu\n", resp);
}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main(){
    string s1;
    string s2;
    string s3;
    cin >> s1 >> s2 >> s3;
    transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
    transform(s2.begin(), s2.end(), s2.begin(), ::toupper);
    transform(s3.begin(), s3.end(), s3.begin(), ::toupper);
    cout << s1[0] << s2[0] << s3[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s;
    int o=0,u=0;
    long long ans=0;
    vector<int> b(26);
    vector<int> c(0);
    for (int i;i<26;i++){
        b.at(i)=0;
    }
    s="abcdefghijklmnopqrstuvwxyz";
    string a;
    cin >> a;
    for (int i=0;i<a.size();i++){
        for (int j=0;j<26;j++){
            if (a.at(i)==s.at(j)) b.at(j)++;
        }
    }
    for (int i=0;i<26;i++){
        if (b.at(i)!=0 && b.at(i)%2==0) c.push_back(b.at(i)/2);
        if (b.at(i)%2==1) {
            u++;
            if (u==2) {
                cout << 0 << endl;
                o=1;
                break;
            }
            if (b.at(i)!=1) c.push_back((b.at(i)-1)/2);
        }
    }
    int y=0;
    vector<long long> h(0);
    for (int i=0;i<c.size();i++){
        y=y+c.at(i);
        int g=1;
        for (int j=1;j<c.at(i)+1;j++){
            g=g*j;
        }
        h.push_back(g);
    }
    long long f=1;
    for (int i=1;i<y+1;i++){
        f=f*i;
    }
    for (int i=0;i<h.size();i++){
        f=f/h.at(i);
    }
    if (o==0) cout << f << endl;
}



Measured memory_bytes: 3216
#include <iostream>
#include <algorithm>

using namespace std;

int N, L[111];
int main(){
	cin >> N;
  	for(int i = 0; i < N; i++)cin >> L[i];
  	sort(L, L + N);
  	int result = 0;
  	for(int i = 0; i < N; i++){
    	for(int j = i + 1; j < N; j++){
        	for(int k = j + 1; k < N; k++){
            	if(L[i] < L[j] && L[j] < L[k] && L[i] + L[j] > L[k])result++;
            }
        }
    }
  	cout << result << '\n';

}


Measured memory_bytes: 3640
import java.util.Scanner;

// Java8
public class Main
{
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) throws Exception
	{ 
		new Main().run();
	}
	
	void run()
	{
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a>=b) System.out.println("delicious");
		else if(x+a>=b) System.out.println("safe");
		else System.out.println("dangerous");
	}
	
}


Measured memory_bytes: 21844
Scanf.scanf "%d" (fun n ->
    let nei = Array.make n [] in
    for i = 1 to n - 1 do
        Scanf.scanf " %d %d" (fun x y ->
            let x = x - 1 in let y = y - 1 in
            nei.(x) <- y :: nei.(x);
            nei.(y) <- x :: nei.(y)
        )
    done;

    let count node =
        let rec dfs parent cur =
            1 + List.fold_left (fun acc v ->
                if v = parent then acc else acc lxor dfs cur v) 0 nei.(cur)
        in
        dfs 0 node
    in

    let r = List.fold_left (fun acc l -> acc lxor count l) 0 nei.(0) in
    print_endline @@ if r <> 0 then "Alice" else "Bob"
)

Measured memory_bytes: 22364
#include<stdio.h>
#include<iostream>

using namespace std;

int main()
{
	int n, m, l, r, lmax, rmin;
	cin >> n;
	cin >> m;
	lmax = 0;
	rmin = n;
	for (int i = 0; i < m; i++)
	{
		cin >> l;
		cin >> r;
		if (lmax < l) lmax = l;
		if (rmin > r) rmin = r;
	}
	if (rmin - lmax + 1 <= 0) cout << "0" << endl;
	else cout << rmin - lmax + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;

  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }

  const int MOD = 1000000007;
  vector<vector<int>> dp(h, vector<int>(w, 0));
  dp[0][0] = 1;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        continue;
      }
      if (i > 0) {
        dp[i][j] += dp[i - 1][j];
        dp[i][j] %= MOD;
      }
      if (j > 0) {
        dp[i][j] += dp[i][j - 1];
        dp[i][j] %= MOD;
      }
    }
  }
  cout << dp[h - 1][w - 1] << endl;

  return 0;
}

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

long long f[2][55][2600];

int main( void ) {
	int n, A;
	scanf("%i %i", &n, &A);
	
	int S[n];
	for( int i = 0; i < n; i++ ) {
		scanf("%i", &S[i]);
	}
	
	for( int sum = 0; sum <= 2500; sum++ ) {
		for( int j = 1; j <= n; j++ ) {
			if( (sum % j == 0) && (sum / j == A) ) {
				f[n%2][j][sum] = 1;
			}
		}
	}
	
	for( int i = n-1; i >= 0; i-- ) {
		int cur = i % 2, nxt = (i+1) % 2;
		
		memset(f[cur], 0, sizeof(f[cur]));
		for( int j = 0; j <= n; j++ ) {
			for( int sum = 0; sum <= 2500; sum++ ) {
				f[cur][j][sum] = f[nxt][j][sum] + f[nxt][j+1][sum+S[i]];
			}
		}
	}
	
	printf("%lld\n", f[0][0][0]);
	
	return 0;
}

Measured memory_bytes: 2432
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N,A;
int32_t x[50];
int64_t dp[50][5001];
int64_t func(int i, int32_t over)
{
	if (i == N) {
		return (over == 0 ? 1 : 0);
	}

	if (dp[i][over + 2500]!=-1) {
		return dp[i][over + 2500];
	}

	return dp[i][over + 2500] = func(i+1,over)+ func(i + 1, over+(x[i]-A));
}

template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

int main()
{
	fill_all(dp, -1);
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>A;
	for (int32_t i = 0; i < N; i++)
	{
		in >> x[i];
	}
	out << func(0, 0)-1 << endl;

	return 0;
}
#endif


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    string w;
    cin >> w;
    int cnt = 0;
    while (1) {
        string s;
        cin >> s;
        if (s == "END_OF_TEXT") break;
        rep(i, 0, (int)s.size()) {
            if ('A' <= s[i] && s[i] <= 'Z') {
            s[i] = s[i] + 'a' - 'A';
            }
        }
        if (s == w) cnt++;
    }
    cout << cnt << endl;
    return 0;
}



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

int main(){
    string s;cin>>s;
    vector<int> hon{2,4,5,7,9};
    vector<int> pon{0,1,6,8};

    
    if (find(hon.begin(), hon.end(), (int)(s[s.size()-1]) - '0') != hon.end()){
        cout << "hon" << endl;
    } else if (find(pon.begin(), pon.end(), (int)(s[s.size()-1]) - '0') != pon.end()){
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
from itertools import accumulate
from collections import Counter
import numpy as np 
n = int(input())
a = list(map(int, input().split()))
itra = [0] + list(accumulate(a))
ans_c = np.array(list(Counter(itra).values())).astype("int64")
ans_c = ans_c * (ans_c - 1) // 2
print(np.sum(ans_c))

Measured memory_bytes: 50528
import sys
from copy import copy
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for test in range(int(input())):
'''
inf = 100000000000000000  # 1e17
mod = 998244353

n, a, b = map(int, input().split())
num = a + b
ans = n // num * a
n %= num
ans += min(n, a)
print(ans)


Measured memory_bytes: 38256
from collections import deque
N, M = map(int, input().split())

path = [[] for i in range(N)]
indicator = [None] * N
indicator[0] = (0, 0)
for i in range(M):
    a, b = map(int, input().split())
    a-=1
    b-=1
    path[a].append(b)
    path[b].append(a)

def solve(N, path, indicator):
    visit = [False]*N
    visit[0] = True
    p = 0
    l = 0
    q = deque()
    q.append((0, 0))

    while q:
        (p, l) = q.popleft()
        for room in path[p]:
            if visit[room]:
                continue
            if indicator[room] is None:
                indicator[room] = (p, l+1)
                q.append((room, l+1))
                visit[room] = True
            elif indicator[room][1] > l+1:
                return []

L = solve(N, path, indicator)
if L == []:
    print("No")
else:
    print("Yes")
    for p, l in indicator[1:]:
        print(p+1)







Measured memory_bytes: 45308
#include <bits/stdc++.h>
#define ll long long int
const ll mod=1e9+7;
using namespace std;

bool cmp(pair<ll,ll> a , pair<ll,ll> b)
{
    if(a.first==b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}

int main()
{
    ll maxPos = -1e10,maxNeg = -1e10,minPos = 1e10 ,minNeg = 1e10;
    ll n ;
    cin>>n;
    for(ll i = 0;i<n ;i++)
    {
        ll x,y;
        cin>>x>>y;
        maxPos = max(maxPos,x+y);
        minPos = min(minPos,x+y);

        maxNeg = max(maxNeg,x-y);
        minNeg = min(minNeg,x-y);
    }
    cout<<max(abs(maxNeg-minNeg),abs(maxPos-minPos));
}


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

using namespace std;

#define ll long long 
#define mod 100000007
#define MAX 100000

int main()
{
	int n, m;
	
	cin >> n >>m;
	int a = (n*(n-1))/2;
	int b = (m*(m-1))/2;
	cout << a + b << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;


int n,m,q;
struct
{
    vector<int>v;
}p[500+5];
int main()
{
    while(~scanf("%d%d%d",&n,&m,&q))
    {
        for(int i=0;i<m;i++)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            p[l].v.push_back(r);
        }
        for(int i=1;i<=n;i++)
            sort(p[i].v.begin(),p[i].v.end());
        for(int i=0;i<q;i++)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            ll sum=0;
            for(int i=l;i<=r;i++)
            {
                ll d=upper_bound(p[i].v.begin(),p[i].v.end(),r)-p[i].v.begin();
                sum+=d;
            }
            printf("%lld\n",sum);
        }
        for(int i=1;i<=n;i++)
            p[i].v.clear();
    }
    return 0;
}


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

int main() {
  int count=0;
string n;
  cin>>n;
  for(int i=0;i<n.length();i++){
    string l=n.substr(i,1);
    int num = atoi(l.c_str());
    count+=num;
  }
  if(count%9==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3736
#include<stdio.h>
int main(){
  int h,w;
  int bool=1;
  while(bool){
    scanf("%d %d",&h,&w);
    if(h == 0 && w == 0){
      bool=0;
    }else{
      for(int i=0;i<h;i++){

        for(int i=0;i<w;i++){
          printf("#");
        }
        putchar('\n');
      }
      putchar('\n');
    }
  }
}



Measured memory_bytes: 2072
n,m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(m)]
w = [0]*(n+1)
for i,j in a:
    if (i==1):
        w[j] = 1
for i,j in a:
    if (j==n):
        if (w[i]==1):
            print("POSSIBLE")
            exit()
print("IMPOSSIBLE")    

Measured memory_bytes: 47036
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
#include <list>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
	int n , x , a = 1001 , m;
    cin >> n >> x;
    for (int i = 0 ; i < n ; i++) {
        cin >> m;
        a = min(a, m);
        x -= m;
    }
    cout << n + x / a;
	
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

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

    vector<int> a = {1, 2, 4, 8, 16, 32, 64, 128};
    for(int i = a.size() - 1; i >= 0; i--){
        if (a[i] <= N) {
            cout << a[i] << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        char[] n = scan.next().toCharArray();
        for (int i = 0; i < n.length; i++) {
            n[i] -= '0';
        }
        int max = 0;
        for (int j = 0; j < n.length; j++) {
            max += n[j];
        }
        for (int i = n.length - 2; i >= 0 ; i--) {
            n[i + 1] = 9;
            if(n[i] == 0) {
                continue;
            }
            n[i]--;
            int sum = 0;
            for (char aN : n) {
                sum += aN;
            }
            max = Math.max(max, sum);
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int n, sum;
double ans;
int main(){
    cin>>n;
    for(int i = 1;i <= n; i++)if(i & 1)sum++;
    printf("%.7lf\n", 1.0 * (sum) / (1.0 * n));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<long long,long long> mp;
long long n,m,a,b,c,ans;
int main() {
    cin >> n >> m;
   for(int i = 0; i < n; i++){
      cin >> a;
      mp[a]++;
   }
    for(int i = 0; i < m; i++){
        cin >> b >> c;
        mp[c] += b;
    }
    map <long long,long long > :: iterator it;
    for( it = -- mp.end();;it--){
        ans += min(n,it->second) * it->first;
        n -= it->second;
        if(n <= 0)
            break;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 16080
from operator import itemgetter
n,m=map(int,input().split())
e=[[int(i) for i in input().split()] for i in range(m)]
for i in range(0,m):
    t=e[i]
    t.append(i)
e.sort()
c=0
k=e[i][0]
for i in range(0,m):
    d=e[i]
    if k==e[i][0]:
        c+=1
        d.append("0"*(6-len(str(k)))+str(k)+"0"*(6-len(str(c)))+str(c))
    else:
        k=e[i][0]
        c=1         
        d.append("0"*(6-len(str(k)))+str(k)+"0"*(6-len(str(c)))+str(c))
e.sort(key=itemgetter(2)) 
for i in range(0,m):
    print(e[i][3])

Measured memory_bytes: 32584
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

string reverseLcs(const string & a, const string & b, const vector<vector<int> > & dp, size_t i, size_t j)
{
    if (i == 0 || j == 0) {
        return "";
    }

    if (a.at(i - 1) == b.at(j - 1)) {
        return reverseLcs(a, b, dp, i - 1, j - 1) + a.at(i - 1);
    } else {
        if (dp[i - 1][j] == dp[i][j]) {
            return reverseLcs(a, b, dp, i - 1, j);
        } else {
            return reverseLcs(a, b, dp, i, j - 1);
        }
    }
}

string lcs(const string & a, const string & b)
{
    vector<vector<int> > dp(a.size() + 1, vector<int>(b.size() + 1));

    for (size_t i = 1; i < dp.size(); ++i) {
        for (size_t j = 1; j < dp[0].size(); ++j) {
            if (a.at(i - 1) == b.at(j - 1)) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = max(dp[i - 1][j],
                               dp[i][j - 1]);
            }
        }
    }

    return reverseLcs(a, b, dp, a.length(), b.length());
}

int main()
{
    string str;
    while (cin >> str) {
        string rstr(str);
        reverse(rstr.begin(), rstr.end());
        cout << lcs(str, rstr) << endl;
    }

    return 0;
}

Measured memory_bytes: 17056
#include<bits/stdc++.h>
using namespace std;
int main() {
  int D,G;
  int P[10],C[10];
  cin>>D>>G;
  for(int i=0; i<D; i++){
    cin>>P[i]>>C[i];
  }
  int ans=100000000;
  for(int i=0; i<(1<<D); i++){
    int point=0,cnt=0;
    for(int j=0; j<D; j++){
      if((i>>j)&1){
        point+=C[j];
        point+=P[j]*(j+1)*100;
        cnt+=P[j];
      }
    }
    vector<int>v;
    for(int j=0; j<D; j++){
      if((i>>j)&1)continue;
      for(int k=0; k<P[j]; k++){
        v.push_back((j+1)*100);
      }
    }
    sort(v.begin(),v.end());
    while(v.size()&&point<G){
      point+=v.back();
      cnt++;
      v.pop_back();
    }
    if(point>=G){
      ans=min(ans,cnt);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#include<cctype>
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back

using namespace std;

inline ll read()
{
	ll f=1,sum=0;char c=getchar();
	while (!isdigit(c)) {if (c=='-') f=-1;c=getchar();}
	while (isdigit(c)) {sum=sum*10+c-'0';c=getchar();}
	return sum*f;
}

int main()
{
	int len=read(),pos=read();
	for (int i=pos-len+1;i<=pos+len-1;i++) cout<<i<<' ';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int main(){
    int n;
    cin >> n;
    string ans = "";
    if(n == 25) ans = "Christmas";
    if(n == 24) ans = "Christmas Eve";
    if(n == 23) ans = "Christmas Eve Eve";
    if(n == 22) ans = "Christmas Eve Eve Eve";
    cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Tuple

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    arms <- replicateM n $ do
        [x,l] <- getIntList
        return (x-l,x+l)
    print . solve (- 10^9) $ sortOn swap arms

solve _ [] = 0
solve m ((l,r):xs) | m <= l = 1 + solve r xs
                   | otherwise = solve m xs

Measured memory_bytes: 68988
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main {


   public static void main(String args[]) throws IOException{

	   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	   int n = Integer.parseInt( br.readLine() );
	   String[] string =  br.readLine().split(" ");
       int[] S = new int[n+1];


       for(int i = 0; i < n; i++ ){

    	   S[i] = Integer.parseInt( string[i] );

       }

       int q = Integer.parseInt( br.readLine() );
	   String[] stringq =  br.readLine().split(" ");
       int[] T = new int[q];


       for(int i = 0; i < q; i++ ){

    	   T[i] = Integer.parseInt( stringq[i] );

       }


       int answer = 0;


       for(int i = 0; i < q ; i++ ){

           answer += Linersearch(S , n,  T[i] );

       }

     System.out.println(answer);


   }



   public static int Linersearch(int[] S, int n,  int key){

	   S[n] = key;
	   for(int i = 0; i < n;i++){


		   if( S[i] == key ){

			   return 1;
		   }

		   if(i == n){
			   return 0;
		   }

	   }

	   return 0;
   }



}

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

int main() {
  int n;cin>>n;
  int m=1;
  if (n==1||n==2||n==4) m=1;
  else 
  {
  while(n!=4) {
    m++;
    if (n%2==0) n /= 2;
    else n = n * 3 + 1;
  }
  }
  cout<<m+3<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;

int main() {
	int n, m, c; CI n >> m >> c;
	VI b(m); CI b;
	int a[26][25] = {};
	REP(i, n) {
		REP(j, m) {
			CI a[i][j];
		}
	}

	int ans = 0;
	REP(i, n) {
		int sum = 0;
		REP(j, m) {
			sum += a[i][j]*b[j];
		}
		if (sum + c > 0)ans++;
	}
	CO ans EN;
}

Measured memory_bytes: 256
class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1]*(n+1)
    self.rnk = [0]*(n+1)
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]
  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if(x == y):
      return 
    if self.root[x] > self.root[y]:
      x, y = y, x
    self.root[x] += self.root[y]
    self.root[y] = x 
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)
  def Count(self, x): # xが属するグループのサイズを返す
    return -self.root[self.Find_Root(x)]
  def Members(self, x): # xが属するグループに属する要素をリストで返す
    return [i for i in range(self.n) if self.Find_Root(i)==self.Find_Root(x)]
  def Roots(self): # 全ての根の要素をリストで返す
    return [i for i, x in enumerate(self.root) if x < 0]
  def Group_Count(self): # グループの数を返す
    return len(self.Roots())

n, k, l = map(int, input().split())
uf_road = UnionFind(n)
uf_train = UnionFind(n)
connect = {}

for _ in range(k):
  p, q = map(lambda x:int(x)-1, input().split())
  uf_road.Unite(p, q)

for _ in range(l):
  r, s = map(lambda x:int(x)-1, input().split())
  uf_train.Unite(r, s)

for i in range(n):
  par1, par2 = uf_road.Find_Root(i), uf_train.Find_Root(i)
  if (par1, par2) in connect.keys():
    connect[(par1, par2)] += 1
  else:
    connect[(par1, par2)] = 1

ans = []
for i in range(n):
  par1, par2 = uf_road.Find_Root(i), uf_train.Find_Root(i)
  ans += [str(connect[(par1, par2)])]

print(" ".join(ans))


Measured memory_bytes: 52060
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;

char a[110], b[110];

int main()
{
	scanf("%s %s", a + 1, b + 1);
	int len1, len2, flag = -1;
	len1 = strlen(a+1);
	len2 = strlen(b+1);
	if(len1 < len2) cout << "LESS" << endl;
	else if(len1 > len2) cout << "GREATER" << endl;
	else{
		for(int i = 1;i <= len1;i++){
		if(a[i] > b[i]){
			flag = 1;
			break;
		}
		if(a[i] < b[i]){
			flag = 0;
			break;
		}
		}
		if(flag == 1) cout << "GREATER" << endl;
		if(flag == 0) cout << "LESS" << endl;
		if(flag ==-1) cout << "EQUAL" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
s = list(input())
l = []
for i in range(len(s)):
    j = i
    

    cnt = 0
    if s[i] in ["A",'C','G','T']:
        cnt +=1
        while j <= len(s)-2 :
            j = j + 1    
            if s[j] in ["A",'C','G','T']:
                cnt += 1
            else:
                break
    l.append(cnt)
print(max(l))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
#define ll long long
using namespace std;
int main(){
    ll x;
    cin>>x;
    ll ans=(x/500)*1000;
    x-=(x/500)*500;
    ans+=(x/5)*5;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

int main()
{
	IOS;
	int n;
	cin>>n;
	if(n==1) cout<<"Hello World\n";
	else{
		int a,b;
		cin>>a>>b;
		cout<<a+b<<'\n';
	}

	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {


    public static void solve() {
        String s = in.nextLine();
        String t = in.nextLine();

        int[][] store = new int[s.length()+1][t.length()+1];

        for(int i = 1; i <= s.length(); i += 1) {
            for(int j = 1; j <= t.length(); j += 1) {
                if(s.charAt(i-1) == t.charAt(j-1))
                    store[i][j] = 1 + store[i-1][j-1];
                else
                    store[i][j] = Math.max(store[i-1][j], store[i][j-1]);
            }
        }

        int length = store[s.length()][t.length()];
        char[] lcs = new char[length];

        int index = length-1;

        int i = s.length(), j = t.length();
        while (i > 0 && j > 0)
        {
            // If current character in X[] and Y are same, then
            // current character is part of LCS
            if (s.charAt(i-1) == t.charAt(j-1))
            {
                // Put current character in result
                lcs[index] = s.charAt(i-1);
                i -= 1;
                j -= 1;
                index -= 1;
            }
            else if (store[i-1][j] > store[i][j-1])
                i -= 1;
            else
                j -= 1;
        }



        out.println(lcs);
    }


    public static InputReader in = new InputReader();
    public static PrintWriter out;

    public static void main(String[] args) {
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }


    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader() {
            reader = new BufferedReader(new InputStreamReader(System.in));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        /**
         * When you call next(), that entire line will be skipped.
         * No flushing buffers.
         * Doesn't work when you want to scan the remaining line.
         *
         * @return entire line
         */
        public String nextLine() {
            String str = "";
            try {
                str = reader.readLine();
                tokenizer = null;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return str;
        }
    }
}

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

int B[500];

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int A[m];
    for(int i = 0; i < m; i++){
        cin >> A[i];
        B[A[i]]++;
    }
    int c1 = 0;
    int c2 = 0;
    for(int i = x; i <= n; i++){
        c1 += B[i];
        
    }
    for(int i = x; i >= 0; i--){
        c2 += B[i];
    }
    cout << min(c1, c2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 long long int gcd(long long int m,long long int n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
long long int lcm(long long int number1,long long int number2){
	return number1 * number2 / gcd(number1,number2);	

}

vector<int> date[100001];//vectorをグループ別に収録する場合int main()外に収録する必要あり？
int main(){
ll N,M;
  cin>>N>>M;
  
  vector<ll>P(M);
  vector<ll>Y(M);

  
  
  rep(i,M){
cin>>P[i]>>Y[i];
    
    date[P[i]].push_back(Y[i]);
  }

  rep(i,N){
sort(date[i+1].begin(),date[i+1].end());
    
  }
  
  
  rep(i,M){
    printf("%06d",P[i]);
    printf("%06d",lower_bound(all(date[P[i]]),Y[i])-date[P[i]].begin()+1);//グループのY[i]の位置からグループの先頭までの距離
      
      cout<<endl;
  
  
  }
  
}
  

Measured memory_bytes: 8576
N,K = map(int, input().split())
A = list(map(int, input().split()))
def f(X):
    res = 0
    for a in A:
        res += X ^ a
    return res

ans = max(f(0), f(K))
for d in range(60, 0, -1):
    if K & (1<<d) == 0:
        continue
    X = K &  ~((1<<d+1)-1)

    for j in range(d): 
        count_should_raise = 0
        mask = 1<<j
        for a in A:
            if a & mask == 0: count_should_raise += 1
        if count_should_raise > N//2:
            X |= 1<<j
    ans = max(ans, f(X))
print(ans)


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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VI a(n);
  int max1 = 0;
  int max2 = 0;
  int loc = -1;
  rep(i, n) {
    cin >> a[i];
    if(max1 <= a[i]){
      max2 = max(max1, max2);
      max1 = a[i];
      loc = i;
    }
    else max2 = max(max2, a[i]);
  }

  rep(i, n){
    if(i == loc){
      out(max2);
    }
    else out(max1);
  }

  return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  unordered_set<int> s;
  for (int i = 0; i < N; ++i) {
    int A;
    cin >> A;
    if (s.count(A)) s.erase(A);
    else s.insert(A);
  }
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define gt(n) scanf("%d", &n)
#define gtll(n) scanf("%ld", &n)
#define out(n) printf("%d", n)
#define outll(n) printf("%ld", n)
#define loop(n) for(int i=0; i<n; i++)
#define MAXX 1001
#define mem(x, y) memset(x, y, sizeof(x))
#define loop1(n) for(int i=1; i<=n; i++)
#define ll long long
#define pb push_back
#define pi acos(-1)
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//(only in c)char[33];itoa(n,buffer,base);printf("%s",buffer);
#define dec_to_bin(n) std::string binary = std::bitset<64>(n).to_string();
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int main()
{
fast;
string a,b;
cin>>a>>b;
int c=0;
for(int i=0;i<3;i++){
if(a[i]==b[i])c++;
}
cout<<c<<endl;
return 0;
}


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

int main() {
  string S,T,U;
  cin>>S>>T;
  int A,B;
  cin>>A>>B;
  cin>>U;
  if (U==S){
    A = A-1;
  }
  else{
    B=B-1;
  }
  cout << A << " "<< B << endl;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(Args&&... args) const { print(std::forward<Args>(args)...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(T&& head, Tail&&... tail) const { std::cout << head, print_rest(std::forward<Tail>(tail)...); }
        template <class T, class... Tail>
        void print_rest(T&& head, Tail&&... tail) const { std::cout << sep << head, print_rest(std::forward<Tail>(tail)...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
    template <class T>
    void print_vec(const std::vector<T>& vec, const char* sep = " ", const char* term = "\n") const {
        const size_t sz = vec.size();
        for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
    }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll N;
    cin >> N;
    vector<Pll> ans;
    if (N & 1) {
        for (ll i = 1; i <= N; i++) {
            for (ll j = i + 1; j <= N; j++) {
                if (i + j == N) continue;
                ans.emplace_back(i, j);
            }
        }
    }
    else {
        for (ll i = 1; i <= N; i++) {
            for (ll j = i + 1; j <= N; j++) {
                if (i + j == N + 1) continue;
                ans.emplace_back(i, j);
            }
        }
    }
    prints()(ans.size());
    for (auto [a, b] : ans) {
        prints()(a, b);
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

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

#define loop(i,n) for(int i=1;i<=n;i++)
int res[102];

int main(){
  int h,w;
  char p;
  cin>>h>>w;
  loop(i,h){
    res[0]=-1;
    loop(j,w){
      cin>>p;
      if(p=='c')res[j]=0;
      else if(res[j-1]==-1) res[j]=-1;
      else res[j]=res[j-1]+1;
      cout<<res[j];
      if(j!=w)cout<<" ";
      else cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 9 * 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<ll> R(N + 1);
    vector<ll> G(N + 1);
    vector<ll> B(N + 1);
    for(int i = N;i >= 1;i--) {
        if(S.at(i - 1) == 'R') {
            R.at(i - 1) = R.at(i) + 1;
        }
        else {
            R.at(i - 1) = R.at(i);
        }
    }
    for(int i = N;i >= 1;i--) {
        if(S.at(i - 1) == 'B') {
            B.at(i - 1) = B.at(i) + 1;
        }
        else {
            B.at(i - 1) = B.at(i);
        }
    }
    for(int i = N;i >= 1;i--) {
        if(S.at(i - 1) == 'G') {
            G.at(i - 1) = G.at(i) + 1;
        }
        else {
            G.at(i - 1) = G.at(i);
        }
    }
    ll ret = 0;
    for(int i = 0;i < N - 2;i++) {
        for(int j = i + 1;j < N - 1;j++) {
            if(S.at(i) != S.at(j)) {
                if((S.at(i) == 'G' && S.at(j) == 'B') || (S.at(i) == 'B' && S.at(j) == 'G')) {
                    if(j + j - i < N && S.at(j + j - i) == 'R') {
                        ret += R.at(j) - 1;
                    }
                    else {
                        ret += R.at(j);
                    }
                }
                if((S.at(i) == 'R' && S.at(j) == 'B') || (S.at(i) == 'B' && S.at(j) == 'R')) {
                    if(j + j - i < N && S.at(j + j - i) == 'G') {
                        ret += G.at(j) - 1;
                    }
                    else {
                        ret += G.at(j);
                    }
                }
                if((S.at(i) == 'R' && S.at(j) == 'G') || (S.at(i) == 'G' && S.at(j) == 'R')) {
                    if(j + j - i < N && S.at(j + j - i) == 'B') {
                        ret += B.at(j) - 1;
                    }
                    else {
                        ret += B.at(j);
                    }
                }
            }
        }
    }
    cout << ret << endl;
}

Measured memory_bytes: 3696
from collections import deque
import sys

N = int(input())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))

isEssentials = [False] * 51
for k in reversed(range(1, 52)):
    adjL = [set() for _ in range(51)]
    for v in range(1, 51):
        for t in range(1, v+1):
            if t < k or isEssentials[t]:
                adjL[v].add(v%t)
        adjL[v] = list(adjL[v])

    for A, B in zip(As, Bs):
        isOK = False
        useds = [False] * 51
        Q = deque([A])
        while Q:
            vNow = Q.popleft()
            if vNow == B:
                isOK = True
                break
            useds[vNow] = True
            for v2 in adjL[vNow]:
                if not useds[v2]:
                    Q.append(v2)
        if not isOK:
            if k == 51:
                print(-1)
                sys.exit()
            isEssentials[k] = True
            break

ans = sum([2**k for k in range(1, 51) if isEssentials[k]])
print(ans)


Measured memory_bytes: 3316
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		new Main();
	}

	public Main() {
		while(sc.hasNext()){
			new aoj0039().doIt();
		}
	}

	class aoj0039 {
		char num[] = {'M','D','C','L','X','V','I'};
		int num2[] = {1000,500,100,50,10,5,1};
		int result = 0;
		int mainas(char nnum1,char nnum2){
			int result2 = 0;
			for(int i = 0;i < num.length;i++){
				if(nnum1 == num[i])result2 = result2 + i;
				if(nnum2 == num[i])result2 = result2 - i;
			}
			return result2;
		}
		int cnt(char[] nnum,int length){
			if(length == 1){
				for(int i = 0;i < num.length;i++){
					if(nnum[0] == num[i])result = result + num2[i];
				}
			}else if(length > 1){
				for(int i = 0;i < num.length;i++){
					if(nnum[0] == num[i]){
						if(num[i] != num[0] && mainas(nnum[0],nnum[1]) > 0){
							result = result + num2[i - mainas(nnum[0],nnum[1])] - num2[i];
							for(int j = 0;j < nnum.length - 2;j++)nnum[j] = nnum[j+2];
							length = length - 2;
							cnt(nnum,length);
							break;
						}else{
							result = result + num2[i];
							for(int j = 0;j < nnum.length - 1;j++)nnum[j] = nnum[j+1];
							length = length - 1;
							cnt(nnum,length);
							break;
						}
					}
				}
			}
			return result;
		}
		void doIt() {
			String n = sc.next();
			char nnum[] = n.toCharArray();
			result = 0;
			System.out.println(cnt(nnum,nnum.length));
		}
	}
}

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

using namespace std;

int main(void)
{
    int N, M, X;
    int C[12];
    int A[12][12];
    cin >> N >> M >> X;
    for(int i = 0; i < N; i++){
        cin >> C[i];
        for(int j = 0; j < M; j++){
            cin >> A[i][j];
        }
    }
    int ans = 1234567890;
    int max = 1 << N;
    for(int bitmap = 0; bitmap < max; bitmap++){
        int cost = 0;
        int a[12] = {0};
        for(int i = 0; i < N; i++){
            if((bitmap >> i)&1){
                cost+=C[i];
                for(int j = 0; j < M; j++){
                    a[j] += A[i][j];
                }
            }
        }
        bool ok = true;
        for(int i = 0; i < M; i++){
            if(a[i] < X){
                ok = false;
                break;
            }
        }
        if(ok)  ans = min(ans, cost);
    }
    if(ans == 1234567890) ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3556