akhauriyash/Code-Regression huggingface dataset:
import Data.Array

main::IO()
main = do
  nmc<-getLine
  let n:m:[]= map read (words nmc) ::[Int]
  pica<-get_mat n
  picb<-get_mat m
  putStr ((if(checker pica picb n m) then "Yes" else "No")++"\n")


get_nline::Int -> IO([String])
get_nline 0 = return []
get_nline n = do
  d<-getLine
  rest<-get_nline (n-1)
  return (d:rest)

get_mat::Int -> IO (Array (Int,Int) Char)
get_mat n = do
  dat<-get_nline n
  return (listArray ((0,0),(n-1,n-1)) (concat (map (take n) dat)))



init_shifts::Int -> Int ->[(Int,Int)]
init_shifts n m = [(i,j)|i<-[0..(n-m)],j<-[0..(n-m)]]

--画像二つとそのサイズをうけて、シフト可能性のもとで一致すること。
checker::(Array (Int,Int) Char) -> (Array (Int,Int) Char) -> Int -> Int -> Bool
checker pic_A pic_B n m = let shifts = init_shifts n m in
                          let check_coord = [(x,y)|x<-[0..(m-1)],y<-[0..(m-1)]] in
                          (foldr extract shifts check_coord)/=[]
                            where extract (l,m) sft = filter (\(a,b)-> (pic_A!(l+a,m+b))==(pic_B!(l,m)) ) sft


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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll n, k, s;
    cin >> n >> k >> s;
    vector<ll> ans(n);
    ll cnt = 0;
    if(s == 1000000000){
        rep(i, 0, n){
            if(i < k){
                ans[i] = 1000000000;
            }else{
                ans[i] = 1000000000 - 1;
            }
        }
    }else{
        rep(i, 0, n){
            if(i < k){
                ans[i] = s;
            }else{
                ans[i] = 1000000000;
            }
        }
    }
    cout << ans[0];
    rep(i, 1, n){
        cout << " " << ans[i];
    }
    cout << endl;

}


Measured memory_bytes: 2048
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
//#define double long double
using namespace std; const int N=400010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
int n,m,k,a[N],b[N];
signed main()
{
    n=read(), m=read(), k=read();
    int res=0;
    for(ri int i=1;i<=n;i++) a[i]=read(), a[i]+=a[i-1];
    for(ri int i=1;i<=m;i++) b[i]=read(), b[i]+=b[i-1];
    for(ri int i=0;i<=n;i++)
    {
        if(a[i]>k) break;
        int p=upper_bound(b+1,b+1+m,k-a[i])-b;
        res=max(res,i+p-1);
    }
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 6804
#include <iostream>

using namespace std;

int main(void)
{
  char a[100][100];
  int H, W;
  cin >> H >> W;

  int heightNum[100] = {0};
  int widthNum[100] = {0};

  for(int j = 0; j < H; j++){
    for(int i = 0; i < W; i++){
      cin >> a[j][i];
    }
  }

  for(int j = 0; j < H; j++){
    for(int i = 0; i < W; i++){
      if(a[j][i] == '#'){
        heightNum[j] = 1;
        break;
      }
    }
  }

  for(int i = 0; i < W; i++){
    for(int j = 0; j < H; j++){
      if(a[j][i] == '#'){
        widthNum[i] = 1;
        break;
      }
    }
  }

  for(int j = 0; j < H; j++){
    if(heightNum[j] == 0){
      continue;
    }
    for(int i = 0; i < W; i++){
      if(widthNum[i] == 0){
        continue;
      }
      cout << a[j][i];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int k = sc.nextInt();

        int count = 0;
        int ans = 0;
        int max = Math.max(a, b);
        for (int i = max; i > 0; i--) {
            if (a % i == 0 && b % i == 0) count++;

            if (count == k) {
                ans = i;
                break;
            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
let () =
  let int_list = List.map int_of_string (Str.split (Str.regexp " ") (read_line ())) in
  let (a, b) = (List.nth int_list 0), (List.nth int_list 1) in
  Printf.printf "%s\n" (if a < b then "a < b" else if a > b then "a > b" else "a == b")

Measured memory_bytes: 2148
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x,T a,T b){return a<=x&&x<=b;}
template<class T> void amin(T &a,T v){if(a>v) a=v;}
template<class T> void amax(T &a,T v){if(a<v) a=v;}
int ROUND(double x) { return (int)(x+0.5); }
bool ISINT(double x) { return fabs(ROUND(x)-x)<=EPS; }
bool ISEQUAL(double x,double y) { return fabs(x-y)<=EPS*max(1.0,max(fabs(x),fabs(y))); }
double SQSUM(double x,double y) { return x*x+y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	stack <char> ls;
	string s;

	cin >> s;
	for (int i = 0; i < SZ(s); ++i)
	{
		ls.push(s[i]);
		while (SZ(ls) >= 2)
		{
			char lst = ls.top();
			ls.pop();
			char lst2 = ls.top();
			ls.pop();

			if (lst == 'T' && lst2 == 'S')
			{
			}
			else
			{
				ls.push(lst2);
				ls.push(lst);
				break;
			}
		}
	}

	printf("%d\n",SZ(ls));


	return 0;
}



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

int main() {

  int N;
  cin >> N;

  vector<long long> answer(N + 1);

  answer[0] = 2;
  answer[1] = 1;

  for (int i = 2; i <= N; i++) {
    answer[i] = answer[i - 1] + answer[i - 2];
  }

  cout << answer[N] << endl;

}

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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (N, K) = Slice2<long>();
            var hi = new long[N];
            for (var i = 0; i < N; ++i)
                hi[i] = Sarray()[0];
            Array.Sort(hi);
            var min = long.MaxValue;
            for (var i = 0; i < N - (K - 1); ++i) 
                min = Min(min, hi[i + K - 1] - hi[i]);
            WriteLine(min);
        }

        static long Mod = (long)1e9 + 7;

        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

Measured memory_bytes: 47684
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
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(){
  int N, M; cin >> N >> M;
  vector<tuple<int, int, int>> city(M);
  for(int i=0;i<M;i++){
    cin >> get<0>(city[i]) >> get<1>(city[i]);
    get<2>(city[i])=i;
  }
  sort(city.begin(), city.end());
  get<1>(city[0])=1;
  for(int i=1;i<M;i++){
    if(get<0>(city[i-1])==get<0>(city[i])){
      get<1>(city[i])=get<1>(city[i-1])+1;
    }
    else get<1>(city[i])=1;
  }
  for(int i=0;i<M;i++){
    swap(get<0>(city[i]),get<2>(city[i]));
  }
  sort(city.begin(),city.end());
  for(int i=0;i<M;i++){
    cout << setfill('0') << right << setw(6) << get<2>(city[i]) << setfill('0') << right << setw(6) << get<1>(city[i]) << endl;
  }
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define llMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int n, m;
map<int, int> mp;

int main(){
  cin >> n >> m;
  vector<int> a(m);
  vector<ll> dp(n+1);
  for(int i = 0; i < m; i++)cin >> a[i];

  //降順にする
  sort(all(a));
  reverse(all(a));

  string res = "";

  //数字とマッチ棒の対応を表す連想配列の定義
  mp[1] = 2; mp[2] = 5; mp[3] = 5;
  mp[4] = 4; mp[5] = 5; mp[6] = 6;
  mp[7] = 3; mp[8] = 7; mp[9] = 6;
  

  //桁に対してDPを行う．dp[i] = 桁数: i本のマッチ棒で作れる桁数
  dp[0] = 0;
  for(int i = 1; i < n+1; i++){
    ll ans  = INT32_MIN;
    for(int j = 0; j < m; j++){
      ll index = i - mp[a[j]];
      if(index >= 0){
        ll tmp = dp[index]+1;
        ans = max(tmp, ans);
      } 
    }
    dp[i] = ans;
  }

  //dp[n]の桁に対して，最上位桁かた順々に決定していく．
  int match = n;//マッチの数
  while(match > 0){
    for(int j = 0; j < m; j++){
      int index = match - mp[a[j]];
      if(index < 0 )continue; //indexの負は未定義なので，処理しない
      if(dp[index] == (dp[match]-1)){
        res += a[j]+'0';
        match -= mp[a[j]];
        break; //決まったら次のマッチ棒へ
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trv(a) cerr<<#a<<":\n";for(ll zz=0;zz<a.size();zz++) cerr<<a[zz]<<" ";cerr<<endl
#define mod 1000000007
#define inf 9999999999999999ll

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a,b,c;
	set <ll> s;
	cin>>a>>b>>c;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	if(s.size()==2)
	{
		cout<<"Yes\n";
	}
	else
		cout<<"No\n";
}


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

using namespace std;

#define PI 3.1415926535897932

//typedef long long ll;


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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 **/


int main(){
    int mod=1000000007;
    int ans=0;
    char s[4];
     
    scanf("%s",&s);
    for (int i=0;i<4;i++) {
        if (s[i]=='+') ans++;
        if (s[i]=='-') ans--;
    }
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 256
#from collections import deque,defaultdict
from sys import stdin
input = stdin.readline
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

import bisect
n,m,k = inm()
a = inl()
b = inl()
acca = [0]*(n+1)
accb = [0]*(m+1)
for i in range(n):
    acca[i] = acca[i-1]+a[i]
acca.pop()
for i in range(m):
    accb[i] = accb[i-1]+b[i]
mx = 0 #bisect.bisect_left(a,k+1)
for i in range(m+1):
    x = 0 if i==0 else accb[i-1]
    if x>k:
        break
    j = bisect.bisect_left(acca,k-x+1)
    #ddprint(f"{i=} {mx=} {x=} {j=}")
    mx = max(mx, i+j)
print(mx)


Measured memory_bytes: 118264
import Data.List
import Control.Monad
prep::[(Int,Int)]->[(Int,Int)]
prep = sortBy (\ (a1,b1) -> \ (a2,b2) -> if a1==a2 then compare b2 b1 else compare a1 a2 )

solver::Int->(Int,Int)->[(Int,Int)]->Int
solver i _ [] = i
solver i (l,r) ((a,b):rest) = if (l>=b)||(r<=a) then solver (i+1) (a,b) rest else solver i (max a l,min b r) rest

main::IO()
main=do
  nm<-getLine
  let n:m:[] =map read (words nm) ::[Int]
  sss <- forM [1..m] (\_ -> getLine)
  let d = map (\x ->let a:b:[]= map read (words x)in (a,b)) sss
  let dat = prep d
  print (solver  1 (head dat) (tail dat))


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

typedef long long ll;
typedef vector<int> vi;

const double PI=acos(-1.0);

int N,X; vi d;

int gcd(int a, int b)
{
    int c=a%b;
    while(c!=0){
        a=b; b=c; c=a%b;
    }
    return b;
}

void input()
{
    cin>>N>>X;
    for(int i=0;i<N;++i){
        int a; cin>>a; 
        d.emplace_back((X-a>0)?X-a:a-X);
    }   
}

void solve()
{
    int ans=d[0];
    for(int i=1; i<d.size(); ++i){
        ans=gcd(ans,d[i]);
    }
    cout<<ans<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3880
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9

using namespace std;

int main()
{

    ll t,n,m,f,a,b,c,d,l,r,q,k,w,x,y,z,ans,mn,mx,sum=0;
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    cin>>a>>b>>c>>d;

    w = a*c;
    x = a*d;
    y = b*c;
    z = b*d;

    cout<<max({w,x,y,z})<<endl;

}


Measured memory_bytes: 3628
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    int x,y,a[]={1,3,5,7,8,10,12},b[]={4,6,9,11},X=0,Y=0;
    cin>>x>>y;
    for(int z:a) if(z==x) X=1; else if(z==y) Y=1;
    for(int z:b) if(z==x) X=2; else if(z==y) Y=2;
    cout<<((X==Y)?"Yes":"No")<<endl;
    
    return 0;
}

Measured memory_bytes: 256
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define        u64             uint64_t
#define        ll              long long
#define        endl            "\n"
#define        PI              acos(-1)
#define        fi              first
#define        si              second
#define        mkp             make_pair
#define        pb              push_back
#define        set0(arr)       memset(arr, 0, sizeof(arr))
#define        setinf(arr)     memset(arr, 126, sizeof(arr))
#define        all(x)          (x).begin(),(x).end()
#define        sz(v)           ((int)(v).size())
#define        IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
using          pll        =      pair<ll, ll> ;
using          vl         =      vector<ll> ;
using          vpll       =      vector<pll> ;
using          mll        =      map<ll, ll> ;
using          mcl        =      map<char, ll> ;
using          msl        =      map<string,ll> ;
using          sl         =      set<ll> ;
using          sc         =      set<char> ;
using          dl         =      deque<ll> ;
const int N = 1e6+5 ;

ll      mod = 1e9+7 ;
vl      adj[N] ;
vpll    adjc[N] ;
ll      vis[N] ;
ll      arr[N],g ;

void dfs(ll x)
{
       g++;
       vis[x]=1;
       for(ll i=0;i<sz(adj[x]);i++)
       {
              ll p=adj[x][i];
              if(!vis[p])
              {
                     dfs(p);
              }
       }
}
int main()
{
    IOS;
    ll a, b, c, d, n, m, p, x, y, z, i, j, k, f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18;
    string   str ;
    char     ch ;
    double   db ;
    ll       l, r ;
    //code

    cin>>n>>m;
    map<pair<ll,ll>,ll>mp;
    for(i=0;i<m;i++)
    {
           cin>>a>>b;
           if(mp[{a,b}]==0){
           adj[a].pb(b);
           adj[b].pb(a);}
           mp[{a,b}]=1;
           mp[{b,a}]=1;
    }
    set0(vis);
    for(i=1;i<=n;i++)
    {
           g=0;
           if(!vis[i])
           {
                dfs(i);
           }
           ma=max(ma,g);
    }
    cout<<ma<<endl;


    //code
    return 0;
}



Measured memory_bytes: 95796
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  if ((n + 1) / 2 >= m) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


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

int main() {
   ll n; cin>>n;
   vector<string> s(n);
   rep(i,n){
     cin>>s.at(i);
     sort(s.at(i).begin(),s.at(i).end());
   }
  
   map<string,ll> a;
   rep(i,n){
     if(a.count(s.at(i))){a[s.at(i)]++;}
     else{a[s.at(i)]=1;}
   }
   ll ans= 0;
   for(pair<string, ll> p:a){
     ll v =p.second;
     ans+=v*(v-1)/2;
   }
   cout<<ans;
}
      

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

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)


int main(){
    ll n;cin>>n;
    ll dp[n+1];
    fr(i,n+1)dp[i]=1e8;
    fr(i,n+1){
        if(i==0)dp[i]=0;
        else{
            ll j = 1;
            while(j<=i){
                dp[i] = min(dp[i],dp[i-j]+1);
                j*=6;
            }
            ll k = 1;
            while(k<=i){
                dp[i]=min(dp[i],dp[i-k]+1);
                k*=9;
            }
        }
    }
    cout << dp[n]<<endl;
}

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

int main(){

  long long N, W, i, j;
  cin>>N>>W;
  vector<long long> v(N), w(N);
  vector<vector<long long>> dp(N+1, vector<long long>(W+1, 0));

  for(i=0; i<N; i++){
    cin>>w[i]>>v[i];
  }

  for(i=0; i<N; i++){
    for(j=0; j<W+1; j++){
      if(j+w[i]<=W) dp[i+1][j+w[i]]=max(dp[i][j]+v[i], dp[i+1][j+w[i]]);
      dp[i+1][j]=max(dp[i][j], dp[i+1][j]);
    }
  }
  
  cout<<dp[N][W]<<endl;
  return 0;
}


Measured memory_bytes: 83192
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
// int dx[]={0,1,0,-1,1,-1,-1,1};
// int dy[]={1,0,-1,0,1,1,-1,-1};
int dx[]={1,0};
int dy[]={0,1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

signed main(){
  int n;
  cin>>n;
  vector<tuple<string,int,int>> sp(n);
  rep(i,n){
    string s;int p;
    cin>>s>>p;
    p*=-1;
    sp[i]=make_tuple(s,p,i+1);
  }
  sort(sp.begin(),sp.end());
  rep(i,n){
    int k=get<2>(sp[i]);
    cout<<k<<endl;
  }


  return 0;
}

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

int main(){
    long double a,b,c,d,ans ;
    cin >> a >> b >> c >> d ;
    ans = sqrt((a-c)*(a-c)+(b-d)*(b-d)) ;
    cout << fixed << setprecision(10) << ans << endl ;
}


Measured memory_bytes: 3292
// Copyright 2017 Parallelc
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std;  // NOLINT
using namespace __gnu_cxx;
using LL = int64_t;
const int INF = 0x3f3f3f3f;
const LL mod = 1000000007;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string n, m;
    cin >> n >> m;
    vector<char> a(n.length()), b(m.length());
    a[0] = n[0];
    string s = "";
    s += a[0];
    for (int i = 1; i < n.length(); i++) {
        s += n[i];
        if (s == "AB" || s == "BA") s = "";
        else if (s == "AA") s = "B";
        else if (s == "BB") s = "A";
        a[i] = s[0];
    }
    b[0] = m[0];
    s = "";
    s += b[0];
    for (int i = 1; i < m.length(); i++) {
        s += m[i];
        if (s == "AB" || s == "BA") s = "";
        else if (s == "AA") s = "B";
        else if (s == "BB") s = "A";
        b[i] = s[0];
    }
    int t;
    cin >> t;
    while (t--) {
        int i, j, k, l;
        cin >> i >> j >> k >> l;
        i--, i--, j--, k--, k--, l--;
        char s, t;
        if (a[i] == a[j]) s = '1';
        else if (a[i] == 0) s = a[j];
        else if (a[j] == 0) s = a[i] == 'B'?'A':'B';
        else s = a[i];
        if (b[k] == b[l]) t = '1';
        else if (b[k] == 0) t = b[l];
        else if (b[l] == 0) t = b[k] == 'B'?'A':'B';
        else t = b[k];
        if (s == t) cout << "YES\n";
        else cout << "NO\n";
    }
}


Measured memory_bytes: 976
import java.io.*;
import java.text.*;
import java.util.*;

public class Main {

    static InputReader sc = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        solver s = new solver();
        int t = 1;
        while (t > 0) {
            s.solve();
            t--;
        }
        out.close();
    }

    static class InputReader {

        public BufferedReader br;
        public StringTokenizer token;

        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream), 32768);
            token = null;
        }

        public String sn() {
            while (token == null || !token.hasMoreTokens()) {
                try {
                    token = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return token.nextToken();
        }

        public int ni() {
            return Integer.parseInt(sn());
        }

        public String snl() throws IOException {
            return br.readLine();
        }

        public long nlo() {
            return Long.parseLong(sn());
        }

        public double nd() {
            return Double.parseDouble(sn());
        }

        public int[] na(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.ni();
            return a;
        }

        public long[] nal(int n) {
            long a[] = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = sc.nlo();
            return a;
        }
    }

    static int inf = 5000013;

    static class solver {
        DecimalFormat df = new DecimalFormat("0.00000000");
        int maxi = 200000000;

        void solve() {
            char c[] = sc.sn().toCharArray();
            char t[] = sc.sn().toCharArray();
            int n = c.length;
            int m = t.length;
            int dp[][] = new int[n + 1][m + 1];
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    if (c[i - 1] == t[j - 1])
                        dp[i][j] = dp[i - 1][j - 1] + 1;
                    else
                        dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
                }
            }
            build(dp, n, m, c,t);
            out.println(ans.reverse());
        }

        StringBuilder ans = new StringBuilder();

        void build(int a[][], int i, int j, char s[],char t[]) {
            if(i==0 || j==0)
                return;
            if(s[i-1]==t[j-1])
            {
                ans.append(s[i-1]);
                build(a,i-1,j-1,s,t);
            }
            else
            {
                if(a[i-1][j]>a[i][j-1])
                    build(a,i-1,j,s,t);
                else
                    build(a,i,j-1,s,t);
            }
        }
    }
}


Measured memory_bytes: 82388
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define all(a) begin(a),end(a)
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define sz(x) ((int)x.size())
#define ins insert
#define rep(i,l,u) for(int i=l;i<=u;++i)
#define reb(i,l,u) for(int i=l;i>=u;--i)
using namespace std;
const int maxn=2e5+10;
const int mod=1e9+7;
int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
int a[maxn];
int n,k;
bool check(int x){
    int need=0;
    if(x==0)return false;
    for(int i=1;i<=n;++i){
        need+=(a[i]-1)/x;
    }
    if(need<=k)return true;
    else return false;
}
main(){
    cin>>n>>k;
    int mx=0;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        mx=max(mx,a[i]);
    }
    int l=0,r=mx;
    while(l<=r){
        int mid=(l+r)>>1;
        if(check(mid)){
            r=mid-1;
        }else{
            l=mid+1;
        }
    }
    cout<<l<<endl;
}


Measured memory_bytes: 5092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9) + 7;
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

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

ll factorial(ll n){
    ll t = 1;
    rep1(i, n){
        t *= i;
        t %= mod;
    }
    return t;
}

ll power(ll a, ll b){
    a %= mod;
    if(b == 0){
        return 1;
    }
    ll ans = power(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}

ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = 1;
    for(ll i = 0; i < b; i++) {
        ans *= (a - i);
        ans /= (i + 1);
        ans %= mod;
    }
    return ans;
}

int main(){
    ll n,p,ans = 1;
    cin >> n >> p;
    if(n == 1){
        pf(p);
        return 0;
    }
    for (ll i = 2; i * i <= p; ++i){
        ll cnt = 0;
        while (p % i == 0) {
            ++cnt;
            p /= i;
        }
        if(cnt >= n)ans *= power(i,(cnt / n));
        if(i >= 3)++i;
    }
    pf(ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = (1LL << 59);
const int iINF = (1 << 31)-1;
const double dINF = 1000000000000000000.0;
const int MAX_N = 1 << 17;


int main(){
	string S; cin >> S;
	ll ans = 0LL;
	for (int i = 0; i < (1 << (S.length() - 1)); i++) {
		int cnt = 0;
		ll temp = 0LL;
		for (auto &&c : S) {
			if (i&(1 << (S.length()-cnt-1))) {
				ans += temp;
				temp = 0;
			}
			temp = 10 * temp + (int)(c - '0');
			cnt++;
		}
		ans += temp;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class E
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var (N, X, M) = Scanner.Scan<long, long, long>();
            var a = X;
            var dict = new Dictionary<long, int>();
            dict[a] = 1;
            var agg = new List<long>() { 0, a };
            var loopStart = 0;
            var loopEnd = -1;
            for (var n = 2; n <= N; n++)
            {
                a = a * a % M;
                agg.Add(agg[agg.Count - 1] + a);
                if (dict.ContainsKey(a))
                {
                    loopStart = dict[a];
                    loopEnd = n;
                    break;
                }
                else dict[a] = n;
            }
            var answer = agg[agg.Count - 1];
            var remains = N - loopEnd;
            if (loopEnd > 0 && remains > 0)
            {
                answer += (agg[loopEnd] - agg[loopStart]) * (remains / (loopEnd - loopStart));
                var rem = (int)(remains % (loopEnd - loopStart));
                answer += agg[loopStart + rem] - agg[loopStart];
            }

            Console.WriteLine(answer);
        }

        public static class Scanner
        {
            private static Queue<string> queue = new Queue<string>();
            public static T Next<T>()
            {
                if (!queue.Any()) foreach (var item in Console.ReadLine().Trim().Split(" ")) queue.Enqueue(item);
                return (T)Convert.ChangeType(queue.Dequeue(), typeof(T));
            }
            public static T Scan<T>() => Next<T>();
            public static (T1, T2) Scan<T1, T2>() => (Next<T1>(), Next<T2>());
            public static (T1, T2, T3) Scan<T1, T2, T3>() => (Next<T1>(), Next<T2>(), Next<T3>());
            public static (T1, T2, T3, T4) Scan<T1, T2, T3, T4>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>());
            public static (T1, T2, T3, T4, T5) Scan<T1, T2, T3, T4, T5>() => (Next<T1>(), Next<T2>(), Next<T3>(), Next<T4>(), Next<T5>());
            public static IEnumerable<T> ScanEnumerable<T>() => Console.ReadLine().Trim().Split(" ").Select(x => (T)Convert.ChangeType(x, typeof(T)));
        }
    }
}


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

int N,M,X,a[1010],Kiri=0,Kanan=0;
int main(){
    cin>>N>>M>>X;
    for(int i=1;i<=M;i++){
        cin>>a[i];
    }
   for(int i=1;i<=M;i++){
       if(1<=a[i]&&a[i]<=X){
           Kiri++;
       }
       else if(X<=a[i]&&a[i]<=N){
           Kanan++;
       }
       
   }
   cout<<min(Kiri,Kanan);
}

Measured memory_bytes: 3652
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        String str = lines[0];
        int n = Integer.parseInt(str);
        int[] x = new int[n];
        long total = 0;
            for (int i = 0; i < n; i++){
                x[i] = i + 1;
            }
            for (int i = 0; i < n; i++){
                if(x[i] % 3 != 0 && x[i] % 5 != 0){
                    total = total + x[i];
                }
            }
        System.out.println(total);
   }
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
}

Measured memory_bytes: 30948
// Author: Jinhai Chen
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;



int main() {
#ifndef ONLINE_JUDGE
	//freopen("data.in","r",stdin);
#endif
	ios::sync_with_stdio(false);
	int x,y;
	cin>>x>>y;
	cout<<x+y/2<<endl;
	return 0;
}














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

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

    int ans = -1;
    if(s == "SUN") ans = 7;
    if(s == "MON") ans = 6;
    if(s == "TUE") ans = 5;
    if(s == "WED") ans = 4;
    if(s == "THU") ans = 3;
    if(s == "FRI") ans = 2;
    if(s == "SAT") ans = 1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int max(int a, int b){
    if(a > b){return a;}
    else{return b;}
}
int main(void){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int ans = a+b+c - max(a, max(b, c));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
using namespace std;
typedef long long ll;

int main()
{
	ll N, C, K;
	cin >> N >> C >> K;

	ll t[100010];
	for (int i = 0; i < N; i++) 
		cin >> t[i];
	
	sort(t, t + N);
	ll limit = t[0] + K;
	ll pas = 1;
	ll ans = 1;
	for (int i = 1; i < N; i++) {
		if (limit >= t[i] && pas != C) {
			pas++;
		}else{
			limit = t[i] + K;
			pas = 1;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;

class abc121_Cz
{
    static void Main(string[] args)
    {
        var line1 = readInts();
        var QN = line1[0];
        var QM = line1[1];

        var Qls = readIntsN(QN);

        // sort by price asc
        Array.Sort(Qls, (a, b) => a[0].CompareTo(b[0]));
        

        long price = 0L;
        long amount = 0L;
        foreach(var a in Qls) {
            long neededAmount = QM - amount;
            if(neededAmount == 0) break;

            long addAmount = Math.Min(a[1], neededAmount);
            long addPrice = addAmount * a[0];

            price += addPrice;
            amount += addAmount;
        }

        Console.WriteLine(price);

    }

    static int[][] readIntsN(int N) { return Enumerable.Range(0, N).Select(x => readInts()).ToArray(); }
    
    static int readInt() { return int.Parse(Console.ReadLine()); }

    static int[] readInts() { return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray(); }

    static long readLong() { return long.Parse(Console.ReadLine()); }

    static long[] readLongs() { return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray(); }

}

Measured memory_bytes: 23736
using System;
using System.Linq;

namespace agc018_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (x[0] == 1) Console.WriteLine(x[1] == a[0] ? "POSSIBLE" : "IMPOSSIBLE");
            else if (x[1] > a.Max()) Console.WriteLine("IMPOSSIBLE");
            else
            {
                Array.Sort(a);
                int n1 = a[0]; int n2 = a[1];
                for (int i = 1; i < x[0]; i++)
                {
                    n2 = a[i];
                    while (n1 != 0)
                    {
                        int now = n2 % n1;
                        n2 = n1;
                        n1 = now;
                    }
                    n1 = n2;
                }
                Console.WriteLine(x[1] % n1 == 0 ? "POSSIBLE" : "IMPOSSIBLE");
            }
        }
    }
}

Measured memory_bytes: 21728
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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 (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    int k,a,b,i=1,tem;
    cin >> k >> a >> b;
    tem =k;

    while(tem<=1000){
        if(tem>=a and tem<=b){
            cout << "OK" <<endl;
            return 0;
        }
        i++;
        tem = i*k;
    }

    cout << "NG" << endl;

    return 0;

}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

int main() {
    string S;
    cin >> S;
    if(S.size() == 2) {
        cout << S << endl;
    }
    else {
        reverse(S.begin(),S.end());
        cout << S << endl;
    }
}

Measured memory_bytes: 256
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())
#define PI 2 * acos(0)

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,r;
    cin>>n>>r;
    ll cnt=0;
    while(n>0)
    {
        n/=r;
        cnt++;
    }
    cout<<cnt;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k,a,b;
	cin >> k >> a >> b;
	for(int i=a;i<=b;++i) if(i%k==0) {
		cout << "OK";
		return 0;
	}
	cout << "NG";
	return 0;
}



Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define MAXN	1000005
#define MAXC	26
char s[MAXN], t[MAXN];
int main() {
	//freopen("007.in", "r", stdin);
	//freopen("007.out", "w", stdout);
	int n; scanf("%d", &n);
	scanf("\n%s", s + 1);
	scanf("\n%s", t + 1);
	bool same = true;
	for (int i = 1; i <= n; ++i) {
		if(s[i] != t[i]) {
			same = false;
			break;
		}
	}
	if(same) {
		cout << 0 << endl;
		return 0;
	}
	int j = n, l = 0, r = 0, ans = 0;
	static int q[MAXN];
	for (int i = n; i; i--) {
		if (!(j >= i && t[j] == s[i])) continue;
		while (j >= i && t[j] == s[i]) j--;
		while (l < r && q[l] - r + l > j) l++;
		if (i <= j) {
			q[r++] = i;
			ans = max(ans, r - l);
		}
	}
	if (j == 0) cout << ans + 1 << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 6144
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val N = rd.readInt()
    val A = rd.readLongArray()
    val B = rd.readLongArray()

    if (A.sum() < B.sum()) {
        println(-1)
        return
    }

    var ok = true
    for (i in 0 until N) {
        if (A[i] < B[i]) {
            ok = false
            break
        }
    }
    if (ok) {
        println(0)
        return
    }

    val diff = ArrayList<Long>()
    val sup = ArrayList<Long>()
    for (i in 0 until N) {
        if (A[i] < B[i]) diff.add(B[i] - A[i])
        else if (A[i] > B[i]) sup.add(A[i] - B[i])
    }
    sup.sortDescending()

    var cnt = diff.size
    var sum = diff.sum()

    var i = 0
    while (sum > 0) {
        val hi = if (i < sup.size) sup[i] else -1
        if (hi < 0) {
            println(-1)
            return
        }
        sum -= hi
        cnt++
        i++
    }

    val ans = cnt
    println(ans)
}


//val rd = debug.Reader("etc", "keyence2019", "c", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
const val EPS = 1e-9; fun DBLEQ(a: Double, b: Double): Boolean {return abs(a - b) < EPS}
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)
typealias ALI = ArrayList<Int>
fun <T>edge(V: Int): Array<ArrayList<T>> { return Array(V){ArrayList<T>()} }
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 62556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
const int MOD = 1e9 + 7;
const int INF = 2e9;
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; }
int GCD(int x, int y) { return y ? GCD(y, x % y) : x; }
int LCM(int x, int y) { return x * y / GCD(x, y); }

int main(){
    int n;
    cin >> n;
    vi a(n), b(n-1);
    for (int i = 0; i < n-1; i++){
        cin >> b[i];
    }
    a[0] = b[0];
    a[n - 1] = b[n - 2];
    for (int i = 1; i < n - 1; i++){
        a[i] = min(b[i - 1], b[i]);
    }
    ll ans = 0;
    for (auto v : a){
        ans += v;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,m=LI()
  if m%n==0:
    return m//n

  ans=0
  for i in range(1,m//n+1):
    if m%i==0:
      ans=i
  
  return ans

# main()
print(main())


Measured memory_bytes: 77448
# https://atcoder.jp/contests/abc075/tasks/abc075_b

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]


def is_bomb(x, y):
    return S[y][x] == "#"

def count_neibor(x, y):
    dxs = [1, -1, 0, 0, 1, 1, -1, -1]
    dys = [0, 0, 1, -1, 1, -1, 1, -1]
    count = 0
    for dx, dy in zip(dxs, dys):
        check_x = x + dx
        check_y = y + dy
        if 0 <= check_x < W and 0 <= check_y < H:
            count += 1 if S[check_y][check_x] == "#" else 0
    return count

result = []
for y in range(H):
    row = []
    for x in range(W):
        if is_bomb(x, y):
            row.append("#")
        else:
            row.append(str(count_neibor(x, y)))
    result.append(row)

for c in result:
    print(''.join(c))



Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long 
#define F first 
#define S second 
#define f(i,n) for(int i=0;i<n;i++) 
#define fr(i,a,b) for(int i=a;i<b;i++) 
#define mp make_pair 
#define pb push_back 
#define P(i,j) pair<i,j> 
#define M(i,j) map<i,j> 
#define V(i) vector<i> 
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)

using namespace std;

void test(){
	int h,w,n;
	cin>>h>>w>>n;
	int ans1=n/h;
	if(n%h!=0)ans1++;
	int ans2=n/w;
	if(n%w!=0)ans2++;
	cout<<min(ans1,ans2)<<"\n";
}

int main(){
	int t=1 ;
//	cin>>t;
	while(t-->0){
		test();
	}
}

Measured memory_bytes: 256
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
K = []
S = []
for i in range(M):
    tmp = LIST()
    K.append(tmp[0])
    S.append(tmp[1:])
P = LIST()

switch_patern = []
for i in range(2**N):
    tmp = format(i, '0'+str(N)+'b')
    tmp = [int(t) for t in tmp]
    switch_patern.append(tmp)

count = 0
for i in range(2**N):
    flag = 0
    for j in range(M):
        tmp = 0
        for k in range(K[j]):
            tmp += switch_patern[i][S[j][k]-1]
        if tmp % 2 == P[j]:
            flag += 1
    if flag == M:
        count += 1
print(count)


Measured memory_bytes: 5316