akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;

using std::vector;
using std::stack;

vector<bool> dfs(int n, const vector<vector<bool>>& c, int v_init){
    stack<int> stack;
    vector<bool> visited(n, false);
    stack.push(v_init);
    while(!stack.empty()){
        int v = stack.top();
        stack.pop();

        if(visited[v]){
            continue;
        }

        visited[v] = true;
        for(int i = 0; i < n; i++){
            if(c[v][i] && !visited[i]){
                stack.push(i);
            }
        }
    }
    return visited;
}


int main(void){
    int n, m;
    cin >> n >> m;

    vector<int> ea(m);
    vector<int> eb(m);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        ea[i] = a - 1;
        eb[i] = b - 1;
    }


    vector<vector<bool>> c(n, vector<bool>(n, false));
    for(int i = 0; i < m; i++){
        c[ea[i]][eb[i]] = true;
        c[eb[i]][ea[i]] = true;
    }

    int cnt = 0;
    for(int i = 0; i < m; i++){
        c[ea[i]][eb[i]] = false;
        c[eb[i]][ea[i]] = false;

        vector<bool> visited = dfs(n, c, 0);
        cnt += std::count(visited.begin(), visited.end(), true) != n;

        c[ea[i]][eb[i]] = true;
        c[eb[i]][ea[i]] = true;
    }
    cout << cnt << endl;

    return 0;
}


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

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        for(;;){
            String w = sc.next();
            if(w.equals("-")) break;
            int m = sc.nextInt();
            for(int i = 0; i < m; i++) {
                int h = sc.nextInt();
                w = w.substring(h) + w.substring(0, h);
            }
            System.out.println(w);
        }
    }
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader br = new InputStreamReader(System.in);
        BufferedReader is = new BufferedReader(br);
        String str = is.readLine();
        int a = Integer.parseInt(str);
        
        a=a*a*a;
        
        System.out.println(a);
	}
}

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

using namespace std;

const int N = (int)1e5 + 5;

int n,m,dp[N];

bool usedSort[N];

vector<int> topSort,g[N];

void dfsSort(int v){
	usedSort[v] = 1;
	for(auto to : g[v]){
		if(!usedSort[to]) dfsSort(to);
	}
	topSort.push_back(v);
}

int main(){
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
    	int a,b;
    	cin >> a >> b;
    	g[a].push_back(b);
    }
    for(int i = 1; i <= n; i++) dfsSort(i);
    reverse(topSort.begin(),topSort.end());
    for(int v : topSort){
    	for(int to : g[v]){
    		dp[to] = max(dp[to],dp[v] + 1);	
    	}	
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) ans = max(ans,dp[i]);
    cout << ans;
    return 0;
}

Measured memory_bytes: 9204
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,no-stack-protector,fast-math")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 4 * N + 5;

map<pair<int, int>, bool> vis;
map<pair<int, int>, int> cnt;

int getSum(int x, int y){
    int ret = 0;

    for(int i = x ; i <= x + 2 ; ++i)
        for(int j = y ; j <= y + 2 ; ++j)
            ret += (vis.find(make_pair(i, j)) != vis.end());

    return ret;
}

int n, m;

ll out[10];

bool isOut(int x, int y){
    return (x <= 0 || y <= 0 || x + 2 > n || y + 2 > m);
}

void solve(int x, int y){
    for(int i = 0 ; i < 3 ; ++i)
        for(int j = 0 ; j < 3 ; ++j)
            if(!isOut(x - i, y - j))
                cnt[make_pair(x - i, y - j)] = getSum(x - i, y - j);
}

int main(){
    int h;
    scanf("%d %d %d", &n, &m, &h);
    vector<pair<int, int> > points;
    while(h--){
        int x, y;
        scanf("%d %d", &x, &y);
        vis[make_pair(x, y)] = true;
        points.emplace_back(x, y);
    }

    for(auto p : points)
        solve(p.first, p.second);

    ll sum = 0;
    for(auto p : cnt)
        ++out[p.second], ++sum;

    out[0] = (1ll * n - 2) * (1ll * m - 2) - sum;

    for(int i = 0 ; i <= 9 ; ++i)
        printf("%lld\n", out[i]);

}

Measured memory_bytes: 63476
#include <iostream>
#include <stdlib.h>
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */
#include <vector>
#include <algorithm>
#include <string>

void print_array(std::vector<std::pair<int, char> > list)
{
  for(int i = 0; i < list.size(); ++i){
    if(i>0) std::cout << " ";
    std::cout << list[i].second << list[i].first;
  }
  std::cout << std::endl;
}

void BubbleSort(std::vector<std::pair<int, char> > &listToSort){
    for (int j=0; j < listToSort.size(); j++) {
        for (int k=listToSort.size()-1; k>j; k--) {
            if(listToSort[k].first<listToSort[k-1].first) {
                std::swap(listToSort[k],listToSort[k-1]);
            }
        }
            
    }
}

void SelectionSort(std::vector<std::pair<int, char> > &listToSort){
    int mini;
    for (int i=0; i<listToSort.size(); i++) {
        mini = i;
        for (int j=i; j<listToSort.size(); j++) {
            if(listToSort[j].first<listToSort[mini].first) {
                mini = j;
            }
        }

        std::swap(listToSort[i],listToSort[mini]);
    }
}

int firstPosition(std::vector<std::pair<int, char> > &list, int value) {
    for(int i=0;i<list.size();i++) {
        if(list[i].first==value) {
            return i;
        }
    }
    return list.size();
}

std::string isStable(std::vector<std::pair<int, char> > &listToSort, std::vector<std::pair<int, char> > &sortedList) {
    for (int i=1; i<10;i++) {
        int j=firstPosition(sortedList,i);
        if( j != sortedList.size()) {
            for(int k=0; k<listToSort.size();k++) {
                    if(listToSort[k].first==i) {
                        if(sortedList[j].second==listToSort[k].second) {
                            j++;
                        }
                        else return "Not stable";
                    }
            }
        }
    }
    return "Stable";
}

int main(void){

    int num;
    std::cin >> num;
    if (num>36) {
        std::cout << "too many cards" << std::endl;
        return 1;
    }
    
    std::vector<std::pair<int, char> > list;
    std::vector<std::pair<int, char> > listBubble;
    std::vector<std::pair<int, char> > listSelection;
    for(int i = 0; i < num; i++){
    std::string value;
    std::cin >> value;
    list.push_back(std::make_pair((int)value[1]-'0',value[0]));
    listBubble.push_back(std::make_pair((int)value[1]-'0',value[0]));
    listSelection.push_back(std::make_pair((int)value[1]-'0',value[0]));
    }

    BubbleSort(listBubble);
    SelectionSort(listSelection);
    print_array(listBubble);
    std::cout << isStable(list, listBubble) << std::endl;
    print_array(listSelection);
    std::cout << isStable(list, listSelection) << std::endl;

    return 0;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

struct mint
{
  ll v;
  mint() : v(0) {}
  mint(ll v) : v((v % MOD + MOD) % MOD) {}
};
mint& operator+=(mint& a, mint b) { return a = a.v + b.v; }
mint& operator-=(mint& a, mint b) { return a = a.v - b.v; }
mint& operator*=(mint& a, mint b) { return a = a.v * b.v; }
mint operator+(mint a, mint b) { return a += b; }
mint operator-(mint a, mint b) { return a -= b; }
mint operator*(mint a, mint b) { return a *= b; }
mint operator-(mint a) { return 0 - a; }
bool operator==(mint a, mint b) { return a.v == b.v; }
bool operator!=(mint a, mint b) { return a.v != b.v; }
istream& operator>>(istream& os, mint& a) { return (os >> a.v); }
ostream& operator<<(ostream& os, const mint& a) { return (os << a.v); }

vector<int> to[100001];

// usage:
// vector<T> v; v.push_back(T(1, 2, 3)); v.emplace_back(1, 2, 3);
// queue<T> q; q.push(T(1, 2, 3));
// int x, y, z; tie(x, y, z) = q.front(); q.pop();
typedef tuple<int, int, mint> T;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    dump(a, b);
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dump(to[0]);
  dump(to[1]);
  dump(to[2]);
  dump(to[3]);
  queue<int> q;
  vector<int> used(N);
  q.push(0);
  mint ans;
  ans = K;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    if (used[v])
      continue;
    used[v] = 1;
    dumpv(v, to[v]);
    int k;
    if (v == 0) {
      k = K;
    } else {
      k = K - 1;
    }
    for (int i = 0; i < to[v].size(); i++) {
      int u = to[v][i];
      if (used[u])
        continue;
      ans *= (--k);
      dump(v, u, k+1, ans.v);
      q.push(u);
    }
  }
  cout << ans.v << endl;
  return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

template<typename T>
struct RSQRAQ2 {
  int n;
  T unit;
  function<T(T, T)> update_f, sum_f, query_f;
  vector<T> dat, lazy;

  RSQRAQ2() {}

  RSQRAQ2(int n_, T unit, function<T(T, T)> update_f, function<T(T, int)> sum_f, function<T(T, T)> query_f)
    : unit(unit), update_f(update_f), sum_f(sum_f), query_f(query_f) {
    n = 1;
    while (n < n_)
      n *= 2;
    dat.assign(n * 2, unit);
    lazy.assign(n * 2, unit);
  }

  RSQRAQ2(vector<T> v, T unit, function<T(T, T)> update_f, function<T(T, int)> sum_f, function<T(T, T)> query_f)
    : unit(unit), update_f(update_f), sum_f(sum_f), query_f(query_f) {
    n = 1;
    while (n < v.size()) n <<= 1;
    dat.assign(n * 2, unit);
    lazy.assign(n * 2, unit);
    for (int i = 0; i < v.size(); i++) {
      dat[n + i - 1] = v[i];
    }
    for (int i = n - 2; i >= 0; i--) {
      dat[i] = query_f(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
  }

  void eval(int len, int k) {
    if (lazy[k] == unit)
      return;
    if (k * 2 + 1 < n * 2 - 1) {
      lazy[2 * k + 1] = update_f(lazy[2 * k + 1], lazy[k]);
      lazy[2 * k + 2] = update_f(lazy[2 * k + 2], lazy[k]);
    }
    dat[k] = update_f(dat[k], sum_f(lazy[k], len));
    lazy[k] = unit;
  }

  // [a, b)
  T update(int a, int b, T x, int k, int l, int r) {
    eval(r - l, k);
    if (b <= l || r <= a)
      return dat[k];
    if (a <= l && r <= b) {
      lazy[k] = update_f(lazy[k], x);
      return query_f(dat[k], sum_f(lazy[k], r - l));
    }
    return dat[k] = query_f(update(a, b, x, 2 * k + 1, l, (l + r) / 2),
                            update(a, b, x, 2 * k + 2, (l + r) / 2, r));
  }

  T update(int a, int b, T x) { return update(a, b, x, 0, 0, n); }

  // [a, b)
  T query(int a, int b, int k, int l, int r) {
    eval(r - l, k);
    if (b <= l || r <= a)
      return unit;
    if (a <= l && r <= b)
      return dat[k];
    return query_f(query(a, b, 2 * k + 1, l, (l + r) / 2), query(a, b, 2 * k + 2, (l + r) / 2, r));
  }

  T query(int a, int b) { return query(a, b, 0, 0, n); }
};

struct N {
  ll l, r, c;
};

bool operator<(const N &l, const N &r) {
  return l.r < r.r;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<N> ns(m);
  ll INF = 1000000000000000LL;
  for (int i = 0; i < m; i++) cin >> ns[i].l >> ns[i].r >> ns[i].c;
  RSQRAQ2<ll> r(n, INF, [](ll l, ll r) {
    return min(l, r);
  }, [](ll l, int t) {
    return l;
  }, [](ll l, ll r) {
    return min(l, r);
  });
  r.update(0, 1, 0LL);
  sort(ns.begin(), ns.end());
  for (int i = 0; i < m; i++) {
    ll v = r.query(ns[i].l - 1, ns[i].r) + ns[i].c;
    r.update(ns[i].l, ns[i].r, v);
  }
  if (r.query(n - 1, n) == INF) {
    cout << -1 << endl;
  } else {
    cout << r.query(n - 1, n) << endl;
  }

  return 0;
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)

using namespace std;

int main(){

	int x,y,s;
	vector<int> vx;
	vector<int> vy;
	vector<int> vs;

	while(1){
		cin>>x>>y>>s;
		if(x==0 && y==0 && s==0) break;
		vx.push_back(x);
		vy.push_back(y);
		vs.push_back(s);
	}

	for(int l=0; l<vx.size(); l++){
		int ans = -1;
		for(int i=1; i<1000; i++){
			for(int j=1; j<1000; j++){
				if((i*(100+vx[l]))/100 + (j*(100+vx[l]))/100 != vs[l]) continue;
				ans = max(ans , (i*(100+vy[l]))/100 + (j*(100+vy[l]))/100);
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int len = s.size();

    for (int right = len - 2; right >= 2; right -= 2) {
        for (int i = 0; i < right / 2; i++) {
            if (s.at(i) != s.at(i + right / 2)) break;

            if (i == right / 2 - 1) {
                cout << right << endl;
                return 0;
            }
        }
    }

    cout << 1 << endl;
}

Measured memory_bytes: 256
from operator import itemgetter

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    change = []
    process = []
    p_append = process.append

    for i in range(m):
        array = list(map(int, input().split()))
        p_append(array)

    process.sort(key = itemgetter(1),reverse=True)

    for i in range(len(process)):
        change += [process[i][1]] * process[i][0]
        if len(change) >= n:
            break

    a = a + change
    a.sort(reverse=True)
    a = a[:n]
    print(sum(a))

if __name__ == '__main__':
    main()

Measured memory_bytes: 36044
import sys
input=sys.stdin.readline
N,k=map(int,input().split())
n=300_003
def update(i,x):#A[i]=x
	now=2**deep+i
	seg[now-1]=x
	while now>1:
		now//=2
		seg[now-1]=min(seg[now*2-1],seg[now*2])
def minimum(x,y):#A[x]からA[y]の最小値	
	s=inf
	l=x+2**deep
	r=y+2**deep+1
	while l<r:
		if l%2==1:
			s=min(s,seg[l-1])
			l+=1
		if r%2==1:
			r-=1
			s=min(s,seg[r-1])
		l//=2
		r//=2
	return s
inf=0
deep=(n-1).bit_length()
seg=[inf]*(2**deep*2-1)
for i in range(N):
	a=int(input())
	x=max(a-k,0)
	y=min(a+k,n)
	update(a,minimum(x,y)-1)
print(-minimum(0,n-1))


Measured memory_bytes: 79416
import java.io.*;
class Main
{
  public static void main(String args[])throws IOException
  {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    int x=Integer.parseInt(br.readLine());
    if(x>=400 && x<600)
      System.out.println("8");
    else if(x>=600 && x<800)
      System.out.println("7"); 
      else if(x>=800 && x<1000)
      System.out.println("6") ;
        else if(x>=1000 && x<1200)
      System.out.println("5");
      else if(x>=1200 && x<1400)
      System.out.println("4"); 
     else if(x>=1400 && x<1600)
      System.out.println("3"); 
      else if(x>=1600 && x<1800)
      System.out.println("2") ;
        else if(x>=1800 && x<2000)
      System.out.println("1");
  }
}

Measured memory_bytes: 25388
#include <iostream>
#include <math.h>
using namespace std;

#define N_MAX 1000

int main(void){
	int n;
	long long t[N_MAX]{}, a[N_MAX]{};
	long long tx, ax, x;

	cin >> n;

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

	for (int i = 1; i < n; i++){
		if ((t[i] < t[i - 1]) || a[i] < a[i - 1]){
			tx = t[i - 1] / t[i];
			ax = a[i - 1] / a[i];
			if (tx > ax){
				if (t[i - 1] % t[i] != 0) x = tx + 1;
				else x = tx;
			}
			else{
				if (a[i - 1] % a[i] != 0) x = ax + 1;
				else x = ax;
			}
			t[i] *= x;
			a[i] *= x;
		}
	}

	cout << t[n - 1] + a[n - 1] << endl;

	return 0;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    string ans = "No";
    if(A == B && A != C){
        ans = "Yes";
    }
    else if(A == C && A != B){
        ans = "Yes";
    }
    else if(B == C && B != A){
        ans = "Yes";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def solve(ai,aj,bi,bj):
    s=pow(3,30)
    dist=abs(ai-bi)+abs(aj-bj)
    while s>1:
        s//=3
        si,sj,ti,tj=ai//s,aj//s,bi//s,bj//s
        if si!=ti:
            return dist
        if abs(sj-tj)>1 and si%3==1:
            up=s*si-1
            down=s*(si+1)
            return min(min(ai,bi)-up,down-max(ai,bi))*2+dist
    return dist

def main():
    q=II()
    for _ in range(q):
        ai,aj,bi,bj=MI1()
        if abs(ai-bi)>abs(aj-bj):ai,aj,bi,bj=aj,ai,bj,bi
        print(solve(ai,aj,bi,bj))

main()

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int AveOrder(int k,int x){
  if(x <= k) return 1;
  return 1 + AveOrder(k,x-(k-1));
}


int main(void){
  int K,N;
  int MinNum =10000;
  int count = 0;
  vector<int > A;
  cin >> N >> K;
  for (int i = 0; i < N; i++)
  {
    int X;
    cin >> X;
    if(X < MinNum){
      MinNum = X;
      count = 0;
    }else if(X == MinNum) {
      count++;
    }
    
    A.push_back(X);
  }

  cout << AveOrder(K,N-count) << endl;
  

  return 0;
}

Measured memory_bytes: 892
import scala.io.StdIn.{readInt,readLine}

object Main {
  def main(args:Array[String]) = {
    val n = readInt
    val m = readInt
    val target = readLine.split(" ").map(_.toInt)
    val score = new Array[Int](n)
    for(i<-0 until m) {
      val guess = readLine.split(" ").map(_.toInt)
      val t = target(i)
      for(j<-0 until guess.length) {
        if(guess(j)==t) score(j) += 1
        else score(t-1) += 1
      }
    }
    println(score.mkString("\n"))
  }
}

Measured memory_bytes: 46568
import java.util.Scanner;


public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		double x=0.0,y=0.0,angle = 90;
		while(true){
			String[] s = sc.nextLine().split(",");
			int value = Integer.parseInt(s[0]);
			int value_2 = Integer.parseInt(s[1]);

			if(value == 0 && value_2 == 0) break;

			x += Math.cos(angle*Math.PI/180)*value;
			y += Math.sin(angle*Math.PI/180)*value;
			angle -= value_2;
		}
		System.out.println((int)x);
		System.out.println((int)y);
	}
}

Measured memory_bytes: 17140
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i, n, bc = 0, bp, tp;
		n = sc.nextInt();
		int[] tcal = new int[n];
		bp = sc.nextInt();
		tp = sc.nextInt();
		bc = sc.nextInt();
		for(i = 0; i < n; i++) tcal[i] = sc.nextInt();
		int sump = bp; int sumc = bc;
		int best = sumc / sump;
		Arrays.sort(tcal);
		for(i = n-1; i >= 0; i--) {
			sumc += tcal[i];
			sump += tp;
			int dpc = sumc / sump;
			if(best <= dpc) best = dpc;
			else break;
		}
		System.out.println(best);
	}
}

Measured memory_bytes: 18268
//AOJ 2236
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	cin>>n;
	vp in;
	int a1,b1,c1,d1;
	cin>>a1>>b1>>c1>>d1;
	bool h=false;
	ll out=0;
	rep(i,n){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		if(d1>d)out-=max(0,b-c1);
		if(b1-c>0)in.pb(pii(max(0,b-c1),(a+b1-c-1)/(b1-c)));
		else if(b-c1<=0);
		else h=true;
	}
	if(h){
		cout<<-1<<endl;
		return 0;
	}
	sort(all(in),[](pii a,pii b){
		return a.second*b.first<a.first*b.second;
	});
	ll co=0;
//	rep(i,in.size())cout<<in[i].first<<" "<<in[i].second<<endl;
	rep(i,in.size()){
		co+=in[i].second;
		if(out!=-inf)out+=co*in[i].first;
//		cout<<out<<endl;
		if(out>=a1)out=-inf;
		if(out==-inf)break;
	}
	if(out==-inf)cout<<-1<<endl;
	else cout<<out<<endl;
}

Measured memory_bytes: 3880
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
#define ff first
#define ss second
#define int long long 
#define endl "\n"
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);	

const int inf = 1e9;
const int MOD = 998244353;
const int N = 1e5+4;

int n , x , m;
int a[N];
vector<int> adj[N] ;
bool vis[N];

void solve(){	
	cin >> n >> m;
	
	for(int i=1 ; i<=n ; i++)
		cin >> a[i];
	
	memset(vis,1,sizeof(vis));
	
	int u1 , v1;
	for(int i=1 ; i<=m ; i++){
		
		cin >> u1 >> v1;
		if(a[u1] >= a[v1])	vis[v1] = 0;
		if(a[u1] <= a[v1])	vis[u1] = 0;
		
	}
	
	int cnt = 0;
	for(int i=1 ;i<=n ; i++)
		cnt += (vis[i]==1);
	cout << cnt << endl;
}

	
int32_t main(){
	FAST;
	int t=1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}	

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

using namespace std;

#define Rep(b, e, i) for (int i = b; i <= e; i++)
#define Repr(e, b, i) for (int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n - 1, i)
#define repr(n, i) Repr(n - 1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T, vector<T>, greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false) std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<vec> mat;
typedef vector<vecll> matll;
typedef vector<vecd> matd;

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

const int MAX = 1000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1000000007;

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

//********************************template END****************************************//

void solve()
{
	vec memo, odds;
	int n = 1, res = -1;
	while(res <= MAX)
	{
		res = n * (n + 1) * (n + 2) / 6;
		memo.pb(res);
		if (res&1) odds.pb(res);
		n++;
	}

	vec dp1(MAX+1, INF), dp2;
	dp1[0] = 0;
	dp2 = dp1;

	rep(MAX, m)
	{
		dp1[m] = min(dp1[m], m);
		dp2[m] = min(dp2[m], m);
		for (int x : memo)
		{
			if (m < x) break;
			dp1[m] = min(dp1[m - x] + 1, dp1[m]);
		}
		for (int x : odds)
		{
			if (m < x) break;
			dp2[m] = min(dp2[m - x] + 1, dp2[m]);
		}
	}

	while (~scanf("%d", &n))
	{
		if (n == 0) break;
		cout << dp1[n] << ' ' << dp2[n] << endl;
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 10576
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

int gcd(int a,int b){
    if(a<=0||b<=0){
        return 0;
    }
    if(a<b)swap(a,b);
    int r=a%b;
    while(r){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}


signed main(){
    int x,y;
    cin >> x >> y;
    cout << 1+x+y-gcd(x,y) << endl;
    
    return 0;
}   


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

#define MAX 100000

int eval(long long P);
int search(int T[], int k, int n);

int main()
{
    int n, k, i;
    int T[MAX];

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

    int ans = search(T, k, n);
    cout << ans << endl;

    return 0;
}

int eval(long long P, int T[], int k, int n)
{
    int i = 0;
    for(int j = 0; j<k; j++)
    {
        long long sum = 0;
        
        while(sum + T[i] <= P)
        {
            sum += T[i];
            i++;
            if(i == n) return n;
        }
    }
    return i;
}

int search(int T[], int k, int n)
{
    int middle;
    long long left = 0;
    long long right = 100000 * 10000;

    while(right - left > 1)
    {
        middle = (left + right) / 2;
        if(eval(middle, T, k, n) >= n)
        {
            right = middle;
        }
        else
        {
            left = middle;
        }
    }
    return right;
}


Measured memory_bytes: 3484
a = int(input())
b = input().split()
seisuu = [int(i) for i in b]
seisuu_sorted = sorted(seisuu)
count = 0

for i in range(a):
    if seisuu[i] != seisuu_sorted[i]:
        count += 1
if count <= 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
import collections, sys
input = sys.stdin.readline

n, m = map(int, input().split())
graph = [[] for i in range(n + 1)]
for i in range(m):
    l, r, d = map(int, input().split())
    graph[l].append([r, d])
    graph[r].append([l, -d])
place = [None for i in range(n + 1)]

num = 0
flag = True
while num <= n:
    if flag == False:
        break
    if place[num] != None:
        num += 1
        continue
    place[num] = 0
    queue = collections.deque([num])
    while queue:
        if flag == False:
            break
        test = queue.popleft()
        for i in graph[test]:
            if place[i[0]] != None:
                if place[i[0]] - place[test] != i[1]:
                    flag = False
                    break
            else:
                place[i[0]] = place[test] + i[1]
                queue.append(i[0])
    else:
        num += 1
if flag == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 133636
#pragma GCC optimize("O3")
    #pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize("Ofast")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include<bits/stdc++.h>
    #define int long long
    # define mo 1000000007
    using namespace std;
    #define goku ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    signed main(){
        goku
      int n,m;
      cin>>n>>m;
      int an=n/m;
      if(n%m!=0)
        an++;
      cout<<an;
       return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

struct UnionFindTree {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        siz.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        siz[x] += siz[y];
    }
    bool is_same(int x, int y) {
        return root(x) == root(y);
    }
    int size(int x) {
        x = root(x);
        return siz[x];
    }
};

bool isPrime[MAX_N];
vector<int> primes;
map<int, int> p2n;

void sieve(int n){
    fill(isPrime, isPrime+n+1, true);
    isPrime[0] = isPrime[1] = false;
    for(int i=2;i*i<=n;i++){
        if(isPrime[i]){
            for(int j=i*i; j<=n; j+=i){
                isPrime[j] = false;
            }
        }
    }
    for(int i=2;i<=n;i++){
        if(isPrime[i]){
            primes.push_back(i);
            p2n[i] = int(primes.size())-1;
        }
    }
}

int n, a[MAX_N];

int main() {
    sieve(100001);
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    UnionFindTree g;
    g.init(n + int(primes.size()));


    for(int i=0;i<n;i++){
        for(int j=0;j<int(primes.size());j++){
            int p = primes[j];
            if(a[i]%p==0){
                g.unite(i, n+j);
                g.unite(i, n+p2n[a[i]/p]);
            }
            if(a[i] < primes[j]*primes[j])break;
        }
        if(isPrime[a[i]]) g.unite(i, n+p2n[a[i]]);
    }
    map<int, vector<int> > ls;
    for(int i=0;i<n;i++){
        ls[g.root(i)].push_back(a[i]);
    }
    for(auto &l : ls){
        sort(l.second.rbegin(), l.second.rend());
    }
    int pre = 0;
    bool ok = true;
    for(int i=0;i<n;i++){
        int x = ls[g.root(i)].back();
        ls[g.root(i)].pop_back();
        if(x < pre) ok = false;
        pre = x;
        //cout << pre << endl;
    }
    cout << (ok?1:0) << endl;
    return 0;
}




Measured memory_bytes: 8012
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>      // std::setprecision
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;
namespace bst = boost;

int main() {
  int N,K;

  cin >> N>>K;
  vector<int> P(N);
  
  int nosort = 0, renzoku = 0, past = -1;
  for (auto& i : P) {
    cin >> i;
    
    if (past < i) {
      renzoku++;
      if (renzoku == K)
        nosort++;
    }
    else {
      renzoku = 1;
    }
    past = i;
  }
  
  int mx = N - K + 1, l = 0, r = 0;
  
  auto itl = P.begin() + 1, itr = P.begin() + K;
  set<int> found;
  found.insert(itl, itr);
  
  
  const auto m = mx - 1;
  auto itf = P.begin();
  REP(i, m) {
    if (*itf < *found.begin() && *itr > *found.rbegin())
      mx--;
    itf++;
    found.insert(*itr++);
    found.erase(*itl++);
  }

  cout << mx - max(nosort - 1, 0) << endl;

  return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n,m;
int a[311][311];
int cnt[311];
bool used[311];

int main(){
	cin.sync_with_stdio(false);
  cin>>n>>m;
  rep(i,n)rep(j,m){
    cin>>a[i][j];
    a[i][j]--;
  }
  int res=INF;
  while(1){
    memset(cnt,0,sizeof(cnt));
    rep(i,n){
      rep(j,m){
        if(used[a[i][j]])continue;
        cnt[a[i][j]]++;
        break;
      }
    }
    int maxc=-1,maxidx=-1;;
    rep(j,m){
      if(maxc<cnt[j]){
        maxc=cnt[j]; maxidx=j;
      }
    }
    minch(res,maxc);
    used[maxidx]=true;
    bool ok=false;
    rep(j,m){
      if(!used[j])ok=true;
    }
    if(!ok)break;
  }
  cout<<res<<endl;
	return 0;
}


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

typedef long long ll;
typedef long double ld;

const int N = 55555;
bool primes[N+1];
 
void sieve(int n){
	vector<int> primelist;
	for (int i = 2; i <= n; i++){
		bool isPrime = true;
		for (int j = 0; j < primelist.size(); j++){
			if (primelist[j]*primelist[j] > i) break;
			if (i % primelist[j] == 0){
				isPrime = false;
				break;
			}
		}
		 
		if (!isPrime) continue;
		 
		primelist.push_back(i);
		primes[i] = true;
	}
} 
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	 
	memset(primes, false, sizeof(primes));
	sieve(N);
	
	vector<int> ans;
	for (int i = 2; i < N; i++){
		if (primes[i]){
			if (i%5 == 2){
				ans.push_back(i);
			}
		}
	}
	
	
	int n; cin >> n;
	for (int i = 0; i < n; i++){
		cout << ans[i] << " ";
	}
	cout << endl;
}

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

#pragma warning(disable:4996)

using namespace std;



int main()
{
	int N;
	string s;
	deque<char> st;
	string res;

	while (cin >> N)
	{
		cin >> s;

		string res;
		int left = 0, right = 0;
		for (int i = 0; i < N; ++i)
		{
			if (s[i] == '(')
			{
				st.push_back('(');
				++left;
			}
			else
			{
				if (left > right)
				{
					st.push_back(')');
					++right;
				}
				else
				{
					st.push_front('(');
					st.push_back(')');
					++left;
					++right;
				}
			}
		}

		if (left > right)
		{
			left -= right;
			for (int i = 0; i < left; ++i)
				st.push_back(')');
			left = 0;
		}
		while (!st.empty())
		{
			res += st.front();
			st.pop_front();
		}
		cout << res << endl;
	}


	return 0;
}


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

using namespace std;

int calc(vector<int> a, vector<int> b){
  return b[0] + a[0]*b[1] + a[1]*b[2] + a[2]*b[3];
}

void out(vector<int> b, vector<int> a){
  cout << a[0];
  if(b[0] == -1) cout << '-';
  if(b[0] == 1) cout << '+';
  cout << a[1];
  if(b[1] == -1) cout << '-';
  if(b[1] == 1) cout << '+';
  cout << a[2];
  if(b[2] == -1) cout << '-';
  if(b[2] == 1) cout << '+';
  cout << a[3] << "=7" << endl;
}

int main(){
  int h;
  cin >> h;
  int a,b,c,d;
  a = (h-h%1000)/1000;
  b = (h-a*1000-h%100)/100;
  c = (h-a*1000-b*100-h%10)/10;
  d = h%10;
  vector<int> num{a,b,c,d};

  vector<int> start{0,0,0};

  stack<vector<int>> st;
  st.push(start);

  while(1){
    vector<int> now = st.top();
    st.pop();

    if(now[2] != 0){
      if(calc(now, num) == 7){
        out(now, num);
        break;
      }
    }

    if(now[0] == 0){
      now[0] = -1;
      st.push(now);
      now[0] = 1;
      st.push(now);
    }else if(now[1] == 0){
      now[1] = -1;
      st.push(now);
      now[1] = 1;
      st.push(now);
    }else if(now[2] == 0){
      now[2] = -1;
      st.push(now);
      now[2] = 1;
      st.push(now);
    }

    if(st.empty()){
      break;
    }
  }
  return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<=(n); i++)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define int int64_t
#define ll long long
#define re(s) reverse((s).begin(),(s).end())
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;
using namespace std;

bool y[100010];
signed main(){
    int n,m,cnt=0,ans=0;
    cin>>n>>m;
    vector<int> x;
    vector<string> s;
    int a;
    string b;

    rep(i,m){
        cin>>a>>b;
        x.push_back(a);
        s.push_back(b);
        if(b == "AC"){
            y[a] = true;
        }
    }

    rep(i,m){
        if(s[i] == "AC" && y[x[i]]){
            ++ans;
            y[x[i]] = false;
        }
        if(s[i] == "WA" && y[x[i]]){
            ++cnt;
        }
    }

    cout<<ans<<' '<<cnt<<'\n';
}

Measured memory_bytes: 6632
/*
cat <<EOF >mistaken-paste
*/

#pragma GCC diagnostic ignored "-Wincompatible-pointer-types"

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

#define BIG 2000000007
#define VERYBIG 200000000000007LL

#define MOD 1000000007
typedef uint64_t ull;
typedef  int64_t sll;

#define N_MAX 300000
#define M_MAX 200000

typedef struct {
	int32_t a;
	int32_t b;
} hw;

typedef struct {
	sll a;
	sll b;
} hwll;

typedef struct {
	hwll a;
	hwll b;
} linell;


typedef struct {
	ull s;
	ull t;
	int32_t c;
} struct_a;

typedef struct {
	int32_t from;
	int32_t to;
	sll cost;
} struct_b;

ull n, m;
ull h, w;
ull k;
ull q;
ull vua, vub, vuc, vud, vue, vuf;
sll vsa, vsb, vsc, vsd, vse, vsf;
long double vra, vrb, vrc;
double vda, vdb, vdc;
size_t slen;
size_t tlen;
char ch, dh;

sll a[N_MAX];

hwll arr[N_MAX];

int32_t pullcomp (const void *left, const void *right) {
	ull l = *(ull*)left;
	ull r = *(ull*)right;
	if (l < r) {
		return -1;
	}
	if (l > r) {
		return +1;
	}
	return 0;
}

ull solve () {
	sll i, j, ki;

	qsort(a, n, sizeof(ull), pullcomp);

	ull kinds = 0;
	i = 0;
	while (i < n) {
		j = i;
		while (j < n && a[j] == a[i]) j++;
		arr[kinds].a = a[i];
		arr[kinds].b = j - i;
		kinds++;

		i = j;
	}

	if (arr[0].b > 2) goto fail;
	
	ull maxnum = ((arr[0].b == 1) ? a[0] * 2 : a[0] * 2 - 1);
	if (kinds != (maxnum - a[0] + 1) || arr[kinds - 1].a != maxnum) goto fail;

	for (i = 1; i < kinds; i++) {
		if (arr[i].b < 2) goto fail;
	}

	puts("Possible");
	return 0;

	fail:
	puts("Impossible");
	return 1;
}

int32_t main (void) {
	int32_t i, j;
	int32_t x, y;

	scanf("%llu", &n, &m);
	for (i = 0; i < n; i++) {
		scanf("%llu", &a[i]);
	}

	solve();

	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int h,w,n; cin >> h >> w >> n;
    int sr,sc; cin >> sr >> sc;
    string s,t; cin >> s >> t;
    
    int u=0,d=0,l=0,r=0;
    int ue=0,de=0,le=0,re=0;
    
    rep(i,n){
        if(s[i]=='L') l++;
        if(s[i]=='R') r++;
        if(s[i]=='U') u++;
        if(s[i]=='D') d++;
        
        if((u-de)>=sr||(d-ue)>=(h-sr+1)||(l-re)>=sc||(r-le)>=(w-sc+1)){
            cout << "NO" << endl;
            return 0;
        }
        
        if(t[i]=='L'){
            le++;
            chmin(le,sc-1+r);
        }
        if(t[i]=='R'){
            re++;
            chmin(re,w-sc+l);
        }
        if(t[i]=='U'){
            ue++;
            chmin(ue,sr-1+d);
        }
        if(t[i]=='D'){
            de++;
            chmin(de,h-sr+u);
        }
    }
    cout << "YES" << endl;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    ll S; cin >> S;
    ll x2 = 1e+9, y2=1;
    ll y3 = S/x2, x3 = S%x2;
    if(x3 != 0){
        y3++; x3 = x2-x3;
    }

    cout << 0 << " " << 0 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
const int N=5e5+5;
int n,q,pos[N],ans[N],to_s[N],to_b[N];

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

template <class T> inline void apn(T &x,const T y){
	if(x>y) x=y;
}

template <class T> inline void apx(T &x,const T y){
	if(x<y) x=y;
}

bool cmp_pos(const int a,const int b){
	return pos[a]<pos[b];
}

struct cmp_pos_greater{
	bool operator () (const int a,const int b){
		return pos[a]>pos[b];
	}
};

namespace G{
	int cnt,fir[N],in[N],buk[N];
	struct edge{
		int to,nx;
	}eg[N<<1];

	inline void add(const int a,const int b){
		eg[++cnt]=(edge){b,fir[a]};
		fir[a]=cnt;
		++in[b];
	}

	inline void init(){
		for(int i=1;i<=n;++i){
			if(to_s[i]<=n) add(i,to_s[i]);
			if(to_b[i]<=n) add(i,to_b[i]);
		}
	}

	inline void topo(){
		std::priority_queue <int,std::vector <int>,cmp_pos_greater> pq;
		int top=0;
		for(int i=1;i<=n;++i){
			if(!in[i]) pq.push(i);
		}
		while(!pq.empty()){
			const int x=pq.top();
			pq.pop();
			buk[++top]=x;
			for(int i=fir[x];i;i=eg[i].nx){
				const int y=eg[i].to;
				if(!--in[y]) pq.push(y);
			}
		}
	}
}

namespace T{
	int x,y,v,tr[N<<1],buk[N];

	inline int idx(const int l,const int r){
		return (l+r)|(l!=r);
	}

	inline void upd(const int l,const int r){
		const int mid=(l+r)>>1;
		tr[idx(l,r)]=tr[idx(l,mid)]+tr[idx(mid+1,r)];
	}

	void mod_t(const int l,const int r){
		if(l==r){
			tr[idx(l,r)]+=v;
			return;
		}
		const int mid=(l+r)>>1;
		if(x<=mid) mod_t(l,mid);
		else mod_t(mid+1,r);
		upd(l,r);
	}

	int ask_l_t(const int l,const int r){
		if(!tr[idx(l,r)]) return n+1;
		if(l==r) return l;
		int tp,mid=(l+r)>>1;
		if(x<=mid&&(tp=ask_l_t(l,mid))<=n) return tp;
		return ask_l_t(mid+1,r);
	}

	inline void mod(const int x,const int v){
		T::x=x,T::v=v;
		mod_t(1,n);
	}

	inline int ask_l(const int x,const int y){
		if(x>y) return n+1;
		T::x=x,T::y=y;
		return ask_l_t(1,n);
	}

	inline void init(){
		for(int i=1;i<=n;++i){
			buk[pos[i]]=i;
		}
		std::sort(buk+1,buk+n+1,cmp_pos);
	}

	inline void solve1(){
		for(int i=1;i<=n;++i){
			if(i-q>0) mod(buk[i-q],-1);
			apn(to_s[buk[i]],ask_l(buk[i]+1,n));
			mod(buk[i],1);
		}
	}

	inline void solve2(){
		for(int i=n;i;--i){
			if(i+q<=n) mod(buk[i+q],-1);
			apn(to_b[buk[i]],ask_l(buk[i]+1,n));
			mod(buk[i],1);
		}
	}
}

int main(){
#ifndef ONLINE_JUDGE
//	freopen("f.in","r",stdin);
#endif
	memset(to_s,1,sizeof(to_s));
	memset(to_b,1,sizeof(to_b));
	n=nxi(),q=nxi();
	for(int i=1;i<=n;++i){
		pos[nxi()]=i;
	}
	T::init();
	T::solve1();
	memset(T::tr,0,sizeof(T::tr));
	T::solve2();
//	for(int i=1;i<=n;++i){
//		printf("%d %d\n",to_l[i],to_r[i]);
//	}
	G::init();
	G::topo();
	for(int i=1;i<=n;++i){
		ans[pos[G::buk[i]]]=i;
	}
	for(int i=1;i<=n;++i){
		printf("%d\n",ans[i]);
	}
	return 0;
}

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

int main(){
  int t,n;
  cin>>t;
  for(int i=0;i<t;i++){
    cin>>n;
    ll a[n];
    string s;
    for(int j=0;j<n;j++){
      cin>>a[j];
    }
    cin>>s;
    for(int j=n-1;j>=0;j--){
      if(a[j]>0){
        if(s[j]-'0'==1){cout<<1<<endl;break;}
        for(int k=0;k<62;k++){
          if((a[j]>>k)&1){
            for(int l=j-1;l>=0;l--){
              if((a[l]>>k)&1)a[l]^=a[j];
            }
            break;
          }
        }
      }
      if(j==0)cout<<0<<endl;
    }
  }
}


Measured memory_bytes: 3624