akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using ll = int_fast64_t;
const int MAX = 510000;
const int MOD = 1e9+7;

ll fac[MAX], finv[MAX], inv[MAX];

void combinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i=2; i<MAX; 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;
    }
}

ll comb(int n, int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
        int n, k;
        scanf("%d %d", &n, &k);
        std::vector<int> a(n);
        for(int i=0; i<n; i++) scanf("%d", &a[i]);
        std::sort(a.begin(), a.end());
        std::vector<int> b(a);
        std::reverse(b.begin(), b.end());

        combinit();
        ll ans = 0;
        for(int i=0; i<n-k+1; i++){
                ans = (ans + (b[i]-a[i])%MOD * comb(n-i-1, k-1) % MOD) % MOD;
        }

        if(ans<0) ans += MOD;
        printf("%ld\n", ans);
        return 0;
}

Measured memory_bytes: 12928
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


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

	int res = 0;
	for (int x=1; x<=N; x++) {
		int n = x;
		int sum = 0;
		while (n>0) {
			sum += n%10;
			n /= 10;
		}
		if (A<=sum and sum<=B) res += x;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
while True:
    H, W = map(int, input().split())

    if H != 0 and W != 0:
        for h in range(H):
            for w in range(W):
                if h == 0 or h == H-1:
                    print("#", end = "")
                elif w == 0 or w == W-1:
                    print("#", end = "")
                else:
                    print(".", end = "")
            print("")
        print("")
    else:
        break


Measured memory_bytes: 7008
N = int(input())
D = [0]+[int(x) for x in input().split()]
D.sort()
li = []
for ind, d in enumerate(D):
    if(ind%2==0):
        li.append(d)
    else:
        li.append(24-d)
li.sort()
li.append(24)
ans = 24
for ind, d in enumerate(li[:-1]):
    ans = min(li[ind+1]-d, ans)
print(ans if ans!=24 else 0)



Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		long T1 = scn.nextLong(), T2 = scn.nextLong(), A1 = scn.nextLong(), A2 = scn.nextLong(), B1 = scn.nextLong(),
				B2 = scn.nextLong();
		long ans = 0;
		if (A1 < B1) {
			long buf1 = A1, buf2 = A2;
			A1 = B1;
			A2 = B2;
			B1 = buf1;
			B2 = buf2;
		}
		if (A2 < B2) {
			long d = (B1 * T1 + B2 * T2) - (A1 * T1 + A2 * T2);
			if (d == 0) {
				System.out.println("infinity");
				return;
			}
			if (d > 0) {
				if ((A1 -B1)* T1 % d == 0) {
					ans = ((A1 - B1) * T1 / d)*2;
				} else {
					ans = ((A1 - B1) * T1 / d)*2 + 1;
				}
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 22996
N = int(input())
S = list(input())
dp = [[0]*N for _ in range(N)]
dp[N-1][N-1] = 1
for i in range(N-1, -1, -1):
  if S[i] == S[-1]:
    dp[N-1][i] = 1

for i in range(N-1, -1, -1):
  if S[i] == S[-1]:
    dp[i][N-1] = 1

for i in range(N-1, 0, -1):
  for j in range(N-1, 0, -1):
    if S[i-1] == S[j-1]:
      dp[i-1][j-1] = dp[i][j] + 1

ans = 0
for i in range(N):
  for j in range(i+1, N):
    ans = max(ans, min(dp[i][j], j-i))
print(ans)

Measured memory_bytes: 230664
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    if (n > 17) {
        cout << "Yes" << endl;
        return 0;
    }
    for (int i = 0; i <= n / 7; ++i) if ((n - i * 7) % 4 == 0) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
s=int(input())
ans=0
for i in range(1,1000):
    t=s
    t-=3*i
    if t<0:
        break
    c=1
    for j in range(i-1):
        c=c*(t+i-1-j)//(j+1)
    ans+=c%(10**9+7)
print(ans%(10**9+7))

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

typedef long long ll;
typedef std::pair<ll, ll> l_l;
typedef std::pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

using namespace std;

int main() {
    int a;
    string s;
    cin >> a >> s;
    
    if (a >= 3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.algorithm;

void main() {
    auto input = getStdin!(string[])[0..$];
    auto c = input[0].split(" ")[1].to!(int);
    auto set = input[1..$];
    int[][] matrix = [];
    foreach (line; set) {
    	auto num = line.split(" ").to!(int[]);
    	matrix ~= num;
    }
    
    for (int i = 0; i < matrix.length; i++) {
    	int sum = reduce!((a, b) => a + b)(0, matrix[i]);
    	matrix[i] ~= sum;
    }
    
    int[] extra = [];
    for (int i = 0; i < c + 1; i++) {
    	int sum = 0;
    	for (int j = 0; j < matrix.length; j++) {
    		sum += matrix[j][i];
    	}
    	extra ~= sum;
    }
    
    matrix ~= extra;
    
    for (int i = 0; i < matrix.length; i++) {
    	matrix[i].to!(string[]).join(" ").writeln;
    }
}

T getStdin(T)() {
    string[] cmd;
    string line;
    while ((line = chomp(stdin.readln())) != "") cmd ~= line;
    return to!(T)(cmd);
}

Measured memory_bytes: 3204
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long lint;

int main()
{
	int n;
	int a[100000];
	int t[300000];
	
	lint sum = 0;
	
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++){
		scanf("%d", a + i);
		sum += a[i];
	}
	
	lint left = 0, right = sum / 3;
	
	while (left != right){
		lint mid = (left + right + 1) >> 1;
		lint sum2 = 0;
		
		int head = 0, tail = 0;
		for (; head < n; head++){
			while (sum2 < mid){
				sum2 += a[tail % n];
				tail++;
			}
			t[head] = tail - 1;
			t[head + n] = tail - 1 + n;
			t[head + n + n] = tail - 1 + n + n;
			sum2 -= a[head];
		}
		
		bool ok = false;
		for (head = 0; head < n; head++){
			if (t[t[t[head] + 1] + 1] - head + 1 <= n){
				ok = true;
				break;
			}
		}
		
		if (ok) left = mid;
		else right = mid - 1;
	}
	
	printf("%lld\n", left);
	
	return (0);
}

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

int main() {
  int a,b,h; cin >>a >>b >>h;
  int ans=(a+b)*h/2;
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>
#include <bitset>
#include <queue>

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

const int INF = 1001001001;
vector<int> to[100005];//vectorを100005個用意(部屋の数)

int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(n, INF);//距離
    vector<int> pre(n, -1);//前の部屋
    dist[0] = 0;
    q.push(0);//列状にデータが入っていき前から処理される(FIFO)
    while (!q.empty()) {
        int v = q.front();//qの最初の要素をvに代入
        q.pop();//qの最初の要素を削除(更新)
        for (int u : to[v]) {//ベクトルto[v]のすべての要素に対して
            if (dist[u] != INF) continue;//初期状態でなければ飛ばす
            dist[u] = dist[v] + 1;//INFかどうかの判定によって到達したかどうかがわかるのでしてない場合はvの次といえる
            pre[u] = v;
            q.push(u);
        }
    }

    cout << "Yes" << endl;
    rep(i, n) {
        if (i == 0) continue;
        int ans = pre[i];
        ++ans;
        cout << ans << endl;
    }
    return 0;
}

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

#define MAX 50

int main() {
	int N, v[MAX];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> v[i];
	sort(v, v + N);
	double X = v[0];
	for (int i = 1; i < N; i++) X = (X + v[i]) / 2;
	cout << X << endl;
	return 0;
}

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

int main() {
    int n,m;
    cin>>n>>m;
    int c[n]{};
    while (m--) {
        int a,b;
        cin>>a>>b;
        a--,b--;
        c[a]++;
        c[b]++;
    }
    for (int i:c)
        cout<<i<<endl;
    return 0;
}

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

// macros
#define overload_rep(va_0, va_1, va_2, name, ...) name
#define rep_0(i, n) for(int i = 0; i < (n); ++i)
#define rep_1(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries

// declarations

// solve
int main(){

    int x[2] = {};
    rep(i, 2)cin >> x[i];

    int ans = 0;
    rep(i, 2){
        if(x[i] == 1)ans += 300000;
        if(x[i] == 2)ans += 200000;
        if(x[i] == 3)ans += 100000;
    }

    if(x[0] == 1 && x[1] == 1)ans += 400000;
    cout << ans << '\n';
    return 0;

}


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

int main() {
    int N, K; cin >> N >> K;
    vector<double> P(N);
    rep(i, N){
        double p; cin >> p;
        double k = (p + 1.0) / 2.0;
        P[i] = k;
    }

    double max = 0;
    double sum = 0;
    rep(i, N - K + 1){
        if (i == 0){
            for(int j = i; j < i + K; j++){
            sum += P[j];
            }
        } else {
            sum -= P[i - 1];
            sum += P[i + K - 1];
        }
        if (sum > max) max = sum;
    }

    printf("%f\n", max);
    return 0;
}

Measured memory_bytes: 1792
N = int(input())
item_list = []
for n in range(N):
    item_list.append(str(input()))

#     item = str(input())
#     if item_list.count(item) == 0:
#         item_list.append(item)
#
# print(len(item_list))

item_set = (set(item_list))
print(len(item_set))


Measured memory_bytes: 35548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int n;
vector<int> adj[100005];
vector<int> dist;
map<P, int> mp;

void dfs(int v, int d = 0, int p = -1) {
    dist[v] = d % 2;
    for (int u : adj[v]) {
        if (u == p)
            continue;
        dfs(u, d + mp[make_pair(v, u)], v);
    }
}

vector<int> calcDist (int v) {
    dist = vector<int>(n);
    dfs(v);
    return dist;
}

int main() {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;    v--;    w %= 2;
        adj[u].push_back(v);
        adj[v].push_back(u);
        mp[make_pair(u, v)] = w;
        mp[make_pair(v, u)] = w;
    }
    
    auto col = calcDist(0);
    for (int c : col)
        cout << c << endl;
    
    return 0;
}

Measured memory_bytes: 23424
def m():
    N, M = map(int, input().split())
    g = [[] for _ in range(N + 1)]
    dp = [10 ** 9] * (N + 1)
    visited = [False] * (N + 1)
    for _ in range(M):
        a, b = map(int, input().split())
        g[a].append(b)
        g[b].append(a)


    def bfs(root):
        visited[root] = True
        dp[root] = 0
        queue = []
        for q in g[root]:
            dp[q] = root
            queue.append(q)
            visited[q] = True
        while queue:
            q = queue.pop(0)
            for k in g[q]:
                if not visited[k]:
                    queue.append(k)
                    dp[k] = q
                    visited[k] = True
    bfs(1)

    if not all(visited[2:]):
        print('No')
        return

    print('Yes')
    for j in dp[2:]:
        print(j)
    return

m()


Measured memory_bytes: 35216
n=gets.to_i
x=gets.chomp.chars.zip(gets.chomp.chars).map{|a,b|a==b}.chunk{|e|e}.map.with_index{|(k,v),i|
	if k
		(i==0 ? 3 : 1)*2**(v.size-1)
	else
		(i==0 ? 6 : 2)*3**(v.size/2-1)
	end
}
p x.reduce(:*)%(10**9+7)

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

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int n, m, a;
	while(cin >> n >> m >> a, n || m || a)
	{
		vector< vector<P> > yoko(1001);
		for(int i = 0; i < m; ++i)
		{
			int h, p, q;
			cin >> h >> p >> q;
			yoko[h].push_back(P(p, q));
		}
		int current = a;
		for(int i = 1000; i >= 1; --i)
		{
			for(int j = 0; j < yoko[i].size(); ++j)
			{
				if(yoko[i][j].first == current)
				{
					current = yoko[i][j].second;
					break;
				}
				else if(yoko[i][j].second == current)
				{
					current = yoko[i][j].first;
					break;
				}
			}
		}
		cout << current << endl;
	}
}

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

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=2050;
vector<int> E[N];
int n,deg[N],ans,par[N],dep[N],c[N];
void DFS(int u, int p)
{
	par[u]=p;
	dep[u]=dep[p]+1;
	for(int v:E[u]) if(v!=p) DFS(v,u);
}
void Set(int u, int v)
{
	if(dep[v]>dep[u]) swap(u,v);
	while(dep[u]>dep[v]) c[u]++,u=par[u];
	while(u!=v)
	{
		c[u]++;c[v]++;
		u=par[u];v=par[v];
	}
}
vector<pair<int,int> > Solve(vector<pair<int,int> > paths)
{
	//printf("Solve: ");
	//for(auto p:paths) printf("(%i %i) ",p.first,p.second);
	//printf("\n");
	if(paths.empty()) return paths;
	int u,v;
	for(u=1;u<=n;u++) if(deg[u]==1) break;
	if(u>n) return paths;
	for(int i=0;i<E[u].size();i++){ v=E[u][i];if(deg[v]) break;}
	//printf("u:%i v:%i\n",u,v);
	deg[u]--;deg[v]--;
	//printf(":D\n");
	vector<pair<int,int> > work,tmp;
	vector<int> id,pos(N,-1);
	for(int i=0;i<paths.size();i++)
	{
		if(paths[i].first==u || paths[i].second==u)
		{
			work.pb(paths[i]);
			id.pb(i);
		}
		else
		{
			pos[i]=tmp.size();
			tmp.pb(paths[i]);
		}
	}
	if(work.empty()) return Solve(paths);
	for(int i=0;i+1<work.size();i+=2)
	{
		if(work[i].second==u) swap(work[i].first,work[i].second);
		if(work[i+1].second==u) swap(work[i+1].first,work[i+1].second);
		if(work[i]==work[i+1])
		{
			if(paths[id[i]]==paths[id[i+1]]) swap(paths[id[i]].first,paths[id[i]].second);
			break;
		}
		pos[id[i]]=pos[id[i+1]]=tmp.size();
		tmp.pb(mp(work[i].second,work[i+1].second));
	}
	if(work.size()&1)
	{
		int i=work.size()-1;
		if(work[i].second==u) swap(work[i].first,work[i].second);
		if(work[i].second!=v)
		{
			pos[id[i]]=tmp.size();
			tmp.pb(mp(v,work[i].second));
		}
	}
	tmp=Solve(tmp);
	for(int i=0;i<paths.size();i++)
	{
		if(pos[i]!=-1 && tmp[pos[i]].first!=paths[i].first && tmp[pos[i]].second!=paths[i].second) swap(paths[i].first,paths[i].second);
	}
	return paths;
}
int main()
{
	int m;
	scanf("%i %i",&n,&m);
	int u,v;
	for(int i=1;i<n;i++) scanf("%i %i",&u,&v),E[u].pb(v),E[v].pb(u),deg[u]++,deg[v]++;
	vector<pair<int,int> > paths(m);
	DFS(1,0);
	for(int i=0;i<m;i++) scanf("%i %i",&paths[i].first,&paths[i].second),Set(paths[i].first,paths[i].second);
	for(int i=1;i<=n;i++) ans+=min(2,c[i]);
	paths=Solve(paths);
	printf("%i\n",ans);
	for(auto p:paths) printf("%i %i\n",p.first,p.second);
	return 0;
}

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

#define mp make_pair
#define pb push_back
#define fill(a) memset(a,0,sizeof(a))

typedef long long ll;
typedef long double ld;




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

    int n,d; cin>>n>>d;

    int ans = 0;
    for(int i=0;i<n;i++)
    {
        int p,q;
        cin>>p>>q;
        ll x = 1LL*p*p + 1LL*q*q;
        ld y = sqrt(x);
        int dist = (int)y;
        if((dist == ceil(y) && dist==d )|| (dist<d)) ans++;

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

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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int D = int.Parse(Console.ReadLine());
            int[] c_list = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            List<int[]> s_list = new List<int[]>();
            List<int> t_list = new List<int>();
            List<int> last_list = new List<int>();
            List<int> value_list = new List<int>();

            for (int i = 0; i < D; i++)
            {
                int[] s_array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                s_list.Add(s_array);
            }

            for (int i = 0; i < D; i++)
            {
                int t = int.Parse(Console.ReadLine());
                t_list.Add(t);
            }

            for (int i = 0; i < 26; i++)
            {
                last_list.Add(0);
                value_list.Add(0);
            }

            for (int i = 1; i <= D; i++)
            {
                for (int j = 0; j < 26; j++)
                {
                    if (t_list[i - 1] - 1 == j)
                    {
                        value_list[j] += s_list[i - 1][j];
                        last_list[j] = i;
                    }
                    else
                    {
                        value_list[j] -= c_list[j] * (i - last_list[j]);
                    }
                }
                int sum = value_list.Sum();
                Console.WriteLine(sum);
            }
        }
    }
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()
#define BETWEEN(a, x, b) (a) <= (x) && (x) <= (b) 

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;

void solve()
{
    int n;
    cin >> n;
    
    cout << n * (n + 1) / 2 << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

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

int main(){
    int d, e;
    while(cin >> d >> e, d+e){
        double ans = 10000;
        for(int i = 0; i < d; i++){
            ans = min(ans, abs(sqrt(pow(i,2)+pow(d-i,2))-e));
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A;
    int B;
    int C;
    int D;
    int L;
    int R;
    cin >> A >> B >> C >> D;
    L = A + B;
    R = C + D;
    
    if (L > R){
        cout << "Left" << endl;
    }
    
    else if (L == R) {
        cout << "Balanced" << endl;
    }
    
    else if (L < R){
        cout << "Right" <<endl;
    }
    
}


Measured memory_bytes: 3624
#include<iostream>
#include<string>
using namespace std;
int main(){
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if(x>=r&&(x+r)<=W&&y>=r&&(y+r)<=H){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}



Measured memory_bytes: 3116
#include <stdio.h>

int main(void)
{
	int i,j,k;
	int h,w;

	for(i =0; 1; i++)
	{
		scanf("%d %d",&h,&w);

		if(h == 0 && w == 0)break;

		for(j = 0; j < h; j++)
		{
			for(k = 0; k < w; k++)
			{
				if (j == 0 || j == h-1)
				{
					printf("#");
				}else
				{
					if (k == 0 || k == w-1)
					{
						printf("#");
					}else
					{
						printf(".");
					}
				}

			}

			printf("\n");
		}

		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 572
import sys
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False

def ddprint(x):
  if DBG:
    print(x)

n = inn()
d = inl()
a = [0]*13
for i in range(n):
    a[d[i]] += 1
    if d[i]==0 or d[i]==12 and a[12]>=2 or a[d[i]]>=3:
        print(0)
        exit()
if n>=13:
    print(1)
    exit()
ddprint('a')
ddprint(a)
mx = -1
for i in range(2**n):
    s = [(i>>j)%2 for j in range(n)]
    e = [0]*25
    e[0] = 1
    for j in range(n):
        suf = (d[j] if s[j]==0 else 24-d[j])
        e[suf] += 1
    ddprint('s,e')
    ddprint(s)
    ddprint(e)
    mn = 25
    strk = 0
    for j in range(1,24):
        if e[j]>=2:
            mn = 0
            break
        elif e[j]==1:
            mn = min(mn, strk+1)
            strk = 0
        else:
            strk += 1
    ddprint(mn)
    mn = min(mn, strk+1)
    mx = max(mx,mn)
print(mx)


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


int main() {
  
  int N , a , b;
  
  cin >> N >> a >> b;
  
  if ( ( b - a ) % 2 == 0 ) cout << "Alice" << endl;
  else cout << "Borys"  << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=201000;
int r,c,n,p,q,x,vis[N];
ll lab[N],mn,mx;
vector<PII> e[N];
VI v;
void dfs(int u,int f) {
	vis[u]=1; v.pb(u);
	if (f==0) mn=min(mn,lab[u]); else mx=min(mx,lab[u]);
	for (auto p:e[u]) {
		if (vis[p.fi]) continue;
		lab[p.fi]=p.se-lab[u];
		dfs(p.fi,f^1);
	}
}
int main() {
	scanf("%d%d",&r,&c);
	scanf("%d",&n);
	rep(i,0,n) {
		scanf("%d%d%d",&p,&q,&x); --p; --q;
		e[p].pb(mp(q+r,x));
		e[q+r].pb(mp(p,x));
	}
	rep(i,0,r+c) if (!vis[i]) {
		mn=0,mx=1ll<<50;
		v.clear();
		dfs(i,0);
		if (mn+mx<0) {
			puts("No");
			return 0;
		}
		for (auto p:v) {
			if ((p>=r)==(i>=r)) lab[p]-=mn; else lab[p]+=mn;
		}
	}
	rep(i,0,r+c) for (auto p:e[i]) if (lab[i]+lab[p.fi]!=p.se) {
		puts("No");
		return 0;
	}
	puts("Yes");
}


Measured memory_bytes: 15608
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;

template <class T>
string to_binary(T a){
	if(a == 0){
		return "0";
	}
	string res = "";
	while(a > 0){
		res += '0'+(a & 1);
		a >>= 1;
	}
	return res;
}

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

	map<int,int> mp;
	for(int i = 0;i < n;i++){
		string s = to_binary(a[i]);
		for(int j = 0;j < s.size();j++){
			if(s[j] == '1')mp[j]++;
		}
	}

	string s = to_binary(k);
	reverse(s.begin(),s.end());
	int m = s.size();
	ll st = 0;
	for(int i = 42;i >= m;i--){
		st += (1LL << i) * mp[i];
	}

	vector<vector<ll>> dp(m+1,vector<ll>(2,0));
	//dp[i][0]:=i桁まで決めて等しい. dp[i][1]:=i桁まで決めて未満.
	dp[0][0] = st;

	for(int i = 0;i < m;i++){
		//最初の桁だけ注意.
		if(i == 0){
			if(s[0] == '0'){
				dp[1][0] = dp[0][0] + (1LL << (m-1)) * mp[m-1];
			}
			else{
				//s[0]=='1'
				dp[1][0] = dp[0][0] + (1LL << (m-1)) * (n - mp[m-1]);
				dp[1][1] = dp[0][0] + (1LL << (m-1)) * mp[m-1];
			}
			continue;
		}
		if(s[i] == '0'){
			//等しい->等しい,未満->未満にしか遷移しない.
			dp[i+1][0] = dp[i][0] + (1LL << (m-1-i)) * mp[m-1-i];
			dp[i+1][1] = dp[i][1] + (1LL << (m-1-i)) * max(n-mp[m-1-i],mp[m-1-i]);
		}
		else{//kk[i]=='1'
			//等しい->等しい,等しい->未満,未満->未満に遷移.
			dp[i+1][0] = dp[i][0] + (1LL << (m-1-i)) * (n-mp[m-1-i]);
			dp[i+1][1] = dp[i][0] + (1LL << (m-1-i)) * mp[m-1-i];
			dp[i+1][1] = max(dp[i+1][1],dp[i][1]+(1LL << (m-1-i)) * max(n-mp[m-1-i],mp[m-1-i]));
		}
	}

	cout << max(dp[m][0],dp[m][1]) << endl;
}


Measured memory_bytes: 1024
process.stdin.resume();
process.stdin.setEncoding("utf8");

// 標準入力取込
let gInput = "";
process.stdin.on("data", (chunk) => gInput += chunk);
process.stdin.on("end", () => main(gInput.split(/\r?\n/)));

// 解答
function main(inputs: string[]): void {

    // 整数の数
    const str: string[] = Array.from(inputs[0]);

    if (str[2] === str[3] && str[4] === str[5]) {

        return console.log('Yes');
    }

    return console.log('No');
}


Measured memory_bytes: 7500
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N,M; cin >> N >> M;
    vector<int> p(M);
    vector<string> S(M);
    vector<int> cnt(N);
    vector<bool> ok(N,false);
    int ans1 = 0;
    int ans2 = 0;
    rep(i,M){
        cin >> p[i];
        cin >> S[i];
        p[i]--;
        if(S[i] == "WA" && !ok[p[i]]){
            cnt[p[i]]++;
        }
        else if(S[i] == "AC" && !ok[p[i]]){
            ok[p[i]] = true;
            ans1++;
        }
    }
    rep(i,N){
        if(ok[i]) ans2 += cnt[i];
    }
    cout << ans1 << " " << ans2 << endl;

}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    vi vec(n);
    cin>>vec;
    int ans=0;
    int now=0;
    REPR(i,n-2){
        if(vec[i]>=vec[i+1]){
            now++;
        }else{
            now=0;
        }
        chmax(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(void){
  int i;
  int y,m,d;

  for(; scanf("%d%d%d",&y,&m,&d)==3 ;){
    if( y<1868 ||
        y==1868 && m<9 ||
        y==1868 && m==9 && d<8)
      printf("pre-meiji\n");
    else if( y<1912 ||
        y==1912 && m<7 ||
        y==1912 && m==7 && d<30)
      printf("meiji %d %d %d\n",y-1867,m,d);
    else if( y<1926 ||
        y==1926 && m<12 ||
        y==1926 && m==12 && d<25)
      printf("taisho %d %d %d\n",y-1911,m,d);
    else if( y<1989 ||
        y==1989 && m==1 && d<8)
      printf("showa %d %d %d\n",y-1925,m,d);
    else
      printf("heisei %d %d %d\n",y-1988,m,d);
  }

  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const int inf=1<<29;
const ll Maxn=1e6;
const double pi=3.1415926536;

struct sumwv{
	int w,v;
}wv[105];

bool cmp(sumwv x,sumwv y){
	return x.v>y.v;
}

sumwv A[105],B[105],C[105],D[105];

int a=0,b=0,c=0,d=0;

ll wa[105],wb[105],wc[105],wd[105];
ll va[105],vb[105],vc[105],vd[105];

int main(void){
	int n,w;
	cin>>n>>w;
	for(int i=1;i<=n;i++){
		cin>>wv[i].w>>wv[i].v;
		if(wv[i].w==wv[1].w) A[++a]=wv[i];
		if(wv[i].w==wv[1].w+1) B[++b]=wv[i];
		if(wv[i].w==wv[1].w+2) C[++c]=wv[i];
		if(wv[i].w==wv[1].w+3) D[++d]=wv[i];
	}
	sort(A+1,A+1+a,cmp);
	sort(B+1,B+1+b,cmp);
	sort(C+1,C+1+c,cmp);
	sort(D+1,D+1+d,cmp);
	wa[0]=wb[0]=wc[0]=wd[0]=0;
	va[0]=vb[0]=vc[0]=vd[0]=0;
	for(int i=1;i<=a;i++){
		wa[i]=wa[i-1]+A[i].w;
		va[i]=va[i-1]+A[i].v;
	}
	for(int i=1;i<=b;i++){
		wb[i]=wb[i-1]+B[i].w;
		vb[i]=vb[i-1]+B[i].v;
	}
	for(int i=1;i<=c;i++){
		wc[i]=wc[i-1]+C[i].w;
		vc[i]=vc[i-1]+C[i].v;
	}
	for(int i=1;i<=d;i++){
		wd[i]=wd[i-1]+D[i].w;
		vd[i]=vd[i-1]+D[i].v;
	}
	ll sum;
	ll sim=0;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				for(int l=0;l<=d;l++){
					sum=wa[i]+wb[j]+wc[k]+wd[l];
					if(sum<=w){
						sim=max(sim,va[i]+vb[j]+vc[k]+vd[l]);
					}
				}
			}
		}
	}
	printf("%lld\n",sim);
}

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

int main(){
  char c;
  cin >> c;
  
  cout << (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' ? "vowel" : "consonant") << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

int main(void)
{
  int N, K;
  cin >> N >> K;
  
  vector<int> A(N);
  
  for(int i = 0;i < N;i++)
  {
    cin >> A[i];
  }
  
  int up = *max_element(A.begin(),A.end());
  int low = 0;
  int mid;
  int cnt = 0;
  
  while(1)
  {
    cnt = 0; 
    mid = (up + low) / 2;
    
    if(mid == low)
    {
      break;
    }
    
    for(int i = 0; i < N; i++)
    {
      if(A[i] % mid == 0)
      {
        cnt += A[i] / mid -1; 
      }
      else
      {
        cnt += A[i] / mid;
      }
            
      if(cnt > K)
      {
        low = mid;
        break;
      }  
    }
    
    if(cnt <= K)
    {
       up = mid;
    }  
  }
cout << up;
}

Measured memory_bytes: 3520
#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(){
	int n,h,w;cin>>n>>h>>w;

	cout << (n - w + 1) * (n - h + 1) << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

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

    ll INF = (ll) 1e12;
    int N;
    ll W;
    cin >> N >> W;
    int v[N];
    ll w[N];
    for (int i = 0; i < N; ++i) {
        cin >> v[i] >> w[i];
    }

    ll dp[N + 1][N * 100 + 1];
    fill(dp[0], dp[0] + N * 100 + 1, INF);
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= N * 100; ++j) {
            if (j < v[i]) {
                dp[i + 1][j] = dp[i][j];
            } else {
                dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
            }
        }
    }

    int res = 0;
    for (int i = 0; i <= N * 100; ++i) {
        if (dp[N][i] <= W) res = i;
    }

    cout << res << '\n';

    return 0;
}



Measured memory_bytes: 11060
S=input().rstrip()
L=l=len(S)
ans=0
for i in range(L-2,-1,-1):
  l-=1
  if l%2==1:
    continue
  f=True
  m=l//2
  for j in range(0,m):
    if S[j]!=S[m+j]:
      f=False
      break
  if f:
    ans=i+1
    break
print(ans)


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

const int N=100005;

int n,l,r,mid;
char s[N];

bool check(int w){
	int c=0,i;
	for (i=n-w+1;i<=w;i++) c+=s[i]=='0';
	if (c==0) return 1;
	if (c==w+w-n) return 1;
	return 0;
}

int main(){
	scanf("%s",s+1); n=strlen(s+1);
	l=1; r=n;
	while (l<r){
		mid=(l+r+1)>>1;
		if (check(mid)) l=mid;
		else r=mid-1;
	}
	printf("%d\n",l);
	return 0;
} 

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>

using namespace std;
int N, W;
string text;
int v[110];
int w[110];
int dp[110][10100];

int main(){
    cin >> N >> W;

    for(int i=0;i<N;i++)cin>>v[i]>>w[i];
    for(int i=0;i<=W;i++)dp[0][i] = 0;
    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(j < w[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]]+v[i]);
        }
    }
    cout << dp[N][W] << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#else
#define dbg(x)
#endif

#define ff first
#define ss second
const int MOD = (int) 1e9 + 7;
const int MAXN = 200100;
int fact[MAXN], invfact[MAXN];
int exp(int a, int b){
    if (b == 0) return 1;
    if (b & 1){
        return (ll) a * exp(a, b-1) % MOD;
    }
    int tmp = exp(a, b/2);
    return (ll) tmp * tmp % MOD;
}

int binom(int N, int R){
    int res = ((ll) fact[N] * invfact[R] % MOD) * invfact[N-R] % MOD;
    return res;
}
void pre(){
    fact[0] = invfact[0] = 1;
    for (int i = 1; i < MAXN; i++){
        fact[i] = (ll)fact[i-1] * i % MOD;
        invfact[i] = exp(fact[i], MOD - 2);
    }
}

int main(){
    std::ios_base::sync_with_stdio(false);
    pre();
    int N, M, A, B;
    cin >> N >> M >> A >> B;
    int res = binom(N + M - 2, N - 1);
    int h = N - A;
    for (int w = 1; w <= B; w++){
        int mul = binom(h + w - 2, h - 1);
        int c = binom(A + (M - w + 1) - 2, A - 1);
        mul = (ll) mul * c % MOD;
        res = (res - mul + MOD) % MOD;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

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


Measured memory_bytes: 3612
/*
	????????¢?????????????????????????????????????????????????????°????????????????????????????????????
	?¬????????????????????????¢?????????????????????????????¨??????????????????????????§?¨? (W,H) ????????????????????????
	????????????????????????????????§?¨? (x,y) ??¨?????? r ??§?????????????????????
*/

#include <iostream>

// ?????????????´??????°??????????????????????????¬??????
template
<
	typename TYPE,
	std::size_t SIZE
>
std::size_t array_length(const TYPE(&)[SIZE])
{
	return SIZE;
}

int main() {
	int W, H, x, y, r;
	// W???H???x???y???r
	std::cin >> W >> H >> x >> y >> r;

	// x????????¢??????????¨????
	if (W < x + r || 0 > x - r || H < y + r || 0 > y - r) {
		std::cout << "No" << std::endl;
	}
	else {
		std::cout << "Yes" << std::endl;
	}
	return 0;
}

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

int main()
{
  int H, W;
  cin >> H >> W;
  vector<string> a(H);
  vector<int> cntH(W);
  vector<int> cntW(H);

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

  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (a[i][j] == '#')
      {
        cntH[j]++;
        cntW[i]++;
      }
    }
  }

  for (int i = 0; i < H; i++)
  {
    if (cntW[i] == 0)
    {
      continue;
    }

    for (int j = 0; j < W; j++)
    {
      if (cntH[j] == 0)
      {
        continue;
      }

      cout << a[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  lb  lower_bound
#define  ub  upper_bound
#define  F   first
#define  S   second
const int N=2e5+2;
ll a[N];
int main()
{
    ft
    ll i,j,n,m,l,r,s=0,c=1;
    cin>>n;
    while(n>=1)
    {
        n/=2;
        s+=c;
        c*=2;
    }
    cout<<s<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <map>
#include <algorithm>
#include <ctime>
#include <queue>
typedef std::vector<std::vector<int>> vvi;

int n;
vvi a(4,std::vector<int>(4));
std::map<vvi, int> mp;
/*ゴール状態をそれぞれ
0 1 2
3 4 5
6 7 *

0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 *
とする
 */

void init(){
	int N = n*n;
	std::vector<bool> use(N,false);
	int now = 0;
	while(now < N){
		int x = rand() % N;
		if(!use[x]){
			a[now/n][now%n] = x;
			use[x] = true;
			now++;
		}
	}
}

bool goal(){
	bool res = true;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(a[i][j] != i*n+j) res = false;
		}
	}
	return res;
}

void print(){
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++) std::cout << a[i][j] << " ";
		std::cout << "\n";
	}
}

int h(int mode){
	if(mode == 0) return 0;
	int res = 0;
	if(mode == 1){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(a[i][j] != i*n+j) res++;
			}
		}
	}else if(mode == 2){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				int y = a[i][j]/n;
				int x = a[i][j]%n;
				res += abs(y-i) + abs(x-j);
			}
		}
	}else{
		return 1<<30;
	}
	return res;
}

int f(int mode, int g){
	return h(mode) + g;
}


bool in(int y, int x){
	return 0 <= y && y < n && 0 <= x && x < n;
}

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

struct dat{
	int f,g;
	vvi vec;
	bool operator< (const dat &d) const {
		return f > d.f;
	}
};

int search(int mode){
	std::priority_queue<dat> pq;
	pq.push({f(mode,0),0,a});
	//std::cout << f(mode,0) << " " << ss << "\n";
	mp[a] = f(mode,0);
	while(!pq.empty()){
		auto p = pq.top(); pq.pop();
		a = p.vec;
		if(goal()) return p.g;
		int y,x;
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(a[i][j] == n*n-1){
					y = i; x = j; break;
				}
			}
		}
		for(int i=0; i<4; i++){
			int ny = y + dy[i];
			int nx = x + dx[i];
			if(!in(ny,nx)) continue;
			std::swap(a[ny][nx], a[y][x]);
			if(mp.find(a) != mp.end()){
				std::swap(a[ny][nx], a[y][x]);
				continue;
			}
			int cost = f(mode, p.g + 1);
			mp[a] = cost;
			pq.push({cost, p.g + 1, a});
			std::swap(a[ny][nx], a[y][x]);
		}
	}
	return -1;
}


int main(){
	//srand(unsigned(time(NULL)));
	int mode = 1;
	n = 3;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			int c; std::cin >> c;
			a[i][j] = c - 1;
			if(a[i][j] < 0) a[i][j] += 9;
		}
	}
	//std::cin >> n >> mode;
	//cin >> n;
	//init();
	std::cout << search(mode) << "\n";
}


Measured memory_bytes: 55032
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;string s="";
  map <string,int>mp;
  for(int i=0;i<n;i++){cin>>s;mp[s]++;}
  cin>>n;
  while(cin>>s)mp[s]--;
  int ans=0;
  for(auto x:mp){ans=max(ans, x.second);}
  cout<<ans<<endl;
}


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

using namespace std;

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

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
	int n;
	int dp[301] = {};
	dp[0] = 1;
	for(int i = 1; i * i <= 300; i++){
		for(int j = i * i; j <= 300; j++){
			dp[j] += dp[j - i*i];
		}
	}
	while(cin>>n,n)cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
using namespace std;
 
int main(){
	long A, B, C;
	cin >> A >> B >> C;
	if(A % 2 == 0 || B % 2 == 0 || C % 2 == 0){
		cout << 0 << endl;
	}else{
		cout << min({A * B, B * C, C * A}) << endl;
	}
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,long double> P;
typedef pair<ll,P> PP;

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

int c[3][3];

bool check(int a1,int a2,int a3,int b1,int b2,int b3) {
	if(c[0][1]!=a1+b2||c[0][2]!=a1+b3||c[1][0]!=a2+b1||c[1][2]!=a2+b3||
		c[2][0]!=a3+b1||c[2][1]!=a3+b2) return false;
	return true;
}

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

	REP(i,3) REP(j,3) cin>>c[i][j];

	REP(a1,101) {
		int b1=c[0][0]-a1;
		if(b1<0) break;
		REP(a2,101) {
			int b2=c[1][1]-a2;
			if(b2<0) break;
			REP(a3,101) {
				int b3=c[2][2]-a3;
				if(b3<0) break;
				if(check(a1,a2,a3,b1,b2,b3)) {
					cout<<"Yes"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <atcoder/scc>

using namespace std;

int main(){
    int N, M; cin >> N >> M;
    atcoder::scc_graph g(N);
    for(int i=0;i<M;i++){
        int a, b; cin >> a >> b;
        g.add_edge(a, b);
    }
    auto l = g.scc();
    cout << l.size() << endl;
    for(auto& v : l){
        cout << v.size();
        for(auto& t : v) cout << " " << t;
        cout << endl;
    }
}

Measured memory_bytes: 40084
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
#define all(v) v.begin(),v.end()
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  lol a, b , c;
  cin >> a >> b >> c;
  lol ans = a / (b + c);
  ans *= b;
  a %= (b + c);
  cout << ans + min(a, b) << '\n';
  return 0;
}


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

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

typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 2*1000+10;
int n, x, y, u, ans[maxn], dis[maxn][maxn];
bool mark[maxn][maxn];
queue<int> q;

void bfs(int cur)
{
	while (!q.empty())
	{
		u = q.front();
		q.pop();
		if (u > 1 && !mark[cur][u - 1])
		{
			q.push(u - 1);
			mark[cur][u - 1] = 1;
			dis[cur][u - 1] = dis[cur][u] + 1;
			if (u - 1 > cur)
				ans[dis[cur][u - 1]]++;
		}
		if (u < n && !mark[cur][u + 1])
		{
			q.push(u + 1);
			mark[cur][u + 1] = 1;
			dis[cur][u + 1] = dis[cur][u] + 1;
			if (u + 1 > cur)
				ans[dis[cur][u + 1]]++;
		}
		if (u == x && !mark[cur][y])
		{
			q.push(y);
			mark[cur][y] = 1;
			dis[cur][y] = dis[cur][u] + 1;
			if (y > cur)
				ans[dis[cur][y]]++;
		}
		if (u == y && !mark[cur][x])
		{
			q.push(x);
			mark[cur][x] = 1;
			dis[cur][x] = dis[cur][u] + 1;
			if (x > cur)
				ans[dis[cur][x]]++;
		}
	}
}

int main()
{
	cin >> n >> x >> y;
	for (int i = 1; i < n; i++)
	{
		mark[i][i] = 1;
		q.push(i);
		bfs(i);
	}
	for (int i = 1; i < n; i++)
		cout << ans[i] << endl;
	return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if (a + b >= 24) cout << a + b - 24 << endl;
    else cout << a + b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

int main()
{
	FASTIO
	
	string s, t;
	cin >> s >> t;

	int count = 0;
	for(int i = 0; i < s.length(); i ++)
	{
		if(s[i] != t[i])
			count ++;
	}

	cout << count << endl;
}

Measured memory_bytes: 3880
# C
N, M, X = map(int, input().split())
ans = -1
lst = [list(map(int, input().split())) for i in range(N)]
ans = 10**9
for i in range(2 ** N):
    bag = []
    total = 0
    score = [0] * M
    for j in range(N):  
        if ((i >> j) & 1):  
            bag.append(lst[j])
    for k in bag:
        total += k[0]
        for idx, l in enumerate(k[1:]):
            score[idx] += l
    right_score = [m for m in score if m >= X]
    if (len(right_score) == M):
        ans = min(ans, total)
if (ans == 10**9):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 74072
data = [int(i) for i in input().split()]

x = data[2] - data[0] 
y = data[3] - data[1]

print("R"*x+"U"*y+"L"*x+"D"*y+"DR"+"R"*x+"U"*y+"ULUL"+"L"*x+"D"*y+"DR")

Measured memory_bytes: 3060