akhauriyash/Code-Regression huggingface dataset:
n,a,b =map(int,input().split())
ans = 0
for i in range(1,n+1):
    # print(i)
    # print(list(str(i)))
    s = sum(int(j) for j in list(str(i)))
    # print(s)
    # print(a <= s and s <= b)
    if a <= s and s <= b:
        ans += i
print(ans)
    

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

int main()
{
    int k;
    cin>>k;
    int l,r;
    cin>>l>>r;
    for(int i=l/k;i<=r/k+1;i++)
    {
        if(i*k>=l&&i*k<=r)
        {
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3624
m,d = map(int,input().split())
ans = 0
for i in range(1,m+1):
    for j in range(10,d+1):
        d1 = j%10
        d2 = j//10
        if d1 >= 2 and d2 >= 2 and d1*d2 == i:
            ans += 1
print(ans)

Measured memory_bytes: 3060
String.prototype.rjust = function(dig) {
  var pre = '';
  for (var i = 0; i < dig; i++) { pre += ' '; }
  return (pre + this).slice(-dig);
};
Number.prototype.rjust = function(dig) {
  return (this+'').rjust(dig);
};
Array.prototype.rjust = function(dig) {
  return this.map(function(m) { return m.rjust(dig); });
};
Array.prototype.sum = function() {
  return this.reduce(function(m, n) { return +n + m; }, 0);
};

var d = require("fs").readFileSync("/dev/stdin", "utf8").trim().split('\n');
while (d[0] !== '0') {
  var lc = +d.shift();
  var sums = [];
  var lastLine = [];
  for (var i = 0; i < lc; i++) {
    var nums = d.shift().split(' ');
    sums.push(nums);
    nums.push(nums.sum());
    console.log(nums.rjust(5).join(''));
  }
  for (var i = 0; i < lc+1; i++) {
    lastLine.push(sums.map(function(n) { return n[i]; }).sum());
  }
  console.log(lastLine.rjust(5).join(''));
}

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

using namespace std;

typedef long long ll;

const int N_MAX = 100002;

int n, k;

ll a[N_MAX];

ll sp[N_MAX];

ll spp[N_MAX];

int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++)
        sp[i] = sp[i - 1] + a[i];
    for(int i = 1; i <= n; i++)
        spp[i] = spp[i - 1] + a[i] * (a[i] > 0);
    ll ans = 0;
    for(int i = k; i <= n; i++)
        ans = max(ans, spp[n] - spp[i] + spp[i - k] + max(0LL, sp[i] - sp[i - k]));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 2560
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias Pair = Tuple!(long, "number", long, "times");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n = lread();
    auto all_have = new long['z' - 'a' + 1];
    foreach (i; 0 .. n)
    {
        auto s = sread();
        auto now = new long['z' - 'a' + 1];
        foreach (e; s)
        {
            if (!i)
                all_have[e - 'a']++;

            now[e - 'a']++;
        }
        foreach (e; 'a' .. 'z' + 1)
        {
            all_have[e - 'a'] = min(now[e - 'a'], all_have[e - 'a']);
        }
    }
    foreach (i, e; all_have)
    {
        if(e)
        {
            long j;
            while(j++ < e)
                write(cast(char)('a' + i));
            
        }
    }
    writeln();
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		HashSet<Integer> st=new HashSet<Integer>();
		for(int i=0;i<3;i++)
			st.add(ir.nextInt());
		out.println(st.size());
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

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

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 23124
#define _USE_MATH_DEFINES /*これがないと円周率M_PIが使えない*/
#include<stdio.h>
#include<math.h>

typedef struct {
	double x;
	double y;
} Point;

void koch(int d, Point p1, Point p2) {
	double th = M_PI * 60.0 / 180.0;

	if (d == 0) {
		return;
	}
	
	Point s = {0, 0}, t = { 0, 0 }, u = { 0, 0 };

	s.x = (2 * p1.x + 1 * p2.x) / 3;
	s.y = (2 * p1.y + 1 * p2.y) / 3;
	t.x = (1 * p1.x + 2 * p2.x) / 3;
	t.y = (1 * p1.y + 2 * p2.y) / 3;
	u.x = (t.x - s.x)*cos(th) - (t.y - s.y)*sin(th) + s.x;
	u.y = (t.x - s.x)*sin(th) + (t.y - s.y)*cos(th) + s.y;

	koch(d - 1, p1, s);
	printf("%f %f\n", s.x, s.y);
	koch(d - 1, s, u);
	printf("%f %f\n", u.x, u.y);
	koch(d - 1, u, t);
	printf("%f %f\n", t.x, t.y);
	koch(d - 1, t, p2);

}

int main() {
	Point p1 = { 0,0 };
	Point p2 = { 100, 0 };
	int n;

	scanf("%d", &n);

	printf("%f %f\n", p1.x, p1.y);
	koch(n, p1, p2);
	printf("%f %f\n", p2.x, p2.y);
 
	return 0;
}


Measured memory_bytes: 2104
from itertools import product
from heapq import *

X,Y,Z,K,*f = map(int, open(0).read().split())
A = f[:X]
B = f[X:X+Y]
C = f[X+Y:]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
AB = [sum(x) * (-1) for x in product(A,B)]
heapify(AB)
AB_picked = []
for i in range(K):
    if AB:
        AB_picked.append(heappop(AB)*(-1))
    else:
        break
ABC = [sum(x) * (-1) for x in product(AB_picked,C)]
heapify(ABC)
for i in range(K):
    print(heappop(ABC)*(-1))

Measured memory_bytes: 231268
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const N = parseInt(args[0][0], 10)
	const H = args[1].map(arg => parseInt(arg, 10))
	let ans = true
	let cur = H[0]

	for (let i = 0; i < N - 1; i++) {
		if (H[i + 1] - 1 >= cur) {
			cur = H[i + 1] - 1
		} else if (H[i + 1] >= cur) {
			cur = H[i + 1]
		} else {
			ans = false
		}
	}

	if (ans) console.log('Yes')
	else console.log('No')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 19776
class UnionFind:
    def __init__(self, size):
        self.parents = [-1] * size

    def find(self, x):
        while self.parents[x] > 0:
            x = self.parents[x]
        return x

    def union(self, i, j):
        pi, pj = self.find(i), self.find(j)
        if pi == pj:
            return
        if self.parents[pi] < self.parents[pj]:
            pi, pj = pj, pi
            i, j = j, i
        self.parents[pi] += self.parents[pj]
        self.parents[pj] = pi
        self.reconnect(j, pi)

    def reconnect(self, i, j):
        while self.parents[i] > 0:
            t = self.parents[i]
            self.parents[i] = j
            i = t


def main():
    n, m, *ab, = map(int, open(0).read().split())
    uf = UnionFind(n + 1)

    for i, j in zip(ab[::2], ab[1::2]):
        uf.union(i, j)

    print(-min(uf.parents))


if __name__ == '__main__':
    main()


Measured memory_bytes: 57256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		int m = scanner.nextInt();

		int[][] A; 
		A = new int[n][m];//行列Aを2次元配列で表す
		int[] B;
		B = new int[m];//ベクトルBは1次元の数列

		for(int a=0;a<n;a++){
			for(int b=0;b<m;b++){
				int c =	scanner.nextInt();
				A[a][b]=c;//行列Aの入力
			}
		}

		for(int a=0;a<m;a++){
			int d =scanner.nextInt();
			B[a]=d;//ベクトルBの入力
		}

		int ci=0;//積ciのための変数

		for(int a=0;a<n;a++){
			ci=0;//計算終了後に初期化
			for(int b=0;b<m;b++){
				ci =ci+( A[a][b]*B[b]);
			}
			System.out.println(ci);

		}
		
		scanner.close();
	}
}



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001;

int N;
vpint G[111111];
int cnt[111111];

/*
void dfs(int v,int p,int a){
    int x=0;
    for(auto &e:G[v]){
        if(e.fi==p)continue;
        dfs(e.fi,v,e.se);
        x^=e.
    }

}*/

int dist[1<<16];

signed main(){
    cin>>N;
    rep(i,N-1){
        int x,y,a;
        cin>>x>>y>>a;
        G[x].pb({y,a});
        G[y].pb({x,a});
    }

    rep(i,N-1){
        int x=0;
        for(auto &e:G[i])x^=e.se;
        if(x)cnt[x]++;
    }

    int ans=0;
    int mask=0;
    rep(i,16){
        ans+=cnt[i]/2;
        mask|=(cnt[i]%2)<<i;
    }


    fill_n(dist,1<<16,INF);
    dist[mask]=0;
    priority_queue<pint,vector<pint>,greater<pint>>que;
    que.push({0,mask});
    while(que.size()){
        int c,b;
        tie(c,b)=que.top();
        que.pop();
        if(dist[b]<c)continue;
        rep(i,16)if(b>>i&1){
            int bb=b^(1<<i);
            if(dist[bb]>dist[b]+1){
                dist[bb]=dist[b]+1;
                que.push({dist[bb],bb});
            }
        }

        rep(i,16)for(int j=i+1;j<16;j++){
            if(!(b>>i)||!(b>>j))continue;
            int cc=c;
            int bb=b;
            cc++;
            bb^=(1<<i);
            bb^=(1<<j);
            int k=j^i;
            if(bb>>k&1){
                bb^=(1<<k);
                cc++;
            }
            else{
                bb|=1<<k;
            }
            if(dist[bb]>cc){
                dist[bb]=cc;
                que.push({cc,bb});
            }
        }
    }

    cout<<ans+dist[0]<<endl;
    return 0;
}


Measured memory_bytes: 9848
//#include <bits/stdc++.h>
#include <iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#define i64 long long
#define vi32 vector<int>
#define vi64 vector<long long>
#define  ii pair<int,int>
const long long mod = 1e6+3, inf = 1e9, linf = 1e18;
using namespace std;
#define pb push_back
#define mp make_pair
#define N 1000003
using namespace std;
i64 f[N+3];
//int pre[N];
i64 fast(i64 a, i64 b)
{
	if (b == 0)return 1;
	i64 d = fast(a, b / 2);
	d = (d % mod * d % mod) % mod;
	if (b % 2)return a * d% mod;
	return d % mod;
}
i64 rev(i64 x)
{
	return fast(x,mod-2);
}
void slv(i64 x, i64 d, i64 n)
{
	if (x == 0)
	{
		cout << "0\n";
		return ;
	}
	if (d == 0)
	{
		cout << fast(x, n) << endl;
		return;
	}
	i64 cur = x * rev(d)%mod;
	if (cur + n - 1 >= mod)
	{
		cout << "0\n";
		return;
	}
	i64 res = f[cur + n - 1] * rev(f[cur - 1]) % mod;
	//cout << f[cur + n - 1] << " " << rev(f[cur - 1]) << endl;
	res = (fast(d, n)%mod * res % mod)%mod;
	cout << res << endl;
}
int main()
{
	f[0] = f[1] = 1;

	f[0] = 1;
	for (int i = 1; i < mod; i++)
		f[i] = (f[i-1]*i)%mod;
	//cout << f[500008];
	int q;
	cin >> q;
	while (q--)
	{
		i64 x, d, n;
		cin >> x >> d >> n;
		slv(x,d,n);
	}
}

Measured memory_bytes: 8704
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <map>
#define ll long long
#define Inf 1000000000
#define MAXN 100000
using namespace std;

int A[222222];
int B[222222];
int C[222222];

int BinarySearch1(int x, int N) {
    if (C[0] >= x)
        return -1;
    int low=0;
    int high=N-1;
    while(low < high) {
        int mid = (low + high+1)/2;
        if (C[mid] >= x) {
            high=mid-1;
        } else {
            low = mid;
        }
    }
    return low;
}


// A[lowid] > B[i]
int BinarySearch2(int x, int N) {
    if (A[N-1] <= x)
        return -1;
    int low=0;
    int high=N-1;
    while(low < high) {
        int mid = (low + high)/2;
        if (A[mid] <= x) {
            low=mid+1;
        } else {
            high = mid;
        }
    }
    return low;
}


int main() {

    int N;
    cin>>N;
    for(int i=0;i<N;i++)
        cin>>C[i];
    for(int i=0;i<N;i++)
        cin>>B[i];
    for(int i=0;i<N;i++)
        cin>>A[i];
    
    sort(A,A+N);
    sort(B,B+N);
    sort(C,C+N);
    
    
    int lowid=0;
    int highid=N-1;
    ll ans = 0;
    for(int i=0;i<N;i++) {
        
        
        ll id1 = BinarySearch1(B[i],N);
        ll id2 = BinarySearch2(B[i],N);
        

        
        
        if (id1 == -1 || id2 == -1)
            continue;
        ans += (id1+1)*(N-id2);

        
    }
    cout << ans << endl;
    

}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <deque>
#include <set>
#include <cmath>
#include <bits/stdc++.h>
#include <limits>

#define MOD 1000000007

using namespace std;

int main(void){
    // Your code here!
    long long n, min_count = LLONG_MAX;
    
    cin >> n;
    for(int i = 0; i < n; i++){
        long long temp, temp_count = 0;
        cin >> temp;
        while(temp % 2 == 0){
            temp_count++;
            temp /= 2;
        }
        min_count = min(min_count, temp_count);
    }
    
    cout << min_count << endl;
    
    return 0;
}

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

#define N 501

using namespace std;

int main() {
    int n;
    double p[N], q[N];
    double pSum[N][N], qSum[N][N];
    double d[N][N];
    double t;
    
    //標準入力から要素数を取得
    cin >> n;
    
    for(int i = 0; i < n; ++i) {
        //p[0]には代入しない
        //標準入力から探索確率を取得
        cin >> p[i];
    }
    
    for(int i = 0; i < n + 1; ++i) {
        //標準入力からダミーキーで探索終了する確率を取得
        cin >> q[i];
        
        //行列dの対角成分としてq[i]を格納
        d[i][i] = q[i];
    }
    
    //
    for(int i = 0; i < n; ++i) {
        pSum[i][i] = p[i];
        
        for(int j = i + 1; j < n; ++j) {
            pSum[i][j] = pSum[i][j - 1] + p[j];
        }
    }
    for(int i = 0; i < n + 1; ++i) {
        qSum[i][i] = q[i];
        for(int j = i + 1; j < n + 1; ++j) {
            qSum[i][j] = qSum[i][j - 1] + q[j];
        }
    }
    
    for(int i = 1; i < n + 1; ++i) {
        for(int j = 0; j < (n + 1) - i; ++j) {
            d[j][j + i] = __DBL_MAX__;
            
            for(int k = 0; k < i; ++k) {
                t = d[j][j + k] + d[j + k + 1][j + i] + pSum[j][j + i - 1] + qSum[j][j + i];
                d[j][j + i] = min(d[j][j + i], t);
            }
        }
    }
    
    printf("%.8lf\n", d[0][n]);
    
    return 0;
}


Measured memory_bytes: 9160
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int ninzuu = 0;
		
		D = D*2+1;
		do {
			N = N-D;
			ninzuu++;
		} while (N > 0);
		
		System.out.println(ninzuu);
		
		sc.close();
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int main(){
    int l;cin>>l;
    int n=0;
    for(int i=0;i<100;i++){
        if(l>=(1<<i)){
            n=i+1;
        }else{
            break;
        }
    }
    int m=(n-1)*2;
    int s=(1<<(n-1));
    for(int i=n-2;i>=0;i--){
        if((1<<i)<=l-s){
            s+=(1<<i);
            m++;
        }
    }
    s=(1<<(n-1));
    cout<<n<<" "<<m<<endl;
    for(int i=n-2;i>=0;i--){
        if((1<<i)<=l-s){
            cout<<i+1<<" "<<n<<" "<<s<<endl;
            s+=(1<<i);
        }
    }
    for(int i=1;i<n;i++){
        cout<<i<<" "<<i+1<<" "<<0<<endl;
        cout<<i<<" "<<i+1<<" "<<(1<<(i-1))<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long llong;

static const int MAX = 10;
int M[MAX][MAX];
int dp[1<<MAX][MAX];
int n, m;

int main(){
    cin >> n >> m;

    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++) M[i][j] = 0;
    }

    int x, y;
    for (int i = 0; i < m; i++){
        cin >> x >> y;
        x--; y--;
        M[x][y] = 1;
        M[y][x] = 1;
    }

    dp[1][0] = 1;

    int cnt;
    int sub;
    for (int i = 0; i < (1<<n); i++){
        for (int j = 0; j < n; j++){
            if (!(i & (1<<j))) continue;

            sub = i ^ (1<<j);
            for (int k = 0; k < n; k++){
                if (M[j][k] == 1) dp[i][j] += dp[sub][k];
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++){
        ans += dp[(1<<n) - 1][i];
    }
    cout << ans << endl;
    return 0;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll W, H, x, y;
    cin >> W >> H >> x >> y;

    long double S = W * H / 2.0;
    cout << setprecision(10) << S << " ";
    if (W % 2 == 0 && H % 2 == 0 && x == W / 2 && y == H / 2) {
        cout << 1;
    } else {
        cout << 0;
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define reverse(s) reverse(s.begin(),s.end())


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

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

int main(){
    int a,b;
    cin >> a >> b;

    if(a==1){
        a = 14;
    }
    if(b==1){
        b = 14;
    }
    
    if(a>b){
        puts("Alice");
    }else if(a==b){
        puts("Draw");
    }else{
        puts("Bob");
    }

    return 0;
}

Measured memory_bytes: 3632
nm=input().split()
vote=[int(i) for i in input().split()]
n=int(nm[0])
m=int(nm[1])
selectable=0
all=sum(vote)
for v in vote:
	if v < all/(4*m):
		continue
	else:
		selectable+=1
if selectable>=m:
	print("Yes")
else:
	print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <string>

using namespace std;

int main(void) {
	string s;
	cin >> s;
	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] == s[i + 1]) {
			printf("%d %d\n", i + 1, i + 2);
			return 0;
		}
		else if (i < s.size() - 2 && s[i] == s[i + 2]) {
			printf("%d %d\n", i + 1, i + 3);
			return 0;
		}
	}
	printf("-1 -1\n");
	return 0;
}

Measured memory_bytes: 512
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n,m;
	cin>>n>>m;
	vint a(n);
	rep(i,n) cin>>a[i],a[i]--;
	vll imos(2*m+10);
	vll v(2*m+10);
	ll sum_cost = 0;
	rep(i,n-1){
		int aa = a[i];
		int bb = a[i+1];
		if(bb < aa) bb += m;
		int cost = bb - aa;
		sum_cost += cost;
		// imos[aa]+=cost;
		// imos[aa+1]-=cost;
		imos[aa+2]--;
		imos[bb+1]++;
		imos[bb+1]+=cost-1;
		imos[bb+2]-=cost-1;
	}
	rep(i,2*m){
		if(i) imos[i] += imos[i-1];
		// cout<<imos[i]+sum_cost<<endl;
	}
	rep(i,2*m){
		if(i) imos[i] += imos[i-1];
		// cout<<imos[i]<<endl;
	}
	vll ans(m);
	rep(i,2*m) ans[i%m] += imos[i];
	sort(ALL(ans));
	cout<<ans[0]+sum_cost<<endl;

}


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

Measured memory_bytes: 4608
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	fmt.Println(max(a*b, c*d))
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
#define N 100005



int main() {

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    ll t=1;
    //cin>>t;

    while(t--) {
        ll n , m;
        cin>>n>>m;

        vector<bool>vec(n+2);
        for(int i=0;i<n+2;i++) vec[i] = true;

        ll h[n+2];
        for(int i=1;i<=n;i++) cin>>h[i];

        int x,y;

        for(int i=0;i<m;i++) {
            cin>>x>>y;

            if(h[x]>h[y]) {
                vec[y] = false;
            }
            else if(h[y]>h[x]) vec[x] = false;
            else vec[x] = vec[y] = false;
        }

        ll ans = 0;
        for(int i=1;i<=n;i++) {
            if(vec[i]) ans++;
        }

        cout<<ans<<"\n";
    }



}


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

int main(){

    int n,x,t;
    cin >> n >> x >> t;
    int i = 1;
    while(1){
        if(n <= x*i){
            cout << t*i << endl;
            return 0;
        }
        i += 1;
    }
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int N;
        int M;
        int[] Ai;
        int sum = 0;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            M = sc.nextInt();
            Ai = new int[M];
            for (int i = 0; i < M; i++) {
                sum +=  sc.nextInt();
            }
        }
        if(sum <= N){
            System.out.println(N -sum);
        }else{
            System.out.println(-1);
        }
    }
}


Measured memory_bytes: 46208
#include <stdio.h>

int main(void){
    
    int a,b;
    
    scanf( "%d %d",&a,&b );
    
    if( a == 1 ){
        a = 14;
    }
    if( b == 1 ){
        b = 14;
    }
    
    if( a > b ){
        printf("Alice");
    }
    else if( a < b ){
        printf("Bob");
    }
    else printf("Draw");
    
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;
namespace ConsoleTest {
  class Program {
    static void Main(string[] args) {
      int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
      if (a[0] + a[1] == 15) {
        Console.WriteLine("+");
      } else if (a[0] * a[1] == 15) {
        Console.WriteLine("*");
      } else {
        Console.WriteLine("x");
      }
    }
  }
}

Measured memory_bytes: 11348
#include<stdio.h>
#include<math.h>
int main()
{
    long long int n,m,i,k;
    scanf("%lld %lld",&n,&k);

    m=n%k;
    i=k-m;
    if(i<0) i=-i;
    if(m>i) m=i;

    printf("%lld\n",m);
}


Measured memory_bytes: 128
#!/usr/bin/env python3

def solve(N, d):
    total = 0
    for i1 in range(len(d)):
        for i2 in range(i1+1, len(d)):
            total += d[i1] * d[i2]
    return total


if __name__ == '__main__':
    N = int(input())
    d = map(int, input().split())

    ans = solve(N, list(d))

    print(ans)


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

int main(){
    int N;
    cin >> N;
    int ans = 0;
    int V[N];
    int C[N];
    for(int i = 0;i < N;i++){
        cin >> V[i];
    }
    for(int i = 0;i < N;i++){
        cin >> C[i];
    }
    for(int i = 0;i < N;i++){
        ans += max(0,V[i] - C[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//by Judge
#define HGS_AK_IOI true
#include<bits/stdc++.h>
#define Rg register
#define fp(i,a,b) for(Rg int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(Rg int i=(a),I=(b)-1;i>I;--i)
#define ll long long
using namespace std;
const int M=5e5+3;
typedef int arr[M];
#ifndef Judge
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
#endif
char buf[1<<21],*p1=buf,*p2=buf;
template<class T>inline bool cmax(T& a,T b){return a<b?a=b,1:0;}
inline void reads(string& s){ char c=getchar();
	for(;c!='<'&&c!='>';c=getchar()); s=">";
	for(;c=='<'||c=='>';c=getchar()) s+=c;
} int n,a[M]; string s; ll sum;
int main(){
	reads(s),n=s.length(),s+='<';
	fp(i,1,n){
		if(s[i-1]=='>'&&s[i]=='<'){
			fd(j,i-1,1){
				if(s[j]=='<') break;
				cmax(a[j],i-j);
			} fp(j,i+1,n){
				cmax(a[j],j-i);
				if(s[j]=='>') break;
			}
		}
	}
	fp(i,1,n) sum+=a[i];
	return !printf("%lld\n",sum);
}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p.at(i);
  int num = 0;
  rep(i, n - 2) {
    if (p.at(i + 1) > p.at(i) && p.at(i + 1) < p.at(i + 2)) num++;
    else if (p.at(i + 1) < p.at(i) && p.at(i + 1) > p.at(i + 2)) num++;
  }
  cout << num << endl;
}

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

typedef pair<int,int>P;
typedef pair<int,P>PP;

#define A first
#define B second.first
#define C second.second

PP pp(int a,int b, int c){
	PP t;
	t.A=a;
	t.B=b;
	t.C=c;
	return t;
}

PP north(PP t){
	return pp(7-t.B,t.A,t.C);
}

PP south(PP t){
	return pp(t.B,7-t.A,t.C);
}

PP west(PP t){
	return pp(7-t.C,t.B,t.A);
}

PP east(PP t){
	return pp(t.C,t.B,7-t.A);
}



int main(){
	int n;
	
	while(cin>>n,n){
		PP d=pp(1,2,3);
		
		while(n--){
			string s;
			cin>>s;
			if(s=="north"){
				d=north(d);
			}
			if(s=="east"){
				d=east(d);
			}
			if(s=="west"){
				d=west(d);
			}
			if(s=="south"){
				d=south(d);
			}
			
		}
		
		cout<<d.A<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
const int N = 2e5 + 4 , M = 1e6 + 3;
const int MOD = 998244353;
int a[N] , inv[M] , n , cnt[M] , f[M];

int mul(int a , int b , int m = MOD){
   return (1LL * (a % m) * (b % m)) % m;
}

int add(int a , int b , int m = MOD){
   return (1LL * (a % m) + (b % m) + MOD) % m;
}

int powMOD(int x , int n , int m = MOD){
   if(!n)return 1;
   int ret = 1;
   if(n & 1)ret = mul(x , powMOD(x , n - 1 , m) , m);
   else{
      int y = powMOD(x , n / 2 , m);
      ret = mul(y , y , m);
   }
   return ret;
}

void pre() {
   inv[0] = inv[1] = 1;
   for (int i = 2; i < M; i++) {
      inv[i] = (MOD - 1ll * (MOD / i) * inv[MOD % i] % MOD + MOD) % MOD;
   }
}

int solve(int g){
   int sum = 0;
   for(int i = g ; i < M ; i += g)
      sum = add(sum , mul(cnt[i] , i));
   int res = 0;
   for(int i = g ; i < M ; i += g)
      res = add(res , mul(mul(cnt[i] , i) , sum));
   for(int i = 2 * g ; i < M ; i += g)
      res = (res - f[i] + MOD) % MOD;
   return f[g] = res;
}

int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   cin >> n;
   for(int i = 0 ; i < n ; ++i)
      cin >> a[i] , cnt[a[i]]++;
   pre();
   int ans = 0;
   for(int i = M - 1 ; i >= 1 ; --i){
      int cur = (1ll * solve(i) * inv[i]) % MOD;
      ans += cur;
      ans %= MOD;
   }

   for(int i = 0 ; i < n ; ++i)
      ans = (ans - a[i] + MOD) % MOD;
   ans = (1ll * ans * inv[2]) % MOD;
   cout << ans << "\n";
}

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

bool put[10001][2];
int dp[10001][3];

int min(int a, int b, int c) {
    return min(a, min(b, c));
}

int main() {
    int T; cin >> T;
    while (T--) {
        int N; cin >> N;
        memset(put, 0, sizeof put);
        char c;
        for (int k=1; k<=4*N; ++k) {
            cin >> c;
            if (c == 'Y') {
                if (k <= 2*N) {
                    put[k/2][0] = true;
                } else {
                    put[(k-2*N)/2][1] = true;
                }
            }
        }
        memset(dp, 0, sizeof dp);
        if (put[0][0] && put[0][1]) {
            dp[0][0] = 3;
            dp[0][1] = 2;
            dp[0][2] = 2;
        } else if (put[0][0] && ! put[0][1]) {
            dp[0][0] = 1;
            dp[0][1] = 1;
            dp[0][2] = 2;
        } else if ( ! put[0][0] && put[0][1]) {
            dp[0][0] = 3;
            dp[0][1] = 2;
            dp[0][2] = 2;
        } else if ( ! put[0][0] && ! put[0][1]) {
            dp[0][0] = 0;
            dp[0][1] = 1;
            dp[0][2] = 2;
        }
        for (int k=1; k<=N; ++k) {
            if (put[k][0] && put[k][1]) {
                dp[k][0] = min(dp[k-1][0] + 4, dp[k-1][1] + 3, dp[k-1][2] + 3);
                dp[k][1] = min(dp[k-1][0] + 3, dp[k-1][1] + 3, dp[k-1][2] + 3);
                dp[k][2] = min(dp[k-1][0] + 3, dp[k-1][1] + 3, dp[k-1][2] + 4);
            } else if (put[k][0] && ! put[k][1]) {
                dp[k][0] = min(dp[k-1][0] + 2, dp[k-1][1] + 2, dp[k-1][2] + 3);
                dp[k][1] = min(dp[k-1][0] + 2, dp[k-1][1] + 2, dp[k-1][2] + 3);
                dp[k][2] = min(dp[k-1][0] + 3, dp[k-1][1] + 3, dp[k-1][2] + 4);
            } else if ( ! put[k][0] && put[k][1]) {
                dp[k][0] = min(dp[k-1][0] + 4, dp[k-1][1] + 3, dp[k-1][2] + 3);
                dp[k][1] = min(dp[k-1][0] + 3, dp[k-1][1] + 2, dp[k-1][2] + 2);
                dp[k][2] = min(dp[k-1][0] + 3, dp[k-1][1] + 2, dp[k-1][2] + 2);
            } else if ( ! put[k][0] && ! put[k][1]) {
                dp[k][0] = min(dp[k-1][0] + 1, dp[k-1][1] + 2, dp[k-1][2] + 3);
                dp[k][1] = min(dp[k-1][0] + 2, dp[k-1][1] + 1, dp[k-1][2] + 2);
                dp[k][2] = min(dp[k-1][0] + 3, dp[k-1][1] + 2, dp[k-1][2] + 1);
            }
        }
        cout << dp[N][0] << endl;
    }
    return 0;
}

Measured memory_bytes: 1304
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[MAX];
int n;

void preParse(int u){
  if(u==NIL)return;
  printf(" %d",u);
  preParse(T[u].left);
  preParse(T[u].right);
}

void inPalse(int u){
  if(u==NIL)return;
  inPalse(T[u].left);
  printf(" %d",u);
  inPalse(T[u].right);
}

void postPalse(int u){
  if(u==NIL)return;
  postPalse(T[u].left);
  postPalse(T[u].right);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].left=l;
    T[v].right=r;
    if(l!=NIL)T[l].parent=v;
    if(r!=NIL)T[r].parent=v;
  }
  for(i=0;i<n;i++){
    if(T[i].parent==NIL)root=i;
  }
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inPalse(root);
  printf("\n");
  printf("Postorder\n");
  postPalse(root);
  printf("\n");

  return 0;
}



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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi; typedef pair<ll, int> pli;
typedef pair<ll, ll> pll; typedef pair<ll, pi> plp;
typedef tuple<int, int, int> ti; typedef tuple<ll, int, int> tli;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

int gcd(int a, int b) { return b==0?a:gcd(b, a%b); }

int main() {
	int N, K; cin >> N >> K;
	int g = 0, maxV = -1;
	for(int i=0; i<N; i++) {
		int x; scanf("%d", &x);
		g = gcd(g, x);
		maxV = max(maxV, x);
	}
	if(K <= maxV && K % g == 0) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}

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

#define SIZE 200000


using namespace std;

int main() {
    unsigned long long int A,B,C,D,i,j,k,N,M,K,Q,X,dix;
  //  long long int A[100][100];

 cin >> N;

 dix = 1;
 for (i=1;i<=9;i++)
  dix *= 10;
 dix *= dix;

 cin >> A;
 long encore;
 encore = 1;
 for (i=2;i<=N;i++) {
   cin >> B;
   if ((A == 0) || (B == 0)) {
     A = 0;
     encore = 1;
   }
   else if (encore) {
     C = A*B;
     if (C <= dix) {
         if (C/B == A) {
           A = C;
         }
         else encore = 0;
     }
     else {
       encore = 0;
     }
   }
 }
if ((encore) || (A == 0))
  cout << A << endl;
else
  cout << "-1" << endl;

  return 0;

}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

int N;
int T[1<<25];
int trans(int b, int p){
  b |= 1<<p;
  VVI cnt(N, VI(N));
  REP(y,N) REP(x,N){
	int i = y*N + x;
	if(b>>i&1){
	  REP(d,8){
		int tx = x + dx[d];
		int ty = y + dy[d];
		if(0 <= tx && tx < N && 0 <= ty && ty < N)
		  cnt[ty][tx]++;
	  }
	}
  }
  int res = 0;
  REP(y,N) REP(x,N){
	int i = y*N+x;
	if(p == i) continue;
	if(b>>i&1){
	  res |= (cnt[y][x]==2 || cnt[y][x]==3? 1 : 0) << i;
	}
	else{
	  res |= (cnt[y][x]==3? 1 : 0) << i;
	}
  }
  return res;
}

int solve(int b, int p){
  queue<int> q;
  map<int,int> dist;
  q.push(b|(p<<25));
  dist[b|(p<<25)] = 0;

  while(!q.empty()){
	int bp = q.front();
	q.pop();
	int b = bp & ((1<<25)-1);
	if(b == 0){
	  return dist[bp];
	}
	int p = bp >> 25;
	int x = p % N, y = p / N;
	REP(d,8){
	  int tx = x + dx[d];
	  int ty = y + dy[d];
	  int np = ty*N + tx;
	  if(!(0 <= tx && tx < N && 0 <= ty && ty < N) || (b>>np&1)) continue;
	  int nb = trans(b, np);
	  int nbp = nb | (np<<25);
	  if(!dist.count(nbp)){
		dist[nbp] = dist[bp] + 1;
		q.push(nbp);
	  }
	}
  }
  return -1;
}

void print(int x){
  REP(y,N){
	cout << bitset<3>(x&((1<<N)-1)) << endl;
	x >>= N;
  }
}

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

  while(cin>>N,N){
	int b = 0, p = 0;
	REP(y,N){
	  string s;
	  cin >> s;
	  REP(x,N)
		if(s[x] == '@')
		  p = y*N+x;
		else if(s[x] == '#')
		  b |= 1 << (y*N+x);
	}

	int res = solve(b, p);
	cout << res << endl;
  }
  
  return 0;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

//「排他的論理和の計算順序は入れ替えて良く」
//「任意の偶数nについてn^n+1 == 1」

int f(int b, int d){
    if(b){
        return d%2;
    }
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);


    ll A, B;
    cin >> A >> B;
    ll ans = 0;
    if (A%2==0){
        if ((B-A+1)%2 == 0){
            ans = ((B-A+1)/2)%2;
        } else {
            ans = (B-A)/2%2^B;
        }
    }
    else {
        if((B-A) % 2 == 0){
            ans = (B-A)/2%2^A;
        } else {
            ans = (B-A)/2%2^A^B;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<map>
using namespace std;
int main()
{
    int count=0;
    string s1,s2;
    cin>>s1;
    cin>>s2;
    for(int i=0;s1[i]!='\0';i++)
    {
        if(s1[i]!=s2[i])
        {
            count++;
        } 
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 3916
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;
int o[100005];
int e[100005];

int main(){
   int n;
   cin>>n;
   vector<int> v(n);
   for(int i=0;i<n;i++)cin>>v[i];

   int ans=0;
   for(int i=0;i<n;i++){
      if(i%2==0)e[v[i]]++;
      else o[v[i]]++;
   }
   ans=n-(*max_element(e,e+100005)+*max_element(o,o+100005));
   if(max_element(e,e+100005)-e==max_element(o,o+100005)-o){
      sort(e,e+100005,greater<int>());
      sort(o,o+100005,greater<int>());
      ans=n-max(e[0],o[0])-max(e[1],o[1]);
   }
   if(*max_element(v.begin(),v.end())==*min_element(v.begin(),v.end()))ans=n/2;
   cout<<ans<<endl;
}

   


Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int popcount(int n){
  int ans=0;
  while(n>0){
    if(n&1)ans++;
    n/=2;
  }
  return ans;
}

int pc_str(string s){
  int pc=0;
  for(char c:s){
    if(c=='1') pc++;
  }
  return pc;
}

int rem_str(string s,int pc){
  int r=0;
  for(char c:s){
    r*=2;
    if(c=='1') r++;
    r%=pc;
  }
  return r;
}

void app() {
  int n;
  cin>>n;

  string xs;
  cin>>xs;

  vector<int> s(n);
  s[0]=0;
  rep_range(i,1,n){
    s[i]=1+s[i%popcount(i)];
  }


  int pcb=pc_str(xs);
  int rem[2];
  rem[0]=rem_str(xs,pcb+1);
  if(pcb!=1) rem[1]=rem_str(xs,pcb-1);
  int rb[2]={1,1};
  rb[0]=rb[0]%(pcb+1);
  if(pcb!=1) rb[1]=rb[1]%(pcb-1);

  vector<int> ans(n);
  rep_rev(i,n,0){
    int pat=(xs[i]=='0')?0:1;
    if(pcb==1&&pat==1){ans[i]=0;continue;}

    ans[i]=1+s[(pat==0)
    ?(rem[0]+rb[0])%(pcb+1)
    :(rem[1]-rb[1]+(pcb-1))%(pcb-1)
    ];
    rb[0]=rb[0]*2%(pcb+1);
    if(pcb!=1) rb[1]=rb[1]*2%(pcb-1);
  }

  rep(i,n)cout<<ans[i]<<endl;
}

int main(){app();return 0;}


Measured memory_bytes: 5260
def main():
    _, M = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    border = sum(A) / (M * 4)
    count = 0
    for a in A:
        if a >= border:
            count += 1
            if count >= M:
                print("Yes")
                return
    print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int n;
	cin>>n;
	int a,b,c,d;
	a=n/1000;
	b=n%1000/100;
	c=n%1000%100/10;
	d=n%1000%100%10;
	if((a==b && b==c)|| (b==c && c==d) )
	   cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<int> a(n),b(n+1,0);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int ans=0,j=0;
    while(1){
        if(a[j]==2){
            ans++;
            cout<<ans<<endl;
            break;
        }else if(b[a[j]]==1){
            cout<<-1<<endl;
            break;
        }else{
            b[a[j]]=1;
            ans++;
            j=a[j]-1;
        }
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    
    vector<long long> A(N);

    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int Q;
    cin >> Q;
    vector<long long> B(Q), C(Q);

    for(int i = 0; i < Q; i++) {
        cin >> B[i] >> C[i];
    }
    long long s = 0;
    vector<int> flag(10000001);
    for(int i = 0; i < N; i++) {
        s += A[i];
        flag[A[i]] += 1;
    }
    
    for(int i = 0; i < Q; i++) {
        if(flag[B[i]] > 0) { cout << s - flag[B[i]] *B[i] + flag[B[i]] *C[i] << endl; s = s - flag[B[i]] *B[i] + flag[B[i]] *C[i];  flag[C[i]] += flag[B[i]]; flag[B[i]] = 0; }
        else cout << s << endl;
    }

    return 0;
    

    }

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

int per2num(vector<int> p)
{
    int n=p.size();
    int num=0;
    for(int i=n-2,k=1; i>=0; i--)
    {
        for(int j=i+1; j<n; j++)
        {
            if(p[j]<p[i])
            {
              
                num+=k;
            }
        }
        k*=n-i; 
    }
    return num+1;
}
int main()
{
    int n;
    int a1,b1;cin>>n;
    vector<int> a;
    vector<int> b;
    for(int i=0; i <n; ++i)
    {
        cin>>a1;
        a.push_back(a1);
    }
    for(int i=0; i <n; ++i)
    {
        cin>>b1;
        b.push_back(b1);
    }
    int f= per2num(a);
    int g= per2num(b);
    cout<<abs(f-g);
}




Measured memory_bytes: 256
import operator
for e in iter(input,'0'):
    target = [[*map(int,input().split())]for _ in[0]*int(e)]
    bx, by = target[0]
    target = {(x - bx, y - by) for x, y in target}
    max_tx = max(map(operator.itemgetter(0), target))
    b = {tuple(map(int,input().split()))for _ in[0]*int(input())}
    max_sx = max(map(operator.itemgetter(0), b))
    lim_x = max_sx - max_tx
    for x,y in b:
        if x > lim_x:continue
        for u,v in target:
            if (x + u, y + v) not in b:break
        else:
            print(x - bx, y - by)
            break


Measured memory_bytes: 6100
o = input()
o_list = o.split(" ")

p = int(o_list[0])
q = int(o_list[1])
r = int(o_list[2])
pq = p + q
qr = q + r
rp = r + p

if pq <= qr and pq <= rp:
    print(pq)
elif qr <= rp and qr <= pq:
    print(qr)
elif rp <= pq and rp <= qr:
    print(rp)

Measured memory_bytes: 3064
def f(i, m, cnt):
    while True:
        if i > n or not cnt[i] == inf:
            return
        cnt[i] = m
        i += 1

n, q = map(int, input().split())
inf = n + 114514
ans = (n - 2) * (n - 2)
cnt1, cnt2 = [inf] * (n + 1), [inf] * (n + 1)
max1, max2 = n - 2, n - 2
for _ in range(q):
    t, x = map(int, input().split())
    if t == 1:
        if cnt1[x] == inf:
            ans -= max2
            max1 = x - 2
            f(x, max2, cnt1)
        else:
            ans -= cnt1[x]
    else:
        if cnt2[x] == inf:
            ans -= max1
            max2 = x - 2
            f(x, max1, cnt2)
        else:
            ans -= cnt2[x]
print(ans)

Measured memory_bytes: 13444