akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){
    ll n;cin>>n;
    l_l a[n];rep(i,0,n-1){
        cin>>a[i].first;a[i].second=i;
    }
    sort(a,a+n);
    ll k=a[n-1].second;
    rep(i,0,n-1){
        if(i==k){
            cout<<a[n-2].first<<endl;
        }else{
            cout<<a[n-1].first<<endl;
        }
    }
    
    return 0;
}







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

using namespace std;

typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 7654321
#define IINF 87654321987654321LL
#define MAXV 200500

ll mod = 1e9 + 7;

int N;
char p[100500];

char tmp[10050];
string s;
void send(int x){
	printf("%d\n",x); fflush(stdout);
}
void get(){
	scanf("%s",tmp); s = tmp;
}

vector<int> list;
int main(){
	
	geti(N);
	
	if( N <= 20 ){
		for(int i=0;i<N;i++){
			send(i); get();
			if( s == "Vacant" ) return 0;
		}
	}

	send(0); get();
	if( s == "Vacant" ){
		return 0;
	}
	if( s == "Male" ) p[0] = 'M';
	if( s == "Female" ) p[0] = 'F';

	send(N/2); get();
	if( s == "Vacant" ){
		return 0;
	}
	if( s == "Male" ) p[N/2] = 'M';
	if( s == "Female" ) p[N/2] = 'F';

	send(N-1); get();
	if( s == "Vacant" ){
		return 0;
	}
	if( s == "Male" ) p[N-1] = 'M';
	if( s == "Female" ) p[N-1] = 'F';
	bool found = false;
	int l = -1, r = -1;
	if( ! found ) if( (N/2+1)%2 == 0 && p[0] == p[N/2] ){
		l = 0, r = N/2; found = true;
	} 
	if( ! found ) if( (N/2+1)%2 == 1 && p[0] != p[N/2] ){
		l = 0, r = N/2; found = true;
	} 
	
	if( ! found ) if( (N-1 - N/2 + 1 )%2 == 0 && p[N-1] == p[N/2] ){
		l = N/2; r = N-1; found = true;
	}
	if( ! found ) if( (N-1 - N/2 + 1 )%2 == 1 && p[N-1] != p[N/2] ){
		l = N/2; r = N-1; found = true;
	}

	while( true ){
		int mid = (l+r)/2;
		send(mid); get();
		if( s == "Vacant" ){
			return 0;
		}
		if( s == "Male" ) p[mid] = 'M';
		if( s == "Female" ) p[mid] = 'F';

		// [l,mid]
		if( (mid-l+1)%2 == 0 && p[mid] == p[l] ){
			r = mid; continue;
		}
		if( (mid-l+1)%2 == 1 && p[mid] != p[l] ){
			r = mid; continue;
		}

		// [mid,r]
		if( (r-mid+1)%2 == 0 && p[r] == p[mid] ){
			l = mid; continue;
		}
		if( (r-mid+1)%2 == 1 && p[r] != p[mid] ){
			l = mid; continue;
		}
	}
	


}

Measured memory_bytes: 852
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn= new Scanner(System.in);
        int start= scn.nextInt();
        int end = scn.nextInt();
        int answer = 0;
        for(int i=start;i<=end;i++){
            String buf = String.valueOf(i);
            for(int j=0;j<buf.length()/2;j++){
                char r = buf.charAt(j);
                char l = buf.charAt(buf.length()-1-j);
                if(r!=l){
                    answer--;
                    break;
                }
            }
            answer++;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 30164
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define ffor(n) for(ll i=0;i<n;i++)
#define rfor(x,y) for(ll i=x;i<y;i++)
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
void solve()
{
    ll n;
    cin>>n;
    ll arr[n][3];
    ffor(n)
    {   
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    ll dp[n][3];
    dp[0][0] = arr[0][0];
    dp[0][1] = arr[0][1];
    dp[0][2] = arr[0][2];
    rfor(1,n)
    {   
        dp[i][0] = max(dp[i-1][1] + arr[i][0] , dp[i-1][2] + arr[i][0]);
        dp[i][1] = max(dp[i-1][0] + arr[i][1] , dp[i-1][2] + arr[i][1]);
        dp[i][2] = max(dp[i-1][0] + arr[i][2] , dp[i-1][1] + arr[i][2]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}
int main()
{   fastio;
    ll t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 8236
h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
#print(c)
ans = 0
from itertools import product

for rb in product(range(2), repeat=h):
    for cb in product(range(2), repeat=w):
        cnt = 0
        for row in range(h):
            for col in range(w):
                if c[row][col] == "#" and rb[row]==0 and cb[col]==0:
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)

Measured memory_bytes: 9176
o=list(input())
e=list(input())
re=""
if len(o)==len(e):
    for i in range(len(o)):
        o[i]+=e[i]
    for j in range(len(o)):
        re+=o[j]
    print(re)
elif len(o)>len(e):
    for i in range(len(o)-1):
        o[i]+=e[i]
    for j in range(len(o)):
        re+=o[j]
    print(re)
else:
    for i in range(len(o)):
        o[i]+=e[i]
    for j in range(len(o)):
        re+=o[j]
    re+=e[len(e)-1]
    print(re)


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

int main(void){
    int n; long long int a[100];
    cin >> n;
    long long int max,min;
    cin >> a[0];
    max = min = a[0];
    for(int i = 1; i < n;i++){
        cin >> a[i];
        if(max < a[i])max = a[i];
        if(min > a[i])min = a[i];
    }
    cout << max - min << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> C(n - 1), S(n - 1), F(n - 1);
    rep(i, n - 1) {
        cin >> C[i] >> S[i] >> F[i];
    }

    rep(i, n - 1) {
        int ans = 0;
        ans += S[i] + C[i];

        for (int j = i + 1; j < n - 1; j++) {
            if (ans == S[j]) {
                ans += C[j];
            } else if (ans < S[j]) {
                ans += C[j] + (S[j] - ans);
            } else {
                if ((ans - S[j]) % F[j] == 0) {
                    ans += C[j];
                } else {
                    ans += C[j] + F[j] - (ans - S[j]) % F[j];
                }
            }
        }

        cout << ans << endl;
    }

    cout << 0 << endl;
}

Measured memory_bytes: 3604
#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 ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

void solve() {
	int N;
	cin >> N;
	
	vector<int> K(N), L(N), R(N);
	REP(i, N) scanf("%d %d %d", &K[i], &L[i], &R[i]), --K[i];
	
	vector<int> ord(N);
	iota(ALL(ord), 0);
	sort(ALL(ord), [&](int i, int j) {
		return abs(L[i] - R[i]) > abs(L[j] - R[j]);
	});
	
	set<int> ls, rs;
	ll ans = 0;
	REP(i, N) {
		ls.insert(-i);
		rs.insert(i);
	}
	// i \leq K[i] then L[i], i > K[i] then R[i]
	
	for (int i : ord) {
		if (L[i] > R[i]) {
			auto it = ls.lower_bound(-K[i]);
			if (it != ls.end()) {
				ls.erase(it);
				ans += L[i];
			}
			else ans += R[i];
		}
		else { // duality
			++K[i];
			auto it = rs.lower_bound(K[i]);
			if (it != rs.end()) {
				rs.erase(it);
				ans += R[i];
			}
			else ans += L[i];
		}
	}
	cout << ans << endl;
}

int main() {
	int T;
	cin >> T;
	while (T--) solve();
	return 0;
}


Measured memory_bytes: 25140
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
#define inf LLONG_MAX
#define bp __builtin_popcountll
#define pb push_back
#define ff first
#define ss second
#define P pair<ll,ll>
#define N 100001
#define all(a) a.begin(),a.end()
#define LG 20
#define int ll
#define nl '\n'
#define sp " "
#define vi vector<int>
#define f(n) for(int i=0;i<n;i++)
#define mod 1000000007
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define ps(x,y) fixed<<setprecision(y)<<x
#define F(i,a,b) for(int i = a ; i < b ; i++)
#define print_vector(v) cout<< #v << " " ; for(auto j:v) cout<<j<<sp; cout<<nl;
#define deb(x) cout<< #x << " " << x << endl;


// vector<vector<int>> dp(100002, vector<int>(6,-1));
int dp[100002][6];


int power(int x, int y){
    if(y==0) return 1;
    int temp = power(x,y/2);

    int curr = (temp*temp)%mod;
    if(y%2) return (curr*x)%mod;
    else return curr;
}



// void dfs(int curr){

// }



void solve(){
    string s,t;
    cin>>s>>t;
    int n = t.length();
    int ans = INT_MAX;
    for(int i=0;i+n<=s.length();i++){
        int temp = 0;
        for(int j = i;j<i+n;j++){
            if(s[j]!=t[j-i]) temp++;
        }
        ans = min(ans,temp);
    }

    cout<<ans<<nl;
}

signed main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast;
    // int t;
    // cin>>t; 
    // while(t--){
        solve();
    // }
}

Measured memory_bytes: 3652
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int k = parseInt(sc.next());
		int s = parseInt(sc.next());
		sc.close();
		int cnt=0;
		int z=0;
		for (i = 0; i <= k; i++) {
			for (j = 0; j <= k; j++) {
				z = s-(i+j);
				if(0<=z && z<=k)cnt++;
			}
		}
		out.println(cnt);
	}
}


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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORE(i, a, b) for (int i = (a); i <= (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
typedef pair<int, int> P;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<int> > dp(h + 1, vector<int>(w, 0));
    dp[0][0] = 1;
    rep(i, h) {
        rep(j, w) {
            rep(k, 1 << (w - 1)) {
                bool ok = true;
                rep(l, w - 2) {
                    if (((k >> l) & 1) && ((k >> (l + 1)) & 1)) {
                        ok = false;
                    }
                }
                if (ok) {
                    if (j >= 1 && ((k >> (j - 1)) & 1)) {
                        dp[i + 1][j - 1] += dp[i][j];
                        dp[i + 1][j - 1] %= MOD;
                    } else if (j <= w - 2 && ((k >> j) & 1)) {
                        dp[i + 1][j + 1] += dp[i][j];
                        dp[i + 1][j + 1] %= MOD;
                    } else {
                        dp[i + 1][j] += dp[i][j];
                        dp[i + 1][j] %= MOD;
                    }
                }
            }
        }
    }

    cout << dp[h][k - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int x;
    cin >> x;
    int ans = 1;
    for (int i = 2; i < x; i++)
    {
        int power = i * i;
        while (power<=x)
        {
            ans = max(ans, power);
            power *= i;
        }
    }
    cout << ans << endl;
}

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



int main(){

    ios::sync_with_stdio(0) ;
    cin.tie(0) ;

    long long r, D, a ;
    cin >> r >> D >> a ;
    for(int i = 0; i<10; i++){

        a = a*r - D ;
        cout << a << '\n' ;

    }

}


Measured memory_bytes: 256
import math 
import bisect
import heapq
from collections import deque

n,k = map(int,input().split())
s = input()
dif = 0

for i in range(n-1):
    if s[i] != s[i+1]:
        dif += 1

same = n-1-dif
if k > dif // 2:
    ans = n-1
else: ans = same + 2*k

print(ans)

Measured memory_bytes: 3564
import sys

def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))
    cnt = 1
    D = 0
    for a in A:
        D += a
        if D > X:
            break
        cnt += 1

    return cnt

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3060
import annotation.tailrec
import collection.mutable.ListBuffer
import io.StdIn

object Main extends App {

  @tailrec
  def primeFactRec(acc:ListBuffer[Long], num:Long, root:Long):List[Long] = {

    if(root * root > num) (acc += num).toList
    else {
      if(num % root == 0L) primeFactRec((acc += root), num/root, root)
      else primeFactRec(acc, num, root+1L)
    }
  }

  def callPrimeFactRec(n:Long):List[Long] = {
    val ret = ListBuffer.empty[Long]
    primeFactRec(ret, n, 2L)
  }

  val n = StdIn.readLong

  val ans = callPrimeFactRec(n)
  println(n + ": " + ans.mkString(" "))
}


Measured memory_bytes: 43836
#include <bits/stdc++.h>
#define MAX 1000000007
using namespace std;

pair <int,int> p1[100001];
pair <int,int> p2[100001];
vector <pair<int,int> > adj[100001];
bool vis[100001]={false};

long long int prim(int x)
{
	priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
	int y;	long long int minCost=0;	pair<int,int> p;
	
	q.push(make_pair(0,x));
	
	while(!q.empty())
	{
		p=q.top();	q.pop();	x=p.second;
		if(vis[x]) continue;
		minCost+=p.first;	vis[x]=true;
		for(int i=0;i<adj[x].size();i++)
		{
			y=adj[x][i].second;
			
			if(!vis[y]) q.push(adj[x][i]);
		}
	}
	return minCost;
}

int main() 
{
	long long int n,u,v;
	
    cin>>n;
    
    for(int i=0;i<n;i++)
    {
    	cin>>u>>v;
    	
    	p1[i]=make_pair(u,i);
    	p2[i]=make_pair(v,i);
    }
    
    sort(p1,p1+n);
    sort(p2,p2+n);
    
    for(int i=0;i<n-1;i++)
    {
    	adj[p1[i].second].push_back(make_pair(abs(p1[i].first-p1[i+1].first),p1[i+1].second));
    	adj[p1[i+1].second].push_back(make_pair(abs(p1[i].first-p1[i+1].first),p1[i].second));
    	
    	adj[p2[i].second].push_back(make_pair(abs(p2[i].first-p2[i+1].first),p2[i+1].second));
    	adj[p2[i+1].second].push_back(make_pair(abs(p2[i].first-p2[i+1].first),p2[i].second));
    }
    
    cout<<prim(1)<<endl;
	return 0;
}

Measured memory_bytes: 10616
# ABC066C - pushpush (ARC077)
def main():
    N, *A = map(int, open(0).read().split())
    if int(N) & 1:
        B = A[::2][::-1] + A[1::2]
    else:
        B = A[1::2][::-1] + A[::2]
    print(*B)


if __name__ == "__main__":
    main()

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int a;
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;

	return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <stdio.h>

using namespace std;

int main(){
  int h, w;
  
  while(1){
    scanf("%d %d", &h, &w);
    if(h==0 && w==0){
      break;
    }
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	    printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
} 



Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e3+7;
map<int,int> mp;
vector<int> a[maxn];
int main()
{
	int len;cin>>len;
	string s;cin>>s;
	//int len=s.length();
	if(len%2==1)
	{
		puts("No");
		return 0;
	}
	for(int i=0;i<len/2;i++)
	{
		if(s[i]!=s[i+len/2])
		{
			puts("No");
		return 0;
		}
	}
	puts("Yes");
 } 

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

using ldbl = long double;

int n;
ldbl xs[50];
ldbl ys[50];

ldbl g(ldbl x, ldbl y) {
    ldbl mx = 0.0;
    forn(i, n) {
        ldbl dx = x - xs[i];
        ldbl dy = y - ys[i];
        chmax(mx, dx * dx + dy * dy);
    }
    return mx;
}

ldbl f(ldbl y) {
    ldbl ans = 0.0;
    ldbl l = -1.0, r = 2000.0;
    forn(i, 200) {
        ldbl c = (r - l) / 3.0;
        ldbl r1 = g(l + c, y), r2 = g(r - c, y);
        if (r1 <= r2) {
            ans = r1;
            r -= c;
        } else {
            ans = r2;
            l += c;
        }
    }
    return ans;
}

int main() {
    fastio();

    cin >> n;
    forn(i, n) {
        cin >> xs[i] >> ys[i];
    }

    ldbl b = -1.0, t = 2000.0;
    forn(i, 200) {
        ldbl c = (t - b) / 3.0;
        if (f(b + c) <= f(t - c)) {
            t -= c;
        } else {
            b += c;
        }
    }

    cout << setprecision(20) << sqrt(f(t)) << endl;

    return 0;
}

Measured memory_bytes: 256
S = list(input())
T = list(input())

# S=list("BBAAABA")
# T=list("BBBA")

q = int(input())

l = []
for i in range(q):
	l.append(list(map(int,input().split(" "))))


sta = [0 for i in range(len(S))]
stb = [0 for i in range(len(S))]

tta = [0 for i in range(len(T))]
ttb = [0 for i in range(len(T))]

if S[0] == "A":
	sta[0] = 1
else:
	stb[0] = 1

if T[0] == "A":
	tta[0] = 1
else:
	ttb[0] = 1

for i in range(1,len(S)):
	if S[i] == "A":
		sta[i] = sta[i-1]+1
		stb[i] = stb[i-1]
	else:
		sta[i] = sta[i-1]
		stb[i] = stb[i-1]+1

for i in range(1,len(T)):
	if T[i] == "A":
		tta[i] = tta[i-1]+1
		ttb[i] = ttb[i-1]
	else:
		tta[i] = tta[i-1]
		ttb[i] = ttb[i-1]+1


def get(l,a,b):
	if a == 0:
		return(l[b])
	else:
		return(l[b]-l[a-1])

for a,b,c,d in l:
	sa = get(sta,a-1,b-1)
	sb = get(stb,a-1,b-1)
	ta = get(tta,c-1,d-1)
	tb = get(ttb,c-1,d-1)


	if (sa+sb*2)%3 == (ta+tb*2)%3:
		print("YES")
	else:
		print("NO")





















Measured memory_bytes: 45584
dic={}
h,w,d=map(int,input().split())
def cost(a,b):
    return abs(a[0]-b[0])+abs(a[1]-b[1])
for i in range(h):
    a=list(map(int,input().split()))
    for j in range(w):
        dic[a[j]]=(i+1,j+1)
dis=[[0] for i in range(d)]
for i in range(d):
    k=1
    for j in range(i+d,h*w,d):
        dis[i].append(dis[i][k-1]+cost(dic[j-d+1],dic[j+1]))
        k+=1
# print(dis)
q=int(input())
ans=0
for i in range(q):
    l,r=map(int,input().split())
    k=l%d-1
    print(dis[k][(r+d-1)//d-1]-dis[k][(l+d-1)//d-1])

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

#define INF 0x1234ABCD

int main(){
	int n;
	int max;
	int min;
	int ans=INF;
	cin>>n;
	vector<int>x(n);
	rep(i,n)cin>>x[i];
	sort(x.begin(),x.end());
	min=x[0];
	sort(x.begin(),x.end(),greater<int>());
	max=x[0];
	for(int i=min;i<=max;++i){
		int sum=0;
		for(int j=0;j<n;++j){
			sum+=(x[j]-i)*(x[j]-i);
		}
		if(sum<ans)ans=sum;
	}
	cout<<ans<<endl;

	return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

//    	File file = new File("test.txt");
//    	Scanner sc = new Scanner(file);
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        sc.close();
        int t = a;
        a = b;
        b = t;
        t = a;
        a = c;
        c = t;
        System.out.printf("%d %d %d", a, b, c);

    }
}

Measured memory_bytes: 21844
def sep():
    return map(int,input().strip().split(" "))
def lis():
    return list(sep())

n=int(input())
ar=lis()
data=[]
for i in range(n):
    data.append((ar[i],i))
data.sort(reverse=True)
dp = [[0] * (n+1) for _ in range(n+1)]

for i in range(n):
    a, p = data[i]
    for j in range(i+1):
        dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + abs(n-1-j-p)*a)
        dp[i+1][j] = max(dp[i+1][j], dp[i][j] + abs(i-j-p)*a)
#print(dp)
print(max(dp[-1]))








Measured memory_bytes: 105960
#include<iostream>
#define long long long
using namespace std;

int n;
long f[87];

int main()
{
    cin>>n;
    f[0]=2;
    f[1]=1;
    for(int i=2;i<=n;i++)
        f[i]=f[i-1]+f[i-2];
    cout<<f[n];
}

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

int main(){
  int N,M;
  cin >> N >> M;
  vector<pair<int,int>> A(N,pair<int,int>(0,0));
  for(int i=0;i<N;i++){
    cin >> A.at(i).second >> A.at(i).first;
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  vector<int> D(M+1,0);
  int count=0;
  int shortcut=1;
  int C=M;
  ll sum = 0;
  for(int i=0;i<N;i++){
    for(int j=max(A.at(i).second,shortcut);j<=C+1;j++){
      if(j==C+1){
        C=A.at(i).second-1;
        break;
      }
      if(D.at(j)==0){
        D.at(j) = A.at(i).first;
        sum += D.at(j);
        count ++;
        if(shortcut>=A.at(i).second){
          shortcut = j;
        }
        break;
      }
    }
    if(count==M){
      break;
    }
  }
  //ll sum=0;
  //for(int i=1;i<=M;i++){
  //  sum += D.at(i);
  //}
  cout << sum << endl;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

struct edge { int to,cost; };
struct ftedge { int from,to,cost; };

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;

int main() {
  int H,W;cin>>H>>W;
  vector<string> grid(H);
  REP(i,H) cin>>grid[i];

  vector<string> ans(H);
  vector<P> dirs{{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1},{0,1}};
  // H*Wを順番に見ていくでOK
  REP(h,H) {
    string ans_row;
    REP(w,W) {
      if (grid[h][w]=='#') {
        ans_row.push_back('#');
      } else {
        int tmp = 0;
        for (P p:dirs) {
          int new_h = h+p.first;
          int new_w = w+p.second;
          if (new_h>=0 && new_h<H && new_w>=0 && new_w<W) {
            if (grid[new_h][new_w]=='#') tmp++;
          }
        }
        ans_row.push_back('0'+tmp);
      }
    }
    ans[h] = ans_row;
  }
  REP(i,H) {
    OUT(ans[i]);
  }

  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	int a, b;
	cin >> a >> b;
	for (int i = 0; i < 100000; i++) {
		if (a * i - (i - 1) >= b) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/math/constants/constants.hpp>

using real = double;

real pi = boost::math::constants::pi<real>();
::std::size_t t = 1;

template<class RandomAccessIterator1, class RandomAccessIterator2, class RandomAccessIterator3>
RandomAccessIterator1 convolution(RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, RandomAccessIterator2 last2, RandomAccessIterator3 result){
    using value_type = typename ::std::iterator_traits<RandomAccessIterator1>::value_type;
    using size_type = ::std::size_t;
    size_type N = last1 - first1, M = last2 - first2;
    while(t < N + M)t <<= 1;

    const auto fft_inline = [](auto& res, value_type hint){
        ::std::size_t N = res.size();

        // bit reverse
        for(::std::size_t i = 0, j = 0; i < N; ++i){
            if(i < j)::std::swap(res[i], res[j]);
            j ^= N / (1 + (i ^ (i + 1))) * (i ^ (i + 1));
        }

        ::std::stack<value_type> root;
        root.push(hint);
        for(::std::size_t i = 2; i < N; i <<= 1)root.push(hint *= hint);

        // fft
        for(::std::size_t i = 1; i < N; i <<= 1){
            auto t = root.top();
            root.pop();
            for(::std::size_t j = 0; j < N; j += 2 * i){
                auto coef = static_cast<value_type>(1);
                for(::std::size_t k = 0; k < i; ++k){
                    auto tmp = res[j + k];
                    res[j + k] += coef * res[j + k + i];
                    res[j + k + i] = tmp - coef * res[j + k + i];
                    coef *= t;
                }
            }
        }
    };

    ::std::vector<value_type> input1(first1, last1), input2(first2, last2), res(t);
    input1.resize(t);
    input2.resize(t);
    value_type hint = value_type(::std::cos(pi / (t / 2)), ::std::sin(pi / (t / 2))), ihint = value_type(::std::cos(pi / (t / 2)), -::std::sin(pi / (t / 2)));
    fft_inline(input1, hint);
    fft_inline(input2, hint);
    ::std::transform(input1.begin(), input1.end(), input2.begin(), res.begin(), ::std::multiplies<value_type>());
    fft_inline(res, ihint);

    return ::std::copy(res.begin(), res.end(), result);
}

int main(){
    using real = double;
    using namespace std;
    unsigned long N, L;
    cin >> N >> L;
    vector<unsigned long> T(N);
    copy_n(istream_iterator<unsigned long>(cin), N, T.begin());
    vector<complex<real>> ps(N), res(4 * N);
    transform(T.begin(), T.end(), ps.begin(), [&L](auto t){return complex<real>(cos(pi * t / L), sin(pi * t / L));});
    convolution(ps.begin(), ps.end(), ps.rbegin(), ps.rend(), res.begin());
    complex<real> x{0};
    for(long i = 0, c = -N; i + 1 < N; ++i)x += res[i] * static_cast<real>(c += 2);
    t *= N * (N - 1) * (N - 2) / 6;
    x /= t;
    cout << setprecision(15) << fixed;
    cout << x.real() << " " << x.imag() << endl;
    return 0;
}

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

#define mod 1000000007
typedef long long ll;

ll fact[1000006], inv[1000006];

ll fp(ll base, ll exp)
{
    if (exp == 0)
        return 1;
    ll ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}

void facninv(ll n)
{
    fact[0] = inv[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}

ll ncr(ll n, ll r)
{
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}

int main()
{  int n,k;
    ll ans;
   facninv(2001);
   cin>>n>>k;
   int r=n-k;
   for(int i=1;i<=k;i++){
    if(r+1>=i)
    ans=(ncr(r+1,i)*ncr(k-1,i-1))%mod;
    else ans=0;
   cout<<ans<<endl;
   }

    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const double PI = acos(-1.0);
const double EPS = 1e-10;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;cin>>N;
    vector<int> A(N);
    REP(i,N) cin>>A[i];
    vector<int> left(N),right(N);
    left[0] = A[0];
    right[N-1] = A[N-1];
    for(int i=1;i<N;i++) left[i] = max(A[i],left[i-1]);
    for(int i=N-2;i>=0;i--) right[i] = max(A[i],right[i+1]);
    REP(i,N){
        if(i==0) cout<<right[1]<<endl;
        else if(i==N-1) cout<<left[N-2]<<endl;
        else{
            cout<<max(left[i-1],right[i+1])<<endl;
        }
    }
}


Measured memory_bytes: 3968
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
ll n, s;
ll dig(ll a, ll b) {
    if (b < a) return b;
    return dig(a, b / a) + (b % a);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n >> s;
    if (n == s) {
        cout << n + 1;
        return 0;
    }
    if (n < s) {
        cout << -1;
        return 0;
    }
    ll best = 1e18;
    for (ll p = 1; p * p <= n - s; p++) {
        if ((n - s) % p == 0) {
            if (dig(p + 1, n) == s) best = min(best, p + 1);
            if (dig((n - s) / p + 1, n) == s) best = min(best, ((n - s) / p) + 1);
        }
    }
    if (best > 1e15) best = -1;
    cout << best;
    return 0;
}

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

void solve() {
    cin >> N >> K;
    int g[N];
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        g[i] = a - 1;
    }
    vector<bool> memo(N, false);
    int idx = 0;
    do {
        memo[idx] = true;
        idx = g[idx];
    } while(!memo[idx]);
    int jo_dis=0;
    int idx1 = 0;
    while(idx != idx1) {
        idx1 = g[idx1];
        jo_dis++;
    }
//    printf("jo_dis: %d\n", jo_dis);

    int idx2 = idx;
    ll loop_count = 1;
    do {
        idx2 = g[idx2];
        loop_count += 1;
    } while(g[idx2] != idx);
//    printf("loop_count: %d\n", loop_count);

    if (K < jo_dis) {
        int town = 0;
        int count = 0;
        while (count < K) {
            town = g[town];
            count++;
        }
        cout << town+1 << endl;
    } else {
        ll m = (K - jo_dis) % loop_count;
        int count = 0;
        int idxx = idx;
        while (count < m) {
            idxx = g[idxx];
            count++;
        }
//        cout << endl;
        cout << idxx+1 << endl;
    }
}

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


Measured memory_bytes: 4440
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int x[50];
int64_t dp[51][51][2501];

int main()
{
    int n, a;
    cin >> n >> a;
    rep(i, n)
    {
        cin >> x[i];
    }

    irep(i, n)
    {
        irep(j, n)
        {
            irep(k, 2500)
            {
                if (i == 0) {
                    dp[i][j][k] = j == 0 && k == 0 ? 1 : 0;
                } else {
                    dp[i][j][k] = dp[i - 1][j][k];
                    if (j - 1 >= 0 && k - x[i - 1] >= 0) {
                        dp[i][j][k] += dp[i - 1][j - 1][k - x[i - 1]];
                    }
                }
            }
        }
    }

    int64_t result = 0;
    irep(i, n)
    {
        result += dp[n][i][i * a];
    }
    cout << result - 1 << endl;

    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);



int main(){
    string s;
    char res[500000];
    int q;
    cin >> s >> q;
    REP(i, s.length()) res[i+200000] = s[i];
    int prev = 199999;
    int next = 200000+s.length();
    bool rev = false;
    REP(i, q){
        int t;
        cin >> t;
        if(t==1) { rev = !rev; continue; }
        int f;
        char c;
        cin >> f >> c;
        if((!rev && f == 2) || (rev && f == 1)) { res[next] = c; next++; }
        else {res[prev] = c; prev--;}
    }
    if (!rev) {for(int i=prev+1; i<next; i++) cout << res[i]; cout<< endl;}
    else{for(int i=next-1; i>prev; i--) cout << res[i]; cout << endl;}
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long; 
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
template<class T> using pq = priority_queue<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
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; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() { // 問題文はしっかり読め!!!
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	a *= 2;
	ll n;
	cin >> n;
	ll half = min(a, b);
	ll one = min(half * 2, c);
	ll two = min(one * 2, d);
	cout << (n / 2) * two + (n % 2) * one << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main(){
    int n, m;
    cin>>n>>m;
    vector<pair<int,int> > e;
    for(int i=0; i<n; i++){
        int a,b;
        cin>>a>>b;
        e.push_back(make_pair(a,b));
    }
    sort(e.begin(), e.end());
    int hon =0;
    long long ans =0;
    int i=0;
    while(hon<m){
        pair<int, int> tmp= e.at(i);
        ans += tmp.first;
        hon++;
        e.at(i).second--;
        if(e.at(i).second==0) i++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <iostream>
#include <list>

int main()
{
	int n, p;
	while(1){
		std::cin >> n >> p;
		if(n == 0 && p == 0) break;
		int a[50], b, c;
		b = p / n;
		c = p % n;
		for(int i = 0; i < n; i++){
			if(i < c) a[i] = b+1;
			else a[i] = b;
		}
		int start = c, bowl;
		while(1){
			if(a[start] != 0){
				bowl = a[start];
				a[start] = 0;
				b= bowl / n;
				c = bowl % n;
				for(int j = 1; j <=n; j++){
					if(j <= c) a[(start + j)%n] += b+1;
					else a[(start+j)%n] += b;
				}
				start = (start + c) % n;
				if(a[start] == p){
					std::cout << start << std::endl;
					break; 
				}
			}
			start = (start + 1) % n;	
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main(){
    int N,K;
    string D;
    char cur;
    cin >> N >> K;
    REP(i,0,K){
        cin >> cur;
        D.push_back(cur);
    }

    string S;
    REP(i,N,100000){
        S=to_string(i);
        bool flag=true;
        REP(j,0,S.size()){
            REP(k,0,D.size()){
                if(S[j]==D[k]) flag=false;
            }
        }
        if(flag){
            P(i);
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            String str[] = br.readLine().split(" ");
            long a[] = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = Long.parseLong(str[i]);
            }
            Arrays.sort(a);
            int i = n - 1;
            long x = -1;
            long y = -1;
            long before = -1;
            while (i >= 0) {
                long tmp = a[i];
                if (before == tmp) {
                    if (x == -1) {
                        x = tmp;
                        before = -1;
                    } else if (y == -1) {
                        y = tmp;
                        break;
                    }
                } else {
                    before = tmp;
                }
                i--;
            }
            if (x != -1 && y != -1) {
                System.out.println(x * y);
            } else {
                System.out.println(0);
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
}


Measured memory_bytes: 47060
N=int(input())
a=input().split()
for i in range(N):
  a[i]=int(a[i])
a.sort()
sum=0
m=len(a)-1
for i in range(m):
  sum+=a[i]
  
if sum>a[len(a)-1]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#
# NoKnowledgeGG @YlePhan
# ('ω')
#
#import collections
#aa = collections.Counter(a) # list to list
def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n = int(input())
    T = []
    X = []
    Y = []
    for i in range(n):
        t,x,y = readInts()
        T.append(t)
        X.append(x)
        Y.append(y)
    cx,cy,ct = 0,0,0
    for i in range(n):
        dist_place = abs(X[i] - cx) + abs(Y[i] - cy)
        dist_time = abs(T[i] - ct)
        if dist_time >= dist_place and (dist_time - dist_place) % 2 == 0:
            cx = X[i]
            cy = Y[i]
            ct = T[i]

            pass
        else:
            print('No')
            exit()
    print('Yes')



if __name__ == '__main__':
  main()


Measured memory_bytes: 11800
%:pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

const int inf = 1e9;
const int N = 5e5 + 50;

int n, k, vis[N], a[N], p[N], d[N], Mi[N];
vector<int> g[N];

namespace seg {
# define ls rt << 1
# define rs ls | 1
	int a[N * 4];
	void build(int rt = 1, int l = 1, int r = n) {
		a[rt] = inf;
		if(l == r) return ;
		int mid = l + r >> 1;
		build(ls, l, mid);
		build(rs, mid + 1, r);
	}
	void modify(int rt, int l, int r, int pos, int v) {
		if(l == r) return (void) (a[rt] = v);
		int mid = l + r >> 1;
		if(pos <= mid) modify(ls, l, mid, pos, v);
		else modify(rs, mid + 1, r, pos, v);
		a[rt] = min(a[ls], a[rs]);
	}
	int query(int rt, int l, int r, int ql, int qr) {
		if(l > qr || r < ql) return inf;
		if(l >= ql && r <= qr) return a[rt];
		int mid = l + r >> 1;
		return min(query(ls, l, mid, ql, qr), query(rs, mid + 1, r, ql, qr));
	}
}
void bfs() {
	priority_queue<int, vector<int>, greater<int> > q;
	for(int i = 0; i < (int) g[0].size(); ++i)
		q.push(g[0][i]);
	while(!q.empty()) {
		int u = q.top(); q.pop();
		static int icnt = 0;
		a[++icnt] = u;
		for(int i = 0; i < (int) g[u].size(); ++i) {
			--d[g[u][i]];
			if(!d[g[u][i]]) q.push(g[u][i]);
		}
	}
}

int main() {
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i)
		scanf("%d", p + i), a[p[i]] = i;
	seg :: build();
	for(int i = n, get; i; --i) {
		get = seg :: query(1, 1, n, a[i], min(n, a[i] + k - 1));
		if(get != inf) {
			++d[a[get]];
			g[a[i]].push_back(a[get]);
		}
		get = seg :: query(1, 1, n, max(1, a[i] - k + 1), a[i]);
		if(get != inf) {
			++d[a[get]];
			g[a[i]].push_back(a[get]);
		}
		seg :: modify(1, 1, n, a[i], i);
	}
	for(int i = 1; i <= n; ++i)
		if(!d[i]) g[0].push_back(i);
	bfs();
	for(int i = 1; i <= n; ++i)
		p[a[i]] = i;
	for(int i = 1; i <= n; ++i)
		printf("%d\n", p[i]);
	return 0;
}


Measured memory_bytes: 47872
#include <bits/stdc++.h>
#include <iomanip>
#include<algorithm>
#define ll long long
using namespace std;

int main() {
  ll A, B, C, K, cnt = 0;
  cin >> A >> B >> C >> K;
  if(A >= K) cout << K << endl;
  else if((A < K) && (B >= K - A)) cout << A << endl;
  else if((A < K) && (B < K - A)) cout << A - (K - A - B) << endl;
}

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

# from fractions import gcd
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

import copy
N, M, X = [int(_) for _ in input().split()]
CA = [[int(_) for _ in input().split()] for i in range(N)]

ret = []

def dfs(index, rikaido, cost):
    
    global ret
    rikaido = [rikai + rikaido[i] for i, rikai in enumerate(CA[index][1:])]
    cost += CA[index][0]

    if all([i >= X for i in rikaido]):
        ret += [cost]
        return
    
    for i in range(index+1, N):
        dfs(i, copy.copy(rikaido), cost)

for i in range(N):
    dfs(i, [0] * M, 0)

if not ret:
    print(-1)
else:
    print(min(ret))

Measured memory_bytes: 9652
n,m,q=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
s=[list(map(int,input().split())) for i in range(q)]
table=[[0]*n for _ in range(n)]
for i in l:
    table[i[0]-1][i[1]-1]+=1
for i in range(n):
    for j in range(1,n):
        table[i][j]+=table[i][j-1]
for i in range(n-1,0,-1):
    for j in range(n):
        table[i-1][j]+=table[i][j]
#print(table)
for i in s:
    print(table[i[0]-1][i[1]-1])

Measured memory_bytes: 73108
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
int INF = 1000000000;
int main(){
	int N, M;
	cin >> N >> M;
	vector<int> D(N);
	for (int i = 0; i < N; i++){
		cin >> D[i];
	}
	vector<vector<pair<int, int>>> E(N);
	for (int i = 0; i < M; i++){
		int U, V;
		cin >> U >> V;
		U--;
		V--;
		E[U].push_back(make_pair(i, V));
		E[V].push_back(make_pair(i, U));
	}
	vector<int> C(N, -1);
	vector<int> W(M, INF);
	queue<int> Q;
	for (int v = 0; v < N; v++){
		for (auto P : E[v]){
			int id = P.first;
			int w = P.second;
			if (D[v] == D[w]){
				if (C[v] == -1){
					if (C[w] == -1){
						C[v] = 0;
						C[w] = 1;
						W[id] = D[v];
						Q.push(v);
						Q.push(w);
					} else {
						C[v] = 1 - C[w];
						W[id] = D[v];
						Q.push(v);
					}
				} else if (C[w] == -1){
					C[w] = 1 - C[v];
					W[id] = D[v];
					Q.push(w);
				}
			}
		}
	}
	while (!Q.empty()){
		int v = Q.front();
		Q.pop();
		for (auto P : E[v]){
			int id = P.first;
			int w = P.second;
			if (C[w] == -1 && D[w] > D[v]){
				C[w] = 1 - C[v];
				W[id] = D[w];
				Q.push(w);
			}
		}
	}
	bool ok = true;
	for (int i = 0; i < N; i++){
		if (C[i] == -1){
			ok = false;
		}
	}
	if (!ok){
		cout << -1 << endl;
	} else {
		for (int i = 0; i < N; i++){
			if (C[i] == 0){
				cout << 'W';
			}
			if (C[i] == 1){
				cout << 'B';
			}
		}
		cout << endl;
		for (int i = 0; i < M; i++){
			cout << W[i] << endl;
		}
	}
}

Measured memory_bytes: 13028
a,b = map(int,input().split())

def calc(i):
  ans = [0 for _ in range(40)]
  i += 1
  for j in range(1,41):
    
    loop = 2**j
    c = (i//loop)*(loop/2)
    c += max(0,(i%loop)-(loop/2))
    if c%2 == 1:
      ans[-j]+=1
  ans = int(''.join(str(_) for _ in ans),2)
  return ans

if a<1:
  print(calc(b))
else:
  print(calc(a-1)^calc(b))

Measured memory_bytes: 3064