akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using pii = pair <int, int>;

#define F first
#define S second
#define mx 3003

int a[mx];
int b[mx];
int dp[mx][mx];

int solve(int i, int t) {
	if (i < 0) return 0;
	if (t < 0) return 0;
	int& ans = dp[i][t];
	if (ans != -1) return ans;
	ans = 0;
	if (t - a[i] >= 0) ans = b[i] + solve(i - 1, t - a[i]);
	ans = max(ans, solve(i - 1, t));
	return ans;
}

int main() {
	int n, t;
	cin >> n >> t;
	vector <pii> vec;
	for (int i = 0; i < n; i++) {
		int aa, bb; cin >> aa >> bb;
		vec.push_back(pii(aa, bb));
	}

	memset(dp, -1, sizeof dp);
	sort(vec.begin(), vec.end());
	for (int i = 0; i < n; i++) {
		a[i] = vec[i].F;
		b[i] = vec[i].S;
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, b[i] + solve(i - 1, t - 1));
	}

	cout << ans << endl;
}

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

int main() {
    int N, M;
    long long K;
    cin >> N >> M >> K;
    vector<long long> A(N), B(M);
    vector<long long> SA(N+1, 0), SB(M+1, 0); // 累積和
    for (int i = 0; i < N; ++i) cin >> A[i], SA[i+1] = SA[i] + A[i];
    for (int i = 0; i < M; ++i) cin >> B[i], SB[i+1] = SB[i] + B[i];

    int result = 0;
    for (int x = 0; x <= N; ++x) {
        if (SA[x] > K) break;

        int y = upper_bound(SB.begin(), SB.end(), K - SA[x]) - SB.begin();
        --y;
        result = max(result, x + y);
    }
    cout << result << endl;
}

Measured memory_bytes: 9560
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

vector<Int> OutDivisor(Int n) {
    vector<Int> ret;
    for(Int i=1; i*i<=n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i*i!=n) ret.push_back(n / i);
        }
    }
    return ret;
}

Int x[105];
Int y[105];
Int h[105];
map<int, int> memo;
map<int, int> memo2;

void output(Int X, Int Y, Int H){
    cout << X << " " << Y << " " << H << endl;
    exit(0);
}

int main(){
    int N;
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> h[i];
    }
    for (Int i = 0; i <= 100; i++){
        for (Int j = 0; j <= 100; j++){
            int flag = 1;
            Int H;
            for (int k = 0; k < N; k++){
                Int manh = abs(i-x[k]) + abs(j-y[k]);
                if (h[k] > 0){
                    H = h[k] + manh;
                    break;
                }
            }
            for (int k = 0; k < N; k++){
                if (max(H - abs(i - x[k]) - abs(j - y[k]), 0LL) != h[k]) flag = 0;
            }
            if (flag == 1){
                output(i, j, H);
            } 
            memo.clear();
            memo2.clear();
        }
    }
} 


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

int top,S[1000];

void push(int x){
  S[++top] = x;
}

int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a,b;
  top = 0;
  char s[100];
  while( scanf("%s", s) != EOF){
    if (s[0] == '+'){
      a = pop();
      b = pop();
      push(a+b);
    }
    else if(s[0] == '-'){
      b = pop();
      a = pop();
      push(a-b);
    }
    else if(s[0] == '*'){
      a = pop();
      b = pop();
      push(a*b);
    }
    else{
      push(atoi(s));
    }
  }

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



Measured memory_bytes: 2088
using System;   
 class Program
    {
        static void Main(string[] args)
        {
            string[] temp = Console.ReadLine().Split(' ');
            int a = int.Parse(temp[0]);
            int b = int.Parse(temp[1]);
            int c = int.Parse(temp[2]);
            int[] iList = { a, b, c };

            Array.Sort(iList);
            int one = iList[0];
            int two = iList[1];
            int three = iList[2];

            int t2 = two - one;
            int t3 = three - two;

            Console.WriteLine(t2 + t3);

        }
    }

Measured memory_bytes: 13140
#include<stdio.h>

int main(){

  int n,p[101],m[101][101];
  int i,j,k,l,s;

  scanf("%d",&n);

  //p[n]=j;

  for(i=1;i<=n;i++) scanf("%d%d",&p[i-1],&p[i]);

  for(i=1;i<=n;i++) m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=8101919;
      for(k=i;k<=j-1;k++){
	s=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];

	if(m[i][j]>s) m[i][j]=s;
	else m[i][j] = m[i][j];
      }
    }
  }
  printf("%d\n",m[1][n]);

  return 0;
}

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

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

  int k,b,p,r;
  long long count=0;
  for(b=K+1; b<=N; b++){
    p = N/b;
    r = N%b;
    count += (long long)(b-K)*p+max(0,r-K+1);
  }
  if(K==0) count -= (long long)N;
  cout << count << endl;
}

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

int main(){
	int n;	cin>>n;
	vector<int> a(n);	for(int i=0;i<n;i++)cin>>a[i];
	sort(a.begin(), a.end());

	int ans=0, now=a[0], count=1;
	for(int i=1; i<n; i++){
		if(now==a[i]) count++;
		else{
			now=a[i];
			if(count%2)ans++;

			count=1;
		}
	}
			if(count%2)ans++;

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 640
x,y = map(int,input().split())
a=(1,3,5,7,8,10,12)
b=(4,6,9,12)
c=(2)
if x in a and y in a:
  print('Yes')
elif x in b and y in b:
  print('Yes')
elif x == c and y == c:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 38256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int a = sc.nextInt();

        if(x<a){
            System.out.println(0);
        }else{
            System.out.println(10);
        }
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>

using namespace std;
using pii=pair<int,int>;
using ll=long long;

struct EDGE{
    int src;
    int dst;
    int coin;
};

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    int n,m,p;
    cin>>n>>m>>p;
    vector<EDGE> edge(m);
    for(int i=0; i<m; i++){
        int a,b,c;
        cin>>a>>b>>c;
        edge[i].src=a-1;
        edge[i].dst=b-1;
        edge[i].coin=-c+p;
    }
    vector<int> coin(n,INT_MAX);
    coin[0]=0;
    for(int i=0; i<n; i++){
        for(EDGE& e : edge){
            if(coin[e.src]==INT_MIN) coin[e.dst]=INT_MIN;
            else if(coin[e.src]!=INT_MAX && coin[e.dst]>coin[e.src]+e.coin){
                if(i==n-1) coin[e.dst]=INT_MIN;
                else coin[e.dst]=coin[e.src]+e.coin;
            }
        }
    }
    for(int i=0; i<n-1; i++){
        for(EDGE& e : edge){
            if(coin[e.src]==INT_MIN) coin[e.dst]=INT_MIN;
        }
    }
    if(coin[n-1]==INT_MIN) cout<<-1;
    else cout<<max(0,-coin[n-1]);

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
	int a[1000], n;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = n-1; i >= 0; i--){
		if (i == 0){
			cout << a[i] << '\n';
		}
		else{
			cout << a[i] << " ";
		}
	}
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int memo[12001][8];
int b_pow(int a,int b){
	if(memo[a][b]) return memo[a][b];
	else if( b == 0 ) return 1;
	else if( b == 1 ) return a;
	else return memo[a][b] = b_pow(a,b/2) * b_pow(a,(b+1)/2);
}
int ans , A;

int dfs(int p , int q , int k , int a , int t){
	if(a <= 0 || a > A || p*t > k*q	) return 0 ;
	if(p == 0) return 1;
	if( t*a > A || k == 0 || p == 0) return 0;
	int ans = 0;
	for(int i = 0 ; i <= k ; i++){
		if(p*t >= i*q) {
			int w = p * t - i * q;
			int x = q * t;
			if(w != 0){
				int g = __gcd(w,x);
				w /= g , x /= g;
			}
			ans += dfs(w , x , k - i , a * b_pow(t,i) ,  t + 1);
		}else{
			break;
		}
	}
	return ans;
}
int main(){
	int a,b,c,d;
	while(cin >> a >> b >> c >> d , a || b || c || d){	
		A = c;
		cout << dfs(a,b,d,1,1) << endl;
	}		
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

const int INF = 1 << 30;

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M; cin >> N >> M;
  vector<vector<int>> edges(N);
  REP(i, M) {
    int u, v; cin >> u >> v; u--, v--;
    edges[u].emplace_back(v);
  }

  int S, T; cin >> S >> T; S--, T--;

  vector<vector<int>> dist(3, vector<int>(N, INF));

  using Tu = tuple<int, int, int>;
  priority_queue<Tu, vector<Tu>, greater<Tu>> pque;
  pque.emplace(0, 0, S);

  while (not pque.empty()) {
    int d, s, v; tie(d, s, v) = pque.top(); pque.pop();
    //cerr << v << ' ' << s << ' ' << d << endl;
    if (s == 0 and v == T) {
      cout << d / 3 << endl;
      return 0;
    }
    if (dist[s][v] < d) continue;
    dist[s][v] = d;

    int next_s = (s + 1) % 3;
    for (int c : edges[v]) {
      if (d + 1 < dist[next_s][c]) {
        dist[next_s][c] = d + 1;
        pque.emplace(d+1, next_s, c);
      }
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 7296
import sys
input = sys.stdin.readline
from collections import defaultdict


def main():
    N, M = map(int, input().split())
    passed = set([])
    penalty = defaultdict(int)
    for _ in range(M):
        p, S = input().split()
        if S == "WA" and p not in passed:
            penalty[p] += 1
        elif S == "AC":
            passed.add(p)
    ans = sum([penalty[p] for p in passed])
    print(len(passed), ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 102520
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll item,weight;
    cin>>item>>weight;
    ll wt[item+5],value[item+5];
    for(int i=1; i<=item; i++)
    {
        cin>>wt[i]>>value[i];
    }
    ll knapsack[item+5][weight+5];
    for(int i=0; i<=item; i++)
    {
        for(int w=0; w<=weight; w++)
        {
            if(i==0 || w==0)
                knapsack[i][w]=0;
            else if(wt[i]<=w)
            {
                knapsack[i][w]=max(value[i]+knapsack[i-1][w-wt[i]],knapsack[i-1][w]);
            }
            else
                knapsack[i][w]=knapsack[i-1][w];
        }
    }
    cout<<knapsack[item][weight]<<endl;


}


Measured memory_bytes: 82324
S=list(input())
ans=0

for x in range(2**(len(S)-1)):
  bin_x = str(format(x,str(len(S)-1)+"b"))[::-1]
  
  l=0
  res=0
  for r,i in enumerate(bin_x):
    if i == "1":
      res+=int("".join(S[l:r+1]))
      l=r+1
  res+=int("".join(S[l:len(S)]))
  ans+=res
print(ans)

Measured memory_bytes: 40048
#include<cstdio>
#include<algorithm>
#define int long long
using namespace std;
int n,m,mod=1000000007;
int fac(int x)
{
	int ans=1;
	for(int i=2;i<=x;i++)ans=ans*i%mod;
	return ans;
}
signed main()
{
	scanf("%lld%lld",&n,&m);
	if(n<m)swap(n,m);
	if(n-m>1){puts("0");return 0;}
	if(n==m)printf("%lld\n",2*fac(n)*fac(m)%mod);
	else printf("%lld\n",fac(n)*fac(m)%mod);
	return 0;
}


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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int ans;
  if(B<C || D<A) ans=0;
  else ans= min(B, D) - max(A, C);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

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

	int a, n, m;
	cin >> a >> n >> m;
	ull res = 0;
	FOR(y, 1, 63+1) {
		int x = pow(y+a, n);
		int k = x;
		int tmp = 0;
		while(k != 0) {
			tmp += (k % 10);
			k /= 10;
		}
		if(x <= m && tmp == y) res++;
	}
	cout << res << endl;
}


Measured memory_bytes: 3396
from collections import defaultdict
from math import gcd
N = int(input())
mod = 10**9 + 7
D = defaultdict(int)
corner = 0
D[(0,1)]=0
D[(1,0)]=0
for i in range(N):
    x, y = map(int, input().split())
    if x*y != 0:
        x, y = x//gcd(x, y), y//gcd(x, y)
        if y > 0:
            D[(x, y)] += 1
        elif y < 0:
            D[(-x, -y)] += 1
    else:
        if x == 0 and y == 0:
            corner += 1
            continue
        else:
            if x == 0:
                D[(0, 1)] += 1
            elif y == 0:
                D[(1, 0)] += 1
ans = corner
# 以下、(0,0) を入れない時。(X,Y) のYは全て0以上で統一する（何も入れないも一応カウント）
c = 1
sub=[]
for x, y in D.keys():
    if x<0 and y>0:
        if not (y,-x) in D.keys():
            sub.append((y,-x))
for some in sub:
    D[some]=0

K=list(D.keys())
for x, y in K:
    if x > 0 and y > 0:
        a = D[(x, y)]
        b = D[(-y, x)]
        c *= (pow(2, a, mod)+pow(2, b, mod)-1)
        c %= mod
    elif y == 0:
        a = D[(1, 0)]
        b = D[(0, 1)]
        c *= (pow(2, a, mod)+pow(2, b, mod)-1)
        c %= mod
ans += c-1

print(ans % mod)

Measured memory_bytes: 162632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Trampoline
 */
public class Main {

	static int N;
	static int[] d;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		N = parseInt(br.readLine());
		d = new int[N];

		for (int i = 0; i < N; i++) {
			d[i] = parseInt(br.readLine());
		}

		int a = solve();

		for (int i = 0, j = N - 1; i < N / 2; i++, j--) {
			int t = d[i];
			d[i] = d[j];
			d[j] = t;
		}

		int b = solve();

		System.out.println(a == 1 && b == 1 ? "yes" : "no");
	}

	static int solve() {
		int last = 0;
		for (int i = 0; i < N; i++) {
			if (last < i * 10) return 0;
			last = Math.max(last, i * 10 + d[i]);
		}
		return 1;
	}
}


Measured memory_bytes: 47756
#include<stdio.h>

int n,A[50];

int solve(int i,int m){
  if(m==0) return 1;
  if(i>=n) return 0;
  int res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}

int main(){
  int q,M,i;

  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%d", &A[i]);
  scanf("%d", &q);
  for(i=0;i<q;i++){
    scanf("%d", &M);
    if(solve(0,M)) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



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

N = int(input())

def dfs(S):
    if int(S) > N:
        return 0
    ret = 1 if all(S.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += dfs(S + c)
    return ret

print(dfs("0"))

Measured memory_bytes: 55004
import java.util.*;


class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int D = sc.nextInt();
		int X = sc.nextInt();
		
		int[] A = new int[ N ] ;
		for(int i = 0 ; i < N ; i ++){
			A[i] = sc.nextInt();
		}
		
		int result = 0 ;
		for(int i = 0 ; i < N ; i ++){
			result = result + 1 + ( D - 1 ) / A[ i ] ;
		}
		result = result + X;
		
		System.out.println(result);
	}
}


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

int main(void)
{
    int n, m;
    scanf("%d%d", &n,&m);
    int path[n+1];
    memset(path, 0, sizeof(path));
    for (int i = 0 ; i < m ; i++)
    {
        int a,b;
        scanf("%d%d", &a, &b);
        path[a]++;
        path[b]++;
    }
    
    for (int j = 1 ; j <= n; j++)
    {
        cout<<path[j]<<endl;
    }
    
    
    
    return 0 ;
}


Measured memory_bytes: 256
import math

n, k = map(int, input().split())
ans = []
for i in range(1, n+1):
    if i < k:
        j = i
        cnt = 0
        while j < k:
            j *= 2
            cnt += 1
        tmp = 1/n * ((1/2) ** cnt)
        ans.append(tmp)
    if i >= k:
        ans.append(1/n)
print('{:.10f}'.format(sum(ans)))

Measured memory_bytes: 6296
// #include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define ll long long
#define pi pair<int,int>
#define vi vector<int>
int solve(){
  int x, n;
  cin>>x>>n;
  if(n==0) return x;
  vector<int> v(n);
  for(int i=0;i<n;++i) {
    cin>>v[i];
  }
  set<int> s(v.begin(), v.end());
  int i=0;
  while(i<=100){
    if(!s.count(x-i)) return x-i;
    if(!s.count(x+i)) return x+i;
    i++;
  }
  return -1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // int t;
  // cin >> t;
  // for (int i = 1; i <= t; ++i) {
  //   cout << solve(i) << "\n";
  // }
  cout << solve() << "\n";

  return 0;
} 

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int x;
    cin>>x;
    long long int y=100;
    long long int count=0;
    while(y<x)
    {
        y=y+y*0.01;
        count++;
    }
    cout<<count<<"\n";
}

Measured memory_bytes: 3616
N = int(input())
Bl = list(map(int, input().split()))

Al = []
Al.append(Bl[0])
for bi in range(N-1):
    try:
        Al.append(min(Bl[bi], Bl[bi+1]))
    except IndexError:
        pass

Al.append(Bl[-1])
print(sum(Al))

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


int main() {
	int D, T, S;
	cin >> D >> T >> S;
	double M = (double)D / S;
	if (M<=T)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int INF = 1e9 + 239;

vector<int> gps(vector<int> a) {
	int n = (int)a.size();
	vector<int> ps(n + 1);
	for (int i = 0; i < n; i++) {
		ps[i + 1] = ps[i] + a[i];
	}
	return ps;
}

int solve(int n, int m, int k, vector<vector<int>> a) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (a[i][j] > k) return INF;
		}
	}
	vector<vector<int>> ps(n);
	for (int i = 0; i < n; i++) {
		ps[i] = gps(a[i]);
	}
	auto ok = [&](int l, int r) {
		r++;
		int ans = 1;
		for (int i = 0; i < n; i++) {
			int v = ps[i][r] - ps[i][l];
			ans &= (v <= k);
		}
		return ans;
	};
	int ans = 0;
	for (int i = 0; i < m; i++) {
		ans++;
		int r = i;
		while (r + 1 < m && ok(i, r + 1)) {
			r++;
		}
		i = r;
	}
	return ans - 1;
}

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

	int n, m, k;
	cin >> n >> m >> k;
	vector<vector<int>> a(n, vector<int> (m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			a[i][j] = c - '0';
		}
	}
	int ans = INF;
	for (int mask = 0; mask < (1 << n) / 2; mask++) {
	// {	
		// int mask = 4;
		int v = __builtin_popcount(mask);
		vector<vector<int>> ca(v + 1, vector<int> (m)); 
		vector<int> bits = {0};
		for (int i = 0; i < n - 1; i++) {
			if ((mask >> i) & 1) bits.push_back(i + 1);
		}
		bits.push_back(n);
		assert((int)bits.size() == v + 2);
		for (int i = 0; i < v + 1; i++) {
			assert(i + 1 < (int)bits.size());
			for (int ri = bits[i]; ri < bits[i + 1]; ri++) {
				for (int j = 0; j < m; j++) {
					// if (ri + 1 == n) cout << "wow add to " << i << endl;
					// cout << a[ri][j] << endl;
					// cout << "ri " << ri << ' ' << i << ' ' << a[ri][j] << endl;
					ca[i][j] += a[ri][j];
				}
			}
		}
		// cout << ca[1][0] << endl;
		int c = v + solve(v + 1, m, k, ca);
		// if (c == 1) {
		// 	cout << mask << endl;
		// 	cout << "hr" << endl;
		// 	for (auto t : ca) {
		// 		for (auto x : t) {
		// 			cout << x;
		// 		}
		// 		cout << endl;
		// 	}
		// }
		ans = min(ans, c);
	}
	cout << ans << endl;
} 


Measured memory_bytes: 384
object Main extends App {
	val n = scala.io.StdIn.readInt
	val h = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	var high = h(0)
	var cnt = 1

	for(i<-1 until n){
		if(h(i) >= high){
			cnt += 1
			high = h(i)
		}
	}

	println(cnt)
}


Measured memory_bytes: 27304
#include <bits/stdc++.h>
using namespace std;
void dfs (
	int crr
, int& cnt
, bool& is_binary
, vector<int>& col
, vector<vector<int>>& grh
) {
	cnt++;
	for (int nxt : grh[crr]) {
		if (col[nxt] ==  -1) {
			col[nxt] = col[crr] ^ 1;
			dfs(nxt, cnt, is_binary, col, grh);
		} else if (col[nxt] == col[crr]) {
			is_binary = false;
		}
	}
}
int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> grh(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		grh[--a].push_back(--b);
		grh[b].push_back(a);
	}
	vector<int> cmp;
	int cnt = 0;
	bool is_binary;
	vector<int> col(n, -1);
	long long a(0), b(0), c(0);
	for (int i = 0; i < n; i++) {
		if (col[i] == -1) {
			col[i] = 1;
			dfs(i, cnt = 0, is_binary = true, col, grh);
			if (cnt > 1 && is_binary) a++;
			else if (cnt > 1 && not is_binary) b++;
			else c++;
		}
	}
	long long ret =
			2 * a * a
		+ 2 * a * b
		+ b * b
		+ 2 * n * c
		- c * c;
	cout << ret << endl;
	return 0;
}

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

// π M_PI
// deg = rad*180/M_PI

bool pair_Cs_R(const pair<ll, ll>& firstElof, const pair<ll, ll>& secondElof) {
    return firstElof.second > secondElof.second;
}

int main() {
    ll k, n;
    cin >> k >> n;
    ll a[n];
    std::vector<ll> v;
    ll ans = 0;
    rep(i, n) {
        cin >> a[i];
        if ( i > 0 ) {
            v.push_back(a[i]-a[i-1]);
        }
    }
    v.push_back(k-a[n-1]+a[0]);
    Sort(v);
    rep(i, n-1) {
        ans += v[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <cstdlib>
typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
 
using namespace std;
 
int main(){
 
    int n;
    cin >> n ;
    ll a[n],b[n];
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    ll sum = 0;
    for(int i=n-1;i>=0;i--){
      	if((a[i]+sum)%b[i] != 0){
        	int x = b[i] - (a[i]+sum)%b[i];
        	sum += x;
    	}
      	//cout << sum << endl;
    }  
    cout << sum;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
  int N,x,i,j,temp,a[100],ans = 0;
  
  scanf("%d%d",&N,&x);
  for(i = 0;i < N;i++){
    scanf("%d",&a[i]);
  }
  
  for(i = 0;i < N - 1;i++) {
    for(j = 0;j <N - 1;j++) {
      if (a[j + 1] < a[j]) {
        temp = a[j];
        a[j] = a[j + 1];
        a[j + 1] = temp;
      }
    }
  }

  for(i = 0;(x - a[i] >= 0) && (i < N -1);i++) {
    ans++;
    x = x - a[i];
  }
  if(x == a[N - 1]) ans++;
  printf("%d",ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
int tran(int x);
int main()
{
    using namespace std;
    int x;
    cin>>x;
    tran(x);
    cout<<tran(x)<<endl;
    return 0;
}
int tran(int x) {
    int j;
    if (x == 0)
    { j=1;
        return j;}
    else
    {  j=0;
        return j;}
}

Measured memory_bytes: 3620
#include<bits/stdc++.h> 
#define int long long
using namespace std;
int solve(vector<int>& weights, vector<int>& value,int N, int W, vector<vector<int>>& dp){
	if (N<=0||W<=0) return 0;
	if (dp[N][W]!=-1) return dp[N][W];
	if (weights[N-1]>W) return dp[N][W]=solve(weights,value,N-1,W,dp);
	return dp[N][W]=max(solve(weights,value,N-1,W,dp),
		value[N-1]+solve(weights,value,N-1,W-weights[N-1],dp));
}
signed main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
	int N,W;
    cin>>N>>W;
    vector<int> weights(N);
    vector<int> value(N);
    for (int i=0;i<N;i++){
    	cin>>weights[i]>>value[i];
    }
    vector<vector<int>> dp(N+1,vector<int>(W+1,-1));
	cout<< solve(weights,value,N,W,dp)<<endl;
    return 0; 
}


Measured memory_bytes: 83160
#include<cstring> 
#include<cstdio> 
#include<cmath> 
using namespace std; 
long long sta[100005],a[100005],t[100005],s[100005],ans; 
int tp,n,m; 
int td(long long k,int r){ 
	int l=1,res=0; 
	while(l<=r){ 
		int mid=(l+r)/2; 
		if(a[mid]<=k) res=mid,l=mid+1; 
		else r=mid-1; 
	} 
	return res; 
} 
int main(){ 
	scanf("%d%d",&n,&m); 
	sta[tp=1]=n; 
	for(int i=1;i<=m;i++){ 
		long long x;
		scanf("%lld",&x); 
		while(x<=sta[tp]) tp--; 
		sta[++tp]=x; 
	} 
	m=tp; 
	for(int i=1;i<=m;i++) a[i]=sta[i]; 
	t[m]=1; 
	for(int i=m;i>=1;i--){ 
		long long k=a[i];
		int p=td(k,i-1); 
		while(p){ 
			t[p]+=(k/a[p])*t[i]; 
			k%=a[p]; 
			p=td(k,p-1); 
		} 
		s[1]+=t[i];
		s[k+1]-=t[i]; 
	} 
	for(int i=1;i<=n;i++){
		ans+=s[i];
		printf("%lld\n",ans);
	} 
	return 0; 
}

Measured memory_bytes: 4736
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

int v[100001], w[100001];

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int tmp;
    cin >> tmp;
    if(i%2==0)v[tmp]++;
    else w[tmp]++;
  }
  int vmax=0, vid=0, wmax=0, wid=0;
  for(int i=0;i<=100000;i++){
    if(vmax<v[i]){
      vid=i;
      vmax=v[i];
    }
    if(wmax<w[i]){
      wid=i;
      wmax=w[i];
    }
  }
  int vvmax=0, vvid=0, wwmax=0, wwid=0;
  if(vid==wid){
      if(vmax<wmax){
        for(int i=0;i<=100000;i++){
          if(vid!=i&&vvmax<v[i]){
            vvid=i;
            vvmax=v[i];
          }
        }
        vmax=vvmax;
      }
      else if(vmax>wmax){
        for(int i=0;i<=100000;i++){
          if(wid!=i&&wwmax<w[i]){
            wwid=i;
            wwmax=w[i];
          }
        }
        wmax=wwmax;
      }
      else{
        for(int i=0;i<=100000;i++){
          if(vid!=i&&vvmax<v[i]){
            vvid=i;
            vvmax=v[i];
          }
        }
        for(int i=0;i<=100000;i++){
          if(wid!=i&&wwmax<w[i]){
            wwid=i;
            wwmax=w[i];
          }
        }
        if(wwmax<=vvmax)vmax=vvmax;
        else wmax=wwmax;
      }
  }
  cout << n-wmax-vmax << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
    
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
        a[i] = sc.nextInt();
        }

        for(int i = n-1;i>=0;i--){
            System.out.print(a[i]);
            if(i>0){
                System.out.print(" ");
            }
            
        }
System.out.println();

        
        sc.close();
        }
        
}


Measured memory_bytes: 26228
#include <bits/stdc++.h>    
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()]
#define endl "\n"
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N 	     = 1000*100+5;
const ll N2     = 1000*1000;
const double PI  = 3.14159265;
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
int main()
{
	//comment for all except cc/cf
	/*
	#ifndef ONLINE_JUDGE
    	freopen("input.txt","r",stdin);
    	freopen("out.txt","w",stdout);
    #endif*/
	fastio();
	int a,b;
	cin>>a>>b;
	int s[3];
	s[0]=a+b;
	s[1]=a-b;
	s[2]=a*b;
	sort(s,s+3);
	cout<<s[2];

}

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

using namespace std;

int N;
int mem[100009];

bool ask (int i)
{
    if (mem[i] != 0)
        return mem[i] - 1;
    printf ("%d\n", i);
    fflush (stdout);
    char sir[20];
    scanf ("%s", sir);
    if (sir[0] == 'V') exit (0);
    mem[i] = (sir[0] == 'M') + 1;
    return (sir[0] == 'M');
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
bool t0 = ask (0), t1 = ask (N - 1);
int st = 0, dr = N - 1;
while (st < dr - 1)
{
    int mij = (st + dr) >> 1;
    int v1 = (st & 1) ^ t0, v3 = (dr & 1) ^ t1, v2 = (mij & 1) ^ ask (mij);
    if (v1 != v2) dr = mij, t1 = ask (mij);
    else st = mij, t0 = ask (mij);
//    printf ("%d %d %d %d\n", st, dr, t0, t1);
}
ask (st + 1);
return 0;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

int main() {
  ll N, D; cin >> N >> D;
  vector<vector<ll>> vec(N,vector<ll>(2));
  rep(i,N){
    cin >> vec[i][0] >> vec[i][1];
  }
  int ans=0;
  rep(i,N){
    if( vec[i][0]*vec[i][0] + vec[i][1]*vec[i][1] <= D*D){
      ans++;
    }
  }
  
  cout << ans << endl;
    
  
  
}


Measured memory_bytes: 14332
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		int init = 0;
		Scanner s = new Scanner(System.in);
		String string = s.next();
		for (int i = 0; i < string.length(); i++) {
			if (string.charAt(i) == '+') {
				init++;
			}
			else {
				init--;
			}
		}
		System.out.println(init);
	}

}


Measured memory_bytes: 21716
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>

long solve(long n, long k)
{
  return std::floor(std::log(n) / std::log(k)) + 1;
}

int main()
{
  long n, k;
  std::cin >> n >> k;

  std::cout << std::setprecision(20);
  std::cout << solve(n, k) << std::endl;
}


Measured memory_bytes: 640
rooms = [[[0 for r in range(10)] for f in range(3)] for b in range(4)]

n = int(input())
for i in range(n):
   b, f, r, v = map(int, input().split())
   rooms[b-1][f-1][r-1] += v

for i in range(4):
   for j in range(-3, 0):
       print("", *rooms[i][j])
   if i != 3:
       print("#"*20)


Measured memory_bytes: 5624
l = input().split()
ABCD = l[0]

A = int(ABCD[0])
B = int(ABCD[1])
C = int(ABCD[2])
D = int(ABCD[3])

#print(A, B, C, D)

def op(code, x, y):
    if code == 0:
        return x + y
    return x - y

def to_op(code):
    if code == 0:
        return '+'
    return '-'

for i in range(8):
    code1 = i % 2
    ans = op(code1, A, B)
    code2 = (i // 2) % 2
    ans = op(code2, ans, C)
    code3 = (i // 4) % 2
    ans = op(code3, ans, D)
    if ans == 7:
        print('{}{}{}{}{}{}{}=7'.format(
            A, to_op(code1),
            B, to_op(code2),
            C, to_op(code3),
            D
        ))
        break


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;

int main(){
  ll n,m;
  string S,T;
  cin >> n >> m >> S >> T;

  ll lcm = n*m/__gcd(n,m);
  if (n>m){
    swap(n,m);
    swap(S,T);
  }
  rep(i,n){
    
    if((i*m)%n==0){
      if(S[i] != T[(i*m)/n]){
        cout << -1 << endl;
        return 0;
      }
    }

  }
  
  cout << lcm << endl;



  return 0;
}


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

int n, u, k, v, a[101][101] = { 0 };

int main(){
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			a[u][v] = 1;
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << a[i][1];
		for (int j = 2; j <= n; j++) {
			cout << " " << a[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3084
def main():
    n,k=map(int,input().split())
    a=sorted(list(map(int,input().split())))
    mod=10**9+7
    ans=0
    for i in range(k-1,n):
        if i==k-1:
            c=1
        else:
            c=(c*i*pow(i-k+1,mod-2,mod))%mod
        ans+=(a[i]-a[n-i-1])*c
        ans%=mod
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 14044
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

int n;
double dp[101][30001];
double b,e,v,f;
int r;
int a[1001];
double mem[30000];
const int INF=1000000000;


double dfs(int idx,int runDist){
    if(!EQ(dp[idx][runDist],-1))return dp[idx][runDist];
    if(idx==n)
        return 0;
    double res=INF;
    double cost=0;
    int ndist=a[idx+1]-a[idx];
    res=min(res,dfs(idx+1,ndist)+mem[ndist-1]+b);
    // no change
    if(runDist>=1)
        res=min(res,dfs(idx+1,ndist+runDist)+mem[ndist+runDist-1]-mem[runDist-1]);
    else
        res=min(res,dfs(idx+1,ndist+runDist)+mem[ndist+runDist-1]);
    return dp[idx][runDist]=res;
}

int main(){
    while(cin>>n&&n!=0){
        a[0]=0;
        for(int i = 0; i < n; i++)cin>>a[i+1];
        cin>>b;
        cin>>r>>v>>e>>f;
        for(int i = 0; i < 101; i++)for(int j = 0; j < 30001; j++)dp[i][j]=-1;
        memset(mem,0,sizeof(mem));
        mem[0]=1.0/(v-f*(r));
        for(int i = 1; i < 10001; i++){
            if(i>=r)
                mem[i]=mem[i-1]+1.0/(v-e*(i-r));
            else
                mem[i]=mem[i-1]+1.0/(v-f*(r-i));
        }
        double res=dfs(0,0);
        printf("%.10f\n",res);
    }
    return 0;
}

Measured memory_bytes: 24000
class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n
        self.rank = [1] * n

    def get_root(self, i):
        while self.parent[i] != -1:
            i = self.parent[i]
        return i

    def is_same_tree(self, i, j):
        return self.get_root(i) == self.get_root(j)

    def merge(self, i, j):
        i = self.get_root(i)
        j = self.get_root(j)
        if i == j:
            return

        if self.rank[i] > self.rank[j]:
            self.parent[j] = i
            self.rank[i] = max(self.rank[i], self.rank[j] + 1)
        else:
            self.parent[i] = j
            self.rank[j] = max(self.rank[j], self.rank[i] + 1)

n, m = [int(i) for i in input().split()]
l = [[] for _ in range(m)]
for i in range(n):
    kl = [int(i)-1 for i in input().split()]
    for j in kl[1:]:
        l[j].append(i)
uf = UnionFind(n)
for i in l:
    for j in range(len(i) - 1):
        uf.merge(i[j], i[j + 1])

for i in range(n - 1):
    if not uf.is_same_tree(i, i + 1):
        print("NO")
        break
else:
    print("YES")

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

int main(){
	int n,t,mak=0,mbk=0,ma=0,mb=0,man=0,mbn=0;
	map <int,int>a,b;	
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>t;
		if(i%2==0){
			a[t]++;
			if(a[t]>mak){
				if(man!=t){
					ma=mak;
				}
				mak=a[t];
				man=t;
			}else if(a[t]>ma){
				ma=a[t];
			}
		}else{
			b[t]++;
			if(b[t]>mbk){
				if(man!=t){
					mb=mbk;
				}
				mbk=b[t];
				mbn=t;
			}else if(b[t]>mb){
				mb=b[t];
			}
		}
	}
	if(man==mbn){
		if(mak>mbk){
			cout<<n-mak-mb<<endl;
		}else if(mak==mbk){
			cout<<n-mak-max(ma,mb)<<endl;
		}else{
			cout<<n-mbk-ma<<endl;
		}
	}else{
		cout<<n-mak-mbk<<endl;
	}
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>
#include <map>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iterator>
#include <deque>
#include <bitset>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <functional>
#include <iterator>
#include <locale>
#include <memory>
#include <stdexcept>
#include <utility>
#include <fstream>
#include <ios>
#include <iosfwd>
#include <iomanip>
#include <istream>
#include <sstream>
#include <streambuf>
#include <complex>
#include <numeric>
#include <valarray>
#include <exception>
#include <limits>
#include <new>
#include <typeinfo>
#include <bitset>
#include <queue>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

int main() {
	long long a, b, c, happy=0;
	cin >> a;
	b = a / 500;
	happy = b * 1000;
	c = (a % 500) / 5;
	happy += c * 5;
	cout << happy;
}



Measured memory_bytes: 3620
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    ll N;
    cin >> N;
    ll odp = 0;
    for (ll d1 = 1; d1 * d1 <= N; ++d1)
    {
        if (N % d1 == 0)
        {
            ll d2 = N / d1 - 1;
            if (d2 != 0 && N / d2 == N % d2)
                odp += d2;
            if (d1 * d1 != N)
                if (d1 != 1 && N / (d1 - 1) == N % (d1 - 1))
                    odp += d1 - 1;

        }
    }
    cout << odp;
    return 0;
}


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

#define int long long

signed main(){
    int q, h, s, d;
    cin >> q >> h >> s >> d;
    int n;
    cin >> n;

    h = min(h, q*2);
    s = min(s, h*2);
    d = min(d, s*2);

    int ans = (n/2) * d;
    if(n % 2 == 1){
        ans += s;
    }

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



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

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int ans = 0;
  for(int i=1;i<=N;i++){
    int a = i%10;
    int b = (i/10)%10;
    int c = (i/100)%10;
    int d = (i/1000)%10;
    int e = (i/10000)%10;
    if(a+b+c+d+e>=A && a+b+c+d+e<=B){
      ans += i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 #include <math.h>
 using namespace std;
 
 int main(){
    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
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	b := make([]int, n)
	for i := range b {
		fmt.Scan(&b[i])
	}
	fmt.Println(seek(n, a, b))
}

func seek(n int, a, b []int) int {
	var s int
	for i := 0; i < n; i++ {
		var sum int
		for _, v := range a[:i+1] {
			sum += v
		}
		for _, v := range b[i:] {
			sum += v
		}
		if sum > s {
			s = sum
		}
	}
	return s
}


Measured memory_bytes: 512
import heapq
from collections import deque
n = int(input())
graph = [set() for _ in range(n)]

for _ in range(n - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    graph[a].add(b)
    graph[b].add(a)

nodes = [False for _ in range(n)]
values = list(map(lambda x: -int(x), input().split()))
print(-sum(values) + min(values))

heapq.heapify(values)
next_nodes = deque()
next_nodes.append(0)
while next_nodes:
    node = next_nodes.popleft()
    nodes[node] = -heapq.heappop(values)
    for g in graph[node]:
        if not (nodes[g]):
            next_nodes.append(g)

print(*nodes)

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

typedef unsigned long long ull;
ull pow[(int)3e5+10];

int main() {
	int n, m;
	string s;
	const ull rdx = 1e9+7;
	ull inv_r;
	ull h;
	int l, r;
	set<ull> u;

	pow[0] = 1;
	for(int i = 1; i < 3e5+10; i++) {
		pow[i] = pow[i-1] * rdx;
	}
	inv_r = 1;
	ull tmp = rdx;
	for(int i = 0; i < 64; i++) {
		inv_r *= tmp;
		tmp *= tmp;
	}
//	cout << inv_r << endl;

	cin >> n >> m;
	cin >> s;

	l = r = 0;
	h = s[0];
	for(int i = 0; i < m; i++) {
		string q;
		cin >> q;

		if(q == "L++") {
			h = h - s[l] * pow[r-l];
			l++;
		}
		else if(q == "L--") {
			l--;
			h = h + s[l] * pow[r-l];
		}
		else if(q == "R++") {
			r++;
			h = h * rdx + s[r];
		}
		else if(q == "R--") {
			h = h - s[r];
			r--;
			h *= inv_r;
		}
		u.insert(h);
	}

	cout << u.size() << endl;
}

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

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try{
	    boolean[] prime = new boolean[50000];
	    Arrays.fill(prime, true);
	    prime[1]=prime[0]=false;
	    for(int i=2; i<Math.sqrt(50000); i++)
		if(prime[i]){
		    for(int j=i*i; j<50000; j+=i)
			prime[j]=false;
		}
	    ArrayList<Integer> pr = new ArrayList<Integer>();	    
	    for(int i=2; i<50000; i++)
		if(prime[i])
		    pr.add(i);
	    
	    int[] nx = new int[50001];
	    for(int i=0; i<pr.size(); i++)
		for(int j=i; j<pr.size() && pr.get(i)+pr.get(j)<=50000; j++)
		    nx[pr.get(i)+pr.get(j)]++;
	    
	    int n;
	    while((n = Integer.valueOf(sc.readLine()))!=0)
		System.out.println(nx[n]);
	}catch (Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int x=1;
    for(int i=0;i<n-1;i++)if(s[i]!=s[i+1])x++;
    cout<<n-max(1,x-2*k)<<endl;
    return 0;
}

Measured memory_bytes: 512
n = int(input())
a = sorted(list(map(int, input().split())))
max = a[-1]
memo = ['Yes'] * (10**6+1)
ans = 0

for i, a_i in enumerate(a):
    if memo[a_i] == 'No':
        continue
    for j in range(a_i, max+1, a_i):
        memo[j] = 'No'
    if i != n-1 and a_i == a[i+1]:
        continue
    ans += 1

print(ans)

Measured memory_bytes: 32240
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rrep(i,n) for(ll i=(n)-1;i>=0;--i)
#define rep1(i,n) for(ll i=1;i<=(n);++i)
#define rrep1(i,n) for(ll i=(n);i>=1;--i)
#define fr first
#define sc second
#define pb push_back
#define INF 0xfffffff
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
struct edge{ll to,cap,rev; }; // ????????????????????????

vector<edge> G[100];
vector<edge> rG[100];
ll d[100];
ll a[100];
ll cnt=0;
void add_edge(ll from,ll to,ll cap){
	G[from].pb((edge){to, cap, rG[to].size() });
	rG[to].pb((edge){from, 0, G[from].size()-1} );
}

ll max_flow(ll V,ll E,ll s,ll t){
	ll res=0;
	memset( d, 0, sizeof(d) );
	memset( a, 0, sizeof(a) );
	d[s] = V;
	a[s]=-1;
	rep(i,G[s].size()){
		edge &e = G[s][i];
		a[e.to] += e.cap;
		rG[e.to][e.rev].cap = e.cap;
		e.cap = 0;
	}

	for(;;){
		ll v = -1;  //1
		ll dmax=-1;
		rep(i,V){
			if( a[i]>0 && dmax<d[i] && i!=t ){
				dmax=d[i];
				v = i;
			}
		}
		if(v < 0) return a[t];
		ll J=0; //2
		ll id;
		rep(i,G[v].size()){
			if( G[v][i].cap>0 && d[v] - d[G[v][i].to] == 1 ){
				id = i;
				J=1;
				break;
			}
		}
		if(!J) rep(i,rG[v].size()){
			if( rG[v][i].cap>0 && d[v] - d[rG[v][i].to] == 1 ){
				id = i;
				J=2;
				break;
			}
		}
	
		if(J){  //3
			edge &e = (J==1?G[v][id]:rG[v][id]);
			if(J==1){
				ll f = min(a[v], e.cap );
				a[v] -= f;
				e.cap -= f;
				rG[e.to][e.rev].cap += f;
				if(a[e.to]>=0) a[e.to] += f;
			}
			else{
				edge &efor = G[e.to][e.rev];
				ll f = min(a[v], e.cap);
				a[v] -= f;
				e.cap -= f;
				efor.cap += f;
				if(a[e.to]>=0) a[e.to] += f;
			}
		}

		else{  //4
			ll dmin=0xfffffff;
			rep(i,G[v].size()){
				if(G[v][i].cap>0) dmin = min(dmin,d[G[v][i].to]);
			}
			rep(i,rG[v].size()){
				if(rG[v][i].cap>0) dmin = min(dmin,d[rG[v][i].to]);
			}
			d[v] = dmin + 1;
		}
	}
}

ll V,E,A[1000],B[1000],C[1000];

void input(){
	scanf("%lld%lld",&V,&E);
	rep(i,E){
		scanf("%lld%lld%lld",&A[i],&B[i],&C[i]);
	}
}

int main()
{
	input();
	rep(i,V){
		G[i].clear(); rG[i].clear();
	}
	rep(i,E) add_edge(A[i], B[i], C[i]);
	cout<<max_flow(V,E,0,V-1)<<endl;
}

Measured memory_bytes: 3300
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0; i<n;i++)
using namespace std;
#define MAX 1e9
int INF=MAX*MAX;

typedef pair<int,int> pii;
typedef pair<pii,long long> piii;
vector<vector<long long>>d(501,vector<long long>(51,INF));
signed main(){
    int n,m;  cin>>n>>m;
    vector<vector<pii>>edge(500,vector<pii>());
    rep(i,m){
        int a,b,c; cin>>a>>b>>c;
        --a,--b;
        edge[a].push_back(pii(b,c));
        edge[b].push_back(pii(a,c));
    }
    int v0,a,b,c; cin>>v0>>a>>b>>c;
    priority_queue<piii,vector<piii>,greater<piii>>que;
    d[0][v0]=0;
    que.push(piii(pii(0,0),v0));
    while(!que.empty()){
        piii now=que.top(); que.pop();
        int v=now.second;
        int _v=(v*a+b)%c;
        if(d[now.first.second][v]<now.first.first)continue;
        for(int i=0; i<edge[now.first.second].size();i++){
            pii next=edge[now.first.second][i];
            if(d[next.first][_v]<=now.first.first+next.second*v)continue;
            d[next.first][_v]=now.first.first+next.second*v;
            que.push(piii(pii(d[next.first][_v],next.first),_v));
        }
    }
    int ans=INF;
    rep(i,51)if(d[n-1][i]!=INF){
        vector<vector<long long>>_d(501,vector<long long>(51,INF));
        _d[n-1][i]=d[n-1][i];
        que.push(piii(pii(d[n-1][i],n-1),i));
        while(!que.empty()){
            piii now=que.top(); que.pop();
            int v=now.second;
            int _v=(v*a+b)%c;
            if(_d[now.first.second][v]<now.first.first)continue;
            for(int i=0; i<edge[now.first.second].size();i++){
                pii next=edge[now.first.second][i];
                if(_d[next.first][_v]<=now.first.first+next.second*v)continue;
                _d[next.first][_v]=now.first.first+next.second*v;
                que.push(piii(pii(_d[next.first][_v],next.first),_v));
            }
        }
        rep(i,51)ans=min(ans,_d[0][i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6288
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
s = p[:x] + q[:y] + r
s.sort(reverse=True)
print(sum(s[:x + y]))


Measured memory_bytes: 23328