akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, m, c) = readLongList()
    val bList = readLongList()
    var ans = 0
    repeat(n.toInt()) {
        val aList = readLongList()
        val tmp = aList.zip(bList).fold(0L) { acc, p -> acc + p.first * p.second } + c
        if (tmp > 0) ans++
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36724
// 部分和：再帰bit全探索

#include <bits/stdc++.h>
using namespace std;
int main(){
    int D, G, p[11], c[11];
    cin >> D >> G;
    for(int i = 0; i < D; ++i){
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask >> i & 1){ // maskのi番目のフラグが立っているとき
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{ // フラグが立っていないとき
                rest_max = i;
            }
        }
        if(s < G){ // スコアが足りないとき
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1; // 残りスコアに必要な問題数
            if(need >= p[rest_max]){ // 問題数がそもそもあるか
                continue;
            }
            num += need; // スコアが到達した時の総問題数
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

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

  vector<pair<int, int> > a(n);

  rep(i, n){
    cin >> a[i].first;
    a[i].second = i;
  }
  
  sort(a.begin(), a.end());

  rep(i, n){
    cout << a[i].second + 1 << ' ';
  }

  cout << endl;


}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]==s[s.length()-1])
    {
        if(s.length()%2==1) cout <<"Second\n";
        else cout <<"First\n";
    }
    else
    {
        if(s.length()%2==0) cout <<"Second\n";
        else cout <<"First\n";
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int MX = 1e6 + 5;
 
int n, A[MX];
bool ok = true;
set<int> found;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	rep(i, 0, MX) A[i] = -1;
	rep(i, 2, MX) {
		if (A[i] == -1) {
			for (int j = i; j < MX; j += i) {
				if (A[j] == -1) {
					A[j] = i;
				}
			}
		}
	}
	
	cin >> n;
	int GCD;
	rep(i, 0, n) {
		int a; cin >> a;
		if (!i) GCD = a;
		else GCD = __gcd(GCD, a);
		set<int> tmp;
		while (a > 1) {
			tmp.insert(A[a]);
			a /= A[a];
		}
		for (auto j : tmp) {
			if (found.find(j) != found.end()) ok = false;
			found.insert(j);
		}
	}
	
	if (ok) cout << "pairwise coprime";
	else if (GCD == 1) cout << "setwise coprime";
	else cout << "not coprime";
}


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

int main() {
  int n;cin>>n;
  int ans=0;
  for(int i=1;i<=n;i++){
    if(i*i>n)break;
    ans=max(ans,i*i);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3612
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        long Y = sc.nextLong();
        long ans = 0;
        while(true){
            if(X <= Y){
                ans++;
                X *= 2;
            }else{
                break;
            }
        }
        System.out.println(ans);
    }
}

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

using namespace std;

#define N 200000

vector<int> g[N + 1];
int dist[N + 1];

void bfs(int x){
	queue<int> q;
	int u, v, i;

	memset(dist, -1, sizeof(dist));

	dist[x] = 0;
	q.push(x);

	while (!q.empty()){
		u = q.front();
		q.pop();

		for (i = 0; i < (int)g[u].size(); i++){
			v = g[u][i];

			if (dist[v] == -1){
				dist[v] = dist[u] + 1;

				q.push(v);
			}
		}
	}
}

int main(){
	int n, m, a, b, i;

	scanf("%d%d", &n, &m);

	for (i = 0; i < m; i++){
		scanf("%d%d", &a, &b);

		g[a].push_back(b);
		g[b].push_back(a);
	}

	bfs(1);

	printf("%s\n", dist[n] == 2 ? "POSSIBLE" : "IMPOSSIBLE");

	return 0;
}

Measured memory_bytes: 13168
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    string S;
    cin>>S;
    ll N=S.size();
    bool YES=true;
    rep(i,N) if(S.at(i)!=S.at(N-1-i)) YES=false;
    rep(i,(N-3)/2) if(S.at(i)!=S.at((N-3)/2-i)) YES=false;
    rep(i,(N-3)/2) if(S.at((N+1)/2+i)!=S.at(N-1-i)) YES=false;
    
    if(YES) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String s = sc.next();
		int[] countAC = new int[n];

		for (int i = 1; i < countAC.length; i++) {
			if (String.valueOf(s.charAt(i)).equals("C") && String.valueOf(s.charAt(i - 1)).equals("A")) {
				countAC[i] = countAC[i-1] + 1;

			} else {
				countAC[i] = countAC[i-1];
			}
			//System.out.println("count"+i +"="+ countAC[i]);
		}

		//01234567
		//ACACTACG
		//01122233
		for (int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = countAC[r - 1] - countAC[l-1];
			System.out.println(ans);
		}
	}
}



Measured memory_bytes: 69112
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long int ll;


int main()
{
	string s,t;
	cin>>s;
	cin>>t;
	bool ans = true;
	for(int i = 0 ; i < s.length(); i++){
		if( s[i] != t[i]){
			ans = false;
		}
	}
	if( ans == true && s.length() + 1 == t.length()){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3628
/**
* Motto:   fight till end
* Author: fyter_112
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define mod 1000000007
int32_t main()
{
  fast;
  int t;
  int n;
  cin>>n;
  int c=0;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    c=c^a[i];
  }
  int d=c;
  for(int i=0;i<n;i++)
  {
    a[i]=c^a[i];
    c=d;
    cout << a[i] <<" ";
  }
}


Measured memory_bytes: 5156
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

const int maxn = 1e5 + 5;

int main() {
    int n;
    cin>>n;
    cout<<999-((n-1)%1000);
    return 0;
}

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

int main() {
	int H,W; cin >> H >> W;
	vector<string> fig(H);
	for(string &k : fig){
		string M;
		cin >> M;
		M.insert(M.begin(),'.');
		M.push_back('.');
		k = M; 
	}
	string S;
	for(int i = 0 ; i < W + 2 ; i++) S += '.';
	fig.insert(fig.begin() , S);
	fig.push_back(S);
	
	for(int i = 1 ; i < H + 1 ; i++){
		for(int j = 1 ; j < W + 1 ; j++){
			if(fig[i][j] == '#'){
				if(
				fig[i+1][j] == '.' &&
				fig[i][j+1] == '.' &&
				fig[i-1][j] == '.' &&
				fig[i][j-1] == '.' 
				){
				cout << "No" << endl;
				return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<cstdio>
using namespace std;
int main(){
  map<string, int> m;
  char s[3];
  int i;

  while(scanf("%d,%s",&i,s)!=EOF)
    m[string(s)]++;

  cout << m["A"] << endl << m["B"] << endl << m["AB"] << endl << m["O"] << endl;

}

Measured memory_bytes: 0
import java.util.*;
import java.util.stream.*;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] x = new int[N];
		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
		}

		int ans = 0;
		for (int i = 0; i < N; i++) {
			if (x[i] < K - x[i]) {
				ans += x[i] * 2;
			} else {
				ans += (K - x[i]) * 2;
			}
		}
		System.out.println(ans);
	}
}


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

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

#define fr first
#define sc second

int main(){
	static int n;
	static int a[100010];
	scanf("%d",&n);
	a[0] = a[n+1] = 0;
	for(int i = 1 ; i <= n ; i ++){
		scanf("%d",&a[i]);
	}
	
	static int ret = 0;
	for(int i = 0 ; i <= n ; i ++){
		ret += abs(a[i+1]-a[i]);
	}
	for(int i = 1 ; i <= n ; i ++){
		if((a[i-1]-a[i])*(a[i+1]-a[i]) <= 0){
			printf("%d\n",ret);
		}
		else {
			printf("%d\n",ret-2*min(abs(a[i-1]-a[i]),abs(a[i+1]-a[i])));
		}
	}
}



Measured memory_bytes: 1664
n = gets.chomp.to_i
r = []
n.times do
  r << gets.chomp.to_i
end
maxv = r[1] - r[0]
minv = r[0]
(1..n-1).each do |i|
  maxv = [maxv, r[i] - minv].max
  minv = [minv, r[i]].min
end

puts maxv

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

#define ll long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (ll)1000000007
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 0x3f3f3f3f
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 500005

int main(){
sp;
int a[3];
for(int i=0;i<3; ++i)cin>>a[i];
sort(a,a+3);
cout<<(a[0]*a[1])/2;
return 0;}


Measured memory_bytes: 256
/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = numeric_limits <int>::max())
{return uniform_int_distribution<int> (l, r)(rng);}

template <typename T, typename G>
ostream& operator << (ostream& out, const pair <T, G> &a) 
{return out << "( " << a.x << ", " << a.y << ")";}

template <typename T>
ostream& operator << (ostream& out, const vector <T> &a) 
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

template <typename T>
ostream& operator << (ostream& out, const set <T> &a) 
{out << "{ "; for(const auto &i: a) out << i << ", "; return out << "}" << endl;}

template <typename T, typename G>
ostream& operator << (ostream& out, const map <T, G> &a) 
{out << "< "; for(const auto &i: a) out << i << ", "; return out << ">" << endl;}

template <typename T, size_t N>
typename enable_if<!is_same <typename remove_cv <T>::type, char>::value,
ostream&>::type operator << (ostream& out, T (&a)[N])
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

void debug_out(){cerr << endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr << (H) << ' '; debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr << '#' << #__VA_ARGS__ << ":\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

const int mod = 1e9 + 7;
int md(int x, int mdo = mod) {
	x %= mdo;
	return x < 0? x + mdo: x;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector <int> a(n);
	for (auto &i : a) 
		cin >> i;
	sort(a.begin(), a.end());
	int ans = 1;
	if (a[n - 1] == 0 && (k & 1)) {
		ans = 0;
	} else if (a[n - 1] <= 0 && (k & 1)) {
		for (int i = n - 1; i >= n - k; --i){
			ans = md(ans * md(a[i]));
		} 
	} else {
		int i = 0, j = n - 1;
		if (k & 1)
			ans = md(ans * a[j--]);
		k /= 2;
		for (int l = 0; l < k; ++l) {
			int left = a[i] * a[i + 1];
			int right = a[j] * a[j - 1];
			if (left > right) {
				ans = md(ans * md(left));
				i += 2;
			} else {
				ans = md(ans * md(right));
				j -= 2;
			}
		} 
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4804
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v, w; };

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

ll MOD = 1000000007;
ll _MOD = 1000000009;
ll e10 = 1e10 + 10;
double EPS = 1e-10;

int main() {
	string s; cin >> s;
	int N = s.length();
	int cnt = 0;
	rep(i, N - 1) if (s[i] != s[i + 1]) cnt++;
	cout << cnt << endl;
}


Measured memory_bytes: 512
//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
static constexpr double PI = 3.1415926535897932;

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

template <typename T>
auto scan(T &d) ->
typename std::enable_if<std::is_same<T, std::string>::value>::type {
	d = std::string();
	int c = 0;
	while (c < 'a' || 'z' < c)
		c = fgetc(stdin);
	while ('a' <= c && c <= 'z') {
		d.push_back(c);
		c = fgetc(stdin);
	}
}
template <typename T>
auto scan(T &d) ->
typename std::enable_if<std::is_same<T, double>::value>::type {
	scanf("%lf", &d);
}
template <typename T>
auto scan(T &d) ->
typename std::enable_if<std::is_signed<T>::value ==
	std::is_same<T, std::string>::value>::type {
	d = 0;
	int c = 0;
	while (c < '0' || '9' < c)
		c = fgetc(stdin);
	while ('0' <= c && c <= '9') {
		d = d * 10 + c - '0';
		c = fgetc(stdin);
	}
}
template <typename T>
auto scan(T &d) ->
typename std::enable_if<std::is_signed<T>::value !=
	std::is_same<T, double>::value>::type {
	d = 0;
	int c = 0;
	bool f = 0;
	while (c < '0' || '9' < c) {
		if (c == '-')
			f = 1;
		c = fgetc(stdin);
	}
	while ('0' <= c && c <= '9') {
		d = d * 10 + c - '0';
		c = fgetc(stdin);
	}
	if (f)
		d = -d;
}

int main(void)
{
	uint32 n, a, b;
	scan(n);scan(a);scan(b);
	if (n + 1 < a + b) {
		puts("-1");return 0;
	}
	if (n + 1 == a + b) {
		printf("%u", b);
		for (uint32 i = b - 1;i;--i) {
			printf(" %u", i);
		}
		for (uint32 i = b + 1;i <= n;++i) {
			printf(" %u", i);
		}
		printf("\n");return 0;
	}
	if (a*b < n) {
		puts("-1");return 0;
	}
	uint32 m = n;
	m -= b;
	m -= a - 1;
	uint32 fb = m / (b - 1);
	uint32 d = m % (b - 1);
	std::vector<uint32> ans(n);
	uint32 itr = 0;
	for (uint32 i = 0;i < b;++i) {
		ans[itr++] = b - i;
	}
	for (uint32 i = 1;i <= fb;++i) {
		for (uint32 j = 0;j < b;++j) {
			ans[itr++] = (i + 1)*b - j;
		}
	}
	if (d != 0) {
		for (uint32 i = 0;i <= d;++i) {
			ans[itr++] = (fb + 1)*b + (d + 1 - i);
		}
	}
	uint32 pitr = itr;
	while (itr < n) {
		ans[itr] = itr + 1;
		++itr;
	}
	printf("%u", ans[0]);
	for (uint32 i = 1;i < n;++i) {
		printf(" %u", ans[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 4352
/*
  Reference:-
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<int,int>
#define all(vec) vec.begin(),vec.end()
ll mod=1000000007;

int main(){
    std::ios::sync_with_stdio(false);
    //string s1,s2;
    int n,k;
    cin>>n>>k;
    int ar[n];
    forn(i,n)cin>>ar[i];
    sort(ar,ar+n);
    int dp[k+1];
    forn(i,k+1)dp[i]=-1;
    dp[ar[0]]=1;
    for(int i=ar[0]+1;i<k+1;i++){
        int one=0,two=0;
        forn(j,n){
            int dif=i-ar[j];
            if(dif<0)break;
            if(dp[dif]==1)two++;
            if(dp[dif]==2||dp[dif]==-1)one++;
        }
        if(one>0)dp[i]=1;
        else dp[i]=2;
    }
    cout<<((dp[k]==1)? "First":"Second");

    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			long mod = (long)1e9+7;
			int N = scan.nextInt();
			int K = scan.nextInt();
			int[]a = new int[N+1];
			for(int i = 1;i<=N;i++)a[i] = scan.nextInt();

			long[][]dp = new long[N+1][K+1];


			dp[0][0] =1;

			for(int i = 1;i<=N;i++) {
				long []s = new long [K+2];
				for(int j = 1;j<=K+1;j++) s[j] = (s[j-1]+dp[i-1][j-1])%mod;

				for(int j = 0;j<=K;j++){
					dp[i][j] = (s[j+1]-s[Math.max(0, j-a[i])]+mod)%mod;
				}
			}


			System.out.println(dp[N][K]);




		}


	}


}


Measured memory_bytes: 166976
#include <iostream>
#include <cstring>

using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const int SIZE = 300;
const int N = 1000002;
int p[SIZE+1];
int dp1[N], dp2[N];

void make_pollock (void )
{
	memset (p, 0, sizeof (p ) );

	for (int i = 0; i <= SIZE; i++ )
		p[i] = i*(i+1LL)*(i+2LL)/6LL;
}

void make_dp (void )
{
	fill (dp1, dp1+N, INF );
	fill (dp2, dp2+N, INF );

	dp1[0] = 0;
	for (int i = 1; i <= SIZE; i++ ){
		int m = p[i];
		for (int j = m; j <= N; j++ )
			if (dp1[j] > dp1[j - m] + 1 )
				dp1[j] = dp1[j - m] + 1;
	} // end for

	dp2[0] = 0;
	for (int i = 1; i <= SIZE; i++ ){
		if (p[i] % 2 == 0 ) continue;
		int m = p[i];
		for (int j = m; j <= N; j++ )
			if (dp2[j] > dp2[j - m] + 1 )
				dp2[j] = dp2[j - m] + 1;
	} // end for	
}
	
int main()
{
	make_pollock();
	make_dp ();

	int n;
	while (cin >> n && n )
		cout << dp1[n] << ' ' << dp2[n] << endl;
	
	return 0;
}

Measured memory_bytes: 8568
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc147/tasks/abc147_e>
 問題文============================================================
 E - Balanced Path
 =================================================================
 解説=============================================================
 ================================================================
 */

bool dp[85][85][80*160*2+1];
const int base = 80*160;
template<class Type>
Type solve(Type res = Type()){
    int H,W; cin >> H >> W;
    auto A = make_v<int>(H,W);
    auto B = make_v<int>(H,W);

    for(auto& vec:A) for(auto& in:vec) cin >> in;
    for(auto& vec:B) for(auto& in:vec) cin >> in;

    dp[0][0][base] = true;
    for(int i = 0; i < H;i++){
        for(int j = 0; j < W;j++){
            for(int k = 0; k <= 80*160*2; k++){
                if(dp[i][j][k]){
                    dp[i+1][j][k+(A[i][j]-B[i][j])] = true;
                    dp[i+1][j][k-(A[i][j]-B[i][j])] = true;

                    dp[i][j+1][k+(A[i][j]-B[i][j])] = true;
                    dp[i][j+1][k-(A[i][j]-B[i][j])] = true;
                }
            }
        }
    }

    res = LINF;
    for(ll k = 0; k <= 80*160*2; k++){
        if(dp[H][W-1][k] | dp[H-1][W][k]){
            res = min(res,abs(k-base));
        }
    }

    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

using namespace std;

int main(){
  int N,s,d;
  cin >> N;
  while(N--){
    cin >> s >> d;
    int res = 0;
    for(int i = 0 ; i < 31 ; i++){
      if(s >> i & 1){
        s += 1<<i;
        res++;
      }
      if(d >> i & 1){
        d -= 1<<i;
        res++;
      }
      if(s == d){ break; }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N = int(input())
H = list(map(int, input().split()))

H1 = H[:-1]
H2 = H[1:]

boolH = [1 if h1 >= h2 else 0 for h1, h2 in zip(H1, H2)]

move = []
c = 0
for h in boolH:
  if h == 0:
    move.append(c)
    c = 0
  else:
    c = c + 1
move.append(c)

print(max(move))

Measured memory_bytes: 14224
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;

struct Point{
  double x, y, r;
};

vector<double> dijkstra(int i,int n, vector<vector<pair<int, double>>> graph) {
  vector<double> d(n, INF);
  d[i] = 0;
  priority_queue<pair<int, double>, vector<pair<int, double>>, greater<pair<int, double>>> q;
  q.push(make_pair(0, i));
  while (!q.empty()) {
    auto p = q.top();
    q.pop();
    auto v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : graph[v]) {
      if (d[x.first] > d[v] + x.second) {
        d[x.first] = d[v] + x.second;
        q.push(pair<int, double>(d[x.first], x.first));
      }
    }
  }
  return d;
}

signed main() {
  double sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;

  int N;
  cin >> N;
  N += 2;

  vector<Point> vec(N);
  vec[0] = {sx, sy, 0};

  FOR(i, 1, N-1) cin >> vec[i].x >> vec[i].y >> vec[i].r;

  vec[N-1] = {gx, gy, 0};

  vector<vector<pair<int, double>>> graph(N);
  REP(i, N){
    REP(j, N){
      if(i == j) continue;
      double h = sqrt((vec[i].x-vec[j].x)*(vec[i].x-vec[j].x)+(vec[i].y-vec[j].y)*(vec[i].y-vec[j].y));
      h -= vec[i].r+vec[j].r;
      if(h < 0) h = 0;
      graph[i].emplace_back(j, h);
    }
  }

  vector<double> ans = dijkstra(0, N, graph);

  printf("%.15f\n", ans[N-1]);
  
  return 0;
}

Measured memory_bytes: 37360
X, N = gets.chomp.split.map(&:to_i)
p = gets.chomp.split.map(&:to_i)

if N == 0
  puts X
  exit
end

(N+1).times do |i|
    plus_now = X + i
    minus_now = X - i


    if !p.include?(minus_now)
       puts minus_now
       exit
    end

    if !p.include?(plus_now)
      puts plus_now
      exit
    end
end


Measured memory_bytes: 14384
N, A, B = map(int, input().split())

# AとBの違うビットが偶数個なら不可能
if bin(A ^ B).count('1') % 2 == 0:
  print('NO')
  exit()

print('YES')
visited = set([A])
n = 1
now = A
xbits = set([2**i for i in range(N)])
is_neighbor = lambda a, b: (a ^ b) in xbits
targets = [(B, xbits)]
M = 2 ** N - 1
print(now)
while True:
  if now == B:
    break
  target, bits = targets[-1]
  # 異なるビットを見つけ、
  # そのビット以外で、適当に1ビット変えた所を暫定targetにする
  xor = now ^ target
  flag = False
  for i in bits:
    if xor & i:
      for j in bits:
        if j != i and now ^ j not in visited:
          targets.append((now ^ j ^ i, {j}))
          targets.append((now ^ j, bits - {i}))
          flag = True
          break
      if flag:
        break
  else:
    # 多分隣り合っている
    now = target
    visited.add(now)
    n += 1
    print(now)
    targets.pop()

Measured memory_bytes: 13944
from collections import deque

def main():
    T = input()
    d = deque(T)
    ans = deque()
    nxt = ""
    cnt = 0

    while d:
        now = d.pop()
        if now == "?":
            now = "D"
        ans.appendleft(now)

    print("".join(ans))
    

if __name__ == "__main__":
    main()            

Measured memory_bytes: 12676
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main()
{
    while(true){
        string s;
        cin >> s;
        int l = s.size();
        if(s == "-") break;
        int n; cin >> n;
        string t = s;
        for(int i = 0; i < n; i++){
            
            string u;
            int k;cin >> k;
            for(int j = k; j < l; j++){
                u +=  t[j];
            }
            for(int j = 0; j < k; j++){
                u += t[j];
            }
            if(i < n-1){
                t = u;
            }else{
                cout << u << endl;
            }
        }
    }
}



Measured memory_bytes: 3100
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

H, W = map(int, readline().split())

import math

if W == 1 or H == 1:
    print(1)
    exit()

w_can = W // 2
ans = w_can * H
if W % 2 != 0:
    ans += math.ceil(H / 2)

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=long long;

using vi=vector<int>;
using vll=vector<ll>;
using vvi=vector<vi>;

int main() {
  int H,W; cin >>H >>W;
  rep(i,0,H) {
    rep(j,0,W) {
      string S; cin >>S;
      if (S=="snuke") {
        cout <<(char)('A'+j) <<i+1 <<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3636
n,x=map(int,input().split())
A=[int(i) for i in input().split()]
eat=0
for i in range(n-1):
    if A[i]+A[i+1]>x:
        eat += A[i]+A[i+1]-x
        if A[i+1]>=A[i]+A[i+1]-x:
            A[i+1]-=(A[i]+A[i+1]-x)
        else:
            A[i+1]=0
            A[i]-=(A[i]+A[i+1]-x)-A[i+1]

print(eat)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n)   scanf("%d",&n)
#define mz(a)   memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n)   ip(A[i]);
#define print(a)  for(auto i : a)   cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b)   {return a>b?a:b;}
ll min(ll a,ll b)   {return a<b?a:b;}

int main() {
    #ifndef ONLINE_JUDGE
    freopen("D:/Sublime/Rough/input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    //std::cout << std::fixed;
    //std::cout << std::setprecision(6);
    Fastio;
    int testcase = 1;
//    cin>>testcase;
    while(testcase--)
    {
        ll n;
        cin>>n;
        ll a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        ll dp[n];
        dp[n-1] = a[n-1];
        for(int i=n-2;i>=0;--i)
            dp[i] = dp[i+1] + a[i];

        ll sm = 0;
        for(int i=0;i<n-1;i++)
            {sm+= ((a[i]%mod)*(dp[i+1]%mod))%mod;
             sm%=mod;}
        cout<<sm;

    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
    #endif
    
    return 0;
}

Measured memory_bytes: 6712
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iostream>

int main() {

    int size = 0;
    scanf("%d", &size);

    std::vector<int> numList;
    numList.resize(size);
    std::string buf;
    for (size_t i=0; i < numList.size(); ++i) {
        int num = 0;
        scanf("%d", &num);
        numList[i] = num;
    }


    for (int k=0; k<numList.size()-1; ++k) {
        printf("%d ", numList[k]);
    }
    printf("%d", numList.back());

    for (int i=1; i < numList.size(); ++i) {
        printf("\n");

        int v = numList[i];
        int j = i - 1;
        while (j >= 0 && numList[j] > v) {
            numList[j+1] = numList[j];
            --j;
        }
        numList[j+1] = v;

        for (int k=0; k<numList.size()-1; ++k) {
            printf("%d ", numList[k]);
        }

        printf("%d", numList.back());

    }

    printf("\n");

    return 0;
}




Measured memory_bytes: 3212
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**6)

def calculate_distance(field,locations,current_HP):
	is_visit = [[False for _ in range(len(field[0]))] for __ in range(len(field))]
	frontier = set()
	frontier.add(locations[current_HP-1])
	for step in range(10**6):
		for cx,cy in frontier:
			if (cx,cy)==locations[current_HP]: return step
			is_visit[cx][cy]=True
		next_frontier = set()
		for cx,cy in list(frontier):
			for dx,dy in [[0,1],[0,-1],[1,0],[-1,0]]:
				nx = cx+dx
				ny = cy+dy
				if not (0<=nx<len(field)):		continue
				if not (0<=ny<len(field[nx])):	continue
				if field[nx][ny]=='X':			continue
				if is_visit[nx][ny]: 			continue
				next_frontier.add((nx,ny))
		if len(next_frontier)==0: return
		frontier = next_frontier
	return -10*3

def solve(field,locations):
	total_step=0
	for current_HP in range(1,len(locations)):
		total_step += calculate_distance(field,locations,current_HP)
	return total_step

def main():
	line=input().strip()
	H,W,N=list(map(int,line.split(' ')))
	field,locations=list(),dict()
	for i in range(H):
		field.append(list(input().strip()))
		for j,x in enumerate(field[-1]):
			if x=='S':
				locations[0] = (i,j,)
			if x.isdigit():
				x = int(x)
				field[-1][j] = x
				locations[x] = (i,j,)
	print(solve(field,locations))

if __name__=='__main__':
	main()

Measured memory_bytes: 25336
#include<iostream>
#include<queue>
#include<stack>
#include<numeric>
#include<cstring>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#include<climits>
#include<cmath>

using namespace std;
#define ll long long
#define pp pair<int,int>
#define ppl pair<ll,ll> 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n,k;
	cin>>n>>k;

	int*arr=new int[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];

	vector<int> dp(n,0);
	for(int i=1;i<n;i++)
	{
		int ans=INT_MAX;
		for(int j=1;j<=k;j++)
		{
			if(i-j>=0)
				ans=min(ans,dp[i-j]+abs(arr[i]-arr[i-j]));
		}

		dp[i]=ans;
	}

	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const debug = false

var sc = bufio.NewScanner(os.Stdin)

/*-----------Main-----------*/

func main() {
	var bingo [3][3]int
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			bingo[i][j] = readI()
		}
	}
	N := readI()
	b := make([]int, N)
	for i := 0; i < N; i++ {
		b[i] = readI()
	}

	for z := 0; z < N; z++ {
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				if bingo[i][j] == b[z] {
					bingo[i][j] = 0
				}
			}
		}
	}

	if bingo[0][0]+bingo[0][1]+bingo[0][2] == 0 {
		fmt.Println("Yes")
		return
	}
	if bingo[1][0]+bingo[1][1]+bingo[1][2] == 0 {
		fmt.Println("Yes")
		return
	}
	if bingo[2][0]+bingo[2][1]+bingo[2][2] == 0 {
		fmt.Println("Yes")
		return
	}
	if bingo[0][0]+bingo[1][0]+bingo[2][0] == 0 {
		fmt.Println("Yes")
		return
	}
	if bingo[0][1]+bingo[1][1]+bingo[2][1] == 0 {
		fmt.Println("Yes")
		return
	}
	if bingo[0][2]+bingo[1][2]+bingo[2][2] == 0 {
		fmt.Println("Yes")
		return
	}
	if bingo[0][0]+bingo[1][1]+bingo[2][2] == 0 {
		fmt.Println("Yes")
		return
	}
	if bingo[2][0]+bingo[1][1]+bingo[0][2] == 0 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

/*-----------Utilities-----------*/

func init() {
	if debug {
		testFile, err := os.Open("./test/sample-1.in")
		if err == nil {
			sc = bufio.NewScanner(testFile)
		}

	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readI() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<char, ll> query;

ll N, Q, ans;

//parent, nearest marked ancestor, ismarked
vector <ll> par, nma, ism;
vector <query> q;

//find nearest marked ancestor (経路圧縮 at the same time)
ll find_nma(ll x){
	if (nma[x] == x) return x;
	else return nma[x] = find_nma(par[x]);
}

void solve(void){
	ENJYU;
	while (cin >> N >> Q) {
		if (N == 0 && Q == 0) break;
		//init
		par.clear(), ism.clear(), nma.clear(), q.clear();
		par.resize(N), ism.resize(N), nma.resize(N), q.resize(Q);
		par[0] = 0, ism[0] = 1, nma[0] = 0;
		ans = 0LL;
		rep(N-1, i) {
			cin >> par[i+1];
			par[i+1]--;
		}
		nma = par;

		//クエリ受け取り
		rep(Q, i) {
			cin >> q[i].fst >> q[i].snd;
			q[i].snd--;
			//先にMARKしておく
			if (q[i].fst == 'M') {
				ism[q[i].snd]++;
				nma[q[i].snd] = q[i].snd;
			}
		}

		//クエリを逆から見ていくと、頂点の更新は根の方向にのみ行われるので、前回の結果を使える
		repr(Q, i) {
			if (q[i].fst == 'M') {
				ism[q[i].snd]--;
				if (ism[q[i].snd]) continue;
				nma[q[i].snd] = find_nma(par[q[i].snd]);
				continue;
			}
			ans += find_nma(q[i].snd) + 1;
		}
		cout << ans << endl;
	}
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 7532
import java.util.*;
import static java.lang.Math.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int D = sc.nextInt();
        int x = sc.nextInt();

        for(int i=1; i<=10; i++){
            int ans = r * x - D;
            if(ans<0) ans = 0;
            System.out.println(ans);
            x = ans;
        }
    }
}

Measured memory_bytes: 21844
from collections import deque

H,W = map(int, input().split())
s = [input() for _ in range(H)]

cnt = 0
for i in range(H):
    cnt += s[i].count('.')

dx = [1,0,-1,0]
dy = [0,1,0,-1]

visited = [[float('inf')] * W for i in range(H)]

def bfs():
    queue = deque([[0,0]])
    visited[0][0] = 1

    while queue:
        y,x = queue.popleft()

        if y == H - 1 and x == W - 1:
            return visited[y][x]
        
        for i in range(4):
            nx = x + dy[i]
            ny = y + dx[i]

            if 0 <= nx < W and 0 <= ny < H and s[ny][nx] != '#' and visited[ny][nx] == float('inf'):
                queue.append([ny,nx])
                visited[ny][nx] = visited[y][x] + 1
    
    return -1

num = bfs()

if num == -1:
    print(num)
else:
    print(cnt - num)

Measured memory_bytes: 3316
/*input
AAAAABBBBAAABBBBAAAA
BBBBAAABBBBBBAAAAABB
10
2 15 2 13
2 13 6 16
1 13 2 20
4 20 3 20
1 18 9 19
2 14 1 11
3 20 3 15
6 16 1 17
4 18 8 20
7 20 3 14
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 100090
#define INF 0x3f3f3f3f
#define ls (now << 1)
#define rs (now << 1 | 1)
#define mid (l + r >> 1)

string s[2];
int sum[MAX * 4];
int pull(int v1 , int v2){
    if(v1 == 0) return v2;
    if(v2 == 0) return v1;
    if(v1 == v2) return 3 - v1;
    if(v1 != v2) return 0;
}
void build(int now , int l , int r , int ty){
    if(l == r) sum[now] = s[ty][l - 1] == 'A' ? 1 : 2;
    else {
        build(ls , l , mid + 0 , ty);
        build(rs , mid + 1 , r , ty);
        sum[now] = pull(sum[ls] , sum[rs]);
    }
}
int query(int now , int l , int r , int ql , int qr){
    if(ql <= l && r <= qr) return sum[now];
    if(qr <= mid + 0) return query(ls , l , mid + 0 , ql , qr);
    if(mid + 1 <= ql) return query(rs , mid + 1 , r , ql , qr);
    return pull(query(ls , l , mid + 0 , ql , qr) , query(rs , mid + 1 , r , ql , qr));
}
int n , q[MAX][4] , x[MAX][2];
int32_t main(){
    IOS;
    cin >> s[0] >> s[1];
    cin >> n;
    REP(i , 1 , n + 1) REP(j , 0 , 4) cin >> q[i][j];
    
    build(1 , 1 , s[0].size() , 0);
    REP(i , 1 , n + 1) x[i][0] = query(1 , 1 , s[0].size() , q[i][0] , q[i][1]);
    
    build(1 , 1 , s[1].size() , 1);
    REP(i , 1 , n + 1) x[i][1] = query(1 , 1 , s[1].size() , q[i][2] , q[i][3]);

    REP(i , 1 , n + 1) cout << (x[i][0] == x[i][1] ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 4304
f,p[5];main(i){for(;({for(f=i=0;i<5;f|=1<<p[i++])scanf("%d\n",p+i);*p;});)for(i=-1;i++<4;puts(f%5+1-p[i]?f%5-p[i]%3?"3":"1":"2"));}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 998244353
using Graph=vector<vector<int>>;

int main(){
  int K,N;
  cin>>K>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  int ans=0;
  A.push_back(K+A.at(0));
  for(int i=0;i<N;i++){
    ans=max(A.at(i+1)-A.at(i),ans);
  }
  cout<<K-ans<<endl;
}


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

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int k;
	cin >> k;
	
	vector<int> x = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	
	cout << x[k - 1] << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define ve vector
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int n;
    cin >> n;
    ve<ll> a(n+1);
    a[0] = 0;
    rep(i,n) cin >> a[i+1];
    rep(i,n) a[i+1] += a[i];
    ve<ve<ll>> dp(405, ve<ll>(405));

    for(int len = 1; len < n; len++){
        for(int i = 0; i+len<n; i++){
            dp[i][i+len] = dp[i][i] + dp[i+1][i+len];
            dp[i][i+len] += a[i+len+1] - a[i];
            for(int m = 1; m < len; m++){
                ll memo = dp[i][i+m]+dp[i+m+1][i+len];
                memo += a[i+len+1] - a[i];
                dp[i][i+len] = min(dp[i][i+len], memo);
            }
        }
    }
    cout << dp[0][n-1] << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
#ifdef LOCAL
  freopen ("input.txt", "r", stdin);
  freopen ("output.txt", "w", stdout);
#endif 
  long long k, n;
  cin >> k >> n;
  vector<long long> a(n);
  vector<long long> dist;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }  
  for (int i = 1; i < n; ++i) {
    dist.push_back(a[i] - a[i - 1]);
  }
  dist.push_back(k - a[n - 1] + a[0]);
  long long tot = accumulate(dist.begin(), dist.end(), 0LL);
  cout << tot - *max_element(dist.begin(), dist.end());
}

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

#define NDEBUG
#include <cassert>


typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

int solve(int a,int b,int c,int d,int e) {
    vi u {a,b,c,d,e};
    sort(ALL(u));
    int best = INT_MAX;
    do {
        int t = 0;
        rep(i,5) {
            t += u[i];
            if (i == 4) break;
            if (t % 10) {
                t += 10;
                t -= (t % 10);
            }
        }
        amin(best, t);
    } while (next_permutation(ALL(u)));
    return best;
}

int main() {
    int a,b,c,d,e; cin >> a >> b >> c >> d >> e;
    cout << solve(a,b,c,d,e) << endl;
    return 0;
}


Measured memory_bytes: 256
/*
            _ _  ___            __ _ _  _       _     
 _   _  ___| | |/ _ \__      __/ _| | || |  ___| |__  
| | | |/ _ \ | | | | \ \ /\ / / |_| | || |_/ __| '_ \ 
| |_| |  __/ | | |_| |\ V  V /|  _| |__   _\__ \ | | |
 \__, |\___|_|_|\___/  \_/\_/ |_| |_|  |_| |___/_| |_|
 |___/                 

*/

#include <bits/stdc++.h>
using namespace std;
#define sz(x) (ll)(x).size()
#define trav(x) for(auto it: x)
#define all(x) x.begin(), x.end()
#define stp fixed<<setprecision(20)
#define db(x) cout<<#x<<": "<<x<<endl
#define tc ll tt; cin>>tt; while(tt--)
#define For(i, st, en) for(ll i=st; i<en; i++)
#define rFor(i, st, en) for(ll i=st; i>=en; i--)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define printv(x) For(i, 0, sz(x)){cout<<x[i]<<" ";} cout<<endl;
#define print2v(x) For(i, 0, sz(x)){For(j, 0, sz(x[0])){cout<<x[i][j]<<" ";} cout<<endl;}
#define ll long long
#define int long long
#define F first
#define S second
#define pb push_back
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector< vector<int> > vvi;
typedef vector< pair<int, int> > vpi;
#define endl '\n'
#define MAXN 300005
#define MOD 1000000007
#define INF 1000000000000000007


signed main(){
	fast
	int n, k;
	cin>>n>>k;
	string s;
	cin>>s;
	int c1=0, c2=0;
	int ans=0;
	For(i, 0, n-1){
		string ss = s.substr(i, 2);
		if(ss=="LR") c1++;
		else if(ss=="RL") c2++;
		else ans++;
	}

	int mh = min(c1, c2);
	int ex = abs(c1-c2);
	if(k<=mh){
		ans+=k*2;
	}else{
		ans+=mh*2;
		if(ex) ans++;
	}
	cout<<ans<<endl;
    return 0;
}
    



Measured memory_bytes: 512