akhauriyash/Code-Regression huggingface dataset:
import sys
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline

N = int(readline())
S = np.array([list(i) for i in read().split()], np.int64)
edges = np.where(S == 1)

# 二部グラフかを判定する。隣り合う頂点の色が被らないように白黒で塗り分ける
graph = [[] for _ in range(N)]

for i, j in zip(edges[0].tolist(), edges[1].tolist()):
    graph[i].append(j)
    graph[j].append(i)


def judge(start):
    colors = [-1] * N
    colors[start] = 0
    queue = deque([(start, 0)])
    while queue:
        V, c = queue.popleft()
        c ^= 1
        for v in graph[V]:
            if colors[v] == -1:
                colors[v] = c
                queue.append((v, c))
            else:
                if colors[v] != c:
                    return False
    return True


start = edges[0][0]
if judge(start):
    d = floyd_warshall(S)
    print(int(np.max(d)) + 1)
else:
    print(-1)


Measured memory_bytes: 19296
#include <iostream>
#include <vector>

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

int main() {
  int x, y;
  cin >> x >> y;

  vector<int> a = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};

  cout << (a.at(x) == a.at(y) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<assert.h>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    if (n%10 == n/100) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000 //1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
  cout << H << " ";
  debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;

// const
// 円周率
const double pi = M_PI;
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
mint choose(ll n,ll a){
  mint x=1;
  mint y=1;
  ll i=0;
  while(i<a){
    x*=n-i;
    y*=i+1;
    i++;
  }
  return x/y;
}

int main()
{
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll x,y; cin >> x >> y;
  ll a=2*x-y, b=-x+2*y;
  if(a%3!=0 or b%3!=0 or a<0 or b<0){
    cout << 0 << endl;
    return 0;
  }
  a/=3; b/=3;
  cout << choose(a+b,a) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define INF (1LL << 30)
#define pii pair<int, int>
#define MOD 1000000007
#define print(x) cout<<(x)<<endl
using namespace std;


signed main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n);

    rep(i,n){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a.begin(),a.end());
    sort(b.rbegin(),b.rend());

    // b: おおきいじゅん
    // a: ちいさいじゅん

    int a1 = b[0];

    //double half = a1 / 2.0;
    int half = a1/2;
    pii mn = make_pair(INF,INF); //  dif, value
    for (auto x: a){
        int r;
        int df;
        if (x > half){
            r = a1-x;
        }
        else {
            r=x;
        }
        df = half - r;
        

        if (mn.first > df){
            mn = make_pair(df,x);
        }
    }

    cout<<a1 << " " << mn.second << endl;




    return 0;
}

Measured memory_bytes: 1792
from collections import deque

h, w = map(int, input().split())
a = ''.join(input() + '#' for _ in range(h))
n = len(a)
b = ['#'] * w
r = 0
for i in range(n):
  if a[i] == '.':
    b[:-w] = a
    b[i] = 0
    q = deque([i])
    while(q):
      i = q.popleft()
      r = max(r, b[i])
      for j in (i - 1, i + 1, i - w - 1, i + w + 1):
        if b[j] == '.':
          b[j] = b[i] + 1
          q.append(j)
print(r)


Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<long long> s1(m + m), s2(m + m);
  int from;
  cin >> from;
  from--;
  long long tot = 0;
  for (int i = 1; i < n; i++) {
    int to;
    cin >> to;
    to--;
    from %= m;
    if (to < from) to += m;
    tot += to - from;
    if (from + 1 == to) {
      from = to;
      continue;
    }
    s1[from + 2]++;
    s1[to + 1]--;
    s2[to + 1] -= to - from - 1;
    from = to;
  }
  long long ans = tot;
  for (int i = 1; i < m + m; i++) s1[i] += s1[i - 1];
  for (int i = 0; i < m + m; i++) s2[i] += s1[i];
  for (int i = 1; i < m + m; i++) s2[i] += s2[i - 1];
  for (int i = 0; i < m; i++) ans = min(ans, tot - s2[i] - s2[i + m]);
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int n, a;
    cin >> n;
    vector<int> v[n+1];
    for (int i = 1; i <= n; i++) {
        cin >> a;
        v[i].push_back(a);
    }
    queue<int> q;
    int vis[n+1], dist[n+1];
    memset(vis,0,sizeof(vis));
    for (int i = 0; i <= n; i++) {
        dist[i] = -1;
    }
    dist[1] = 0;
    q.push(1);
    while(!q.empty()) {
        int ver = q.front();
        q.pop();
        for (auto i : v[ver]) {
//            cout << i << " |";
            if (vis[i] != 0)
                continue;
            dist[i] = dist[ver]+1;
            vis[i] = 1;
            q.push(i);
        }
    }
    cout << dist[2];
    return 0;
}


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

int main() {
  int N,d1,d2,Ans=0;
  cin>>N;
  rep(i,N){cin>>d1>>d2;
          if(d1==d2){Ans++;}else{Ans=0;}
          if(Ans==3){break;}
          }
  if(Ans==3){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
}


Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>
typedef long long LL;

using namespace std;



int main(void) {
	string s;
	int w;
	cin >> s >> w;
	string ans;
	for (int i = 0; i < s.size(); i++) {
		if (i % w == 0) {
			ans.push_back(s[i]);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
char A[55][55];
char B[55][55];
int a,b;
bool fun(int i,int j)
{
    for(int r=0;r<b;r++)
    {
        for(int c=0;c<b;c++)
        {
            if(A[i+r][j+c]!=B[r][c])
                return false;
        }
    }
    return true;
}
int main()
{
    scanf("%d%d",&a,&b);
    for(int i=0;i<a;i++)
        scanf("%s",A[i]);
    for(int j=0;j<b;j++)
        scanf("%s",B[j]);
    for(int i=0;i<=a-b;i++)
    {
        for(int j=0;j<=a-b;j++)
        {
            if(A[i][j]==B[0][0])
            {
                if(fun(i,j))
                {
                   printf("Yes\n");
                   return 0;
                }
            }
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include<float.h>
#include<cstdio>
using namespace std;
#define EPS (1e-10)
#define equals(a,b) fabs((a)-(b))<DBL_EPSILON*fmax(1,fmax(fabs(a),fabs(b)))
//点のクラス
class Point{
    public:
        double x,y;
        Point(double x=0,double y=0):x(x),y(y){}

        Point operator + (Point p){return Point(x+p.x,y+p.y);}
        Point operator - (Point p){return Point(x-p.x,y-p.y);}
        Point operator * (double a){return Point(a*x,a*y);}
        Point operator / (double a){return Point(x/a,y/a);}

        double norm(){return x*x+y*y;}
        double abs(){return sqrt(norm());}    

        bool operator < (const Point &p)const{
            return x!=p.x?x<p.x:y<p.y;
        }
        bool operator == (const Point &p)const{
            return equals(x,p.x)&&equals(y,p.y);
        }
};
typedef Point Vector;
struct Segment{ Point p1,p2; };
typedef Segment Line;
//内積
double dot(Vector a,Vector b){ return a.x*b.x+a.y*b.y; }
//外戚
double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; }
//ベクトルa,bの位置関係
int ccw(Point p0,Point p1,Point p2){
    Vector a=p1-p0;
    Vector b=p2-p0;
    if(cross(a,b)>EPS) return 1;//p0,p1,p2が反時計回り
    if(cross(a,b)<-EPS) return -1;//p0,p1,p2が時計回り
    if(dot(a,b)<-EPS) return 2;//p1,p0,p2の順で一直線
    if(a.norm()<b.norm()) return -2;//p0,p1,p2の順で一直線
    return 0; //p0,p2,p1の順で一直線
}
//交差判定　p389
bool intersect(Point p1,Point p2,Point p3,Point p4){
    return ( ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
            ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);//p1,p2,p3,p4の順で一直線になるのを除く
}
int main(){
    int q;
    cin>>q;
    Point p[4];
    for(int i=0;i<q;i++){
        cin>>p[0].x>>p[0].y>>p[1].x>>p[1].y;
        cin>>p[2].x>>p[2].y>>p[3].x>>p[3].y;
        if(intersect(p[0],p[1],p[2],p[3]))cout<<1<<"\n";
        else cout<<0<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int w,n;
	scanf("%d",&w);
	scanf("%d",&n);
	int *lot = new int[w+1];
	for(int i=0;i<=w;i++){
		lot[i] = i;
	}
	for(int i=0;i<n;i++){

		string str1,str2;
		int a,b;
		getline(cin,str1,',');
		getline(cin,str2);
		sscanf(str1.c_str(),"%d",&a);
		sscanf(str2.c_str(),"%d",&b);
		swap(lot[a],lot[b]);
	}

	for(int i=1;i<=w;i++){
		printf("%d\n",lot[i]);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    s += s;
    string ans;
    for(int i = 0; i < 4; i++){
        ans = "";
        if(i == 0) ans += "SS";
        if(i == 1) ans += "SW";
        if(i == 2) ans += "WS";
        if(i == 3) ans += "WW";
        for(int j = 1; j <= n+1; j++){
            if(s[j] == 'o'){
                if(ans[j] == 'S'){
                    ans += ans[j-1];
                }
                else{
                    if(ans[j-1] == 'S') ans += 'W';
                    else ans += 'S';
                }
            }
            else{
                if(ans[j] == 'S'){
                    if(ans[j-1] == 'S') ans += 'W';
                    else ans += 'S';
                }
                else{
                    ans += ans[j-1];
                }
            }
        }
        if(ans[0] == ans[n] && ans[1] == ans[n+1]){
            cout << ans.substr(0, n) << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3848
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#pragma warning( disable:4996 )
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))


int main(void) {
	/*int n;
	scanf("%d", &n);
	printf("%d", (n - 2) * 180);*/
	char s[16];
	scanf("%s", s);
	int len = strlen(s);
	int count = 0;
	for (int i = 0; i < len; i++) {
		if (s[i] == 'o')count++;
	}
	int remain = 8-count;
	if (remain <= 15 - len) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
A - Harmony
https://atcoder.jp/contests/abc135/tasks/abc135_a

"""
import sys


def solve(A, B):
    if A > B:
        A, B = B, A
    diff = B - A
    if diff % 2:
        return 'IMPOSSIBLE'
    return B - diff // 2


def main(args):
    A, B = map(int, input().split())
    ans = solve(A, B)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3060
/*  Bismillahir Rahmanir Rahim
 *  Author: Md Asfakur Rahat.
 *  asfakurrahat7@gmail.com
 *  BUBT
*/
#include<bits/stdc++.h>

using namespace std;


char Uplowch(char ch){if(ch >= 'A' &&  ch <= 'Z') ch += 32; return ch;}
char Lowupch(char ch){if(ch >= 'a' &&  ch <= 'z') ch -= 32; return ch;}
bool Isalpha(char ch){if((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) return true; return false;}
int Strtoint(string str){stringstream ss(str);int x = 0;ss >> x ;return x ;}
string Intostr(int x){stringstream ss; ss << x; string str = ss.str(); return str;}


#define     O_0_O               ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define     ll                  long long
#define     nl                  '\n'
#define     fa                  ' '
#define     ff                  first
#define     ss                  second
#define     floop(begin,end,k)  for(k=begin;k<end;k++)
#define     rloop(end,begin,k)  for(k=begin-1;k>=end;k--)
#define     all(p)              (p).begin(),(p).end()
#define     sz(a)               (ll)a.size()
#define		gcd(a,b)            __gcd(a,b)
#define		lcm(a,b)            (a*b)/gcd(a,b)
#define     sqr(a)              (a)*(a)
#define     cube(a)             (a)*(a)*(a)
#define     pb                  push_back
#define     pi                  acos(-1.0)
#define     Mx                  1e6+5
#define     vi                  vector<int>
#define     vll                 vector<ll>
#define     vc                  vector<char>
#define     vs                  vector<string>
#define     tem                 template<class T
#define     r(a)                cin>>a
#define     write(a)            cout<<a
#define     test(t)             cin>>t;while(t--)
#define     haha                cout<<"YES"<<nl
#define     nono                cout<<"NO"<<nl


void  inline File_Read()
{
        /// File Reader.......................
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        #endif
}


tem>T abs(T a){ return (a<0?-a:a);}

bool matchs(string s,string p){int i,len=sz(p);floop(0,sz(s)-len,i){if(p==s.substr(i,len))return true;}return false;}


typedef string str;
typedef double ld;



ll arll[100010];
int ari[100010];
char arc[100005];
map<char,int>mci;
map<string,int>msi;
map<int,int>mii;

/// For loop Variable

ll i,j,k,tc;

int main()
{
        //File_Read();
        /// Optimizer...............
        O_0_O;
        /// Main code............
        /// Created:
		ll n;
		cin>>n;
		ll ans=0;
		floop(1,n+1,i)
			floop(1,n+1,j)
				floop(1,n+1,k)
					ans+=gcd(i,gcd(j,k));
					
		cout<<ans<<nl;
        return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    std::vector<int> v(3);
    std::cin>>v[0]>>v[1]>>v[2];

    std::sort(v.begin(), v.end());
    int cnt = 0;
    int k1 = (v[2] - v[0]) / 2;
    int k2 = (v[2] - v[1]) / 2;
    cnt = k1 + k2;
    v[0] = v[0] + k1 * 2;
    v[1] = v[1] + k2 * 2;
    //std::cout<<v[0]<<v[1]<<v[2]<<std::endl;
    if((v[0] == v[1]) && (v[1] != v[2])){
        ++cnt;
    }else if(v[0] != v[1]){
        cnt+=2;
    }
    std::cout<<cnt<<std::endl;
    return 0;
}

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

void solve()
{
    string s;
    cin >> s;
    set<char> st;
    bool ok = true;
    rep(i, s.size())
    {
        if (st.count(s[i]))
        {
            ok = false;
            break;
        }
        else
            st.insert(s[i]);
    }
    if (ok)
        cout << "yes" << endl;
    else
        cout << "no" << endl;
}

int main()
{
    solve();
    return 0;
}

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

using namespace std;
long long gcd(long long a,long long b)
{
    if(b>a)swap(a,b);
    if(b==0)return a;
    return gcd(b,a%b);
}
long long nww(long long a,long long b){return a*b/gcd(a,b);}
int main()
{
    long long n;
    cin>>n;
    long long akt=1;
    int odp=0;
    for(int i = 0;i<n;i++)
    {
        int pom;
        cin>>pom;
        if(akt==pom)
        {
            akt++;
            odp++;
        }
    }
    odp=n-odp;
    cout<<(odp==n?-1:odp);
}


Measured memory_bytes: 256
import math
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right
# import numpy as np

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
INF = float("inf")

N, W = s_inpl()
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

w, v = [], []
for _ in range(N):
    wi, vi = s_inpl()
    w.append(wi)
    v.append(vi)

for i in range(N):
    for sum_w in range(W+1):

        # i番目の品物が選べて，選ぶとき
        if sum_w >= w[i]:
            dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w-w[i]] + v[i])

        # i番目の品物を選ばないとき
        dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w])

print(dp[N][W])

Measured memory_bytes: 170888
use std::collections::*;
fn is753(n: u32) -> bool {
    let mut c3 = 0;
    let mut c5 = 0;
    let mut c7 = 0;
    let mut m = n;
    while m > 0 {
        match m % 10 {
            3 => c3 += 1,
            5 => c5 += 1,
            7 => c7 += 1,
            _ => return false,
        }
        m /= 10;
    }
    c3 > 0 && c5 > 0 && c7 > 0
}
fn add753(v: &mut Vec<u32>) {
    let vlen = v.len();
    let w = v.clone();
    let v753 = vec![7, 5, 3];
    for x in v753 {
        for i in 0..vlen {
            v.push(w[i] * 10 + x);
        }
    }
}

fn main() {
    let n = read::<u32>();

    if n < 357 {
        println!("0");
        return;
    }

    let mut keta = 0;
    let mut m = n;
    while m > 0 {
        keta += 1;
        m /= 10;
    }

    let v753: Vec<u32> = vec![3, 5, 7];
    let mut v = vec![];
    for x in &v753 {
        for y in &v753 {
            for z in &v753 {
                v.push(x * 100 + y * 10 + z);
            }
        }
    }
    for _ in 4..keta + 1 {
        add753(&mut v);
    }
    let ansv = v
        .into_iter()
        .filter(|&x| is753(x) && x <= n)
        .collect::<HashSet<u32>>();
    //println!("{:?}", ansv);
    println!("{}", ansv.len());
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 6396
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
result = [0 for i in range(m)]
for mindex in range(0,m):
    for nindex in range(0,n):
        for kindex in range(1,a[nindex][0]+1):
            if a[nindex][kindex] == mindex+1:
                result[mindex]+=1
            else:
                pass
                
 
print(result.count(n))

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;

class Main{
    final static long MOD = 1000000007;
    FastScanner sc = new FastScanner();

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

    void run(){

        int a = sc.nextInt();
        int b = sc.nextInt();

        int ans = 0;
        if(a == 1) ans += 300000;
        if(b == 1) ans += 300000;
        if(a == 2) ans += 200000;
        if(b == 2) ans += 200000;
        if(a == 3) ans += 100000;
        if(b == 3) ans += 100000;
        if(a == 1 && b == 1) ans += 400000;

        System.out.println(ans);



    }

    long gcd(long a, long b){ // return aとbの最大公約数
        if(b == 0){
          return a;
        }
        return gcd(b, a % b);
    }

    long pow_mod(long a, long r){ // return a^r (mod MOD)
        long sum = 1;
        while(r > 0){
            if((r & 1) == 1){
                sum *= a;
                sum %= MOD;
            }
            a *= a;
            a %= MOD;
            r >>= 1;
        }
        return sum;
    }



}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <= 0){
                return false;
            }
        }
        return true;
    }
    private int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c){ return 33 <= c && c <= 126;}
    public boolean hasNext(){ while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b <= '9'){
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble(){ return Double.parseDouble(next());}
}


Measured memory_bytes: 22484
def func(x,y):
    return min(x,y)

class SegmentTree:
    def __init__(self, n): #a1, a2, ..., an
        n_ = 1
        while n_ < n:
            n_ *= 2

        self.n = n_
        self.arr = [10**18] * (2*self.n-1)

    def update(self, k, a): #0_indexed
        k += self.n - 1
        self.arr[k] = a

        while k > 0:
            k = (k-1) // 2
            self.arr[k] = min(self.arr[2*k+1], self.arr[2*k+2])

    def query(self, l, r):
        L, R = l+self.n, r+self.n
        ide_ele = float("inf")
        #単位元(ide_ele)は、区間外の値などに設定する値です。
         #ex) 最小値のセグ木 → +inf
         #　和のセグ木 → 0
         #　積のセグ木 → 1
         #  gcdのセグ木 → 0
        res = ide_ele
        while L < R:
            if R & 1:
                R -= 1
                res = func(res, self.arr[R-1]) #

            if L & 1:
                res = func(res, self.arr[L-1])
                L += 1

            L >>= 1
            R >>= 1

        return res
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
lrc=[tuple(map(int,input().split())) for _ in range(m)]
dp=SegmentTree(n+1)
dp.update(1,0)

rl=[[] for _ in range(n+1)]
rc=[[] for _ in range(n+1)]
for l,r,c in lrc:
    rl[r].append(l)
    rc[r].append(c)

for r in range(2,n+1):
    x=float("inf")
    for l,c in zip(rl[r],rc[r]):
        y=dp.query(l,r)+c
        if x>y:
            x=y
    dp.update(r,x)
    if r==n:
        ans=x

if ans==float("inf"):
    ans=-1
print(ans)


Measured memory_bytes: 135388
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
int main() {
  ll N = 0;
  cin >> N;
  if(N%10 == 2||N%10 == 4||N%10 == 5||N%10 == 7||N%10 == 9){
    cout << "hon" << endl;
  }
  if(N%10 == 0||N%10 == 1||N%10 == 6||N%10 == 8){
    cout << "pon" << endl;
  }
  if(N%10 == 3){
    cout << "bon" << endl;
  }

}


Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include<iomanip>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    int t[n], a[n];
    for (int i = 0; i < n; i ++)
    {
        cin >> t[i] >> a[i];

    }

    ll x = t[0];
    ll y = a[0];
    for (int i = 1; i < n; i ++)
    {
        ll k1;
        ll k2;
        if (x % t[i] == 0) k1 = x / t[i];
        else k1 = (x / t[i]) + 1;
        if (y % a[i] == 0) k2 = y / a[i];
        else k2 = (y / a[i]) + 1;

        x = t[i] * max(k1, k2);
        y = a[i] * max(k1, k2);
    }

    cout << x + y << endl;

}


Measured memory_bytes: 256
N,M = list(map(int,input().split()))
H = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(M)]


ans = [0] * N
for a in A:
    n1,n2, = a[0]-1,a[1]-1
    if H[n1] < H[n2]:
        ans[n1] = -1
    elif H[n1] == H[n2]:
        ans[n1] = -1
        ans[n2] = -1
    if H[n1] > H[n2]:
        ans[n2] = -1

print(ans.count(0))

Measured memory_bytes: 31860
#!/usr/bin/env python
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor

def main():
    #N, M = map(int, input().split())
    N = int(input())
    As = list(map(int, input().split()))

    d = defaultdict(int)
    for i, a in enumerate(As):
        key = i - a
        d[key] += 1

    cnt = 0
    for i, a in enumerate(As):
        key = i + a
        cnt += d[key]

    print(cnt)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61756
def main():
    N = int(input())
    S = [input() for _ in range(N)]
    t = input()
    mn = 1
    mx = N+1
    for s in S:
        smin = s.replace("?", "a")
        smax = s.replace("?", "z")
        if t < smin:
            mx -= 1
        if smax < t:
            mn += 1
    ans = list(range(mn, mx+1))
    print(*ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 46552
object Main extends App {
	val Array(a, b, c) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	if(a==b && a!=c) println("Yes")
	else if(a==c && a!=b) println("Yes")
	else if(b==c && a!=b) println("Yes")
	else println("No")
}

Measured memory_bytes: 27336
#include<stdio.h>

int main(void)
{
	int a[100],n, i;
	scanf("%d", &n);
	for (i = 0;i < n;i++)
	{
		scanf("%d", &a[i]);
	}
	for (i = n-1;i >= 0;i--)
	{
		printf("%d", a[i]);
		if (i != 0) printf(" ");
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 600
n = int(input())
ns = list(map(int, input().split()))
li = 1
ans = 0
max_leafs = [1]
for i in ns:
    li = (li - i) * 2
    max_leafs.append(li)
points = ns.pop()
ans += points
for i in range(len(ns)-1, -1, -1):
    a = ns[i]
    points = min(points + a, max_leafs[i])
    ans += points
if max_leafs[-1] < 0:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 701992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;

int main(){
  ll n,k,ans =-10e9;
  cin >> n >> k;
  vector<ll>p(n),c(n);
  for(int i=0; i<n; i++){
    cin >> p[i];
    p[i]--;
  }
  for(int i=0; i<n; i++) cin >> c[i];
  
  for(ll i=0; i<n; i++){
    ll count=0,sum=0,x = i;
    vector<ll>m(n+1,-10e9);
    do{
      count++;
      x = p[x];
      sum += c[x];
      m[count] = max(m[count],sum);
    }while(x != i);
    
    ll roop,all = -10e9;
    roop = k/count;
    if(roop  == 0){
      for(int j=1; j<=k%count; j++){
        all = max(all,m[j]);
      }
    }else{
      for(int j=1; j<=k%count+count; j++){
         if(j>count){
          all = max(all,m[count]+m[j-count]);;
        }else{
          all = max(all,m[j]);
        }
      }
    }
    if(roop>0 && m[count] > 0)all += m[count]*(roop-1);
    ans = max(ans,all);
  }
  
  
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3748
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i,  r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define X real()
#define Y imag()
#define maxN 2005
#define oo 2000000007
#define EPS 1e-9
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, k;
vector<int> g[maxN];

void DFS(int u, int p, int depth, vector<int> &path) {
    path[depth]++;
    forit(it, g[u]) {
        int v = *it;
        if (v != p) DFS(v, u, depth+1, path);
    }
}

int main () {
    scanf("%d%d", &n, &k);
    fto(i, 1, n-1) {
        int u, v;
        scanf("%d%d", &u, &v);
        g[u].pb(v); g[v].pb(u);
    }

    int ans = n;
    fto(u, 1, n) {
        vector<vector<int> > path(sz(g[u]));
        fto(i, 0, sz(g[u])-1) {
            int v = g[u][i];

            path[i].assign(n+1, 0);
            DFS(v, u, 1, path[i]);

            fto(j, 1, n) path[i][j] += path[i][j-1];
        }

        fto(i, 0, sz(g[u])-1) {
            int v = g[u][i], sum = path[i][n]-path[i][(k+1)/2];
            fto(j, 0, sz(g[u])-1) {
                if (j != i) sum += path[j][n]-path[j][k/2];
            }
            ans = min(ans, sum);
        }
    }

    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 16000
N, m = map(int, raw_input().split())

three = [False]*N
for loop in xrange(m):
    c, d = map(int, raw_input().split())
    if c < d:
        three[c:d] = [True]*len(three[c:d])

ans = 0
for i in xrange(N):
    ans += 1
    if three[i]:
        ans += 2
print ans+1

Measured memory_bytes: 4232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9, mod = 1e9+7;
#define endl     '\n'

void solve(){
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    int cnt = 0;
    while (a >= b) b *= 2, cnt++;
    while (b >= c) c *= 2, cnt++;
    cout << (cnt <= k ? "Yes" : "No");
}


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

    solve();
    return 0;
}


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

int main(void) {
  unsigned int N;
  unsigned int H[100000];
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> H[i]; 
  }
  
  int cnt = 0;
  int _max = 0;
  for(int i = 1; i < N; i++) {
    if(H[i] <= H[i - 1]) {
      cnt++;
      _max = max(cnt, _max);
    }
    else {
      cnt = 0;
    }
  }
  cout << _max;
  
  return 0; 
}

Measured memory_bytes: 640
#include <iostream>
#include <initializer_list>
#include <algorithm>
using namespace std;
int main(void)
{
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	int d[n][3];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	d[0][0] = a[0];
	d[0][1] = b[0];
	d[0][2] = c[0];
	for (int i = 1; i < n; i++) {
		d[i][0] = max(d[i-1][1], d[i-1][2]) + a[i];
		d[i][1] = max(d[i-1][0], d[i-1][2]) + b[i];
		d[i][2] = max(d[i-1][0], d[i-1][1]) + c[i];
	}

	cout << *max_element(&d[n-1][0], &d[n-1][3]) << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

constexpr ll DIVIDE = 1'000'000'007;

void main_()
{
    ll N;
    cin >> N;
    string S;
    cin >> S;

    unordered_map<char, ll> chmap;
    for (auto ch : S) {
        chmap[ch]++;
    }

    ll ans = accumulate(begin(chmap), end(chmap),
        1LL,
        [](auto acc, auto&& n) {
            return acc * (n.second + 1) % DIVIDE;
        });

    // 全ての文字を選ばないのは許されていない
    ans--;

    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair

const int MOD = 1000000007;
const int N = 1e5 + 18;



int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    //cin >> t;
    while (t--) {

        int n, k;
        cin >> n >> k;
        int a[n];
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
        }
        int l = 0, r = 1e9;
        while (l + 1 < r)
        {
            int m = (l + r) / 2;
            int s = 0;
            for (int i = 0; i < n; i++)
            {
                s += (a[i] + m - 1) / m - 1;
            }
            if (s <= k)
                r = m;
            else
                l = m;

        }
        cout << r << endl;

    }
    return 0;

}



Measured memory_bytes: 5224
_n = gets
a = gets.split.map(&:to_i)
puts a.inject(a[0]) { |res, num|
  if res >= num
    l, s = res, num
  else
    l, s = num, res
  end
  loop do
    l, s = s, l % s
    break if s == 0
  end
  res = l
}

Measured memory_bytes: 11012
n = int(input())
l = []
for i in range(2):
  l.append(list(map(int, input().split())))

a = []
for i in range(n):
  p = 0
  for j in range(n):   
    if i == j:
      p += l[0][j] + l[1][j]
    elif i < j:
      p += l[1][j]
    else:
      p += l[0][j]
  a.append(p)
print(max(a))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

int n;
int a[100001], b[100001], c[100000];
ll cb[100001], cc[100001];
 
int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) cin >> a[i];
	REP(i, n) cin >> b[i];
	REP(i, n) cin >> c[i];
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	a[n] = b[n] = 1000000001;

	int ai = 0;
	cb[0] = 0;
	REP(i, n) {
		for (; a[ai] < b[i]; ++ai) ++cb[i];
		cb[i + 1] = cb[i];
	}

	int bi = 0;
	cc[0] = 0;
	REP(i, n) {
		for (; b[bi] < c[i]; ++bi) cc[i] += cb[bi];
		cc[i + 1] = cc[i];
	}

	ll res = 0;
	REP(i, n) res += cc[i];

	cout << res << endl;
	return 0;
}
 

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

int main() {
    int n;
    while(cin >> n, n) {
        vector<string> ws(n);
        for(auto& w : ws) cin >> w;
        vector<string> ss = {""};
        while(cin >> ss.back()) {
            if(ss.back().back() == '.') break;
            ss.push_back("");
        }
        ss.back().pop_back(); // period
        const auto ts = ss;
        sort(begin(ss), end(ss), [] (string s1, string s2) {
                return set<char>{begin(s1), end(s1)}.size() > set<char>{begin(s2), end(s2)}.size();
            });

        auto conv = [] (string s, vector<char> const& m) {
            for(auto& c : s) {
                c = m[c - 'A'];
            }
            return s;
        };
        string ans;
        function<void(int, vector<char>)> dfs = [&] (int i, vector<char> m) {
            if(ans == "-.") return;
            if(i == (int)ss.size()) {
                string tans = conv(ts[0], m);
                for(int j = 1; j < (int)ts.size(); ++j) {
                    tans += " " + conv(ts[j], m);
                }
                tans += ".";
                if(!ans.empty() && ans != tans) {
                    ans = "-.";
                } else {
                    ans = tans;
                }
                return;
            }
            const auto& s = ss[i];
            for(auto const& w : ws) {
                if(s.size() != w.size()) continue;
                bool check = true;
                vector<char> tm = m;
                for(int j = 0; j < (int)s.size(); ++j) {
                    check &= m[s[j] - 'A'] == w[j] || (m[s[j] - 'A'] == '*' && m[w[j] - 'A'] == '*');
                    tm[s[j] - 'A'] = w[j];
                    tm[w[j] - 'A'] = s[j];
                }
                if(!check) continue;
                dfs(i + 1, move(tm));
            }
        };
        dfs(0, vector<char>(26, '*'));

        cout << ans << endl;
    }
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a),_b=(b);i<=_b;i=i+1)
#define FORD(i,b,a) for (int i=(b),_a=(a);i>=_a;i=i-1)
#define REP(i,n) for (int i=0,_n=(n);i<_n;i=i+1)
#define FORE(i,v) for (__typeof((v).begin()) i=(v).begin();i!=(v).end();i++)
#define ALL(v) (v).begin(),(v).end()
#define fi   first
#define se   second
#define MASK(i) (1LL<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define div   ___div
#define next   ___next
#define prev   ___prev
#define left   ___left
#define right   ___right
#define __builtin_popcount __builtin_popcountll
using namespace std;
template<class X,class Y>
    void minimize(X &x,const Y &y) {
        if (x>y) x=y;
    }
template<class X,class Y>
    void maximize(X &x,const Y &y) {
        if (x<y) x=y;
    }
template<class T>
    T Abs(const T &x) {
        return (x<0?-x:x);
    }

/* Author: Van Hanh Pham */

/** END OF TEMPLATE - ACTUAL SOLUTION COMES HERE **/

#define MAX   300300

int a[MAX], n;

void process(void) {
    scanf("%d", &n);
    FOR(i, 1, 3 * n) scanf("%d", &a[i]);
    sort(a + 1, a + 3 * n + 1, greater<int>());

    long long res = 0;
    FOR(i, 1, n) res += a[2 * i];
    cout << res << endl;
}

int main(void) {
    process();
    return 0;
}

/*** LOOK AT MY CODE. MY CODE IS AMAZING :D ***/


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

int X,Y,S;
int tax(int rate,int price){
    return((int)(price*(float)(100+rate)/100));
}
int main(){
    while(cin >>X>>Y>>S && X>0){
        int maximum=0;
        for(int i=1;i<S;i++){
            for(int j=i;j<S;j++){
                if(tax(X,i)+tax(X,j)==S){
                    if(maximum<tax(Y,i)+tax(Y,j)){
                        maximum=tax(Y,i)+tax(Y,j);
                    }
                }
            }
        }
        cout << maximum << endl;
    }
}



Measured memory_bytes: 3084
using System;

namespace AtCoderTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int p2 = int.Parse(input[2]);

            int p1 = a * b;
            int ans = p2;
            if (p1 < p2)
            {
                ans = p1;
            }

            Console.WriteLine(ans);
        //    Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11092
# coding=utf-8

if __name__ == '__main__':
    N, M = map(int, input().split())
    set_list = [set(list(map(int, input().split()))[1:]) for i in range(N)]
    if len(set_list) == 1:
        print(len(set_list[0]))
    else:
        _intersect = set_list[0]
        for _set in set_list[1:]:
            _intersect = _intersect.intersection(_set)
        print(len(_intersect))


Measured memory_bytes: 3060
/************
* 	@Just Another Source code by: ankit.sangwan1999
*	@created on: 10 Sept 2020
*/
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) //;cout.tie(NULL)
#define ll long long
const int mod = 1e9+7;
const long double pie = 3.14159265358979323846;
#define endl '\n'
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gp_hash_table<int, ll> ma; // orderd_map using pb_ds


bool fun(int *arr, int n, int k, int mid){
	int ops = 0;
	for(int i=0;i<n;i++){
		ops += (arr[i]-1)/mid;		
		if(ops > k) return 0;
	}
	return 1;
}

void solve(){

	int n, k; cin>>n>>k;
	int ma = INT_MIN;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
		ma = max(ma, arr[i]);
	}
	
	int high = ma;
	int low = 1;
	int mid = (low + high)/2;
	int ans;
	while(low<=high){

		if(fun(arr, n, k, mid)){
			ans = mid;
			high = mid - 1;
		}
		else{
			low = mid + 1;
		}
		mid = (low + high)/2;
	}

	cout<<ans<<endl;

}

signed main(){

	#ifndef ONLINE_JUDGE
    freopen("/mnt/DATA/D_Drive/CP/input.txt", "r", stdin);
    freopen("/mnt/DATA/D_Drive/CP/output.txt", "w", stdout);
    #endif

    fastio;
    int t=1;
    // cin>>t;

    while(--t>=0){
    	solve();
    }
		

    return 0;
}

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

N = int(input())
A = list(map(int, input().split()))
A.append(0)

money = 1000
stock = 0

for i in range(N):
  if A[i] < A[i+1]:
    stock += money//A[i]
    money = money%A[i]
  elif A[i] > A[i+1]:
    money += stock*A[i]
    stock = 0

print(money)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n, x;
    cin >> n >> x;
    int ans = n;
    int m = 1e8;
    rep(i, n) {
        int a;
        cin >> a;
        x -= a;
        m = min(m, a);
    }
    ans += x / m;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,k,h[100005],num;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>h[i];
	for(int i=1;i<=n;i++)
		num+=h[i]>=k;
	cout<<num;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int main() {
  int N;
  cin >> N;
  int h[N + 1];
  REP(i, N) cin >> h[i];
  h[N] = 0;

  bool end = false;
  ll ans = 0;
  while (!end) {
    int min_val = INF;
    int start = 0;
    end = true;
    REP(i, N + 1) {
      if (h[i] > 0) {
        min_val = min(min_val, h[i]);
        end = false;
      }
      if (h[i] == 0) {
        for (int j = start; j < i; j++) {
          h[j] -= min_val;
        }
        if (min_val != INF) {
          ans += min_val;
        }
        start = i + 1;
        min_val = INF;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int M,N;
  cin>>N>>M;
  int ans1,ans2,ans;
  ans1=N*(N-1)/2;
  ans2=M*(M-1)/2;
  ans=ans1+ans2;
  cout<<ans<<endl;
}

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

int main() {
  int n; cin >> n;
  vector<int> ans(n+1);
  for (int x = 1; x*x<=n; x++) {
    for (int y = 1; y*y<=n; y++) {
      if (x*x + y*y > n) continue;
      for (int z = 1; z*z<=n; z++) {
        ll tot = x*x + y*y + z*z + x*y + y*z + z*x;
        if (n >= tot) ans[tot]++;
      }
    }
  }
  rep (i,n+1) {
    if (i==0) continue;
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(){
  
  int n,a,b,c;
  
  
  scanf("%d%d",&a,&b);


  // compare two natural numbers

  if(a<b)//the system that a is smaller than B
    {
      n = a;
      a = b;
      b = n;
  } 


  /* Euclid */
  c = a % b;
  while(c!=0){
    a = b;
    b = c;
    c = a % b;
  }

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

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

int main()
{
    int n;
    cin >> n;
    long long sum = 0;
    long long a[n] = {};
    vector<long long> plus;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        int b;
        cin >> b;
        if(a[i] >= b) plus.push_back(a[i]-b);
        sum += a[i]-b;
    }
    
    if(sum < 0){
        cout << -1 << endl;
        return 0;
    }
    sort(plus.begin(), plus.end());
    if(n-plus.size() == 0){
        cout << 0 << endl;
        return 0;
    }
    int same = 0;
    for(auto c: plus){
        if(sum >= c){
            sum -= c;
            same++;
        }else{
            break;
        }
    }
    
    cout << n - same<< endl;
    return 0;
}

Measured memory_bytes: 2168
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef set<int> si;
typedef string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int A[200010];
int N;
void solve(){
  int m=0,m2=0,x,x2;
  rep(i,N){
    if(m<=A[i]){
      m2=m;
      m=A[i];
      x2=x;
      x=i;
    }
    else if(m2<=A[i]){
      m2=A[i];
    }
  }
  rep(i,N){
    if(i==x) prin(m2);
    else prin(m);
  }
}
int main(){
  cin>>N;
  rep(i,N) cin>>A[i];
  solve();
  return 0;
}


Measured memory_bytes: 2432