akhauriyash/Code-Regression huggingface dataset:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

mod = 10**9+7 #出力の制限
N = 10**5 * 2
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
def p(n,r):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
# a = cmb(n,r)

import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n,k = m()

co = 0

for i in range(min(k+1,n)):
    co += cmb(n,i) * cmb(n-1,n-i-1) %mod
    co %= mod


print(co)





Measured memory_bytes: 29108
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char ch[100090];
    int mini = 999;
    scanf("%s",&ch);
    int len=strlen(ch);
    for(int i=0; i<=len-3; i++)
    {
        int val = ((ch[i]-'0')*100)+((ch[i+1]-'0')*10)+(ch[i+2]-'0');
        if(fabs(val-753)<mini)mini=fabs(val-753);
    }
    printf("%d\n",mini);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int c;
	while(1){
		c = getchar();
		if(c == '\n'){break;}
		if('D' <= c && c <= 'Z' || 'd' <= c && c <= 'z'){
			c -= 3;
		}else{
			c = c + ('Z'-'A') - 2;
		}
		putchar(c);
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

typedef long long ll;

bool check(const vector<vector<char>> &b, int n) {
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (b[i][j] != b[j][i])
                return false;
        }
    }
    return true;
}

int main() {
    int n = 0;
    cin >> n;
    vector<vector<char>> a;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        a[i].resize(n);
        string str;
        cin >> str;
        for (int j = 0; j < n; j++) {
            a[i][j] = str[j];
        }
    }
    int res = 0;
    for (int k = 0; k < n; k++) {
        vector<vector<char>> b;
        b.resize(n);
        for (int i = 0; i < n; i++) {
            b[i].resize(n);
            for (int j = 0; j < n; j++) {
                b[i][j] = a[(i + k) % n][j];
            }
        }
        if (check(b, n))
            res += n;
    }

    cout << res;
    return 0;
}


Measured memory_bytes: 436
N = int(input())
A = list(map(int, input().split()))

for a in A:
    if a % 2 == 0:
        if a % 3 == 0 or a % 5 == 0:
            N -= 1
    else:
        N -= 1

if N == 0:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    map<int, int> mp;
    rep(i, n){
        mp[a.at(i)]++;
    }

    int ans = 0;
    int mnid = 100000;
    int mxid = -1;
    int cnt = 0;
    for(auto b: mp){
        ans++;
        if(b.second%2==0){
            cnt++;
            mnid = min(mnid, b.first);
            mxid = max(mxid, b.first);
        }
        else{
            b.second = 1;
        }
    }

    dump(mnid);
    dump(mxid);

    if(cnt%2==0){
        cout << ans << endl;
        return 0;
    }

    cout << ans - 1<< endl;

    
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){
    ll n,k,s;
    cin>>n>>k>>s;
    vector<ll> v;
    rep(i,k){
        v.push_back(s);
    }

    rep(k,n){
        if(s==1000000000){
            v.push_back(1);
        }else{
           v.push_back(s+1);
        }
    }

    rep(i,n){
        cout<<v[i]<<" ";
    }
    cout<<endl;


    
return 0;
}


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

bool isPal(string s) {
   string t = s;
   reverse(s.begin(), s.end());
   return s == t;
}

int main() {

   ios_base::sync_with_stdio(0);
   cin.tie(0); 

   string s;
   cin >> s;
   int n = s.length();

   string s_left = s.substr(0, n / 2);
   string s_right = s.substr(n / 2 + 1, n / 2);

   if(isPal(s) && isPal(s_left) && isPal(s_right)) {
      cout << "Yes" << endl;
   } else {
      cout << "No" << endl;
   }
   return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //定番のn回繰り返しを省略
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
 

//ここから書き始める
int main(int argc, char const *argv[])
{
    int a,b,n;
    cin >> n;

    if(n == 1)
    {
        cout << "Hello World" << endl;
    }
    if(n == 2)
    {
        cin >> a;
        cin >> b;
        cout << a+b << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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 REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define mp make_pair
#define pb push_back
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

template <class T> inline auto __lcm(T &a, T &b)
{ return a * b / __gcd(a, b); }


int main() {

    int r, D, x;  cin >> r >> D >> x;

    rep(i, 10) {
        x = r * x - D;
        print(x);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    int n; cin >> n;
    int ans = 0;
    while(n != 0){
        if(n%10 == 2) ans++;
        n /= 10;
    }
    cout << ans << endl;
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,a[100001],ans=0;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
         ans+=a[i];
    }
    if(ans%2==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <algorithm>
#include <map>
#include <numeric>
#include <iomanip>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 100;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */

/* main */
int main() {

    int n; cin >> n;
    vector< queue<int> > v(n, queue<int>());
    int q; cin >> q;
    while (q--) {

        int op; cin >> op;
        int t; cin >> t;

        if (op == 0) {
            int x; cin >> x;
            v[t].push(x);

        }
        else if (op == 1) {
            if (v[t].empty())
                continue;
            cout << v[t].front() << '\n';
        }
        else {
            if (v[t].empty())
                continue;
            v[t].pop();
        }
    }
}



Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF=1e9+7;
typedef long long ll;
typedef pair<int,int> P;

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

	if(N.at(0)=='7' || N.at(1)=='7' || N.at(2) =='7')
		cout << "Yes";
	else
		cout << "No";
	cout << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define pb       push_back
#define mp       make_pair
#define mod      1000000007
#define pi       acos(-1.0)
#define test     int t;cin>>t;while(t--)
typedef long long ll;
using namespace std;
int main()
{

     ios::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     vector<pair<string,int>>p;
     p.push_back(mp("SUN",1));
      p.push_back(mp("MON",2));
       p.push_back(mp("TUE",3));
        p.push_back(mp("WED",4));
         p.push_back(mp("THU",5));
          p.push_back(mp("FRI",6));
           p.push_back(mp("SAT",7));

    string s;
    cin>>s;
    for(int i=0;i<p.size();i++)
    {
       if(p[i].first==s)
       {
         cout<<7-(p[i].second-1)<<endl;
         return 0;
       }
    }




     return 0;

}

Measured memory_bytes: 3548
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        char[] charIn = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
        Scanner sc = new Scanner(System.in);
        
        String writing = "";
        while(sc.hasNext()){
            writing += sc.nextLine();    
        }
        writing = writing.toLowerCase();
        
        int[] count = new int[charIn.length];
        
        //暗黙的は怖いから初期値の設定
        for(int i = 0; i < charIn.length; i++){
            count[i] = 0;
        }
        
        //入力文字列の判定
        for(int i = 0; i < writing.length(); i++){
            for(int j = 0; j < charIn.length; j++){
                if(writing.charAt(i) == (charIn[j])){
                    count[j]++;
                }
            }
        }
        
        //出力
        for(int i = 0; i < charIn.length; i++){
            System.out.println(charIn[i] + " " + ":" + " " + count[i]);
        }
    }
}



Measured memory_bytes: 26068
program main
   implicit none
   integer N, X, countN, i
   integer, allocatable :: m(:)
   read(*, *) N, X
   allocate(m(1: N))
   do i = 1, N
       read(*, *) m(i)
   end do
   do i = 1, N
      X = X - m(i)
   end do
   countN = N
   countN = countN + X / minval(m(:))
   write(*, *) countN
end program main

Measured memory_bytes: 768
Imports System.Console
Module Module1
    Dim ans As Int64
    Dim max, min As Int64
    Dim n, k, x, t, d As Int64
    Sub Main()
        Dim s As String = ReadLine()
        Dim tt As String = ReadLine()
        Dim tlon As Integer = tt.Length
        min = 2 ^ 31
        For i = 0 To s.Length - tlon
            Dim w As Integer = Diff(tt, s.Substring(i, tlon))
            If w <= min Then
                min = w
            End If
        Next
        WriteLine(min)
        ReadLine()
    End Sub
    Function Diff(s1 As String, s2 As String) As Integer
        Dim c1() As Char = s1.ToCharArray
        Dim c2() As Char = s2.ToCharArray
        Dim ret As Integer
        For i = 0 To c1.Length - 1
            If c1(i) <> c2(i) Then
                ret += 1
            End If
        Next
        Return ret
    End Function
    Sub Add(ByRef arr() As Integer, ByVal num As Integer)
        If arr Is Nothing Then
            ReDim arr(0)
            arr(0) = num
        Else
            ReDim Preserve arr(arr.Length)
            arr(arr.Length - 1) = num
        End If
    End Sub
End Module


Measured memory_bytes: 27220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ll n;
    cin>>n;
    ll arr[n],sum=0;
    int b[100001]={0};
    for(ll i=0;i<n;i++)
    {   
        cin>>arr[i];
        sum+=arr[i];
        b[arr[i]]++;
    }
    ll q;
    cin>>q;
    while(q--)
    {
        ll a,c;
        cin>>a>>c;
        b[c]+=b[a];
        sum+=(c-a)*b[a];
        b[a]=0;
        cout<<sum<<"\n";
    }
}


Measured memory_bytes: 4760
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = []
for i in range(N):
    s = list(map(int,input().split()))
    A.append(s)
ans = 0
for i in A:
    cnt = 0
    for j in range(M):
        cnt += i[j]*B[j]
    if cnt > -C:
        ans+=1
print(ans)

Measured memory_bytes: 3064
/*  -*- coding: utf-8 -*-
 *
 * 2706.cc: Let's Solve Geometric Problems
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_P = 32000;

/* typedef */

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

/* global variables */

bool primes[MAX_P + 1];

/* subroutines */

int gen_primes(int maxp, vi &pnums) {
  memset(primes, true, sizeof(primes));
  primes[0] = primes[1] = false;

  int p;
  for (p = 2; p * p <= maxp; p++)
    if (primes[p]) {
      pnums.push_back(p);
      for (int q = p * p; q <= maxp; q += p) primes[q] = false;
    }
  for (; p <= maxp; p++)
    if (primes[p]) pnums.push_back(p);
  return (int)pnums.size();
}

bool prime_decomp(int n, vi &pnums, vpii& pds) {
  pds.clear();

  int pn = pnums.size();
  for (int i = 0; i < pn; i++) {
    int pi = pnums[i];
    if (pi * pi > n) {
      if (n > 1) pds.push_back(pii(n, 1));
      return true;
    }

    if (n % pi == 0) {
      int fi = 0;
      while (n % pi == 0) n /= pi, fi++;
      pds.push_back(pii(pi, fi));
    }
  }
  return false;
}

int gcd(int m, int n) {  // m >= n > 0
  while (n > 0) {
    int r = m % n;
    m = n;
    n = r;
  }
  return m;
}

int powi(int a, int b) {
  int p = 1;
  while (b) {
    if (b & 1) p *= a;
    a *= a;
    b >>= 1;
  }
  return p;
}

/* main */

int main() {
  vi pnums;
  int pn = gen_primes(MAX_P, pnums);
  //printf("pn=%d\n", pn);

  int p, q;
  scanf("%d%d", &p, &q);

  int g = gcd(q, p);
  //printf("gcd(%d,%d)=%d\n", p, q, g);
  int n = q / g;
  vpii pds;
  prime_decomp(n, pnums, pds);

  /*
  printf("%d = ", n);
  for (int i = 0; i < pds.size(); i++) {
    if (i) putchar('*');
    printf("%d^%d", pds[i].first, pds[i].second);
  }
  putchar('\n');
  */
  
  int m = 1;
  for (int i = 0; i < pds.size(); i++) m *= pds[i].first;

  printf("%d\n", m);
  return 0;
}

Measured memory_bytes: 3348
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
	int n;cin>>n;
	for(;n--;)
	{
		double a,b,c,d,e,f;
		cin>>a>>b>>c>>d>>e>>f;
		double A=a,B=b;
		double lx1,lx2,ly1,ly2;
		lx1=(a+c)/2;
		ly1=(b+d)/2;
		if(b!=d)
		{
			lx2=lx1+1;
			ly2=ly1-((c-a)/(d-b));
		}
		else
		{
			lx2=lx1;
			ly2=ly1+1;
		}
		double lx3,lx4,ly3,ly4;
		lx3=(a+e)/2;
		ly3=(b+f)/2;
		if(b!=f)
		{
			lx4=lx3+1;
			ly4=ly3-((e-a)/(f-b));
		}
		else
		{
			lx4=lx3;
			ly4=ly3+1;
		}
		double g,h;
		a=lx1,b=ly1,c=lx2,d=ly2,e=lx3,f=ly3,g=lx4,h=ly4;
		double x,y;
		x=((f*g-e*h)*(c-a)-(b*c-a*d)*(g-e))/((d-b)*(g-e)-(c-a)*(h-f));
		y=((f*g-e*h)*(d-b)-(b*c-a*d)*(h-f))/((d-b)*(g-e)-(c-a)*(h-f));
		cout<<fixed<<setprecision(3)<<x<<" "<<y<<" "<<hypot(A-x,B-y)<<endl;
	}
}


Measured memory_bytes: 3300
s=input()
k=int(input())
n=len(s)
counter=1
allsame=0
samefirst=1
samelast=1
firstletter=''
lastletter='.'
for i in range(n):
  if s[i]!=s[0]:
    firstletter=s[i]
    samefirst=i
    break
  if i==n-1:
    allsame=1
for i in range(n):
  if s[n-i-1]!=s[n-1]:
    lastletter=s[n-i-1]
    samelast=i
    break
  if i==n-1:
    allsame=1
anstemp=0
previousletter=s[samefirst-1]
for i in range(samefirst,n-samelast+1):
  currentletter=s[i]
  if currentletter==previousletter:
    counter+=1
  else:
    anstemp+=counter//2
    counter=1
    previousletter=currentletter
if allsame==1:
  print((k*n)//2)
elif firstletter==lastletter:
  print(anstemp*k+samefirst//2+samelast//2+(k-1)*((samefirst+samelast)//2))
else:
  print((anstemp+samefirst//2+samelast//2)*k)

Measured memory_bytes: 3064
import numpy as np
def fact(M):
    if M == 1:
        return 1
    else:
        return fact(M-1)*M
def count(N, X):
    number = np.arange(N)+1
    res = 1
    for i in range(N-1):
        idx = int(np.where(number == X[i])[0])
        res = res + fact(N-i-1) * idx
        number = np.delete(number,idx)
    return res

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

print(abs(count(N,P)-count(N,Q)))


Measured memory_bytes: 12716
package main
import (
  "fmt"
  "sort"
)

func max(arr []int) int {
  num := 0
  for _, a := range arr {
    if num < a {
      num = a
    }
  }
  return num
}

func main() {
  var n, h int
  fmt.Scan(&n, &h)
  as := make([]int, n)
  bs := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&as[i], &bs[i])
  }
  sort.Ints(bs)
  maxA := max(as)
  result := 0
  cnt := 0
  for {
    if h <= 0 {
      break
    }
    if n-1-cnt < 0 {
      if h%maxA == 0 {
        result += h/maxA
      } else {
        result += h/maxA + 1
      }
      break
    }
    b := bs[n-1-cnt]
    if b <= maxA {
      if h%maxA == 0 {
        result += h/maxA
      } else {
        result += h/maxA + 1
      }
      break
    }
    h -= b
    result++
    cnt++
  }
  fmt.Println(result)
}

Measured memory_bytes: 7168
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np



# 文字列を一文字ずつのリストに代入 test は['t', 'e', 's', 't']
a = list(input())

y=int(a[0])*1000+int(a[1])*100+int(a[2])*10+int(a[3])
m=int(a[5])*10+int(a[6])
d=int(a[8])*10+int(a[9])

#print(y,m,d)

if y<=2018:
    print("Heisei")
elif y>=2020:
    print("TBD")
else:
    if m <= 4:
        print("Heisei")
    else:
        print("TBD")



Measured memory_bytes: 20488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(void){
    int n;cin>>n;
    vector<double>v(n);rep(i,n)cin>>v.at(i);
    sort(v.begin(),v.end());
    double ans=0;
    rep(i,n-3){ans=max(ans,(v.at(n-1)+v.at(n-2))/(v.at(i+1)-v.at(i)));}
    ans=max(ans,(v.at(n-4)+v.at(n-1))/(v.at(n-2)-v.at(n-3)));
    ans=max(ans,(v.at(n-4)+v.at(n-3))/(v.at(n-1)-v.at(n-2)));
    cout << fixed << setprecision(10);
    cout<<ans<<endl;
}


Measured memory_bytes: 3284
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <utility>
using namespace std;

const double eps = 1e-5;
template <typename T>
void print_vec(const vector<T> &v) {
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    if (i > 0) cout << ' ';
    cout << v[i];
  }
  cout << '\n';
}

bool check(vector<int> &a, double len, int k) {
  int cnt = 0;
  for (auto ai: a) {
    if (ai <= len) continue;
    cnt += (ai + len - 1) / len - 1;
  }
  return cnt <= k;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  int max_len = 0;
  for (auto &ai: a) {
    cin >> ai;
    max_len = max(max_len, ai);
  }

  int l = 0, r = max_len;
  while (r - l > 1) {
    int mid = (l + r)/ 2;
    if (check(a, mid, k)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 3952
s = input()
a = 0
if s == "SUN":
    a = 7
    print(a)
elif s == "MON":
    a = 6
    print(a)
elif s == "TUE":
    a = 5
    print(a)
elif s == "WED":
    a = 4
    print(a)
elif s == "THU":
    a = 3
    print(a)
elif s == "FRI":
    a = 2
    print(a)
elif s == "SAT":
    a = 1
    print(a)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
	int n,m,i,j,k,t[16],c[16],p,d;
	for( t[0] = n = i = 1; i < 16; i++ )t[i] = n *= 3;
	for(;scanf("%d%d",&n,&m),n;){
		for( k = 3; k-- ;)
			for( scanf("%d",&i); i--; c[j] = k )scanf("%d",&j);
		p = j = 0;
		for( k = 0; k++ < n;){
			j+=t[n-k]*abs(i=p-c[k]),p=i%2*2+p&3;
		}
		k = t[n] - 1 - j;
		if( j > k ) j = k;
		printf("%d\n", j > m ? -1 : j );
	}
	return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**6)  

N, M = map(int, input().split())
G = {k:[] for k in range(N)}
for _ in range(M):
  a, b = map(int, input().split())
  G[a-1].append(b-1)
  G[b-1].append(a-1)


def rel_side(v, G):  # 任意の頂点から、他のすべての頂点を訪問したかどうかを確認する関数
  if all(vis):
    return 1
  r = 0
  for side in G[v]:
    if not vis[side]:
      vis[side] = True
      r += rel_side(side, G)
  return r


bridge = 0
for i in range(N):
  for j, k in enumerate(G[i]):
    vis = [False] * N
    vis[i] = True
    pop1 = G[i].pop(j)
    idx = G[pop1].index(i)
    pop2 = G[pop1].pop(idx)
    if not rel_side(i, G):
      bridge += 1
    # print(vis, rel_side(i, G))
    G[i].insert(j, pop1)
    G[pop1].insert(idx, pop2)
    

print(bridge // 2)

Measured memory_bytes: 3064
import java.util.*;

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

        int n = sc.nextInt();
        
        int[] pricelist = new int[n];

        for(int i = 0;i < n;i++){
            pricelist[i] = sc.nextInt();
        }

        Arrays.sort(pricelist);

        pricelist[n-1] /= 2;

        int result = 0;
        for(int i = 0;i < pricelist.length;i++){
            result += pricelist[i];
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 23380
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int N = n;
		for(int i=0;i<111;i++){
			if((n+i)%111==0){
				System.out.println(n+i);
				break;
			}
		}
	}
}


Measured memory_bytes: 23120
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main() {
	int n, d;
	cin >> n >> d;
	int s = n / (2 * d + 1);
	if (n % (2 * d + 1) != 0)
		s++;
	cout << s << endl;
}

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

int main(){
  string s, a = "abc"; cin >> s;
  
  do{
      if(s == a){
          cout << "Yes" << endl;
          return 0;
      }
  }while(next_permutation(a.begin(), a.end()));
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
def main():    
    t =  int(input())
    n = 1
    a = list(map(int,input().strip().split()))[:t]
    for i in range(t):
        if a[i]==0:
            return 0
    for i in range(t):
        n*=a[i]
        if n>1e18:
            return -1
    if n>1e18:
        return -1
    else:
        return n
        
if __name__ == '__main__':
    print(main())

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  ll n,m;cin>>n>>m;
  P v[n+10];rep(i,0,n)cin>>v[i].first>>v[i].second;

  sort(v,v+n);

  ll sum=0;
  rep(i,0,n){
    if(m-v[i].second>=0)m-=v[i].second;
    else {sum+=v[i].first*m;break;}
    sum+=v[i].first*v[i].second;
  }
  out(sum);


  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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



int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    string ans = "";
    rep(i,n){
        ans += s[i];
        ans += t[i];
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
constexpr long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	ll h, n;
	cin >> h >> n;
	vector<ll> a(n), b(n);
	for (ll i = 0; i < n; i++) cin >> a[i] >> b[i];
	vector<ll> dp(h + 1, INF);
	dp[0] = 0;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j <= h; j++) {
			dp[j] = min(dp[j], dp[max(0ll, j - a[i])] + b[i]);
		}
	}
	cout << dp[h] << endl;
}

Measured memory_bytes: 3728
#include<iostream>
#include<algorithm>
#include<vector>
#include<tuple>
using namespace std;
int H, W, x[1000][1000], maxn = 1, cnt = 1;
vector<tuple<long double, int, int>>tup;
int analysis(int p, int q) {
	int D = x[p - 1][q - 1] * 1 + x[p - 1][q] * 2;
	D += x[p][q - 1] * 4 + x[p][q] * 8;
	if (D == 8 || D == 7)return 1;
	if (D == 1 || D == 14)return -1;
	return 0;
}
int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			char c; cin >> c; if (c == '#')x[i][j] = 1;
		}
	}
	for (int i = 1; i <= H + 1; i++) {
		for (int j = 1; j <= W + 1; j++) {
			int XX = (H + 1) - i, YY = j - 1;
			if (XX + YY == 0)continue;
			tup.push_back(make_tuple(1.0l*YY / XX, i, j));
		}
	}
	sort(tup.begin(), tup.end());
	for (int i = 0; i < tup.size(); i++) {
		int p = analysis(get<1>(tup[i]), get<2>(tup[i]));
		cnt += p;
		long double B = 0.0l;
		if (i < tup.size() - 1)B = fabs(get<0>(tup[i]) - get<0>(tup[i + 1]));
		if (i == (tup.size() - 1) || B > 1e-12) {
			maxn = max(maxn, cnt);
		}
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 21660
/*
Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog ender-zzm.enbar.cn
*/
#include <bits/stdc++.h>
using namespace std;

inline int Isdigit(char c) {
	if (c < '0' || c > '9') return 0;
	return 1;
}
inline int readint(){
    register int x = 0, flag = 1;
    register char ch;
    while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}

inline long long readlong() {
	register long long x = 0, flag = 1;
	register char ch;
	while (!Isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), Isdigit(ch = getchar()));
	return x * flag;
}
template <class T>
inline void write(T x){
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, x, y) for (int i = (x); i <= (y); i++) 
#define Rep(i, x, y) for (int i = (x); i >= (y); i--) 
#define ri readint
#define rl readlong

#define int long long
const int maxn = 2e5 + 30;
int n, Mod;
int a[maxn];
int tong[maxn];
string s;
signed main() {
	n = ri(); Mod = ri();
	cin >> s;
	int ans = 0;
	int tmp = 0;
	if (Mod == 2 || Mod == 5) {
		for (int i = 0; i < s.size(); i++) {
			a[i] = s[i] - '0';
			if (Mod == 2 && a[i] % 2 == 0) {
				ans += i + 1;
			}
			if (Mod == 5 && (a[i] == 0 || a[i] == 5)) {
				ans += i + 1;
			}
		}
		cout << ans; return 0;
	}
	tong[0]++;
	int op = 1;
	for (int i = s.size() - 1; i >= 0; i--) {
		a[i] = s[i] - '0';
		tmp = (1ll * tmp + 1ll * a[i] * op % Mod) % Mod;
		op = op * 10 % Mod;
		ans += tong[tmp];
		tong[tmp]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5372
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		int min=Integer.MAX_VALUE;
		for(int i=0;i<s.length()-2;i++) {
			int temp = Integer.parseInt(s.substring(i,i+3));
			if(Math.abs(temp-753)<min)min=Math.abs(temp-753);
		}
		System.out.println(min);
	}

}


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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(n) scanf("%d",&n)
#define sff(n1,n2) scanf("%d %d",&n1,&n2)
#define sfff(n1,n2,n3) scanf("%d %d %d",&n1,&n2,&n3)
#define sl(n) scanf("%lld",&n)
#define sll(n1,n2) scanf("%lld %lld",&n1,&n2)
#define slll(n1,n2,n3) scanf("%lld %lld %lld",&n1,&n2,&n3)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define nl puts("");
#define pb push_back
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define sz(x) x.size()
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define line puts("-------");
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
typedef long long int ll;
using namespace std;
int main()
{
    ll n;
    cin>>n;
    if(n&1)
    {
        cout<<0;
        return 0;
    }
    ll m=n,cur=10,cnt=0;
    while(cur<=n)
    {
        cnt+=n/cur;
        cur*=5;
    }
    cout<<cnt;
}


Measured memory_bytes: 256
import java.util.*;


class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        sc.close();
        int ans = 0;
        for(int i = 0; i < 10; i++){
            ans = r * x - d;
            System.out.println(ans);
            //次の繰り返し処理でXi+1にするためのもの
            x = ans;
        }
    }
}

Measured memory_bytes: 21588
n = int(input())
w = [int(s) for s in input().split()]

s = 0
for t in range(n):
    s1 = sum(w[:t])
    s2 = sum(w[t:])
    if(t != 0 and s < abs(s1-s2)):
        break
    else:
        s = abs(s1-s2)

print(s)


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include <vector>
#include <set>
using namespace std;
int main(){
	string a;
	cin>>a;
	if(a=="a"||a=="i"||a=="u"||a=="e"||a=="o")
		cout<<"vowel"<<endl;
	else cout<< "consonant"<<endl;
}


Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d%d", $n, $k);
  fscanf(STDIN, "%d%d%d", $r, $s, $p);
  $t = trim(fgets(STDIN));
  $sco = array(
      "r" => $p,
      "s" => $r,
      "p" => $s
      );
//   print_r($sco);
  $ans = 0;
  for($i=0; $i<$n; $i++){
      $ans += $sco[$t[$i]];
  }
  for($i=$k; $i<$n; $i++){
      if($t[$i] == $t[$i-$k]){
          $ans -= $sco[$t[$i]];
          $t[$i] = "f";
      }
  }
  echo $ans;
  

Measured memory_bytes: 16488
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 1e6 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
const long long MAXL = 1e18;
ll a[N];
void solve(){
    int n;
    cin >> n;
    ll ans = 1;
    int cnt = 0;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        cnt += a[i] == 0;
    }
    if(cnt){
        cout << 0;
        return;
    }    
    for(int i = 1; i <= n; ++i) {
        if(ans <= LINF / a[i]) {
            ans *= a[i];
        }else {
            cout << -1;
            return;
        }
    }

    if(ans > MAXL) {
        cout << -1;
    }else {
        cout << ans;
    }
}

 
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  int a = 0, b = 0;
  for (int i = 0; i < n; ++i)
  {
    string s, t;
    cin >> s >> t;
    if (s > t)
      a += 3;
    else if (s < t)
      b += 3;
    else
      a++, b++;
  }
  cout << a << ' ' << b << endl;

  return 0;
}



Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(){
    string a,b,c;
    cin>>a>>b;
    c = a+b;
    int d=0,i,k=1;
    for(i = c.size()-1;i >= 0;i--){
        d = d+(c[i]-'0')*k;
        k = k*10;
    }
    int flag=0;
    for(i = 1;i < 2000;i++){
        if(i*i==d){
            flag++;
        }
    }
    c = b+a;
    for(i = c.size()-1;i >= 0;i--){
        d = d+(c[i]-'0')*k;
        k = k*10;
    }
    //int flag=0;
    for(i = 1;i < 2000;i++){
        if(i*i==d){
            flag++;
        }
    }
    if(flag>0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int a, b;
    char c;
    while (cin >> a >> c >> b && c != '?'){
        if (c == '+') a += b;
        if (c == '-') a -= b;
        if (c == '*') a *= b;
        if (c == '/') a /= b;
        cout << a << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <assert.h>
#include <numeric>

using namespace std;

int solve() {
    int N;
    cin >> N;

    vector<int> Xs(N);
    vector<int> SXs(N);
    for (int i = 0; i < N; i++) {
        int X;
        cin >> X;
        Xs[i]=X;
        SXs[i]=X;
    }
    sort(SXs.begin(), SXs.end());
    int med = SXs[(SXs.size()+1)/2];
    for (int i = 0; i < N; i++) {
        if (N%2) {
            if (Xs[i] > med) {
                cout << SXs[(SXs.size()+1)/2-1] << endl;
            } else {
                cout << SXs[(SXs.size()+1)/2] << endl;
            }
        } else {
            if (Xs[i] >= med) {
                cout << SXs[(SXs.size()+1)/2-1] << endl;
            } else {
                cout << SXs[(SXs.size()+1)/2] << endl;
            }
        }
    }
    return 0;
}

int main() {
    solve();
#ifdef DEBUG
    while (1) {
        solve();
    }
#endif
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
template<typename T>
struct UnionFind
{
	vector<T> par;
	vector<T> rank;
	UnionFind(T n):par(n),rank(n,0){
	   for(T i=0;i<n;i++){
	     par[i]=i;
	   }
	}
	T root(T x){
	  return par[x]==x?x:par[x]=root(par[x]);
	}

	bool unite(T x,T y){
	  if(x==y) return false;
	  x=root(x); y=root(y);
	  if(x==y) return false;
	  if(rank[x]<rank[y]) swap(x,y);
	  if(rank[x]==rank[y]) rank[x]++;
	  par[y]=x;
	  return true;
	}
	bool same(T x,T y){
	  return root(x)==root(y);
	}
};
int main(){
  ll n,m;
  cin>>n>>m;
  vll p(n);
  rep(i,n) cin>>p[i];
  UnionFind<ll> uf(n+1);
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    uf.unite(a,b);
  }
  ll ans=0;
  rep(i,n){
    if(uf.same(i+1,p[i])){
      ans++;
    }
  }
  COUT(ans);
}

Measured memory_bytes: 2560
import math
from collections import defaultdict
import numpy as np
n = int(input())
dic = defaultdict(lambda : 0)
for i in range(2, n + 1):
    sqrt = math.floor(i ** 0.5)
    for j in range(2, sqrt + 1):
        if not i % j:
            count = 0
            while i % j == 0:
                count += 1
                i //= j
            dic[j] += count
    if i > 1:
        dic[i] += 1
values = np.array(list(dic.values()))
v1 = len(values[values >= 2])
v2 = len(values[values >= 4])
v = (v2 * (v2 - 1) // 2) * (v1 - 2)

v3 = len(values[values >= 24])
v += v3 * (v1 - 1)

v4 = len(values[values >= 14])
v += v4 * (v2 - 1)

v5 = len(values[values >= 74])
v += v5
print(v)

Measured memory_bytes: 20232
#include<iostream>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int w,h,s,sum;
struct P{
	int y,x;
	inline P(){}
	inline P(int y,int x):y(y),x(x){}
};
P pmax(P a,P b){
	if(a.y!=b.y){
		if(a.y>b.y)
			return a;
		return b;
	}else{
		if(a.x>b.x)
			return a;
		return b;
	}
}
int u[32][32];
P dp[32][32][32][32];
P ret(P a,P b,int cnt){
	if(dp[a.y][a.x][b.y][b.x].y!=-1)
		return dp[a.y][a.x][b.y][b.x];
	P ans(1,cnt);
	int s1=0,s2=0;
	for(int i=a.y;i<b.y;i++){
		for(int j=a.x;j<=b.x;j++){
			s1+=u[i][j];
		}
		if(sum-s1>s)
			continue;
		if(sum-(cnt-s1)>s)
			break;
		P x=ret(a,P(i,b.x),s1),y=ret(P(i+1,a.x),b,cnt-s1);
		ans=pmax(ans,P(x.y+y.y,min(x.x,y.x)));
	}
	for(int i=a.x;i<b.x;i++){
		for(int j=a.y;j<=b.y;j++){
			s2+=u[j][i];
		}
		if(sum-s2>s)
			continue;
		if(sum-(cnt-s2)>s)
			break;
		P x=ret(a,P(b.y,i),s2),y=ret(P(a.y,i+1),b,cnt-s2);
		ans=pmax(ans,P(x.y+y.y,min(x.x,y.x)));
	}
	return dp[a.y][a.x][b.y][b.x]=ans;
}
int main(){
	while(cin>>h>>w>>s,h||w||s){
		sum=0;
		rep(i,h)rep(j,w)rep(k,h)rep(l,w)
		dp[i][j][k][l]=P(-1,0);
		rep(i,h)rep(j,w){
			cin>>u[i][j];
			sum+=u[i][j];
		}
		P ans=ret(P(0,0),P(h-1,w-1),sum);
		cout<<ans.y<<" "<<s-(sum-ans.x)<<endl;
	}
	return 0;
}

Measured memory_bytes: 9068
#include <bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int maxn=2*1e5+5;

int main()
{
    FAST

    int x;
    cin>>x;
    int a[x];
    for(int i=0; i<x; i++)
        cin>>a[i];
// sort(a,a+x);
    int t=1;
    bool flag=true;
    int ans=0;
    for(int i=0; i<x; i++)
    {
        if(a[i]==t)
        {

            t++;
        }
        else
        {
            a[i]=0;

        }
    }
    for(int i=0; i<x; i++)
        if(a[i])
            ans++;

        if(!ans)
            cout<<-1<<endl;
        else
            cout<<x-ans<<endl;

    return 0;
}


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

int main()
{
	int N;
	cin >> N;
	vector<int> vec(N);
	for (auto& v : vec)
	{
		cin >> v;
	}

	int ans = 0;
	for (int i = 1; i < N - 1; ++i)
	{
		if (min(vec[i - 1], vec[i + 1]) < vec[i] && max(vec[i - 1], vec[i + 1]) > vec[i])
			ans++;
	}

	cout << ans << endl;
	return 0;
}


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

int main(){

  vector<int>w,k;
  for(int i=0;i<10;i++){
    int n;
    cin>>n;
    w.push_back(n);
  }
  for(int i=0;i<10;i++){
    int n;
    cin>>n;
    k.push_back(n);
  }

  sort(w.begin(),w.end());
  sort(k.begin(),k.end());

  cout<<w[9]+w[8]+w[7]<<" "<<k[9]+k[8]+k[7]<<endl;

}

Measured memory_bytes: 1220
#include <stdio.h>

int main(void)
{
    int loop, n = 0;
    char i[4];
    scanf("%s", i);
    for (loop = 0; loop < 4; loop++)
    {
        if (i[loop] == '+') n++;
        else if (i[loop] == '-') n--;
    }
    printf ("%d\n", n);
    return (0);
}


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

int main()
{
    int n;
    cin >> n;
    bool bRet = false;
    for(int i=1;i<10;i++){
        if(n%i == 0 && n/i < 10){
            bRet = true;
            break;
        }
    }
    if(bRet)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
using namespace std;

int main(){

  long long int n, a=2, b=1, ans;
  cin >> n;

  for(int i=0; i<n-1; i++){
    ans=a+b;
    a=b;
    b=ans;
  }

  if(n==1){
    cout << 1 << endl;
    return 0;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let a = get!([isize]);
    let b = get!([isize]);

    let mut anum = 0;
    let mut bnum = 0;
    for (a,b) in a.into_iter().zip(b.into_iter()) {
        let c = a-b;
        if c < 0 {
            anum += -c/2;
        } else {
            bnum += c;
        }
    }
    if anum >=  bnum {
        println!("Yes");
    } else   {
        println!("No");
    }
}


Measured memory_bytes: 8572
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a;
        a = new int[n];
        int i;
        long sum = 0;
        for(i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int max = a[0];
        int min = a[0];
        for(i = 0; i < n; i++) {
            if(max < a[i]) {
                max = a[i];
            }
            if(min > a[i]) {
                min = a[i];
            }
            sum += a[i];
            }
            System.out.println(min + " " + max + " " + sum);
        }
    }



Measured memory_bytes: 41804
N, A = map(int, input().split())
X = list(map(lambda x: int(x)-A, input().split()))
X_MAX = max(max(X), -min(X))
NX = N * X_MAX
dp = [[0] * (X_MAX * (N+1) * 2 + 1)  for i in range(N+1)]
dp [0][NX] = 1
for i in range(1, N+1):
    for j in range(NX*2+1):
        dp[i][j] += dp[i-1][j]
        dp[i][j] += dp[i-1][j-X[i-1]]

print(dp[N][NX]-1)

Measured memory_bytes: 68988
/*      ex4_1
        Tarara  */
#include <stdio.h>
#include <math.h>

int main(void)
{
    int n;        // 林檎の木の本数
    int distance; //ひとりの監視員が監視する距離

    scanf("%d %d", &n, &distance);

    int range = 2 * distance + 1; //ひとりの監視員が監視できる最大範囲
    int observers = (int)ceil((double)n / range); //必要な監視員の数
    printf("%d\n", observers);
    return 0;
}

Measured memory_bytes: 128
from fractions import gcd

N, M = map(int, input().split())
S = input()
T = input()

lcm = N * M // gcd(N, M)
n = N // gcd(N, M)
m = M // gcd(N, M)

for k in range(gcd(N, M)):
    a = k * n
    b = k * m
    if S[a] != T[b]:
        print(-1)
        exit()

print(lcm)


Measured memory_bytes: 65260
#include <stdio.h>
int main(void)
{
	int a, b, c, x, y, z;
	scanf("%d %d %d", &a, &b, &c);
	x=a; y=b; z=c;
	if(x>y){
		x=b; y=a;
		if(y>z){
			y=c; z=a;
			if(x>y){
				x=c; y=b;
			}
		}		
	}else if(y>z){
		y=c; z=b;
		if(x>y){
			x=c; y=a;
		}
	}
	printf("%d %d %d\n", x, y, z);
	return 0;
}

Measured memory_bytes: 596
N = int(input())

if N < 10:
    print(N)
elif N < 100:
    print(9)
elif N < 1000:
    print(N - 100 + 1 + 9)
elif N < 10000:
    print(909)
elif N < 100000:
    print(N - 10000 + 1 + 909)
elif N == 100000:
    print(90909)


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

typedef long long ll;
const ll INF=0x3f3f3f3f;
const int N=1e5+5;

int main()
{
    ll max1=INF,ans=0;
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        ll a,b;
        scanf("%lld%lld",&a,&b);
        ans+=a;
        if(a>b)
        {
            if(b<max1)
            max1=b;
        }
    }
    printf("%lld\n",max1==INF?0:ans-max1);
    return 0;
}



Measured memory_bytes: 256