akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String x = in.next() + in.next();
            int y = 0;
            for (int i = 0; i < x.length(); i++) {
                y += (x.charAt(i) - '0');
                if (i + 1 != x.length()) y *= 10;
            }
            int z = (int) Math.sqrt(y);
            if (z * z == y) {
                out.print("Yes");
                return;
            }
            out.print("No");
        }

    }

    static class FastScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        public FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

    }
}



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

int main(){
    int n;
    cin >> n;
    int s = 0;
    vector<int> v(n),c(n);
    rep(i,n){
        cin >> v[i];
    }
    rep(i,n){
        cin >> c[i]; 
    }
    rep(i,n){
        if(v[i] > c[i]) s += v[i] - c[i]; 
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> a(m);
    rep(i,m){
        cin >> a[i].first >> a[i].second;
    }
    vector<int> w[100001];
    rep(i,m){
        w[a[i].first-1].push_back(a[i].second);
    }
    // vector<map<int,int>> q(n); 
    rep(i,n){
        sort(w[i].begin(),w[i].end());
        // rep(j,w[i].size()){
        //     q[i][w[i][j]] = j+1;
        // }
    }
    rep(i,m){
        printf("%06d%06d\n",a[i].first,int(lower_bound(w[a[i].first-1].begin(),w[a[i].first-1].end(),a[i].second)-w[a[i].first-1].begin()+1));
    }


    return 0;
}

Measured memory_bytes: 9288
#include <bits/stdc++.h>
#include <queue>
#define maxn 102333 
using namespace std;
int main() {
	int T;
	scanf("%d", &T);
	while(T--) {
		priority_queue< pair<int, int> > Ql, Qr;
		int n;
		scanf("%d", &n);
		long long ans = 0;
		for(int i = 1; i <= n; ++i) {
			int k, l, r;
			scanf("%d%d%d", &k, &l, &r);
			ans += min(l, r);
			if(l > r) Ql.push(make_pair(k, l - r));
			else Qr.push(make_pair(n - k, r - l));
		}
		priority_queue< int > Q;
		for(int i = (signed) Ql.size() - 1; i >= 0; --i) {
			while(!Ql.empty() && Ql.top().first > i) {
				Q.push(Ql.top().second);
				Ql.pop();
			}
			if(!Q.empty()) {
				ans += Q.top();
				Q.pop();
			}
		} 
		Q = decltype(Q)();
		for(int i = (signed) Qr.size() - 1; i >= 0; --i) {
			while(!Qr.empty() && Qr.top().first > i) {
				Q.push(Qr.top().second);
				Qr.pop();
			}
			if(!Q.empty()) {
				ans += Q.top();
				Q.pop();
			}
		} 
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 5720
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp44 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int N = st[0];
            int K = st[1];

            var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            Array.Sort(A);

            var num = new int[A.Distinct().Count()];

            int cnt = 0;

            for (int i = 0; i < N; i++) {
                if (i == 0) {
                    num[cnt]++;
                    continue;
                }
                if (A[i] != A[i - 1]) {
                    cnt++;
                }
                num[cnt]++;
            }

            Array.Sort(num);

            if (num.Count() >= K) {
                Console.WriteLine(num.Take(num.Count() - K).Sum());
            } else {
                Console.WriteLine(0);
            }

            

        }
    }
}


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

int main(){
    int N,L;
    cin >> N >> L;
    int sum = 0;
    for(int i = 0;i < N;i++){
        sum += L + i;
    }
    if(L > 0){
        cout << sum-L << endl;
    }else if(L+N-1 < 0){
        cout << sum-(L+N-1) <<endl;
    }else{
        cout << sum << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
#define M 200000

ll cnt = 0;
int A[M], L[M / 2 + 1], R[M / 2 + 1], n;
 
void merge(int l, int m, int r){
    int n1 = m - l, n2 = r - m, i, j;
    for(i = 0;i < n1;i++)L[i] = A[i + l];
    for(i = 0;i < n2;i++)R[i] = A[i + m];
    i = j = 0;
    for(int k = 0;k < r - l;k++){
        if(j == n2 || (i < n1 && L[i] <= R[j]))A[k + l] = L[i++];
        else A[k + l] = R[j++], cnt += n1 - i;
    }
}

void mergeSort(int l, int r){
    if(l + 1 < r){
        int m = (l + r) / 2;
        mergeSort(l, m);
        mergeSort(m, r);
        merge(l, m, r);
    }
}
 
int main(){
    scanf("%d", &n);
    for(int i = 0;i < n;i++)scanf("%d", &A[i]);
	mergeSort(0, n);
	printf("%lld\n", cnt);
return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;


int main(){
	/*input*/
	int n, h, w;
	cin >> n >> h >> w;

	int a[1000];
	int b[1000];
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
	}

	/*calc*/
    int ans = 0;
    for(int i = 0; i < n; i++){
    	if(a[i] >= h && b[i] >= w) ans++;
    }

    /*output*/
	cout<< ans <<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int[] dice = new int[6];
        int cnt = 0;
        while (scan.hasNextInt()) {
            dice[cnt] = scan.nextInt();
            cnt ++;
        }
        String mark = scan.next();
        String hougaku = "";
        for (int i = 0; i < mark.length(); i++) {
            hougaku = mark.substring(i, i + 1);
            int irekae = 0;
            if (hougaku.equals("S")) {
                irekae = dice[0];
                dice[0] = dice[4];
                dice[4] = dice[5];
                dice[5] = dice[1];
                dice[1] = irekae;
            } else if (hougaku.equals("N")) {
                irekae = dice[0];
                dice[0] = dice[1];
                dice[1] = dice[5];
                dice[5] = dice[4];
                dice[4] = irekae;
            } else if (hougaku.equals("W")) {
                irekae = dice[0];
                dice[0] = dice[2];
                dice[2] = dice[5];
                dice[5] = dice[3];
                dice[3] = irekae;
            } else if (hougaku.equals("E")) {
                irekae = dice[0];
                dice[0] = dice[3];
                dice[3] = dice[5];
                dice[5] = dice[2];
                dice[2] = irekae;
            }
        }
        scan.close();
        System.out.println(dice[0]);
    }
}

Measured memory_bytes: 17368
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<ll, ll> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 55;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

bool isPrime(int u) {
    FOR(i,2,int(sqrt(u)))
        if (u % i == 0) return false;
    return true;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    while (1) {
        if (isPrime(n)) {
            cout << n;
            return 0;
        }
        n++;
    }
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define eps 1e-9
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES\n"; }
void NO() { cout << "NO\n"; }
void Yes() { cout << "Yes\n"; }
void No() { cout << "No\n"; }
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

int main() {
	ll x;
	cin >> x;
	x *= 2;
	for (ll i = 1; ; ++i) {
		if (i * (i + 1) >= x) {
			cout << i << endl;
			break;
		}
	}

	return 0;
}

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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define pi 3.141592653589793238462643383279

int main() {
    double r;
    cin >> r;
    cout<<2*pi*r;
    return 0;
}


Measured memory_bytes: 3772
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;

int main(){
	string s; cin >> s;
	int n = s.length();
	int ans = n-1;
	for (char c = 'a'; c <= 'z'; c++) {
		int res = 0;
		for (int i = 0; i < n; i++) {
			int j = i;
			while (j<n && s[j]!=c) j++;
				res = max(res,j-i);
			}
		ans = min(ans,res);
		//cout << ans << endl;
	}

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

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

using namespace std;

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

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

const double EPS = 1e-10;

double det(double A[3][3])
{
    return A[0][0]*A[1][1]*A[2][2] + A[0][1]*A[1][2]*A[2][0] + A[0][2]*A[1][0]*A[2][1]
         - A[0][0]*A[1][2]*A[2][1] - A[0][1]*A[1][0]*A[2][2] - A[0][2]*A[1][1]*A[2][0];
}

void solve(double A[3][3], double b[3], double ans[3])
{
    double d = det(A);
    rep(i, 3){
        double tmp[3][3];
        rep(j, 3) rep(k, 3){
            tmp[j][k] = k == i ? b[j] : A[j][k];
        }
        ans[i] = det(tmp) / d;
    }
}

int main()
{
    double o[3];
    rep(i, 3) cin >> o[i];
    
    double e[3], b[3][3];
    rep(i, 3){
        cin >> e[i];
        e[i] -= o[i];
    }
    rep(i, 3) rep(j, 3){
        cin >> b[j][i];
        b[j][i] -= o[j];
    }
    
    double a[3];
    solve(b, e, a);
    
    if(a[0] > -EPS && a[1] > -EPS && a[2] > -EPS && a[0]+a[1]+a[2] > 1-EPS){
        cout << "MISS" << endl;
    }
    else{
        cout << "HIT" << endl;
    }
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1e9;
const long long LONG_INF = 1e18;
const long long MOD = 1e9 + 7;

using namespace std;

int main()
{

    int n;
    cin >> n;
    vector<int> dp(n);
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for (int i = 2; i < n; i++)
    {
        int a = dp[i - 2] + abs(h[i] - h[i - 2]);
        int b = dp[i - 1] + abs(h[i] - h[i - 1]);
        dp[i] = min(a, b);
    }

    cout << dp[n - 1] << endl;
    return 0;
}

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

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

	int n, m;
	cin >> n >> m;
	// 1234 - n
	int mx = n;
	int mn = 1;
	for (int i = 0; i < m; i++) {
		int l, r;
		cin >> l >> r;

		mn = max(mn, l);
		mx = min(mx, r);
	}

	cout << max(0, mx - mn + 1);
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, [ $t:tt ]) => {{
    let len = read_value!($iter, usize);
    (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  }};

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    s: String,
  }
  for _ in 0 .. s.len() {
    puts!("x");
  }
  puts!("\n");
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
int main() {
    int n;
    std::cin>>n;
    std::vector<double> w,w1;
    for(int i=0; i<n;i++){
        int t;
        std::cin>>t;
        w.push_back(t);
    }
    double sum=0;
    for(int i=0;i<n;i++){
        sum = sum + w[i];
        w1.push_back(sum);
    }
    int d=100000;
    for(int i=0;i<n;i++){
        int t=sum-w1[i] - w1[i];
        if(abs(t)<abs(d)){
            d = abs(t);
        }
    }
    std::cout<<d<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b,c,d,ans;
int main()
{
    cin>>a>>b>>c>>d;
    if(a<c)
    {
        ans=min((b-c),(d-c));
        if(ans<0)ans=0;
        cout<<ans<<endl;
    }
    else
    {
        ans=min(d-a,b-a);
        if(ans<0)ans=0;
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
s=gets.chomp.split("")
a,b,c=0,0,0

if s[0]=="A"
    a=1
end
s.delete_at(0)
n=s.size

for i in 1...n-1
    if s[i]=="C"
        b=1
        s.delete_at(i)
        break
    end
end

for u in s
    if u<="Z"
        c=1
        break
    end
end

if a==1 and b==1 and c==0
    puts "AC"
else
    puts "WA"
end

Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <algorithm>    // std::copy
#include <iterator>     // std::back_inserter
#include <set>
using namespace std;
 
int main(){
    int N ,Q;
    long long K;
    cin >> N >> K >> Q;

    vector<long long> A(N,K);
    for(int i = 0; i < Q ; i++){
        int ans;
        cin >> ans;
        ans--;
        A[ans]++;
    }

    for(int i = 0; i < N ; i++){
        if(A[i] - Q  > 0 ){
            cout << "Yes"<< endl;
        }
        else {
            cout << "No"  <<endl;
        }
    }

}

Measured memory_bytes: 1408
#include <stdio.h>

int main(){
  int n, i, a, sum;

  while(1){
    scanf("%d", &n);

    if(n==0){
      break;
    }

    sum=0;
    for(i=0;i<n/4;i++){
      scanf("%d", &a);
      sum = sum + a;
    }
    
    printf("%d\n", sum);
  }
    
  return 0;
}

Measured memory_bytes: 600
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
arr = [a,b,c,d,e]
bool = True

for i in range(len(arr)):
  for j in range(len(arr)):
    if i != j and abs(arr[i] - arr[j]) > k:
      bool = False
      break;
      
if bool:
  print("Yay!")
else:
  print(":(")

Measured memory_bytes: 3064
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(int argc, const char * argv[]) {
    
    int N,K;
    cin >> N >>K;
    
    int h[N];
    
    for(int i=0;i<N;i++)
    {
        cin >> h[i];
    }
    
    int f=0;
    
    for(int i=0;i<N;i++)
    {
        if(h[i] >= K)
        {
            f++;
        }
    }
    
    cout << f << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	long long x, y;
	cin >> x >> y;

	int ans = 0;
	while (x <= y) {
		ans++;
		x *= 2;
	}

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


Measured memory_bytes: 256
#include <stdio.h>
       
        int main(void){
          double a,b,c,d,e,f,x,y; int xx,yy;
           while (( scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)) != EOF){
                   x =(c*e-f*b)/(a*e-d*b);
                   y =(c*d-a*f)/(b*d-a*e);
            xx = x*1000; yy = y*1000;
         x =xx;
         x=x/1000;
         y=yy;
         y=y/1000;
          printf("%.3lf %.3lf\n",x,y);
              }
                  return 0;
}

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

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

  ll MOD = 1e9 + 7;
  ll N; cin >> N;
  ll M; cin >> M;
  vector<ll> A(N + 1, 0); for (ll i = 0; i < N; i++) cin >> A[i];
  vector<ll> B(M + 1, 0); for (ll i = 0; i < M; i++) cin >> B[i];
  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());

  ll a = 0, b = 0;
  ll ans = 1;
  for (ll i = 0; i < N * M; i++) {
    ll k = N * M - i;
    if (ans == 0) {
      cout << ans << '\n';
      return 0;
    }
    if (A[a] > k || B[b] > k) ans = 0;
    else if (A[a] == k && B[b] == k) {
      a++; b++;
    } else if (A[a] == k) {
      ans = (ans * b) % MOD;
      a++;
    } else if (B[b] == k) {
      ans = (ans * a) % MOD;
      b++;
    } else {
      ll temp = a * b;
      temp -= i;
      ans = (ans * temp) % MOD;
    }
  }
  cout << ans << '\n';
  return 0;
}

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

using namespace std;
#define ll long long
const long double EPS = 1e-8;
const long double PI = acos(-1);
const int N = 1e5 + 9;
ll arr[109][2];
ll mem[N];
int n, k;

const ll inf = 1e14 + 7LL;

ll solve() {
    for (int i = 0; i < n; i++) {
        for (int j = k; j > -1; j--) {
            if (arr[i][0] <= j)
                mem[j] = max(mem[j], mem[j - arr[i][0]] + arr[i][1]);
        }
    }
    return *max_element(mem, mem + k + 1);
}

int main() {

    scanf("%d%d", &n, &k);

    for (int i = 0; i < n; i++) {
        scanf("%lld%lld", &arr[i][0], &arr[i][1]);
    }

    printf("%lld\n", solve());
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>

using namespace std;


int main(){

        int h,w;
        bool isSharp=1;
        char c;

        while(1){
                scanf("%d %d\n",&h,&w);
                if(h==0 && w==0)
                        return 0;

                for(int j=0;j<h;j++){
                        for(int i=0;i<w;i++) {
                                if(isSharp)
                                        c='#';
                                else
                                        c='.';

                                isSharp = !isSharp;
                                putchar(c);

                        }
                        putchar('\n');
                        if(j%2==0)
                                isSharp = 0;
                        if(j%2==1)
                                isSharp = 1;

                }
                putchar('\n');
                isSharp=1;
        }
}


Measured memory_bytes: 3148
#include <iostream>
#include <cmath>
using namespace std;
int F[1001];
int P[10010];

void init(int N) {
	for (int i=0; i<N; ++i) { P[i] = i; }
}

int root(int a) {
	if (P[a] == a) return a;
	return (P[a] = root(P[a]));
}

bool is_same_set(int a, int b) {
	return root(a) == root(b);
}

void unite(int a, int b) {
	P[root(a)] = root(b);
}

int main() {
	int V,D;
	int count;
	
	F[0] = 1, F[1] = 2;
	for (int i=0; i<1001; i++) {
		F[i+2] = (F[i] + F[i+1]) % 1001;
	}
	
	while(cin >> V >> D) {
		count = 0;
		init(V+1); //自分を設定
		for(int i=1; i<=V; ++i) {
			for(int j=i+1; j<=V; ++j) {
				if (abs(F[j] - F[i]) < D) {
					unite(i,j);
				}
			}
		}
		for(int i=1; i<=V; ++i) {
			if (root(i) == i) {
				count++;
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1176
#include <stdio.h>
#include <math.h>
int main(void)
{
  int n,i,c,p,a[10];
  while(scanf("%d",&n)!=EOF){
    for(i=0;i<10;i++)
      a[i]=0;
    c=-1;
    for(i=9;i>=0;i--){
      p=(int)pow(2,i);
      if(n/p){
	  a[++c]=p;
	  n%=p;
      }
    }
    for(i=c;i>0;i--)
      printf("%d ",a[i]);
      printf("%d\n",a[0]);
  }
  return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <string>
using namespace std;
int N, t[55], ans;
string s[55], X;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s[i] >> t[i];
  }
  cin >> X;
  for (int i = N - 1; i >= 0; i--) {
    if (s[i] == X) break;
    ans += t[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int n,m;
int a[100005],g[100005],k;
long long ans=0;
vector <pair<int,int> > v;
vector <int> lt;
int F(int x)
{
	return g[x]==x?g[x]:g[x]=F(g[x]);
}
void U(int x,int y)
{
	g[F(x)]=F(y);
}
int main() 
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		g[i]=i;
	}
	for(int i=0;i<m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if(F(x)!=F(y))
		    U(x,y);
	}
	for(int i=0;i<n;i++)
	    v.push_back(make_pair(F(i),i));
	sort(v.begin(),v.end());
    int cnt=1;
	for(int i=1;i<v.size();i++)
	    if(v[i].first!=v[i-1].first)
	        cnt++;
	if((cnt-1)*2>n)
	{
		cout<<"Impossible";
		return 0;
	}
	if(cnt==1)
	{
		cout<<0;
		return 0;
	}
	k=(cnt-1)*2;
	int mk=0,now=a[v[0].second];
	for(int i=1;i<v.size();i++)
	    if(v[i].first!=v[i-1].first)
	    {
	    	ans+=now;
	    	v[mk].first=2e9;
	    	k--;
	    	mk=i;
	    	now=a[v[i].second];
		}
		else
		if(a[v[i].second]<now)
		{
			now=a[v[i].second];
			mk=i;
		}
	ans+=now;
	v[mk].first=2e9;
	k--;
	for(int i=0;i<v.size();i++)
	    if(v[i].first!=2e9)
	        lt.push_back(a[v[i].second]);
	sort(lt.begin(),lt.end());
	for(int i=0;i<k;i++)
	    ans+=lt[i];
	cout<<ans;
	return 0;
}
/*
10 6
1 2 3 4 5 6 7 8 9 10
0 1
0 2
1 2
1 3
1 4
1 5
*/

Measured memory_bytes: 2676
using System;
using System.IO;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;
using static System.Math;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = new int[] { 0 }.Concat(Console.ReadLine().Split().Select(int.Parse).ToArray()).Concat(new int[] { 0 }).ToArray();
        int sum = 0;
        for (int i = 1; i < a.Length; i++)
        {
            sum += Abs(a[i - 1] - a[i]);
        }
        for (int i = 1; i < a.Length - 1; i++)
        {
            Console.WriteLine(sum - (Abs(a[i - 1] - a[i]) + Abs(a[i + 1] - a[i])) + Abs(a[i + 1] - a[i - 1]));
        }
    }
}

Measured memory_bytes: 27484
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int n;
int main(){
	cin >> n;
	vector<int> cnt(n+1), a(n);
	rep(i, 0, n){
		int t; cin >> t;
		a[i] = t;
		cnt[t]++;
	}
	
	ll all = 0;
	rep(i, 1, n+1){
		ll c = cnt[i];
		all += (c*(c-1))/2;
	}
	rep(i, 0, n){
		int k = a[i];
		cout << all - cnt[k] + 1 << endl;
	}
    return 0;
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max() / 2;
const ll mod = 1e9+7;

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
  if (a < b) return a = b, true; else return false;
}


void solve(){
  ll N, M;
  cin >> N >> M;
  map<ll, ll, greater<ll>> t;
  rep(i, N){
    ll a;
    cin >> a;
    if(t.count(a)) t[a]++;
    else t[a] = 1;
  }

  rep(i, M){
    ll b, c;
    cin >> b >> c;
    if(t.count(c)) t[c] += b;
    else t[c] = b;
  }

  ll sum = 0;
  ll count = 0;
  for(auto p : t){
    sum += p.first * min(N-count, p.second);
    count += p.second;
    if(count >= N)
      break;
  }

  cout << sum << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int K;  cin >> K;
    queue<ll> que;
    ROP(i, 9)  que.push(i);

    ll ans;
    while(K--){
      ans = que.front();  que.pop();
      if(ans % 10 != 0)  que.push(ans*10 + (ans%10)-1);
      que.push(ans*10 + (ans%10));
      if(ans % 10 != 9)   que.push(ans*10 + (ans%10)+1);
    }

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


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

ans = 1
flag_overflow = False
flag_zero = False
for a in A:
  if(flag_overflow) :
    if(a == 0) :
      flag_zero = True
  else :
    ans *= a
    if(ans > 10 ** 18) :
      flag_overflow = True

if(flag_zero) :
  print(0)
elif(flag_overflow) :
  print(-1)
else :
  print(ans)

Measured memory_bytes: 21700
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

vector<ll> inv,fact,invfact;

//snuke
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
 


void mod_build(int n=101010){  
  fact.resize(n+1);
  inv.resize(n+1);
  invfact.resize(n+1);
  fact[0]=inv[0]=invfact[0]=1;
  inv[1]=1;
  rep(i,n){
    fact[i+1]=fact[i]*(i+1)%mod;
    if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
    invfact[i+1]=invfact[i]*inv[i+1]%mod;
  }
}
ll perm(int n,int k){
  if(n<0||k<0||k>n)return 0;
  return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
  if(n<0||k<0||k>n)return 0;
  return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
  k%=mod-1;
  if(k<0)k+=mod-1;
  ll ret=1;
  while(k){
    if(k&1)ret=ret*n%mod;
    n=n*n%mod;
    k>>=1;
  }
  return ret;
}

int main(){  
  mod_build();
  int n,k;
  cin >> n >> k;
  vector<ll> a(n,0);  
  rep(i,n){ cin>>a[i]; }

  sort(a.rbegin(),a.rend());
  mint ans=0;
  for(ll i=0; i<n-k+1; i++){
    ans += (a[i]*comb(n-i-1,k-1));
  }

  sort(a.begin(),a.end());
  mint ansb=0;
  for(ll i=0; i<n-k+1; i++){
    ansb += (a[i]*comb(n-i-1,k-1));
  }

  ans = ans-ansb;
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 3456
#include<cstdio>
#include<list>
#include<algorithm>
using namespace std;
int main()
{
	int q, x;
	char com[20];
	list<int> v;
	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		scanf("%s", com);
		if (com[0] == 'i')
		{
			scanf("%d", &x);
			v.push_front(x);
		}
		else if (com[6] == 'L')
			v.pop_back();
		else if (com[6] == 'F')
			v.pop_front();
		else if (com[0] == 'd')
		{
			scanf("%d", &x);
			for (list<int>::iterator it = v.begin(); it != v.end(); it++)
				if (*it == x)
				{
					v.erase(it);
					break;
				}
		}
	}
	int isf = 0;
	for (list<int>::iterator it = v.begin(); it != v.end(); it++)
	{
		if (isf++ > 0)
			printf(" ");
		printf("%d", *it);
	}
	printf("\n");
}


Measured memory_bytes: 33880
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

#define INF 1e9

int main()
{
  int n;
  int a[51];
  int mi = 1, ma = 1;

  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    if(a[mi] > a[i]) mi = i;
    if(a[ma] < a[i]) ma = i;
  }

  if(abs(a[ma]) > abs(a[mi])){
    cout << 2 * (n - 1) << endl;
    for(int i = 1; i <= n; i++){
      if(i != ma) cout << ma << " " << i << endl;
    }
    for(int i = 2; i <= n; i++){
      cout << i-1 << " " << i << endl; 
    }
  }else{
    cout << 2 * (n - 1) << endl;
    for(int i = 1; i <= n; i++){
      if(i != mi) cout << mi << " " << i << endl;
    }
    for(int i = n-1; i > 0; i--){
      cout << i+1 << " " << i << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint;
	long k = rlong;
	long[] as = rlong(n);
	long[] fs = rlong(n);
	
	log("n:", n, "k:", k, "as:", as, "fs:", fs);
	
	fs.sort!"a<b"();
	as.sort!"a>b"();
	
	bool isOK(long q){
		long xsum;
		foreach(i; 0 .. n){
			long x = min(as[i], q / fs[i]);
			xsum += x;
		}
		if(xsum >= as.sum - k) return 1;
		else return 0;
	}
	
	long ans = downlimit(0, 1_000_000_000_999, &isOK);
	ans.writeln;
}

// 二分探索テンプレート
T uplimit(T)(T a, T c, bool delegate(T) f){
	if(f(c)) return c; if(! f(a)) return a - 1;
	while(a + 1 < c){ T b = (a + c) / 2; if(f(b)) a = b; else c = b; }
	return a;
}
T downlimit(T)(T a, T c, bool delegate(T) f){
	if(f(a)) return a; if(! f(c)) return c + 1;
	while(a + 1 < c){ T b = (a + c) / 2; if(f(b)) c = b; else a = b; }
	return c;
}




Measured memory_bytes: 18104
n, m, _ = gets.split.map(&:to_i)
r = gets.split.map { |z| z.to_i - 1 }
max = 1e10
d = Array.new(n) { Array.new(n, max) }
m.times do
  a, b, c = gets.split.map(&:to_i)
  a -= 1
  b -= 1
  d[a][b] = c
  d[b][a] = c
end
n.times do |k|
  n.times do |i|
    n.times do |j|
      tmp = d[i][k] + d[k][j]
      d[i][j] = tmp if d[i][j] > tmp
    end
  end
end
ans = r.permutation.map do |perm|
  perm.each_cons(2).inject(0) { |sum, (x, y)| sum + d[x][y] }
end.min

p ans


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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int X;
    cin >> X;
    YES(X == 3 || X == 5 || X == 7);
}


Measured memory_bytes: 256
from collections import deque

n,q=map(int,input().split())

g=[[] for i in range(n+1)]
for i in range(1,n):
    a,b=map(int,input().split())
    g[a].append(b)
    g[b].append(a)
    

cnt=[0]*(n+1)
for i in range(q):
    p,x=map(int,input().split())
    cnt[p]+=x

q = deque([1])
visited=set()
while q:
    v = q.popleft()
    visited.add(v)
    for next_v in g[v]:
        if next_v not in visited:
            cnt[next_v]+=cnt[v]
            q.append(next_v)

print(*cnt[1:])


Measured memory_bytes: 64988
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main() {
	int N, M, C;
	int i, j;
	int A[50][50];
	int B[100];
	int res = 0;
	int sum = 0;
	cin >> N >> M >> C;

	for (i = 0; i < M; ++i) {
		cin >> B[i];
	}

	for (i = 0; i < N; ++i) {
		for (j = 0; j < M; ++j) {
			cin >> A[i][j];
		}
	}

	for (i = 0; i < N; ++i) {
		for (j = 0; j < M; ++j) {
			 sum+=A[i][j]*B[j];
		}
		sum += C;
		if (sum > 0) {
			++res;
		}
		sum = 0;
	}



	cout << res << endl;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
A = [list(map(int, input().split())) for i in range(m)]
s, t = map(int, input().split())

saki = [[] for i in range(n+1)]
for i in range(m):
    saki[A[i][0]].append(A[i][1])

F = [[-1,-1,-1] for i in range(n+1)]

# print(saki)

def idou(x, y):
    # print(F)
    if F[x][y%3] == -1:
        F[x][y%3] = y
        #print(F)
        for item in saki[x]:
            #print(item)
            if F[item][(y+1)%3] == -1:
                #print("m")
                mada[(y+1)%3].append([item,y+1])
    # print(mada)

mada = [[] for i in range(3)]
a=0
b=0
c=0

idou(s,0)
# print("while")
while a<len(mada[0]) or b<len(mada[1]) or c<len(mada[2]):
    while a<len(mada[0]):
        # print("a")
        idou(mada[0][a][0], mada[0][a][1])
        a += 1
    while b<len(mada[1]):
        # print("b")
        idou(mada[1][b][0], mada[1][b][1])
        b += 1
    while c<len(mada[2]):
        # print("c")
        idou(mada[2][c][0], mada[2][c][1])
        c += 1
# print(F)
print(F[t][0]//3)

Measured memory_bytes: 123096
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	k := nextInt()
	list := make([]int, n)
	for i := 0; i < n; i++ {
		list[i] = nextInt()
	}

	result := (n - 1) / (k - 1)
	if (n-1)%(k-1) != 0 {
		result++
	}
	fmt.Println(result)
}


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

int main(){
    int x, y, z;
    cin >> x >> y >> z;

    int cnt = 0;
    int size = 0;
    while(true){
        size += (y + z);
        if(size < x && (x - size) >= z){
            cnt++;
        }
        else{
            break;
        }
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main(void){
	while(1){
		int n; cin >> n;
		if(n == 0) break;
		priority_queue<pint, vector<pint>, greater<pint> > q;
		q.push(make_pair(0, INF));
		map<int, vpint> m;
		rep(i, n){
			char c; cin >> c;
			if(c == 'W'){
				int num, size; cin >> num >> size;
				while(size > 0){
					int l = q.top().fi, r = q.top().se;
					// printf("l %d r %d\n", l, r);
					q.pop();
					if(r - l + 1 >= size){//??????
						// printf("push %d %d\n", l + size, r);
						q.push(make_pair(l + size, r));
						m[num].push_back(make_pair(l, l + size - 1));
						size = 0;
					}else{//?¶??????????
						m[num].push_back(make_pair(l, r));
						size -= (r - l + 1);
					}
				}
			}else if(c == 'D'){
				int num; cin >> num;
				for(auto u : m[num]){
					// printf("delete %d %d\n", u.fi, u.se);
					q.push(make_pair(u.fi, u.se));
				}
				m[num].erase(all(m[num]));
			}else{
				int idx; cin >> idx;
				bool flag = false;
				each(it, m){
					auto key = it->fi;
					auto v = it->se;
					// printf("key %d vsize %d\n", key, (int)v.size());
					for (int i = 0; i < v.size(); ++i){
						if(v[i].fi <= idx && idx <= v[i].se){
							printf("%d\n", key);
							flag = true;
							break;
						}
					}
					if(flag) break;
				}
				if(!flag){
					printf("-1\n");
				}
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 23616
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
 
using namespace std;


ll a[20],n;



int main()
{
	cin>>a[1]>>a[2]>>a[3]>>a[4];
	
	
	cin>>n;n*=4;
	

	if(a[1]*2<a[2])a[2]=a[1]*2;
	if(a[2]*2<a[3])a[3]=a[2]*2;
	if(a[3]*2<a[4])a[4]=a[3]*2;
	
	ll res=0;
	if(n>=8)
	{
		res+=n/8*a[4];
		n%=8;	
	}	
	
	if(n>=4)
	{
		res+=n/4*a[3];
		n%=4;
	}
	
	if(n>=2)
	{
		res+=n/2*a[2];
		n%=2;
	}
	
	if(n>=1)
	{
		res+=n/1*a[2];
		n%=1;
	}
	
	cout<<res<<endl;
	
	return 0;	
} 

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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    while(true){
        int a,b,c,s;
        cin >> a >> b >> c;
        if(a==-1&&b==-1&&c==-1){
            break;
        }
        s=a+b;
        if(a==-1||b==-1)cout<<'F'<<'\n';
        else if(s>=80)cout<<'A'<<'\n';
        else if(s>=65)cout<<'B'<<'\n';
        else if(s>=50)cout<<'C'<<'\n';
        else if(s>=30){
            if(c>=50)cout<<'C'<<'\n';
            else cout<<'D'<<'\n';
        }
        else cout<<'F'<<'\n';
    }
}


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

typedef long long ll;

int main()
{
  ll x, y;
  cin >> x >> y;
  
  ll ans = 1e+18;
  if(x <= y) ans = min(ans, y-x);
  if(-x <= y) ans = min(ans, y+x+1);
  if(x <= -y) ans = min(ans, -y-x+1);
  if(-x <= -y) ans = min(ans, -y+x+2);
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# hello worldと表示する
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m=MI()
lis=LI()
count=0
lis.sort(reverse=True)
total=sum(lis)
for i in range(n):
    if lis[i]*4*m>=total:
        count+=1
if count>=m:
    print("Yes")
else:
    print("No")
    
    




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

/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

const int mxN= 100010;
vector<int> tree[mxN];

int dfs(int v = 0,int p = -1) {
	int res = 0;
	for(auto u : tree[v]) if(u != p) res ^= dfs(u,v);
	if(v) res ++;
	return res;
}

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

	int N,u,v;
	cin>>N;
	for(int i = 1;i < N;i++) {
		cin>>u>>v;
		u--,v--;
		tree[u].push_back(v);
		tree[v].push_back(u);
	}
	int res = dfs();
	cout<<(res?"Alice":"Bob")<<'\n';
	return 0;
}


Measured memory_bytes: 10368