akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  vector<Int> X(N);
  cin>>X;
  for(Int &x:X) x--;

  vector<P> A(N);
  for(Int i=0;i<N;i++) A[i] = P(X[i], i);
  sort(A.begin(), A.end());


  vector<Int> used(N * N);
  vector<Int> ans(N * N);
  for(Int i=0;i<N;i++) used[ X[i] ] = 1, ans[ X[i] ] = i + 1;

  Int l = 0;
  for(Int i=0;i<N;i++){
    Int x, a; tie(x, a) = A[i];
    for(Int j=0;j<a;j++){
      while(l < N * N && used[l]) l++;
      if(l > x){cout<<"No"<<endl;return 0;}
      ans[l] = a + 1;
      used[l] = 1;
    }
  }
  Int r = N * N - 1;
  for(Int i=N-1;i>=0;i--){
    Int x, a; tie(x, a) = A[i];
    for(Int j=0;j<N - 1 - a;j++){
      while(r >= 0 && used[r]) r--;
      if(r < x){cout<<"No"<<endl;return 0;}
      ans[r] = a + 1;
      used[r] = 1;
    }
  }

  cout<<"Yes"<<endl;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    vector<string> w(N);
    for(int i = 0; i < N; i++)
    {
        cin >> w.at(i);
    }
    int judge = 0;
    for(int i = 0; i < N - 1; i++)
    {
        for(int j = i + 1; j < N; j++)
        {
            if(w.at(i) == w.at(j))
            {
                judge = 1;
                break;
            }
        }
    }
    for(int i = 0; i < N-1; i++)
    {
        if(w.at(i).at(w.at(i).size() - 1) != w.at(i+1).at(0))
        {
            judge = 1;
            break;
        }
    }
    if(judge == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) {//最大公約数
    if(a<b){
        ll tmp = a;
        a = b;
        b = tmp; 
    }
    if (b==0) return a;
    else return gcd(b, a%b);
}
ll lcm(ll a, ll b) {//最小公倍数
    return a * b / gcd(a, b);
}

int main(){
    int x,a; cin >> x >> a;
    if(x<a){
        cout << 0 << endl;
        return 0;
    }else{
        cout << 10 << endl;
        return 0;
    }
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int ansmin = 0, ansmax = 0;
	int n; cin >> n;
	bool b[10]; for (int i = 0; i < 10; i++)b[i] = false;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		if (a < 400)b[0] = true;
		else if (a < 800)b[1] = true;
		else if (a < 1200)b[2] = true;
		else if (a < 1600)b[3] = true;
		else if (a < 2000)b[4] = true;
		else if (a < 2400)b[5] = true;
		else if (a < 2800)b[6] = true;
		else if (a < 3200)b[7] = true;
		else {
			b[8] = true;
			ansmax++;
		}
	}
	for (int i = 0; i <= 7; i++) {
		if (b[i]) {
			ansmin++;
			ansmax++;
		}
	}
	if (!b[0] && !b[1] && !b[2] && !b[3] && !b[4] && !b[5] && !b[6] && !b[7] && b[8])ansmin = 1;
	cout << ansmin << ' ' << ansmax << endl;
}

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

const int maxn=300010;
int n;
char s[maxn];
int a[maxn], b[maxn];

void chkmin(int& x,int y){ if(x>y) x=y; }

int main(){

	scanf("%d", &n);
	scanf("%s", s+1);
	for(int i=1;i<=n;i++) a[i]=a[i-1]+(s[i]=='W');
	for(int i=n;i>=1;i--) b[i]=b[i+1]+(s[i]=='E');
	int ans=n;
	for(int i=1;i<=n;i++){
		chkmin(ans, a[i-1]+b[i+1]);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
const double PI = acos(-1.0);

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

#define NMAX 105
#define WMAX 10005
#define DIAGONAL 1
#define TOP 0

struct Item
{
  int value, weight;
};

int N, W;
Item items[NMAX + 1];
int C[NMAX + 1][WMAX + 1], G[NMAX + 1][WMAX + 1];

void compute(int &maxValue, vector<int> &selection)
{
  for (int w = 0; w <= W; w++)
  {
    C[0][w] = 0;
    G[0][w] = DIAGONAL;
  }
  for (int i = 1; i <= N; i++)
    C[i][0] = 0;

  for (int i = 1; i <= N; i++)
  {
    for (int w = 1; w <= W; w++)
    {
      C[i][w] = C[i - 1][w];
      G[i][w] = TOP;
      if (items[i].weight > w)
        continue;
      if (items[i].value + C[i - 1][w - items[i].weight] > C[i - 1][w])
      {
        C[i][w] = items[i].value + C[i - 1][w - items[i].weight];
        G[i][w] = DIAGONAL;
      }
    }
  }

  maxValue = C[N][W];
  selection.clear();
  for (int i = N, w = W; i >= 1; i--)
  {
    if (G[i][w] == DIAGONAL)
    {
      selection.push_back(i);
      w -= items[i].weight;
    }
  }

  reverse(selection.begin(), selection.end());
}

void input()
{
  cin >> N >> W;
  for (int i = 1; i <= N; i++)
  {
    cin >> items[i].value >> items[i].weight;
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int maxValue;
  vector<int> selection;
  input();
  compute(maxValue, selection);

  cout << maxValue << endl;
  return 0;
}

// i個目までの品物を考慮して大きさWのナップサックに入れる場合の価値の合計の最大値C[i][w]とする二次元配列
// C[i - 1][w - 品物iの重さ] + 品物iの価値，またはC[i - 1][w]の大きい方になる．1はこの時点で品物iを選択する．2.はこの時点で品物iを選択しない．ただし，1.の場合は品物iの重さが品物iの重さがwを超えない場合に限る．



Measured memory_bytes: 11064
#include"bits/stdc++.h"

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

int compute_score(int D, const vector<int> & c, const vector<vector<int>> & s, const vector<int> & t) {
	vector<int> last(26, 0);
	int v = 0;
	rep(i, D) {
		v += s[i][t[i]];
		last[t[i]] = i + 1;
		rep(j, 26) {
			v -= c[j] * (i + 1 - last[j]);
		}
		//デバッグ用
		if (false) { cout << v << endl; }
	}

	return v;
}

int main(void) {
	//========================================
	
	int D; cin >> D;
	vector<int> c(26); rep(i, 26)cin >> c[i];
	vector<vector<int>> s(D, vector<int>(26));
	rep(i, D) {
		rep(j, 26)cin >> s[i][j];
	}

	//=========================================

	vector<int> t(D);
	rep(i, D)t[i] = rand() % 26;
	
	//=========================================

	for (int x : t) {
		cout << x + 1 << endl;
	}

	//=========================================

	return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    int K, X; cin >> K >> X;
    if (500*K >= X) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 896
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			final int n = in.nextInt();
			final int k = in.nextInt();
			if (n == 0 && k == 0) {
				System.exit(0);
			}
			int max = Integer.MIN_VALUE, val = 0;
			Deque<Integer> deq = new ArrayDeque<Integer>(k);
			for (int i = 0; i < n && in.hasNext(); i++) {
				final int number = in.nextInt();
				if (i < k) {
					val += number;
					max = val;
				} else {
					final int f = deq.pollFirst();
					val += (number - f);
					if (val > max) {
						max = val;
					}
				}
				deq.offerLast(number);

			}
			System.out.println(max);
		}

	}
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = ReadInt();
            var s = Read();
            if (a >= 3200)
            {
                WriteLine(s);
            }
            else
            {
                WriteLine("red");
            }
        }

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

        public static void debuglist(List<int> x)
        {
            foreach (var item in x)
            {
                WriteLine(item);
            }
        }
        public static void debuglist(List<string> x)
        {
            foreach (var item in x)
            {
                WriteLine(item);
            }
        }
        public static void debugarray(int[] x)
        {
            foreach (var item in x)
            {
                WriteLine(item);
            }
        }
        public static void debugarray(string[] x)
        {
            foreach (var item in x)
            {
                WriteLine(item);
            }
        }

        public static bool IsPrime(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false;

            double sqrtNum = Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    return false;
                }
            }
            return true;
        }

        //最大公約数
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

        //文字数を数える
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
    }
}


Measured memory_bytes: 13140
/*

	Author : @karngyan
	Team : BlundersPride
	Date : 09-03-2019
	Time : 05:20:14

	*/


	#include<bits/stdc++.h>
	//#include <ext/pb_ds/assoc_container.hpp>
	//using namespace __gnu_pbds;
	//typedef tree<int,null_type,less<int>,rb_tree_tag,
	//tree_order_statistics_node_update> indexed_set;
	using namespace std;

	typedef long long ll;
	typedef long double ld;
	typedef std::vector<ll> vll;
	typedef std::pair<ll,ll> pll;
	typedef std::vector<vll> vvll;

	#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	#define endl '\n'
	#define pb push_back
	#define rep(i,a,b) for(ll i=a;i<b;++i)
	#define rrep(i,a,b) for(ll i=a;i>b;--i)
	#define max3( a, b, c ) max( a , max(b , c))
	#define cres(c,n) (c).clear(),(c).resize(n)
	#define all(a) (a).begin(), (a).end()
	#define rall(a) (a).rbegin(), (a).rend()
	#define ff first
	#define ss second
	#define mk make_pair


	ll f(ll a)
	{
		if(a <= 0)
			return 0;
		if(a%4 == 1)
			return 1;
		if(a%4 == 2)
			return a+1;
		if(a%4 == 3)
			return 0;
		if(a%4 == 0)
			return a;
	}
	signed main()
	{
		fast;
	////////////////////////////////////////////////////////////////////////////////////////////
		
		ll a , b ;
		cin >> a >> b;
		ll ans = f(b)^f(a-1);

		cout<<ans<<endl;





	////////////////////////////////////////////////////////////////////////////////////////////
		
		return 0;
	}



Measured memory_bytes: 256
mod=10**9+7
fact=[1]
for i in range(1,5*10**5+1):
  fact.append((fact[-1]*i)%mod)
revfact=[1]
for i in range(1,5*10**5+1):
  revfact.append(pow(fact[i],mod-2,mod))
n,m=map(int,input().split())
patternA=(fact[m]*revfact[n]*revfact[m-n]*fact[n])%mod
patternB=patternA
for i in range(1,n+1):
  tmp=(fact[n]*revfact[i]*revfact[n-i])*(fact[m-i]*revfact[n-i]*revfact[m-n])*fact[n-i]
  if i%2==0:
    patternB+=tmp
    patternB%=mod
  else:
    patternB-=tmp
    patternB%=mod
print((patternA*patternB)%mod)

Measured memory_bytes: 158664
n = int(input())
t_co = h_co = 0

for i in range(n):
    t_str, h_str = list(map(str, input().split()))
    
    if t_str > h_str:
        t_co += 3
    
    elif h_str == t_str:
        t_co += 1
        h_co += 1
    else:
        h_co += 3
        
print(t_co, h_co)



Measured memory_bytes: 5596
package main

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

func main() {
	sc := NewScanner()
	L, R, d := sc.NextInt(), sc.NextInt(), sc.NextInt()
	cnt := 0
	for i := L; i <= R; i++ {
		if i%d == 0 {
			cnt++
		}
	}
	fmt.Println(cnt)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 1772
n = input()
ue = int(n[:2])
shita = int(n[2:])

if 1 <= ue and ue <= 12 and 1 <= shita and shita <= 12:
    print('AMBIGUOUS')
elif 1<=shita and shita <= 12:
    print('YYMM')
elif 1<=ue and ue <= 12:
    print('MMYY')
else:
    print('NA')


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

int main (void){
    int a, b, c, x;
    cin >> a >> b >> c;
    x = c - (a - b);
    if(0 < x){
        cout << x << endl;
    }else{
        cout << "0" << endl;
    }
    return 0;
}



Measured memory_bytes: 3536
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>


#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define vint vector<int>
#define INF 1e9

using namespace std;
typedef long long  ll;

int main(){
    int n, k;
    cin >> n >> k;
    vint ans(n, 1);
    int d;
    int tmp;
    REP(i, 0, k){
        cin >> d;
        REP(j, 0, d){
            cin >> tmp;
            ans[tmp-1] = 0;
        }
    }

    p(accumulate(ans.begin(), ans.end(), 0LL));

    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll

typedef vector<int> vi;
typedef pair<int,int> pii;

signed main(void) {
  int i,j;
  int n,k;
  cin>>n>>k;
  pii p[100000];
  rep(i,n)cin>>p[i].first>>p[i].second;
  sort(p,p+n);
  ll sum=0;
  rep(i,n){
    sum+=p[i].second;
    if(sum>=k){
      cout<<p[i].first<<endl;
      return 0;
    }
  }
}


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


int main(){
	string str;
	cin>>str;
	int ans;
	if(str=="SSS")ans=0;
	else if(str=="SSR")ans=1;
	else if(str=="SRS")ans=1;
	else if(str=="RSS")ans=1;
	else if(str=="RRS")ans=2;
	else if(str=="RSR")ans=1;
	else if(str=="SRR")ans=2;
	else ans=3;
	cout<<ans<<endl;
	return 0; 
}


Measured memory_bytes: 3616
{-# OPTIONS_GHC -O #-}

import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main=do
    n <- readLn
    ss <- replicateM (n-1) $ unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine
    --
    forM_ (tails ss) $ \s -> do print $ solve 0 s

solve t [] = t
solve t (([c,s,f]):ss)
    | t < s = solve (s+c) ss
    | True  = solve (((t+f-1)`div`f)*f+c) ss

Measured memory_bytes: 1020
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


int n, k;
double ans;
double p[200005];
  
int main() {

	cin >> n >> k;
	REP(i, 1, n + 1) {
		cin >> p[i];
		p[i] = p[i - 1] + (1 + p[i]) / 2;
	}

	REP(i, k, n + 1) {
		ans = max(ans, p[i] - p[i - k]);
	}

	cout << fixed << setprecision(10) << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

typedef long long ll;

const int N=2e5+50,P=1e9+7;

int mul(int a,int b){ return 1ll*a*b%P; }
int mul(int a,int b,int c){ return mul(a,mul(b,c)); }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int power(int a,int k){
	int res=1;
	for(;k;k>>=1,a=mul(a,a)){
		if(k&1){
			res=mul(res,a);
		}
	}
	return res;
}
int inverse(int x){ return power(x,P-2); }

int n,a[N],g[N],cnt[N],ans,L[N],R[N];
struct BinaryIndexedTree{
	int c[N],res;
	void update(int p,int k){
		for(;p<=n;p+=p&-p)c[p]=add(c[p],k);
	}
	int query(int p){
		for(res=0;p>=1;p-=p&-p)res=add(res,c[p]); 
		return res;
	}
	void clear(){
		memset(c,0,sizeof(c)); 
	}
} trG,trC;

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
//	freopen("my.out","w",stdout);
#endif
	cin>>n;
	rep(i,1,n){
		cin>>a[i]; 
		++cnt[a[i]];
	}
	dec(i,n-1,1)cnt[i]+=cnt[i+1];
	int prod=1;
	rep(i,1,n){
		cnt[i]-=n-i;
		if(cnt[i]<=0){
			puts("0");
			return 0;
		}
		prod=mul(prod,cnt[i]);
		if(i==1||cnt[i]==1){
			L[i]=i;
			g[i]=1;
		}else {
			L[i]=L[i-1];
			g[i]=mul(cnt[i]-1,inverse(cnt[i]));
			g[i]=mul(g[i-1],g[i]);
		}
	}
	dec(i,n,1){
		if(i==n||cnt[i]==1||cnt[i+1]==1)R[i]=i;
		else R[i]=R[i+1];
	}
	rep(i,1,n){
		int up=mul(g[a[i]],sub(trG.query(a[i]),trG.query(L[a[i]]-1)));	
		ans=add(ans,mul(prod,up,inverse(2)));
		trG.update(a[i],inverse(g[a[i]]));	
	}
	trG.clear(); 
	rep(i,1,n){
		int tot=mul(prod,sub(trC.query(n),trC.query(a[i])));
		int unl=mul(prod,mul(inverse(g[a[i]]),sub(trG.query(R[a[i]]),trG.query(a[i]))),inverse(2));
		ans=add(ans,sub(tot,unl));
		trG.update(a[i],g[a[i]]);
		trC.update(a[i],1);
	}
	printf("%d\n", ans);
	return 0;
}

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

int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    int ax = abs(x - a);
    int bx = abs(x - b);

    if (ax < bx)
    {
        cout << 'A' << endl;
    }
    else
    {
        cout << 'B' << endl;
    }
    
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    int l[2 * n];
    rep(i, 2 * n) cin >> l[i];

    sort(l, l + 2 * n);

    int sum = 0;

    rep(i, n) sum += l[i * 2];

    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double ans = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    printf("%.8f\n", ans);
    return 0;
}


Measured memory_bytes: 3228
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:16777216")
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>  
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(A,value) memset(A,value,sizeof(A))

#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair
const double PI=acos(-1.0);

typedef long long Int;
typedef long long LL;
typedef unsigned long long UINT;
typedef vector <int> VI;
typedef pair <int, int> PII;
typedef pair <double, double> PDD;

const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 500000;
const int MAX2 = 20007;
const int IT = 18;
const int BASE = 1000000000;
const int CNT = 300;
const int MOD = 1000000007;

int n;
char S[MAX];


int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);


    scanf("%s", S);
    n = strlen(S);
    
    Int res = 0, cnt = 0;
    for (int i = 0; i+1 < n; ++i)
    {
      if (S[i] == 'B' && S[i+1] == 'C')
      {
        res += cnt;
        ++ i;
      }
      else
      if (S[i] == 'A') ++ cnt;
      else cnt = 0;
      
    }

    cout << res << endl;

 
    return 0;
}



Measured memory_bytes: 384
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val n = in.readLine()

    val c = n.charAt(n.length - 1).toInt - '0'

    out.println(
      if (List(2, 4, 5, 7, 9).contains(c)) {
        "hon"
      } else if (List(0, 1, 6, 8).contains(c)) {
        "pon"
      } else {
        "bon"
      }
    )

    out.flush()
  }
}


Measured memory_bytes: 54536
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int h, w, d, n;
	boolean[][] map, map2;
	int[] r;
	int[] X, Y, s;
	int sx, sy;
	
	final String YES = "Yes", NO = "No", UNKNOWN = "Unknown", BROKEN = "Broken";
	
	void run() {
		Scanner sc = new Scanner(System.in);
		h = sc.nextInt(); w = sc.nextInt(); d = sc.nextInt(); n = sc.nextInt();
		map2 = new boolean[h+2][w+2];
		map = new boolean[h+2][w+2];
		for (int y=1;y<=h;y++) {
			String s = sc.next();
			for (int x=0;x<w;x++) {
				switch (s.charAt(x)) {
				case '#':
					map[y][x+1] = map2[y][x+1] = false;
					break;
				case 'D':
					sx = x+1; sy = y;
				default:
					map[y][x+1] = map2[y][x+1] = true;
				}
			}
		}
		
		r = new int[d];
		for (int i=0;i<d;i++) r[i] = sc.nextInt();
		
		X = new int[n]; Y = new int[n]; s = new int[n];
		for (int i=0;i<n;i++) {
			X[i] = sc.nextInt() + 1; Y[i] = sc.nextInt() + 1; s[i] = sc.nextInt();
		}
//		debug(X, Y);
		System.out.println(solve());
	}
	
	String solve() {
		boolean yes = false, no = false;
		dfs(sx, sy);
		for (int x = 1;x <= w;x++) for (int y = 1; y <= h;y++) if (map2[y][x]){
			boolean f = ok(x, y);
			yes |= f & ! map[y][x];
			no  |= f & map[y][x];
			if (f) {
//				debug("ok", x, y);
			}
		}
		
		if (yes&no) return UNKNOWN;
		if (yes) return YES;
		if (no) return NO;
		return BROKEN;
		
	}
	
	int[] dx = {-1,0,1,0}, dy = {0,-1,0,1};
	void dfs(int x, int y) {
		map[y][x] = false;
		
		for (int i=0;i<4;i++) if (map[y+dy[i]][x+dx[i]]) 
			dfs(x+dx[i], y+dy[i]);
	}
	
	boolean ok(int x, int y) {
		for (int i=0;i<n;i++) {
			if (s[i] == r.length) {
//				debug("out", x, y, abs(x - X[i]), abs(y - Y[i]), r[r.length-1]);
				if (max(abs(x - X[i]), abs(y - Y[i]) ) <= r[r.length-1]) return false;
			}
			else if (s[i] == 0){
//				debug("in ", x, y, abs(x - X[i]), abs(y - Y[i]), r[s[i]]);
				if (max(abs(x - X[i]), abs(y - Y[i]) ) > r[s[i]]) return false; 
			}
			else {
				if (max(abs(x - X[i]), abs(y - Y[i]) ) > r[s[i]] || max(abs(x - X[i]), abs(y - Y[i]) ) <= r[s[i]-1]) return false; 
			}
		}
		return true;
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

Measured memory_bytes: 20460
#include<bits/stdc++.h>
using namespace std;
int main(){

  int A,B,count=0;
  cin >> A >> B;
  for(int i=A;i<=B;i++){
  	int a,b,c,d;
    a=i/10000;
    b=i/1000%10;
    c=i/10%10;
    d=i%10;
      if(a==d && b==c){
          count++;
      }
    } 
  cout << count << endl;

  }
  

Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
using namespace std;
int a[101],n,k;
bool cmp(int a,int b){
    return a>b;
}
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1,cmp);
    int tot=0;
    for(int i=1;i<=k;i++) tot+=a[i];
    cout<<tot<<endl;
    return 0;
}

Measured memory_bytes: 256
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin>>n;
	int k;
	cin>>k;
	vi v(n);
	rep(i,n){
		cin>>v[i];
	}	
	sort(all(v));
	ll ans = 0;
	rep(i,n-k){
		ans += v[i];
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
	do {\
		std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
		debug_impl(__VA_ARGS__);\
		std::cerr << std::noboolalpha;\
	} while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
	{ for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
	for (auto it = v.begin(); it != v.end(); it++)
		{os << (it != v.begin() ? "," : "") << *it;}
	return os << "}";
}

int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	lint n, k; std::cin >> n >> k;
	std::vector<lint> a(n); std::cin>>a;
	for (lint & x : a) x--;
	debug(a);

	std::vector<lint> mul(n,0);
	for (lint x : a) mul.at(x) ++;
	std::sort(all(mul));
	debug(mul);
	loop(k) mul.pop_back();
	lint ans = std::accumulate(all(mul),0ll);
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 3456
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1e9 as usize + 9;

fn main() {
    input! {
        q: usize,
        queries: [[i64; eol]; q],
    }

    let mut maxheap = BinaryHeap::new();
    let mut minheap = BinaryHeap::new();

    let mut sum = 0;
    for query in queries {
        if query.len() == 1 {
            println!("{} {}", maxheap.peek().unwrap(), sum);
        } else {
            let a = query[1];
            let b = query[2];
            sum += b;
            maxheap.push(a);
            minheap.push(-a);
            if *maxheap.peek().unwrap() > -minheap.peek().unwrap() {
                let maxv = maxheap.pop().unwrap();
                let minv = -minheap.pop().unwrap();
                maxheap.push(minv);
                minheap.push(-maxv);
                sum += (maxv - minv).abs();
            }
        }
    }
}


Measured memory_bytes: 17332
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    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;
}

template<typename T>
inline void remax(T& x, T y) { x = max(x, y); }

template<typename T>
inline void remin(T& x, T y) { x = min(x, y); }

int main() 
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for(int& x : v) cin >> x;
    int lo = 1, hi = *(max_element(all(v)));
    
    auto can_cut = [&] (int max_piece) {
        int cuts = 0;
        for(int i = 0; i < n; ++i)
        {
            if(v[i] <= max_piece) continue;
            else {
                int need = v[i] / max_piece;
                cuts += need;
                if(cuts > k) return false;
            }
        }
        return true;
    };
    
    while(lo < hi)
    {
        int mid = (lo + hi) / 2;
        if( can_cut(mid) ) hi = mid;
        else lo = mid + 1;
    }

    cout << lo << '\n';
    return 0;
}





Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define x first
#define y second
#define N 131072
#define pi acos(-1)
int mod=998244353;
LL fra[10005];
LL inv[10005];
LL f_pow(LL a,LL b){
	LL res=1,temp=a;
	while(b){
		if(b&1)res=res*temp%mod;
		temp=temp*temp%mod;
		b>>=1;
	}
	return res;
}
void build(){
	fra[0]=1;
	for(int i = 1;i<10005;i++){
		fra[i]=fra[i-1]*i%mod;
	}
	inv[10004]=f_pow(fra[10004],mod-2);
	for(int i = 10003;i>=0;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
}
LL C(LL a,LL b){
	return fra[a]*inv[b]%mod*inv[a-b]%mod;
}
int main(){
	build();
	int n,x;
	scanf("%d %d",&n,&x);
	int len[3005];
	fill(len,len+n+1,0);
	len[0]=1;
	for(int i = 1;i<=n;i++){
		for(int j = 0;j<x;j++){
			int two=j-i,one=i-two;
			if(one<0||two<0)
			continue;
			//printf("%d %d\n",two,one);
			len[i]+=C(two+one,one);
			len[i]%=mod;
		}
		if(x&1){
			if(i*2>x)
				len[i]++;
		}
	//	printf("%d\n",len[i]);
		if(i>=2){
			for(int k = 2;k<=i;k+=2){
				int templ=i-k;
				int j = x-1-k;
				int two= j-templ,one=templ-two;
				if(one<=0||two<0){
					//printf("%d\n",len[i]);
					//continue;
				}
				else{
					len[i]+=C(two+one,one);
					len[i]%=mod;
				}
			}
		}
	//	printf("%d\n",len[i]);
	}
	LL ans=0;
	for(int i = 0;i<=n;i++){
		ans+=len[i]*C(n,i)%mod;
	//	printf("%d %d\n",len[i],C(n,i));
		ans%=mod;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println(solve());
	}
	
	public static String solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		return (N == 3 || N == 5 || N == 7) ? "YES" : "NO";
	}
}

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

int main()
{
    int n;
    unsigned long long result = 1, border = 1000000000000000000;

    cin >> n;

    vector<unsigned long long> a(n);

    for (int i = 0; i < n ; i++)
    {
        cin >> a.at(i);
        if(0 == a.at(i))
        {
            cout << 0 << endl;
            return 0; 
        }
    }
    sort(a.begin(),a.end());

    for (int i = 0; i < n ; i++)
    {
        result *= a.at(i);
        border /= a.at(i);

        if(border <= 0 )
        {
            cout << -1 << endl;
            return 0;        
        }
    }

    cout << result << endl;
    return 0;
}

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


int main(){
    int n, arr[100], key;
    while(scanf("%d", &n) != EOF && n){
        for(int x = 0; x < n; x++){
            scanf("%d", &arr[x]);
        }
        scanf("%d", &key);
        int left = 0, right = n-1, mid, count = 0;
        while(left <= right){
            count++;
            mid = (left + right) / 2;
            if(arr[mid] == key) break;
            if(arr[mid] < key) left = mid + 1;
            if(arr[mid] > key) right = mid - 1;
        }
        printf("%d\n", count);
    }
    return 0;
}

Measured memory_bytes: 1028
# -*- coding: utf-8 -*-

A, B, C, D = map(int, input().split())


def gcd(a, b):
    while b:
        a, b = b, a % b

    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def f(n):
    res = n
    res -= n // C
    res -= n // D
    res += n // lcm(C, D)

    return res

ans = f(B) - f(A - 1)

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

int main()
{
    ll N;
    cin >> N;

    vector<ll> A(N);
    rep (i, N) { cin >> A[i]; }

    ll yen = 1000;
    ll num = 0;

    ll i=0;

    while (i + 1 < N)
    {
        while (i + 1 < N && A[i + 1] < A[i]) { ++i; }
        if (i + 1 == N) { break; }

        num = yen / A[i];
        yen -= num * A[i];

        ll j = i;
        while (j + 1 < N && A[j + 1] >= A[j]) { ++j; }

        yen += num * A[j];
        num = 0;

        i = j + 1;
    }

    // if (num != 0) { yen += num * A[N - 1]; }

    cout << yen << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <cmath>
#include <string>
#include <stdio.h>

#define rep(i,b,e) for (int (i) = (b); (i) < (e); (i)++)
typedef long long ll;


using namespace std;

int main() {

    string S;
    long K;
    cin >> S >> K;

    string ans = "1";
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != '1') {
            ans = S[i];
            break;
        }
        if (K-i == 1) {
            break;
        }
    }

    cout << ans << endl;
}

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

int winner(int a, int b)
{
  if (a == 1 && b == 2) return (1);
  else if (a == 2 && b == 3) return (2);
  else if (a == 1 && b == 3) return (3);
}

int main()
{
  int input[5];

  while (scanf("%d", &input[0]), input[0]){
    bool check[4] = {false};
    check[input[0]] = true;
    for (int i = 1; i < 5; i++){
      scanf("%d", &input[i]);
      check[input[i]] = true;
    }
    bool only = false;
    int cnt = 0;
    for (int i = 1; i <= 3; i++){
      if (!check[i]) cnt++;
    }
    if (cnt == 2) only = true;

    if ((check[1] && check[2] && check[3]) || only){
      for (int i = 0; i < 5; i++) printf("3\n");
    }
    else {
      int tmp[2];
      for (int i = 1, j = 0; i <= 3; i++){
        if (check[i]) tmp[j++] = i;
      }
      int win = winner(tmp[0], tmp[1]);
      for (int i = 0; i < 5; i++){
        if (input[i] == win){
          printf("1\n");
        }
        else {
          printf("2\n");
        }
      }
    }
  }

  return (0);
}

Measured memory_bytes: 1168
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[][] a = new long[n][2];
		int add = 0;
		for (int i = 0; i < n; ++i) {
			a[i][0] = sc.nextInt() - k;
			a[i][1] = i;
			if (i > 0) {
				a[i][0] += a[i - 1][0];
			}
			if (a[i][0] >= 0) {
				++add;
			}
		}
		Arrays.sort(a, new Comparator<long[]>() {
			@Override
			public int compare(long[] o1, long[] o2) {
				return Long.compare(o1[0], o2[0]);
			}
		});

		int[] arr = new int[n];
		int p = 0;
		for (int i = 0; i < n; ++i) {
			if (i > 0) {
				if (a[i][0] != a[i - 1][0]) {
					++p;
				}
			}
			arr[(int) a[i][1]] = p;
		}
		solve(n, arr, add);
	}

	void solve(int n, int[] arr, int add) {
		int[][] e = new int[n][2];
		for (int i = 0; i < n; ++i) {
			e[i][0] = arr[i];
			e[i][1] = i;
		}
		Arrays.sort(e, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				if (o1[0] != o2[0]) {
					return Integer.compare(o1[0], o2[0]);
				} else {
					return Integer.compare(o1[1], o2[1]);
				}
			}
		});
		BIT bit = new BIT(n);
		long ans = 0;
		for (int i = 0; i < n; ++i) {
			ans += bit.get(e[i][1]);
			bit.add(e[i][1]);
		}
		System.out.println(ans + add);
	}


	class BIT {
		int n;
		int[] v;

		public BIT(int n) {
			this.n = n;
			v = new int[n + 1];
		}

		void add(int k) {
			++k;
			while (k < v.length) {
				++v[k];
				k += k & -k;
			}
		}

		int get(int k) {
			++k;
			int s = 0;
			while (k > 0) {
				s += v[k];
				k -= k & -k;
			}
			return s;
		}

	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i < n+1; i+=2) {
        int count = 0;
        for (int j = 1; j < i+1; j++) {
            if (i%j == 0) {
                count++;
            }
        }
        if (count == 8) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(void){
  int N; cin >> N;
  vector<int> S(N);
  for(int i = 0; i < N; i++) cin >> S[i];
  int M; cin >> M;
  vector<int> T(M);
  for(int i = 0; i < M; i++) cin >> T[i];

  int ans = 0;

  for(int i = 0; i < M; i++){
    int key = T[i];
    int l = 0, r = N;
    while(l < r - 1){
      int mid = (l+r) / 2;
      if(S[mid] > key){
        r = mid;
      }else{
        l = mid;
      }
    }
    if(S[l] == key) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1564
import std.algorithm;
import std.array;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

bool ask (long value)
{
	writeln ("? ", value);
	stdout.flush ();
	return readln.strip == "Y";
}

void answer (long value)
{
	writeln ("! ", value);
	stdout.flush ();
}

void main ()
{
	long lo = 1;
	bool rem = false;
	while (true)
	{
		auto x = ask (lo);
		auto y = ask (lo * 10 - 1);
		if (x && !y)
		{
			rem = true;
		}
		if (x && y && rem)
		{
			break;
		}
		if (!x && y)
		{
			lo /= 10;
			break;
		}
		if (lo >= int.max * 10L)
		{
			lo = 1;
			break;
		}
		lo *= 10;
	}

	long hi = lo * 10 - 1;
	while (lo < hi)
	{
		long me = (lo + hi) / 2;
		if (ask (me * 10))
		{
			hi = me;
		}
		else
		{
			lo = me + 1;
		}
	}

	answer (lo);
}


Measured memory_bytes: 596