akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**7)

N, Q = map(int, input().split())
edge = [[] for _ in range(N+1)]
for _ in range(N-1):
        a, b, c, d = map(int, input().split())
        edge[a].append((b, c, d))
        edge[b].append((a, c, d))
        
depth = [0] * (N+1)
U = 17
ancestor = [[0] * (U+1) for _ in range(N+1)]

q = [(1, 0, 0)]
while q:
        qq = []
        for x, d, parent in q:
                depth[x] = d
                ax = ancestor[x]
                ax[0] = parent
                for i in range(d.bit_length()-1):
                        ax[i+1] = ancestor[ax[i]][i]

                for y, _, _ in edge[x]:
                        if y == parent:
                                continue
                        qq.append((y, d+1, x))
        q = qq

def lca(x, y):
        dx = depth[x]
        dy = depth[y]
        if dx > dy:
                x, y = y, x
                dx, dy = dy, dx
        diff = dy - dx
        while diff:
                step = diff & (-diff)
                y = ancestor[y][step.bit_length()-1]
                diff -= step
        while x!=y:
                j = 0
                while ancestor[x][j] != ancestor[y][j]:
                        j += 1
                if j==0:
                        return ancestor[x][0]
                x = ancestor[x][j-1]
                y = ancestor[y][j-1]
        return x

task = [[] for _ in range(N+1)]
for i in range(Q):
        x, y, u, v = map(int, input().split())
        task[u].append((i, x, y, 1))
        task[v].append((i, x, y, 1))
        task[lca(u, v)].append((i, x, y, -2))

answer = [0] * Q

def dfs(x=1, sums=[0]*(N+1), nums=[0]*(N+1), total=0, parent=0):
        for i, c, d, coef in task[x]:
                answer[i] += coef * (total - sums[c] + nums[c]*d)
        for y, c, d in edge[x]:
                if y == parent:
                        continue
                sums[c] += d
                nums[c] += 1
                total += d
                dfs(y, sums, nums, total, x)
                sums[c] -= d
                nums[c] -= 1
                total -= d
        return

dfs()

print('\n'.join(map(str, answer)))


Measured memory_bytes: 201492
using System;
using System.Collections.Generic;

namespace TESt
{
    class Program
    {
    internal class GuruGuru
    {
        int tempPower = 0;
        public int Power { get; private set; } = 0;

        internal void Execute()
        {
            //Console.WriteLine("Please enter the string of operations performed by Guru Guru: ");
            string input = Console.ReadLine();

            for (int i = 0; i < input.Length; i++)
            {
                if (input[i] == 'R')
                    ++tempPower;
                else if (input[i] == 'L')
                    --tempPower;

                // tempPower = 4 means one full clockwise rotation so we increment mystical power.
                if (Math.Abs(tempPower) == 4)
                {
                    if(tempPower == 4)
                        ++Power;
                        
                    tempPower = 0;
                }
            }

            //Console.WriteLine("Number of times mystical powers activated were: {0}", Power);
             Console.WriteLine(Power);
        }
    }
        
        static void Main(string[] args)
        {
            new GuruGuru().Execute();
        }
    }
}


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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i,n){
    cin >> h[i];
  }
  int max=0;
  int cur=0;
  rep(i,n-1){
    if (h[i]-h[i+1]<0){
      if (cur>max) max = cur;
      cur=0;
    }
    else{
      cur++;
    }
  }
  if (cur>max) max = cur;
  
  cout << max << endl;

  return 0;
}


Measured memory_bytes: 640
import bisect

def main():
    n = int(input())
    buf = []
    a = [None] * n
    for i in range(n):
        a[i] = int(input())
    for i in reversed(a):
        index = bisect.bisect_right(buf, i)
        if index < len(buf) and buf[index] > i:
            buf[index] = i
        else:
            buf.append(i)
    print(len(buf))

if __name__ == "__main__":
    main()


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

  
int main() {
int N;
cin >> N;
vector<double>v(N);
REP(i, N) cin >> v.at(i);
sort(all(v));
double ans = v.at(0);
REP(i, N - 1){
ans = (ans + v.at(i + 1) ) / 2;
}
print(ans);
}


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

using namespace std;

typedef long long ll;
const ll mod=998244353;
const ll N=1e6;
int a[N];
int b[N];
ll pow_mod(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res%mod;
}
int main()
{
	int n;
	cin>>n;
	int k;
	ll ans=0;
	cin>>k;
	if(k!=0){
		cout<<ans<<endl;
		return 0;
	}
	a[k]++;
	b[0]=k;
	for(int i=1;i<n;i++){
		cin>>k;
		b[i]=k;
		a[k]++;
	}
	if(a[0]>1){
		cout<<ans<<endl;
		return 0;
	}
	sort(b,b+n);
	for(int i=0;i<b[n-1];i++){
		if(a[i]==0){
			cout<<ans<<endl;
			return 0;
		}
	}
	ans=1;
	for(int i=1;i<=b[n-1];i++){
		ans=(ans%mod*pow_mod(a[i-1],a[i]))%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =  1e9 + 7 ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
    int n ,k  ;
    cin >> n >> k;
    vector < ll > a(n) ;
    for( int i = 0 ; i <n ; i++) cin >> a[i] ;
    sort(a.rbegin(),a.rend());
    ll low = 1 , high = a[0] ;
    ll ans = 0 ;
    while(low<=high){
       ll mid = (low+high)/2;
       ll steps = 0 ;
       for(int i = 0 ; i < n ; i++){
//            ld x = a[i] ;
//            ll t = 1;
//            while(x>mid){
//                ld one = x-mid , two = mid ;
//                ll add = (1ll<<(t-1)) ;
//                steps += add ;
//                x = one ;
//                t++;
//            }
            steps += a[i]/mid + (a[i]%mid!=0)-1;
       }
     //  cout << low << " " << high << " " << mid << " " << steps << "\n";
       if(steps<=k){
            ans = mid ;
            high = mid-1 ;
       }
       else{
            low = mid+1 ;
       }
    }
    cout << ans << "\n";


}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}


Measured memory_bytes: 4768
S = ""

def rec(nums,step,N): #step → + を挿入する場所

    if step == N:
        nums = list(map(int,nums))
        return sum(nums)

    else:
        num = S[step]
        nums2 = nums[::]
        nums2[-1] += num
        nums.append(num)
        return rec(nums,step+1,N) + rec(nums2,step+1,N)
        #+を入れたパターン#+を入れなかったパターン



def func():
    global S
    S = input()
    N =len(S)
    print(rec([S[0]],1,N))

if __name__ == '__main__':
    func()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<list>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
#define lll __int128
const int inf=1e9+7;
const int mod=1e9+7;

//const int maxn=

ll int gcd(ll int a,ll int b)
{
	return b==0?a:gcd(b,a%b);
}

ll int lcm(ll int a,ll int b)
{
	return a/gcd(a,b)*b;
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    ll int a,b;
    
    cin>>a>>b;
    
    cout<<lcm(a,b)<<endl;
    
    return 0;
}

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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> height(n+1);
	vector<int> ma(n+1);

	for(int i = 1; i <= n; i++){
		cin >> height.at(i);
		ma.at(i) = 0;
	}
	for(int i = 0; i < m;i++){
		int a, b;
		cin >> a >> b;
		ma.at(a) = max(ma.at(a), height.at(b));	 
		ma.at(b) = max(ma.at(b), height.at(a));	 
	}

	int ans = 0;
	for(int i = 1; i <= n; i++){
		ans += height.at(i) > ma.at(i);
	}
	cout << ans << endl;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
int n,x;
cin>>n>>x;
int m[n],MIN=1000000000;
rep(i,n){
cin>>m[i];
x-=m[i];
MIN=min(MIN,m[i]);
}
int count=0;
while(x>=MIN){
  count++;
  x-=MIN;
}
cout<<n+count<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
S = [0]*N
P = [0]*N
A = [0]*N
for i in range(N):
    s, p =input().split()
    A[i] = [i, s, int(p)]

A = sorted(A,key=lambda x: (x[1],-x[2]))

for i in range(N):
    print( A[i][0]+1)


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

int main() {
  int N;
  cin>>N;
  vector<int64_t> v(87);
  v[0]=2;
  v[1]=1;
  for(int i=2;i<87;i++)v[i]=v[i-1]+v[i-2];
  cout<<v[N]<<endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(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)
using ll=long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

ll dp[51][51][2505];

int main() {
	ll n, a;
	ll ans = 0;
	cin >> n >> a;
	vector<ll>x(n);
	repp(i, 0, n)cin >> x[i];
	repp(i, 0, n+1) repp(j, 0, n+1) repp(k, 0,2501) {
		if (i == 0 && j == 0 && k == 0)dp[i][j][k] = 1;
		else if (i > 0 && j > 0 && k >= x[i-1]) dp[i][j][k] = dp[i - 1][j - 1][k - x[i-1]] + dp[i - 1][j][k];
		else if (i > 0 && k < x[i-1])dp[i][j][k] = dp[i - 1][j][k];
		else dp[i][j][k] = 0;
			}
	repp(i, 1, n+1)ans += dp[n][i][i * a];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 51200
from bisect import bisect_left
import sys
input = sys.stdin.readline

N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())

a.sort()
b.sort()
ans = 0

for i in reversed(b[bisect_left(b, a[-1]):]):
    H -= i
    ans += 1
    if H <= 0:
        print(ans)
        exit()

print(ans + H // a[-1] + min(1, H % a[-1]))

Measured memory_bytes: 11944
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {
	
	int n, maxcount = -1, count = 0, number;
	scanf("%d", &n);

	rep(i, n) {
		number = i + 1;
		while (!(number % 2)) {
			++count;
			number /= 2;
		}
		maxcount = max(maxcount, count);
		count = 0;
	}
	printf("%d\n", int(pow(2, maxcount)));

	return 0;
}


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

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

  if(k == 1 ||k == 2 ||k == 3 ||k == 5 ||k == 7 ||k == 11 ||k == 13 ||k == 15 ||k == 17 ||k == 19 ||k == 23 ||k ==29 ||k == 31  ){
      cout << 1 << endl;
      return 0;
  }

  else if(k==4 ||k==6 ||k==9 ||k==10 ||k==14 ||k==21 ||k==22 ||k==25 ||k==26 ){
      cout << 2 << endl;
      return 0;
  }
  else if(k==28 || k==30){
      cout << 4 << endl;
      return 0;
  }

  else if(k==8 ||k==12 ||k==18 ||k==20 ||k==27 ){
      cout << 5 << endl;
      return 0;
  }

  else if(k==16){
      cout << 14 << endl;
      return 0;
  }
  else if(k==24){
      cout << 15 << endl;
      return 0;
  }
  else if(k==32){
      cout << 51 << endl;
      return 0;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		for(;;){
			String n = cin.next();
			String m = cin.next();
			if((n+m).equals("00"))break;
			char[] s1 = n.toCharArray();
			char[] s2 = m.toCharArray();
			int hit=0,blow=0;
			for(int i = 0;i<s1.length;i++){
				if(s1[i]==s2[i]){
					hit++;
					s1[i]=(char)i;
					s2[i]=(char)(i+4);
				}
			}
			for(int i = 0;i<s1.length;i++){
				for(int j = 0;j<s2.length;j++){
					if(s1[i]==s2[j]){
						blow++;
						s1[i]=(char)(i*1000);
						s2[j]=(char)(j*10000);
					}
				}
			}
			System.out.println(hit+" "+blow);
		}
	}

}

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

using Edge = pair<int, int>;
using Graph = vector<vector<Edge> >;

int n;
Graph g;

vector<int> ans;

void dfs(int v, int p, int color) {
    ans[v] = color;
    for (auto e : g[v]) {
        if (e.first == p) continue;
        if (e.second & 1) dfs(e.first, v, 1 - color);
        else dfs(e.first, v, color);
    }
}

int main() {
    cin >> n;
    g.assign(n, vector<Edge>());
    for (int i = 0; i < n - 1; i++) {
        int u, v, w; cin >> u >> v >> w;
        --u, --v;
        g[v].push_back(Edge(u, w));
        g[u].push_back(Edge(v, w));
    }
    ans.assign(n, 0);
    dfs(0, -1, 1);
    for (auto v : ans) cout << v << endl;
    return 0;
}


Measured memory_bytes: 8960
n = int(input())
p = ''
d = {}
for _ in range(n):
  w = input()
  if p and p[-1] != w[0]:
    print('No')
    exit()
  if w in d:
    print('No')
    exit()
  p = w[-1]
  d[w] = 1
print('Yes')
  


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int x,a,b;
  cin >> x >> a >> b;
  if(b<=a)
  cout <<"delicious"<< endl;
  else if(b<=x+a)
  cout <<"safe"<<endl;
  else
  cout << "dangerous" << endl;
}

Measured memory_bytes: 256
import numpy as np

N,M,X = map(int, input().split())
books = []
for i in range(N):
    book = list(map(int, input().split()))
    books.append(book)
books = np.array(books)
answer = 10**5 * N
for i in range(2**N):
    flag = False
    bin_str = format(i, '0{}b'.format(N))
    bin_array = []
    for letter in bin_str:
        bin_array.append(int(letter))
    bin_array = np.array(bin_array).reshape(N,1)
    v = np.sum(bin_array*books, axis=0)
    #print(v)
    j = 0
    while j < M:
        if v[j+1] < X:
            break
        j += 1
        if j == M:
            flag = True
            answer = min(answer, v[0])
if flag:
    print(answer)
else:
    print('-1')

Measured memory_bytes: 27272
import java.util.Scanner;
public class Main
{
  public static void main(String args[])
  {
    int a,b;
    Scanner sc = new Scanner(System.in);
    a = sc.nextInt();
    b = sc.nextInt();
    if(a>(2*b))
      System.out.print(a-2*b);
    else
      System.out.print("0");
  }
}

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

string REVERSE(string s, int a, int b){
	string S = s;
	for(int i = a; i <= b; i++) s[i] = S[a+b-i];
	return s;
}

string REPLACE(string s, int a, int b, string r){
	for(int i = a; i <= b; i++) s[i] = r[i-a];
	return s;
}

int main(){
	//?????????????????????
	string str;
	cin >> str;
	//???????????°????????????
	int q;
	cin >> q;
	//??????????????????????????????
	vector<string> Order, Replace;
	vector<int> Start, End;
	for(int i = 0; i < q; i++){
		string order, replace;
		int start, end;
		cin >> order;
		Order.push_back(order);
		cin >> start;
		Start.push_back(start);
		cin >> end;
		End.push_back(end);
		if(order == "replace"){
			cin >> replace;
			Replace.push_back(replace);
		}else{
			Replace.push_back("EMPTY");
		}
	}
	//??????????????????????????????????????????
	for(int i = 0; i < q; i++){
		if(Order[i] == "print") cout << str.substr(Start[i], End[i] - Start[i] + 1) << endl;
		if(Order[i] == "reverse") str = REVERSE(str, Start[i], End[i]);
		if(Order[i] == "replace") str = REPLACE(str, Start[i], End[i], Replace[i]);
	}
//	system("pause");
	return 0;
}

Measured memory_bytes: 1276
T = list(input())

if len(T) == 1:
    if T[0] == '?':
        T[0] = 'D'

else:
    if T[0] == '?':
        if T[1] == 'D' or T[1] == '?':
            T[0] = 'P'
        if T[1] == 'P':
            T[0] = 'D'

    for i in range(len(T)-1):
        if T[i] == '?':
            if T[i+1] == 'D' and T[i-1] == 'P':
                T[i] = 'D'
            if T[i+1] == 'D' and T[i-1] == 'D':
                T[i] = 'P'
            if T[i+1] == 'P':
                T[i] = 'D'
            if T[i+1] == '?' and T[i-1] == 'P':
                T[i] = 'D'
            if T[i+1] == '?' and T[i-1] == 'D':
                T[i] = 'P'

    if T[-1] == '?':
        T[-1] = 'D'

ans = ''.join(T)
print(ans)

Measured memory_bytes: 10640
from collections import OrderedDict

#カードを初期値をFalseとして全てリストに収納する
cards = OrderedDict()
pattern = ['S', 'H', 'C', 'D']
for cha in pattern:
    for num in range(1, 14):
        key = f'{cha} {num}'
        cards[key]= False
#標準入力を受け取る
n = int(input())
for i in range(n):
    i = input()
    #入力されたカードの真理値を反転させる
    cards[i] = not(cards[i])
    
#入力されていないカードは真理値がFalseであるので
for result , cards_bool in cards.items():
    if not cards_bool:
        print(result)


Measured memory_bytes: 6008
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	P[] ps;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if( n == 0 ) break;
			ps = new P[n];
			for(int i=0;i<n;i++) {
				ps[i] = new P(sc.nextDouble(), sc.nextDouble());
			}
			int cnt_max = 1;
			int cnt = 0;
			for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) {
				
				if( sqrt(dis( ps[i], ps[j] )) < 2.0 ) {
					P m = new P( (ps[i].x+ps[j].x)/2, (ps[i].y+ps[j].y)/2);
					double d = sqrt(1-dis(ps[i], m ));
					P dp = new P((ps[i].y-ps[j].y), -(ps[i].x-ps[j].x));
					dp.nom();
					dp.mult(d);
					P c[] = new P[2];
					c[0] = m.add(dp);
					dp.mult(-1.0);
					c[1] = m.add(dp);
					for(int l=0;l<2;l++) {
						cnt = 0;
//						LinkedList<Double> dist = new LinkedList<Double>();
//						LinkedList<Integer> ind = new LinkedList<Integer>();
						for(int k=0;k<n;k++) {
							if(dis(c[l], ps[k]) < 1.0 || k==i||k==j) {
//							debug(dis(c[l], ps[k]));
//								dist.add(dis(c[l], ps[k]));
//								ind.add(k);
								cnt++;
							}
						}
//						debug(c[l].x, c[l].y, i, j, cnt);
						cnt_max = max(cnt_max, cnt);
					}
				}
			}
			System.out.println(cnt_max);
		}
	}
	
	double dis( P p1, P p2 ) {
		return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y);
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
	
	class P {
		double x, y;
		P (double x, double y) {
			this.x = x;
			this.y = y;
		}
		void nom() {
			double nom = sqrt(x*x + y*y);
			x /= nom;
			y /= nom;
		}
		P add(P p) {
			x += p.x;
			y += p.y;
			return new P(x, y);
		}
		P mult(double d) {
			x *= d;
			y *= d;
			return new P(x, y);
		}
	}
}

Measured memory_bytes: 58552
#!/usr/bin/env python3
import sys


def solve(S: str):
    if S == 'Sunny':
        print('Cloudy')
    elif S == 'Cloudy':
        print('Rainy')
    elif S == 'Rainy':
        print('Sunny')
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

typedef complex<double> P;
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))


// OÏ
double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}
// àÏ
double dot(P a, P b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}

// »ÝÌxNgÆAÚ_ÌÊu©çAÌxNgðÔ·
P calcNextVector(P p,P v){
	// ÚüxNg
	P v2(-v.imag(),v.real());
	// ÚüÉ¼ÈPÊxNg
	P v3 = P(-v2.imag(),v2.real()); v3/=abs(v3);
	// ü«ðà¤É·é
	if(cross(v3,v2)<0){
		v3=-v3;
	}
	return p-2*dot(p,v3)*v3;
}

// _a,bðÊé¼üÆ_cÌÔÌ£
double distance_l_p(P a, P b, P c) {
  return abs(cross(b-a, c-a)) / abs(b-a);
}
// a,bðÊé¼üÆ¼a1,´_ÉÊu·é~ÆÌð_ðßé
vector<P> calcCrossPoint(P a,P b){
	double dlp=distance_l_p(a,b,P(0,0));
	double x=sqrt(1-dlp*dlp);
	P c = a-b;
	P d=c/abs(c);

	vector<P> v;
	v.push_back(d*x);
	v.push_back(-d*x);
	return v;
}
// _cª¼üabãÉ é©È¢©
int is_point_on_line(P a, P b, P c) {
  return EQ( cross(b-a, c-a), 0.0 );
}
int main(){

	double D;
	double px,py,vx,vy;
	while(cin>>D&&!EQ(D,0.0)){
		double sumDist=0;
		cin>>px>>py>>vx>>vy;
		P p = P(px,py);
		P v = P(vx,vy);
		double a=(dot(P(0,0)-p,v))/(abs(P(0,0)-p)*abs(v));
		if(EQ(a,-1)){
			//	double dist=abs(
			double dist=abs(p-P(0,0));
			dist=2-dist;
			if(EQ(dist,D)||dist<D){
				printf("%lf\n",dist);
			}
			else{
				cout<<"impossible"<<endl;
			}
		}
		else if(EQ(a,1)){
			double dist=abs(p-P(0,0));
			if(EQ(dist,D)||dist<D){
				printf("%lf\n",dist);
			}
			else{
				cout<<"impossible"<<endl;
			}
		}
		else
			cout<<"impossible"<<endl;

		//bool ok=true;
		//while(1){
		//	// ~ÆÌð_ðvZ
		//	vector<P> ret = calcCrossPoint(p,v);
		//	P op;
		//	if(EQV(((ret[0]-p)/abs((ret[0]-p))),(v/abs(v)))){
		//		op=ret[0];
		//	}
		//	else{
		//		op=ret[1];
		//	}
		//	// £ðvZ
		//	double dist=abs(op-p);

		//	// ´_ðÊé©Åêí¯
		//	if(is_point_on_line(op,p,P(0,0))){
		//		double g=abs(P(0,0)-p);
		//		if(!EQ(sumDist+g,D)&&sumDist+g>D){
		//			ok=false;
		//			break;
		//		}
		//		else{
		//			sumDist+=g;
		//			ok=true;
		//			break;
		//		}
		//	}
		//	else{
		//		if(EQ(sumDist+dist,D)||sumDist+dist>D){
		//			ok=false;
		//			break;
		//		}
		//		else{
		//			sumDist+=dist;
		//			v=calcNextVector(v,op);
		//			p=op;
		//		}
		//	}
		//}
		//if(ok){
		//	printf("%lf\n",sumDist);
		//}
		//else
		//	cout<<"impossible"<<endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
  int N, Q;
  while(cin >> N >> Q, N || Q){
    int day[101] = {0};
    for(int i = 0; i < N; i++){
      int M;
      cin >> M;
      for(int j = 0; j < M; j++){
	int d;
	cin >> d;
	day[d]++;
      }
    }
    int p = max_element(day, day + 101) - day;
    if(day[p] < Q) cout << 0 << endl;
    else cout << p << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll A,B;
  cin>>A>>B;
  ll A1=0, A2=0, B1=0, B2=0;
  A1=A*25/2;
  if(A%2==1)
    A1++;
  A2=(A+1)*25/2;
  if(A%2==1)
    A2--;
  B1=B*10;
  B2=(B+1)*10-1;
  for(int i=A1; i<=A2; i++){
    if(i>=B1 && i<=B2){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

  int N;
  cin >> N;
  vector<int> a(N);
  repr(i, N, 0) cin >> a[i];
  a[0] -= 1;
  for (int i = 1; i < N; ++i) {
    if (a[i] - 1 >= a[i-1]) a[i] -= 1;
  }
  vector<int> src(a.begin(), a.end());
  sorti(src);
  if (a == src) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int FindSumofDigits(int n){
  int sum = 0;
  while(n > 0){
    sum += n % 10;
    n /= 10;
  }

  return sum;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for(int i = 1; i <= N; i++){
    int sum = FindSumofDigits(i);
    if(sum >= A && sum <= B){
      total += i;
    }
  }

  cout << total << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;


int N, M, Q;
vector<int>a, b, c, d;
vector<int> buf;
int sum;

int main() {
	ll X;
	cin >> X;
	for (int i = 1; i <=100000; i++) {

		if (X <=i * (i + 1) / 2) {

			cout << i;
			break;

		}
	}
}

Measured memory_bytes: 384
import java.util.Arrays;
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());
        String[] ary = new String[n];
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            char[] c = new char[10];
            c = s.toCharArray();
            Arrays.sort(c);
            ary[i] = new String(c);
        }
        Arrays.sort(ary);
        long ans = 0L;
        long cnt = 0L;
        s:for (int i = 0; i < n; i++) {
            if (i == n - 1) {
                if (cnt != 0) {
                    ans += calc(cnt);
                }
            } else {
                if (ary[i].equals(ary[i + 1])) {
                    cnt++;
                } else if (cnt != 0){
                    ans += calc(cnt);
                    cnt = 0;
                }
            }
        }
        System.out.println(ans);
    }

    public static long calc(long l) {
        if (l == 0) {
            return 0;
        } else {
            return l + calc(l - 1);
        }
    }
}

Measured memory_bytes: 56760
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int a[n];
  int c=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]%2==1)c=1;
  }
  if(c==1)cout<<"first"<<endl;
  else cout<<"second"<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#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=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VI a(n), b(n), c(n);
    REP(i,n) scanf("%d", &a[i]);
    REP(i,n) scanf("%d", &b[i]);
    REP(i,n) scanf("%d", &c[i]);
    sort(ALL(a));
    sort(ALL(b));
    sort(ALL(c));

    VL x(n);
    int j = 0;
    REP(i,n){
        while (j < n && c[j] <= b[i]) j++;
        x[i] = n - j;
    }
    FORR(i,n-2,0) x[i] += x[i+1];

    ll ans = 0;
    j = 0;
    REP(i,n){
        while (j < n && b[j] <= a[i]) j++;
        if (j < n) ans += x[j];
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 2176
#include <assert.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

// const ll MOD = 998244353;
const ll MOD = 1000000007;

// UnionFind
template<class T>
struct UnionFind {
  std::vector<T> uni;
  T num;
  UnionFind(T s) : uni(s, -1), num(s) {}

  //頂点aが所属するグループ
  T root(T a) {
    if (uni[a] < 0) {
      return a;
    }
    return uni[a] = root(uni[a]);
  }

  // a,bをつなげる
  bool connect(T a, T b) {
    a = root(a);
    b = root(b);
    if (a == b) {
      return false;
    }

    if (uni[a] > uni[b]) {
      std::swap(a, b);
    }

    uni[a] += uni[b];
    uni[b] = a;
    return true;
  }

  // a,bが同グループか確認
  bool isConnect(T a, T b) { return root(a) == root(b); }

  // aが属するグループの要素数
  T size(T a) { return -uni[root(a)]; }

  //グループ数を返す
  T groups() {
    std::set<T> b;
    for (T i = 0; i < num; i++) {
      b.insert(root(i));
    }
    return b.size();
  }
};

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,k,l;
  std::cin>>n>>k>>l;
  UnionFind<int> load(n),rail(n);
  rep(i,0,k){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    load.connect(a,b);
  }
  rep(i,0,l){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    rail.connect(a,b);
  }
  std::vector<P> temp1(n),temp2(n);
  rep(i,0,n){
    temp1[i]=P(load.root(i),rail.root(i));
    temp2[i]=P(load.root(i),rail.root(i));
  }
  sort(all(temp1));
  rep(i,0,n){
    auto low=std::lower_bound(all(temp1),temp2[i]);
    auto up=std::upper_bound(all(temp1),temp2[i]);
    std::cout<<up-low<<" ";
  }
  return 0;
}

Measured memory_bytes: 8448
/*
for (int i = 0; i < N; ++i){}

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
 

int main() {
	// 入力
	ll X;
	cin >> X;
 
	// 解法
	if (X==7 | X==5 | X==3) cout << "YES" << endl;
	else cout << "NO" << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 100000000000;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<P> a(n);
	ll rmax = 0, rmin = INF, bmax = 0, bmin = INF;
	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		if (x > y) swap(x, y);
		rmax = max(rmax, x);
		rmin = min(rmin, x);
		bmax = max(bmax, y);
		bmin = min(bmin, y);
		a[i].first = x;
		a[i].second = y;
	}
	sort(a.begin(), a.end());

	ll ans = (rmax - rmin) * (bmax - bmin);

	rmax = bmax;
	ll d = a.back().first - a.front().first;
	ll ymin = a.front().second, ymax = a.front().second;
	for (int i = 1; i < n; i++) {
		d = min(d, max(ymax, a.back().first) - min(ymin, a[i].first));
		ymin = min(ymin, a[i].second);
		ymax = max(ymax, a[i].second);
	}
	d = min(d, ymax - ymin);
	ans = min(ans, (rmax - rmin) * d);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N, K;
    cin>>N>>K;
    vector<int> A(N);
    vector<int> B(N);
    for (int i=0; i<N; i++)
        cin>>A[i]>>B[i];
    long long ans = 0;
    for (int b=-1; b<=30; b++)
    if (b==-1 || (K>>b&1) == 1)
    {
        long long a = 0;
        for (int i=0; i<N; i++)
        {
            bool ok = true;
            for (int j=0; j<=30; j++)
                if (!((!(j==b) || (A[i]>>j&1)==0) &&
                      (!(j>b) || (!((K>>j&1)==0) || (A[i]>>j&1)==0))))
                    ok = false;
            if (ok)
                a += B[i];
        }
        ans = max(ans, a);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
const int maxn = 6010;
const int mod = 998244353;


int fac[maxn];
map <int,int> mp;


int expo(int x, int exp) {
	int res = 1, base = x;
	while (exp) {
		if (exp & 1) res = (res * base) % mod;
		base = (base*base) % mod;
		exp >>= 1;
	}
	return res;
}

int inv(int x) {
	if (mp.find(x) != mp.end()) return mp[x];
	else return mp[x] = expo(x,mod-2);
}


int choose(int N, int k) {
	return fac[N] * inv(fac[k]*fac[N - k] % mod) % mod;
}

int K,n;

int32_t main() {
	FAST
	cin >> K >> n;
	fac[0] = 1;
	for (int i =1; i<maxn;i++) fac[i] = fac[i-1] * i % mod;
	
	for (int i = 2;i <= 2 * K; i++) {
		int ans = 0;
		int pairs = i/2 - max(1ll, i - K) + 1;
		
		for (int x = 0; x <= pairs; x++) {
			if (n < x * 2) break;
			int v = choose(n - x*2 + K -1, n - x * 2) * choose(pairs,x) % mod;
			if (x % 2 == 0) ans = (ans + v) % mod; 
			else ans = (ans - v + mod) % mod;
			//cout << i << " " << x << " " << v << " " << ans << "\n";
		}
		cout << ans << "\n";
	}
}









Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

class SCCDecomp {
    int n;
    vvi adj;
    
public:
    vvi scc;
    SCCDecomp(int n) : n(n), adj(n) {}
    
    void addArc(int a, int b) {
        adj[a].push_back(b);
    }

    int run() {
        vi num(n), low(n);
        stack<int> S;
        vi inS(n);
        int t = 0;
        function<void(int)> visit = [&](int v) {
            low[v] = num[v] = ++t;
            S.push(v);
            inS[v] = 1;
            for (int s: adj[v]) {
                if (!num[s]) {
                    visit(s);
                    low[v] = min(low[v], low[s]);
                } else if (inS[s]) {
                    low[v] = min(low[v], num[s]);
                }
            }
            if (low[v] == num[v]) {
                scc.push_back(vi());
                while (1) {
                    int w = S.top();
                    S.pop();
                    inS[w] = false;
                    scc.back().push_back(w);
                    if (v == w) {
                        break;
                    }
                }
            }
        };

        for (int i = 0; i < n; i++) {
            if (num[i] == 0) {
                visit(i);
            }
        }

        return scc.size();
    }
};

int main() {
    int v, e;
    cin >> v >> e;
    SCCDecomp s(v);
    for (int i = 0; i < e; i++) {
        int a, b;
        cin >> a >> b;
        s.addArc(a, b);
    }

    int n = s.run();
    cout << (v != n) << endl;
}


Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#include<string>
using ll = long long;
using lli = long long int;
using namespace std;
const ll MM = 1000000000;
const ll mod = MM + 7;
int main(){
    bool flag = false;
    string a; cin >> a;
    int b[30] = {0};
    for(int i = 0; i < 27; i++){
        for(int j = 0; j < a.size(); j++){
            if(a[j] == 'a' + i) b[i]++;
        }
        if(b[i] % 2 != 0){
            flag = true;
            break;
        }
    }
    if(!flag) cout << "Yes";
    else cout << "No";
    cout << endl;
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())

if a > b or (n < 2 and a != b):
    ans = 0
elif a == b:
    ans = 1
else:
    x = n - 2
    mina = a * x
    maxb = b * x
    ans = maxb - mina + 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<min(a,b)+min(c,d)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
 
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0) 
#define F first
#define S second
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)5e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

int a, b, c, x, y;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	onlycin;
	cin >> a >> b >> c >> x >> y;
	int res = mod*2;
	updmin(res, x*a+y*b);
	updmin(res, max(x, y)*2*c);
	int mn = min(x, y);
	updmin(res, mn*2*c+(x-mn)*a+(y-mn)*b);
	cout << res << nxtl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 251
int main(){
  int A[MAX],n,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
  for(i=1;i<=n;i++) {
    printf("node %d: key = %d, ",i,A[i]);
    if(i/2>0) printf("parent key = %d, ",A[i/2]);
    if(i*2<=n) printf("left key = %d, ",A[i*2]);
    if(i*2+1<=n) printf("right key = %d, ",A[i*2+1]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 600
use std::cmp::min;

#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let mut comb = vec![vec![0i64; 51]; 51];
    comb[0][0] = 1;
    for i in 1..comb.len() {
        for j in 0..(i + 1) {
            comb[i][j] += comb[i - 1][j];
            if j > 0 {
                comb[i][j] += comb[i - 1][j - 1]
            }
        }
    }

    let (_, a, b) = scan!(usize, usize, usize);
    let mut vs = scan!(i64;;);
    vs.sort_by(|a, b| a.cmp(b).reverse());
    let ave = vs.iter().take(a).sum::<i64>() as f64 / a as f64;

    let mut ans = 0;
    if vs[0] == vs[a - 1] {
        let num = vs.iter().filter(|&&x| x == vs[a - 1]).count();
        for i in a..min(b + 1, num + 1) {
            ans += comb[num][i]
        }
    } else {
        let num0 = vs.iter().filter(|&&x| x == vs[a - 1]).count();
        let num1 = vs.iter().take(a).filter(|&&x| x == vs[a - 1]).count();
        ans = comb[num0][num1]
    }

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


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
	int n, i, j;
	ll a, b;
	cin >> n >> a >> b;
	if (a > b) {
		swap(a, b);
	}
	vl s(n + 1);
	s[0] = -INF;
	for (i = 1; i <= n; i++) {
		cin >> s[i];
	}
	for (i = 0; i <= n - 2; i++) {
		if (s[i + 2] - s[i] < a) {
			cout << 0 << endl;
			return 0;
		}
	}
	vl dp(n + 1);
	dp[0] = 1;
	vl sum(n + 2);
	sum[1] = 1;
	int last = 0;
	for (i = 1; i <= n; i++) {
		/*
		for (j = last; j < i; j++) {
			if (s[i] - s[j] < b) {
				break;
			}
			dp[i] += dp[j];
			dp[i] %= MOD;
		}
		*/
		auto itr = upper_bound(s.begin() + last, s.begin() + i, s[i] - b);
		int k = itr - s.begin();
		dp[i] += sum[k] - sum[last] + MOD;
		dp[i] %= MOD;
		sum[i + 1] = (sum[i] + dp[i]) % MOD;
		if (s[i] - s[i - 1] < a) {
			last = i - 1;
		}
	}
	//DEBUG_VEC(dp);
	ll ans = 0;
	for (i = last; i <= n; i++) {
		ans += dp[i];
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
 
#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 FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#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);
 
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 vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  string w;cin>>w;
  vi v(26,0);
  rep(i,w.size()){
    v[w[i]-'a']++;
  }
  string ans="Yes";
  rep(i,v.size()){
    if(v[i]%2!=0)ans="No";
  }
  cout(ans);
  return 0;
}

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

using namespace std;

int min(int a, int b, int c){
    int res;
    if(a <= b && a <= c){
        res = a;
    }else if( b <= c && b <= a){
        res = b;
    }else{
        res = c;
    }
    return res;
}

int main(){

    int n, x, y;
    cin >> n >> x >> y;
    int arr[2003] ={0, };

    for(int i=1; i<=n-1; i++){
        for(int j=i+1; j<=n; j++){
            int minDist = min(abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x));
            arr[minDist] += 1;
        }
    }

    for(int i=1; i<=n-1; i++){
        cout << arr[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

int a[201][201];
int dp[201][201];
int n;

int main(){

  string s;
  while(cin>>s){
    n++;
    int st=0;
    int cnt=0;
    for(int i=0;i<s.size();i++){
      if(s[i]==','){
	a[n-1][cnt++]=atoi(s.substr(st,i-st).c_str());
	st=i+1;
      }
      else if(i==s.size()-1)
	a[n-1][cnt++]=atoi(s.substr(st,i-st+1).c_str());
    }
  }

  for(int i=n-1;i>=0;i--){
    for(int j=0;j<n;j++){
      int res=0;
      if(i==n-1)res=0;
      else{
	if(i<n/2){
	  res=max(res,dp[i+1][j]+a[i+1][j]);
	  res=max(res,dp[i+1][j+1]+a[i+1][j+1]);
	}
	else{
	  if(j!=0)
	    res=max(res,dp[i+1][j-1]+a[i+1][j-1]);
	  if(j!=n-i-1)
	    res=max(res,dp[i+1][j]+a[i+1][j]);
	}
      }
      dp[i][j]=res;
    }
  }
  cout<<dp[0][0]+a[0][0]<<endl;

  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <algorithm>
using namespace std;

int m, n;
int ans = 0;
int dx[4] = {0,1,0,1}, dy[4] = {0,0,1,1};
char flag[1000][1000], hole[2][2], joi[3] = {'J', 'O', 'I'};

int main(){
	scanf("%d%d", &m, &n);
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++) scanf(" %c", &flag[i][j]);
	}
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 2; j++) scanf(" %c", &hole[i][j]);
	}
	for(int i = 1; i < m; i++){
		for(int j = 1; j < n; j++){
			if(flag[i-1][j-1]==hole[0][0]&&flag[i][j-1]==hole[1][0]&&flag[i-1][j]==hole[0][1]&&flag[i][j]==hole[1][1]) ans++;
		}
	}
	int paper = 0;
	for(int i = 0; i < m; i++){
		for(int j = 0; j < n; j++){
			int t = 0;
			char tmp = flag[i][j];
			for(int k = 0; k < 4; k++){
				if((i==0&&(k==0||k==2))||(j==0&&(k==0||k==1))||(i==m-1&&(k==1||k==3))||(j==n-1&&(k==2||k==3))) continue;
				if(flag[i-1+dx[k]][j-1+dy[k]]==hole[0][0]&&flag[i+dx[k]][j-1+dy[k]]==hole[1][0]&&flag[i-1+dx[k]][j+dy[k]]==hole[0][1]&&flag[i+dx[k]][j+dy[k]]==hole[1][1]) t++;
			}
			int ss = 0;
			for(int u = 0; u < 3; u++){
				int s = 0;
				flag[i][j] = joi[u];
				for(int k = 0; k < 4; k++){
					if((i==0&&(k==0||k==2))||(j==0&&(k==0||k==1))||(i==m-1&&(k==1||k==3))||(j==n-1&&(k==2||k==3))) continue;
					if(flag[i-1+dx[k]][j-1+dy[k]]==hole[0][0]&&flag[i+dx[k]][j-1+dy[k]]==hole[1][0]&&flag[i-1+dx[k]][j+dy[k]]==hole[0][1]&&flag[i+dx[k]][j+dy[k]]==hole[1][1]) s++;
				}
				ss = max(ss,s);
			}
			paper = max(paper,ss-t);
			flag[i][j] = tmp;
		}
	}
	printf("%d\n", ans+paper);
}

Measured memory_bytes: 2000