akhauriyash/Code-Regression huggingface dataset:
#[大きい数のnCkの計算]
#https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#5-%E4%BA%8C%E9%A0%85%E4%BF%82%E6%95%B0-ncr
def combi(n, k)
  @fac[n] * (@finv[k] * @finv[n - k] % MOD) % MOD
end

MAX = 10 ** 5
MOD = 10 ** 9 + 7
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort

@fac = []
@finv = []
@inv = []
@fac[0] = @fac[1] = 1
@finv[0] = @finv[1] = 1
@inv[1] = 1
2.upto(MAX) do |i|  
  @fac[i] = @fac[i - 1] * i % MOD
  @inv[i] = MOD - @inv[MOD % i] * (MOD / i) % MOD
  @finv[i] = @finv[i - 1] * @inv[i] % MOD
end

res = 0
(N-1).downto(K-1) do |i|
  num = combi(i, K-1)
  res -= (A[N-1-i] * num) % MOD
  res += (A[i] * num) % MOD
end
p res % MOD

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_N 20000
#define MAX_M 16

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int a, b;
int ca[10000], cb[10000];

int main(){
	cin >> a >> b;
	REP(i, a)cin >> ca[i];
	REP(i, b)cin >> cb[i];
	int ans = 0, co = 0, bpos = 0;
	REP(i, b){
		bpos = i;
		co = 0;
		REP(j, a){
			if (ca[j] == cb[bpos]){
				co++;
				bpos++;
			}
		}
		ans = max(ans, co);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1204
/**
 * Title:
 * Url:
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

int ctoi(char c) {
	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

ll next(ll num, int keta) {
    string hoge =to_string(num);
    string ne = "";
    for(int i=0;i<keta; i++) {
        if(i==0) {
            ne += to_string(ctoi(hoge[i])+1);
        } else {
            ne += to_string(max(ctoi(ne[i-1])-1, 0));
        }
    }
    return stoll(ne);
}

bool jd(ll num) {
    string hoge =to_string(num);
    for(auto h:hoge) {
        if(ctoi(h)!=9) return false;
    }
    return true;
}

bool jd2(ll num, int keta) {
    string hoge =to_string(num);
    if(keta==1) return true;
    for(int i=1; i<keta; i++) {
        if(abs(ctoi(hoge[i])-ctoi(hoge[i-1]))>=2) return false;
    }
    return true;
}

int main() {
    ll k; cin >> k;
    queue<ll> q;
    for(ll i=1; i<=9; i++) {
        q.push(i);
    }
    ll ans;
    for(int i=0; i<k; i++) {
        ll x = q.front();
        ans = x;
        q.pop();
        if(x%10!=0) q.push(10*x-1+ x%10);
        q.push(10*x+ x%10);
        if(x%10!=9) q.push(10*x+1+ x%10);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
int main()
{
	char buf[128];
	int res = 0;
	while (fgets(buf, 128, stdin)) {
		for (int i = 0; buf[i]; ++i) if (!isdigit(buf[i])) buf[i] = ' ';
		char* p = strtok(buf, " ");
		while (p) { res += atoi(p); p = strtok(NULL, " "); }
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 0
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Queue;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;



public class Main{
	
	static int posx;
	static int posy;
	static int type;
	static int diff;
	static int INF = Integer.MAX_VALUE;
	static int[][] d;
	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 
	 long A=sc.nextLong();
	 long B=sc.nextLong();
	 long C=sc.nextLong();
	 long D=sc.nextLong();
	 
	 long numC=A/C;
	 if(A%C!=0) {
		 numC+=1;
	 }
	 long numC2=B/C;
	 
	 long numD1=A/D;
	 if(A%D!=0) {
		 numD1+=1;
	 }
	 long numD2=B/D;
	 
	
	 long numCD1=A/lcm(C,D);
	 if(A%(lcm(C,D))!=0) {
		 numCD1+=1;
	 }
	 long numCD2=B/lcm(C,D);
	 
	 
	 
	 
	 long result=(numC2-numC+1)+(numD2-numD1+1)-(numCD2-numCD1+1);
	 
	 //System.out.println(numC+" "+numC2+" "+numD1+" "+numD2+" "+numCD1+" "+numCD2);
	 System.out.println(B-A+1-result); 
	 
	
	 
	 
	 
 }
	


}


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

using namespace std;
typedef long long ll;

const int N = 2e5;

int cnt[3];
int col[N + 5];
int ans[N + 5];
vector < int > G[N + 5];

void dfs(int u, int p, int c) {
	cnt[c]++;
	col[u] = c;
	for(int v : G[u]) {
		if(v == p) continue;
		dfs(v, u, 1^c);
	}
}

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(ans,-1,sizeof ans);
	int n; cin >> n;
	for(int i=0; i<n-1; i++) {
		int u,v; cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1,-1,0);
//	for(int i=1; i<=n; i++) printf("%d ",col[i]);
//	puts("");
	int val[5], rem[5];
	for(int i=1; i<=3; i++) {
		rem[i] = (3-i+n)/3;
		val[i] = i;
	}
	int id[3];
	id[0] = 0; id[1] = 1;
	if(cnt[0] > cnt[1]) {
		swap(id[0], id[1]);
	}
	for(int i=0; i<2; i++) {
		if(cnt[id[i]] <= rem[3]) {
			for(int j=1; j<=n; j++) {
				if(col[j] == id[i]) {
					ans[j] = val[3];
					val[3] += 3;
					rem[3]--;
				}
			}
		}
	}
	
	for(int i=0; i<2; i++) {
		for(int j=1; j<=n; j++) {
			if(ans[j] != -1) continue;
			if(rem[id[i]+1] == 0) break;
			if(col[j] == id[i]) {
				ans[j] = val[id[i]+1];
				val[id[i]+1] += 3;
				rem[id[i]+1]--;
			}
		}
	}
	for(int i=1; i<=n; i++) {
		if(ans[i] != -1) continue;
		for(int j=3; j>=1; j--) {
			if(rem[j] == 0) continue;
			ans[i] = val[j];
			val[j] += 3;
			rem[j]--;
			break;
		}
	}
	for(int i=1; i<=n; i++) {
		if(i > 1) cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 19328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,x); REP(i,sizeof(a)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  int N,e; cin>>N;
  vector<int> ans;
  int cumu[N+1];
  cumu[0]=0LL;
  for(int i=1;i<=N;++i){
    cumu[i]=cumu[i-1]+i;
    ans.push_back(i);
    if(cumu[i]<N){continue;}
    else{ e = cumu[i]-N;break;}
  }
  for(int x:ans){
    if(x!=e){printf("%d\n",x);}
  }
  
}


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

long long N, M, a[100009][3], maxn = -(1LL << 60);

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++)
			cin >> a[i][j];
	}
	for (int i = 0; i < 8; i++) {
		vector<long long>vec;
		for (int j = 1; j <= N; j++) {
			long long S = 0;
			for (int k = 0; k < 3; k++) {
				
				 if ((i / (1 << k)) % 2 == 0) 
				 {
					S += a[j][k];
				 }
				 else S -= a[j][k];
			}
			vec.push_back(S);
		}
		sort(vec.begin(), vec.end()); 
		reverse(vec.begin(), vec.end());
		long long ans = 0;
		for (int j = 0; j < M; j++) 
				ans += vec[j];
		maxn = max(maxn, ans);
	}
	cout << maxn << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define llong long long
#define mp make_pair
#define f first
#define s second

using namespace::std;

const int A = 26;

int main()
{
    ios::sync_with_stdio(false);
    ifstream fin("input.txt");
    string str;
    cin >> str;
    int N = str.size();
    vector<int> dp(A, 0);
    vector<string> dps(A, "");
    for (int i = 0; i < N; i++) {
        int c = str[i] - 'a';
        dp[c]++;
        dps[c] += str[i];
        for (int j = 0; j < A; j++) {
            if (dp[j] > dp[c]) {
                dps[j] = dps[c];
            }
            else if (dp[j] == dp[c]) {
                dps[j] = min(dps[j], dps[c]);
            }
            dp[j] = min(dp[j], dp[c]);
        }
    }
    string ans = dps[0] + 'a';
    for (int i = 1; i < A; i++) {
        if (ans.size() - 1 > dp[i]) {
            ans = dps[i] + (char)(i + 'a');
        }
        else if (ans.size() - 1 == dp[i]) {
            ans = min(ans, dps[i] + (char)(i + 'a'));
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 720
import sys

def S(n):
  return n / sum(map(int, str(n)))


def f(n):
  d = 0
  C = [n]
  while S(n) > (10**d / 9*(d+1)):
    c = 10**(d+1) * (n // 10**(d+1) + 1) - 1
    C.append(c)
    d += 1
  Smin = float('inf')
  res = 0
  for c in C:
    if S(c) < Smin:
      Smin = S(c)
      res = c  
  return res


def main():
  input = sys.stdin.readline
  K = int(input())
  ans = 1
  for _ in range(K):
    print(ans)
    ans = f(ans+1)


if __name__ == '__main__':
  main()

Measured memory_bytes: 3188
# ITP_11_D
import sys

class Dice :
    def __init__(self, dice) :
        self.dice = dice
    def roll(self, direction):
        tmp = self.dice[:]
        if direction == "N":
            self.dice[0] = tmp[1]
            self.dice[1] = tmp[5]
            self.dice[4] = tmp[0]
            self.dice[5] = tmp[4]
        elif direction == "E":
            self.dice[0] = tmp[3]
            self.dice[2] = tmp[0]
            self.dice[3] = tmp[5]
            self.dice[5] = tmp[2]
        elif direction == "W":
            self.dice[0] = tmp[2]
            self.dice[2] = tmp[5]
            self.dice[3] = tmp[0]
            self.dice[5] = tmp[3]
        else:
            self.dice[0] = tmp[4]
            self.dice[1] = tmp[0]
            self.dice[4] = tmp[5]
            self.dice[5] = tmp[1]

    def check_dice(self, another):
        for dire in "NNNNWNNNWNNNENNNENNNWNNN":
            self.roll(dire)
            check = True
            for i in range(6):
                if self.dice != another.dice:
                    check = False
                    break
            if check == True:
                break
        return check
    def get_dice_nums(self):
        return(self.dice)
    
    def check_dice_some(self, another):
        for dire in "NNNNWNNNWNNNENNNENNNWNNN":
            self.roll(dire)
            check = True
            for i in range(6):
                if self.dice != another.dice:
                    check = False
                    break
            if check == True:
                break
        return check
    def get_dice_nums(self):
        return(self.dice)
    
    def dice_top(self):
        print(self.dice[0])
    
dice_list = []
for i in range(int(input())):
    dice_list.append(Dice(list(map(str, input().split()))))
    
for i in range(len(dice_list)-1):
    judge = dice_list[0].check_dice(dice_list[i+1])
    if judge == True:
        print("No")
        sys.exit()
        
print("Yes")


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

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

    for (int i = b*10; i <= b*10+9 ;i++) {
        if (i*8 / 100 == a) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
#if 0
    if ((a * 5)/4 != b) {
        cout << -1 << endl;
        return 0;
    }

    int ans = 1;
    while (true) {
        if ((ans*8)/100 == a && ((ans * 10 / 100) == b)) {
            cout << ans << endl;
            return 0;
        }
        ans++;
    }
#endif 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define pb push_back
#define mp make_pair
using namespace std;

const long long INF = 2e18 + 18;
const long long mod = 1e9 + 7;

vector<pair<long long, long long> > coords;
long long fact[200010];

long long binpow(long long a, long long p) {
	if (p == 0) return 1;
	else if (p & 1) return a * binpow(a, p - 1) % mod;
	else {
		long long res = binpow(a, p / 2);
		return res * res % mod;
	}
}

long long mul(long long a, long long b) {
	return a * b % mod;
}

long long sub(long long a, long long b) {
	return (a - b + mod) % mod;
}

long long inv(long long a) {
	return binpow(a, mod - 2);
}

long long cnk(long long n, long long k) {
	if (n < 0 or k < 0 or n < k) return 0;
	return mul(fact[n], inv(mul(fact[n - k], fact[k])));
}

long long f(long long a, long long b) {
	return cnk(a + b, b);
}

void precalc() {
	fact[0] = 1;
	for (long long i = 1; i < 200010; i++) {
		fact[i] = mul(fact[i - 1], i);
	}
}

void solve() {
	precalc();
	int h, w; cin >> h >> w;
	int n; cin >> n;
	coords.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> coords[i].first >> coords[i].second;
	}
	sort(coords.begin(), coords.end(), [&](pair<long long, long long> p1, pair<long long, long long> p2){
		return p1.first + p1.second < p2.first + p2.second;
	});
	coords.push_back(mp(h, w));
	vector<long long> dp(n + 1);
	for (int i = 0; i <= n; i++) {
		long long temp = f(coords[i].first - 1, coords[i].second - 1);
		for (int j = 0; j < i; j++) {
			if (coords[i].first >= coords[j].first and coords[i].second >= coords[j].second) {
				temp = sub(temp, mul(dp[j], f(coords[i].first - coords[j].first, coords[i].second - coords[j].second)));
			}
		}
		dp[i] = temp;
	}
	cout << dp[n] << endl;
}

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

Measured memory_bytes: 2048
def p_b():
    N = int(input())
    p = list(map(int, input().split()))
    ans = 0
    for i in range(N - 2):
        if max(p[i:i + 3]) != p[i + 1] and min(p[i:i + 3]) != p[i + 1]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    p_b()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

typedef long long i64; 
typedef vector< int > vi;
typedef vector< i64 > vi64;
typedef pair< int, int > pi;
typedef vector< pair< int, int > > vpi;

void crypt() {
	i64 h, w; int n, y, x; cin >> h >> w >> n;
	int total = 0;
	map< pi, int > check;
	forn(i, n) {
		cin >> y >> x; y--, x--;
		fore(j, y-2, y, 1) {
			fore(k, x-2, x, 1) {
				if (j < 0 || k < 0) continue;
				if (j + 2 > h - 1 || k + 2 > w - 1) continue;
				if (check.find({j, k}) != check.end()) check[{j, k}] += 1;
				else check[{j, k}] = 1;
			}
		}
	}
	vi64 ans(10, 0);
	for (auto u: check) {
		ans[u.se] += 1;
		total += 1;
	}
	ans[0] = (h - 2) * (w - 2) - total;
	forn(i, 10) cout << ans[i] << '\n';
}

int main(void) {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	cout << fixed;
	int t = 1; 
//	cin >> t;
	while (t--) crypt();
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p.at(i);
    }

    int sum = 1;
    int small = p.at(0);
    for(int i = 1; i < n; i++){
        if(p.at(i) <= small){
            sum++;
        }
        small = min(small,p.at(i));
    }

    cout << sum << endl;
}

Measured memory_bytes: 1152
import collections
from collections import deque

s= input()
n=int(input())
q= [list(input().split()) for i in range(n)]

s=deque(s)
flag=True
for i in range(n):
    if q[i][0]==str(1):
        if flag:
            flag=False
        else:
            flag=True
    else:
        if q[i][1]==str(1):
            if flag:
                s.appendleft(q[i][2])
            else:
                s.append(q[i][2])
        if q[i][1]==str(2):
            if flag:
                s.append(q[i][2])
            else:
                s.appendleft(q[i][2])

if not flag:
    s.reverse()
print(''.join(s))

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

const ll INF = 1LL << 60;

ll N, A, B;
string S;
int main() {
    cin >> N >> A >> B;
    cin >> S;

    ll passed = 0;
    ll b_passed = 0;
    rep(i, S.size()) {
        if (S[i] == 'a') {
            if (passed < A + B) {
                cout << "Yes" << endl;
                passed++;
            } else {
                cout << "No" << endl;
            }
        } else if (S[i] == 'b') {
            if (passed < A + B && b_passed < B) {
                cout << "Yes" << endl;
                passed++;
                b_passed++;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define ll long long int 
using namespace std;
int main(){
	int n,x,t;
	cin>>n>>x>>t;
	ll count=0;
	if(n%x!=0)	
	count++;
	
	count+=n/x;
	cout<<count*t<<endl;
	}

Measured memory_bytes: 3588
#include <iostream>
    
using namespace std;
    
int main(){
 int H,W,i,j;
 while (1) {
  cin>>H;
  cin >>W;
  if (H==0 && W==0) break;
  for (i=0;i<H;i++) {
   for (j=0;j<W;j++) {
    cout << "#";
   }
   cout << endl;
  }
  cout << endl;
 }
 return 0;
}



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

using namespace std;

int main() {
	
	
	       
	string s;
	cin>>s;
	int cnt=0,i,m=0;
	
	for(i=0;i<s.length();++i)
	  {
	      if(s[i]=='R')
	        cnt++;
	        
	   else
	     {
	         m=max(m,cnt);
	         cnt=0;
	     }
	  }
	  
	  m=max(m,cnt);
	  
	  cout<<m;
	
	
	
	return 0;
}

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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		int x, n;
		cin >> x >> n;
		
		vi p(102, 0);
		int k;
		for(int i=0 ; i<n ; ++i){
			cin >> k;
			p[k]++;
		}
		
		int mn = INT_MAX;
		int ans=0;
		for(int i=0 ; i<102 ; ++i){
			if(!p[i]){
				int diff = abs(x - i);
				if(diff < mn){
					mn = diff;
					ans = i;
				}
			}
		}
		
		cout << ans;
	}
}


Measured memory_bytes: 3608
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {

	int n;
	cin >> n;
	vector<int> d(n);
	int ans = 0;
	rep(i, n) {
		cin >> d[i];
	}
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			ans += (d[i] * d[j]);
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	x := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
		if x[i] < k-x[i] {
			sum += x[i]
		} else {
			sum += k - x[i]
		}
	}
	sum *= 2
	fmt.Println(sum)

}


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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)


struct data{ 
	int x; 
	ll y;
};
bool operator<(const data &data1,const data &data2){
	return data1.y < data2.y;
};
int main(){
	int n,m;
	cin >> n >> m;
	vector<ll> a;
	ll A;
	for(int i = 0; i < n; i++){
		cin >> A;
		pb(a,A);
	}
	sort(ben(a));
	priority_queue<data> q;
	int b;
	ll c;
	for(int i = 0; i < m; i++){
		data d;
		cin >> b >> c;
		d.x = b;
		d.y = c;
		q.push(d);
	}
	int l = 0;
	int r;
	int ok = 0;
	for(int i = 0; i < m; i++){
		data d = q.top();
		q.pop();
		r = l + d.x;
		for(int j = l; j < min(r,n); j++){
			if(a[j] >= d.y){
				ok = 1;
				break;
			}
			else{
				a[j] = d.y; 
			}
		}
		l = r;
		if(ok)break;
		if(l - 1 > n)break;
	}
	ll sum = 0;
	for(int i = 0; i < n; i++){
		sum += a[i];
	}
	cout << sum << endl;
	return 0; 
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef long long ll;

int main(){
  string s;
  cin >> s;

  int n = s.size();
  int a=0,b=0,c=0;
  rep(i,n){
    if(s.at(i)=='a') a++;
    else if(s.at(i)=='b') b++;
    else if(s.at(i)=='c') c++;
  }

  int m = min(a, min(b,c));
  if((m==a||m+1==a)&&(m==b||m+1==b)&&(m==c||m+1==c)) cout<<"YES";
  else cout << "NO";
}

Measured memory_bytes: 3696
n = int(input())
ac, wa, tle, re = 0, 0, 0, 0
for _ in range(n):
    x = input()
    if x == "AC":
        ac += 1
    elif x == "WA":
        wa += 1
    elif x == "TLE":
        tle += 1
    else:
        re += 1

print("AC x {}".format(ac))
print("WA x {}".format(wa))
print("TLE x {}".format(tle))
print("RE x {}".format(re))

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

struct RollingHash {
    long long mod, b;
    vector<long long> hash, p;
    
    RollingHash(const string &s, long long b, long long mod) : b(b), mod(mod) {
        int n = s.length();
        hash.assign(n+1, 0);
        p.assign(n+1, 1);
        for (int i = 0; i < n; i++) {
            hash[i+1] = (hash[i] * b + s[i]) % mod;
            p[i+1] = p[i] * b % mod;
        }
    }
    // [i, i+len)
    long long get_hash(int l, int r) {
        if (r < l) swap(l, r);
        long long res = hash[r] + mod - hash[l] * p[r-l] % mod;
        return res > mod ? res-mod : res;
    }
};



int main() {
    int N;
    string S;
    cin >> N >> S;
    
    long long B = 1777771;
    long long MOD1 = 1e9+7, MOD2 = 1e9+9;
    RollingHash rh1(S, MOD1, B), rh2(S, MOD2, B);
    
    auto check = [&](int L){
        using P = pair<long long, long long>;
        set<P> hs;
        for (int i = N - L; i >= 0; i--) {
            if (i+L+L <= N) {
                hs.emplace(rh1.get_hash(i+L, i+L+L), rh2.get_hash(i+L, i+L+L));
            }
            if (hs.count({rh1.get_hash(i, i+L), rh2.get_hash(i, i+L)})) {
                return true;
            }
        }
        return false;
    };
    
    int ok = 0, ng = N;
    while (abs(ok-ng) > 1) {
        int mid = (ok + ng) / 2;
        if (check(mid)) ok = mid;
        else ng = mid;
    }
    
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

const int N = 14;
const int S = (1 << N) + 1;
const long double INF =	1e10;

int n;
long double x[N * 2], y[N * 2];
long double f[N * 2][S];

long double update(long double &a, long double b)
{
	a = min(a, b);
}

long double dis(long double xa, long double ya, long double xb, long double yb)
{
	return hypot(xa - xb, ya - yb);
}

void solve()
{
	for(int i = 0; i < n + n; ++ i) {
		cin >> x[i] >> y[i];
	}
	int s = 1 << n;
	for(int i = 0; i < n + n; ++ i) {
		for(int j = 0; j < s; ++ j) {
			f[i][j] = INF;
		}
		f[i][1 << (i >> 1)] = 0;
	}
	long double sum = 0;
	for(int i = 0; i < n; ++ i) {
		sum += dis(x[i * 2], y[i * 2], x[i * 2 + 1], y[i * 2 + 1]);
	}

	long double ret = INF;
	for(int i = 0; i < s; ++ i) {
		for(int j = 0; j < n + n; ++ j) {
			if (f[j][i] >= INF) continue;
			if (i == s - 1) {
				update(ret, f[j][i]);
			}
			for(int k = 0; k < n + n; ++ k) {
				if (~i >> (k >> 1) & 1) {
					update(f[k][i + (1 << (k >> 1))], f[j][i] + dis(x[j ^ 1], y[j ^ 1], x[k], y[k]));
				}
			}
		}
	}
	printf("%.12f\n", (double)(ret + sum));
}

int main()
{
	int test = 0;
	for( ; cin >> n && n; ) {
		printf("Case %d: ", ++ test);
		solve();
	}
	return 0;
}

Measured memory_bytes: 8428
#include<stdio.h>
int main(void){
	int n=0,m=0,a=0,b=0,c=0,sum=0,max=0;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d %d",&a,&b);
		c=n-a;
		if(c>0){
			sum+=c;
		}
		if(c>max){
			max=c;
		}
	}
	printf("%d\n",sum-max);
	return 0;
}

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

int mod = 1000000007;
int64_t large = 9223372036854775807;

int main()
{
    int N;
    cin >> N;
    vector<tuple<string, int, int>> list;
    for (int i = 0; i < N; i++)
    {
        int p;
        string tmp;
        cin >> tmp >> p;
        list.push_back(make_tuple(tmp, -p, i));
    }
    sort(list.begin(), list.end());

    for (int i = 0; i < N; i++)
        cout << get<2>(list[i]) + 1 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp36
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            int x = num * 800;
            int a = num / 15;
            int y = a * 200;
            Console.WriteLine(x - y);
        }
    }
}


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

using namespace std;

int main() {
    /* code */
    int A, B, C, D, E;
    cin >> A;
    if (A<=1)
    {
        cout << 1 << endl;
        /* code */
    }else if (A<=3)
    {
        cout << 2 << endl;
        /* code */
    }else if (A<=7)
    {
        cout << 4 << endl;
        /* code */
    } else if (A<=15)
    {
        cout << 8 << endl;
        /* code */
    } else if (A<=31)
    {
        cout << 16 << endl;
        /* code */
    }else if (A<=63)
    {
        cout << 32 << endl;
        /* code */
    }else if (A<=100)
    {
        cout << 64 << endl;
        /* code */
    }
    return 0;
}

Measured memory_bytes: 3624
#include <cmath>
#include <chrono>
#include <random>
#include <ctime>
#include <algorithm>
#include <iosfwd>
#include <iostream>
#include <list>
#include <ostream>
#include <streambuf>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long int ll;
typedef long long int ull;
typedef long double ld;
#define fori(i, n) for(ll i = 0; i < (n); ++i)
#define forI(i, n) for(ll i = 1; i <= (n); ++i)
#define pll pair<ll, ll>
#define ff first
#define ss second

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#define pt pair<ll, ll>
#define x first
#define y second

pll operator+(pll a, pll b) { return {a.x + b.x, a.y + b.y}; }
pll operator-(pll a, pll b) { return {a.x - b.x, a.y - b.y}; }

ll rand0m() {return (ull(rand()) << 15ull | ull(rand()));}                   //[0 ... n)
ll rand0m(ll x) {return rand0m() % x;}               //[0 ... n)
ll rand0m(ll minn, ll maxx) {return rand0m(maxx - minn + 1) + minn;}   //[minn ... maxx]

const ll MAXN = 100000 + 1;
const ll mod = 1e9 + 7;
const ll INF = 1e18;
pll dt[] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

ll n, m;

vector<vector<ll>> operator *(vector<vector<ll>> a, vector<vector<ll>> b){
    vector<vector<ll>> res(n, vector<ll>(n, 0));
    fori(i, n)
        fori(j, n)
            fori(k, n)
                res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % mod;
    return res;
}

vector<vector<ll>> pw(vector<vector<ll>> a, ll p){
    if(p == 1) return a;
    auto e = pw(a, p >> 1);
    if(p & 1) return (e * e) * a;
    return e * e;
}

void solve(){
    cin >> n >> m;
    vector<vector<ll>> g(n, vector<ll>(n));
    fori(i, n) fori(j, n) cin >> g[i][j];
    g = pw(g, m);
    ll c = 0;
    fori(i, n) fori(j, n) c = (c + g[i][j]) % mod;
    cout << c;
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //stress();
    solve();
}


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

void solve(long long N, vector<long long> A, vector<long long> B){
  long long ans = 0;
  long long ad = 0;
	for ( long long i = A.size() - 1; i >= 0; i-- ) {
    long long a = A[i] + ad;
    long long b = B[i];
    if (a % b == 0) continue;
    long long d = b - (a % b);
    if ( b == 1 ) { d = 0; }
    ad += d;
    ans += d;
  }
  cout << ans << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	vector<long long> B(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
		scanf("%lld",&B[i]);
	}
	solve(N, A, B);
	return 0;
}



Measured memory_bytes: 3456
package main

import (
    "fmt"
    "bufio"
    "os"
)

var sc = bufio.NewScanner(os.Stdin)

func indexOf(element string, data []string) (int) {
   for k, v := range data {
       if element == v {
           return k
       }
   }
   return -1    //not found.
}

func main() {
    var s string
    weather := []string{"Sunny", "Cloudy", "Rainy"}
    if sc.Scan() {
        s = sc.Text()
    }
    fmt.Println(weather[(indexOf(s, weather)+1)%3])
}

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

int main(){

  int N, M, X, Y, x, xmax=-100, y, ymin=100;
  cin >> N >> M >> X >> Y;
  for(int i=0; i < N; i++){
    cin >> x;
    if(xmax < x) xmax = x;
  }
  for(int i=0; i < N; i++){
    cin >> y;
    if(y < ymin) ymin = y;
  }
  for(int z=X+1; z <= Y; z++){
    if(xmax < z && z <= ymin){
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#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)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	char a, b;
	cin >> a >> b;
	if (a > b)
		cout << '>' << endl;
	else if (a < b)
		cout << '<' << endl;
	else
		cout << '=' << endl;

	return 0;
}

Measured memory_bytes: 888
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数


int main (){
    ll int h,n;
    cin >> h >> n;
    vei a(n);
    REP(i,n){
        cin >> a[i];
    }
    ll int aa = 0;
    REP(i,n){
        aa += a[i];
    }
    if(h<=aa) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int n;
int x[222222];
int a[222222];

int main(){
  ios_base::sync_with_stdio(false);

  int l;

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

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

  l = (n/2) - 1;

  for(int i=0;i<n;i++){
    if(a[l] <= x[i]){
      cout << a[l+1] << endl;
    } else {
      cout << a[l] << endl; 
    }
  }
  
  return 0;
}



Measured memory_bytes: 3840
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














int A, P;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> A >> P;

	P += A * 3;
	int ans = P / 2;
	cout << ans << endl;
}















Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long w[2020][2020];
int main()
{
	int n,k;
	cin>>n>>k;
	int i,j;
	w[0][0]=1;
	for(i=1;i<=2000;i++)
	{
		for(j=0;j<=i;j++)
		{
			if(j==0||j==i)
				w[i][j]=1;
			else
				w[i][j]=(w[i-1][j]+w[i-1][j-1])%1000000007;
		}
	}
	for(i=1;i<=k;i++)
	{
		cout<<(w[n-k+1][i]*w[k-1][i-1])%1000000007<<endl;
	}
	return 0;
}

Measured memory_bytes: 30336
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long f(int n)
{
    if(n==1)return 1;
    else return n*f(n-1);
}
int main()
{
    int n;
    while(cin>>n)
        cout<<f(n)<<endl;

    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	vector<int> v(5);
	for(int i = 0; i < 3; i++) {
		int a,b;cin>>a>>b;
		v[a]++;
		v[b]++;
	}
	for(int i = 1; i <= 4; i++) {
		if(v[i] == 0 || v[i] > 2){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

long long int powint(long long int a, long long int b) {
	assert(b >= 0);
	if (b == 0)return 1;
	if (b == 1)return a;
	long long int ans = 1;
	long long int aa = powint(a, b / 2);
	ans *= aa*aa;
	if (b % 2)ans *= a;
	return ans;
}

vector<long long int>memo(20);
long long int getans(const long long  int n) {
	if (n <= 3)return n;
	else if (n == 4)return 5;
	else if (n <= 9)return n + 2;
	else {
		int keta;
		for (int i = 19; i >= 0; --i) {
			if (memo[i] < n) {
				keta = i;
				break;
			}
		}
		int num = n / memo[keta];
		if (num <= 3) {
			return powint(10, keta)*num + getans(n - memo[keta] * num);
		}
		else if (num == 4) {
			return powint(10, keta)*(num+1) + getans(n  - memo[keta] * num);
		}
		else {
			return powint(10, keta)*(num+2) + getans(n - memo[keta] * num);
		}

	}
}

int main() {
	memo[1] = 8;
	for (int i = 2; i < 20; ++i) {
		memo[i] = memo[i - 1] * 8;
	}
	while (1) {
		int N; cin >> N;
		if (!N)break;
		else {
			long long int ans = getans(N);
			cout << ans << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 2964
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

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

  int ans=0;
  for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
      for(int k=1;k<=K;k++){
        int tmp=gcd(i,j);
        tmp=gcd(tmp,k);
        ans+=tmp;
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, greater<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 200'000;
const int LOGN = 19;

int n, m, k;
void solve(int test)
{
  cin >> n;
  vector<vector<int>> a(n, vector<int>(n - 1));
  vector<int> p(n, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n - 1; ++j) {
      cin >> a[i][j];
      --a[i][j];
    }
  }
  int ans = 0;
  queue<tuple<int, int, int>> q;
  for (int i = 0; i < n; ++i) {
    int with = a[i][p[i]];
    if (i < with && i == a[with][p[with]]) {
      q.emplace(i, with, 1);
    }
  }
  while (!q.empty()) {
    int p1, p2, day;
    //const auto& [p1, p2, day] = q.front();
    tie(p1, p2, day) = q.front();
    q.pop();
    ++p[p1];
    ++p[p2];
    ans = max(ans, day);

    if (p[p1] < n - 1) {
      int with = a[p1][p[p1]];
      if (p1 == a[with][p[with]]) {
        q.emplace(p1, with, day + 1);
      }
    }
    if (p[p2] < n - 1) {
      int with = a[p2][p[p2]];
      if (p2 == a[with][p[with]]) {
        q.emplace(p2, with, day + 1);
      }
    }
  }
  if (count(begin(p), end(p), n - 1) == n) {
    cout << ans << '\n';
  }
  else {
    cout << "-1\n";
  }
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 4224
import math
import fractions
import sys
import itertools
import numpy as np
from collections import Counter
import datetime
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))

def keta(N):
	return len(str(N))


def input_daytime(input_time):
	time,distance=input_time.split()
	t=time.split(":")
	se=str(t[-1]).split(".")
	dt1 = datetime.timedelta(hours=int(t[0]),minutes=int(t[1]),seconds=int(se[0]),milliseconds=int(se[1]))
	return dt1

n=input1()
d=input_array()
result=0
for i in range(n):
	tako=d[i]
	for j in range(i+1,n):
		result+=d[i]*d[j]
print(result)











Measured memory_bytes: 13724
result = []
while True:
    no_referee = int(input())
    if no_referee == 0:
        break
    else:
        sum_score = 0
        max_score = 0
        min_score = 1000
        for i in range(no_referee):
            score = int(input())
            sum_score += score
            if score > max_score:
                max_score = score
            if score < min_score:
                min_score = score
        sum_score = sum_score - max_score - min_score
        result.append(int(sum_score/(no_referee-2)))

for r in result:
    print(str(r))


Measured memory_bytes: 5600
#include<iostream>
#include<string>
#include<map>
using namespace std;
int main(){
  map<string,int> t;
  string s, mxc, mxl;
  int freq = 1, len = 0;
  while(cin >> s){
    if(t.find(s) == t.end()){
      t[s] = 1;
    }
    else{
      t[s]++;
    }

    if(t[s] > freq){
      freq = t[s];
      mxc = s;
    }
    if(s.size() > len){
      len = s.size();
      mxl = s;
    }
  }
  cout << mxc << " " << mxl << endl;
}

Measured memory_bytes: 3176
n,m,c=map(int,input().split())
b=[0]*m
a=[0]*n
ans=0
b=list(map(int,input().split()))
for i in range(n):
  a[i]=[0]*m
  a[i]=list(map(int,input().split()))
  size=0
  for j in range(m):
    size+=b[j]*a[i][j]
  size+=c
  if (size>0):
    ans+=1

print(ans)

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

int main() {
	string s; cin >> s;
	string mdl; cin >> mdl;
	for (int i = 0; i < s.size(); i++) {
		if (s == mdl) {
			cout << "Yes" << endl;
			return 0;
		}
		string tmp; tmp = s[s.size()-1];
		for (int j = 0; j < s.size() - 1; j++) {
			tmp += s[j];
		}
		s = tmp;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
// tenka12019_b

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
  int n, k;
  string s;
  char c;
  cin >> n >> s >> k;

  c = s[k-1];
  for (int i=0; i < n; i++) {
    if (s[i]!=c) {
      s[i]='*';
    }
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(dead_code, unused_imports, deprecated)]
use std::cmp::{max, min, Reverse};
use std::collections::*;
use maplit::*;
use num::Integer;
use proconio::input;
use proconio::marker::*;
use proconio::fastout;

const INF : i64 = 1000000007;

fn main() {
  input! {
    n : usize,
  };

  let mut dp = vec![vec![0usize; 3]; n];
  
  for i in 0..n {
    input! {
      a : usize, b : usize, c : usize,
    };
    
    if i == 0 {
      dp[0][0] = a;
      dp[0][1] = b;
      dp[0][2] = c;
    } else {
      dp[i][0] = a + max(dp[i - 1][1], dp[i - 1][2]);
      dp[i][1] = b + max(dp[i - 1][2], dp[i - 1][0]);
      dp[i][2] = c + max(dp[i - 1][0], dp[i - 1][1]);
    }
  }
  
  println!("{}", dp[n - 1].iter().max().unwrap());
}


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,a,b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        int s = 0; int t = i;
        for(int j = 0; j < 5; j++){
            s += t % 10;
            t /= 10;
        }
        if(a <= s && s <= b) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
n,m=map(int,input().split())
a=[[] for ii in range(n)]
for ii in range(m):
  p,s=input().split()
  p=int(p)-1
  a[p].append(s)
r=0
q=0
for ii in range(n):
  #print(a[ii])
  if "AC" in a[ii]:
    r+=1
    q+=a[ii].index("AC")
print(r,q)

Measured memory_bytes: 20272
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
 
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    ld pi=3.14159265359;
    ld r;
    cin>>r;
    cout<<fixed<<setprecision(10);
    cout<<(2.0*pi*r)<<endl;
    return 0;
}

Measured memory_bytes: 3764
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


#mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

from scipy.optimize import fmin



def main():
	n = int(input())
	xy = [list(map(int, input().split())) for _ in [0] * n]
	def calc(k):
		i, j = k
		return max((x - i) ** 2 + (y - j) ** 2 for x,y in xy)

	x, y = fmin(calc, [500, 500],disp=0)
	print(calc((x, y)) ** 0.5)



if __name__ == "__main__":
	main()


Measured memory_bytes: 30280