akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;
class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		/*
		 * 完全グラフの辺の和は n(n+1)/2-自分なので、
		 * 適当な本数減らしてすべて同じにしたい
		 *
		 * 偶数と奇数で場合分けしたい
		 * 奇数は偶数のやつをかんがえてから処理したらよさそう
		 *
		 */
		int N=sc.nextInt();
		if(N%2==0) {
			int kosu=0;
			boolean[][] list=new boolean[N][N];
			for(int i=0; i<N; i++) {
				for(int j=0; j<N; j++) {
					if(i!=j) {
						list[i][j]=true;
					}
				}
			}
			for(int i=0; i<N; i++) {
				list[Math.abs(i)][Math.abs(N-1-i)]=false;
			}
			for(int i=0; i<N; i++) {
				for(int j=0; j<N; j++) {
					if(list[i][j]) {
						kosu++;
					}
				}
			}
			pl(kosu/2);
			for(int i=0; i<N; i++) {
				for(int j=0; j<N; j++) {
					if(i<j) {
						if(list[i][j]) {
							pl((i+1)+" "+(j+1));
						}
					}
				}
			}
		}
		else if(N%2==1) {
			int kosu=0;
			boolean[][] list=new boolean[N][N];
			for(int i=0; i<N-1; i++) {
				for(int j=0; j<N-1; j++) {
					if(i!=j) {
						list[i][j]=true;
					}
				}
			}
			for(int i=0; i<N-1; i++) {
				list[Math.abs(i)][Math.abs(N-2-i)]=false;
			}
			for(int i=0; i<N-1; i++) {
				list[N-1][i]=true;
				list[i][N-1]=true;
			}
			for(int i=0; i<N; i++) {
				for(int j=0; j<N; j++) {
					if(list[i][j]) {
						kosu++;
					}
				}
			}
			pl(kosu/2);
			for(int i=0; i<N; i++) {
				for(int j=0; j<N; j++) {
					if(i<j) {
						if(list[i][j]) {
							pl((i+1)+" "+(j+1));
						}
					}
				}
			}
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 23636
n = int(input())
s = [input() for i in range(n)]

t = [[s_i[0] for s_i in s].count(c) for c in "MARCH"]

sum_num = 0
for i in range(5):
	t_dummy_i = list(tuple(t))
	i_num = t_dummy_i.pop(i)
	for j in range(4):
		t_dummy_j = list(tuple(t_dummy_i))
		j_num = t_dummy_j.pop(j)
		for k in range(3):
			sum_num += i_num * j_num * t_dummy_j[k]

print(sum_num//6)

Measured memory_bytes: 10528
#include<stdio.h>

int main(){

	int i, j, height, width;

	while(1){
		scanf("%d %d", &height, &width);

		if(height == 0 && width == 0){
			break;
		}

		for(i = 0; i < height; i++){
			if(i % 2 == 0){
				for (j = 0; j < width; j++){
					if(j % 2 == 0){
						printf("#");
					} else {
						printf(".");
					}
				}
			} else {
				for (j = 0; j < width; j++){
					if(j % 2 == 1){
						printf("#");
					} else {
						printf(".");
					}
				}
			}

			printf("\n");
		}
		printf("\n");
	}

	return 0;

}

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

int g[15][15];

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

    rep(i, N) rep(j, N) g[i][j] = -1;
    rep(i, N){
        int m;  cin >> m;
        rep(j, m) {
            int a, x; cin >> a >> x;
            a--;
            g[i][a] = x;
        }
    }

    int ans = 0;
    rep(i, 1 << N) {
        vector<int> d(N);
        rep(j, N) {
            if (i >> j & 1) {
                d[j] = 1;
            }
        }
        bool ok = true;
        rep(j, N) {
            if (d[j]) {
                rep(k, N) {
                    if (g[j][k] == -1) continue;
                    if (g[j][k] != d[k]) ok = false;
                }
            }
        }
        if (ok) ans = max(ans, __builtin_popcount(i));
    }

    cout << ans << endl;
}


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

int main(){
  ll m;
  cin >> m;
  ll d, c;
  ll ans = -1;
  ll sum = 0;
  rep(i, m){
    cin >> d >> c;
    ans += c;
    sum += d * c;
  }
  ans += (sum-1) / 9;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations, product
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,A = ilint()
# ans = A[0]
# for a in A[1:]:
#     ans = gcd(ans,a)
# print(ans)
from functools import reduce
def lgcd(l):
    return reduce(gcd, l)
print(lgcd(A))

Measured memory_bytes: 87976
#include<iostream>

using namespace std;

int main(){

	int H,W;
	while(true){
		cin>>H>>W;
		if(H==0 && W==0)break;
		for(int i=0;i<H;++i){
			for(int j=0;j<W;++j){
				if((i+j)%2==0)
					cout<<"#";
				else
					cout<<".";
			}
			cout<<endl;
		}
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int NPrime=3000000;
bool prime[NPrime+1];
vi EnumeratePrime(){
	fill(prime+2,prime+NPrime+1,true);
	vi a;
	for(int i=2;i<=NPrime;i++) if(prime[i]){
		a.emplace_back(i);
		for(int j=2*i;j<=NPrime;j+=i) prime[j]=0;
	}
	return a;
}

int n,m,k;

int main(){
	while(1){
		cin>>n>>m>>k;
		if(n==0) break;
		vvi dp(m+1,vi(k+1));
		dp[0][0]++;
		for(int i=1;i<=n;i++){
			vvi DP=dp;
			for(int j=0;j<m;j++) for(int l=0;l<=k-i;l++) DP[j+1][l+i]+=dp[j][l];
			dp=DP;
		}
		cout<<dp[m][k]<<endl;
	}
}


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

#ifdef LOCAL
	#define de(x) cout<<#x<<"="<<x<<endl
	#define rff freopen("input.txt","r",stdin)
	#include "Debug.h"
#else
	#define de(x)
	#define rff
#endif

#define itr(x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define For(i,n) for (int i=1;i<=(int)(n);i++)
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define all(x) (x).begin(),(x).end()
#define PQ priority_queue
#define pii pair<int,int>
#define vi vector <int>
#define ll long long
#define pb push_back
#define mp make_pair
#define re return
#define se second
#define fi first
const int INF=0x7fffffff;
const int MAXN=+3;

int n,t,a,INDEX,h;
double mn=1000000;

int main(){
	cin>>n>>t>>a;
	For(i,n){
		cin>>h;
		if (fabs(t-0.006*h-a)<mn){
			mn=fabs(t-0.006*h-a);
			INDEX=i;
		}
	}
	cout<<INDEX;
	re 0;
}

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


using namespace std;


using ll = long long;


mt19937 mt(736);


int foo(const vector<string> &matr, int st)
{
	queue<pair<int, int>> pq;

	vector<int> col(matr.size(), -1);

	pq.emplace(st, 0);

	while (!pq.empty())
	{
		int v = pq.front().first;
		int d = pq.front().second;

		pq.pop();

		if (col[v] == -1)
		{
			col[v] = d;

			for (int i = 0; i < matr.size(); i++)
				if (matr[v][i] == '1')
					pq.emplace(i, d + 1);
		}
	}

	for (int i = 0; i < matr.size(); i++)
		for (int j = i + 1; j < matr.size(); j++)
			if (matr[i][j] == '1')
				if (col[i] == col[j])
					return -1;

	return *max_element(col.begin(), col.end()) + 1;
}


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;

	cin >> n;

	vector<string> matr(n);

	for (auto &row : matr)
		cin >> row;

	int ans = -1;

	for (int i = 0; i < n; i++)
		ans = max(ans, foo(matr, i));

	cout << ans << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	auto st = clock();

	ifstream fin("../input.txt");

	solve(fin);

	cout << "clock: " << setprecision(4) << (clock() - st) / (double) CLOCKS_PER_SEC << endl;
#else
	solve();
#endif

	return 0;
}


Measured memory_bytes: 704
import sys
from collections import defaultdict

n, a, *x = map(int, sys.stdin.read().split())
for i in range(n): x[i] -= a

def main():
  dp = defaultdict(int); dp[0] = 1
  for i in range(n):
    ndp = dp.copy()
    for k, v in dp.items():
      ndp[k+x[i]] += v
    dp = ndp
  print(dp[0] - 1)
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3444
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
money = 1000
stock = 0
(n-1).times do |i|
  if as[i] < as[i+1]
    stock += money / as[i]
    money -= as[i] * (money / as[i])
  elsif as[i] > as[i+1]
    money += stock * as[i]
    stock = 0
  end

  if i == n - 2
    money += stock * as[i+1]
    stock = 0
  end

end

puts money


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

int main(){
    int N;
    long long ans = 0;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        ans ^= A[i];
    }

    if (ans == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#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 llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 10007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;
typedef vector<double> DV;

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



int main() {
	llong N;
	cin >> N ;
    double ans =0;
    REP(i,N){
        double k = 0;
        string S ;
        cin >> k >> S;
        if(S=="JPY"){
            ans +=k;
        }else{
            ans += k*380000.0;
        }
    }
    cout << ans <<endl;
    


}


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

int main() {
  string s;
  cin >> s;
  ll sum = 0;
  for (int bit = 0; bit < (1 << s.size() -1); bit++){
    ll num = 0;
    for (int i = 0; i < s.size(); i++){
      num = num * 10 + s[i] - '0';
      if(bit & (1<<i)){
        sum += num;
        num = 0;
      }
    }
    sum += num;
  }
  cout << sum << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    vector<tuple<ll,ll,ll>> v;
    for(int i=0;i<n;++i){
        ll x,y,p;
        cin>>x>>y>>p;
        v.push_back(make_tuple(x,y,p));
    }
    vector<vector<ll>> xco(1<<15,vector<ll>(n));
    auto yco = xco;
    for(int mask=0;mask<1<<n;++mask){
        for(int i=0;i<n;++i){
            xco[mask][i] = abs(get<0>(v[i]))*get<2>(v[i]);
            yco[mask][i] = abs(get<1>(v[i]))*get<2>(v[i]);
            for(int j=0;j<n;++j)if(mask&1<<j){
                xco[mask][i] = min(xco[mask][i],abs(get<0>(v[j]) - get<0>(v[i]))*get<2>(v[i]));
                yco[mask][i] = min(yco[mask][i],abs(get<1>(v[j]) - get<1>(v[i]))*get<2>(v[i]));
            }
        }
    }
    vector<ll> ret(n+1,infl);
    for(int xmask=0;xmask<1<<n;++xmask){
        int l = xmask^((1<<n)-1);
        for(int ymask=l;ymask>=0;ymask--){
            ymask &= l;
            ll sum = 0;
            for(int i=0;i<n;++i)sum += min(xco[xmask][i],yco[ymask][i]);
            int num = __builtin_popcount(xmask|ymask);
            ret[num] = min(ret[num],sum);
        }
    }
    ll mi = infl;
    for(int i=0;i<=n;++i){
        mi = min(mi,ret[i]);
        cout << mi << endl;
    }
    return 0;
    
}

Measured memory_bytes: 12980
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        string s = sc.Next();

        long[] leftBlackSum = new long[n];
        leftBlackSum[0] = s[0] == '#' ? 1 : 0;
        for (int i = 1; i < n; i++)
        {
            leftBlackSum[i] = leftBlackSum[i - 1] + (s[i] == '#' ? 1 : 0);
        }

        long[] rightWhiteSum = new long[n];
        rightWhiteSum[n - 1] = s[n - 1] == '.' ? 1 : 0;
        for (int i = 1; i < n; i++)
        {
            rightWhiteSum[n - 1 - i] = rightWhiteSum[n - i] + (s[n - 1 - i] == '.' ? 1 : 0);
        }

        long answer = long.MaxValue;

        for (int i = 0; i < n; i++)
        {
            long tmpAnswer = (i == 0 ? 0 : leftBlackSum[i - 1]) + (i == n - 1 ? 0 : rightWhiteSum[i + 1]);
            answer = Math.Min(answer, tmpAnswer);
        }
        answer = Math.Min(answer, leftBlackSum[n - 1]);

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 31340
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    int n, a, b, c, ans = 0;
    string s, t;

    cin >> a >> b;

    if(a * b <= 0) cout << "Zero" << endl;
    else if(a > 0 || (b - a) % 2) cout << "Positive" << endl;
    else cout << "Negative" << endl;

}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

struct UnionFind {
    vector<int> par; // 親を指すvector,-par[親]は木のサイズ
    UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
    int root(int x) { // 親をたどる&データの整理
        if(par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    bool unite(int x, int y) { // データの結合
        x = root(x);
        y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    bool same(int x, int y) {return root(x) == root(y);} // 所属判定
    int size(int x) {return -par[root(x)];} // 木のサイズ
};

struct edge {
    int u, v;
    double cost;
    edge(int u=0, int v=0, double cost=0.0):u(u), v(v), cost(cost) {} 
};

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

// 辺の数でresize & 入力
vector<edge> es;
//最小全域木, Vは頂点数
double kruskal(int V) {
    int E = es.size();
    sort(es.begin(), es.end(), comp);
    UnionFind uft(V);
    double res = 0.0;
    for(int i = 0; i < E; ++i) {
        edge e = es[i];
        if(!uft.same(e.u, e.v)) {
            uft.unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

double leng(double x1, double y1, double z1, double x2, double y2, double z2) {return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));}

int main() {
    cout << fixed << setprecision(3);
    while(1) {
        int n;
        cin >> n;
        if(!n) break;
        vector<double> x(n), y(n), z(n), r(n);
        rep(i, n) {
            cin >> x[i] >> y[i] >> z[i] >> r[i];
        }
        rep(i, n) {
            rep(j, i) {
                double kyo = leng(x[i], y[i], z[i], x[j], y[j], z[j]) - r[i] - r[j];
                if(kyo > 0.0) {
                    es.push_back(edge(i, j, kyo));
                } else {
                    es.push_back(edge(i, j, 0.0));
                }
            }
        }

        cout << kruskal(n) << endl;
        es.clear();
    }
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int n,i,j,c=0;
 	string s;
 	cin>>s;
 	n=s.length();
 	i=0;
 	j=n-1;
 	while(i<j)
 	{
 		if(s[i++]!=s[j--])	
 		{
 			c++;
			
		 }
	 
 	}
 	cout<<c<<endl;
 }

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(2e5 + 5);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};



int main() {
    int n, m;
    while(cin >> n >> m, n){
        UnionFind<ll> g(n+1);
        REP(i,m){
            string s;
            cin >> s;
            if(s=="!"){
                ll a, b, w;
                cin >> a >> b >> w;
                g.merge(a,b,w);
            }
            else {
                ll a, b;
                cin >> a >> b;
                if(g.issame(a,b)){
                    cout << g.diff(a,b) << endl;
                }
                else cout << "UNKNOWN" << endl;
            }

        }

    }
    return 0;
}   


Measured memory_bytes: 4420
n = gets.to_i

ary = n.times.map {
  gets.split.map(&:to_i)
}

sum = 0

ary.each do |i|
  if i[0] === i[1]
    if sum >= 2
      sum += 1
      break
    else
      sum += 1
    end
  else
    sum = 0
  end
end

if sum >= 3
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 14308
#include <stdio.h>

int main(){
    char s[27];
    int keys[26] = {0};
    scanf("%s", s);

    for(int i = 0; s[i] != '\0'; i++){
        keys[s[i] - 'a']++;
    }

    for(int i = 0; i < 26; i++){
        if(keys[i] > 1){
            printf("no\n");
            return 0;
        }
    }
    printf("yes\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=(b); i++)
#define per(i,a,b) for (int i=(a); i>=(b); i--)
using namespace std;



int main() {
	int A, B, C;
	long long K;
	
	scanf("%d%d%d%I64d", &A, &B, &C, &K);
	if (K&1) printf("%d\n", B - A);
	else printf("%d\n", A - B);
	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  int sum = 0;
  rep(i, n) {
    cin >> v[i];
    sum += v[i];
  }

  sort(all(v), greater<int>());

  int alice = 0;
  for (int i = 0; i < n; i += 2) {
    alice += v[i];
  }
  cout << alice - (sum - alice) << endl;

  return 0;
}                 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;


int main(){
  int n; cin >> n;
  vector<vector<pii>> G(n);
  rep(i,n) {
    int a; cin >> a;
    rep(j,a) {
      int x,y; cin >> x >> y;
      x--;
      G[i].pb(mp(x,y));
    }
  }
  int ans = 0;
  rep(bit,(1 << n)) {
    int cnt = 0;
    bool ok = true;
    rep(i,n) {
      if(bit & (1 << i)){
        cnt++;
        for(auto g : G[i]) {
          int x = g.first;
          int y = g.second;
          if((bit & (1 << x)) && y == 0) ok = false;
          if(!(bit & (1 << x)) && y == 1) ok = false;
        }
      }
    }
    if(ok) chmax(ans, cnt);
  }

  cout << ans << endl;
}


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




int main(){
    string s;
    cin >> s;
    cout << -(s[0]+s[1]+s[2]+s[3]-','*4) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  int ball_count;
  int b_type_x_position;
  int total_distance = 0;
  
  cin >> ball_count >> b_type_x_position;
  
  for (int i = 0; i < ball_count; i++) {
    int ball_x_position;
    cin >> ball_x_position;
    
    int distance_a = ball_x_position * 2;
    int distance_b = abs(ball_x_position - b_type_x_position) * 2;
    
    if (distance_a < distance_b) {
      total_distance += distance_a;
    } else {
      total_distance += distance_b;
    }
  }
  
  cout << total_distance << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
int main()
{
  int N,M;
  cin >> N >> M;
  int P;
  string S;
  
  int ACcnt=0, WAcnt=0;
  int ACflg[105000], WA[105000];
  
  while(M--){
    cin >> P >> S;
    if(ACflg[P]==1) continue;
    if(S=="AC"){
      ACflg[P] = 1;
      ACcnt++;
      WAcnt += WA[P];
    }else{
      WA[P]++;
    }
  }
  cout << ACcnt << " " << WAcnt << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        scanner.nextLine();

        String[] s = scanner.nextLine().split("");
        int count = 0;
        for (int x = 0; x < n - 2; x++) {
            if (s[x].equals("A") && s[x + 1].equals("B") && s[x + 2].equals("C")) {
                count++;
            }
        }
        System.out.println(count);
    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
ll pows[222222];
ll inv9;
int N, q;

ll power(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

template<typename T>
struct LazySegmentTree {
	const int INF = numeric_limits<int>::max();
	int n0;
	vector<T> node, lazy;

	LazySegmentTree(vector<T> &v) {
		int n = v.size();
		n0 = 1;
		while (n0 < n) n0 <<= 1;
		node.resize(2 * n0 - 1);
		lazy.assign(2 * n0 - 1, INF);
		for (int i = 0; i < n; i++) node[i + n0 - 1] = v[i] * pows[N - i - 1] % mod;
		for (int i = n0 - 2; i >= 0; i--) node[i] = node[i * 2 + 1] + node[i * 2 + 2];
	}

	void eval(int k, int l, int r) {
		if (lazy[k] == INF) return;

		if (k < n0 - 1) {
			lazy[k * 2 + 1] = lazy[k];
			lazy[k * 2 + 2] = lazy[k];
		}
		//cout << l << " " << r << endl;
		ll r1 = (pows[N - r] - 1 + mod) % mod * inv9 % mod;
		ll l1 = (pows[N - l] - 1 + mod) % mod * inv9 % mod;
		//cout << l1-r1 << endl;
		node[k] = lazy[k] * (l1 - r1 + mod) % mod;
		lazy[k] = INF;
	}

	void update(int a, int b, T x, int k, ll l, ll r) {
		eval(k, l, r);
		if (a <= l && r <= b) {
			lazy[k] = x;
			eval(k, l, r);
		} else if (a < r && l < b) {
			update(a, b, x, k * 2 + 1, l, (l + r) / 2);
			update(a, b, x, k * 2 + 2, (l + r) / 2, r);
			node[k] = (node[k * 2 + 1] + node[k * 2 + 2]) % mod;
		}
	}

	void update(int l, int r, T x) { update(l, r, x, 0, 0, n0); }

	T query(int a, int b, int k, ll l, ll r) {
		eval(k, l, r);
		if (r <= a || b <= l) return 0;
		else if (a <= l && r <= b) {
			return node[k];
		} else {
			T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
			return (vl + vr) % mod;
		}
	}
	T query(int l, int r) { return query(l, r, 0, 0, n0); }

	inline T operator[](int a) { return query(a, a + 1); }
};

void solve() {
	cin >> N >> q;
	inv9 = power(9, mod - 2);
	vector<ll> v(N, 1);
	pows[0] = 1;
	for (int i = 1; i <= N; i++)pows[i] = (pows[i - 1] * 10) % mod;
	LazySegmentTree<ll> seg(v); pows[0] = 1;
	while (q--) {
		int l, r, d; cin >> l >> r >> d;
		l--; r--;
		seg.update(l, r + 1, d);
		cout << seg.query(0, N) << endl;
	}


}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--)
	solve();

}


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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL MOD = 1e9 + 7;
map<LL, LL> mf;
map<LL, LL> mv;
LL f(LL v, int k) {
	if(k == 0) { return v; }
	if(mf[v] != 0) { return mv[v]; }
	
	LL b = 1LL << (k - 1);
	assert(inII(v, 0, 2 * b));
	
	if(v <= b) {
		mv[v] = f(v, k - 1);
	} else if(v < 2 * b) {
		LL x = (b - 1) & ( v);
		LL y = (b - 1) & (~v);
		mv[v] = (MOD + 2 * f(b, k - 1) - 1 + f(x, k - 1) - f(y, k - 1)) % MOD;
	} else if(v == 2 * b) {
		mv[v] = (f(b, k - 1) * 3 + (MOD - 1)) % MOD;
	} else {
		assert(false);
	}
	
	mf[v] = 1;
	return mv[v];
}

int main() {
	LL n;
	cin >> n;
	
	cout << f(n + 1, 60) << endl;
	
	return 0;
}


Measured memory_bytes: 256
import math
a, b, C = map(int, input().split())

C_rad = C * math.pi / 180.0

h = b * math.sin(C_rad)
S = a * h / 2.0
c = math.sqrt(math.pow(h, 2) + math.pow(a - b * math.cos(C_rad), 2))
L = a + b + c

print(S)
print(L)
print(h)

Measured memory_bytes: 7952
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

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

    int N;
    cin >> N;

    vector<int> price(N);
    int tmp_cost;
    int ans = 0;

    for (int i = 0; i < N; ++i) {
        cin >> price[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> tmp_cost;
        ans += max(price[i] - tmp_cost, 0);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
let S = readLine()!.characters.map{$0}
var ans = (0..<S.count).map{_ in 0}
var a = 0
var b = 0
for (i, c) in S.enumerate() {
    if c == "R" {
        i%2>0 ?a++:b++
    } else {
        ans[i] += (i%2>0 ?a:b)
        ans[i-1] += (i%2>0 ?b:a)
        a = 0
        b = 0
    }
}
for (i, c) in S.enumerate().reverse() {
    if c == "L" {
        i%2>0 ?b++:a++
    } else {
        ans[i] += (i%2>0 ?b:a)
        ans[i+1] += (i%2>0 ?a:b)
        a = 0
        b = 0
    }
}
print(ans.map{String($0)}.joinWithSeparator(" "))

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


/* macro */
//#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define sec second
#define fir first
#define pb push_back



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
//const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};



/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




/* main */



signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    
    map<int, int> mp;

    rep(i,0,3) mp[input()] ^= 1;

    each(mp, itr){
        if(itr -> second) print(itr -> first);
    }
    

    
    




    
    



    
    

    







   




    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










Measured memory_bytes: 256
//written by NewbieChd
#include <cstdio>
#include <cctype>
#include <vector>
#include <algorithm>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    register int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 1000003;
int col[maxN];
vector <pair <int, int> > g[maxN];
void dfs(int x, int f) {
    for (auto y : g[x])
        if (y.first != f)   
            col[y.first] = col[x] ^ (y.second & 1), dfs(y.first, x);
}

int main() {
    int n = read(), i, x, y, z;
    for (i = 1; i < n; ++i)
        x = read(), y = read(), z = read(), g[x].push_back(make_pair(y, z)), g[y].push_back(make_pair(x, z));
    dfs(1, 0);
    for (i = 1; i <= n; ++i)
        printf("%d\n", col[i]);
    return 0;
}


Measured memory_bytes: 31232
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//絶対値
long long int change_plus(long long int a) {
	if (a < 0) { return -a; }
	if (a >= 0) { return a; }
}
//大小比較(大)
long long int big(long long int a, long long int b) {
	if (a >= b) {
		return a;
	}
	else {
		return b;
	}
}

//大小比較(小)
long long int small(long long int a, long long int b) {
	if (a >= b) {
		return b;
	}
	else {
		return a;
	}
}

int main() {
	long long int n,s,t,w, m, k,p,q,r=0;
	char str[60],str2[60],str3[15];
	int num[1200];
	scanf("%lld%lld",&n,&m);
	if (n+m==15) { printf("+"); }
	else if(n*m==15) { printf("*"); }else{ printf("x"); }
	
}

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

using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

bool dp[100100];

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

    vector<int>x(N);
    rep(i,N){
        cin >> x[i] ;
    }

    int ans = 0;
    rep(i,N){
        int kyori =min(x[i],abs(x[i]-K))*2;
        ans += kyori;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
while gets
  str, arr = $_.chomp, [*"a".."z"]
  
  26.times do
    break if /the|this|that/ =~ str
    
    j = 0
    
    str.each_char do |c|
      if /\w/ =~ c
        idx = (arr.index(c) + 1) % 26
        str[j] = arr[idx]
      end
      j += 1
    end
  end
  
  puts str
end

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

namespace ABC
{
    class MPCO2020D
    {
        const string FILE = "/tmp/data.txt";

        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            var N = RI();
            var A = RIa(N);

            long amount = 1000;
            long nstock = 0;
            for (int d = 0; d < N; ++d)
            {                
                if (nstock == 0)
                {
                    for (int nd = d; nd < N; ++nd)
                    {
                        if (A[nd + 1] > A[nd])
                        {   // nd に買う
//                            Console.WriteLine($"L:{nd} {A[nd]} * {amount / A[nd]} {amount} -> {amount % A[nd]}");
                            nstock = amount / A[nd];
                            amount = amount % A[nd];
                            d = nd;
                            break;
                        }
                    }
                }
                else
                {
                    for (int nd = d; nd < N + 1; ++nd)
                    {
                        if (A[nd + 1] < A[nd])
                        {   // nd に売る
//                            Console.WriteLine($"S:{nd} {A[nd]} * {nstock} {amount} -> {amount + nstock * A[nd]}");
                            amount += nstock * A[nd];
                            nstock = 0;
                            d = nd;
                            break;
                        }
                    }
                }
            }
            Console.WriteLine(amount);

#if DEBUG
            Console.WriteLine("*** end ***");
            Console.SetIn(Console.In);
            Console.ReadKey();
            Console.WriteLine();
#endif
        }

        static int RI()
        {
            return int.Parse(Console.ReadLine());
        }

        static int[] RIa(int n)
        {
            string[] sa = Console.ReadLine().Split(' ');
            int[] la = new int[n + 1];
            for (int i = 0; i < n; ++i)
            {
                la[i] = int.Parse(sa[i]);
            }
            la[n] = int.MinValue;
            return la;
        }
    }
}


Measured memory_bytes: 27528
#include<bits/stdc++.h>
using namespace std;
int A[5],D;
int main(){
	cin>>A[0]>>A[1]>>A[2];
	cin>>D;
	sort(A,A+3);
	A[2]=A[2]<<D;
	cout<<A[0]+A[1]+A[2];
	return 0;
}


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

using namespace std;

int main() {
    int n, p;
    string s;
    vector<tuple<string, int, int>> v;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s >> p;
        v.push_back(make_tuple(s, -p ,i));
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); ++i) cout << get<2>(v.at(i)) + 1 << endl;
}

Measured memory_bytes: 256
# coding: UTF-8

#共通関数と演算
def pprint(numlist):
  print(" ".join(map(str,numlist)))
def greater(s,t):
  if s[1] > t[1]:
    return True
  else:
    return False
def equal(s,t):
  if s[1] == t[1]:
    return True
  else:
    return False
def wasStable(Ans,Initial,N):
  I = Initial.copy()
  for i in range(N-1):
    if equal(Ans[i],Ans[i+1]):
      for x in I:
        if equal(Ans[i],x):
          if(Ans[i][0] != x[0]):
            return False
          else:
            I.remove(x)
            break
  return True
  
#input
N = int(input())
A = input().split()
Initial = A.copy()
B = A.copy()

#バブルソート
count = 0
flag = True
while flag:
  flag = False
  j = N - 1
  while j >= 1:
    if greater(A[j-1],A[j]):
      v = A[j]
      A[j] = A[j-1]
      A[j-1] = v
      flag = True
      count += 1
    j -= 1
pprint(A)
print("Stable")

#選択ソート
count = 0
for i in range(N):
  j=i
  minj=i
  while j<= N-1:
    if greater(B[minj],B[j]):
      minj = j
    j += 1
  if i != minj:
    v=B[i]
    B[i]=B[minj]
    B[minj]=v
    count += 1
    
print(" ".join(map(str,B)))
if wasStable(B,Initial,N):
  ans = "Stable"
else:
  ans = "Not stable"
print(ans)

    



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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    set<int> s;
    s.insert(0);
    int d;
    for (int i = 0; i < n; i++) {
        cin >> d;
        if (d == 0) {
            cout << 0 << endl;
            return 0;
        }
        if (s.count(d) == 1) {
            if (s.count(24 - d) == 1) {
                cout << 0 << endl;
                return 0;
            } else {
                s.insert(24 - d);
            }
        } else {
            s.insert(d);
        }
    }

    vector<int> x(25, 0);
    x[0] = 1;
    x[24] = 1;
    bool left = true;
    for (const int h : s) {
        if (h > 12) {
            break;
        }
        if (h == 12) {
            x[h] = 1;
        } else if (s.count(24 - h) == 0) {
            if (left) {
                x[h] = 1;
                left = false;
            } else {
                x[24 - h] = 1;
                left = true;
            }
        } else {
            x[h] = 1;
            x[24 - h] = 1;
            left = true;
        }
    }

    int mn = 12;
    int c = 1;
    for (int i = 1; i <= 24; i++) {
        if (x[i] == 1) {
            mn = min(mn, c);
            c = 1;
        } else {
            c++;
        }
    }

    cout << mn << endl;
}


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



int q_num = 0; // ? の数
int p10[100001]; // p10[i] = 10^(1+i番目の?の位置)
ll ct[100001][13] = {0}; // ct[i][j] = ?を1+i番目まで確定した場合に余りがjになる個数 


int main(){
	string S;
	cin >> S;
	int len = S.length();
	
	int remain0 = 0; // ?の文字が全て0とした場合の、S % 13
	int p = 1; // 10^(len-i-1) % 13
	for ( int i = 0; i < len; i++ ){
		int j = len - 1 - i;
		if ( S[j] == '?' ){
			p10[q_num] = p;
			q_num++;
		}
		else {
			remain0 = (remain0 + (S[j]-'0')*p) % 13;
		}
		p = p * 10 % 13;
	}
	
	
	ct[0][remain0] = 1;
	
	for ( int i = 0; i < q_num; i++ ){
		for ( int j = 0; j < 13; j++ ){
			for ( int k = 0; k < 10; k++ ){
				ct[i+1][(p10[i]*k+j)%13] += ct[i][j];
			}
		}
		for ( int j = 0; j < 13; j++ )
			ct[i+1][j] %= 1000000007;
	}
	
//	for ( int i = 0; i < q_num+1; i++ ){
//		for ( int j = 0; j < 13; j++ )
//			cout << ct[i][j] << " ";
//		cout << endl;
//	}
	
	
	cout << ct[q_num][5] << endl;
	
	return 0;
}



Measured memory_bytes: 11008
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int nax = 502;
int d[nax][nax];
int ord[nax * nax];
bool rem[nax][nax];
int n;
int dr[]={1,-1,0,0};
int dc[]={0,0,-1,1};

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	rep(row, 0,n+2) {
		d[row][0] = d[row][n+1] = -1;
	}
	rep(col, 0, n+2) {
		d[0][col] = d[n+1][col] = -1;
	}
	rep(row,1,n+1) rep(col,1,n+1) d[row][col] = min({row - 1, n - row, col-1, n - col});
	// rep(row, 0, n+2) {
	// 	rep(col, 0, n+2) {
	// 		printf("%2d ", d[row][col]);
	// 	}
	// 	printf("\n");
	// }
	int res = 0;
	rep(i,0,n*n) {
		cin >> ord[i];
		--ord[i];
		int row = ord[i] / n, col = ord[i] % n;
		row = row + 1, col = col + 1;
		res += d[row][col];
		rem[row][col] = 1;
		queue<pii> q;
		q.push({row, col});
		while (!q.empty()) {
			auto cur = q.front(); q.pop();
			int npossible = d[cur.st][cur.nd] + 1 - rem[cur.st][cur.nd];
			rep(dir, 0, 4) {
				int nr = cur.st + dr[dir], nc = cur.nd + dc[dir];
				if (nr < 1 || nr > n || nc < 1 || nc > n) {
					continue;
				}
				if (npossible < d[nr][nc]) {
					d[nr][nc] = npossible;
					q.push({nr, nc});
				}
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 5800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

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

    int N; cin >> N;
    string S; cin >> S;
    char pre = 'A';
    int ans = 0;
    REP(i,N){
        if(S[i] == pre){

        }else{
            pre = S[i];
            ans++;
        }
    }
    cout << ans << endl;


}


Measured memory_bytes: 512