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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	int *num = new int[N];
	for (int i = 0; i < N; i++) {
		num[i] = 0;
	}

	int a, b;
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		num[a - 1]++;
		num[b - 1]++;
	}

	for (int i = 0; i < N; i++) {
		cout << num[i] << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int cap1 = A-B;
		
		int use = 0;
		
		if(cap1<C){
			use = cap1;
		}else{
			use = C;
		}
		
		System.out.println(C-use);
	}

}

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

const int nmax = 8;
int graph[nmax][nmax];

int dfs(int v, int N, bool visited[]) {

    bool all_visited = true;

    for (int i = 0; i < N; i++) {
        if (visited[i] == false) {
            all_visited = false;
        }
    }

    if (all_visited) {
        return 1;
    }

    int ret = 0;

    for (int i = 0; i < N; i++) {
        if (graph[v][i] == false) continue;
        if (visited[i]) continue;

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}


int main() {
    int N, M;
    cin >> N >> M;
    int a, b;

    rep(i, M) {
        cin >> a >> b;
        a--; b--;
        graph[a][b] = true;
        graph[b][a] = true;
    }

    bool visited[N];
    for (int i = 0; i < N; i++) {
        visited[i] = false;
    }

    visited[0] = true;
    cout << dfs(0, N, visited) << endl;
    
    return 0;
}

Measured memory_bytes: 256
def dfs(n, next_nodes, path, all_paths)
  if path.size == n
    all_paths.push(path.dup)
  else
    next_nodes[path[-1]].each do |node|
      if !path.include?(node)
        path.push(node)
        dfs(n, next_nodes, path, all_paths)
        path.pop
      end
    end
  end
end

n, m = gets.split.map(&:to_i)
next_nodes = (n + 1).times.map { [] }
for i in 0...m do
  a, b = gets.split.map(&:to_i)
  next_nodes[a].push(b)
  next_nodes[b].push(a)
end

all_paths = []
path = [1]
dfs(n, next_nodes, path, all_paths)

puts all_paths.size
#p all_paths


Measured memory_bytes: 3068
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 2e3+1;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll p = 29;


int main(){

    FASTIO;
    PRECISION; 

    int a,b;
    cin>>a>>b;

    cout<<(a*3+b)/2<<"\n";

}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

#define INF 1000000000

using namespace std;

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

    cout << (N * (N - 1) / 2) + (M * (M - 1) / 2) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){
  int N; string S; cin >> N >> S;

  for (int i = 0; i < S.length(); i++){
    char now = S[i] + N;
    if (now > 'Z'){
      now -= 'Z' - 'A' + 1;
    }
    cout << now;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int X, A, B;
  unused = scanf("%d %d %d", &X, &A, &B);

  if(B-A <= 0) printf("delicious");
  else if(B-A <= X) printf("safe");
  else printf("dangerous");

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#define ll long long

using namespace std;

int main(){

    string S;
    cin >> S;
    if(S == "Cloudy"){
        cout << "Rainy" << endl;
    }
    else if(S == "Rainy"){
        cout << "Sunny" << endl;
    }
    else{
        cout << "Cloudy" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
s = input()
if s == "AKIHABARA" or s == "AKIHABAR" or s == "AKIHABRA" or s == "AKIHBARA" or s == "AKIHABR" or s == "AKIHBAR" or s == "AKIHBRA" or s == "AKIHBR":
    print("YES")
elif s == "KIHABARA" or s == "KIHABAR" or s == "KIHABRA" or s == "KIHBARA" or s == "KIHBRA" or s == "KIHBAR" or s == "KIHABR" or s == "KIHBR":
    print("YES")
else:
    print("NO")

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

int main() {
  rep(i, 3) {
    int h, m, s, H, M, S;
    cin >> h >> m >> s >> H >> M >> S;
    int t = (3600 * H + 60 * M + S) - (3600 * h + 60 * m + s);
    cout << t / 3600 << " " << (t % 3600) / 60 << " " << t % 60 << endl;
  }
  return 0;
}


Measured memory_bytes: 3108
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        String[] str = lines[0].split(" ");
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        int c = Integer.parseInt(str[2]);
        int nums = 0;
        for (int i = a; a <= i && i <= b; i++){
            if(c % i == 0){
                nums++;
            }
        }
        System.out.println(nums);
       
   }
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
}


Measured memory_bytes: 26360
def main():
    import sys
    input=sys.stdin.buffer.readline
    n=int(input())
    b,M=37,998244353
    x,y=1,0
    f,h=[1],[0]
    f_add,h_add=f.append,h.append
    for i,c in enumerate(input()):
        x=x*b%M
        f_add(x)
        y=(y*b+c)%M
        h_add(y)
    ok,ng=0,n//2+1
    while ng-ok>1:
        mid=ok+ng>>1
        d={}
        for i in range(n-mid+1):
            k=(h[i+mid]-h[i]*f[mid])%M
            if k in d:
                if d[k]+mid<=i:
                    ok=mid
                    break
            else:
                d[k]=i
        else:
            ng=mid
    print(ok)
main()

Measured memory_bytes: 4148
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

x=sum(b)-sum(a)
y=0
for i in range(n):
    if a[i]<b[i]:
        y+=-((a[i]-b[i])//2)
print("No" if x<y else "Yes")

Measured memory_bytes: 40628
import java.io.*;

/**
 * Created by Ayushi on 18/08/2019.
 */

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        String[] temp = r.readLine().split(" ");
        int n = Integer.parseInt(temp[0]);
        String a = r.readLine();
        r.close();
        if (n >= 3200) System.out.println(a);
        else System.out.println("red");
    }
}


Measured memory_bytes: 23124
#include<iostream>
#include<climits>
#include<vector>
using namespace std;

vector< int > dp(100010);

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

	dp[0] = 0;
	
	for(int i = 1; i <= 100000; i++)
	{
		dp[i] = 100010;
		int power = 1;

		while(power <=i){
			dp[i] = min(dp[i], dp[i-power]+1);
			power *= 6;
		}
		power = 1;
		while(power <=i){
			dp[i] = min(dp[i], dp[i-power]+1);
			power *= 9;
		}
	}
	
	cout << dp[N] << endl;
	
	return 0;

}



Measured memory_bytes: 640
import io.{StdIn => in}

object Main extends App {
  val Array(n, a) = in.readLine.split(" ").map(_.toInt)
  val x = in.readLine.split(" ").map(_.toInt)
  val sumMax = math.max(x.max * n, a * n)
  val dp = Array.ofDim[Long](n+1, n+1, sumMax + 1)

  for(i <- 0 to n) dp(i)(0)(0) = 1
  for{
      i <- 1 to n; xi = i - 1
      j <- 1 to n; if j <= i
      k <- 1 to sumMax
    } {
      dp(i)(j)(k) =
        if(k < x(xi)) dp(i-1)(j)(k)
        else dp(i-1)(j)(k) + dp(i-1)(j-1)(k-x(xi))

      // if(k == sumMax) println(i + " " + j + " : " + dp(i)(j).mkString(" "))
    }

  val ans = (1 to n)./:(0L)((acc,j) => {
    // println(n + " " + j +  " " + a*j + " : " + dp(n)(j)(a*j))
    acc + dp(n)(j)(a*j)
  })
  println(ans)
}

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

#define INF 1e9
using namespace std;
using ll = long long;

int main() {

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

    int ans = 0;
    int right = 0;

    while (right < n) {
        if (ans == 0) {
            right += k;
        } else {
            right += k - 1;
        }
        ++ans;
    }
    
    cout << ans << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}
int INF=1e5;
int main(){
	startTime=clock();
	int h,w;
	cin >> h >> w;
	string s[h];
	int black=0;
	FOR(i,h){
			cin >> s[i];
	}
	int visited[h][w];
	FOR(i,h)
		FOR(j,w)
			if(s[i][j]=='#') black++;
	FOR(i,h) 
		FOR(j,w) 
			visited[i][j]=false;
	int distance[h][w];
	FOR(i,h) 
		FOR(j,w)
			 distance[i][j]=INF;

	vector<pair<int,int>> edges[h*w];
	int side[2]={-1,1};
	FOR(i,h){
		FOR(j,w){
			if(s[i][j]=='.'){
				for(auto r : side){
					if(i+r<h && i+r>=0 && s[i+r][j]=='.'){
						
						edges[(i+r)*w+j].PB(MP(i,j));
					}
					if(j+r<w && j+r>=0 && s[i][j+r]=='.'){
						edges[i*w+j+r].PB(MP(i,j));
					}
				}
			}
		}
	}
	
	queue<pi> q;
	q.push(MP(0,0));
	distance[0][0]=0;
	visited[0][0]=true;
	
	while(!q.empty()){
		int x=q.front().F;
		int y=q.front().S;
		q.pop();

		for(auto v : edges[x*w+y]){
			int a=v.F;
			int b=v.S;
			visited[a][b]=true;
			if(distance[a][b]> distance[x][y]+1) {
				distance[a][b]=distance[x][y]+1;
				q.push(v);
			}
		}
	}
	
	if(visited[h-1][w-1]==false)cout << -1 ;
	else cout << h*w-(black+distance[h-1][w-1]+1);

	return 0;
}

Measured memory_bytes: 3788
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
priority_queue<lint> x,y;
lint z[200100];
int main()
{
	memset(z,0,sizeof(z));
	int X,Y,a,b,c,t;
	cin>>X>>Y>>a>>b>>c;//x.push(0);y.push(0);
	rep(i,a){
		cin>>t;x.push(t);
	}
	rep(i,b){
		cin>>t;y.push(t);
	}
	rep(i,c){
		cin>>z[i];
	}
	sort(z,z+200050);reverse(z,z+200050);
	lint now=0,out=0;
	rep(i,X+Y) now+=z[i];out=now;
	rep(i,X+Y){
		now-=z[X+Y-i-1];
		lint n=x.top(),m=y.top();
		//cout<<x.size()<<y.size()<<endl;
		if((x.size()>a-X && n>m) || y.size()<=b-Y){
			now+=n;x.pop();
		}
		else{
			now+=m;y.pop();
		}
		//cout<<now<<endl;
		out=max(out,now);
	}
	cout<<out<<endl;
}


Measured memory_bytes: 4084
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

class Node{
public:
	int location;
	int p, l, r;
	Node() {}
};

class Point {
public:
	int id, x, y;
	Point() {}
	Point(int id, int x, int y) : id(id), x(x), y(y) {}
	bool operator < (const Point &p)const {
		return id < p.id;
	}

	void print() {
		printf("%d\n", id);
	}
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2) {
	return p1.x < p2.x;
}

bool lessY(const Point &p1, const Point &p2) {
	return p1.y < p2.y;
}

int makeKDTree(int l, int r, int depth) {
	if (!(l < r))return NIL;
	int mid = (l + r) / 2;
	int t = np++;
	if (depth % 2 == 0) {
		sort(P + l, P + r, lessX);
	} else {
		sort(P + l, P + r, lessY);
	}
	T[t].location = mid;
	T[t].l = makeKDTree(l, mid, depth + 1);
	T[t].r = makeKDTree(mid + 1, r, depth + 1);

	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int depth, vector<Point> &ans) {
	int x = P[T[v].location].x;
	int y = P[T[v].location].y;

	if (sx <= x && x <= tx && sy <= y && y <= ty) {
		ans.push_back(P[T[v].location]);
	}

	if (depth % 2 == 0) {
		if (T[v].l != NIL) {
			if (sx <= x) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		}
		if (T[v].r != NIL) {
			if (x <= tx) find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	} else {
		if (T[v].l != NIL) {
			if (sy <= y) find(T[v].l, sx, tx, sy, ty, depth + 1, ans);
		}
		if (T[v].r != NIL) {
			if (y <= ty) find(T[v].r, sx, tx, sy, ty, depth + 1, ans);
		}
	}
}

int main() {
	int x, y;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &x, &y);
		P[i] = Point(i, x, y);
		T[i].l = T[i].r = T[i].p = NIL;
	}

	np = 0;

	int root = makeKDTree(0, N, 0);

	int q;
	scanf("%d", &q);
	int sx, tx, sy, ty;
	vector<Point> ans;
	for (int i = 0; i < q; i++) {
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		ans.clear();
		find(root, sx, tx, sy, ty, 0, ans);
		sort(ans.begin(), ans.end());
		for (int j = 0; j < ans.size(); j++) {
			ans[j].print();
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 15988
//RTn_E
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define _file freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long
#define ld long double
#define sp setprecision 
#define pb push_back
#define F first
#define S second
#define mk make_pair
#define pii pair < int , int >
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;
const int maxn = 4e4 + 100;
const ll inf = 1e18;

//Main CODE :/\

int main(){
	ios_base :: sync_with_stdio(false) , cin.tie(0) , cout.tie(0);
	int H , W , d , i1 , j1;
	cin >> H >> W >> d >> i1 >> j1;
	string t , s;
	cin >> t >> s;
	int p1 = j1 , p11 = j1 , p2 = i1 , p22 = i1;
	for (int i = 0; i < d; i++){
		if (t[i] == 'R')
			p1++;
		else if (t[i] == 'L')
			p11--;
		else if (t[i] == 'D')
			p2++;
		else if (t[i] == 'U')
			p22--;
		if (p1 > W || p11 < 1 || p2 > H || p22 < 1)
			return cout << "NO\n" , 0;
		if (s[i] == 'R')
			p11 = min(p11 + 1 , W);
		if (s[i] == 'L')
			p1 = max(p1 - 1 , 1);
		if (s[i] == 'D')
			p22 = min(p22 + 1 , H);
		if (s[i] == 'U')
			p2 = max(p2 - 1 , 1);	
		if (p1 > W || p11 < 1 || p2 > H || p22 < 1)
			return cout << "NO\n" , 0;
	}

	cout << "YES\n";
	return 0;
}
//The_End																											 
//Game Over :D
																	


Measured memory_bytes: 920
h,w,c,max;
int *_M;
int D(x,y,c,n){
	int r=1;
	_M[x+(w+2)*y]=n;
	if(_M[x-1+(w+2)*y]==c)r+=D(x-1,y,c,n);
	if(_M[x+1+(w+2)*y]==c)r+=D(x+1,y,c,n);
	if(_M[x+(w+2)*(y-1)]==c)r+=D(x,y-1,c,n);
	if(_M[x+(w+2)*(y+1)]==c)r+=D(x,y+1,c,n);
	return r;
}
E(d,M)int *M;{
	if(d==4&&M[1+w+2]==c)return;
	int *m=malloc(4*(w+2)*(h+2));
	if(d==4){
		memcpy(m,M,4*(w+2)*(h+2));_M=m;
		D(1,1,m[1+w+2],c);
		int k=D(1,1,m[1+w+2],-1,m);
		if(max<k)max=k;
	}else{
		int i=1;
		for(;i<7;i++){
			if(M[1+w+2]==i)continue;
			memcpy(m,M,4*(w+2)*(h+2));_M=m;
			D(1,1,m[1+w+2],i,m);
			E(d+1,m);
		}
	}
	free(m);
}
a[100];
main(i,j){for(;scanf("%d%d%d",&h,&w,&c),c;printf("%d\n",max)){
	memset(a,0,4*(w+2)*(h+2));
	for(j=1;j<h+1;j++)for(i=1;i<w+1;i++)scanf("%d",a+i+(w+2)*j);
	E(max=0,a);
}}

Measured memory_bytes: 620
//56
#include<iostream>

using namespace std;

int a[7],b[7];

int dfs(int n,int m){
  if(m==0){
    return n==0;
  }else{
    int s=0;
    for(int i=0;i<=b[m-1];i++){
      s+=dfs(n-a[m-1]*i,m-1);
    }
    return s;
  }
}

int main(){
  for(int m;cin>>m,m;){
    for(int i=0;i<m;i++){
      cin>>a[i]>>b[i];
    }
    int g;
    cin>>g;
    while(g--){
      int n;
      cin>>n;
      cout<<dfs(n,m)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N;
ll s[200001], ans = llmax;

int main() {
	cin >> N;
	for (int i = 1; i != N + 1; ++i) {
		cin >> s[i];
		s[i] += s[i - 1];
	}
	for (int i = 2; i != N - 1; ++i) {
		int l = 0, r = i;
		ll L[2][2], R[2][2];
		while (l + 1 != r) {
			int k = (l + r) / 2;
			if (s[k] < s[i] / 2)
				l = k;
			else
				r = k;
		}
		L[0][0] = s[l];
		L[0][1] = s[i] - s[l];
		L[1][0] = s[r];
		L[1][1] = s[i] - s[r];
		l = i; r = N;
		while (l + 1 != r) {
			int k = (l + r) / 2;
			if (s[k] - s[i] < (s[N] - s[i]) / 2)
				l = k;
			else
				r = k;
		}
		R[0][0] = s[l] - s[i];
		R[0][1] = s[N] - s[l];
		R[1][0] = s[r] - s[i];
		R[1][1] = s[N] - s[r];
		for (int j = 0; j != 2; ++j) {
			for (int k = 0; k != 2; ++k) {
				ans = min(max({ L[j][0],L[j][1],R[k][0],R[k][1] }) - min({ L[j][0],L[j][1],R[k][0],R[k][1] }), ans);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<algorithm>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<iostream>
#include<istream>
#include<map>
#include<math.h>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
long long n,W,w[1000],v[1000],dp[110][100010];
int main(){
	cin>>n>>W;
	for (long long i=1;i<=n;i++) cin>>w[i]>>v[i];
	for (long long i=1;i<=n;i++)
		for (long long j=1;j<=W;j++)
			if (w[i]>j)
				dp[i][j]=dp[i-1][j];
			else
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
	cout<<dp[n][W]<<endl;
	return 0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
/*using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define rep(i,l,r) for(int i=l;i<r;i++)
#define bep(i,l,r) for(int i=l;i>=r;i--)
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define el '\n'
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define mr  make_pair

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
//int powmod(int a,int b) {int res=1;if(a>=mod)a%=mod;for(;b;b>>=1){if(b&1)res=res*a;if(res>=mod)res%=mod;a=a*a;if(a>=mod)a%=mod;}return res;}
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
       int n,m;
       cin>>n>>m;
       long double arr[n];
       int sum = 0;
       rep(i,0,n){
       cin>>arr[i];
       sum+=arr[i];
       }
       int ct = 0;
       rep(i,0,n)
       {
       		if(arr[i]>=(sum/(4.0*m)))
       		ct++;
       } 
       cout<<((ct>=m)?"Yes":"No")<<el;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,op,an;
	
	while(1) {
		scanf("%d %c %d", &a, &op, &b);
		
		if (op == '+') {
			an = a + b;
		}
		else if (op == '-')
			an = a - b;
		else if (op == '*')
			an = a * b;
		else if (op == '/')
			an = a / b;
		else {
			break;
		}
		
		printf("%d\n",an);
	}
	
	return 0;
}

Measured memory_bytes: 600
n , m = map(int, input().split())
bridge = []
for i in range(m):
    a , b = map(int, input().split())
    bridge.append((a,b))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(n)
ans1 = n*(n-1)//2
ans = []
for i in range(m):
    ans.append(ans1)
    a1,b1=bridge[m-1-i]
    a1-=1
    b1-=1
    if not uf.same(a1,b1):
        ans1 -= uf.size(a1)*uf.size(b1)
    uf.union(a1,b1)

ans.reverse()
for i in ans:
    print(i)


Measured memory_bytes: 28572
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

void ok(){
  cout << "Yes" << endl;
  exit(0);
}

void ng(){
  cout <<  "No" << endl;
  exit(0);
}

Int n, l;
int main(){
  cin >> n;
  Int longest = 0;
  Int sum = 0;
  for(int i = 0;i < n;i++){
    cin >> l;
    longest = max(l, longest);
    sum += l;
  }
  if(longest < sum - longest)ok();
  else ng();
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, hit, sum;
	int i;
	
	while (1){
		sum = 0;
		scanf("%d", &n);
		if (n == 0)return (0);
		for (i = 0; i < n / 4; i++){
			scanf("%d", &hit);
			sum += hit;
		}
		
		printf("%d\n", sum);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;
int main()
{
    int h,n;
    cin >> h >> n;
    vector<int> dp(h+1,INF);
    dp[h] = 0;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        for(int j = h;j>=0;--j){//このdpは配るしかできない
        //なぜなら、体力をa削ることでオーバーキルしても良いから（dp[j] がdp[0]に遷移するかどうかはわかるが、dp[0]に遷移するようなjがいくつあるか、それがなにかがわからない
            dp[max(j-a,0)] = min(dp[j]+b,dp[max(j-a,0)]);
        }
    }
    cout << dp[0] << endl;

    return 0;
}

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

using namespace std;
using ll = long long;

int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  ll ans = 0;
  cin >> n;
  vector<ll> v(n);
  for (int i = 0; i < n; ++i)  {
    int a, b;
    cin >> a >> b;
    v[i] = a + b;
    ans -= b;
  }
  sort(v.begin(), v.end(), greater<int>()); //降順

  for (int i = 0; i < n; i += 2) {
    ans += v[i];
  }


  cout << ans << "\n";
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
        string s;
        cin >> s;
        vector<vector<int>> node(20);
        int k = (int)s.size();
        int left = 0;
        bool flag = false;
        for (int j = 0; j < k; j++){
            if (s[j] == '[') {
                left++;
                flag = false;
            }
            if (s[j] == ']'){
                if (flag){
                    int w = (int)node[left].size();
                    vector<int> tmp;
                    for (int z = 0; z < w; z++){
                        tmp.push_back(node[left][z]);
                    }
                    sort(tmp.begin(), tmp.end());
                    int ans = 0;
                    for (int z = 0; z <= w/2; z++) ans += tmp[z];
                    node[left-1].push_back(ans);
                    node[left].clear();
                    left--;
                }
                else{
                    left--;
                    flag = true;
                    int x = 0;
                    for (int z = 1; z <= 4; z++){
                        if (j - z < 0) break;
                        if (0 <= s[j-z] - '0' && s[j-z] - '0' <= 9) x += (s[j-z] - '0') * pow(10, z-1);
                        else break;
                    }
                    node[left].push_back(x/2 + 1);
                }
            }
        }
        cout << node[0][0] << endl;
    }
}


Measured memory_bytes: 3432
a,b = map(int,input().split())
A = []
B = []
for i in range(b):
    A.append(a)
for i in range(a):
    B.append(b)
c = []
c.append(A)
c.append(B)
c.sort()
for i in range(len(c[0])):
    c[0][i] = str(c[0][i])
print(''.join(c[0]))

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

int main() {
    ll n,k;
    std::cin >> n>>k;
    vector<ll> p(n);
    vector<ll> sum(n,0);
    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
        if(i>0){
            sum[i] = sum[i-1] + (p[i]>p[i-1]);
        }
    }
    if(n==k){
        std::cout << 1 << std::endl;
        return 0;
    }
    ll cnt = 0;
    ll res = 0;
    
    set<ll> se;
    for (int i = 0; i < k; i++) {
        se.insert(p[i]);
    }
    if(sum[k-1]-sum[0]>=k-1){
        cnt++;
    }
    
    ll sub = 0;
    for (int i = 1; i+k-1 < n; i++) {
        bool ok = *se.begin() == p[i-1];
        se.erase(p[i-1]);
        se.insert(p[i+k-1]);

        if(sum[i+k-1]-sum[i]>=k-1){
            cnt++;
        }else if(ok && *se.rbegin()==p[i+k-1]){
            sub++;
        }else{
       
            
        }
    }
    // std::cout << cnt << std::endl;
    
    std::cout << n-k+1-sub-max((ll)0,(cnt-1)) << std::endl;
    
    
}


Measured memory_bytes: 12672
import java.util.*;

public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> li = new ArrayList<Integer>();
        for(int i=0;i<3;i++){
            li.add(sc.nextInt());
        }
        Collections.sort(li);
        System.out.println(li.get(2) - li.get(0));
    }
}

Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int D; cin >> D;
    vector<int> c(27);
    for (int i = 1; i < 27; i++) {
        cin >> c[i];
    }

    vector<vector<int>> s(D+1, vector<int> (27));
    for (int i = 1; i < D+1; i++) {
        for (int j = 1; j < 27; j++) {
            cin >> s[i][j];
        }
    }

    vector<int> t(D+1);

    ll score = 0;
    vector<int> last(27, 0);
    int M;
    int MJ;
    for (int i = 1; i < D+1; i++) {
        M = 0;
        for (int j = 1; j < 27; j++) {
            if(s[i][j] + c[j] * (i-last[j]) > M){
                M = s[i][j] + c[j] * (i-last[j]);    
                MJ = j;
            }
        }
        t[i] = MJ;
        score += s[i][MJ];
        last[MJ] = i;
        for (int j = 1; j < 27; j++) {
            score -= c[j] * (i - last[j]);
        }
    }
    
    //ここまでが貪欲解の導出
    //ここから微調整

    // そのコンテストが開催された日の集合
    vector<set<int>> day(27, set<int> ());
    for (int i = 1; i < D+1; i++) {
        day[t[i]].insert(i);
    }
    for (int i = 1; i < 27; i++) {
        day[i].insert(0);
        day[i].insert(D+1);
    }

    //更新作業
    //i回目の更新では、i%D日目の開催をt[i%D]+7i%26に変更し、差分が正だったら更新
    int CNT = 100000;
    int dd, qq;
    int tq;
    int d1, d2;
    auto itr1 = day[1].lower_bound(0);
    dd = 1; tq = 1;
    ll diff;
    for (int i = 0; i < CNT; i++) {
        diff = 0;
        
        day[t[dd]].erase(dd);

        qq = (t[dd] + tq) % 26;
        if(qq == 0) qq = 26;

        diff += s[dd][qq];
        diff -= s[dd][t[dd]];
        
        itr1 = day[qq].lower_bound(dd);
        d2 = *itr1;
        itr1--;
        d1 = *itr1;
        diff += c[qq] * (dd - d1) * (d2 - dd);

        itr1 = day[t[dd]].lower_bound(dd);
        d2 = *itr1;
        itr1--;
        d1 = *itr1;
        diff -= c[t[dd]] * (dd - d1) * (d2 - dd);

        //差分が正なら更新
        if(diff > 0){
            // tとsetを更新
            t[dd] = qq;
            day[qq].insert(dd);
        }
        else{
            day[t[dd]].insert(dd);
        }

        //ddとqqを更新
        dd++; tq = tq * 7;
        if(dd == D+1) dd = 1;
        if(tq >= 27) tq = tq % 26;

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

}

Measured memory_bytes: 3768
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>

using namespace std;

#define PI 3.14159265358979323846//264338327950

int main() {
	long double A, B, H, M;

	cin >> A >> B >> H >> M;

	long double h, m,kaku;
	m = (long double)M / 60 * 2 * PI;
	h = ((long double)H / 12 + (long double)M / 720) * 2 * PI;
	kaku = fabs(m - h);

	long double ans;

	ans = A * A + B * B - 2 * A * B * cosl(kaku);
	ans = sqrt(ans);
	cout << fixed << setprecision(20) << ans << endl;

	return 0;
}

Measured memory_bytes: 4124
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> f(n);
  rep(i, n){
    int add = 0;
    rep(j, 10){
      int in;
      cin >> in;
      add <<= 1;
      if(in == 1)add++;
    }
    f.at(i) = add;
  }
  vector<vector<int>> p(n, vector<int>(11));
  rep(i, n){
    rep(j, 11){
      cin >> p.at(i).at(j);
    }
  }
  int ans = -2e9;
  rep2(bit, 1, 1 << 10){
    int add = 0;
    rep(i, n){
      int now = bit & f.at(i);
      auto fc = [] (int n)->int{
        int res = 0;
        while(n != 0){
          if(n % 2 == 1) res++;
          n /= 2;
        }
        return res;
      };
      int co = fc(now);
      add += p.at(i).at(co);
    }
    ans = max(ans, add);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){

int N, K;
  cin >> N >> K;

  int sum = 0;
  
  for(int i = 0;i < N;i++){
  int x;
    cin >> x;
    sum += min(x, (K - x));
  }
  
  cout << sum * 2 << endl;

return 0;
  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
int a;scanf("%d",&a);
int L=a/100;
int R=a%100;
if(1<=L&&L<=12){
if(1<=R&&R<=12)printf("AMBIGUOUS\n");
else printf("MMYY\n");
}else{
if(1<=R&&R<=12)printf("YYMM\n");
else printf("NA\n");
}
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = int(b) - 1; i >= (int)(a); --i)
using pii = pair<int, int>;
using vi = vector<int>;

int solve(int n) {
	vi a(n);
	rep(i, 0, n) {
		string s;
		cin >> s;
		a[i] = s.size();
	}

	const vi seq = { 5, 7, 5, 7, 7 };
	rep(i, 0, n) {
		int s = 0;
		int idx = 0;
		bool ng = false;
		rep(j, i, n) {
			s += a[j];
			if (s == seq[idx]) {
				s = 0;
				idx++;
				if (idx == seq.size())break;
			}
			else if (s > seq[idx]) {
				ng = true;
				break;
			}
		}
		if (!ng) {
			return i + 1;
		}
	}
	return -1;
}

signed main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0) break;
		cout << solve(n) << endl;
	}
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-9
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n;
ll k,a[N];
int o[62];
ll dp[62][2];

ll solve(int i, int j){
    if(i < 0) return 0;
    ll &ret = dp[i][j];
    if(~ret) return ret;
    ret = 0;
    if(j) ret = max(o[i], n - o[i]) * (1ll<<i) + solve(i-1, 1);
    else{
        int x = (k & (1ll<<i)) > 0;
        ret = o[i] * (1ll<<i) + solve(i-1, x);
        if(x) ret = max(ret, (n - o[i]) * (1ll<<i) + solve(i-1, 0));
    }
    return ret;
}

int main(){
    cin >>n >>k;
    lp(i,1,n){
        cin >>a[i];
        lp(j,0,60) o[j] += (a[i] & (1ll << j)) > 0;
    }
    memset(dp, -1, sizeof dp);
    cout <<solve(60, 0);
}

/*
uniform_int_distribution<type>(l, r)(rng)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
*/


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

int h, w, n;
bool memo[31][31];
int dx[2] = {-1,1};
int dy[2] = {0,0};

void debug(const vector<string>& v){
	cout << "[debug]" << endl;
	for(int y=0 ; y < h ; y++ ){
		cout << v[y] << endl;
	}
	cout << endl;
}

bool is_clear(const vector<string>& v){
	for(int x=0 ; x < w ; x++ ){
		if( v[h-1][x] != '.' ) return false;
	}
	return true;
}

bool fall(vector<string>& v){
	bool change = false;
	for(int y=1 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			while( true ){
				bool flag = false;
				if( y-1 >= 0 && v[y-1][x] != '.' && v[y][x] == '.' ){
					swap( v[y-1][x] , v[y][x] );
					y--;
					change = true;
					flag = true;
				}
				if( !flag ) break;
			}
		}
	}
	return change;
}

void check_row(int x, int y, const vector<string>& v, char c){
	int cnt = 0;
	for(int sx=x ; sx < x+n && sx < w ; sx++ ){
		if( v[y][sx] == c ){
			cnt++;
		}else{
			break;
		}
	}
	if( cnt == n ){
		for(int sx=x ; sx < x+n && sx < w ; sx++ ){
			memo[y][sx] = true;
		}
	}
}

void check_col(int x, int y, const vector<string>& v, char c){
	int cnt = 0;
	for(int sy=y ; sy < y+n && sy < h ; sy++ ){
		if( v[sy][x] == c ){
			cnt++;
		}else{
			break;
		}
	}
	if( cnt == n ){
		for(int sy=y ; sy < y+n && sy < h ; sy++ ){
			memo[sy][x] = true;
		}
	}
}

bool remove(vector<string> v){
	fall(v);
	while( true ){
		bool change=false;
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				memo[y][x] = false;
			}
		}
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				if( v[y][x] != '.' ){
					check_col(x, y, v, v[y][x]);
					check_row(x, y, v, v[y][x]);
				}
			}
		}
		for(int y=0 ; y < h ; y++ ){
			for(int x=0 ; x < w ; x++ ){
				if( memo[y][x] ){
					change = true;
					v[y][x] = '.';
				}
			}
		}
		fall(v);
		if( !change ) break;
	}
	return is_clear(v);
}

bool solve(vector<string> v){
	bool flag = false;
	for(int y=0 ; y < h ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			for(int i=0 ; i < 2 ; i++ ){
				int mx = x + dx[i];
				int my = y + dy[i];
				if( mx < 0 || my < 0 || w <= mx || h <= my ) continue;
				if( v[y][x] == v[my][mx] ) continue;
					
				swap( v[y][x] , v[my][mx] );
				flag = remove(v);
				swap( v[y][x] , v[my][mx] );
				if( flag ){
					return true;
				}
			}
		}
	}
	return false;
}

int main(){
	cin >> h >> w >> n;
	vector<string> v(h);
	for(int y=0 ; y < h ; y++ ){
		cin >> v[y];
	}
	bool ans = solve(v);
	cout << (ans? "YES" : "NO") << endl;
}

Measured memory_bytes: 1216
// 参考：解説放送
// 以下の3つを満たす数をfunc(S, X)とする
//   1. a + b <= S
//   2. a xor b <= X
//   3. aとb, どちらにビットを立ててもいいときは、aに立てる

// この後は典型的なdigit DP
// func(S, X) = func(S/2, X/2) 　　// a, bが両方2の倍数
//            + func((S-1)/2, (X-1)/2)
//            + func((S-2)/2, X/2)
// 
// func(N, N)が答

#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll MOD = 1000000007;
map<pair<ll,ll>, ll> cache;
ll func(ll S, ll X) {
    if (cache.count(mp(S,X))) return cache[mp(S,X)];
    if (S == 0 && X == 0) return 1;
    if (S == 1 && X == 0) return 1;
    if (S == 0 && X == 1) return 1;
    ll ans = func(S/2, X/2) % MOD;
    if (S >= 1 && X >= 1) {
        ans = (ans + func((S-1)/2, (X-1)/2)) % MOD;
    }
    if (S >= 2) {
        ans = (ans + func((S-2)/2, X/2)) % MOD;
    }
    cache[mp(S,X)] = ans;
    return ans;
}

int main(void)
{
    cin.sync_with_stdio(false);
    ll N;
    cin >> N;
    cout << func(N,N) << endl;

    return 0;
}


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

using namespace std;

int main(){
    int k, q;
    while(cin >> k >> q){
        vector<int> d(k);
        for(auto& t : d) cin >> t;
        for(int _=0;_<q;_++){
            long long n, x, m; cin >> n >> x >> m;
            if(d.empty()){
                cout << 0 << endl;
                continue;
            }
            long long sum = 0;
            for(auto& t : d) sum += (t%m ? t%m : m);
            long long e = x + (n-1)/k * sum;
            for(int i=0;i<(n-1)%k;i++){
                e += (d[i]%m ? d[i]%m : m);
            }
            cout << (n-1)-e/m+x/m << endl;
        }
    }
}

Measured memory_bytes: 256
import numpy as np


def get_coin(button_sizes):
    largest_button = np.argmax(button_sizes)
    earned = button_sizes[largest_button]
    button_sizes[largest_button] -= 1
    return earned


if __name__ == '__main__':
    button_sizes = np.array([int(x) for x in input().split(' ')])
    coin = 0
    for i in range(2):
        coin += get_coin(button_sizes)
    print(coin)


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

using namespace std;

typedef long long int64;

int dp[300][300];

int grundy(int x, int y)
{

  if(~dp[x][y]) return (dp[x][y]);
  set< int > beet;
  for(int i = 1; 2 * i <= x; i++)
    beet.insert(grundy(x - 2 * i, y + i));
  for(int i = 1; 2 * i <= y; i++)
    beet.insert(grundy(x + i, y - 2 * i));
  int ei = 0;
  while(beet.count(ei)) ++ei;
  return (dp[x][y] = ei);
}

int main()
{
  memset(dp, -1, sizeof(dp));

  // 0 : Bruwn
  // 非 0 : Alice

  int64 X, Y;
  cin >> X >> Y;
  if(abs(X - Y) <= 1) cout << "Brown" << endl;
  else cout << "Alice" << endl;


}

Measured memory_bytes: 640
n = int(input())
A = input()
B = input()
C = input()
a = [0] * n
for i in range(n):
  if (A[i] == B[i] and A[i] != C[i]):
    a[i] += 1
  elif (A[i] == C[i] and A[i] != B[i]):
    a[i] += 1
  elif (B[i] == C[i] and A[i] != B[i]):
    a[i] += 1
  elif (A[i] == B[i] and B[i] == C[i]):
    a[i] += 0
  else:
    a[i] += 2

print(sum(a))


Measured memory_bytes: 3064
def ols(): return input()
def oli(): return map(int, input().split())
def olai(): return list(map(int, input().split()))
def olas(): return list(input().split())
def mlai(L): return [int(input()) for _ in range(L)]
def mlas(L): return [input() for _ in range(L)]

n, m = oli()
print(n*(n-1)//2 + m*(m-1)//2)


Measured memory_bytes: 3060
class BIT
  def initialize(n)
    @tree = Array.new(n + 1, 0)
  end

  def add(i, diff)
    while i < @tree.size
      @tree[i] += diff
      i += (i & -i)
    end
  end

  def sum(i)
    t = 0
    while i > 0 do
      t += @tree[i]
      i -= (i & -i)
    end
    return t
  end
end

n, k = gets.chomp.split.map(&:to_i)
ps = gets.chomp.split.map(&:to_i)
es = ps.map do |p|
  p * (p + 1) / 2.0 * (1.0 / p)
end

bit = BIT.new(n)
1.upto(n) do |i|
  bit.add(i, es[i - 1])
end

m = bit.sum(k)
k.upto(n) do |i|
  t = bit.sum(i) - bit.sum(i - k)
  m = [t, m].max
end

puts m

Measured memory_bytes: 22672
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

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

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios_base::sync_with_stdio(0);
  int c[6] = {1, 5, 10, 50, 100, 500};
  int in[6];
  for(int i = 0; i < 6; i++) cin >> in[i];
  int sum = 0;
  for(int i = 0; i < 6; i++) sum += in[i] * c[i];
  if(sum >= 1000) cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}

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



int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
     int ma = a[0];
    long long ans = 0;
    for(int i=0;i<n;i++)
        if(a[i]<ma) ans+=(ma-a[i]);
        else ma=max(ma,a[i]);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3952
#include<stdio.h>

int main(void){
    int H,W,i,j;
    
    while(1){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0){break;}
    
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            printf("#");
        }
        printf("\n");
    }
     printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2692
N = int(input())
A = list(map(int, input().split()))

res = 0

num = [0]*(N)
cnt = [0]*(N)

for i in range(N):
    if A[i] > N:
        res += 1
    else:
        cnt[A[i]-1] += 1

for i in range(N):
    if cnt[i] < i+1:
        res += cnt[i]
    else:
        res += cnt[i] - (i+1)

print(res)

Measured memory_bytes: 14232
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
p = set(list(map(int, input().split())))

if x not in p:
    print(x)
    exit()

xp = x
xm = x
while True:
    xp += 1
    xm -= 1
    if xp in p and xm in p:
        continue
    elif xm not in p:
        print(xm)
        break
    else:
        print(xp)
        break


Measured memory_bytes: 61900
from sys import stdin
n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
point = 0
for i in range(101):
    for j in range(101):
        flag = True
        kizyun = False
        count = 0
        for a,b,c in li:
            if c != 0:
                count += 1
                if kizyun == False:
                    h = c+abs(a-i)+abs(b-j)
                    if h-abs(a-i)-abs(b-j) != c:
                        flag = False
                    kizyun = True
                else:
                    k = c+abs(a-i)+abs(b-j)
                    if h != k and kizyun == True:
                        flag = False
        if count == 1:
            print(a,b-1,c+1)
            exit()
        if flag == True:
            point += 1
            print(i,j,h)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long s = sc.nextLong();
        long a, b, c, d;
        double n = Math.sqrt(s);
        long intNum = (int)Math.ceil(n);
        long diff = (intNum * intNum) - s;
        a = intNum;
        b = 1;
        c = diff;
        d = intNum;
        if(diff == 0) {
            b = 0;
            c = 0;
        }
        System.out.println("0 0 " + a + " " + b + " " + c + " " + d);
    }
}


Measured memory_bytes: 23380
N, W = [int(i) for i in input().split()]
weight, value = [0] * N, [0] * N
for i in range(N):
    weight[i], value[i] = [int(i) for i in input().split()]

dp = [[0] * (W+1) for _ in range(N)]
dp[0][weight[0]] = value[0]
for i in range(1, N):
    for w in range(W+1):
        if w-weight[i] >= 0:
            dp[i][w] = max(dp[i-1][w-weight[i]]+value[i], dp[i-1][w])
        else:
            dp[i][w] = dp[i-1][w]
print(max(dp[N-1]))

Measured memory_bytes: 119148
import java.util.*;

public class Main {

    public static void main(String[] args) {
        exec();
    }

    static void exec() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt(); 
        }
        int maxv = -2000000000;
        int minv = a[0];

        for (int i = 1; i < a.length; i++) {
            maxv = Math.max(maxv, a[i]-minv);
            minv = Math.min(minv, a[i]);
        }

        System.out.println(maxv);

    }
}


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

#define MAX 1000000
#define INF 1000000000

int dp1[MAX + 1], dp2[MAX + 1];

int main()
{
    for (int i = 1; i <= MAX; i++)
    {
        dp1[i] = INF;
        dp2[i] = INF;
    }

    for (int n = 1; n * (n + 1) * (n + 2) / 6 <= MAX; n++)
    {
        int a = n * (n + 1) * (n + 2) / 6;
        for (int i = a; i <= MAX; i++)
        {
            dp1[i] = min(dp1[i], dp1[i - a] + 1);
        }
        if (a % 2 == 0)
            continue;
        for (int i = a; i <= MAX; i++)
        {
            dp2[i] = min(dp2[i], dp2[i - a] + 1);
        }
    }

    while (1)
    {
        int n;
        cin >> n;
        if (n == 0)
            break;
        cout << dp1[n] << " " << dp2[n] << endl;
    }
    return 0;
}


Measured memory_bytes: 10828