akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define uu unsigned
#define io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define pl pair<ll,ll>
#define mkp make_pair
#define ss second
#define ff first
#define mit(a,b) map<a,b>::iterator
#define sit(a) set<a>::iterator
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define printf __mingw_printf
#define printcas cout<<"Case "<<cas<<": "
#define _ continue;
#define endl '\n'
#define __ cout<<endl;continue;
const ll oo=(1ll<<60);
int gi(){
	int x=0,w=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')w=0,ch=getchar();
	while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
vector<vi> v(100005);
unordered_set<int> us;
int n,m,x,y,i,j,k,dp[100005];
int f(int id)
{
    if(dp[id]!=-1) return dp[id];
    int sz=v[id].size();
    //cout<<'S'<<sz<<endl;
    if(!sz) return dp[id]=0;
    int ans=-1;
    for(int jj=0;jj<sz;jj++)
        {//cout<<v[id][jj]<<endl;
        ans=max(ans,1+f(v[id][jj]));}
        //cout<<endl<<id<<' '<<ans<<endl;
    return dp[id]=ans;
}
int main()
{
     io;
    //string hudai(1000000,'a');
    int T=1;
    //T=gi();
     for(int cas=1;cas<=T;cas++)
    {
       n=gi();
       m=gi();
       for(i=1;i<=m;i++)
       {
           x=gi();
           y=gi();
           v[x].pb(y);
           us.insert(y);

       }
       for(i=1;i<=n;i++)dp[i]=-1;
       int ans=-1;
       for(i=1;i<=n;i++)
       {
           if(us.find(i)==us.end())ans=max(ans,f(i));
       }
       cout<<ans;

    }
    return 0;
}



Measured memory_bytes: 17908
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}


int main() {
    int x,y,x2,y2;
    cin >> x >> y >> x2 >> y2;
    int dx = x2-x;
    int dy = y2-y;
    int x3 = x2-dy;
    int y3 = y2 + dx;
    int x4 = x - dy;
    int y4 = y + dx;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int m, d;
    cin >> m >> d;
    
    int cnt = 0;
    rep3(i, 1, m + 1) {
        rep3(j, 1, d + 1) {
            if (j % 10 < 2) continue;
            if ((j / 10) % 10 < 2) continue;
            if ((j % 10) * (j / 10 % 10) == i) {
                // out(i << " " << j);
                cnt++;
            }
        }
    }
    out(cnt);
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
#define F first
#define S second
#define MK make_pair
const ll E=1e17+7;
const ll MOD=1000000007;

ll n;

vector<vector<ll>> e(100);

ll dfs(ll w,set<ll> done){
    if(done.size()==n-1){return 1;}
    ll count=0;
    done.insert(w);
    for(int i=0;i<e[w].size();i++){
        if(done.find(e[w][i])==done.end()){
            count+=dfs(e[w][i],done);
        }
    }
    return count;
}



int main(){
    ll m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        ll f,t;
        cin>>f>>t;
        f--; t--;
        e[f].push_back(t);
        e[t].push_back(f);
    }
    set<ll> a;
    cout<<dfs(0,a)<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
struct p{
	long long int a,b;
};
bool cmp(struct p x,struct p y){
	return x.a<y.a;
}
int main(){
	int n,m;
	while(cin>>n>>m){
		struct p arr[n];
		for(int i=0;i<n;i++){
			cin>>arr[i].a>>arr[i].b;
		}
		sort(arr,arr+n,cmp);
		long long int sum=0;
		for(int i=0;i<n;i++){
			if(m>=arr[i].b){
				m-=arr[i].b;
				sum+=arr[i].b*arr[i].a;
			}
			else{
				sum+=m*arr[i].a;
				break;
			}
			if(m==0)
				break;			
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 1792
/**
*    created: 17.05.2020 12:13:35
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int main() {
    int n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    //if(h[i+1]-h[i]>=-1)
    bool f = false,t;
    //f:h[i]が下げれないときtrue
    //t:h[i-1]が下げれたら
    rep(i,n){
        if(i==n-1){
            cout << "Yes" << endl;
            break;
            }
       // cout << "f:"<<f << endl;
        if(h[i+1]==h[i]){
            continue;
        }
        if(h[i+1]==h[i]-1){
            if(f){
                cout << "No" << endl;
                break;
            }else{
                f = 1;
                continue;
            }
        }
        if(h[i+1]-h[i]<-1){
            cout << "No" << endl;
            break;
        }
        f = 0;
        t = 0;
    }
}

Measured memory_bytes: 1152
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
T = [[0] * w for i in range(h)]
i, j = 0, 0
cnt = 0
m = 1
k = a[m - 1]
while True:
    T[i][j] = m
    k -= 1
    if k == 0:
        if cnt == h * w - 1:
            break
        m += 1
        k = a[m - 1]
    if i % 2 == 0:
        j += 1
        if j == w:
            j -= 1
            i += 1
    else:
        j -= 1
        if j == -1:
            j += 1
            i += 1
    cnt += 1

for i in range(h):
    print(" ".join(map(str, T[i])))

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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	string s; cin >> s;
	int n = int (s.size());
	int m = (n-1)/2;
	int l = (n+3)/2;
	for(int i=0;i<m;i++){
		if(s[i]!=s[m-1-i]){
			cout << "No" << endl;
			return 0;
		}
	}
	for(int i=l-1;i<n;i++){
		if(s[i]!=s[n-1-i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N;
  while(cin >> N){
    vector<int> P(N); cin >> P;

    set<int> s;

    int ans = 0;

    REP(i,N){
      s.insert(P[i]);
      //dump(s);

      ///dump(*s.begin());

      if(*s.begin() == P[i]) ++ans;
    }
    
    
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

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

    int n;
    cin>>n;
    int pos=-1,num=INF;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(pos<a){
            pos=a;
            num=b;
        }
    }
    cout<<pos+num<<endl;

}

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


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

vector < int > g[1005];
vector<int> mt;
vector<bool> used;
 
bool try_kuhn (int v) {
	if (used[v])  return false;
	used[v] = true;
	for (size_t i=0; i<g[v].size(); ++i) {
		int to = g[v][i];
		if (mt[to] == -1 || try_kuhn (mt[to])) {
			mt[to] = v;
			return true;
		}
	}
	return false;
}


int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
vector<pii> v1,v2;
rep(i,1,n)
{
	int x,y;
	cin>>x>>y;
	v1.pb(mp(x,y));
}
rep(i,1,n)
{
	int x,y;
	cin>>x>>y;
	v2.pb(mp(x,y));
}

rep(i,0,n-1)
{
	rep(j,0,n-1)
	{
		if(v1[i].ff<v2[j].ff&&v1[i].ss<v2[j].ss)
		{
			g[i].pb(j);
		}
	}
}

	mt.assign (n, -1);
	for (int v=0; v<n; ++v) {
		used.assign (n, false);
		try_kuhn (v);
	}
 int ans=0;
	for (int i=0; i<n; ++i)
		if (mt[i] != -1)
			ans++;
ol(ans);
return 0;
}



Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author koneko096
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    DHandstand solver = new DHandstand();
    solver.solve(1, in, out);
    out.close();
  }

  static class DHandstand {
    private List<Integer> trans = new ArrayList<>();

    public void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt(), k = in.nextInt();
      char[] s = in.next().toCharArray();

      for (int i = 1; i < n; i++) {
        if (s[i] != s[i - 1])
          trans.add(i - 1);
      }

      int ans = 0;
      for (int i = 0; i < n; i++) {
        ans = Math.max(ans, compute(i, k, n, s[i] == '1'));
      }
      out.println(ans);
    }

    private int compute(int i, int k, int n, boolean one) {
      int m = trans.size(), R;
      int rightIdx = SearchUtil.lowerBound(trans, 0, m, i) + 2 * k;
      if (!one)
        rightIdx--;
      if (rightIdx >= m)
        R = n - 1;
      else
        R = trans.get(Math.min(rightIdx, m - 1));
      return R - i + 1;
    }

  }


  static class SearchUtil {
    public static int lowerBound(List<Integer> a, int low, int high, int element) {
      while (low < high) {
        int middle = (low + high) / 2;
        if (element > a.get(middle))
          low = middle + 1;
        else
          high = middle;
      }
      return low;
    }

  }


  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

    public int nextInt() {
      return Integer.parseInt(next());
    }

  }
}



Measured memory_bytes: 29396
#include <bits/stdc++.h>
using namespace std;
int n;
struct Node {
	int l, r;
	friend int operator < (Node a, Node b) {
		return a.r > b.r;
	}
};
priority_queue<Node> que;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) {
		int x, l;
		scanf("%d%d", &x, &l);
		que.push((Node){x - l, x + l});		
	}
	int cnt = 0, ex = -1e9;
	while (! que.empty()) {
		Node cur = que.top();
		que.pop();
		if (cur.l >= ex)
			cnt ++, ex = cur.r;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 1400
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
d = gets.chomp.to_i
e = gets.chomp.to_i

arr_for_whole_sum = [a,b,c,d,e]

whole_sum = 0
arr_for_whole_sum.each do |v|
  whole_sum += v
end

arr_for_distance_from_10 = []
arr_for_whole_sum.each do |v|
  arr_for_distance_from_10 << (10- (v.to_s.split("")[-1].to_i))
end

rest_sum = 0
arr_for_distance_from_10.delete 10
arr_for_distance_from_10.sort!
arr_for_distance_from_10.delete_at(-1)

arr_for_distance_from_10.each do |v|
  rest_sum += v
end

p whole_sum + rest_sum


Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int m[270] = {};

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

    for (int i = 0; i < w.length(); i++) {
        m[w[i] - 'a'] += 1;
    }

    bool ans = true;
    for (int i = 0; i < sizeof(m)/sizeof(int); i++) {
        if (m[i] % 2 != 0) {
            ans = false;
            break;
        }
    }

    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val A = Array.fill(3, 3)(sc.nextInt)
  val N = sc.nextInt
  val b = Array.fill(N)(sc.nextInt)

  val x = A.map(_.map(b.contains(_)))
  val y = {
    val d = x.exists(x => x.forall(y => y))
    val e = x.transpose.exists(x => x.forall(y => y))
    val f = x(0)(0) && x(1)(1) && x(2)(2)
    val g = x(0)(2) && x(1)(1) && x(2)(0)

    d || e || f || g
  }
  val z = if (y) "Yes" else "No"
  println(z)
}


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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
#define sbp(p, n) rep(i, n) { int a, b; scanf("%d %d", &a, &b); p[i] = make_pair(a, b); }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n,m; cin>>n>>m;
	int a[n]; memset(a,-1,sizeof(a));
	for(int i=0;i<m;i++)
	{
	    int p,q; cin>>p>>q;
	    p--;
	    if(a[p]!=-1 && a[p]!=q){ cout<<-1; return 0; }
	    if(n>1 && p==0 && q==0){ cout<<-1; return 0; }
	    a[p]=q;
	}
	if(a[0]==-1 && n>1) a[0]=1;
	else if(a[0]==-1) a[0]=0;
	for(int i=1;i<n;i++) if(a[i]==-1) a[i]=0;
	for(auto it:a) cout<<it;
	
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
 
 
int main() {
    int a, b, c;
    std::cin >> a >> b >> c;
 
    if (a==b && b==c)
    {
        std::cout << "1" << std::endl;
    }
    else if (a==b || b==c || a==c)
    {
        std::cout << "2" << std::endl;
    }
    else
    {
        std::cout << "3" << std::endl;
    }
    return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  
  int division = (a + b) / 2;
  int residue = (a + b) % 2;
  
  if (a == b|| residue == 0) {
    cout << division << endl;
  }
  else {
    cout << "IMPOSSIBLE" <<endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	string A, B, C;
	cin >> N >> A >> B >> C;

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		set<char> s = { A[i], B[i], C[i] };
		ans += s.size() - 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
 	int n, d; cin >> n >> d;
  	double x, y;
  	int ans=0;
  	while(n--){
   		cin >> x >> y;
      	double a=sqrt(x*x+y*y);
      	if(a<=d)
          ans++;
    }
  	cout << ans;
}

Measured memory_bytes: 3696
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		String N = sc.nextLine();
		sc.close();

		for(int i=0; i<3; i++) {
			if(N.charAt(i) == '7') {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");



		}

	}




Measured memory_bytes: 35556
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
    return '"' + s + '"';
}
string to_string(const char* s) {
    return to_string((string) s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}
template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
//Auther: Arin Roday
#define vec vector
#define i64 long long
#define endl '\n'
#define sz(x) (x).size()
#define times(n) for(int i = 0; i < (n); ++i)
#define bits(x) __builtin_popcount(x)
#define int long long
int test_case_number = 1;

void print_case(){
    #ifdef LOCAL
    cout << "Case #" << test_case_number++ << ": ";
    #endif
}

bool is_possible(int length, vector<int> a, int k){
    for(int val : a){
        k -= ((val + length - 1)/length) - 1;
        debug(length, k);
    }
    return k >= 0;
}

void solve(){
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    int right = INT_MIN;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        right = max(right, a[i]);
    }
    debug(a);
    int left = 1, mid;
    while(left <= right){
        mid = left + (right - left)/2;
        if(is_possible(mid, a, k)){
            right = mid - 1;
        } else {
            left = mid + 1;
        }
        debug(left, right);
    }
    cout << left << endl;
}
 
int32_t main(){
    solve();
}   

Measured memory_bytes: 6368
N = int(input())
print(input().count("ABC"))

""" 3文字ずつスライスし判定
S = input()
count = 0
# スライスでi+2文字目まで行くのでfor文範囲はN-2でとどめる
for i in range(N-2):
    if S[i:i+3] == "ABC":
        count += 1
print(count) """

Measured memory_bytes: 61408
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define souatari rep1(i,n-1)rep(j,i)
#define souatari1 for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;


vi edge[200005];
int counter[200005];
ll ans[200005];

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

  int n,q;
  cin >> n >> q;

  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  rep(i,q){
    int  p,x;
    cin >> p >> x;
    counter[p]+=x;
  }

  stack<array<ll,3>> que;
  que.push({1,0,0});

  while(!que.empty()){
    array<ll,3> tmp = que.top();
    que.pop();
    ans[tmp[0]] += counter[tmp[0]] + tmp[1];


    for(const auto& t : edge[tmp[0]]){
      if(t == tmp[2]) continue;
      que.push({t,ans[tmp[0]],tmp[0]});
    }
  }

  rep1(i,n)printf("%lld ", ans[i]);
  printf("\n");


  return 0;

}


Measured memory_bytes: 19736
//---------- Begin IO utilities ----------
// Thanks to https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:tt : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! p {
    ($v:ident) => {
        println!("{}", $v);
    };
    ($v:ident, $($t:ident),*) => {
        print!("{}", $v);
        ($(print!(" {}", $t)),*);
        println!();
    }
}
#[allow(unused_macros)]
macro_rules! ps {
    ($v:ident) => {
        println!("{}", $v.iter().collect::<String>());
    };
    ($v:ident, $($t:ident),*) => {
        print!("{}", $v.iter().collect::<String>());
        ($(print!(" {}", $t.iter().collect::<String>())),*);
        println!();
    }
}
#[allow(dead_code)]
fn pv<T: std::string::ToString>(v: &[T], sep: &str) {
    let s = v.iter().map(|e| e.to_string()).collect::<Vec<String>>().join(sep);
    println!("{}", s);
}
#[allow(dead_code)]
fn pvs(v: &[Vec<char>], sep:&str) {
    let s = v.iter().map(|e| e.iter().collect::<String>()).collect::<Vec<String>>().join(sep);
    println!("{}", s);
}
//---------- End IO utilities ----------

fn main() {
    input!{
        s: chars
    }
    let mut v = vec![0; s.len() + 1];
    v[0] = 0;
    let mut b = 1;
    for i in 1..v.len() {
        b = b * 10 % 2019;
        v[i] = (v[i-1] + b * (s[s.len()-i] as usize - 48)) % 2019;
    }
    let mut cnt = vec![0; 2019];
    for x in v {
        cnt[x] += 1;
    }
    let mut ans = 0;
    for x in cnt {
        ans += x * (x - 1) / 2;
    }
    p!(ans);
}


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

const int N = 200005, M = 200005;
const long long mod = 998244353ll, inv2 = mod + 1 >> 1, base = 1000000000000000000ll;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}
template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

int n, m1, m2, m3, f1[N], f2[N], f3[N];
vector<int> g1[N], g2[N], g3[N];
bool tmp[N];

long long x1[N << 1], x2[N << 1], x3[N << 1], x[N << 1];
void fwt (long long *f, int len, int ty) {
	for (int i = 1; i < len; i <<= 1) {
		for (int j = 0; j < len; j += (i << 1)) {
			for (int k = 0; k < i; k++) {
				long long u = f[j + k], v = f[i + j + k];
				f[j + k] = (u + v) % mod;
				f[i + j + k] = (u + mod - v) % mod;
			}
		}
	}
	if (ty < 0) {
		long long coef = 1ll;
		for (int i = 1; i < len; i <<= 1) coef = coef * inv2 % mod;
		for (int i = 0; i < len; i++) f[i] = f[i] * coef % mod;
	}
}

int main () {
	read(n);
	for (int i = 0; i <= n; i++) tmp[i] = false;

	read(m1);
	for (int i = 1; i <= m1; i++) {
		int u, v;
		read(u), read(v);
		g1[min(u, v)].push_back(max(u, v));
	}

	read(m2);
	for (int i = 1; i <= m2; i++) {
		int u, v;
		read(u), read(v);
		g2[min(u, v)].push_back(max(u, v));
	}

	read(m3);
	for (int i = 1; i <= m3; i++) {
		int u, v;
		read(u), read(v);
		g3[min(u, v)].push_back(max(u, v));
	}

	for (int i = n; i; i--) {
		f1[i] = 0;
		for (int j = 0; j < g1[i].size(); j++) tmp[f1[g1[i][j]]] = true;
		while (tmp[f1[i]]) f1[i]++;
		for (int j = 0; j < g1[i].size(); j++) tmp[f1[g1[i][j]]] = false;
	}

	for (int i = n; i; i--) {
		f2[i] = 0;
		for (int j = 0; j < g2[i].size(); j++) tmp[f2[g2[i][j]]] = true;
		while (tmp[f2[i]]) f2[i]++;
		for (int j = 0; j < g2[i].size(); j++) tmp[f2[g2[i][j]]] = false;
	}

	for (int i = n; i; i--) {
		f3[i] = 0;
		for (int j = 0; j < g3[i].size(); j++) tmp[f3[g3[i][j]]] = true;
		while (tmp[f3[i]]) f3[i]++;
		for (int j = 0; j < g3[i].size(); j++) tmp[f3[g3[i][j]]] = false;
	}

	int U = 1;
	while (U < n) U <<= 1;
	for (int i = 0; i < U; i++) x1[i] = x2[i] = x3[i] = 0ll;

	long long pw = 1ll;
	for (int i = 1; i <= n; i++) {
		pw = pw * (base % mod) % mod;
		x1[f1[i]] = (x1[f1[i]] + pw) % mod;
	}

	pw = 1ll;
	for (int i = 1; i <= n; i++) {
		pw = pw * (base % mod) % mod;
		x2[f2[i]] = (x2[f2[i]] + pw) % mod;
	}

	pw = 1ll;
	for (int i = 1; i <= n; i++) {
		pw = pw * (base % mod) % mod;
		x3[f3[i]] = (x3[f3[i]] + pw) % mod;
	}

	fwt(x1, U, 1), fwt(x2, U, 1), fwt(x3, U, 1);
	for (int i = 0; i < U; i++) x[i] = x1[i] * x2[i] % mod * x3[i] % mod;
	fwt(x, U, -1);
	write(x[0]), putchar('\n');
	return 0;
}

Measured memory_bytes: 33280
import Control.Applicative

main :: IO ()
main = solve <$> f >>= print
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> Int
solve [a, b, k] = let g = gcd a b
                  in (f g g) !! (k - 1)
  where
    f x y
      | y == 0 = []
      | x `mod` y == 0 = y : f x (y - 1)
      | otherwise = f x (y - 1)


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

int main(void) {
	string str;
	cin >> str;
	int N = 0, W = 0, S = 0, E = 0;
	for (int i = 0; i < str.length();i++) {
		N += str[i] == 'N';
		W += str[i] == 'W';
		S += str[i] == 'S';
		E += str[i] == 'E';
	}
	auto ok = [&](int x, int y) {
		if (!x && !y) return true;
		if (!x || !y) return false;
		return true;
	};
	cout << ((ok(N, S) && ok(W, E)) ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
	int i,j,k,l,x,y, s[6], n[6], n2[6];
	char c;
	for (i = 0; i<6; i++){
		scanf("%d", &s[i]);
		n[i] = i;
	}
	scanf("%d", &l);
	for (k = 0; k < l; k++){
		scanf("%d %d", &x, &y);
		for (j = 0; j < 5000; j++){
			if (j%6<3&&j%5==4){
				n2[0] = n[1]; n2[1] = n[5]; n2[3] = n[3]; n2[4] = n[0]; n2[2] = n[2]; n2[5] = n[4];
			}
			else {
				n2[0] = n[3]; n2[1] = n[1]; n2[3] = n[5]; n2[4] = n[4]; n2[2] = n[0]; n2[5] = n[2];
			}
			for (i = 0; i < 6; i++){
				n[i] = n2[i];
			}
			if (s[n[0]] == x&&s[n[1]] == y){
				printf("%d\n", s[n[2]]); break;
			}
		}
	}

	return 0;
}

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

int main(){
    ll m,n;
    cin>>m>>n;
    char matrix[m][n];
    ll dp[m][n],i,j;
    for(i=0;i<m;i++){
        for(j=0;j<n;j++)
        cin>>matrix[i][j];
    }
    dp[0][0]=1;
    for(j=1;j<n;j++) {
        if(matrix[0][j]=='.')
        dp[0][j]=dp[0][j-1];
        else
        dp[0][j]=0;
    }
    for(i=1;i<m;i++) {
        if(matrix[i][0]=='.')
        dp[i][0]=dp[i-1][0];
        else
        dp[i][0]=0;
    }
     for(i=1;i<m;i++){
        for(j=1;j<n;j++) {
            if(matrix[i][j]=='.')
            dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
            else
            dp[i][j] = 0;
        }
     }
     cout<<dp[m-1][n-1]%mod;
}

Measured memory_bytes: 12348
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <complex>
#include <sstream>

using namespace std;

typedef long long lli;

int data[100][100];
int n;
int size[100];

main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++){
      //int size;
      cin >> size[i];
      for(int j=0;j<size[i];j++){
        int in;
        cin >> in;
        //data[i].insert(in);
        data[i][j] = in;
      }
    }
    int m;
    cin >> m;
    int data2[100];
    for(int i=0;i<m;i++){
      int in;
      cin >> in;
      //data2.insert(in);
      data2[i] = in;
    }
    int ans = -1;
    for(int i=0;i<n;i++){
      bool f = true;
      for(int k=0;k<m;k++){
        for(int j=0;j<size[i];j++){
          if(data2[k] == data[i][j]){
            goto C;
          }
        }
        f = false;
        C:;
      }
      if(f){
        if(ans == -1) ans = i+1;
        else{
          ans = -1;
          goto END;
        }
      }
    }
    END:;
    cout << ans << endl;
  }
}

Measured memory_bytes: 908
#include <bits/stdc++.h>
#define i64 long long
#define maxn (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;


int main(){
	int n; cin>>n;
	int p[n+1], total=0;
	for(int i=0;i<n;i++) {
		cin>>p[i];
		total+=p[i];
	}
	sort(p,p+n);
	printf("%d\n", total-p[n-1]/2);
	return 0;
}

Measured memory_bytes: 256
class Integer
  def divisor
    res = []
    1.upto((self**0.5)) do |i|
      if self % i == 0
        res.push i
        res.push self / i if i != self / i
      end
    end
    res.sort
  end
end

def answer_if_valid(x, a, d)
  b = a - d
  if x == a ** 5 - b ** 5
    puts "#{a} #{b}"
    exit
  end
end

x = gets.to_s.to_i

r = x % 5

x.divisor.each do |d|
  (-200..200).each{ |a| answer_if_valid(x, a, d) }
end


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

template <class T> inline bool chmin(T& a,T b)
{
	if(a > b)
    {
    	a = b;
      	return true;
    }
  	return false;
}

typedef long long ll;
const ll INF = 1LL << 60;

int main ()
{
	int n, k;
  	cin >> n >> k;
  	ll height[100010];
  	for(int i = 0; i < n; i++)
    {
    	cin >> height[i];
    }
  	ll dp[110000];
  	for(int i = 0; i < 110000; i++)
    {
    	dp[i] = INF; 
    }
  	dp[0] = 0;
  	for(int i = 0; i < n; i++)
    {
    	for(int j = i + 1; j <= min(n, i+k); j++)
        {
        	chmin(dp[j], dp[i] + abs(height[j] - height[i]));
        }
    }
  	cout << dp[n-1] << endl;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

class unionfind {
    VI par, rank;
    int forest_num;
public:
    unionfind(int n) : par(n), rank(n, 1) {
        forest_num = n;
        for (int i = 0; i < n; i++)par[i] = i;
    }
    void init(int n) {
        par.clear(); par.resize(n);
        rank.clear(); rank.resize(n, 1);
        forest_num = n;
        for (int i = 0; i < n; i++)par[i] = i;
    }
    int root(int x) {
        if (par[x] == x)return x;
        return par[x] = root(par[x]);
    }
    int size(int x) {
        if (par[x] == x)return rank[x];
        return size(par[x]);
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)return;
        if (rank[rx] < rank[ry]) {
            par[rx] = ry;
            rank[ry] += rank[rx];
        }
        else {
            par[ry] = rx;
            rank[rx] += rank[ry];
        }
        forest_num--;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    int fnum() {
        return forest_num;
    }
};

int main() {
    init();

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

    unionfind uf(n);
    VI club(n, -1);
    int num, a, b, ans = INF;
    eFOR(i, 1, k) {
        cin >> num >> a >> b;
        a--, b--;
        int ar = uf.root(a), br = uf.root(b);
        if (num == 1){
            if (!uf.same(a, b)) {
                uf.unite(a, b);
                int nextr = uf.root(a);
                if (club[ar] != club[br]) {
                    if (club[ar] == -1)club[nextr] = club[br];
                    else if (club[br] == -1)club[nextr] = club[ar];
                    else chmin(ans, i);
                }
            }
        }
        else {
            if (club[ar] == -1)club[ar] = b;
            else if (club[ar] != b)chmin(ans, i);
        }
    }
    cout << ans % INF << "\n";
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int sig(int x)
{
  if(x==0){
    return 0;
  }else{
    return sig(x-1)+x;
  }
}

int main()
{
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  vector<double> ex(n);
  for(int i=0;i<n;i++){
    int q;
    cin >> q;
    p.at(i) = q;
    ex.at(i) = sig(q)/(double)q;
  }

  double max=0,count=0;
  for(int i=0;i<k;i++){
    count += ex.at(i);
  }
  max = count;

  for(int i=0;i<n-k;i++){
    count = (double)count - ex.at(i) + ex.at(k+i);
    if(count>=max){
      max = count;
    }
  }

  // for(int i=0;i<n;i++){
  //   cout << ex.at(i) << ' ';
  // }
  // cout << endl;
  cout << fixed << setprecision(12);
  cout << max << endl;

  return 0;
}


Measured memory_bytes: 2560
// Winners don't quit and Quitters don't win
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mod 998244353
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a;
    long double b,c;
    cin>>a>>b;
    c = (double)(a * b);
	cout<<(ll)c;  
}

Measured memory_bytes: 3736
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;
const int N_MAX=1e5*2+1;

signed main(){
  int n,k;
  cin>>n>>k;
  vector<int> h(n);
  for(int i=0;i<n;i++)cin>>h[i];
  int ans=1e9;
  sort(h.begin(),h.end());
  for(int i=0;i<=n-k;i++){
    ans=min(ans,h[i+k-1]-h[i]);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
a,b,c=map(int,raw_input().split())

k=0
h=[]
while a/2*2==a and b/2*2==b and c/2*2==c:
    an=(b+c)/2
    bn=(c+a)/2
    cn=(a+b)/2
    a=an
    b=bn
    c=cn

    if [a,b,c] in h:
        k=-1
        break
    h.append([])
    h[k].append(a)
    h[k].append(b)
    h[k].append(c)
            
    k=k+1
    
print(k)



Measured memory_bytes: 2568
def main():
    n, k = map(int, input().split())
    w = []
    for i in range(n):
        w.append(int(input()))
    minp = max(w)
    maxp = sum(w)
    p = (minp + maxp) // 2
    while minp < maxp:
        l = w[0]
        t = 1
        for ww in w[1:]:
            if l + ww <= p:
                l += ww
            else:
                t += 1
                l = ww
        if t > k:
            minp = p + 1
        else:
            maxp = p
        p = (minp + maxp) // 2
    print(p)


if __name__ == '__main__':
    main()



Measured memory_bytes: 10344
n = gets.to_i
sort = gets.split().map(&:to_i)
min = 1000
count = 0

(n-1).times do |i|
  minIndex = i
  (i..n-1).each do |j|
    minIndex = j if sort[minIndex] > sort[j]
  end
  count += 1 if sort[i] != sort[minIndex]
  sort[i], sort[minIndex] = sort[minIndex], sort[i]
end

puts sort.join(" ")
puts count


Measured memory_bytes: 6864
#include <stdio.h>

int main() {
	long a, b;
	long GCD, LCM;
	long i, temp, c, d;
	while(scanf("%ld %ld", &a, &b) != EOF) {
		//GCD with Eucledean
		c = a, d = b;
		while(d > 0) {
			temp = c % d;
			c = d;
			d = temp;
		}
		GCD = c;
		//LCM
		LCM = (a / GCD) * b;
		printf("%ld %ld\n", GCD, LCM);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
int main(){
	int x,y,z;
	cin>>x>>y>>z;
	int ans=0;
	x-=z;
	while(x>0){
		if(x>=y+z){
			x-=y+z;
			ans++;	
		}
		else break;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define uint unsigned int
#define MOD 1000000007
#define MAXN 200005
#define MAXH 4
#define MAXM 100
#define INF 1LL << 30
#define ll long long
#define ull unsigned long long
#define RNG mt19937
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
const int N = 100005;
int cnt[N];

int main(){
	fast_io();
	string s;cin >> s;
	int k;cin >> k;
	set<string> S;
	cu(i,0,s.length()){
		fu(j,1,min(k, (int)s.length() - i)){
			S.insert(s.substr(i, j));
		}
	}
	auto it = S.begin();--k;
	while(k--)++it;
	cout << (*it) << '\n';
}



Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)cin >> v[i];

    int ret = 0;
    for (int i = 1; i < n - 1; i++) {
        if (v[i] != max({v[i - 1], v[i], v[i + 1]}) &&
            v[i] != min({v[i - 1], v[i], v[i + 1]}))
            ret++;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp std::make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
const ll MOD=1e9+7;
//const ll MOD=998244353;
//const ll MOD=100000;
const ll MAX=1e7;
const ll INF=(1ll<<60);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
struct Union_Find{
    ll N;
    vi par;
    vi siz;
    Union_Find(int n):N(n){
        par.resize(N);
        siz.resize(N,1);
        rep(i,0,N) par[i]=i;
    }
    ll root(ll X){
        if(par[X]==X) return X;
        return par[X]=root(par[X]);
    }
    bool same(ll X,ll Y){
        return root(X)==root(Y);
    }
    void unite(ll X,ll Y){
        X=root(X);
        Y=root(Y);
        if(X==Y) return;
        par[X]=Y;
        siz[Y]+=siz[X];
        siz[X]=0;
    }
    ll size(ll X){
        return siz[root(X)];
    }
};
ll modpow(ll X,ll Y){
    ll sum=X,cnt=1;
    vi A;
    while(cnt<=Y){
        A.pb(sum);
        sum*=sum;
        sum%=MOD;
        cnt*=2;
    }
    int M=A.size();
    ll ret=1;
    REP(i,1,M){
        if(Y>=(1ll<<M-i)){
            Y-=(1ll<<M-i);
            ret*=A[M-i];
            ret%=MOD;
        }
    }
    return ret;
}
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n,ll r){
    if(n<r||n<0||r<0) return 0;
    return fac[n]*finv[r]%MOD*finv[n-r];
}
signed main(){
    ll N,M; cin>>N>>M;
    vii edge(N);
    rep(i,0,M){
        ll X,Y; cin>>X>>Y;
        edge[X-1].pb(Y-1);
        edge[Y-1].pb(X-1);
    }
    vi dist(N,-1);
    std::queue<ll> que;
    que.push(0);
    dist[0]=0;
    vi ans(N);
    while(!que.empty()){
        ll X=que.front(); que.pop();
        rep(i,0,edge[X].size()){
            ll Y=edge[X][i];
            if(dist[Y]==-1){
                dist[Y]=dist[X]+1;
                ans[Y]=X+1;
                que.push(Y);
            }
        }
    }
    cout<<"Yes"<<endl;
    rep(i,1,N) cout<<ans[i]<<endl;
}


Measured memory_bytes: 13824
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    vector<Pl> ab(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i] >> b[i];
        ab[i].first = a[i] + b[i];
        ab[i].second = i;
    }
    sort(ab.begin(), ab.end(), greater<Pl>());
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        if(i % 2 == 0)  ans += a[ab[i].second];
        else    ans -= b[ab[i].second];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3456