akhauriyash/Code-Regression huggingface dataset:
// C++ program to print all prime factors  
#include <bits/stdc++.h> 
using namespace std; 
  
// A function to print all prime  
// factors of a given number n  
void primeFactors(long long int n)  
{  
    // Print the number of 2s that divide n  
  //  set<long long int> ans;
    map<long long int,int> m;
    while (n % 2 == 0)  
    {  
      //  ans.insert(2);
        m[2]++;
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (long long int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
    //        ans.insert( i);  
            m[i]++;
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2){  
   //     ans.insert( n);
        m[n]++;
    }
        
   // sort(ans,ans+ans.size());
    long long int ans1=0,t=1;
    for(auto i=m.begin();i!=m.end();i++)
    {
        long long int temp,z=1;
        temp= z;
       while(temp<i->second)
       {
           z++;
           temp = z*(z+1)/2;
       }
       if(temp!=i->second)
       z--;
      // cout<<z<<endl;
       ans1+=z;
    }
    cout<<ans1<<endl;
}  
  
/* Driver code */
int main()  
{ 
    long long int n;
    cin>>n;
    primeFactors(n);    
}


Measured memory_bytes: 3600
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
 
int main() {
	ios::sync_with_stdio(false);
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	for (int i=0;i<ty-sy;i++) cout << 'U';
	for (int i=0;i<tx-sx;i++) cout << 'R';
	for (int i=0;i<ty-sy;i++) cout << 'D';
	for (int i=0;i<tx-sx;i++) cout << 'L';  
	cout << 'L';
	for (int i=0;i<ty-sy+1;i++) cout << 'U';
	for (int i=0;i<tx-sx+1;i++) cout << 'R';
	cout << 'D' << 'R';
	for (int i=0;i<ty-sy+1;i++) cout << 'D';
	for (int i=0;i<tx-sx+1;i++) cout << 'L';
	cout << 'U';
}

Measured memory_bytes: 256
N = int(input())
A = MAX = [0]*N
max_1 = max_2 = index = 0
for i in range(N):
  A[i] = int(input())
  if A[i] >= max_1:
    max_2 = max_1
    max_1 = A[i]
  elif A[i] > max_2:
    max_2 = A[i]
for i in range(N):
  if A[i] == max_1:
    print(max_2)
  else:
    print(max_1)

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

n = len(s)
m = len(t)

a = set(list(t))
b = set(list(s))

for x in a:
    if x not in b:
        print(-1)
        exit()

positions = [[0]*26 for i in range(n+1)]

for i in range(n):
    for j in range(26):
        if j == ord(s[-1-i])-97:
            positions[-2-i][j] = n-i
        else:
            positions[-2-i][j] = positions[-1-i][j]

roop = 0
p = 0
for i in range(m):
    a = ord(t[i])-97
    if positions[p][a]==0:
        roop += 1
        p = 0
    p = positions[p][a]

print(roop*n+p)

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

int main(){
	int c[3];
	cin >> c[0] >> c[1] >> c[2];

	int count = 0;
	bool flag = 1;
	
	if(c[0] % 2 != 0 || c[1] % 2 != 0 || c[2] % 2 != 0){
		flag = 0;
		count = 0;
	}


	if(flag == 1){
		while(1){
			int cold[3] = {c[0], c[1], c[2]};
			c[0] = (cold[1] + cold[2]) / 2;
			c[1] = (cold[0] + cold[2]) / 2;
			c[2] = (cold[0] + cold[1]) / 2;
			++count;
			if(c[0] % 2 != 0 || c[1] % 2 != 0 || c[2] % 2 != 0){
				break;
			}else if(c[0] == c[1] && c[1] == c[2]){
				count = -1;
				break;
			}
		}
	}

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        for(int i = 0; i < n; i++){
            A[i] = sc.nextInt();
        }
        int[] count = new int[n];
        int div = 0;
        int check = 0;
        for(int i = 0; i < n; i++){
            check = A[i];
            while(check%2 == 0){
                div++;
                check = check/2;
            }
            count[i] = div;
            div = 0;
        }
        Arrays.sort(count);
        System.out.print(count[0]);
    }
}

Measured memory_bytes: 21972
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    x, a, b = LI()
    if b <= a:
        print("delicious")
    elif b <= a + x:
        print("safe")
    else:
        print("dangerous")

    return

#B
def B():
    n = II()
    a = IR(n)
    check = [False] * (n + 1)
    check[1] = True
    now = a[0]
    for i in range(1,n+1):
        if check[now]:
            break
        if now == 2:
            print(i)
            return
        check[now] = True
        now = a[now - 1]
    print(-1)
    return

#C
def C():
    return

#D
def D():
    def root(x):
        if x == par[x]:
            return x
        par[x] = root(par[x])
        return par[x]
    
    def same(x,y):
        return root(x) == root(y)
    
    def unite(x,y):
        x = root(x)
        y = root(y)
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1
    n = II()
    v = LIR(n)
    l = [None for i in range(2*n-2)]
    for i in range(n):
        v[i].append(i)
    par = [i for i in range(n)]
    rank = [0 for i in range(n)]
    v.sort(key = lambda x:x[0])
    for i in range(n-1):
        l[i] = [v[i][2],v[i+1][2],v[i+1][0]-v[i][0]]
    v.sort(key = lambda x:x[1])
    for i in range(n-1):
        l[i+n-1] = [v[i][2],v[i+1][2],v[i+1][1]-v[i][1]]
    l.sort(key = lambda x:x[2])
    k = 0
    ans = 0
    for i in range(2*n-2):
        x,y,c = l[i]
        if not same(x,y):
            k += 1
            ans += c
            unite(x,y)
        if k == n-1:break
    print(ans)
    return

#Solve
if __name__ == '__main__':
    D()


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

int main() {
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> P(A), Q(B), R(C);
    for (int &p : P) cin >> p;
    for (int &q : Q) cin >> q;
    for (int &r : R) cin >> r;
    
    sort(P.rbegin(), P.rend());
    sort(Q.rbegin(), Q.rend());
    sort(R.rbegin(), R.rend());
    
    priority_queue<int> PQ;
    for (int i = 0; i < X; i++) PQ.push(-P.at(i));
    for (int i = 0; i < Y; i++) PQ.push(-Q.at(i));
    for (int i = 0; i < C; i++) {
        int pq = PQ.top(); PQ.pop();
        PQ.push(min(pq, -R.at(i)));
    }
    
    long ans = 0;
    while (PQ.size()) {
        ans += PQ.top(); PQ.pop();
    }
    
    cout << -ans << "\n";
}

Measured memory_bytes: 2552
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using ld = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

VS grid(1005);
VVLL ans(1005, VLL(1005, 0));
VI Y = {0, -1}, X = {-1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  REP(i, H) cin >> grid[i];
  ans[0][0] = 1;
  REP(y, H) REP(x, W)
  {
    if (grid[y][x] == '#') continue;
    REP(i, 2)
    {
      int yy = y + Y[i], xx = x + X[i];
      if (0 <= yy && yy < H && 0 <= xx && xx < W && grid[yy][xx] != '#')
      {
        ans[y][x] += ans[yy][xx];
        ans[y][x] %= MOD;
      }
    }
  }
  cout << ans[H-1][W-1] << endl;

  return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

set<pair<int,int>> used_edge;

template <typename T>
class Dijkstra {
    struct edge { int to; T cost; };
    typedef pair<T, int> P; // <最短距離, 頂点番号>

public:
    T INF;

    Dijkstra(int V) 
        : INF(std::numeric_limits<T>::max())
        , m_V(V)
        {
        m_G.resize(m_V);
    }

    // a -> bに片方向のエッジを張る
    void add_dir_edge(int a, int b, T cost) {
        m_G[a].push_back( edge{ b, cost } );
    }

    // a <-> bに両方向のエッジを張る
    void add_undir_edge(int a, int b, T cost) {
        add_dir_edge(a, b, cost);
        add_dir_edge(b, a, cost);
    }

    // 頂点sから各頂点までの距離を計算して返す
    vector<T> shortest_path(int s) {
        vector<T> d(m_V, INF);
        vector<pair<int,int>> last_edge(m_V);

        priority_queue<P, vector<P>, greater<P> > que;
        d[s] = 0;
        que.push(P(0, s));
    
        while(!que.empty()) {
            P p = que.top();
            que.pop();

            auto dist = p.first;
            auto v = p.second;
            if (d[v] < dist) continue;
            REP(i, m_G[v].size()) {
                edge e = m_G[v][i];
                if (d[e.to] > d[v] + e.cost) {
                    d[e.to] = d[v] + e.cost;
                    que.push(P(d[e.to], e.to));
                    last_edge[e.to] = mp(v, e.to);
                }
            }
        }

        for (auto edge : last_edge) {
            int v1 = edge.first;
            int v2 = edge.second;
            if (v1 != v2) {
                used_edge.insert(mp(v1,v2));
                used_edge.insert(mp(v2,v1));
            }
        }

        return d;
    }

private:
    int m_V;
    vector<vector<edge> > m_G;
};

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

    Dijkstra<int> dij(N);
    REP(m,M) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        dij.add_undir_edge(a, b, c);
    }
    REP(n,N) {
        auto res = dij.shortest_path(n);
    }
    cout << (M - (SIZE(used_edge) / 2)) << endl;

    return 0;
}


Measured memory_bytes: 888
/*
我的心脏怦怦跳，监管者就在附近
*/
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<unistd.h>
#include<stdio.h>
#include<cstring>
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;

int main()
{
	int n,x;
	cin>>n>>x;
	if(n<x) cout<<0;
	else if(n>=x) cout<<10;	
	return 0;
}

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

using namespace std;

int main() {
    long long n;
    cin >> n;
    int a[n]; 

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

    for (int i = 0; i < n-1; i++){
        //cout << a[i] << a[i+1] << "\n";
        if (a[i+1] == a[i]){
            //cout << "No" << "\n";
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    string s;
    cin >> s;
    if (s.at(0) == 'S')
        cout << "Cloudy";
    else if (s.at(0) == 'C')
        cout << "Rainy";
    else
        cout << "Sunny";
}

Measured memory_bytes: 3636
from sys import stdin

def main():
    input = stdin.readline

    A = [[0] * 3 for i in range(3)]
    F = [[0] * 3 for i in range(3)]

    A[0][0],A[0][1],A[0][2] = map(int,input().split())
    A[1][0],A[1][1],A[1][2] = map(int,input().split())
    A[2][0],A[2][1],A[2][2] = map(int,input().split())

    N = int(input())

    B = []
    for _ in range(N):
        B.append(int(input()[:-1]))
    B.sort()
    
    for i in range(3):
        for j in range(3):
            for b in B:
                if(A[i][j] == b):
                    F[i][j] = True
                    break

    # 縦
    for i in range(3):
        if(F[i][0]) & (F[i][1]) & (F[i][2]):
            print("Yes")
            return
    for i in range(3):
        if(F[0][i]) & (F[1][i]) & (F[2][i]):
            print("Yes")
            return
    if (F[0][0]) & (F[1][1]) & (F[2][2]):
        print("Yes")
        return
    if (F[2][0]) & (F[1][1]) & (F[0][2]):
        print("Yes")
        return

    print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
const int maxn=10000+10;
const int maxm=100000+10;
int n,m;
struct node
{
    char s[20];
    bool operator <(const node& rhs)const
    {
        return strcmp(s,rhs.s)<0;
    }
};
map<node,int> mp;//将字符串node映射成节点编号
struct Edge
{
    node u,v;
    bool flag;//标记该边是不是桥
}e[maxm];
vector<int> G[maxn];
int pre[maxn],low[maxn];
int dfs_clock;
void tarjan(int u,int fa)
{
    low[u]=pre[u]=++dfs_clock;
    for(int i=0;i<G[u].size();i++)
    {
        int v=G[u][i];
        if(v==fa) continue;
        if(!pre[v])
        {
            tarjan(v,u);
            low[u]=min(low[u],low[v]);
        }
        else low[u] = min(low[u],pre[v]);
    }
}
int main()
{

        int id=0;
        scanf("%d%d",&n,&m);
        mp.clear();
        dfs_clock=0;
        memset(pre,0,sizeof(pre));
        for(int i=1;i<=n;i++) G[i].clear();
        for(int i=0;i<m;i++)
        {
            e[i].flag=false;
            scanf("%s%s",e[i].u.s,e[i].v.s);
            if(mp.find(e[i].u)==mp.end()) mp[e[i].u]= ++id;
            if(mp.find(e[i].v)==mp.end()) mp[e[i].v]= ++id;
            int x = mp[e[i].u], y=mp[e[i].v];
            G[x].push_back(y);
            G[y].push_back(x);
        }
        tarjan(1,-1);
        bool ok=true;//判断是否连通图
        for(int i=1;i<=n;i++)if(!pre[i])
        {
            ok=false;
            break;
        }
        if(!ok) printf("0\n");
        else
        {
            int ans=0;//计数桥总数
            for(int i=0;i<m;i++)
            {
                int u=mp[e[i].u], v=mp[e[i].v];
                if(low[u]>pre[v]||low[v]>pre[u]) e[i].flag=true,ans++;
            }
            printf("%d\n",ans);

        }

    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

typedef struct List {
	struct List *next;
	int v;
} list;

int main()
{
	int i, u, w, N, M;
	list *adj[100001] = {}, m[200001];
	scanf("%d %d", &N, &M);
	for (i = 0; i < M; i++) {
		scanf("%d %d", &u, &w);
		m[i*2].v = w;
		m[i*2+1].v = u;
		m[i*2].next = adj[u];
		m[i*2+1].next = adj[w];
		adj[u] = &(m[i*2]);
		adj[w] = &(m[i*2+1]);
	}
	
	int j, k, flag[100001] = {}, q[2][100001];
	list *p;
	q[0][0] = 1;
	i = 0;
	while (1) {
		u = q[0][i++];
		flag[u] = 1;
		for (p = adj[u]; p != NULL; p = p->next) if (flag[p->v] == 0) break;
		if (p == NULL) break;
		else q[0][i] = p->v;
	}
	q[1][0] = 1;
	j = 0;
	while (1) {
		u = q[1][j++];
		flag[u] = 1;
		for (p = adj[u]; p != NULL; p = p->next) if (flag[p->v] == 0) break;
		if (p == NULL) break;
		else q[1][j] = p->v;
	}
	
	printf("%d\n", i + j - 1);
	for (k = i - 1; k > 0; k--) printf("%d ", q[0][k]);
	for (k = 0; k < j - 1; k++) printf("%d ", q[1][k]);
	printf("%d\n", q[1][j-1]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 6348
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());

        System.out.printf("%d\n", (a >= 13) ? b : (a >= 6) ? b / 2 : 0);
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <tuple>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int main()
{

  string S, T;
  cin >> S >> T;
  vector<int> good(10000, -1);
  vector<int> good2(10000, -1);

  rep(i, S.size())
  {
    if (good[S[i] - '0'] == -1)
    {
      good[S[i] - '0'] = T[i] - '0';
    }
    else
    {
      if (good[S[i] - '0'] != T[i] - '0')
      {
        cout << "No";
        return 0;
      };
    }

    if (good2[T[i] - '0'] == -1)
    {
      good2[T[i] - '0'] = S[i] - '0';
    }
    else
    {
      if (good2[T[i] - '0'] != S[i] - '0')
      {
        cout << "No";
        return 0;
      };
    }
  }
  cout << "Yes";
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const ll mod =1000000007;
#define rep(i,n) for(ll i=0; i<n; i++)
int main(){
    int a,b,k;
    cin>>k>>a>>b;
    bool ok = false;
    for(int i=a; i<=b; i++){
        if(i%k==0) ok=true;
    }
    cout<<(ok?"OK":"NG")<<endl;
}

Measured memory_bytes: 3632
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int n; cin >> n;
    vector<int> p(n);
    REP(i,n) cin >> p[i];
    int ans = 0;
    for(int i = 0; i <= n - 3; i++) {
        //cout << p[i] << " " << p[i+1] << " " << p[i+2] << endl;
        veci a;
        a.push_back(p[i]);
        a.push_back(p[i+1]);
        a.push_back(p[i+2]);
        sort(a.begin(),a.end());
        //cout << a[0] << " " << a[1] << " " << a[2] << endl;
        if(p[i+1] == a[1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
class Phrase
  def initialize s, l, p
    @s = s
    @l = l
    @p = p
  end
  attr_reader :s, :l, :p
end

def main
  n = gets.chomp.to_i
  phrases = []
  min = 393;
  n.times do
    s,l,p = gets.chomp.split(' ').map(&:to_i)
    min = s if min > s
    phrases << Phrase.new(s, l, p)
  end

  results = []
  melodys = []
  m = gets.chomp.to_i
  m.times do
    w = gets.chomp.to_i
    if w < min
      puts '-1'
      return 0;
    end
    melodys << w
  end

  max_long_melody = melodys.max
  p_arr = Array.new(max_long_melody + 1, 0)
  d_arr = Array.new(max_long_melody + 1, 0)
  phrases.each do |phrase|
    phrase.s.upto(max_long_melody) do |i|
      pp = p_arr[i-phrase.s] + phrase.p
      if pp > p_arr[i]
        p_arr[i] = pp
        d_arr[i] = d_arr[i-phrase.s] + phrase.l - phrase.s
      end
    end
  end

  melodys.each do |w|
    max_index = p_arr[0..w].index(p_arr[0..w].max)
    if w - max_index > d_arr[max_index]
      puts '-1'
      return 0;
    end

    results << p_arr[max_index]
  end

  results.each do |result|
    puts result
  end
end

main

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

#define REP(i,n) for(long long i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(long long i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int dp[100006] = {(int)INF};

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> h(N+1);
  REP(i, N){
    cin >> h[i];
  }
  h[N] = INF;
  REP(i, N){
    dp[i] = INF;
  }
  dp[0] = 0;
  REP(i, N-1){
    for(int j=1; j<=K && j+i < N; j++){
      dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
    }
  }

  cout << dp[N-1] << endl;
  return 0;
}


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

const int N = 1e5+15,M = 2e5+5;

bool vis[N];

ll dp[N];

vector<pair<int,int> >adj[N];


void dfs(int node) {
    vis[node] = true;
    for(int i=0;i<adj[node].size();++i) {
        
        int nextNode = adj[node][i].first , ww = adj[node][i].second;
        if(!vis[nextNode]) {
            dp[nextNode] = dp[node] + ww;
            dfs(nextNode);
        } else {
            if(dp[node]+ ww != dp[nextNode]) {
                printf("No\n");
                exit(0);
            }
        }
    }
}
void solve() {
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;++i) {
        int l,r,w;
        scanf("%d%d%d",&l,&r,&w);
        adj[l].push_back(make_pair(r,w));
        adj[r].push_back(make_pair(l,-w));
    }
    for(int i=1;i<=n;++i) {
        if(!vis[i]) {
            dfs(i);
        }
    }
    printf("Yes\n");
}
int main() {
   //freopen("input.txt","r",stdin);
   solve();
}


Measured memory_bytes: 12416
#include<iostream>
#include<algorithm>

int main(){

	int num[3];
	for (int i = 0; i < 3; i++)std::cin >> num[i];

	std::sort(num, num + 3);

	for (int i = 0; i < 3; i++){
		if (i == 2)std::cout << num[i] << std::endl;
		else std::cout << num[i] << " ";
	}

	return 0;
}

Measured memory_bytes: 1176
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair


int main(){
  CIN(n);vector<string> s(n);VECCIN(s);

  if(n==1){sort(ALL(s[0]));COUT(s[0]);return 0;}

  vector<V> vec(n,V(26,0));
  REP(i,n)REP(j,s[i].size())vec[i][s[i][j]-97]++;
  
  V ans(26);
  REP(j,26){
    int ttt=INF;
    REP(i,n){
      ttt=min(ttt,vec[i][j]);
    }
    ans[j]=ttt;
  }
  string str;
  REP(i,26)REP(j,ans[i])str.pb(i+97);
  COUT(str);

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>


char a[120], b[120], c[120];
bool found;

void task(){
    scanf("%s %s", a, b);
    found = 0;
    int n = strlen(a);
    for(int i = 0; i < n; ++i){
        c[0] = a[n - 1];
        for(int j = 1; j < n; ++j){
            c[j] = a[j - 1];
        }
        strcpy(a, c);
        if(strcmp(a, b) == 0){
            printf("Yes\n");
            found = 1;
            break;
        }
    }
    if(!found)printf("No\n");
}

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

    // freopen("/Users/deepsajeda/Projects/input.txt","r", stdin);
    // freopen("/Users/deepsajeda/Projects/output","w",stdout);
    task();
}
//printf("%.5f\n", clock() / (float)CLOCKS_PER_SEC); time in seconds

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x
#define foreach(x,a) for(auto &x:a)
typedef long long ll;
const ll MOD = 998244353;
//}}}

int main(){
  int D, N;
  cin >> D >> N;
  int ans = 1;
  rep(i, D) ans *= 100;
  if (N == 100) N++;
  ans *= N;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N, Q = gets.split(' ').map(&:to_i)
tree = Array.new(N + 1){Array.new}

(N - 1).times do
	a, b = gets.split(' ').map(&:to_i)
	tree[a].push(b)
	tree[b].push(a)
end

counter = [0] * (N + 1)
Q.times do
	po, x = gets.split(' ').map(&:to_i)
	counter[po] += x
end

queue = [[0, 1]]
checker = [false] * (N + 1)
ans = [0] * (N + 1)
while !queue.empty?
	pre, now = queue.shift
	checker[now] = true
	if pre == 0
		ans[now] = counter[now]
	else
		ans[now] = ans[pre] + counter[now]
	end
	tree[now].each do |i|
		if checker[i] == false
			queue.push([now, i])
		end
	end
end

puts ans[1..N].join(' ')

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if(A + B > C + D) {
    cout << "Left" << endl;
  }
  
  if(A + B == C + D) {
    cout << "Balanced" << endl;
  }
  
  if(A + B < C + D) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define MAXN 100005
#define PLI pair<long long,int>
#define fi first
#define se second
#define mp make_pair
//#define ivorysi
using namespace std;
typedef long long int64;
int64 A,B,C;
int X,Y;
int64 calc(int t) {
	return 2 * t * C + max(X - t,0) * A + max(Y - t,0) * B;
}
void Solve() {
	scanf("%lld%lld%lld%d%d",&A,&B,&C,&X,&Y);
	int L = 0,R = max(X,Y);
	while(1) {
		int k = (R - L) / 3;
		if(!k) break;
		if(calc(L + k) > calc(R - k)) L = L + k;
		else R = R - k;
	}
	int64 ans = X * A + Y * B;
	for(int i = L ; i <= R ; ++i) {
		ans = min(ans,calc(i));
	}
	printf("%lld\n",ans);
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
	return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())                            # 1行2列
List=[list(map(int,input().split())) for i in range(M)] # N行C列・・・Cは任意


if N == 1:
	answer = ' '
elif N == 2:
	answer = '  '
elif N == 3:
	answer = '   '

ok = 0
for search in List:
	# search[0]:桁数
	# search[1]:値
	if answer[search[0]-1] == str(search[1]) or answer[search[0]-1] == ' ':
		if N != 1 and search[0] == 1 and search[1] == 0:
			ok = -1
			break
		else:
			anslist = list(answer)
			anslist[search[0]-1] = str(search[1])
			answer = ''.join(anslist)
	else:
		ok = -1
		break

if ok == -1:
	print(-1)
else:
	for i in range(N):
		if answer[i] == ' ':
			anslist = list(answer)
			
			if i == 0 and N != 1:
				anslist[i] = '1'
			else:
				anslist[i] = '0'
			
			answer = ''.join(anslist)
	print(answer)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)

// http://topcoder.g.hatena.ne.jp/iwiwi/20130105/1357363348
ll inverse(ll v, ll mod) {
	ll a = v, b = mod, x = 1, y = 0;
	while (b) {
		ll t = a / b;
		swap(a -= t * b, b);
		swap(x -= t * y, y);
	}
	return (x % mod + mod) % mod;
}

int main() {
#ifdef _WIN32
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0); // cin??¨cout?????£????????????
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n, m, k;
	cin >> n >> m >> k;

	ll mod = TEN(9) + 7;
	vector<ll> powmod(3 * TEN(6)); powmod[0] = 1;
	FOR(i, 1, 3 * TEN(6)) powmod[i] = powmod[i - 1] * i % mod;
	auto nCk = [&](ll n, ll k) {
		ll v = powmod[n] * inverse(powmod[k] * powmod[n - k] % mod, mod) % mod;
		assert(v >= 0);
		return v;
	};

	ll sum = 0;
	REP(i, k + 1) {
		ll v = nCk(n + m + k * 2, n + i * 2);
		{
			ll c1 = (n + 1) * inverse(n + i + 1, mod) % mod;
			(v *= nCk(n + i * 2, i) * c1 % mod) %= mod;

			ll c2 = (m + 1) * inverse(m + (k - i) + 1, mod) % mod;
			(v *= nCk(m + (k - i) * 2, k - i) * c2 % mod) %= mod;
		}
		(sum += v) %= mod;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 26320
class Dice():

    def __init__(self, nums):
        self.__indexTop__ = 1
        self.__indexFront__ = 2
        self.__indexRight__ = 3
        self.__indexLeft__ = 4
        self.__indexBack__ = 5
        self.__indexBottom__ = 6
        self.__sides__ = {1:nums[0], 2:nums[1], 3:nums[2], 4:nums[3], 5:nums[4], 6:nums[5]}
    
    def getTopSideNum(self):
        return self.__sides__[self.__indexTop__]
    
    def getTopsideIndex(self):
        return self.__indexTop__
    
    def roll(self, direction):
        initTop = self.__indexTop__
        initFront = self.__indexFront__
        initRight = self.__indexRight__
        initLeft = self.__indexLeft__
        initBack = self.__indexBack__
        initBottom = self.__indexBottom__
        if direction == 'N':
            self.__indexTop__ = initFront
            self.__indexFront__ = initBottom
            self.__indexRight__ = initRight
            self.__indexLeft__ = initLeft
            self.__indexBack__ = initTop
            self.__indexBottom__ = initBack
        elif direction == 'E':
            self.__indexTop__ = initLeft
            self.__indexFront__ = initFront
            self.__indexRight__ = initTop
            self.__indexLeft__ = initBottom
            self.__indexBack__ = initBack
            self.__indexBottom__ = initRight
        elif direction == 'S':
            self.__indexTop__ = initBack
            self.__indexFront__ = initTop
            self.__indexRight__ = initRight
            self.__indexLeft__ = initLeft
            self.__indexBack__ = initBottom
            self.__indexBottom__ = initFront
        elif direction == 'W':
            self.__indexTop__ = initRight
            self.__indexFront__ = initFront
            self.__indexRight__ = initBottom
            self.__indexLeft__ = initTop
            self.__indexBack__ = initBack
            self.__indexBottom__ = initLeft

die = Dice([int(i) for i in input().split()])
for direction in input():
    die.roll(direction)
print(die.getTopSideNum())



Measured memory_bytes: 5612
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
string s[maxn];
int main()
{
	int n;
	int d=0,a=0,b=0,ab=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=1;j<s[i].length();j++)
		{
			if(s[i][j-1]=='A'&&s[i][j]=='B')
			{
				d++;
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		if(s[i][0]=='B') b++;
		if(s[i][s[i].length()-1]=='A') a++;
		if(s[i][0]=='B'&&s[i][s[i].length()-1]=='A') ab++;
	}
	int ans=0;
	ans=d+min(b,a);
	if(b==a&&b==ab&&b!=0) ans--;
//	cout<<a<<" "<<b<<endl;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;
auto in = [](auto &&... args) { (cin >> ... >> args); };


signed main(){
  ios::sync_with_stdio(false);cin.tie(0);
  int n;
  in(n);
  vector<int> a(n);
  for(int &i : a){
    cin >> i;
  }
  vector<int> C(3 , 0);
  int ans = 1;
  for(int i : a){
    int cnt = 0, id = -1;
    if(i == C[0]) {
      cnt++;
      id = 0;
    }
    if(i == C[1]){
      cnt++;
      id = 1;
    }
    if(i == C[2]){
      cnt++;
      id = 2;
    }
    if(id == -1){
      cout << 0 << '\n';
      return 0;
    }

    ans = (ans * cnt) % Mod;
    C[id]++;
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;
int N;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N;
  if(N == 1){
    cout << "Hello World" << endl;
  }
  else{
    int A,B;
    cin >> A >> B;
    cout << A+B << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
B = list(map(int, input().split()))

ans = 0
for i in range(n):
    if i == 0:
        ans += B[0]
    elif i == n - 1:
        ans += B[n - 2]
    else:
        ans += min(B[i - 1], B[i])

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
using namespace std;
struct Circle { long double x, y, r; };
int solve(Circle c, Circle d) {
	long double dist = (c.x - d.x)*(c.x - d.x) + (c.y - d.y)*(c.y - d.y);
	dist = sqrt(dist);
	long double dist2 = d.r + dist;
	if (dist2 < c.r) { return 2; }
	long double dist3 = c.r + dist;
	if (dist3 < d.r) { return -2; }
	long double dist4 = c.r + d.r;
	if (dist4 < dist) { return 0; }
	return 1;
}
int main() {
	Circle a, b; int n; cin >> n;
	for (int i = 0; i < n;i++){
		cin >> a.x >> a.y >> a.r >> b.x >> b.y >> b.r;
		cout << solve(a, b) << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int a,b;
    cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#include <math.h>
#include <regex>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
ld n , d;
vector<vector<ld>> x(n,vector<ld>(d));

int main(){
    ll n , a, b; cin >> n >> a >> b;
    if(n==1){
        if(a==b){
            cout << 1 << endl;
        }else{
            cout << 0 << endl;
        }
        return 0;
    }
    if(a>b){
        cout << 0 << endl;
        return 0;
    }
    cout << (n-2)*(b-a)+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const int N=3e3+10;
char s[N],t[N];
int dp[N][N];
int main()
{
	int len1,len2,l,r,i,j;
	scanf("%s",s+1);
	scanf("%s",t+1);
	len1=strlen(s+1);len2=strlen(t+1);
	for(i=len1;i>=1;i--)
	{
		for(j=len2;j>=1;j--)
		{
			if(s[i]==t[j]) dp[i][j]=dp[i+1][j+1]+1;
			else dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
		}
	}
	l=1;r=1;
	while(l<=len1&&r<=len2)
	{
		if(s[l]==t[r])
		{
			printf("%c",s[l]);
			l++;r++; 
		}
		else if(dp[l][r]==dp[l+1][r]) l++;
		else r++;
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool check = true;
    REP (i, 0, s.size()) {
        if (i % 2 && s[i] == 'R')  check = false;
        if (i % 2 == 0 && s[i] == 'L') check = false;
    }
    cout << (check ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int n, h, w, a, b, ans = 0;
	scanf("%d %d %d", &n, &h, &w);
	while (n--) {
		scanf("%d %d", &a, &b);
		if ((a >= h) && (b >= w))
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

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

int main(){
	string s;
	cin >> s;
	
	rep(bit, 1<<3){
		vector<int> d(3,0);
		int ans = 0;
		rep(i,3){
			if(bit & (1<<i)){
				d[i] = 1;
			}
		}
		ans += s[0] - '0';
		rep(i,3){
			if(d[i] == 0){
				ans += s[i+1] - '0';
			}
			if(d[i] == 1){
				ans -= s[i+1] - '0';
			}
		}
		if(ans == 7){
			cout << s[0];
			rep(i,3){
				if(d[i] == 0){
					cout << '+' << s[i+1];
				}
				if(d[i] == 1){
					cout << '-' << s[i+1];
				}
			}
			cout << "=7" << endl;
			return 0;
		}else{
			continue;
		}
	}
    return 0;
}



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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int h, w;
    cin >> h >> w;

    loop(i, h){
        string str;
        cin >> str;
        cout << str << endl;
        cout << str << endl;
    }

    return 0;
}


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

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


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

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

    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<pair<char, int>> runLength;
    char bef;
    int cnt = 1;
    for(int i = 0; i < n; i++){
        if(i == 0) bef = s[i];
        else{
            if(bef == s[i]){
                cnt++;
            }else{
                runLength.push_back(make_pair(bef, cnt));
                cnt = 1;
                bef = s[i];
            }
        }
    }
    runLength.push_back(make_pair(bef, cnt));

    int ans = 0, right = 0, zero_cnt = 0, one_cnt = 0;
    int rs = runLength.size();
    for(int left = 0; left < rs; left++){
        while((right < rs) && ((zero_cnt + (runLength[right].first == '0')) <= k)){
            zero_cnt += (runLength[right].first == '0');
            one_cnt += runLength[right].second;
            right++;
        }
        ans = max(ans, one_cnt);

        if(left == right) right++;
        else{
            zero_cnt -= (runLength[left].first == '0');
            one_cnt -= runLength[left].second;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1528
(setf ht (make-hash-table))
(setf (gethash 0 ht) 1000)

(loop repeat (read) with price do
      (setf price (read))
      (multiple-value-bind (q r) (floor (gethash 0 ht) price)
        (if (> r (or #1=(gethash q ht) -1))
            (setf #1# r)))
      (setf (gethash 0 ht)
            (loop for k being each hash-key of ht
                  using (hash-value v)
                  maximize (+ (* price k) v))))

(princ (gethash 0 ht))

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll A, B;
    cin >> A >> B;

    ll ans = 0;
    ll base = 1;
    for (ll i = 0; i < 50; i++) {
        ll num1 = A / (base * 2) * base;
        ll num2 = (B + 1) / (base * 2) * base;
        num1 += max(A % (base * 2) - base, 0LL);
        num2 += max((B + 1) % (base * 2) - base, 0LL);
        if ((num2 - num1) & 1) {
            ans += base;
        }
        base <<= 1;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;
vector<int> vis;
void dfs(int u, vector<vector<int> > &adj) {
	if(vis[u]) return;
	int ans = 1;
	for(int v : adj[u]) {
		dfs(v, adj);
		ans = max(ans, vis[v] + 1);
	}
	vis[u] = ans;
}
int main() {
	int n,m;
	cin>>n>>m;
	vector<vector<int> > adj (n+1);
	for(int i=0;i<m;i++) {
		int u,v;
		cin>>u>>v;
		adj[u].push_back(v);
	}
	vis.resize(n+1, 0);
	int ans = 1;
	for(int i=1;i<=n;i++) {
		if(!vis[i]) {
			dfs(i, adj);
		}
		ans = max(ans, vis[i]);
	}
	cout<<ans-1<<endl;
	return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)

int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n;
   cin >> n;
   map<string , int> mp;
   int mx = 0;
   for(int i = 0 ; i < n ; ++i){
      string s;
      cin >> s;
      mp[s]++;
      mx = max(mx , mp[s]);
   }

   for(auto s : mp){
      if(s.second == mx){
         cout << s.first << "\n";
      }
   }
}

Measured memory_bytes: 23808
/* code of Ayush Tiwari
    codeforces- servermonk
    codechef- ayush572000
*/

#include <bits/stdc++.h>
#define ll long long

//STL
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define all(v) v.begin(), v.end()

//loops
#define forn(i,a,b) for(int i=a;  i<b; i++)
#define rforn(i,a,b) for(int i=a; i>=b; i--)

// defined values
#define maxn 2004
#define Mod 1000000007

// fast io
#define FIO() ios_base::sync_with_stdio(0);cin.tie(0);


using namespace std;

char a[maxn][maxn];
int dp[maxn][maxn],n,m;

int dfs(int x,int y){
    if(x>=n|| y>=m || a[x][y]=='#') return 0;
    if(x==n-1 && y==m-1) return 1;
    if(dp[x][y]!=-1)  return dp[x][y];
    dp[x][y]=(dfs(x+1,y)+dfs(x,y+1))%Mod;
    return dp[x][y];
    
    
}

void solution(){

    // This is the main code
    cin>>n>>m;
    memset(dp,-1,sizeof(dp));
    forn(i,0,n){
        forn(j,0,m) cin>>a[i][j];
    }
    cout<<dfs(0,0)%Mod;
    
}


int main(){
    
    #ifndef ONLINE_JUDGE
    freopen("E:/CP/input.txt","r",stdin);
    freopen("E:/CP/output.txt","w",stdout);
    #endif  
    
    FIO()   
    
    ll t=1;
    //cin>>t;
    while (t--)
    {
        solution();
    }
    return 0;
}

Measured memory_bytes: 21232
import sys


def main() -> None:
    h, w = [int(next_str()) for _ in range(2)]
    cnt = 0
    for i in range(h):
        cnt += input().count("#")
    print(["Impossible", "Possible"][cnt == h + w - 1])


def next_str() -> str:
    result = ""
    while True:
        tmp = sys.stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long[] n = {a, b, c};
		Arrays.sort(n);
		if(a%2==0||b%2==0||c%2==0) {
			System.out.println(0);
			return;
		}
		//System.out.println(Arrays.toString(n));
		System.out.println(n[0]*n[1]);
	}
}


Measured memory_bytes: 21844