akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<vector<int> > G(N);
	for (int i = 0; i < N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int M;
	cin >> M;
	vector<int> p(M), q(M);
	for (int i = 0; i < M; ++i) {
		cin >> p[i] >> q[i];
		--p[i], --q[i];
	}
	vector<int> par(N), depth(N);
	function<void(int, int)> make_order = [&](int pos, int pre) {
		par[pos] = pre;
		for (int i : G[pos]) {
			if (i == pre) continue;
			depth[i] = depth[pos] + 1;
			make_order(i, pos);
		}
	};
	make_order(0, -1);
	vector<long long> A(1 << M);
	for (int i = 0; i < M; ++i) {
		long long x = 0;
		while (p[i] != q[i]) {
			if (depth[p[i]] < depth[q[i]]) {
				swap(p[i], q[i]);
			}
			x |= 1LL << (p[i] - 1);
			p[i] = par[p[i]];
		}
		for (int j = 1 << i; j < 2 << i; ++j) {
			A[j] = A[j - (1 << i)] | x;
		}
	}
	long long ans = 0;
	for (int i = 0; i < 1 << M; ++i) {
		long long mul = 1LL << (N - 1 - __builtin_popcountll(A[i]));
		if (__builtin_popcount(i) & 1) ans -= mul;
		else ans += mul;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; ++i){
    int p, q, c = 0;
    bool f = false;
    cin >> p >> q;
    for(int i = 0; i*i < 20000; ++i){
      if(f) break;
      for(int j = 0; i*i + j*j < 20000; ++j){
	if(i == 0 && j == 0) continue;
	int d = i*i + j*j;
	if((!((i*p + j*q)%d)) && (!((i*q - j*p)%d))){
	  //	  cout << i << " " << j << endl;
	  ++c;
	}
	if((!((-i*p + j*q)%d)) && (!((-i*q - j*p)%d))){
	  ++c;
	}
	if(c > 8){
	  cout << "C" << endl;
	  f = true;
	  break;
	}
      }
    }
    if(!f){
      cout << "P" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2944
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N = int(readline())
    A = list(map(int, readline().split()))

    def judge():
        for x in A:
            if x % 2 == 0:
                if (x % 3 != 0) and (x % 5 != 0):
                    return False
        return True

    if judge():
        print("APPROVED")
    else:
        print("DENIED")


if __name__ == '__main__':
    main()


Measured memory_bytes: 62004
#include <iostream>

using namespace std;

int main(){
    string s;
    cin >> s;

    int start, end;
    bool flag_a = false;

    for(int i=0; i < s.size(); i++){
        if(s[i] == 'A' && flag_a == false){
            start = i;
            flag_a = true;
        } else if(s[i] == 'Z') end = i;
    }

    cout << end - start + 1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

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

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

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


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

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

   vector<int> a(N + 1), b(N + 1, 0);
   rep(i, 1, N + 1) cin >> a.at(i);

   for (int i = N; i >= 1; i--) {
     int cnt = 0;
     if (N / i == 1) b.at(i) = a.at(i);
     else {
       for (int j = 2; j <= N / i; j++) cnt += b.at(j * i);
       b.at(i) = cnt % 2 == a.at(i) ? 0 : 1;
     }
   }

   vector<int> ans;
   rep(i, 1, N + 1) {
     if (b.at(i)) ans.push_back(i);
   }

   cout << ans.size() << endl;

   if (ans.size() > 0) {
     rep(i, 0, ans.size() - 1) cout << ans.at(i) << " ";
     cout << ans.at(ans.size() - 1) << endl;
   }
 }


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

using namespace std;

void dfs(long long s, long long p, vector<long long>* adj, bool* visited, pair<long long, long long>* numberOfWays) {

	if (visited[s]) {
		return;
	}

	visited[s] = true;	

	vector< pair<long long, long long> > childWays;
	for (long long i = 0; i < adj[s].size(); i++) {
		if (adj[s][i] != p) {
			dfs(adj[s][i], s, adj, visited, numberOfWays);
			childWays.push_back(numberOfWays[adj[s][i]]);
		}
	}

	if (childWays.empty()) {
		numberOfWays[s] = make_pair(1, 1);
		return;
	}

	long long blackCount = 1;
	long long whiteCount = 1;
	for (long long i = 0; i < childWays.size(); i++) {
		blackCount *= childWays[i].second;
		whiteCount *= (childWays[i].second + childWays[i].first);
		blackCount %= 1000000007;
		whiteCount %= 1000000007;
	}
	numberOfWays[s] = make_pair(blackCount, whiteCount);
	return;

}

int main() {

	long long n;
	cin >> n;

	vector<long long> adj[n];
	for (long long i = 0; i < n-1; i++) {
		long long a, b;
		cin >> a >> b;
		a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	bool visited[n] = {0};
	pair<long long, long long> numberOfWays[n];

	dfs(0, -1, adj, visited, numberOfWays);

	// cout << "-----------" << endl;

	// for (long long i = 0; i < n; i++) {
	// 	cout << numberOfWays[i].first << " " << numberOfWays[i].second << endl;
	// }

	cout << (numberOfWays[0].first + numberOfWays[0].second) % 1000000007 << endl;

}

Measured memory_bytes: 17152
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<int(n);(i)++)
typedef pair<char,int> pci;

int main()
{
  int n;
  while(1){
    cin >> n;
    if(n == 0) break;
    int v[26] = {};
    int lv = n;
    bool flag = true;
    REP(i,n){
      char c;
      cin >> c;
      if(flag){
        v[c-'A']++;
        int *mp = max_element(v,v+26);
        lv--;
        flag = false;
        REP(j,26){
          if(v+j == mp) continue;
          if(lv+v[j] >= *mp){
            flag = true;
            break;
          }
        }
        if(!flag) cout << (char)(mp-v+'A') << " " << i+1 << endl; 
      }
    }
    if(flag) cout << "TIE" << endl;
  }
}

Measured memory_bytes: 3076
N = int(input())
low = 0
high = N - 1
t = (low + high) // 2
flag = 0
print(0)
resl = input()
print(N-1)
resr = input()
if resl == "Vacant" or resr == "Vacant":
    flag = 1

while(flag == 0):
    print(t)
    inp = input()
    if inp == "Vacant":
        break
    if (high-t) % 2 == 0 and inp != resr:
        low = t
        resl = inp
    elif (high-t) % 2 == 1 and inp == resr:
        low = t
        resl = inp
    elif (t-low) % 2 == 0 and inp != resl:
        high = t
        resr = inp
    else:
        high = t
        resr = inp
    t = (low + high) // 2



Measured memory_bytes: 38976
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int main (){

	int arr[1000000];
	int N=1000000;

		for(int i = 0; i < N; i++){
			arr[i] = 1;
		}
		for(int i = 2; i < sqrt(N); i++){
			if(arr[i]){
				for(int j = 0; i * (j + 2) < N; j++){
					arr[i *(j + 2)] = 0;
				}
			}
		}
	
	while(1){
		int n,a=0;
		cin >> n;
		if(n==0)
			break;

		
		for(int i = 2,j=0; j < n; i++){
			if(arr[i]){
				a+=i;
				j++;
			}
		}

		cout << a << endl;
	}
}

Measured memory_bytes: 5064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

//辺を表す構造体{行先、容量、コスト、逆辺}
struct edge { int to, cap, cost, rev; };
int V, E, F;
vector<edge>G[110];
int dist[110];
int prevv[110], preve[110];

void add_edge(int from, int to, int cap, int cost) {
	G[from].push_back(edge{ to, cap, cost, (int)G[to].size() });
	G[to].push_back(edge{ from,0,-cost,(int)G[from].size() - 1 });
}
//sからtへの流用fの最小費用流を求める
//流せない場合は-1を返す
int min_cost_flow(int s, int t, int f) {
	int res = 0;
	//ベルマンフォードによりs-t間最短路を求める
	while (f > 0) {
		fill(dist, dist + V, INF);
		dist[s] = 0;
		bool upgrade = true;
		while (upgrade) {
			upgrade = false;
			for (int v = 0; v < V; ++v) {
				if (dist[v] == INF)continue;
				for (int i = 0; i < G[v].size(); ++i) {
					edge &e = G[v][i];
					if (e.cap > 0 && dist[e.to] > dist[v] + e.cost) {
						dist[e.to] = dist[v] + e.cost;
						prevv[e.to] = v;
						preve[e.to] = i;
						upgrade = true;
					}
				}
			}
		}
		if (dist[t] == INF) {
			return -1;
		}
		int d = f;
		for (int v = t; v != s; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * dist[t];
		for (int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int main() {
	cin >> V >> E >> F;
	REP(i, E) {
		int from, to, cap, cost;
		cin >> from >> to >> cap >> cost;
		add_edge(from, to, cap, cost);
	}
	cout << min_cost_flow(0,V-1,F) << endl;
	return 0;
}


Measured memory_bytes: 3204
#!/usr/bin/env python3

def main():
    *N, = map(int, open(0).read().split())
    A = N[1:]
    N = N[0]

    s = 1
    for i in range(0, N):
        s = s * A[i]
    S = 0
    for i in range(0, N):
        S += s / A[i]
    
    print(s/S)


main()

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s=="abc"){
           cout<<"Yes"<<endl;
    }
    else if(s=="bac"){
           cout<<"Yes"<<endl;
    }
    else if(s=="acb"){
          cout<<"Yes"<<endl;
    }

    else if(s=="cab"){
           cout<<"Yes"<<endl;
    }
    else if(s=="cba"){
      cout<<"Yes"<<endl;
    }
    else if(s=="bca"){
      cout<<"Yes"<<endl;
    }

   else{
    cout<<"No"<<endl;
   }
    return 0;
}



Measured memory_bytes: 256
def is_prime(x):
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            return False
            break
    return True

n = int(input())
x = 11
ans = []
while(True):
    if is_prime(x) and x % 5 == 1:
        ans.append(x)
        if len(ans) == n:
            break
    x += 2
print(*ans)


Measured memory_bytes: 3060
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	int a,b,h; cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
	return 0;
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vl p(A), q(B), r(C);
    rep(i,A) cin >> p[i];
    rep(i,B) cin >> q[i];
    rep(i,C) cin >> r[i];

    vector<pll> abc;
    rep(i,A) abc.emplace_back(p[i], 1);
    rep(i,B) abc.emplace_back(q[i], 2);
    rep(i,C) abc.emplace_back(r[i], 3);
    sort(all(abc));

    vl ansX, ansY, bufC;
    rrep(i,abc.size()){
        ll t = abc[i].fi, c = abc[i].se;
        if(c == 1 && ansX.size() < X) ansX.push_back(t);
        else if(c == 2 && ansY.size() < Y) ansY.push_back(t);
        else if(c == 3){
            bufC.push_back(t);
        }
        if(ansX.size() + ansY.size() + bufC.size() == X + Y) break;
    }
    ll ans = 0;
    rep(i,ansX.size()) ans += ansX[i];
    rep(i,ansY.size()) ans += ansY[i];
    rep(i,bufC.size()) ans += bufC[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12780
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
#define MOD 1000000007;
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
long long LCM(long long A,long long B){
  long long g=GCD(A,B);
  return A/g*B;
}
long long num_order(long long X){
  long long ans=0;
  while(true){
    if(X==0){
      break;
    }
    else{
      X/=10;
      ans++;
    }
  }
  return ans;
}
int main() {
  
  long long N;
  cin>>N;
  
  
  for(int i=1;i<=3500;i++){
    for(int j=1;j<=3500;j++){
      long long x=N*i*j;
      long long y=4*i*j-i*N-j*N;
      if(y!=0&&x%y==0&&x/y>0){
        cout<<i<<" "<<j<<" "<<x/y;
        return 0;
      }
    }
  }
}

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

int main(){
   std::string S;
   std::cin >> S;
   int s, e;
   for (int i=0; i<S.size(); i++){
      if (S.at(i) == 'A'){
         s = i;
         break;
      }
   }
   for (int i=S.size()-1; i>=0; i--){
      if (S.at(i) == 'Z'){
         e = i;
         break;
      }
   }
   std::cout << e-s+1 << std::endl;
}



Measured memory_bytes: 640
S = input()
N = len(S) + 1
Ans = [0]
a = 0
for c in S:
    if c=="<":
        a += 1
    else:
        a = 0
    Ans.append(a)

a = 0
for c, i in zip(S[::-1], range(N-2, -1, -1)):
    if c==">":
        a += 1
    else:
        a = 0
    Ans[i] = max(Ans[i], a)

print(sum(Ans))


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

using namespace std;
long long MOD = 1000000007;
const int MAX = 200001;
long long fac[MAX];
long long finv[MAX];
long long inv[MAX];

void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    int H;
    int W;
    int A;
    int B;
    cin >> H >> W >> A >> B;

    comb_init();
    long long ans = 0;
    for(int i = 0; i < H - A; i++){
        ans = (ans + (comb(i + B - 1, i) * comb(W - B + H - i - 2, W - B - 1)) % MOD) % MOD;
    }

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


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

        internal class Solution
        {
            string row;
            int temp;
            int best_score = 10000;
            public void Run()
            {
                row = Input.ReadString();
                for(int i = 0; i <= row.Length-3; i++)
                {
                    temp= Math.Abs(753 -(int.Parse(string.Format("{0}{1}{2}", row[i], row[i + 1], row[i + 2]))));
                if (best_score > temp) { best_score = temp; }
                }
                Console.WriteLine(best_score);
            }
        }

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


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

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

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

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

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

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

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

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

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long llint;
const llint MOD = 1e9 + 7;
int main() {
    llint N;
    cin >> N;
    vector<llint> b(N - 1), a(N);
    for(auto& e: b) {
        cin >> e;
    }
    a[0] = b[0];
    for(int i = 1; i < N - 1; i++) {
        a[i] = min(b[i - 1], b[i]);
    }
    a[N - 1] = b.back();
    llint sum = 0;
    for(auto e: a) {
        sum += e;
    }
    cout << sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
// #include <vector>
#define rep(i,n) for(int i = 0 ; i < (n); ++i)
using namespace std;
using ll = long long;
// using P = pair<int,int>;
const int mod = 1000000007;
int main(){
  ll n;
  cin >> n;
  ll a[n];
  rep(i,n) cin >> a[i];
  ll ans = 0;
  ll x=0;
  rep(i,n){
    ans = (ans + a[i]*x)%mod;
    x = ( x + a[i]) % mod;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    string S;
    string T;

    cin >> S >> T;

    vector<string> ress = {};

    bool flg = false;
    for (int i = 0; i < S.size(); i++) {
        if (i + T.size() > S.size()) break;

        string S2 = S;
        bool is_match = true;
        for (int j = 0; j < T.size(); j++) {
            if (S.at(i + j) == T.at(j) || S.at(i + j) == '?') {
                S2.at(i + j) = T.at(j);
            } else {
                is_match = false;
                break;
            }
        }
        if (is_match) {
            for (int i = 0; i < S.size(); i++) {
                if (S2.at(i) == '?') S2.at(i) = 'a';
            }
            ress.push_back(S2);
        }
    }
    if (ress.size() == 0) {
        cout << "UNRESTORABLE" << endl;
    } else {
        sort(ress.begin(), ress.end());
        cout << ress[0] << endl;
    }
}

Measured memory_bytes: 3624
n, m, q = map(int, input().split())
req = [list(map(int, input().split())) for i in range(q)]
  
lst = []

if n == 2:
  for a in range(1,m+1):
    for b in range(a, m+1):
      lst.append([a, b])
    
if n == 3:
  for a in range(1,m+1):
    for b in range(a, m+1):
      for c in range(b, m+1):
        lst.append([a, b, c])

if n == 4:
  for a in range(1,m+1):
    for b in range(a, m+1):
      for c in range(b, m+1):
        for d in range(c, m+1):
          lst.append([a, b, c, d])                      

if n == 5:
  for a in range(1,m+1):
    for b in range(a, m+1):
      for c in range(b, m+1):
        for d in range(c, m+1):
          for e in range(d, m+1):
            lst.append([a, b, c, d, e])

if n == 6:
  for a in range(1,m+1):
    for b in range(a, m+1):
      for c in range(b, m+1):
        for d in range(c, m+1):
          for e in range(d, m+1):
            for f in range(e, m+1):
              lst.append([a, b, c, d, e, f])
                      
if n == 7:
  for a in range(1,m+1):
    for b in range(a, m+1):
      for c in range(b, m+1):
        for d in range(c, m+1):
          for e in range(d, m+1):
            for f in range(e, m+1):
              for g in range(f, m+1):      
                lst.append([a, b, c, d, e, f, g])
                      
if n == 8:
  for a in range(1,m+1):
    for b in range(a, m+1):
      for c in range(b, m+1):
        for d in range(c, m+1):
          for e in range(d, m+1):
            for f in range(e, m+1):
              for g in range(f, m+1):
                for h in range(g, m+1):
                  lst.append([a, b, c, d, e, f, g, h])
                      
if n == 9:
  for a in range(1,m+1):
    for b in range(a, m+1):
      for c in range(b, m+1):
        for d in range(c, m+1):
          for e in range(d, m+1):
            for f in range(e, m+1):
              for g in range(f, m+1):
                for h in range(g, m+1):
                  for i in range(h, m+1):
                    lst.append([a, b, c, d, e, f, g, h, i])
                      
if n == 10:
  for a in range(1,m+1):
    for b in range(a, m+1):
      for c in range(b, m+1):
        for d in range(c, m+1):
          for e in range(d, m+1):
            for f in range(e, m+1):
              for g in range(f, m+1):
                for h in range(g, m+1):
                  for i in range(h, m+1):
                    for j in range(i, m+1):
                      lst.append([a, b, c, d, e, f, g, h, i, j])
        
ans = 0        
for i in range(len(lst)):
  res = 0
  for j in range(q):
    if lst[i][req[j][1]-1] - lst[i][req[j][0]-1] == req[j][2]:
      res += req[j][3]
  ans = max(ans, res)

print(ans)
              

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

typedef uint32_t u32;
typedef uint64_t u64;

int stationid(char c) {
  if( 'A' <= c and c <= 'Z' ) return c - 'A';
  return c - 'a' + 26;
}

int main() {

  std::string table;
  for(char c = 'A'; c <= 'Z'; ++c) table += c;
  for(char c = 'a'; c <= 'z'; ++c) table += c;

  for(;;) {
    int n;
    std::cin >> n;
    if( n == 0 ) break;
    std::vector<int> k(n);
    std::string str;
    for(int& I : k) std::cin >> I;
    std::cin >> str;
    for(int i = 0; i < (int)str.size(); ++i) {
      std::cout << table[(stationid(str[i]) + 52 - k[i % n]) % 52];
    }
    std::cout << std::endl;
  }  
  
  return 0;
}

Measured memory_bytes: 3224
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc =new Scanner(System.in);
        int n=sc.nextInt();
        int min=sc.nextInt();
        int max=min;
        long sum=min;
        n--;
        while(n>0){
            int tmp=sc.nextInt();
            if(min>tmp)min=tmp;
            if(max<tmp)max=tmp;
            sum+=tmp;
            n--;
        }
        System.out.println(min+" "+max+" "+sum);
    }
}


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

using ll = long long;
using pll = pair<ll, ll>;

template<typename Monoid>
class segment_tree {
    using T = typename Monoid::type;

public:
    segment_tree(std::vector<T> const& init)
        : sz(init.size()), n(expand(init.size()))
    {
        dat.assign(n*2, Monoid::id());
        std::copy(begin(init), end(init), begin(dat) + n);
        for(int i = n - 1; i >= 0; --i) {
            dat[i] = Monoid::op(dat[i * 2], dat[i * 2 + 1]);
        }
    }

    segment_tree(int const n_, T const& init = Monoid::id())
        : segment_tree(std::vector<T>(n_, init))
    {}

    void update(int p, T val) {
        assert(0 <= p && p < sz);
        dat[p += n] = val;
        while(p /= 2) {
            dat[p] = Monoid::op(dat[p * 2], dat[p * 2 + 1]);
        }
    }

    // [l, r)
    T query(int l, int r) const {
        assert(0 <= l && l <= r && r <= sz);
        l += n, r += n;
        T res1 = Monoid::id(), res2 = Monoid::id();
        while(l != r) {
            if(l & 1) res1 = Monoid::op(res1, dat[l++]);
            if(r & 1) res2 = Monoid::op(dat[--r], res2);
            l /= 2, r /= 2;
        }
        return Monoid::op(res1, res2);
    }

private:
    int expand(int n_) const {
        assert(n_ >= 1);
        return n_ == 1 ? n_ : expand((n_ + 1) / 2) * 2;
    }

private:
    const int sz, n;
    std::vector<T> dat;
};

struct LIS {
    using type = pll;
    static type id() {
        return make_pair(0, 0);
    }
    static type op(type const& l, type const& r) {
        return max(l, r);
    }
};

int main() {
    int n; cin >> n;
    vector<int> a(n), as;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        as.push_back(a[i]);
    }
    sort(begin(as), end(as));
    as.erase(unique(begin(as), end(as)), end(as));
    for(int i = 0; i < n; ++i) {
        a[i] = lower_bound(begin(as), end(as), a[i]) - begin(as);
    }

    segment_tree<LIS> seg(n);
    for(int i = 0; i < n; ++i) {
        auto ma = seg.query(0, a[i]);
        ma.first += 1;
        ma.second += as[a[i]];
        if(seg.query(a[i], a[i] + 1) < ma) {
            seg.update(a[i], ma);
        }
    }

    cout << seg.query(0, n).second << endl;
}


Measured memory_bytes: 9332
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

const ll MAX_V = 100000;
struct edge {long long to, cap, rev; };  // 行き先、容量、逆辺

vector<edge> G[MAX_V];  // 隣接リスト
bool used[MAX_V];  // すでに訪問済みかのフラグ

// fromからtoへの容量capの辺をグラフに追加する
void add_edge(long long from, long long to, long long cap) {
    G[from].push_back((edge){to, cap, (ll)G[to].size()});
    G[to].push_back((edge){from, 0, (ll)(G[from].size()-1)});
}

// DFSで増加パスを探索
long long dfs(long long v, long long t, long long f) {
    if (v == t) return f;
    used[v] = true;
    for (int i=0; i<G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            long long d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

// sからtへの最大流を求める
long long max_flow(long long s, long long t) {
    long long flow = 0;
    for (;;) {
        REP(i, MAX_V) used[i] = false;
        long long f = dfs(s, t, HIGHINF);
        if (f == 0) return flow;
        flow += f;
    }
}

int n, m;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    V<int> ec(n, 0);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        add_edge(a, b, 1);
        add_edge(b, a, 1);
        ec[a]++, ec[b]++;
    }

    int c6 = 0, c4 = 0;
    V<int> c4nodes;
    bool is_euler = true;
    for (int i = 0; i < n; i++) {
        if (ec[i] & 1) {
            is_euler = false;
            break;
        } else if (ec[i] == 4) c4++, c4nodes.emplace_back(i);
        else if (ec[i] >= 6) c6++;
    }

    if (!is_euler) cout << "No\n";
    else if (c6 > 0) cout << "Yes\n";
    else if (c4 > 2) cout << "Yes\n";
    else if (c4 == 2) {
        // 最小カットが 2 -> Yes
        int start = c4nodes[0], end = c4nodes[1];
        ll mf = max_flow(start, end);
        if (mf == 2) cout << "Yes\n";
        else cout << "No\n";
    } else cout << "No\n";
    return 0;
}


Measured memory_bytes: 16768
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = 2e9;
const int MAX_N = 1;

int main() {
  int A, B; cin >> A >> B;
  if (A <= 8 && B <= 8) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long check(vector <long long> &tmp){
    //for(int i=0;i<tmp.size();i++)
   // cout<<tmp[i];
    if(tmp[0]>=0) return abs(tmp[tmp.size()-1]);
    if(tmp[tmp.size()-1]<=0) return abs(tmp[0]);
    if(abs(tmp[tmp.size()-1])<=abs(tmp[0]))
    return abs(2*tmp[tmp.size()-1])+abs(tmp[0]);
    else   return abs(tmp[tmp.size()-1])+2*abs(tmp[0]);
}

int main(void){
    int n,k; cin>>n>>k;
    long long ans=9999999999999;
    vector <int> c(n);
    vector <long long> tmp(k);
    for(int i=0;i<n;i++) cin>>c[i];
    
    for(int i=0;i<=n-k;i++){
        for(int j=0;j<k;j++){
            tmp[j]=c[i+j];
        }
        long long x=check(tmp);
        //cout<<x<<endl;
       if(ans>x) ans=x;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int ans = a * b;
    if(ans % 2 == 0) {
      System.out.println("Even");
    } else {
      System.out.println("Odd");
    }
    scanner.close();

  }
}



Measured memory_bytes: 21972
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
    int N;
    int maxV[] = {0, 0};
    vector<int> A;
    cin >> N;
    for (int i=1; i<N+1; i++) {
        int a;
        cin >> a;
        if (a == maxV[0]) {
            maxV[1] = a;
        } else if (a == maxV[1]) {
            maxV[1] = a;
        } else if (a > maxV[0]) {
            maxV[1] = maxV[0];
            maxV[0] = a;
        } else if (a > maxV[1]) {
            maxV[1] = a;
        }
        A.push_back(a);
    }

    for (int i=0; i<N; i++) {
        if (A[i] == maxV[0]) {
            cout << maxV[1] << endl;
        } else {
            cout << maxV[0] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2548
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a==2&&b==1||a==1&&b==2)
    cout<<3;
  if(a==2&&b==3||a==3&&b==2)
    cout<<1;
  if(a==3&&b==1||a==1&&b==3)
    cout<<2;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _cin      ios_base::sync_with_stdio(0);  cin.tie(0);
#define READ      freopen("input.txt", "r", stdin);
#define WRITE     freopen("output.txt", "w", stdout);
#define endl "\n"
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<ll> >
#define vll vector<ll>
#define mint map<ll,ll>
#define sz(x) (ll)x.size()
#define sll set<ll>
#define pll pair<ll,ll>
#define F first
#define S second
const ll MAX = 1000004;
const ll INF = 1e18L + 5;

int main() {

	_cin
	// READ
	// WRITE
	ll n, W;
	cin >> n >> W;
	ll s_v = 0;
	ll w[n], v[n];
	rep(i, 0, n) {
		cin >> w[i] >> v[i];
		s_v += v[i];
	}
	vll dp(s_v + 1, INF);
	dp[0] = 0;
	// dp[i]--min weight having value i
	rep(i, 0, n) {
		repd(j, s_v, 0) {
			if (v[i] <= j)
				dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
		}
	}
	ll ans = 0;
	rep(i, 0, s_v + 1) {
		if (dp[i] <= W) {
			ans = max(ans, i);
		}
	}
	cout << ans << endl;





}

Measured memory_bytes: 3992
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
#define pb push_back
#define endl '\n'
bool cmp(char a, char b){
	return a<b;
}
ll solve(){
	ll n,d;
	cin>>n>>d;
	ll cnt=0;
	double x,y;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		if(sqrt(x*x+y*y)<=d) cnt++;
	}
	cout<<cnt;
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3860
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int cnt = 0;
		for(int i=0; i < 3; i++) {
			if(S.charAt(i)=='R') {
				if(i==2&&S.charAt(1)=='S'){
                  cnt=0;
                }
				  cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 35560
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sa = [0 for i in range(n+1)]
sb = [0 for i in range(m+1)]

c = 0

for i in range(n):
  c += a[i]
  sa[i+1] = c
c = 0
for i in range(m):
  c += b[i]
  sb[i+1] = c
ans = 0
# if k >= sum(a)+sum(b):
#   print (n+m)
#   exit()
for i in range(n+1):
  x = k - sa[i]
  if x < 0:
    continue
  y = bisect.bisect_right(sb,x)
  y += i
  ans = max(ans, y-1)
print (ans)

Measured memory_bytes: 47560
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>	
#define inf INT_MAX
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(int *)a-*(int *)b;
}

int main(void){
	int n=in(),a[100],i;
	rep(i,n){
		a[i]=in();
	}
	qsort(a,n,sizeof(int),cmp);
	print(a[n-1]-a[0]);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <math.h>
using namespace std;
int main(void){
    // Your code here!
    long long int a, n, m, x, count=0, tmp, sum;
    cin >> a >> n >> m;
    
    for(long long int i=1; ;i++){
        x = pow((i+a), n);
        if(x>m) break;
        sum=0;
        tmp=x;
        while(tmp!=0){
            sum+=tmp%10;
            tmp=tmp/10;
        }
        if(sum == i) count++;
   }
   cout << count << endl;
   return 0;
}



Measured memory_bytes: 3260
S = input()

s1 = S[0] + S[1]
s2 = S[2] + S[3]


if (
    int(s1) > 12
    and int(s2) > 12
    or int(s1) == 0
    and int(s2) == 0
    or int(s1) == 0
    and int(s2) > 12
    or int(s1) > 12
    and int(s2) == 0
):
    print("NA")

elif 1 <= int(s1) <= 12 and (int(s2) > 12 or int(s2) == 0):
    print("MMYY")

elif 1 <= int(s2) <= 12 and (int(s1) > 12 or int(s1) == 0):
    print("YYMM")

else:
    print("AMBIGUOUS")

Measured memory_bytes: 3064
import java.util.*;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int alice = 0;
    int bob = 0;
    List<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < N; i++) {
      list.add(sc.nextInt());
    }
    Collections.sort(list, Collections.reverseOrder());
    for (int i = 0; i < N; i++) {
      if (i % 2 == 0) {
        alice += list.get(i);
      } else {
        bob += list.get(i);
      }
    }
    System.out.println(alice - bob);
  }
}


Measured memory_bytes: 21844
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i) { return i / 2;}
int left(int i) { return 2 * i;}
int right(int i) { return 2 * i + 1;}

int main(){
    int H, i, A[MAX+1];

    cin >> H;
    for(i = 1; i <= H; i++) cin >> A[i];

    for(i = 1; i <= H; i++) {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if(parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
        if(left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
        if(right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }

    return 0;
}


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

int main(){
  int N,Y;
  cin >> N >> Y;
  Y/=1000;
  for(int i=0;i<=N;i++){
    for(int j=0;j<=N;j++){
      int tmp = Y-i-j*5;
      if(tmp<0) continue;
      if(tmp%10==0 && (i+j+tmp/10)==N){
        cout << tmp/10 << " " << j << " " << i << endl;
        exit(0);
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 256
S=input().strip()
def solve(S):
    while len(S)>0:
        if S[-6:]=='eraser':
            S=S[:-6]
        elif S[-7:]=='dreamer':
            S=S[:-7]
        elif S[-5:]=='erase':
            S=S[:-5]
        elif S[-5:]=='dream':
            S=S[:-5]
        else:
            return False
    return True

if solve(S):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<long long>;
using vlad=valarray<double>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9

int main(){
    vvi f(10,vi(10,-1)); vi a(2,0);
    range(i,1,9)range(j,1,9){
        char c;cin>>c;
        if(c=='o'){f[i][j]=0;a[0]++;}
        if(c=='x'){f[i][j]=1;a[1]++;}
    }
    int t=0,nt=0;
    while(a[0]+a[1]<64&&a[0]&&a[1]){
        int mx=0,px,py;
        range(i,1,9){
            range(j,1,9){
                int turnable=0, y=t?9-i:i, x=t?9-j:j;
                if(f[y][x]!=-1)continue;
                vi v={1,0,-1,0,1,1,-1,-1,1};
                rep(k,8){
                    int dy=v[k],dx=v[k+1];
                    range(l,1,8){
                        if(f[y+dy*l][x+dx*l]==-1)break;
                        if(f[y+dy*l][x+dx*l]==t){
                            turnable+=l-1;
                            break;
                        }
                    }
                }
                if(mx<turnable){
                    mx=turnable; py=y; px=x;
                }
            }
        }
        if(mx==0){
            nt++;
            if(nt==2){
                break;
            }
        }else{
            nt=0;
            vi v={1,0,-1,0,1,1,-1,-1,1};
            a[t]++;
            rep(k,8){
                int y=py,x=px;
                int dy=v[k],dx=v[k+1];
                range(l,1,8){
                    if(f[y+dy*l][x+dx*l]==-1)break;
                    if(f[y+dy*l][x+dx*l]==t){
                        rep(m,l) f[y+dy*m][x+dx*m]=t;
                        a[t]+=(l-1);
                        a[!t]-=(l-1);
                        break;
                    }
                }
            }
        }
        t=!t;
    }
    range(i,1,9){range(j,1,9)cout<<(".ox"[f[i][j]+1]);cout<<endl;}
	return 0;
}



Measured memory_bytes: 3164
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	private static final boolean TEST = false;

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		do {
			String s = in.next();
			System.out.println(solve(s));
		} while (TEST);
	}

	private static String solve(String s) {
		for (int i = 0; i < s.length(); i++)
			if (i % 2 == 0)
				if (s.charAt(i) == 'L')
					return "No";
				else
					continue;
			else if (s.charAt(i) == 'R')
				return "No";
		return "Yes";
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

priority_queue<ll,vector<ll >,greater<ll > > pq;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll ar[M];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n,k,i,sm = 0;
	cin >> n >> k;
	for(i=1;i<=n;++i)
		cin >> ar[i];
	sort(ar+1,ar+1+n);
	for(i=1;i<=k;++i)
		sm += ar[i];
	cout << sm << "\n";
}

Measured memory_bytes: 3672
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	result := "DENIED"
	evencount := 0
	count := 0
	for i:=0; i<n; i++{
		fmt.Scan(&a[i])
		if a[i] % 2 == 0{
			evencount++
			if (a[i] % 3 ==0 || a[i] % 5 == 0){
				count++
			}
		}
	}

	if evencount == count{
		result = "APPROVED"
	}

	fmt.Println(result)
}

Measured memory_bytes: 1776
#include <algorithm>
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
template <class T> inline void chmax(T &a, T b) { a < b ? a = b : a; };
template <class T> inline void chmin(T &a, T b) { a > b ? a = b : a; };

int main() {
    ll dp[102][100100];
    int n, W;
    cin >> n >> W;
    vi w(n);
    vi v(n);
    rep(i, n) cin >> w[i] >> v[i];
    rep(i, n) rep(j, W) dp[i][j] = 0;
    rep(i, n) {
        REP(j, 1, W + 1) {
            if(j >= w[i]) {
                dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }
    cout << dp[n][W] << endl;
}


Measured memory_bytes: 79744
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

ll dp[101][101];
ll a[101],b[101];

const ll MAX=INT_MAX;
ll dfs(int l,int r){
	if(dp[l][r]!=MAX){
		return dp[l][r];
	}
	if(r-l==1){
		return dp[l][r]=min(dp[l][r],a[l]*b[l]*a[r]*b[r]);
	}else if(r==l){
		return dp[l][r]=0;
	}
	ll best=MAX;
	FOR(i,l,r){
		ll cost=a[l]*b[i]*a[i+1]*b[r];
		best=min(best,dfs(l,i)+dfs(i+1,r)+cost);
	}
	return dp[l][r]=min(dp[l][r],best);
}

int main(){
	int n;
	cin>>n;
		REP(i,n+1)REP(j,n+1){
			dp[i][j]=MAX;
		}

		REP(i,n){
			cin>>a[i]>>b[i];
		}

		cout<<dfs(0,n-1)<<endl;
}

Measured memory_bytes: 0
using System;

class ITP1_3_D {
    public static void Main() {

        string[] Input = Console.ReadLine().Split(' ');

        int a = int.Parse(Input[0]);
        int b = int.Parse(Input[1]);
        int c = int.Parse(Input[2]);
        int count = 0;

        for (; a <= b; a++) {
            if (c % a == 0) count++;
        }

        Console.WriteLine(count);
    }
}

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

int main() {
  int64_t n, m, a, b, r;
  cin >> n >> m;
  a = max(n, m);
  b = min(n, m);
  for(int i = b; i > 0; --i){
    if(a % i == 0 && b % i == 0){
      r = (a / i) * b;
      break;
    }
  }
  cout << r << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,a;
    getline(cin,s);
    int i,j=0;
    for(i=0;s[i];i++)
    {
        if(s[i]=='B' && j>0)
            j--;
        else if(s[i]!='B'){
            a[j]=s[i];
            j++;
        }
    }
    for(i=0;i<j;i++)
        cout<<a[i];
    cout<<endl;
}


Measured memory_bytes: 256
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))

a = list(input().split())
li = ["A","B","C","D","E","F"]



if a[0] > a[1]:
    print(">")
elif a[0] == a[1]:
    print("=")
else:
    print("<")




Measured memory_bytes: 2940