akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 4e5 + 10;
int n, m;
vector<int> g[MAX_N];
map<int, vector<int> > g0[MAX_N];
int dist[MAX_N];
int dest[MAX_N], tpe[MAX_N];
bool used[MAX_N];
int ans = mod;

void bfs() {
    deque<int> q;
    q.push_front(0);
    fill_n(dist, MAX_N, mod);
    dist[0] = 0;
    while(!q.empty()) {
        auto curr = q.front(); q.pop_front();
        int x = dest[curr], t = tpe[curr];
        if(x == n) {
            chkmin(ans, dist[curr]);
        }
        for(auto it : g0[x][t]) {
            if(dist[curr] < dist[it]) {
                q.push_front(it);
                dist[it] = dist[curr];
            }
        }
        g0[x][t].resize(0);
        if(used[x]) {continue;}
        used[x] = true;
        for(auto it : g[x]) {
            if(dist[curr] + 1 < dist[it]) {
                q.push_back(it);
                dist[it] = dist[curr] + 1;
            }
        }
    }
}

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> m;
    dest[0] = 1;
    tpe[0] = -1;
    for(int i = 1; i <= m; i ++) {
        int a, b, c;
        cin >> a >> b >> c;
        g[a].push_back(2 * i);
        g[b].push_back(2 * i + 1);
        g0[a][c].push_back(2 * i);
        g0[b][c].push_back(2 * i + 1);
        dest[2 * i] = b;
        dest[2 * i + 1] = a;
        tpe[2 * i] = c;
        tpe[2 * i + 1] = c;
    }
    ans = mod;
    bfs();
    if(ans == mod) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

const ll INF = 1LL << 60;
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; }

/*
#define MAX 10000
#define NIL -1
struct Node { int p, l, r; };
struct Node T[MAX];
*/

int main() {

    ll dp[100007][3];
    ll activity[100007][3]; //ここ5乗じゃないとダメやんけ！！
    int n;
    cin >> n;
    rep(i,n) {
        cin >> activity[i][0] >> activity[i][1] >> activity[i][2];
    }

    /* 0で初期化するのであればこの処理はいらない
    rep(i,100007){
        rep(j,3){
            dp[i][j] = 0;
        }
    }
    */

    for (int i = 0; i < n; i++){
        for (int j = 0; j < 3; j++){ //now
            for (int k = 0; k < 3; k++){ //nexta
                if(j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + activity[i][k]); //dp[i+1][k] は、前のkループでの結果が入ってる。でそれと今回とを比較
                // 配るDP
            }
        }
    }

    ll ans = 0;
    rep(i, 3) chmax(ans, dp[n][i]);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (b <= a) cout << "delicious" << endl;
  else if (b <= a + x) cout << "safe" << endl;
  else cout << "dangerous" << endl;
}



Measured memory_bytes: 256
#標準入力
X = int(input())

max_beki = 1
for i in range(1,X):
  for j in range(2,X):
    beki = i ** j
    
    if beki > X:
      break
      
    elif beki > max_beki:
      max_beki = beki
 
print(max_beki)


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

int main() {
  
  int64_t N,K;
  cin >> N >> K;
  
  int64_t A = N -((N / K) * K);
  
  while(true){
    A -= K;
    if(A <= 0){
      break;
    }
  }
  int64_t S = A + K;
  int64_t T = A * (-1);
  
  if(S < T){
    cout << S << endl;
  }
  
  else{
    cout << T << endl;
  }
  
    
    
}
    


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

int main()
{
  int N, Y; cin >> N >> Y;

  int x, y, z;
  x = y = z = -1;

  bool brk = false;
  for(int i = 0; i <= N && 10000*i <= Y && !brk; i++) {
    for(int j = 0; i+j <= N && 10000*i+5000*j <= Y && !brk; j++) {
      int k = N - i - j;
      int sum = 10000*i + 5000*j + 1000*k;
      if(sum == Y) {
        x = i;
        y = j;
        z = k;
        brk = true;
      }
    }
  }

  cout << x << " " << y << " " << z << endl;
  return 0;
}


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

using namespace std;
int main(void){
    // Your code here!
    int s,t;
    cin>>s>>t;
    if(s==t){
        cout<<"Draw"<<endl;
    }
    else if(s>=2&&s<t||t==1){
        cout<<"Bob"<<endl;
    }
    else if(t>=2&&t<s||s==1){
        cout<<"Alice"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int         long long int
#define pb          push_back
#define endl        "\n"
#define hell        1000000007
#define INF         1000000000000000000

using namespace std;

  void solve()
  {
  int n;
  cin>>n;
  vector<pair<int,int>>v;
  for(int i=0;i<n;i++)
  {
    int a,b;
    cin>>a>>b;
    v.push_back({a,b});
  }    
  for(int i=0;i<n-2;i++)
  {int flag=0;
    for(int j=i;j<i+3;j++)
    {
      if(v[j].first!=v[j].second)
        flag=1;
    }
    if(flag==0)
    {
      cout<<"Yes";return ;
    }
  }
  cout<<"No";

  }
  
  

 
  signed main()
  {
    ios::sync_with_stdio(false);
      cin.tie(0);
      cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif
   
        solve();

return 0;
  }

Measured memory_bytes: 3656
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll n, v[4];
	for (int i = 0; i < 4; ++i)
		cin >> v[i];
	cin >> n;
	ll res = 1e18;
	for (int solve = 20; solve <= 24; ++solve) {
		ll take = max(n - solve, 0ll);
		ll cost = 1e18;
		double z[4] = { 0.25,0.5,1,2 };
		for (int i = 0; i < 4; ++i) {
			ll need = (ll)(take / z[i] + 1e-9);
			if (fabs(need*z[i] - take) > 1e-9)
				continue;
			cost = min(cost, need*v[i]);
		}
		take = n - take;
		for (int a = 0; a <= solve / 0.25 + 1; ++a)
			for (int b = 0; b <= solve / 0.5 + 1; ++b)
				for (int c = 0; c <= solve / 1 + 1; ++c)
					for (int d = 0; d <= solve / 2 + 1; ++d) {
						double have = a*0.25 + b*0.5 + c + d * 2;
						if (fabs(have - take) < 1e-9) {
							res = min(res, cost + a*v[0] + b*v[1] + c*v[2] + d*v[3]);
						}
					}
	}
	cout << res << endl;
	return 0;
}

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

from collections import deque



def submit():
    n = int(input())
    edge = {i: [] for i in range(1, n + 1)}
    for _ in range(n - 1):
        a, b = map(int, input().split())
        edge[a].append(b)
        edge[b].append(a)

    # 1とNの最短路を求める
    def dfs(q, path, hist):
        p = q.pop()
        if p == n:
            return path

        for e in edge[p]:
            if not hist[e]:
                q.append(e)
                path.append(e)
                hist[e] = True
                ret = dfs(q, path, hist)
                if ret:
                    return ret
                path.pop(-1)
        return None


    q = deque()
    q.append(1)
    hist = {i: False for i in range(n + 1)}
    hist[1] = True
    direct_path = dfs(q, [1], hist)
    d = len(direct_path) 
    if d % 2:
        fennec = direct_path[:d // 2 + 1]
        snuke = direct_path[d // 2 + 1:]
    else:
        fennec = direct_path[:d // 2]
        snuke = direct_path[d // 2:]

    edge[fennec[-1]].remove(snuke[0])
    
    # fennecが取れる数を数える
    color = 0
    picked = [False for _ in range(n)]
    q = deque()
    q.append(1)
    picked[0] = True
    while len(q):
        p = q.pop()
        color += 1
        for e in edge[p]:
            if not picked[e - 1]:
                q.append(e)
                picked[e - 1] = True
    
    if color > n - color:
        print("Fennec")
    else:
        print("Snuke")


submit()

Measured memory_bytes: 149988
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> a[1010];
 
int main(){
    scanf("%d",&n);
    int t = sqrt(2*n);
    if(t*(t+1)==2*n){
        printf("Yes\n%d\n",t+1);
        int cnt = 1;
        for(int i=1;i<=t;i++){
            for(int j=1;j<=i;j++){
                a[i].push_back(cnt);
                if(j==i)a[t+1].push_back(cnt);
                else
                a[j].push_back(cnt);
                cnt++;
            }
        }
        for(int i=1;i<=t+1;i++){
            printf("%d",t);
            for(int j=0;j<a[i].size();j++){
                printf(" %d",a[i][j]);
            }
            printf("\n");
        }
    }
    else printf("No\n");
}

Measured memory_bytes: 2304
#include <iostream>

using lint = long long;

int main() {
    lint N;
    std::cin >> N;

    lint ans = 0;
    for (int i = 0; i < 5; ++i) {
        lint A;
        std::cin >> A;
        lint G = (N + A - 1) / A;
        ans = std::max(ans, G + 4);
    }

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

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

int main(){
    int n, number;
    string suit;
    int s[13], h[13], c[13], d[13];
    cin >> n;
    for(int i=0; i<13; i++){
        s[i] = 0;
        h[i] = 0;
        c[i] = 0;
        d[i] = 0;
    };
    for (int i=0; i<n; i++){
        cin >> suit >> number;
        number -= 1;
        if(suit == "S"){
            s[number] = 1;
        }else if(suit == "H"){
            h[number] = 1;
        }else if(suit == "C"){
            c[number] = 1;
        }else if(suit == "D"){
            d[number] = 1;
        };
    };
    for (int i=0; i<13; i++){
        if(s[i]==0){
            cout << "S " << i+1 << endl;
        };
    };
    for (int i=0; i<13; i++){
        if(h[i]==0){
            cout << "H " << i+1 << endl;
        };
    };
    for (int i=0; i<13; i++){
        if(c[i]==0){
            cout << "C " << i+1 << endl;
        };
    };
    for (int i=0; i<13; i++){
        if(d[i]==0){
            cout << "D " << i+1 << endl;
        };
    };
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n; string s; cin >> n>> s;
  vi L(n);
  vi R(n);
  L[0] = 0;
  R[n-1]=0;
  int b =0, w=0;
  for (int i=1; i<n; i++) {
   L[i] = L[i-1];
   if (s[i-1] == '#') {
     L[i]++;
   }
  }
  for (int i=n-2; i>=0;i--) {
    R[i] = R[i+1];
    if (s[i+1] == '.') R[i]++;
  }
  int ans = INF;
  rep (i, n-1) {
    if (s[i] != s[i+1]) {
      ans = min(ans, R[i+1]+L[i+1]);
    }
  }
  ans=min(ans,R[0]+L[0]);
  ans=min(ans,R[n-1]+L[n-1]);
  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 2180
n = int(input())
s = [int(input()) for _ in range(n)]

sumNum = sum(s)
if sumNum % 10 != 0:
  print(sumNum)
  exit()

t = 0
for i in s:
  if (sumNum - i)%10 != 0:
    t = max(t, sumNum-i)
print(t)

Measured memory_bytes: 9172
import java.util.Scanner;
public class Main {
	
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		long ans = 1;
		for (int i = 0; i < N; i++) {
			long t = sc.nextLong();
			ans = lcm(ans, t);
		}
		
		System.out.println(ans);
	}
	
	//最小公倍数
	public static long lcm(long m, long n) {
		return m / gcd(m, n) * n;
	}
	
	public static long gcd(long m, long n) {
		if (n == 0) return m;
		return gcd(n, m % n);
	}
}

Measured memory_bytes: 23892
X,Y = map(int,input().split())
if (X + Y) % 3 != 0:
    print(0)
    exit()
n = (-X+2*Y)//3
m = (2*X-Y)//3
if n < 0 or m < 0:
    print(0)
    exit()

mod = 10**9+7
mod_inv = [0, 1] + [0] * (max(n,m)+3)
for i in range(2, max(n,m)+5):
    mod_inv[i] = - mod_inv[mod % i] * (mod // i) % mod
def comod(n, r, mod):
    ans = 1
    for i in range(r):
        ans *= (n-i) % mod
        ans *= mod_inv[i+1]
        ans %= mod
    return ans
ans = comod(n+m,n,mod)
print(ans)

Measured memory_bytes: 45552
#include<bits/stdc++.h>
using namespace std;
#define eps 0.00001
#define pi acos(-1.0)
int main()
{
    double a,b,c,d,e,f,g,h,x;
    int i,j,k,l;
    scanf("%lf %lf %lf",&a,&b,&x);
    h=x/(a*a);
    g=b-h;
    if((abs((2.0*g)-b)<=eps) || ((2.0*g)<=b)){
        g=(2.0)*g;
        h=g/a;
        f=atan(h);
        f*=180;
        f/=pi;
        printf("%.10f",f);
    }
    else{
        f=a*b*b;
        f/=2;
        f/=x;
        f=atan(f);
        f*=180;
        f/=pi;
        printf("%.10f",f);
    }

}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(),K=sc.nextInt();

		System.out.println((int)(K*Math.pow((K-1), N-1)));


	}
	public static int sample(int n) {
		return n;
	}

}


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

int main() {
  
  int N, ans=0;
  cin >> N;
  vector<int> d(N);
  for(int i=0; i<N; i++) cin >> d.at(i);
  
  for(int i=0; i<N; i++) {
    for(int j=i+1; j<N; j++) {
      ans += d.at(i)*d.at(j);
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
 


int main() {
	priority_queue<int>que;
	while (1) {
		string st; cin >> st;
		if (st == "end")break;
		else if (st == "insert") {
			int n; cin >> n;
			que.push(n);
		}
		else if (st == "extract") {
			cout << que.top() << endl;
			que.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 7144
class Dice:
    def __init__(self, pip):
        self.pip = pip
    
    def move(self, dir):
        if str(dir) == 'E':
            self.pip[0], self.pip[2], self.pip[3], self.pip[5] = \
                self.pip[3], self.pip[0], self.pip[5], self.pip[2]
        elif str(dir) == 'W':
            self.pip[0], self.pip[2], self.pip[3], self.pip[5] = \
                self.pip[2], self.pip[5], self.pip[0], self.pip[3]
        elif str(dir) == 'N':
            self.pip[0], self.pip[1], self.pip[4], self.pip[5] = \
                self.pip[1], self.pip[5], self.pip[0], self.pip[4]
        elif str(dir) == 'S':
            self.pip[0], self.pip[1], self.pip[4], self.pip[5] = \
                self.pip[4], self.pip[0], self.pip[5], self.pip[1]


d1 = Dice(list(map(int, input().split())))
d2 = Dice(list(map(int, input().split())))

check = "No"
for x in "EEENEEENEEESEEESEEENEEEN":
    if d1.pip == d2.pip:
        check = "Yes"
        break
    d2.move(x)
print(check)


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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

ll gcd( ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main (void) {
    ll A,B,C,D,ans;
    ll C1,C2,C3;
    scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
    
    C1 = (ll)  B / C -  (ll) ( A + ( C - 1 ) ) / C + 1;
    C2 = (ll)  B / D -  (ll) ( A + ( D - 1 ) ) / D + 1;
    
    
    ll E = C * D;

    if( C > D ){
        ll tmp = D;
        D = C;
        C = tmp;
    }


    ans = B - A + 1;

    E = (ll) E / gcd( C, D );


    C3 = (ll) B / E  -  (ll)  (A + (E - 1)) / E + 1;

    ans -= C1 + C2 - C3;

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

k=ii()
ans=0
arr=deque([1,2,3,4,5,6,7,8,9])
while k>ans:
    n=int(arr.popleft())
    if n%10==9:
        arr.append(n*10 + n%10 -1)
        arr.append(n*10 + n%10 )
    elif n%10==0:
        arr.append(n*10 + n%10)
        arr.append(n*10 + n%10+1)
    else:
        arr.append(n*10 + n%10 -1)
        arr.append(n*10 + n%10)
        arr.append(n*10 + n%10 +1)
    ans+=1
print(n)





Measured memory_bytes: 66156
#include <iostream>

using namespace std;

long A, B;

long gcd(long a, long b){
    if(a < b) swap(a, b);
    while(b != 0){
        long tmp = b;
        b = a%b;
        a = tmp;
    }
    return a;
}

int main(){
    cin >> A >> B;
    long g = gcd(A, B);
    long G = g;
    int cnt = 0;
    for(long i = 2; i*i <= G; i++){
        if(g%i == 0) cnt++;
        while(g%i == 0){
            g /= i;
        }
    }
    if(g != 1) cnt++;
    cout << cnt+1 << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.min

fun main(args: Array<String>) {

    // IO Templates
    val br = BufferedReader(InputStreamReader(System.`in`))
    val out = PrintWriter(System.out)

    val (n, q) = br.readLine()!!.split(' ').map { it.toInt() }

    val yoko = Field(n)
    val tate = Field(n)

    var bl: Long = (n - 2).toLong() * (n - 2).toLong()


    for (i in 1..q) {
        val (flg, x) = br.readLine()!!.split(' ').map { it.toInt() - 1 }

        val (a, b) = if (flg == 0) (tate to yoko) else (yoko to tate)

        if (x < a.minBlIdx) {
            bl -= a.minBl
            for (i in x until a.minBlIdx) {
                a.arr[i] = a.minBl
            }
            a.minBlIdx = x
            b.minBl = x - 1
        } else {
            bl -= a.arr[x]
        }
    }

    out.println(bl)

    out.flush()
}

class Field(val n: Int) {
    val arr = IntArray(n) { n - 2 }
    var minBl = n - 2
    var minBlIdx = n
}

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

int main () {
  int n, m, c;
  cin >> n >> m >> c;
  
  vector<int> b(m);
  for (int i = 0; i < m; i++)
    cin >> b[i];
  
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++)
      cin >> a[i][j];
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int sum = c;
    for (int j = 0; j < m; j++)
      sum += a[i][j] * b[j];

    if (sum > 0)
      ans++;
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
int A[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	int res = inf;
	for(int i = -100; i <= 100; i++) {
		int tmp = 0;
		rep(j, 0, N) {
			tmp += (A[j] - i) * (A[j] - i);
		}
		MIN(res, tmp);
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
using System;
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        switch (n % 10) 
        {
            case 2:
            case 4:
            case 5:
            case 7:
            case 9:
                Console.WriteLine("hon");
                break;
            case 0:
            case 1:
            case 6:
            case 8:
                Console.WriteLine("pon");
                break;
            case 3:
                Console.WriteLine("bon");
                break;
        }

    }
}

Measured memory_bytes: 27516
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <complex>
#include <queue>
#include <cstdio>
using namespace std;

const double EPS = 1e-9;
const double PI = acos(-1);

typedef complex<double> P;
typedef vector<P> G;

struct L :public vector<P> {
	L(const P &a,const P &b){
		push_back(a);
		push_back(b);
	}
};

#define next(P,i) (P[(i+1)%P.size()])
#define curr(P,i) (P[(i+0)%P.size()])

double cross(const P &a,const P &b){
	return imag(conj(a)*b);
}
double dot(const P &a,const P &b){
	return real(conj(a)*b);
}

int ccw(P a,P b,P c){
	b -= a;
	c -= a;
	if( cross(b,c) > 0 ) return +1;
	if( cross(b,c) < 0 ) return -1;
	if( dot(b,c) < 0 ) return +2;
	if( norm(b) < norm(c) ) return -2;
	return 0;
}

P crosspoint(const L &l,const L &m){
	double A = cross(l[1]-l[0],m[1]-m[0]);
	double B = cross(l[1]-l[0],l[1]-m[0]);
	if( abs(A) < EPS && abs(B) < EPS) return m[0];
	return m[0]+B/A*(m[1]-m[0]);
}


G convex_cut(const G &poly,const L &l){
	G Q;
	for(int i = 0 ; i < poly.size() ; i++){
		P A = curr(poly,i) , B = next(poly,i);
		if( ccw(l[0],l[1],A)!=-1)Q.push_back(A);
		if( ccw(l[0],l[1],A)*ccw(l[0],l[1],B)<0)Q.push_back(crosspoint(L(A,B),l));
	}
	return Q;
		 
}

L bisector(P a,P b){
	P A = (a+b) * P(0.5,0);
	return L(A,A+(b-a)*P(0,PI/2));
}
G voronoi(G g,vector<P> v,int s){
	for(int i = 0 ; i < v.size() ; i++){
		if( i != s ){
			g = convex_cut(g,bisector(v[s],v[i]));
		}
	}
	return g;
}

int main(){
	int n;
	while(cin >> n && n){
		G area,p;
		area.push_back(P(0,0));
		area.push_back(P(0,4));
		area.push_back(P(4,4));
		area.push_back(P(4,0));
		
		for(int i = 0 ; i < n ; i++){
			double x,y;
			cin >> x >> y;
			p.push_back(P(x,y));
		}
		vector<L> l;
		vector<P> vertex;
		
		for(int i = 0 ; i < n ; i++){
			G v = voronoi(area,p,i);
			for(int j = 0 ; j < v.size() ; j++){
				vertex.push_back(v[j]);
				//cout << i << ": " << v[j] << endl;
				l.push_back(L(curr(v,j),next(v,j)));
				l.push_back(L(next(v,j),curr(v,j)));
			}
		}
		int done[16000]={};
		priority_queue< pair<double,int> , vector< pair<double,int> > , greater < pair<double,int> > > Q;
		for(int i = 0 ; i < n ; i++){
			if( fabs(vertex[i].real()) < EPS ){
				Q.push(make_pair(0,i));
			}
		}
		
		while(Q.size()){
			pair<double,int> q = Q.top(); Q.pop();
			if( done[q.second]++ )continue;
			if( fabs(vertex[q.second].real() - 4.0 ) < EPS ){
				printf("%.8lf%c",q.first,10);
				goto exit;
			}
			for(int i = 0 ; i < vertex.size() ; i++){
				L ll(vertex[q.second],vertex[i]);
				int f = false;
				for(int j = 0 ; j < l.size() ; j++){
					if( abs(l[j][0] - ll[0]) < EPS && abs(l[j][1]-ll[1]) <EPS ){
						f++;
					}
				}
				if(f >= 2) Q.push(make_pair(q.first+abs(ll[0]-ll[1]),i));
			}
		}
		cout << "impossible" << endl;
		
		exit:;
		
	}
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
//#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0,x=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000],c;

	int ara[n_size],ara2[n_size];

	cin>>n;
    cin>>s;

	stack<char>stk;


	f(i,0,n-1){
        if(s[i]=='('){
            stk.push('(');
        }
        if(s[i]==')'){
            x+=stk.empty();
            if(stk.empty()==false) stk.pop();
        }
	}
    //cout<<stk.size()<<endl;


	f(i,1,x) cout<<"(";
	cout<<s;
    f(i,1,stk.size()) cout<<")";

    cout<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
class Rands {
  public:
    int a, b, c, x, countNext;
    Rands(int _a, int _b, int _c, int _x):
      a(_a),
      b(_b),
      c(_c),
      x(_x),
      countNext(0) {
    }
    int getNext() {
      ++countNext;
      int oldX = x;
      x = (a * x + b) % c;
      return oldX;
    }
    int getLast() {
      return x;
    }
    int getCountOfNext() {
      return countNext - 1;
    }
};

int main() {
  int n, a, b, c, x;
  while(cin >> n >> a >> b >> c >> x, n || a || b || c || x) {
    Rands rands(a, b, c, x);
    for(int i = 0; i < n; ++i) {
      int rand;
      cin >> rand;
      while(rand != rands.getNext() && rands.getCountOfNext() <= 10000);
    }
    cout << ((rands.getCountOfNext() > 10000) ? -1 : rands.getCountOfNext()) << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
    cin>>a>>b>>c ;
    cout<<a<<" "<<b<<" "<<3*c-a-b<<" "<<endl;
    cout<<4*c-2*a-b<<" "<<c<<" "<<2*a+b-2*c<<" "<<endl;
    cout<<a+b-c<<" "<<2*c-b<<" "<<2*c-a<<" "<<endl;
    return 0 ;
}

Measured memory_bytes: 256
#include <cstdio>

#define MAX_N 100000

int N;
long long A[MAX_N];

int main() {
  long long ans = 1;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", A+i);
  }

  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      printf("0\n");
      return 0;
    }
  }

  for (int i = 0; i < N; i++) {
    if (1000000000000000000L / ans < A[i] || 1000000000000000000L / A[i] < ans || ans < 0L) {
      printf("-1\n");
      return 0;
    }
    ans *= A[i];
  }

  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 2512
import itertools
import bisect

n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
aa=list(itertools.accumulate(a))
bb=list(itertools.accumulate(b))
r=0
for i,ax in enumerate(aa):
    bis=bisect.bisect_right(bb,k-ax)
    if bis==0 and ax>k:continue
    r=max(r,i+bis)
print(r)

Measured memory_bytes: 49212
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<dyn Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input)?;
    let str = input.trim().to_owned();
    input.clear();

    if str.eq(&str.to_ascii_uppercase()) {
        println!("A");
    } else {
        println!("a");
    }

    Ok(())
}


Measured memory_bytes: 2096
#include <stdio.h>
#include <stdlib.h>

#define Mod 1000000007

typedef struct List {
	struct List *next;
	int v;
} list;

int main()
{
	int i, N, P[5001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(P[i]));
	
	list **adj = (list**)malloc(sizeof(list*) * (N + 1)), *d = (list*)malloc(sizeof(list) * N * 2);
	for (i = 0; i < N; i++) {
		if (P[i+1] == -1) continue;
		d[i*2].v = P[i+1];
		d[i*2+1].v = i + 1;
		d[i*2].next = adj[i+1];
		d[i*2+1].next = adj[P[i+1]];
		adj[i+1] = &(d[i*2]);
		adj[P[i+1]] = &(d[i*2+1]);
	}
	
	list *p;
	int j, k, K, comp[5001] = {}, q[5001], head, tail, size[5001] = {};
	for (i = 1, k = 1; i <= N; i++) {
		if (P[i] != -1) continue;
		comp[i] = k;
		q[0] = i;
		for (head = 0, tail = 1; head < tail; head++) {
			for (p = adj[q[head]]; p != NULL; p = p->next) {
				if (comp[p->v] == 0) {
					comp[p->v] = k;
					q[tail++] = p->v;
				}
			}
		}
		size[k++] = tail;
	}
	for (i = 1, K = k - 1; i <= N; i++) {
		if (comp[i] != 0) continue;
		comp[i] = k;
		q[0] = i;
		for (head = 0, tail = 1; head < tail; head++) {
			for (p = adj[q[head]]; p != NULL; p = p->next) {
				if (comp[p->v] == 0) {
					comp[p->v] = k;
					q[tail++] = p->v;
				}
			}
		}
		k++;
	}
	free(adj);
	free(d);
	
	int l;
	long long ans = N - k + 1 + K, dp[2][5001] = {{1}}, N_pow[5001] = {1}, fact;
	for (i = 1; i <= K; i++) {
		l = i % 2;
		N_pow[i] = N_pow[i-1] * (N - 1) % Mod;
		dp[l][0] = dp[1-l][0] * size[i] % Mod;
		for (j = 1; j <= i; j++) dp[l][j] = (dp[1-l][j-1] + dp[1-l][j] * size[i]) % Mod;
	}
	ans = (ans * N_pow[K] - (dp[K%2][K-1] - K) * N_pow[K-1] % Mod) % Mod;
	for (i = 2, fact = 1; i <= K; i++, fact = fact * (i - 1) % Mod) {
		ans = (ans + Mod - ((dp[K%2][K-i] * fact % Mod) * N_pow[K-i] % Mod)) % Mod;
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1976
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 998244353;

int main() {
	
	int n, k;
	cin >> n >> k;
	vi p(n);
	rep(i, n)cin >> p[i];
	sort(all(p));
	int sum = 0;
	rep(i, k)sum += p[i];
	cout << sum << endl;
}

Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main() {
	int a,b,ans;
	cin >> a;
	cin >> b;
	ans = a*b;
	if (ans % 2 == 0) {
		cout << "Even" << "\n";
	}
	else  {
		cout << "Odd" << "\n";
	}
	
	
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
h = np.array(list(map(int, input().split())))

dp = np.full_like(h, np.inf)

dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, len(h)):
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[(len(h) - 1)])

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

int main(){
    int64_t N,K;
    const int64_t mod = 1000000007;
    cin>>N>>K;
    int64_t dp[N+1][N+1][K+1];
    fill(dp[0][0],dp[N+1][0],0);
    dp[0][0][0]=1;
    for(int i=0;i<N;i++){
        for(int j=0;j<=i;j++){
            for(int k=0;k+2*j<=K;k++){
                dp[i+1][j+1][k+2*j]+=dp[i][j][k];
                dp[i+1][j+1][k+2*j]%=mod;
                dp[i+1][j][k+2*j]+=(2*j+1)*dp[i][j][k];
                dp[i+1][j][k+2*j]%=mod;
                if(j){
                    dp[i+1][j-1][k+2*j]+=j*j*dp[i][j][k];
                    dp[i+1][j-1][k+2*j]%=mod;
                }
            }
        }
    }
    cout<<dp[N][0][K]<<endl;
    return 0;
}

Measured memory_bytes: 51072
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
using namespace std;

#define MAX_N 100000000
#define INF 1000000000

int main(){
  int n,m;
  cin >> n >> m;
  int a[m];
  for(int i=0;i<m;i++) cin >> a[i];
  int ma[10];
  ma[1] = 2;
  ma[2] = 5;
  ma[3] = 5;
  ma[4] = 4;
  ma[5] = 5;
  ma[6] = 6;
  ma[7] = 3;
  ma[8] = 7;
  ma[9] = 6;
  sort(a,a+m);
  int dp[n+1];
  dp[0] = 0;
  for(int i=1;i<n+1;i++){
    dp[i] = -1*INF;
    for(int j=0;j<m;j++){
      if(i-ma[a[j]] >= 0){
        dp[i] = max(dp[i],dp[i-ma[a[j]]]+1);
      }
    }
  }
  string ans = "";
  int count = n;
  for(int i=0;i<dp[n]-1;i++){
    for(int j=m-1;j>=0;j--){
      if(dp[count]-1 == dp[count-ma[a[j]]] && count-ma[a[j]] >= 0){
        count -= ma[a[j]];
        ans += to_string(a[j]);
        break;
      }
    }
  }

  for(int j=m-1;j>=0;j--){
    if(count == ma[a[j]]){
      ans += to_string(a[j]);
      break;
    }
  }

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


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

int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int N, M;
    cin >> N >> M;

    int tmp, As=0;
    for(int i=0; i<M; i++){
        cin >> tmp;
        As+=tmp;
    }

    int res = N - As;
    if(res>=0){
        cout << res << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int n,m;
  cin>>n>>m;
  long long a[m];
  for(int i=0;i<m;i++) cin>>a[i];
  long long dp[n+1];
  dp[0]=1;
  int j=0;
  if(a[0]==1) {
    dp[1]=0;
    if(j<m-1) j++;
  }
  else dp[1]=1;
  for(int i=2;i<=n;i++){
    if(a[j]==i){
      dp[i]=0;
      if(j<m-1) j++;
    }
    else{
      dp[i]=dp[i-1];
      dp[i]%=1000000007;
      dp[i]+=dp[i-2];
      dp[i]%=1000000007;
    }
  }
  cout<<dp[n]<<endl;
}


Measured memory_bytes: 1792
def insertionSort(A, n, g):
	global cnt

	for i in range(g, n):
		v = A[i]
		j = i - g
		while j >= 0 and A[j] > v:
			A[j + g] = A[j]
			j = j - g
			cnt = cnt + 1
		A[j + g] = v

def shellSort(A, n):
	global m
	global G

	h = 1
	while (True):
		if h > n:
			break
		G.append(h)
		h = 3 * h + 1

	m = len(G)
	G.reverse()

	for i in range(m):
		insertionSort(A, n, G[i])

if __name__ == '__main__':
	N = int(input())
	R = [int(input()) for i in range(N)]

	cnt = 0
	G = []
	m = 0

	shellSort(R, N)

	print(m)
	print(" ".join(map(str, G)))
	print(cnt)
	for i in range(N):
		print(R[i])


Measured memory_bytes: 45516
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

#define MAX 1000002

int Lv[MAX];
int n, k;

bool cmp_Lv(const int i, const int j){ return Lv[i] < Lv[j]; }

bool cmp(const int i, const int j){
    if(Lv[i] != Lv[j]){ return Lv[i] < Lv[j]; }
    int L_i = (i + k >= n ? -1 : Lv[i + k]);
    int L_j = (j + k >= n ? -1 : Lv[j + k]);

    return L_i < L_j;
}

int main()
{
    int A[MAX], newLv[MAX];
    std::string T;
    std::cin >> T;
    n = T.size();

    int i;
    for(i = 0; i < n; i++){ A[i] = i; }
    for(i = 0; i < n; i++){ Lv[i] = T[i]; }
    std::sort(A, A + n, cmp_Lv);

    newLv[A[0]] = 0;
    for(i = 1; i < n; i++){
        newLv[A[i]] = newLv[A[i - 1]] + (Lv[A[i]] != Lv[A[i - 1]] ? 1 : 0);
    }
    for(i = 0; i < n; i++){ Lv[i] = newLv[i]; }

    k = 1;
    while(1){
        if(k > n) break;

        std::sort(A, A + n, cmp);
        newLv[A[0]] = 0;
        for(i = 1; i < n; i++){ newLv[A[i]] = newLv[A[i - 1]] + (cmp(A[i - 1], A[i]) ? 1 : 0); }
        for(i = 0; i < n; i++){ Lv[i] = newLv[i]; }

        if(Lv[A[n - 1]] == n - 1) break;
        k <<= 1;
    };

    std::string P;
    int q, left, right, mid, crit;
    bool exist;
    scanf("%d", &q);

    A[n] = n;

    while(q){
        std::cin >> P;
        left = 0, right = n, exist = false;
        while(left < right){

            if(n < P.size()){ exist = false; break; }

            mid = (left + right) / 2;
            crit = T.compare(A[mid], P.size(), P);

            if(crit > 0){ right = mid; }
            else if(crit < 0){ left = mid + 1; }
            else{ exist = true; break; }
        };
        if(T.compare(A[right], P.size(), P) == 0) exist = true;
        if(exist){ printf("1\n"); }else{ printf("0\n"); }
        q--;
    }
    return 0;
}

Measured memory_bytes: 13992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define REP(i, n) for(int i=0; i<n; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9+7;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    vector<ll> f(n);
    REP(i, n){cin >> a[i];}
    REP(i, n){cin >> f[i];}
    sort(ALL(a)); //昇順
    sort(ALL(f), greater<ll>()); //降順
    bool converge = true;
    ll upper = INF;
    ll lower = 0;
    ll tmp_dot;
    ll difference;
    ll criterion;
    // 二分探索
    while(upper - lower > 1){
        difference = 0;
        criterion = (lower+upper)/2;
        REP(i, n){
            tmp_dot = a[i] * f[i];
            if(tmp_dot > criterion){
                difference += (ll)ceil((double)(tmp_dot-criterion) / (double)f[i]);
            }
        }
        if(difference <= k){
            upper = criterion;
        }else{
            lower = criterion;
        }
    }
    ll lo_dif = 0;
    REP(i, n){
        tmp_dot = a[i] * f[i];
        if(tmp_dot > lower){
            lo_dif += (ll)ceil((double)(tmp_dot-lower) / (double)f[i]);
        }
    }
    if(lo_dif<=k){
            cout << lower << endl;
    }else{
        cout << upper << endl;
    }
    return 0;
}

Measured memory_bytes: 3328
from math import ceil


class Solver(object):
    def __init__(self):
        self.n, self.k = list(map(int, input().split(" ")))
        self.a_s = list(map(int, input().split(" ")))

    def solve(self):
        print(ceil((self.n-self.k) / (self.k-1)) + 1)


if __name__ == "__main__":
    s = Solver()
    s.solve()

Measured memory_bytes: 13812
#include <iostream>
#include <string>
//#include <algorithm>
#include <vector>

using namespace std;

int main(){
    int N;
    cin >> N;
    //long long result;
    long long L[N+1];
    L[0] = 2;
    L[1] = 1;
    if (N == 1){
        cout << L[1] << endl;
        return 0;
    }
    for (int i = 2; i < N+1; i++){
        L[i] = L[i-2] + L[i-1];
    }

    cout << L[N] << endl;

    return 0;
}


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

int n, a, mx, md, fl=1, c[105];
int main() {
	int i;
	cin>>n;
	for(i=0; i<n; i++) {
		cin>>a;
		c[a]++;
		mx = max(mx, a);
	}
	md = (mx+1)/2;
	if(c[md] != mx%2+1) fl = 0;
	for(i=md+1; i<=mx; i++) if(c[i]<2) fl = 0;
	cout<<(fl ? "P":"Imp")<<"ossible";
	return 0;
}

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

int choice(int n,int k){
    if(n == k){
        return 1;
    }
    if(k == 1){
        return n;
    }
    return choice(n-1,k-1) + choice(n-1,k);
}

int main(){  
    int n ,h ,w;
    cin >> n >> h >> w;
    cout << (n-h+1) * (n-w+1) << endl;
}

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

using namespace std;

class DisjointSet {
  public:
    DisjointSet(int num_nodes);
    int find(int element);
    void do_union(int elment_a, int element_b);
    void dup(vector<int> &v);
  private:
    vector<int> parent_, rank_;
};

DisjointSet::DisjointSet(int num_nodes) : parent_(num_nodes),rank_(num_nodes, 0){
  for (int i = 0; i < num_nodes; i++) parent_[i] = i;
}

int DisjointSet::find(int element){
  if(parent_[element] == element) return element;
  return parent_[element] = find(parent_[element]);
}

void DisjointSet::do_union(int a, int b){
  if(parent_[a] == parent_[b]) return;
  int fa = find(a), fb = find(b);

  if(rank_[fa] < rank_[fb]) {
    parent_[fa] = fb;
  } else {
    parent_[fb] = fa;
    if(rank_[fa] == rank_[fb]) rank_[fa]++;
  }
}

int main(){
  int n = 0, q = 0;
  cin >> n >> q;

  DisjointSet ds(n);

  vector<bool> ans;

  for (int i = 0; i < q; i++){
    int com = 0, x = 0, y = 0;
    cin >> com >> x >> y;

    if(com == 0){
      ds.do_union(x, y);
    } else {
      ans.push_back(ds.find(x) == ds.find(y));
    }
  }

  for (int i = 0; i < ans.size(); i++){
    cout << ans[i] << endl;
  }
}


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    string s,t;cin>>s>>t;

    REP(i,SIZE(s)){
        if(s[i]!=t[i]){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.length();
	bool ans = false;
	for (int i = 0; i < n; i++) {
		bool c = true;
		for (int j = i; j < n + i; j++) {
			if (s[j - i] != t[j % n])c = false;
		}
		ans |= c;
	}
	if (ans) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256