akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


void eating_symbols_easy()
{
  string s;
  cin >> s;

  int cnt = 0;
  for (int i = 0; i < 4; ++i)
  {
    if (s[i] == '+') ++cnt;
    else --cnt;
  }
  cout << cnt << "\n";
}


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

  if (n % 2 == 0) cout << n << "\n";
  else cout << 2 * n << "\n";
}


void task_scheduling_problem()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

  sort(a.begin(), a.end());

  cout << a[2] - a[0] << "\n";
}


void rated_for_me()
{
  int r;
  cin >> r;

  if (r < 1200) cout << "ABC\n";
  else if (r < 2800) cout << "ARC\n";
  else cout << "AGC\n";
}


void atcoder_crackers()
{
  int n, k;
  cin >> n >> k;

  if (n % k == 0) cout << 0 << "\n";
  else cout << 1 << "\n";
}


void garden()
{
  int a, b;
  cin >> a >> b;

  cout << (a - 1) * (b - 1) << "\n";
}


void train()
{
  int n, i;
  cin >> n >> i;

  cout << n - i + 1 << "\n";
}


void Pair()
{
  int k;
  cin >> k;

  if (k % 2 == 0) cout << k / 2 * k / 2 << "\n";
  else cout << k / 2 * (k / 2 + 1) << "\n";
}


void ABC333()
{
  int a, b;
  cin >> a >> b;

  if ((a == 1 && (b == 1 || b == 3)) || (a == 3 && (b == 1 || b == 3))) cout << "Yes\n";
  else cout << "No\n";
}


void maximize_the_formula()
{
  int a, b, c;
  cin >> a >> b >> c;

  int v_max = max({ a,b,c });
  cout << a + b + c + 9 * v_max << "\n";
}


int main()
{
  //eating_symbols_easy();
  //multiple_of_2_and_n();
  //task_scheduling_problem();
  //rated_for_me();
  //atcoder_crackers();
  //garden();
  //train();
  //Pair();
  //ABC333();
  maximize_the_formula();
}

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

using namespace std;

string s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    cout << (s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main() {

  int n, m; cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  if (n%2 == 0) {
    for(int i=1; i<=m; i++) {
      if (n/2 < n+1 - 2*i) {
        a[i-1] = i;
        b[i-1] = n-i+1;
      } else {
        a[i-1] = i;
        b[i-1] = n-i;
      }
    }
  } else {
    for(int i=0; i<m; i++) {
      a[i] = i+1;
      b[i] = n-i;
    }
  }

  for(int i=0; i<m; i++) {
    cout << a[i] << " " << b[i] << endl;
  }

  return 0;
}

// EOF


Measured memory_bytes: 3856
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int op[3] = {};
    int v;
  	cin>>v;
	int a, b, c, d;
    d = v % 10;
  	v /= 10;
  	c = v % 10;
    v /= 10;
    b = v % 10;
    v /= 10;
    a = v % 10;
	int m = 0;
	string ab, bc, cd;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				op[0] = i;
				op[1] = j;
				op[2] = k;
              m = 0;
				m += a;
				if (op[0] == 0) {
					m += b;
				}
				else {
					m -= b;
				}
				if (op[1] == 0) {
					m += c;
				}
				else {
					m -= c;
				}
				if (op[2] == 0) {
					m += d;
				}
				else {
					m -= d;
				}
				if (m == 7) {
					if (op[0] == 0) {
						ab = '+';
					}
					else {
						ab = '-';
					}
					if (op[1] == 0) {
						bc = '+';
					}
					else {
						bc = '-';
					}
					if (op[2] == 0) {
						cd = '+';
					}
					else {
						cd = '-';
					}
				}
			}
		}
	}
	cout << a << ab << b << bc << c << cd << d <<"=7"<< endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))

max_x = max(x)
min_x = min(x)

ans = []
for i in range(1, 101):
  a = 0
  for xi in x:
    a += (xi - i)*(xi - i)
  ans.append(a)
  
print(min(ans))

Measured memory_bytes: 38768
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
int n,m;
char s[120][120];
inline bool cheh(int x){
	fo(i,1,m) if (s[x][i]=='#') return 0;
	return 1;
}
inline void delh(int x){
	fo(i,x,n-1) fo(j,1,m) s[i][j]=s[i+1][j];
	n--;
}
inline bool chel(int x){
	fo(i,1,n) if (s[i][x]=='#') return 0;
	return 1;
}
inline void dell(int x){
	fo(j,x,m-1) fo(i,1,n) s[i][j]=s[i][j+1];
	m--;
}
int main(){
	scanf("%d%d",&n,&m);
	fo(i,1,n) scanf("%s",s[i]+1);
	while (1){
		bool ok=0;
		fo(i,1,n) if (cheh(i)){
			delh(i);
			ok=1;
			break;
		}
		fo(i,1,m) if (chel(i)){
			dell(i);
			ok=1;
			break;
		}
		if (!ok) break;
	}
	fo(i,1,n){
		fo(j,1,m) putchar(s[i][j]);
		putchar('\n');
	}
	return 0;
} 


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func main() {
	io := NewIo()
	defer io.Flush()

	N := io.NextInt()
	limitList := make([]int, 5)
	neckIndex := 0
	for i := range limitList {
		limitList[i] = io.NextInt()
		if limitList[neckIndex] > limitList[i] {
			neckIndex = i
		}
	}

	mainTime := N / limitList[neckIndex]
	if N%limitList[neckIndex] != 0 {
		mainTime++
	}

	if limitList[neckIndex] >= N {
		io.PrintLn(5)
	} else {
		io.PrintLn(mainTime + 4)
	}

}


Measured memory_bytes: 640
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

bool isPossible(vector<int> &vc, int k, int num) {
  int c = 0;
  for (int i = 0; i < (int)vc.size(); i++) {
    int p = (vc[i] + (num - 1) ) / num;
    c += max(0ll, p - 1);
  }
  return c <= k;
}

int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  int n, k;
  cin >> n >> k;
  vector<int> vc(n);
  for (auto &i: vc) cin >> i;
  int l = 1, r = 1e9;
  int ans;
  while (l <= r) {
    int mid = (l + r) / 2;
    if (isPossible(vc, k, mid)) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
  // cout << isPossible(vc, k, 1ll) << endl;
  return 0;
}


Measured memory_bytes: 4780
#include <stdio.h>

int main(){
    int a,b,c,n,i[1001],j[1001],k[1001],r[1001],x,p[301];
    while (1) {
        scanf("%d %d %d",&a,&b,&c);
        if (a==0&&b==0&&c==0) break;
        scanf("%d",&n);
        for (x=1;x<=a+b+c;x++) {
            p[x]=2;
        }
        for (x=1;x<=n;x++) {
            scanf("%d %d %d %d",&i[x],&j[x],&k[x],&r[x]);
            if (r[x]==1) {
                p[i[x]]=1;
                p[j[x]]=1;
                p[k[x]]=1;
            }
        }
        for (x=1;x<=n;x++) {
            if (r[x]==0) {
                if (p[i[x]]*p[j[x]]*p[k[x]]==2) {
                    if (p[i[x]]==2) p[i[x]]=0;
                    if (p[j[x]]==2) p[j[x]]=0;
                    if (p[k[x]]==2) p[k[x]]=0;
                }
            }
        }
        for (x=1;x<=a+b+c;x++) {
            printf("%d\n",p[x]);
        }
    }
    return 0;
}

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

int main() {
	string w, t;
	int a = 0;
	cin >> w;
	while (cin >> t) {
	    if (t == "END_OF_TEXT") break;
	    for (int i = 0; i < t.size(); i++) {
	        if (t[i] >= 'A' && t[i] <= 'Z') t[i] += 32;
	    }
	    if (t == w) a++;
	}
	cout << a << endl;
}



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

int main () {
  int t;
  int n;
  int result;
  for (int i = 0; i < 4; i++) {
    cin >> t >> n;
    switch (t) {
      case 1:
        result = 6000 * n;
        break;
      case 2:
        result = 4000 * n;
        break;
      case 3:
        result = 3000 * n;
        break;
      case 4:
        result = 2000 * n;
        break;
    }
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
main = do
    weights <- fmap (map read.lines) getContents
    mapM_ (putStrLn.classify) $ weights

classify :: Double -> String
classify w
    | w <= 48 = "light fly"
    | w <= 51 = "fly"
    | w <= 54 = "bantam"
    | w <= 57 = "feather"
    | w <= 60 = "light"
    | w <= 64 = "light welter"
    | w <= 69 = "welter"
    | w <= 75 = "light middle"
    | w <= 81 = "middle"
    | w <= 91 = "light heavy"
    | otherwise = "heavy"

Measured memory_bytes: 3964
c = [list(map(int,input().split())) for _ in range(3)]
#c = [[1, 0, 1], [2, 1, 2], [1, 0, 1]]

cmax = 0
for i in c:
  for j in i:
    cmax = max(cmax,j)

ck = 0
for i in range(-cmax,cmax+1):
  a = [0,0,0]
  b = [0,0,0]

  a[0] = i

  b[0] = c[0][0] - a[0]
  b[1] = c[0][1] - a[0]
  b[2] = c[0][2] - a[0]

  a[1] = c[1][0] - b[0]
  if c[1][1] - b[1] != a[1] or c[1][2] - b[2] != a[1]:
    continue

  a[2] = c[2][0] - b[0]
  if a[2] != c[2][1] - b[1] or a[2] != c[2][2] - b[2]:
    continue

  ck = 1
  break

if ck:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int a[50], b[50], c[50];
int dp[51][501][501];

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    for (int i = 0; i <= n; i++) {
        for (int ca = 0; ca <= 400; ca++) {
            for (int cb = 0; cb <= 400; cb++) {
                dp[i][ca][cb] = 1e6;
            }
        }
    }

    dp[0][0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int ca = 0; ca <= 400; ca++) {
            for (int cb = 0; cb <= 400; cb++) {
                if (dp[i][ca][cb] == 1e6) continue;
                dp[i + 1][ca][cb] = min(dp[i][ca][cb], dp[i + 1][ca][cb]);
                dp[i + 1][ca + a[i]][cb + b[i]] =min(dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]);
            }
        }
    }

    int ans = 1e6;
    for (int ca = 1; ca <= 400; ca++) {
        for (int cb = 1; cb <= 400; cb++) {
            if (ca * mb == cb * ma) {
                ans = min(ans, dp[n][ca][cb]);
            }
        }
    }
    if (ans == 1e6) {
        ans = -1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 40832
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let s: String = it.next().unwrap().parse().unwrap();
    let _t: String = it.next().unwrap().parse().unwrap();
    let mut a: usize = it.next().unwrap().parse().unwrap();
    let mut b: usize = it.next().unwrap().parse().unwrap();
    let u: String = it.next().unwrap().parse().unwrap();
    if s == u {
        a -= 1;
    } else {
        b -= 1;
    }
    println!("{} {}", a, b);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int x[200], y[200], h[200], N;
void check(int X, int Y){
  int L = 0, R = 2E9;
  for(int i = 0; i < N; i += 1){
    if(h[i]) L = max(L, abs(X - x[i]) + abs(Y - y[i]) + h[i]),
    	R = min(R, abs(X - x[i]) + abs(Y - y[i]) + h[i]);
    else R = min(R, abs(X - x[i]) + abs(Y - y[i]));
  }
  if(L == R && L){
     cout << X << " " << Y << " " << L;
     exit(0);
  }
}
int main(){
  cin >> N;
  for(int i = 0; i < N; i += 1)
    cin >> x[i] >> y[i] >> h[i];
  for(int x = 0; x <= 100; x += 1)
    for(int y = 0; y <= 100; y += 1)
      check(x, y);
  
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; 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;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

#define CMAX 26

void solve()
{
  ll D; cin >> D;
  vector<ll> c(CMAX + 1); rep1(i, CMAX) cin >> c[i];
  vector<vector<ll>> s(D + 1, vector<ll>(CMAX + 1));
  rep1(i, D) rep1(j, CMAX) cin >> s[i][j];
  vector<ll> last(CMAX + 1, 0);

  
  vector<ll> t(D + 1);
  //rep1(i, D) {cin >> t[i];}
  rep1(day, D) {
    ll id;
    ll smax = 0;
    ll lmin = INF;
    vector<ll> cpoint(CMAX + 1);
    rep1(ct, CMAX) {
      cpoint[ct] = (day - last[ct]) * 1000 + s[day][ct];
    }
    rep1(ct, CMAX) {
      if(cpoint[ct] > smax) {
	t[day] = ct;
	smax = cpoint[ct];
      }
    }
    last[t[day]] = day;
  }

  rep1(i, D) {
    cout << t[i] << "\n";
  }

  

  ll sat = 0;
  ll dis;
  for(ll day = 1; day <= D; day++) {
    sat += s[day][t[day]];
    last[t[day]] = day;
    dis = 0;
    rep1(i, CMAX) {
      dis += c[i] * (day - last[i]);
    }
    
    sat -= dis;

    //cerr << sat << endl;
  }
  cerr << sat << endl;
  
  
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3800
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<stdio.h>
#include<iomanip>
using namespace std;
typedef unsigned long long ll;
ll mod = (10e+8)+ 7;

ll howMuch(ll K, ll ANS){
	ll i = K;
	int j = 0;
	while(1){
		if(i >= ANS)return j;
		i*=2;
		j++;
	}
}

ll ePow(ll N, ll b){
	int a = b;
	if(N == 0)return 1;
	if(N < 1)return b;
	
	for(ll i = 0; i < N - 1; i++){
		b *= a;
	}
	return b;
}


int main(){
	ll N, K;
	cin>>N>>K;
	double ans = 0;
	for(ll i = 1; i <= N; i++){
		ll temp = N * ePow(howMuch(i, K), 2);
		ans += ((double)1/(double)temp);
	}
	cout<<setprecision(40)<<ans<<endl;

}

Measured memory_bytes: 256
from heapq import heappop, heappush
n, m, s, t = map(int, input().split())
edge_a = [set() for _ in range(n + 1)]
edge_b = [set() for _ in range(n + 1)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    edge_a[u].add((v, a))
    edge_a[v].add((u, a))
    edge_b[u].add((v, b))
    edge_b[v].add((u, b))

def dijkstra(edge, s):
    sp = [10 ** 19] * (n + 1)
    sp[s] = 0
    q = [(0, s)]
    while q:
        dist, s = heappop(q)
        for t, w in edge[s]:
            if dist + w < sp[t]:
                sp[t] = dist + w
                heappush(q, (sp[t], t))
    return sp

sp_a = dijkstra(edge_a, s)
sp_b = dijkstra(edge_b, t)
dist = [int(sp_a[-1] + sp_b[-1])]
for i in range(n - 1, 0, -1):
    dist.append(min(dist[-1], int(sp_a[i] + sp_b[i])))

snuk = 10 ** 15
print(*(snuk - d for d in reversed(dist)), sep='\n')

Measured memory_bytes: 107936
#include<iostream>
using namespace std;
int main(){
    int a,b,c,t;
    cin>>a>>b>>c;
    if(a>b){
        t=a;
        a=b;
        b=t;
    }
    if(b>c){
        t=b;
        b=c;
        c=t;
    }
    if(a>b){
        t=a;
        a=b;
        b=t;
    }
    cout<<a<<' '<<b<<' '<<c<<endl;
    return 0;
}


Measured memory_bytes: 3068
#include <stdio.h>
int main(void){
	int a,n[33]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	scanf("%d",&a);
	printf("%d",n[a-1]);
	return 0;
}

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

int main() {
  int K, N;
  cin >> N;
  cin >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  int total = 0;
  for (int i = 0; i < K; i++) {
    total += p[i];
  }

  cout << total << endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;

int main(void) {
  int a, b;
  int n;
  while(cin >> a >> b >> n){
    int ans = 0;
    a %= b;
    for(int i=0; i<n; i++){
      a *= 10;
      ans += (a/b);
      a %= b;
    }
    cout << ans << endl;
  }




  return 0;
}

// EOF

Measured memory_bytes: 2964
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, D, X;
	cin >> N >> D >> X;
	vector<int>A(N);
	vector<int>chocolate(D, 0);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		int j = 0;
		while (j * A.at(i) + 1 <= D) {
			chocolate.at(j * A.at(i))++;
			j++;
		}
	}
	int ans = 0;
	for (int i = 0; i < D; i++) {
		ans += chocolate.at(i);
	}
	cout << ans + X << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;

int LCS(string &s, string &t){
    int n = s.size(), m = t.size();
    vector<vector<int>> dp(n+8, vector<int>(m+8, 0));
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(s[i]==t[j]){
                dp[i+1][j+1] = max({dp[i][j]+1, dp[i][j+1], dp[i+1][j]});
            }
            else{
                dp[i+1][j+1] = max({dp[i][j], dp[i][j+1], dp[i+1][j]});
            }
        }
    }
    return dp[n][m];
}
signed main(){
    int q;
    cin >> q;
    for(long long i=0; i<q; i++){
        string s, t; cin>>s>>t;
        cout << LCS(s, t) << endl;
    }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int x, y; cin >> x >> y;
  for(int i = 0; i <= x; ++i) {
    int j = x-i;
    if(i*2+j*4==y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3620
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;
import std.datetime;
 
 
immutable long MOD = 10^^9 + 7;

int N, X, Y, Z, S, MASK, NG;
long[][] mem;


long dp(int n, int mask) {
    if (n >= N) return 1;
    if (mem[n][mask] >= 0) return mem[n][mask];

    long ret = 0;
    foreach (i; 1..11) {
        //if (i == ng) continue;
        int n_mask = (mask << i) | (1 << (i - 1));
        if ((n_mask & NG) == NG) continue;
        n_mask &= MASK;
        ret = (ret + dp(n+1, n_mask)) % MOD;
    }

    return mem[n][mask] = ret;
}


void main() {
    scanf("%d %d %d %d", &N, &X, &Y, &Z);
    
    S = X + Y + Z;
    mem = new long[][](N, 1<<S);
    foreach (i; 0..N) fill(mem[i], -1);
    MASK = (1 << S) - 1;

    NG |= (1 << (Z-1));
    NG |= (1 << (Y+Z-1));
    NG |= (1 << (X+Y+Z-1));

    long ans = 1;
    foreach (i; 0..N) ans = (ans * 10) % MOD;
    ans = ((ans - dp(0, 0)) % MOD + MOD) % MOD;

    ans.writeln;

}


Measured memory_bytes: 42364
n, m = map(int, input().split())
a_lst = [str(input()) for _ in range(n)]
b_lst = [str(input()) for _ in range(m)]

flag = False
for i in range(n - m + 1):
    for j in range(n - m + 1):

        count = 0
        if a_lst[i][j] == b_lst[0][0]:
            for k in range(m):
                for l in range(m):
                    if a_lst[i + k][j + l] == b_lst[k][l]:
                        count += 1

            if count == m ** 2:
                flag = True

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9220
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        // Scanner scan = new Scanner(System.in);
        // PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        // int n = Integer.parseInt(bf.readLine());
        StringTokenizer st = new StringTokenizer(bf.readLine());
        int n =  Integer.parseInt(st.nextToken());
        int m =  Integer.parseInt(st.nextToken());
        long ans = 0;
        if((n == 1) && (m == 1)) ans = 1;
        else if(n == 1) ans = (m-2);
        else if(m == 1) ans = (n-2);
        else ans = 1L*(m-2)*(n-2);

        System.out.println(ans);

        // int[] a = new int[n];
        // for(int i=0; i<n; i++) a[i] =  Integer.parseInt(st.nextToken());

        // out.close(); System.exit(0);
    }


}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  ll N;
  cin >> N;
  ll ans = 0, num = 0;
  REP(i, N) {
    ll a;
    cin >> a;
    if (num > a) {
      ans += num - a;
    }
    num = max(num, a);
  }
  cout << ans << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define p(x) cout << x << endl;
#define all(v) (v).begin(), (v).end()

#define MOD 1000000007
#define PI 3.14159265359

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

    int a, b;
    cin >> a >> b;

    if(b % a == 0){
        p(a + b);
    }else{
        p(b - a);
    }
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
string S;
int main(){
	cin>>S;
	int AA=200000;
	int ZZ=0;
	for(int i=0;i<S.size();i++){
		if(S[i]=='A')AA=min(AA,i);
		if(S[i]=='Z')ZZ=max(ZZ,i);
	}
	cout<<ZZ-AA+1<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int64_t gcd(int64_t a, int64_t b) {
  if(a < b) return gcd(b, a);
  int64_t r;
  while ((r=a%b)) {
    a = b;
    b = r;   
  }
  return b;
} 
int main() {
  int n;
  cin >> n;
  cout << 360/gcd(360,n) << endl;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  
  vector<int> vec(a);
  
  for(int i=0;i<a;i++){
    cin>>vec.at(i);
    }
   
  sort(vec.begin(),vec.end());
  
  int answer=1000000000;
  int v;
  
  for(int i=0;i<a-b+1;i++){
    v=vec.at(b+i-1)-vec.at(i);
    if(v<answer){
      answer=v;
    }
  }
  
  cout<<answer<<endl;
  
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;



int main() {

    int n;
    cin>>n;
    cout<<180*(n-2)<<endl;
}



Measured memory_bytes: 256
from collections import deque
n=int(input())
e=[[] for _ in range(n+1)]
dist=[-1]*(n+1)
for i in range(n-1):
    a,b,c=map(int,input().split())
    e[a].append((b,c))
    e[b].append((a,c))
q,k=map(int,input().split())
a=deque()
a.append((k,0))
while a:
    x,d=a.popleft()
    dist[x]=d
    for j,nc in e[x]:
        if dist[j]!=-1:
            continue
        else:
            a.append((j,d+nc))
ans=[]
for i in range(q):
    x,y=map(int,input().split())
    ans.append(dist[x]+dist[y])
print(*ans,sep="\n")

Measured memory_bytes: 54364
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdio>

using namespace std;



int main() {
   int x,y;
   int t;
   for(int i=0;  ;i++){
       cin>>x>>y;
      
       if( x == 0 && y == 0) break;
       if(x>y){
            t=x;
           x=y;
           y=t;
       }
        cout<<x<<" "<<y<<endl;
   }
   
}


Measured memory_bytes: 3088
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define N 8

int max, min;
int d[N];
bool flag[N];

void
permutation(int n, int lv)
{
	static int p[N];
	int memo[N];
	int a;
	int i, j;

	flag[n] = true;
	p[lv] = d[n];

	j = 0;
	for (i = 0; i < N; ++i)
	{
		if (!flag[i])
			memo[j++] = i;
	}

	if (j == 1)
	{
		p[lv + 1] = d[memo[0]];

		a = 0;
		for (i = 0; i < N; ++i)
			a = a * 10 + p[i];

		if (a < min)
			min = a;

		if (a > max)
			max = a;

		flag[n] = false;
		return;
	}

	for (i = 0; i < j; ++i)
		permutation(memo[i], lv + 1);

	flag[n] = false;
}

int
main(int argc, char **argv)
{
	int n;
	char c;
	int i;

	scanf("%d\n", &n);
	while (n--)
	{
		for (i = 0; i < N; ++i)
		{
			scanf("%c", &c);
			d[i] = c - '0';
			flag[i] = false;
		}

		min = 99999999;
		max = 0;
		for (i = 0; i < N; ++i)
			permutation(i, 0);

		scanf("%c", &c);
		printf("%d\n", max - min);
	}

	return 0;
}

Measured memory_bytes: 596
/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define add	 	accumulate
  #define ll 	 	long long int
  #define ff	 	first
  #define ss 	 	second
  #define pb 	 	push_back
  #define pob		pop_back
  #define pf 	 	push_front
  #define pof		pop_front
  #define mp 	 	make_pair
  #define vll 	 	vector<ll>
  #define lb 	 	lower_bound
  #define ub     		upper_bound
  #define pll 	 	pair<ll,ll>
  #define vpll   		vector<pll>
  #define all(v) 		v.begin(), v.end()
  #define rep(i,k,n)    for(int i=k;i<n;i++)
  #define hs            ios_base::sync_with_stdio(false);cin.tie(NULL);
  template <class C> void setmin(C &a,C b){if(a>b)a=b;}
  template <class C> void setmax(C &a,C b){if(a<b)a=b;}
  const ll mod=1e9+7;
  const ll MAX=1e6;
  //
  //
  	void solve(){
  		ll n;
  		cin>>n;
  		vll vec(n);
  		rep(i,0,n)
  			cin>>vec[i];
  		sort(all(vec));
  		double ans=(vec[0]+vec[1])/2.0;
  		rep(i,2,n){
  			ans=(ans+vec[i])/2;
  		}
  		cout<<ans;
  	}
	int main(){ 
		solve();
    return 0; 
} 	


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
K = int(input())
if K <= 50 and K >= 2:
    a = [K]*K
    print(K)
    print(*a)
elif K == 0:
    print(2)
    print(1,1)
elif K == 1:
    print(2)
    print(0,3)
else:
    x = K // 50
    y = K % 50
    a = []
    for i in range(y):
        a.append(49+x+1)
    for j in range(50-y):
        a.append(49+x-y)
    print(50)
    print(*a)
    

Measured memory_bytes: 27080
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args){
		
		Scanner input = new Scanner(System.in);
		long N = input.nextInt();
        long D = input.nextInt();
        long remain = (long)(2 * Math.pow(10,9)) * 2;
        for (long i = N; i < D; i++) {
            for (long j = i + 1; j <= D; j++) {
                if(i*j %2019 < remain)
                    remain = i*j %2019;
                if(remain == 0)
                    break;
            }
            if(remain == 0)
                break;
        }
		System.out.println(remain);
	}
}

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

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

    if( (a + b) > (c+d)  ) cout << "Left" << endl;
    else if( (a + b) < (c+d)  ) cout << "Right" << endl;
    else cout << "Balanced" << endl;
  }

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

int main() {
  int N, K, sum = 1;
  cin >> N >> K;
 
  for (int i = 0; i < N  ; i++) {
    if (2*sum <= sum + K) {
      sum *= 2;
    }
    else { sum += K;
         }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], ans;
int main () {
	scanf("%d", &n);
	for (int i=1; i<=n; i++) scanf("%d", &a[i]);
	for (int i=1; i<=n; i++){
		if (a[a[i]]==i) ans++;
	}
	printf("%d\n", ans/2);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,a[100],sum,avg;
int main(){
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>a[i];
    sum+=a[i];
  }
  if((double)sum/n<sum/n+0.5)avg=sum/n;
  else avg=sum/n+1;
  sum=0;
  for(int i=0;i<n;++i){
    sum+=pow(abs(a[i]-avg),2);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <bitset>
#include <math.h>

typedef long long ll;

#define vi std::vector<int>
#define vl std::vector<ll>
#define floop(n) for(int i = 0; i < n; ++i)
#define print(x) std::cout << x << std::endl;

const ll INF = 1e18;

int main()
{
    int A, B, C, K, res=0, temp;
    std::cin >> A >> B >> C;
    std::cin >> K;

    while(A >= B)
    {
        K--;
        B *= 2;
    }

    if(K < 0)
    {
        print("No");
        return 0;
    }

    while(B >= C)
    {
        K--;
        C *= 2;
    }

    if(K < 0)
    {
        print("No");
    }

    else
    {
        print("Yes");
    }
    
    return 0; 
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const int MOD = 10000;
void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; }

int N, K;
int a[210];

int dp[210][5][5];

int main() {
    while (cin >> N >> K) {
        memset(a, -1, sizeof(a));
        for (int i = 0; i < K; ++i) {
            int h, w; cin >> h >> w; --h;
            a[h] = w;
        }
        
        memset(dp, 0, sizeof(dp));
        dp[0][0][0] = 1;
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j <= 3; ++j) {
                for (int k = 0; k <= 3; ++k) {
                    //if (dp[i][j][k]) cout << i << ", " << j << ", " << k << " : " << dp[i][j][k] << endl;
                    
                    for (int l = 1; l <= 3; ++l) {
                        if (j == k && k == l) continue;
                        if (a[i] != -1 && a[i] != l) continue;
                        
                        add(dp[i+1][l][j], dp[i][j][k]);
                    }
                }
            }
        }
        
        int res = 0;
        for (int j = 1; j <= 3; ++j) for (int k = 1; k <= 3; ++k) add(res, dp[N][j][k]);
        
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1188
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    long long ans = a[0];
    int cnt = n - 2;
    for (int i = 1; cnt > 0; i++, cnt -= 2)
        ans += a[i] * (cnt > 1 ? 2 : 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4012
#include <stdio.h>
#include <string.h>

int main() {
    int N, M;
    char U[300][11];
    char T[11];

    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%s", U[i]);
    }

    scanf("%d", &M);

    int lock = 1, flag = 0;

    for (int i = 0; i < M; i++) {
        scanf("%s", T);
        flag = 0;
        for (int j = 0; j < N; j++) {
            // U[i] と T が一致するとき
            if (strcmp(T, U[j]) == 0) { flag = 1; break;}
        }
        // if (flag == 0) と同じ
        if (!flag) {
            printf("Unknown %s\n", T);
        } else if (lock) {
            printf("Opened by %s\n", T);
            lock = 0;
        } else {
            printf("Closed by %s\n", T);
            lock = 1;
        }
    }
    return 0;
}


Measured memory_bytes: 2104
let readString() = stdin.ReadLine()
let readStringArray() = stdin.ReadLine().Split(' ');
let readInt() = readString() |> int
let readIntArray() = readStringArray() |> Array.map (fun x -> int x)


let x, a, b = readIntArray() |> fun x -> (x.[0], x.[1], x.[2])

if abs (x - a) < abs (x - b) then "A" else "B" 
|> printfn "%s"

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

int N;
vector<int> ans;

void rec(int n) {
	int x, y;
	if (n == 0 || n == 1) {
		ans.push_back(n);
		return;
	}
	if (n < 0) {
		x = (-n % 2 == 0) ? -n / 2 : -n / 2 + 1;
		y = n - (-2 * x);
	}
	else {
		x = -n / 2;
		y = n % 2;
	}
	ans.push_back(y);
	rec(x);
}

int main(void) {
	cin >> N;
	rec(N);
	for (int i = (int)ans.size() - 1; i >= 0; --i)
		cout << ans[i];
	cout << '\n';
	return 0;
}


Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f("ABC", X) :- X < 1200, !.
f("ARC", X) :- X < 2800, !.
f("AGC", X).

main :-
	get_number(N),
    f(X, N),
    writeln(X).


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

class Program
{
  static void Main(string[] args)
  {
        int[] arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int a = arr[0];
        int b = arr[1];
        int h = arr[2];
        int m = arr[3];

        double kaku = Math.Abs(30 * h + 0.5 * m - 6 * m);
        double cos = Math.Cos(kaku * (Math.PI / 180));
        double ans = 0;
        ans = Math.Sqrt(a * a + b * b - 2 * a * b * cos);
        Console.WriteLine(ans);


    }

   

}



Measured memory_bytes: 19832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int n,w; cin >> n >> w;
    ll wv[n][2];
    rep(i,n) cin >> wv[i][0] >> wv[i][1];
    ll dp[w+1];
    rep(i,w+1) dp[i]=0;

    rep(i,n+1){
        for(int j=w; j>=wv[i][0]; j--){
            dp[j]=max(dp[j-wv[i][0]]+wv[i][1],dp[j]);
        }
    }

    cout << dp[w] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e12;

// computational complexity : O(E*V)

struct edge{
    int from, to, cost;
};

int V,E;// number of (vertices, edges)
vector<edge> e;
vector<long long int> d;// shortest distances

void shortest_path(int s){// s = starting point
    // initialize (INF)
    for(int i=0; i<V; i++){
        d[i] = INF;
    }
    d[s] = 0;

    // search (rather naive)
    while(true){
        bool update = false;// flag
        for(int i=0; i<E; i++){
            if(d[e[i].from] != INF 
            && d[e[i].to] > d[e[i].from] + e[i].cost){
                d[e[i].to] = d[e[i].from] + e[i].cost;// update minimum cost
                update = true;
            }
        }
        if(update != true) break;// no updates anymore
    }
}

bool detect_negative_loop(){
    // initialize (zero) : since trying to detect "negative" edges
    for(int i=0; i<V; i++){
        d[i] = 0;
    }

    // if no negative loop, the shortest path <= (V-1) edges
    // (since it does not allow visiting the same vertex twice!)
    for(int i=0; i<V; i++){
        for(int j=0; j<E; j++){
            if(d[e[j].to] > d[e[j].from] + e[j].cost){
                d[e[j].to] = d[e[j].from] + e[j].cost;
                if(i == V-1) return true;
            }
        }
    }
    return false;
}

vector<bool> reachable_from_s;
void DFS1(const vector<vector<int>> &graph, int v){
    if(reachable_from_s[v] == true) return;

    reachable_from_s[v] = true;
    for(auto next_v : graph[v]){
        DFS1(graph, next_v);
    }
}

vector<bool> reachable_to_t;
void DFS2(const vector<vector<int>> &graph, int v){
    if(reachable_to_t[v] == true) return;

    reachable_to_t[v] = true;
    for(auto previous_v : graph[v]){
        DFS2(graph, previous_v);
    }
}

int main(){
    int s = 0, p;
    cin >> V >> E >> p;
    d.resize(V);

    reachable_from_s.assign(V, false);
    reachable_to_t.assign(V, false);

    vector<int> from(E), to(E), cost(E);
    vector<vector<int>> graph(V), graph_inv(V);
    for (int i=0; i<E; i++){
        cin >> from[i] >> to[i] >> cost[i];
        from[i] -= 1;
        to[i] -= 1;
        cost[i] -= p;
        cost[i] *= -1;

        graph[from[i]].push_back(to[i]);
        graph_inv[to[i]].push_back(from[i]);
    }

    DFS1(graph, 0);
    DFS2(graph_inv, V-1);

    vector<bool> reachable(V, false);
    for(int i=0; i<V; i++){
        if(reachable_from_s[i] == true
        && reachable_to_t[i]   == true){
            reachable[i] = true;
        }
    }

    for (int i=0; i<E; i++){
        if(reachable[from[i]] == true 
        && reachable[to[i]]   == true){
            e.push_back({from[i], to[i], cost[i]});
        }
    }
    E = e.size();

    if(detect_negative_loop() == true) cout << -1 << endl;
    if(detect_negative_loop() == false){
        shortest_path(s);// starting from s
        cout << max(0LL, -d[V-1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 768
void solve(){
}
void main(){
	int x, a, b;
	readf("%d %d %d", &x, &a, &b);
	if(b<=a)writeln("delicious");
	else if(b<=a+x)writeln("safe");
	else writeln("dangerous");
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;
alias instr = () => readln().chomp();
T inelm(T= int)(){ return to!(T)( readln().chomp() ); }
T[] inary(T = int)(){ return readln().chomp().split().to!(T[])(); }



Measured memory_bytes: 2764
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>*/
#include <bits/stdc++.h>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

int main() {
	int N; cin >> N;
	vi a(N); 
	F0R(i,N) cin >> a[i];
	sort(a.begin(),a.end());
	cout << a[a.size()-1]-a[0];
}

Measured memory_bytes: 256