akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
	string s;

	/*
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	*/
	cin >> s;
	if(s.substr(0,4) == "YAKI"){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
while True:
    table = input().split()
    
    a = int(table[0])
    op = table[1]
    b = int(table[2])
    
    if op == "?":
        break
    
    elif op == "+":
        print(a + b)
    elif op == "-":
        print(a - b)
    elif op == "*":
        print(a * b)
    elif op == "/":
        print(a // b)
    


Measured memory_bytes: 5592
#include <iostream>
#include <vector>
 
int main(){
    u_int a;	// width
    u_int b;	// height
    while(std::cin >> a >> b){
        if(a == 0 && b == 0){
            break;
        }
		
		// initialization
        std::vector<std::vector<u_int>> path(a+1, std::vector<u_int>(b+1, 1));
        
        // construction
        u_int n;
        std::cin >> n;
        for(u_int i = 0; i < n; ++i){
            u_int x, y;
            std::cin >> x >> y;
            path[x][y] = 0;
        }
        
        // out path
        for(u_int i = 0; i < a+1; ++i) path[i][0] = 0;
        for(u_int i = 0; i < b+1; ++i) path[0][i] = 0;
        
        // calc the number of path
        for(u_int x = 1; x <= a; ++x){
            for(u_int y = 1; y <= b; ++y){
                if(path[x][y] != 0 && !(x == 1 && y == 1)){
                    path[x][y] = path[x-1][y] + path[x][y-1];
                }
            }
        }
        
        std::cout << path[a][b] << std::endl;
         
    }
    return 0;
}

Measured memory_bytes: 1204
import sys
input = sys.stdin.buffer.readline


N = int(input())
A = [list(map(int, input().split()))[::-1] for _ in range(N)]
day = 0
cnt = N
Last = set([i for i in range(N)])
while cnt:
    flag = True
    Done = [False] * N
    L = set()
    for i in Last:
        if len(A[i]) == 0:
            continue
        if Done[i]:
            continue
        x = A[i][-1] - 1
        if A[x] and (not Done[x]) and (A[x][-1] - 1 == i):
            A[i].pop()
            A[x].pop()
            Done[i] = True
            Done[x] = True
            L.add(i)
            L.add(x)
            flag = False
            if not A[i]:
                cnt -= 1
            if not A[x]:
                cnt -= 1
    Last = L
    if flag:
        break
    day += 1
if cnt:
    print(-1)
else:
    print(day)

Measured memory_bytes: 89248
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;
int main() {
    int n;
    cin >> n;
    int x[n][6];
    for (int i=0;i<n;i++){
        for (int j=0; j<6; j++) {
            cin >> x[i][j];
        }
    }
    
    char a[30]= {'N','N','N','N','E','E','E','N','N','N','E','E','E','N','N','N','E','N','N','N','E','N','N','N','E','E','E','N','N','N'};
    int b,c,d,e;
    b=c=d=e=0;
    for(int k=0;k<n;k++){
        for (int i=0;i<30;i++){
            if (a[i]=='E') {
                b=x[k][0];c=x[k][2];d=x[k][3];e=x[k][5];
                x[k][2]=b;x[k][5]=c;x[k][0]=d;x[k][3]=e;
                }
            
            if(a[i]=='N'){
                b=x[k][0];c=x[k][1];d=x[k][4];e=x[k][5];
                x[k][4]=b;x[k][0]=c;x[k][5]=d;x[k][1]=e;
                }
        for(int j=0;j<k;j++){
            if(x[j][0]==x[k][0]&&x[j][1]==x[k][1]&&x[j][2]==x[k][2]&&x[j][3]==x[k][3]&&x[j][4]==x[k][4]&&x[j][5]==x[k][5]){
                cout << "No"<<endl;
                goto l;
            }
        }
            }
        if(k == n-1){
            cout << "Yes" << endl;
            goto l;
        }
        }
    l:;
    return 0;
    
    }




Measured memory_bytes: 3088
#![allow(unused_imports)]

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

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};

fn main() {
    input! {
        x: i32,
    }
    for t in 1.. {
        if x == t * (t + 1) / 2 {
            println!("{}", t);
            return;
        }
        else if t * (t + 1) / 2 < x && x < (t + 1) * (t + 2) / 2 {
            println!("{}", t + 1);
            return;
        }
    }
}


Measured memory_bytes: 4352
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

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

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

	cin >> N;
	vector<long long int>c(26);
	for (auto &i : c)cin >> i;
	vector<vector<int>>v(N, vector<int>(26));
	for (auto &i : v)for (auto &j : i)cin >> j;
	vector<long long int>bef(26, -1);
	vector<long long int>t(N);
	for (auto &i : t) {
		cin >> i;
		i--;
	}
	cin >> K;
	long long int ans = 0;
	for (int i = 0; i < N; i++) {
		ans += v[i][t[i]];
		bef[t[i]] = i;
		for (int j = 0; j < 26; j++) {
			ans -= c[j] * (i - bef[j]);
		}
	}
	while (K--) {
		int a = -1, b = -1;
		cin >> L >> R;
		L--, R--;
		a = t[L];
		b = R;
		for (int j = 0; j < 26; j++)bef[j] = -1;
		for (int i = 0; i < N; i++) {
			ans -= v[i][t[i]];
			bef[t[i]] = i;
			ans += c[a] * (i-bef[a]);
			ans += c[b] * (i-bef[b]);
		}
		t[L] = R;
		for (int j = 0; j < 26; j++)bef[j] = -1;
		for (int i = 0; i < N; i++) {
			ans += v[i][t[i]];
			bef[t[i]] = i;
			ans -= c[a] * (i - bef[a]);
			ans -= c[b] * (i - bef[b]);
		}
		cout << ans << endl;
	}
	
}

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

const int kN = 2e3 + 5;

int ans[kN];
int Abs(int x) { return x > 0 ? x : -x; }

int main() {
	int n, x, y;
	scanf("%d%d%d", &n, &x, &y);
	for(int i = 1; i <= n; ++i)
		for(int j = i + 1; j <= n; ++j) {
			int cur_d = std::min({Abs(i - j), Abs(i - x) + Abs(j - y) + 1, Abs(i - y) + Abs(j - x) + 1});
			++ans[cur_d];
		}
	for(int i = 1; i < n; ++i)
		printf("%d\n", ans[i]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
int prime[1000001];
bool vis[1000001];

int main()
{
    ll n;
    int cnt = 0;
    int ans=0;
    scanf("%lld",&n);
    memset(vis, false, sizeof(vis));
    memset(prime, 0, sizeof(prime));
    for(int i = 2; i <= 1000000; i++)
    {
        if(!vis[i])
        prime[cnt++] = i;
        for(int j = 0; j<cnt && i*prime[j]<=1000000; j++)
        {
            vis[i*prime[j]] = true;
            if(i % prime[j] == 0) break;
        }
    }
    for(int i=0;i<cnt;i++)
    {
        int cou=0;
        while(n%prime[i]==0){n/=prime[i];cou++;}
        int t=1;
        while(cou>=t){cou-=t;t++;ans++;}
    }
    if(n>1)ans++;
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 8712
include Math

n = gets.to_i
p = n.times.map{|i|gets.split.map(&:to_f).push(i)}.sort
ans = Array.new(n,0.0)

l = []
a = p[0]
while a != l[0]
    l.push(a)
    b = p[0]
    for i in 1..n-1
        if b == a
            b = p[i]
        else
            v = (b[0]-a[0])*(p[i][1]-a[1])-(p[i][0]-a[0])*(b[1]-a[1])
            if v > 0 || (v == 0 && (p[i][0]-a[0])**2+(p[i][1]-a[1])**2 > (b[0]-a[0])**2+(b[1]-a[1])**2)
                b = p[i]
            end
        end
    end
    a = b
end

s = l.size
s.times do |i|
    u = atan(-(l[i-1][0]-l[i][0])/(l[i-1][1]-l[i][1]))
    v = atan(-(l[(i+1)%s][0]-l[i][0])/(l[(i+1)%s][1]-l[i][1]))
    u += PI if u-v <= Float::EPSILON
    ans[l[i][2]] = (u-v)/2/PI
end
puts ans

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 1) return (a * powmod(a, n - 1, mod)) % mod;
	return powmod((a * a) % mod, n / 2, mod);
}

int mod = 1000000007;
int fact[200001];
int finv[200001];

int comb(int n, int k) {
	if (k < 0) return 0;
	return fact[n] * finv[k] % mod * finv[n - k] % mod;
}

int n, k;

signed main() {
	int i;
	
	cin >> n >> k;
	
	fact[0] = 1;
	finv[0] = 1;
	for (i = 1; i <= 200000; i++) {
		fact[i] = (i * fact[i - 1]) % mod;
		finv[i] = powmod(fact[i], mod - 2, mod);
	}
	
	int ans = 0;
	for (i = max(1LL, n - k); i <= n; i++) {
		int res = comb(n, i) * comb(n - 1, i - 1);
		ans += res;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

  private void solve(Scanner in, PrintWriter out) {
    long x = in.nextLong();
    long e = 11;
    long ans = (x / e) * 2;
    long r = x % e;

    if (r > 0) {
      if (r <= 6) {
        ans++;
      } else {
        ans += 2;
      }
    }
    out.println(ans);

  }

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(in, out);
    in.close();
    out.close();
  }
}


Measured memory_bytes: 10320
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<climits>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define mkp make_pair
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;

int solve(){
	string s,t;
	cin>>s>>t;
	int n1=s.length();
	int n2=t.length();
	int mini=INT_MAX;
	rep(i,0,n1-n2+1){
		int cnt=0;
		rep(j,0,n2){
			if(s[i+j]!=t[j])cnt++;
		}
		mini=min(mini,cnt);
	}
	cout<<mini<<endl;
	return 0;
}
int main(){
    waste;
    int t;
    //cin>>t;
    t=1;
    while(t--){
       	solve();
    }
}


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

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

	vector<tuple<long long, int>> p;

	for (int i = 0; i < n; i++) {

		long long tmp_l;
		int tmp_i;

		cin >> tmp_l >> tmp_i;

		p.emplace_back(tmp_l, tmp_i);

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

	long long ans = 0;
	int tmoCnt = 0;
	int accumCnt = 1;

	for (int i = 0; i < m; i++) {

		if (accumCnt <= get<1>(p[tmoCnt]) ) {}

		else {
			tmoCnt++;
			accumCnt = 1;
		}
		ans += get<0>(p[tmoCnt]);
		accumCnt++;
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2420
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <queue>
using namespace std;

const int V = 6010;
const int E = 3010;
int n, m, cap;

struct dot{
	int p, oil;
}front, rear;

struct edge{
	int to, w;
};

vector<edge> G[V];
char s1[20], s2[20];

void add_edge(int u, int v, int d){
	edge ee;
	ee.to = v;
	ee.w = d;
	G[u].push_back(ee);
	ee.to = u;
	G[v].push_back(ee);
}

bool sta[V];
int dis[V][2010];
//bool inq[V][2010];

int main () { //freopen("in.txt", "r", stdin);
	while(~scanf("%d%d%d", &n, &m, &cap)){
		if(!n && !m && !cap) break;
		map<string, int> city;
		cap *= 10;
		scanf("%s %s", s1, s2);
		city[string(s1)] = 1;
		city[string(s2)] = 2;
		for(int i = 0; i < V; i++) G[i].clear();
		int u, v, d, cou = 2;
		for(int i = 0; i < n; i++){
			scanf("%s %s %d", s1, s2, &d);
			if(!city[string(s1)]) city[string(s1)] = ++cou;
			if(!city[string(s2)]) city[string(s2)] = ++cou;
			u = city[string(s1)];
			v = city[string(s2)];
			add_edge(u, v, d);
		}
		memset(sta, 0, sizeof(sta));
		for(int i = 0; i < m; i++){
			scanf("%s", s1);
			if(!city[string(s1)]) continue;
			else sta[city[string(s1)]] = 1;
		}
		queue<dot>q;
		front.oil = cap;
		front.p = 1;
		q.push(front);
		int mmin  = 0x3f3f3f3f;
		//memset(inq, 0, sizeof(inq));
		memset(dis, 0x3f, sizeof(dis));
		dis[1][cap] = 0;
		int ok = 0;
		while(!q.empty()){
			front = q.front();
			q.pop();
		//	inq[front.p][front.oil] = false;
			if(front.p == 2) {ok = 1; if(dis[2][front.oil] < mmin) mmin = dis[2][front.oil]; continue; }
			for(int i = 0; i < G[front.p].size(); i++){
				if(G[front.p][i].w > front.oil) continue;
				rear.oil = front.oil -G[front.p][i].w;
				rear.p = G[front.p][i].to;
				if(sta[rear.p]) rear.oil = cap;
				if(dis[rear.p][rear.oil] > dis[front.p][front.oil] + G[front.p][i].w){
					dis[rear.p][rear.oil] = dis[front.p][front.oil] + G[front.p][i].w;
					//if(!inq[rear.p][rear.oil]){
					//	inq[rear.p][rear.oil] = 1;
						q.push(rear);
					//}
				}
			}
		}
		if(!ok)puts("-1");
		else printf("%d\n", mmin);
	}
}

Measured memory_bytes: 59184
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())

int main(void){
  int n;
  while(cin>>n,n){
    stack<int> stk;
    while(n){
      int amari = n%-10;
      if(amari<0)amari+=10;
      stk.push(amari);
      n = (n-amari)/-10;
    }
    while(!stk.empty()){
      cout<<stk.top();
      stk.pop();
    }
    cout<<endl;
  }

  return 0;
}

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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  for(int i=0;i<n;i++){
    char c;cin>>c;
    if(c=='Y'){cout<<"Four"<<endl;return 0;}
  }
  cout<<"Three"<<endl;

  return 0;
}


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

using namespace std;

typedef long long int ll;

const ll MOD = 1000000007;

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

  int N;
  cin >> N;
  vector<int> a(N);
  for (auto &x: a) cin >> x;

  for (auto &x: a) x = -x; // invert sign

  multiset<int> maxCol;
  maxCol.insert(a[0]);
  for (int i = 1; i < N; i++) {
    auto it = maxCol.upper_bound(a[i]);
    if (it != maxCol.end()) {
      maxCol.erase(it);
    }
    maxCol.insert(a[i]);
  }

  cout << maxCol.size() << endl;

  return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <list>
#include <math.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define sz(x) int(x.size())

typedef long long ll;

using namespace std;

/*******-c++14 don't include-*******/
template<typename T>
T gcd(T a, T b){if( b == 0)return a; return gcd(b, a%b); }
template<typename T>
T lcm(T a, T b){return a*b/gcd(a,b); }
void printArr(int *a, int len){for(int i=0; i<len; i++){if(i)cout << " ";cout << a[i];}cout << endl;}
/*******---------------------*******/

static const int INTINF = (2147483647);
static const ll LLINF = (1ll<<32);
static const int MAX = 100001;

int arr[MAX];

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> v;
    rep(i, s.size()){
        v.push_back(s[i] - 'A');
    }
    rep(i, s.size()){
        v[i] += n;
        if(v[i] >= 26){
            v[i] -= 26;
        }
    }
    rep(i, s.size()){
        cout << (char)(v[i] + 'A');
    }
    cout << endl;
    
    
    return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int w, h, n;
  cin >> w >> h >> n;

  int t = h, b = 0, l = 0, r = w;
  for (int i = 0; i < n; ++i) {
    int x, y, a;
    cin >> x >> y >> a;
    switch (a) {
      case 1:
        l = max(l, x);
        break;
      case 2:
        r = min(r, x);
        break;
      case 3:
        b = max(b, y);
        break;
      default:
        t = min(t, y);
        break;
    }
  }

  cout << max(0, r - l) * max(0, t - b) << '\n';
  return 0;
}

Measured memory_bytes: 3604
n, ma, mb = list(map(int, input().split()))

a, b, c = [], [], []

for i in range(n):
    aa,bb,cc = list(map(int,input().split()))
    a.append(aa)
    b.append(bb)
    c.append(cc)

dp = [[0]*(sum(b)+1) for i in range(sum(a)+1)]

max_a = 0
max_b = 0
for i in range(n):
    max_a += a[i]
    max_b += b[i]
    for ai in range(a[i], max_a+1)[::-1]:
        for bi in range(b[i], max_b+1)[::-1]:
            if dp[ai - a[i]][bi - b[i]]:
                if dp[ai][bi]:
                    dp[ai][bi] = min(dp[ai-a[i]][bi-b[i]]+c[i],dp[ai][bi])
                else:
                    dp[ai][bi] = dp[ai-a[i]][bi-b[i]]+c[i]
            elif ai == a[i] and bi == b[i]:
                if dp[ai][bi]:
                    dp[ai][bi] = min(c[i],dp[ai][bi])
                else:
                    dp[ai][bi] = c[i]

ans = float("inf")
for i in range(1, min(max_a//ma, max_b//mb)):
    if dp[i*ma][i*mb]:
        ans = min(ans, dp[i*ma][i*mb])
if ans == float("inf"):
    print(-1)
else:
    print(ans)

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

int n,m;
string str[20];
int s[10], id[30];
bool head[10];
vector<int> comb[6];
vector<int> pre[1<<10], suf[1<<10];

string bin(int a){
  string res = "";
  for(int i=0;i<10;i++){
    if((a>>i)&1)res += "1";
    else res += "0";
  }
  return res;
}

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

  int lim = 1<<10;
  for(int i=1;i<6;i++){
    int tmp = (1<<i)-1;
    while(tmp < lim){
      comb[i].push_back(tmp);
      int x = tmp & -tmp, y = tmp + x;
      tmp = ( ( (tmp & ~y) /x ) >> 1) | y;
    }
  }

  while(cin >> n,n){
    vector<char> v;
    for(int i=0;i<n;i++){
      cin >> str[i];
      for(int j=0;j<str[i].size();j++){
	v.push_back(str[i][j]);
      }
    }

    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());

    m = v.size();
    for(int i=0;i<m;i++)id[v[i]-'A'] = i;

    for(int i=0;i<m;i++){
      s[i] = 0; head[i] = false;
    }

    for(int i=0;i<n;i++){
      if(str[i].size()>1)head[id[str[i][0]-'A']] = true;

      int tmp = (i==n-1?-1:1);
      for(int j=str[i].size()-1;j>=0;j--){
	s[id[str[i][j]-'A']] += tmp;
	tmp *= 10;
      }
    }

    if(m==1){
      if(s[0] == 0 && !head[0])cout << 1 << endl;
      else cout << 0 << endl;
      continue;
    }

    int plen = m/2, slen = m-plen;
 
    for(int i=0;i<comb[plen].size();i++){
      int comb1 = comb[plen][i];
      pre[comb1].clear();

      vector<int> tmp;
      for(int j=0;j<10;j++){
	if( (comb1>>j)&1 )tmp.push_back(j);
      }
      
      do{
	int sum = 0;
	bool f = true;
	for(int j=0;j<plen;j++){
	  if(tmp[j] == 0 && head[j]){
	    f = false;
	    break;
	  }
	  sum += s[j]*tmp[j];
	}
	if(f)pre[comb1].push_back(sum);
      }while(next_permutation(tmp.begin(),tmp.end()));
      
      sort(pre[comb1].begin(),pre[comb1].end());
    }
    
    for(int i=0;i<comb[slen].size();i++){
      int comb1 = comb[slen][i];
      suf[comb1].clear();

      vector<int> tmp;
      for(int j=0;j<10;j++){
	if( (comb1>>j)&1 )tmp.push_back(j);
      }
      
      do{
	int sum = 0;
	bool f = true;
	for(int j=0;j<slen;j++){
	  if(tmp[j] == 0 && head[plen+j]){
	    f = false;
	    break;
	  }
	  sum += s[plen+j]*tmp[j];
	}
	if(f)suf[comb1].push_back(sum);
      }while(next_permutation(tmp.begin(),tmp.end()));
      
      sort(suf[comb1].begin(),suf[comb1].end());
    }

    int ans = 0;
    for(int i=0;i<comb[plen].size();i++){
      for(int j=0;j<comb[slen].size();j++){
	int comb1 = comb[plen][i], comb2 = comb[slen][j], num;
	if(!(comb1&comb2)){
	  for(int k=0;k<pre[comb1].size();k++){
	    if(!k || (pre[comb1][k] != pre[comb1][k-1])){
	      num = upper_bound(suf[comb2].begin(),suf[comb2].end(),-pre[comb1][k])
		- lower_bound(suf[comb2].begin(),suf[comb2].end(),-pre[comb1][k]);
	    }
	    ans += num;
	  }
	}
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1624
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

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

    int n;
    long k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    long l = -1000000000000000001LL;
    long r = 1000000000000000001LL;
    while (r > l + 1) {
        long m = (l + r) / 2;
        long s = 0;
        // count a[i] + a[j] < m
        for (int i = 0; i < n; i++) {
            if (a[i] > 0) {
                int ll = -1; // <= m
                int rr = n; // > m
                while (rr > ll + 1) {
                   int mm = (ll + rr) / 2;
                   if ((long)a[i] * a[mm] <= m) {
                       ll = mm;
                   } else {
                       rr = mm;
                   }
                }
                s += rr;
            } else {
                int ll = -1; // > m
                int rr = n; // <= m
                while (rr > ll + 1) {
                    int mm = (ll + rr) / 2;
                    if ((long)a[i] * a[mm] > m) {
                        ll = mm;
                    } else {
                        rr = mm;
                    }
                }
                s += n - rr;
            }
        }
        for (int i = 0; i < n; i++) {
            if ((long)a[i] * a[i] <= m) s--;
        }
        s /= 2;
        if (s < k) {
            l = m;
        } else {
            r = m;
        }
//        cout << m << " " << s << "\n";
    }
    cout << r << "\n";

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int INF=INT_MAX-1;

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

    int n;
    cin >> n;
    bool ok=0;
    while(n>0 && !ok){
        ok=(n%10)==7;
        n/=10;
    }
    if(ok)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for(const auto& e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void yn(bool j){cout << (j ? "Yes" : "No") << endl; return;}
template<class Head> void pt(Head&& head){cout << head << endl; return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> long long bcount(T1 v, T2 a){return upper_index(v, a) - lower_index(v, a);} 
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

int main(){
    ll N, K; cin >> N >> K;
    vector<ll> h(N, 1);
    rep(i, K){
        ll d; cin >> d;
        rep(j, d){
            ll a; cin >> a;
            h[a-1]  = 0;
        }
    }
    pt(accumulate(all(h), 0LL));
}

Measured memory_bytes: 3632
s = list(input())

all = len(s)
g = s.count('g')
p = s.count('p')

top = g-p

if all%2 == 1:
	deer = 1
	top += 1
	top //= 2
elif all%2 == 0:
	deer = 0
	top //= 2 
print(top - deer)

Measured memory_bytes: 3956
#include<iostream>
#include<stdio.h>
using namespace std;

double kakuritu(double N);

int main() {
	double a;

	cin >> a;

	if (1 <= a && a <= 100) {
		printf("%.6f", kakuritu(a));
	}
	return 0;
}

double kakuritu(double N) {
	double a,x = 0;
	
	for (int i = 1; i <= N; i++) {
		if (i % 2 == 1) {
			x++;
		}
	}
	a = (x / N);

	return a;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)


function main()
L, R, d = parseMap(split(readline()))

ans = 0
for i in L:R
    if i % d == 0
        ans += 1
    end
end

println(ans)

end

main()

Measured memory_bytes: 164676
#include<bits/stdc++.h>
#include<numeric>
#include<cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
const long long mod=1e9+7;
const int INF=1001001001;
const int inf=100000;
//const ll inf=1e9+7;
//const ll ful=1e18;
using namespace std;
//namespace mp = boost::multiprecision;
int main() 
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans_ac=a*c;
	ll ans_ad=a*d;
	ll ans_a=max(ans_ac,ans_ad);
	ll ans_bc=b*c;
	ll ans_bd=b*d;
	ll ans_b=max(ans_bc,ans_bd);
	ll ans=max(ans_a,ans_b);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <string.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define ll long long
#define inf 0x3f3f3f3f
#define ms(x,a) memset(x,a,sizeof(x))
#define sd(x) scanf("%d",&x)
#define sdd(x,y) scanf("%d%d",&x,&y)
#define sddd(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld%lld",&x,&y)
#define slll(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define sf(x) scanf("%lf",&x)
#define sff(x,y) scanf("%lf%lf",&x,&y)
#define sfff(x,y,z) scanf("%lf%lf%lf",&x,&y,&z)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define repp(i,n,a) for(int i=n;i>=a;i--)
#define pd(x) printf("%d\n",x)
#define pdd(x,y) printf("%d%d\n",x,y)
#define pddd(x,y,z) printf("%d%d%d\n",x,y,z)
#define pl(x) printf("%lld\n",x)
#define pll(x,y) printf("%lld%lld\n",x,y)
#define plll(x,y,z) printf("%lld%lld%lld\n",x,y,z)
#define debug() printf("***\n")
using namespace std;
int n,m;
ll a,b,c;

int main() {
	while(sd(n)!=EOF){
		int cnt;
		if(n==1e5){
			cnt=99999-9999+999-99+9;
		}
		else if(n<1e5&&n>=10000){
			cnt=n-9999+999-99+9;
		}
		else if(n<10000&&n>=1000){
			cnt=999-99+9;
		}
		else if(n<1000&&n>=100){
			cnt=n-99+9;
		}
		else if(n<100&&n>=10){
			cnt=9;
		}
		else {
			cnt=n;
		}
		pd(cnt);
	}
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int n; cin >> n;
  Graph a(n, vector<int> (n-1));
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n-1; ++j){
      cin >> a[i][j];--a[i][j];
    }
  }
  vector<int> idx(n);
  queue<int> q;
  for(int i = 0; i < n; ++i)q.push(i);
  
  int ans = 0;
  bool f = true;
  while(f){
    f = false;
    ++ans;
    unordered_set<int> se;
    queue<int> q2;
    while (q.size()){
      int i = q.front(); q.pop();
      if(se.count(i))continue;
      if(idx[i]==n-1)continue;
      int t = a[i][idx[i]];
      if(se.count(t))continue;
      if(idx[t]==n-1)continue;
      if(a[t][idx[t]]==i){
        f = true;
        se.insert(i);
        se.insert(t);
        ++idx[i];++idx[t];
        q2.push(i); q2.push(t);
      }
    }
    swap(q,q2);
  }
  for(int i = 0; i < n; ++i){
    if(idx[i]!=n-1)ans = 0;
  }
  cout << ans-1 << endl;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;cin>>N>>M;
  vector<string>A(N);for(int i=0;i<N;i++)cin>>A[i];
  vector<string>B(M);for(int i=0;i<M;i++)cin>>B[i];
  bool ans=false;
  for(int i=0;i<N-M+1;i++)for(int j=0;j<N-M+1;j++){
    bool tmp=true;
    for(int k=0;k<M;k++){
      if(A[i+k].substr(j,M)!=B[k])tmp=false;
    }
    if(tmp)ans=tmp;
  }
  cout<<(ans?"Yes":"No");
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}


int main(void){
  int N;
  cin >> N;
  int a1[N], a2[N];
  rep(i, N) cin>>a1[i];
  rep(i, N) cin>>a2[i];
  int ans = 0;
  rep(i, N){
    int ans_now = 0;
    rep(j, i+1) ans_now += a1[j];
    rep_s(j, i, N) ans_now += a2[j];
    ans = max(ans, ans_now);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
#define fr first
#define sc second
#define EPS 1e-8
#define INF 1 << 30

int main()
{
  int n;
  int num[15], dist[15], box[15];
  int dp[1 << 15][15];
  int prev[1 << 15][15];
  int speed[1 << 15];
  fill_n( *prev, 15 * (1 << 15), -1);
  fill_n( *dp, 15 * (1 << 15), INF);

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> num[i] >> dist[i] >> box[i];
  }
  
  for(int i = 0; i < 1 << n; i++){
    int ret = 0;
    for(int j = 0; j < n; j++){
      if(i >> j & 1) continue;
      ret += box[j];
    }
    speed[i] = 7 + ret * 2;
  }
  for(int i = 0; i < n; i++){
    dp[1 << i][i] = 0;
  }
           
  for(int bit = 0; bit < 1 << n; bit++){
    for(int i = 0; i < n; i++){
      if(!((bit >> i) & 1)) continue;
      for(int k = 0; k < n; k++){
        int power = abs( dist[i] - dist[k]) * speed[bit];
        if((bit >> k) & 1) continue;

        int nxbit = bit|(1 << k);
        if(dp[nxbit][k] > dp[bit][i] + power){
          dp[nxbit][k] = dp[bit][i] + power;
          prev[nxbit][k] = i;
        }
      }
    }
  }
  
  int pos = 0;
  int bit = (1 << n) - 1;
  for(int i = 1; i < n; i++){
    if( dp[bit][pos] > dp[bit][i]) pos = i;
  }
  queue< int > st;
  while(pos != -1){
    st.push(num[pos]);
    int foo = prev[bit][pos];
    bit ^= 1 << pos;
    pos = foo;
  }
  while(st.size() > 1){
    cout << st.front() << " ";
    st.pop();
  }
  cout << st.front() << endl;
  return(0);
}

Measured memory_bytes: 5168
#!/usr/bin/env python3
import sys, os
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
if os.environ.get("USER") == "shun":
    def debug(*args): print(*args, file=sys.stderr)
else:
    print("NO DEBUG", file=sys.stderr)
    def debug(*args): pass
def exit(): sys.exit(0)


a, b = map(int, input().split())
c, d = map(int, input().split())
e, f = map(int, input().split())


count = {1: 0, 2: 0, 3: 0, 4: 0}


for i in [a, b, c, d, e, f]:
    count[i] += 1

count_list = []
for key in count.keys():
    count_list.append(count[key])

m = max(count_list)
if m >= 3:
    print("NO")
else:
    print("YES")


Measured memory_bytes: 38384
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

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

int N;

int maxcandy;
int candy;

void dfs(int x, int y, const vector< vector<int> > &v)
{
    candy += v[y][x];

    if (y == 1 && x == N - 1)
    {
        maxcandy = max(maxcandy, candy);
        return;
    }

    for (int i = 0; i < 2; i++)
    {
        int nx = x + dx[i];
        int ny = y + dy[i];

        if (N - 1 < nx || 1 < ny) continue;

        int tmp = candy;
        dfs(nx, ny, v);
        candy = tmp;
    }
}

int main()
{
    if (scanf("%d", &N) < 1) return 0;

    vector< vector<int> > field(2, vector<int>(N, -1));

    for (int i = 0; i < 2; i++)
        for (int j = 0; j < N; j++)
            if (scanf("%d", &field[i][j]) < 1) return 0;

    maxcandy = 0;
    candy = 0;

    dfs(0, 0, field);

    printf("%d\n", maxcandy);

    return 0;
}


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

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

  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    
    sum += (r + 1) - l;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
from collections import deque

n = int(input())
A = deque()

for i in range(n):
  order = input().split()
  if order[0] == "insert":
    A.appendleft(order[1])
  elif order[0] == "delete":
    try:
      A.remove(order[1])
    except ValueError:
      pass
  elif order[0] == "deleteFirst":
    A.popleft()
  elif order[0] == "deleteLast":
    A.pop()

print(" ".join(map(str, A)))



Measured memory_bytes: 69740
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
	int N=0,i=0;
	int A[300000];
	int B[300000]={};
	
	scanf("%d",&N);
	
	while(i<N-1){
		scanf("%d",&A[i]);
		B[A[i]]++;		
		i++;
	}
	
	for(i=1;i<=N;i++){
		printf("%d\n", B[i]);
	}


	return 0;
}


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

std::vector<int> A;
static const int INF = 1001001001;
int cnt = 0;

void merge(int left, int midp1, int right){
    std::vector<int> B, C;
    int an, bn, cn, j, k;

    an = right - left + 1;
    bn = midp1 - left;
    cn = right - midp1 + 1;

    B.resize(bn);
    C.resize(cn);

    for(int i = 0; i < bn; i++){
	B[i] = A[left + i];
    }
    for(int i = 0; i < cn; i++){
	C[i] = A[midp1 + i];
    }

    B.push_back(INF);
    C.push_back(INF);

    j = 0;
    k = 0;

    for(int i = 0; i < an; i++){
	if(B[j] < C[k]){
	    A[left + i] = B[j];
	    j++;
	}else{
	    A[left + i] = C[k];
	    k++;
	}
	cnt++;
    }
}

int mergeSort(int left, int right){
    if(left >= right){
	return 0;
    }
    int mid = (left + right) / 2;
    mergeSort(left, mid);
    mergeSort(mid + 1, right);
    merge(left, mid + 1, right);
    return 0;
}
    

int main(void){
    int m, n;
    std::cin >> n;
    A.resize(n);

    for(int i = 0; i < n; i++){
	std::cin >> A[i];
    }

    mergeSort(0, n-1);

    for(int i = 0; i < n; i++){
	if(i != 0){
	    std::cout << " " << A[i];
	}else{
	    std::cout << A[i];
	}
    }
    std::cout << std::endl;

    std::cout << cnt << std::endl;

    return 0;

}



Measured memory_bytes: 8600
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if(s.size() == 2) cout << s << endl;
  else{
    cout << s[2] << s[1] << s[0] << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

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

    Long n = sc.nextLong();
    Long m = sc.nextLong();
    Long d = sc.nextLong();

    double ans = 2 * (n-d) * (m-1) / Math.pow(n, 2);

    if (d==0) {
      ans /= 2.0;
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 23764
import sys
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

def factorial(n):
    if n == 1: return 1
    ret = 1
    for i in range(2, n + 1):
        ret *= i
        ret %= mod
    return ret

def main():
    N, M = map(int, input().split())
    if abs(N - M) > 1:
        print(0)
        return
    if N != M:
        print((factorial(M) * factorial(N)) % mod)
    else:
        print((factorial(M) * factorial(N) * 2) % mod)

if __name__ == "__main__":
    main()


Measured memory_bytes: 62516
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
string s[8];
bool is(int x,int y){
	return 0<=x&&x<8&&0<=y&&y<8;
}
int dx[8]={1,1,0,-1,-1,-1,0,1},dy[8]={0,1,1,1,0,-1,-1,-1};
int main(){
	rep(i,8) cin>>s[i];
	bool mami=true;
	bool skip=false;
	while(true){
		if(mami){
			int chi,chj,mx=0;
			rep(i,8) rep(j,8){
				if(s[i][j]!='.') continue;
				int stone=0;
				rep(d,8){
					int x=i,y=j;
					int cnt=0;
					x+=dx[d],y+=dy[d];
					while(is(x,y)&&s[x][y]=='x'){
						x+=dx[d],y+=dy[d];
						cnt++;
					}
					if(is(x,y)&&s[x][y]=='o'&&cnt>0) stone+=cnt;
				}
				if(stone>mx){
					chi=i,chj=j,mx=stone;
				}
			}
			if(mx==0){
				if(skip) break;
				skip=true;
			}else{
				rep(d,8){
					int x=chi,y=chj;
					int cnt=0;
					x+=dx[d],y+=dy[d];
					while(is(x,y)&&s[x][y]=='x'){
						x+=dx[d],y+=dy[d];
						cnt++;
					}
					if(is(x,y)&&s[x][y]=='o'&&cnt>0){
						int xx=chi,yy=chj;
						while(true){
							xx+=dx[d],yy+=dy[d];
							if(s[xx][yy]=='o') break;
							s[xx][yy]='o';
						}
					}
				}
				s[chi][chj]='o';
				skip=false;
			}
		}else{
			int chi,chj,mx=0;
			for(int i=7;i>=0;i--) for(int j=7;j>=0;j--){
				if(s[i][j]!='.') continue;
				int stone=0;
				rep(d,8){
					int x=i,y=j;
					int cnt=0;
					x+=dx[d],y+=dy[d];
					while(is(x,y)&&s[x][y]=='o'){
						x+=dx[d],y+=dy[d];
						cnt++;
					}
					if(is(x,y)&&s[x][y]=='x'&&cnt>0) stone+=cnt;
				}
				if(stone>mx){
					chi=i,chj=j,mx=stone;
				}
			}
			if(mx==0){
				if(skip) break;
				skip=true;
			}else{
				rep(d,8){
					int x=chi,y=chj;
					int cnt=0;
					x+=dx[d],y+=dy[d];
					while(is(x,y)&&s[x][y]=='o'){
						x+=dx[d],y+=dy[d];
						cnt++;
					}
					if(is(x,y)&&s[x][y]=='x'&&cnt>0){
						int xx=chi,yy=chj;
						while(true){
							xx+=dx[d],yy+=dy[d];
							if(s[xx][yy]=='x') break;
							s[xx][yy]='x';
						}
					}
				}
				s[chi][chj]='x';
				skip=false;
			}
		}
		mami=!mami;
	}
	rep(i,8) cout<<s[i]<<endl;
}

Measured memory_bytes: 1184
module ABC141

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public  :: task_B
  private :: check_string

  ! constants for this <module>
  integer(INT32),           parameter, private :: len_string_max = 100_INT32
  character(len=1, kind=1), parameter, private :: char_left      = 'L'
  character(len=1, kind=1), parameter, private :: char_right     = 'R'

  ! variables for this <module>
  character(len=len_string_max, kind=1) :: buffer

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_B

    ! variables for this <subroutine>

    ! STEP.01
    ! read out the given string
    read(unit=INPUT_UNIT, fmt='(A)') buffer

    ! STEP.02
    ! output the answer of this task
    if ( check_string( len_trim(buffer) ) ) then
      write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'Yes'
    else
      write(unit=OUTPUT_UNIT, fmt='(A)', advance='yes') 'No'
    end if

    ! STEP.END
    return

  end subroutine task_B

  function check_string (len_string) result(stat)

    ! arguments for this <function>
    integer(INT32), intent(in) :: len_string

    ! return value of this <function>
    logical :: stat

    ! support variables for this <function>
    integer(INT32) :: itr

    ! STEP.01
    ! initialize the return value of this function
    stat = .true.

    do itr = 1_INT32, len_string, 1_INT32
      if (mod(itr, 2_INT32) .eq. 0_INT32) then
        if (buffer(itr:itr) .eq. char_right) then
          stat = .false.
          return
        end if
      else
        if (buffer(itr:itr) .eq. char_left) then
          stat = .false.
          return
        end if
      end if
    end do

    return

  end function check_string

end module ABC141


program main

  ! <module>s to import
  use, non_intrinsic :: ABC141

  ! require all variables to be explicitly declared
  implicit none

  call task_B

end program main

Measured memory_bytes: 768
import java.util.*;

class Main {
    private static Scanner sc;

    public static void main(final String[] args) {
        sc = new Scanner(System.in);
        int a = sc.nextInt(),b = sc.nextInt(),ans = 0;
        int[] list = new int[a];
        for(int i = 0; i < b; i++){
            int c = sc.nextInt();
            for (int j = 0; j < c; j++){
                list[sc.nextInt()-1] +=1;
            }
        }
        for(int x: list){
            if(x == 0) ans++;
        }
        System.out.println(ans);
    }
}








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

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if(a >= b){
        cout << "delicious" << endl;
    }else if(x >= b - a){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct node{
  int key;
  node *left,*right,*p;
  node(){}
  node(int key):key(key){left=right=p=NULL;};
};
node *root;
void insert(node z){
  node *y=NULL;
  node *x=root;
  while(x!=NULL){
    y=x;
    if(z.key<x->key) x=x->left;
    else x=x->right;
  }
  z.p=y;
  if(y==NULL) root=new node(z);
  else if(z.key<y->key) y->left=new node(z);
  else y->right=new node(z);
}
bool find(int z){
  node *x=root;
  while(x!=NULL){
    if(z==x->key) return true;
    if(z<x->key) x=x->left;
    else x=x->right;
  }
  return false;
}
void inorderTreeWalk(node *v){
  if(v==NULL) return;
  inorderTreeWalk(v->left);
  cout<<" "<<v->key;
  inorderTreeWalk(v->right);
}
void preorderTreeWalk(node *v){
  if(v==NULL) return;
  cout<<" "<<v->key;
  preorderTreeWalk(v->left);
  preorderTreeWalk(v->right);
}
signed main(){
  int n;
  cin>>n;
  root=NULL;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    //cout<<(root==NULL?-1:root->key)<<endl;
    if(s=="print"){
      inorderTreeWalk(root);
      cout<<endl;
      preorderTreeWalk(root);
      cout<<endl;
      continue;
    }
    int x;
    cin>>x;
    if(s=="insert"){
      insert(node(x));
    }
    if(s=="find"){
      cout<<(find(x)?"yes":"no")<<endl;
    }
  }
  return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> vvec(N);
  for (int i = 0; i < N; i++)
  {
    cin >> vvec[i];
  }
  sort(vvec.begin(), vvec.end());
  double ans = vvec[0];
  for (int i = 1; i < N; i++)
  {
    ans = vvec[i] + ans;
    ans /= 2.0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
bis=0
yen=0

k,a,b=map(int,input().split())

k_num =k #残り回数
n=b-a #クッキーを円を経由することにより増える枚数

k_num-=(a-1) #円に交換できるまでクッキーを増やす

func_num=k_num/2 #交換できる回数
func_num=int(func_num)
#print(func_num)
add_bis=func_num*n #増やせたクッキーの数
#print(add_bis)
if(k_num%2==1): #奇数なので最後に割っとく
    bis +=1

#print(bis)

if(k<3 and a>1 or n<3):
    print(k+1)
else:
    print(bis+add_bis + a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    cout << n * n * n << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(15000)
n,m = map(int,sys.stdin.readline().split())
g = list(range(n))
def find(x):
  while g[x] != x:
    x = g[x]
    g[x] = g[g[x]]
  return x
def union(s,t):
  sp = find(s)
  tp = find(t)
  if sp == tp:
    pass
  elif sp < tp:
    g[sp] = tp
  else:
    g[tp] = sp
for i in range(m):
  s,t = map(int,sys.stdin.readline().split())
  union(s,t)

q = int(sys.stdin.readline())
for i in range(q):
  s,t = map(int,sys.stdin.readline().split())
  if find(s) == find(t):
    print("yes")
  else:
    print("no")


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

#define endl '\n'
#define ll long long
#define ui unsigned int
#define ull unsigned long long

int main(void)
{
    int h;
    while (cin >> h)
    {
        vector<int> node;
        for (int i = 0 ; i < h ; i++)
        {
            int tmp;
            cin >> tmp;
            node.push_back(tmp);
        }
        make_heap(node.begin(), node.end());
        for (int i = 0 ; i < h ; i++)
        {
            cout << " " << node[i];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 4852
#include<iostream>

using namespace std;

int main(){
    long long a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    if(k>0){
        ans+=(k<a?k:a);
        k-=(a+b);
    }
    if(k>0){
        ans-=k;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3680