akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char* argv[]){
  std::string s;
  int n;
  std::getline(std::cin, s);
  std::cin >> n;
  std::vector<std::string> ss;

  for (std::size_t i = 0; i < s.length(); i++) {
    for (std::size_t len = 1; len <= s.length() ; len++){
      if (len + i > s.length()){
        break;
      }
      std::string a = s.substr(i, len);
      if(ss.size() == 0){
        ss.push_back(a);
      } else if (ss.size() >= 5){
        if (ss[4] <= a){
          break;
        }
      }
      for (size_t order = 0; order < 5; order++){
        if (ss[order] > a){
          ss.insert(ss.begin() + order, a);
          break;
        } else if (ss[order] == a) {
          break;
        } else if (order == ss.size() - 1){
          ss.push_back(a);
          break;
        }
      }

    }
  }

  std::cout << ss[n - 1] << std::endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;

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

	int n,k;
	cin >> n >> k;

	if(n%k == 0) cout << 0 << "\n";
	else		cout << 1 << "\n";

	return 0;
}

Measured memory_bytes: 256
var input = require("fs").readFileSync("/dev/stdin", "utf8");

var lines = input.split('\n');
var N = Number(lines[0]);
var words = lines[1].split(' ');

function countDiv2(n, count) {
    if (!n || n % 2) {
        return count;
    }
    var result = n / 2;
    return countDiv2(result, count + 1);
}

var min = 30;
for (var i = 0; i < N; i++) {
    var n = Number(words[i]);
    var count = countDiv2(n, 0);
    min = Math.min(min, count);
}
console.log(min);


Measured memory_bytes: 9420
#include <bits/stdc++.h>
int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int k, x; std::cin >> k >> x;
  for (int i = x - k + 1; i <= x + k - 1; i++) {
    std::cout << (i > x - k + 1 ? " " : "") << i;
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main(){
  int n;
  string s;
  cin>>n;
  cin>>s;
  if(n>=3200){
    cout<<s<<endl;
  }
  else{
    cout<<"red"<<endl;
  }
  return 0;
}


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

using namespace std;

int dp[100001];
int h[100001];

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

    int n, k;
    cin >> n >> k;
    if (n == 1) {
        cout << 0;
        return 0;
    }

    for (int i = 0; i < n; i++){
        cin >> h[i];
    }
    if (n == 2) {
        cout << abs(h[0]-h[1]);
        return 0;
    }

    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);

    for (int i = 2; i < n; i++) {
        int m = INT_MAX;
        for (int j = 1; j <= k && i-j >= 0; j++) {
            m = min(m, dp[i-j] + abs(h[i-j]-h[i]));
        }
        dp[i] = m;
    }

    cout << dp[n-1];


    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	double a,b,c,d,e,f,g=0,x=0,y=0;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=-1){
		if(a!=0){
			y=(f-c*d/a)/(e-b*d/a);
			x=(c-b*y)/a;
		}else{
			x=(f-c*e/b)/d;
			y=c/b;
		}
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

typedef pair<int, int> P;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int N, a, b, c, x;
    while( cin >> N >> a >> b >> c >> x, N | a | b | c | x ){
        vector<int> ran( N );
        REP( i, N ) cin >> ran[i];

        int ans = -1;
        int reel = 0;
        REP( i, 10001 ){
            if( x == ran[reel] ) reel++;
            if( reel == N ){
                ans = i;
                break;
            }
            x = ( a * x + b ) % c;
        }

        cout << ans << endl;
    }
}



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

int main() {
	int n, x, y;
	cin >> n >> x >> y;
	vector<long long>ans(n-1,0);
	for (int i = 1; i <= n - 1; i++) {
		for (int j = i + 1; j <= n; j++) {
			long long res = 0;
			if (i <= x && y <= j)res = j - i - (y - x - 1);
			else if (i <= x && x <= j && j <= y)res = min(j - i, y - j + 1 + x - i);
			else if (x <= i && i <= y && y <= j)res = min(j - i, i - x + 1 + j - y);
			else if (x <= i && i <= y && x <= j && j <= y)res = min(j - i, i - x + 1 + y - j);
			else res = j - i;
			ans.at(res - 1)++;
			//cout << i << " " << j << " " << res << endl;
		}
	}

	for (int i = 0; i < n-1; i++)cout << ans.at(i) << endl;
}

Measured memory_bytes: 256
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


N, X = map(int, input().split())
x = list(map(lambda s: abs(int(s) - X), input().split()))

if len(x) < 2:
    print(x[0])
    exit()
d = gcd(x[0], x[1])

for i in range(2, len(x)):
    d = gcd(d, x[i])
print(d)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
   T res = 1;
   for(;n;n>>=1) {
      if (n & 1) res = res * a;
      a = a * a;
   }
   return res;
}


const ll MAX = 110;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

ll dp[110][110][260]={};

signed main(){
    COMinit();
   cin.tie(0);ios::sync_with_stdio(false);
   cout<<fixed<<setprecision(20);
    ll n,K;cin>>n>>K;
    vector<ll> v(n);rep(i,0,n)cin>>v[i];
    dp[0][0][0]=1;

    rep(i,0,n){
        rep(j,0,i+1){
            rep(k,0,256){
                (dp[i+1][j+1][k^v[i]]+=dp[i][j][k])%=mod;
                (dp[i+1][j][k]+=dp[i][j][k])%=mod;
            }
        }
    }

    ll ans=0;
    rep(i,0,101){
        ll add=dp[n][i][K];
        add*=fac[i];
        add%=mod;
        (ans+=add)%=mod;
    }
    cout<<ans<<endl;


}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 22912
n=int(input())
a=list(map(int,input().split()))
fg=[1,-1]
ret = [0]*2
tot = [0]*2
for i in range(n):
  for j in range(2):
    tot[j]+=a[i]
    if tot[j]*fg[j]<=0:
      ret[j] += abs(fg[j] - tot[j])
      tot[j] += fg[j] - tot[j]
    fg[j]*=-1
print(min(ret))

Measured memory_bytes: 14332
#D

line = [int(x) for x in input().split()]
n = line[0]
x = line[1]
y = line[2]

results =[0]*(n+2)

for i in range(1, n):
    for j in range(i+1,n+1):
        results[min([abs(j-i), abs(x-i) + 1 + abs(j-y)])-1] += 1

for i in range(0, n-1):
    print(results[i])



Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(void){
    vector<int> a;
    int ans = 1000;
    for(int i = 0;i < 5;i++){
        int r;
        cin >> r;
        a.push_back(r);
    }
    do{
        int tmp = 0;
        for(int i = 0;i < 5;i++){
            if(tmp % 10 == 0) tmp += a[i];
            else tmp += (10-a[i-1]%10),tmp += a[i];
        }
        ans = min(ans,tmp);
    }while(next_permutation(a.begin(),a.end()));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,k;
	cin >> n >> k;
	vi v(n);
	rep(i,0,n)cin >> v[i];
	sort(all(v));
	cout << accumulate(v.begin(), v.begin()+k,0) << '\n';
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  int a[6];
  for(int i = 0; i < 6; i++)
    cin >> a[i];
  string s;
  cin >> s;
  for(int i = 0; i < s.length(); i++) {
    if(s[i] == 'E') {
      int temp = a[0];
      a[0] = a[3];
      a[3] = a[5];
      a[5] = a[2];
      a[2] = temp;
    }
    if(s[i] == 'N') {
      int temp = a[0];
      a[0] = a[1];
      a[1] = a[5];
      a[5] = a[4];
      a[4] = temp;
    }
    if(s[i] == 'S') {
      int temp = a[0];
      a[0] = a[4];
      a[4] = a[5];
      a[5] = a[1];
      a[1] = temp;
    }
    if(s[i] == 'W') {
      int temp = a[0];
      a[0] = a[2];
      a[2] = a[5];
      a[5] = a[3];
      a[3] = temp;
    }
  }
  cout << a[0] << endl;

  return 0;
}



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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

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

const ll INF = 912345678;

int a, b, c;

int main()
{
    cin >> a >> b >> c;
    if (a + b < c)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
}

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

int main(){
  int a,b;
  cin >> a >> b;
  
  int sump, summ, sumk;
  sump = a+b;
  summ = a-b;
  sumk = a*b;
  
  int ans;
  ans = max({sump, summ, sumk});
  
  cout << ans << endl;  
}

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

using ll = long long;

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

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
	
	int conteo1,conteo2;
	for(conteo1=1;conteo1<=9;conteo1++){
		for(conteo2=1;conteo2<=9;conteo2++){
			printf("%dx%d=%d\n",conteo1,conteo2,conteo1*conteo2);
		}
	}
	return 0;
}

Measured memory_bytes: 524
-- A Point in a Triangle
main = getContents >>= putStr . solve
--
solve :: String -> String
solve = unlines . map (isIn . toTuples . map read . words) . lines


cross :: (Float, Float) -> (Float, Float) -> Float
cross a b = (fst a) * (snd b) - (snd a) * (fst b)

toTuples :: [Float] -> [(Float, Float)]
toTuples [] = []
toTuples (x1:x2:xs) = (x1,x2) : toTuples xs

sub :: (Float, Float) -> (Float, Float) -> (Float, Float)
sub a b = (fst a - fst b, snd a - snd b)

-- case: counter clock wise
--         C(x3,y3)
--        / \
--       /   \
--      /  P  \
--     /(xp,yp)\
--    A---------B
-- (x1,y1)   (x2,y2)
--
-- case: clock wise
--         B(x2,y2)
--        / \
--       /   \
--      /  P  \
--     /(xp,yp)\
--    A---------C
-- (x1,y1)   (x3,y3)
--
-- AB = b - a = (abx, aby) = (x2-x1, y2-y1)
-- BC = c - b = (bcx, bcy) = (x3-x2, y3-y2)
-- CA = a - c = (cax, cay) = (x1-x3, y1-y3)
-- BP = p - b = (bpx, bpy) = (xp-x2, yp-y2)
-- CP = p - c = (cpx, cpy) = (xp-x3, yp-y3)
-- AP = p - a = (apx, apy) = (xp-x1, yp-y1)
isIn :: [(Float, Float)] -> String
isIn [a,b,c,p]
  | counterClockWise || clockWise = "YES"
  | otherwise = "NO"
    where
      counterClockWise= cross (b `sub` a) (p `sub` b) > 0 && cross (c `sub` b) (p `sub` c) > 0 && cross (a `sub` c) (p `sub` a) > 0
      clockWise = cross (b `sub` a) (p `sub` b) < 0 && cross (c `sub` b) (p `sub` c) < 0 && cross (a `sub` c) (p `sub` a) < 0

Measured memory_bytes: 4400
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

func Solve() {
  var N int
  NextInt(&N)
  var A []int
  NextIntVec(&A)
  C := make([]int, N + 1)
  for _, a := range A {
    C[a]++
  }
  D := make([]int, N + 1)
  for _, c := range C {
    D[c]++
  }
  KD := make([]int, N + 1)
  for i, d := range D {
    KD[i] = i * d
  }
  for i := 0; i < N; i++ {
    KD[i + 1] += KD[i]
  }
  XD := make([]int, N + 1)
  for i := N; 0 < i; i-- {
    XD[i - 1] = XD[i] + D[i]
  }
  L := make([]int, N + 1)
  for x := 1; x <= N; x++ {
    L[x] = (KD[x] + x * XD[x]) / x
  }
  for k := 1; k <= N; k++ {
    if L[1] < k {
      Write(0)
      continue
    }
    if k <= L[N] {
      Write(N)
      continue
    }
    succ, fail := 1, N
    for 1 < fail - succ {
      med := (fail + succ) / 2
      if L[med] < k {
        fail = med
      } else {
        succ = med
      }
    }
    Write(succ)
  }
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 20736
import java.util.*;
import java.math.BigInteger;
import java.math.RoundingMode;

public class Main {
    public static void main(String[] args) {
      Scanner s = new Scanner(System.in);
        final int N = Integer.parseInt(s.next());
        BigInteger result = new BigInteger("1");
        List<String> aList = new ArrayList<String>();

        for (int i = 0 ; i < N ; i++) {
            aList.add(s.next());
        }

        if (aList.contains("0")) {
            System.out.println(0);
            return;
        }

        for (String aStr : aList) {
            if (result.multiply(new BigInteger(aStr)).compareTo(new BigInteger("1000000000000000000")) > 0)  {
                System.out.println(-1);
                return;
            }
            result = result.multiply(new BigInteger(aStr));
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 57804
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    stations = list(map(string_to_int, inputs))
    N = len(stations)
    ret = []
    for i, s in enumerate(stations):
        [C, S, F] = s
        t = S + C
        for j in range(i+1, N):
            if t < stations[j][1]:
                t = stations[j][0] + stations[j][1]
            else:
                w = (t - stations[j][1]) % stations[j][2]
                waiting = 0 if w == 0 else stations[j][2] - w
                t += waiting + stations[j][0]
        ret.append(t)
    ret.append(0)
    return ret


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N-1))
    for r in ret:
        print(r)


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll mpow(ll m, ll p){
  ll power = m;
  ll res = 1;
  while(p>0){
    if(p&1)
      res = res*power%MOD;
    power = (power*power)%MOD;
    p /= 2;
  }

  return res;
}

ll mod_inv(ll m){
  return mpow(m, MOD-2);
}

struct COM{
  vll fact, fact_inv;
  COM(ll n): fact(n+1,1), fact_inv(n+1,1){
    for(ll i=1; i<=n; i++)
      fact[i] = fact[i-1]*i%MOD;

    fact_inv[n] = mod_inv(fact[n]);
    for(ll i=n; i>=1; i--)
      fact_inv[i-1] = fact_inv[i]*i%MOD;
  }

  ll calc(ll n, ll k){
    if(k<0 || n<k)
      return 0;
    ll res = fact[n]*fact_inv[n-k]%MOD*fact_inv[k]%MOD;
    return res;
  }
};


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

  ll s;
  cin>>s;


  COM com(s);

  ll ans=0;
  REP(i,s/3){
    ll r=i+1;
    ll x=s-3*r;
    ll t=com.calc(r+x-1,r-1);

    ans=(ans+t)%MOD;
  }

  cout<<ans<<endl;
}



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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;


int main(){
    int N, M;
    while(cin >> N >> M){
        if(N == 0 && M == 0) break;
        vector<ll> P(N+1);
        P[0]=0;
        for(int i=1; i<=N; i++) cin >> P[i];
        ll res=0;
        vector<ll> PP;
        for(int i=0; i<=N; i++){
            for(int j=0; j<=N; j++){
                PP.push_back(P[i]+P[j]);
            }
        }
        sort(all(PP));
        for(int i=0; i<=N; i++){
            for(int j=0; j<=N; j++){
                auto it=upper_bound(all(PP), M-P[i]-P[j]);
                ll sum=P[i]+P[j]+(it == PP.begin() ? 0:*(--it));
                if(sum <= M) res=max(res, sum);
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 18944
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int M=1e9+5;
int main() {
	int a,b;
	cin >> a>>b;
	if((a+b)%2)cout <<"IMPOSSIBLE" <<endl;
	else cout <<(a+b)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>

#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <fstream>
using namespace std;

#define maxn 100010
#define inf 1000000000000000000LL
#define ll long long
#define mod 1000000007

int pre[maxn], post[maxn], fix[maxn];

int main() {
    // freopen("test.in", "r", stdin);
    int n;
    cin >> n;
    for (int i = 1; i <= n ; ++i) {
        cin >> pre[i];
    }
    for (int i = 1; i <= n; ++i) {
        cin >> post[i];
    }

    for (int i = 1; i <= n; ++i) {
        if (pre[i] > pre[i-1]) {
            fix[i] = pre[i];
        }
    }

    for (int i = n; i >= 1; --i) {
        if (post[i] > post[i+1]) {
            if (fix[i] && fix[i] != post[i]) {
                cout << 0;
                return 0;
            } else {
                fix[i] = post[i];
            }
        } else {
            if (fix[i] && fix[i] > post[i]) {
                cout << 0;
                return 0;
            }
        }
    }

    long long prod = 1;
    for (int i = 1; i <= n; ++i) {
        if (!fix[i]) {
            prod = prod * min(pre[i], post[i]) % mod;
        }
    }

    cout << prod;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  	ios::sync_with_stdio(false);
  cin.tie(NULL);
	int n;
	cin>>n;
	ll a[n+1],pref[n+1];
	pref[0]=0;
	
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
		pref[i]=a[i] + pref[i-1];
	}
	ll ans=INT_MAX;
	for(int i=0;i<=n;++i)
	{
		ans=min(ans,abs(pref[n]-2*pref[i]));
	}
	cout<<ans;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
const int N = 10 + 5;

int arr[N];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n, ans = 1, odd = 1; cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		if(arr[i]&1) odd *= 1;
		else odd *= 2;
		ans *= 3;
	}
	cout<<ans-odd<<'\n';
	return 0;
}

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

int _compare(const void *a, const void *b) {
	if(*(char *)a < *(char *)b)
		return -1;
	else if(*(char *)a == *(char *)b)
		return 0;
	else
		return 1;
}

int main(void) {
	char A[200000];
	long int start[26] = {0};
	long int end[26] = {0};
	int sp = 0;
	long long int ans = 0, k, l;
	
	scanf("%s", A);
	ans++;
	ans += strlen(A) * (strlen(A)-1) / 2;
	qsort(A, strlen(A), sizeof(*A), _compare);
	for(k=0; k<strlen(A)-1; k++) {
		if(A[k] != A[k+1]) {
			end[sp] = k;
			start[++sp] = k+1;
		}
	}
	end[sp] = strlen(A)-1;
	for(k = 0; k <= sp; k++) {
		ans -= (end[k] - start[k] + 1) * (end[k] - start[k]) / 2;
	}
	/*
	for(k = 2; k <= strlen(A); k++) {
		ans += strlen(A)-k+1;
		char_count[A[k-1]-97]++;
	}
	*/
	/*
	for(k=0; k < 26; k++) {
		ans -= char_count[k] * (char_count[k]-1) / 2;
	}
	*/
	/*
	for(k = 1, l = 1, m = 0; k < strlen(A) - 1; k++) {
		if(A[k] == A[k+1]) {
			if(k-1 < strlen(A) - 1) {
			ans--;
			for(m = 1; k-m >= 0 && k+1+m <= strlen(A)-1; m++) {
				if(A[k-m] == A[k+1+m])
					ans--;
				else
					break;
			}
			m = 0;
		}
		if(A[k-l] == A[k+l]) {
			ans--;
			for(l = 2; k-l >= 0 && k+l <= strlen(A)-1; l++) {	
				if(A[k-l] == A[k+l])
					ans--;
				else
					break;
			}
			l = 1;
		}
	}
	// 偶数で左右対称
	for(k = 0, l = 0; k < strlen(A) - 1; k++) {
		if(A[k] == A[k+1]) {
			ans--;
			for(l = 1; k-l >= 0 && k+1+l <= strlen(A)-1; l++) {
				if(A[k-l] == A[k+1+l])
					ans--;
				else
					break;
			}
			l = 0;
		}
	}
	*/

	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 508
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b;
    cin >> a >> b;
    string S;
    cin >> S;
    bool res = true;

    {
        if (S.length() != a + b + 1) {
            res = false;
        } else {
            if (S[a] == '-') {
                for (int i = 0; i < S.length(); ++i) {
                    if (i == a) {
                        continue;
                    }
                    if (!isdigit(S[i])) {
                        res = false;
                    }
                }
            } else {
                res = false;
            }
        }
    }

    if (res) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

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

ll pat[52];
ll siz[52];

int main(){
    int n;
    cin >> n;
    pat[0] = 1;
    siz[0] = 1;
    for ( int i = 1; i <= n; ++i ) {
        pat[i] = pat[i-1] * 2 + 1;
        siz[i] = siz[i-1] * 2 + 3;
    }
    ll x;
    cin >> x;
    ll ret = 0;
    while(n>0 && x>0) {
        if (x>=2+2*siz[n-1]) {
            ret+=1+2*pat[n-1];
            x=0;
            break;
        }
        if(x>=2+siz[n-1]) {
            ret+=1+pat[n-1];
            x-=2+siz[n-1];
        }
        else if (x==1+siz[n-1]) {
            ret+=pat[n-1];
            x-=1+siz[n-1];
        }
        else {
            --x;
        }
        --n;
    }
    //if (x) ++ret;
    cout << ret << endl;
    return 0;
}


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

int main(){
    int a, b, t;
    cin >> a >> b >> t;
    int ans = 0;
    for(int i = 1; i <= t; i++){
        if(i % a == 0){
            ans += b;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func main() {
	list := getStdinIntArr()
	N := list[0]
	L := list[1]

	min := math.MaxInt32
	minIdx := -1
	for i := 1; i <= N; i++ {
		n := L + i - 1
		if n < 0 {
			n = -n
		}
		if n < min {
			min = n
			minIdx = i
		}
	}

	sum := 0
	for i := 1; i <= N; i++ {
		if minIdx != i {
			sum += L + i - 1
		}
	}
	fmt.Printf("%d\n", sum)
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;


int main(){FIN

    map<ll,ll> mp;
    ll n,m;cin>>n>>m;
    REP(i,n){
        ll k;cin>>k;
        REP(i,k){
            ll a; cin>>a;
            mp[a]++;
        }
    }

    ll cnt=0;
    for(auto p:mp){
        if (p.second==n) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	h := make([]int, 100100)
	dp := make([]int, 100100)
	for i := 0; i < N; i++ {
		fmt.Scan(&h[i])
	}

	for i := 0; i < 100100; i++ {
		dp[i] = math.MaxInt64
	}
	dp[0] = 0

	for i := 0; i < N; i++ {
		for j := 1; j <= K; j++ {
			dp[i+j] = Min(dp[i+j], dp[i]+Abs(h[i]-h[i+j]))
		}
	}
	fmt.Println(dp[N-1])
}
func Abs(a int) int {
	return int(math.Abs(float64(a)))
}
func Min(a, b int) int {
	if b < a {
		return b
	}
	return a
}


Measured memory_bytes: 5504
#include<cstdio>
#include<cstdlib>
#include<string.h>
#include<stdlib.h>

struct Node{
	int key;
	Node *next,*prev;
};

Node *nil;

Node* listSearch(int key){
	Node *cur = nil->next;	// ??????????¬????????´?????????????
	while(cur != nil && cur ->key!=key){
		cur =cur-> next;
	}
	return cur;
}

//????????? next??¨prev??????????????????
void init(){
	nil=(Node *)malloc(sizeof(Node));
	nil ->next=nil;
	nil ->prev =nil;
}

void printList(){
	Node *cur = nil->next;
	int isf=0;
	while(1){
		if(cur==nil)break;
		if(isf++>0)printf(" ");
		printf("%d", cur -> key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t){
	if(t==nil)return;	//t??????????????´?????????????????????
	t->prev->next=t->next;
	t->next->prev=t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	//????´¢????????????????????????
	deleteNode(listSearch(key));
}

void insert(int key){
	Node *x=(Node *)malloc(sizeof(Node));
	x->key=key;
	//???????????´??????????´??????????
	x->next=nil->next;
	nil->next->prev=x;
	nil->next=x;
	x->prev=nil;
}

int main(){
	int key,n,i;
	int size=0;
	char com[20];
	int np=0,nd=0;
	scanf("%d",&n);
	init();
	for(i=0;i<n;i++){
		scanf("%s%d",com,&key);	//?????????????????\?????¢??°
		if(com[0]=='i'){insert(key); np++; size++; }
		else if(com[0]=='d'){
			if(strlen(com)>6){
				if(com[6]=='F')deleteFirst();
				else if(com[6]=='L')deleteLast();
			}
			else{
				deleteKey(key); nd++;
			}
			size--;
		}
	}
	
	printList();
	
	return 0;
}

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

using namespace std;

deque<int> dq;

int main()
{
  ios_base::sync_with_stdio(false);
  int q;
  //int k = 1000000000;
  //cout << k << endl;
  cin >> q;
  while (q--) {
    int a, d, x;
      cin >> a;
      if (a == 0) {
        cin >> d >> x;
        if (d == 0) {
          dq.push_front(x);
        }
        else if (d == 1) {
          dq.push_back(x);
        }
      }
      else if (a == 1) {
        cin >> x;
        cout << dq[x] << endl;
      }
      else if (a == 2) {
        cin >> d;
        if (d == 0) {
          dq.pop_front();
        }
        else if (d == 1) {
          dq.pop_back();
        }
      }
  }
  return 0;
}



Measured memory_bytes: 4600
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int64_t gcd(int64_t a, int64_t b) {return b?gcd(b, a%b):a;}
int64_t lcm(int64_t a, int64_t b) {return a/gcd(a,b)*b;}
int64_t extgcd(int64_t a, int64_t b, int64_t &x, int64_t &y) { // ax+by=gcd(a, b)の解を与える
    int64_t d = a;
    if(b) {
        d = extgcd(b, a%b, y, x);
        y -= (a/b)*x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    ll x, y;
    extgcd(a, b, x, y);
    cout << x << ' ' << y << '\n';
}


Measured memory_bytes: 3220
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

void printout_array(int* A, int N){
   string str = "";
   for(int i = 0; i < N; i++){
       str += to_string(A[i]);
       if(i != N - 1){
           str += " ";
       }
   }
   cout << str << "\n";
}

void insertionSort(int* A, int N){
    for(int i = 1; i < N; i++){
        int v = A[i];
        int j = i - 1;
        while( j >= 0 && A[j] > v){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        printout_array(A, N);
    }
}


int main(){
    int N;
    scanf("%d", &N);

    int array[N];
    for(int i = 0; i < N; i++){
        scanf("%d", &array[i]);
    }
    printout_array(array, N);
    insertionSort(array, N);
}



Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
#define ll long long
 
#define mod 1000000007
long long exp(long long taban, long long us) {
    long long carpan = taban;
    long long temp = us;
    long long res = 1;
    for(int i = 0;;i++){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
        if(temp == 0) break;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (((a*b)%mod)*(exp(ebob(a,b), (ll)mod-2))) % mod;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n, k; cin>>n>>k;
	int res = 0;
	while(n > 0){
		n /= k;
		res++;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 256
/*
ID: skipian1
PROB:
LANG: C++11
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF = 2000000000
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define X first
#define Y second

int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  int dp[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    dp[i] =  1e9;
  }
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = i-k; j < i; j++) {
      if (j < 0) continue;
      dp[i] = min(dp[i], abs(arr[i]-arr[j])+dp[j]);
    }
  }
  cout << dp[n-1] << "\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];


int main () {
    int L;
    scanf("%d",&L);
    printf("%.12f\n",(double)L*L*L/27);

}

Measured memory_bytes: 256
#!/usr/bin/env python3

n, k = map(int, input().split())
D = list(map(int, input().split()))

paid = n
while True:
    st = set(int(x) for x in str(paid))
    l = len(st)
    if len([x for x in st if x not in D]) == l:
        print(paid)
        break
    paid += 1

Measured memory_bytes: 3060
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = [B[i] - A[i] for i in range(N)]
K = sum(B) - sum(A)
flag = True
if(K < 0):
    flag = False

if(flag):
    p1 = K
    m2 = K
    for i in range(N):
        if(C[i] == 0):
            pass
        elif(C[i] < 0):
            p1 += C[i]
        elif(C[i] > 0):
            if(C[i] % 2 == 0):
                m2 -= C[i] // 2
            else:
                m2 -= C[i] // 2 + 1
                p1 -= 1
    if(p1 < 0 or m2 < 0):
        flag = False
    else:
        if(p1 == 2*m2):
            flag = True
        else:
            flag = False
    #print(K,p1,m2)
#print(C)
if(flag):
    print('Yes')
else:
    print('No')

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

int main() {
    int n, res = 0;
    cin>>n;
    for(int i = 1; i <= n; i+=1) {
        int num;
        cin>>num;
        if((i&1) && (num&1)) {
            res += 1;
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<string>
using namespace std;
int main(){
int x,a,b;
cin>>x>>a>>b;
if(b-a<=0)
cout<<"delicious"<<endl;
else if(b-a<=x)
cout<<"safe"<<endl;
else if(b-a>x)
cout<<"dangerous"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	for(int l=0;l<n;l++){
		int num[2][9],a[2][9],geitu,jacky;
		double winrate1=0,winrate2=0;
		for(int j=0;j<2;j++){
			for(int k=0;k<9;k++)cin>>a[j][k];
		}
		for(int z=0;z<9;z++){
			num[0][0]=0;
			num[1][0]=0;
			if(a[0][0]>a[1][z])num[0][0]=(a[0][0]+a[1][z]);
			else num[1][0]=(a[0][0]+a[1][z]);
			for(int b=0;b<9;b++){
				if(b==z)continue;
				num[0][1]=0;
				num[1][1]=0;
				if(a[0][1]>a[1][b])num[0][1]=(a[0][1]+a[1][b]);
				else num[1][1]=(a[0][1]+a[1][b]);
				for(int c=0;c<9;c++){
					if(c==z||c==b)continue;
					num[0][2]=0;
					num[1][2]=0;
					if(a[0][2]>a[1][c])num[0][2]=(a[0][2]+a[1][c]);
					else num[1][2]=(a[0][2]+a[1][c]);
					for(int d=0;d<9;d++){
						if(d==z||d==b||d==c)continue;
						num[0][3]=0;
						num[1][3]=0;
						if(a[0][3]>a[1][d])num[0][3]=(a[0][3]+a[1][d]);
						else num[1][3]=(a[0][3]+a[1][d]);
						for(int e=0;e<9;e++){
							if(e==z||e==b||e==c||e==d)continue;
							num[0][4]=0;
							num[1][4]=0;
							if(a[0][4]>a[1][e])num[0][4]=(a[0][4]+a[1][e]);
							else num[1][4]=(a[0][4]+a[1][e]);
							for(int f=0;f<9;f++){
								if(f==z||f==b||f==c||f==d||f==e)continue;
								num[0][5]=0;
								num[1][5]=0;
								if(a[0][5]>a[1][f])num[0][5]=(a[0][5]+a[1][f]);
								else num[1][5]=(a[0][5]+a[1][f]);
								for(int g=0;g<9;g++){
									if(g==z||g==b||g==c||g==d||g==e||g==f)continue;
									num[0][6]=0;
									num[1][6]=0;
									if(a[0][6]>a[1][g])num[0][6]=(a[0][6]+a[1][g]);
									else num[1][6]=(a[0][6]+a[1][g]);
									for(int h=0;h<9;h++){
										if(h==z||h==b||h==c||h==d||h==e||h==f||h==g)continue;
										num[0][7]=0;
										num[1][7]=0;
										if(a[0][7]>a[1][h])num[0][7]=(a[0][7]+a[1][h]);
										else num[1][7]=(a[0][7]+a[1][h]);
										for(int i=0;i<9;i++){
											if(i==z||i==b||i==c||i==d||i==e||i==f||i==g||i==h)continue;
											num[0][8]=0;
											num[1][8]=0;
											if(a[0][8]>a[1][i])num[0][8]=(a[0][8]+a[1][i]);
											else num[1][8]=(a[0][8]+a[1][i]);
											geitu=0;
											jacky=0;
											for(int m=0;m<9;m++){
												geitu+=num[0][m];
												jacky+=num[1][m];
											}
											if(geitu>jacky)winrate1++;
											else if(geitu<jacky)winrate2++;
										}
									}
								}
							}
						}
					}
				}
			}
		}
		double ans,ans2;
		ans=winrate1/362880;
		ans*=100000;
		ans+=0.5;
		ans=int(ans);
		ans/=100000;
		ans2=winrate2/362880;
		ans2*=100000;
		ans2+=0.5;
		ans2=int(ans2);
		ans2/=100000;
		cout<<ans<<" "<<ans2<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3200
while True:
    grade = input()
    grade_list = grade.split(" ")
    mid_exam = int(grade_list[0])
    fin_exam = int(grade_list[1])
    re_exam = int(grade_list[2])
    if mid_exam == -1 and fin_exam == -1 and re_exam == -1:
        break
    if mid_exam == -1 or  fin_exam == -1:
        print("F")
    elif mid_exam + fin_exam >= 80:
        print("A")
    elif mid_exam + fin_exam >= 65:
        print("B")
    elif mid_exam + fin_exam >= 50:
        print("C")
    elif mid_exam + fin_exam >= 30 and re_exam >= 50:
        print("C")
    elif mid_exam + fin_exam >= 30:
        print("D")
    else:
        print("F")


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

// typedef long long ll;
typedef cpp_int ll;
typedef pair<ll, ll> p;
// ll res = 0;

vector<ll> dp(100, -1);

ll f(ll n){
  // if(dp[n] != -1) return dp[n];
  // if(n < 2) return dp[n] = 1;
  // else return dp[n] = n * f(n-2);
  if(n < 2) return 1;
  else return n * f(n-2);
}

ll g1(ll n, int p){
  if(n == 0) return 0;
  return n / p + g1(n/p, p);
}

ll g2(ll n, int p){
  if(n % 2 == 1){
    return g1(n, p) - g2(n-1, p);
  }
  ll res = g1(n/2, p);
  if(p == 2) res += n / 2;
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  if(n % 2 == 1) cout << 0 << endl;
  else{
    cout << g2(n, 5) << endl;
  }
}


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

//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define ff first
#define ss second
#define err stderr
#define out stdout

typedef long long int ll;
typedef long double ld;
typedef short int sh;

inline void readI(int *i)
{
	register int t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=(t*znak);
}
inline void readUI(int *i)
{
	register int t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*i=t;
}
inline void readL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	int znak=1;
	if (z=='-')
	{
		znak*=-1;
	}
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
		if (z=='-')
		{
			znak=-1;
		}
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=(t*znak);
}
inline void readUL(ll *l)
{
	register ll t=0;
	register char z=getchar();
	while ((z<'0') || ('9'<z))
	{
		z=getchar();
	}
	while (('0'<=z) && (z<='9'))
	{
		t=(t<<3)+(t<<1)+z-'0';
		z=getchar();
	}
	*l=t;
}
inline void writeL(ll l)
{
	if (l==0)
	{
		putchar(48);
	}
	else
	{
		if (l<0)
		{
		   l*=-1;
		   putchar(45);
		}
		int _tab[21];
		int wsk=0;
		while (l>0)
		{
			++wsk;
			_tab[wsk]=(l%10)+48;
			l/=10;
		}
		for (int j=wsk; j>=1; --j)
		{
			putchar(_tab[j]);
		}
	}
}
inline void writeS(string s)
{
	int l=s.length();
	for (int i=0; i<l; ++i)
	{
		putchar(s[i]);
	}
}
inline void space()
{
	putchar(32);
}
inline void endl()
{
	putchar(10);
}

#define debug if(1)
#define debug2 if(1)
#define debug3 if(1)
#define debug4 if(1)
#define MAXN (int)(1e5)+5

int n, k;
int h[MAXN], dp[MAXN];
int inf=(1e9)+2137;

int main()
{
	readUI(&n);
	readUI(&k);
	for (int i=1; i<=n; ++i)
	{
		readUI(&h[i]);
		dp[i]=(i==1 ? 0 : inf);
		for (int j=i-1; j>=max(1, i-k); --j)
		{
			dp[i]=min(dp[i], dp[j]+abs(h[i]-h[j]));
		}
	}
	fprintf (out, "%d\n", dp[n]);
	return 0;
}
/*
*/




Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<string.h>

using namespace std;

int main(){
  int n;
  cin >> n;
  for(int i=1;i<=9;i++){
    int a = n%i;
    int b = n/i;
    if(a==0 && b<=9 && b>=1){
      cout <<"Yes" << endl;
      return 0;
    }
  }
cout <<"No" << endl;
      return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
const int mod=1e9+7;
int n,m,i,lst,dp[200005],s[200005],f[200005][2],tmp,mi=0x3f3f3f3f,l;
string st;
int main(){
	cin>>n>>m;
	cin>>st;
	st=" "+st;
	i=1;lst=1;
	while(i<=m){
		if(st[i]!=st[i-1]){
			if(st[i]!=st[1]){
				if(lst==1||((i-lst)&1)){
					mi=min(mi,i-lst);
				}
			}
			else{
				lst=i;
			}
		}
		i++;
	}
	if(mi<0x3f3f3f3f){
		if(n&1){
			puts("0");
			return 0;
		}
		mi=mi/2+1;
		n/=2;
		l=1;
/*		s[1]=1;s[mi+1]+=mod-1;
		rep(i,n){
			tmp=(tmp+s[i])%mod;
			dp[i]=tmp;
			s[min(n,i+1)]=(s[min(n,i+1)]+dp[i])%mod;
			s[min(n,i+mi)+1]=(s[min(n,i+mi)+1]+mod-dp[i])%mod;
		}
		cout<<dp[n]<<endl;*/
	}
	else{
		l=2;
	}
	for(i=l;i<=n;i++){
		dp[i]=(s[i-l]+(i>mi?-s[i-mi-1]:(3ll-l)*i))%mod;
		s[i]=(s[i-1]+dp[i])%mod;
	}
	cout<<(dp[n]+l-1+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 5232
//--------------------------------------------------template----------------------------------------//
//c
#include <stdio.h>
#include <time.h>
#include <math.h>
//c++
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <complex>
#include <cmath>
//c++11
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) (c).rbegin(),(c).rend()
//#define sort(v,n) sort(v,v+n)
//#define vsort(v) sort(v.begin(),v.end())
#define vvsort(v) sort(v.rbegin(),v.rend())
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
#define inf 999999999
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
ll a, b;

inline ll solve() {
	ll now = 2;
	ll ans = 1;
	while (now <= min(a, b)) {
		if (a%now == 0 && b%now == 0) {
			ans *= now;
			a /= now; b /= now;
		}
		else {
			now++;
		}
	}
	return ans;
}

inline ll solve2() {
	ll ans = max(a, b);
	for (ll i = max(a, b); i <= 2000000000; i+=max(a,b)) {
		if (i%a == 0 && i%b == 0) {
			ans = i;
			break;
		}
	}
	return ans;
}


int main() {
	while (cin >> a >> b) {
		cout << solve() << " " << solve2() << endl;
	}
	return 0;
}

Measured memory_bytes: 3024
def isPrime(num):
    if num < 2:
        return False
    elif num == 2:
        return True
    elif num % 2 == 0:
        return False

    for i in range(3, int(num**0.5)+1, 2):
        if num % i == 0:
            return False
    return True

def is_2017(num):
    temp = (num + 1) // 2
    if isPrime(num) and isPrime(temp):
        return True
    else:
        return False

if __name__ == "__main__":
    
    is_2017_list = [0] * (10**5 + 1)
    count = 0
    for i in range(1, 10**5):
        if is_2017(i):
            count += 1
            is_2017_list[i] = count
            
        else:
            is_2017_list[i] = count

    Q = int(input())

    ans_list = []
    for _ in range(Q):
        l, r = map(int, input().split())
        ans = is_2017_list[r] - is_2017_list[l-1]
        ans_list.append(ans)
    
    for ans in ans_list:
        print(ans)

    




Measured memory_bytes: 14352