akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long LL;
typedef long double LD;
int read() {
    char ch = getchar();
    int x = 0, flag = 1;
    for (;!isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1;
    for (;isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x * flag;
}
void write(int x) {
    if (x < 0) putchar('-'), x = -x;
    if (x >= 10) write(x / 10);
    putchar(x % 10 + 48);
}

const int Maxn = 3e5 + 9;
struct Point {
	int x, y;
	int operator < (const Point &a) const {
		return x < a.x;
	}
}s[Maxn];
int n, ans, h, w;

void init() {
	w = read(), h = read(); n = read();
	rep (i, 1, n) s[i].x = read(), s[i].y = read();
	s[++n] = (Point){0, 0};
	s[++n] = (Point){w, h};
}

pair<int, int> stkA[Maxn], stkB[Maxn]; 
int topa, topb;

struct SGMTtree {
	int tree[Maxn << 2], add[Maxn << 2];
#define lc(x) ((x) << 1)
#define rc(x) ((x) << 1 | 1)
#define ls rt << 1, l, mid
#define rs rt << 1 | 1, mid + 1, r

	void clear() {
		clar(tree, 0), clar(add, 0);
	}
	void pushup(int rt) {
		tree[rt] = max(tree[lc(rt)], tree[rc(rt)]);
	}
	void pushdown(int rt) {
		if (add[rt]) {
			add[lc(rt)] += add[rt]; add[rc(rt)] += add[rt];
			tree[lc(rt)] += add[rt]; tree[rc(rt)] += add[rt];
			add[rt] = 0;
		}
	}
	void modify(int rt, int l, int r, int p, int q, int v) {
		if (p <= l && r <= q)  {
			add[rt] += v; tree[rt] += v;
			return ;
		}

		int mid = (l + r) >> 1; pushdown(rt);
		if (q <= mid) modify(ls, p, q, v);
		else if (p >= mid + 1) modify(rs, p, q, v);
		else modify(ls, p, q, v), modify(rs, p, q, v);
		pushup(rt);
	}
#undef lc
#undef rc
#undef ls
#undef rs
}st;

void ZhaoQingFei() {
	sort(s + 1, s + n + 1);

	st.clear(); topa = topb = 0;
	rep (i, 1, n) {
		int Nxt = i - 1; 
		if (s[i].y <= h / 2) {
			while (topa && stkA[topa].second <= s[i].y) {
				st.modify(1, 1, n, stkA[topa].first, Nxt, stkA[topa].second - s[i].y);
				Nxt = stkA[topa].first - 1; --topa;
			}
			if (Nxt != i - 1) stkA[++topa] = make_pair(Nxt + 1, s[i].y);
		} else {
			while (topb && stkB[topb].second >= s[i].y) {
				st.modify(1, 1, n, stkB[topb].first, Nxt, s[i].y - stkB[topb].second);
				Nxt = stkB[topb].first - 1; --topb;
			}
			if (Nxt != i - 1) stkB[++topb] = make_pair(Nxt + 1, s[i].y);
		}
		stkA[++topa] = make_pair(i, 0);
		stkB[++topb] = make_pair(i, h);

		st.modify(1, 1, n, i, i, h - s[i].x);
		ans = max(ans, s[i + 1].x + st.tree[1]);
	}
}

void solve() {
	ZhaoQingFei();
	
	rep (i, 1, n) swap(s[i].x, s[i].y);
	swap(h, w);
  	
	ZhaoQingFei();
	cout << ans * 2 << endl;
}

int main() {
//	freopen("ARC047B.in", "r", stdin);
//	freopen("ARC047B.out", "w", stdout);

	init();
	solve();

#ifdef Qrsikno
    debug("\nRunning time: %.3lf(s)\n", clock() * 1.0 / CLOCKS_PER_SEC);
#endif
    return 0;
}



Measured memory_bytes: 16640
#include<bits/stdc++.h>
#include<vector>
#include<deque>
#include<list>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
struct pos{
	int x,y,cost;
};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int n;
	cin>>n;
	if(n>=65&&n<=90)cout<<"1"<<endl;
	else if(n>=97&&n<=122)cout<<"2"<<endl;
	else cout<<"0"<<endl;

	return 0;
}



Measured memory_bytes: 3116
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

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

    int sum = 0;
    int count = 0;

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

    if(count == 0){
        System.out.println("NO");
    }else{
        System.out.println("YES");
    }




    





    
    


    
	}
}

Measured memory_bytes: 35752
#include <iostream>

using namespace std;

int main()
{
	int a, b;
	int N;
	int s, f;

	cin >> a >> b;
	cin >> N;

	int ret = 0;	// 良い
	for (int i = 0; i < N; i++) {
		cin >> s >> f;

		if ( ! (b <= s || f <= a) ) {
			ret = 1;	// ダメだった
		}
	}
	cout << ret << endl;
	return 0;
}



Measured memory_bytes: 3128
W, H, N = map(int, input().split())
xya = [list(map(int, input().split())) for _ in range(N)]

p1, p2 = [0, 0], [W, H]

for *p, a in xya:
    if a == 1:
        if p1[0] < p[0]:
            p1[0] = p[0]
    elif a == 2:
        if p2[0] > p[0]:
            p2[0] = p[0]
    elif a == 3:
        if p1[1] < p[1]:
            p1[1] = p[1]
    else:
        if p2[1] > p[1]:
            p2[1] = p[1]

if p2[0]-p1[0] < 0 or p2[1] - p1[1] < 0:
    print(0)
else:
    print((p2[0]-p1[0]) * (p2[1] - p1[1]))

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

int main() {
    ll r, d, x;
    cin >> r >> d >> x;

    for (int i = 0; i < 10; ++i) {
        x = r * x - d;
        cout << x << endl;
    }

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size() - 1;

    for(int i = 0; i < n; i++){
        if(s[i] != s[n - i]){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i = 0; i < (n - 1) / 2; i++){
        if(s[i] != s[(n - 1) / 2 - i]){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i = (n + 3) / 2 - 1; i < n; i++){
        if(s[i] != s[n - i]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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

int main() {
    LL n,k;
    cin >> n >> k;

    LL u = n % k;
    LL t = abs(u-k);
    LL ans = min(t,u);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include"stdio.h"
#include"stdlib.h"
#include"string.h"
#include"math.h"

#define pi 3.1415926535898
#define DEC (pi/180)

int main()
{
    int i,j,k,a,b;
    double n,x,yh,ym,h,m;
    scanf("%d %d %lf %lf",&a,&b,&h,&m);
    if(h<=6)
    {
        if(m<=30)
        {
                yh=h*30+m/60*30;
                ym=m/60*360;
                x=((yh-ym)>=0?(yh-ym):(ym-yh));
        }
        else if(m>30)
        {
            yh=180-(h*30+m/60*30);
            ym=(m-30)/60*360;
            x=((yh+ym)<=180?(yh+ym):(360-yh-ym));
        }
    }
    else if(h>6)
    {
        if(m>=30)
        {
            yh=(h-6)*30+m/60*30;
            ym=(m-30)/60*360;
            x=((yh-ym)>=0?(yh-ym):(ym-yh));
        }
        else if(m<30)
        {
            yh=(h-6)*30+m/60*30;
            ym=180-m/60*360;
            x=((yh+ym)<=180?(yh+ym):(360-yh-ym));
        }
    }
    n=sqrt(a*a+b*b-2*a*b*cos(x*DEC));
   // printf("%lf ",x);
    //printf("%lf ",cos(x*DEC));
    printf("%.20lf ",n);

    return 0;
}


Measured memory_bytes: 2584
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,l,r) for(int i=(l);i<(r);i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef long long ll;  //ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<ll, ll> > PS;
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
// g++ -std=c++11 prac.cpp 
int main(){
    ll a,b,x=0,y=0,z=0,n,m=0,k,ans=0,h,w,sum=0,Max=-1e9-1,cnt=0,Min=1e9+1;
    string s,t,u;
    bool ok=true;
    cin >> k >> x;
    if(k*500 >= x) cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


 

Measured memory_bytes: 256
N,M = map(int,input().split())
PS = [list(input().split()) for i in range(M)]

resultdict = {}
count_ans,count_pena = 0,0

for sub in PS :
    resultdict.setdefault(sub[0],{"AC":0, "WA":0})
    if resultdict[sub[0]]["AC"] == 0 :
        resultdict[sub[0]][sub[1]] += 1

for v in resultdict.values() :
    count_ans += v["AC"]
    if v["AC"] == 1 :
        count_pena += v["WA"]

print(count_ans,count_pena)

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

using namespace std;
typedef long long LL;

#define MAXN 100001
#define MOD 1000000007

int main(int argc, char** argv) {
#ifdef OJ
    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
#endif
    std::ios::sync_with_stdio(false);

    int ans = 0;

    int N;
    cin >> N;
    while (N--) {
        int a;
        cin >> a;
        while (a % 2 == 0) {
            ans++;
            a /= 2;
        }
    }

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

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

int main() {
	int N, A, count = 1;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A;
		count *= ((A + 1) % 2 + 1);
	}
	cout << pow(3, N) - count << endl;
}

Measured memory_bytes: 384
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int X = input[0];
            int Y = input[1];
            Console.WriteLine(X + (Y / 2));
        }
    }
}

Measured memory_bytes: 11092
//g++でビルド

#include "bits/stdc++.h"

using namespace std;


int main(){

    int N, K;
    cin >> N >> K;
    int result = 0;
    int sum = 0;
    int max = 0;
    vector<int> trees;

    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        trees.push_back(a);
    }

    sort(trees.begin(), trees.end());

    int min = __INT_MAX__;

    for(int i = 0; i < N-K+1; i++){
        int now = trees[i+K-1] - trees[i];
        if(now < min){
            min = now;
        }
    }

    result = min;

    cout << result << endl;
    return 0;
}

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

from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)


X, Y, A, B, C = map(int, input().split())
apples_A = sorted(list(map(int, input().split())))
apples_B = sorted(list(map(int, input().split())))
apples_C = sorted(list(map(int, input().split())))

# 赤のリンゴからおいしさが大きい順に X 個選ぶ
# 緑のリンゴからおいしさが大きい順に Y 個選ぶ
# 無色のリンゴからおいしさが最も大きいリングを選び、そのリンゴ以上の美味しさでかつ美味しさが最も小さい赤 or 緑リンゴと交換する
# 上記の交換をできるだけ多く行う

apples_rest = sorted(apples_A[-X:] + apples_B[-Y:] + apples_C)
ans = sum(apples_rest[ -(X + Y):])

# while apples_C:
#     candidate = apples_C.pop()
#     min_apple = min(res_A[0], res_B[0])
#     if candidate <= min_apple:
#         break

#     if res_A[0] <= res_B[0]:
#         res_A[0] = candidate
#     else:
#         res_B[0] = candidate

# ans = sum(res_A) + sum(res_B)

print(ans)


Measured memory_bytes: 109048
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	b := []byte(readString())

	var ans int
	for i := 1; i < len(b); i++ {
		if b[i] != b[i-1] {
			ans++
		}
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  int n;
  cin >> n;
  if (n == 1) cout << "Hello World" << endl;
  else {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#ifndef ONLINE_JUDGE
#include <custom/prettyprint.hpp>
#endif
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b) - 1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rb(i,x) for (auto& i : x)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define UNIQUE(x) (x).resize(unique(all(x)) - begin(x))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define pow10(n) stoll("1"+string(n,'0'))
#define dbg(x) cout << ">>> " << #x << ": " << x << '\n'

const int MOD = 1e9+7; //998244353
const int inf = 1e9+3;
const ll INF = ll(3e18)+3;
const ld PI = acos((ld)-1);
const int dx[8] = {1,0,-1,0,1,1,-1,-1}, dy[8] = {0,1,0,-1,-1,1,1,-1};
mt19937_64 rng((uint64_t)chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll n) { return uniform_int_distribution<ll>(0, n)(rng); }
template<class T> bool ckmin(T& a, const T& b) { 
	return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0; }
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 

void setIO(const string& s) {
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen((s+".in").c_str(),"r",stdin);
//	freopen((s+".out").c_str(),"w",stdout);
#endif
}

int main() {
    
    setIO("input");
    string s; cin >> s;
    int sum = 0;
    for(auto& i : s) {
        int digit = i - '0';
        sum = (sum + digit) % 9;
    }
    cout << (sum == 0 ? "Yes\n" : "No\n");
    
}

/*  ! CHECK THIS IF YOU GET IT WRONG !
	* int overflow, array bounds, NO VLAs
	* uninitialized local variables, rounding errors
	* intermediate result type, scientific
	* special cases (n = 0 or 1?)
	* reset your variables in scope
	* INF not large enough for ans, adding value to _MAX
	* using wrong variables, sorting extra 0s in global array
	* comment out input from file
	* operator precedence
*/

Measured memory_bytes: 3720
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
import java.lang.Integer;

/**
 * Created by Messick on 2019/10/26.
 */
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int cnt = 0;
        String s = in.next();
        int n = s.length();
        for (int i = 0; i < n / 2; i++) {
            if (s.charAt(i) != s.charAt(n - 1 - i))cnt++;
        }
        System.out.print(cnt);
    }
}


Measured memory_bytes: 21844
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("panic read line");
    let splitted_input: Vec<i32> = input.split_whitespace()
                        .map(|s| s.parse().expect("panic parse"))
                        .collect();

    let n = splitted_input[0];
    let a = splitted_input[1];
    let b = splitted_input[2];

    let mut some_sum = 0;
    for i in 1..n+1 {
        let s: String = i.to_string();
        let mut sum: i32 = 0;
        for c in s.chars() {
            let digit: i32 = c as i32 - 48;
            sum += digit;
        }

        if sum >= a && sum <= b {
            some_sum += i;
        }
    }

    println!("{}", some_sum);
}


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

using namespace std;


int main(){
    char c;
    char a[5] = {'a','i','u','e','o'};
    cin >> c;
    bool flag = false;

    for(int i = 0;i<5;i++){
        if( a[i] == c){
            flag = true;
            break;
        }
    }

    if(flag) cout << "vowel" << endl;
    else cout << "consonant" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.stream.*;

@SuppressWarnings("unused")
public class Main {
	static int[] s, t, dp[];
	final static int MOD = (int) (1e9 + 7);

	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(), m = in.nextInt();
		s = readArray(in, n);
		t = readArray(in, m);
		dp = new int[n][m];
		for (int i = 0; i < n; i++)
			Arrays.fill(dp[i], -1);
		System.out.println(dp(n - 1, m - 1));
	}

	private static int dp(int i, int j) {
		if (i == -1 || j == -1)
			return 1;
		if (dp[i][j] == -1) {
			if (s[i] == t[j])
				dp[i][j] = (dp(i,j-1)+dp(i-1,j))%MOD;
			else
				dp[i][j] = (((dp(i,j-1)+dp(i-1,j))%MOD)-dp(i-1,j-1))%MOD;
		}
		return (dp[i][j] + MOD)%MOD;
	}
	
	public static int[] readArray(Scanner in, int n) {
		int[] array = new int[n];
		for (int i = 0; i < n; i++)
			array[i] = in.nextInt();
		return array;
	}
	
}


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

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

  int n;
  string s;
  cin >> n >> s;

  vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));
  for (int i = n - 1; i >= 0; i--) {
    for (int j = n - 1; j >= 0; j--) {
      if (s[i] == s[j]) {
        dp[i][j] = dp[i + 1][j + 1] + 1;
      } else {
        dp[i][j] = 0;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i >= j) continue;

      ans = max(ans, min(dp[i][j], j - i));
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 98176
import sys
input = sys.stdin.readline
N,M = map(int,input().split())
A = []
C = []

for i in range(M):
    A.append(int(input().split()[0]))
    C.append(list(map(int,input().split())))


inf = 1000000000
dp = [inf for _ in range(2**N)]
dp[0] = 0

for i in range(M):
    cost = A[i]
    candidate = C[i]
    mask = 0
    for c in candidate:
        mask += 1 << (c-1)
    for j in range(2**N):
        if dp[j|mask] > dp[j] + cost:
            dp[j|mask] = dp[j] + cost

if dp[-1] == inf:
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 42348
#include "stdio.h"
#include"string.h"
int main()
{
    char a;
    scanf("%c",&a);
    if (a=='A')
    {
        printf("T\n");
    }else if(a=='G')
    {
        printf("C\n");
    }else if(a=='T')
    {
        printf("A\n");
    }else{
        printf("G\n");
    }
    return 0;
}

Measured memory_bytes: 128
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Pass = Tuple!(long, "x", long, "y");

void main()
{
    long a, b, c;
    scan(a, b, c);
    if (a + b + c < 22)
        writeln("win");
    else
        writeln("bust");
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
from collections import deque

def bfs(maze):
    h = len(maze)
    w = len(maze[0])
    visited = [[-1 for _ in range(w)] for _ in range(h)]
    d = deque()
    
    last =[-1, -1]
    for y in range(h):
        for x in range(w):
            if maze[y][x] == '#':
                d.append([y, x])
                visited[y][x] = 0
                last[0] = y
                last[1] = x
    
    while d:
        y, x = d.popleft()
        
        for l, k in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            new_y, new_x = y + l, x + k
            
            if new_y < 0 or h <= new_y or new_x < 0 or w <= new_x:
                continue
            elif visited[new_y][new_x] != -1:
                continue
            elif maze[new_y][new_x] == '#':
                continue
            
            d.append([new_y, new_x])
            visited[new_y][new_x] = visited[y][x] + 1

        last[0] = y
        last[1] = x
        
    ''' 確認用
    print(last)
    for i in range(h):
        print(visited[i])
    '''
        
    return visited[last[0]][last[1]]

if __name__ == "__main__":
    h, w = map(int, input().split())
    maze = []
    for i in range(h):
        maze.append(list(input()))
    ''' 確認用
    for i in range(h):
        print(maze[i])
    '''
    
    print(bfs(maze))

Measured memory_bytes: 177500
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    lump = True
    for j in range(m):
        k=s[j][0]
        sw=s[j][1:]
        cnt=0
        for si in sw:
            if i>>(si-1) & 1:
                cnt+=1
        if cnt%2 != p[j]:
            lump=False
    if lump:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
using namespace std;
const int INF = 1000000000;

int d[110], dNumber = 1;
int f(int c) { return c * (c + 1) * (c + 2) / 6; }
int dp1[1000000], dp2[1000000];

int main() {
  while (1) {
    d[dNumber] = f(dNumber);
    if (d[dNumber] > 1000000) break;
    dNumber++;
  }
  for (int i = 0; i < 1000000; i++) dp1[i] = dp2[i] = INF;
  dp1[0] = dp2[0] = 0;
  for (int i = 1; i < 1000000; i++) {
    for (int j = 1; j < dNumber; j++) {
      if (d[j] > i) break;
      dp1[i] = min(dp1[i], dp1[i - d[j]] + 1);
      if (d[j] % 2 == 1) dp2[i] = min(dp2[i], dp2[i - d[j]] + 1);
    }
  }
  int N;
  while (1) {
    scanf("%d", &N);
    if (N == 0) break;
    printf("%d %d\n", dp1[N], dp2[N]);
  }
}



Measured memory_bytes: 10424
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
#include <stdexcept>
//#include <boost/graph/adjacency_list.hpp>
using namespace std;

int main()
{
	cout << fixed << setprecision(6);
	int n;
	cin >> n;
	vector<int> als(n + 1), bls(n);
	for (auto& x : als) cin >> x;
	for (auto& x : bls) cin >> x;
	
	auto killCount = 0ULL;
	int preva = 0;
	for (int i = 0; i < n; ++i) {
		if (als[i] > bls[i]) {
			killCount += bls[i];
		}else{
			killCount += als[i];
			preva = als[i + 1];
			als[i + 1] = max(0, als[i + 1] - (bls[i] - als[i]));
			killCount += (preva - als[i + 1]);
		}
	}

	cout << killCount << endl;
	
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

bool check(ll n, ll k, vector<ll> a, vector<ll> f){
  ll tmp=0;
  REP(i,a.size()){
    if(a[i]*f[i]>n){
      tmp += a[i] - n/f[i];
    }
  }
  return tmp <= k;
}

int main(){
  ll N, K;

  cin >> N >> K;

  vector<ll> A(N),F(N);

  REP(i,N)cin>>A[i];
  REP(i,N)cin>>F[i];

  sort(A.begin(),A.end());
  sort(F.rbegin(),F.rend());

  ll l=-1;
  ll r=1e13;
  while(l+1<r){
    ll mid=(l+r)/2;
    if(check(mid,K,A,F)){
      r=mid;
    }else{
      l=mid;
    }
  }
  cout << r << endl;
}



Measured memory_bytes: 8568
n, m, k = gets.chomp.split.map(&:to_i)
ab = []
m.times do
  ab.push(gets.chomp.split.map(&:to_i))
end
cd = []
k.times do
  cd.push(gets.chomp.split.map(&:to_i))
end

@p = Array.new(n+1, -1)

def root(x)
  @p[x] < 0 ? x : @p[x] = root(@p[x])
end

def unite(x, y)
  x, y = root(x), root(y)
  if x != y
    x, y = y, x if @p[y] < @p[x]
    @p[x] += @p[y]
    @p[y] = x
  end
end

def num(x)
  @p[x] == -1 ? 1 : -@p[root(x)]
end

def union?(x, y)
  root(x) == root(y)
end

friends = Array.new(n+1) {Array.new}
ab.each do |a, b|
  unite(a, b)
  friends[a] << b
  friends[b] << a
end

blocks = Array.new(n+1) {Array.new}
cd.each do |c, d|
  blocks[c] << d
  blocks[d] << c
end

ans = []
1.upto(n) do |i|
  ans.push(num(i) - friends[i].count{|t| union?(i,t)} - blocks[i].count{|t| union?(i,t)} - 1)
end
puts ans.join(' ')


Measured memory_bytes: 33012
import java.util.Scanner;

public class Main {
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);
        int w = scan.nextInt();
        int n = scan.nextInt();

        int list[] = new int[w];
        for(int i = 0;i < w;i++)list[i] = i+1;
        
        for(int i = 0;i < n;i++){
            String s = scan.next();
            int conma = s.indexOf(",");
            int a1 = Integer.parseInt(s.substring(0, conma))-1;
            int a2 = Integer.parseInt(s.substring(conma+1, s.length()))-1;
            int x = list[a1];
            list[a1] = list[a2];
            list[a2] = x;
        }
 
        for(int i = 0;i < w;i++)System.out.println(list[i]);

        scan.close();
    }

    

}


Measured memory_bytes: 26152
import std;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto S = sread();
    auto sum = new long[][](3, N + 1);
    foreach (i; 0 .. N)
    {
        switch (S[i])
        {
        case 'R':
            sum[0][i + 1] = 1;
            break;
        case 'G':
            sum[1][i + 1] = 1;
            break;
        case 'B':
            sum[2][i + 1] = 1;
            break;
        default:
            assert(0);
        }
    }
    foreach (i; 0 .. 3)
        foreach (j; 0 .. N)
        {
            sum[i][j + 1] += sum[i][j];
        }
    long[] idx = [0, 1, 2];
    long ans;
    do
    {
        foreach (i; 0 .. N)
        {
            if (S[i] == "RGB"[idx[0]])
                foreach (j; i + 1 .. N)
                {
                    if (S[j] == "RGB"[idx[1]])
                    {
                        ans += sum[idx[2]][$ - 1] - sum[idx[2]][j + 1];
                        // writefln("%s %s %s", i, j, sum[$ - 1] - sum[j + 1]);
                        if (j + (j - i) < N && S[j + (j - i)] == "RGB"[idx[2]])
                        {
                            // writefln("%s %s %s", i, j, j + (j - i));
                            ans--;
                        }
                    }
                }
        }
    }
    while (nextPermutation(idx));
    writeln(ans);
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int a[3],b[2];
	for(int i=0;i<3;i++){
		cin >> a[i];
	}
	for(int i=0;i<2;i++){
		cin >> b[i];
	}
	sort(a,a+3);
	sort(b,b+2);
	cout << a[0]+b[0]-50 << endl;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#define LL long long int
using namespace std;
int main(void)
{
	int i,j,k,n,x,y,z,a[100],b[100],c[100],f1[101]={0},f2[101]={0},f3[101]={0},cnt;
	cin>>n;
	cin>>x;for(i=0;i<x;i++) cin>>a[i],f1[a[i]]=1;
	cin>>y;for(i=0;i<y;i++) cin>>b[i],f2[b[i]]=1;
	cin>>z;for(i=0;i<z;i++) cin>>c[i],f3[c[i]]=1;
	cnt=0;
	for(i=0;i<=n;i++) {
		if(f1[i]==1&&f2[i]==1&&f3[i]==1) cnt++;
		if(f1[i]==0&&f2[i]==1&&f3[i]==1) cnt++;
		if(f1[i]==0&&f2[i]==0&&f3[i]==1) cnt++;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3120
N = int(input())
S = list(map(int,input().split()))

ans = 0
for C in range(1,N):
    dp = 0
    for k in range((N-1)//C):
        if (2*k-1)*C == N-1 or 2*k*C == N-1:
            break
        dp += S[N-1-C*k]+S[C*k]
        ans = max(ans,dp)

print(ans)

Measured memory_bytes: 63216
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut ans = 0;
    for _ in 0..n {
        let v = read_vec::<usize>();
        ans += v[1] - v[0] + 1;
    }
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;

int f(int x){
    int ret = 0;
    while(x){
        ret += x%10;
        x/=10;
    }
    return ret;
}

int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
	//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#endif

    int n;
    sfi1(n);
    int ans = n;
    range(i,1,n-1){
        ans = min(ans , f(i) + f(n-i));
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cmath>

#define rep0(i, n) for (i = 0; i < n; i++)
#define rep(i, s, n) for (i = s; i < n; i++)
using namespace std;
typedef long long ll;

ll N,ans;
int i,j;
ll mod = 1000000007;

ll powmod(ll x, ll y){
    ll r = 1;
    rep0(i, y) r = r * x % mod;
    return r;
}

int main()
{
    cin >> N;
    ans=powmod(10,N)-powmod(9,N)-powmod(9,N)+powmod(8,N);
    ans%=mod;
    ans=(ans+mod)%mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

LL dp[112345] = {};
LL ans[112345] = {};
LL M;
VVI g;

LL dfs1(int v, int p){
    LL res = 1;
    for(int u : g[v]){
        if(u == p) continue;
        res = res * (dfs1(u,v) + 1) % M;
    }
    return dp[v] = res;
}

void dfs2(int v, int p){
    ans[v] = dp[v];
    LL sz = SZ(g[v]);
    VL left(sz+1,1),right(sz+1,1);
    REP(i,sz) left[i+1] = left[i] * (dp[g[v][i]]+1) % M;
    REP(i,sz) right[i+1] = right[i] * (dp[g[v][sz-1-i]]+1) % M;
    REP(i,sz){
        int u = g[v][i];
        if(u == p) continue;
        LL tmp1 = dp[v];
        LL tmp2 = dp[u];
        dp[v] = left[i] * right[sz-1-i] % M;
        dp[u] = dp[u] * (dp[v]+1) % M;
        dfs2(u,v);
        dp[v] = tmp1;
        dp[u] = tmp2;
    }
}



signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; 
    cin >> N >> M;
    g.resize(N);
    REP(i,N-1){
        int x,y; cin >> x >> y;
        x--; y--;
        g[x].eb(y);
        g[y].eb(x);
    }
    dfs1(0,-1);
    dfs2(0,-1);
    REP(i,N){
        cout << ans[i] << endl;
    }


}

Measured memory_bytes: 20864
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	string s;
	cin >> s;
	int n = (int)s.size();
	int pc = 0;
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		if (i == n || s[i] == '1') {
			int other = binpow(3, max((int)0, n - i - 1));
			other = mul(other, binpow(2, pc));
			ans = add(ans, other);
			pc++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

using System.IO;

class _Class
{
	void _Do()
  {
		//
		var abc = _int();

		var a = abc[0];
		var b = abc[1];
		var c = abc[2];

	
		if (a == b && b == c)
			if (a % 2 == 0)
			{
				Console.WriteLine("-1");
				return;
			}

		int x = 0;
		for (;;)
		{
			if (a % 2 == 1) break;
			if(b % 2 == 1) break;
			if(c % 2 == 1) break;
			var _a = (b + c)/2;
			var _b = (a+c) / 2;
			var _c = (b + a) / 2;
			a = _a;
			b = _b;
			c = _c;
			x += 1;
		}
		Console.WriteLine(x);

	}

	static void Main(string[] args)
  {
    new _Class()._Do();
  }

#region

  string _string()
  {
    return Console.ReadLine();
  }

	//
	string[] _strings()
  {
    return Console.ReadLine().Split();
  }

  int[] _int(int n)
  {
    var x = new int[n];
    for (var i = 0; i < n; i++)
    {
      x[i] = int.Parse(Console.ReadLine());
    }
    return x;
  }

	//
	int[] _int()
  {
    var ss = Console.ReadLine().Split();

    var x = new int[ss.Length];
    for (var i = 0; i < ss.Length; i++)
      x[i] = int.Parse(ss[i]);

    return x;
  }

	long[] _long()
	{
		var ss = Console.ReadLine().Split();

		var x = new long[ss.Length];
		for (var i = 0; i < ss.Length; i++)
			x[i] = long.Parse(ss[i]);

		return x;
	}
#endregion

}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  map<string, bool> m;
  for (ll i = 0; i < n; ++i) {
    string s;
    cin >> s;

    m[s] = true;
  }

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

  return 0;
}


Measured memory_bytes: 19060
#include<bits/stdc++.h>
using namespace std;
#define int long long
int q,a,b,c,d,pn,k;
inline bool check(int x){
	int t=x/(k+1);
	int ra=a-t*k-x%(k+1),rb=b-t;
	if (t*(k+1)==x) ++rb;
	return rb<=(ra+1)*k;
}
signed main(){
	scanf("%lld",&q);
	while (q--){
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		if (a==b){
			for (int i=c;i<=d;++i) putchar(i&1?'A':'B');
			puts("");
		}else if (a>b){
			pn=b+1;
			k=(a-1)/pn+1;
			int ans=0;
			for (int l=1,r=a+b,mid;l<=r;check(mid=(l+r)>>1)?ans=mid,l=mid+1:r=mid-1);
			for (int i=c;i<=d;++i){
				if (i<=ans) putchar(i%(k+1)==0?'B':'A');
				else putchar((a+b-i+1)%(k+1)==0?'A':'B');
			}
			puts("");
		}else{
			pn=a+1;
			k=(b-1)/pn+1;	
			int ans=0;
			swap(a,b);
			for (int l=1,r=a+b,mid;l<=r;check(mid=(l+r)>>1)?ans=mid,l=mid+1:r=mid-1);
			ans=a+b-ans;
			for (int i=c;i<=d;++i){
				if (i<=ans) putchar(i%(k+1)==0?'B':'A');
				else putchar((a+b-i+1)%(k+1)==0?'A':'B');
			}
			puts("");
		}
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define Int long long
#define all(x) begin(x),end(x)
#define endl "\n"
#define cy cout << "YES"<<endl 
#define cn cout<<"NO"<<endl
#define elif else if

using namespace std;

int main () {
		string s; cin >> s;
		int count{};
		int real{1};
		for(size_t i {}; i<3;i++){
			if(s[i]=='R')count++;
			if(s[i]=='R'&&s[i+1]=='R'&&i<2)real++;
		}
		if(count == 0) real =0;
		
		cout << real << endl;
    return 0;
    
}


Measured memory_bytes: 3624
n,l=map(int,input().split())
apple=list(range(1,n+1))
aji=[l+i-1 for i in apple]
sum_num=sum(aji)
sa=10000
for i in range(len(aji)):
    if abs(aji[i])<sa:
        sa=abs(aji[i])
        ans=aji[i]
print(sum_num-ans)

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long prime = 1000000007;
    int n, k;
    cin >> n >> k;
    int m = 1;
    while ((m+1) * (m+1) <= n) ++m;
    vector<int> ws(2*m, 1);
    ws[m] = n/m - m;
    for (int i = m+1; i < 2*m; ++i) {
        ws[i] = n/(2*m-i) - n/(2*m-i+1);
    }
    vector<vector<long long>> res(k+2, vector<long long>(2*m, 0LL));
    res[0][0] = 1LL;
    for (int j = 1; j <= k+1; ++j) {
        long long running = 0LL;
        for (int i = 2*m-1; i >= 0; --i) {
            running = (running + res[j-1][2*m-1-i]) % prime;
            res[j][i] = (running * ws[i]) % prime;
        }
    }
    cout << res[k+1][0] << endl;
    return 0;
}


Measured memory_bytes: 51584
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
double pi = 3.141592653589793;
using namespace std;
int z=0;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
//ここから始めよう
signed main(){
    int n;cin>>n;
    int a[111111];rep(i,0,n)cin>>a[i];
    sort(a,a+n);
    if(a[n-1]-a[0]>1){
        cout<<"No"<<endl;
        return 0;
    }
    if(a[n-1]==a[0]){
        if(a[0]==n-1||a[0]<=n/2)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        return 0;
    }
    int cnt=1;
    rep(i,1,n)if(a[i]==a[i-1])cnt++;else break;
    int left=1;
    for(int i=n-1;i>=1;i--)if(a[i]==a[i-1])left++;else break;
    if(cnt+1<=a[n-1]&&a[n-1]<=cnt+(left/2))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;return 0;
}

Measured memory_bytes: 1024
k = int(input())

print(50)
d, m = divmod(k, 50)

initial = [i for i in range(50)]


def undo_one(xs):
    m = 10**16+1001
    mi = None
    for i, x in enumerate(xs):
        if x < m:
            m = x
            mi = i
    xs[mi] += 51
    for i in range(50):
        xs[i] -= 1

def undo_k(xs, k):
    return list(map(lambda x: x+k, xs))

xs = undo_k(initial, d)
for i in range(m):
    undo_one(xs)

print(" ".join(map(str, xs)))




Measured memory_bytes: 3064
#include <iostream>
using namespace std;
typedef unsigned long long u64;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  for (char c = 'a'; c <= 'z'; ++c) {
    int isc = 0;
    int len = 0;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == c) {
        isc++;
      } else {
        isc--;
      }
      len++;
      if (isc < 0) {
        len = 0;
        isc = 0;
      } else if (len >= 2 && isc > 0) {
        cout << i - len + 2 << " " << i + 1 << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int cnt = 0;
	for(int i = 0; i < n;i++){
		int a;
		cin >> a;
		if (a == 2) { cnt++; continue; }
		if (a < 2 || a % 2 == 0)continue;
		int k = 3;
		bool flag = true;
		while (k <= sqrt(a))
		{
			if (a%k == 0)flag = false;
			k += 2;
		}
		if(flag)cnt++;
	}
	cout << cnt << endl;
	return 0;
}


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

int main() {
  int n; cin >> n;
  int tmp;
  rep(i,n) {
    cin >> tmp;
    if (tmp%2==0 && tmp%3!=0 && tmp%5!=0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

Measured memory_bytes: 256