akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#include <cstdlib>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

//tourist head

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pw(x) (1ll << (x))
////////////////////////////////////////////////////////////////////////

void read_input(){
	
}

void solve(){
	
}

int main(){
    int N,Y;
    cin>>N>>Y;
    for(int i=0;i<=N;i++){
    	for(int j=0;j<=N;j++){
    		int m = N-i-j;
    		if (m<0)
    			continue;
    		if (i*10000+j*5000+m*1000 == Y){
    			cout<<i<<" "<<j<<" "<<m<<endl;
    			return 0;
    		}
    	}
    }
    cout<<"-1 -1 -1"<<endl;
	return 0;
}


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

using namespace std;

int main() {
  int N;
  long long K;
  cin >> N >> K;
  vector<int> A(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  vector<int> visited(N + 1, -1);
  int a = 0;  // steps to reach to the beginning of the cycle
  int T = 0;  // cycle
  int p = 1;
  for (int i = 0; i <= N; i++) {
    if (visited[p] != -1) {
      T = i;
      break;
    }
    visited[p] = i;
    p = A[p];
  }
  a = visited[p];
  T -= a;
  p = 1;
  if (K <= a) {
    for (int i = 0; i < K; ++i) p = A[p];
  } else {
    for (int i = 0; i < a; ++i) p = A[p];
    K = (K - a) % T;
    for (int i = 0; i < K; ++i) p = A[p];
  }
  cout << p << endl;
  return 0;
}


Measured memory_bytes: 4840
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let c: i32 = read();
    println!("{}", if c < a || c > b { "No" } else { "Yes" })
}


Measured memory_bytes: 4352
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var sc = bufio.NewScanner(os.Stdin)

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()
	s := make([]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		s[i] = ri()
		sum += s[i]
	}

	if sum%10 != 0 {
		fmt.Println(sum)
		return
	}

	sort.Ints(s)

	for _, v := range s {
		if x := sum - v; x%10 != 0 {
			fmt.Println(x)
			return
		}
	}

	fmt.Println(0)
}


Measured memory_bytes: 640
#include <cstdint>
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int64_t v = 0;
    for (int i = 0; i < n; i++)
    {
        int64_t a;
        cin >> a;
        v += a;
    }
    v -= n;
    cout << v << endl;
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N;
    std::cin >> N;
    std::vector<int> A(N);
    REP(i, N) {
        std::cin >> A[i];
    }
    RSORT(A);

    priority_queue<int> pq;
    pq.push(A[1]);
    pq.push(A[1]);
    ll ans = A[0];
    for(int i = 2; i < N; i++) {
        auto top = pq.top();
        pq.pop();
        ans += top;
        pq.push(A[i]);
        pq.push(A[i]);
    }
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 5064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        int c = sc.nextInt();

        int sum = 0;
        for (int i = a; i <= b; i++) {
            if (c % i == 0)sum++;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 26336
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, S):
    # g = defaultdict(list)
    # for i, r in enumerate(S):
    #     for j, c in enumerate(r):
    #         if c == '.':
    #             if i > 0 and j > 0:
    #                 g[(i, j)].append((i-1, j-1))
    #     # g[u].append((v, (a, b)))
    #     # g[v].append((u, (a, b)))

    def d(s):
        dist = defaultdict(lambda : sys.maxsize)
        q =[]
        dist[s] = 0
        heapq.heappush(q, (dist[s], s))
        while q:
            c, u = heapq.heappop(q)
            if dist[u] > c:
                continue
            i, j = u
            g = []            
            if i > 0 and S[i-1][j] == '.':
                g.append((i-1, j))

            if j > 0 and S[i][j-1] == '.':
                g.append((i, j-1))

            if i < H-1 and S[i+1][j] == '.':
                g.append((i+1, j))

            if j < W-1 and S[i][j+1] == '.':
                g.append((i, j+1))
            
            for v in g:
                alt = dist[u] + 1
                if dist[v] > alt:
                    dist[v] = alt
                    heapq.heappush(q, (alt, v))
        return dist

    dist = d((0, 0))[(H-1, W-1)]
    if dist == sys.maxsize:
        return -1
    return (H * W - sum(map(lambda x: x.count('#'), reduce(add, S)))) - dist - 1


def main():
    H, W = read_int_n()
    S = [read_str() for _ in range(H)]

    
    print(slv(H, W, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7224
#include <iostream>

using namespace std;

int main() {
  int N;
  int A[100];
  
  cin >> N;
  for (int i=0; i<N; i++) cin >> A[i];
  
  int cnt = 0;
  for (int i=0; i<N; i++) {
    int minj = i;
    for (int j=i; j<N; j++) if (A[j] < A[minj]) minj = j;
    if (i != minj) {
        int tmp = A[i];
        A[i] = A[minj];
        A[minj] = tmp;
        cnt++;
      }
  }
  
  for (int k=0; k<N; k++) cout << (k != 0 ? " " : "") << A[k];
  cout << endl << cnt << endl;
  
  return 0;
}



Measured memory_bytes: 3044
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int l,r,d;
  cin >> l >> r >> d;
  int cnt = 0;
  REP2(i,l,r+1){
    if(i%d == 0) cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    double arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    double dp[n+1][n+1];
    dp[0][0]=1.0;
    for(int j=1;j<=n;j++)
        dp[0][j]=0;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=dp[i-1][0]*(1-arr[i-1]);
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            dp[i][j]=((dp[i-1][j]*(1-arr[i-1]))+(dp[i-1][j-1]*arr[i-1]));
        }
    }
    int temp=n/2;
    double ans=0.0;
    for(int i=temp+1;i<=n;i++)
    {
        ans+=dp[n][i];
    }
    cout<<fixed<<setprecision(15)<<ans<<endl;
}


Measured memory_bytes: 70528
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main(){

    int n;
    string s;
    cin >> n;
    cin >> s;
    if(n%2 == 0) {
        int l = s.size();
        bool flag = true;
        rep(i, l/2){
            if(s[i] != s[l/2+i]) flag = false;
        }

        if (flag){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  cout << (n >= 2 * k - 1 ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 2*asin(1)
#define int long long
#define mod 1000000007
#define all(a) begin(a),end(a)
#define fore(i, j, n) for(long long i = j; i < n;i++)
using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int a,b; cin >> a >> b;
    if(a <= 9 && b <= 9) cout << a*b;
    else cout << -1;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		int n = cin.nextInt();
		long k = cin.nextLong();
		int[][] abs = new int[n][];
		for (int i = 0; i < n; i++)
			abs[i] = new int[] { cin.nextInt(), cin.nextInt() };
		long ans = solve(n, k, abs);
		cout.println(ans);
	}

	private static long solve(int n, long k, int[][] abs) {
		Arrays.sort(abs, (ab1, ab2) -> Integer.compare(ab1[0], ab2[0]));
		for (int[] ab : abs) {
			k -= ab[1];
			if (k <= 0)
				return ab[0];
		}
		throw new IllegalArgumentException();
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


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

int main() {
  int N;
  cin >> N;
  
  int a, b, c, d;
  a = N % 10;
  b = N / 10 % 10;
  c = N / 100 % 10;
  d = N / 1000;
  //cout << a << b << c << d << endl;
  
  if (b == c) {
    if ((a == b) || (d == b)) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 256
def main():
    H, W = map(int, input().split(" "))
    # r1 + c1 = r2 + c2
    # r1 - c1 = r2 - c2
    c = H * W
    if H == 1 or W == 1:
        print('1')
        return

    if c % 2 == 0: # OK
        print(c // 2)
    else:
        print((c // 2) + 1)


# def main():
#     H, W = map(int, input().split(" "))
#     # r1 + c1 = r2 + c2
#     # r1 - c1 = r2 - c2

#     if H == 1 or W == 1:
#         print('1')

#     c = H * W
#     if c % 2 == 0:
#         print(c // w)
#     else:
#         MAX = max(H, W)
#         MIN = min(H, W)

#         out = MIN * (MIN - 1) + MAX % MIN
        


main()

Measured memory_bytes: 2940
#!/usr/bin/python3
# abc059_a

"""
Three-letter-acronym
"""

def main():
    """
    単語の先頭の文字を大文字にしてくっつける。
    """
    S = list(input().split())
    answer = S[0][0].upper() + S[1][0].upper() + S[2][0].upper()
    print(answer)


if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int s[525];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int H, W, h, w;
  int a[525][525];
  cin>>H>>W>>h>>w;
  if(H%h==0 && W%w==0){
    cout<<"No"<<'\n';
    return 0;
  }
  cout<<"Yes"<<'\n';
  bool f=H%h;
  int N=(f ? H : W);
  int n=(f ? h : w);
  FOR(i, n, N){
    s[i]=s[i-n]-1;
  }
  s[N]=1;
  for(int i=N-n; i>=0 ; i-=n){
    s[i]=s[i+n]+1;
  }
  int b[525];
  REP(i, N){
    b[i]=s[i+1]-s[i];
  }
  if(f){
    REP(i, W)REP(j, H){
      a[j][i]=b[j];
    }
  }
  else{
    REP(i, H)REP(j, W){
      a[i][j]=b[j];
    }
  }
  REP(i, H)REP(j, W){
    cout<<a[i][j]<<" \n"[j==W-1];
  }
  return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
#include<cmath>
#define reg register
#define LL long long
inline LL read(){
	LL x=0,y=1;
	char c=std::getchar();
	while(c<'0'||c>'9'){if(c=='-') y=0;c=std::getchar();}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=std::getchar();}
	return y?x:-x;
}
LL n,a,b;
int main(){
	n=read();a=read();b=read();
	LL sum=a+b;
	LL times=n/sum;
	LL ans=times*a;
	ans+=std::min(n-times*sum,a);
	std::printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n,l; cin >> n >> l;
  vector<string> s(n);
  rep(i,n){
    cin >> s.at(i);
  }
  sort(all(s));
  rep(i,n){
    cout << s.at(i);
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map> 
#define INF 0x3f3f3f3f
#define int long long 
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn=2e5+6;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n,m; 
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}        
void write(int x){        
    if(x < 0) {        
        putchar('-');        
        x = -x;        
    }        
    if(x > 9)        
        write(x/10);        
    putchar(x % 10 + '0');        
    return;        
}   
signed main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	int ans=0;
	int cnt=min(k, a);
	ans+=cnt;
	k-=cnt;
	if(k>0){
		cnt=min(b,k);
		k-=cnt;
	}
	if(k>0){
		cnt=min(c,k);
		k-=cnt;
		ans-=cnt;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  int n, m;
  cin >> n >> m;
  int time = 1900 * m + 100 * (n - m);
  int ans = time * pow(2, m);
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int exp(int n, int k) {
  if (k == 0) return 1;
  if (k == 1) return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2) ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
//#define MULTIPLE_TEST_CASE
void solution() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max({a * c, b * d, a * d, b * c}) << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#define all(c) c.begin(),c.end()
#include<algorithm>
#define MAX 20
#include<vector>
using namespace std;
int main(){
	int n;
	cin>>n;
	while(n--){
		int sum=0;
		int M=9*8*7*6*5*4*3*2*1;
		vector<int> va(9);
		vector<int> vb(9);
		for(int i=0;i<9;i++)
		cin>>va[i];
		for(int i=0;i<9;i++)
		cin>>vb[i];
		sort(all(va));
		//cout<<va[0]<<endl;
		/*for(int i=0;i<9;i++)
		cout<<va[i];
		cout<<endl;
		*/
		do{
			int a=0,b=0;
			for(int i=0;i<9;i++){
				if(va[i]>vb[i])
					a+=va[i]+vb[i];
				else
					b+=va[i]+vb[i];
			}
			if(a>b)
			sum++;
		}while(next_permutation(all(va)));
		//cout<<M<<"   "<<sum<<endl;
		printf("%.5lf %.5lf\n",(double)sum/M,(double)(M-sum)/M);
		
	}
	return 0;
}

Measured memory_bytes: 944
//
//  main.cpp
//  1
//
//  Created by dive5617 on 14-5-24.
//  Copyright (c) 2014年 dive5617. All rights reserved.
//

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

typedef double DB;

const DB eps=1e-9;

#define _sign(x) ((x)>eps?1:((x)<-eps?2:0))
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)

struct point
{
	DB x,y;
}p[105],q[105];

DB dist(point a,point b)
{
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
DB xmult(point p1,point p2,point p0)
{
	return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
int inside_convex(point q,int n,point *p)
{
	int i,s[3]={1,1,1};
	for(i=0;i<n && s[1]|s[2];i++)	s[_sign(xmult(p[(i+1)%n],q,p[i]))]=0;
	return s[1]|s[2];
}
bool isIntersected(point s1,point e1,point s2,point e2)
{
	return ( max(s1.x,e1.x)>=min(s2.x,e2.x)	&&
            max(s2.x,e2.x)>=min(s1.x,e1.x) &&
            max(s1.y,e1.y)>=min(s2.y,e2.y) &&
            max(s2.y,e2.y)>=min(s1.y,e1.y) &&
            xmult(s2,e1,s1)*xmult(e1,e2,s1)>=0 &&
            xmult(s1,e2,s2)*xmult(e2,e1,s2)>=0 );
}
struct cmp
{
	point p;
	cmp(const point &p0) {p=p0;};
	bool operator()(const point &a,const point &b)
	{
		if(fabs(xmult(a,b,p))<eps)	return dist(a,p)<dist(b,p);
		return xmult(a,b,p)>0;
	}
};
int scan(point *p,int n){
	int i,k=0,top;
	for(i=1;i<n;i++)	if(p[i].y<p[k].y || (fabs(p[i].y-p[k].y)<eps && p[i].x<p[k].x))	k=i;
	swap(p[0],p[k]);
	sort(p+1,p+n,cmp(p[0]));
	top=1;
	for(i=2;i<n;i++)
	{
		while(top && xmult(p[i],p[top],p[top-1])>=0)	top--;
		p[++top]=p[i];
	}
	return top+1;
}

bool judge(point *p,int n,point *q,int m){
	if(n==1)	p[n++]=p[0];
	if(m==1)	q[m++]=q[0];
	if(n==2 && m==2)	return !isIntersected(p[0],p[1],q[0],q[1]);
	if(m>2)	for(int i=0;i<n;i++)	if(inside_convex(p[i],m,q))	return 0;
	if(n>2)	for(int i=0;i<m;i++)	if(inside_convex(q[i],n,p))	return 0;
	for(int i=0;i<n;i++)	for(int j=0;j<m;j++)	if(isIntersected(p[i],p[(i+1)%n],q[j],q[(j+1)%m]))	return 0;
	return 1;
}

int main(void){
	int n,m;
	while(scanf("%d%d",&n,&m)==2 && (n||m))
	{
		for(int i=0;i<n;i++)	scanf("%lf%lf",&p[i].x,&p[i].y);
		for(int i=0;i<m;i++)	scanf("%lf%lf",&q[i].x,&q[i].y);
		if(n*m==0 || n*m==1)
		{
			puts("YES");
			continue;
		}
		n=scan(p,n);
		m=scan(q,m);
		puts(judge(p,n,q,m)?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 1068
import sys
inf = 10**15
mod = 10**9+7
s = input()
n = len(s)-1
for i in range(2**n):
    ans = int(s[0])
    acc = ans
    a = [s[0]]
    for j in range(n):
        if ((i >> j) & 1):  # 1だったら(オンだったら)
            acc = int(s[j + 1])
            ans+=acc
            a.append('+')
            a.append(s[j+1])
        else:
            acc = int(s[j + 1])
            ans-=acc
            a.append('-')
            a.append(s[j+1])
    if ans == 7:
        a.append('=7')
        print(''.join(a))
        sys.exit()

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int TOP=10;
int a[5100][5100];
long long val[5100];
int dis[5100];
int n;
int m;
long long ans;
struct KT
{
    int st[5100];
	int which;
	int top;
    void PJ(int x)
	{	
		which=x;
	}
    void XN(int x)
	{
        while(top&&a[st[top]][which]<=a[x][which])
		{
            val[st[top]]-=a[st[top]][which];
            if(top>1)
            val[st[top-1]]+=a[st[top]][which];
            --top;
        }
        st[++top]=x;
        val[st[top]]+=a[st[top]][which];
        if(top>1)
        val[st[top-1]]-=a[st[top]][which];
    }
}f[5100];
int main()
{
    long long sum;
    cin>>n>>m;
    for(int i=1;i<n;i++) 
	scanf("%d",dis+i);
    memset(val,0,sizeof(val));
    for(int i=1;i<=n;i++)
    {
    	for(int j=1;j<=m;j++)
    	{
    		cin>>a[i][j];
    	}
    }
    for(int i=1;i<=m;i++) 
	f[i].PJ(i);
    for(int l=n;l>=1;--l)
	{
        for(int i=1;i<=m;i++)
        f[i].XN(l);
        sum=0;
        for(int r=l;r<=n;r++)
		{
            sum+=val[r];
            ans=max(ans,sum);
            sum-=dis[r];
        }
    }
    cout<<ans;
}

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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair   
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 3005;

int dp[maxn][maxn]; //dp[i][j] is the number of valid permutation until index i with j is the last number

const int mod = 1e9 + 7;

void add(int &a, int b){
	if(b < 0){b += mod;}
	a += b;
	if(a < 0){a += mod;}
	if(a >= mod){a -= mod;}
}

int main(){
	int n,i,j,k;
	string kata;
	scanf("%d",&n);
	cin>>kata;

	for(i=1;i<=n;i++){
		dp[1][i] = 1;
	}
	int pref[n+1];
	
	for(i=2;i<=n;i++){
		memset(pref, 0, sizeof pref);
		for(j=1;j<i;j++) {
			pref[j] = dp[i-1][j];
			add(pref[j], pref[j-1]);
		}
		for(j=1;j<=i;j++){ //mau coba place dari 1 sampe i
			if(kata[i-2] == '>'){
				add(dp[i][j], pref[j-1]);
				// for(k=1;k<j;k++){
				// 	add(dp[i][j], dp[i-1][k]);
				// }
			}else{
				add(dp[i][j], pref[i-1] - pref[j-1]);
				// for(k=j;k<i;k++){
				// 	add(dp[i][j], dp[i-1][k]);
				// }
			}
		}
	}
	int ans = 0;
	for(i=1;i<=n;i++){
		add(ans, dp[n][i]);
	}
	printf("%d\n",ans);
	return 0;
};

Measured memory_bytes: 34176
#include <stdio.h>
int main(){
  int pep,lim,i;
  int count = 0;
  int hei[100010];
  scanf("%d%d",&pep,&lim);
  for(i=0;i<=pep;i++){scanf("%d",&hei[i]);}  
  for(i=0;i<pep;i++){
    if(hei[i] >= lim)count++;
  }
  printf("%d",count);
}

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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<pair<int, int> > A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		int X, L;
		cin >> X >> L;
		A[i].first = X + L;
		A[i].second = X - L;
	}
	sort(A.begin(), A.end());
	int l = -((int)1 << 50);
	for (int i = 0; i < N; i++) {
		int R = A[i].first;
		int L = A[i].second;
		if(l <= L){
			l = R;
			res++;
		}
	}
	cout << res << endl;
}

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


int main(){

  char c;

  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }

}

Measured memory_bytes: 256
#include<cstdio>
#define ll long long
const int N=2005,M=4e6+5,mo=1e9+7;
int n,m,nm,i,j,f[N];
int fact[M],inv[M],fv[M];
void init(int n){
	fact[0]=fact[1]=inv[1]=fv[0]=fv[1]=1;
	for (i=2;i<=n;i++){
		fact[i]=(ll)fact[i-1]*i%mo;
		inv[i]=(ll)inv[mo%i]*(mo-mo/i)%mo;
		fv[i]=(ll)fv[i-1]*inv[i]%mo;
	}
}
int C(int n,int m){return (ll)fact[n]*fv[m]%mo*fv[n-m]%mo;}
/*
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttetesttesttest
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttetesttesttest
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttetesttesttest
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttetesttesttest
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttetesttesttest
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttetesttesttest
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttetesttesttest
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttetesttesttest
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttetesttesttest
testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttetesttesttest
*/
int main(){
	scanf("%d%d",&n,&m);m--;
	if (!m){puts("1");return 0;}
	nm=n*m+n;init(nm);f[0]=1;
	for (i=1;i<=n;i++) for (j=1;j<=i;j++)
		f[j]=(f[j]+(ll)C(nm-i-(j-1)*m-1,m-1)%mo*f[j-1])%mo;
	for(int i=1;i<=n;i++)f[n]=1ll*f[n]*i%mo;
	printf("%d",f[n]);
}


Measured memory_bytes: 47104
A, B, C = map(int, input().split())

# a1 = min(C, A)
# C -= a1
# pad = 1 if B <= C else 0
# a2 = max(B, C)
# print(a1 + a2 + pad)

if A + B + 1 >= C:
    print(B + C)
else:
    print(B + (A + B + 1))

Measured memory_bytes: 38256
if __name__ == '__main__':
    N, K = map(int, input().split())
    ab = []
    for i in range(N):
        ab.append(list(map(int, input().split())))
    ab.sort(key=lambda x: x[0])
    count = 0
    for i in ab:
        count += i[1]
        if K <= count:
            print(i[0])
            break

Measured memory_bytes: 29144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
double a[100];
int main()
{
    double ans;
    int n;cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i],ans+=1/a[i];
    printf("%.5f\n",1/ans);
    return 0;
}

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

int main(){
  while(1){

  int n,m,b,d[1000000]={},a,mx=0;
  cin>>n>>m;
  if(n+m==0) break;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    d[b]+=a;
 mx=max(mx,b);
  }

  for(int i=mx;i>=0;i--){
    if(d[i]>0 && m>0){
      int t= d[i];
      d[i]-=m;
      m-=t;
      }
  }
  int ans=0;
  for(int i=0;i<=mx;i++)
    if(d[i]>0) ans+=(i*d[i]);
     cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 5072
#coding:utf-8




def solve(i,s,n)
	if s == $sum && n == 0 then
			$count += 1
			return
	end

	if i==10 || n==0 then
		return
	end
	#print "i:#{i}, s:#{s}, n:#{n}\n"
	solve(i+1, s+i, n-1)
	solve(i+1, s, n)
	
end

while true do
	str = gets.chomp.split(' ').map(&:to_i)
	break if str == [0,0]
	n,$sum = str[0], str[1]
	$count = 0
	
	#puts n
	#puts $sum

	solve(0,0,n)
	puts $count

end

Measured memory_bytes: 6096
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}


long long int pow_mod(long long int p_a,long long int p_n,long long int p_p=1e9+7){
	//p_a^p_n mod p_p
	long long int p_b=1,p_t=1;
	for(;p_b<=p_n;p_b<<=1);
	for(p_b>>=1;p_b>0;p_b>>=1){
		p_t*=p_t;
		if(p_t>=p_p)p_t%=p_p;
		if(p_n&p_b)p_t*=p_a;
		if(p_t>=p_p)p_t%=p_p;
	}
	return p_t;
}
LL divi(LL a,LL b){//a/b
	return (a*pow_mod(b,MAX-2))%MAX;
}

int main(){
	LL n,m;
	LL i,j,k;
	LL a,b,c,d,e;
	LL p,q;
	LL s=0;
	cin>>n;
	cin>>a>>b>>c;
	c=100-c;
	c=pow_mod(c,MAX-2)*(LL)100%MAX;
	d=divi(a,a+b),e=divi(b,a+b);
	p=pow_mod(d,n);
	for(i=0;i<n;i++){
		s+=(p*(n+i)%MAX)*c%MAX;
		s%=MAX;
		p*=divi(n+i,i+1)*e%MAX;
		p%=MAX;
	}
	p=pow_mod(e,n);
	for(i=0;i<n;i++){
		s+=(p*(n+i)%MAX)*c%MAX;
		s%=MAX;
		p*=divi(n+i,i+1)*d%MAX;
		p%=MAX;
	}
	cout<<s%MAX<<endl;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%s", $s);
$arr = str_split($s);

$result = true;
foreach ($arr as $i => $char) {
    if (($i + 1) % 2 === 0) {
        if ($char === 'R') {
            $result = false;
            break;
        }
    } else {
        if ($char === 'L') {
            $result = false;
            break;
        }
    }
}

echo $result ? 'Yes' : 'No';


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  ll t, x;
  cin >> t >> x;
  cout << (double)t / x << endl; 

  return 0;
}

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

int main() {
    // input
    string S;
    cin >> S;

    // solve
    int ans = 0;
    int n = S.length();
    for (int i = 0; i < n; ++i) {
        S.erase(S.length() - 1);
        if (S.length() % 2 == 0) {
            if (S.substr(0, S.length() / 2) == S.substr(S.length() / 2, S.length() / 2)) {
                ans = S.length();
                break;
            }
        }
    }

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define mem(a,x) memset(a,x,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int maxn = 2e6 + 7;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
inline void print(ll n){
	if(!n) return ;
	ll p = n%26;
	
	if(p) print(n/26);
	else print((n-26)/26),p += 26;
	
	printf("%c",(p-1)+'a');
	return ;
}

int main()
{	
	ll n;
	scanf("%lld",&n);
	print(n);
	return 0;
}


Measured memory_bytes: 3824
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int n;
  cin >> n;
  while(n--){

  string num1,num2;
  cin >> num1 >> num2;

  if(num1.size() < num2.size())swap(num1,num2);
  if(num1.size() > 80){
    cout << "overflow" << endl;
    continue;
  }
  int m = num1.size()-num2.size();
  int M = num1.size();
  string n1="",n2="";
  for(int i = 0 ; i < m ; i++ )n2+='0';
  n2 = n2 + num2;
  string nn1="",nn2="";
  for(int i = M-1 ; i >= 0 ; i-- ){
    nn1+=num1[i];
    nn2+=n2[i];
  }
  string ans="",ansi="";
  int t = 0;

  for(int i = 0 ; i < num1.size() ; i++ ){
    if(t + (nn1[i] - '0') + (nn2[i] - '0') >= 10){
      ans += (t + (nn1[i] - '0') + (nn2[i] - '0') - 10) + '0' ;
      t = 1;
    } else {
      ans += (char)(t + (nn1[i]-'0') + (nn2[i]-'0') + '0');
      t = 0;
    }
  }

    if(t==1)ans+='1';
    for(int i = ans.size()-1 ; i >= 0 ; i--){
      ansi += ans[i];
    }
    if(ansi.size() > 80){
      cout << "overflow" << endl;
    }else cout << ansi << endl;
    }
  return 0;
}

Measured memory_bytes: 1216
import java.util.Scanner;

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

    int N = scanner.nextInt();
    System.out.println(luca(N));
  }

  private static long luca(int N) {
    N--;
    long a = 2;
    long b = 1;
    while (N > 0) {
      long c = a + b;
      a = b;
      b = c;
      N--;
    }
    return b;
  }
}


Measured memory_bytes: 22612
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>

using namespace std;
using lint = long long;
using pii = pair<int, int>;
using vec = vector<lint>;
using pq = priority_queue<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define mp(x, y) make_pair((x), (y))
#define space (char)0x20

constexpr lint MOD = 1e9 + 7;
constexpr int INF = 1<<(int)29;
lint A, B, C, F, H, I, J, K, L, M, N, P, Q, R, S, T, U, V, W, X, Y;
// int ans;
// string ans;
vec a, ans;

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

	cin >> N;
    a.resize(N);
    ans.resize(N);
    rep(i, N) {
        cin >> a[i];
    }

    ans[0] = accumulate(all(a), 0LL);
    for(int i = 1; i <= N - 1; i += 2) {
        ans[0] -= 2 * a[i];
    }

    rep1(i, N - 1) {
        ans[i] = 2 * a[i-1] - ans[i-1];
    }
    
    foreach(it, ans) {
        cout << *it << space;
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define trav(x, v) for(auto &x : v)
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

int n,k;
vi ai;

int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin.exceptions(cin.failbit);
	
	cin >> n >> k;
	ai = vi(n);
	rep(i,0,n) cin >> ai[i];
	vi bi(n);
	int s=0;
	bool can =true;
	rep(i,0,n){
		bi[i] = max(0,k+1-ai[i]);
		s += bi[i];
		if(bi[i]>(k+1)/2) can=false;
	}
	if(can && s<=k){
		int y=0;
		while(s<k){
			if(bi[y]<(k+1)/2){
				bi[y]++;
				s++;
			}else{
				y++;
			}
		}
		int x=0;
		vi seq(k);
		int half=-1;
		rep(i,0,n){
			if(bi[i]==(k+1)/2) half=i;
		}
		if(half==-1){
			rep(i,0,n){
				rep(j,0,bi[i]){
					seq[x]=i;
					x+=2;
					if(x>=k) x=1;
				}
			}
		}else{
			rep(i,0,(k+1)/2) seq[2*i]=half;
			x=1;
			rep(i,0,n){
				if(i==half) continue;
				rep(j,0,bi[i]){
					seq[x]=i;
					x+=2;
					if(x>=k) x=1;
				}
			}
		}
		vi ans;
		rep(i,0,n){
			if(i!=seq[0]) ans.pb(i);
		}
		ans.pb(seq[0]);
		rep(i,0,k-1){
			rep(j,0,n){
				if(j!=seq[i] && j!=seq[i+1]) ans.pb(j);
			}
			ans.pb(seq[i+1]);
		}
		rep(i,0,n){
			if(i!=seq[k-1]) ans.pb(i);
		}
		
		cout << sz(ans) << endl;
		trav(a,ans){
			cout << a+1 << " ";
		}
		cout << endl;
	}else{
		cout << -1 << endl;
	}
}


Measured memory_bytes: 256
def f(n, m, q, requirements):
    A = [1 for i in range(n + 1)]
    ans = 0
    while True:
        # スコア計算
        score = 0
        for requirement in requirements:
            a, b, c, d = requirement
            if A[b] - A[a] == c:
                score += d
        ans = max(ans, score)
        # 数列更新
        j = n
        while j > 0:
            if A[j] < m:
                A[j] += 1
                for i in range(j + 1, n + 1):
                    A[i] = A[j]
                break
            j -= 1
        if j == 0:
            break
    return ans


if __name__ == '__main__':
    n, m, q = map(int, input().split())
    requirements = []
    for i in range(q):
        requirements.append(tuple(map(int, input().split())))
    print(f(n, m, q, requirements))


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;

string S[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) cin>>S[y];
	
	y=x=0;
	while(1) {
		S[y][x]='.';
		if(y==H-1 && x==W-1) break;
		if(x<W-1 && S[y][x+1]=='#') {
			x++;
		}
		else if(y<H-1 && S[y+1][x]=='#') {
			y++;
		}
		else {
			return _P("Impossible\n");
		}
	}
	FOR(y,H) FOR(x,W) if(S[y][x]=='#') return _P("Impossible\n");
	
	_P("Possible\n");
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll A, B;
  string s;
  cin >> A >> B >> s;
  if (s.length() != (A + B + 1)) {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < s.length(); i++) {
    if (i < A && !('0' <= s[i] && s[i] <= '9')) {
      cout << "No" << endl;
      return 0;
    }
    if (i == A && s[i] != '-') {
      cout << "No" << endl;
      return 0;
    }
    if (A < i && !('0' <= s[i] && s[i] <= '9')) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3588
//i ll be the king
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
int main()
{
	sync;
	ll n;
	cin>>n;
	ll arr[n][3];
	for(ll i=0;i<n;i++)
	for(ll j=0;j<3;j++)
	cin>>arr[i][j];
	ll dp[n][3];
	dp[0][0]=arr[0][0];
	dp[0][1]=arr[0][1];
	dp[0][2]=arr[0][2];
	for(ll i=1;i<n;i++)
	{
		dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
   int a; // 縦
   int b; // 横  
   int area; //面積
   int permeter; //外周

   cin  >> a >> b;

   area = a*b;
   permeter = a*2 + b*2;

   cout << area << " " << permeter << endl;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }

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

const int INF = 1000000007;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    vector<int> c(m), d(m);
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,m) cin >> c[i] >> d[i];
    vector<int> ans(n);
    rep(s, n){
        int min_dis = INF;
        int ans_s = 0;
        rep(p, m){
            int dis = abs(a[s] - c[p]) + abs(b[s] - d[p]);
            if (chmin(min_dis, dis)) ans_s = p;
        }
        ans[s] = ans_s+1;
    }
    rep(i, n) cout << ans[i] << endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  vector<vector<int>> bingo(3, vector<int>(3,0));
  vector<vector<int>> sheet(3, vector<int>(3));
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++) cin >> sheet[i][j];
  }
  int n;
  cin >> n;
  vector<int> num(n);
  for(int i = 0; i < n; i++) cin >> num[i];
  
  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < n; k++){
        if(sheet[i][j] == num[k]) bingo[i][j] = 1;
      }
    }
  }
  
  bool ok = false;
  if(bingo[0][0] == 1 && bingo[1][1] == 1 && bingo[2][2] == 1) ok = true;
  if(bingo[0][2] == 1 && bingo[1][1] == 1 && bingo[2][0] == 1) ok = true;
  for(int i = 0; i < 3; i++){
    if(bingo[i][0] == 1 && bingo[i][1] == 1 && bingo[i][2] == 1) ok = true;
  }
  for(int i = 0; i < 3; i++){
    if(bingo[0][i] == 1 && bingo[1][i] == 1 && bingo[2][i] == 1) ok = true;
  }
    
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3544
N = gets.to_i
Vs = gets.split.map(&:to_i)

as, bs = Hash.new(0), Hash.new(0)
Vs.each_slice(2) do |a, b|
  as[a] += 1
  bs[b] += 1
end
a1, a2 = as.sort_by(&:last).reverse.take(2).map(&:first)
b1, b2 = bs.sort_by(&:last).reverse.take(2).map(&:first)
puts a1 != b1 ? N - as[a1] - bs[b1] : [N - as[a1] - bs[b2], N - as[a2] - bs[b1]].min

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

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

    bool flag = 0;

    string s;
    cin >> s;
    for(int i = 0; i<n; i++){
        s[i] += '0' - '1';
        if(s[i] == '1') flag = 1;
    }

    if(!flag){
        for(int i = 0; i<n; i++){
            if(s[i] == '2') s[i] = '1';
        }
    }

    int ans = 0;
    for(int i = 0; i<n; i++){
        int cnt = 0;
        for(int j = 0; j<22; j++){
            cnt += (n - 1) / (1 << j);
        }

        for(int j = 0; j<22; j++){
            cnt -= (n - 1 - i) / (1 << j);
        }

        for(int j = 0; j<22; j++){
            cnt -= i / (1 << j);
        }

        if(cnt == 0) ans ^= ((s[i] - '0') % 2);
    }

    if(flag) cout << ans << endl;
    else cout << 2*ans << endl;

}


Measured memory_bytes: 1412
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int i,j,k;
int n,a,b,ans1,ans2;

int main(){
	scanf("%d",&n);
	while(n!=0){
		ans1=0;ans2=0;
		for(i=0;i<n;i++){
			scanf("%d %d",&a,&b);
			if(a>b)ans1+=a+b;
			else if(a<b)ans2+=a+b;
			else if(a==b)ans1+=a,ans2+=b;
		}
		printf("%d %d\n",ans1,ans2);
		scanf("%d",&n);
	}
	
	return 0;
}

Measured memory_bytes: 0
def dice(n, k ,numbers)
  count = 0
  max = 0
  expects = 0
  sum = numbers[0..k-1].inject(:+)
  numbers_a = numbers[0..k - 1]
  
  while count < n - k do
    sum = sum + numbers[k + count] - numbers[count]
    if sum > max
      max = sum
      numbers_a = numbers[count + 1..count + k]
    end
    count = count + 1
    
  end
  numbers_a.each do |num|
    expects += ((1 + num)/2.to_f)
  end
  puts expects
end

n, k = gets.chomp.split(" ").map(&:to_i)
numbers = gets.chomp.split(" ").map(&:to_i)
dice(n, k ,numbers)

Measured memory_bytes: 16012