akhauriyash/Code-Regression huggingface dataset:
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
# mod = 10 ** 9 + 7
mod = 998244353 

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def f(A, S):
    T = [0] * len(A[0])
    for a in A:
        for k in a:
            if k in S:
                continue
            T[k] += 1
            break
    
    v = max(T)
    return (T.index(v), v)


def main():
    N, M = read_values()
    A = [list(read_index()) for _ in range(N)]

    K = [0] * N

    res = V(min, N)
    S = set()
    for _ in range(M - 1):
        k, v = f(A, S)
        S.add(k)
        res.ud(v)

    print(res)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int n;cin>>n;
    string s,t;cin>>s>>t;
    REP(i,n){
        if(s.substr(i)==t.substr(0,n-i)){
            cout<<n+i<<endl;
            return 0;
        }
    }
    cout<<2*n<<endl;
    return 0;
}

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

using namespace std;

struct Num_Group
{
    int self_len;
    int prev_len;
};


int main() {
    int N, K;
    string S;
    cin >> N >> K >> S;

    char prev = 'a'; // 直前の状態をほじ
    int group_size = 0;
    int max_len = 0;
    vector<Num_Group> group;


    for(int i=0; i < N; i++) {
        if (S[i] == prev) {
            group_size += 1;
        } else {
            if (S[i] == '0') {
                if (group.size() == K) {
                    // 計算処理
                    int tmp =0;
                    for (int j=0; j < K; j++) {
                        tmp += group[j].prev_len;
                        tmp += group[j].self_len;
                    }
                    max_len = max(max_len, tmp + group_size);
                    group.erase(group.begin());
                }

                Num_Group g = {0, group_size};

                group.push_back(g);
            }

            prev = S[i];
            group_size = 1;
        }

        if(S[i] == '0') {
            group[group.size() - 1].self_len += 1;
        }

    }

    // 最後が1のセットで終わった場合
    if (S[S.length() - 1] == '1') {
        // 計算処理
        int tmp =0;
        for (int j=0; j < group.size(); j++) {
            tmp += group[j].prev_len;
            tmp += group[j].self_len;
        }
        max_len = max(max_len, tmp + group_size);
    } else {
        int tmp =0;
        for (int j=0; j < group.size(); j++) {
            tmp += group[j].prev_len;
            tmp += group[j].self_len;
        }
        max_len = max(max_len, tmp);       
    }


    cout << max_len << endl;

    return 0;
}

Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<((int)n);i++)
#define REP(i,n)	for(int i=0;i<=((int)n);i++)
#define srep(i,a,n)	for(int i=a;i<((int)n);i++)
#define SREP(i,a,n)	for(int i=a;i<=((int)n);i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
template<typename T> istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec)	is >> x;
	return is;
}
template<typename T> ostream& operator << (ostream& os, vector<T>& vec) {
	os << "[";
	rep(i, vec.size())	os << (i ? ", " : "") << vec[i];
	os << "]";
	return os;
}
template<typename T> istream& operator >> (istream& is, pair<T, T>& p) {
	is >> p.first >> p.second;
	return is;
}
template<typename T> ostream& operator << (ostream& os, pair<T, T>& p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll sqrtll(ll x) {
	ll left = 0, right = x;
	rep(i, 100) {
		ll mid = (left + right) >> 1;
		if (mid*mid <= x)	left = mid;
		else	right = mid;
	}
	return left;
}
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
#define debug(x)	printf("Case #%d: ", x)
#define DEBUG 0
const ll inf = 1e9;
const ld infl = 1e100;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

int main() {
	int n;	cin >> n;
	string a, b, c;	cin >> a >> b >> c;
	int ret = 0;
	rep(i, n) {
		map<char, int> mp;
		mp[a[i]]++;	mp[b[i]]++;	mp[c[i]]++;
		int cnt = 0;
		for (auto it : mp)	cnt = max(cnt, it.second);
		ret += 3 - cnt;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        Set<String> set = new HashSet<>();
        int n = scanner.nextInt();
        for(int i = 0; i < n; i++){
            String s = scanner.next();
            set.add(s);
        }
        System.out.println(set.size());
        return;
    }
}

Measured memory_bytes: 76908
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,a,b;
ll res = 0;

int main() {
    cin >> n >> a >> b;
    vector<int> x(n);
    REP(i,n){
        cin >> x[i];
    }
    REP(i,n-1){
        ll c = (ll)(x[i+1]-x[i])*a;
        if(c<b){
            res += c;
        }else{
            res += b;
        }
    }
    put(res);
    return 0;
}


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

using namespace std;
typedef long long ll;
const int N = 200;
int x[N], y[N], n; ll h[N];
ll ok(int cx, int cy) {
	ll zh=1e15, ph=1e15;
	for (int i=0; i<n; ++i)
		if (h[i] == 0) {
			zh = min(zh, h[i] + abs(x[i] - cx) + abs(y[i] - cy));
		}
		else {
			ll hh = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
			if (ph != 1e15 && hh != ph) return -1;
			ph = hh;
		}
	if (ph > zh) return -1;
	if (zh < 1) return -1;
	return ph;
}
int main() {
	cin >> n; for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> h[i];
	for (int cx = 0; cx <= 100; ++cx)
		for (int cy = 0; cy <= 100; ++cy)
			if (ok(cx, cy)!=-1) {
				cout << cx << " " << cy << " " << ok(cx, cy) << endl;
				exit(0);
			}
}

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

int main() {
	int n;
	cin >> n;
	vector<vector<ll>>xyh(0, vector<ll>(3));
	for (int i = 0; i < n; i++) {
		ll x, y, z;
		cin >> x >> y >> z;
		if (z != 0) xyh.push_back({ x, y, z });
	}
	if (xyh.size() == 1) {
		cout << xyh.at(0).at(0) << " " << xyh.at(0).at(1) << " " << xyh.at(0).at(2) << endl;
		return 0;
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			ll cx = i;
			ll cy = j;
			ll ch = abs(cx - xyh.at(0).at(0)) + abs(cy - xyh.at(0).at(1)) + xyh.at(0).at(2);
			bool b = false;
			for (int k = 0; k < xyh.size(); k++) {
				if (xyh.at(k).at(2) == 0)continue;
				if (ch != abs(cx - xyh.at(k).at(0)) + abs(cy - xyh.at(k).at(1)) + xyh.at(k).at(2)) {
					b = true;
					break;
				}
			}
			if (!b) {
				cout << cx << " " << cy << " " << ch << endl;
				return 0;
			}
			else continue;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<string>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	string s, t;
  	string ans = "No";
	cin >> s >> t;
	ll x = stoi(s + t);
	for (ll i = 1; i <= 1000; i++) {
		if (i*i == x) {
			ans = "Yes";
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

main = abc162a

abc162a = do
    n <- BS.getLine
    putStrLn $ if BS.elem '7' n then "Yes" else "No"

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

Measured memory_bytes: 3736
#include <stdio.h>
int main(){
int A;
int B;
int C;	
	
scanf("%d",&A);
scanf("%d",&B);
scanf("%d",&C);	

	if(A==C&&A!=B&&B!=C){
	printf("Yes\n");
	}
	else if(A==B&&A!=C&&B!=C){
		printf("Yes\n");
	}
	else if(B==C&&B!=A&&A!=C){
		printf("Yes\n");
	}
	else if(A==B&&A==C&B==C){
		printf("No\n");
	}
	else if(A!=B&&A!=C&B!=C){
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1616
// AOJ 0171: Dice Puzzle
// 2017.8.17 bal4u@uu
// 2017.12.29
// ?????????????????¢??¨??????????????????????????°

#include <stdio.h>
#include <ctype.h>

int rot[24][7] = {
	{ 0,1,2,3,4,5,6 },{ 0,1,3,5,2,4,6 },{ 0,1,4,2,5,3,6 },{ 0,1,5,4,3,2,6 },
	{ 0,2,6,3,4,1,5 },{ 0,2,3,1,6,4,5 },{ 0,2,1,4,3,6,5 },{ 0,2,4,6,1,3,5 },
	{ 0,3,1,2,5,6,4 },{ 0,3,2,6,1,5,4 },{ 0,3,5,1,6,2,4 },{ 0,3,6,5,2,1,4 },
	{ 0,4,1,5,2,6,3 },{ 0,4,2,1,6,5,3 },{ 0,4,5,6,1,2,3 },{ 0,4,6,2,5,1,3 },
	{ 0,5,1,3,4,6,2 },{ 0,5,3,6,1,4,2 },{ 0,5,4,1,6,3,2 },{ 0,5,6,4,3,1,2 },
	{ 0,6,2,4,3,5,1 },{ 0,6,3,2,5,4,1 },{ 0,6,5,3,4,2,1 },{ 0,6,4,5,2,3,1 } };

int con[8][7][2] = {{{0}},
	{{0},{0},{0},{0},{0,3},{0},{0}},		// ?????????????????¨??¢??????
	{{0},{0},{1,5},{0},{0},{0},{0}},
	{{0},{0},{0,5},{2,4},{0},{0},{0}},
	{{0},{0},{0},{0},{0},{0},{0,1}},
	{{0},{0},{0},{0},{4,3},{0},{1,1}},
	{{0},{0},{5,5},{0},{0},{0},{2,1}},
	{{0},{0},{4,5},{6,4},{0},{0},{3,1}}};

char dice[8][8];
char kari[8][8], f[9];

int check(char *c, int i, char c2)
{
	int j;
	char c1;

	if (c2 <= 'Z') *c = c1 = c2-'A'+'a';
	else 		   *c = c1 = c2-'a'+'A';
	for (j = 1; j <= 6; j++) {
		if (dice[i][j] == c1) return 1;
	}
	return 0;
}

int rec(int n)
{
	int i, j, k, n0, p0, goal, cnt;
	char tbl[7][2], c;


	if (n == 8) return 1;
	for (i = 0; i < 8; i++) {
		if (f[i]) continue;
		cnt = 0;
		if (n) {
			goal = 0;
			for (j = 1; j <= 6; j++) {
				if (!con[n][j][1]) continue;
				goal++;
				n0 = con[n][j][0], p0 = con[n][j][1];
				if (check(&c, i, kari[n0][p0])) tbl[cnt][0] = j, tbl[cnt++][1] = c;
			}
			if (cnt != goal) continue;
		}

		for (j = 0; j < 24; j++) {
			for (k = 1; k <= 6; k++) kari[n][k] = dice[i][rot[j][k]];
			for (k = 0; k < cnt; k++) {
				if (kari[n][tbl[k][0]] != tbl[k][1]) break;
			}
			if (k < cnt) continue;
			f[i] = 1;
			if (rec(n+1)) return 1;
			f[i] = 0;
		}
	}
	return 0;
}

int main()
{
	int i, j;
	char buf[10];

	while (1) {
		for (i = 0; i < 8; i++) {
			fgets(buf, 10, stdin);
			if (*buf == '0') return 0;
			for (j = 0; j < 6; j++) dice[i][j+1] = buf[j];
			f[i] = 0;
		}
		puts(rec(0) ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 1820
N, K = map(int, input().split())
Ps = list(map(int, input().split()))
Cs = list(map(int, input().split()))

cycles = []
cycleSums = []
visited = [False]*N
for i, p in enumerate(Ps):
    if visited[i]:
        continue
    cycle = []
    now = i
    S = 0
    while not visited[now]:
        visited[now] = True
        now = Ps[now] - 1
        cycle.append(Cs[now])
        S += Cs[now]
    cycles.append(cycle)
    cycleSums.append(S)

ans = float('-inf')
for cycle, cycleSum in zip(cycles, cycleSums):
    L = len(cycle)
    cycle = cycle + cycle
    DPL = L + 1
    DPL2 = K % L + 1
    M = float('-inf')
    M2 = float('-inf')
    dp = [None]*DPL
    dp[0] = 0
    for c in cycle:
        ndp = [None]*DPL
        ndp[0] = 0
        for i in range(1, DPL):
            if dp[i-1] is None:
                break
            tmp = dp[i-1] + c
            ndp[i] = 0 if 0 > tmp else tmp
            M = M if M > tmp else tmp
            if i < DPL2:
                M2 = M2 if M2 > tmp else tmp
        dp = ndp
    if cycleSum > 0:
        if K % L != 0:
            tmp = cycleSum * (K // L) + M2
            tmp2 = cycleSum * ((K // L)-1) + M
            tmp = tmp if tmp > tmp2 else tmp2
        else:
            tmp = cycleSum * ((K // L)-1) + M
    else:
        tmp = M
    ans = ans if ans > tmp else tmp

print(ans)



Measured memory_bytes: 85064
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <unordered_map>
#define maxn 100005
#define mod 998244353
using namespace std;
typedef long long LL;
char s[1000];
int check(int l,int r)
{
    while(s[l]==s[r]&&l<=r)
    {
        l++;r--;
    }
    if(l<=r) return 0;
    return 1;
}
int main()
{

    scanf("%s",s+1);
    int len=strlen(s+1);
    if(check(1,len/2)==1&&check(len/2+2,len)==1&&check(1,len)==1) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 888
a,b,c = map(int,input().split())
max = max(a,b,c)
min = min(a,b,c)
sec = a+b+c-max-min
if ((max-min)+(max-sec)) % 2 == 0:
	print( ((max-min)+(max-sec))//2 )
else:
	print( ((max-min)+(max-sec)+3)//2 )

Measured memory_bytes: 3188
def main():
    H, W = map(int, input().split())
    A = [
        list(input())
        for _ in range(H)
    ]

    # 2 <= H,W <= 8 より右下全列挙でもいけそう
    # H+W-2歩く(0,0からのため)、max:2 ** 14 = 16384
    # x:0, y:1
    p = [0] * (H + W - 2)

    def dfs(i):
        if i == H + W - 2:
            # 歩き方はあり得るか
            if p.count(1) != H-1 or p.count(0) != W-1:
                return False

            b = [
                ["."] * W
                for _ in range(H)
            ]
            x, y = (0, 0)
            b[0][0] = "#"
            for c in p:
                if c == 1:
                    y += 1
                else:
                    x += 1
                b[y][x] = "#"

            return A == b

        p[i] = 0
        if dfs(i + 1):
            return True
        p[i] = 1
        if dfs(i + 1):
            return True

        return False

    if dfs(0):
        print("Possible")
    else:
        print("Impossible")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	num := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&num[i])
	}
	m := make(map[int]int, n)
	for i := 0; i < n; i++ {
		m[num[i]]++
	}
	j := []int{}
	for _, v := range m {
		j = append(j, v)
	}
	sort.Ints(j)
	boll := 0
	for i := 0; i < (len(j) - k); i++ {
		boll += j[i]
	}
	fmt.Println(boll)
}


Measured memory_bytes: 15744
using System;

class Program
{
    static void Main(string[] args)
    {
        string[] arr = Console.ReadLine().Split(' ');
        int a = int.Parse(arr[0]);
        int b = int.Parse(arr[1]);

        Console.WriteLine((a * b).ToString() + ' ' + (2 * a + 2 * b).ToString());

    }
}


Measured memory_bytes: 15932
import java.util.*

fun main(args: Array<String>) {
	val (n, m) = readLine()!!.split(" ").map({ it -> it.toInt() })
	val graph = WeightedDirectedGraph(n)
	for (i in 1..m) {
		val (a, b, c) = readLine()!!.split(" ").map({ it -> it.toInt() })
		graph.addEdge(a - 1, b - 1, (-c).toLong())
	}
	val ans = bellmanFord(0, n - 1, graph)
	if (ans == null) {
		println("inf")
	} else {
		println(-ans)
	}
}

class WeightedDirectedGraph(n: Int) {
	val len = n
	val edges = Array<MutableList<Pair<Int, Long>>>(n) { mutableListOf() }
	fun addEdge(from: Int, to: Int, cost: Long) {
		this.edges[from].add(Pair(to, cost))
	}
}

fun bellmanFord(src: Int, snk: Int, graph: WeightedDirectedGraph): Long? {
	val costs = LongArray(graph.len) { Long.MAX_VALUE }
	costs[src] = 0L
	for (i in 1..(graph.len - 1)) {
		for (j in 0..(graph.len - 1)) {
			if (costs[j] == Long.MAX_VALUE) {
				continue
			}
			for (p in graph.edges[j]) {
				val newCost = costs[j] + p.second
				costs[p.first] = Math.min(newCost, costs[p.first])
			}
		}
	}
	for (i in 1..graph.len) {
		for (j in 0..(graph.len - 1)) {
			if (costs[j] == Long.MAX_VALUE) {
				continue
			}
			for (p in graph.edges[j]) {
				val newCost = costs[j] + p.second
				if (newCost < costs[p.first]) {
					costs[p.first] = newCost
					if (p.first == snk) {
						return null
					}
				}
			}
		}
	}
	return costs[snk]
}

Measured memory_bytes: 55084
#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;

bool dp[8001][16001];

bool can_reach(vector <int> moves, int pos){
    int total_moves = accumulate(moves.begin(), moves.end(), 0);
    //cout << total_moves << " " << pos << endl;
    if(pos > total_moves || (- total_moves) > pos){
        return false;
    }

    for(int i  = 0; i < moves.size() + 1; i++){
        for(int j = 0; j < 2 * total_moves + 1; j++){
            dp[i][j] = false;
        }
    }

    dp[0][total_moves] = true;
    for(int i = 1; i <= moves.size(); i++){
        //cout << "moves " << moves[i] << endl;
        for(int j = 0; j < 2 * total_moves + 1; j++){
            if(j + moves[i - 1] < 2 * total_moves + 1){
                dp[i][j] |= dp[i - 1][j + moves[i - 1]];
            }
            if(j - moves[i - 1] >= 0){
                dp[i][j] |= dp[i - 1][j - moves[i - 1]];
            }
        }
    }

    /*
    for(int i = 0; i <= moves.size(); i++){
        for(int j = 0; j < 2 * total_moves + 1; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    */
    return dp[moves.size()][pos + total_moves];
}

int main(){
    string S;
    int x;
    int y;
    cin >> S;
    cin >> x >> y;

    vector <int> horizontal_moves;
    vector <int> vertical_moves;

    bool horizontal = true;
    int cur_move_size = 0;
    for(int i = 0; i < S.size(); i++){
        //cout << horizontal << endl;
        if(S[i] == 'F'){
            cur_move_size ++;
        }
        if(S[i] == 'T' || i == S.size() - 1){
            if(horizontal){
                horizontal_moves.push_back(cur_move_size);
            } else {
                vertical_moves.push_back(cur_move_size);
            }
            horizontal = !horizontal;
            cur_move_size = 0;
        }
    }
    
    /*
    for(int i = 0; i < horizontal_moves.size(); i++){
        cout << horizontal_moves[i] << " ";
    }
    cout << endl;
    for(int i = 0; i < vertical_moves.size(); i++){
        cout << vertical_moves[i] << " ";
    }
    cout << endl;
    */

    x -= horizontal_moves[0];
    horizontal_moves.erase(horizontal_moves.begin(), horizontal_moves.begin() + 1);

    /* 
    for(int i = 0; i < horizontal_moves.size(); i++){
        cout << horizontal_moves[i] << " ";
    }
    cout << endl;
    for(int i = 0; i < vertical_moves.size(); i++){
        cout << vertical_moves[i] << " ";
    }
    cout << endl;
    */

    if(can_reach(horizontal_moves, x) && can_reach(vertical_moves, y)){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 60288
import numpy as np
N,A,B = map(int,input().split())

if A+B > N+1:
  print("-1")
  exit()
if A == 1:
  if B== N:
    ans = [i+1 for i in reversed(range(N))]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if B == 1:
  if A== N:
    ans = [i+1 for i in range(N)]
    print(*ans)
    exit()
  else:
    print("-1")
    exit()
if A >= B:
  Flag = True
else:
  Flag = False
  A,B = B,A
#print((N+A-1)//A, B)
if A*B<N:
  print("-1")
  exit()
else:
  L = [1 for _ in range(B)]
  nokori = N-B
  for i in range(B):
    if A-L[i] >0:
      temp = min(A-L[i],nokori)
      L[i] += temp
      nokori -= temp
    if nokori == 0:
      break
  now = 0
  P = [[] for _ in range(B)]
  for i,num in enumerate(L):
    for j in range(num):
      now += 1
      P[-i-1].append(now)
  #print(P)
  ans = P
  output = []
  for i in range(len(ans)):
    for j in ans[i]:
      output.append(j)
  if Flag:
    print(*output)
  else:
    output = output[::-1]
    print(*output)


Measured memory_bytes: 58612
deck = list()
for s in ["S", "H", "C", "D"]:
    for i in range(1,14):
        deck.append(s + " " + str(i))

n = int(input())
for _ in range(n):
    deck.remove(input()) 

if len(deck) > 0:
    print("\n".join(deck))


Measured memory_bytes: 5596
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String a = sc.next();
        String b = sc.next();
        int cross = 0;
        for(int i = 1; i <= n; i++){
            String b1 = b.substring(0,i);
            if(a.lastIndexOf(b1)+i == a.length()){
                cross = i;
            }
        }
        System.out.println(a.length() + b.length() - cross);
    }
}


Measured memory_bytes: 24916
n, m = map(int, input().split())
lis = []
ans = 0

for _ in range(n):
  A, B = map(int, input().split())
  lis.append((A, B))

lis.sort()

for x in lis:
  a, b = x
  if m >= b:
    m -= b
    ans = ans + (a*b)
  else:
    ans = ans + (a*m)
    break
  
print(ans)
    

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

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

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


int N, M;
int num[10] = {1000000007, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int A[10];
string dp[10001];

bool compare(string s, string t){
    if(s.length() == t.length()){
        return s < t;
    }else{
        return s.length() < t.length();
    }
}

void solve(){
    REP(i, N + 1) dp[i] = "-";
    dp[0] = "";
    REP(i, N + 1){
        REP(j, M){
            if(i - num[A[j]] < 0 || dp[i - num[A[j]]] == "-") continue;
            if(compare(dp[i], dp[i - num[A[j]]] + to_string(A[j]))){
                dp[i] = dp[i - num[A[j]]] + to_string(A[j]);
            }
        }
    }
}

signed main(){
    cin >> N >> M;
    REP(i, M) cin >> A[i];
    sort(A, A + M, greater<int>());
    solve();
    PRINT(dp[N]);
    return 0;
}

Measured memory_bytes: 32896
s = gets.chomp

odd = s.chars.select.with_index(1) { |_, i| i.odd? }
even = s.chars.select.with_index(1) { |_, i| i.even? }

if odd.include?('L') || even.include?('R')
  puts 'No'
else
  puts 'Yes'
end


Measured memory_bytes: 1788
#include <iostream>
#include<bits/stdc++.h>
using namespace std ;
const int INF=1e9+5;
#define  IO cin.tie(0); cin.sync_with_stdio(0)
typedef  long long ll ;


int main(){
    IO;
     int n ;
     cin>>n ;
     ll best_even_begin_not_token=0,best_odd_begin_not_token=0,best_even_begin_token=-INF,best_odd_begin_token=-INF;
     ll arr[n+10];
     for(int i =0 ; i < n ; i++)cin>>arr[i];
     for(int i=n;i<n+6;i++)arr[i]=0;
     for(int i =0 ; i< n ; i+=2){
         ll temp_best_even_begin_not_token=best_even_begin_not_token,temp_best_odd_begin_not_token=best_odd_begin_not_token,
         temp_best_even_begin_token=best_even_begin_token,temp_best_odd_begin_token=best_odd_begin_token;

           best_even_begin_not_token=temp_best_even_begin_not_token+arr[i];
           best_odd_begin_not_token=max(temp_best_odd_begin_not_token,temp_best_even_begin_not_token)+arr[i+1];
           best_even_begin_token=max(temp_best_even_begin_token,temp_best_even_begin_not_token)+arr[i+1];
           best_odd_begin_token=max({temp_best_odd_begin_token,temp_best_even_begin_token,temp_best_odd_begin_not_token})+arr[i+2];
     }
     if(n%2==0)cout<<max(best_even_begin_not_token,best_odd_begin_not_token);
     else cout<<max(best_even_begin_token,best_odd_begin_token);
    return 0;
}


Measured memory_bytes: 5184
using System;

namespace _0008
{
    class Program
    {

        static private int calcAns(int n)
        {
            int cnt = 0;
            for (int a = 0; a < 10; a++)
            {
                for (int b = 0; b < 10; b++)
                {
                    for (int c = 0; c < 10; c++)
                    {
                        for (int d = 0; d < 10; d++)
                        {
                            if(a + b + c + d == n)
                            {
                                cnt++;
                            }
                        }
                    }
                }
            }

            return cnt;
        }

        static void Main(string[] args)
        {
            string temp;
            while((temp = Console.ReadLine()) != null)
            {
                int n = int.Parse(temp);
                Console.WriteLine(calcAns(n));
            }
        }
    }
}



Measured memory_bytes: 17972
#include <iostream>

int main()
{
	long X = 0;
	std::cin >> X;

	long nowYen = 100;
	long answer = 0;
	while (X > nowYen)
	{
		nowYen += nowYen / 100;

		answer++;
	}

	std::cout << answer << "\n";

	return 0;
}

Measured memory_bytes: 3636
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    X = [] # x+y
    Y = [] # x-y
    for i in range(N):
        x,y=mi()
        X.append(x+y)
        Y.append(x-y)
    
    X.sort()
    Y.sort()
    ans = max(X[-1]-X[0],Y[-1]-Y[0])

    print(ans)







if __name__ == "__main__":
    main()

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

using namespace std;
typedef long long ll;

int main(){
    ll K;
    ll sum = 0;
    cin >> K;
    for(int i=1;i<=K;i++){
        for(int j=1;j<=K;j++){
            for(int k=1;k<=K;k++){
                sum += gcd(gcd(i,j),k);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

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

#define M 998244353

int mm[200000], sm[200001];
void init(){
	int c=1;
	sm[0]=0;
	rep(i, 200000){
		mm[i]=c;
		sm[i+1]=(sm[i]+c)%M;
		c=((ll)c*10)%M;
	}
}

int main(){
	init();
	int n, q;
	cin>>n>>q;

	set<P> ps;
	vector<int> md(n);
	int ans=0;

	auto add=[&](int l, int r, int d){
		ans=(ans+(ll)(d+M) *sm[r-l+1]%M *mm[l]%M)%M;
	};
	auto ins=[&](int x, int lr, int d){
		ps.insert(make_pair(x, lr));
		md[x]=d;
	};

	add(0, n-1, 1);
	ins(0, 0, 1);
	ins(n-1, 1, 1);

	rep(_, q){
		int tl, tr, d;
		cin>>tl>>tr>>d;
		int l=n-tr;
		int r=n-tl;

		auto it=ps.lower_bound(make_pair(l, 0));
		int kl=-1, kr;
		vector<set<P>::iterator> dl;
		while(it!= ps.end() && (it->first) <=r){
			if(it->second == 0){
				kl= it->first;
			}
			else{
				kr=it->first;
				if(kl== -1){//right cut
					kl=l;
					ins(l-1, 1, md[kr]);
				}
				add(kl, kr, -md[kr]);
				kl= -1;
			}
			dl.push_back(it);
			it++;
		}
		if(kl != -1){//left cut
			kr=r;
			add(kl, kr, -md[kl]);
			ins(r+1, 0, md[kl]);
		}
		for(auto it : dl) ps.erase(it);

		it=ps.lower_bound(make_pair(r+1, 0));
		if(it!=ps.end() && it->second==1){//middle cut
			int kd= md[it->first];
			add(l, r, -kd);
			ins(l-1, 1, kd);
			ins(r+1, 0, kd);
		}

		add(l, r, d);
		ins(l, 0, d);
		ins(r, 1, d);

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


Measured memory_bytes: 24372
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;

int A,B;
int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> A;
    cin >> B;
    if(B != 100){
        if(A == 0){
            cout << B << endl;
        }else if(A == 1){
            cout << B*100 << endl;
        }else{
            cout << B *10000 << endl;
        }
    }else{
        if(A == 0){
            cout << B+1 << endl;
        }else if(A == 1){
            cout << (B+1)*100 << endl;
        }else{
            cout << (B+1) *10000 << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int i,n,arr[100],res=0;
    cin>>n;
    for(i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    for(i=n-1;i>=0;i--){
        if((n-i)%2) res+=arr[i];
        else res-=arr[i];
    }
    cout<<res<<endl;
    return 0;
}


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

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

    int n;
    cin >> n;
    
    vector<vector<int>> f(n, vector<int>(10));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 10; ++j) cin >> f[i][j];
    }

    vector<vector<int>> p(n, vector<int>(11));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 11; ++j) cin >> p[i][j];
    }
    
    vector<int> open(10);
    vector<int> cnt(10);
    int res = -1001001001;
    for(int i = 1; i < (1<<10); ++i){
        open.assign(10, 0);
        for(int j = 0; j < 10; ++j){
            if(i & (1<<j)) open[j] = 1;
        }
        
        cnt.assign(n, 0);
        for(int j = 0; j < n; ++j){
            int c = 0;
            for(int k = 0; k < 10; ++k){
                c += open[k] & f[j][k];
            }
            cnt[j] = c;
        }

        int reward = 0;
        for(int j = 0; j < n; ++j){
            reward += p[j][cnt[j]];
        }

        res = max(res, reward);
    }

    cout << res << endl;
}

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

public static class Program
{
    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var listA = new List<List<int[]>>();
        for (int i = 0; i < n; i++)
        {
            var a = int.Parse(Console.ReadLine());
            listA.Add(new List<int[]>(Enumerable.Range(0, a)
                .Select(x => Console.ReadLine().Split(' ')
                .Select(y => int.Parse(y)).ToArray())));
        }
        var max = 0;
        for (int i = 0; i < Math.Pow(2, n); i++)
        {
            var ary = new bool[n];
            for (int j = 0; j < n; j++)
            {
                var y = (i >> j) & 1;
                ary[j] = y == 1;
            }
            var katei = ary.Select((val, idx) => new { Index = idx, Value = val })
                .Where(x => x.Value).Select(x => x.Index).ToArray();
            if (katei.Length == 0)
            {
                continue;
            }
            if (ary.Check(katei.Select(x => listA[x]).ToList()))
            {
                max = katei.Length > max ? katei.Length : max;
            }
        }
        Console.WriteLine(max);
    }

    public static bool Check(this bool[] ary, List<List<int[]>> listA)
    {
        foreach (var syougen in listA)
        {
            foreach (var item in syougen)
            {
                if (item[1] == 1)
                {
                    if (!ary[item[0] - 1])
                    {
                        return false;
                    }
                }
                else
                {
                    if (ary[item[0] - 1])
                    {
                        return false;
                    }
                }
            }
        }
        return true;
    }
}

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

int main() {
  string s,t;
  cin>>s>>t;
  string ans="No";
  for(int i=0;i<s.size();i++){
    if(t==s){
      ans="Yes";
    }
    s=s.back()+s.substr(0,s.size()-1);
  }
  cout<<ans<< endl;
}
  

Measured memory_bytes: 256
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;

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


    int n;
    cin >> n;
    map<string, int> a;
    for(int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        ++a[s];
    }
    cout << a.size() << endl;
}

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

long long int a, b, c, x, y, ans;

int main() {
    cin >> a >> b >> c >> x >> y;

    if (x > y)
    {
        ans = min(a+b, 2*c) * min(x, y) + min(a, 2*c) * (x-y);
    } else {
        ans = min(a+b, 2*c) * min(x, y) + min(b, 2*c) * (y-x);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<lol, lol>;
typedef vector<int> vit;

/*
struct SegmentTree{
  
  vector<lol> SumV(1000005,0);
  vector<lol> MaxV(1000005,0);
  vector<lol> MinV(1000005,0);
  int N;
  
  void update(int i,int x){
    i += N - 1;
    minv[i] = x;
    maxv[i] = x;
    sumv[i] = x;
    while(i > 0){
      i = (i - 1)/2;
      maxv[i] = max(maxv[i*2+1],maxv[i*2+2]);
      minv[i] = min(minv[i*2+1],minv[i*2+2]);
      sumv[i] = sumv[i*2+1]+sumv[i*2+2];
    }
  }
  
  void add(int i,int x){
    i += N - 1;
    sumv[i] += x;
    maxv[i] += x;
    minv[i] += x;
    while(i > 0){
      i = (i - 1)/2;
      sumv[i] = sumv[i*2+1]+sumv[i*2+2];
      minv[i] = min(minv[i*2+1],minv[i*2+2]);
      maxv[i] = max(maxv[i*2+1],maxv[i*2+2]);
    }
  }
  
  int getmax(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return -INF;
    if(a <= l && r <= b) return maxv[k];
    else{
      int c1 = getmax(a,b,2*k+1,l,(l+r)/2);
      int c2 = getmax(a,b,2*k+2,(l+r)/2,r);
      return max(c1,c2);
    }
  }
  
  int getmin(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return INF;
    if(a <= l && r <= b) return minv[k];
    else{
      int c1 = getmin(a,b,2*k+1,l,(l+r)/2);
      int c2 = getmin(a,b,2*k+2,(l+r)/2,r);
      return min(c1,c2);
    }
  }
  
  int getsum(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return sumv[k];
    else{
      int c1 = getsum(a,b,2*k+1,l,(l+r)/2);
      int c2 = getsum(a,b,2*k+2,(l+r)/2,r);
      return c1+c2;
    }
  }
}
*/

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}


signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  cout << (n + 999) / 1000 * 1000 - n << '\n';
  return 0;
}


Measured memory_bytes: 3640
length = int(input())
targ = [int(n) for n in input().split(' ')]
ans = 0
for l in range(length):
    value = l
    for init in range(l + 1,length):
        if targ[value] > targ[init]:
            value = init
    if value != l:
        disp = targ[l]
        targ[l] = targ[value]
        targ[value] = disp
        ans += 1
print(' '.join([str(n) for n in targ]))
print(ans)

Measured memory_bytes: 7744
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
int tot = 0;
int a,b;
char ch;
scanf("%d%d",&a,&b);
int out = (a * b) %2;
if(out == 0){
	printf("Even");
	
}else{
	printf("Odd");
}

return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int  n,m,s[1001],i,cut[1001],k,j,sex,max=-1;
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
	scanf("%d",&s[i]);
	cut[i]=0;
	}
	for(i=0;i<m;i++){
	 scanf("%d",&k);
	  for(j=1;j<=n;j++){
	  if(k>=s[j]){
	  cut[j]++;
	  break;
	  }
	 }
}	 
	for(i=1;i<=n;i++){
		if(max<cut[i]){
		 max=cut[i];
		 sex=i;
		 }
		 }
	printf("%d\n",sex);
		return 0;
}

Measured memory_bytes: 1032
//BFS-标程
#include <bits/stdc++.h>
#define MAXN 1000005
#define INF 1e18
#define LL long long
 
int n, m, cnt, head[MAXN], vis[MAXN];
LL l=1, r=INF, root=-1, f[MAXN][5];
 
LL min(LL x, LL y) {if(x>y) return y; return x;}
LL max(LL x, LL y) {if(x<y) return y; return x;}
 
struct Edge{int next, to; LL dis;} edge[MAXN];
 
std::queue<int> q;
 
void addedge(int from, int to, LL dis)
{
	edge[++cnt].next=head[from];
	edge[cnt].to=to;
	edge[cnt].dis=dis;
	head[from]=cnt;
} 
 
void bfs(int x)
{
	vis[x]=1; q.push(x);
	f[x][0]=1; f[x][1]=0;
	while(!q.empty())
	{
		int x=q.front(); q.pop();
		for(int i=head[x]; i; i=edge[i].next)
		{
			int to=edge[i].to;
			if(vis[to]) continue;
			f[to][0]=-f[x][0];
			f[to][1]=edge[i].dis-f[x][1];
			vis[to]=1; q.push(to);
		}
	}
}
 
int main()
{
	scanf("%d%d", &n, &m);
	for(int i=1; i<=m; i++)
	{
		int u, v, s;
		scanf("%d%d%d", &u, &v, &s);
		addedge(u, v, s);
		addedge(v, u, s);
	}
	bfs(1);
	for(int i=1; i<=n; i++)
	{
		if(f[i][0]==1) l=max(l, 1-f[i][1]);
		else r=min(r, f[i][1]-1);
		for(int j=head[i]; j; j=edge[j].next)
		{
			int to=edge[j].to;
			LL x=f[i][0]+f[to][0];
			LL y=f[i][1]+f[to][1];
			if(x==0 && y!=edge[j].dis) {printf("0\n"); return 0;}
			if(x!=0)
			{
				LL temp=edge[j].dis-y;
				if(temp%2 || temp/x<=0) {printf("0\n"); return 0;}
				if(root==-1) root=temp/x;
				if(root!=temp/x) {printf("0\n"); return 0;}
			}
		}
	}
	if(root==-1) printf("%lld\n", max(0, r-l+1));
	else printf("%d\n", (root>=l && root<=r));
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  long long N, x;
  cin >> N >> x;
  vector<long long> a(N);
  for(int i = 0; i < N; i++) cin >> a[i];
  long long ans = 0;
  for(int i = 0; i < N-1; i++){
    long long sum = a[i] + a[i+1];
    ans += max((long long)0, sum - x);
    if(sum - x > 0){
      a[i+1] -= min(a[i+1], sum - x);
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 3980
S = input()
err_flg = False
for i in range(len(S)):
    if i % 2 == 0: # 偶数
        if S[i] == 'L': 
            err_flg = True
            break
    else: # 奇数
        if S[i] == 'R': 
            err_flg = True
            break

if err_flg:
    print('{}'.format('No'))
else:
    print('{}'.format('Yes'))

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

int main(){

	ios::sync_with_stdio(0) ;
	cin.tie(0) ;
	
	string s ;
	cin >> s ;
	
	if(s[0] == s[1] && s[1] == s[2])
    cout << "No" ;
	else
	cout << "Yes" ;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
int main(){
    int H,W;
    cin >> H >> W;
    vector<string> S;
    for(int i=0; i<H; i++){
        string t;
        cin >> t;
        S.push_back(t);
    }
    bool flg = true;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j]=='#'){
                bool tmp = false;
                if(j-1 >= 0 && S[i][j-1]=='#') tmp = true;
                if(i-1 >= 0 && S[i-1][j]=='#') tmp = true;
                if(j+1 < W && S[i][j+1]=='#') tmp = true;
                if(i+1 < H && S[i+1][j]=='#') tmp = true;
                if(!tmp) flg = false;
            }
            
        }
    }
    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

long long gcd(long long a, long long b) {
	return (b == 0) ? a : gcd(b, a % b);
}

long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, m;
	cin >> n >> m;

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

	long long l = lcm(n, m);
	map<long long, char> s_map;
	for (long long i = 0, j = 0; i < l; i += l / n, ++j) {
		s_map[i] = s[j];
	}

	for (long long i = 0, j = 0; i < l; i += l / m, ++j) {
		if (s_map.count(i) && s_map[i] != t[j]) {
			cout << "-1\n";
			return 0;
		}
	}

	cout << l << "\n";

	return 0;

}

Measured memory_bytes: 6144
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;


long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

#define int __int64_t

int used[MAXN];

int is_bipar = 0;

vector <int> g[MAXN];

void dfs(int v) {
    for (int i : g[v]) {
        int inverse = 3 - used[v];
        if (used[i]) {
            if (used[i] != inverse) {
                is_bipar = 0;
            }
            continue;
        }
        used[i] = inverse;
        dfs(i);
    }
}


main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt(), m = readInt();
    for (int i = 1; i <= m; i++) {
        int v = readInt(), u = readInt();
        g[v].pb(u);
        g[u].pb(v);
    }
    int isolated = 0;
    int bipartie = 0;
    int non_bipartie = 0;
    for (int i = 1; i <= n; i++) {
        if (used[i] != 0) continue;
        if (g[i].size() == 0) {
            isolated ++;
            continue;
        } else {
            used[i] = 1;
            is_bipar = 1;
            dfs(i);
            if (is_bipar) {
                bipartie ++;
            } else {
                non_bipartie++;
            }
        }
    }
    cout << 1ll * isolated * isolated + 2 * isolated * (n - isolated) + bipartie * bipartie + (bipartie + non_bipartie) * (bipartie + non_bipartie);
    return 0;
}



Measured memory_bytes: 33792
#include <iostream>
long long int dfs(long long int h)
{
  if (h == 1)
  {
    return 1;
  } else
  {
    
    return 2 * dfs(h / 2) + 1;
  }
  
}

int main()
{
  long long int h;
  std::cin >> h;
  std::cout << dfs(h) << std::endl;
}

Measured memory_bytes: 256
import sys
INF = 10**18

if __name__ == "__main__":
    n,k = map(int,input().split())
    h = list(map(int,input().split()))
    dp = [INF]*n
    dp[0] = 0
    for i in range(1,n):
        c = INF
        for j in range(max(i-k,0),i):
            d = dp[j] + abs(h[j]-h[i])
            c = min(c,d)
        dp[i] = c
    print(dp[-1])

Measured memory_bytes: 52448