akhauriyash/Code-Regression huggingface dataset:
#define k from p
def calck(all_w, p):
    count = 0
    sum = 0
    for w in all_w:
        if sum + w <= p:
            sum += w
        else:
            count+=1 
            sum = w
    return count+1

#get n and k
n, k =map(lambda x: int(x), input().split(' '))

#get all w
#set min and max of p
all_w = []
max = -1
sum = 0
for i in range(n):
    w = int(input())
    all_w.append(w)
    if w > max:
        max = w
    sum += w
max_weight = max
sum_weight = sum
min, max = max, sum
#binary search of p

while min<=max:
    p_pointer = (min+max)//2
    calcedk = calck(all_w, p_pointer)
    if calcedk > k:
        min = p_pointer+1
    elif p_pointer == max_weight or calck(all_w, p_pointer-1) > k:
        print(p_pointer)
        break
    else:
        max = p_pointer-1


Measured memory_bytes: 9560
#include <bits/stdc++.h>
using namespace std;
long long w[1010];
long long v[1010];
int N;
long long dp[110][100010];
long long mo(int pos , long long W){
    if(W < 0) return -1e9;
    if(pos == N){
        return 0;
    }
    long long &re = dp[pos][W];
    if(re != -1) return re;
    
    re = max( mo(pos+1 , W) , mo(pos+1 , W-w[pos]) + v[pos]);
    return re;
}   
int main(){
    int W;
    while(cin>>N>>W){
        memset(dp,-1,sizeof dp);
        for(int i = 0 ; i < N ; i++){
            cin>>w[i]>>v[i];
        }
        cout<<mo(0,W)<<"\n";
    }
    return 0;
}


Measured memory_bytes: 89508
#include <bits/stdc++.h>
using namespace std;
#define MS(x, i) memset(x, i, sizeof x)
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define NOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int maxn = 5e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-5;
char F[200];

inline ll read() {
    ll ret = 0, sgn = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-') sgn = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        ret = ret*10 + ch - '0';
        ch = getchar();
    } 
    return ret*sgn;
}

inline void write( ll x ) {
    ll tmp = x > 0 ? x : -x;
    if(x < 0) putchar('-');
    int cnt = 0;
    while(tmp > 0) {
       F[cnt++] = tmp % 10 + '0';
       tmp /= 10;
    }
    while(cnt > 0) putchar(F[--cnt]);
}

ll notprime[maxn];
ll prims[maxn];

void Prim()
{
    notprime[1] = 1;

    for(int i = 2; i < maxn; i++)
    {
        if(!notprime[i])
            prims[++prims[0]] = i;

        for(int j = 1; j <= prims[0] && i * prims[j] < maxn; j++)
        {
            notprime[i * prims[j]] = 1;
            if(i % prims[j] == 0)
                break;
        }
    }
}

ll nums[310];
ll ans = 0;
ll x = 0, d = 0, s = 0;
ll num;

bool dfs(ll up, ll now, ll check)
{
    if((now ^ d) > check)
        return false;
    ans = now ^ d;

    for(ll i = 0; i < up; i++)
    {
        if((num >> i) & 1)
        {
            if(!dfs(i, now + (1ll << i), check))
                return false;
        }
    }

    return true;
}
 
int main()
{
    NOS
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    
    //a + b = a ^ b + (a & b) >> 1;

    int n;
    cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> nums[i];

    s = nums[1] + nums[2];

    for(int i = 3; i <= n; i++)
        x ^= nums[i];

    if((s - x) % 2)
        cout << -1 << endl;
    else
    {
        d = (s - x) >> 1;

        if(d & x || d > nums[1])
            cout << -1 << endl;
        else
        {
            ans = d;
            num = x;
            dfs(50, 0, nums[1]);

            if(ans == 0) cout << -1 << endl;
            else cout << nums[1] - ans << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3660
N, K = map(int, input().split())
Alist = list(map(int, input().split()))
ans = 0

for i in range(N):
    a, b = 0, 0
    A = Alist[i]
    for j in range(N):
        if Alist[j] < A:
            b += 1
            if j > i:
                a += 1
    ans += a * K + b * (K**2 - (K * (K + 1)) // 2)
    # print(i, A, a, b)
print(ans % (10**9 + 7))

Measured memory_bytes: 41580
#include <iostream>

using namespace std;



int main(){
  long long t,a;
  int n;
  long long t_ans = 1;
  long long a_ans = 1;

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> t >> a;
    long d = max((t_ans + t - 1)/t, (a_ans + a - 1)/a);
    t_ans = t * d;
    a_ans = a * d;
  }

  cout << t_ans + a_ans << endl;

  return 0;
}


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

typedef pair< int , int > Pi;
const int INF = 1 << 30;

int main(){
  int n, m;
  int mas[100][100];
  int ser[4][50][50];
  Pi point[4];


  while(cin >> n >> m, n){
    for(int i = 0; i < 4; i++){
      point[i] = Pi( INF, INF);
    }

    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        cin >> mas[i][j];
      }
    }
    for(int i = 0; i < m; i++){
      for(int j = 0; j < m; j++){
        cin >> ser[0][i][j];
        if(ser[0][i][j] != -1) point[0] = min( point[0], Pi( i, j));
      }
    }
    for(int k = 0; k < 3; k++){
      for(int i = 0; i < m; i++){
        for(int j = 0; j < m; j++){
          ser[k + 1][j][m - i - 1] = ser[k][i][j];
          if(ser[k + 1][j][m - i - 1] != -1){
            point[k + 1] = min( point[k + 1], Pi( j, m - i - 1));
          }
        }
      }
    }

    Pi p = Pi( INF, INF);
    for(int i = 0; i + m <= n; i++){
      for(int j = 0; j + m <= n; j++){
        for(int q = 0; q < 4; q++){
          bool flag = true;
          for(int l = 0; l < m; l++){
            for(int o = 0; o < m; o++){
              if(ser[q][l][o] != -1 && mas[i + l][j + o] != ser[q][l][o]) flag = false;
            }
          }
          if(flag) p = min( p, Pi( i, j + point[q].second));
        }
      }
    }
    if(p == Pi( INF, INF)) cout << "NA" << endl;
    else cout << p.second + 1 << " " << p.first + 1 << endl;
  }
}

Measured memory_bytes: 1240
package main

import (
	"fmt"
	"sort"
)

type Bot struct {
	X, L int
}

type Bots []Bot

func (b Bots) Len() int {
	return len(b)
}

func (b Bots) Less(i, j int) bool {
	// return b[i].X < b[j].X
	return b[i].X+b[i].L < b[j].X+b[j].L
}

func (b Bots) Swap(i, j int) {
	b[i], b[j] = b[j], b[i]
}

func main() {
	var n int
	fmt.Scan(&n)

	bots := make([]Bot, n)
	for i := 0; i < n; i++ {
		var x, l int
		fmt.Scan(&x, &l)
		bots[i] = Bot{X: x, L: l}
	}
	sort.Sort(Bots(bots))

	bot := 0
	current := int(-1e9 - 10)
	for i := 0; i < n; i++ {
		b := bots[i]
		if current <= b.X-b.L {
			current = b.X + b.L
			bot++
		}
	}
	fmt.Println(bot)
}


Measured memory_bytes: 5504
#include <iostream>

using namespace std;

int a[100];
int n;

int main()
{
    cin>>n;
    int i,j,countnum=0;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    for(i=0;i<n;i++){
        for(j=n-1;j>i;j--){
            if(a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                countnum++;
            }
        }
    }
    for(i=0;i<n;i++){
        cout<<a[i];
        if(i!=n-1)cout<<" ";
    }
    cout<<endl;
    cout<<countnum<<endl;
    return 0;
}

Measured memory_bytes: 3092
N, M = gets.split.map(&:to_i)
x = []
count = 0
sum = 0

N.times do
  x << gets.split.map(&:to_i)
end

x.sort_by!{|i| i[0]}

x.each do |a, b|
  if count + b >= M
    sum += a * (M - count)
    break
  else
    sum += a * b
    count += b
  end
end

puts sum

Measured memory_bytes: 12664
//by kcz 1552920354@qq.com
//if you find any bug in my code
//please tell me
#include<bits/stdc++.h>
using namespace std;

template <typename T> void chmin(T &x,const T &y)
{
	if(x>y)x=y;
}
template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mp make_pair
#define gc (c=getchar())
char readc()
{
	char c;
	while(gc<'-');
	return c;
}
int read()
{
    char c;
    while(gc<'-');
    if(c=='-')
    {
        int x=gc-'0';
        while(gc>='0')x=x*10+c-'0';
        return -x;
    }
    int x=c-'0';
    while(gc>='0')x=x*10+c-'0';
    return x;
}
#undef gc

int main()
{
	//freopen("1.in","r",stdin);//freopen("1.out","w",stdout);
	int a[3];
	rep(i,0,2)cin>>a[i];
	int ans=0;
	while(1)
	{
		sort(a,a+3);
		if(a[0]==a[2])break;
		++ans;
		if(a[0]==a[1])
		{
			++a[0];++a[1];
		}
		else
		{
			a[0]+=2;
		}
	}
	cout<<ans;
}



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

using namespace std;

using ll = long long;

int main(){
	ll n, a, b; cin >> n >> a >> b;
	if(b < a)cout << 0;
	else if(n == 1 && b != a){
		cout << 0;
	}else if(n == 1 && b == a){
		cout << 1;
	}else{
		cout << (n - 2) * b - (n - 2) * a + 1;
	}
	
    return 0;
}


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

int arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(void) {
	int k;
	scanf("%d",&k);
	printf("%d",arr[k-1]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;

int main(){
    int n;
    cin >>n;
    vector<double> p(n+1,0);
    for(int i=0;i<n;i++){
        cin >>p[i];
    }
    vector<vector<double>>dp(n+5,vector<double>(n+5,+0.0));
    dp[1][0]=1-p[0];
    dp[1][1]=p[0];
    /*
 dp:[i][j]=try i-th --->true j
 i,j=i-1,j *p'   +i-1,j-1 * p
 */
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
        //    cout<<dp[i][j]<<" ";
                        //try --> faliure
            dp[i+1][j]+= dp[i][j]*(1-p[i]);
            //try --> succisu
            dp[i+1][j+1]+=dp[i][j]*p[i];
        }
       // cout<<endl;
    }
    double ans=0.0;
    for(int i=(n+1)/2;i<=n;i++){
        ans+=dp[n][i];
    }
    printf("%.15lf\n",ans);
}


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

int main() {
  int A;
  int B;
  char op;
  
  cin >> A;
  cin >> op;
  cin >> B;
 
 if ( op == '+'){
   cout << A + B << endl;
 }
  else{
    cout << A - B << endl;
  }
  
 
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

//??°?????????????????°

void function()
{
    //??¢??°
}
 
int main(){
    for (int i = 1; i <= 9; i++){
    	for (int j = 1; j <= 9; j++){
    		cout << i << "x" << j << "=" << i * j << endl;	
    	}
    }
    return 0;
}

Measured memory_bytes: 1116
import numpy as np


def prepare(n):
    f = 1
    for i in range(2, n + 1):
        f = f * i % MOD
    inv = [1] * (n + 1)
    inv[n] = pow(f, MOD - 2, MOD)
    for i in range(n, 0, -1):
        inv[i - 1] = inv[i] * i % MOD
    return f, inv


MOD = 998244353
s = input()
n = len(s)
dp = np.zeros(n + 1, dtype=np.int64)
dp[0] = 1
b_all = 0
i, j = 0, 1
for k in range(n):
    b_all += int(s[k])
    ball = 2 * (k + 1)
    dp += np.roll(dp, 1)
    dp %= MOD
    if j <= ball - b_all:
        j += 1
    else:
        dp[j] = 0
    if k - i < b_all:
        pass
    else:
        dp[i] = 0
        i += 1
r_all = 2 * n - b_all
f, inv = prepare(n)
ans = 0
for k in range(i, j):
    r = r_all - k
    b = n - r
    ans += dp[k] * f % MOD * inv[r] % MOD * inv[b]
    ans %= MOD
print(ans)


Measured memory_bytes: 12504
INF=float("inf")
n, m, x = map(int, input().strip().split())
L = [list(map(int, input().split())) for _ in range(n)]

ans=INF
for i in range(2**n):
    bin_=i
    money=0
    rikaido=[0]*m
    book=0
    while bin_:
        if bin_ & 1: # read
            money+=L[book][0]
            for j in range(m):
                rikaido[j]+=L[book][j+1]
        bin_>>=1
        book+=1
    for j in range(m):
        if rikaido[j]<x:
            break
    else:
        ans=min(ans,money)
        
if ans==INF:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<int, int, int> T;
// get<K>(tuple型の変数)

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

int main(void){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n; cin >> n;
    vector<pair<double, double>> v;
    rep(i, n){
        int x, y; cin >> x >> y;
        if(x!=0 || y!=0) v.push_back(make_pair(x, y));
    }

    sort(v.begin(), v.end(), [](pair<double, double> a, pair<double, double> b){ return argument(make_pair(0, 0), a) < argument(make_pair(0, 0), b);});

    double ans=0.0;
    n = v.size();
    rep(i, n){
        double x=0.0, y=0.0;
        rep(j, n){
            auto p=v[(i+j)%n];
            x += p.first;
            y += p.second;
            chmax(ans, sqrt(x*x + y*y));
        }
    }
    cout << setprecision(15);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
    char s[3];
    cin >> s;
    int value=700;
    for(int i=0; i<3; i++){
        if(s[i]=='o'){
            value+=100;
        }
    }
    cout << value << endl;
    return 0;
}

Measured memory_bytes: 256
fun main() {
    val n = nextInt()
    println(1000.minus(n.rem(1000)).rem(1000))
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

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

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	double a, b;
	cin >> a >> b;
	cout << ceil((b - 1) / (a - 1)) << endl;
	return 0;
}


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


int main() {
  int x, y, z;
  cin >> x >> y >> z;
  int i=0;
  while(1){
    ++i;
    if(z+i*(y+z)>x) break;
  }
  cout << i-1 << endl;
  return 0;
}

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

typedef long long ll;

const ll mod = 1e9 + 7; 
const int N = 200010;

ll mult(ll x, ll y) { return (x * y) % mod; }

ll binpow(ll a, ll n) {
	ll res = 1;
	while (n) {
		if (n & 1) res = mult(res, a);
		a = mult(a, a);
		n >>= 1;
	}
	return res;
}

ll h, w, a, b, f[N], inv[N], pref[N], ans;

void precalc() {
	f[0] = 1;
	for (ll i = 1; i < N; i++)
		f[i] = mult(f[i - 1], i);
	for (ll i = 0; i < N; i++)
		inv[i] = binpow(f[i], mod - 2);
}

ll get(ll n, ll m) {
	ll res = mult(f[n + m - 2], inv[n - 1]);
	return mult(res, inv[m - 1]);
}

int main() {
	precalc();
	cin >> h >> w >> a >> b;	
	for (ll i = 1; i <= h - a; i++) {
		ll part1 = get(i, b + 1);
		if (i > 1) part1 = (part1 - pref[i - 1] + mod) % mod;
		pref[i] = (pref[i - 1] + part1) % mod;
		ll part2 = get(h - i + 1, w - b);
		ans += mult(part1, part2);
		ans %= mod;
	}
	cout << ans;
}


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

int main()
{
  int n;
  cin >> n;
  int h;
  cin >> h;
  int ans = 1;
  for (int i = 0; i < n - 1; i++)
  {
    int m;
    cin >> m;
    if (m >= h)
    {
      ans++;
      h = m;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int r = in.nextInt();
		int g = in.nextInt();
		int b = in.nextInt();
		int n = in.nextInt();
		System.out.println(solve(r, g, b, n));
		in.close();
	}

	private static int solve(int r, int g, int b, int n) {
		int ans = 0;
		for (; n >= 0; n -= r)
			for (int m = n; m >= 0; m -= g)
				if (m % b == 0)
					ans++;
		return ans;
	}
}

Measured memory_bytes: 21844
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n, x, y;
	cin >> n >> x >> y;
	int res[n] = {};
	// roop外が端点
	for(int i = 1; i < x; i++){
		for(int j = i+1; j<x; j++){
			res[j-i]++;
		}
	}
	for(int i = y+1; i <= n; i++){
		for(int j = i+1; j<= n; j++){
			res[j-i]++;
		}
	}
	for(int i = 1; i < x; i++){
		for(int j = y+1; j<= n; j++){
			res[(j-y)+(x-i)+1]++;
		}
	}
	//両端点がループ内
	REP1(i, (y-x+1)/2){ 
		if((y-x+1)%2==0 && i == (y-x+1)/2) res[i] += (y-x+1)/2;
		else res[i] += y-x+1;

	}
	//片方がループ内、もう片方がループ外
	for(int i = 1; i < x; i++){
		REP(j, (y-x+1)/2 + 1){
			if(j == 0)res[x-i+j]++;
			else if((y-x+1)%2==0 && j == (y-x+1)/2) res[x-i+j]++;
			else res[x-i+j] += 2;
		}
	}
	for(int i = y+1; i <= n; i++){
		REP(j, (y-x+1)/2 + 1){
			if(j == 0)res[i-y+j]++;
			else if((y-x+1)%2==0 && j == (y-x+1)/2) res[i-y+j]++;
			else res[i-y+j] += 2;
		}
	}
	REP1(i, n-1) cout << res[i] << endl;
	//cout << ans << endl;
}

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

long long n,k;
signed main(){
	scanf("%lld%lld",&n,&k);
	long long v=1;
	long long i=k;
	while(i<n+1){
		v+=i*n-i*(i-1)+1;
		i++;
	}
	long long a=pow(10,9)+7;
	cout<<v%a;
//	printf("%lld",v%a);
	return 0;
} 

Measured memory_bytes: 3768
n=int(input())
a=[]
for i in range(n):
    x=int(input())
    b=[[int(i) for i in input().split()] for i in range(x)]
    a.append(b)

ans=0

for i in range(2**n):
    status=[True]*n
    for j in range(n):
        if ((i>>j)&1):
            status[j]=False
    
    judge=[None]*n
    contradiction=False
    
    for x,person in enumerate(a):
        if status[x]==False:
            continue
        for testimony in person:
            if testimony[1]==1: 
                if judge[testimony[0]-1]!=False and status[testimony[0]-1]==True:
                    judge[testimony[0]-1]=True
                else:
                    contradiction=True
            else:
                if judge[testimony[0]-1]!=True and status[testimony[0]-1]==False:
                    judge[testimony[0]-1]=False
                else:
                    contradiction=True

    if contradiction==False:
        ans=max(ans,status.count(True))
print(ans)
            

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>

#define mod 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define PB push_back

using namespace std;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
    int N;
    cin>>N;
    cout<<N*180-360;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int64_t a = 2;
  	int64_t b = 1;
  	int64_t c,N;
  	cin >> N;
   	if(N == 1){
    cout << b << endl;
    }
  	if(N > 1){
  		for(int i = 1;i < N; i++){
			c = b + a;
    		a = b;
    		b = c;
    	}
      cout << c << endl;
    }
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    string t = "";
    for (int i = s.size() - 1; i >= 0; i--) {
        t += s[i];
        if (t == "maerd" || t == "remaerd" || t == "esare" || t == "resare") {
            t = "";
        }
    }
    if (t == "") cout << "YES" << '\n';
    else cout << "NO" << '\n';
    return 0;
}

Measured memory_bytes: 592
s = input()
flag = 0
flag1 = 0
flag2 = 0
count1 = s.find('A')
if count1 == -1:
	flag = 1
if flag == 0:
	if s.index('A') != 0:
		flag = 1
if flag == 0:
	s = '1' + s[1:]

count2 = s.find('C')
if count2 > 1 and count2 < len(s) - 1: 
	flag1 = 0
else:
	flag1 = 1

if flag1 == 0:
	s = s[:count2] + '2' + s[count2 + 1:]


if s.find('A') != -1:
	flag2 = 1
if s.find('C') != -1:
	flag2 = 1
if s.find('B') != -1:
	flag2 = 1
if s.find('D') != -1:
	flag2 = 1
if s.find('E') != -1:
	flag2 = 1
if s.find('F') != -1:
	flag2 = 1
if s.find('G') != -1:
	flag2 = 1
if s.find('H') != -1:
	flag2 = 1
if s.find('I') != -1:
	flag2 = 1
if s.find('J') != -1:
	flag2 = 1
if s.find('K') != -1:
	flag2 = 1
if s.find('L') != -1:
	flag2 = 1
if s.find('M') != -1:
	flag2 = 1
if s.find('N') != -1:
	flag2 = 1
if s.find('O') != -1:
	flag2 = 1
if s.find('P') != -1:
	flag2 = 1
if s.find('Q') != -1:
	flag2 = 1
if s.find('R') != -1:
	flag2 = 1
if s.find('S') != -1:
	flag2 = 1
if s.find('T') != -1:
	flag2 = 1
if s.find('U') != -1:
	flag2 = 1
if s.find('V') != -1:
	flag2 = 1
if s.find('W') != -1:
	flag2 = 1
if s.find('X') != -1:
	flag2 = 1
if s.find('Y') != -1:
	flag2 = 1
if s.find('Z') != -1:
	flag2 = 1

if flag == 1 or flag1 == 1 or flag2 == 1:
	print('WA')
else:
	print('AC')

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
const char* LF = "\n";
namespace{struct _{_(){
    cin.tie(0);
    ios::sync_with_stdio(false);
}}a;}

signed main() {
    string S;
    cin >> S;
    S[3] = '8';
    cout << S << LF;
    return 0;
}


Measured memory_bytes: 256
D,G = map(int,input().split())
l = list(list(map(int, input().split())) for _ in range(D))

#得点の大きい順に並び替えておく
l = l[::-1]

ans = float("inf")
for i in range(2**D):
    total = 0
    cnt = 0
    for j in range(D):
        if (i>>j)&1:
            total += 100*(D-j)*l[j][0] + l[j][1]
            cnt += l[j][0]
    if total >= G:
        ans = min(ans,cnt)
        continue
    for j in range(D):
        if (i>>j)&1 == False:
            for k in range(l[j][0]):
                total += 100*(D-j)
                cnt+=1
                if total >= G:
                    ans = min(ans,cnt)
                    break
            #break

print(ans)

Measured memory_bytes: 3064
N =int(input())
Alist=list(map(int,input().split()))

Flag=True
for i in range(N):
    if Alist[i]%2==0:
        if Alist[i]%3==0 or Alist[i]%5==0:
            continue
        else:
            Flag=False

if Flag:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RREP(i, n) for(int i = (n)-1; i >= 0; i--)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

constexpr int dx[] = {-1, 0, 1, 0};
constexpr int dy[] = {0, -1, 0, 1};

template <typename T, std::size_t N>
struct make_vector_type {
	using type =
		typename std::vector<typename make_vector_type<T, (N - 1)>::type>;
};

template <typename T>
struct make_vector_type<T, 0> {
	using type = typename std::vector<T>;
};

template <typename T, size_t N>
auto make_vector_impl(const std::vector<std::size_t>& ls, T init_value) {
	if constexpr(N == 0) {
		return std::vector<T>(ls[N], init_value);
	} else {
		return typename make_vector_type<T, N>::type(
			ls[N], make_vector_impl<T, (N - 1)>(ls, init_value));
	}
}

template <typename T, std::size_t N>
auto make_vector(const std::size_t (&ls)[N], T init_value) {
	std::vector<std::size_t> dimensions(N);
	for(int i = 0; i < N; i++) {
		dimensions[N - i - 1] = ls[i];
	}
	return make_vector_impl<T, N - 1>(dimensions, init_value);
}

template <typename T>
std::vector<T> make_vector(std::size_t size, T init_value) {
	return std::vector<T>(size, init_value);
}

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max<T>(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min<T>(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n;
	cin >> n;
	list<int> b;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		b.push_back(tmp);
	}

	list<int> result;
	REP(i, n) {
		auto ittr = b.rbegin();
		bool exists = false;
		RREP(j, n - i + 1) {
			if(*ittr == j) {
				result.push_front(*ittr);
				b.erase(--(ittr.base()));
				exists = true;
				break;
			}
			ittr++;
		}
		if(!exists) {
			cout << -1 << endl;
			return 0;
		}
	}
	EACH(e, result) { cout << e << endl; }
	return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#define BUG puts("no bug")
#define sci(x) scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define ll long long
#define ull unsigned long long
#define REP(a,b,c) for(ll a=b;a<=c;a++)
#define PER(a,b,c) for(ll a=b;a>=c;a--)
#define lb(a) (a&(-a))
#define pp (p<<1)
#define ppp (p<<1|1)
#define pi pair<ll,ll>
#define pii pair<pair<ll,ll>,ll>
using namespace std;
const ll MAXN=1e6+5;
ll mod=1e9+7;
ll n,m,t;
ll total=0;
ll head[MAXN],nxt[MAXN],to[MAXN],len[MAXN];
void add(ll a,ll b,ll c=1){
    nxt[++total]=head[a];
    to[total]=b;
    len[total]=c;
    head[a]=total;
}
void exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll INV(ll a)
{
    ll x,y;
    exgcd(a,mod,x,y);
    return (x+mod)%mod;
}
ll siz[MAXN];
ll ans[MAXN];
void dfs1(ll x,ll fa){
    siz[x]++;
    for(ll i=head[x];i;i=nxt[i]){
        ll tmpto=to[i];
        if(tmpto==fa)continue;
        dfs1(tmpto,x);
        siz[x]+=siz[tmpto];
    }
}
void dfs2(ll x,ll fa){
    for(ll i=head[x];i;i=nxt[i]){
        ll tmpto=to[i];
        if(tmpto==fa)continue;
        ans[tmpto]=ans[x]*INV(siz[tmpto])%mod*(n-siz[tmpto])%mod;
        dfs2(tmpto,x);
    }
}
int main(){
    cin>>n;
    REP(i,1,n-1){
        ll a,b;
        cin>>a>>b;
        add(a,b);
        add(b,a);
    }
    dfs1(1,0);
    ans[1]=1;
    REP(i,1,n)ans[1]=ans[1]*siz[i]%mod;
    ll t=1;
    REP(i,1,n)t=t*i%mod;
    dfs2(1,0);
    REP(i,1,n){
        cout<<t*INV(ans[i])%mod<<endl;
    }
}

Measured memory_bytes: 24320
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int N;
    cin >> N;
    int before = 0;
    int ans = 0;
    rep(i, N) {
        int a;
        cin >> a;
        if (a == before) ans += 1, before = 0;
        else before = a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<cstdio>

using namespace std;
typedef long long ll;
const int N = 1010;

int main()
{
	char a[5];
	scanf("%s", a);
	
	int r = 0, ans = -1;
	for(int i = 0; i < 3; i++)
	{
		if(a[i] == 'R')	r++;
		else	r = 0;
		ans = max(ans, r);
	}
	printf("%d\n", ans); 
	return 0;
}



Measured memory_bytes: 3820
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define MOD 1000000007
int N,L;
int x[5010],a[5010];
int dp[5010][5010];
int rec(int i,int j)
{
	if(j==N)return 1ll;
	if(i==L)return 0ll;
	if(dp[i][j]!=-1)return dp[i][j];
	ll res =  rec(i+1,j);
	if((a[j]==0&&i==x[j])||(a[j]!=0&&i>=x[j]&&(i-x[j])%a[j]==0))res = (res+rec(i+1,j+1))%MOD;
	return dp[i][j]=res;
}
int main()
{
	scanf("%d %d",&N,&L);
	rep(i,N)scanf("%d",&x[i]);
	rep(i,N)scanf("%d",&a[i]);
	memset(dp,-1,sizeof(dp));
	printf("%d\n",rec(0,0));
	return 0;
}

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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
using pii = pair<int, int>;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)
#define be(c) begin(c), end(c)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

signed dfs_biparate_graph(vector<vector<int>> const & g) {
    const int n = g.size();
    vector<char> used(n, -1);
    function<bool (int)> dfs = [&](int i) {
        for (int j : g[i]) {
            if (used[j] != -1) {
                if (used[j] == used[i]) {
                    return false;
                }
            } else {
                used[j] = used[i] ^ 1;
                if (!dfs(j)) return false;
            }
        }
        return true;
    };
    used[0] = 0;
    if (!dfs(0)) return -1;
    return count(be(used), 0);
}

signed main(){
    int n, m;
    scanf("%d%d", &n, &m);
    vector<vector<int>> g(n);
    rep(i, m) {
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int k = dfs_biparate_graph(g);
    ll result = k == -1 ?
        n *(ll) (n - 1) / 2 - m : // 完全グラフ
        k *(ll) (n - k) - m; //2部グラフ
    // output
    cout << result << nl;
    return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define LL long long
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int n;
int main(){
	cin>>n;
	if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9)puts("hon");
	else if(n%10==3)puts("bon");
	else puts("pon");
	return 0;
}


Measured memory_bytes: 3592
# -*- coding: utf-8 -*-
import numpy
n, d = map(int, input().split())

li = []
for i in range(n):
  x, y = map(int,input().split())
  li.append([x, y])

answer = 0
for i in li:
  if numpy.sqrt(i[0]**2 + i[1]**2) <= d:
    answer += 1
print(answer)

Measured memory_bytes: 56756
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);

template<class T> inline T sqr(T x) {return x*x;}

int main() {
	int h,w;
	cin >> h >> w;
	string s;
	REP(i,0,h) REP(j,0,w) {
		cin >> s;
		if (s == "snuke") {
			cout << (char)('A'+j) << i+1 << endl;
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 100
#define NIL -1

struct Node {int parent, left, right;};
Node t[MAX];

// 中左右
void preOrder(int id) {
    if (id == NIL) return;
    cout << " " << id;
    preOrder(t[id].left);
    preOrder(t[id].right);
}

// 左中右
void inOrder(int id) {
    if (id == NIL) return;
    inOrder(t[id].left);
    cout << " " << id;
    inOrder(t[id].right);
}

// 左右中
void postOrder(int id) {
    if (id == NIL) return;
    postOrder(t[id].left);
    postOrder(t[id].right);
    cout << " " << id;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        t[i].parent = NIL;
    }
    for (int i = 0; i < n; i++) {
        int id, left , right;
        cin >> id >> left >> right;
        t[id].left = left;
        t[id].right = right;
        t[left].parent = t[right].parent = id;
    }

    int root;
    for (int i = 0; i < n; i++) {
        if (t[i].parent == NIL) root = i;
    }

    cout << "Preorder" << endl;
    preOrder(root);
    cout << endl;
    cout << "Inorder" << endl;
    inOrder(root);
    cout << endl;
    cout << "Postorder" << endl;
    postOrder(root);
    cout << endl;

    return 0;
}


Measured memory_bytes: 3116
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
const int inf=0x3f3f3f3f;
const int Maxn=1e6+5;
int vis[Maxn],dist[Maxn];
int n,m,ptr[Maxn],q[Maxn];
vector <pair <int,int> > g[Maxn];
vector <int> newg[Maxn],comp[Maxn];
int main()
{
	cin>>n>>m;
	for (int i=0;i<m;++i)
	{
		int a,b,c;
		cin>>a>>b>>c;
		--a,--b;
		g[a].push_back(make_pair(c,b));
		g[b].push_back(make_pair(c,a));
		comp[c].push_back(a);
		comp[c].push_back(b);
	}
	for (int i=0;i<n;++i) sort(g[i].begin(),g[i].end());
	memset(vis,-1,sizeof(vis));
	int nn=n;
	for (int c=0;c<Maxn;c++)
	{
		if (comp[c].empty()) continue;
		for (int v:comp[c])
		{
			if (vis[v]==c) continue;
			int head=0,tail=1;
			q[0]=v;
			while (head<tail)
			{
				while (ptr[q[head]]<(int)g[q[head]].size())
				{
					int C=g[q[head]][ptr[q[head]]].first;
					if (C!=c) break;
					int u=g[q[head]][ptr[q[head]]].second;
					if (vis[u]!=c)
					{
						vis[u]=c;
						q[tail++]=u;
					}
					ptr[q[head]]++;
				}
				head++;
			}
			for (int i=0;i<tail;++i)
			{
				newg[q[i]].push_back(nn);
				newg[nn].push_back(q[i]);
			}
			nn++;
		}
	}
	memset(dist,63,sizeof(dist));
	queue <int> q;
	q.push(0);
	dist[0]=0;
	while (!q.empty())
	{
		int cur=q.front();q.pop();
		for (int u:newg[cur])
		{
			if (dist[u]==inf)
			{
				dist[u]=dist[cur]+1;
				q.push(u);
			}
		}
	}
	if (dist[n-1]==inf) cout<<"-1\n";
	else cout<<dist[n-1]/2<<endl;
	return 0;
}

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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int N,A,B;

    cin>>N>>A>>B;

    if(N*A>B){
        cout<<B<<endl;
    }
    else{
        cout<<N*A<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
double x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
cout<< setprecision(10) << sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) << endl;
}

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

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  int h_max,w_max;
  scanf("%d%d",&h_max,&w_max);

  char a[101][101];
  for(int i = 0; i < h_max; ++i){
    scanf("%s",a[i]);
  }

  int ans_x[101] = {0};
  int ans_y[101] = {0};
  for(int h = 0; h < h_max; ++h){
    for(int w = 0; w < w_max; ++w){
      if(a[h][w] == '#'){
        ans_x[w] = 1;
        ans_y[h] = 1;
      }
    }
  }

  for(int i = 0; i < h_max; ++i){
    int flag = 0;
    for(int j = 0; j < w_max; ++j){
      if(ans_x[j] == 1 && ans_y[i] == 1){
        printf("%c",a[i][j]);
        flag = 1;
      }
    }
    if(flag == 1) printf("\n");
  }

  return 0;
}


Measured memory_bytes: 1656
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N;
int a[100005];
int b[100005];
int imos[100005];
bool ok(int m) { return imos[m] >= m; }
int main() {
    cin >> N;
    rep(i, N) cin >> a[i] >> b[i];
    rep(i, N) a[i]--, b[i]--;
    rep(i, N) {
        ++imos[a[i]];
        --imos[b[i] + 1];
    }
    rep(i, 100005) if (i) imos[i] += imos[i - 1];
    // rep(i, N + 1) cout << i << ", " << imos[i] << endl;
    int ans = 0;
    rep(i, N + 1) if (ok(i)) ans = i;
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(false)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;

ll gcd(ll a, ll b) { return __gcd(a, b); }
ll lcm(ll a, ll b) { return (a == 0 || b == 0) ? 0 : (a / __gcd(a, b) * b); }

int main(int argc, const char* argv[]) {
	ll k, x;
	cin >> k >> x;

	ll l = x - k + 1;
	ll r = x + k - 1;

	repd(i, l, r) {
		cout << i << " ";
	}

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 256
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef pair<ll , pair<ll, ll> > pi;
int pow(int x,int y){
    int res=1;
    while(y){
        if(y&1) res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}   
struct Compare {
    constexpr bool operator()(pi const & a,
                              pi const & b) const noexcept
    { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }
 
};
void prefix_function( string s,ll arr[] )
{
     long long border=0; arr[0]=0;
    for(long long i=1;i<s.size();i++)
    {
      while(border>0 && s[i]!=s[border])
        border=arr[border-1];
     
     if(s[i]==s[border])
         border++;
      else
       border=0;
      
      arr[i]=border;
    }
}//send mod-2 for a^-1 if mod is a prime number

ll mod=998244353;
ll add( ll a , ll b)
{
    return (((a%mod)+(b%mod))%mod);
}
ll mul(ll a,ll b)
{
  return (((a%mod)*(b%mod))%mod);
}
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}
ll subs(ll a,ll b)
{
    return (((a%mod)-(b%mod)+mod)%mod);
}
ll dv(ll a,ll b)
{
    ll inv=binpow(b,mod-2);
    return mul(a,inv);
}

ll dsu_arr[100000];
ll dsu_sz[100000];
void dsu(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        dsu_arr[i]=i;
        dsu_sz[i]=1;
    }
}
ll find(ll x)
{
     ll root=x;
    while (root!=dsu_arr[root])
    {
        root=dsu_arr[root];
    }
    while(x!=dsu_arr[x])
    {
        dsu_arr[x]=root;
        x=dsu_arr[x];
    }
    return root;
}
ll merge(ll x,ll y)
{
    ll root1=find(x);
    ll root2=find(y);
    
    if(root1==root2)
    return 0ll;
 
    if(dsu_sz[x]>dsu_sz[y]){
    dsu_arr[root2]=root1;
    dsu_sz[root1]+=dsu_sz[root2];
    }
    else
    {
         dsu_sz[root2]+=dsu_sz[root1];
        dsu_arr[root1]=root2;
    }
    return 1ll;
}
/*
vector<ll>adj[100005];
bool vis[100005];
ll dist[100005];
void bfs(ll c)
{
  vis[c]=true;
  dist[c]=0;
  q.push(c);
while(!q.empty())
{
    ll x=q.front();
    q.pop();
   
    for(ll i=0;i<adj[x].size();i++)
    {
        ll y=adj[x][i];
        if(!vis[y])
        {
            vis[y]=true;
            dist[y]=dist[x]+1;
            
            q.push(y);
        }
    }
 
}
}
*/

int main()
{
    Fast
ll a,b,c,d;
cin>>a>>b>>c>>d;
ll x=a*d;
ll y=a*c;
ll m=b*c;
ll n=b*d;
cout<<max(x,max(y,max(n,m)))<<endl;


}



   
      
    
        



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

int main(){
    int H,W;
    cin >> H >> W;
    vector<string> vec(H);
    for(int i=0;i<H;i++){ cin >> vec.at(i); }
    
    for(int i=0;i<W+2;i++){ cout << "#"; }//1行目
    cout << endl;
    
    for(int i=0;i<H;i++){
        cout << "#" << vec.at(i) << "#" << endl;
    }
    
    for(int i=0;i<W+2;i++){ cout << "#"; }//最終行
    cout << endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
//#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod=1e9+7;
const int MAXN=1e6+7;
///////////////////////////////////////////////////////////////////////////////////////
map<int,int> q;
multiset<int> p;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for (int i=0;i<m;i++){
        q[i]=i;
        p.insert(0);
    }
    for (int i=1;i<=n;i++){
        //cout << "i=" << i << endl;
        int x,y;
        scanf("%d%d",&x,&y);
        auto f=q.lower_bound(--x);
        int ff=-1;
        while(f!=q.end()&&f->first<=y){
            ff=max(ff,f->second);
            p.erase(p.find(f->first-f->second));
            q.erase(f++);
        }
        if(ff!=-1&&y<m){
            p.insert(y-ff);
            q[y]=ff;
        }
        if(p.size()==0) printf("-1\n");
        else printf("%d\n",*p.begin()+i);
    }
    return 0 ;
}



Measured memory_bytes: 22520
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	var wh = input[0].split(" ");
  var h = parseInt(wh[0], 10);
  var w = parseInt(wh[1], 10);

  for (var i = 0; i < h + 2; i++) {
    var column = ['#'];

    for (var j = 0; j < w; j++) {
      if (i === 0 || i === h + 1) {
        column.push('#');
      } else {
        column.push(input[i][j]);
      }
    }

    column.push('#');
    console.log(column.join(''));
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int MAX = 1e7 + 4;
 
int isprime[MAX];
   //to store smallest prime factor of number
    void sieve()
    {
       for(int i = 1;i < MAX;++i)
           isprime[i] = i;
 
        for(int i = 2;i < MAX;++i)
        {
            if(i == isprime[i])
            {
                for(int j = 2 * i;j <= MAX;j += i)
                {
                    if(isprime[j] == j)
                    isprime[j] = i;
                }
            }
        }
 
    }
 
map<int,int>mp;
void store(int x)
{
     while(x > 1)
        {
           int val = isprime[x];
 
           int cnt = 0;
 
             while(isprime[x] == val)
            {
 
                x /= isprime[x];
                cnt++;
            }
 
                mp[val] = cnt;
       }
}
 
 
int main()
{
    int t = 1;
   sieve();
//    cin >> t;
ll SUM = 0;
    while(t--)
    {
        ll n;
        cin >> n;
        for(int i = 1;i <= n;++i)
        {
            vector<ll>X;
            mp.clear();
            
               store(i);
            ll sum = 1;
                for(auto it : mp)
                {
                   sum *= (it.second + 1);
                }
            SUM += (sum * i);
            
        }
        cout << SUM;
    }
}

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

long long n,k;
char s[105]; 
long long p[105],cnt=1;
long long ans=0;
int main()
{
	cin>>s;	
	cin>>k;
	n=strlen(s);
	p[1]=1;
	for(int i=1;i<n;i++)
	{
		if(s[i]==s[i-1])
			p[cnt]++;
		else
			p[++cnt]++;
	}
	if(s[0]!=s[n-1])
	{
		for(int i=1;i<=cnt;i++)
			ans+=k*(p[i]/2);
		cout<<ans<<endl;
	}
	else
	{
		if(cnt==1)
			cout<<k*n/2<<endl; 
		else
		{
			for(int i=2;i<cnt;i++)
				ans+=k*(p[i]/2);
			ans+=p[1]/2+p[cnt]/2;
			ans+=(p[1]+p[cnt])/2*(k-1);
			cout<<ans<<endl; 
		}
	}
	return 0;
}


Measured memory_bytes: 256