akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n,m,Q;
vvll sum;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>m>>Q;
  
  vll l(m), r(m);
  rep(i,m) cin>>l[i]>>r[i];
  
  sum=vvll(n+1, vll(n+1));
  rep(i,m){
    sum[l[i]][r[i]]++;
  }
  
  rep(i,n){
    rep(j,n){
      sum[i+1][j+1]+=sum[i+1][j]+sum[i][j+1]-sum[i][j];
    }
  }
  
  vll p(Q), q(Q);
  rep(i,Q) cin>>p[i]>>q[i];
  
  rep(i,Q){
    ll l=p[i], r=q[i];
    ll ans=sum[r][r]-sum[r][l-1]-sum[l-1][r]+sum[l-1][l-1];
    cout<<ans<<endl;
  }
  
}

Measured memory_bytes: 7680
N, M = list(map(int, input().split()))
if N % 2 == 1:
    for i in range(1, M+1):
        print(i, N-i+1)
else:
    for i in range(1, M+1):
        if i % 2 == 1:
            print(N//2+M//2  -i//2, N//2+ M//2  - i//2 + i)
        else:
            print(M//2 + 1 - i//2, M//2 + 1 - i//2 + i)


Measured memory_bytes: 9284
import sys
x,k,d = map(int,input().split())

# x:位置　k：回数　d:距離

#往復に辿りつく前に終わるパターン
if(abs(x)-d*k >= 0):
    print(abs(abs(x)-d*k))
#0またいで往復するパターン
else:
    #往復直前までにかかる回数
    r_count = abs(x)//d
 
    #残り捜査回数
    rest = k - r_count

    #残り回数の奇遇によって計算を判断
    #残り回数が偶数の時はr_count分動かした時と変わらない
    if(rest %2 == 0):
        print(abs(abs(x) - d*r_count))
    #残り回数が奇数:さらにD移動した分？
    else:
        print(abs(abs(abs(x) - d*r_count)-d))


#通らない.....





Measured memory_bytes: 9104
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
#pragma endregion

int main() {
  cin >> N;
  string s;
  cin >> s;
  int count = 0;
  rep(i, N-2){
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') count++;
  }
  cout << count;
}



Measured memory_bytes: 256
//Try until you reach your goal
#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define endl "\n"
# define str string
# define vll vector<ll>
# define pb push_back
# define mll map<ll,ll>
# define mp make_pair
# define ff first
# define ss second
# define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll x;
    cin>>x;
    while(x--){
        cout<<"ACL";
    }
    return 0;
}

Measured memory_bytes: 3616
// Created by Krishna Ashok
#include <bits/stdc++.h>
using namespace std;

#define dbg(x) cout<<#x<<"="<<x<<'\n'
#define ll long long
#define pr pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define rep(i,n) for(int i=0;i<(n);++i)
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#define fin ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MOD 1000000007
const int INF=1e9;



void solve(){
  int n,k;
  cin>>n>>k;
  int h[n];
  for(int &x:h) cin>>x;  
  ll dp[n+1];
  //memset(dp,INT_MAX,sizeof(dp));
  for(int i=1;i<=n;i++)dp[i]=1e15;
  dp[1]=0;
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=i+k;j++)
    if(j<=n) dp[j]=min(dp[j],dp[i]+abs(h[i-1]-h[j-1]));
    // if(i+2<=n) dp[i+2]=min(dp[i+2],dp[i]+abs(h[i-1]-h[i+1]));
    //cout<<dp[i]<<" "<<dp[i+1]<<" "<<dp[i+2]<<endl;
  }
  //for(int x:dp) cout<<x<<" ";
  cout<<dp[n]<<endl; 
}



int main()
{
    fin;
    
      solve();
        //cout<<solve()<<"\n";
    
    return 0;
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}

template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}

template <typename T> void print(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void print(const T &value, const Args&... args){std::cout << value << " ";print(args...);}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  i64 A;
  i64 B;
  i64 C;
  char dot;
  
  while(cin >> A >> B >> dot >> C){
    
    dump(B * 100 + C);
    
    i64 ans = A * (i64)(B * 100 + C);
    ans /= 100;

    print(ans);
  }

  return 0;
}


Measured memory_bytes: 3660
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<queue>
#include<vector>
#define ll long long
#define lowbit(x) (x& -x)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-18
inline ll read()
{
    ll tmp=0; char c=getchar(),f=1;
    for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
    for(;'0'<=c&&c<='9';c=getchar())tmp=(tmp<<3)+(tmp<<1)+c-'0';
    return tmp*f;
}
using namespace std;
struct data{
	int id,k;
}a[200010];
int ans[200010];
int n;
bool cmp(data a,data b){return a.k<b.k;}
int main()
{
	int i;
	n=read();
	for(i=1;i<=n;i++)a[i].k=read(),a[i].id=i;
	sort(a+1,a+n+1,cmp);
	for(i=1;i<=n;i++)
		if(i<=n/2)ans[a[i].id]=a[n/2+1].k;
		else ans[a[i].id]=a[n/2].k;
	for(i=1;i<=n;i++)printf("%d\n",ans[i]);
	return 0;
}

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

int main(){
    int h,w,i;
    string ans="",temp="";
    while(1){
      cin>>h>>w;
      if (h==0&&w==0)break;
      else{
        for (i=0;i<w;i++)temp+="#";
        temp+="\n";
        for (i=0;i<h;i++)ans+=temp;
        cout<<ans<<endl;
        ans="";temp="";
      }
    }
    return 0;
}




Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*あらかじめAとBを用意して順番どおりに表示させればOK?
1 2 3 4 5
9 7 5 3 1
10 9 8 7 6
ああ、意味分かった。出力順の和を満たす必要があるのか
5   4  3  2  1
1   2  3  4  5 A
100 98 96 94 92 B

1   2  3  4  5
1   3  5  7  9 A
100 99 98 97 96 B

5 2  1  4  3
1 2  3  7  8 A
1との差をたしていく感じ？
5  7  8  12 15 A 順位をそのまま足す
99 96 92 91 89 5との差をさげる
2乗する
25 29 30 46 55
99 90 74 73 69
124119104119124

25 29 30 46 55
99 96 92 91 89 5との差をさげる
124125122137144

Aに加算、Bに減産していく感じ？
20000*20000ってアウトかな
5 2 1 4 3
1 2 3 4 5
5 4 3 2 1

Aは固定でBで調整か
うまくいかん。順位が高いものは大きく、小さいものは小さく。
5 2  1  4  3
1 2  3  7  8 A
1との差をたしていく感じ？
5  7  8  12 15 A 順位をそのまま足す
99 94 92 91 87 総合値からひいて、あてはめてみる
104101100103102
1  5  2  3  4
1  6  8  11 15
100 99 94 92 89
101105102103104
なんかいいかも。
ルール間違ってた･･･。
2 3 1として
大きさが2<3<1
N+1の差をたしてくA
2  3  1
2  3  6
2 3 1、大きさ順位は
3 1 2
3  4  6 Aは順位の差をたす
96 93 92 Bは総合との差 
99 97 98

*/
int main(){
  ll N; cin>>N;
  vector<ll> A(N+1,0), B(N+1,0), C(N+1,1e9), P(N+1,0);
  //順位が高いほうが高得点
  for(int i=1; i<=N; i++){
    ll p; cin>>p;
    P[p]=i;
    C[p]+=i;//総合点。後にでてくるほど加点iが大きい
  }
  //Aつくる
  ll sum=0;
  for(int i=1; i<=N; i++){
    sum+=P[i];
    A[i]=sum;
  }
  for(int i=1; i<=N; i++) B[i]=C[i]-A[i];
  for(int i=1; i<=N; i++){
    cout<<A[i];
    if(i==N)
      cout<<endl;
    else
      cout<<" ";
  }
  for(int i=1; i<=N; i++){
    cout<<B[i];
    if(i==N)
      cout<<endl;
    else
      cout<<" ";
  }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main () {
    int n;
    cin >> n;
    vector<int> a(n+1), b(n);
    for (int i = 0; i < n+1; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] >= b[i]) {
            a[i] -= b[i];
            ans += b[i];
        }
        else {
            b[i] -= a[i];
            ans += a[i];
            a[i] = 0;
            a[i+1] -= b[i];
            ans += b[i];
            b[i] = 0;
            if (a[i+1] < 0) {
                ans += a[i+1];
                a[i+1] = 0;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
pattern = {
    'r':P,
    's':R,
    'p':S
}
ret = 0
for i in range(N):
    tmp = i - K
    if tmp >= 0 and T[tmp] == T[i]:
        T[i] = ''
        continue
    ret += pattern[T[i]]
print(ret)


Measured memory_bytes: 4084
n = gets.to_i
a = gets.split.map(&:to_i)
max, min = a.max, a.min
if min >= 0
  puts n-1
  1.upto(n-1) do |i|
    puts [i, i+1].join(' ')
  end
elsif max <= 0
  puts n-1
  n.downto(2) do |i|
    puts [i, i-1].join(' ')
  end
elsif max.abs > min.abs
  puts 2*n-1
  (1..n).each do |i|
    puts [a.index(max)+1, i].join(' ')
  end
  1.upto(n-1) do |i|
    puts [i, i+1].join(' ')
  end
else
  puts 2*n-1
  (1..n).each do |i|
    puts [a.index(min)+1, i].join(' ')
  end
  n.downto(2) do |i|
    puts [i, i-1].join(' ')
  end
end

Measured memory_bytes: 1788
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)

	ans := int(1e10)
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			ans = min(ans, max(strlen(i), strlen(n/i)))
		}
	}
	fmt.Println(ans)
}

func strlen(i int) int {
	return len(strconv.Itoa(i))
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

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 INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k,a,b; string s;
char maze[60][60];
int dis[101][101];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int gcd(int x, int y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
int main() {
	cin >> s; int res = 0;
	rep(i, 4) {
		if (s[i] == '+') {
			res++;
		}
		else {
			res--;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

template <typename T>
struct ReRooting
{
  using F = function<T(T)>;
  using M = function<T(T, T)>;
  static const int MAX_V = 200010;
  int V;
  vector<int> E[MAX_V];
  vector<T> dp[MAX_V];
  //遷移：dp[vの子]にfを作用させてmergeでまとめる
  F f;
  M merge;
  T mi; //mergeの単位元
  int root;

  ReRooting(int V_, F f_, M merge_, T mi_) : V(V_), f(f_), merge(merge_), mi(mi_) {}

  void add_E(int a, int b)
  {
    E[a].push_back(b);
    E[b].push_back(a);
  }

  //上から下
  ll dfs1(int p, int v)
  {
    ll res = mi;
    rep(i, E[v].size())
    {
      if (E[v][i] == p)
        continue;
      dp[v][i] = dfs1(v, E[v][i]);
      res = merge(res, f(dp[v][i]));
    }

    return res;
  }

  //下から上
  void dfs2(int p, int v, T add)
  {
    //上から持ってきた値を清算
    rep(i, E[v].size())
    {
      if (E[v][i] == p)
      {
        dp[v][i] = add;
        break;
      }
    }

    //左右からの累積を作っておく
    vector<T> pL(E[v].size() + 1), pR(E[v].size() + 1);
    pL[0] = mi;
    rep(i, E[v].size()) pL[i + 1] = merge(pL[i], f(dp[v][i]));
    pR[E[v].size()] = 1;
    for (int i = E[v].size(); i > 0; --i)
      pR[i - 1] = merge(pR[i], f(dp[v][i - 1]));

    rep(i, E[v].size())
    {
      if (E[v][i] == p)
        continue;
      T val = merge(pL[i], pR[i + 1]);
      dfs2(v, E[v][i], val);
    }
  }

  void calc(int root = 0)
  {
    rep(i, V) dp[i].resize(E[i].size());
    dfs1(-1, root);
    dfs2(-1, root, 0);
  }

  T solve(int v)
  {
    T ans = mi;
    rep(i, E[v].size())
    {
      ans = merge(ans, f(dp[v][i]));
    }
    return ans;
  }
};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  ll n, m;
  cin >> n >> m;
  auto f = [](ll a) { return a + 1; };
  auto g = [&](ll a, ll b) { return a * b % m; };
  ReRooting<ll> re(n, f, g, 1);
  rep(i, n - 1)
  {
    int a, b;
    cin >> a >> b;
    a--, b--;
    re.add_E(a, b);
  }
  re.calc();
  rep(v, n) cout << re.solve(v) << endl;
  return 0;
}


Measured memory_bytes: 32256
#include <iostream>

using namespace std;

int main()
{
   int a ,b;
   cin >> a >> b;
   
   if (a < b)
       cout << "a < b" << endl; 
   else if (a > b)
       cout << "a > b" << endl;
   else
       cout << "a == b" << endl;
   
   return 0;
}


Measured memory_bytes: 3076
array = gets.chomp.split(" ").map(&:to_i)

N = array[0]
Y = array[1]
M = N+1 

a = -1
b = -1

M.times{|i|
  M.times{|j|
    if(9*i + 4*j == Y/1000 - N)
      a = i 
      b = j 
    end
  }
}

c = N - (a+b)

if (a < 0) || (b < 0) || (c < 0)
  a = -1
  b = -1
  c = -1
end

puts("#{a} #{b} #{c}")

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X;
  int range = 0;
  
  vector<int> A;
  vector<int> B;
  
  cin >> X;
  
  while (range < 100000000) {
    range += 100;
    
    for (int i = -range; i < range; i++) {
      //A.push_back(i * i * i * i * i);
      
      for (int j = -range; j < range; j++) {
        if ((i * i * i * i * i) - (j * j * j * j * j) == X) {
          cout << i << " " << j << endl;
          return 0;
        }  
      }  
    }      
  }  
}

Measured memory_bytes: 3584
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
using namespace std;

int D;
vector<int> c(26);
vector<vector<int>> s;

int scoring(const vector<int>& t) {
    int v = 0;
    vector<int> last(26, -1);
    rep(i, D) {
        v += s[i][t[i]];
        last[t[i]] = i;
        rep(j, 26) {
            v -= c[j] * (i - last[j]);
        }
    }
    return v;
}

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

    auto start = chrono::system_clock::now();
    
    cin >> D;
    rep(i, 26) cin >> c[i];
    s.resize(D, vector<int>(26));
    rep(i, D) rep(j, 26) cin >> s[i][j];

    vector<int> t(D);

    rep(i, D) t[i] = max_element(all(s[i])) - s[i].begin();
    
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> rand_d(0, D-1);
    uniform_int_distribution<> rand_t(0, 25);
    
    int v = scoring(t);
    int x = 0;
    while (true) {
        int to_d = rand_d(mt);
        int to_t = rand_t(mt);
        if (t[to_d] == to_t) continue;
        int old = t[to_d];
        t[to_d] = to_t;
        int nv = scoring(t);
        if (nv < v) {
            t[to_d] = old;
        }
        x++;
        if (x % 1000 == 0) {
            auto end = chrono::system_clock::now();
            auto dur = end - start;
            auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
            if (msec >= 1970) break;
        }
    }
    rep(i, D) cout << t[i] + 1 << '\n';
}


Measured memory_bytes: 3752
#include<stdio.h>
int main(){
  int x,y;
  while(1){
    scanf("%d%d",&x,&y);
    if(x == 0 && y == 0){
      break;
    }
    else if(x <= y){
      printf("%d %d\n",x,y);
    }   
    else{
	printf("%d %d\n",y,x);
      }
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int b1, b2, b3;
    cin >> b1 >> b2 >> b3;
    if((b1==1&&b2==1)||b3==1)
        cout << "Open" << endl;
    else 
        cout << "Close" << endl;
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

template<typename T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};

int main() {
    int n;cin >> n;
    vi p(n);
    rep(i,n)cin >> p[i];

    int ans = 1;
    int target = p[0];
    for(int i=1;i<n;i++){
        if(target>=p[i]){
            ans++;
            target = p[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li p[111];

int main() {

    li n;
    cin >> n;
    li a, b;
    li cnt[3] = {0};
    cin >> a >> b;
    rep(i, n) {
        cin >> p[i];
        if (p[i] <= a) {
            cnt[0]++;
        } else if (p[i] <= b) {
            cnt[1]++;
        } else {
            cnt[2]++;
        }
    }
    cout << min(cnt[0], min(cnt[1], cnt[2])) << endl;

    return 0;
}

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

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

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

    vector<int> B, W;
    int cnt = 1;
    for(int i = 1; i < n; i++){
        if(s[i - 1] == s[i]){
            cnt++;
            if(i == n - 1){
                if(s[i - 1] == '0'){
                    B.push_back(cnt);
                }else{
                    W.push_back(cnt);
                }
            }
        }else{
            if(s[i - 1] == '0'){
                B.push_back(cnt);
            }else{
                W.push_back(cnt);
            }
            cnt = 1;
        }
    }
    if(cnt == 1){
        if(s[n - 1] == '0'){
            B.push_back(cnt);
        }else{
            W.push_back(cnt);
        }
    }

    if(B.size() <= k){
        cout << n << endl;
        return 0;
    }

    int ans = 0;
    vector<int> Ba, Wa;
    Ba.push_back(0);
    Wa.push_back(0);
    for(int i = 0; i < B.size(); i++){
        Ba.push_back(Ba[Ba.size() - 1] + B[i]);
    }
    for(int i = 0; i < W.size(); i++){
        Wa.push_back(Wa[Wa.size() - 1] + W[i]);
        ans = max(ans, W[i]);
    }

    if(Ba.size() > Wa.size()){
        for(int i = k; i < Ba.size(); i++){
            if(i == Ba.size() - 1){
                ans = max(ans, Ba[i] - Ba[i - k] + Wa[(int)Wa.size() - 1] - Wa[(int)Wa.size() - 1 - k]);  
            }else if(i == k){
                ans = max(ans, Ba[i] - Ba[i - k] + Wa[i] - Wa[0]);
            }else{
                ans = max(ans, Ba[i] - Ba[i - k] + Wa[min(i, (int)Wa.size() - 1)] - Wa[max(0, i - k - 1)]);            
            }
        }
    }else if(Ba.size() < Wa.size()){
        for(int i = k; i < Ba.size(); i++){
            if(i == Ba.size() - 1){
                ans = max(ans, Ba[i] - Ba[i - k] + Wa[max(i + 1, (int)Ba.size() - 1)] - Wa[i - k]);  
            }else if(i == k){
                ans = max(ans, Ba[i] - Ba[i - k] + Wa[max(i, min(i + 1, (int)Wa.size() - 1))] - Wa[0]);   
            }else{
                ans = max(ans, Ba[i] - Ba[i - k] + Wa[min(i + 1, (int)Wa.size() - 1)] - Wa[max(0, i - k)]);            
            }
        }
    }else{
        for(int i = k; i < Ba.size(); i++){
            // cout << ans << endl;
            if(i == Ba.size() - 1){
                if(s[n - 1] == '0') ans = max(ans, Ba[i] - Ba[i - k] + Wa[i] - Wa[max(0, i - k)]);
                else ans = max(ans, Ba[i] - Ba[i - k] + Wa[i] - Wa[max(0, i - k - 1)]);
            }else if(i == k){
                if(s[0] == '0') ans = max(ans, Ba[i] - Ba[i - k] + Wa[i] - Wa[0]);
                else ans = max(ans, Ba[i] - Ba[i - k] + Wa[max(i, min(i + 1, (int)Wa.size() - 1))] - Wa[0]);   
            }else{
                ans = max(ans, Ba[i] - Ba[i - k] + Wa[min(i + 1, (int)Wa.size() - 1)] - Wa[max(0, i - k)]);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1372
from itertools import combinations
mod = 10**9 + 7
h, w, k = map(int, input().split())
edge = [[0]*w for i in range(w)]

for r in range(w//2+1):
    for c in combinations(range(w-1),r):
        # 横線が隣接する場合を排除
        flag = True
        if len(c) > 1:
            for i in range(len(c)-1):
                if c[i+1] - c[i] == 1:
                    flag = False
                    break
        if not flag:continue
        for i in range(w):
            if i in c: continue
            if i-1 in c:
                edge[i-1][i] += 1
                edge[i][i-1] += 1
            else:
                edge[i][i] += 1

# DP[i][j] == i行目まで見た時に1がjの位置にある場合の数
DP = [[0]*w for i in range(h+1)]
DP[0][0] = 1
for i in range(h):
    for j in range(w):
        for l in range(w):
            DP[i+1][j] = (DP[i+1][j] + DP[i][l]*edge[l][j]) % mod
#print(DP)
print(DP[-1][k-1])

Measured memory_bytes: 3064
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int solve(const string &s) {
  int len = s.size();
  int l, r;
  char c;
  if(len % 2 == 0) {
    r = len / 2;
    l = r - 1;
    c = s[l];
  } else {
    l = len / 2 - 1;
    r = l + 2;
    c = s[len / 2];
  }
  while(l >= 0 && s[l] == c && s[r] == c) {
    l--;
    r++;
  }
  return max(len - l - 1, (len+1) / 2);
}

int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  cout << solve(s) << endl;
  
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = 1L<<60;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll a, b;
/******* define variable end *******/
int solve() {
	cin >> a >> b;
	cout << a * b << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 3656
#include <iostream>
using namespace std;
#define MAX 100000
#define MAX_ 50000

void merge_sort(int x[],int left,int right){
    int mid,i,j;
    int temp[MAX];
    
    if(left >= right)
        return;
    
    mid = (left + right) / 2;
    merge_sort(x, left ,mid);
    merge_sort(x, mid + 1,right);
    
    for(int i = left;i <= mid; i++){
        temp[i] = x[i];
    }
    
    for(int i = mid + 1,j = right; i <= right; i++,j--){
        temp[i] = x[j];
    }
    
    i = left;
    j = right;
    
    for(int k = left; k <= right; k++){
        if(temp[i] <= temp[j]) x[k] = temp[i++];
        else x[k] = temp[j--];
    }
}


int main(){
    int n,S[MAX],q,T[MAX_],cnt=0;
    
    cin >> n;
    for(int i = 0;i < n; i++) cin >> S[i];
    
    cin >> q;
    for(int j = 0;j < q; j++) cin >> T[j];
    
    merge_sort(S, 0, n-1);
    merge_sort(T, 0, q-1);
    
    
    for(int i = 0,j = 0;i < n && j < q ; ){
        if(S[i]==T[j]) cnt++,i++,j++;
        else if(S[i] < T[j]) i++;
        else if(S[i] > T[j]) j++;
        
    }
    
    cout << cnt << endl;
    
    return 0;
}



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

int main() {
  int H,W; cin >> H >> W;
  char a[H][W]; rep(i,0,H) rep(j,0,W) cin >> a[i][j];
  
  rep(i,0,H+2) {
    rep(j,0,W+2) {
      if (i == 0 || i == H+1) cout << "#"; 
      else if (j == 0 || j == W+1) cout << "#";
      else cout << a[i-1][j-1];
    }
    cout << endl;
  }
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define x first
#define y second

const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int h, w, n;
int fact[N], invfact[N], reach[N], leave[N];
pair<int, int> a[N];

inline int add(int x, int y) { x += y; return x % mod;}
inline int sub(int x, int y) { x -= y; x %= mod; x += mod; return x % mod;}
inline int mul(int x, int y) { return (x * y) % mod;}
inline int powr(int a, int b) {
	int x = 1 % mod;
	b %= (mod - 1);
	while (b) {
		if (b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}
inline int inv(int a) { return powr(a, mod - 2);}
void pre()
{
	fact[0] = invfact[0] = 1;
	for (int i = 1; i < N; i++)
		fact[i] = mul(i, fact[i - 1]);

	invfact[N - 1] = inv(fact[N - 1]);
	for (int i = N - 2; i >= 1; i--)
		invfact[i] = mul(invfact[i + 1], i + 1);

	assert(invfact[1] == 1);
}
inline int nCr(int n, int k)
{
	if (n < k || k < 0)
		return 0;
	return mul(fact[n], mul(invfact[k], invfact[n - k]));
}

int formula(int x1, int y1, int x2, int y2)
{
	if (y1 > y2)
		return 0;
	return nCr(x2 - x1 + y2 - y1, x2 - x1);
}

void computedp()
{
	reach[1] = formula(1, 1, a[1].x, a[1].y);
	for (int i = 2; i <= n; i++)
	{
		reach[i] = formula(1, 1, a[i].x, a[i].y);
		int subtract = 0;
		for (int j = 1; j < i; j++)
		{
			subtract += reach[j] * formula(a[j].x, a[j].y, a[i].x, a[i].y);
			subtract %= mod;
		}
		reach[i] -= subtract;
		reach[i] += mod;
		reach[i] %= mod;
	}
}

int32_t main()
{
	IOS;
	pre();
	cin >> h >> w >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].x >> a[i].y;
	}
	n++;
	a[n].x = h;
	a[n].y = w;
	sort(a + 1, a + n + 1);
	computedp();
	cout << reach[n];
}


Measured memory_bytes: 5632
#include <iostream>
#include <vector>
#include <string>
#include <set>

using namespace std;

int main()
{
  long x;
  cin >> x;
  long y, n;
  y = 100;
  n = 0;
  do{
    y = y+ y/100;
    n++;
  }while(y < x);
  cout << n<< endl;
 }


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

using LL = long long;
using LD = long double;
 
LL mod = 1e9+7;

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

	vector<vector<LL>> adj(n);

	for (LL i = 1; i < n; ++i) {
		LL x;
		cin >> x;
		adj[i].push_back(x-1);
		adj[x-1].push_back(i);
	}

	cout << adj[0].size() << "\n";
	for (LL i = 1; i < n; ++i) {
		cout << adj[i].size()-1 << "\n";
	}
}



Measured memory_bytes: 16244
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c,d,i=0;
  cin>>a>>b>>c>>d;
  for(int i=1;;i++)
  {
      if(i%2)
        c-=b;
      else
        a-=d;
      if(a<=0)
      {
          cout<<"No\n";
          break;
      }
      if(c<=0)
      {
          cout<<"Yes\n";
          break;
      }
  }
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define invrep(i, n) for(int i = (n)-1; i >= 0; i--)        // n-1, n-2, ..., 0
#define invREP(i, x, n) for(int i = (n)-1; i >= (x; i--)    // n-1, n-2, ..., x
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define PB push_back

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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

ll dp[100010][3];
ll a[100010][3];

int main(){
    int N; cin >> N;
    rep(i, N) rep(j, 3) cin >> a[i][j];

    rep(i, N){
        rep(j, 3){
            rep(k, 3){
                if(j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }
    ll res = 0;
    rep(j, 3) chmax(res, dp[N][j]);
    COUT(res);
}   

Measured memory_bytes: 4992
def listprint(lists):
	global N
	count = 0
	for i in lists:
		count += 1
		if count < N:
			print(i, end = ' ')
		if count == N:
			print(i)

if __name__ == '__main__':
	N = int(input())
	l = input().split()

	for i in range(N):
		l[i] = int(l[i])

	listprint(l)

	for i in range(1, N):
		v = l[i]
		j = i - 1

		while j >= 0 and l[j] > v:
			l[j + 1] = l[j]
			j -= 1

		l[j + 1] = v
		listprint(l)


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

int main() {
    int n, k;
    cin >> n >> k;
    bool d[10] = {1,1,1,1,1,1,1,1,1,1};
    for(int i=0; i<k; i++) {
        int a;
        cin >> a;
        d[a] = 0;
    }

    int ans=n;
    while(1) {
        int i = ans;
        bool flag=1;
        while(i!=0) {
            if(!d[i%10]) flag=0;
            i /= 10;
        }
        if(flag) break;
        ans++;
    }

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int u, v, cost; };
int mod = 1000000007;

signed main() {
	int n; cin >> n;
	rep(i, 100) {
		rep(j, 100) {
			if (i * 4 + j * 7 == n) {
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>

using namespace std;

int ga, gb;
int depth;

vector<pair<pair<int, int>, int>> get(long long a, long long b, int k)
{
    if (++depth > 10) assert(0);
    if (a <= k && b <= k) {
        vector<pair<pair<int, int>, int>> ret;
        ret.push_back(make_pair(make_pair(a, b), 1));
        return ret;
    }
    long long l = 1, r = a + b + 1;
    if (a > b) {
        if (b * k < a) {
            vector<pair<pair<int, int>, int>> ret;
            ret.push_back(make_pair(make_pair(k, 1), b));
            ret.push_back(make_pair(make_pair(a - b * k, 0), 1));
            return ret;
        }
        while(l + 1 < r) {
            long long mid = (l + r) / 2;
            long long la = a - mid * k, lb = b - mid;
            if (la < 0 || lb < 0 || la * k < lb || lb * k < la) {
                r = mid;
            } else {
                l = mid;
            }
        }
        long long la = a - l * k, lb = b - l;
        vector<pair<pair<int, int>, int>> ret = get(la, lb, k);
        ret.insert(ret.begin(), make_pair(make_pair(k, 1), l));
        return ret;
    } else {
        if (a * k < b) {
            vector<pair<pair<int, int>, int>> ret;
            ret.push_back(make_pair(make_pair(0, b - a * k), 1));
            ret.push_back(make_pair(make_pair(1, k), a));
            return ret;
        }
        while(l + 1 < r) {
            long long mid = (l + r) / 2;
            long long lb = b - mid * k, la = a - mid;
            if (la < 0 || lb < 0 || la * k < lb || lb * k < la) {
                r = mid;
            } else {
                l = mid;
            }
        }
        long long lb = b - l * k, la = a - l;
        vector<pair<pair<int, int>, int>> ret = get(la, lb, k);
        ret.push_back(make_pair(make_pair(1, k), l));
        return ret;
    }
}

void solve()
{
    int n;
    cin >> n;
    for( ; n--; ) {
        depth = 0;
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int len;
        if (a >= b) {
            len = (a - 1) / (b + 1) + 1;
        } else {
            len = (b - 1) / (a + 1) + 1;
        }
        vector<pair<pair<int, int>, int>> vec = get(a, b, len);
        for(int i = c; i <= d; ++ i) {
            int x = i;
            for(int j = 0; j < vec.size(); ++ j) {
                int a = vec[j].first.first;
                int b = vec[j].first.second;
                int mul = vec[j].second;
                if (x <= (a + b) * mul) {
                    x %= a + b;
                    if (x == 0) x += a + b;
                    if (x <= a) putchar('A');
                    else putchar('B');
                    break;
                } else {
                    x -= (a + b) * mul;
                }
            }
        }
        puts("");
    }
}

int main()
{
    solve();
    return 0;
}


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

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

  ll r = 0, g = 0, b = 0;
  for (auto c: s) {
    if (c == 'R') ++r;
    else if (c == 'G') ++g;
    else ++b;
  }
  ll all = r * g * b;
  ll sub = 0;
  for (int i=0; i<n; ++i) {
    for (int j=i+1; j<n; ++j) {
      if (s[i] == s[j]) continue;
      int k = j*2 - i;
      if (k >= n || s[k] == s[i] || s[k] == s[j]) continue;
      ++sub;
    }
  }
  cout << all-sub << endl;
  return 0;
}


Measured memory_bytes: 3632
N=gets.to_i
A=gets.split.map &:to_i
minc=2
maxc=2
(N-1).downto(0){|k|
  if (minc/A[k].to_f).ceil>(maxc/A[k]) then
    p -1
    exit
  end
  minc=(minc/A[k].to_f).ceil*A[k]
  maxc=(maxc/A[k])*A[k]+A[k]-1
}
puts "#{minc} #{maxc}"

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

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    int sum = y + 2 * z;
    int ans = 1;
    while(sum + y + z <= x) {
        ans++;
        sum+= y + z;
    }

    cout << ans << endl;
}

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

int P[100010],com,x,y;
int n,q;

void init(int N) {
for (int i=0; i<=N; ++i) P[i] = i;
}

int root(int a) {
if (P[a] == a) return a;
return (P[a] = root(P[a]));
}

bool same(int a, int b) {
return root(a) == root(b);
}

void unite(int a, int b) {
P[root(a)] = root(b);
}

int main()
{
    cin>>n>>q;
    init(n);
    for(int i=0;i<q;i++)
    {
        cin>>com>>x>>y;
        if(com==0){
            unite(x,y);
        }
        else{
            cout<<same(x,y)<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3212
#include<stdio.h>
int main(void)
{
	int H,M,S,x,y,z;
	scanf("%d",&z);
	S=z%60;
	x=z/60;
	M=x%60;
	H=x/60;
	
	printf("%d:",H);
	printf("%d:",M);
	printf("%d\n",S);
	return 0;
}


Measured memory_bytes: 2000
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int, int>;
int main()
{
	int n;
	cin >> n;
	vector<int> vec(n), ans(n);
	int sum = 0;
	rep(i, n) {
		cin >> vec[i];
		sum ^= vec[i];
	}
	rep(i, n) {
		ans[i] = sum ^ vec[i];
		cout << ans[i];
		if (i < n - 1)	cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 4764
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){

    int n;
    cin >> n;
    int ans  = 0;

    rep(i,1,n){
	if(i != n-i)ans++;
    }
    P(ans/2);
    return  0;
}


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

using namespace std;

int main(int, char**)
{

	uint d;
	unsigned long long ans = 0;
	std::cin >> d;

	if (d == 25) {
		cout << "Christmas" << endl;
	} else if (d == 24) {
		cout << "Christmas Eve" << endl;
	} else if (d == 23) {
		cout << "Christmas Eve Eve" << endl;
	} else {
		cout << "Christmas Eve Eve Eve" << endl;
	}

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <stack>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

typedef long long ll;

int main()
{
  char s[10];
  scanf("%s",s);
  if(s[0]==s[2]) printf("Yes");
  else printf("No");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include<stdio.h>
#include <functional>
#include<algorithm>
#define PI 3.14159265
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define SZ(x) ((int)(x).size())

using namespace std;



int main() {
	int a,b;
	cin >> a >> b;
	cout << (a - 1)*(b - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
s=input().rstrip()
x=list(s)
A=0;
while(1):
    G=0;
    for i in range(1,len(x)-1):
        if x[i-1]!=x[i+1]:
            del(x[i])
            A+=1;
            G=1;
            break;
    if G==0:
        break;
if A%2==0:
    print("Second")
else:
    print("First")

Measured memory_bytes: 4084