akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

const int MAX_N = 100005;
 
int parent[MAX_N];
int ran[MAX_N];
 
void init(int n){
    int i;
    rep(i,n){
        parent[i]=i;
        ran[i]=0;
    }
}
 
int find(int x){
    if(parent[x]==x)return x;
    else return parent[x]=find(parent[x]);
}
 
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
 
    if(ran[x]<ran[y])
        parent[x]=y;
    else{
        parent[y]=x;
        if(ran[x]==ran[y])ran[x]++;
    }
}
 
struct edge{ int u,v,cost;};
 
bool comp(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;
}
 
edge es[2*MAX_N];
int v,e=0;
 
int kruskal(){
    sort(es,es+e,comp);
    init(v);
    int res=0,i;
    rep(i,e){
        edge e=es[i];
        if(find(e.u) != find(e.v)){
            unite(e.u,e.v);
            res+=e.cost;
        }
    }
    return res;
}

int main(){
  int n; cin >> n;
  v = n;
  
  vector<tuple<int,int,int>> p(n);
  rep(i,n){
    int x,y; cin >> x >> y;
    p[i] = make_tuple(x,y,i);
  }
  
  sort(p.begin(),p.end());
  
  rep(i,n-1){
    int x1,y1,num1; tie(x1,y1,num1) = p[i];
    int x2,y2,num2; tie(x2,y2,num2) = p[i+1];
    es[e].u = num1;
    es[e].v = num2;
    es[e].cost = x2 - x1;
    e++;
  }
  
  rep(i,n){
    int x,y,num; tie(x,y,num) = p[i];
    p[i] = make_tuple(y,x,num);
  }
  sort(p.begin(),p.end());
  
  rep(i,n-1){
    int y1,x1,num1; tie(y1,x1,num1) = p[i];
    int y2,x2,num2; tie(y2,x2,num2) = p[i+1];
    es[e].u = num1;
    es[e].v = num2;
    es[e].cost = y2 - y1;
    e++;
  }
  
  cout << kruskal() << endl;
  
  return 0;
}

Measured memory_bytes: 4480
#include<iostream>
using namespace std;
int main()
{
	int n,k,i;
	scanf("%d%d\n",&n,&k);
	char c[n];
	for(i=1;i<=n;i++)
	c[i]=getchar();
	c[k]=c[k]+32;
	for(i=1;i<=n;i++)
	printf("%c",c[i]);
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(a, max(b, c))
#define MIN(x, y, z) min(a, min(b, c))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  string A, B;
  cin >> A >> B;

  REVERSE(B);
  if (A == B) {
    COUT("YES");
  } else {
    COUT("NO");
  }

  return 0;
}

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

int main(int argc, char** argv){
  int s;
  cin >> s;
  
  int MAX_NUM = 1e6;
  vector<int> v;
  v.push_back(s);
  
  int ans;
  for(int cnt0=0; cnt0 < MAX_NUM + 1; cnt0++){
    if(s%2 == 0) s /= 2;
    else s = 3*s + 1;
//    cout << "s at cnt[" << cnt0 << "]: " << s << endl;
    if(find(v.begin(), v.end(), s) != v.end()) {
      ans = cnt0;
      break;
    }
    v.push_back(s);
  }
  printf("%d", ans+2);
  return 0;
  
  
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647;
const LL mod = 1000000007ll;
 
int N;
 
int ans = 0;
 
void solve(){
	ans = (N+N%2)/2;
}
 
int main(){
	cin >> N;
 
	solve();
 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
#define INF 0x3f3f3f3f
#define ll long long
#define pi acos(-1.0)
int a[110000];
int sum[110000];
int temp[110000];
LL t1 = 0 ,t2 = 0;
int n;
void MergeSort(int l,int r){
//	puts("ca");
	if (l == r)return ;
	int mid = (l+r)>>1;
	MergeSort(l,mid);
	MergeSort(mid+1,r);
	int p = l, q = mid + 1,k = l;
	while(p <= mid && q <= r){
		if(sum[p] < sum[q]){
			temp[k++] = sum[p++];
		}else{
			t1 += (p-l);
			temp[k++] = sum[q++];
		}
	}
	while(p <= mid){
		temp[k++] = sum[p++];
	}
	while(q <= r){
		t1 += (p-l);
		temp[k++] = sum[q++];
	}
	for(int i = l ; i <= r ; i++){
		sum[i] = temp[i];
	}
}
bool Check(int x){
	t1 = 0;
	for(int i = 1 ; i <= n ; i++){
		if(a[i] <= x){
			sum[i] = 1;
		}else{
			sum[i] = -1;
		}
	}
	for(int i = 1 ; i <= n ; i++){
		sum[i] += sum[i-1];
	}
	MergeSort(0,n);
	return t1 >= (t2/2+1);
}
int main(){
	int L = 1100000000,R = -1100000000;
	scanf("%d",&n);
	for(int i = 1 ; i <= n ; i++){
		scanf("%d",&a[i]);
		L = min(L,a[i]);
		R = max(R,a[i]);
		t2 += i;
	}//t2存总的区间个数
	while(L < R){
		int mid = (L+R)>>1;
		if(Check(mid))R = mid ;
		else L = mid + 1;
	}
	printf("%d\n",L);
}
/*
10
5 9 5 9 8 9 3 5 4 3
3
10 30 20
*/

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

using namespace std;

const int md = 1e9 + 7;

inline void add(int &x, int y) {
  x += y;
  if (x >= md) {
    x -= md;
  }
}

inline int mul(int x, int y) {
  return (long long) x * y % md;
}

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  int n;
  scanf("%d", &n);
  vector<bool> used(n * 2);
  vector<bool> single(n * 2);
  int free = 0;
  for (int i = 0; i < n; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (~x) {
      --x;
    }
    if (~y) {
      --y;
    }
    if (~max(x, y)) {
      if (~min(x, y)) {
        used[x] = used[y] = true;
      } else {
        single[max(x, y)] = true;
      }
    } else {
      ++free;
    }
  }
  vector<vector<int>> dp(n + 1, vector<int> (n * 2 + 1));
  dp[0][0] = 1;
  for (int i = n * 2 - 1; ~i; --i) {
    if (!used[i]) {
      vector<vector<int>> new_dp(n + 1, vector<int> (n * 2 + 1));
      for (int j = 0; j <= n; ++j) {
        for (int k = 0; k <= n * 2; ++k) {
          if (dp[j][k]) {
            if (single[i]) {
              add(new_dp[j + 1][k], dp[j][k]);
              if (k) {
                add(new_dp[j][k - 1], dp[j][k]);
              }
            } else {
              add(new_dp[j][k + 1], dp[j][k]);
              if (j) {
                add(new_dp[j - 1][k], mul(j, dp[j][k]));
              }
              if (k) {
                add(new_dp[j][k - 1], dp[j][k]);
              }
            }
          }
        }
      }
      swap(dp, new_dp);
    }
  }
  int answer = dp[0][0];
  for (int i = 1; i <= free; ++i) {
    answer = mul(answer, i);
  }
  printf("%d\n", answer);
  return 0;
}


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

int main(){
    int a[5];
    for(int i=0;i<5;i++){
        cin>>a[i];
    }
    int k;
    cin>>k;
    int min=9999;
    int max=0;
    for(int i=0;i<5;i++){
        if(a[i]<min)min=a[i];
        if(a[i]>max)max=a[i];
    }
    if((max-min)>k)cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby
from heapq import heapify, heappush, heappop
 
# sys.setrecursionlimit(5000)
 
n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]
 
def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return map(lambda x: x + d, A)
def ldec(A, d=1): return map(lambda x: x - d, A)
 
H, W = nn()
Ch, Cw = nn()
Dh, Dw = nn()
S = sm(H)
 
T = [u"#"*(W+4)] * 2
for s in S:
    T.append("##" + s[0] + "##")
T += [u"#"*(W+4)] * 2
 
H += 4
W += 4
Ch += 2 - 1
Cw += 2 - 1
Dh += 2 - 1
Dw += 2 - 1
 
deq1 = deque()
deq1.append((Ch, Cw))
deq2 = deque()
 
cnt = 0
 
memo = array2(H, W, 10**6)
memo[Ch][Cw] = 0
 
memo2 = deque()

for i in range(10**6):
    #pprint(T)
    #pprint(memo)
    #print("-"*30 + "\n")
 
    if len(deq1) == 0:
        print(-1)
        exit(0)
 
    while len(deq1) > 0:
        h, w = deq1.pop()
        memo2.append((h, w))

        if h == Dh and w == Dw:
            print(i)
            exit(0)
 
        def sch(x, y, i):
            #print(x, y, T[x][y])
            if T[x][y] == "." and i < memo[x][y]:
                memo[x][y] = i
                deq1.append((x, y))
 
        sch(h+1, w, i)
        sch(h-1, w, i)
        sch(h, w+1, i)
        sch(h, w-1, i)
 
    #for j in range(H):
    #    for k in range(W):
    while len(memo2) > 0:
        j, k = memo2.pop()
        if memo[j][k] == i:
            for l in range(-2, 3):
                for m in range(-2, 3):
                    if T[j+l][k+m] == "." and i + 1 < memo[j+l][k+m]:
                        memo[j+l][k+m] = i + 1
                        deq2.append((j+l, k+m))
 
    deq1 = deq2
    deq2 = deque()
    memo2 = deque()

Measured memory_bytes: 97292
using System;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());

        string[] input = Console.ReadLine().Split(' ');
        int[] V = new int[N];
        for(int i = 0; i < input.Length; i++)
        {
            V[i] = int.Parse(input[i]);
        }
        input = Console.ReadLine().Split(' ');
        int[] C = new int[N];
        for (int i = 0; i < input.Length; i++)
        {
            C[i] = int.Parse(input[i]);
        }
        int[] Ans = new int[N];
        for(int i = 0; i < N; i++)
        {
            Ans[i] = V[i] - C[i];
        }
        Array.Sort(Ans);
        int sum = 0;
        for (int i = N - 1; i >= 0; i--)
        {
            if (Ans[i] > 0)
                sum += Ans[i];
            else
                break;
        }
        Console.WriteLine(sum);
    }
}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  int64_t k;
  cin>>s>>k;
  int r=0;
  char x='1';
  for(int i=0;i<s.size();i++){
    if(s.at(i)!='1'){
      x=s.at(i);
      break;
    }
    r++;
  }
  cout<<(r<k?x:'1')<<endl;
}

Measured memory_bytes: 3624
// AOJ 2161 Defend the Bases
// 2018.3.9 bal4u

#include <stdio.h>
#include <string.h>
#include <math.h>

#define MAX 210
int  hi[MAX], to[MAX][MAX];
char seen[MAX];
int  match[MAX];

int bpm(int u);
int bipartiteMatching(int m, int n, int V)
{
	int u, max;

	memset(match, -1, V*sizeof(int));
	max = 0;
	for (u = 0; u < m; u++) {
		memset(seen, 0, V);
		if (bpm(u)) max++;
	}
	return max;
}

int bpm(int u)
{
	int i, v;

	for (i = 0; i < hi[u]; i++) {
		v = to[u][i];
		if (seen[v]) continue;
		seen[v] = 1;
		if (match[v] < 0 || bpm(match[v])) {
			match[u] = v, match[v] = u;
			return 1;
		}
	}
	return 0;
}

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

#define LIM 100
#define EPS 1e-8

typedef struct { int from, to; double d; } EDGE;
EDGE edge[10010], *tail;
typedef struct { int x, y, v; } TROOP;
TROOP troop[102];
typedef struct { int x, y; } BASE;
BASE  base[102];
int   N, M, V;

double dist(int t, int b) {	return hypot(troop[t].x-base[b].x, troop[t].y-base[b].y); }

int check(double md)
{
	EDGE *e;

	memset(hi, 0, V << 2);
	for (e = edge; e < tail; e++) {
		if (e->d < md+EPS) to[e->from][hi[e->from]++] = e->to;
	}
	return bipartiteMatching(N, M, V) == M;
}

int main()
{
	int i, j, lim;
	double lb, ub, md;
	EDGE *e;

	while (N = in()) {
		M = in(), V = N+M;
		for (i = 0; i < N; i++) troop[i].x = in(), troop[i].y = in(), troop[i].v = in();
		for (i = 0; i < M; i++) base[i].x = in(), base[i].y = in();

		e = edge; for (i = 0; i < N; i++) for (j = 0; j < M; j++) {
			e->from = i, e->to = N+j, e->d = dist(i, j) / troop[i].v, e++;
		}
		tail = e;

		lb = 0, ub = 15000;
		lim = LIM; while (lim--) {
			md = 0.5*(lb+ub);
			if (check(md)) ub = md; else lb = md;
		}
		printf("%.20lf\n", ub);
	}
	return 0;
}


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

int arr[200003] , N;

int main(){
	cin >> N;
	for(int i = 1 ; i <= N ; ++i) cin >> arr[i];
	if(arr[1] != 0){puts("-1"); return 0;}
	long long ans = 0; int pos = 1;
	for(int i = 2 ; i <= N ; ++i){
		if(arr[i] > i - pos){puts("-1"); return 0;}
		ans += arr[i] == arr[i - 1] + 1 ? 1 : arr[i];
		pos = max(pos , i - arr[i]);
	}
	cout << ans; return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))

color = [False for _ in range(8)]
x = 0
for a in A:
    if a >= 3200:
        x += 1
    else:
        tmp = a // 400
        color[tmp] = True

ans = color.count(True)
if ans == 0:
    print(1, ans + x)
else:
    print(ans, ans + x)

Measured memory_bytes: 3064
import java.util.Scanner;
 
public class Main {
    static int scoreR;
    static int scoreS;
    static int scoreP;
	public static void main(String[] args) {
        try (Scanner scn = new Scanner(System.in)) {
            int h = scn.nextInt();
            int n = scn.nextInt();
            scn.nextLine();
            for(int i=0; i<n; i++){
                h = h-scn.nextInt();
            }
            String ret = h > 0 ? "No":"Yes";
            System.out.println(ret);
        }
	}
	
}


Measured memory_bytes: 47524
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		if(c>=a && c<=b) System.out.println("Yes");
		else System.out.println("No");
	}

}


Measured memory_bytes: 27068
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;
const int MOD = 1000000007;
const ll INF = 1LL << 60;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<vector<ll> > dp;
vector<vector<vector<int> > > vvvi;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


int main(int argc, char**argv){
    int n, w;
    cin >> n >> w;
    vector<ll> weight(n), value(n);
    for (int i = 0; i < n; i++){
        cin >> weight[i] >> value[i];
    }

    dp = vector<vector<ll> >(n+1, vector<ll>(w+1, 0));
    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= w; j++){
            if (j - weight[i-1] >= 0){
                chmax(dp[i][j], dp[i-1][j - weight[i-1]] + value[i-1]);
            }
            chmax(dp[i][j], dp[i-1][j]);
        }
    }
    cout << dp[n][w] << endl;

    return 0;
}


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

#define all(v) (v).begin(), (v).end()
typedef long long LL;

using namespace std;

void read_and_sort(vector <LL> &A, int n)
{
    A[0] = 1e15;

    for(int i = 1; i <= n; i++)
        cin >> A[i];

    sort(all(A), greater <LL>());
}

int main()
{
    int no_of_1_candles, no_of_2_candles, no_of_3_candles, no_of_chosen_cakes;
    cin >> no_of_1_candles >> no_of_2_candles >> no_of_3_candles >> no_of_chosen_cakes;

    vector <LL> cake_1(no_of_1_candles + 1, 0);
    read_and_sort(cake_1, no_of_1_candles);

    vector <LL> cake_2(no_of_2_candles + 1, 0);
    read_and_sort(cake_2, no_of_2_candles);

    vector <LL> cake_3(no_of_3_candles + 1, 0);
    read_and_sort(cake_3, no_of_3_candles);

    vector <LL> chosen_cakes;
    for(int i = 1; i <= no_of_1_candles; i++)
    {
        for(int j = 1; j <= no_of_2_candles; j++)
        {
            for(int k = 1; k <= no_of_3_candles; k++)
            {
                if(i*j*k > no_of_chosen_cakes)
                    break;

                chosen_cakes.push_back(cake_1[i] + cake_2[j] + cake_3[k]);
            }
        }
    }

    sort(all(chosen_cakes), greater <LL>());

    for(int i = 0; i < no_of_chosen_cakes; i++)
        cout << chosen_cakes[i] << "\n";

    return 0;
}


Measured memory_bytes: 1404
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>

#define REP(i, s, e) for (ll i = s; i < e; ++i)

using namespace std;
using ll = long long;
using ld = long double;

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

    ll N;
    cin >> N;

    if (N % 2 == 0)
    {
        cout << N << endl;
    }
    else
    {
        cout << N * 2 << endl;
    }

    return 0;
}


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

using namespace std;

void sign(int, int);

char maze[101][101];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int h, w, ans;
char flag;

int main() {
    while(3) {
        ans=0;
        cin>>h>>w;
        if (h == 0 && w == 0)
            break;
        for (int i = 0; i < h; i++)
            for (int t = 0; t < w; t++){
                cin>>maze[i][t];
            }
        for (int i = 0; i < h; i++)
            for (int t = 0; t < w; t++) {
                if (maze[i][t] != ' ') {
                    flag = maze[i][t];
                    sign(i, t);
                    ans++;
                }
            }
        cout << ans << endl;
    }
    return 0;
}

void sign(int a, int b) {
    maze[a][b] = ' ';
    for (int i = 0; i < 4; i++) {
        int x = a + dx[i];
        int y = b + dy[i];
        if (x >= 0 && x < h && y >= 0 && y < w && maze[x][y] == flag)
            sign(x, y);
    }
}


Measured memory_bytes: 3400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();
			System.out.println((a + b >= c) ? "Yes" : "No");
		}
	}
}


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

signed main(){
  string S;
  cin>>S;
  int SS=S.size();
  cout<<S[0]<<(SS-2)<<S[SS-1]<<endl;
  return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin >> b>> a;
    vector<int> l(b);
    for (int i = 0; i < b; i++) {
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int c = 0;
    for (int i = 0; i < a; i++) {
        c+= l[i];
    }
    cout << c;
}


Measured memory_bytes: 3628
n = int(input())
d = []
for i in range(n):
    x = list(map(int, input().split()))
    d.append(x)

d2 = []
ans = "No"

for i in range(n):
    if d[i][0] == d[i][1]:
        d2.append(1)
    else:
        d2.append(0)

for i in range(0, n-2):
    if d2[i] == 1 and d2[i+1] == 1 and d2[i+2] == 1:
        ans = "Yes"
        break

print(ans)

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>

using namespace std;
typedef long long li;

const li dp_size = 1000 * 105;

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

    li n, capacity;
    cin >> n >> capacity;

    vector<li> weights(n), values(n);

    for (int i = 0; i < n; ++i) {
        cin >> weights[i] >> values[i];
    }

    vector<li> dp(dp_size, 1LL << 50);
    dp[0] = 0;
    
    for (int item = 0; item < n; ++item) {
        vector<li> newdp = dp;

        for (int v = 0; v < dp_size; ++v) {
            li new_v = v + values[item];
            if (new_v >= dp_size) {
                continue;
            }
            newdp[new_v] = min(newdp[new_v], dp[v] + weights[item]);
        }
        
        dp = newdp;
    }

    li ans = 0;
    for (li i = 0; i < dp.size(); ++i) {
        if (dp[i] <= capacity) {
            ans = max(ans, i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        int N;cin>>N;
        int cnt=0;
        while(N>=10){
            string S=to_string(N);
            int maxi=0;
            for(int i=1;i<S.size();i++){
                int A=stoi(S.substr(0,i)),B=stoi(S.substr(i,int(S.size())-i));
                maxi=max(maxi,A*B);
            }
            N=maxi;
            cnt++;
        }
        
        cout<<cnt<<endl;
    }
}



Measured memory_bytes: 3292
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int[] x = new int[3000];
		int[] y = new int[3000];
		int tmp;
		for(int i=0;i<3000;i++){
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			if(x[i] == 0 && y[i] == 0) break;
			if(x[i] > y[i]){
				tmp=x[i];
				x[i]=y[i];
				y[i]=tmp;
			}
			System.out.println(x[i]+" "+y[i]);
		}
	}
}

Measured memory_bytes: 35500
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#include<queue>
#include<functional>
#include<stack>
#include<bitset>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 10;
int n, m;
struct node {
	int v, next;
}e[MAXN << 1];
int tot;
int head[MAXN];
void init() {
	memset(head, -1, sizeof head);
	tot = 0;
}
void add(int u, int v) {
	e[tot].v = v; e[tot].next = head[u]; head[u] = tot++;
}
int main() {
	while (cin >> n >> m) {
		init();
		for (int i = 1; i <= m; ++i) {
			int ai, bi;
			cin >> ai >> bi;
			add(ai, bi);
		}
		bool ff = false;
		for (int i = head[1]; i != -1&&!ff; i = e[i].next) {
			int u = e[i].v;
			for (int j = head[u]; j != -1&&!ff; j = e[j].next) {
				int v = e[j].v;
				if (v == n) {
					ff = true;
					break;
				}
			}
		}
		if (ff)cout << "POSSIBLE" << endl;
		else cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 2560
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    n, m = LI()
    print((n-1)*(m-1))
    return

#B
def B():
    s = S()
    print(s[0]+str(len(s)-2)+s[-1])
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 3700
using System;

class MainClass
{
	public static void Main (string[] args)
	{
		string str = Console.ReadLine ();
		string[]spStr = str.Split(' ');

		int w = int.Parse (spStr[0]);
		int h = int.Parse (spStr[1]);
		int x = int.Parse (spStr[2]);
		int y = int.Parse (spStr[3]);
		int r = int.Parse (spStr[4]);

		if (w >= (x + r) && 0 <= (x - r) && h >= (y + r) && 0 <= (y - r))
		{
			Console.WriteLine ("Yes");
		}
		else
		{
			Console.WriteLine ("No");
		}
	}
}

Measured memory_bytes: 9008
n, m, x = map(int, input().split())
BOOKS = [tuple(map(int, input().split())) for _ in range(n)]

ans = float("inf")
for i in range(2**n):
    tmp = 0
    A = [0] * m
    for j in range(n):
        if i & 2**j:
            tmp += BOOKS[j][0]
            for k in range(m):
                A[k] += BOOKS[j][k + 1]
    flag = True
    for a in A:
        if a < x:
            flag = False
    if flag:
        ans = min(ans, tmp)

print(-1 if ans == float("inf") else ans)


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

//Function Macros:
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type Definitions:
typedef long long ll;
typedef unsigned long long ull;

//Constants:
const int INF = 2e9;
const int MOD = 1e9 + 7;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);

//================ Main Loop ================
int main()
{
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(Q), score(N);
    rep(i, N)
    {
        score[i] = K - Q;
    }

    rep(i, Q)
    {
        cin >> A[i];
        score[A[i] - 1]++;
    }

    rep(i, N)
    {
        if (score[i] > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }

    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

Measured memory_bytes: 1408
/**
*    author:  souzai32
*    created: 01.08.2020 23:22:01
**/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {   

    int n,m;
    cin >> n >> m;
    vector<tuple<int,int>> con(m);
    int s,c;
    rep(i,m){
        cin >> s >> c;
        con.at(i)=make_tuple(s,c);
    }
    sort(con.begin(),con.end());

    vector<int> num(4,-1);
    bool a=true;
    int ans=0;

    rep(i,m){
        if(num.at(get<0>(con.at(i)))!=-1 && num.at(get<0>(con.at(i)))!=get<1>(con.at(i))) a=false;
        if(get<0>(con.at(i))==1&&get<1>(con.at(i))==0&&n!=1) a=false;
        num.at(get<0>(con.at(i)))=get<1>(con.at(i));
    }

    int t=1;
    rep(i,n) t*=10;

    if(a){
        for(int i=1; i<=n; i++){
            t/=10;
            if(num.at(i)==-1){
                if(i==1 && n!=1) num.at(i)=1;
                else num.at(i)=0;
            }
            ans+=num.at(i)*t;
        }
        cout << ans << endl;
    }
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3636
a,b,h,m=gets.split.map(&:to_f)
htheta=30*h+m/2
mtheta=6*m
theta=[(htheta-mtheta).abs,360-(htheta-mtheta).abs].min*Math::PI/180
puts (a**2+b**2-2*a*b*Math.cos(theta))**0.5


Measured memory_bytes: 14916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
    string S, T;
    cin >> S >> T;
    int ans = T.size();
    for (int i = 0; i+T.size() <= S.size(); i++) {
        int a = 0;
        for (int j = 0; j < T.size(); j++) {
            if (S[i+j] != T[j]) {
                a++;
            }
        }
        ans = min(a, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

string a(string t){
  string s = t;
  REP(i,10)REP2(j,i+1,10){
   if(s[i] > s[j]) swap(s[i],s[j]);
  }
  return s;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N; cin >> N;
  string s;
  unordered_map<string,ll> mp;
  REP(i,N){
    cin >> s;
    s = a(s);
    mp[s]++;
  }
  ll ans = 0;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
    ans += itr->second*(itr->second-1)/2;
  }
   cout << ans;

  return 0;
}

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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

LL a[110];

int main()
{
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

    LL n;
    cin >> n;

    for(LL i = 1; i <= n; i++){
        LL cnt = 0, N = i;
        while(N % 2 == 0)
            N /= 2, cnt++;
        a[i] = cnt;
    }

    LL ans, mx = 0;
    for(LL i = 1; i <= n; i++){
        if(mx <= a[i])
            mx = a[i], ans = i;
    }

    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
const int maxn=1e5+10,mod=1e9+7,inf=0x3f3f3f3f;
typedef long long ll;
using namespace std;
int n,m,k,t;
int id(int x,int y){return (x-1)*m+y;}
char a[30][30];
int f[410][410];
int main()
{
    int i,j;
    //freopen("in.txt","r",stdin);
    memset(f,inf,sizeof(f));
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {
        scanf("%s",a[i]+1);
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(a[i][j]=='.')
            {
                if(i+1<=n&&a[i+1][j]=='.')
                {
                    f[id(i,j)][id(i+1,j)]=1;
                    f[id(i+1,j)][id(i,j)]=1;
                }
                if(j+1<=m&&a[i][j+1]=='.')
                {
                    f[id(i,j)][id(i,j+1)]=1;
                    f[id(i,j+1)][id(i,j)]=1;
                }
            }
        }
    }
    for(i=1;i<=n*m;i++)
    {
        for(j=1;j<=n*m;j++)
        {
            for(k=1;k<=n*m;k++)
            {
                if(i==j||j==k||j==k)continue;
                f[j][k]=min(f[j][k],f[j][i]+f[i][k]);
            }
        }
    }
    int ma=-1;
    for(i=1;i<=n*m;i++)
        for(j=1;j<=n*m;j++)
            if(f[i][j]!=inf)ma=max(ma,f[i][j]);
    printf("%d\n",ma);
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h,w;
	cin>>h>>w;
	int n;
	cin>>n;
	int a[n];
	int arr[h][w];
	for(int i=0;i<n;i++)
		cin>>a[i];
	int k=0;
	for(int i=0;i<n;i++)
	{
		
		for(int j=0;j<a[i];j++)
		{
			int r = k/w;
			int c = k%w;
			if(r%2!=0)
				c=w-c-1;
			arr[r][c]=(i+1);
			//cout<<r<<" "<<c<<"\n";
			k++;
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
			cout<<arr[i][j]<<" ";
		cout<<"\n";
	}



}

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

int linearSearch(int a[], int n, int x) {
  for (int i = 0; i < n; i++) {
    if (a[i] == x) {
      return i;
    }
  }
  return -1;
}

const int MAX = 10005;

int n, q;
int S[MAX];
int T[MAX];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> S[i];
  cin >> q;
  for (int i = 0; i < q; i++) cin >> T[i];

  int ans {0};
  for (int i = 0; i < q; i++) {
    if (linearSearch(S, n, T[i]) != -1) {
      ans++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3144
#include <stdio.h>

int main(){
  double x,min=10000,max=0;
  while (scanf("%lf",&x)!=EOF){
    if (min>x){
      min=x;
    }
    if (max<x){
      max=x;
    }
  }
  printf("%lf\n",max-min);
  return 0;
}

Measured memory_bytes: 648
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>
#include <string>
#include <valarray>
#include <queue>
#include <utility>
#include <functional>
#include <list>


using namespace std;

const double ESP = 1E-8;

struct Point
{
    //friends
    friend Point operator*(double c, const Point & p);
    friend ostream & operator<<(ostream & os, const Point & p);
    friend istream & operator>>(istream & is, Point & p);
    friend double cross(const Point & p1, const Point & p2);

  
    //data members
    double x, y;

    //function members
    Point() {};
    Point(double x, double y): x(x), y(y) {};
    Point operator-(const Point & p) const {return Point(x - p.x, y - p.y);}
    double operator*(const Point & p) const {return x*p.x + y*p.y;}
    Point operator*(double c) const {return Point(c*x, c*y);}
    Point operator+(const Point & p) const {return Point(x+p.x, y+p.y);}
    Point projection(const Point & p1, const Point & p2) const {Point a(*this-p1), b(p2-p1); return (a*b)/(b*b)*b+p1;}
    Point reflection(const Point & p1, const Point & p2) const {return this->projection(p1, p2)*2 - *this;}

};


struct Line
{
    Line() = default;
    Line(const Point & p1, const Point & p2): 
        direction(p1-p2), point_online(p1) {}; 
    Point direction, point_online;
    Point get_normal() const {return Point(direction.y, -direction.x);}

};


class Polygon
{
    friend istream & operator>>(istream & is, Polygon & p);

    public:
        double area();
        
    private:
        vector<Point> Vertices;
};



int main()
{
    Polygon polygon;
    cin >> polygon;
    cout << fixed << setprecision(1) << polygon.area() << endl;
}



//function members and friend functions of Point
Point operator*(double c, const Point & p)
{
    return p*c;
}

ostream & operator<<(ostream & os, const Point & p) 
{
    os << setprecision(8) << fixed << p.x << ' ' << p.y << endl;
    return os;
}

istream & operator>>(istream & is, Point & p)
{
    is >> p.x >> p.y;
    return is;
}

double cross(const Point & p1, const Point & p2)
{
    return p1.x*p2.y-p1.y*p2.x;
}




//function members and friend functions of Polygon
istream & operator>>(istream & is, Polygon & p)
{
    int q;
    is >> q;
    
    p.Vertices.resize(q);
    for (int i = 0; i < q; ++i)
    {
        cin >> p.Vertices[i];
    }

    return is;
}

double Polygon::area()
{
    double a = 0;
    for (int i = 0; i < Vertices.size(); ++i)
    {
        a += cross(Vertices[i], Vertices[(i+1)%Vertices.size()]);
    }

    return fabs(a/2);
}


Measured memory_bytes: 3296
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c=Math.max(a,b);
    long d=Math.min(a,b);
    if(d==1){
      if(c==1){
        System.out.println(1);
      }else{
        System.out.println(a*b-2);
      }
    }else{
      System.out.println(a*b-(c+d-2)*2);
    }
  }
}

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

int main(){
  char str[1500];
  char temp;
  int count,i;
  
  scanf("%s",str);
  temp = str[0];
  //printf("%c\n",temp);
  count = 0;
  for(i=1;i<=strlen(str);i++){
    //printf("%c\n",temp);
  	if(temp == str[i]){
      count++;
    //printf("%c %d\n",temp,count);
    }
    else{
      count = 0;
      temp = str[i];
    }
    if(count >=2) break;
  }
  if(temp >= 2) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef pair<Int,Int> Pl;
constexpr int mod = 1e9+7;
constexpr int INF32 = numeric_limits<int>::max();
constexpr Int INF64 = numeric_limits<Int>::max();
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rer(i,l,r) for(int(i)=(l); (i)<(r); ++(i))
#define rep(i,n) rer(i,0,n)
#define gnr(i,l,r) for(int (i)=(r)-1; (i)>=(l); --(i))
#define pri(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(i,n-1)cout<<a[i]<<' '; if(n)cout<<a[n-1]<<'\n';}
#define prip(p) cout<<(p).fi<<' '<<(p).se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

Int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

int main(){
  cin.tie(nullptr); ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);

  cin>>n>>m;
  if(n+m==15)pri('+');
  else if(n*m==15)pri('*');
  else pri('x');
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n;
	cin >> n;
	if (n == 1)
	{
		cout << "Hello World" << endl;
	}
	else
	{
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int ans = 0;
    for(int i = 0; i < m; i++){
        int a;
        cin >> a;
        if(m < a && a <= n)ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3108
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


a,b = map(int, input().split())
ab = str(a)*b
ba = str(b)*a
if ab<ba:
    ans = ab
else:
    ans = ba
print(ans)

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

int n, m, k, a[505][505], b[505][505];
char s[3][3]; 

int main()
{
	scanf("%d%d%d", &n, &m, &k);
	s[0][0] = 'R', s[1][0] = 'G', s[0][1] = 'Y', s[1][1] = 'B';
	for(int op = 0, cnt = 0, i = -m - 1; i <= n; i++, cnt++)
	{
		if(cnt >= k) cnt = 0, op ^= 1; 
		for(int j = 1; j <= m; j++)
			if(i + j >= 1 && i + j <= n) a[i + j][j] = op; 
	}
	for(int op = 0, cnt = 0, i = n + m + 1; i >= 1; i--, cnt++)
	{
		if(cnt >= k) cnt = 0, op ^= 1; 
		for(int j = 1; j <= m; j++)
			if(i - j <= n && i - j >= 1) b[i - j][j] = op; 
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++) printf("%c", s[a[i][j]][b[i][j]]);
		puts("");
	}
	return 0; 
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n,m;
bool edge[11][11];
int ord[11];

int main(){
  cin.sync_with_stdio(false);
  cin>>n>>m;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--; b--;
    edge[a][b]=edge[b][a]=true;
  }
  ll cnt=0;
  rep(i,n)ord[i]=i;
  do{
    if(ord[0]!=0)continue;
    bool ok=true;
    rep(i,n-1){
      if(!edge[ord[i]][ord[i+1]])ok=false;
    }
    if(ok){
      cnt++;
    }
  }while(next_permutation(ord,ord+n));
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* {{{ */
/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)

#define all(i) (i).begin(),(i).end()
#define rall(i) (i).begin(),(i).end(),greater<int>()
#define print(x) cout << (x) << endl
#define PB push_back
#define pb push_back
#define mp make_pair
#define FI first
#define SE second

inline int in(){int x;std::cin>>x;return x;}
struct FAST {FAST(){cin.tie(0);ios::sync_with_stdio(false);}} Fast;
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;
/*-------------------------------*/
/* }}} */ 

int n, m, a;
bool no[20][20] = {};
int point[20][20];

int rec(int i, int j)
{
  if (no[i][j] == true) return 0;
  if (i == 0 || j == 0) return 0;
  if (i == 1 && j == 1) return 1;

  return point[i][j] = rec(i - 1, j) + rec(i, j - 1);
}

signed main(void)
{
  while (true){
    cin >> n >> m;
  
    if (n == 0 && m == 0) break;
  
    cin >> a;

    memset(no, false, sizeof(no));
    memset(point, 0, sizeof(point));

    rep(i, a){
      int x, y;
      cin >> x >> y;

      no[x][y] = true;
    }
  
    cout << rec(n, m) << endl;
  }

  return (0);
}

Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int num1, num2;
        StringBuilder in1 = new StringBuilder();
        StringBuilder in2 = new StringBuilder();
        Scanner sc = new Scanner(System.in);
        num1 = sc.nextInt();
        sc.nextLine();

        for (int i = 0; i < num1; i++) {
            in1.append(sc.nextInt());
            //System.out.println(in1);
        }

        num2 = sc.nextInt();
        sc.nextLine();

        for (int i = 0; i < num2; i++) {
            in2.append(sc.nextInt());
            //System.out.println(in2);
        }

        if (in1.toString().compareTo(in2.toString()) >= 0)
            System.out.println(0);
        else
            System.out.println(1);

    }

}


Measured memory_bytes: 32516
n, y = map(int, input().split())
for i in range(0, n+1):
  for j in range(0, n+1):
    if i+j > n :
      break
    k = n - i - j
    if i*10000 + j*5000 + k*1000 == y:
      print(i,j,k)
      exit()
    if i*10000 + j*5000 + k*1000 > y:
      break
print('-1 -1 -1')

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
const int maxn = 500005;
int a[maxn*4];
int H;
void maxHeapify(int i){
	int l,r,largest;
	l = 2*i;
	r = l + 1;
	if(l <= H && a[l] > a[i])largest = l;
	else largest = i;
	if(r <= H && a[r] > a[largest])largest = r;
	if(largest != i){
		swap(a[i],a[largest]);
		maxHeapify(largest);
	}
}
int main()
{
	cin>>H;
	for(int i=1;i<=H;++i)cin>>a[i];
	
	for(int i=H/2;i>=1;--i)maxHeapify(i);
	
	for(int i=1;i<=H;++i)cout<<" "<<a[i];
	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 4996
import sys
from collections import defaultdict
def smin(x,y):
    if x>y:
        return y
    else:
        return x

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

def main():
    N = int(input())

    dd = defaultdict(list)
    ans = 10**27

    for i in range(N):
        x,y,u = input().split()
        x,y = int(x),int(y)
        dd[u].append((x,y))

    dd_u = defaultdict(list)

    for x,y in dd["U"]:
        dd_u[x].append((y,"U"))

    for x,y in dd["D"]:
        if x in dd_u:
            dd_u[x].append((y,"D"))

    for x in dd_u:
        dd_u[x].sort()
        for i in range(len(dd_u[x])-1):
            if dd_u[x][i][1]=="U" and dd_u[x][i+1][1]=="D":
                ans = smin((dd_u[x][i+1][0]-dd_u[x][i][0])/2,ans)

    dd_l = defaultdict(list)

    for x,y in dd["L"]:
        dd_l[y].append((x,"L"))

    for x,y in dd["R"]:
        if y in dd_l:
            dd_l[y].append((x,"R"))

    for y in dd_l:
        dd_l[y].sort()
        for i in range(len(dd_l[y])-1):
            if dd_l[y][i][1]=="R" and dd_l[y][i+1][1]=="L":
                ans = smin((dd_l[y][i+1][0]-dd_l[y][i][0])/2,ans)

    dd_v = defaultdict(list)

    for x,y in dd["U"]:
        v = y-x
        dd_v[v].append((x+y,"U"))

    for x,y in dd["L"]:
        v = y-x
        if v in dd_v:
            dd_v[v].append((x+y,"L"))

    for v in dd_v:
        dd_v[v].sort()
        for i in range(len(dd_v[v])-1):
            if dd_v[v][i][1]=="U" and dd_v[v][i+1][1]=="L":
                ans = smin((dd_v[v][i+1][0]-dd_v[v][i][0])/2,ans)

    dd_v = defaultdict(list)

    for x,y in dd["U"]:
        v = y+x
        dd_v[v].append((x-y,"U"))

    for x,y in dd["R"]:
        v = y+x
        if v in dd_v:
            dd_v[v].append((x-y,"R"))

    for v in dd_v:
        dd_v[v].sort()
        for i in range(len(dd_v[v])-1):
            if dd_v[v][i][1]=="R" and dd_v[v][i+1][1]=="U":
                ans = smin((dd_v[v][i+1][0]-dd_v[v][i][0])/2,ans)


    dd_v = defaultdict(list)

    for x,y in dd["D"]:
        v = y-x
        dd_v[v].append((x+y,"D"))

    for x,y in dd["R"]:
        v = y-x
        if v in dd_v:
            dd_v[v].append((x+y,"R"))

    for v in dd_v:
        dd_v[v].sort()
        for i in range(len(dd_v[v])-1):
            if dd_v[v][i][1]=="R" and dd_v[v][i+1][1]=="D":
                ans = smin((dd_v[v][i+1][0]-dd_v[v][i][0])/2,ans)

    dd_v = defaultdict(list)

    for x,y in dd["D"]:
        v = y+x
        dd_v[v].append((x-y,"D"))

    for x,y in dd["L"]:
        v = y+x
        if v in dd_v:
            dd_v[v].append((x-y,"L"))

    for v in dd_v:
        dd_v[v].sort()
        for i in range(len(dd_v[v])-1):
            if dd_v[v][i][1]=="D" and dd_v[v][i+1][1]=="L":
                ans = smin((dd_v[v][i+1][0]-dd_v[v][i][0])/2,ans)

    if ans>10**24:
        print("SAFE")
    else:
        print(int(ans*10))


if __name__ == '__main__':
    main()




Measured memory_bytes: 178148