akhauriyash/Code-Regression huggingface dataset:
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:i64));
    if n % 2 == 0 { n } else { n * 2 }.to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "3" => "6",
    test2: "10" => "10",
    test3: "999999999" => "1999999998",
}


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

int a,b;

int gcd(int x,int y)
{
	if(y==0) return x;
	return gcd(y,x%y);
}

int main()
{
	scanf("%d %d",&a,&b);
	printf("%lld",1ll*a*b/gcd(a,b));
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<string.h>
#include<algorithm>
using namespace std;

typedef double Weight;
const int INF = 1e9;

//UnionFind
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x,int y) {
    x = root(x);
    y = root(y);
    if(x != y) {
      if(data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
      return x != y;
  }
  bool findSet(int x,int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

struct Edge {
  int src,dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator<(const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

//UnionFindðg¤
//Å¬SæØ(Kruskal) verifyÏÝ
Weight minimumSpannnigTree(Graph graph) {
  int n = graph.size();
  UnionFind uf(n);
  Weight total = 0.0;
  priority_queue<Edge> q;
  for(Graph::iterator it = graph.begin(); it != graph.end(); ++it)
    for(Edges::iterator j = (*it).begin(); j != (*it).end(); ++j)
      q.push(*j);

  while(!q.empty()) {
    Edge e = q.top();
    q.pop();
    if(uf.unionSet(e.src, e.dst))
      total += e.weight;
  }
  return total;
}

struct Part{
  double x,y,z,r;
  Part(double x,double y,double z,double r) : x(x), y(y), z(z), r(r) { }
};

double dist(Part a,Part b) {
  double d = sqrt((a.x-b.x)*(a.x-b.x)
		  + (a.y-b.y)*(a.y-b.y)
		  + (a.z-b.z)*(a.z-b.z));
  return max(0.0, d-a.r-b.r);
}

int main() {
  int n;
  double x,y,z,r;
  while(cin>>n, n) {
    Graph g(n);
    vector<Part> p;
    for(int i=0; i<n; ++i) {
      cin>>x>>y>>z>>r;
      p.push_back( Part(x,y,z,r) );
    }
    for(int i=0; i<n; ++i) {
      for(int j=0; j<n; ++j) {
	if(i == j) continue;
	g[i].push_back(Edge(i,j,dist(p[i],p[j])));
      }
    }
    printf("%.3f\n", minimumSpannnigTree(g));
  }
  return 0;
}

Measured memory_bytes: 1756
a, b, c, x, y = map(int, input().split())
ans = 0
min_ = min(x, y)
res = abs(x-y)
if a+b < 2*c:
    ans += min_*(a+b)
else:
    ans += min_*2*c
if x>y and res*a < res*2*c:
    ans += res*a
elif x<y and res*b < res*2*c:
    ans += res*b
else:
    ans += res*2*c
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
	int a,b,c,d,e,f,g;
	scanf("%d %d",&a,&b);
	if (a==0)
	{
		if (1868<=b&&b<=1911)
		{
			c=b-1867;
			printf("M%d\n",c);
		}
		else if (1912<=b&&b<=1925)
		{
			c=b-1911;
			printf("T%d\n",c);
		}
		else if (1926<=b&&b<=1988)
		{
			c=b-1925;
			printf("S%d\n",c);
		}
		else if (1989<=b&&b<=2016)
		{
			c=b-1988;
			printf("H%d\n",c);
		}
	}
	if (a==1)
	{
		c=1867+b;
		printf("%d\n",c);
	}
	if (a==2)
	{
		c=1911+b;
		printf("%d\n",c);
	}
	if (a==3)
	{
		c=1925+b;
		printf("%d\n",c);
	}
	if (a==4)
	{
		c=1988+b;
		printf("%d\n",c);
	}
	return 0;
}

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

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef long int li;

int main()
{
    IOS;
    //freopen("fr1.txt","r",stdin);
    int n;
    cin>>n;
    string s;
    cin>>s;
    bool ok=true;
    if(n%2!=0)
        ok=false;
    for(int i=0;i<n/2;i++){
        if(s[i]!=s[n/2+i])
            ok=false;
    }
    if(ok)
        cout<<"Yes"<<endl;
    else 
        cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int L,R;
    cin>>L>>R;
    int ans=99999999;
    if(R-L>=2018)ans=0;
    L%=2019;R%=2019;
    if(L>=R){
        ans=0;
    }else{
        for(int i=L;i<R;i++){
            for(int j=i+1;j<=R;j++){
                ans=min(ans,(i*j)%2019);
            }
        }
    }
    cout<<ans<<endl;
}


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

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += s[i] != t[i];
    }
    cout << ans << endl;
}


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

int H, W, black, white, d[400][400];
char s[400][400];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

void dfs(int x, int y){
	d[x][y] = 1;
	if(s[x][y] == '#'){
		black++;
	}else{
		white++;
	}
	for(int i=0; i<4; i++){
		int nx = x + dx[i], ny = y + dy[i];
		if(0<=nx && nx<H && 0<=ny && ny<W && s[nx][ny] != s[x][y] && d[nx][ny] != 1){
			dfs(nx, ny);
		}
	}
}

int main(){
	long long ans = 0;
	cin >> H >> W;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			cin >> s[i][j];
		}
	}
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			black = 0, white = 0;
			if(!d[i][j]){
				dfs(i, j);
			}
			ans += (long long)black*white;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main()
{
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
	string s, t;
	cin >> s >> t;
	int ans = 0;

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

  return 0;
}


Measured memory_bytes: 3836
from collections import defaultdict
n=int(input())
dic=defaultdict(int)
for _ in range(n):
    s = input()
    dic[s]+=1
L=list(dic.items())
L.sort(key=lambda x:x[0])
c=L[0][1]
for a,b in L:
    c=max(c,b)
for a,b in L:
    if b == c:
        print(a)

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

int main(){
	int n, m;
	cin >> n >> m;
	int ans = 0;
	for(int i=0 ; i < n ; i++ ){
		int s = 0;
		for(int j=0 ; j < m ; j++ ){
			int a;
			cin >> a;
			s += a;
		}
		ans = max( ans , s );
	}
	cout << ans << endl;
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>

using namespace std;

int main() {
  int n, m, d;
  scanf("%d%d%d", &n, &m, &d);
  double e;
  if (d == 0) {
    e = 1.0 / n * (m - 1);
  } else {
    e = (n - d) * 2.0 / n / n * (m - 1);
  }
  printf("%.10f\n", e);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <utility>
using namespace std;

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

    sort(a.begin(), a.end(), greater<int>());
    int alice = 0;
    int bob = 0;

    for(int i = 0; i < n; i+=2) alice += a[i];
    for(int i = 1; i < n; i+=2) bob += a[i];

    cout << alice - bob << endl;

    return EXIT_SUCCESS;
}


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

int num[100010],n;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	n=rd();
	for (int i=1;i<=n;i++) num[i]=rd();
	int mn=n+1,mx=0;
	for (int i=1;i<=n;i++) mn=min(mn,num[i]),mx=max(mx,num[i]);
	if (mx-mn>1) { puts("No");return 0; }
	if (mn==mx)
	{
		int h1=1,h2=n/2;
		if ((mn>=h1&&mn<=h2)||mn==n-1) puts("Yes");
		else puts("No");
	}
	else
	{
		int sum=0;
		for (int i=1;i<=n;i++) if (num[i]==mx) sum++;
		int h1=1,h2=sum/2;
		if (mx>=h1+n-sum&&mx<=h2+n-sum) puts("Yes");
		else puts("No");
	}
	return 0;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N;
	cin >> N;
	map<char, ll> m;
	rep(i, 0, N) {
		string s;
		cin >> s;
		m[s[0]]++;
	}

	char c[] = {'M', 'A', 'R', 'C', 'H'};

	ll rsl = 0;

	rep(i, 0, 5) rep(j, i + 1, 5) rep(k, j + 1, 5) {
		ll tmp = m[c[i]] * m[c[j]] * m[c[k]];
		rsl += tmp;
	}

	cout << rsl << endl;

}


Measured memory_bytes: 256
// abc174_e
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int N, K;
vector<int> A;

bool check(double x){

    ll k = 0;
    REP(i, N){
        k += ll(A[i] / x);

        if (floor(x)==x){
            int x_ = int(x);
            if (A[i] % x_ == 0){
                k--;
            }
        }
    }
    return k <= K;
}

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    cin >> N >> K;
    A.assign(N, 0);
    REP(i, N) cin >> A[i];

    if (K == 0){
        int ans = *max_element(ALL(A));
        print(ans);
        return 0;
    }

    double ng = 0;
    double ok = 1e9+1;
    while (ok - ng > 1e-6){

        double mid = (ok + ng) / 2;

        if (check(mid)){
            ok = mid;
        } else {
            ng = mid;
        }

    }
    int ans = ceil(ok);
    if (ok - (ans-1) < 1e-6) ans--;
    print(ans);


    return 0;
}


Measured memory_bytes: 3988
from collections import defaultdict
N,Q = map(int,input().split())
d = defaultdict(list)

for _ in range(N-1):
    a,b = map(int,input().split())
    d[a].append(b)
    d[b].append(a)

c = defaultdict(int)

for _ in range(Q):
    p,x = map(int,input().split())
    c[p] += x

ans = [0 for i in range(N)]
que = [(1,0,-1)]
while len(que)>0:
    tmp = []
    for v,x,par in que:
        x += c[v]
        ans[v-1] = str(x)
        for w in d[v]:
            if w != par:
                tmp.append((w,x,v))
    que = tmp

print(*ans)


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

int n, nlb, nra, nab, nlr;
string s;

int main(){
	cin >> n;
	nlb = nra = nab = nlr = 0;
	for (int i = 0; i < n; ++i){
		cin >> s;
		if (s[s.size()-1] == 'A'){
			if (s[0] == 'B') nlr++;
			else nra++;
		}
		else if (s[0] == 'B') nlb++;
		for (size_t i = 0; i < s.size()-1; ++i){
			if (s.substr(i, 2) == "AB") nab++;
		}
	}
	if (nlr > 0){
		if (nlb > 0){nlb--; nab++;}
		if (nra > 0){nra--; nab++;}
		cout << (nab + nlr - 1 + min(nlb, nra));
	}
	else{
		cout << (nab + min(nlb, nra));
	}
}

Measured memory_bytes: 256
/*
*          Name : chaitanya
*
*     Institute : ANITS,Visakhapatnam
*
*/
#include<cstdio>
#include<iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include<cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define infy  1000000000
#define all(x) begin(x),end(x)
#define ll long long int
#define ff first
#define ss second
#define pb push_back
const ll mod = 1000000007;
#pragma GCC optimization ("O3")
const int N = 1000010;
using namespace std;
vector<string> vec_splitter(string s) {
  s += ',';
  vector<string> res;
  while(!s.empty()) {
    res.push_back(s.substr(0, s.find(',')));
    s = s.substr(s.find(',') + 1);
  }
  return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
  if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
  stringstream ss; ss << H;
  cerr << args[idx] << " = " << ss.str();
  debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
ll lcm(ll a,ll b)
{
  return (a*b)/__gcd(a,b);
}
int main()
{
  // int x = -1, y = 10000;
  // double z = 0.2;
  // string s2 = "beginner1010";
  // long long b = 1LL << 60;
    
  // // debug(x, y, z, s, b);
    
  // double aux = 1010.0;
  // string code = "code";
    
  // debug(code + "forces",-aux / 10 * 2.3);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  ll n,a,m;
  cin >> n >> a;
  for (ll i = 1; i <= a; ++i)
  {
    cin >> m;
    n -= m;
  }
  if (n <= 0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


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

int main() {
	int a;
	int b[9];
	while (cin >> a&&a != 0) {
		for (int i = 0; i < 9; i++) {
			cin >> b[i];
		}
		for (int i = 0; i < 9; i++) {
			a -= b[i];
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 2968
S = input()

result1 = 0
result2 = 0

for i, c in enumerate(S):
    if i % 2 == 0:
        if c == '0':
            result1 += 1
        else:
            result2 += 1
    else:
        if c == '0':
            result2 += 1
        else:
            result1 += 1

#print(result1, result2)
result = min(result1, result2)
print(result)


Measured memory_bytes: 3188
n = int(input())
h = list(map(int,input().split()))
h.append(10**10)
maxc = 0
cnt = 0
for i in range(n):
    if h[i]>=h[i+1]:
        cnt +=1
    else:
        maxc = max(maxc,cnt)
        cnt = 0
print(maxc)

Measured memory_bytes: 15020
isInRange :: Ord a => a -> a -> a -> Bool
isInRange x y z = x <= y && y <= z

main :: IO ()
main = do input <- getLine
          let w : h : x : y : r : _ = map read $ words input :: [Int]
          putStrLn $ if isInRange r x (w-r) && isInRange r y (h-r) then "Yes" else "No"

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int h, n;
    scanf("%d%d", &h, &n);
    int a[n], sum=0;
    rep(i, n){
        scanf("%d", &a[i]);
        sum+=a[i];
    }
    puts(h<=sum ? "Yes": "No");
}

Measured memory_bytes: 640
n,m,l =map(int,input().split())
a =[]
b=[]

for i in range(n):
    a.append(list(map(int,input().split())))
for j in range(m):
    b.append(list(map(int,input().split())))
    
for i in range(n):
    li=[]
    for j in range(l):
        su =0
        for k in range(m):
             su += a[i][k] * b[k][j]
        li.append(su)
    print(" ".join(list(map(str,li))))


Measured memory_bytes: 6244
// https://atcoder.jp/contests/abc175/tasks/abc175_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> L(N);
    for (auto &x : L) {
        cin >> x;
    }
    // sort(ALL(L));
    int ans = 0;
    REP(i, N) {
        FOR(j, i + 1, N) {
            FOR(k, j + 1, N) {
                vector<int> t;
                t.emplace_back(L[i]);
                t.emplace_back(L[j]);
                t.emplace_back(L[k]);
                sort(ALL(t));
                if (t[0] != t[1] && t[1] != t[2] && t[2] != t[0] &&
                    t[0] + t[1] > t[2]) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
N = int(input())
A = list(map(int, input().split()))
mi, ma = min(A), max(A)
print(2*N)
if abs(mi)<=ma:
    k = A.index(ma)
    print(k+1,1)
    print(k+1,1)
    for i in range(N-1):
        print(i+1,i+2)
        print(i+1,i+2)
else:
    k = A.index(mi)
    print(k+1,N)
    print(k+1,N)
    for i in reversed(range(N-1)):
        print(i+2,i+1)
        print(i+2,i+1)

Measured memory_bytes: 62488
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>> n;
  set<int> d;
  for(int i=0; i<n; i++){
    int tmp;
    cin>>tmp;
    d.insert(tmp);
  }
  cout << d.size() << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i, n, x, y, z;
	x = y = z = 1;
	
	scanf("%d", &n);
	
	for(i = 0; i < n - 1; i++){
		z = x + y;
		y = x;
		x = z;
	}
	
	printf("%d\n", z);

	return 0;
}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a;
    cin>>a;
    string b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();++i)
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 512
n=int(input())
A=list(map(int,input().split()))
for i in range(n):
  if A[i]>i+1:
    print(-1)
    exit()
    
ANS=[]
for _ in range(n):
  for i in range(1,n+1):
    if A[-i]==n-i+1:
      ANS.append(A[-i])
      del A[-i]
      n-=1
      break
    

for i in ANS[::-1]:
  print(i)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
using namespace std;
 
int main() {
  int n,k;
  int goukei = 0;
  cin >> n >> k;
  vector<int> p(n);

  for(int i = 0; i < n; i++) cin >> p[i];

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

  for(int i = 0; i < k; i++){
    goukei += p[i];
    }
 
  cout << goukei << endl;

}

Measured memory_bytes: 3624
//----------------------Shanu Garg here---------------------
//-------------Search on youtube : Shanu Garg---------------
//-Studying at National Institute of Technology Delhi(NITD)-
//---------------------From Delhi, India--------------------

#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define f(i,n) for(auto i=0;i<n;i++)
#define fr(i,n) for(auto i=n-1;i>=0;i--)
#define fs(i,a,b,c) for(auto i=a;i!=b;i+=c)
#define fl(i,x) for(auto i : x)
#define nl cout<<"\n";
#define chk(x) cout<<#x<<" : "<<x, nl
#define ll long long int
#define vi vector<int>
#define vvi vector<vi>
#define pr pair<ll, ll>
#define vii vector<pair<int, int>>
#define vll vector<pr>
#define vl vector<ll>
#define m(a,b) map<a, b>
#define ci m(char, ll)
#define ii m(ll, ll)
#define mid(a,b) ((a+b)/2)
#define pb push_back
#define LCM(a,b) ((a*b)/__gcd(a, b))
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;

class triplet{ll f, s, t;};

vl in(ll n){vl v;ll x;
    f(i,n)
    cin>>x, v.pb(x%mod);
    return v;}
void out(vl v){fl(i,v)cout<<i;}
void out(vl v, char ch){
    fl(i,v)
    cout<<i<<ch;}

void solve(){
    ll A,B;
    cin>>A>>B;
    cout<<LCM(A, B);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
   return 0;
}

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

using ll = long long;

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

	if (k % 2 == 0) {
		cout << a - b << endl;
	}
	else {
		cout << b - a << endl;
	}



	return 0;
}

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

long long MAX = 1e18;
int main(void)
{
    int n; cin >> n;
    long long prod = 1;
    long long a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (prod  != 0)
        {
            if (a <= MAX / prod || a == 0) prod *= a;
            else prod = -1;
        }
    }
    cout << prod << endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

struct Point {
    ll x, y;
};

using P = pair<ll, ll>;

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}

    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

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

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int N;
    cin >> N;
    vector<Point> p(N);
    rep(i, N) cin >> p[i].x >> p[i].y;

    set<P> dist;
    rep(i, N) {
        for (int j = i + 1; j < N; j++) {
            int dx = p[i].x - p[j].x;
            int dy = p[i].y - p[j].y;
            if (dx != 0 || dy != 0) dist.insert(P{dx, dy});
        }
    }

    int ans = N;
    for (auto d: dist) {
        UnionFind uf(N);
        rep(i, N) rep(j, N) if (p[j].x + d.first == p[i].x && p[j].y + d.second == p[i].y) uf.merge(i, j);
        int now = 0;
        rep(i, N) if (uf.root(i) == i) now++;
        chmin(ans, now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;


int main () {

  string S;
  cin >> S;

  ll len = S.length();

  REP(i, 0, len) {
    cout << 'x';
  }
  cout << endl;

  return 0;
}


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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

vector<int> g[2000];
int re[2000];
vector<int> ds;
int main() {
  int n, x, y;
  cin >> n >> x >> y;
  repi(n - 1) {
    g[i].push_back(i + 1);
    g[i + 1].push_back(i);
  }
  g[x - 1].push_back(y - 1);
  g[y - 1].push_back(x - 1);
  repi(n) {
    ds = vector<int>(n, -1);
    ds[i] = 0;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      auto p = q.front();
      q.pop();
      itr(g[p]) {
        if (ds[v] >= 0) continue;
        ds[v] = ds[p] + 1;
        q.push(v);
      }
    }
    repj(n)++ re[ds[j]];
  }
  rep(i, 1, n) cout << re[i] / 2 << endl;
}


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

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

const int MAX = 200100;
LL fact[MAX];
LL powm(LL x, LL y){
  if(y == 0) return 1;
  return powm(x*x%MOD, y/2) * (y%2==1?x:1) % MOD;
}
LL inv(LL x){
  return powm(x,MOD-2);
}
LL C(int x, int y){
  return fact[x] * inv(fact[x-y]) % MOD * inv(fact[y]) % MOD;
}

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

  fact[0] = 1;
  REP(i,MAX) fact[i+1] = fact[i] * (i+1) % MOD;
  
  LL H, W, A, B; cin >> H >> W >> A >> B;
  LL ans = 0;
  vector<LL> acc(H-A);
  REP(y,H-A){
	acc[y] = C(y+B-1, B-1);
  }

  REP(y,H-A){
	(ans += acc[y] * C(H-1-y+W-B-1, W-B-1) % MOD) %= MOD;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
string s;
int ans, t;
int main(){
    cin >> s;
    for(auto it : s){
        if(it == 'A' || it == 'T' || it == 'G' || it == 'C') t++;
        else t = 0;
        ans = max(ans, t);
    }
    cout << ans << endl;
}

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


int main(){
  vector<int> a(3);
  
  rep(i,3) cin >> a[i];
  sort(a.begin(),a.end());
  
  if (a[0] = 5 && a[1] == 5 && a[2] == 7) cout << "YES" << endl;
  else cout << "NO" << endl;

}

Measured memory_bytes: 256
import math
H, W = map(int, input().split())

ceil_H = math.ceil(H / 2)
floor_H = math.floor(H / 2)

ceil_W = math.ceil(W / 2)
floor_W = math.floor(W / 2)

if H == 1 or W == 1:
  print(1)
else:
  print(ceil_H * ceil_W + floor_H * floor_W)

Measured memory_bytes: 3060
#include <stdio.h>
typedef long long ll;
ll GCD(ll a, ll b) {
    return (b == 0) ? a : GCD(b, a % b);
}

ll LCM(ll a, ll b) {
    ll g = GCD(a,b);
    return (a/g) * b;
}
int main() {
    int N;
    scanf("%d", &N);
    ll res = 1, t;
    for (int i = 0; i < N; ++i) {
        scanf("%lld", &t);
        res = LCM(res, t);
    }
    printf("%lld", res);
    return 0;
}



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

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

    int ans = 800 * n - (n / 15) * 200;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,n,b,f,r,v,count[4][3][10];
  scanf("%d",&n);
  for(b = 0;b < 4;b++){
    for(f = 0;f < 3;f++){
      for(r = 0;r < 10;r++){
        count[b][f][r] = 0;
      }
    }
  }
  for(i = 0;i < n;i++){
    scanf("%d%d%d%d",&b,&f,&r,&v);
    count[b-1][f-1][r-1] += v;
  }
  for(b = 0;b < 4;b++){
    for(f = 0;f < 3;f++){
      for(r = 0;r < 10;r++){
        printf(" %d",count[b][f][r]);
      }
    printf("\n");
    }
    if(b == 3){
      break;
    }
    printf("####################\n");
}
return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "first" : "second")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int n;
	int ans = 0;
	cin >> n;
	V a(n);
	rep(i, n) {
		cin >> a[i];
		ans += (a[i] % 2);
	}
	cout << solve(ans != 0) << endl;
}
/*
lose: get 1 or 0 (win)
win: get 2n
*/

Measured memory_bytes: 3996
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() { 
  int a,b;cin >> a >> b;
  int ans;
  repd(i,1,b-a){
    ans += i;
  }
  cout << ans-a << endl;
}


Measured memory_bytes: 256
n,x=map(int,input().split())
a=list(map(int,input().split()))
s=[0]*(n-1)
ans=0
if a[0]>x:
    ans+=a[0]-x
    a[0]=x
for i in range(n-1):
    s[i]=a[i]+a[i+1]
for i in range(n-2):
    if s[i]>x:
        t=s[i]-x
        s[i+1]-=t
        s[i]=x
        ans+=t
if s[n-2]>x:
    ans+=s[n-2]-x
print(ans)

Measured memory_bytes: 20048
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7


n = int(readline())

ans = (pow(10, n, mod) - 2*pow(9, n, mod) + pow(8, n, mod))%mod

print(ans)


Measured memory_bytes: 9428
import java.util.*;

public class Main{
  public static void main(String[] args){
    StringBuilder sb = new StringBuilder();
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    int[] digit = new int[4];
    char[] c = new char[4];
    int s_idx = 0;
    int c_idx = 3;

    for(int i = 0; i < 4; i++){
      char tmp = s.charAt(s_idx);
      c[c_idx] = tmp;
      s_idx++;
      c_idx--;
    }

    for(int i = 3; i >= 0; i--){
      digit[i] = c[i] - '0';
    }



    outline:for(int j = 0; j < (int)Math.pow(2, 3); j++){
      sb.append(digit[3]);
      int sum = digit[3];
      for(int k = 2; k >= 0; k--){
        if((1 & (j >> k)) == 1){
          sb.append('-');
          sb.append(digit[k]);
          sum -= digit[k];
        }else{
          sb.append('+');
          sb.append(digit[k]);
          sum += digit[k];
        }
      }
      if(sum == 7){
        System.out.println(sb + "=7");
        break outline;
      }
      sb.setLength(0);
    }
  }
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll memo[1000005];

ll rec(ll v){
  if(v==1) return 1;
  if(v<=1e6 && memo[v]>0) return memo[v];
  if(v<=1e6) return memo[v]=rec(v/2)+rec(v/2)+1;
  else return rec(v/2)+rec(v/2)+1;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h; cin>>h;
  cout<<rec(h)<<endl;
}

Measured memory_bytes: 4352
N = int(input())
 
res = {i+1: 0 for i in range(N)}
 
for i in range(1, int(N**0.5)):
  for j in range(1, int(N**0.5)):
    for k in range(1, int(N**0.5)):
      n = i**2 + j**2 + k**2 + i*j + j*k + k*i
      if n in res:
        res[n] += 1
for r in res.values():
  print(r)


Measured memory_bytes: 9972
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, A, B = mapint()
Vs = list(mapint())
Vs.sort(reverse=True)
from collections import defaultdict, Counter
from math import factorial, gcd

count = defaultdict(int)
c = Counter(Vs)
ans = 0
ans_2 = (0, 0)
for i in range(A, B+1):
    val = sum(Vs[:i])
    if val/i>=ans-0.000000000000001:
        ans = val/i
        lowest_cnt = 0
        lowest = Vs[i-1]
        for j in range(i):
            if Vs[j]==lowest:
                lowest_cnt += 1
        val, i = val//gcd(val, i), i//gcd(val, i)
        count[(val, i)] += factorial(c[lowest])/factorial(lowest_cnt)/factorial(c[lowest]-lowest_cnt)
        ans_2 = (val, i)

print(ans)
print(round(count[ans_2]))

Measured memory_bytes: 83612
import sys
from itertools import permutations
readline = sys.stdin.readline

def f(i, j):
    return ((X[i] - X[j])**2 + (Y[i] - Y[j])**2)**0.5



N = int(readline())
jj = [1]*(N+1)
for i in range(1, N+1):
    jj[i] = jj[i-1]*i

XY = [map(int, readline().split()) for _ in range(N)]
X, Y = map(list, zip(*XY))
sumi = 0

L = list(range(N))
for k in permutations(L):
    for i in range(N-1):
        sumi += f(k[i], k[i+1])

print(sumi/jj[N])


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

int N;
vector<int> R, W;

int solve(){
    vector<pair<int, int>> Rp(N);
    for(int i=0; i<N; i++)
        Rp.push_back({R[i], i});
    
    sort(Rp.rbegin(), Rp.rend());
    int Rs = 0;
    for(int i=1; i<N; i++)
        Rs += Rp[i].first;
    
    int Ws = 0;
    for(int i=0; i<N; i++)
        Ws += W[i];
    
    if(Rs >= Rp[0].first){
        return  Rs + Rp[0].first + Ws;
    }
    
    int rem = Rp[0].first - Rs;
    vector<bool> dp(rem + 1, false);
    dp[0] = true;
    
    for(int i=0; i<N; i++) if(i != Rp[0].second){
        int w = W[i];
        for(int j=rem; j>=0; j--){
            if(j - w < 0) break;
            dp[j] = dp[j] || dp[j-w];
        }
    }
    
    int add = -1;
    for(int i=rem; i>=0; i--) if(dp[i]){
        add = rem - i;
        break;
    }
    return Rs + Rp[0].first + Ws + add;
}

int main(){
    while(cin >> N, N){
        R.resize(N);
        W.resize(N);
        for(int i=0; i<N; i++)
            cin >> R[i] >> W[i];
        
        cout << solve() << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3184
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<int> ans;
    int prev_minid = 100, cnt = 0;
    while(1){
        int min_id = 100, mi = 1000;
        for(int i = 0; i < n; i++){
            if(i == prev_minid) continue;
            if(mi > a[i]){
                min_id = i;
                mi = a[i];
            }
        }
        if(mi <= 0) break;
        for(int i = 0; i < n; i++){
            if(i == min_id || i == prev_minid) continue;
            ans.push_back(i + 1);
            a[i]--;
        }
        ans.push_back(min_id + 1);
        a[min_id]--;
        prev_minid = min_id;
        cnt++;
    }
    if(cnt <= k){
        cout << -1 << endl;
    }else{
        cout << ans.size() << endl;
        cout << ans[0];
        for(int i = 1; i < ans.size(); i++){
            cout << " " << ans[i];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/ruby

MARU = 0
KAKU = 1

def check ln
  read = []
  ln.split("").each do |c|
    if c == '('
      read << MARU
    elsif c == '['
      read << KAKU
    elsif c == ')'
      last = read.pop
      return false if last != MARU
    elsif c == ']'
      last = read.pop
      return false if last != KAKU
    end
  end
  read.size == 0
end

loop do
  ln = gets.chomp
  break if ln == '.'
  res = if (check ln) then "yes" else "no" end
  puts res
end

Measured memory_bytes: 6108
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#include<math.h>
#include<string.h>
int main()
{
    ll a,b,c,d,test,i,j,k,l,m,o,p;
    cin>>a>>b;
    printf("%lld\n",6-(a+b));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >>n;
	for(int i=0;7*i<=n;i++)
	{
		if((n-7*i)%4==0)
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

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

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a, b, c;
    cin >> a >> b >> c;

    cout << min({a+b, a+c, b+c}) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)

int main(void)
{
	int a,b,i,c=0;
	scanf("%d %d",&a,&b);
/*	for(i=0;i<2;i++){
		if(a<b){
			c=c+b;
			b--;
		}else{
			c=c+a;
			a--;
		}
	}*/
	printf("%d",max(a+a-1,max(a+b,b+b-1)));
	return 0;
}

Measured memory_bytes: 128
# coding: utf-8
while 1:
    n=int(input())
    if n==0:
        break
    dic={}
    ok=[[False for i in range(30)] for i in range(n)]
    for i in range(n):
        dic[i]=[i]
        for m in list(map(int,input().split()))[1:]:
            ok[i][m-1]=True
    f=False
    for i in range(30):
        tmp=[]
        for j in range(n):
            if ok[j][i]:
                tmp+=list(dic[j])
        tmp=set(tmp)
        for j in range(n):
            if ok[j][i]:
                dic[j]=list(tmp)
                if len(dic[j])==n:
                    print(i+1)
                    f=True
                    break
        if f:
            break
    if not f:
        print(-1)
                


Measured memory_bytes: 5636
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int num;
    int tmp;
    cin >> num;
    array<long long,200010> ans={};
    for(int i=1;i<num;i++){
        cin >> tmp;
        ans[tmp] ++;
    }
    for(int i=1;i<=num;i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4756
let solve k ar =
  let flag = ref false in
  for i = 0 to 4 do
    for j = 0 to 4 do
      if abs (ar.(i) - ar.(j)) > k then flag := true
    done;
  done;
  if !flag then ":(" else "Yay!"

let _ =
  let ar = Array.make 5 0 in
  for i = 0 to 4 do
    Scanf.scanf "%d\n" (fun a -> ar.(i) <- a)
  done;
  let k = Scanf.scanf "%d\n" (fun k -> k) in
  solve k ar |> print_string


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		sc.close();
		
		if( N % 2 == 0) {
			System.out.println(N / 2);
		}else {
			System.out.println(N / 2 + 1);
		}
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323
inline ll add(ll a, ll b)   { a += b; if(a>=mod) a-=mod; return a; }
inline ll sub(ll a, ll b)   { a -= b; if(a<0) a+=mod; return a; }

const int N = 101, K = 1e5+5;
ll n, p, a[N], dp[N][K], pre[N][K];

void solve()
{
       cin>>n>>p;
       rep(i,1,n+1) cin>>a[i];
       rep(i,0,n+1) dp[i][0]=pre[i][0]=1;
       rep(j,0,p+1) pre[0][j]=1;          // 0-st row means not giving to any, total ways of this = 0
       rep(i, 1, n+1)
       {
              rep(j, 1, p+1)
              {
                     ll f = (j-a[i]-1 >= 0)?pre[i-1][j-a[i]-1]:0;
                     ll s = pre[i-1][j];
                     dp[i][j] = add(dp[i][j], sub(s,f));
                     pre[i][j] = add(pre[i][j-1],dp[i][j]);
              }
       }
       cout<<dp[n][p]<<endl;
}

int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 158080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<29;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;






int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string a,b,c; cin >> a >> b >> c;
    if(a.back()==b.front() && b.back()==c.front()) cout << "YES" << endl;
    else cout << "NO" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int		H, W;

	for (;;)
	{
		cin >> H >> W;

		if ((H == 0) && (W == 0))
			break;

		string		str("#");

		for (int i = 1; i < W; i++)
			str += "#";
		str += "\n";

		for (int i = 0; i < H; i++)
		{
			cout << str;
		}
		cout << "\n";
	}

	return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  int a,b,c,d; cin>>a>>b>>c>>d;
  int x=c-a;
  int y=d-b;
  printf("%d %d %d %d\n", c-y, d+x, a-y, b+x);
}

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


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

using namespace std;

int main()
{
  int n;
  cin>>n;
  int arr[n],count[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  count[0] = 0;
  count[1] = abs(arr[0]-arr[1]);
  for(int i=2;i<n;i++)
  {
    count[i] = min((abs(arr[i-1]-arr[i])+count[i-1]),(abs(arr[i-2]-arr[i])+count[i-2]));
  }
  cout<<count[n-1]<<endl;
}

Measured memory_bytes: 1024