akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
lis_A = list(map(int, input().split()))
bd = sum(lis_A)/(4*M)
n_above_bd = sum(map(lambda x: x >= bd, lis_A))
if n_above_bd >= M:
    print('Yes')
else :
    print('No')

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

map<ll,ll> mp;
ll n,a,b,c,d;
ll dfs(ll n)
{
	if(!n)return 0;
	if(mp[n]!=0)return mp[n];
	//if(mp[n]!=0)return mp[n];
	if(n==1)return mp[1] =  d;
	//if(n==0)return 0;

	ll now;
	if(n>1e18/d)now = LLONG_MAX;
	else now = n*d;
	ll A = n%2;
	now = min(now, dfs((n-A)/2)+A*d+a);
	now = min(now, dfs((n+A)/2)+A*d+a);

	ll B = n%3;
	now = min(now, dfs((n-B)/3)+B*d+b);
	now = min(now, dfs((n+(3-B))/3)+(3-B)*d+b);

	ll C = n%5;
	now = min(now, dfs((n-C)/5)+C*d+c);
	now = min(now, dfs((n+(5-C))/5)+(5-C)*d+c);
	return mp[n] = now;
}

int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		cin >> n >> a >> b >> c >> d;

		cout<<dfs(n)<<endl;
		mp.clear();
	}
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        String t = br.readLine();
        br.close();
        int[][] arr = new int[s.length()+1][t.length()+1];
        for(int i=1;i<=s.length();i++){
            for (int j=1; j<=t.length();j++){
                arr[i][j]=Math.max(arr[i][j-1],arr[i-1][j]);
                if (s.charAt(i-1)==t.charAt(j-1)){
                    arr[i][j]=arr[i-1][j-1]+1;
                }
            }
        }
        int l = arr[s.length()][t.length()];
        StringBuilder sb = new StringBuilder();
        int r=s.length();
        int c=t.length();
        while(c>0){
            int temp=r;
            while(r-1>0 && arr[r-1][c]==arr[r][c]){
                r--;
            }
            if(r-1==0){
                if((c==1||arr[r][c-1]==0) && arr[r][c]==1){
                    sb.append(t.charAt(c-1));
                    break;
                }
                r=temp;
            } else {
                if(arr[r][c]>arr[r][c-1]) sb.append(t.charAt(c-1));
            }
            c--;
        }
        System.out.println(sb.reverse().toString());
    }
}

Measured memory_bytes: 82132
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
#define pb push_back
#define rrep(i,m,n) for(int i = m;i >= n;--i)
#define INF INT_MAX-1;
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };





int main(){
	ll a, b, q;
	cin >> a >> b >> q;
	vector<ll>sd;
	vector<ll>td;
	sd.pb(-inf);
	td.pb(-inf);
	rep(i, 0, a) {
		ll s;
		cin >> s;
		sd.pb(s);
	}
	rep(i, 0, b) {
		ll t;
		cin >> t;
		td.pb(t);
	}
	sd.pb(inf);
	td.pb(inf);
	
	rep(i, 0, q) {
		ll x;
		cin >> x;
		auto position_s = lower_bound(all(sd), x);
		auto position_t = lower_bound(all(td), x);
		ll idx_s = distance(sd.begin(), position_s);
		ll idx_t = distance(td.begin(), position_t);

		vector<pair<ll, ll>>dist;
		dist.pb({ sd[idx_s],0 });
		dist.pb({ sd[idx_s - 1],0 });
		dist.pb({ td[idx_t],1 });
		dist.pb({ td[idx_t - 1], 1 });

		ll ans = inf;
		rep(i, 0, 4)rep(j, 0, 4) {
			if (dist[i].second != dist[j].second) {
				ll temp;
				if (dist[i].first >= x && dist[j].first >= x) {
					temp = max(dist[i].first - x, dist[j].first - x);
				}else if(dist[i].first <= x && dist[j].first <= x){
					temp = max(x-dist[i].first, x-dist[j].first);
				}
				else {
					temp = 2 * abs(x - dist[i].first) + abs(x - dist[j].first);
				}
				ans = min(ans, temp);
			}
		}
		cout << ans << endl;
	}




	return 0;
}

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

using ll = long long;
const int MOD = (int) 1e9 + 7;

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

    unsigned long N, X;
    cin >> N >> X;

    ll S[N];
    for (int i = 0; i < N; ++i) {
        cin >> S[i];
    }
    sort(S, S +N);

    vector<vector<ll> > dp(N + 1, vector<ll>(X + 1, 0));
        for (int j = 0; j <= X; ++j) {
            dp[0][j] = j;
        }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= X; ++j) {
            dp[i + 1][j] += dp[i][j % S[i]];
            dp[i + 1][j] %= MOD;
            dp[i + 1][j] += dp[i][j] * i % MOD;
            dp[i + 1][j] %= MOD;
        }
    }

    cout << dp[N][X] << '\n';

    return 0;
}


Measured memory_bytes: 158592
#include <algorithm>
#include <cstring>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  int i = 0;
  while (1) {
    if (n >= pow(k, i)) {
      i++;
    } else {
      break;
    }
  }
  // i++;
  cout << i;
  return 0;
}


Measured memory_bytes: 384
#include <cmath>
#include <complex>
#include <algorithm>
#include <cassert>
using namespace std;

typedef long double Real;
typedef complex<Real> Point;
#define PCR Point const &
#define X real()
#define Y imag()

const Real EPS = 1e-10;
const Real INF = 1e100;
const Real PI = acos(-1);

struct Segment {
    Point p[2];
    Segment (PCR a = Point(), PCR b = Point()){
        p[0] = a, p[1] = b;
    }
    Point & operator [] (int k) { return p[k]; }
    Point const & operator [] (int k) const { return p[k]; }
};
typedef vector<Point> Polygon;
struct Circle { Real radius; Point center; };

Real dot(PCR a, PCR b){
    return a.X*b.X + a.Y*b.Y;
}
Real cross(PCR a, PCR b){
    return a.X*b.Y - a.Y*b.X;
}

Point pSP(Segment const & s, PCR p){
    Point base = s[1] - s[0];
    Real r = dot(p - s[0], base) / norm(base);
    return s[0] + base * r;
}

Point rSP(Segment const & s, PCR p){
    Point v = pSP(s,p) - p;
    return p + v * Real(2);
}

enum { LEFT = 1, RIGHT = -1, BACK = 2, FRONT = -2, ON = 0 };
// Includes end-points. Comment in to exclude.
int ccw(PCR x, PCR p, PCR q){
    Point a = p - x, b = q - x;
    if(cross(a,b) > EPS) return LEFT;
    if(cross(a,b) < -EPS) return RIGHT;
    if(/* abs(a) < EPS || */ dot(a,b) < -EPS) return BACK;
    if(/* abs(b) < EPS || */ norm(a) < norm(b)) return FRONT;
    return ON;
}

bool isParallel(Segment const & s, Segment const & t){
    return abs(cross(s[1]-s[0],t[1]-t[0])) < EPS;
}

bool isOrthogonal(Segment const & s, Segment const & t){
    return abs(dot(s[1]-s[0],t[1]-t[0])) < EPS;
}

// Includes end-points. Modify CCW to exclude
bool iSS(Segment const & s, Segment const & t){
    bool f1 = ccw(s[0],s[1],t[0]) * ccw(s[0],s[1],t[1]) <= 0;
    bool f2 = ccw(t[0],t[1],s[0]) * ccw(t[0],t[1],s[1]) <= 0;
    return f1 && f2;
}

Point cSS(Segment const & s, Segment const & t){
    assert(iSS(s,t));
    assert(!isParallel(s,t));
    Real d = cross(t[1]-t[0], s[1]-s[0]);
    return s[0] + (s[1] - s[0]) * cross(t[1]-t[0], t[1]-s[0]) * (1.0 / d);
}

#include <iostream>
#include <cstdio>

int main(){
    Segment s,t;
    Real x,y;
    int n; cin >> n;
    for(int i=0;i<n;i++){
        cin >> x >> y;
        s[0] = Point(x,y);
        cin >> x >> y;
        s[1] = Point(x,y);
        cin >> x >> y;
        t[0] = Point(x,y);
        cin >> x >> y;
        t[1] = Point(x,y);
        Point p = cSS(s,t);
        printf("%.10Lf %.10Lf\n", p.X,p.Y);
    }
}

Measured memory_bytes: 1252
//template code, C343, 2019
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Iterator;

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	
	static int totalVertex;
	static ArrayList<ArrayList<Integer>> adjList;
	static ArrayList<Integer> undiscovered;
	static int[] findTimes;
	static int[] completeTimes;
	static int time = 0;
	static int currentVertex = 0;
	
	public static void main(String argv[]) {
		
		getInput();
		
		findTimes = new int[totalVertex];
		completeTimes = new int[totalVertex];
		undiscovered = new ArrayList<Integer>();
		
		for(int i = 0; i < totalVertex; i++) {
			findTimes[i] = -1;
			completeTimes[i] = -1;
			
			undiscovered.add(i);
		}
		
		while(undiscovered.isEmpty() == false) {
			searchVertex(undiscovered.get(0));
		}
		
		for(int i = 0; i < totalVertex; i++) {
			System.out.println((i+1) + " " + findTimes[i] + " " + completeTimes[i]);
		}
		
		
	}
	
	public static void searchVertex(int i) {
		
		time++;
		undiscovered.remove(undiscovered.indexOf(i));
		
		findTimes[i] = time;
		
		for(Iterator iter = adjList.get(i).iterator(); iter.hasNext();) {
			int temp = (int)iter.next();
			if(undiscovered.contains(temp)) searchVertex(temp);
		}
		
		time++;
		completeTimes[i] = time;
		
		
	}
	
	public static void getInput() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new ArrayList<ArrayList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			ArrayList<Integer> tmp = new ArrayList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
}


Measured memory_bytes: 28696
import sys
import numpy as np
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

B = 0
s = 1
for i, a in enumerate(A):
    if i >= K:
        B = A[i-K]
        s = a
        if B != 0 and B < s:
            print('Yes')
        elif B != 0 and B >= s:
            print('No')


Measured memory_bytes: 50148
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0LL;
    ans += min(a, k);
    k = max(k - a, 0LL);
    k = max(k - b, 0LL);
    ans -= min(k, c);
    cout << ans << '\n';
}


Measured memory_bytes: 3636
function Main(input) {
    input.trim().split("\n").forEach(line => {
        var a = parseInt(line);
        var root = Math.floor(Math.sqrt(a));
        for (var i = root; i > 0; i--) {
            if (a % i === 0) {
                console.log(i + (a / i) - 2);
                return;
            }
        }
    });
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
var globalInput = '';
process.stdin.on('data', function(chunk) {
    globalInput += chunk;
})
process.stdin.on('end', function() {
    Main(globalInput)
})

// Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 9548
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def divisors(n):
    lower = []
    upper = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            lower.append(i)
            if i != n // i:
                upper.append(n // i)

    lower.extend(reversed(upper))
    return lower


def main():
    N = int(readline())

    D = divisors(N)
    D1 = divisors(N - 1)
    ans = len(D1) - 1

    for d in D:
        if d == 1:
            continue
        n = N
        while n % d == 0:
            n //= d
        if n % d == 1:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 65904
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
// lint mod = 1000000007;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
#define ycomb [](auto f){ return [=](auto&&... args){ return f(f, std::forward<decltype(args)>(args)...); }; }

class FenwickTree {
  vector<lint> dat;
public:
  FenwickTree(int n){ dat.resize(n); }
  void add(int i, lint x){ for(i++;i<=dat.size();i+=i&-i) dat[i-1]+=x; }
  lint sum(int e){ lint res=0; for(;e>0;e-=e&-e) res+=dat[e-1]; return res; }
  lint sum_range(int b,int e){ return sum(e)-sum(b); }
};

void app() {
  int n,q;
  cin>>n>>q;

  vector<int> c(n);
  rep(i,n){
    cin>>c[i];
    c[i]--;
  }

  vector<vector<int>> qid(n+1);
  vector<vector<int>> ql(n+1);
  vector<int> ans(q);
  rep(_,q){
    int l,r;
    cin>>l>>r;
    l--;
    qid[r].push_back(_);
    ql[r].push_back(l);
  }

  vector<int> signipos(n,-1);
  FenwickTree signiset(n);
  rep(r,n){
    int col=c[r];
    if(signipos[col]>=0) signiset.add(signipos[col],-1);
    signiset.add(r,+1);
    signipos[col]=r;

    rep(i,qid[r+1].size()){
      ans[qid[r+1][i]]=signiset.sum_range(ql[r+1][i],r+1);
    }
  }

  rep(i,q) cout<<ans[i]<<endl;
}

int main(){app();return 0;}


Measured memory_bytes: 54896
from sys import stdin, exit
N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
count, l, r = 0, 0, 0

for i in range(len(S)):
    if S[i] == '(':
        count += 1
    else:
        if count == 0:
            l += 1
        else:
            count -= 1
r = count
ans = ""
for i in range(l):
    ans += '('
ans += S
for i in range(r):
    ans += ')'
print(ans)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;int main(){	int a,b,c,d;	cin >> a >> b >> c >> d;	if (abs(a-c)<=d) cout<<"Yes";	else if (abs(a-b)<=d&&abs(b-c)<=d) cout<<"Yes";	else cout<<"No";	return 0;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  
  int ans=0;
  int x;
  for(int i=0; i<n; i++){
    cin >> x;
    ans+=min(x,k-x);
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include<numeric>
#include<functional>

using namespace std;
#define ll long long
#define ull unsigned long long
#define rrep(i,m,n) for(ll (i)=(ll)(m);(i)>=(ll)(n);(i)--)
#define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
constexpr long double m_pi = 3.1415926535897932L;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 62;
constexpr long double EPS = 1e-10;
template<typename T> using vector2 = vector<vector<T>>;
template<typename T> using vector3 = vector<vector2<T>>;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

	ll n;
	cin >> n;
	map<Array, ll> mp;
	vector<Array> a(n);
	auto normalize = [](Array c) {
		Array t = c;
		REP(j, 4) {
			rotate(c.begin(), c.begin() + 1, c.end());
			if (t > c)t = c;
		}
		return t;
	};
	REP(i, n) {
		Array c(4);
		REP(j, 4)cin >> c[j];
		Array t = normalize(c);
		mp[t]++;
		a[i] = t;
	}
	ll ans = 0;
	REP(i, n) {
		mp[a[i]]--;
		rep(j, i + 1, n) {
			mp[a[j]]--;
			REP(k, 4) {
				ll tmp = 1;
				REP(l, 4) {
					Array c(4);
					c[0] = a[i][(l + 1) % 4];
					c[1] = a[i][l % 4];
					c[2] = a[j][(k - l+1 + 4) % 4];
					c[3] = a[j][(k - l +4) % 4];
					Array t = normalize(c);
					if (mp.count(t) == 0)tmp = 0;
					else tmp *= mp[t], mp[t]--;
					if (t[0] == t[1] && t[0] == t[2] && t[0] == t[3])tmp *= 4;
					else if (t[0] == t[2] && t[1] == t[3])tmp *= 2;
				}
				ans += tmp;
				REP(l, 4) {
					Array c(4);
					c[0] = a[i][(l + 1) % 4];
					c[1] = a[i][(l) % 4];
					c[2] = a[j][(k - l+1+4) % 4];
					c[3] = a[j][(k - l + 4) % 4];
					Array t = normalize(c);
					if (mp.count(t) != 0)mp[t]++;
				}
			}
			mp[a[j]]++;
		}
		mp[a[i]]++;
	}
	cout << ans / 3<< "\n";

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	ll X;
	cin >> X;

    if (400 <= X && X <= 599)
    {
        cout << "8" << endl;
        return 0;
    }
    if (600 <= X && X <= 799)
    {
        cout << "7" << endl;
        return 0;
    }
    if (800 <= X && X <= 999)
    {
        cout << "6" << endl;
        return 0;
    }
    if (1000 <= X && X <= 1199)
    {
        cout << "5" << endl;
        return 0;
    }
    if (1200 <= X && X <= 1399)
    {
        cout << "4" << endl;
        return 0;
    }
    if (1400 <= X && X <= 1599)
    {
        cout << "3" << endl;
        return 0;
    }
    if (1600 <= X && X <= 1799)
    {
        cout << "2" << endl;
        return 0;
    }
    if (1800 <= X && X <= 1999)
    {
        cout << "1" << endl;
        return 0;
    }
}


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

void solve() {
	ll a, b, c, d; cin >> a >> b >> c >> d;
	ll ans = -1e18 - 1000;
	ans = max(ans, a * c);
	ans = max(ans, a * d);
	ans = max(ans, b * c);
	ans = max(ans, b * d);
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t; cin >> t;
	// while (t--)
	solve();

}



Measured memory_bytes: 3504
a = [0]*10**5
while 1:
    n,k = map(int, raw_input().split())
    if n==0 and k==0: break
    for i in range(n): a[i] = int(raw_input())
    S = sum(a[0:k]); ans = 0;
    for i in range(n-k):
        ans = max(ans, S)
        S += a[k+i]-a[i]
    print(str(ans))

Measured memory_bytes: 10272
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
vector <int> G[MAXN];
bool vis[MAXN];
void dfs(int pos)
{
	if(vis[pos])
		return;
	vis[pos] = true;
	for (int i = 0; i < G[pos].size(); ++i)
	{
		dfs(G[pos][i]);
	}
}
int main()
{
	int n,m;
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i)
	{
		int x;
		scanf("%d", &x);
		while(x--)
		{
			int y;
			scanf("%d", &y);
			y+=n;
			G[i].push_back(y);
			G[y].push_back(i);
		}
	}
	dfs(1);
	bool ok = true;
	for (int i = 1; i <= n; ++i)
		ok = (ok && vis[i]);
	cout<<(ok?"YES":"NO")<<"\n";
	return 0;
}

Measured memory_bytes: 8704
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll dp[105][123456];
int a[123456];
int main(){
    int n,k;
    cin >> n >> k;
    rep(i,n){
        cin >> a[i];
    }
    dp[0][0] = 1;
    rep(i,n){
        ll temp = 0;
        rep(j,k+1){
            temp += dp[i][j];
            if(j-a[i]-1>=0)temp -= dp[i][j-a[i]-1];
            temp = (temp + mod) % mod;
            dp[i+1][j] = temp;
        }
    }
    cout << dp[n][k] << endl;
}

Measured memory_bytes: 97152
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	map<int, int> mp;
	for(int i = 0; i < n; ++i) {
		int d;
		cin >> d;
		mp[d]++;
	}
	
	int m;
	cin >> m;
	
	vector<int> t(m);
	for(int i = 0; i < m; ++i) {
		cin >> t[i];
	}
	
	bool yes = true;
	for(int i = 0; i < m; ++i) {
		if( mp[t[i]] == 0 ) {
			yes = false;
			break;
		}
		
		mp[t[i]]--;
	}
	
	if( yes ) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

int N;
int max_num_robots = 0;
std::vector<std::pair<int,int>> right_left;

int main() {
  std::cin >> N;
  right_left.assign(N, std::pair<int, int>(0, 0));
  for (int i = 0; i < N; ++i) {
    int x, l;
    std::cin >> x >> l;
    right_left[i] = std::make_pair(x + l, x - l);
  }
  std::sort(right_left.begin(),right_left.end());
  int current_mostright = 0;
  for (int i = 0; i < N; ++i) {
    if (i == 0) {
      current_mostright = right_left[0].first;
      ++max_num_robots;
    } else if (current_mostright <= right_left[i].second) {
      current_mostright = right_left[i].first;
      ++max_num_robots;
    }
  }
  std::cout << max_num_robots << std::endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,w,wt,p,i,j;
    cin>>n>>w;
    ll dp[w+1] = {0}; //0 to W
    for(i = 0 ; i < n ; i++)
    {
        cin>>wt>>p;
        for(j = w-wt; j>=0 ; j--)
        {
            dp[j+wt] = max(dp[j+wt],p+dp[j]);
        }
    }
    cout<<dp[w];
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

#define rep(i, n) for(int i = 0;i < (n);i++)
#define rrep(i, n) for(int i = (n);i >= 0;i--)
#define FOR(i, m, n) for(int i = (m);i < (n);i++)

using namespace std;
using ll = long long;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}

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


//////////////////////////////////////////////////



int main() {
    ll n, x; cin >> n >> x;

    vector<ll> p(60), a(60);
    p[0] = 1;
    a[0] = 1;
    for (int i = 0; i < 50; i++)
    {
        p[i+1] = p[i]*2 + 1;
        a[i+1] = a[i]*2 + 3;
    }

    auto func = [&](auto &&func, int level, ll x) -> ll {
        if (level == 0) return 1;
        if (x == 1) return 0;
        if (x <= 1+a[level-1])      return func(func, level-1, x-1);
        if (x == 2+a[level-1])      return p[level-1] + 1;
        if (x <= 2+2*a[level-1])    return p[level-1] + 1 + func(func, level-1, x-2-a[level-1]);
        if (x == 3+2*a[level-1])    return 2*p[level-1] + 1;
    };
    ll ans = func(func, n, x);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define debug(aa, a) fprintf(stderr, aa, a)

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	ll t, a, beft = 1, befa = 1;
	rep(i, n) {
		scanf("%lld%lld", &t, &a);
		ll p = (ll)max(ceil((long double)beft / t), ceil((long double)befa / a));
		t *= p;
		a *= p;
		beft = t;
		befa = a;
	}
	printf("%lld\n", t + a);
	Please AC;
}

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

int max(int,int);

int main(void){
  char str[200];
  int a,b;
  
  while(1){
    for(int i=0;i<200;i++){
      str[i]='\0';
    }
    scanf("%[^\n]%*c",str);
    a=0;
    b=0;
    if(str[0]=='0')break;
    
    for(int i=1;str[i]!='\0';i++){  
      if(str[i]=='A')a++;
      else if(str[i]=='B')b++;
    }
    
    if(a==max(a,b))a++;
    else if(b==max(a,b))b++;
    cout << a <<" "<< b << endl;
  }
  
  return 0;
}

int max(int x,int y){
  return (x<y)?y:x;
}

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

int main(){
    int i, n, k, a = 1;
    cin >> n >> k;
    for(i=0; i<n; i++){
        if(a < k){
            a *= 2;
        }else{
            a += k;
        }
    }
    cout << a;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int D = stdIn.nextInt();
		int X[][] = new int[N][D];
		int ans = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < D; j++){
				X[i][j] = stdIn.nextInt();
			}
		}

		for(int i = 0; i < N; i++){
			for(int j = i + 1; j < N; j++){
				double tmp = 0;
				for(int k = 0; k < D; k++){
					tmp += Math.pow(X[j][k] - X[i][k],2);
				}
				double sq = Math.sqrt(tmp);
				if((sq - (int)sq) == 0){
					ans++;
				}
			}
		}
		System.out.println(ans);
		stdIn.close();
	}
}

Measured memory_bytes: 35988
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

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

bool isInCircle(double px,double py,double cx,double cy, double r){
	double a = pow(px - cx,2.0) + pow(py - cy,2.0);
	return a < r*r ? true : false;
}

bool isIntersectCircleAndLine(double px1,double py1,double px2, double py2,double cx,double cy, double r){
	if(isInCircle(px1,py1,cx,cy,r) && isInCircle(px2,py2,cx,cy,r)) return false;

	//vector1: from the center of the circle to the staring point
	double vx1 = (cx - px1);
	double vy1 = (cy - py1);

	//vector2: from the starting point to the ending point
	double vx2 = (px2 - px1);
	double vy2 = (py2 - py1);


	double n1=vx1*vx2 + vy1*vy2;
	double n2=vx2*vx2 + vy2*vy2;
	double n3=vx1*vx1 + vy1*vy1;
	

	if(n1 < 0){
		//distance between the starting point and the center of the circle
		return (pow(px1 - cx,2.0) + pow(py1 - cy,2.0) <= r*r) ? true : false;
	}

	else if(n1 > n2){
		//distance between the ending point and the center of the circle
		return (pow(px2 - cx,2.0) + pow(py2 - cy,2.0) <= r*r) ? true : false;
	}
	else{
		if(n2<=0) return (n3*n2 - n1*n1 >= r*r*n2) ? true : false; 
		else return (n3*n2 - n1*n1 <= r*r*n2) ? true : false; 
	}
}

int main(){
	
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		vector<PP> wall;
		for(int i=0;i<n;i++){
			int x,y,r;
			scanf("%d %d %d",&x,&y,&r);
			wall.push_back(PP(P(x,y),r));
		}

		int m;
		scanf("%d",&m);
		for(int i=0;i<m;i++){
			double tx,ty,sx,sy;
			scanf("%lf %lf %lf %lf",&tx,&ty,&sx,&sy);
			bool isSafe = false;
			for(int i=0;i<wall.size();i++){
				if(isIntersectCircleAndLine(tx,ty,sx,sy,wall[i].first.first,
					wall[i].first.second,wall[i].second)){
						isSafe = true;
				}
			}

			printf("%s\n",isSafe ? "Safe" : "Danger");
		}
	}
}

Measured memory_bytes: 0
#include <stdio.h>

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

	scanf("%d", &d);

	switch(d) {
		case 25:
			printf("Christmas\n");
			break;
		case 24:
			printf("Christmas Eve\n");
			break;
		case 23:
			printf("Christmas Eve Eve\n");
			break;
		case 22:
			printf("Christmas Eve Eve Eve\n");
			break;
		default:
			break;
	}

	return(0);
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




int main() {
	string s;
	int a, b;
	rep(i, 9) {
		cin >> s >> a >> b;
		cout << s << " " << a + b << " " << a * 200 + b * 300 << endl;
	}
}

Measured memory_bytes: 1200
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll x;
    cin>>x;
    for(int i=1;i<=180;i++)
    {
        if((i*360)%(x)==0)
        {
            cout<<(i*360)/(x);
            return;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

using namespace std;

#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

vector<int> sieve(int n) {
    vector<int> res(n);
    for(int i = 0; i < n; ++i) res[i] = i;
    for (int i = 2; i*i < n; ++i) {
        if (res[i] < i) continue;
        for (int j = i*i; j < n; j += i)
        if (res[j] == j) res[j] = i;
    }

    return res;
}

vector<int> factor(int n, const vector<int>& min_factor) {
    vector<int> res;
    while (n > 1) {
        res.push_back(min_factor[n]);
        n /= min_factor[n];
    }

    return res;
}

int main(void){

    int n;
    cin >> n;

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

    int x = a[0];
    for(int i = 0; i < n; ++i) x = gcd(x, a[i]);
    if(x != 1){
        cout << "not coprime" << "\n";
        return 0;
    }

    vector<int> b = sieve(1000005);
    set<int> prime;
    for(int i = 0; i < n; ++i){
        vector<int> c = factor(a[i], b);
        set<int> ps(all(c));
        for(auto v : ps){
            if(prime.find(v) != prime.end()){
                cout << "setwise coprime" << "\n";
                return 0;
            }
            prime.insert(v);
        }
    }

    cout << "pairwise coprime" << "\n";

    return 0;
}


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

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

    int ans = 0;
    for(int i = 0; i < k; i++)
        ans += p[i];

    cout << ans << endl;

}

Measured memory_bytes: 3636
#include <stdio.h>

int main() {
    int a;
    int b;
    scanf("%d %d", &a, &b);
    if (a > b) {
        printf("a > b\n");
    } else if (a == b) {
        printf("a == b\n");
    } else {
        printf("a < b\n");
    }
}


Measured memory_bytes: 2600
import math
def make_prime_list(num):
    if num < 2:
        return []
    prime_list = [i for i in range(num + 1)]
    prime_list[1] = 0
    num_sqrt = math.sqrt(num)

    for prime in prime_list:
        if prime == 0:
            continue
        if prime > num_sqrt:
            break
        
        for non_prime in range(2 * prime, num, prime):
            prime_list[non_prime] = 0
    return [prime for prime in prime_list if prime != 0]

def prime_factorization(num):
    if num <= 1:
        return {1 : 1}
    else:
        num_sqrt = math.floor(math.sqrt(num))
        prime_list = make_prime_list(num_sqrt)

        dict_counter = {}
        for prime in prime_list:
            while num % prime == 0:
                if prime in dict_counter:
                    dict_counter[prime] += 1
                else:
                    dict_counter[prime] = 1
                num //= prime
        if num != 1:
            if num in dict_counter:
                dict_counter[num] += 1
            else:
                dict_counter[num] = 1
        return dict_counter




if __name__ == '__main__':
    N, P = map(int, input().split())

    d = prime_factorization(P)

    cnt = 1

    for key, value in d.items():
        while value >= N :
            cnt *= key
            value -= N
    if N == 1:
        print(P)
    else:
        print(cnt)


Measured memory_bytes: 43320
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

typedef long long ll;

int main(int argc, char* argv[])
{
  ll n;
  std::cin >> n;

  std::vector< ll > va(n, 0);
  std::vector< ll > vb(n, 0);
  std::vector< ll > vc(n, 0);
  for (int i = 0; i < n; i++) {
    std::cin >> va[i];
  }
  for (int i = 0; i < n; i++) {
    std::cin >> vb[i];
  }
  for (int i = 0; i < n; i++) {
    std::cin >> vc[i];
  }

  std::sort(va.begin(), va.end());
  std::sort(vc.begin(), vc.end());

  std::vector< ll >::iterator ita;
  std::vector< ll >::iterator itb;
  std::vector< ll >::iterator itc;

  ll ans = 0;

  for (itb = vb.begin(); itb != vb.end(); itb++) {
    ita = std::lower_bound(va.begin(), va.end(), *itb);
    itc = std::upper_bound(vc.begin(), vc.end(), *itb);
    //std::cout << (va.size() - std::distance(va.begin(), ita)) << " " << *itb << " " << (vc.size() - std::distance(vc.begin(), itc)) << std::endl;
    ans += std::distance(va.begin(), ita) * (n - std::distance(vc.begin(), itc));
  }

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


Measured memory_bytes: 2688
#include <iostream>

using namespace std;

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

    int a, max_a = 0, min_a = 1000;
    for (int i = 0; i < n; i++) {
        cin >> a;
        max_a = max(a, max_a);
        min_a = min(a, min_a);
    }

    cout << (max_a-min_a) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int N,T;
   cin>>N>>T;
   int c,t;
   int m=1010;
   rep(i,N){
       cin>>c>>t;
       if(t<=T){
           m=min(m,c);
       }
   }
   if(m==1010){
       cout<<"TLE"<<endl;
   }
   else{
       cout<<m<<endl;
   }
     
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n;
  cin >> n;
  vector<ll> a(n),b(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  ll ans = 0;
  // ll pa,pb;
  // pa = pb = 0;
  for(int i = 28; i>=0;i--){
    sort(b.begin(),b.end());
    int c1 = 0;
    // cout << "i " << i << endl;
    rep(j,n){
      ll lb = (1<<i) - a[j];
      ll ub = (1<<(i+1)) - 1 - a[j];
      // cout << ub << " " << lb << endl;
      // cout << (upper_bound(b.begin(),b.end(),ub) - lower_bound(b.begin(),b.end(),lb)) << endl;
      c1 += (upper_bound(b.begin(),b.end(),ub) - lower_bound(b.begin(),b.end(),lb));
      c1 = c1 & 1;
      lb += 1<<(i+1);
      ub += 1<<(i+1);
      c1 += (upper_bound(b.begin(),b.end(),ub) - lower_bound(b.begin(),b.end(),lb));
      c1 = c1 & 1;
    }
    if(c1) {
      ans = ans | (1<<i);
    }
    rep(j,n){
      a[j] = a[j] & ((1<<i) -1);
      b[j] = b[j] & ((1<<i) -1);
    }
  }
  cout << ans << endl;

  return 0;
    

}


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

#define INF 2e9

#define REP(i,n) for(int i = 0; i < n;++i)
#define REPA(i,a,n) for(int i = a; i < n; ++i)
#define REPR(i,a) for(int i = a; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
template<typename A> void psn(A a){ cout << a << endl; }
template<typename A, typename... B> void psn(A a, B... b){ cout << a << ' '; psn(b...); }

int main(void) {
    
    int N, a, count = 0;
    ll sum = 1, temp = 0, m = 998244353;
    cin >> N;
    
    vi A(N);
    vector<ll> D(N, 0);
    REP(i, N) {
        cin >> A[i];
        D[A[i]]++;
    }

    if(N == 1){
        if(D[0] == 1) psn(1);
        else psn(0);
        return 0;
    }
    
    if(A[0] != 0) {
        psn(0);
        return 0;
    }

    REP(i, N - 1){
        if(D[i] == 0 && count != N){ // 途中で辺がなくなる場合
            psn(0);
            return 0;
        }
        if(i == 0 && D[i] != 1){ // 頂点が一つでない場合
            psn(0);
            return 0;
        }
        
        count += D[i]; // 計算済みの頂点の数
        if(i == 0){
            sum = 1;
            continue;
        }
        
        if(D[i - 1] == 1) continue;
        
        // sum *= pow(D[i-1], D[i]);
        // Dが大きいとmで割る前にオーバーフローしてしまう
        temp = D[i];
        while(temp > 0){
            sum = (sum * D[i - 1]) % m;
            temp--;
        }
    }
    
    psn(sum);
    
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<queue>
#include<cstdio>
using namespace std;
int n, q;
typedef pair<string, int> P;
queue <P> que; 
int main(){
	scanf("%d%d", &n, &q);
	for(int i = 0; i < n; i++){
		string t;
		cin >> t; 
		int len;
		scanf("%d", &len);
		que.push({t, len});
	}
	int sum = 0;
	while(!que.empty()){
		P m = que.front(); que.pop();
		if(m.second <= q){
			sum += m.second;
			cout << m.first;
			printf(" %d\n", sum);
		}else{
			m.second -= q;
			sum += q;
			que.push(m);
		}
	}
	return 0;
} 


Measured memory_bytes: 6484
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
struct graph
{
	int to,next;
}gr[1000005];
int n,num,cnt,tot,ans,head[1000005],a[1005][1005],c[1005][1005],in[1000005],t[1000005],day[1000005];
void border(int u,int v)
{
	cnt++;
	gr[cnt].to=v;
	gr[cnt].next=head[u];
	head[u]=cnt;
	return;
}
void topsort()
{
	for(int i=1;i<=tot;i++)
	{
		int u=t[i];
		for(int j=head[u];j;j=gr[j].next)
		{
			int v=gr[j].to;
			day[v]=day[u]+1;
			in[v]--;
			if(!in[v]) t[++tot]=v;
		}
	}
	for(int i=1;i<=num;i++) ans=max(ans,day[i]);
	return;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<n;j++)
		{
			scanf("%d",&a[i][j]);
			if(!c[i][j]&&!c[j][i]) c[i][j]=c[j][i]=++num;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=2;j<n;j++)
		{
			border(c[i][a[i][j-1]],c[i][a[i][j]]);
			in[c[i][a[i][j]]]++;
		}
	}
	for(int i=1;i<=num;i++)
	  if(!in[i])
	  {
	  	t[++tot]=i;
	  	day[i]=1;
	  }
	topsort();
	if(tot!=num) puts("-1");
	else printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 31488
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
#include <sstream>

using namespace std;

int INF = 1e9 + 7;

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

vector<vector<ll>> dp(310, vector<ll>(310, 0));

int main() {
	int n, m;
	while (cin>>n>>m) {
		vector<int> c(n + 1), v(n + 1), d(n + 1), l(n + 1);

		for (int i = 1; i <= n; i++) {
			string s;
			cin.ignore();
			getline(cin, s);
			cin >> c[i] >> v[i] >> d[i] >> l[i];
		}

		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {

				if (j - c[i] >= 0) dp[i][j] = max(dp[i - 1][j], dp[i][j - c[i]] + v[i]);
				else dp[i][j] = dp[i - 1][j];

			}
		}

		ll ans = 0;
		for(int i=1; i<=m; i++) ans = max(ans, dp[n][i]);

		for (int i = 0; i <= 305; i++) {
			for (int j = 0; j <= 305; j++) {
				dp[i][j] = 0;
			}
		}

		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {

				if (j - c[i] >= 0) dp[i][j] = max(dp[i - 1][j], dp[i][j - c[i]] + d[i]);
				else dp[i][j] = dp[i - 1][j];

			}
		}

		for (int i = 1; i <= m; i++) ans = max(ans, dp[n][i]);

		for (int i = 0; i <= 305; i++) {
			for (int j = 0; j <= 305; j++) {
				dp[i][j] = 0;
			}
		}

		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= m; j++) {

				if (j - c[i] >= 0) dp[i][j] = max(dp[i - 1][j], dp[i][j - c[i]] + l[i]);
				else dp[i][j] = dp[i - 1][j];

			}
		}

		for (int i = 1; i <= m; i++) ans = max(ans, dp[n][i]);

		cout << ans << endl;
	}
}


Measured memory_bytes: 3416
#include <bits/stdc++.h>
#define ll long long
#define mod 998244353
using namespace std;

ll fact[300001],inv[300001];

ll gcd(ll a,ll b,ll*x,ll*y){
	if(a%b==0){
		*x=0;	*y=1;
		return b;
	}
	ll x1,y1,ans=gcd(b,a%b,&x1,&y1);
	*x=y1;	*y=x1-(a/b)*y1;
	return ans;
}

ll ncr(ll n,ll r){
	if(r<0 || r>n)	return 0;
	ll ans=fact[n];
	ans*=inv[r];	ans%=mod;
	ans*=inv[n-r];	ans%=mod;
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll i,j;	fact[0]=1;
	for(i=1;i<=300000;i++){
		fact[i]=(fact[i-1]*i)%mod;
	}
	gcd(fact[300000],mod,&i,&j);
	i%=mod;	i=(i+mod)%mod;
	inv[300000]=i;
	for(i=300000;i>0;i--){
		inv[i-1]=(inv[i]*i)%mod;
	}

	ll n,a,b,k;	cin>>n>>a>>b>>k;

	ll ans=0;

	for(i=0;i<=k;i++){
		if(i*a > k)	break;
		if((k-i*a)%b != 0)	continue;
		ans+=(ncr(n,i)*ncr(n,(k-i*a)/b))%mod;
	}

	cout<<ans%mod<<endl;

	return 0;
}

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

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))

#define fillInt(xs)        \
  for (int i = 0; i < (xs).size(); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs)       \
  for (int i = 0; i < (xs).size(); i++) \
    scanf("%ld", &xs[i]);
#define fillDouble(xs)       \
  for (int i = 0; i < (xs).size(); i++) \
    scanf("%lf", &xs[i]);
#define fillString(xs)       \
  for (int i = 0; i < (xs).size(); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

long minr[100005];
long minrinv[100005];
long maxr[100005];

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

  int n;
  cin >> n;

  vector<P> lr;
  rep(i, n) {
    long l, r;
    cin >> l >> r;
    lr.push_back({l, r});
  }
  sortv(lr);

  minr[0] = INF;
  maxr[0] = 0;
  minrinv[n] = INF;
  long allmin = INF;
  rep(i, n) {
    minr[i+1] = min(minr[i], lr[i].second);
    maxr[i+1] = max(maxr[i], lr[i].second);
    minrinv[n-1-i] = min(minrinv[n-i], lr[n-1-i].second);
    allmin = min(allmin, lr[i].second);
  }

  long res = 0;
  long maxl2 = lr[n-1].first;
  rep(i, n-1) {
    long maxl1 = lr[i].first;
    long minr1a = minr[i+1];
    long minr2a = minrinv[i+1];
    res = max(res, max(0L, minr1a - maxl1 + 1) +  max(0L, minr2a - maxl2 + 1));
    long minr1b = maxr[i+1];
    res = max(res, max(0L, minr1b - maxl1 + 1) +  max(0L, allmin - maxl2 + 1));
  }

  cout << res << endl;
}


Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())

// https://atcoder.jp/contests/abc137/submissions/6847236

int p;
const ll INF = 1e18; // O(|V||E|)
int MAX_V = 3000;
vector<ll> d(2501, INF); // 0からの時間
int n, e, r; // 頂点、辺、スタート
bool bell(int n, vector<vector<pii> > edge, int s) {
    d[s] = 0;
    
    rep(cnt, 2 * MAX_V) {
        
        rep(from, n) {
            if (d[from] == INF) continue;
            rep(j, SZ(edge[from])) {
                int to = edge[from][j].F;
                int cost = edge[from][j].S;
                
                if (d[to] > d[from] + cost) {
                   
                    d[to] = d[from] + cost;
                    if (cnt >= MAX_V - 1 && d[to] != INF) {
                        d[to] = -INF;
                        if (to == n - 1) return 0;
                    }
                }
            }
        }
        
    }
    
    return 1;
    
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> e >> p;
    
    vector<vector<pii> > edge(n);
    rep(i, e) {
        int s, t, d;
        cin >> s >> t >> d;
        s--; t--;
        d = d - p;
        edge[s].eb(t, -d);
    }
    
    if (bell(n, edge, r) == 0) {
        out(-1);
    } else {
        out(max(0LL, -d[n - 1]));
    }
    
}


Measured memory_bytes: 512
x, k, d = gets.split.map(&:to_i)

x = x.abs

if x >= k * d
  puts x - k * d
else
  q = x / d
  r = x % d

  if r < (r - d).abs
    puts (k - q).even? ? r : (r - d).abs
  else
    puts (k - (q + 1)).even? ? (r - d).abs : r
  end
end

Measured memory_bytes: 14324