akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a = 0, b = 0;
    string s;
    cin >> n >> s;
    for ( int i = 0 ; i < n ; i++ ) {
        if ( s[i] == '(' ) b++;
        else b--;
        if ( b < 0 ) {
            b = 0;
            a++;
        }
    }
    while ( a-- ) cout << '(';
    cout << s;
    while ( b-- ) cout << ')';
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn read_line(n: usize) -> String {
    let mut ss = String::new();
    for _i in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        ss.push_str(&s);
    }
    ss
}

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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main()
{
    parse!{
        h: i32,
        n: usize,
        aas: [i32; n],
    }
    let sum = aas.iter().fold(0, |sum, v| sum + v);
    if sum < h {
        println!("No");
    }
    else {
        println!("Yes");
    }
}

Measured memory_bytes: 4352
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MAXN = 500 + 10;
vector<PII> G[MAXN];
vector<int> pp[MAXN];
bool vis[MAXN][MAXN];
PII Q[MAXN * MAXN];
char E[MAXN][10];
int L[MAXN], can[MAXN];
int n, m, a, b;

int trans(char *s, int n, int x, char *t, int lt) {
  if (x == n) return x;
  int i = 0;
  while (x < n && i < lt && s[x] == t[i]) {
    ++ x; ++ i;
  }
  if (x == n || i == lt) return x;
  else return -1;
}

bool check(char *s, int l) {
  for (int i = 0; i < n; ++ i) {
    for (int j = 0; j <= l; ++ j) {
      vis[i][j] = false;
    }
  }
  vis[a][0] = 1; Q[0] = PII(a, 0);
  for (int h = 0, t = 1; h < t; ++ h) {
    int u = Q[h].first, x = Q[h].second;
    for (size_t i = 0; i < G[u].size(); ++ i) {
      int v = G[u][i].first, is = G[u][i].second;
      int ll = trans(s, l, x, E[is], L[is]);
      if (ll != -1 && !vis[v][ll] && can[v]) {
        vis[v][ll] = true;
        Q[t ++] = PII(v, ll);
        if (ll == l) return true;
      }
    }
  }
  return vis[b][l];
}

int trans1(char *s, int n, int x, char *t, int lt) {
  for (int i = 0; i < lt; ++ i) {
    if (i + x == n || s[i + x] != t[i]) return -1;
  }
  return x + lt;
}

bool check1(char *s, int l) {
  for (int i = 0; i < n; ++ i) {
    for (int j = 0; j <= l; ++ j) {
      vis[i][j] = false;
    }
  }
  vis[a][0] = 1; Q[0] = PII(a, 0);
  for (int h = 0, t = 1; h < t; ++ h) {
    int u = Q[h].first, x = Q[h].second;
    for (size_t i = 0; i < G[u].size(); ++ i) {
      int v = G[u][i].first, is = G[u][i].second;
      int ll = trans1(s, l, x, E[is], L[is]);
      if (ll != -1 && !vis[v][ll]) {
        vis[v][ll] = true;
        Q[t ++] = PII(v, ll);
      } 
    }
  }
  return vis[b][l];
}
char ret[MAXN];
bool solve() {
  int l, mx = (n - 1) * 6;
  for (l = 1; l <= mx; ++ l) {
    ret[l - 1] = ' ';
    for (char c = 'a'; c <= 'z'; ++ c) {
      ret[l - 1] = c;
      if (check(ret, l)) break;
      ret[l - 1] = ' ';
    }
    if (ret[l - 1] == ' ') break;
  }
  if (ret[l - 1] == ' ') -- l;
  if (l == mx) return false;
  check1(ret, l);
  for (int i = 1; i <= l; ++ i) if (vis[b][i]) {
    ret[i] = 0;
    puts(ret); return true;
  }
  return false;
}

void bfs(int u) {
  queue<int> Q; Q.push(u);
  for (int i = 0; i < n; ++ i) can[i] = 0; can[u] = 1;
  while (!Q.empty()) {
    int u = Q.front(); Q.pop();
    for (size_t i = 0; i < pp[u].size(); ++ i) {
      int v = pp[u][i];
      if (!can[v]) can[v] = 1, Q.push(v);
    }
  }
}
int main() {
  /*int T; scanf("%d", &T);
  for (int cas = 1; cas <= T; ++ cas) {
    printf("Case #%d:\n", cas);*/
    while (scanf("%d%d%d%d", &n, &m, &a, &b) == 4 && n) {
    for (int i = 0; i < n; ++ i) {
      G[i].clear(); pp[i].clear();
    }
    for (int i = 0; i < m; ++ i) {
      int u, v;
      scanf("%d%d%s", &u, &v, E[i]);
      L[i] = strlen(E[i]);
      G[u].push_back(PII(v, i));
      pp[v].push_back(u);
    }
    bfs(b);
    if (!can[a] || !solve()) puts("NO");
  }
  return 0;
}

Measured memory_bytes: 3300
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)



int main() {
	int n,sum=0,memo;
	cin >> n;

	VI s(n);
	rep(i, n) cin >> s[i];
	sort(all(s));

	rep(i, n) sum += s[i];
	memo = sum;
	if (sum % 10 == 0) {
		for (int i = 0; i < n; i++) {
			if(s[i]%10!=0) sum -= s[i];
			if (sum % 10 != 0) break;
		}
		if (memo == sum) sum = 0;
	}

	cout << sum << endl;

	return 0;
}


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

#define N_MAX 100

int main() {
    long a, b, k;
    cin >> a >> b >> k;

    long i = 1;
    long div = min(a, b);
    long ans;
    while (i <= k) {
        if (a % div == 0 && b % div == 0) {
            ans = div;
            i++;
        }
        div--;
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int d, n;
    cin >> d >> n;
    int cnt = 0, i = 0;
    while(cnt < n){
        i++;
        int div_num = 0;
        int tmp = i;
        while(tmp%100 == 0){
            tmp /= 100;
            div_num++;
        }
        if(d == div_num) cnt++;
    }
    cout << i << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=1005;
int n,m,a,b;

int main(){
	scanf("%d%d%d%d",&n,&m,&a,&b);
	REP(i,n)REP(j,m){
		if(i<=b&&j<=a)putchar('0');
		else if(i<=b&&j>a)putchar('1');
		else if(i>b&&j<=a)putchar('1');
		else putchar('0');
		if(j==m)putchar('\n');
	}
	return 0;
} 

Measured memory_bytes: 1280
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

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

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    LL n;
    LL a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    LL ans = 0;

    LL ma = a, mb = min(b, ma), mc = min(c, mb), md = min(d, mc), me = min(e, md);

    ans += (n + a - 1) / a;
    LL prev = n % a;
    if (prev == 0) prev = a;
    //dump(ans);
    //dump(prev);

    LL rest = n - (ans - 1) * mb;
    ans += (rest + b - 1) / b;
    prev = rest % b;
    if (prev == 0) prev = b;
    //dump(ans);
    //dump(prev);

    rest = n - (ans - 2) * mc;
    ans += (rest + c - 1) / c;
    prev = rest % c;
    if (prev == 0) prev = c;
    //dump(ans);
    //dump(prev);

    rest = n - (ans - 3) * md;
    ans += (rest + d - 1) / d;
    prev = rest % d;
    if (prev == 0) prev = d;
    //dump(ans);
    //dump(prev);

    rest = n - (ans - 4) * me;
    ans += (rest + e - 1) / e;
    prev = rest % e;
    if (prev == 0) prev = e;
    //dump(ans);
    //dump(prev);

    cout << ans << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int64_t M, N;
  cin >> M >> N;
  if(M == 1) {
    cout << N;
  }
  else {
    int64_t ans = N;
    rep(i, M - 1) {
      ans *= (N - 1);
    }
    cout << ans;
  }
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        int count4 = 0;
        int count2 = 0;
        int count = 0;
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextLong();
            if(a[i] % 4 == 0) {
                count4++;
            } else if(a[i] % 2 == 0) {
                count2++;
            } else {
                count++;
            }
        }
        if(count2 > 0) {
            count++;
        }
        if(count4 + 1 >= count) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

int main(){
   IOS;
 //    #ifndef ONLINE_JUDGE
 //        freopen("in.txt",  "r",  stdin);
 //        freopen("out.txt", "w", stdout);
 //    #endif


   long int x;
   cin>>x;


   if(x < 100)
   	return cout<<"0",0;

   if(x < 106 || !(x % 105))
   	return cout<<"1",0;


   vector<bool> dp(x + 5);
   dp[100] = dp[101] = dp[102] = dp[103] = dp[104] = dp[105] = 1;
   
   for(long int i = 105; i <= x + 4; i++){
   	dp[i] = (dp[i-100] || dp[i-102] || dp[i-103] || dp[i-104] || dp[i-105] || dp[i-101]);
   }

   cout<<dp[x];
   return 0;
}

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


void solve(long long H, long long W)
{
    if(H==1||W==1)
        cout<<1<<endl;
    else
        cout<<(H*W+1)/2<<endl;
}

int main()
{
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    solve(H, W);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

map<ll, ll> primeFactors(ll n)
{
    map<ll, ll> ret;
    while (n % 2 == 0)
    {
        if( ret.find(2) != ret.end() ) {
            ret[2]++;
        }
        else
        {
            ret[2] = 1;
        }
        n = n / 2;
    }
    for (ll i = 3; i <= sqrt(n); i = i+2)
    {
        while (n%i == 0)
        {
            if( ret.find(i) != ret.end() ) {
            ret[i]++;
        }
        else
        {
            ret[i] = 1;
        }
            n = n / i;
        }
    }
    if (n > 2)
        {
            if( ret.find(n) != ret.end() ) {
            ret[n]++;
        }
        else
        {
            ret[n] = 1;
        }
        }
    return ret;
}

int main()
{
    ll N;
    cin >> N;
    map<ll, ll> mp;
    rep(i, N){
        if (i+1 == 1) {
            mp[1] = 1;
            continue;
        }
        map<ll, ll> tmp;
        tmp = primeFactors(i+1);
        for(P p : tmp) {
            mp[p.first] += p.second;
        }
    }
    ll count = 1;
    for(pair <ll, ll> p : mp) {
        if (p.first == 1) continue;
        count *= p.second+1;
        count %= MOD;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
// ConsoleApplication.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#define _USE_MATH_DEFINES

#include "stdio.h"
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <unordered_set>
#include <functional>
#include <array>

using namespace std;

int INF = 1000000000;
int MAX = 5000001;

void merge(vector<int>& A, const int left, const int mid, const int right, int & cnt, vector<int>& L, vector<int>& R) {
	L.clear();  L.insert(L.end(), A.begin() + left, A.begin() + mid); L.push_back(INF);
	R.clear();  R.insert(R.end(), A.begin() + mid, A.begin() + right); R.push_back(INF);
	int i = 0, j = 0;
	cnt += right - left;
	for (int k = left; k != right; ++k) {
		A.at(k) = L.at(i) <= R.at(j) ? L.at(i++) : R.at(j++);
	}

}

void mergeSort(vector<int>& A, const int left, const int right, int& cnt, vector<int>& L, vector<int>& R) {
	if ( !(left + 1 < right) ) return;
	const int mid = (left + right) / 2;
	mergeSort(A, left, mid, cnt, L, R);
	mergeSort(A, mid, right, cnt, L, R);
	merge(A, left, mid, right, cnt, L, R);
}

int mergeSort(vector<int>& A) {
	int cnt = 0;
	vector<int> L, R;
	L.reserve(MAX);
	R.reserve(MAX);
	mergeSort(A, 0, A.size(), cnt, L,R);
	return cnt;
}

int main()
{
	int n;
	cin >> n;
	vector<int> A(n);
	for (auto& i : A)cin >> i;
	const int swapCount = mergeSort(A);
	/*const string out = accumulate(A.begin() + 1, A.end(), to_string(A.front()), [&](const string& init, const int val) {
		return init + " " + to_string(val);
	});
	cout << out << endl;
	*/
	cout << A.front();
	for_each(A.begin() + 1, A.end(), [](const int i) {cout << " " << i; });
	cout << endl;
	cout << swapCount << endl;


	return 0;
}


Measured memory_bytes: 6796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll p=a*c;
	p=max(b*d,p);
	p=max(a*d,p);
	p=max(b*c,p);
	cout<<p<<endl;
	return 0;
}

Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    # N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    X, N = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    if N == 0:
        print(X)
        return
    if N >= 1:
        p_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([p_list]))

    p_set = set(p_list)
    for i in range(100):
        for s in (-1, 1):
            r = X + i * s
            if r not in p_set:
                print(r)
                return


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6 5
4 7 10 6 5"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10 5
4 7 10 6 5"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """100 0"""
        output = """100"""
        self.assertIO(input, output)


Measured memory_bytes: 16296
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		String s = sc.next();
		int min = 1000;
		for(int i = 0; i < s.length() - 2; i++) {
			int n = Math.abs(Integer.parseInt(s.substring(i, i + 3)) - 753);
			if(min > n)min = n;
		}
		System.out.println(min);
	}
	Main(){doIt();}
	public static void main(String[] args) {
		new Main();
	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N,K,Q; cin>>N>>K>>Q;
  vector<int> A(Q);
  vector<int> tmp(N,0);
  for(int i=0;i<Q;i++){
    cin>>A.at(i);
    tmp.at(A.at(i)-1)++;
  }

  if(K>Q){
    for(int i=0;i<N;i++){
      cout<<"Yes"<<endl;
    }
  }else{
    for(int i=0;i<N;i++){
      if(tmp.at(i)+K-Q<=0){
        cout<<"No"<<endl;
      }else{
        cout<<"Yes"<<endl;
      }
    }

  }
}


Measured memory_bytes: 1408
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        n: usize,
        ab: [(usize1, usize1); n-1]
    }

    let mut g = vec![vec![]; n];
    for i in 0..n-1 {
        g[ab[i].0].push(ab[i].1);
        g[ab[i].1].push(ab[i].0);
    }
    println!("{}", if diameter(&g).len() % 3 != 2 {"First"} else {"Second"});
}

#[allow(dead_code)]
fn far_vertex(
    btrace: &mut [Option<usize>],
    graph: &[Vec<usize>],
    pre: Option<usize>,
    cur: usize,
) -> (usize, usize) {
    let mut ret = (cur, 0);
    for &v in &graph[cur] {
        match pre {
            Some(p) if v == p => continue,
            _ => (),
        };
        let mut tmp = far_vertex(btrace, graph, Some(cur), v);
        tmp.1 += 1;
        if tmp.1 > ret.1 {
            ret = tmp;
            btrace[v] = Some(cur);
        }
    }
    ret
}
#[doc = " returns a diameter route"]
#[allow(dead_code)]
pub fn diameter(graph: &[Vec<usize>]) -> Vec<usize> {
    let mut btrace = vec![None; graph.len()];
    let leaf = far_vertex(&mut btrace, graph, None, 0);
    btrace = vec![None; graph.len()];
    let far = far_vertex(&mut btrace, graph, None, leaf.0);
    let mut ret = vec![];
    let mut cur = Some(far.0);
    while let Some(c) = cur {
        ret.push(c);
        cur = btrace[c];
    }
    ret
}

Measured memory_bytes: 55804
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
using pii =pair<int,int>;

int n;
vector<int> a;
void input(){
    cin>>n;
    a.resize(n);
    rep(i,n) cin>>a[i];
}
void src(){
    double sum=0.0;
    rep(i,n) sum+=1.0/a[i];
    cout<<setprecision(10)<<fixed<<1.0/sum;
    return;
}

int main(int argc,char* argv[]){
    //ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
package main
import (
   "fmt"
   "os"
   "bufio"
   "strconv"
)
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Split(bufio.ScanWords)
  n := nextInt()
  a := nextInt()
  b := nextInt()


  div := n / (a + b)
  divRemain := n % (a + b)
  remainBlue := 0

  if divRemain <= a {
	  remainBlue = divRemain
  } else {
	  remainBlue = a
  }

  fmt.Println(div * a + remainBlue)

}

func nextString() (string) {
	sc.Scan()
	v := sc.Text()
	return v
}

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

func nextFloat() (float64) {
	sc.Scan()
	v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil { panic(e) }
    return v
}


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

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

  vector<int> c(N);
  vector<int> t(N);

  for (int i = 0; i < N; i++){
    cin >> c.at(i) >> t.at(i);
  }

  int min = 999999;
  for (int i = 0; i < N; i++)
  {
    if (T >= t.at(i) && min > c.at(i)) min = c.at(i);
  }

  if (min == 999999){
    cout << "TLE" << endl;
  }
  else
  {
    cout << min << endl;  
  }
  
  
  
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  int A = nextInt();
  int B = nextInt();
  cout << min(A*N, B) << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;


public class Main {
	static Scanner InData = new Scanner(System.in);
	static HashSet<Integer> S = new HashSet<Integer>();
	
	public static void main(String[] args) {
		getQuery();
	}

	private static void getQuery() {
		int qNum = InData.nextInt();
		int qType, qVal;
		for(int indexOfQuery = 0; indexOfQuery < qNum; indexOfQuery++) {
			qType = InData.nextInt();
			qVal = InData.nextInt();;
			doQuery(qType, qVal);
		}
	}

	private static void doQuery(int type, int val) {
		switch(type) {
		case 0:
			S.add(val);
			System.out.println(S.size());
			break;
		case 1:
			System.out.println(S.contains(val) ? 1 : 0);
			break;
		case 2:
			S.remove(val);
		}
	}
}


Measured memory_bytes: 153124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int r,g,b; cin>>r>>g>>b;
    if((r*100+g*10+b)%4==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
# AOJ ITP2_7_C: Set: Range Search
# Python3 2018.6.24 bal4u

from bisect import bisect_left, bisect_right, insort_left
dict = {}
keytbl = []
cnt = 0
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = int(a[1])
	if a[0] == '0':
		if ki not in dict:
			dict[ki] = 1
			cnt += 1
			insort_left(keytbl, ki)
		elif dict[ki] == 0:
			dict[ki] = 1
			cnt += 1
		print(cnt)
	elif a[0] == '1': print(dict[ki] if ki in dict else 0)
	elif a[0] == '2':
		if ki in dict:
			cnt -= dict[ki]
			dict[ki] = 0
	else:
		L = bisect_left (keytbl, int(a[1]))
		R = bisect_right(keytbl, int(a[2]), L)
		for j in range(L, R):
			if dict[keytbl[j]] == 1: print(keytbl[j])


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

int main() {
    string s;
    cin >> s;
    int ans=0;
    rep(i,3){
        if(s[i]=='R') ans++;
    }
    if(s[1]=='S') ans=min(ans,1);
    cout << ans << endl;
}

Measured memory_bytes: 3588
import std;

// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}
T[] lreads(T=long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}
void arywrite(T=long)(T[] ary){ary.map!(text).join(' ').writeln;}
void scan(TList...)(ref TList Args){auto line = readln.split;
foreach (i,T;TList){T val=line[i].to!(T);Args[i]=val;}}
void dprint(TList...)(TList Args){debug{auto s=new string[](TList.length);
static foreach(i,a;Args) s[i]=text(a);s.map!(text).join(' ').writeln;}}
alias sread=()=>readln.chomp();enum MOD =10^^9+7;
alias PQueue(T,alias less="a<b") = BinaryHeap!(Array!T,less);
// dfmt on

void main()
{
    long N, M, X;
    scan(N, M, X);
    auto CA = new long[][](N);
    foreach (i; 0 .. N)
        CA[i] = aryread();
    long ans = long.max;
    o: foreach (state; 1 .. (1 << N))
    {
        long cost;
        auto x = new long[](M);
        foreach (i; 0 .. N)
            if (state & (1 << i))
            {
                cost += CA[i][0];
                x[] += CA[i][1 .. $];
            }
        // writefln("%020b %s", state, cost);
        foreach (i; 0 .. M)
            if (x[i] < X)
                continue o;
        ans = ans.min(cost);
    }
    writeln(ans == long.max ? -1 : ans);
}


Measured memory_bytes: 3908
n = int(input())
dp = [1000000] * 100010
dp[0] = 0
for i in range(1, n + 1):
    a = 1
    while a <= i:
        dp[i] = min(dp[i], dp[i - a] + 1)
        a *= 6
    b = 1
    while b <= i:
        dp[i] = min(dp[i], dp[i - b] + 1)
        b *= 9
print(dp[n])


Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define test ll t; cin>>t; while(t--)
typedef long long int ll;
ll n;
ll a[401];
ll prefix[401];
ll dp[401][401];
ll calc(ll a,ll b){
    if(a>b){
        return LONG_MAX;
    }
    return prefix[b]-prefix[a-1];
}
ll solve(int l,int r){
    if(dp[l][r]!=-1){
        return dp[l][r];
    }
    if(l==r){
        return dp[l][r]=0;
    }
    if(l+1==r){
        return dp[l][r]=a[l]+a[r];
    }
    ll best=LONG_MAX;
    for(int i=l;i<r;i++){
        ll cand=solve(l,i)+solve(i+1,r)+calc(l,r);
        best=min(best,cand);
    }
    return dp[l][r]=best;
}
int main() {
    FIO;
    //test
    {
       cin>>n;
       for(int i=1;i<=n;i++){
           cin>>a[i];
       }
       prefix[0]=0;
       for(int i=1;i<=n;i++){
           prefix[i]=prefix[i-1]+a[i];
       }
       memset(dp,-1,sizeof(dp));
       cout<<solve(1,n)<<endl;
    }
	return 0;
}


Measured memory_bytes: 4948
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): pass
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
G = [[] for _ in range(n)]
for _ in range(n - 1):
    x, y = LI()
    G[x - 1] += [y - 1]
    G[y - 1] += [x - 1]


par = [-1] * n
def f(u):
    b, w = 1, 1
    for v in G[u]:
        if v == par[u]:
            continue
        par[v] = u
        cb, cw = f(v)
        b = b * cw % mod
        w = w * (cw + cb)
    return b, w

bb, ww = f(0)
print((bb + ww) % mod)


Measured memory_bytes: 106864
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    char c;
    int ans = 0;
    rep(i,3){
        cin >> c;
        if(c == '1')ans ++;
    }
    cout << ans << endl;
    return 0;
}

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

const int m = 1e9 + 7;

vector<vector<int>> adj;

int mul(int a, int b) {
    return ((long long) a * b) % m;
}

vector<int> numWays(int node, int parent) {
    vector<int> ways(2);
    ways[0] = ways[1] = 1;
    for(int neigh : adj[node]) {
        if(neigh == parent) continue;
        vector<int> subWays = numWays(neigh, node);
        ways[0] = mul(ways[0], subWays[0] + subWays[1]);
        ways[1] = mul(ways[1], subWays[0]);
    }
    return ways;
}

int main() {
    int n;
    cin>>n;
    adj.resize(n);
    for(int i=1; i<n; i++) {
        int u, v;
        cin>>u>>v;
        adj[u-1].push_back(v-1);
        adj[v-1].push_back(u-1);
    }
    vector<int> ways = numWays(0, -1);
    cout<< (ways[0] + ways[1]) % m << endl;
    return 0;
}


Measured memory_bytes: 16896
#include<iostream>
#include <stdio.h>

using namespace std;
int a[202020],n,cnt = 0,k;
int main(){
	scanf("%d",&n);
	for (int i = 1;i <= n; i++) {
		scanf("%d",&a[i]);
	}
	long long lef = 1000,ans = 1000,c = 0;
	for (int i = 1;i <= n; i++) {
		if (a[i+1] > a[i]) {
			c += lef/a[i];
			lef %= a[i];
		}
		else {
			lef += c*a[i];
			c = 0;
		}
		ans = max(ans,lef + c*a[i]);
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  vi a(n + 2);
  a[0] = 0;
  a[n + 1] = 0;
  REP(i, n) { cin >> a[i + 1]; }

  int sum = 0;
  REP(i, n + 1) { sum += abs(a[i + 1] - a[i]); }

  FOR(i, 1, n + 1) {
    cout << sum - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) +
                abs(a[i - 1] - a[i + 1])
         << endl;
  }
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int K = scan.nextInt();
		int[] d = new int[K];
		int[][] A = new int[K][N];
		int[] x = new int[N];
		int ans =0;
		for (int i = 0; i < N; i++) {
			x[i] = 0;
		}
		for (int i = 0; i < K; i++) {
			d[i] = scan.nextInt();
			for (int j = 0; j < d[i]; j++) {
				A[i][j] = scan.nextInt();
			}
		}

		for (int i = 0; i < K; i++) {
			for (int j = 0; j < d[i]; j++) {
				x[A[i][j]-1] = 1;
			}
		}

		for (int i = 0; i < N; i++) {
			if (x[i] == 0) {
				ans++;
			}
		}

		System.out.println(ans);
	}

}

Measured memory_bytes: 46072
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int maxn=2010;
pair<int,int>e[maxn];
vector<int> edge[maxn];
bool vis[maxn];
int cnt;
void dfs(int n,int k)
{
	vis[n]=1;
	cnt++;
	if(k==0)return ;
	for(int i=0;i<edge[n].size();i++)
	{
		if(!vis[edge[n][i]])dfs(edge[n][i],k-1);
	}
}
int main()
{
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		e[i].first=a;
		e[i].second=b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	int ans=n;
	if(k&1)
	{
		for(int i=1;i<=n-1;i++)
		{
			cnt=0;
			memset(vis,0,sizeof(vis));
			vis[e[i].second]=1;
			dfs(e[i].first,k/2);
			dfs(e[i].second,k/2);
			int temp=n-cnt;
			ans=min(ans,temp);
		}
	}
	else {
		for(int i=1;i<=n;i++)
		{
			cnt=0;
			memset(vis,0,sizeof(vis));
			dfs(i,k/2);	
			int temp=n-cnt;
			ans=min(temp,ans);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
const int mod = 1e9 + 7;
const int gakki = 5 + 2 + 1 + 19880611 + 1e9;
const int N = 3e5 + 5;
int preE[N];
int preW[N];
string f;
int main()
{
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        int n;
        cin >> n;
        cin >> f;
        preE[0] = preW[0] = 0;
        for (int i = 1; i <= n; i++)
        {
                if (f[i - 1] == 'W')
                {
                        preW[i] = preW[i - 1] + 1;
                        preE[i] = preE[i - 1];
                }
                else
                {
                        preE[i] = preE[i - 1] + 1;
                        preW[i] = preW[i - 1];
                }
        }
        ll anser = INT_MAX;
        ll now;
        for (int i = 1; i <= n; i++)
        {
                now = preW[i - 1] - preW[0];
                now += preE[n] - preE[i];
                anser = min(anser, now);
        }
        cout << anser << endl;
        return 0;
}


Measured memory_bytes: 2964
import java.util.*;

public class Main {
    class Node {
        int key;
        Node left = null, right = null, parent = null;
        Node(int key) {
            this.key = key;
        }
    }

    Node tree;

    boolean needPrefix = true;
    void inorder(Node t) {
        needPrefix = false;
        inorder_(t);
    }
    void inorder_(Node t) {
        if (t == null) {
            return;
        }
        if (t.left != null) {
            inorder_(t.left);
        }
        if (needPrefix) {
            System.out.print(" ");
        }
        System.out.print(t.key);
        needPrefix = true;
        if (t.right != null) {
            inorder_(t.right);
        }
    }

void preorder(Node t) {
        needPrefix = false;
        preorder_(t);
    }
    void preorder_(Node t) {
        if (t == null) {
            return;
        }
        if (needPrefix) {
            System.out.print(" ");
        }
        System.out.print(t.key);
        needPrefix = true;
        if (t.left != null) {
            preorder_(t.left);
        }
        if (t.right != null) {
            preorder_(t.right);
        }
    }


    void insert(Node z) {
       Node y = null;
       Node x = tree;
       while (x != null) {
           y = x;
           if (z.key < x.key) {
               x = x.left;
           } else {
               x = x.right;
           }
       }
       z.parent = y;
       if (y == null) {
           this.tree = z;
       } else if (z.key < y.key) {
           y.left = z;
       } else {
           y.right = z;
       }
    }

void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String inst = sc.next();
            if ("insert".equals(inst)) {
                insert(new Node(sc.nextInt()));
            } else {
                inorder_(tree);
                System.out.println();
                preorder_(tree);
                System.out.println();
            }
        }
    }
    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 256408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////

string ca(string s){
    if(s=="")return s;
    if(s.size()==1)return s;
    bool b=false;
    rep(i,0,s.size()-2){
        if(s.size()<=1){
            return s;
        }
        if(s[i]=='(' && s[i+1]==')'){
            s.erase(i,2);
            i--;
            b=true;
        }
    }
    if(b){
        return ca(s);
    }else{
        return s;
    }
}


int main(){
    ll n;cin>>n;string s;cin>>s;
    string t=ca(s);
    //cout<<t<<endl;
    if(t.size()>0){
        rep(i,0,t.size()-1){
            if(t[i]==')'){
                s='('+s;
            }else{
                s=s+')';
            }
        }
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int w,h,m,f;
int p[11][10][51],mp[10][10];

void search(int x,int y,int o,int f3,int *g) {
      int i,j,k,x2,o2,f2,v=1,smp[10];	
	  for (i=0;i<2;i++) { v=-v; x2=x; o2=o; f2=f3; for (k=0;k<w;k++) smp[k]=g[k]; 
	  for (j=0;j<w;j++) {
		   if (smp[x2]>0) { o2+=smp[x2]; if (o2>m) o2=m;}
		   if (smp[x2]<0) { f2-=smp[x2]; if (f2>f) break;}
		   if (f2<p[y+1][x2][o2-1]) p[y+1][x2][o2-1]=f2;
		   smp[x2]=0;
		   x2+=v; o2--;
		   if (x2<0 || x2>=w || o2<1) break;
		   if (smp[x2]>0) { search(x2,y,o2,f2,smp); break;}   
		 }  
     }	
 }

int main() {
    int a,i,j,k,f2,o;
    while(cin >> w >> h && w!=0) {
		cin >> f >> m >> o;
		for (i=0;i<h;i++) for (j=0;j<w;j++) cin >> mp[i][j];
		for (k=0;k<h;k++) for (i=0;i<w;i++) for (j=0;j<=m;j++) p[k][i][j]=999999;
		for (i=0;i<w;i++) if (o>1 && mp[0][i]<f) p[0][i][o-1]=0;
		for (i=0;i<h-1;i++) {
			for (j=0;j<w;j++) {
				f2=999999;
				for (k=m;k>0;k--) if (p[i][j][k]<f2) { search(j,i,k,p[i][j][k],mp[i]); f2=p[i][j][k];}
			}
        }
        a=999999;
        for (i=0;i<w;i++) for (j=1;j<=m;j++) {
			if (mp[h-1][i]>0 && a>p[h-1][i][j]) a=p[h-1][i][j]; 
			if (mp[h-1][i]<0 && a>p[h-1][i][j]-mp[h-1][i]) a=p[h-1][i][j]-mp[h-1][i];
		}
        if (a>f) cout << "NA" << endl; else cout << a << endl;
      }
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int k,n; cin>>k>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	
	int d=k-a[n-1]+a[0];
	for(int i=0;i<n-1;i++) a[i]=a[i+1]-a[i];
	a[n-1]=d;
	
	sort(a,a+n);
	long long sum=0;
	for(int i=0;i<n-1;i++) sum+=a[i];
	
	cout<<sum;
}

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

using namespace std;

const int INF = 1e9;

int n, a[55], dp[55][50005], sum[55];

int main(){
	scanf("%d", &n);
	
	for(int i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		sum[i] = sum[i - 1] + a[i];
	}
	
	for(int i = 1; i <= 50000; i++)
	dp[0][i] = i + 1;
	
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= 50000; j++){
			dp[i][j] = -INF;
			
			for(int k = 0; k < i; k++){
				if(i == n && k == 0) continue;
				
				int v = sum[i] - sum[k];
				if(v <= j)
				dp[i][j] = max(dp[i][j], min(v, dp[k][j]));
			}
		}
	}
	
	int res = INF;
	
	for(int i = 1; i <= 50000; i++)
	res = min(res, i - dp[n][i]);
	
	printf("%d\n", res);
}



Measured memory_bytes: 13196
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    int n;
    scanf("%d",&n);
    char s[n][55],cmp[27]="abcdefghijklmnopqrstuvwxyz";
    int count[n][27];
    for (int i=0; i<n; i++){
        scanf("%s",s[i]);
    }
    
    for (int i=0; i<n; i++){
        for (int k=0; k<27; k++){
            count[i][k]=0;
        }
    }
    
    for (int i=0; i<n; i++){
        for (int j=0; j<strlen(s[i]); j++){
            for (int k=0; k<27; k++){
                if(s[i][j]==cmp[k]){
                    count[i][k]++;
                }
            }
        }
    }
    
    int ans[27],tmp=55;
    for (int i=0; i<27; i++){
        ans[i]=0;
        for (int j=0; j<n; j++){
            if (tmp>count[j][i]){  
                tmp=count[j][i];
            }
        }
        ans[i]=tmp;
        tmp=55;
    }
    
    for (int i=0; i<27; i++){
        while (ans[i]>0){
            printf("%c",cmp[i]);
            ans[i]--;
        }
    }
    printf("\n");
	return 0 ;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r;
  cin >> r;
  int a,b,c,d;
  a=r/1000; b=(r-a*1000)/100; c=(r-a*1000-b*100)/10; d=r%10;
  int s=a+b+c+d;
  int t=a-b-c-d;
  if(s==7){cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl; return 0;}
  if(s-2*b==7){cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl; return 0;}
  if(s-2*c==7){cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl; return 0;}
  if(s-2*d==7){cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl; return 0;}
  if(t==7){cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl; return 0;}
  if(t+2*b==7){cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl; return 0;}
  if(t+2*c==7){cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl; return 0;}
  if(t+2*d==7){cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl; return 0;}
}

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

int n;

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

	cin >> n;

	cout << (1000 - (n % 1000)) % 1000 << '\n';

	return 0;
}

Measured memory_bytes: 3632
N = int(input())
X = int(N/1.08)
flag=0
while True:   
    if int(X*1.08)==N:
        flag=1
        break
    elif int(X*1.08)>N:
        break
    X += 1
if flag==1:
    print(X)
else:
    print(":(")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n;cin >> n;
  vector<long long> a(n),b(n);
  for (int i=0;i<n;i++) {
    cin >> a[i] >> b[i];
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  if (n%2==1) {
    long long x=(n-1)/2;
	cout << b[x]-a[x]+1 << endl;
  }
  else {
    long long x=(n/2)-1;
	cout << (b[x]+b[x+1])-(a[x]+a[x+1])+1 << endl;
  }
}

Measured memory_bytes: 6372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
using namespace std;
const int maxn = 10005;
const int mod = 1e9 + 7;

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0);
    ll n, m;
    while (cin >> n >> m) {
        ll ans = 0;
        map<ll,ll>mp;
        vector<ll>pre;
        mp[0] = 1;
        ll sum = 0;
        pre.pb(0);
        f1(n) {
            ll x;
            cin >> x;
            x += m - 1;
            x %= m;
            sum += x;
            sum %= m;
            if (i >= m) {
                mp[pre[i-m]]--;
            }
            ans += mp[sum];
            mp[sum]++;
            pre.pb(sum);
        }
        cout << ans << '\n';
    }
}

Measured memory_bytes: 14320
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <list>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
  int N;
  vector<int> L;
  cin >> N;
  for(int i = 0; i < N; i++) {
    int l;
    cin >> l;
    L.push_back(l);
  }
  
  sort(L.begin(), L.end());
  
  int cnt = 0;
  vector<int> two_sum;
  two_sum.push_back(L[0]+L[1]);
  for(int i = 2; i < N; i++) {
     for(auto ts: two_sum) {
       if(ts > L[i]) {
         cnt++;
       }
     }
     for(int j = 0; j < i; j++) {
       two_sum.push_back(L[j] + L[i]); 
     }
  }
  
  cout << cnt;
  
  return 0;
}


Measured memory_bytes: 10488
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<25;
const double pi=acos(-1);
const double eps=1e-8;
const vi emp;

vvc field(8,vc(8));

int main(){
	for(int i=0;i<8;i++) for(int j=0;j<8;j++) cin>>field[i][j];
	cout<<90<<endl;
	for(int i=0;i<8;i++){
		for(int j=7;j>=0;j--) cout<<field[j][i];
		cout<<endl;
	}
	cout<<180<<endl;
	for(int i=7;i>=0;i--){
		for(int j=7;j>=0;j--) cout<<field[i][j];
		cout<<endl;
	}
	cout<<270<<endl;
	for(int i=7;i>=0;i--){
		for(int j=0;j<8;j++) cout<<field[j][i];
		cout<<endl;
	}
}

Measured memory_bytes: 1196
def main():
    S=input()
    T=[]
    X=[]
    T_append=T.append
    X_append=X.append
    for i in range(0,len(S)):
        if S[i] in ['A','G','C','T']:
            T_append(1)
        else:
            T_append(0)
    for i in range(0,len(S)):
        if T[i]==0:
            X_append(i)
    m=0
    if X==[]:
        print(len(S))
    else:
        m=max(X[0],len(S)-X[len(X)-1]-1)
        if len(X)==1:
            print(m)
        else:
            for i in range(0,len(X)-1):
                x=X[i+1]-X[i]-1
                if x>m:
                    m=x
            print(m)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import itertools
n = int(input())
xy = [list(map(int , input().split())) for _ in range(n)]

m = 1
for i in range(1, n+1):
    m *= i
total = 0
for p in itertools.permutations(list(range(n)), n):
    for i in range(1, n):
        total += ((xy[p[i]][0] - xy[p[i-1]][0]) ** 2 + (xy[p[i-1]][1] - xy[p[i]][1]) ** 2) ** 0.5
print(total / m)


Measured memory_bytes: 40684