akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
#ABC140 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,k = LI()
s = input()
x,y = 0,0
for i in range(1,n):
    if s[i] == s[i-1]:
        x += 1
    else:
        y += 1
print(x + min(y,2*k))


Measured memory_bytes: 39664
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long int ll;
ll N,K;
ll num[100001];
int main(){
  cin >> N >> K;
  set<int> s;
  for(int i=0;i<N;i++){
    int a,b;
    cin >> a >> b;
    s.insert(a);
    num[a]+=b;
  }
  for(set<int> ::iterator itr = s.begin();itr!=s.end();itr++){
    ll n=num[*itr];
    if(K<=n){
      cout << *itr << endl;
      return 0;
    }
    else K-=n;
  }
  
  return 0;
}


Measured memory_bytes: 3968
/******************************************
* AUTHOR :kamesh_11 *
* INSTITUTION : GVPCOE *
******************************************/

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

#define ll long long
#define MOD 1000000007
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bs binary_search
#define endl '\n'
#define start_clock clock_t beginn=clock()
#define end_clock clock_t endd=clock()
#define cal_exec_time double time_spent=(double)(endd-beginn)/CLOCKS_PER_SEC
#define print_exec_time cout<<endl<<time_spent<<" secs"

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

	int n;
	cin>>n;
	int arr[n][3];
	for(int i=0;i<n;i++)
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];

	int dp[n][3];
	dp[0][0]=arr[0][0], dp[0][1]=arr[0][1], dp[0][2]=arr[0][2];

	for(int i=1;i<n;i++){
		dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + arr[i][0];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + arr[i][1];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + arr[i][2];
	}

	cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]));

	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

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

    string s;
    int ans = 0;
    cin >> s;

    if(s[0] == '0' ) {
        for (int i = 0; i < s.length(); i++) {
            if(i%2 == 0){
                if(s[i] == '1') ans++;
            }else{
                if(s[i] == '0' ) ans ++;
            }
        }
    }else{
        for (int i = 0; i < s.length(); i++) {
            if(i%2 == 0){
                if(s[i] == '0') ans++;
            }else{
                if(s[i] == '1' ) ans ++;
            }
        }
    }
    
    cout << ans;
    return 0;
}









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

const int INF = 1e9;

vector<vector<int> > G;

void bfs(int s, vector<int> &d) {
  int N = G.size();
  queue<int> que;
  d.assign(N, INF);
  d[s] = 0;
  que.push(s);
  while (!que.empty()) {
    int u = que.front(); que.pop();
    for (auto&& v : G[u]) {
      if (d[v] == INF) {
        d[v] = d[u] + 1;
        que.push(v);
      }
    }
  }
}

main() {
  int N; cin >> N;
  G.resize(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<int> db, dw;
  bfs(0, db);
  bfs(N - 1, dw);
  int sdb = 0, sdw = 0;
  for (int i = 0; i < N; i++) {
    if (db[i] <= dw[i]) {
      sdb++;
    } else {
      sdw++;
    }
  }
  cout << ( (sdb > sdw) ? "Fennec" : "Snuke" ) << endl;
}

Measured memory_bytes: 6528
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

void main(){
    long n, x;
    readlnTo(n, x);
    auto a = readLongs();
    long ans = long.max;
    auto b = a.dup();
    for(uint i; i < n; ++i) {
        long tmp;
        for(uint j; j < n; ++j) {
            b[j] = min(b[j], a[(j+i)%n]);
        }
        for(uint j; j < n; ++j) {
            tmp += b[j];
        }
        tmp += x*i;
        ans = min(ans, tmp);
    }
    writeln(ans);
}



Measured memory_bytes: 380
#include <iostream>
#include <algorithm>
using namespace std;
int cnt[100005];
int main(){
	int n;
	cin >> n;
	int ai;
	while(n--){
		scanf("%d",&ai);
		cnt[ai-1]++;
		cnt[ai]++;
		cnt[ai+1]++;
	}
	int max=0;
	for(int i=0;i<100005;i++){
		if(cnt[i]>max) max=cnt[i];
	}
	printf("%d\n",max);
	return 0;
}


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

using namespace std;

int main(){
  string s,str;
  cin >> s >> str;
  bool f = true;
  for(int i = 0;i < s.size();i++){
    if(s[i] != str[str.size()-1-i])
      f = false;
  }
  if(f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


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

int main(){
    long long N, K, t, s;
    scanf("%lld %lld", &N, &K);
    if( K % 2 ){
        t = N / K;
        printf("%lld\n" , t * t * t);
    }else{
        t = N / K;
        s = (N + K / 2) / K ;
        printf("%lld\n" , t * t * t + s * s * s);
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int l, r;
        cin >> l  >> r;
        ans += (r - l + 1);
    }
    cout << ans << endl;
}

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

int main(){
	long int N;
	long int count = 1;
	string s;
	
	cin >> N;
	cin >> s;
	
	for(string::iterator it = s.begin() + 1; it != s.end(); ++it){
		 if(*it == *(it - 1)){
		 	continue;
		 } else {
		 	count++;
		 }
	}
	
	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    int K=sc.nextInt();
    long S=sc.nextLong();
    long[] answer=new long[N];
    
    if(S==1000000000){
      for(int i=0;i<K;i++){
        answer[i]=1000000000;
      }
      for(int i=K;i<N;i++){
        answer[i]=1;
      }
    }else{
      for(int i=0;i<K;i++){
        answer[i]=S;
      }
      for(int i=K;i<N;i++){
        answer[i]=1000000000;
      }
    }
    for(int i = 0;i < answer.length;i++){
		if(i > 0)System.out.print(" ");
		System.out.print(answer[i]);
	}
  }
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acos(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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; }

void dfs(string s, char mx, const int &n)
{
	if(s.size() == n)
	{
		cout << s << '\n';
		return;
	}
	else
	{
		for(char c = 'a'; c <= mx; c++)
		{
			dfs(s + c, (c == mx ? (char)(mx + 1) : mx), n);
		}
	}
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n; cin >> n;
	dfs("", 'a', n);
	return 0;
}

Measured memory_bytes: 1536
s = input()
n = len(s)

for i in range(2**(n-1)):
  f = s[0]
  ans = int(s[0])
  for j in range(n-1):
    if i & (1<<j):
      f += '+'
      ans += int(s[j+1])
    else:
      f += '-'
      ans -= int(s[j+1])
    f += s[j+1]
      
  if ans == 7:
    print(f + '=7')
    exit()

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


int K;
vector<int> cand;
vector<int> ans;


int S(int x){
    int res = 0;
    while(x > 0){
        res += x%10;
        x /= 10;
    }
    return res;
}


double g(int x){
    return (double)x/S(x);
}


signed main(){
    cin >> K;

    int p10 = 1, n = 0;
    for(int i = 0;i <= 12;i++){
        for(int j = 1;j <= 999;j++) if(j*p10+n <= 1e15-1) cand.push_back(j*p10+n);
        n *= 10;
        n += 9;
        p10 *= 10;
    }

    sort(begin(cand), end(cand), greater<int>());
    cand.erase(unique(begin(cand), end(cand)), end(cand));

    ans.push_back(cand[0]);
    double m = g(cand[0]);
    for(int i = 1;i < cand.size();i++)
        if(g(cand[i]) <= m) m = g(cand[i]), ans.push_back(cand[i]);

    reverse(begin(ans), end(ans));

    for(int i = 0;i < K;i++) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 512
import sys
#from fractions import Fraction
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def a(s):
	if s.count('.')==0:
		n2=0
		n5=0
		v = int(s)
	else:
		p = s.index('.')
		n2 = -(len(s) - p - 1)
		n5 = -(len(s) - p - 1)
		if p == 1 and s[0]=='0':
			v= int(s[2:])
		else:
			v = int(s[:p]+s[p+1:])
	while v % 2 == 0:
		v = v//2
		n2+=1
	while v % 5 == 0:
		v = v//5
		n5+=1
	return str(n2)+'_'+str(n5)

def main():
	n = int(input())
	#b , c = tin()
	al = [a(input()) for _ in range(n)]
	cal = collections.Counter(al)
	#pa(cal)
	ret = 0
	pp = set()
	for k in cal:
		for k2 in cal:
			if k+'_'+k2 in pp:
				continue
			#pa((vi*vj)/(10**20))
			if k==k2:
				a2, a5 = map(int, k.split('_'))
				if a2>=0 and a5 >= 0:
					ret += cal[k]*(cal[k]-1)//2
			else:
				a2, a5 = map(int, k.split('_'))
				b2, b5 = map(int, k2.split('_'))
				if a2+b2 >= 0 and a5+b5 >= 0:
					ret += cal[k]*cal[k2]
				
			pp.add(k+'_'+k2)
			pp.add(k2+'_'+k)
			#pa((k,k2,ret))
			
	return ret
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 101768
//ProblemB

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

//ProblemB

class Solve {
private:

	bool check(const vector<string>& s, int t) {
		int n = s.size();
		for (int i = 0; i < n; i++) for(int j = 0;j < n; j++){
			if (s[(j + t + n) % n][(i - t + n) % n] != s[i][j]) return false;
		}
		return true;
	}

	void solve() {
		int n;
		cin >> n;

		vector<string> s(n);
		for (int i = 0; i < n; i++) cin >> s[i];

		int cnt = 0;
		for (int t = -(n - 1); t <= n - 1; t++) {
			if (check(s, t)) {
				cnt += n - abs(t);
			}
		}
		cout << cnt << endl;
	}

public:
	Solve() { solve(); }
};

int main(int argc, char* argv[]) {
	unique_ptr<Solve> solve = make_unique<Solve>();
	return 0;
}


Measured memory_bytes: 384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();
        int a = in.nextInt();

        out.println(((n % 500) > a) ? "No" : "Yes");
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 22996
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
constexpr int MX = 2e5+3;
ld a[MX];

int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    int n; ll k; cin >> n >> k;
    // priority_queue<tuple<ld, ld, int>> pq;
    rep(i,n) {
        cin >> a[i];
    }

    ld left = 0.0;
    ld right = 1e10;
    auto f = [&](ld cur, ll total) {
        rep(i,n) {
            total -= ceil(a[i]/cur) - 1;
            // cout << total << endl;
        }
        if(total < 0) return false;
        else return true;
    };
    rep(_, 100) {
        ld mid = (left+right)/2.0;
        if(f(mid, k)) right = mid;
        else left = mid; 
        // cout << left << endl;
    }
    // cout << ceil(left) << endl;
    printf("%ld", (ll)ceil(left));
    return 0;
}


Measured memory_bytes: 6844
#include <iostream>
using namespace std;
int main(void){
    int n;
    string s,t,u[4]={"SS", "SW", "WS", "WW"};
    cin>>n>>s;
    for(int j=0;j<4;j++){
        t=u[j];
        bool f=true;
        for(int i=1;i<n-1;i++){
            if((s[i]=='o'&&t[i]==t[i-1])||(s[i]=='x'&&t[i]!=t[i-1])){
                t+='S';
            }else{
                t+='W';
            }
        }
        for(int i=n-1;i<=n;i++){
            if(t[(i-1+n)%n]==t[(i+1)%n]){
                if((t[i%n]=='S'&&s[i%n]=='x')||(t[i%n]=='W'&&s[i%n]=='o')){
                    f=false;
                }
            }else{
                if((t[i%n]=='S'&&s[i%n]=='o')||(t[i%n]=='W'&&s[i%n]=='x')){
                    f=false;
                }
            }
        }
        if(f){
            cout<<t<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define lli long long int
#define pb push_back

using namespace std;


int main() {
    int n;
    cin>>n;
    
    if(n%10 == 9 || n/10 == 9){
    	cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
    
    return 0;
}


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

ll licm(ll a,ll b) { return a/__gcd(a,b)*b;}
//素因数分解
vector<pair<ll,int>> factorize(ll n){
    vector<pair<ll,int>>res;
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        res.emplace_back(i,0);
        while (n%i == 0)
        {
        n /= i;
        res.back().second++;
        }
        
    }
    if(n != 1) res.emplace_back(n,1);
    return res;
}
ll f(ll x, int c,int d){
    ll res = x;
    res -= x/c;
    res -= x/d;
    res += x/licm(c,d);
    return res;
}

int main(){
    ll A,B,C,D;
    cin >> A >> B >> C >>D;
    ll count =  f(B,C,D) - f(A-1,C,D);
    
    cout << count << endl;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABallDistribution solver = new ABallDistribution();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABallDistribution {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), k = s.nextInt();
            w.println(k == 1 ? 0 : n - k);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

int main() {
  long long l, r;
  cin >> l >> r;

 int  l_mod = l % 2019;
 int  r_mod = r % 2019;

 int val = 2019;

  if ( l_mod >= r_mod){
    cout << 0 << endl;
  } else if ( r - l >= 2019){
      cout << 0 << endl;
  } else if ( r_mod >= 673 && l_mod < 673){
    cout << 0 << endl;
  } else {
    for ( int i = l_mod; i < r_mod; i++){
      for ( int j = i+1; j <= r_mod; j++){
        val = min(val, i * j % 2019);
      }
    }
    cout << val << endl;
  }
  return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let s: Vec<char> = input::<String>().chars().collect();
    let x: i64 = input();
    let y: i64 = input();

    let mut dx = vec![vec![0]; 2];
    let mut dir = 0;
    let mut cnt = 0;
    for &c in &s {
        if c == 'F' {
            cnt += 1;
        } else {
            dx[dir].push(cnt);
            dir = 1 - dir;
            cnt = 0;
        }
    }
    if cnt > 0 {
        dx[dir].push(cnt);
    }

    let mut start = vec![0, 0];
    if s[0] != 'T' {
        start[0] += dx[0][1];
        dx[0].remove(1);
    }

    let n = std::cmp::max(dx[0].len(), dx[1].len());
    let mut dp = vec![vec![vec![false; 16010]; n + 1]; 2];
    for &dir in &[0, 1] {
        dp[dir][0][8000 + start[dir]] = true;
        for i in 1..dx[dir].len() {
            for x in 0..16010 {
                if !dp[dir][i - 1][x] {
                    continue;
                }

                dp[dir][i][(x + dx[dir][i]) as usize] = true;
                dp[dir][i][(x - dx[dir][i]) as usize] = true;
            }
        }
    }

    let ok =
        dp[0][dx[0].len() - 1][(8000 + x) as usize] && dp[1][dx[1].len() - 1][(8000 + y) as usize];
    println!("{}", if ok { "Yes" } else { "No" });
}


Measured memory_bytes: 166140
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from typing import Iterable, List
import sys
def main(N, M, AB):
    uf = UnionFindTree(N)
    for a, b in AB:
        a, b = a - 1, b - 1
        uf.union(a, b)
    print(len(uf.groups()) - 1)

class UnionFindTree:
    __slots__ = ('parent')

    def __init__(self, n: int) -> None:
        self.parent = [-1] * n

    def find(self, x: int) -> int:
        p = self.parent
        while p[x] >= 0: x, p[x] = p[x], p[p[x]]
        return x

    def union(self, x: int, y: int) -> bool:
        x, y, p = self.find(x), self.find(y), self.parent
        if x == y: return False
        if p[x] > p[y]: x, y = y, x
        p[x], p[y] = p[x] + p[y], x
        return True

    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)

    def size(self, x: int) -> int:
        return -self.parent[self.find(x)]

    def same_all(self, indices: Iterable[int]) -> bool:
        f, v = self.find, self.find(indices[0])
        return all(f(i) == v for i in indices)

    def groups(self) -> List[int]:
        return [i for i, p in enumerate(self.parent) if p < 0]

if __name__ == '__main__':
    input = sys.stdin.readline
    N, M = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in range(M)]
    main(N, M, AB)


Measured memory_bytes: 84736
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  int r = 0;
  int b = 0;
  for(int i = 0; i < n; i++) {
    cin >> s[i];
    if(s[i] == 'R') r++;
    else b++;
  }
  cout << ((r > b) ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long long n, a[10000];
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  cout << *min_element( a, a + n) << " "
       << *max_element( a, a + n) << " "
       << accumulate( a, a + n, 0LL) << endl;
}


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

#define ll long long

using namespace std;

int n;
map<string, int> m;
ll sol;

int main() {
    cin >> n;
    for(int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        if (m.count(s))
            m[s]++;
        else
            m.insert({s, 1});
    }

    for (auto kv : m)
        sol += ((ll)kv.second) * (kv.second - 1) / 2;

    cout << sol;
    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e3+5;
const int mod=1e9+7;

ll n,y,m,t,k,ans,cnt,mini=N,flag;

ll a[505][505],b[505][505],c[505][505];
double dp[N],p;
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin>>n;
    dp[0]=1;
	for(int i=1;i<=n;i++){
		cin>>p;
		for(int j=i;j>=0;j--)
			dp[j]=(j==0?0:dp[j-1]*p)+dp[j]*(1-p);
	}

	double ans=0;
	for(int i=0;i<=n;i++)
		if(i>n-i)
        ans+=dp[i];

	cout<<fixed<<setprecision(10);
	cout<<ans<<"\n";
}


Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
//to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

bool ABC(int n) {
	if (0 < n && n < 13) {
		return true;
	}
	else {
		return false;
	}
}

int main(void) {

	int n;
	cin >> n;
	llint sum = 0;
	rop(i, n) {
		if (i % 3 == 0 || i % 5 == 0) {

		}
		else if (i % 3 == 0 && i % 5 == 0) {

		}
		else {
			sum += i;
		}
	}
	cout << sum << rt;

	please AC;
}
//参考：---


Measured memory_bytes: 3640
#include<stdio.h>
#include<string.h>
int main()
{
	int a,b,c;
	char n[10003];
	scanf("%d%s",&a,&n);
	for(int i=0;i<strlen(n);i++)
	{
		n[i]=n[i]+a;
		if((n[i]-'A')>=26)
		{
			n[i]='A'+(n[i]-'A')%26;
		}
		printf("%c",n[i]);
	}
	return 0;
}



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

int main(){
	int a,b,c;
	int ans;
	bool flg;
	int cnt=-1;
	
	while(cin>>a>>b){
		cnt++;flg=false;
		//-----test-----
		switch(cnt){
		case 0:
			if(b!=0) flg=true; 
			break;
		}
		
		if(flg) break;
		
		//--------------
		c=a+b;
		ans=1;
		while(10<=c){
			c/=10;
			ans++;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner cro=new Scanner(System.in);
int i,j;
long sum;
int n=cro.nextInt();
int a[][]=new int[n-1][3];
for(i=0;i<n-1;i++)
{
a[i][0]=cro.nextInt();
a[i][1]=cro.nextInt();
a[i][2]=cro.nextInt();
}
for(j=0;j<n-1;j++)
{
sum=a[j][0]+a[j][1];
for(i=j+1;i<n-1;i++)
{
if(a[i][1]>sum)
{
sum=a[i][1];
}
if(sum%a[i][2]!=0)
{
sum=sum+(a[i][2]-sum%a[i][2]);
}
sum=sum+a[i][0];
}
System.out.println(sum);
}
System.out.println(0);
}
}


Measured memory_bytes: 26748
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Set<String> s = new HashSet<>();

        while (sc.hasNext()) {
            s.add(sc.next());
        }

        System.out.println(s.size());
    }
}


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

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

    return 0;
}

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

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

  float total = 0;

  for(int i = 0; i < n; i++){
    float value;
    string name;
    cin >> value >> name;
    if(name == "JPY"){
      total += value;
    }else{
      total += value * 380000;
    }
  }

  cout << total << endl;

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int Mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

void f()
{
    int n,x,cnt=0;
    cin>>n>>x;
    int a[n+2]= {0};
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        a[i]=a[i]+a[i-1];
    }
    for(int i=0; i<=n; i++)
    {
        if(a[i]<=x)
            cnt++;
    }
    cout<<cnt<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3620
import sys
input=sys.stdin.readline

N=int(input())
H=list(map(int,input().split()))
m=H[0];c=0
for i in range(0,N):
  if (H[i]>=H[0])and(H[i]>=m):
    c+=1
    m=max(H[0],H[i])
print(c)

Measured memory_bytes: 3060
import sys

X, N = map(int, sys.stdin.readline().strip().split())
P = list(map(int, sys.stdin.readline().strip().split()))

i = 0
while True:
    ans = X - i
    if ans not in P:
        break

    ans = X + i
    if ans not in P:
        break

    i += 1

print(ans)


Measured memory_bytes: 9140
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <numeric>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;

  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  
  int ans = 1e9;
  for (int i = -100; i <= 100; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      sum += (a[j] - i) * (a[j] - i);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, s, N) for(ll i{N - 1}; i > s - 1; i--)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

int main(){
  kyopro;
  ll N;
  cin >> N;
  ll sum{};
  ll night{};
  ll mini{1000000000};
  rep(j, 0, N){
    ll i;
    cin >> i;
    if(i < 0){
      i *= -1;
      night++;
    }
    mini = min(mini, i);
    sum += i;
  }
  if(night % 2) cout << -mini * 2 + sum << rt;
  else cout << sum << rt;
}

Measured memory_bytes: 256
/*in the name of Allah the most beneficent the most merciful.*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
#define base 139
// #define MOD 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define out(x) cout << #x << " -> " << x << endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE   freopen("input.txt", "r", stdin);  freopen("out.txt", "w", stdout);
using namespace std;
const ll B = 20, N = 300010, M = 2000000;
string s;
int solve()
{
    cin>>s;
    if(s=="AAA" || s=="BBB")
        printf("No\n");
    else printf("Yes\n");
    return 0;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    return solve();
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
#define MAXN 20
char s[MAXN + 1];
int main()
{
	int n;
	
	scanf("%s", s);
	n = strlen(s);
	while(n > 0) {
		n--;
		putchar(s[n]);
	}
	putchar('\n');
	
	return 0;
}

Measured memory_bytes: 524
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt(), x = sc.nextInt(), y = sc.nextInt(), sum = 0;
        
        if (n<k) {
            sum = n*x;
        } else {
            sum = (k*x) + (n-k)*y;
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 21844
<?php

fscanf(STDIN, "%d %d %d", $n, $a, $b);
$v = explode(" ", fgets(STDIN));
array_unshift($v, 0);

//動的計画法を使う
$dp = [];

//初期化 0 <= $i, $j <= $n の範囲を 最大値0, 個数0 で埋める
for ($i = 0; $i <= $n; $i++) {
	for ($j = 0; $j <= $n; $j++) {
		$dp[$i][$j] = [0, 0]; // [最大値, 個数];
		if ($j === 0) {
			$dp[$i][$j] = [0, 1];
		}
	}
}

for ($i = 1; $i <= $n; $i++) {
	$current = (int)$v[$i];
	for ($j = 1; $j <= $i; $j++) {
		if ($dp[$i - 1][$j][0] > $dp[$i - 1][$j - 1][0] + $current) {
			// i-1番目までの品物からj個選んだときの最大値のほうが
			// i-1番目までの品物からj-1個選んだときの最大値に今見ている品物の価値を足したものより
			// 大きい
			$dp[$i][$j] = $dp[$i - 1][$j];
			continue;
		}
		if ($dp[$i - 1][$j][0] < $dp[$i - 1][$j - 1][0] + $current) {
			// i-1番目までの品物からj個選んだときの最大値のほうが
			// i-1番目までの品物からj-1個選んだときの最大値に今見ている品物の価値を足したものより
			// 小さい
			$dp[$i][$j] = [$dp[$i - 1][$j - 1][0] + $current, $dp[$i - 1][$j - 1][1]];
			continue;
		}
		// i-1番目までの品物からj個選んだときの最大値と
		// i-1番目までの品物からj-1個選んだときの最大値に今見ている品物の価値を足したものと
		// 等しい
		$dp[$i][$j] = [$dp[$i - 1][$j][0], $dp[$i - 1][$j][1] + $dp[$i - 1][$j - 1][1]];
	}
}

$max = 0;
$comb = 0;
for ($num = $a; $num <= $b; $num++) {
	$mean = $dp[$n][$num][0] / $num;
	if ($mean > $max) {
		$max = $mean;
		$comb = $dp[$n][$num][1];
		continue;
	}
	if ($mean === $max) {
		$comb += $dp[$n][$num][1];
	}
}

echo $max, "\n", $comb, "\n";


Measured memory_bytes: 4728
#include "iostream"
#include "stdio.h"
#include "math.h"
#include<algorithm>//排序sort()
#include "vector"
#include "cstring" //strcmp
#include "string"
#include "set"
#include "stack"
#include "vector"
#include "map"
#include "queue"
using namespace std;
const int maxn= 100005;

int main()
{
    int h[maxn],dp[maxn];
    int num;
    scanf("%d",&num);
    for (int i = 0; i < num; ++i) {
        scanf("%d",h+i);
    }
    dp[num - 1]=0;
    dp[num - 2]=abs(h[num-2] -h[num - 1]);
    for (int i = num -3; i >= 0 ; --i) {
        dp[i] = min(dp[i+1] + abs(h[i] - h[i + 1]),dp[i + 2] + abs(h[i+2] - h[i]));
    }
    cout<<dp[0];
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,M;
  cin >> N >> M;
  ll a[2020],b[2020],c[2020];
  ll dp[1010];
  const ll INFA =1LL<<50;
  for(int i=0;i<1010;i++){
      dp[i]=INFA;
  }
  ll p,q,r;
  for(int i=0;i<M;i++){
    cin >> p >> q >> r;
    p--;
    q--;
    r=-r;
    a[i]=p;
    b[i]=q;
    c[i]=r;
  }
  dp[0]=0;
  for(int i=0;i<N-1;i++){
    for(int j=0;j<M;j++){
      if(dp[a[j]]==INFA)continue;
      if(dp[b[j]]>dp[a[j]]+c[j]){
        dp[b[j]]=dp[a[j]]+c[j];
      }
    }
  }

  ll distance=dp[N-1];

  for(int i=0;i<N-1;i++){
    for(int j=0;j<M;j++){
      if(dp[a[j]]==INFA)continue;
      if(dp[b[j]]>dp[a[j]]+c[j]){
        dp[b[j]]=dp[a[j]]+c[j];
      }
    }
  }
  ll ans=dp[N-1];

  if(ans!=distance){
    cout << "inf" << endl;
  }else{
    cout << -distance << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
    using namespace std;
    #define pii pair<int,int>
    #define fir first
    #define sec second
    #define MP make_pair
    #define rep(i,x,y) for (int i=(x);i<=(y);i++)
    #define drep(i,x,y) for (int i=(x);i>=(y);i--)
    #define go(x) for (int i=head[x];i;i=edge[i].nxt)
    #define templ template<typename T>
    #define sz 101001
    typedef long long ll;
    typedef double db;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
    templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
    templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
    templ inline void read(T& t)
    {
        t=0;char f=0,ch=getchar();double d=0.1;
        while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
        while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
        if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
        t=(f?-t:t);
    }
    template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
    char __sr[1<<21],__z[20];int __C=-1,__zz=0;
    inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
    inline void print(register int x)
    {
        if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
        while(__z[++__zz]=x%10+48,x/=10);
        while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
    }
    void file()
    {
        #ifdef NTFOrz
        freopen("a.in","r",stdin);
        #endif
    }
    inline void chktime()
    {
        #ifndef ONLINE_JUDGE
        cout<<(clock()-t)/1000.0<<'\n';
        #endif
    }
    #ifdef mod
    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
    ll inv(ll x){return ksm(x,mod-2);}
    #else
    ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
    #endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n,m;
int sum1[sz],sum2[sz];
char s1[sz],s2[sz];

int main()
{
    file();
	cin>>(s1+1)>>(s2+1);
	n=strlen(s1+1),m=strlen(s2+1);
	rep(i,1,n) sum1[i]=sum1[i-1]+1+(s1[i]=='B');
	rep(i,1,m) sum2[i]=sum2[i-1]+1+(s2[i]=='B');
	int Q;read(Q);
	while (Q--)
	{
		int l1,r1,l2,r2;
		read(l1,r1,l2,r2);
		int S1=sum1[r1]-sum1[l1-1],S2=sum2[r2]-sum2[l2-1];
		if (S1%3==S2%3) puts("YES");
		else puts("NO");
	}
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi l(n), r(n);
	rep(i, n) cin >> l[i] >> r[i];
	
	ll ans = 0;
	map<ll, int> left, right;
	ll ofsL = r[0], ofsR = r[0];
	left[0] = right[0] = 1;
	
	for(int i = 1; i < n; i++){
		ofsL += l[i - 1] - r[i - 1];
		ofsR += r[i] - l[i];
		
		ll a = ofsL + left.rbegin()->first;
		ll b = ofsR + right.begin()->first;
		
		if(a <= r[i] && r[i] <= b){
			++left[r[i] - ofsL];
			++right[r[i] - ofsR];
		}
		else if(r[i] < a){
			ans += a - r[i];
			
			++left[r[i] - ofsL];
			++left[r[i] - ofsL];
			
			if(--left[a - ofsL] == 0) left.erase(a - ofsL);
			++right[a - ofsR];
		}
		else{
			ans += r[i] - b;
			
			++right[r[i] - ofsR];
			++right[r[i] - ofsR];
			
			if(--right[b - ofsR] == 0) right.erase(b - ofsR);
			++left[b - ofsL];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 13568
//IrohasObsession.cpp (C)
#include <iostream>
using namespace std;

int main(){
  int N,K;
  cin >> N >> K;
  int A[10] = {0};
  for(int i = 0; i < K; i++){
    int a;
    cin >> a;
    A[a] = 1;
  }

  for(int i = N; i <= 10*N; i++){
    int x = i;
    while(A[x%10]==0&&x!=0){
      x /= 10;
    }
    if(x == 0){
      cout << i << endl;
      return 0;
    }
  }

}


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

using namespace std;

int A, B;
char s[12];
int main() {
	cin >> A >> B;
	cin >> s;
	for (int i = 0; i < A; i++) {
		if (!('0' <= s[i] && s[i] <= '9'))
		{
			puts("No");
			return 0;
		}
		if (s[A] != '-') {
			puts("No");
			return 0;
		}
	}
	for (int i = A + 1; i <= A + B; i++) {
		if (!('0' <= s[i] && s[i] <= '9'))
		{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>

int main() {
    char str[1001];
    
    while(1){
        scanf("%s", str);
        if(str[0] == '0') break;
        int sum = 0;
        for (int i = 0;i < strlen(str);i++){
            sum += (str[i] - '0');
        }
        
        printf("%d\n", sum);
    }
    
    return 0;
}

Measured memory_bytes: 2712
#include <stdio.h>
#include <string.h>
#include <stdint.h>


int main(int argc, char const* argv[])
{
  int64_t N, M, C;
  scanf("%ld %ld %ld", &N, &M, &C);
  int64_t Bs[M];
  for (int i = 0; i < M; i++) {
    scanf("%ld%*c", &Bs[i]);
  }

  int64_t temp, sum = 0, ctr = 0;
  for (int i = 0; i < N; i++, sum = 0) {
    for (int k = 0; k < M; k++) {
      scanf("%ld%*c", &temp);
      temp *= Bs[k];
      sum += temp;
    }
    if (sum + C > 0) 
      ctr++;
  }

  printf("%ld\n", ctr);
  return 0;
}


Measured memory_bytes: 128
/* is_bipartite.cpp
    二部グラフ判定を深さ優先探索（DFS）で行う

    not verified: AtCoder CODE FESTIVAL 2017 qual B  C - 3 Steps
        https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_c
*/
#include <bits/stdc++.h>
using namespace std;

struct Edge {
    long long to;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, long>;

bool dfs(const Graph &G, int v, int c, P &num, vector<int> &color) {
    bool ret = true;
    color[v] = c;
    if (c == 1) {
        num.first++;
    } else if (c == -1) {
        num.second++;
    }
    for (auto e : G[v]) {
        if (color[e.to] == 0 && !dfs(G, e.to, -c, num, color)) {
            ret = false;
        } else if (color[e.to] == c) {
            ret = false;
        }
    }
    return ret;
}

/* is_bipartite(G,nums): 二部グラフかどうか判定
    副作用：
        nums[i] := i 番目の連結成分の {左ノード数, 右ノード数}とする c = 1: 左、-1: 右」
*/
bool is_bipartite(const Graph &G, vector<P> &nums) {
    bool ret = true;
    int N = G.size();
    vector<int> color(N, 0);
    for (int i = 0; i < N; i++) {
        if (color[i] == 0) {
            P num = {0, 0};
            if (!dfs(G, i, 1, num, color)) {
                ret = false;
            }
            nums.push_back(num);
        }
    }
    return ret;
}

int main() {
    long long N, M;
    cin >> N >> M;
    Graph G(N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back({b});
        G[b].push_back({a});
    }

    vector<P> nums;
    if (is_bipartite(G, nums)) { // 完全二部グラフ
        long long ans = 0;
        for (auto i : nums) {
            ans += i.first * i.second;
        }
        cout << ans - M << endl;
    } else { // 完全グラフ
        cout << N * (N - 1) / 2 - M << endl;
    }
    return 0;
}


Measured memory_bytes: 8448