akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
import math

n, m = [int(x) for x in stdin.readline().rstrip().split()]

s = [0] * m
c = [0] * m
for i in range(m):
    s[i], c[i] = [int(x) for x in stdin.readline().rstrip().split()]

result = -1
for nn in range(10 ** n):
    ns = str(nn)
    if len(ns) < n:
        continue
    #ns = ns.zfill(n)
    flag = True
    for i in range(m):
        if ns[s[i]-1] == str(c[i]):
            continue
        else:
            flag = False
            break
    if flag:
        result = nn
        if n > 1 and result == 0:
            result = -1
        break

print(result)
        


Measured memory_bytes: 3064
using System;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int A = cin.nextInt();
        int B = cin.nextInt();
        int C = cin.nextInt();

        Console.WriteLine(Math.Min(C, B / A));
    }
}


class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <cctype>
#include <cmath>
#include <iomanip>
#define ARB ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);
using namespace std;
typedef long long ll;
int main()
{
    ARB;
    int n;
    cin>>n;
    if(n%2==1)
        cout<<n/2+1;
    else
        cout<<n/2;

   return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long target = sc.nextLong();
		long b = sc.nextLong();
		long r = sc.nextLong();
		long sum = r + b;

		//B+RがNよりも大きい場合
		long count = target / sum;
		long answer = b * count;

		answer += Math.min(target%sum, b);

		System.out.println(answer);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

constexpr ll mod = 1000000007;

vector<vector<ll>> mat_mul(vector<vector<ll>> a, vector<vector<ll>> b) {
	int n = a.size();
	vector<vector<ll>> ans(n, vector<ll>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				ans[i][j] += a[i][k] * b[k][j];
				ans[i][j] %= mod;
			}
		}
	}
	return ans;
}

vector<vector<ll>> mat_pow(vector<vector<ll>> a, ll b) {
	int n = a.size();
	vector<vector<ll>> ans(n, vector<ll>(n));
	for (int i = 0; i < n; i++) ans[i][i] = 1;
	while (b) {
		if (b & 1) ans = mat_mul(ans, a);
		a = mat_mul(a, a);
		b >>= 1;
	}
	return ans;
}

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

	ll n, m;
	cin >> n >> m;
	vector<ll> x(m);
	rep(i, m) cin >> x[i];
	vector<P> p;
	ll prev = -1;
	rep(i, m) {
		ll cnt = x[i] - prev - 2;
		if (cnt > 0) p.pb({ 1,cnt });
		ll sz = 2; ll cur = x[i];
		while (i + 1 < m && cur + 1 == x[i + 1]) {
			cur++; i++; sz++;
		}
		p.pb({ sz,1 });
		prev = x[i];
	}
	if (prev != n - 1) p.pb({ 1,n - prev - 1 });
	p.pb({ 0,1 });
	int psz = p.size(); psz--;
	vector<vector<ll>> mat(3, vector<ll>(3));
	rep(i, 3) mat[i][i] = 1;
	rep(i, psz) {
		int ps = p[i].second;
		if (i == 0) {
			if (p[i].second == 1) continue;
			else ps--;
		}
		if (p[i].first == 1) {
			if (ps > 1) {
				vector<vector<ll>> b = { {2,1,0},{3,1,2},{1,0,1} };
				b = mat_pow(b, ps - 1);
				mat = mat_mul(b, mat);
			}
		}
		ll c = p[i].first;
		ll d = p[i + 1].first;
		vector<vector<ll>> b = { {1 + c * c,c,0},{2 * c + d,1,c + d},{1,0,1} };
		rep(bx, 3) rep(by, 3) b[bx][by] %= mod;
		mat = mat_mul(b, mat);
	}
	ll a0 = p[0].first;
	ll a1 = p[1].first;
	if (p[0].second > 1) a1 = p[0].first;
	ll ans = 0;
	ans += a0 * a0 % mod * mat[0][0] % mod;
	ans += (2 * a0 + a1) * mat[0][1] % mod;
	ans += mat[0][2] % mod;
	ans %= mod;
	cout << ans << '\n';
}

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

using namespace std;
int Check(int ni,vector<int> Li,int inh){
    Li.resize(ni+1);
    Li[ni]=inh;
    int  ih=0;
    while (Li[ih]!=inh){
        ih++;}
    if(ih==ni){
        return -1;
    }else{
        return ih;
    }

}

int main(){
    int n;
    cin>>n;
    vector<int> L(n);

    int count=0;
    for (int i=0;i<n;++i){
        cin>>L[i];

    }
    int q;
    cin>>q;
    while(q>0){
        q--;
        int l;
        cin>>l;

        if(Check(n,L,l)!=-1){

           ++count;
        }else{

        }
    }

    cout<< count<<endl;
}


Measured memory_bytes: 3220
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
//ll dp[26][];
#define COMB_MAX (int)2e6 + 10
ll f[COMB_MAX], rf[COMB_MAX];
ll inv(ll x) {
	ll res = 1;
	ll k = mod - 2;
	ll y = x;
	while (k) {
		if (k & 1) res = (res * y) % mod;
		y = (y * y) % mod;
		k /= 2;
	}
	return res;
}
void init() {
	f[0] = 1;
	rep(i, 1, COMB_MAX) f[i] = (f[i - 1] * i) % mod;
	rep(i, 0, COMB_MAX) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
	if (k<0 || k>n || n < 0)return 0;
	ll a = f[n]; // = n!
	ll b = rf[n - k]; // = (n-k)!
	ll c = rf[k]; // = k!

	ll bc = (b * c) % mod;

	return (a * bc) % mod;
}
int main(void) {
	int k;
	string s;
	cin >> k >> s;
	ll ans = 0, len = s.size();
	init();
	rep(i, 0, k + 1) {
		ans += C(i + len - 1, len - 1) * mpower(25, i) % mod * mpower(26, k - i) % mod;
		ans %= mod;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 35628
#include <bits/stdc++.h>
using namespace std;
int main(){
//    cout << fixed << setprecision(10);
    long long n;
    cin>>n;
    long long ans =0;
    ans += (n/500)*1000;
    n = n%500;
    ans += (n/5)*5;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

void load(void);
void output(void);

int a;

int main(){
	load();
	output();
	return 0;
}

void load(void){
	cin >> a;
}

void output(void){
	int res;
	res = a + a*a + a*a*a;
	cout << res;
}

Measured memory_bytes: 3616
import java.io.*;

class Main{
    public static void main (String[ ] args) throws Exception{
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
        
        String str = br.readLine();
        int cnt = Integer.parseInt(str);

        int min = Integer.MAX_VALUE, max = Integer.MIN_VALUE;
        long sum = 0;
        str = br.readLine();
        String[] strArr = str.split(" ");
        for(int loop = 0; loop < cnt; loop++)
        {
            int i = Integer.parseInt(strArr[loop]);
            if(i < min)
            {
                min = i;
            }
            if(i > max)
            {
                max = i;
            }
            sum += i;
        }
        
        System.out.println(min + " " + max + " " + sum);
    }
}

Measured memory_bytes: 28548
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;

int main() {
	string s;
	int w;
	cin >> s >> w;
	for (int i = 0; i < s.size(); i += w) cout << s[i];
	cout << endl;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << " " << a * 2 + b * 2 << endl;
}


Measured memory_bytes: 3112
import math

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

cnt = 0
tmp = 0

for i in range(N-1):
    for j in range(i+1, N):
        for d in range(D):
            tmp += (X[i][d] - X[j][d])**2
        if is_integer_num(math.sqrt(tmp)):
            cnt += 1
        tmp = 0

print(cnt)


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

# define rep(i, n) for(int(i)=0;(i)<(n);(i)++)
# define reps(i, n) for(int(i)=1;(i)<=(n);(i)++)
# define rrep(i, n) for(int i=((int)(n)); i>0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>=0; --i)
# define ALL(v) v.begin(), v.end()
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<typename T> void dump(T e){std::cout << e << std::endl;}
template<typename T> void dump(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void dump(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ dump(v); } }
typedef long long ll;


int main(){
  int n;
  string word;cin >> word >> n;
  rep(i,n) {
    string op,rep;
    int s,e;
    cin >> op >> s >> e;
    if (op == "replace") {
      cin >> rep;
      word.replace(s,e-s+1,rep);
    }
    if (op == "reverse") {
      reverse(word.begin() + s, word.begin() + e + 1);
    }
    if (op == "print") {
      cout << word.substr(s,e-s+1) << endl;
    }
  }
}



Measured memory_bytes: 3228
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <chrono>
#include <stack>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

llong pow(int x, int n) {
    llong ans = x;
    if (n == 0) return 1;

    for(int i = 0; i < n - 1; i++) {
        ans *= x;
    }

    return ans;
}

void swap(int *X, int *Y){
    int t = *X; *X = *Y; *Y = t;
}

int main() {
    int a, b, x;
    cin >> a >> b >> x;
    if (a + b >= x && a <= x) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define max(a, b) ((a)>(b)?(a):(b))
#define min(a, b) ((a)>(b)?(b):(a))
long N, u, v, ans;
main(){
	scanf("%ld", &N);
	ans = N * (N+1) * (N+2) / 6;
	for(int i=1; i<N; i++){
		scanf("%ld%ld", &u, &v);
		ans -= min(u,v) * (N+1-max(u,v));
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 1736
package main
import (
	"fmt"
)

func main(){
	var s,r string
	var n int
	fmt.Scanf("%d",&n)
	fmt.Scanf("%s",&s)
	for _,value := range s{
		r=r+string((byte(value)+byte(n)-'A')%26+'A')
	}
	fmt.Println(r)
}

Measured memory_bytes: 6656
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x,int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
		return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int a[11111];
signed main() {
	int n,ans=0;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for(int i=0;i<n;i++){
		while (a[i] % 2 == 0) {
			a[i] /= 2;
			ans++;
		}
	}
	cout << ans << endl;
	ll
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main(void)
{
	int a,s,d,f,g,h,i,j;
	scanf("%d",&a);
	while(a!=0){
		g=-10;
		h=0;
		for(i=1;i<=a;i++){
			scanf("%d %d %d",&s,&d,&f);
			if(g<f+d){
				g=f+d;
				h=s;
			}
		}
		printf("%d %d\n",h,g);
		scanf("%d",&a);
	}
	return 0;
}

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

ll euclid(ll a, ll b){
    while(1){
        ll c=a%b;
        if(c==0){
            return b;
        }
        else{
            a=b;
            b=c;
            continue;
        }
    }
}

ll ans(ll x, ll y, ll z){
    ll k=x/y+x/z;
    ll l=(y*z)/euclid(y,z);
    k-=x/l;
    return x-k;
}

int main()
{
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    cout << ans(B,C,D)-ans(A-1,C,D) << endl;
}

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


signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    int a[n];
    int b[n];
    map<int,int> mp;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i] = a[i];
        mp[a[i]]=0;
    }
    int cnt=0;
    for(auto &i:mp){
        i.second = cnt;
        cnt++;
    }
    reverse(b,b+n);
    vector<vector<int>> u(cnt),v(cnt);
    for(int i=0;i<n;i++){
        a[i] = mp[a[i]];
        b[i] = mp[b[i]];
        u[a[i]].push_back(i);
        v[b[i]].push_back(i);
    }
    int ui[cnt]={},vi[cnt]={};
    int l=0,r=0;
    bool fi = true;
    for(int i=0;i<n;i++){
        r = max(r,v[a[i]][vi[a[i]]]);
        vi[a[i]]++;
        if(i==r){
            if(!fi) cout << " ";
            cout << i+1;
            fi = false;
        }
    }
    cout << endl;
}


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

int main(int argc, char **argv)
{
    int N, x;
    std::cin >> N >> x;

    std::vector<int> a(N);
    for(int i = 0; i < N; i++){
        std::cin >> a.at(i);
    }

    std::sort(a.begin(), a.end());

    int sum = 0;
    for(int i = 0; i < N-1; i++){
        if(x >= a.at(i)){
            x -= a.at(i);
            sum++;
        }
    }
    if(x == a.at(N-1)) sum++;
    
    std::cout << sum << std::endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) throws IOException {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int answer = ((n-m) * 100 + m * 1900) * (int)Math.pow(2,m);
    System.out.println(answer);
    }
  }


Measured memory_bytes: 21716
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
// #include <bits/stdc++.h>
#include <vector>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <iostream>
#include <random>
#include <queue>
#include <algorithm>
#include <climits>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <cstring>
#include <deque>

 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<cd> vcd;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vl> vvl;


#define FOR(i,a,b) for (int i=a; i<b; i++)
#define F0R(i,a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = b; i > a; i--)
#define F0Rd(i,a) for (int i = a; i > -1; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define que queue
#define pa pair
#define ex(m,i) m.find(i)!=m.end()
#define nex(m,i) m.find(i)==m.end()
#define ms(arr,i) memset(arr,i,sizeof(arr))

#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int inf = 1e9;
const int MX = 100001; //check the limits, dummy
const double epsilon = 1e-12;
const int ds[4][2] = {
    {-1,0},
    {1,0},
    {0,-1},
    {0,1}
};

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

    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);

    ll a, b, c, d; cin >> a >> b >> c >> d;
    printf("%lld\n",max(max(a*c,b*d),max(a*d,b*c)));
    
    return 0;
}

Measured memory_bytes: 3200
#include<stdio.h>

#define MAX 44

int fibDP[ MAX+1 ];

int fib( int n )
{
	if( 0 == n || 1 == n ) { return 1; }
	if( 0 != fibDP[n] ) { return fibDP[n]; }
	
	fibDP[n] = fib( n-1 ) + fib( n-2 );
	
	return fibDP[n];
}

int main( void ) 
{   
    int n;
	       
    scanf( "%d", &n );
    
	printf( "%d\n", fib( n ) );

    return 0;
}

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

#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const ll N = 5e5 +9;

ll a, b[N], t, c, n, m;
string s;
vector <int> v;
int main(){
    cin >> n >> m;
    if(n % m == 0){
        cout<<0;
        return 0;
    }
    cout<<1;

        return 0;
}


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

using namespace std;

int main() {
  int N, M, S, T;
  cin >> N >> M;
  vector<pair<int, int>> nodes(M);
  vector<vector<int>> edges(N);
  for (auto &node : nodes) {
    cin >> node.first >> node.second;
    edges[node.first - 1].push_back(node.second - 1);
  }
  cin >> S >> T;
  S--; T--;
  
  vector<vector<int>> flag(N, vector<int>(3, -1));
  queue<pair<int, int>> que;
  que.push(make_pair(S, 0));
  
  while(!que.empty()) {
    int edge = que.front().first;
    int num = que.front().second;    
    que.pop();
    if (edge == T && num % 3 == 0) {
      cout << num / 3 << endl;
      return 0;
    }
    if (flag[edge][num % 3] == -1) {
      flag[edge][num % 3] = num;
      for (int next : edges[edge])
        que.push(make_pair(next, num + 1));
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 12032
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            A();
        }

        static void A()
        {
            var S = Read();
            Println(DateTime.Parse(S) <= DateTime.Parse("2019-04-30") ? "Heisei" : "TBD");
        }

        static List<int> ReadLines(int n)
        {
            var l = new List<int>();
            for (int i = 0; i < n; i++)
            {
                l.Add(ReadInt());
            }
            return l;
        }

        static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0 || start > stop || (start <= 0 && stop <= 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        static int SumDigits(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        static int Gcd(int a, int b) => b == 0 ? a : Gcd(b, a % b);

        static bool IsPrime(int x)
        {
            if (x <= 1 || (x != 2 && x % 2 == 0)) return false;
            if (x == 2) return true;

            for (int i = 3; i < x; i += 2)
                if (x % i == 0) return false;

            return true;
        }

        static string Read() => Console.ReadLine();
        static int ReadInt() => int.Parse(Read());
        static long ReadLong() => long.Parse(Read());

        static List<string> ReadSplit() => Read().Split().ToList();
        static List<int> ReadSplitInt() => Read().Split().Select(int.Parse).ToList();
        static List<long> ReadSplitLong() => Read().Split().Select(long.Parse).ToList();

        static void Print(object value) => Console.Write(value.ToString());
        static void Println(object value) => Console.WriteLine(value.ToString());

        static string Join<T>(IEnumerable<T> list) => string.Join("", list);
    }

    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }
}


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

int main() {
  int n, k;
  int l[50] = {};

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

  sort(l,l+n, greater<int>());

  int ans = 0;
  for(int i = 0; i < k; i++){
    ans += l[i];
  }
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
 
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};
 
const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
 
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int H, R;
    cin >> H >> R;

    if(H + R == 0)
        cout << 0 << endl;
    else 
    {
        if(H + R < 0)
            cout << -1 << endl;
        else 
            cout << 1 << endl;
    }
    return 0;
}
 


Measured memory_bytes: 3048
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a , b;
    cin >> a >> b;
    if ( a.length() > b.length() ) cout << "GREATER";
    else if ( a.length() < b.length() ) cout << "LESS";
    else {
        for ( int i = a.length() - 1 ; i >= 0 ; i-- ) {
            if ( a > b ) {
                cout << "GREATER";
                return 0;
            } else if ( a < b ) {
                cout << "LESS";
                return 0;
            }
        }
        cout << "EQUAL";
    }
}


Measured memory_bytes: 256
H = dict([])
N = int(input())
L = [input() for _ in range(N)]

ctr = 0
for i in range(N):
    H[L[i]] = 0
    if len(H) == ctr:
        H.pop(L[i])
    ctr = len(H)
    
        
        
print(len(H))

Measured memory_bytes: 19468
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
ll a[3];
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
cout<<a[1]-a[0]+a[2]-a[1]<<endl;
}









Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int xC2(int x){
        int A;
        if(x>1)
            A= x*(x-1)/2;
        else
            A = 0;
        
        return A;
        }
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
        int M = stdIn.nextInt();

        int E = 0;
        E = xC2(N) + xC2(M);

        System.out.print(E);



    }
}

Measured memory_bytes: 22740
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;

class Main{


	public static void main(String[] a){


		Scanner sc = new Scanner(System.in);



		while(sc.hasNext()) {

			int n = sc.nextInt();

			if(n == 0){break;}


			int syainNo;
			int tanka;
			int suryo;
			int goukei;
			Map<Integer, Integer> map = new LinkedHashMap<>();

			for(int i = 0; i < n; i++) {
				syainNo = sc.nextInt();
				tanka = sc.nextInt();
				suryo = sc.nextInt();
				goukei = tanka * suryo;

				if(map.get(syainNo) == null) {
					map.put(syainNo, goukei);
				}else{
					map.put(syainNo, map.get(syainNo) + goukei);
				}

			}

			int count = 0;
			for(int no: map.keySet()) {
				int data = map.get(no);

				if(data >= 1000000) {
					System.out.println(no);
					count++;
				}

			}
			if(count == 0) {System.out.println("NA");}


		}


	}
}

Measured memory_bytes: 35464
import java.util.*;
class Main
{
 public static void main(String[] args)
 {
   Scanner s = new Scanner(System.in);
   char[] c  =s.next().toCharArray();
   long c1=0,c2=0;
   for(int i=0;i<c.length;i++)
   {
     if(c[i]=='W')
     {
       c1+=c2;
     }
     else
     {
      	c2++;
     }
   }
   System.out.println(c1);
 }
}

Measured memory_bytes: 28444
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int i,n,a[N];

void solve()
{
    cin>>n;
    for(i=1;i<=n;++i)
    {
        cin>>a[i];
    }
    sort(a+1,a+n+1);
    int ans=a[n],last=n-1,curr=0;
    for(i=1;i<=n-2;++i)
    {
        if(!curr)
        {
            ans+=a[last];
            curr^=1;
        }
        else
        {
            ans+=a[last];
            curr^=1;
            last--;
        }
    }
    cout<<ans;
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


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

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える


int main(){
    int n, m; cin >> n >> m;
    int a[n];
    rep(i, m) cin >> a[i];

    int s = 0;
    rep(i, m) s += a[i];

    if(s > n) cout << -1 << endl;
    else cout << n - s << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
   int n;
    cin >> n;
    
   int a[n];
    f(i,n) cin >> a[i];
   
   sort(a,a+n);
    
   int res = a[n-1];
    
   int v = n-2; 
    
   for(int i=2;i<n;i+=2)
   {
       if(i == n-1) res-=a[v];
       res+=a[v] + a[v];
       v--;
   }
    
   cout << res; 
     
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 5192
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		System.out.println(eulerPhi(n));
	}
	static long eulerPhi(long n) {
		long ret = n;
		for (long i = 2; i * i <= n; i++) {
			if (n % i == 0) {
				ret -= ret / i;
				while (n % i == 0) {
					n /= i;
				}
			}
		}
		if (n > 1) {
			ret -= ret / n;
		}
		return ret;
	}
}


class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 24416
from collections import deque

def main():
    n=int(input())
    l=[0]*n
    d={}
    for i in range(n-1):
        a,b,c=map(int,input().split())
        a-=1
        b-=1
        if a in d:
            d[a].add((b,c))
        else:
            d[a]={(b,c)}
        if b in d:
            d[b].add((a,c))
        else:
            d[b]={(a,c)}
    q,k=map(int,input().split())
    k-=1
    p=deque([k])
    while len(p):
        w=p.popleft()
        for i in d[w]:
            if (l[i[0]]==0 and i[0]!=k) or (l[i[0]]!=0 and l[i[0]]>l[w]+i[1]):
                l[i[0]]=l[w]+i[1]
                p.append(i[0])

    for i in range(q):
        x,y=map(int,input().split())
        print(l[x-1]+l[y-1])
if __name__ == '__main__':
    main()

Measured memory_bytes: 61732
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int INF=(int)1e9+7;

int main(){
    //入力パート 1問目と同じ
    int n; cin>>n;
    vector<pair<int,int>> tonari[100010]; //隣接リスト 一つ目が行先の頂点で二つ目が辺のコスト
    vector<int> dist(n,INF); //各頂点の（暫定）最短距離を格納
    vector<bool> det(n,false); //各頂点の最短距離が確定しているか格納
    for(int i=0;i<n;++i){
        int u,k,c,v;
        cin>>u>>k;
        for(int j=0;j<k;++j){
            cin>>c>>v;
            tonari[u].push_back(make_pair(c,v));
        }
    }
    //探索パート
    dist[0]=0; //出発地点の最短距離は0
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<>> pq; //1つ目は暫定最短距離，2つ目が頂点番号
    pq.push(make_pair(0,0));
    while(!pq.empty()){
        pair<int,int> node=pq.top();
        pq.pop();
        if(det[node.second]) continue;
        det[node.second]=true;
        for(auto tsugi:tonari[node.second]){
            if(dist[tsugi.first]>dist[node.second]+tsugi.second){
                 dist[tsugi.first]=dist[node.second]+tsugi.second;
                 pq.push(make_pair(dist[tsugi.first],tsugi.first));
            }
        }
    }
    //出力パート 1問目と同じ
    for(int i=0;i<n;++i){
        cout<<i<<" "<<dist[i]<<endl;
    }
    return 0; 
}



Measured memory_bytes: 10148
let n = Int(readLine()!)!
let divider = 1000_000_000 + 7
let aArray = readLine()!.split(separator: " ").map{Int($0)!}
var sum = 0
var accumulatedSum = 0
for i in 0..<n-1 {
    let j = n - 1 - i
    accumulatedSum += aArray[j] % divider
    accumulatedSum %= divider
    sum += accumulatedSum * aArray[j-1] % divider
    sum %= divider
}
print(sum)




Measured memory_bytes: 21228
import sys
sys.setrecursionlimit(100000)

def count(h, w, fruits):
    if h < 0 or h >= H:
        return False
    if w < 0 or w >= W:
        return False
    if fruits == '_':
        return False
    if fruits != land[h][w]:
        return False
    land[h][w] = '_'
    count(h+1, w, fruits)
    count(h-1, w, fruits)
    count(h, w+1, fruits)
    count(h, w-1, fruits)

while True:

    H, W = list(map(int, input().split()))

    if H == 0:
        break

    ans = 0

    land = [list(input()) for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if land[i][j] != '_':
                ans += 1
                count(i, j, land[i][j])

    print(ans)





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

using namespace std;



int main()
{
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(), greater<char>());
  if(s>=t)
     printf("No");
  
  else
     printf("Yes");
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

struct SegmentTree{
	seg: Vec<i64>,
	sz: usize,
}
	
impl SegmentTree {
	fn new(n: usize) -> SegmentTree {
		let mut sz: usize = 1;
		while sz < n { sz *= 2; }
		
		SegmentTree {
			seg: vec![0; 2 * sz],
			sz : sz,
		}
	}
	
	fn add(&mut self, mut k: usize, x: i64) {
		k += self.sz - 1;
		self.seg[k] += x;
		
		while k > 0 {
			k = (k - 1) / 2;
			self.seg[k] = self.seg[2 * k + 1] + self.seg[2 * k + 2];
		}
	}
	
	fn _get(&self, a: usize, b: usize, k: usize, l: usize, r: usize) -> i64 {
		if b <= l || r <= a { return 0; }
		if a <= l && r <= b { return self.seg[k]; }
		
		SegmentTree::_get(self, a, b, 2 * k + 1, l, (l + r) / 2) + SegmentTree::_get(self, a, b, 2 * k + 2, (l + r) / 2, r)
	}
	
	fn get(&self, a: usize, b: usize) -> i64 {
		SegmentTree::_get(self, a, b, 0, 0, self.sz)
	}
}

fn main() {
	let (n, q): (usize, usize) = (read(), read());
	let mut seg: SegmentTree = SegmentTree::new(n);
	
	for i in 0 .. q {
		let (mut a, mut b, c): (usize, usize, usize) = (read(), read(), read());
		
		if a == 0 {
			SegmentTree::add(&mut seg, b - 1, c as i64);
		} else if a == 1 {
			let s: i64 = SegmentTree::get(&seg, b - 1, c);
			
			println!("{}", s);
		}
	}
}



Measured memory_bytes: 7072
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
#define sz(x) (ll)x.size()
#define lnt(s) (ll)s.length()
#define mt(cnt) cnt.empty()
using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> osSet;

using pll = pair<ll, ll>;
using pl = pair<ll, pll>;
using tll = tuple<ll, ll, ll>;

const ll maxN = 1e5;
const ll INF = 1e17;
const ll MOD = 1e9 + 7;

ll xs[] = {-1, 1, 0, 0, -1, 1, 1, -1};
ll ys[] = {0, 0, -1, 1, -1, 1, -1, 1};

ll segtree[maxN << 2];
ll lazy[maxN << 2];
ll A[maxN];

inline ll left(ll x){
	return x << 1;
}

inline ll right(ll x){
	return (x<<1) + 1;
}

ll func(ll x){
	return (x*(x+1))/2;
}

ll _pow(ll b, ll p){
	if(p == 0) return 1;
	if(p == 1) return b;
	ll exB = b*b;
	if(p&1) return b*_pow(exB, p/2);
	return _pow(exB, p/2);
}

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n, m, x, y;
	cin >> n >> m;
	ll ans = 0;
	while(n--){
		cin >> x >> y;
		if(sqrt(x*x + y*y) <= m)
			ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3692
#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
	int N, L;
	scanf("%d %d", &N, &L);
	L--;

	int taste[201];
	int total = 0;
	int i;
	for (i = 1; i <= N; i++) {
		taste[i] = i + L;
		total += taste[i];
	}
	int j;
	int res = 0;
	int diff = 10000;
	for (i = 1; i <= N; i++) {
		int total2 = 0;
		for (j = 1; j <= N; j++) {
			if (i == j)
				continue;
			total2 += taste[j];
		}
		int d = abs(total - total2);
		if (diff > d) {
			res = total2;
			diff = d;
		}
	}
	printf("%d\n", res);
	return (0);
}


Measured memory_bytes: 128
use std::io::stdin;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.clear();
    stdin().read_line(&mut buf).unwrap();
    let upper: i32 = buf.trim().parse().unwrap();
    buf.clear();
    stdin().read_line(&mut buf).unwrap();
    let axises: Vec<i32> = buf.trim().split_whitespace().map(|iter| iter.parse::<i32>().unwrap()).collect();
    println!("{}", solve(upper, axises));
}

fn solve(upper: i32, axises: Vec<i32>) -> i32{
    axises.iter().map(|&axis| min(axis, upper - axis)).sum::<i32>() * 2
}

Measured memory_bytes: 4352
a,b,c = map(int,input().split())

arr = [a, b, c]
# if arr[0] > arr[1]:
#     arr[0], arr[1] = arr[1], arr[0] 
# if arr[1] > arr[2]:
#     arr[1], arr[2] = arr[2], arr[1] 
# if arr[0] > arr[1]:
#     arr[0], arr[1] = arr[1], arr[0] 

arr.sort()

print(arr[0], arr[1], arr[2])


Measured memory_bytes: 5592
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
using namespace std;


int main() {
	string a;
	cin >> a;
	for(int i = 0; i < a.size(); ++i) cout << 'x';
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    int count,count2;
    count = Math.abs(a-b);
    count2 = Math.abs(b-c);
		if(count<=d && count2<=d){
          System.out.println("Yes");
    }
    else if(Math.abs(a-c)<=d){
          System.out.println("Yes");
    }
    else{
          System.out.println("No");
    }
  }
 }


Measured memory_bytes: 23892
n = int(input())
a = [0]*n
for i in range(n):
  a[i] = int(input())

x = sorted(set(a), reverse = True)
t = [0]*2
if len(x) > 1:
  t[0],t[1] = x[0],x[1]
else:
  t[0],t[1] = x[0],x[0]
  
max = t[0]
count= a.count(max)
for i in range(n):
  if a[i] == max:
    if count > 1:
      print(max)
    else:
      print(t[1])
  else:
    print(max)
  

Measured memory_bytes: 17004