akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int a, b, c, d;
int ans;


int main() {
    cin >> a >> b >> c >> d;
    if (b <= c || d <= a) {
        cout << 0 << endl;
    } else if(a <= c && d <= b) {
        cout << d-c << endl;
    } else if(c <= a && b <= d) {
        cout << b-a << endl;
    } else if(a <= c) {
        cout << b-c << endl;
    } else if(c <= a) {
        cout << d-a << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main(void) {
  int N, M;
  cin >> N >> M;

  map<int, int> count;
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    count[a]++;
    count[b]++;
  }
  for (auto& num : count) {
    if (num.second % 2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

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

string map[20];
int count,W,H;
int walk(int ,int);

int main(){
	int W,H,x,y,r;
	cin >> W >> H >> x >> y >> r;
	if(x-r>=0 && x+r <= W && y-r >=0 && y+r <= H) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main()
{
int n;
cin>>n;
int h[n];
int mm=0;
for(int i=0;i<n;i++)
cin>>h[i];
int m=h[n-1];
int c=0;
for(int i=n-2;i>=0;i--)
{
    if(m<=h[i])c++;
    else c=0;

    if(c>mm) mm=c;
    m=h[i];
}
  cout<<mm;
return 0;
}


Measured memory_bytes: 640
def cnt_primenumber(arr):
    cnt = 0
    for i in range(len(arr)):
        if arr[i] == 1:
            continue
        flag = 1
        for j in range(2,int(arr[i]**0.5)+1):
            if arr[i] % j == 0:
                flag = 0
                break
        if flag:
            cnt += 1
    return cnt

ls = []
n = int(input())
for i in range(n):
    a = int(input())
    ls.append(a)

print(cnt_primenumber(ls))



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

int main() {
	int N ;
	cin >> N;
	int count = 0;
	int order=0;
	
	for(int i=0;i<6;i++){
		if(pow(10,i)<=N && N<pow(10,i+1)){
			order = i;
			
			break;
		}
		
		else if (i%2==0){
			count = count + pow(10,i+1)-pow(10,i);
		}
	}
	
	if (order%2==0){
		count = count + N- pow(10,order)+1;
	}
	

	cout << count << endl;
	
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int N,a,b,c;
string s;

int main(){
	bool f=0;
	while(cin>>N){
		if(!N)return 0;
		if(f)cout<<endl;
		pair<int,pair<int,string> > p[10];
		for(int i=0;i<N;i++){
			cin>>s>>a>>b>>c;
			p[i]=make_pair(a*-3-c,make_pair(i,s));
		}
		sort(p,p+N);
		for(int i=0;i<N;i++)cout<<p[i].second.second<<","<<-1*p[i].first<<endl;
		f=1;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef		 double    ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;



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

   ll n,d;
   cin>>n>>d;
   ll ans=0;
   while(n--)
   {
       ll x,y;
       cin>>x>>y;
       x=x*x;
       y=y*y;
       ll dis=(ll)sqrt(x+y);
       if(dis<=d) ans++;
   }
   cout<<(int)ans<<nn;











}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***

*/





Measured memory_bytes: 3844
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;
int main() {
    int n;
    cin >> n;
    vector<string> s(n + 5);
    for(int i = 1; i <= n; i++) {
        cin >> s[i];
    }
    string t;
    cin >> t;
    int st = 1, dr = n + 1;
    for(int i = 1; i <= n; i++) {
        string x = s[i];
        for(int i = 0; i < x.size(); i++) {
            if(x[i] == '?') {
                x[i] = 'a';
            }
        }
        if(strcmp(x.c_str(), t.c_str()) > 0) {
            dr--;
        }
        string y = s[i];
        for(int i = 0; i < y.size(); i++) {
            if(y[i] == '?') {
                y[i] = 'z';
            }
        }
        if(strcmp(y.c_str(), t.c_str()) < 0)  {
            st++;
        }
    }
    for(int i = st; i <= dr - 1; i++) {
        cout << i << " ";
    }
    cout << dr << endl;
    return 0;
}

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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque
//stack…FILO
//queue…FIFO
//priority_queue
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, unsigned int index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}

template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}

template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

ull ans = 0;
/*
int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}
*/
int main() {
    int n, k;
    cin >> n >> k;
    ans = n - k + 1;
    cout << ans;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val x = sc.nextInt()
    val y = sc.nextInt()
    if (x % y == 0) {
        println(-1)
    } else {
        println(x)
    }
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 34368
// itne me hi thakk gaye?
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")
#define ll long long 
#define ull unsigned long long
using ld = long double;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ll rk = 256;
const ld PI = 3.141592653589793;
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define print(a) for(auto j:a) {cout<<j<<",";} cout << "\n";
#define endl '\n'
#define whatis(x) cout << "> "<<#x << " ==> " << x << endl;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
// // Printing pair
ostream & operator << (ostream & os, pair <ll, ll> const& x) {
    os << x.first << "," << x.second;
    return os;
}
 
// printing vector
template <class T>
ostream & operator << (ostream & os, vector <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
// printing set
template <class T>
ostream & operator << (ostream & os, set <T> const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}
 
template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
    return os << "[ " << p.first << ", " << p.second << "]" ;
}
const int mxn = 3005;

int32_t main(){
    FastIO;
    int n;cin >> n;
    vc <ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    vc < vc<ll> > dp(mxn, vc <ll> (mxn));
    // dp[0][n-1] is the range where our answer lies
    for(int l=n-1; l>=0; l--) {
        for(int r=l; r<n; r++) {
            if (l==r) {
                dp[l][r] = a[l];
            }
            else {
                dp[l][r] = max(a[l] - dp[l+1][r], a[r] - dp[l][r-1]);
            }
        }
    }
    cout << dp[0][n-1] << endl;
    return 0;
}


Measured memory_bytes: 71040
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long int
int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    // #endif
    // ios_base::sync_with_stdio(false);
    ll  n;
    cin>>n;
    ll arr[n+2];
    for(ll i=0;i<n-1;i++)
    cin>>arr[i];
    ll sum=arr[0];
    for(ll i=1;i<n-1;i++)
    {
        sum=sum+min(arr[i],arr[i-1]);
    }
    sum+=arr[n-2];
    cout<<sum;

return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {


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

		while (true) {
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			int top = 1;
			int north = 2;
			int west = 3;
			
			for(int i = 0; i < n; i++){
				String input = sc.next();
				
				if("north".equals(input)){
					int next_top = 7 - north;
					int next_north = top;
					
					top = next_top;
					north = next_north;
				}else if("south".equals(input)){
					int next_top = north;
					int next_north = 7 - top;
					
					top = next_top;
					north = next_north;
				}else if("east".equals(input)){
					int next_top = west;
					int next_west = 7 - top;
					
					top = next_top;
					west = next_west;
				}else if("west".equals(input)){
					int next_top = 7- west;
					int next_west = top;
					
					top = next_top;
					west = next_west;
				}
			}
			
			System.out.println(top);
		}
	}

}

Measured memory_bytes: 21180
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll INF = 1LL << 50;

char beet(char c) {
  if (c == 'r') return 'p';
  if (c == 'p')
    return 's';
  else
    return 'r';
}

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

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

  ll x0 = 0, x1 = INF;
  ll minv = LONG_LONG_MAX;
  while (x0 + 1 < x1) {
    ll t = 0;
    ll x = (x0 + x1) / 2;
    rep(i, n) t += n - Lower_bound(a, x - a[i]);
    if (t >= m)
      x0 = x;
    else
      x1 = x;
  }

  vll sum(n + 1, 0);
  rep(i, n) sum[n - i - 1] = sum[n - i] + a[n - i - 1];

  ll ans = 0;
  ll mp = 0;
  for (ll i = 0; i < n; i++) {
    ll i0 = Lower_bound(a, x0 - a[i]);
    if(i0 != n) chmin(minv, a[i] + a[i0]);
    ans += sum[i0] + (n - i0) * a[i];
    mp += n - i0;
  }
  ans -= x0 * (mp - m);

  assert(x0 == minv);
  // cout << minv << " " << x0 << endl;
  cout << ans << endl;

  return 0;
}


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

namespace _0227
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (n[0] == n[1] && n[0] == 0) { break; }
                int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                Array.Sort(a);
                int ans = a.Sum();
                for(int i = a.Length-n[1]; i >=0; i -= n[1])
                {
                    ans -= a[i];
                }Console.WriteLine(ans);
            }
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 10132
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }
 
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
 
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};
 
const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod


#include <bits/stdc++.h>
using namespace std;
signed main(){
    string S,T; cin>>S>>T;
    bool ans = true;
    REP(i,S.size()){
        if(S[i]!=T[i]) ans = false;
    }
    if(ans) Out("Yes");
    else Out("No") ;   
}

Measured memory_bytes: 3648
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [a*2 for a in A]
    total = sum(A)
    ans = [0] * N
    ans[0] = total - sum(B[1::2])
    for i in range(0, N-1):
        ans[i+1] = B[i] - ans[i]
    print(*ans)


if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define N 6
double p[N], q[N];

int main () {
	for (int i = 0; i < N; i ++) {
		cin >> p[i];
		p[i] /= 100.0;
	}
	for (int i = 0; i < N; i ++) {
		cin >> q[i];
		q[i] /= 100.0;
	}
	double S = 1;
	for (int i = 0; i < N; i ++) if (p[i]+q[i]>1e-5) {
		double x = (double)q[i]/(p[i]+q[i]);
		double T = 0;
		for (int j = 0; j < N; j ++) {
			//T += max(p[j], q[j])*(p[j]*x+q[j]*(1-x))/100.0;
			T += max(p[j]*x, q[j]*(1-x));
		}
		S = min(S, T);
	}
	printf ("%.9lf\n", S);
	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
m = (10**9) + 7
after = sum([len(list(filter(lambda x: A[i] > x, A[i+1:]))) for i in range(N - 1)])%m
_all = sum([len(list(filter(lambda x: A[i] > x, A))) for i in range(N)])%m

k = (K*K-(K*(K+1)//2))%m

print((
  (after*K)%m
  +(_all*k)%m
)%m)


Measured memory_bytes: 3188
#include<iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <iostream>
#include <algorithm>
using namespace std;
__int128 ans;
int main()
{
	/*long long n;
	scanf("%lld",&n);
	if(n%9==0)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}*/
	string s;
	getline(cin,s);
	for(long long i=0;i<s.size();i++)
	{
		ans+=s[i]-'0';
	}
	if(ans%9==0 || ans==0)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 3844
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(long long sx, long long sy, long long tx, long long ty){
    const int dx=tx-sx, dy=ty-sy;
    cout<<string(dy,'U')<<string(dx,'R');
    cout<<string(dy,'D')<<string(dx,'L');
    cout<<'L'<<string(dy+1,'U')<<string(dx+1,'R')<<'D';
    cout<<'R'<<string(dy+1,'D')<<string(dx+1,'L')<<'U';
    cout<<endl;
}

int main(){
    long long sx;
    scanf("%lld",&sx);
    long long sy;
    scanf("%lld",&sy);
    long long tx;
    scanf("%lld",&tx);
    long long ty;
    scanf("%lld",&ty);
    solve(sx, sy, tx, ty);
    return 0;
}


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

const int mnx = 3e5 + 9;
const int mod = 1e9 + 7;

ll h, w;
char a[9][9];

int main(){

cin>>h>>w;

for(int i=1; i<=h; i++){
    for(int j=1; j<=w; j++){
        cin>>a[i][j];
    }
}

for(int i=1; i<=h; i++){
    for(int j=1; j<=w; j++){
        if(a[i+1][j] == '#' && a[i][j+1] == '#'){ cout<<"Impossible\n"; return 0; }
        if(a[i-1][j] == '#' && a[i][j-1] == '#'){ cout<<"Impossible\n"; return 0; }
    }
}

cout<<"Possible\n";

return 0;

}














Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit


double getDistance(vector<vector<double>> x, int i, int j,int d){
  double ans = 0;
  rep(k,d){
    ans+=pow(x.at(i).at(k)-x.at(j).at(k),2);
  }
  return sqrt(ans);
}
bool isInteger(double x){
  return floor(x)==x;
}
int main() {
  cout << fixed << setprecision(10);
  int n,d;
  cin >> n >> d;
  vector<vector<double>> x(n,vector<double>(d));
  rep(i,n){
    rep(j,d){
      cin >> x.at(i).at(j);
    }
  }
  int count = 0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      if(isInteger(getDistance(x,i,j,d))){
        count++;
      }
    }
  }
  cout << count << endl;
}


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

int main() {
	
	int L, R;
	cin >> L >> R;
	
	int min = 2020;
	for(int i=L; (i<L+2020) && (i<R); i++){
		for(int j=L+1; (j<L+2020) && (j<=R); j++){
			int x = ((i % 2019) * (j % 2019)) % 2019;
			if(x < min) min = x;
		}
	}
	cout << min << endl;
	
	return 0;
}

Measured memory_bytes: 256
/*    
                                                                             
	1. Practice makes a man perfect.
	2. Let go of the past.
	3. Without pain, without sacrifice, we would have nothing.
	4. Great things never come from comfort zones.
	5. Turn your wounds into wisdom.
	6. No pain ... no palm, no throne, no glory,no cross, no crown.
	7. You never know how strong you are until being strong is your only choice.
	8. Smooth seas do not make skillful sailors.
	9. I am not what happened to me, I am what I choose to become.
	10. No matter how fail life pushes you down, No matter how much you hurt,You can always bounce back.
		
		
	--> This lines keep me motivated.		

	Author:- Gaurang_Kothiya
	
*/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  

#define data_set(type) tree<type,null_type,less<type>,rb_tree_tag,tree_order_statistics_node_update>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define ld long double
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(int i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define ook(num) order_of_key(num)
#define fbo(num) find_by_order(num)
#define gcd(a,b) __gcd(a,b)
#define bits(n) __builtin_popcountll(n)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846

const int inf= 1e9 +1;
const int inf64= 1e18 -1;
const int MOD= 1e9 +7;


 
void Solve()
{	
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	while(b<=a && k>0)
	{
		b *=2;
		k--;
	}
	while(c<=b && k>0)
	{
		c *=2;
		k--;
	}
	if(c>b && b>a) cout<<"Yes";
	else cout<<"No";
}
 
signed main() 
{
	speed		

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
		
	return 0;
} 

Measured memory_bytes: 3628
K = int(input())
c = 1
nana = 7
if K%2 == 0:
    print("-1")
else:
    n = 7%K
    while True:
        i = nana%K
        if i == 0:
            print(c)
            break
        elif c >= 10**6:
            print("-1")
            break
        else:
            nana = (10*i+n)%K
            c += 1

Measured memory_bytes: 9112
#include<iostream>
#include<string>
#include<iomanip>

using namespace std;
int main(void) {
	int n[5];
	int z;
	for (int i = 0; i < 5; i++) {
		cin >> n[i];
		if (n[i] == 0)
			z = i + 1;
	}
	cout << z;
	return 0;
}

Measured memory_bytes: 3560
#include <cstdio>

int K;
long long data[100000];

int main(void) {
	scanf("%d", &K);
	for(int i = 0; i < K; i++) scanf("%lld", data + i);
	long long minValue = 2, maxValue = 2;
	for(int i = K - 1; i >= 0; i--) {
		long long v = data[i];
		long long nmin = minValue / v * v;
		if(nmin < minValue) nmin += v;
		if(nmin > maxValue) {
			minValue = -1;
			break;
		}

		long long nmax = maxValue / v * v;
		if(nmax < minValue) {
			minValue = -1;
			break;
		}

		minValue = nmin;
		maxValue = nmax + v - 1;
	}

	if(minValue == -1) printf("-1\n");
	else printf("%lld %lld\n", minValue, maxValue);
	
	return 0;
}

Measured memory_bytes: 896
#include "bits/stdc++.h"
    using namespace std;
    const int N=2e3+1,MOD=1e9+7;
    int c[N][N],n,k,red,blue,ans;
    int main()
    {
        c[0][0]=1;
        for(int n=1;n<N;n++)
        {
            for(int r=0;r<=n;r++)
            {
                if(r==0 or r==n) c[n][r]=1;
                else c[n][r]=c[n-1][r-1]+c[n-1][r];
                c[n][r]%=MOD;
            }
        }
     
        cin>>n>>k;
     
        blue=k,red=n-k;
        for(int k=1;k<=blue;k++)
        {
            ans=(1ll*c[red+1][k]*c[blue-1][k-1])%MOD;
            printf("%d\n",ans);
        }
    }

Measured memory_bytes: 14976
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<vector>
#include<cctype>
using namespace std;


/*void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}*/
int main(){

int n;cin>>n;
	for(int i=1;i<=n;i++){
		int x=i;
		if(i%3==0)cout<<" "<<i;
		else{
			while(x>=10){
				if(x/10==3||x%10==3){
				cout<<" "<<i;break;
				}
				x=x/10;
			}
		}
	}
		
	cout<<endl;
return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
int A[20], B[20];
int dp[1 << 18][51];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    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 < (1 << N); i++){
        for(int j = 0; j <= 50; j++){
            dp[i][j] = inf;
        }
    }
    dp[0][0] = 0;
    
    for(int i = 0; i < (1 << N); i++){
        for(int j = 0; j <= 50; j++){
            int s = 0;
            for(int k = 0; k < N; k++){
                s += (i >> k) & 1; 
            }

            int p = 0;
            for(int k = 0; k < N; k++){
                if((i >> k) & 1) continue;
                if(abs(k - s) & 1){
                    if(j <= B[k]){
                        chmin(dp[i | (1 << k)][B[k]], dp[i][j] + p);
                    }
                }else{
                    if(j <= A[k]){
                        chmin(dp[i | (1 << k)][A[k]], dp[i][j] + p);
                    }
                }
                p++;
            }
        }
    }
    int ans = inf;
    for(int i = 0; i <= 50; i++){
        chmin(ans, dp[(1 << N) - 1][i]);
    }
    cout << (ans == inf ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 52608
#define GODSPEED ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define f(i,x,n) for(i=x;i<n;i++)
#define rf(i,x,n) for(i=n;i>x;i--)
#define ll long long
#define GCD(a,b) __gcd(a,b)
#define adios return 0;

/*
SHERAJUL ARIFIN
Dept. of CSE,
IUT.
*/


#include <bits/stdc++.h>
using namespace std;

int main()
{
    GODSPEED;
    ll t,n,a,b,c,d,s=0,i,j,flag;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        if(i%15!=0 and i%3!=0 and i%5!=0) s+=i;
    }
    cout<<s<<endl;



    adios;
}


Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  for(int n=0;n<7;n++){
    cin >>a>>b;
    cout <<a-b<<'\n';
  }
  return (0);
}



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

int main() {
  int n;
  map<int, int> a;

  cin >> n;

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

  int mx = 0;
  for(auto p : a) mx = max(mx, p.second);

  if(mx == 1) cout << "YES" << endl;
  else  cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define xx first
#define yy second
#define D if(0)
#define cerr D cerr

using namespace std;
typedef long long ll;

template <typename T>
vector<T> read_n(int n) {
  vector<T> ret(n);
  for(int i = 0; i < n; i++) cin >> ret[i];
  return ret;
}

template <typename iter>
void dump(iter begin, iter end) {
  for(iter it = begin; it != end; it++) {
    if(it != begin) cout << " ";
    cout << *it;
  } cout << endl;
}

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

  int a, b; cin >> a >> b;

  cout << a * b << "\n";

  return 0;
}


Measured memory_bytes: 3612
import java.math.BigInteger;
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int a[] = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt();
        }
        int max = -1;
        for (int i = 0; i < m; i++) {
            if (a[i] < x) {
                max = i;
            } else {
                break;
            }
        }
        System.out.println(Math.min(max + 1, m - (max + 1)));
    }

}

Measured memory_bytes: 21844
S=input().rstrip()
S=S[::-1]
T=["dream","dreamer","erase","eraser"]
for i in range(len(T)):
  T[i]=T[i][::-1]
while len(S):
  flag=False
  for t in T:
    if S.startswith(t):
      S=S[len(t):]
      flag=True
  if not flag: break
if len(S)==0:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

vector<P> g[334];
vector<int> f[334];
ll dist[334][334],ans[334][334];
priority_queue<P, vector<P>, greater<P> > pq;
queue<int> que;

int main(void){
	int n,m,i,j,k,a,b,q,s,t;
	ll l,c;
	fill(dist[0],dist[334],INFLL);
	fill(ans[0],ans[334],INFLL);
	cin >> n >> m >> l;
	for(i=0; i<m; ++i){
		cin >> a >> b >> c; --a; --b;
		g[a].push_back(P(c,b));
		g[b].push_back(P(c,a));
	}
	for(s=0; s<n; ++s){
		dist[s][s] = 0ll;
		pq.push(P(dist[s][s],s));
		while(!pq.empty()){
			a = pq.top().second;
			c = pq.top().first;
			pq.pop();
			if(dist[s][a] < c){
				continue;
			}
			for(i=(g[a].l_ength()-1); i>=0; --i){
				b = g[a][i].second;
				c = g[a][i].first;
				if(dist[s][b]>dist[s][a]+c){
					dist[s][b] = dist[s][a] + c;
					pq.push(P(dist[s][b],b));
				}
			}
		}
	}
	for(i=0; i<n; ++i){
		for(j=0; j<i; ++j){
			if(dist[i][j]>l){
				continue;
			}
			f[i].push_back(j);
			f[j].push_back(i);
		}
	}
	for(s=0; s<n; ++s){
		ans[s][s] = 0ll;
		que.push(s);
		while(!que.empty()){
			a = que.front();
			que.pop();
			for(i=(f[a].l_ength()-1); i>=0; --i){
				b = f[a][i];
				if(ans[s][b] > ans[s][a]+1){
					ans[s][b] = ans[s][a]+1;
					que.push(b);
				}
			}
		}
	}
	cin >> q;
	for(i=0; i<q; ++i){
		cin >> s >> t; --s; --t;
		cout << (ans[s][t]%INFLL-1) << endl;
	}
	return 0;
}


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

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

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

  vi h(N, 0);
  vvi edge(N, vi());
  REP(i, M) {
    IN(from); IN(to);
    --from; --to;
    edge[from].push_back(to);
    ++h[to];
  }

  // トポロジカルソート
  stack<int> st;
  REP(i, N) if (h[i] == 0) st.push(i);

  vi sorted;
  while (!st.empty()) {
    int p = st.top(); st.pop();
    sorted.push_back(p);
    for (const auto& to : edge[p]) {
      --h[to];
      if (h[to] == 0)
        st.push(to);
    }
  }

  vi dp(N, 0);
  REP(i, N) {
    int from = sorted[i];
    for (const auto& to : edge[from]) {
      dp[to] = max(dp[from] + 1, dp[to]);
    }
  }
  int ans = 0;
  REP(i, N) {
    ans = max(ans, dp[i]);
  }
  OUT(ans);

  return 0;
}


Measured memory_bytes: 7032
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,x,t,k,sum;
	cin>>n>>x>>t;


	if(n%x==0)
	{
		cout<<t*(n/x)<<endl;
	}
	else
		cout<<t*((n/x) +1)<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000007;
const int mod=1000000007;
const int max_n=100000;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
int main(){
  ll a,b,c,k;cin>>a>>b>>c>>k;
  ll ans=a-b;
  if(k%2==1)ans*=-1;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))

a = cino()
x,y = 1,1
for _ in range(a):
    p,q = cin()
    k = max((x+p-1)//p,(y+q-1)//q)
    x,y = k*p,k*q
print(x+y)
    


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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,a,b;
    cin>>n>>a>>b;
    if(a == 0){
        cout << 0 << endl;
        return 0;
    }
    ll num = n/(a+b);
    ll num2 = n%(a+b);
    cout << num*a + min(num2,a) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, N, a, b) for(int i = a; i < N; i += b)
typedef long long ll;

int main(){
	int N, M;
	cin >> N;

	map<string, int> str;
	rep(i, N){
		string tmp;
		cin >> tmp;
		if (str.count(tmp)) str[tmp]++;
		else str[tmp] = 1;
	}
	cin >> M;
	rep(i, M){
		string tmp;
		cin >> tmp;
		if (str.count(tmp)) str[tmp]--;
		// if (str[tmp] < 0) str[tmp] = 0;
	}
	int ans = 0;
	for (auto p: str) ans = max(p.second, ans);
	cout << ans << endl;
}

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

int main(){
  long long int N, K, Q;
  cin >> N >> K >> Q;
  vector<long long int> scores(N,0);
  
  int A;
  for(int i = 0; i < Q; i++){
	cin >> A;
    scores[A -1] ++; //正解数
    
  }
  
  long long int score = 0;
  for(int i = 0 ; i < N;i++){
    score = K - (Q - scores[i]);
    if(score < 1){cout << "No" << endl;}
    else{cout << "Yes" << endl;}
  }
  
  return 0;
}

Measured memory_bytes: 1408
s = input()
t = input()

dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = dp[i][j] + 1
        else:
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])

ans = ""
i = len(s)
j = len(t)
while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += s[i-1]
        i -= 1
        j -= 1
print(ans[::-1])

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	string S;
	int K;
	cin >> N >> S >> K;
	rep(i, 0, N)
	{
		if (S[i] != S[K - 1])
		{
			S[i] = '*';
		}
	}

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MMOD 998244353
#define MAX 2010101
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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(){
  ll N;
  cin>>N;
  Graph G(N);
  REP(i,N-1){
    ll A,B;
    cin>>A>>B;
    A--,B--;
    G[A].PB(B);
    G[B].PB(A);
  }
  
  priority_queue<pair<ll,ll>> P;
  ll ANS[N];
  REP(i,N) ANS[i]=-1;
  
  ll K;
  cin>>K;
  REP(i,K){
    ll X,Y;
    cin>>X>>Y;
    ANS[X-1]=Y;
    P.push(MP(-Y,X-1));
  }
  
  while(!P.empty()){
    ll cur=P.top().second;
    P.pop();
    
    FORE(e,G[cur]){
      if(ANS[e]==-1){
        ANS[e]=ANS[cur]+1;
        P.push(MP(-ANS[e],e));
      }
      else{
        if(abs(ANS[e]-ANS[cur])!=1){
          cout<<"No"<<endl;
          return 0;
        }
      }
    }
  }
  
  cout<<"Yes"<<endl;
  REP(i,N) cout<<ANS[i]<<endl;
  return 0;
}

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

using namespace std;

using int64 = long long;

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector< int > Y[200000];
  for(int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    Y[x].push_back(y);
  }
  int ret = H;
  for(int i = 1; i < H; i++) {
    sort(begin(Y[i]), end(Y[i]));
  }
  vector< int > correct(H);
  for(int i = 1; i < H; i++) {
    correct[i] = correct[i - 1];
    if(!binary_search(begin(Y[i]), end(Y[i]), correct[i] + 1)) {
      ++correct[i];
    }
  }
  for(int i = 1; i < H; i++) {
    for(auto &p : Y[i]) {
      if(correct[i - 1] >= p) {
        ret = min(ret, i);
      }
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 11904
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();

    let mut stack = vec![];

    for c in s.chars() {
        if c == 'S' {
            stack.push(c);
        } else {
            if stack.last() == None || stack.last() == Some(&'T') {
                stack.push('T');
            } else if stack.last() == Some(&'S') {
                stack.pop();
            }
        }
    }

    println!("{}", stack.len());
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

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

   string s;
   cin >> s;
   rep(i, 0, 3) { cout << s[i]; }
   cout << endl;
   return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T & a, const T & b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7;

template <std::int_fast64_t Modulus>
class modint
{
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept
	{
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept
	{
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept
	{
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept
	{
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept
	{
		a += rhs.a;
		if (a >= Modulus)
		{
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept
	{
		if (a < rhs.a)
		{
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept
	{
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept
	{
		u64 exp = Modulus - 2;
		while (exp)
		{
			if (exp % 2)
			{
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
typedef modint<MOD> ModInt;

ModInt mod_pow(ModInt x, ModInt n) {
	ModInt ret = 1;
	while (n.a > 0) {
		if (n.a & 1) (ret *= x);
		(x *= x);
		n.a >>= 1;
	}
	return ret;
}

ModInt dp[100001][2];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	string L;
	cin >> L;
	lint l = SZ(L);
	fill((long long*)dp, (long long*)dp + sizeof(dp) / sizeof(long long), 0);

	dp[0][0] = 1;
	REP(i, l) {
		int D = L[i] - '0';
		REP(j, 2) {
			REP(d, (j ? 2 : D + 1)) {
				if (d == 1) {
					dp[i + 1][j] += dp[i][j] * 2;
				}
				else {
					if (D == 1 && j == 0) dp[i + 1][1] += dp[i][0];
					else dp[i + 1][j] += dp[i][j];
				}
			}
		}
	}
	cout << (dp[l][0] + dp[l][1]).a << endl;
}


Measured memory_bytes: 2000
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(M)]

MIN = [LR[i][0] for i in range(M)]
MAX = [LR[i][1] for i in range(M)]

if min(MAX) >= max(MIN):
    print(min(MAX) - max(MIN) + 1)
else:
    print(0)

Measured memory_bytes: 29032
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, m;
    cin >> n >> m;
    map<int,int> v;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        v[a]++, v[b]++;
    }
    for (auto &&i : v) {
        if(i.second % 2){
            puts("NO");
            return 0;
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 4352