akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		var a=new Data[n];
		for(int i = 0;i<n;i++) {
			string[] e=sc.Sa;
			a[i]=new Data(i+1,e[0],int.Parse(e[1]));
		}
		Array.Sort(a,(x,y)=>{var c=x.s.CompareTo(y.s);return c==0?y.a.CompareTo(x.a):c;});
		//a=a.OrderBy(x=>x.s).ThenByDescending(x=>x.a).ToArray();
		for(int i = 0;i<n;i++) {Console.WriteLine("{0}",a[i].n);}
	}
}

public class Data{
	public int n,a;
	public string s;
	public Data(int n,string s,int a){
		this.n=n;
		this.s=s;
		this.a=a;
	}
}

public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return a[n];}}
	public string Sz{get{return Console.ReadLine();}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2(int b){return Array.ConvertAll((((b&1)!=0?"0 ":"")+Console.ReadLine()+((b&2)!=0?" 0":"")).Split(),int.Parse);}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public string[] Sa2{get{return (Console.ReadLine()+" 0").Split();}}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 11476
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  while(true){
    int d,n,m;
    vector<int> s;
    scanf("%d",&d);
    if(d==0) return 0;
    scanf("%d %d",&n,&m);
    for(int i=0;i<n-1;i++){
      int x;
      scanf("%d",&x);
      s.push_back(x);
    }
    s.push_back(0);
    s.push_back(d);
    sort(s.begin(),s.end());
    int ans = 0;
    for(int i=0;i<m;i++){
      int a;
      scanf("%d",&a);
      int b = upper_bound(s.begin(),s.end(),a) - s.begin();
      ans += min(s[b]-a,a-s[b-1]);
    }
    printf("%d\n",ans);
  }
}

Measured memory_bytes: 3064
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let s: Vec<char> = iterator.next().unwrap().chars().collect();

    if n % 2 != 0 {
        return "No".to_string();
    }

    for i in 0..(n / 2) {
        if s[i] != s[n / 2 + i] {
            return "No".to_string();
        }
    }

    return "Yes".to_string();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main(){
  string h;
  bool ac;
  cin>>a>>b>>c>>h;
  b+=c;
  for(int i=0;i<h.length();++i){
    if(h[i]=='a'&&b){cout<<"Yes"<<endl;--b;}
    else if(h[i]=='b'&&b&&c){
      cout<<"Yes"<<endl;
      --b;--c;
    }
    else{cout<<"No"<<endl;}
  }
}

Measured memory_bytes: 896
import sys

N = int(input())

A = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(2)]

res = 0

for i in range(N):
    cnt = 0
    for j in range(i + 1):
        cnt += A[0][j]
    cnt += A[1][i]
    for j in range(i + 1, N):
        cnt += A[1][j]
    
    res = max(cnt, res)

print(res)

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

ans_list = [0] * N
total = 0
for i in range(N):
    if i + A[i] < N:
        ans_list[i + A[i]] += 1
    if i - A[i] >= 0:
        total += ans_list[i - A[i]]

print(total)


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

using namespace std;

int main(){
 	string a,b,c;
  	cin >> a >> b >> c;

  	a = a + b + c;

    int num = stoi(a);
  	if(num%4 == 0){
		cout << "YES";
    }else{
     	cout << "NO";
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int x,ans = 8,n = 600;
      
    cin >> x;
  
  	for(int i = 0;i < 8;i++){
      if(x < n)
        break;
      n += 200;
      ans--;
    }
  
  	cout << ans << endl;
}

Measured memory_bytes: 3620
// http://arc084.contest.atcoder.jp/submissions/1737556
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
 
#define debug(format, ...) printf(format, __VA_ARGS__);
 
const int K_ = int(1e5), B = 50;
 
int K;
bool vis[K_][B+1];
 
int main() {
#ifdef IN_MY_COMPUTER
  freopen("d.in", "r", stdin);
#endif
  scanf("%d", &K);
 
  int ub = 0;
  for(int k = K; k > 0; k /= 10) ub += k % 10;
  
  priority_queue< pii, vector<pii>, greater<pii> > pq;
  pq.emplace(0, 0);
  vis[0][0] = true;
 
  while(!pq.empty()) {
    int u, s; tie(s, u) = pq.top(); pq.pop();
    if(u == 0 && s > 0) {
      printf("%d\n", s);
      return 0;
    }
    for(int d = 0; d <= 1; d++) {
      int v = (u * 10 + d) % K;
      int t = s + d;
      if(t <= B && !vis[v][t]) {
        vis[v][t] = true;
        pq.emplace(t, v);
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 6392
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC046
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var n = nk[0];
            var k = nk[1];

            var result = k;
            for (int i = 0; i < n - 1; i++)
            {
                result *= (k - 1);
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 28192
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
int main() {
	int a,b;

	cin >> a>>b;

	if (13 <= a) {
	cout << b << endl;
	}
	else if (6 <= a&&a <= 12) {
		cout << b/2 << endl;
	}
	else if(a<=5){
		b = 0;
		cout << b << endl;
	}
	
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, A, B;
	cin >> N >> A >> B;


	auto digisum = [&](int n) {
		int sum = 0;
		while (n) { sum += n % 10; n /= 10; }
		return sum;
	};

	int ans = 0;
	for (int i = 1; i <= N; i++) {
		int tmp = digisum(i);
		if (A <= tmp && tmp <= B) {
			ans += i;
			DMP(i);
		}
	}

	cout << ans << "\n";

	return 0;
}

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

import static java.lang.Math.*;
import static java.lang.System.*;

class X {
  public int v;
  public X p;
  public HashSet<X> c = new HashSet<>();
}

public class Main {
  static void exec(X root) {
    for (X x : root.c) {
      x.v += root.v;
      exec(x);
    }
  }
  
  
  public static void main(String ... args) throws Exception {
    if (false) {
      Scanner sc = new Scanner(System.in);
      // 整数の入力
      int a = sc.nextInt();
      // スペース区切りの整数の入力
      int b = sc.nextInt();
      int c = sc.nextInt();
      // 文字列の入力
      String s = sc.next();
      // 出力
      out.println((a+b+c) + " " + s);

      return;
    }
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    X[] tree = new X[n];
    for (int i=0; i<n; i++) {
      tree[i] = new X();
    }
    for (int i=0; i<n-1; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      tree[b-1].p = tree[a-1];
      tree[a-1].c.add(tree[b-1]);
    }
    for (int i=0; i<q; i++) {
      int p = sc.nextInt();
      int x = sc.nextInt();
      tree[p-1].v += x;
    }

    X root = null;
    for (X x : tree) {
      if (x.p == null) {
        root = x;
        break;
      }
    }

    exec(root);
    
    PrintWriter pw = new PrintWriter(out, false);
    for (X x : tree) {
      pw.println(x.v);
    }
    pw.flush();
  }
  
  static int correct(Node c0, Node[] nodes, int lim) {
    if (c0.isCorrected) {
      return 0;
    }
//    err.println("correct: " + c0.id);
    c0.isCorrected = true;
    int ret = 0;
    int branch = 0;
    if (c0.jam) {
      ret++;
    }
    for (Integer x : c0.list) {
      int co = correct(nodes[x], nodes, 1);
      ret += co;
      if (co >= 1) {
        branch++;
        if (branch >= lim) {
          return ret;
        }
      }
    }
    return ret;
  }

  static class Node {
    public Node(int id) {
      this.id = id;
    }
    public final int id;
    public final ArrayList<Integer> list = new ArrayList<>();
    public boolean jam;
    public boolean isCorrected;
  }

  static int ama(int a, int b) {
    if (a == b) {
      return -1;
    }
    if (b > a) {
      int swap = b;
      b = a;
      a = swap;
    }
    int lim = a - 1;
    int fl = min(a - b, b);
    for (int i=lim; i>=fl; i--) {
      if (a % i == b %i) {
        return i;
      }
    }
    return 1;
  }
  
  static int gcd(int a, int b) {
    if (b > a) {
      int swap = b;
      b = a;
      a = swap;
    }
	int yo = a % b;
    if (yo == 0) {
      return b;
    }
    return gcd(b, yo);
  }
}


Measured memory_bytes: 239220
#include<string>
#include<map>
#include<iostream>

int N,Q;
int main(){
	while (std::cin >>N >>Q && N){
		std::map<int,std::string> start; // 西暦=> その年に始まった元号の名前
		std::map<std::string,int> finish; // 元号=> 何年まで続いたことがわかっているか
		
		std::string name;
		for(int i=0;i<N;++i){
			int local, western;
			std::cin >> name >> local >> western;
			start[western-local+1]=name;
			if(western>finish[name]) finish[name]=western;
		}
		for(int i=0;i<Q;++i){
			int western;
			std::cin >> western;
			bool isUnknown=true;
			for (auto& pair : start){
				if(pair.first<=western && finish[pair.second]>=western){
					std::cout << pair.second << " " << western-pair.first+1 << std::endl;
					isUnknown=false;
					break;
				}
			}
			if(isUnknown) std::cout << "Unknown" << std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1404
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <stack>

int main()
{
	std :: string Str;
	std :: cin >> Str;

	int Len = Str.size(), Ans = 0;
	std :: stack<int> Stack;
	Stack.push(Str[0] - '0');
	for (int i = 1; i < Len; i++) {
		int Now = Str[i] - '0';
		if (Stack.empty()) Stack.push(Now);
		else
		if (Now != Stack.top()) {
			Stack.pop();
			Ans += 2;
		} else {
			Stack.push(Now);
		}
	}

	printf("%d", Ans);

	return 0;
}


Measured memory_bytes: 768
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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
 */
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);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskD {
		final int n = 100;

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int a = in.nextInt();
			int b = in.nextInt();
			char[][] s;
			if (a <= b) {
				s = solve(a, b);
			} else {
				s = invert(solve(b, a));
			}

			out.println(n + " " + n);
			for (int i = 0; i < n; i++) {
				out.println(new String(s[i]));
			}
		}

		private char[][] invert(char[][] s) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					s[i][j] = (char) (s[i][j] ^ '.' ^ '#');
				}
			}
			return s;
		}

		private char[][] solve(int a, int b) {
			char[][] s = new char[n][n];
			for (char[] arr : s) {
				Arrays.fill(arr, '.');
			}
			--a;

			for (int r = 0; r + 2 < n; r += 4) {
				for (int c = 0; c + 2 < n; c += 4) {
					if (a == 0 || b == 0) {
						break;
					}
					--a;
					--b;
					for (int i = 0; i < 3; i++) {
						for (int j = 0; j < 3; j++) {
							s[r + i][c + j] = '#';
						}
					}
					s[r + 1][c + 1] = '.';
				}
			}

			outer:
			while (b > 0) {
				for (int r = 0; r + 2 < n; r += 4) {
					for (int c = 0; c + 2 < n; c += 4) {
						boolean ok = true;
						for (int i = 0; i < 3; i++) {
							for (int j = 0; j < 3; j++) {
								if (s[r + i][c + j] == '#') {
									ok = false;
								}
							}
						}
						if (ok) {
							s[r + 1][c + 1] = '#';
							--b;
							continue outer;
						}
					}
				}
			}

			return s;
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}



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

using namespace std;

typedef long long ll;

int main()
{
  ll N; cin >> N;
  ll t = 1, a = 1;
  for(int i = 0; i < N; i++) {
    ll T, A; cin >> T >> A;
    ll l = 0, r = 1000000000000000010LL/max(T, A);
    while(l + 1 < r) {
      ll m = (l + r) / 2;
      if(t <= T*m && a <= A*m) r = m;
      else l = m;
    }
    t = T*r, a = A*r;
  }
  cout << t + a << endl;
  
  return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define EPS 1e-9
#define INF  1e15 +1    /// 10^15 + 1
#define INF2 1<<63 /// 2^63
#define all(a)  a.begin(),a.end()
#define forn(i,n) for(int i=0;i<n;i++)
#define dbg(x) cout << #x"=" << x << '\n';
#define dbg_(x,y) cout << #x"=" << x << " " << #y"=" << y << '\n';
#define MOD 1000000007

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector < pii > vpii;
typedef vector < pll > vpll;
typedef vector < vpii > vvpii;

ll n,x,i,j,k,a,b,c,m,t,w;
vpll v;
vll dp;

int main(){
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
    cin>>n>>w;
    v.assign(n,mp(0,0));
    dp.assign(w+1,0);
    for(i=0;i<n;i++){
        cin>>v[i].fi>>v[i].se;
    }
    for(i=0;i<n;i++){
        for(j=0;j<=w;j++){
            if(j-v[i].fi>=0) dp[j-v[i].fi] = max(dp[j-v[i].fi],v[i].se + dp[j]);
        }
    }
    cout<<dp[0];
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

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

	int n;
	cin >> n;

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

	vector<ll> dp(n+1, 0);
	vector<ll> dp2(202020, 0);
	dp[0] = 1;

	rep(i, n){
		if(c[i-1] == c[i]){
			dp[i+1] = dp[i];
		}else{
			dp[i+1] = dp[i] + dp2[c[i]];
			dp[i+1] %= MOD;

			dp2[c[i]] += dp[i];
			dp2[c[i]] %= MOD;
		}
	}

	cout << dp[n] << endl;

}


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

using namespace std;
typedef long long int ll;

const int MAXN = 1e5 + 5;
int n, par[MAXN], mn;
ll d, sz[MAXN], h[MAXN], sum = 0;
map <ll, ll> mp;
vector <int> adj[MAXN];
bool can = false, mark[MAXN];
vector <pair<ll, int>> v;

void dfs(int v, int parv){
	mark[v] = true;
	sum += h[v];
	for(auto u: adj[v]){
		if(!mark[u]){
			h[u] = h[v] + 1ll;
			dfs(u, v);
		}
		else if(u != parv)
			can = true;
	}
	return;
}

bool check(){
	for(int i = 1; i <= n; i++)
		if(i != mn && (par[i] < 1 || par[i] > n)){
			return true;
		}
	dfs(mn, -1);
	for(int i = 1; i <= n; i++)
		if(!mark[i])
			can = true;
	if(sum != -v[n - 1].first)
		can = true;
	return can;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for(ll i = 1; i <= n; i++){
		cin >> d; sz[i] = 1ll;
		mp[d] = i;
		v.push_back({-d, i});
	}
	sort(v.begin(), v.end());
	for(int i = 0; i < n - 1; i++){
		d = -v[i].first;
		ll ind = v[i].second;
		ll dpar = d + (2ll * sz[ind]) - (ll)n;
		if(!mp[dpar] || mp[dpar] == ind){
			cout << -1 << endl;
			return 0;
		}
		par[ind] = mp[dpar];
		sz[par[ind]] += sz[ind];
		adj[par[ind]].push_back(ind);
		adj[ind].push_back(par[ind]);
	}
	mn = v[n - 1].second;
	if(check()){
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0; i < n - 1; i++){
		cout << par[v[i].second] << " " << v[i].second << '\n';
	}
	return 0; 
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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 main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int d, g;
	cin >> d >> g;

	vector<int> p(d), c(d);
	for (int i = 0; i < d; i++) {
		cin >> p[i] >> c[i];
	}

	int pSum = accumulate(begin(p), end(p), 0);

	vector<vector<int>> dp(d + 1, vector<int>(pSum + 1)); //スコア[p[i]のiまで][解いた問題数]
	for (int i = 1; i <= d; i++) {
		for (int j = 1; j <= pSum; j++) {
			int ma = dp[i - 1][j];
			for (int k = j - 1; k >= (j - p[i - 1]); k--) {
				ma = max(ma, dp[i - 1][k] + (j - k) * 100 * i);

				if (k == j - p[i - 1]) {
					// コンプリート
					ma = max(ma, dp[i - 1][k] + (j - k) * 100 * i + c[i - 1]);
				}

				if (k == 0) {
					break;
				}
			}
			dp[i][j] = ma;
		}
	}

	for (int i = 0; i <= pSum; i++) {
		if (dp[d][i] >= g) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,d,a;
    cin >> n >> d >> a;
    vector<ll> x(n),cnt(n+1,0),h(n);
    vector<P> p;
    rep(i,n){
        ll s,t;
        cin >> s >> t;
        p.push_back(P(s,t));
    }
    SORT(p);
    rep(i,n){
        tie(x[i],h[i]) = p[i];
    }
    x.push_back(INF);
    ll ans = 0;
    rep(i,n){
        if (i > 0) cnt[i] += cnt[i-1];
        h[i] -= cnt[i]*a;
        if (h[i] <= 0) continue;
        ll nxt = (h[i]%a ? h[i]/a+1 : h[i]/a);
        ans += nxt;
        ll r = upper_bound(all(x),x[i]+2*d)-x.begin();
        cnt[i] += nxt;
        cnt[r] -= nxt;
    }
    PRINT(ans);
}


Measured memory_bytes: 11372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  string S;
  cin >> S;
  int count = 0;
  rep(i,3){
    if(S.at(i) == 'R'){
      count ++;
    }
  }
  if(count == 2){
    if(S.at(1) == 'S'){
      count --;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
            #include <ext/pb_ds/assoc_container.hpp>
            #include <ext/pb_ds/tree_policy.hpp>
            using namespace std;
            using namespace __gnu_pbds;
            #define rep(i,a,b) for(ll i =a; i<b;++i)
            #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            #define endl "\n"
            #define pb push_back
            #define F first
            #define S second
            #define print(a)       for(auto x : a) cout << x << " "; cout << endl
            #define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
            #define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl
            #define mk(x,y)  make_pair(x,y)
            typedef int ll;
            const ll N =  4e6+ 5 ;
            const ll mod = 998244353;
            ll   n ,a[N];
    ll pow_mod_m(ll a , ll n)
    {
        if(!n)
            return 1;
        ll pt =  pow_mod_m(a,n/2);
        pt *= pt , pt %= mod;
        if(n&1)
            pt *= a  ,pt %= mod;
        return pt;
    }


    int main()
    {
         IOS;
         int ts =1;
      ///   cin >> ts;
         while(ts--)
         {
            cin >> n;
            ll l = 360*n /__gcd(360 ,n);
            cout << l /n << endl;
         }
    }



Measured memory_bytes: 3604
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

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

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 10;
const int NEG_INF = numeric_limits<int>::min() / 10;
typedef long long ll;
typedef pair<int, int> P;
string inp;
vector<int> ind_mat[26];

/*
P check(int i) {
    vector<int> index = ind_mat[i];
    REP(i, index.size() - 1) {
        for (int j = i + 1; j < index.size(); j++) {
            int cnt = j - i + 1;
            int w = index[j] - index[i] + 1;
            if (cnt > w / 2) {
                return P(index[i] + 1, index[j] + 1);
            }
        }
    }
    return P(-1, -1);
}
*/
P check(int i) {
    vector<int> index = ind_mat[i];
    REP(i, index.size() - 1) {
        int diff = index[i + 1] - index[i];
        if (diff <= 2) {
            return P(index[i] + 1, index[i+1] + 1);
        }
    }
    return P(-1, -1);
}

int main(int argc, char const* argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> inp;
    REP(i, inp.size()) {
        ind_mat[inp[i] - 'a'].push_back(i);
    }
    /*
    REP(i, 26) {
        cout << "DBG" << i << endl;
        for (auto x : ind_mat[i]) {
            cout << x << " ";
        }
        cout << endl;
    }
    */
    REP(i, 26) {
        if (ind_mat[i].size() <= 1) {
            continue;
        }
        P res = check(i);
        if (res.first != -1 and res.second != -1) {
            cout << res.first << " " << res.second << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}


Measured memory_bytes: 1104
// I give up.
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s1, s2;
    cin >> s1 >> s2;
    unsigned long long a = atol(s1.c_str());
    unsigned long long b = atol(s2.erase(s2.find("."), 1).c_str());
    cout << (a * b / 100) << endl;
    return 0;
}

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

int main(){
  string s;
  cin>>s;
  if(s=="SAT"){
    cout<<1<<endl;
  }
  else if(s=="FRI"){
    cout<<2<<endl;
  }
  else if(s=="THU"){
    cout<<3<<endl;
  }
  else if(s=="WED"){
    cout<<4<<endl;
  }
  else if(s=="TUE"){
    cout<<5<<endl;
  }
  else if(s=="MON"){
    cout<<6<<endl;
  }
  else if(s=="SUN"){
    cout<<7<<endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll sum = a+b ;
    ll re = n/sum;
    ll ans;
    ll amari;
    if(n-sum*re>a) amari = a;
    else amari = n- sum*re;
    ans = re*a + amari;

    cout << ans << endl;
    return 0;




}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>

using namespace std;

const int maxn = 100002;

int n, m, year[maxn];
unordered_map<int, vector<int> > groups;

bool mycmp(int& a, int& b) {
	return year[a] < year[b];
}

int main() {

	cin >> m >> n;

	vector<string> ans(n);

	int p;
	for (int i = 0; i < n; ++i)
	{
		cin >> p >> year[i];
		groups[p].push_back(i);
	}

	for (unordered_map<int, vector<int> >::iterator it = groups.begin();
		it != groups.end(); ++it) {
		sort(it->second.begin(), it->second.end(), mycmp);

		string firstPart = to_string(it->first);
		if (firstPart.length() < 6)
			firstPart = string(6 - firstPart.length(), '0') + firstPart;

		for (int k = 0; k < it->second.size(); ++k) {
			int cur = it->second[k];
			string secondPart = to_string(k+1);
			if (secondPart.length() < 6)
				secondPart = string(6 - secondPart.length(), '0') + secondPart;

			ans[cur] = firstPart + secondPart;
		}
	}

	for (int i = 0; i < n; ++i)
		cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 16164
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

#include <vector>
using namespace std;

/* Union-Find-Tree */
/* 必ず要素数をコンストラクタに入れること */
template <class T = long long>
class Union_Find {
  using size_type = std::size_t;
  using _Tp = T;
public:

  vector<_Tp> par;
  vector<_Tp> rnk;

  // 親の根を返す。値の変更は認めない。
  const _Tp & operator[] (size_type child) {
    find(child);
    return par[child];
  }

  Union_Find (_Tp n) {
    par.resize(n), rnk.resize(n);
    for (int i = 0; i < n; ++i) {
      par[i] = i;
      rnk[i] = 0;
    }
  }

  // 木の根を求める
  _Tp find(_Tp x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = find(par[x]);
  }

  // xとyの属する集合を併合
  void merge(_Tp x, _Tp y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (rnk[x] < rnk[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rnk[x] == rnk[y]) rnk[x]++;
    }
  }

  // xとyが同じ集合に属するか否か
  bool same(_Tp x, _Tp y) {
    return find(x) == find(y);
  }
};


int main() {
  int n,k,l;
  cin >> n >> k >> l;
  Union_Find<long long> uf_road(n+1), uf_train(n+1);

  int r,s;
  rep(i,k) {
    cin >> r >> s;
    uf_road.merge(r, s);
  }

  rep(i,l) {
    cin >> r >> s;
    uf_train.merge(r, s);
  }

  vector<pair<int,int> > com;
  map<pair<int,int>, int> mp;

  for (int i = 1; i <= n; ++i) {
    int a, b;
    a = uf_road[i];
    b = uf_train[i];
    com.push_back(make_pair(a,b));
    mp[make_pair(a,b)] += 1;
  }

  for (int i = 0; i < n; ++i) {
    cout << mp[com[i]] << " ";
  }

  END;
}


Measured memory_bytes: 19568
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <sstream>
#include <cassert>
#include <functional>
#include <cfloat>
#include <climits>
#include <cstring>
#include <stack>
#include <time.h>
#include <complex>
using namespace std;
int main()
{
int A, B;
cin >> A >> B;
	if (A == B) {
		cout << "Draw" << endl;
	}
	else if (A == 1 or (A > B and B != 1)) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Bob" << endl;
	}
return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
gpu_hash_table<int, int> mp;
#define ordered_set tree<ttgl, null_type,less<ttgl>, rb_tree_tag,tree_order_statistics_node_update>
 */
using ll = long long;
using ld = long double;
const ll MOD = 924844033;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 2001;
ll dp[2*mxN][mxN][2];
bool flag[2*mxN];
ll fact[mxN];
int n, k;
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>k;
    int tot = 0;
    fact[0] = 1;
    owo(i, 1, n+1) {
        fact[i] = (fact[i-1]*i)%MOD;
    }
    owo(i, 1, k+1) {
        int nxt = (n-i)/k+1;
        flag[tot+1] = true;
        tot+=nxt;
        flag[tot+1] = true;
        tot+=nxt;
    }
    dp[0][0][0] = 1;
    owo(i, 1, tot+1) {
        owo(j, 0, n+1) {
            dp[i][j][0] = (dp[i-1][j][0] + dp[i-1][j][1])%MOD;
            if(!flag[i]&&j<n) dp[i][j+1][1] = dp[i-1][j][0];
        }
    }
    ll res = 0;
    owo(i, 0, n+1) {
        ll incl = ((dp[tot][i][0] + dp[tot][i][1])*fact[n-i])%MOD;
        if(i&1) {
            res = (res + MOD - incl)%MOD;
        }else {
            res = (res + incl)%MOD;
        }
    }
    cout<<res<<"\n";
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int x[n], l[n];
    P ps[n];
    rep(i, n) cin >> x[i] >> l[i];
    
    rep(i, n) ps[i] = P(x[i] + l[i], x[i] - l[i]);
    sort(ps, ps + n);
    int cur = -1000000000;
    int ans = 0;
    rep(i, n) {
        if(cur <= ps[i].second) {
            ans++;
            cur = ps[i].first;
        }
    }

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

Measured memory_bytes: 1792
#pragma GCC optimize(2,3,"Ofast","unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
    char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
    in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
    in ll read()
    {
        ll x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
        x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
    }
    in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
    in int gs(char *s) {char c,*t=s;while(c=gc(),c<=32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
    in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
    in void flush() {if(C>1<<22) ot();}
    template <typename T>
    in void write(T x,char t)
    {
        int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
        if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
    }
    in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
#define pb push_back
const int N=1<<16|1,K=18,p=1e9+7;
int n,m,tot,ans,a[K],fac[N],inv[N],f[K][N],d[N];
in void M(int &x) {x-=p;x+=x>>31&p;}
in int c(int n,int m) {return n<m?0:1ll*fac[n]*inv[m]%p*inv[n-m]%p;}
int main()
{
	n=read(),m=read();tot=1<<n;fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<=tot;i++) inv[i]=1ll*(p-p/i)*inv[p%i]%p;
	for(int i=1;i<=tot;i++) fac[i]=1ll*fac[i-1]*i%p,inv[i]=1ll*inv[i]*inv[i-1]%p;
	for(int i=1;i<=m;i++) a[i]=read();sort(a+1,a+m+1);f[m+1][0]=1;
	for(int i=m;i;i--) for(int j=0;j<tot;j++)
	{
		M(f[i][j]+=f[i+1][j]);
		for(int k=0,t;k<n;k++) if(!(j&(1<<k)))
		t=tot-a[i]-j,M(f[i][j+(1<<k)]+=1ll*f[i+1][j]*c(t,(1<<k)-1)%p*fac[1<<k]%p);
	}
	for(int i=0;i<tot;i++)
	{
		d[i]=d[i>>1]+(i&1);f[1][i]=1ll*f[1][i]*fac[tot-i-1]%p;
		if(d[i]&1) M(ans+=p-f[1][i]); else M(ans+=f[1][i]);
		// cout<<ans<<" ";
	}
	write(1ll*ans*tot%p,'\n');
	return ot(),0;
}
//Author: disangan233


Measured memory_bytes: 8456
#define DINGER_GISBAR
#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<int>(1e9) + 7;
//{{{TEMPLATE_BEGIN
#include <unistd.h>
using namespace std::rel_ops;
#ifdef ZEROKUGI
#include <dumper.hpp>
#define dump(x) dumper::dumper(cerr, __LINE__, (#x), (x), 50, 1, 1)
#define tick(...) dumper::tick(__VA_ARGS__)
#pragma message "Compiling " __FILE__
#else
#define dump(x)
#define tick(...)
#endif
typedef long long lint;
typedef unsigned long long ulint;
typedef long double ldouble;
typedef vector<int> vint;
#define rep(i, n) \
    for (int i = 0, i##_len = static_cast<int>(n); i < i##_len; i++)
#define all(c) begin(c), end(c)
#define perm(c)   \
    sort(all(c)); \
    for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))
#define uniquenize(v) (v).erase(unique(all(v)), end(v))
#define cauto const auto &
#define memset(x, y) memset(x, y, sizeof(x))
#define popcount __builtin_popcount
#define gcd __gcd
inline lint bit(int x) { return 1LL << x; }
template <class T>
inline int size(const T& a) {
    return (int)a.size();
}
template <class T>
inline bool chmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
    return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T>& v, const char& c) {
    return make_pair(v, c);
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
#ifdef ZEROKUGI
    if (v.empty()) {
        cerr << "Error L" << __LINE__ << ": vector size is zero." << endl;
        exit(EXIT_FAILURE);
    }
#endif
    for (auto& x : v) is >> x;
    return is;
}
template <class T>
inline ostream& operator<<(ostream& os, const pair<vector<T>, char>& v) {
    bool t = 0;
    for (const T& x : v.first) {
        if (t) os << v.second;
        os << x;
        t = 1;
    }
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
    return os << v * ' ';
}
struct before_main {
    before_main() {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
        tick(0, 0);
    };
} __before_main;
//}}}TEMPLATE_END

int main() {
    string s;
    cin >> s;
    cout << s.substr(0, 4) + " " + s.substr(4) << endl;

}



Measured memory_bytes: 764
fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val numbers = readLine()!!.split(" ").map { it.toInt() }
    val ans = (0 until  n - 2).map { numbers.subList(it, it +3).let { (it[0] <= it[1] && it[1] <= it[2]) || (it[2] <= it[1] && it[1] <= it[0]) } }.filter { it }.count()
    println(ans)
}


Measured memory_bytes: 37748
x,k,d = list(map(int,input().split()))

x = abs(x)

m = x // d

if m >= k:
    ans = x - (d*k)

elif (k-m) % 2 == 0:
    ans = x - (d*m)

else:
    ans = x - (d*m) - d

print(abs(ans))

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

int main() {
	int cnt = 0;
	rep(i, 5) {
		int a; cin >> a;
		cnt += max(a, 40);
	}
	cout << cnt / 5 << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int N,K;
  	int d;
    int list[101]={};	
    cin>> N>>K;
   	int ans=N;
	for(int i=0; i< K; i++)
	{
      cin >> d;
      for(int j = 0; j< d; j++)
	  {
        int input;
        cin >>input;
        if (list[input]==0) ans =ans-1;
      	list[input] =list[input]+1;
      }
    }
    cout <<ans;
    return 0;
}


Measured memory_bytes: 3556
#include "bits/stdc++.h"
using namespace std;
#define LL long long

void Solve(){
   int n,k;
   cin>>n>>k;
   if(k%2 or n*4<k or k<n*2){
       puts("No");
       return;
   }
   int x = k/2;
   int y = k/4;
   
   if(x==n or y==n){
       puts("Yes");
       return;
   }
   
   while(k){
       k = k - 4;
       n--;
       int m = k/2;
       if(m==n){
           puts("Yes");
           return;
       }
   }
   puts("No");
}

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

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define ld long double
#define ff first
#define ss second

const long long MOD7 = 1000000007;

using namespace std;

vector<ll> RSQ(const vector<ll> &v) {
    vector<ll> ans(v.size() + 1);

    ans[0] = 0;
    for(size_t i = 1; i <= v.size(); i++) {
        ans[i] = ans[i - 1] + v[i - 1];
    }

    // for(int i = 0; i <= v.size(); i++) {
    //     cout << ans[i] << (i == v.size()? endl : " ");
    // }

    return ans;
}

int main() {
    ios::sync_with_stdio(0);
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> da(n), db(m);

    for(auto &ent : da)
        cin >> ent;

    for(auto &ent : db)
        cin >> ent;

    vector<ll> sa = RSQ(da), sb = RSQ(db); 

    ll ans = 0, i, j = m;
    for(i = 0; i <= n; i++) {
        
        if(sa[i] > k)
            break;
        
        while(j >= 0 and sb[j] > k - sa[i])
            j--;

        ans = max(ans, i + j);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9592
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
typedef pair<ll, ll>P;
ll h, w;
char a[1919][1919];
//進む方向
ll dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
//(i,j)までの適切な'#'から出発した場合の最短距離
ll d[1919][1919];
queue<P>que;
void bfs() {
	//ここから幅優先
	rep(i, h) { rep(j, w) { d[i][j] = 1e9 + 7; } }
	rep(i, h) {
		rep(j, w) {
			if (a[i][j] == '#') { que.push(P(i, j)); d[i][j] = 0; }
		}
	}
	while (que.size()) {
		P p = que.front(); que.pop();
		rep(i, 4) {
			ll nx = p.first + dx[i], ny = p.second + dy[i];
			if (nx >= 0 && ny >= 0 && nx < h && ny < w) {
				//ここでマッハッタン距離の更新と通ったかどうかの判別が同時に処理される
				if (d[nx][ny] > d[p.first][p.second] + 1) {
					d[nx][ny] = d[p.first][p.second] + 1;
					que.push(P(nx, ny));
				}
			}
		}
	}
}
signed main() {
	cin >> h >> w;
	rep(i, h) { rep(j, w) { cin >> a[i][j]; } }
	ll ans = 0;
	bfs();
	rep(i, h) {
		rep(j, w)ans = max(ans, d[i][j]);
	}
	cout << ans << endl;
	ggr
}



Measured memory_bytes: 34612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    string t;
    cin>>s;
    cin>>t;
    unsigned int x=s.size();
    unsigned int y=t.size();
    int ans[x][y];
    int solution[x][y];
    for(unsigned int i=0;i<x;i++)
    {
        for(unsigned int j=0;j<y;j++)
        {   
            if (i==0)
            {
               if (j==0)
               {
                    if (s[i]==t[j])
                        {ans[0][0]=1;
                        solution[0][0]=1;}
                    else
                        {ans[0][0]=0;
                        solution[0][0]=5;
                        }//end
               }
               else//j!=0
               {
                    if (s[i]==t[j])
                        {ans[0][j]=1;
                        solution[0][j]=1;
                        }
                    else
                        {ans[0][j]=ans[0][j-1];
                         solution[0][j]=0;
                        }                   
               }             
            }
            else if (j==0)
            {
                if (s[i]==t[j])
                        {ans[i][0]=1;
                        solution[i][0]=1;
                        }
                else
                    {ans[i][0]=ans[i-1][0];
                     solution[i][0]=-1;
                    }
            }
            else if (s[i]==t[j])
               {
                   ans[i][j]=ans[i-1][j-1]+1;
                   solution[i][j]=1;
                }
            else
            {
                auto a= ans[i-1][j];
                auto b=ans[i][j-1];
                if (a<=b)
                   {
                       ans[i][j]=b;
                       solution[i][j]=0;
                   }
                else
                {
                   ans[i][j]=a;
                   solution[i][j]=-1;
                }
            }
        }
    }
    // for(int i=0;i<x;i++)
    //   for(int j=0;j<y;j++)
    //     cout<<i<<" "<<j<<" "<<solution[i][j]<<endl;
    int p=x-1,q=y-1;
    string final="";
    while (p>=0 && q>=0)
    { 
          if (solution[p][q]==1)
        {
            final=final+s[p];
            p-=1;
            q-=1;
        }
        else if(solution[p][q]==0)
        {
            q-=1;
        }
        else
        {
            p-=1;
        }
    }
    for(int i=final.size()-1;i>=0;i--)
    cout<<final[i];
    cout<<endl;
}


Measured memory_bytes: 73992
#include<stdio.h>
#define MAX 100005
#define BIG 1000000000

typedef struct {
  char suit;
  int value;
}Card;

Card L[MAX/2+2],R[MAX/2+2];

void merge(Card A[], int n,int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
int i = 0,j = 0,k=0;
  for(i = 0;i<n1;i++) L[i]=A[left+i];
  for(i = 0;i<n2;i++) R[i]=A[mid+i];
  L[n1].value = BIG;
  R[n2].value = BIG;
  i=0;j=0;
  for(k=left;k < right;k++) {
    if (L[i].value <= R[j].value) {
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
    }
}
}

void mergeSort(Card A[],int n, int left,int right){
  if (left+1 < right) {
    int mid = (left + right)/2;
    mergeSort(A,n, left, mid);
    mergeSort(A,n, mid, right);
    merge(A, n, left, mid, right);
  }
  }

int partition(Card A[], int n, int p, int r) {
  Card x = A[r],temp ;
  int i = p-1,j;
  for(j = p; j < r ;j++) {
    if(A[j].value <= x.value) {
      i++;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  }
    temp = A[i+1];
    A[i+1] = A[r];
    A[r] = temp;
  return i+1;
}

void quicksort(Card A[], int n, int p , int r) {
  int q;
  if ( p < r ) {
    q = partition(A , n , p , r);
    quicksort(A, n , p , q-1);
    quicksort(A , n, q + 1 , r);
  }
}

int main() {
  int n, i ,v;
  Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d",&n);

  for(i = 0; i < n; i++) {
    scanf("%s %d\n",S , &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quicksort(B,n,0,n-1);

  for(i = 0; i < n;i++) {
    if(A[i].suit != B[i].suit) stable = 0;
  }
  if(stable == 1) printf("Stable\n");
  else printf("Not stable\n" );
  for(i = 0;i<n;i++) {
    printf("%c %d\n", B[i].suit, B[i].value);
  }
  return 0;
}

Measured memory_bytes: 2956
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e3+5;
const int INF = 0x3f3f3f3f;

int ans[maxn];

int main(){
	int n,x,y;
	cin >> n >> x >> y;
	
	for(int i = 1;i <= n;++i){
		for(int j = i+1;j <= n;++j){
			int len = min(j-i,abs(x-i)+abs(y-j)+1);
			//printf("%d %d %d %d %d\n",i,j,j-i,x-i+y-j+1,len);
			ans[len]++;
		}
	}
	
	for(int i = 1;i < n;++i) printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 256
// https://docs.rs/proconio/0.4.1/proconio/
use proconio::input;

fn compute_dp(val: &Vec<u32>, wgt: &Vec<u32>) -> Vec<Vec<u32>> {
    let max_l = 100000;
    let max_dp_n: usize = (1 << 10) - 1;
    let n    = val.len();
    let dp_n = std::cmp::min(n, max_dp_n);

    let mut vec: Vec<Vec<u32>> = Vec::new();
    let mut dp0: Vec<u32> = Vec::new();
    for i in 0..=max_l {
        dp0.push(if i < wgt[0] { 0 } else { val[0] });
    }
    vec.push(dp0);

    for u in 1..dp_n {
        let p = (u - 1) / 2;
        let mut dpu: Vec<u32> = Vec::new();
        for i in 0..=max_l {
            let ii = i as usize;
            dpu.push(
                if i < wgt[u] {
                    vec[p][ii]
                } else {
                    let jj = (i - wgt[u]) as usize;
                    std::cmp::max(vec[p][ii], vec[p][jj] + val[u])
                });
        }
        vec.push(dpu);
    }
    vec
}

fn solve(u: u32, l: u32, dp: &Vec<Vec<u32>>, val: &Vec<u32>, wgt: &Vec<u32>)
   -> u32
{
    let uu = u as usize;
    let ll = l as usize;
    if uu < dp.len() {
        dp[uu][ll]
    } else {
        let p  = (u - 1) / 2;
        let s = solve(p, l, &dp, &val, &wgt);
        if l >= wgt[uu] {
            std::cmp::max(s, val[uu] + solve(p, l - wgt[uu], &dp, &val, &wgt))
        } else {
            s
        }
    }
}

fn main() {
    input! {
        n:       usize,
        val_wgt: [(u32, u32); n],
        q:       usize,
        query:   [(u32, u32); q],
    }

    let mut val: Vec<u32> = Vec::new();
    let mut wgt: Vec<u32> = Vec::new();
    val_wgt.into_iter().for_each(|vw| { val.push(vw.0); wgt.push(vw.1) });

    let dp = compute_dp(&val, &wgt);

    for ul in query.iter() {
        println!("{}", solve(ul.0 - 1, ul.1, &dp, &val, &wgt));
    }
}


Measured memory_bytes: 412888
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s,w = map(int,input().split())
if s <= w:
  print("unsafe")
else:
  print("safe")

Measured memory_bytes: 65208