akhauriyash/Code-Regression huggingface dataset:
class MaxHeap
  def initialize(&block)
    @array = []
    @score = block
  end

  def insert(key)
    @array.push(key)

    # sifting up
    index = @array.size - 1
    until index == 0
      pindex = (index - 1) / 2
      if (@score.(@array[index]) <=> @score.(@array[pindex])) <= 0
        break
      else
        @array[pindex], @array[index] = @array[index], @array[pindex]
        index = pindex
      end
    end
  end

  alias push insert

  def peek
    if @array.empty?
      fail 'empty'
    end

    @array[0]
  end

  def size
    @array.size
  end

  def empty?
    @array.empty?
  end

  def pop
    if @array.empty?
      fail 'empty'
    end

    top = @array[0]
    last = @array.pop
    if @array.empty?
      return top
    end

    @array[0] = last
    i = 0
    # sifting down
    while true
      break unless i*2 + 1 < @array.size

      if i*2 + 2 < @array.size &&
         (@score.(@array[i*2 + 1]) <=> @score.(@array[i*2 + 2])) <= 0
        if (@score.(@array[i*2 + 2]) <=> @score.(@array[i])) <= 0
          break
        else
          @array[i], @array[i*2 + 2] = @array[i*2 + 2], @array[i]
          i = i*2 + 2
        end
      else
        fail "logic error" unless i*2 + 1 < @array.size
        if (@score.(@array[i*2 + 1]) <=> @score.(@array[i])) <= 0
          break
        else
          @array[i], @array[i*2 + 1] = @array[i*2 + 1], @array[i]
          i = i*2 + 1
        end
      end
    end

    return top
  end
end

def degrade(ai, bi, ci)
  res = []
  if ai > 0
    res.push [ai - 1, bi, ci]
  end
  if bi > 0
    res.push [ai, bi - 1, ci]
  end
  if ci > 0
    res.push [ai, bi, ci - 1]
  end
  return res
end

_x, _y, _z, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
b = gets.split.map(&:to_i).sort
c = gets.split.map(&:to_i).sort

queue = MaxHeap.new { |ai, bi, ci|  a[ai] + b[bi] + c[ci] }
queue.push [a.size-1, b.size-1, c.size-1]
seen = {}

until k == 0
  ai, bi, ci = queue.pop

  puts a[ai] + b[bi] + c[ci]
  k -= 1

  paths = degrade(ai,bi,ci).reject { |path| seen[path] }
  paths.each do |path|
    seen[path] = true
  end
  paths.each do |path|
    queue.push(path)
  end
end


Measured memory_bytes: 2808
class WeightedUnionFind:
    """
    重み付きUnionFind

    """
    root_position = 0

    def __init__(self, size: int):
        # 負の値はルート (集合の代表) で集合の個数
        # 正の値は次の要素を表す
        self.size = size
        self.parent = [-1] * size
        self.weight = [WeightedUnionFind.root_position] * size

    def find(self, x: int) -> (int, int):
        """
        xを含む集合の代表とxの代表からの位置を求める
        """
        if self.parent[x] < 0:
            return x, self.weight[x]
        root, weight = self.find(self.parent[x])
        self.parent[x] = root
        self.weight[x] += weight
        return root, self.weight[x]

    def union(self, x: int, y: int, weight: int) -> bool:
        """
        xを含む集合とyを含む集合を併合する
        `weight[x] + weight = weight[y]`になるように辺に重みをもたせる。
        xとyがすでに同じ集合に含まれている場合Falseを返す。
        """
        root_x, weight_x = self.find(x)
        root_y, weight_y = self.find(y)

        if root_x == root_y:
            return False

        if self.parent[root_x] >= self.parent[root_y]:
            self.parent[root_x] += self.parent[root_y]
            self.parent[root_y] = root_x
            self.weight[root_y] = weight_x + weight - weight_y
        else:
            self.parent[root_y] += self.parent[root_x]
            self.parent[root_x] = root_y
            self.weight[root_x] = weight_y - weight - weight_x

        return True


def main():
    n, m = map(int, input().split())
    wut = WeightedUnionFind(n)
    for _ in range(m):
        l, r, d = map(int, input().split())
        l -= 1
        r -= 1
        merged = wut.union(l, r, d)
        if not merged:
            root_l, weight_l = wut.find(l)
            root_r, weight_r = wut.find(r)
            if root_l != root_r or weight_l + d != weight_r:
                return False
    return True


if __name__ == '__main__':
    result = main()
    print('Yes' if result else 'No')


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

using namespace std;

typedef long long ll;

int gcd(int a, int b){
  while(b>0){
    int c=a;
    a=b;
    b=c%b;
  }
  return a; 
}

ll f(ll m, vector<int> a){
  ll res=0;
  for(int i=0;i<a.size();i++)res+=(m%a[i]);
  return res;
}

int main(void){


  int n;
  ll sum=0;

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

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a;
    int s, m, h;
 
    scanf("%d", &a);
 
    s = a % 60;
    a = a - s;
   
    m = (a % 3600)/60;
    a = a - m;
   
    h = a / 3600;
   
    printf("%d:%d:%d\n", h, m, s);
   
    return 0;
}

Measured memory_bytes: 1752
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {
	int X, Y, A, B, C;
	long[] p, q, r;
	List<Tuple> list;

	static class Tuple {
		long val;
		int type;

		Tuple(long val, int type) {
			this.val = val;
			this.type = type;
		}
	}

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		X = Integer.parseInt(tokens[0]);
		Y = Integer.parseInt(tokens[1]);
		A = Integer.parseInt(tokens[2]);
		B = Integer.parseInt(tokens[3]);
		C = Integer.parseInt(tokens[4]);
		p = new long[A];
		q = new long[B];
		r = new long[C];
		list = new ArrayList<>(A + B + C);
		tokens = in.readLine().split(" ");
		for (int i = 0; i < A; ++i) {
			p[i] = Long.parseLong(tokens[i]);
			list.add(new Tuple(p[i], 1));
		}
		tokens = in.readLine().split(" ");
		for (int i = 0; i < B; ++i) {
			q[i] = Long.parseLong(tokens[i]);
			list.add(new Tuple(q[i], -1));
		}
		tokens = in.readLine().split(" ");
		for (int i = 0; i < C; ++i) {
			r[i] = Long.parseLong(tokens[i]);
			list.add(new Tuple(r[i], 0));
		}
		Collections.sort(list, new Comparator<Tuple>() {
			@Override
			public int compare(Tuple o1, Tuple o2) {
				return -1 * Long.compare(o1.val, o2.val);
			}
		});
	}

	void calc() {
		long sum = 0;
		int cMax = X + Y;
		int xNum = 0;
		int yNum = 0;
		int index = 0;
		int count = 0;
		while (count < X + Y) {
			Tuple tuple = list.get(index);
			if (tuple.type == 0) {
				if (cMax > 0) {
					cMax--;
					sum += tuple.val;
					++count;
				}
			} else if (tuple.type == 1) {
				if (xNum < X) {
					xNum++;
					sum += tuple.val;
					++count;
				}
			} else {
				if (yNum < Y) {
					yNum++;
					sum += tuple.val;
					++count;
				}
			}
			++index;
		}
		System.out.println(sum);
	}

	void showResult() {
	}

}


Measured memory_bytes: 75160
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll x,ll y){
    ll r;
    while((r=x%y) !=0){
        x=y;
        y=r;
    }
    return y;
}

ll lcm(ll x, ll y){
    x /= gcd(x,y);
    y /=gcd(x,y);
    return (x*y);
}

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    if((a+b)<=k){
        cout << "0 0" << endl;
    }
    else{
        if(a>=k){
            a-=k;
            cout << a << " " << b << endl;
        }
        else{
            k-=a;
            if(k>=b){
                cout << "0 0" << endl;
            }
            else{
                b-=k;
                cout << "0 " << b << endl;
            }
        }
    }
    return 0;
}

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

using namespace std;

#define ll long long
#define rep(i,n) for(int i=1;i<=(n);i++)
#define rep0(i,n) for(int i=0;i<(n);i++)

const ll INF=1e9+7;
string s;
int k; 
int main()
{
	/*freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);*/
	cin>>s;
	while(k<s.size()){
		if(k+4<s.size()&&s[k]=='d'&&s[k+1]=='r'&&s[k+2]=='e'&&s[k+3]=='a'&&s[k+4]=='m'){
			if(s[k+5]=='e'&&s[k+6]=='r'&&s[k+7]!='a'){
				k+=7;
			}
			else{
				k+=5;
			}
		}
		else if(k+4<s.size()&&s[k]=='e'&&s[k+1]=='r'&&s[k+2]=='a'&&s[k+3]=='s'&&s[k+4]=='e'){
			if(s[k+5]=='r'){
				k+=6;
			}
			else{
				k+=5;
			}
		}
		else{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
    string s;
    getline(cin, s);
    ll n0 = 0;
    for(char c : s){
        n0 += (c == '0');
    }
    cout << min(n0, (ll)s.size() - n0) * 2 << endl;
    return 0;
}


Measured memory_bytes: 512
import math
import sys

import itertools

N = int(input())
P  = ''.join(input().split())
Q  = ''.join(input().split())

#print (N,P,Q)
s = ""
for i in range(1,N+1):
    s=s + str(i)
# print(s)

iq= -1
ip = -1
i = 0 
for x in itertools.permutations(s):
    #print(x)
    s = ''.join(x)
    if P == s:
        ip = i
        if iq != -1:
            print(abs(ip -iq))
            exit(0)
    if Q == s:
        iq = i
        if ip != -1:
            print(abs(ip -iq))
            exit(0)
    i = i + 1    

exit(0)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    string s;
    ll x,y;
    cin >> s >> x >> y;
    map<ll,ll> LX, LY;
    LX[0] = 1;
    LY[0] = 1;
    vector<ll> v,h;
    ll N = s.size();
    ll cnt = 0;
    bool st = 0;
    bool init = 1;
    rep(i,N){
        map<ll,ll> tm;
        if(s[i] == 'T'){
            if(st==0){
                for(auto&e:LX){
                    tm[e.fi+cnt] = 1;
                    if(init)continue;
                    tm[e.fi-cnt] = 1;
                }
                LX = tm;
                h.push_back(cnt);
                init = 0;
            }else{
                for(auto&e:LY){
                    tm[e.fi+cnt] = 1;
                    tm[e.fi-cnt] = 1;
                }
                LY = tm;
                v.push_back(cnt);
            }
            st = !st;
            cnt = 0;
        }else{
            cnt++;
        }
    }
    //cout << N << endl;
    //cout << cnt << endl;
    if(cnt > 0){
        map<ll,ll> tm;
        if(st==0){
            for(auto&e:LX){
                tm[e.fi+cnt] = 1;
                if(init)continue;
                tm[e.fi-cnt] = 1;
            }
            LX = tm;
            h.push_back(cnt);
        }else{
            for(auto&e:LY){
                tm[e.fi+cnt] = 1;
                tm[e.fi-cnt] = 1;
            }
            LY = tm;
            v.push_back(cnt);
        }
    }
    if(LX[x]&&LY[y]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 4356
#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <bitset>
#include <cstdio>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define SIZE 100010

int d[SIZE];
int main() {
   int k;
   scanf("%d", &k);
   for (int i = 0 ; i < k ; ++i) d[i] = 1e9;
   deque<int> q;   

   q.push_back(1);
   d[1] = 0;
   while (!q.empty()) {
      int v = q.front(); q.pop_front();
      if (d[(v + 1) % k] > d[v] + 1) {
         d[(v + 1) % k] = d[v] + 1;
         q.push_back((v + 1) % k);
      }
      if (d[(v * 10) % k] > d[v]) {
         d[(v * 10) % k] = d[v];
         q.push_front((v * 10) % k);
      }
   }

   printf("%d\n", d[0] + 1); 
   return 0;
}


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

int main()
{
	int n; cin >> n;
	
	vector<long long> a(n);

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

	string ans = "YES";



	sort(a.begin(), a.end());

	for (int i = 0; i < n; i++) {
	
		if (a[i] == a[i + 1]) {
			ans = "NO";
			break;
		}
	
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P;
typedef vector<int> Vi;
int const MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { return a = b; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { return a = b; } return false; }

int d[100001];

int main(){
  cin.tie(0); ios::sync_with_stdio(false);
    
  int n; cin>>n; int a[n],b[n],c[n]; Int ans=0;
  for (int i = 0; i < n; i++)cin>>a[i];
  for (int i = 0; i < n; i++)cin>>b[i];
  for (int i = 0; i < n; i++)cin>>c[i];
  sort(a,a+n); sort(b,b+n); sort(c,c+n);
  Int bc[n+1]; bc[n]=0;
  for (int i = 0; i < n; i++)bc[i]=n-distance(c,upper_bound(c,c+n,b[i]));
  for (int i = n-1; i >= 0; i--)bc[i]+=bc[i+1];
  for (int i = 0; i < n; i++)ans+=bc[distance(b,upper_bound(b,b+n,a[i]))];
  cout<<ans<<'\n';
}

Measured memory_bytes: 2176
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;

public class Main {
    static int h, w, c;
    static int[][] map;
    static Deque<ArrayList<Point>> stack;
    static int max;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            h = sc.nextInt();
            w = sc.nextInt();
            c = sc.nextInt();
            if ((h | w | c) == 0) {
                break;
            }
            map = new int[h][w];
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    map[i][j] = sc.nextInt();
                }
            }
            stack = new ArrayDeque<>();
            max = Integer.MIN_VALUE;
            dp(1);
            System.out.println(max);
        }

    }

    public static void dp(int k) {
        int col = map[0][0];
        if (k == 5) {
            if (col == c) {
                return;
            }
            ArrayList<Point> pos = new ArrayList<>();
            fill(0, 0, col, c, pos);
            ArrayList<Point> pos2 = new ArrayList<>();
            fill(0, 0, c, 10, pos2);
            for (Point p : pos2) {
                map[p.y][p.x] = c;
            }
            for (Point p : pos) {
                map[p.y][p.x] = col;
            }
            max = Math.max(pos2.size(), max);
            return;
        }
        for (int i = 1; i <= 6; i++) {
            if (i == col) {
                continue;
            }
            ArrayList<Point> pos = new ArrayList<>();
            fill(0, 0, col, i, pos);
            dp(k + 1);
            for (Point p : pos) {
                map[p.y][p.x] = col;
            }
        }
    }

    public static void arrayDump(int[][] a) {
        for (int i = 0, l = a.length; i < l; i++) {
            for (int j = 0, l2 = a[0].length; j < l2; j++) {
                System.out.print(a[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println();
    }

    public static void fill(int y, int x, int colFrom, int colTo, ArrayList<Point> pos) {
        if (y < 0 || x < 0 || y >= h || x >= w) {
            return;
        }
        if (map[y][x] != colFrom) {
            return;
        }
        map[y][x] = colTo;
        pos.add(new Point(y, x));
        fill(y + 1, x, colFrom, colTo, pos);
        fill(y - 1, x, colFrom, colTo, pos);
        fill(y, x + 1, colFrom, colTo, pos);
        fill(y, x - 1, colFrom, colTo, pos);
    }

    public static class Point {
        int x;
        int y;

        Point(int y, int x) {
            this.x = x;
            this.y = y;
        }

    }
}

Measured memory_bytes: 112828
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    vs ss;
    rep(i, s.size()) {
        if(!i) ss.push_back(s.substr(0, 1));
        else {
            if(s.substr(i, 1) == ss[ss.size()-1]) {
                if(i == s.size()-1) {
                    ss[ss.size()-1] += s[i];
                }
                else ss.push_back(s.substr(i++, 2));
            } else {
                ss.push_back(s.substr(i, 1));
            }
        }
    }

    //rep(i, ss.size()) cout << ss[i] << endl;

    cout << (int)ss.size() << endl;
}

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

int main(){
    int abc[3];
    int five = 0;
    int seven = 0;
    cin >> abc[0] >> abc[1] >> abc[2];
    for(const auto& num: abc){
        if(num == 5){
            five ++;
        }
        if(num == 7){
            seven ++;
        }
    }

    if(five == 2 && seven == 1){
        cout << "YES";
    }else{
        cout << "NO";
    }
}

Measured memory_bytes: 3036
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(n: usize, l: i64);
    let mut vs = vec![0i64; n];
    for i in 0..n {
        vs[i] = l + i as i64;
    }
    let sum = vs.iter().sum::<i64>();
    let mut ans = 1 << 30;
    let mut hoge = 0;
    for i in 0..n {
        let a = vs[i];
        let ss = sum - a;
        if ans > (sum - ss).abs() {
            ans = (sum - ss).abs();
            hoge = ss;
        }
    }
    println!("{}", hoge);
}


Measured memory_bytes: 4352
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

ll MOD = 1000000007;




int  main()
{
	int N, K, Q;
	cin >> N >> K >> Q;
	vec score(N, K - Q);
	for (int i = 0; i < Q; ++i)
	{
		int A; cin >> A;
		score[A-1]++;
	}

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

	return 0;
}

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

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

int main() {
    int a,b,x; cin>>a>>b>>x;
    if(a <= x && x <= a+b) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = input()
t = input()
flag = True
for i in range(len(s)):
    if s[i] != t[i]:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int maxn = 2e5;
const int inf = 1e6;
map<int ,int> mp;
char s[maxn+10];
int f[maxn+10];
int main() {
	//freopen("in","r",stdin);
	scanf("%s",s);
	int n=strlen(s);
	mp[0]=0;
	int state=0;
	for(int i=0;i<n;i++) {
		state^=1<<(s[i]-'a');
		f[i]=inf;
		for(int j=0;j<26;j++)
			if(mp.find(state^(1<<j))!=mp.end()) f[i]=min(f[i],mp[state^(1<<j)]+1);
		if(mp.find(state)!=mp.end()) f[i]=min(f[i],mp[state]+1);
		if(mp.find(state)==mp.end()) mp[state]=f[i];
		else if(mp[state]>f[i]) mp[state]=f[i];
	}
	printf("%d\n",f[n-1]);
	return 0;
}

Measured memory_bytes: 10624
def check(c):
    l = [['.']*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            l[(i+c)%n][j] = s[i][j]
    for i in range(n):
        for j in range(n):
            if l[i][j]!=l[j][i]:
                return False
    return True
n = int(input())
s = [input() for _ in range(n)]
ans = 0
for c in range(n):
    if check(c):
        ans+=n
print(ans)

Measured memory_bytes: 141992
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let d: usize = sc.read();
    let x: Vec<Vec<i64>> = (0..n).map(|_| sc.vec(d)).collect();

    let mut ans = 0;
    for i in 0..n {
        for j in 0..i {
            let mut dist2 = 0;
            for k in 0..d {
                let dx = x[i][k] - x[j][k];
                dist2 += dx * dx;
            }

            let sq = (dist2 as f64).sqrt() as i64;
            if sq * sq == dist2 {
                ans += 1;
            }
        }
    }

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

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)

typedef pair<int, int> P;

const int inf = 1 << 25;

struct edge
{
  int to, cost;
  edge(){}
  edge(int to, int cost):to(to), cost(cost){}
};

vector< vector<edge> > graph;
vector< vector<int> > mincost;

int dijkstra(int s)
{
  priority_queue<P, vector<P>, greater<P> > que;
  que.push(P(0, s));
  mincost[s][s] = 0;
  while(!que.empty()) {
    int cost, now;
    tie(cost, now) = que.top(); que.pop();
    if(mincost[s][now] < cost) continue;
    for(edge& e : graph[now]) {
      if(e.cost + cost < mincost[s][e.to]) {
	mincost[s][e.to] = e.cost + cost;
	que.push(P(mincost[s][e.to], e.to));
      }
    }
  }
  return *max_element(all(mincost[s]));
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, R;
  cin >> N >> R;
  graph.resize(N);
  rep(i, R) {
    int s, t, d;
    cin >> s >> t >> d; s--, t--;
    graph[s].emplace_back(t, d);
    graph[t].emplace_back(s, d);
  }

  mincost.resize(N, vector<int>(N, inf));
  int maxdist = 0;
  rep(i, N) maxdist = max(maxdist, dijkstra(i));

  vector<P> ep;
  rep(i, N) reps(j, i+1, N) {
    if(mincost[i][j] == maxdist) {
      ep.emplace_back(i, j);      
    }
  }

  vector<int> ans;
  rep(i, N) {
    bool flag = true;
    for(auto& p : ep) {
      int s, t; tie(s, t) = p;
      if(mincost[s][i] + mincost[i][t] == maxdist) {      
	flag = false;
	break;
      }
    }
    if(flag) ans.push_back(i+1);
  }
  
  cout << ans.size() << endl;
  rep(i, ans.size()) cout << ans[i] << endl;
  
  return 0;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  string s, ans = "Yes";
  cin >> s;
  
  for(int i=0; i<a+b+1; i++){
    if(i==a) {
      if(s[i] != '-') ans = "No";
    }
    else{
      if(s[i] == '-') ans = "No";
    }
  }
  cout << ans << endl;
  return 0;		    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	stack <ll int> st;
	string s;
	while(cin>>s){
		if(s=="+"){
			ll int tmp = st.top();
			st.pop();
			tmp+=st.top();
			st.pop();
			st.push(tmp);
		}else if(s=="-"){
			ll int tmp = st.top();
			st.pop();
			tmp = st.top() - tmp;
			st.pop();
			st.push(tmp);
		}else if(s=="*"){
			ll int tmp = st.top();
			st.pop();
			tmp*=st.top();
			st.pop();
			st.push(tmp);
		}else if(s=="/"){
			ll int tmp = st.top();
			st.pop();
			tmp = st.top() / tmp;
			st.pop();
			st.push(tmp);
		}else{
			st.push(stoi(s));
		}	
	}
	cout << st.top() << endl;
}

Measured memory_bytes: 1204
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
//#include "toollib.h"
//#include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#pragma warning (disable:4018)
#pragma warning (disable:4244)

using namespace std;
typedef long long int lint;


//***** Main Program *****

int main() {
	int n, q;
	cin >> n >> q;
	queue<pair<string, int>> qp;
	Loop(i, n) {
		string a;
		int b;
		cin >> a >> b;
		qp.push({ a,b });
	}
	int time = 0;
	while (qp.size() > 0) {
		pair<string, int> f = qp.front();
		if (f.second <= q) {
			time += f.second;
			qp.pop();
			cout << f.first << " " << time << endl;
		}
		else {
			time += q;
			qp.pop();
			qp.push({ f.first, f.second - q });
		}
	}
	return 0;
}

Measured memory_bytes: 6356
from itertools import permutations
import math
n = int(input())
x = []
for i in range(n):
    x.append(list(map(int,input().split())))

p = permutations(x)
ans = 0
for i in p:
    #print(i)
    for j in range(n-1):
        ans += math.sqrt((i[j][0]-i[j+1][0])**2+(i[j][1]-i[j+1][1])**2)
ans /= math.factorial(n)
print(ans)


Measured memory_bytes: 73672
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

template <class Container>
std::vector<int> zalgo(const Container& dat) {
    int n = dat.size();

    std::vector<int> ret(n);
    ret[0] = n;

    int i = 1, len = 0;
    while (i < n) {
        while (i + len < n && dat[len] == dat[i + len]) {
            ++len;
        }
        ret[i] = len;

        if (len == 0) {
            ++i;
            continue;
        }

        int nlen = 1;
        while (i + nlen < n && nlen + ret[nlen] < len) {
            ret[i + nlen] = ret[nlen];
            ++nlen;
        }

        i += nlen;
        len -= nlen;
    }

    return ret;
}

constexpr int MOD = 1000000007;
constexpr int S = 100;

void solve() {
    int n;
    std::cin >> n;

    std::vector<std::set<std::string>> ses(S);
    std::vector<std::string> ss;

    while (n--) {
        std::string s;
        std::cin >> s;

        if ((int)s.length() < S) {
            ses[s.length()].insert(s);
        } else {
            ss.push_back(s);
        }
    }

    std::string t;
    std::cin >> t;
    int m = t.length();

    std::vector<std::vector<int>> to(m);
    for (int i = 0; i < m; ++i) {
        for (int k = 0; k < S; ++k) {
            if (ses[k].count(t.substr(i, k))) {
                to[i].push_back(i + k);
            }
        }
    }

    for (auto s : ss) {
        int l = s.length();
        s += t;
        auto vs = zalgo(s);
        for (int i = 0; i < m; ++i) {
            if (vs[i + l] >= l) to[i].push_back(i + l);
        }
    }

    std::vector<int> dp(m + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < m; ++i) {
        for (auto j : to[i]) {
            (dp[j] += dp[i]) %= MOD;
        }
    }
    std::cout << dp.back() << std::endl;
}

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

    solve();

    return 0;
}



Measured memory_bytes: 407144
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unordered_set<int> uset;

void print(const vector<pair<char,int>>& v ){
  for( auto p : v ) cerr << " (" << p.first << "," << p.second << ")";
  cerr << endl;
}

void print( const vector<int>& v ){
  for( auto x : v ) cerr << " " << x; cerr << endl;
}

int main( int argc, char* argv[] ){
  int N;
  cin >> N;
  int min_sum = 999999999;
  for( int i=1; i<=N/2; ++i ){
    int a = i, b=N-i;
    int sum = 0;
    while( a > 0 ){
      sum += a % 10;
      a /= 10;
    }
    while( b > 0 ){
      sum += b % 10;
      b /= 10;
    }
    min_sum = min( sum, min_sum );
  }
  cout << min_sum << endl;
  return 0;
}

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

typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  map<int, vector<int>> mp;
  for (int i = 0; i < N; i++) {
    int t, d;
    cin >> t >> d;
    mp[t].push_back(d);
  }

  // split into max values of each type and others
  vector<int> maxes, others;
  for (auto &p : mp) {
    vector<int> v = p.second;
    sort(v.rbegin(), v.rend());
    maxes.push_back(v[0]);
    for (int i = 1; i < v.size(); i++) {
      others.push_back(v[i]);
    }
  }

  // reverse sort
  sort(maxes.rbegin(), maxes.rend());
  sort(others.rbegin(), others.rend());

  // cumulative sum
  vector<ll> maxes_sum(N + 1, 0);
  for (int i = 0; i < maxes.size(); i++) {
    maxes_sum[i + 1] = maxes_sum[i] + maxes[i];
  }
  vector<ll> others_sum(N + 1, 0);
  for (int i = 0; i < others.size(); i++) {
    others_sum[i + 1] = others_sum[i] + others[i];
  }

  // find best k
  int kmax = min(K, (int)maxes.size());
  ll ans = 0;
  for (ll k = 1; k <= kmax; k++) {
    ll sum = maxes_sum[k] + others_sum[K - k] + k * k;
    ans = max(ans, sum);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 13304
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#include <math.h>

int main() {

	int n;

	string ans = "bon";

	cin >> n;

	if (n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 7 || n % 10 == 9) {

		ans = "hon";
	}

	if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {

		ans = "pon";
	}

	cout << ans;

	cin >> ans;

	return 0;


}

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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;

  if (A == B && A != C)
  {
    cout << "Yes" << endl;
  }
  else if (A == C && A != B)
  {
    cout << "Yes" << endl;
  }
  else if (B == C && B != A)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << 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;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p=-1) {
    int d = ans[v];
    for (int u : to[v]) {
        if (u == p) continue;
        ans[u] += d;
        dfs(u,v);
    }
}

int main() {
    int n, q;
    cin >> n >> q;
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(0);
    rep(i,n) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 24312
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
typedef long double ld;
typedef complex<ld> Point;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
const ld eps = 1e-9, pi = acos(-1.0);
const ld dtop = pi / 180.;
const ld ptod = 1. / dtop;


int main() {
  while (1) {
    int n, p; cin >> n >> p;
    if (!n)break;
    vector<int>stones(n, 0);
    int bowl(p);
    int nplayer = 0;
    while (1) {
      if (bowl) {
        bowl--;
        stones[nplayer]++;
        if (stones[nplayer] == p)break;
      }
      else {
        bowl += stones[nplayer];
        stones[nplayer] = 0;
      }
      nplayer = (nplayer + 1) %n;
    }
    cout << nplayer << endl;
  }
  return 0;
}

Measured memory_bytes: 3076
#include<iostream>

using namespace std;

int n;
int score[100];
int bucket[1001] = {0};
int sum_score, ave_score;

void set_score(){
    for(int i=0; i < n; i++){
        cin >> score[i];
    }
}

void sort(){
    for(int i = 0; i < n; i++){
        bucket[score[i]]++;
    }

    for(int i=0,k=0; i < 1001;i++){
        for(int j=0; j<bucket[i]; j++){
            score[k++] = i;
        }
    }
}

void ave(){
    for(int i=1; i < n-1; i++){
        sum_score += score[i];
    }
    ave_score = sum_score/(n-2);
}

void reset(){
    sum_score = 0;
    for(int i=0;i<1001; i++){
        bucket[i] = 0;      
    }
}

int main(void){
    while(1){
        cin >> n;
        if(n == 0){
            break;
        }
        set_score();
        sort();
        ave();
        cout << ave_score << endl;
        reset();
        
    }
    return 0;
}


Measured memory_bytes: 3088
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
const int MAX = (int)2e5 + 5;

ll N, A, B;
ll x[MAX];

void solve() {
	cin >> N >> A >> B;
	rep(i, N) cin >> x[i];
	ll res = 0;
	rep(i, N - 1) {
		ll tmp = (x[i + 1] - x[i]) * A;
		if (tmp < B) {
			res += tmp;
		}
		else {
			res += B;
		}
	}
	cout << res << endl;
}

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int poor_or_not = 0;
  
  if (A==B){
    if (B != C){
      poor_or_not = 1;
    }else{
      poor_or_not = 0;
    }
  }else{
      if(B==C || A==C){
        poor_or_not = 1;
      }else{
        poor_or_not =0;
      }
    }
    
    if (poor_or_not == 1){
      cout << "Yes";
    }else{
      cout << "No";
    }
      
      

      
      
}

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

int gcd(int x, int y) {if (y == 0) return x; return gcd(y,x%y);}

int main(){
  int n; cin>>n;
  int a[n]; for(int i=0;i<n;i++) cin>>a[i];
  int b[n]; b[0] = a[0];
  int c[n]; c[n-1] = a[n-1];
  for(int i=1;i<n;i++) {
    b[i] = gcd(b[i-1], a[i]);
  }
  for(int i=n-2;i>=0;i--) {
    c[i] = gcd(c[i+1], a[i]);
  }
  int an = max(c[1], b[n-2]);
  for(int i=0;i<n;i++) {
    an = max(an, gcd(b[i-1], c[i+1]));
  }
  cout<<an<<endl;
}

Measured memory_bytes: 4740
w,h,n = map(int,input().split())
b,c,d,e = 0,w,0,h
for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        b = max(b,x)
    elif a == 2:
        c = min(c,x)
    elif a == 3:
        d = max(d,y)
    else:
        e = min(e,y)
print(max(c-b,0)*max(e-d,0))

Measured memory_bytes: 62596
function Main(input) {
	let input = input.split("\n");
	let tmp = input[0].split(" ");
	let N = parseInt(tmp[0], 10);
	let P = parseInt(tmp[1], 10);

    let pf = primeFactor(P);
    let max = 1;
//    Object.keys(pf).forEach(function(key){
//        console.log( key + '：' + this[key] );
//    }, pf);
    for (let key in pf) {
        let divisor = key;
        let count = pf[key];
        while (count >= N) {
            max *= divisor;
            count -= N;
        }
    }
	//出力
	console.log('%d',max);
}
function primeFactor(n) {
    let res = {};
    for (let i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            if (res[i]) {
                res[i] = res[i]+1;
            }else{
                res[i] = 1;
            }
            n/=i;
        }
    }
    if (n != 1) {
        if (res[n]){
            res[n] = res[n]+1;
        }else{
            res[n] = 1;
        }
    }
    return res;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> vec (3);
    for(int i = 0;i < 3;i++){
        cin >> vec[i];
    }
    SORT(vec);
    if(vec[2] == vec[0] + vec[1]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,N) for(auto i=0; i<N; ++i)
#define ALL(x) x.begin(), x.end()

/* clang-format off */
template <class T> inline void chmin(T& a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T& a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {

  string s, t;
  cin >> s >> t;

  ll N, M; N = s.size(); M = t.size();
  vector< vector<ll > > dp(N + 1, vector<ll>(M + 1, 0));
  FOR(_i, N) {
    auto i = _i + 1;
    FOR(_j, M) {
      auto j = _j + 1;
      if (s[i-1] == t[j-1]) {
        dp[i][j] =
          max(dp[i][j], dp[i - 1][j - 1] + 1);
        /*  max(max(dp[i][j], max(dp[i][j - 1]+1,
            dp[i - 1][j - 1]+1)),
            dp[i - 1][j]+1);*/
      }
      else {
        dp[i][j] =
          max(max( dp[i][j], max(dp[i][j - 1],
            dp[i - 1][j - 1])),
            dp[i - 1][j]);
      }
    }
  }

  string ans;
  ll next = 1;
  //FOR(_i, N) {
  //  auto i = _i + 1;
  //  FOR(_j, M) {
  //    auto j = _j + 1;
  //    if (dp[i][j] == next) {
  //      ans += t[j];
  //      next += 1;
  //      break;
  //    }
  //  }
  //}
  ll cnt = dp[N][M];
  ll i = N;
  ll j = M;
  //string ans;
  while (cnt) {
    while (dp[i][j] == cnt) {
      i -= 1;
    }
    i += 1;
    while ( dp[i][j] == cnt) {
      j -= 1;
    }
    j += 1;
    
    ans += s[i-1];
    cnt -= 1;
    i -= 1;
    j -= 1;

  }
  reverse(ALL(ans));
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 70784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public long N, M;
        public long[,] V;
        public long[,] VV;

        public void Run()
        {
            {
                var line = Input.ReadLongArray();
                N = line[0];
                M = line[1];
                V = new long[N, 3];
                VV = new long[N, 8];
            }

            for (int i = 0; i < N; i++)
            {
                var line = Input.ReadLongArray();
                V[i, 0] = line[0];
                V[i, 1] = line[1];
                V[i, 2] = line[2];
            }

            for (int f1 = 0; f1 < 2; f1++)
                for (int f2 = 0; f2 < 2; f2++)
                    for (int f3 = 0; f3 < 2; f3++)
                    {
                        for (int i = 0; i < N; i++)
                        {
                            long v = (f1 == 0 ? 1 : -1) * V[i, 0]
                                     + (f2 == 0 ? 1 : -1) * V[i, 1]
                                     + (f3 == 0 ? 1 : -1) * V[i, 2];
                            VV[i, f1 + f2 * 2 + f3 * 4] = v;
                        }
                    }

            long ret = 0;
            for (int f = 0; f < 8; f++)
            {
                long r = 0;
                var a = new long[N];
                for (int i = 0; i < N; i++) a[i] = VV[i, f];
                Array.Sort(a);
                Array.Reverse(a);
                for (int i = 0; i < M; i++) r += a[i];
                ret = Math.Max(ret, r);
            }

            Console.WriteLine(ret);

        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13396
s=input()
t=input()
data=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
S=[0]*len(s)
T=[0]*len(t)
for i in range(len(s)):
  S[i]=data.index(s[i])
for i in range(len(t)):
  T[i]=data.index(t[i])
S.sort()
T.sort(reverse=True)
if S<T:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9048
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N, M = map(int, input().split())
    edges = [[] for _ in range(N)]

    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edges[a].append(b)
        edges[b].append(a)

    for edge in edges:
        if len(edge) % 2 == 1:
            print('NO')
            return

    print('YES')


sol()

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

int main() {
  
  char c;
  cin >> c;
  if ( c == 'a'
      || c == 'e'
      || c == 'i'
      || c == 'o'
      || c == 'u'
     ) cout << "vowel" << endl;
  else cout << "consonant" << endl;
}


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

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

  if(a<b){
    cout<<"<"<<endl;
  }
  else if(a==b){
    cout<<"="<<endl;
  }
  else{
    cout<<">"<<endl;
  }
}

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

using namespace std;

char in[120];
pair<pair<string,int>,int> p[110];
int main(){
  int a;scanf("%d",&a);
  for(int i = 0;i < a;i++){
    int t;scanf("%s%d",in,&t);
    string tmp = in;
    p[i] = make_pair(make_pair(in,-t),i);
  }
  sort(p,p+a);
  for(int i=0;i<a;i++){
    printf("%d\n",p[i].second+1);
  }
}


Measured memory_bytes: 256
import itertools

a = map(int, input().split())
ans = 1000000000000000
for p in itertools.permutations(a):

    cost = 0
    for i in range(1, len(p)):
        cost += abs(p[i] - p[i - 1])
    if ans >= cost:
        ans = cost

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,afterA,afterB;
  int n=1;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    afterA=n*2;
    afterB=n+K;
    if(afterA<afterB)n=afterA;
    else n=afterB;
  }
  cout<<n<<endl;
}

Measured memory_bytes: 256