akhauriyash/Code-Regression huggingface dataset:
# E - 1 or 2
from typing import List


def main():
    def dfs(source: int) -> None:
        stack = [source]
        is_visited[source] = True
        while stack:
            u = stack.pop()
            for v in graph[u]:
                if is_visited[v]:
                    continue
                is_visited[v] = True
                stack.append(v)

    N, M, *X = map(int, open(0).read().split())
    graph: List[List[int]] = [[] for _ in range(N + 1)]
    for x, y, _ in zip(*[iter(X)] * 3):
        graph[x].append(y), graph[y].append(x)

    is_visited = [False] * (N + 1)
    res = 0
    for i in range(1, N + 1):
        if is_visited[i]:
            continue
        res += 1
        dfs(i)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41292
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>
using namespace std;

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if (k <= n)
        cout << k * x + (n - k) * y << endl;
    else
        cout << n * x << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
const int INF = numeric_limits<int>::max()/2;

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

    string s;cin>>s;
    int a=0,b=0,c=0;
    for(int i=0;i<(int)s.length();i++){
        if(s[i]=='a') a++;
        else if(s[i]=='b') b++;
        else c++;
    }
    if(max(a,max(b,c))-min(a,min(b,c))<=1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 512
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<pair<long long int, long long int>>v(N);
	L = INT_MAX;
	for (int i = 0; i < N; i++) {
		cin >> M >> K;
		L = min(M, L);
		R = max(R, M);
		L = min(K, L);
		R = max(R, K);
		if (M < K) {
			v[i] = { M,K };
		}
		else {
			v[i] = { K,M };
		}
	}
	long long int ans = LLONG_MAX;
	long long int lmin = INT_MAX;
	long long int lmax = 0;
	long long int rmax = 0;
	long long int rmin = INT_MAX;
	for (int i = 0; i < N; i++) {
		lmin = min(lmin, v[i].first);
		lmax = max(lmax, v[i].first);
		rmin = min(rmin, v[i].second);
		rmax = max(rmax, v[i].second);
	}
	ans = min(ans, (lmax - lmin)*(rmax - rmin));
	sort(v.begin(), v.end());
	long long int emin = INT_MAX;
	long long int emax = 0;
	ans = min(ans, (R - L)*(v[N - 1].first - v[0].first));
	for (int i = 0; i < N-1; i++) {
		emin = min(emin, v[i].second);
		emax = max(emax, v[i].second);
		ans = min(ans, (max(emax, v[N - 1].first) - min(emin, v[i + 1].first))*(R - L));
	}
	emin = min(emin, v[N - 1].second);
	emax = max(emax, v[N - 1].second);
	ans = min(ans, (R - L)*(emax - emin));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
x,y=map(int,input().split())
if (x in a and y in a) or(x in b and y in b) or(x in c and y in c): 
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
// All Heil Fire Lord Zuko

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

#define F first
#define S second
#define PB push_back
#define debug(x) cerr << #x << " = " << x << endl

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;

const int N = 2 * 100 * 1000 + 19;

int32_t main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int x, a;
    cin >> x >> a;
    if (x < a)
        cout << 0;
    else
        cout << 10;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

// union find
class union_find {
public:
    int n;
    vector<int> parent, rnk, num;
    
    union_find(int n) : n(n), parent(n), rnk(n, 0), num(n, 1) {rep(i, n) parent[i] = i; }
    
    int root(int x){ return (parent[x] == x) ? x : root(parent[x]); }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) {
            return;
        }
        if (rnk[x] < rnk[y]) {
            parent[x] = y;
            num[y] += num[x];
        }
        else{
            parent[y] = x;
            num[x] += num[y];
            if (rnk[x] == rnk[y]) {
                rnk[x]++;
            }
        }
        n--;
    }
    
    bool same(int x, int y) {return root(x) == root(y);}
    
    int count(int x){ return num[root(x)]; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N, M;
    cin >> N >> M;
    union_find uf(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i, N) ans = max(ans, uf.count(i));
    output(ans);
    
    
    return 0;
}


Measured memory_bytes: 5568
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String[] array = s.split("");
		int kingaku = 700;
		for(int i = 0; i < s.length(); i++){
			if(array[i].equals("o")){
				kingaku += 100;
			}
		}
		System.out.println(kingaku);
	}
}

Measured memory_bytes: 27044
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

struct Point{
    double x, y, z;
    double r;
};


double dist(Point a, Point b){
    auto pow = [](double a){return a * a; };
    return sqrt(pow(b.x - a.x) + pow(b.y - a.y) + pow(b.z - a.z)) - (a.r + b.r);
}

class Edge {
    public:
        int to;
        double cost;
        Edge(int to, double cost) : to(to), cost(cost) { }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

double prim(const Graph &g, int s = 0) {
    int n = g.size();
    double total = 0;

    vector<bool> visited(n);
    priority_queue<pair<double, int>, vector<pair<double, int>>, greater<pair<double, int>>> q;
    //priority_queue<pair<double, int> > q;

    q.push(make_pair(0.0,s));
    while (not q.empty()) {
        pair<double, int> u = q.top(); q.pop();
        if (visited[u.second]) continue;
        total += u.first;
        visited[u.second] = true;
        for(auto it : g[u.second]) {
            if (not visited[it.to]) q.push(make_pair(it.cost, it.to));
        }
    }
    return total;
}

int main(){
    int n;
    while(cin >> n,n){
        Point p[105];
        rep(i,n) cin >> p[i].x >> p[i].y >> p[i].z >> p[i].r;

        Graph g(n);
        rep(i,n){
            rep(j,n){
                double tmp = dist(p[i], p[j]);
//                cout << i << ' ' << j << endl;
//                show(tmp)
                g[i].emplace_back(Edge{j,tmp < 0 ? 0 : tmp});
            }
        }
        cout <<fixed << setprecision(3) <<  prim(g,0) << endl;
    }
}

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

int main () {
    
    int K, A, B; cin >> K >> A >> B;
    bool flag = false;
    for(int i = A; i <= B; i++) {
        if(i%K == 0) {
            flag = true;
            break;
        }
    }

    flag ? cout << "OK" << endl : cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.readline
from collections import *

N, K = map(int, input().split())
cnt = [0]*N

for _ in range(K):
    d = int(input())
    a = list(map(int, input().split()))
    
    for ai in a:
        cnt[ai-1] += 1

ans = cnt.count(0)
print(ans)

Measured memory_bytes: 67908
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0, d = 0, e = 0, ans = 0, x = 0, y = 0, z = 0, N = 0, m = 0, maxy = 0, mini = 9999999999, mini2 = 9999999999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremono[100010], koware[100001];
long long  int iremono2[100001], check[100001], xpo[10000001], ypo[10000001], hei[1000001];
std::vector<char>kinds{}, kaku{}, kakutwo{};
char maze[1000];
int sx, sy;
int gx, gy;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
long long int dp[4][100003] ,ire[4][100003];
std::string input[103],one,two,three;
char re;

int H, W;//はんい
bool qw = false, er = false, ty = false, ui = false;
std::string code;
long long int gcd(long long int a, long long int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

	return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a,long long int b)
{
	return a * b / gcd(a, b);
}

int main() {
	cin >> a;
	rep(i, a) {
		cin >> b;
		vec.push_back(b);
	}
	std::vector<long long int> sorted=vec;
	std::sort(sorted.begin(), sorted.end());
	rep(i, a) {
		if (vec[i] < sorted[a / 2]) {
			cout << sorted[a / 2 ] << endl;
		}
		else {
			cout << sorted[a / 2 - 1] << endl;
		}
	}
}




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

int main() {
	int		a,b,c,r,i,j,k,n,m,x,y,ans = 0;
	string	str;
	
	cin >> str;
	
	if ( (str == "AAA") || (str == "BBB") ) {
		cout << "No" << endl;
	} else{
		cout << "Yes" << endl;
	}


}


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

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

  int N500 = N/500; //500円で払える枚数
  int NA500 = N - 500*N500; //500円硬貨で払う額をNからマイナス

  string yes = "Yes";
  string no = "No";

  if (NA500 <= 0 || NA500 <= A) {
    cout << yes << endl;
  }else{
    cout << no << endl;
  }

}


Measured memory_bytes: 256
n,x = map(int,input().split())
li = list(map(int,input().split()))
list.sort(li)
num = 0
for i in range(1,n+1):
    if sum(li[:i]) <= x:
        num = i
if sum(li[:n+1]) < x:
    print(n-1)
else: 
    print(num)


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

ll INF = 1LL << 60;

int 
main() {

  int N, Q; cin >> N >> Q;
  vector<vector<ll>> tree(N + 1);
  rep(i, 0, N - 1){
    ll a, b; cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  vector<ll> imos(N + 1, 0);
  rep(i, 0, Q){
    int p, q; cin >> p >> q;
    imos[p] += q;
  }

  queue<ll> q;
  vector<bool> seen(N + 1, false);
  seen[1] = true;
  q.push(1);
  while(! q.empty()){
    ll nodes = q.front();
    q.pop();
    for(auto node: tree[nodes]){
      if(seen[node])continue;
      imos[node] += imos[nodes];
      seen[node] = true;
      q.push(node);
    }
  }

  rep(i, 1, N + 1){
    cout << imos[i] << endl;
  }
}


Measured memory_bytes: 18920
H,W=gets.split.map &:to_i
c=[0]*26
$<.map{|l|
  l.chomp.chars{|a|
    c[a.ord-?a.ord]+=1
  }
}
puts c.count{|x|x%2==1}<2 && c.count{|x|x%4==2}<=(W%2)*(H/2)+(H%2)*(W/2)?:Yes: :No


Measured memory_bytes: 1788
//by tzupengwang™
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<iostream>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;

int n;
int s[200005];
vector<int> v;

void init() {
  scanf("%d", &n);
  for (int i = 0; i < n; i ++) {
    scanf("%d", &s[i]);
    v.push_back(s[i]);
  }

  sort(v.begin(), v.end());
}

void process() {
  int c1 = v[n / 2 - 1], c2 = v[n / 2];

  for (int i = 0; i < n; i ++) {
    if (s[i] <= c1) printf("%d\n", c2);
    else printf("%d\n", c1);
  }
}

int main() {
/*
#ifdef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
#endif
  int Cases;
  scanf("%d", &Cases);
  for (int cs = 1; cs <= Cases; cs ++) {
*/
    init();
    process();
/*
  }
*/
  return 0;
}


Measured memory_bytes: 3828
#include <cstdio>
#include <iostream>

using namespace std;
const int N = 1e5 + 10;
int n, q;
int a[N], key;
int sum;

int binary_search(int key)
{
    int l = 0, r = n;
    int mid;
    while(l < r)
    {
        mid = (l + r) >> 1;
        if(key == a[mid]) return 1;
        if(key < a[mid])
            r = mid;
        else if(key > a[mid])
            l = mid + 1;
    }
    return 0;
}

int main(void)
{
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);
    scanf("%d", &q);
    while(q--)
    {
        scanf("%d", &key);
        if(binary_search(key)) sum++;
    }

    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x))

using namespace std;

struct DSU {
    vector <int> par;
    stack <int> stk;
    int n;
    inline void init(int _n) {
        n = _n;
        par.resize(n + 1);
    }
    int root(int x) {
        if(par[x] == 0)
            return x;
        return par[x] = root(par[x]);
    }
    inline void join(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            stk.push(x);
            par[x] = y;
        }
        else {
            stk.push(-1);
        }
    }
    inline void undo() {
        if(stk.top() != -1) {
            par[stk.top()] = 0;
        }
        stk.pop();
    }
};


int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, j, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n;
    if(n == 3) {
        cout << "2\n1 3\n3 2";
        return 0;
    }
    for(int s = 1; s <= n * (n - 1) / 2; s++) {
        vector <int> sum(n + 1, 0);
        DSU dsu; dsu.init(n);
        for(i = 1; i <= n; i++) {
            int cur = n * (n + 1) / 2 - i - s;
            if(cur > n) {
                break;
            }
            for(j = 1; j <= n; j++) {
                if(i != j && cur != j) {
                    sum[i] += j;
                    sum[j] += i;
                    dsu.join(i, j);
                }
            }
        }
        bool flag = 1;
        for(i = 1; i <= n && flag; i++) {
            if(dsu.root(1) != dsu.root(i)) {
                flag = 0;
            }
        }
        for(i = 2; i <= n && flag; i++) {
            if(sum[i] != sum[1]) {
                flag = 0;
            }
        }
        if(flag) {
            vector < vector <bool> > vis(n + 1, vector<bool>(n + 1, 0));
            vector < pair <int, int> > sol;
            for(i = 1; i <= n; i++) {
                int cur = n * (n + 1) / 2 - i - s;
                for(j = 1; j <= n; j++) {
                    if(j != cur && j != i && vis[i][j] == 0) {
                        vis[i][j] = vis[j][i] = 1;
                        sol.push_back({i, j});
                    }
                }
            }
            cout << sol.size() << "\n";
            for(auto it : sol) {
                cout << it.first << " " << it.second << "\n";
            }
        }
    }
    //cin.close();
    //cout.close();
    return 0;
}


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

const int c[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

string to_str(int a) {
    string s = "";
    s += '0' + a;
    return s;
}

string large(string a, string b) {
    if (a.size() > b.size()) {
        return a;
    } else if (a.size() < b.size()) {
        return b;
    }
    for (int i=0; i<a.size(); ++i) {
        if (a[i] > b[i]) {
            return a;
        } else if (a[i] < b[i]) {
            return b;
        }
    }
    return a;
}

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

    int N, M;
    cin >> N >> M;

    vector<int> A(M);
    for (int i=0; i<M; ++i) cin >> A[i];

    string dp[10100][10];
    for (int i=0; i<N; ++i) {
        for (int j=0; j<10; ++j) {
            dp[i][j] = "";
        }
    }

    for (int i=0; i<N; ++i) {
        for (int j=0; j<M; ++j) {
            if (i != 0 && dp[i][A[j]] == "") continue;
            for (int k=0; k<M; ++k) {
                if (A[k] < A[j]) continue;
                dp[i+c[A[k]]][A[k]] = large(dp[i+c[A[k]]][A[k]], to_str(A[k])+dp[i][A[j]]);
            }
        }
    }

    string ans = "";
    for (int i=0; i<M; ++i) {
        ans = large(ans, dp[N][A[i]]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 270080
import java.io.PrintWriter

fun main() {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val n = readLine()!!
    val ans = if (n.contains("7")) {
        "Yes"
    } else {
        "No"
    }
    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 35768
#include<iostream>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>//min,max,swap,rand,reverse,sort,lower_bound
#include<functional>
#include<vector>
#include<list>
#include<map>
#include<tuple>
#include<cmath>//abs, sin, cos
#include<bitset>
using namespace std;

int main()
{
	int N, K, t;
	int sum = 0;
    vector<int> p;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> t;
		p.push_back(t);
	}
	sort(p.begin(), p.end());
	for (int i = 0; i < K; i++)
		sum += p[i];
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final String[] abc = "abcdefghijklmnopqrstuvwxyz".split("");
		int[] cnt = new int[abc.length];
		
		while(sc.hasNext()){
			String[] text = sc.nextLine().split("");
			
			for(int i=0; i<text.length; i++){
				for(int j=0; j<abc.length; j++){
					if(text[i].equals(abc[j]) || text[i].equals(abc[j].toUpperCase())){
						cnt[j]++;
					break;
					}
				}
			}
		}
		
		for(int j=0; j<abc.length; j++){
			System.out.println(abc[j] + " : " + cnt[j]);
		}
	}

}

Measured memory_bytes: 28856
#include<iostream>
using namespace std;
typedef long long ll;
int main() {
	ll n, t, a[114514], ans = 0, min, p = 0;
	cin >> n >> t; for (int i = 0; i < n; i++)cin >> a[i];
	min = a[0];
	for (int i = 1; i < n; i++) {
		if (min > a[i])min = a[i];
		else if (a[i] - min == p)ans++;
		else if (a[i] - min > p) {
			p = a[i] - min; ans = 1;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: u64,
        m: usize,
        aa: [u64;m]
    }
    let s = aa.iter().sum::<u64>();
    if n < s {
        println!("-1");
    } else {
        println!("{}", n - s);
    }
}


Measured memory_bytes: 2188
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second


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

bool app[50][50][50][50];

main(){
  int w,h;
  while(cin>>w>>h,w|h){
    memset(app,0,sizeof(app));
    string lr[h],rr[h];
    rep(i,h){
      cin>>lr[i]>>rr[i];
    }

    string ans="No";
    int rsx,rsy,lsx,lsy;
    rep(i,h)rep(j,w){
      if(lr[i][j]=='L')lsx=i,lsy=j;
      if(rr[i][j]=='R')rsx=i,rsy=j;
    }

    queue<pair<PI,PI> > Q;
    Q.push(mp(mp(lsx,lsy),mp(rsx,rsy)));

    while(!Q.empty()){
      PI tp=Q.front().F;
      int clx,cly,crx,cry;
      clx=tp.F,cly=tp.S;
      tp=Q.front().S;Q.pop();
      crx=tp.F,cry=tp.S;
      if(lr[clx][cly]=='%' && rr[crx][cry]=='%'){
        ans="Yes";
        break;
      }
      if(lr[clx][cly]=='%' || rr[crx][cry]=='%')continue;
      
      app[clx][cly][crx][cry]=true;

      rep(i,4){
        int nrx=crx+dx[i],nlx=clx+dx[i],nry=cry+dy[i],nly=cly-dy[i];
        if(nrx<0 || nry<0 || nrx>=h || nry>=w)nrx=crx,nry=cry;
        if(nlx<0 || nly<0 || nlx>=h || nly>=w)nlx=clx,nly=cly;
        if(lr[nlx][nly]=='#'){
          nlx=clx;
          nly=cly;
        }
        if(rr[nrx][nry]=='#'){
          nrx=crx;
          nry=cry;
        }
        if(app[nlx][nly][nrx][nry])continue;
        app[nlx][nly][nrx][nry]=true;
        Q.push(mp(mp(nlx,nly),mp(nrx,nry)));
      }
/*      
      rep(i,h){
        rep(j,w){
          if(clx==i && cly==j)cout<<'L';
          else if(lr[i][j]=='L')cout<<'.';
          else cout<<lr[i][j];
        }
        cout<<" ";
        rep(j,w){
          if(crx==i && cry==j)cout<<'R';
          else if(rr[i][j]=='R')cout<<'.';
          else cout<<rr[i][j];
        }
        cout<<endl;
      }
      cout<<endl;
*/
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 7932
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	ll N, X[1000], Y[1000], XY[1000];
	cin >> N;
	rep(i, N) {
		cin >> X[i] >> Y[i];
		XY[i] = X[i] + Y[i];
	}
	int allodd = 1;
	int alleven = 1;
	rep(i, N) {
		if (XY[i] % 2) alleven = 0;
		else allodd = 0;
	}
	if (allodd || alleven) {
		if (alleven) {
			co(36);
			rep(i, N) {
				X[i]++;
			}
		}
		else co(35);
		rep(i, 34) {
			cosp(1ll << (34 - i));
		}
		if (alleven) {
			cosp(1);
			co(1);
		}
		else {
			co(1);
		}

		rep(i, N) {
			string S;
			rep(ii, 35) {
				if (X[i] < Y[i]) {
					if (X[i] + Y[i] > 0) {
						S += "U";
						Y[i] -= (1ll << (34 - ii));
					}
					else {
						S += "L";
						X[i] += (1ll << (34 - ii));
					}
				}
				else {
					if (X[i] + Y[i] > 0) {
						S += "R";
						X[i] -= (1ll << (34 - ii));
					}
					else {
						S += "D";
						Y[i] += (1ll << (34 - ii));
					}
				}
			}
			if (alleven) {
				S += "L";
			}
			ce(X[i]);
			ce(Y[i]);
			co(S);
		}
	}
	else { co(-1); }
	Would you please return 0;
}

Measured memory_bytes: 384
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 200100;

    void solve(){
        ll n, cnt = 0;
        cin >> n;
        ll a[n], in = 0, b[n];
        rep(i, n) cin >> a[i];
        map<ll, ll> mp;
        rep(i, n-1) {
            mp[in]++;
            b[i] = in;
            a[i+1] > a[i] ? in = i+1:0;
        } mp[in]++;
        trav(i, mp) cnt = max(cnt, i.snd - 1);
        cout << cnt << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
     /*
      #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
      #endif
     */
      //te
      solve();
      return 0;
    } 


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string S,T;
    cin >> S >> T;
    int A,B;
    cin >> A >> B;
    string U;
    cin >> U;
    if(S==U)cout << A-1 << " " << B << endl;
    else cout << A << " " << B-1 << endl;
}

Measured memory_bytes: 896
//=template==================================================================//
// include
#include <vector>
#include <list>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

// namespace
using namespace std;

// define
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(i,n) FOR(i,0,n)
#define MIN_V(v) *min_element(v.begin(), v.end())
#define MAX_V(v) *max_element(v.begin(), v.end())

// typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;

// conversion
inline int toInt(string s) {int v; istringstream sin(s); sin>>v; return v;}
inline int countChar(string s, char c) {int cnt,i; cnt=0; REP (i,s.size()) {if (s[i]==c) cnt++;} return cnt;}
template<class T> inline string toString(T x) {ostringstream sout; sout<<x; return sout.str();}
//===========================================================================//

//=function prototype========================================================//

//===========================================================================//

//=variables=================================================================//

//===========================================================================//
int main(void)
{
  // Scan begin.
  double n, m, d;
  cin >> n >> m >> d;
  // Scan done.

  // Code begin.
  if (d==0) {
    printf("%12.10lf\n", ((m-1)/n));
  }
  else {
    printf("%12.10lf\n", ((2*(n-d)*(m-1)/n/n)));
  }
  // Code done.

  return 0;
}

//=functions=================================================================//

//===========================================================================//

Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
shop = []
order = {}
for i in range(n):
    s,p = ls()
    p = int(p)
    shop.append([s,p])
    order[(s,p)] = i

ans = sorted(sorted(shop, key=lambda x: x[1], reverse=True), key=lambda x:x[0])


for i, (name, point) in enumerate(ans):
    print(order[(name, point)] + 1)
    order[(name, point)] = i


Measured memory_bytes: 3064
#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 n;
	cin >> n;
	
	ll ans = 0;
	for (int a = 1; a <= n; ++a) {
		ans += (n - 1) / a;
	}
	
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T x=0,f=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
#define int long long
namespace run{
	const int N=2e5+9;
	int k,n,a[N],mx;
	int main(){
		k=read<int>(),n=read<int>();
		for(int i=1;i<=n;i++) a[i]=read<int>(),mx=max(mx,a[i]-a[i-1]);
		mx=max(mx,k-a[n]+a[1]);
		printf("%lld\n",k-mx);
		return 0;
	}
}
#undef int
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
long long n;
long long a[100005];
long long sum=0,ch1=0,ch2=0;
int main()
{
	cin>>n;
	int last=-1;  
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
		if(sum==0)
		{
			ch1++;
			if(last<0)
			    sum=1;
			else
			    sum=-1;
		}
		else
		if(sum<0&&last<0)
		{
			ch1+=(1-sum);
			sum=1;
		}
		else
		if(sum>0&&last>0)
		{
			ch1+=(sum+1);
			sum=-1;
		}
		last=sum;
	}
	sum=0;
	last=1;
	for(int i=0;i<n;i++)
	{
		sum+=a[i];
		if(sum==0)
		{
			ch2++;
			if(last<0)
			    sum=1;
			else
			    sum=-1;
		}
		else
		if(sum<0&&last<0)
		{
			ch2+=(1-sum);
			sum=1;
		}
		else
		if(sum>0&&last>0)
		{
			ch2+=(sum+1);
			sum=-1;
		}
		last=sum;
	}
	cout<<min(ch1,ch2);	
	return 0;
}

Measured memory_bytes: 1024
S=io.read()
K=io.read("n")
a=string.sub(S,1,1)
t=2
while(a=="1") do
  a=string.sub(S,t,t)
  t=t+1
end
b=tonumber(a)
if K<t-1 then
  print(1)
  else
  print(b)
end

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mk(a, b) make_pair(a, b)
#define pb(a) push_back(a)
const int MAXN = 1 << 17;

int K, N, Q;
int A[100100];

pair<int, int> dat[2 * MAXN - 1];
int n;

void init(int n_)
{
    n = 1;
    while(n < n_) n *= 2;

    for(int i = 0; i < 2 * n - 1; i++){
        dat[i].first = 1;
    }
}

void update(int k, int a, int b)
{
    k += n - 1;
    dat[k] = mk(a, b);

    while(k > 0){
        k = (k - 1) / 2;
        pair<int, int> l = dat[k * 2 + 1], r = dat[k * 2 + 2];
        dat[k] = mk(l.first * r.first, (K + l.second + l.first * r.second) % K);
    }
}

signed main()
{
    cin >> K >> N >> Q;
    init(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(A[i] == 0){
            update(i, -1, 0);
        }
        else{
            update(i, 1, (K - A[i]) % K);
        }
        //printf("a:%lld\n", -A[i]);
    }
    /*for(int i = 0; i < 2 * n - 1; i++){
        printf("dat[%lld]:p(%lld, %lld)\n", i, dat[i].first, dat[i].second);
    }*/
    queue<int> que;
    for(int i = 0; i < Q; i++){
        int a, b;
        cin >> a >> b;
        if(A[b - 1] == 0){
            update(a - 1, -1, 0);
        }
        else{
            update(a - 1, 1, (K - A[b - 1]) % K);
        }
        if(A[a - 1] == 0){
            update(b - 1, -1, 0);
        }
        else{
            update(b - 1, 1, (K - A[a - 1]) % K);
        }
        swap(A[a - 1], A[b - 1]);
        int res = (1 + dat[0].second + K) % K;
        //printf("res:%lld dat:%lld\n", res, dat[0].second);
        if(res == 0){
            res = K;
        }
        if(dat[0].first == 1){
            que.push(res);
        }
        else{
            que.push(-res);
        }

        /*for(int j = 0; j < 2 * n - 1; j++){
            printf("dat[%lld]:p(%lld, %lld)\n", j, dat[j].first, dat[j].second);
        }*/
    }
    while(!que.empty()){
        cout << que.front() << endl;
        que.pop();
    }

    return 0;
}
/*

5 7 5
0 0 3 3 3 3 3
1 2
2 3
3 4
4 5
5 6

5 3 1
1 -2 0
2 3

*/



Measured memory_bytes: 8416
use std::collections::BTreeSet;

fn main() {
    let (h, w, n) = {
        let a = getvec::<i64>();
        (a[0], a[1], a[2])
    };
    let mut black = BTreeSet::new();
    let mut cand = BTreeSet::new();
    for _ in 0..n {
        let (y, x) = {
            let a = getvec::<i64>();
            (a[0], a[1])
        };
        black.insert((y, x));
        for i in (y - 2)..(y + 1) {
            for j in (x - 2)..(x + 1) {
                if i > 0 && j > 0 && i < h - 1 && j < w - 1 {
                    cand.insert((i, j));
                }
            }
        }
    }
    let mut ans = [0i64; 10];
    for &p in &cand {
        let (i, j) = p;
        let mut sum : usize = 0;
        for x in j..j + 3 {
            for y in i..i + 3 {
                if black.contains(&(y, x)) {
                    sum = sum + 1;
                }
            }
        }
        ans[sum] += 1;
    }
    ans[0] = (h - 2) * (w - 2);
    for i in 1..10 {
        ans[0] -= ans[i];
    }
    for i in 0..10 {
        println!("{}", ans[i]);
    }
}

fn next_line() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input
}

#[allow(dead_code)]
fn getnum<T : std::str::FromStr>() -> T {
    let res = next_line();
    let res = res.trim().parse::<T>().ok().unwrap();
    res
}

#[allow(dead_code)]
fn getvec<T : std::str::FromStr>() -> Vec<T> {
    let res = next_line();
    let res : Vec<T> = res.split_whitespace().map(|x| x.parse::<T>().ok().unwrap()).collect();
    return res;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    int n,k;
    cin >> n >> k;
    VI pv(n);
    REP(i, n) cin >> pv[i];
    SORT(pv);
    int ans = 0;
    REP(i, k) ans += pv[i];
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>

using namespace std;

//void abc_150a();


void abc_150a()
{
  int K, X;
  cin >> K >> X;

  if (500 * K >= X) cout << "Yes\n";
  else cout << "No\n";
}


int main()
{
  abc_150a();
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    int a;
    long long b, n;
    cin >> a >> b >> n;
    long long ans;
    if (n < b) ans = a*n/b;
    else if (b == n) {
        if (n == 1) ans = 0;
        else ans = a*(n-1)/b - a*((n-1)/b);
    } else {
        n = n - n%b;
        ans = a*(n-1)/b - a*((n-1)/b);
    }
    cout << ans << endl;
}


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

// in-short-use macros

#define all(c) (c).begin(),(c).end()
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define PI 3.14159265
#define sizes 1000010

# define M_PI           3.14159265358979323846

//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ld n;
    cin>>n;
    cout<<2*n*M_PI<<"\n";
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define sz(x) ((long long)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define oo 1e15;
const ld eps = 1e-9;
const ld pi = acosl(-1);
const int mod = 998244353;
const int mod1 = 1e9 + 7;


mt19937_64 rnd(time(0));

void faster()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
}

signed main() {
    faster();
    // freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
    //______________________________________
    ///*__*/double start = clock();/*__*/
    //_____________________________________
    int n, m;
    cin >> n >> m;
    char a[n][m];
    int dp[n][m];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> a[i][j];
    dp[0][0] = 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (i == 0 && j == 0) continue;
            dp[i][j] = 0;
            if (a[i][j] == '#') continue;
            if (i > 0)
                dp[i][j] = dp[i - 1][j];
            dp[i][j] %= mod1;
            if (j > 0)
                dp[i][j] += dp[i][j - 1];
            dp[i][j] %= mod1;
        }
    }
    cout << dp[n - 1][m - 1];
    //______________________________________
    //  cerr << "Time " << (clock() - start)  * 1.0 / CLOCKS_PER_SEC << "s\n";
    return 0;
}

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

#define mod 1000000007
typedef long long ll;

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void calcFacAndInv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

ll npr(ll n, ll r)
{
    return (fact[n] * inv[n - r]) % mod;
}

ll dp[102][100005], a[100005][2];
int n, w;

ll solve(int i, int j)
{
    if (i == n)
        return 0;
    if (dp[i][j] != -1)
        return dp[i][j];
    ll c = solve(i + 1, j);
    if (j >= a[i][0])
        c = max(c, solve(i + 1, j - a[i][0]) + a[i][1]);
    return dp[i][j] = c;
}

int main()
{
    memset(dp, -1, sizeof dp);
    cin >> n >> w;
    for (int i = 0; i < n; i++)
        cin >> a[i][0] >> a[i][1];
    cout << solve(0, w);
    return 0;
}


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

using namespace std;

int W, H;
int start_x = 0, start_y = 0;
int sum;

vector<vector<char>> makeroom(int w, int h) {
	vector<vector<char>> room(h);
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			char tmp;
			cin >> tmp;
			if(tmp == '@') {
				start_x = j;
				start_y = i;
			}
			room[i].push_back(tmp);
		}
	}
	return room;
}

void dfs_run(vector<vector<char>>& room, vector<vector<bool>>& checker, int x, int y) {
	
	if(x != 0) {
		if(room[y][x - 1] == '.' and checker[y][x - 1]) {
			sum++;
			checker[y][x - 1] = false;
			dfs_run(room, checker, x - 1, y);
		}
	}
	if(x != W - 1) {
		if(room[y][x + 1] == '.' and checker[y][x + 1]) {
			sum++;
			checker[y][x + 1] = false;
			dfs_run(room, checker, x + 1, y);
		}
	}
	if(y != 0) {
		if(room[y - 1][x] == '.' and checker[y - 1][x]) {
			sum++;
			checker[y - 1][x] = false;
			dfs_run(room, checker, x, y - 1);
		}
	}
	if(y != H - 1) {
		if(room[y + 1][x] == '.' and checker[y + 1][x]) {
			sum++;
			checker[y + 1][x] = false;
			dfs_run(room, checker, x, y + 1);
		}
	}
}

void dfs(vector<vector<char>>& room) {
	vector<vector<bool>> checker;
	checker = vector<vector<bool>>(room.size(), vector<bool>(room[0].size(), true));

	dfs_run(room, checker, start_x, start_y);
}


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

		vector<vector<char>> room = makeroom(W, H);
		sum = 0;
		dfs(room);

		cout << sum + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll Q=1000000007;
const double PI=3.14159265358979323846;

int main(){
  int N;
  cin >> N;
  for(int i=0;i<=N;i++){
    if(N==(i*108)/100){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
         final var br = new BufferedReader(stdin)) {
      final var s = br.readLine();
      int sum = 0;
      for (int i = 0; i < s.length(); i++) {
        final var n = s.charAt(i) - '0';
        sum += n;
      }

      System.out.println(sum % 9 == 0 ? "Yes" : "No");
    }
  }
}


Measured memory_bytes: 35864
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  ll N;
  ll D;
  cin >> N >> D;
  ll X[N];
  ll Y[N];
  int Sum=0;
  ll k;
  int i=0;
  rep(i,N){cin >> X[i] >> Y[i];}
  rep(i,N){
    k=(X[i])*(X[i])+(Y[i])*(Y[i]);
    if(k<=D*D){Sum++;}
  }
  cout << Sum << endl;
  return 0;
}


Measured memory_bytes: 6752
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	/*int a, b;
	cin >> a >> b;
	int ans = -1;
	if (a < 10 && b < 10)ans = a * b;
	cout << ans;*/


	/*int n;
	cin >> n;
	int i, j;

	for (i = 1; i < 10; i++) {
		for (j = 1; j < 10; j++) {
			if (i * j == n) {
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";*/


	ll n;
	cin >> n;
	ll ans = 1e12;
	int i;
	for (i = 1; i <= 1000000; i++) {
		if (n % i == 0) {
			ans = min(ans, i + n / i - 2);
		}
		if (i > n)break;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0] * N
E = [[] for _ in range(N)]
L = [0] * N
for i in range(N - 1):
  a = int(input())
  A[i + 1] = a - 1
  E[a - 1].append(i + 1)
D = [[0, i] for i in range(N)]
Q = [0] * N
pos = 0
for i in range(N):
  s = Q[i]
  for adj in E[s]:
    D[adj][0] = D[s][0] + 1
    pos += 1
    Q[pos] = adj
D.sort(reverse=True)
for d in D:
  if not E[d[1]]:
    continue
  L[d[1]] = max([l + i + 1 for i, l in enumerate(sorted([L[e] for e in E[d[1]]], reverse=True))])
print(L[0])

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

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

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	if(a+b>c+d){
		printf("Left\n");
	}else if(a+b<c+d){
		printf("Right\n");
	}else{
		printf("Balanced\n");
	}
	return 0;
}

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

int main() {
	int n;
	while (cin >> n, n) {
		map<int, string>m;
		for (int i = 0;i < n;i++) {
			string s;
			int a[8];
			cin >> s;
			for (int j = 0;j < 8;j++)cin >> a[j];
			int t = 0, se = 0;
			for (int j = 0;j < 8;j += 2)t += a[j];
			for (int j = 1;j < 8;j += 2)se += a[j];
			int b = t * 60 + se;
			m.insert(make_pair(b, s));
		}
		auto itr = m.begin();
		cout << itr->second << endl;
		itr++;
		cout << itr->second << endl;
		auto it= m.rbegin();
		it++;
		cout << it->second << endl;

	}
	return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
#define N 100005
using namespace std;
vector<int> e[N];
int n,m,q,s,t,cnt;
int used[N];

void dfs(int x){
  if(used[x])return;
  used[x]=cnt;
  for(int i=0;i<e[x].size();i++)
    dfs(e[x][i]);
}

int main(){
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>s>>t;
    e[s].push_back(t);
    e[t].push_back(s);
  }
  cnt=1;
  for(int i=0;i<n;i++){
    if(!used[i])dfs(i),cnt++;
  }
  cin>>q;
  while(q--){
    cin>>s>>t;
    if(used[s]==used[t])cout<<"yes"<<endl;
    else cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 10180