akhauriyash/Code-Regression huggingface dataset:
use proconio::{input, fastout};
use proconio::marker::Usize1;

trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}

struct DpSolver {
    dp: Vec<Vec<i64>>,
    max: Vec<i64>,
    maximum: i64,
    update_stack: Vec<(usize, usize, i64)>,
}

impl DpSolver {
    fn register(&mut self, a: usize, b: usize, c: i64) {
        self.update_stack.push((a.min(b), a.max(b), c));
    }

    fn register_up_count(&mut self, a: usize, b: usize, c: usize, d: usize) {
        let a1 = a.min(b);
        let a2 = a.max(b);
        if self.dp[a1][a2] != -1 {
            self.register(c.min(d), c.max(d), self.dp[a1][a2] + 1);
        }
    }

    fn update(&mut self, a: usize, b: usize, c: i64) {
        self.dp[a][b].chmax(c);
        self.max[a].chmax(c);
        self.max[b].chmax(c);
        self.maximum.chmax(c);
    }

    fn do_update(&mut self) {
        while !self.update_stack.is_empty() {
            let (a, b, c) = self.update_stack.pop().unwrap();
            self.update(a, b, c);
        }
    }
}


#[fastout]
fn main() {
    input! {
        n: usize,
        aaa: [Usize1; n * 3],
    }

    let mut dps = DpSolver {
        dp: vec![vec![-1; n]; n],
        max: vec![-1; n],
        maximum: 0,
        update_stack: vec![],
    };
    let mut add = 0i64;
    let a = aaa[0].min(aaa[1]);
    let b = aaa[0].max(aaa[1]);
    dps.update(a, b, 0);

    for s in aaa[2..].chunks_exact(3) {
        let (a0, a1, a2) = (s[0], s[1], s[2]);
        if a0 == a1 && a1 == a2 {
            add += 1;
            continue;
        }
        if a0 == a1 || a1 == a2 || a2 == a0 {
            let q = a0 ^ a1 ^ a2;
            let p = (a0 + a1 + a2 - q) / 2;
            for b in 0..n {
                dps.register(q, b, dps.max[b]);
                dps.register_up_count(p, b, q, b);
            }
            dps.register(p, p, dps.maximum);
            dps.register(p, q, dps.maximum);
            dps.register_up_count(q, q, p, p);
        } else {
            dps.register(a0, a1, dps.maximum);
            dps.register(a0, a2, dps.maximum);
            dps.register(a1, a2, dps.maximum);
            dps.register_up_count(a0, a0, a1, a2);
            dps.register_up_count(a1, a1, a0, a2);
            dps.register_up_count(a2, a2, a0, a1);
            for b in 0..n {
                dps.register(a0, b, dps.max[b]);
                dps.register(a1, b, dps.max[b]);
                dps.register(a2, b, dps.max[b]);
            }
        }
        dps.do_update();
    }

    let &la = aaa.last().unwrap();
    dps.maximum.chmax(dps.dp[la][la] + 1);

    let ans = add + dps.maximum;

    println!("{}", ans);
}


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

int main() {
  int M, N;
  cin >> M >> N;
  vector<string> flag(M), emblem(2);
  for(auto& s: flag) cin >> s;
  for(auto& s: emblem) cin >> s;

  for(auto& s: flag) s = "X" + s + "X";
  flag.emplace(begin(flag), N + 2, 'X');
  flag.emplace_back(N + 2, 'X');

  int all = 0;
  for(int i = 1; i < M; ++i) for(int j = 1; j < N; ++j) {
    bool ok = true;
    for(int di: {0, 1}) for(int dj: {0, 1}) ok &= (flag[i + di][j + dj] == emblem[di][dj]);
    if(ok) ++all;
  }

  int dif = 0;
  for(int y = 1; y <= M; ++y) for(int x = 1; x <= N; ++x) {
    char dup = flag[y][x];
    int high = 0;
    int original = 0;
    for(char c: {'J', 'O', 'I'}) {
      flag[y][x] = c;
      int cnt = 0;
      for(int i: {y-1, y}) for(int j: {x-1, x}) {
        bool ok = true;
        for(int di: {0, 1}) for(int dj: {0, 1}) ok &= (flag[i + di][j + dj] == emblem[di][dj]);
        if(ok) ++cnt;
      }
      if(c == dup) original = cnt;
      high = max(high, cnt);
    }
    dif = max(dif, high - original);
    flag[y][x] = dup;
  }

  cout << all + dif << endl;
}

Measured memory_bytes: 3112
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define INF 111111111111111111
#define MOD 1000000007
#define pb push_back
#define F first 
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag;
#pragma endregion
#define MAX 111111

ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
char maze[55][55];
int main(void) {
  ll h, w;
  cin >> h >> w;
  FOR(i, 0, w + 1) maze[0][i] = '.';
  FOR(i, 0, h + 1) maze[i][0] = '.';
  FOR(i, 1, h+1) {
	FOR(j, 1, w + 1) {
	  cin >> maze[i][j];
	 // cout << maze[i][j];
	}
	//cout << endl;
  }
  FOR(i, 1, h + 1) {
	FOR(j, 1, w + 1) {
	  if (maze[i][j] == '#') {
		flag = false;
		FOR(k, 0, 4) {
		  if (maze[i + dy[k]][j + dx[k]] == '#') flag = true;
		}
		if (!flag) {
		  cout << "No" << endl;
		  //cout << i << " " << j << endl;
		  return 0;
		}
	  }
	}
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
fn main(){
    let x: usize = read();
    println!("{}", 10 - x / 200);
}

#[allow(dead_code)]
fn read<T>() -> T
where T: std::str::FromStr,
      T::Err: std::fmt::Debug
{
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).expect("failed to read");
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 2108
n = int(input())
s = input()
bad_num = [0] * n
pair = 0
b_num = []
ans = 0
for i in range(n - 1):
    if s[i] == "B":
        b_num.append(i)
        continue
    for j in range(i + 1, n):
        if s[j] == "B" or s[j] == s[i]: continue
        pair += 1
        if 2 * i - j >= 0:
            bad_num[2 * i - j] += 1
        if (j - i) % 2 == 0:
            bad_num[(i + j) // 2] += 1
        if 2 * j - i < n:
            bad_num[2 * j - i] += 1
if s[-1] == "B":
    b_num.append(n - 1)

for k in b_num:
    ans += pair - bad_num[k]
print(ans)

Measured memory_bytes: 9232
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

void A_AC_or_WA(void) {

	int N, M;
	cin >> N >> M;
	cout << ((N == M) ? "Yes" : "No") << flush;
}

void B_Comparing_Strings(void) {

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

	for (int loop = 0; loop < max(a, b); loop++) cout << min(a, b);
	cout << flush;
	return;
}

void C_Low_Elements(void) {

	int N;
	cin >> N;

	vector<int> P(N);
	for (int& it : P) cin >> it;

	int PMin = 0;
	int counter = 0;
	for (int loop = 0; loop < N; loop++) {
		if (loop == 0 || P[loop] <= PMin) {
			counter++;
			PMin = P[loop];
		}
	}
	cout << counter << flush;
	return;
}

void D_Handstand2(void) {

	int N;
	cin >> N;

	int num[10][10] = { 0 };

	int length = 0;
	for (int loop = 1; loop <= N; loop++) {

		if (loop == (int)pow(10, length)) length++;
		num[int(loop / pow(10, length - 1))][loop % 10]++;
	}
	
	int counter = 0;
	for (int loop1 = 1; loop1 < 10; loop1++) {
		for (int loop2 = 1; loop2 < 10; loop2++) {
			counter += num[loop1][loop2] * num[loop2][loop1];
		}
	}
	cout << counter << flush;
	return;
}

int main(void) {

	//A_AC_or_WA();
	//B_Comparing_Strings();
	//C_Low_Elements();
	D_Handstand2();
	return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

long long gcd(long long x, long long y){
	if (x > y){
		if (x%y == 0)return y;
		else return gcd(y, x - ((x / y)*y));
	}
	else {
		if (y%x == 0)return x;
		else return gcd(x, y - ((y / x)*x));
	}
}
int main(void){
	long long a[1000];
	int c, d;
	int k;
	int n, m;
	int s, t;
	int x, y, z;
	long long  ans;
	long long gcdn;


	scanf("%d", &n);

	for (int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
	}
	 
	ans = 1;

	for (int i = 0; i < n; i++){
		gcdn = gcd(a[i], ans);
		a[i] = a[i] / gcdn;
		ans = ans*a[i];
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 128
(defun al-2-num (x)
  (if (char= x #\r)
	0
	(if (char= x #\s)
	  1
	  2)))

(defun winner-num (x)
  (mod (+ (al-2-num x) 2) 3))

(defun make-point-list ()
  (let ((res (make-array 3)))
	(progn
	  (dotimes (i 3)
		(setf (aref res i) (read)))
	  res)))

(let* (
	  (n (read))
	  (k (read))
	  (point-list (make-point-list))
	  (s (read-line))
	  (used (make-array k :initial-element -1))
	  (ans 0))
  (progn
	(dotimes (i n)
	  (if (= (aref used (mod i k)) (winner-num (aref s i)))
		(setf (aref used (mod i k)) -1)
		(progn
		  (setf (aref used (mod i k)) (winner-num (aref s i)))
		  (setf ans (+ ans (aref point-list (winner-num (aref s i))))))))
	(princ ans)))


Measured memory_bytes: 19680
#include<iostream>
using namespace std;
int a[301][301];
bool ok[301][301];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>a[i][j];
		}
	}
	for(int k=1;k<=n;k++)
	{
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(i!=j&&i!=k&&j!=k)
				{
					if(a[i][j]>a[i][k]+a[k][j])
					{
						cout<<-1<<endl;
						return 0;
					}
					else if(a[i][j]==a[i][k]+a[k][j])
					{
						ok[i][j]=1;
					}
				}
			}
		}
	}
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(ok[i][j]==0) ans+=a[i][j];
		}
	}
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

long GCD(long a, long b){
  long dividend, divisor;
  if (a >= b) {
    dividend = a;
    divisor = b;
  } else {
    dividend = b;
    divisor = a;
  }
  long remainder;
  while (1) {
    if (divisor == 1) {
      return 1;
    }
    remainder = dividend % divisor;
    if (remainder == 0) {
      break;
    } else {
      dividend = divisor;
      divisor = remainder;
    }
  }
  return divisor;
}

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);
  long a[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
  }
  long lcm_all = a[0];
  for (long i = 1; i < n; i++) {
    lcm_all = (lcm_all/GCD(lcm_all,a[i]))*a[i];
    if (lcm_all > 3000000000) {
      lcm_all = 3000000000;
    }
  }
  long half = lcm_all/2;
  for (long i = 0; i < n; i++) {
    if (half%a[i] != a[i]/2) {
      printf("0\n");
      return 0;
    }
  }
  long mod = m%lcm_all;
  long ans = m/lcm_all;
  if (mod >= half) {
    ans++;
  }
  printf("%ld\n", ans);

  return 0;
}

Measured memory_bytes: 896
package main

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

var sc *bufio.Scanner

const BufferSize = 1024

func nextInt() int {
	if !sc.Scan() {
		panic(nil)
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var production bool

func debugf(format string, v ...interface{}) {
	if !production {
		fmt.Printf(format, v...)
	}
}

func answer(reader io.Reader, writer io.Writer) {
	sc = bufio.NewScanner(reader)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, 1e+6)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	q := nextInt()

	e := make([][]int, n)
	s := make([]int, n)

	for i := 0; i < n-1; i++ {
		u := nextInt()
		v := nextInt()
		e[u-1] = append(e[u-1], v-1)
		e[v-1] = append(e[v-1], u-1)
	}
	for i := 0; i < q; i++ {
		p := nextInt()
		x := nextInt()
		s[p-1] += x
	}

	ans := make([]int, n)
	ok := make([]bool, n)
	var dfs func(int, int)
	dfs = func(v int, x int) {
		ans[v] += x + s[v]
		ok[v] = true
		for _, u := range e[v] {
			if !ok[u] {
				dfs(u, s[v]+x)
			}
		}
	}
	dfs(0, 0)

	for i := 0; i < n; i++ {
		_, _ = fmt.Fprintf(writer, "%d", ans[i])
		if i < n-1 {
			_, _ = fmt.Fprint(writer, " ")
		}
	}
}

func main() {
	production = true
	answer(os.Stdin, os.Stdout)
}


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

int N, M;
vector<int> A, B, C, D;
const int MAX_D = 2000000000;

int main(void) {
	cin >> N >> M;
	A.resize(N);
	B.resize(N);
	C.resize(M);
	D.resize(M);
	for (int i = 0; i < N; ++i)
		cin >> A[i] >> B[i];
	for (int i = 0; i < M; ++i)
		cin >> C[i] >> D[i];

	for (int i = 0; i < N; ++i) {
		int ans = M;
		int d_min = MAX_D;
		for (int j = 0; j < M; ++j) {
			int dist = abs(A[i] - C[j]) + abs(B[i] - D[j]);
			if (dist < d_min) {
				d_min = dist;
				ans = j + 1;
			}
		}
		cout << ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int H = scan.nextInt();
		int W = scan.nextInt();
		int ans = (N-H+1)*(N-W+1);
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
H,W,K=map(int,input().split())
S=[[int(c) for c in input()] for i in range(H)]
A=[[0]*(W+1) for i in range(H+W)]
for i in range(H):
    for j in range(W):
        A[i+1][j+1]=A[i+1][j]+A[i][j+1]-A[i][j]+S[i][j]
from itertools import product
r=2000
def v(l,r,t,b):
    return A[b][r]-A[t][r]-A[b][l]+A[t][l]
for x in product((0,1),repeat=H-1):
    l=0
    a=sum(x)
    for j in range(W):
        f=1
        t=0
        for k in range(H-1):
            if x[k]:
                if v(l,j+1,t,k+1)>K:
                    f=2 if l<j else 0
                    l=j
                t=k+1
        if v(l,j+1,t,H)>K:
            f=2 if l<j else 0
            l=j
        if f==2:
            a+=1
        elif f==0:
            a=-1
            break
    if a>=0:
        r=min(r,a)
print(r)

Measured memory_bytes: 52572
#include <bits/stdc++.h>
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++)

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

    rep(i,3){
        if(s[i] == '1')s[i] = '9';
        else if(s[i] == '9')s[i] = '1';
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;
#define INF 1000000000

template <class X>
vector<vector<X>> warshall_floyd(int n, const vector<vector<pair<X, int>>> &G) {
    vector<vector<X>> d(n, vector<X>(n, INF));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < G[i].size(); j++)
            d[i][G[i][j].second] = G[i][j].first;
    for (int i = 0; i < n; i++) d[i][i] = 0;

    for (int k = 0; k < n; k++)
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if(d[i][k] != INF && d[k][j] != INF)
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    return d;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<vector<pair<int, int>>> G(N);
    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back(pair<int, int>(c, b));
        G[b].push_back(pair<int, int>(c, a));
    }
    vector<vector<int>> d = warshall_floyd(N, G);

    int ans = 0;
    for(int i=0; i<N; i++){
        for(auto e : G[i]){
            if(e.first > d[i][e.second]) ans++;
        }
    }
    ans /= 2;
    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long ll;

const int INF = 2e9;
template <class T> void chmin(T &a, T b) { if (a > b) a = b; }

const int MN = 1010;
const int MM = 5010;
vector<int> g[MN];
int n;
int x[MN];
int dp[MM], ndp[MM];
int mw[MN];

bool dfs(int v, int p) {
    for (int i = 0; i < int(g[v].size()); i++) {
        int u = g[v][i];
        if (u == p) continue;
        if (!dfs(u, v)) return false;
    }

    fill(dp, dp + x[v] + 1, INF);
    dp[0] = 0;
    for (int i = 0; i < int(g[v].size()); i++) {
        int u = g[v][i];
        if (u == p) continue;

        for (int j = 0; j <= x[v]; j++) {
            ndp[j] = INF;
            if (j - x[u] >= 0) {
                chmin(ndp[j], dp[j-x[u]] + mw[u]);
            }
            if (j - mw[u] >= 0) {
                chmin(ndp[j], dp[j-mw[u]] + x[u]);
            }
        }
        copy(ndp, ndp + x[v] + 1, dp);
    }
    if (int(g[v].size()) == 0) {
        mw[v] = 0;
    } else {
        mw[v] = *min_element(dp, dp + x[v] + 1);
    }
    return mw[v] < INF;
}

bool solve() {
    cin >> n;
    for (int i = 0; i < n; i++) g[i].clear();
    for (int i = 1; i < n; i++) {
        int p;
        cin >> p; p--;
        g[p].push_back(i);
    }
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    return dfs(0, -1);
}

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

    // int t;
    // cin >> t;
    int t = 1;
    for (int ph = 0; ph < t; ph++) {
        if (solve()) cout << "POSSIBLE" << endl;
        else cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
ll num[9],ans;

string out(ll n){
  string res,o="0123456789abcdef";
  if(n>=16) return out(n/16)+o[n%16];
  return res+o[n%16];
}

ll s2i(string s){
  ll res=0;
  for(int i=0;i<s.size();i++)
    if('0'<=s[i]&&s[i]<='9') res=res*16+s[i]-'0';
    else res=res*16+(10+s[i]-'a');
  return res;
}

bool saiki(ll a,ll b,int kai){
  if(a%(1LL<<(kai-1))!=b%(1LL<<(kai-1)))return 0;
  if(kai==33)return 1;
  ll cnt=0;
  for(int i=0;i<8;i++)cnt+=(num[i]>>kai)%2;

  ll c=(num[8]>>kai)%2;
  if(saiki(a+(cnt<<kai),b+(c<<kai),kai+1))return 1;
  if(saiki(a+((8-cnt)<<kai),b+((1^c)<<kai),kai+1)) {
    ans|=(1LL<<kai);
    return 1;
  }

  return 0;
}


int main(){
  int q;
  cin >>q;
  while(q--){
    string str;
    for(int i=0;i<9;i++)cin>>str,num[i]=s2i(str);
    ans=0;
    saiki(0,0,0);
    cout<<out(ans)<<endl;
  }
  return 0;
}

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

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

    int A[n+1],i,j,a;
    for(i=0; i<n; i++)
    {
        scanf("%d",&j);
        A[i]=j;
    }

    A[n]=A[0]+k;
    a=0;
    for(i=0; i<n; i++)
    {
        if(A[i+1]-A[i]>a)
        {
            a=A[i+1]-A[i];
        }
    }
    i=k-a;
    cout<<i<<endl;
    return 0;
}


Measured memory_bytes: 1024
var
	n,a,b,c,s,x:Longint;
	i,j,k:byte;
	d:array[0..255]of Longint;
	f:array[0..255]of Longint=(0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8);
begin
	read(n,a,b,c);
	i:=0;
	for k:=1 to n do begin
		read(x);
		for j:=0 to i do begin
			d[j+i+1]:=d[j]+x;
		end;
		inc(i,i+1);
	end;
	s:=5000000;
	d[0]:=50000000;
	for j:=0 to i do for k:=0 to i do begin
		x:=abs(d[j and k]-a)+abs(d[j and not k]-b)+abs(d[k and not j]-c)+f[j or k]*10-30;
		if s>x then s:=x;
	end;
	writeln(s);
end.

Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {

	sc.Split(bufio.ScanWords)
	var n, k, c int
	c=0

	fmt.Scanf("%d %d", &n, &k)
	t := make([]int, n)
	for i := 0; i < len(t); i++ {
		sc.Scan()
		j, _ := strconv.Atoi(sc.Text())
		if(j>=k){
			c++
		}

	}
	fmt.Printf("%d\n",c)
}


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

int main(){
  int n, b, f, r, v;
  int house[10][10][13] = {0};
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>b>>f>>r>>v;
    house[b][f][r] += v;
  }
  for(b=1;b<=4;b++){
    for(f=1;f<=3;f++){
      for(r=1;r<=10;r++){
	cout<<" "<<house[b][f][r];
      }
      cout<<endl;
    }
    if(b<=3)cout<<"####################"<<endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using ll = long long;

struct Corr {
    ll x;
    ll y;
    ll depth;
};

int h, w;  // 迷路の縦，横
ll s_y, s_x, g_y, g_x;  // スタート，ゴールの座標
ll y, x, depth;  // キューから取り出した座標
queue<Corr> q;

ll y_can[4] = {0, 0, -1, +1};  // 進む方向の簡便化，テクニックとして覚えておく．
ll x_can[4] = {-1, +1, 0, 0};  // ループで回すことで上下左右に移動できるようになっている

//int bfs() ;

int main() {

   // input
    cin >> h >> w  ;
    char maze[h][w] ;
    int ans = 0 ;
    for (ll i = 0; i < h; ++i){
        for(ll j=0;j<w;j++){
             cin >> maze[i][j] ;
             if(maze[i][j]=='.') ++ans ;
        }
    } 

    // calculation
    s_x = 0 ;
    s_y = 0 ;
    Corr start = {s_x, s_y, 0};  // 初期位置の深さ(depth)は 0
    q.emplace(start);  // 初期位置をキューに格納

    bool ok = false ;
    //bfs
     while(!q.empty()){
        Corr now = q.front( );
        q.pop();
        x = now.x ; y = now.y ; depth = now.depth ;
        
        if (y == (w-1) && x == (h-1) ) {
            ok = true ;
            break ;
        }
        for (int i = 0; i < 4; i++)
        {
            Corr next = {x + x_can[i], y + y_can[i], depth + 1} ;
                if(0 <= next.y && next.y <= w-1 && 0 <= next.x && next.x <= h-1 && maze[next.x][next.y] == '.')
                {
                    maze[next.x][next.y] = 'x' ;
                    q.push(next) ;
                }
        }
    }

   //cout << start.depth << start.x << endl ;
   if(ok)
    cout << ans-depth-1 << endl ;
   else
    cout << -1 << endl ;    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool visited[100000]={false};
void dfs(int v,vector<vector<int>> &adj,vector<int> &dp)
{
    visited[v]=true;
   // cout<<v<<endl;
    for (size_t i = 0; i < (int) adj[v].size(); ++i)
    {
        if(!visited[adj[v][i]])
            dfs(adj[v][i],adj,dp);
    
        dp[v] = max(dp[v], 1 + dp[adj[v][i]]); 
    }

}

int main()
{
    int N; int M;
    cin>>N>>M;
    vector<vector<int>> g(N+1);
    for(int i=0;i<M;i++)
    {
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
    }
    vector<int> dp(N+1);
    for (int i = 1; i <= N; i++) { 
        if (!visited[i]) 
            dfs(i, g, dp); 
    } 
    int ans = 0; 
  
    // Traverse and find the maximum of all dp[i] 
    for (int i = 1; i <= N; i++) { 
        ans = max(ans, dp[i]); 
    } 
    cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 8960
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    while (true) {
        int a, b;
        cin >> a >> b;
        if (a == 0 && b == 0)return 0;
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                if (1 <= i&&i <= a - 2 && 1 <= j&&j <= b - 2)cout << '.';
                else cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

int main(){
    string S,T;
    cin>>S>>T;
    int i,j;
    for(i=0,j=0;i<S.size();i+=2,j++){
        while(S[i]!=T[j]&&j<T.size())j++;
        if(j==T.size()) break;
    }
    if(i>=S.size()){
        cout<<"Yes"<<endl;
        return 0;
    }
    for(i=1,j=0;i<S.size();i+=2,j++){
        while(S[i]!=T[j]&&j<T.size())j++;
        if(j==T.size()) break;
    }
    if(i>=S.size()){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3196
using System;
using System.Linq;
using System.Collections.Generic;

class Cmondai
{
    static void Main()
    {
        var N = Int64.Parse(Console.ReadLine());
        var X = Console.ReadLine().Split(' ').Select(num=>Int64.Parse(num)).ToArray();
        var narabikae = X.OrderBy(x => x).ToList();
        var tyuo = N / 2;
        var tyuoNum1 = narabikae[(int)tyuo-1];
        var tyuoNum2 = narabikae[(int)tyuo];
        for (int i=0;i<N;++i)
        {
            var ans = (X[i] < tyuoNum2) ? tyuoNum2 : tyuoNum1;
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 47176
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll long long
#define INF 10000000000000000LL
#define pll pair<long long , long long>
const int MAX=1e5+10;
const int MOD=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
vector<int>adj[MAX];
int lvl[MAX];
int vis[MAX];
string find_lcs(string s, string t){
	int n=s.size();
	int m=t.size();
	int dp[n+1][m+1];
	memset(dp,  0, sizeof(dp));
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++)
		{
			if(i==0||j==0)
				dp[i][j]=0;
			else if(s[i-1]==t[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	int l=dp[n][m];
	int i=n, j=m;
	string ans="";
	while(i>0&&j>0){
		if(s[i-1]==t[j-1])
		{
			ans=ans+s[i-1];
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
			i--;
		else
			j--;
	}
	reverse(ans.begin(), ans.end());
	return ans;
}
int main() 
{ 
	//ios_base::sync_with_stdio(false);
  //  cin.tie(NULL);	
//	#ifndef ONLINE_JUDGE
//	freopen("inp.txt" ,"r", stdin );
////	freopen("out.txt", "w", stdout);
	//#endif
	string s , t;
	cin>>s>>t;
	cout<<find_lcs(s, t);
	
	
}

Measured memory_bytes: 37760
a, b, c, d = map(int, input().split())

"""
両方に関して割り切れるものの個数から公倍数で割り切れるものを除けばいい
"""
import fractions

C = b//c - (a-1)//c
D = b//d - (a-1)//d

# 最小公倍数を求める
CD = fractions.gcd(c, d)
lcm = (c * d) // CD

G = b//lcm - (a-1)//lcm


count = C + D - G
print(b - a + 1 - count)

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

int main(){
  int n;
  cin>>n;
  double nm=0;
  vector<double>x(n);
  vector<string>u(n);
  for(int i=0;i<n;i++){
    cin>>x[i]>>u[i];
  }
  for(int i=0;i<n;i++){
    if(u[i]=="BTC"){
      nm+=x[i]*380000;
    }
    else{
      nm+=x[i];
    }
  }
  cout<<fixed<<setprecision(20)<<nm<<endl;
}

Measured memory_bytes: 256
(function(stdin) {
  // Define Function

  // Declare Variable
  const inputs  = stdin.toString().trim().split('\n');

  // Main Procedure
  const result = (function(x) {

    return Math.pow(x, 3);

  }(parseInt(inputs[0], 10)));

  // Display
  console.log(result);

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())

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

const int MAXN = 2e5 + 5;

int a[MAXN];

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

  int n; cin >> n;

  REP(i, n) {
    cin >> a[i];
  }

  ll sol = 0;
  int tmp = 0;
  for(int i = n - 1; i >= 0; --i) {
    if(a[i] > i || tmp > a[i]) {
      cout << -1;
      return 0;
    }
    if(a[i] != tmp) {
      sol += a[i];
      tmp = a[i];
    }

    if(tmp) {
      tmp --;
    }
  }
  cout << sol << endl;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 2147483647;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 2000005;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[SIZE], finv[SIZE], inv[SIZE];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;
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 mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

double len(int a, int b, int c, int d) {
	return (double)sqrt((a - c) * (a - c) + (b - d) * (b - d));
}


int main() {
	long double a, b, c;
	cin >> a >> b >> c;
	cout << setprecision(20) << b / a * c << endl;
}


Measured memory_bytes: 3292
#include <stdio.h>

int count;

int main(void)
{
    int N;
    int i, j;
    int sum;
    int count;
    
    while (1){
        scanf("%d", &N);
        if (N == 0){
            break;
        }
        
        count = 0;
        for (i = 1; i <= 499; i++){
            sum = i;
            for (j = i + 1; j <= 500; j++){
                sum += j;
                if (sum > N){
                    break;
                }
                if (sum == N){
                    count++;
                    break;
                }
            }
        }
        printf("%d\n", count);
    }

    return (0);
}




        

Measured memory_bytes: 600
package main

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

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func bordersInt(in_map [][]int, invalid int) [][]int{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]int, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]int, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func bordersString(in_map [][]string, invalid string) [][]string{
	H, W := len(in_map), len(in_map[0])
	out_map := make([][]string, H+2)
	for h:=0; h<H+2; h++ {
		out_map[h] = make([]string, W+2)
		for w:=0; w<W+2; w++ {
			out_map[h][w] = invalid
		}
	}
	for h:=0; h<H; h++{
		for w:=0; w<W; w++{
			out_map[h+1][w+1] = in_map[h][w] 
		}
	}
	return out_map
}

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

var (
	N, M, ans int
	imap [][]bool
)

func check(visited map[int]bool, index int) {
	visited[index] = true
	cnt := 0
	for i, v := range imap[index] {
		if v && !visited[i]{
			new_visited := make(map[int]bool, N)
			for j:=0; j<N; j++ {
				new_visited[j] = visited[j]
			}
			check(new_visited, i)
		}
		if visited[i] {
			cnt++
		}
	}
	if cnt == N {
		ans++
	}
}

func main(){
	fmt.Scan(&N, &M)
	imap = make([][]bool, N)
	for i:=0; i<N; i++ {
		imap[i] = make([]bool, N)
	}
	for i:=0; i<M; i++ {
		arr := scanIntSplit(2)
		imap[arr[0]-1][arr[1]-1] = true
		imap[arr[1]-1][arr[0]-1] = true
	}
	visited := make(map[int]bool, N)
	for i:=0; i<N; i++ {
		visited[i] = false
	}
	check(visited, 0)
	fmt.Println(ans)
}

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

int main(){
  string S,T;
  cin >> S >> T;
  int count = 0;
  for (int i=0 ;i < S.size();i++){
    if (S.at(i)!=T.at(i)){
      count++;
    }
  }
  cout << count << endl;
  return 0;

}


Measured memory_bytes: 3800
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int number = scanner.nextInt();

        int max = 0;
        int result = 0;

        for (int i = 0; i < number; i++) {
            final int mountain = scanner.nextInt();
            if (mountain >= max) {
                result++;
                max = mountain;
            }
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 23124
#include <iostream>
using namespace std;
int main(){
	
	int d[102],n;
	int last,diff,flag,FLAG;
	
	while(cin>>n,n){
		for(int i=1;i<=n+1;i++)cin>>d[i];
		for(int i=1;i<=n+1;i++){
			last=flag=-1;
			FLAG=1;
			for(int j=1;j<=n+1;j++){
				if(j!=i){
					if(last==-1)last=d[j];
					else if(flag==-1){
						flag=1;
						diff=d[j]-last;
						last=d[j];
					}
					else if(diff==d[j]-last)last=d[j];
					else{
						FLAG=0;
						last=d[j];
					}
				}
			}
			if(FLAG)cout<<d[i]<<endl,i+=200;
		}
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int n;
char s[100100];
int ap[100100],bp[100100];
int ca,cb;
string f[3030];
bool book[6060];
int nxt[6060];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;++i)
		if(s[i]=='a')ap[++ca]=i;
		else bp[++cb]=i;
	n/=2;
	for(int i=1;i<=n;++i)nxt[min(ap[i],bp[i])]=i;
	for(int i=n*2;i;--i)if(!nxt[i])nxt[i]=nxt[i+1];
	for(int i=n;i;--i)
	{
		memset(book,0,sizeof(book));
		book[ap[i]]=book[bp[i]]=1;
		if(bp[i]<ap[i])
		{
			int mxa=ap[i];
			for(int j=i+1;j<=n;++j)
				if(bp[j]<ap[j]&&bp[j]<mxa)
				{
					book[ap[j]]=book[bp[j]]=1;
					mxa=max(mxa,ap[j]);
				}
			for(int j=1;j<=n*2;++j)
				if(book[j])f[i]+=s[j];
			f[i]+=f[nxt[mxa+1]];
		}
		else f[i]="ab"+f[nxt[bp[i]+1]];
		f[i]=max(f[i],f[i+1]);
	}
	cout<<f[1]<<endl;
	return 0;
}


Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>k;i--)
using namespace std;
int main(){
    long long n,sum=0;
    cin>>n;
    long long a[n],b[n];
    f(i,0,n){
        cin>>a[i];
        sum+=a[i];
    }
    long long ans=sum,sum2=0;
    f(i,0,n){
        sum2+=a[i];
        ans=min(ans,abs(2*sum2-sum));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5172
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
const int inf = INT_MAX;
const double eps = 0.0000001;
const double PI = acos(-1.0);
const int MOD = 1e9+7;
const int N  = 105;

int w[N], v[N], dp[N][100005], ready[N][100005];

int solve (int i, int j) {
	if (j == 0) return 0;
	if (j < 0) return -inf;
	if (i == 0) return 0;
	if (ready[i][j]) return dp[i][j];
	ready[i][j];
	dp[i][j] = max(v[i] + solve(i-1, j-w[i]), solve(i-1, j));
	return dp[i][j];
}

signed main(){
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif  
    IOS;

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

Measured memory_bytes: 80128
#全点最短距離の使い回し

import sys

v, e = map(int, input().split( ))

Edge = [[] for _ in range(v)]

for i in range(e):
    inpt = list(map(int, input().split( )))
    Edge[inpt[0]].append(inpt[1])

inf = 10**12


dp = [[inf for _ in range(v)] for __ in range(v)]
for i in range(v):
    for ed in Edge[i]:
        dp[i][ed] = -1
for i in range(v):
    dp[i][i] = 0
"""
・for k,for i, for jの順。for i,j,kだと別物
・dpはkによらず使い回しでよい
"""
for k in range(v):
    for j in range(v):
        for i in range(v):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

for i in range(v):
    if dp[i][i]<0:
        print(1)
        sys.exit()

print(0)



Measured memory_bytes: 6316
#include <list>
#include <iostream>
#include <vector>
#include <sstream>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <map>
#include <sstream>
#include <set>
#include <cmath>
#include <iomanip>
#include <queue>

#define endl "\n"
#define int long long
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rr return 0

using namespace std;


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n],b[n],c[n];
    for(int i = 0;i < n;i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    int dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for(int i = 1;i < n;i++){
        dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][1],dp[i-1][0]);
        dp[i][1] = b[i] + max(dp[i-1][0],dp[i-1][2]);
    }
    cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
    rr;
}


Measured memory_bytes: 4992
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int a,b,k;cin>>a>>b>>k;
    vector<int>d;
    rep(i,200){
        if(i==0)continue;
        if(a%i==0 && b%i==0)d.push_back(i);
    }
    cout<<d[d.size()-k]<<endl;
}



Measured memory_bytes: 256
n = gets.to_i
l = gets.chomp.split(" ").map(&:to_i).sort.reverse

results = 0
0.upto(n - 1) do |a|
	b = a + 1
	c = n - 1
	while b < c
		if l[c] > l[a] - l[b] then
			results = results + c - b
			b = b + 1
		else
			c = c - 1
		end
	end
end
p results

Measured memory_bytes: 1912
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = Integer.parseInt(scanner.nextLine());

		Map<String, Integer> map = new HashMap<>();

		map.put("AC", 0);
		map.put("WA", 0);
		map.put("TLE", 0);
		map.put("RE", 0);

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

			String a = scanner.nextLine();

			if(a.equals("AC")) {

					map.put("AC", map.get("AC") + 1);

			}else if(a.equals("WA")) {

					map.put("WA", map.get("WA") + 1);

			}else if(a.equals("RE")) {

					map.put("RE", map.get("RE") + 1);

			}else{

				map.put("TLE", map.get("TLE") + 1);

			}
        }
      			System.out.println("AC x " + map.get("AC"));
			System.out.println("WA x " + map.get("WA"));
			System.out.println("TLE x " + map.get("TLE"));
			System.out.println("RE x " + map.get("RE"));

	}
}

Measured memory_bytes: 60664
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    println!("{}", n * n * n);
}

// region template
#[allow(dead_code)]
fn iu(i: isize) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> isize { i as isize }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

#[allow(dead_code)]
fn alt<S, T>(v: Vec<S>) -> T where T: FromIterator<S> {
    v.into_iter().collect::<T>()
}

#[allow(dead_code)]
fn dup<S, T>(v: &[S]) -> T where T: FromIterator<S>, S: Clone {
    v.iter().cloned().collect::<T>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
#include <iostream> 
#include <vector>
using namespace std;
#define ll long long 

int main() {
  int n;
  string s;
  cin >> n >> s;
  int r = 0, b = 0;
  for ( int i = 0; i < n; ++i ) {
    if ( s[i] == 'R' ) ++r;
    else ++b;  
  }
  if(r > b) cout << "Yes" << endl;
  else cout << "No" << endl; 
  return 0;
}


Measured memory_bytes: 888
h, w = map(int, input().split())
a=[[j for j in input()] for i in range(h)]
ans = 'Yes'
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            if 1<=i<=h-2 and 1<=j<=w-2:
                if a[i-1][j] == "." and a[i+1][j] == "." and a[i][j-1] == "." and a[i][j+1] == ".":
                    ans = 'No'
                    break
            elif i == 0 and 1<=j<=w-2:
                if a[i][j-1] == "." and a[i][j+1] == "." and a[i+1][j] == ".":
                    ans = 'No'
                    break
            elif  i == h and 1<=j<=w-2:
                if a[i][j-1] == "." and a[i][j+1] == "." and a[i-1][j] == ".":
                    ans = 'No'
                    break
            elif 1<=i<=h-2 and j == 0 :
                if a[i-1][j] == "." and a[i+1][j] == "." and a[i][j+1] == "." :
                    ans = 'No'
                    break
            elif 1<=i<=h-2 and j == w:
                if a[i-1][j] == "." and a[i+1][j] == "." and a[i][j-1] == "." :
                    ans = 'No'
                    break
            elif i==0 and j==0:
                if a[i][j+1]=="." and a[i+1][j]==".":
                    ans = 'No'
                    break 
            elif i==h-1 and j==0:
                if a[i-1][j]=="." and a[i][j+1]==".":
                    ans = 'No'
                    break 
            elif i==0 and j==w-1:
                if a[i][j-1]=="." and a[i+1][j]==".":
                    ans = 'No'
                    break 
            elif i==h-1 and j==w-1:
                if a[i][j-1]=="." and a[i-1][j]==".":
                    ans = 'No'
                    break 
print(ans)

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, c;
  while (cin >> n >> c) {
    int d[c][c];
    for (int i = 0; i < c; ++i) {
      for (int j = 0; j < c; ++j) {
        cin >> d[i][j];
      }
    }
    int g[n][n];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        cin >> g[i][j];
        --g[i][j];
      }
    }

    map<int, int> cnt[3];
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        ++cnt[(i + j) % 3][g[i][j]];
      }
    }

    int mn = 1 << 29;
    for (int x = 0; x < c; ++x) {
      for (int y = 0; y < c; ++y) {
        for (int z = 0; z < c; ++z) {
          if (x == y || x == z || y == z) continue;
          int sum = 0;
          each (i, cnt[0]) sum += d[i.first][x] * i.second;
          each (i, cnt[1]) sum += d[i.first][y] * i.second;
          each (i, cnt[2]) sum += d[i.first][z] * i.second;
          mn = min(mn, sum);
        }
      }
    }
    cout << mn << endl;
  }

  return 0;
}


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

int main(){
    long long int x;
    cin >> x;
    long long int sum = 0;
    long long int  a500 = x /500;
    long long int amari500 = x % 500;
    long long int a5 = amari500 / 5;
    sum += 1000 * a500;
    sum += 5 * a5;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
using namespace std;

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <numeric>
typedef long long ll;
typedef pair<int,int> p;

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


int main()
{
  // input & declare
  int n,tmp;
  cin >> n;
  std::vector<int> v;
  for(int i = 0; i < n; i++)
  {
    cin >> tmp;
    v.push_back(tmp);
  }
  set<int> s(v.begin(), v.end());
  std::cout << s.size() << '\n';

}


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

int main(){
  int len;
  cin >> len;
  int a[len];
  for(int i=0;i<len;i++){
    cin >> a[i];
  }
  int count = 0;
  bool allEven = true;
  while(allEven){
    for(int i=0;i<len;i++){
      if(a[i]%2 == 1){
        allEven = false;
        break;
      }
      a[i] /= 2;
    }
    if(allEven)count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_110
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] abc = ReadInts();
            Array.Sort(abc);
            WriteLine(abc[2] * 10 + abc[1] + abc[0]);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13268