akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














int N;
string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> S;
	N = S.length();
	S += "BBBBB";

	ll ans = 0;
	int R = 0;
	int BC = 0;
	rep(L, 0, N) {
		if (S[L] == 'A') {
			if (R <= L) {
				BC = 0;
				R = L + 1;
				while (R < N) {
					if (S[R] == 'A') R++;
					else if (S[R] == 'B' and S[R + 1] == 'C') {
						BC++;
						R += 2;
					}
					else break;
				}
			}

			ans += BC;
		}
		else if (S[L] == 'B' and S[L + 1] == 'C') BC--;
	}
	cout << ans << endl;
}







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

#define INF 1000000000

using namespace std;


int main()
{
    int m, d, flag = 0;
    cin >> m >> d;
    if(m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
    {
        if(d == 31)
        {
            flag = 1;
        }
    }
    else if(m == 2)
    {
        if(d == 28)
        {
            flag = 1;
        }
    }
    else
    {
        if(d == 30)
        {
            flag = 1;
        }
    }
    cin >> m >> d;
    cout << flag << endl;
   return 0;
}

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

int main() {
	int n, s[100];
	cin >> n;
	int t = 0;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		t += s[i];
	}
	if (t % 10) {
		cout << t << endl;
	} else {
		sort(s, s + n);
		for (int i = 0; i < n; i++) {
			if (s[i] % 10) {
				t -= s[i];
				break;
			}
		}
		if (t % 10) {
			cout << t << endl;
		} else {
			cout << 0 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
import math as m
while True:
    x=int(input())
    if x==0:
        break
    else:
        y=list(map(int,input().split()))
        m=sum(y)/x
        a=0
        for i in range(0,x):
            r=(y[i]-m)**2
            a+=r
        a=a/x
        print(f'{a**(1/2):.8f}')


Measured memory_bytes: 5732
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  vector<int> len(3);
  cin >> len[0] >> len[1] >> len[2];
  sort(len.begin(), len.end());
  if (len[0] == 5 & len[1] == 5 & len[2] == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
//int INF = numeric_limits<int>::max() / 2;
//using ll = long long;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> numofeach(100001,0);
	for(int i = 0; i < n; i++){
		int a;
		cin >> a;
		numofeach[a]++;
	}
	int ans = 0;
	for(int i = 0; i < 100001 - 2; i++){
		int temp = numofeach[i] + numofeach[i+1] + numofeach[i+2];
		if(ans < temp) ans = temp;
	}
	cout << ans << endl;
	return 0;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int n, m;
    cin >> n >> m;
    v_ll x(n), y(n), z(n);

    irep(i, n) {
        cin >> x[i] >> y[i] >> z[i];
    }
    
    ll ans = -LINF;
    irep2(i, -1, 1) {
        irep2(j, -1, 1) {
            irep2(k, -1, 1) {
                if(i == 0 || j == 0 || k == 0) { continue; }
                v_ll sum(n);
                irep(l, n) {
                    sum[l] = (i*x[l]) + (j*y[l]) + (k*z[l]);
                }
                sort(sum.rbegin(), sum.rend());
                ll tmp = 0;
                irep(l, m) {
                    tmp += sum[l];
                }
                ans = max(ans, tmp);
            }
        }   
    }
    
    cout << ans << endl;
    return 0;
}   
/** atcoder **/


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

int main() {
  int s;
  cin >> s;
  int s1 = s/100;
  int s2 = s/10 - 10*s1;
  int s3 = s%10;
  
  cout << s1+s2+s3 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b<<endl;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

s=input().split("BC")
s.pop()
ans = 0
now=0
#print(s)
for i in s:
    if "B" not in i and "C" not in i:
        now += len(i)
        ans += now
    else:
        x=i.rfind('B')
        y=i.rfind('C')
        now = len(i) - max(x,y) - 1
        ans += now
#    print(now,ans)

print(ans)

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

bool v[30];
string a;
int main()
{
	int i, j;
	cin >> a;
	if (a.size() < 26) {
		for (i = 0; i < a.size(); i++) v[a[i] - 'a'] = 1;
		for (i = 0; i <  26; i++) if (!v[i]) break;
		cout << a << (char)(i + 'a');
	} else if (a == "zyxwvutsrqponmlkjihgfedcba") {
		cout << -1;
	} else {
		for (i = a.size() - 1; i > 0; i--) {
			if (a[i - 1] < a[i]) break;
		}
		for (j =0; j < i - 1; j++) {
			v[a[j] - 'a'] = 1;
		}
		for (j = a[i - 1] - 'a' + 1; j < 26; j++) if (!v[j]) break;
		a[i - 1] = (char)(j + 'a');
		for (j = 0; j < i; j++) cout << a[j];
	}
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define Se second
#define Fi first
#define rep(i, n) for(int i=0;i<n;i++)
#define pb(x) push_back(x)

char ans[105][105];

int main() {
//	freopen("output.txt", "w", stdout);
	int A, B;
	scanf("%d %d", &A, &B);

	bool cc = false;
	if (A > B) {
		cc = true;
		swap(A, B);
	}

	if (A == 1) {
		for (int i = 0; i < 100; i++) for (int j = 0; j < 100; j++) ans[i][j] = '.';
		
		int t = B;
		for (int i = 0; i < 100; i++) for (int j = 0; j < 100; j++) {
			if (i % 2 || j % 2) continue;
			if (t) {
				ans[i][j] = '#';
				t--;
			}
		}
	}
	else {
		for (int i = 0; i < 50; i++) for (int j = 0; j < 100; j++) ans[i][j] = '#';
		int t = A - 1;
		for (int i = 0; i < 50; i++) for (int j = 0; j < 100; j++) {
			if (i % 2 || j % 2) continue;
			if (t) {
				ans[i][j] = '.';
				t--;
			}
		}

		for (int i = 99; i >= 50; i--) for (int j = 0; j < 100; j++) ans[i][j] = '.';
		t = B - 1;
		for (int i = 99; i >= 50; i--) for (int j = 0; j < 100; j++) {
			if (i % 2 || j % 2) continue;
			if (t) {
				ans[i][j] = '#';
				t--;
			}
		}
	}
	if (cc) {
		for (int i = 0; i < 100; i++) for (int j = 0; j < 100; j++) ans[i][j] ^= '.' ^ '#';
	}

	printf("100 100\n");
	for (int i = 0; i < 100; i++) printf("%s\n", ans[i]);
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map(String::toInt)
    val C = IntArray(N + 1)
    var total = 0L
    for (a in A) {
        total += C[a]
        C[a]++
    }
    for (k in A.indices) {
        println(total - (C[A[k]] - 1)) // - nC2 + (n-1)C2 = -(n-1)
    }
}

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

#define faster      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi          acos(-1.0)
#define nl          '\n'

///Library
#define mem(a,b)    memset(a,b,sizeof(a))
#define all(a)      a.begin(),a.end()
#define Sort(x)     sort(x.begin(),x.end())
#define Reverse(x)  reverse(x.begin(),x.end())
#define SortA(ar,s) sort(ar,ar+s)
#define SortD(ar,s) sort(ar,ar+s,greater<int>())
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b)    (a*(b/gcd(a,b)))
#define sq(x)       (x)*(x)

#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min(b,min(c,d)))
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max(b,max(c,d)))
#define ABS(x)             ((x)<0?-(x):(x))
#define pb                 push_back
#define mod                1000000007
#define end                printf("\n")
#define yes                printf("YES\n")
#define no                 printf("NO\n")

///data type
typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    faster
    ll n,c=0;
    cin>>n;
    int A[n+1];
    for(int i=1; i<=n; i++)
        cin>>A[i];
    sort(A+1,A+n+1);
    for(int i=1; i<=n; i++)
    {
        for(int j=i+1; j<=n; j++)
        {
            for(int k=j+1; k<=n; k++)
            {
                if((i<j && j<k) && (A[i]+A[j]>A[k]) && (A[i]!=A[j] && A[j]!=A[k] && A[i]!=A[k]))
                {
                        c++;
                }
            }
        }
    }
    cout<<c<<nl;
    return 0;
}


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

using namespace std;

#define LCM(a,b) (a)*(b) / ( __gcd( a , b) )
#define loop(n) for(int i=0;i<n;i++)
#define loop2(l,n,in) for(int i=l;i<n;i+=in)
#define endl '\n'
typedef long long ll;


int main() {
    cin.tie(0);
    cin.sync_with_stdio(0);
    cout.tie(0);


  int n,mn,mx;
  cin>>n;

    int a[n]={};

    loop(n)cin>>a[i];

   sort(a,a+n);
   mn=a[0];
   mx=a[n-1];


   int r=mn,mnCost=INT_MAX;
   while(r<=mx){

        ll cost=0;
       loop(n){
           cost+=pow((a[i]-r),2);
       }
     if(cost<mnCost)mnCost=cost;
     r++;
   }
   cout<<mnCost;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long

using namespace std;

ll a[102][7],l,k,i,j,z;

void DICE(ll x, ll y){
	k=0;
	if(x==a[z][1] && a[z][6]==a[l][6]){
		if(y==a[z][2] && a[z][3]==a[l][3] && a[z][4]==a[l][4] && a[z][5]==a[l][5]) k=1;
		if(y==a[z][3] && a[z][5]==a[l][3] && a[z][2]==a[l][4] && a[z][4]==a[l][5]) k=1;
		if(y==a[z][4] && a[z][2]==a[l][3] && a[z][5]==a[l][4] && a[z][3]==a[l][5]) k=1;
		if(y==a[z][5] && a[z][4]==a[l][3] && a[z][3]==a[l][4] && a[z][2]==a[l][5]) k=1;
	}
	if(x==a[z][2] && a[z][5]==a[l][6]){
		if(y==a[z][1] && a[z][4]==a[l][3] && a[z][3]==a[l][4] && a[z][6]==a[l][5]) k=1;
		if(y==a[z][3] && a[z][1]==a[l][3] && a[z][6]==a[l][4] && a[z][4]==a[l][5]) k=1;
		if(y==a[z][4] && a[z][6]==a[l][3] && a[z][1]==a[l][4] && a[z][3]==a[l][5]) k=1;
		if(y==a[z][6] && a[z][3]==a[l][3] && a[z][4]==a[l][4] && a[z][1]==a[l][5]) k=1;
	}
	if(x==a[z][3] && a[z][4]==a[l][6]){
		if(y==a[z][1] && a[z][2]==a[l][3] && a[z][5]==a[l][4] && a[z][6]==a[l][5]) k=1;
		if(y==a[z][2] && a[z][6]==a[l][3] && a[z][1]==a[l][4] && a[z][5]==a[l][5]) k=1;
		if(y==a[z][5] && a[z][1]==a[l][3] && a[z][6]==a[l][4] && a[z][2]==a[l][5]) k=1;
		if(y==a[z][6] && a[z][5]==a[l][3] && a[z][2]==a[l][4] && a[z][1]==a[l][5]) k=1;
	}
	if(x==a[z][4] && a[z][3]==a[l][6]){
		if(y==a[z][1] && a[z][5]==a[l][3] && a[z][2]==a[l][4] && a[z][6]==a[l][5]) k=1;
		if(y==a[z][2] && a[z][1]==a[l][3] && a[z][6]==a[l][4] && a[z][5]==a[l][5]) k=1;
		if(y==a[z][5] && a[z][6]==a[l][3] && a[z][1]==a[l][4] && a[z][2]==a[l][5]) k=1;
		if(y==a[z][6] && a[z][2]==a[l][3] && a[z][5]==a[l][4] && a[z][1]==a[l][5]) k=1;
	}
	if(x==a[z][5] && a[z][2]==a[l][6]){
		if(y==a[z][1] && a[z][3]==a[l][3] && a[z][4]==a[l][4] && a[z][6]==a[l][5]) k=1;
		if(y==a[z][3] && a[z][6]==a[l][3] && a[z][1]==a[l][4] && a[z][4]==a[l][5]) k=1;
		if(y==a[z][4] && a[z][1]==a[l][3] && a[z][6]==a[l][4] && a[z][3]==a[l][5]) k=1;
		if(y==a[z][6] && a[z][4]==a[l][3] && a[z][3]==a[l][4] && a[z][1]==a[l][5]) k=1;
	}
	if(x==a[z][6] && a[z][1]==a[l][6]){
		if(y==a[z][2] && a[z][4]==a[l][3] && a[z][3]==a[l][4] && a[z][5]==a[l][5]) k=1;
		if(y==a[z][3] && a[z][2]==a[l][3] && a[z][5]==a[l][4] && a[z][4]==a[l][5]) k=1;
		if(y==a[z][4] && a[z][5]==a[l][3] && a[z][2]==a[l][4] && a[z][3]==a[l][5]) k=1;
		if(y==a[z][5] && a[z][3]==a[l][3] && a[z][4]==a[l][4] && a[z][2]==a[l][5]) k=1;
	}
}
int main(){
	ll i,n,p,s[102];
	
	
	cin>>n;
	for(i=1;i<=n;i++){
		s[i]=0;
		for(j=1;j<7;j++){
			cin>>a[i][j];
			s[i]+=a[i][j];
		}
	}
	
	p=0;
	for(i=1;i<n;i++){
		z=i;
		for(j=i+1;j<=n;j++){
			l=j;
			if(s[i]==s[j]){
				DICE(a[l][1],a[l][2]);
				if(k==1) p=1,j=n,i=n;
			}
		}
	}
	if(p==0) cout<<"Yes\n";
		else cout<<"No\n";
	
	
	return 0;
}


Measured memory_bytes: 3076
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int unsigned long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
//最大公約数
int gcd(int x, int y) { return y ? gcd(y, x%y) : x; }
//最小公倍数
int lcm(int x, int y) { return x*y / gcd(x, y); }
//最大公約数 複数個
int gcd(const vector<int> &v) {
	int ret = v[0];
	for (int i = 1; i < v.size(); i++)
		ret = gcd(ret, v[i]);
	return ret;
}
//最小公倍数 複数個
int lcm(vector<int> &v) {
	int ret = v[0];
	for (int i = 1; i < v.size(); i++) {
		if (ret%v[i] == 0)continue;
		bool f(false);
		int x = gcd(ret, v[i]);
		if (ret%x == 0)ret /= x, f = true;
		else if (v[i] % x == 0)v[i] /= x, f = true;

		if (f)ret = ret*v[i];
		else ret = ret*v[i] / x;
		
		dump(ret);
	}
	return ret;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
	sort(all(v), greater<int>());
	cout << lcm(v) << endl;
	return 0;
}

Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
from collections import Counter
n = int(input())
ans = 0
list_N = prime_factorize(n)
list_Q = Counter(list_N).values()

for num in list_Q:
    k = 0
    while True:
        k += 1
        if num - k < 0:
            break
        num -= k
        ans += 1

print(ans)

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

#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define faster() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const long long int infLL = 9000000000000000000;

#define mem(a,b) memset(a, b, sizeof(a) )
#define all(a) (a).begin(),(a).end()
#define mx_int_prime 999999937

const int inf = 2000000000;
const double PI = acos(-1);
const double eps = 1e-9;
typedef long double ld;

#define MOD 1000000007

typedef long long ll;
const int mx=2e5+125;

ll pr[mx],ar[mx],br[mx];

#define PB push_back
#define endl '\n'
#define S second
#define F first


void solve()
{
    int k;
    cin>>k;
    for(int i=0; i<k; i++)
        cout<<"ACL";
    cout<<endl;


}
int main()
{
    faster();
    int tc;
    tc=1;
    while(tc--)
        solve();
    return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e6+10;
int n,m,a[N];
#define lc x<<1
#define rc x<<1|1
ll k[N],b[N],val[N];
void add(int x,int l,int r,int L,int R,int v1,int v2){
	if (l>=L&&r<=R){k[x]+=v1;b[x]+=v2;return;}
	int mid=(l+r)>>1;
	if (L<=mid) add(lc,l,mid,L,R,v1,v2);
	if (R>mid) add(rc,mid+1,r,L,R,v1,v2);
}
void dfs(int x,int l,int r){
	if (l==r) return void(val[l]=k[x]*l+b[x]);
	int mid=(l+r)>>1;
	k[lc]+=k[x];b[lc]+=b[x];
	k[rc]+=k[x];b[rc]+=b[x];
	dfs(lc,l,mid);
	dfs(rc,mid+1,r);
}
int main()
{
	scanf("%d%d%d",&m,&n,&a[1]);
	for (int i=2;i<=m;i++){
		scanf("%d",&a[i]);
		if (a[i]==a[i-1]) continue;
		if (a[i]>a[i-1]){
			if (a[i]<n) add(1,1,n,a[i]+1,n,0,a[i]-a[i-1]);
			add(1,1,n,1,a[i-1],0,a[i]-a[i-1]);
			add(1,1,n,a[i-1]+1,a[i],-1,a[i]+1);
		}
		else{
			add(1,1,n,a[i]+1,a[i-1],0,a[i]+n-a[i-1]);
			if (a[i-1]<n) add(1,1,n,a[i-1]+1,n,-1,a[i]+n+1);
			add(1,1,n,1,a[i],-1,a[i]+1);
		}
	}
	dfs(1,1,n);
	ll ans=1e18;
	for (int i=1;i<=n;i++) ans=min(ans,val[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11136
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL K;

LL ans = -1;

void solve(){
	if(K==1 || K==7){
		ans = 1;
		return;
	}
	//10のi乗をpow10_modKとおく
	vector<LL> pow10_modK(10000001);
	pow10_modK[0] = 1;
	for(int i=1;i<=10000000;i++){
		pow10_modK[i] = (pow10_modK[i-1]*10)%K;
	}

	LL num = 7%K;
	for(int i=1;i<=10000000;i++){
		if(num==0){
			ans = i;
			return;
		}else{
			num = (num + ((pow10_modK[i]*7))%K)%K;
		}
	}
}

int main(){
    cin >> K;

    solve();

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

Measured memory_bytes: 80984
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
 
int main(){
  int a,b,c;
  cin>> a >> b >>c;
  
  int ans = b + c - a;
  if(ans < 0) ans = 0;
  cout << ans << endl;
  return 0;
}

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

int main(){
    int x, y;
    while (true)
    {
        cin >> x >> y;
        if(x == 0 && y == 0) break;
        if(x >= y) cout << y << " " << x << endl;
        else cout << x << " " << y << endl;
    }
    return 0;
}


Measured memory_bytes: 3036
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n, q;

	cin >> n;
	vector<long long> a(n);

	for (int i = 0; i < n; i++)
		cin >> a[i];

	cin >> q;

	for (int i = 0; i < q; i++) {
		long long k;
		cin >> k;

		cout << (lower_bound(a.begin(), a.end(), k) - a.begin()) << endl;
	}

	return 0;
}


Measured memory_bytes: 3592
#include <iostream>

using namespace std;

int n, a[200010];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    int tot = 0;
    for (int i = 1; i <= n; i++)
        tot ^= a[i];
    for (int i = 1; i <= n; i++)
        cout << (tot ^ a[i]) << ' ';
    cout << endl;

    return 0;
}

Measured memory_bytes: 4392
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    double a1,b1;
    a1 = a;
    b1 = b;
    printf("%d %d %.5f\n",(a/b),(a%b),(a1/b1));
    return 0;
    
}



Measured memory_bytes: 3212
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  s=S()

  if len(s)>9:
    return 'NO'
  if len(s)==9:
    if s=='AKIHABARA':
      return 'YES'
    return 'NO'
  if len(s)==8:
    if s=='KIHABARA' or s=='AKIHBARA' or s=='AKIHABRA' or s=='AKIHABAR':
      return 'YES'
    return 'NO'
  if len(s)==7:
    if s=='KIHBARA' or s=='KIHABRA' or s=='KIHABAR' or s=='AKIHBRA' or s=='AKIHBAR' or s=='AKIHABR':
      return 'YES'
    return 'NO'
  if len(s)==6:
    if s=='KIHBRA' or s=='KIHABR' or s=='KIHBAR' or s=='AKIHBR':
      return 'YES'
    return 'NO'
  if len(s)==5:
    if s=='KIHBR':
      return 'YES'
    return 'NO'
  else:
    return 'NO'

# main()
print(main())


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

char in[120];
pair<pair<string,int>,int> p[110];
int main(){
    int a;
    cin >> a;
    for(int i = 0; i < a; i++){
        int t;
        cin >> in >> t;
        string tmp = in;
        p[i] = make_pair(make_pair(in, -t),i);
    }
    sort(p,p+a);
    for(int i = 0; i < a; i++){
        cout << p[i].second+1 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x2 -= x1;
    y2 -= y1;
    int dx = x2;
    int dy = y2;
    int ddx = -1 * dy;
    int ddy = dx;
    int x4 = ddx + x1;
    int y4 = ddy + y1;
    int x3 = x4 + x2;
    int y3 = y4 + y2;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;


    // if(x1 == x2){
    //     int y = abs(y1 - y2);
    //     if(y1 > y2){
    //         cout << x1 + y << " " << y2 << " " << x1 + y << " " << y1 << endl;
    //     }else{
    //         cout << x1 - y << " " << y2 << " " << x1 - y << " " << y1 << endl;
    //     }
    // }else{
    //     int x = abs(x1 - x2);
    //     if(x1 > x2){
    //         cout << x2 << " " << y2 - x << " " << x1 << " " << y2 - x << endl; 
    //     }else{
    //         cout << x2 << " " << y2 + x << " " << x1 << " " << y2 + x << endl; 
    //     }
    // }

}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
inline char gc() {
//	return getchar();
	static char buf[100000],*l=buf,*r=buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void rd(T &x) {
	x=0; int f=1,ch=gc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=gc();}
	x*=f;
}
typedef long long ll;
ll N,A,B;
inline ll cal(ll l,ll r) {return (r-l)/2;}
int main() {
	rd(N),rd(A),rd(B);
	if((A^B)&1) printf("%lld\n",min(cal(1,B-A)+A,cal(A+(N-B)+1,N)+(N-B)+1));
	else printf("%lld\n",cal(A,B));
	return 0;
}

Measured memory_bytes: 3736
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
	    java.util.Scanner scanner = new java.util.Scanner(System.in);
	    int n = scanner.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		Arrays.sort(a);
		int count1 = 1;
		int count2 = 0;
		int count3 = 0;
		int maxcount = 1;
		// 1 1 2 2 3 3
		for (int i = 0; i < n - 1; i++) {
			maxcount = Math.max(maxcount, count1+count2+count3);
			int diff = a[i+1] - a[i];
			if (diff == 0) {
				count1++;
			} else if (diff == 1) {
				count3 = count2;
				count2 = count1;
				count1 = 1;
			} else {
				count3 = 0;
				count2 = 0;
				count1 = 1;
				// reset
			}
		}
//		if (n > 1) {
//			int lastdiff = a[n - 1] - a[n - 2];
//			if (lastdiff == 0) {
//				count1++;
//			} else if (lastdiff == 1) {
//				count3 = count2;
//				count2 = count1;
//				count1 = 1;
//			} else {
//				count3 = 0;
//				count2 = 0;
//				count1 = 1;
//			}
//			maxcount = Math.max(maxcount, count1+count2+count3);
//		}
		maxcount = Math.max(maxcount, count1+count2+count3);
		System.out.println(maxcount);
	}
}


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

bool dp[8001][40000];
int solve(vector<int> a, int x){
	fill((bool*)dp, (bool*)(dp+8001) , 0);
	dp[0][20000] = 1;
	int n = a.size();
	for(int i = 0;i < n;i++){
		for(int j = 0;j < 40000;j++){
			if(j+a[i] < 40000)dp[i+1][j+a[i]] = max(dp[i+1][j+a[i]], dp[i][j]);
			if(j-a[i] >= 0)dp[i+1][j-a[i]] = max(dp[i+1][j-a[i]], dp[i][j]);
		}
	}
	if(dp[n][20000+x] == true)return 1;
	return 0;
}

int main(){
	vector<int> a, b;
	string str;
	int f = 0, sum = 0, from, x, y;
	cin >> str >> x >> y;
	str.push_back('T');
	
	for(from = 0;from < str.size();from++){
		if(str[from] == 'T')break;x--;
	}
	for(int i = from;i < str.size();i++){
		if(str[i] == 'T' && sum){
			if(f == 0)a.push_back(sum);
			else b.push_back(sum);
			sum = 0;
		}
		if(str[i] == 'F')sum++;
		if(str[i] == 'T')f = !f;
	}
	
	int t1 = solve(a, x);
	int t2 = solve(b, y);
	if(t1 && t2)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 312832
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		String ans = "";

		if(a*b % 2 == 0) {
			ans = "Even";
		} else {	
			ans = "Odd";
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int n, ans = 1;
long long a[100005];
int main()
{
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> a[i];
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= n; i ++) a[i] += a[i - 1];
    for(int i = n - 1; i; i --) {
        if(2* a[i] >= a[i + 1] - a[i])
            ans ++;
        else break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    scanf("%d",&N);
    if(N>=100&&N<=111)
        printf("111\n");
    else if(N>=112&&N<=222)
        printf("222\n");
    else if(N>=223&&N<=333)
        printf("333\n");
    else if(N>=334&&N<=444)
        printf("444\n");
    else if(N>=445&&N<=555)
        printf("555\n");
    else if(N>=556&&N<=666)
        printf("666\n");
    else if(N>=667&&N<=777)
        printf("777\n");
    else if(N>=778&&N<=888)
        printf("888\n");
    else if(N>=889&&N<=999)
        printf("999\n");
}



Measured memory_bytes: 256
line = input()
h1, m1, h2, m2, k = line.split(" ")
h1, m1, h2, m2, k = int(h1), int(m1), int(h2), int(m2), int(k)

houre = h2 - h1
minute = m2 - m1

print(houre * 60 + minute - k)


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

using namespace std;

int a[30];
int b[30];
int main(void){

    int n;
    cin>>n;
    for(int i=1;i<=n;i++)   cin >>a[i];
    for(int i=1;i<=n;i++)   cin >>b[i];
    int res = 0;
    for(int i=1;i<=n;i++){
        if(a[i]-b[i]>0) res += (a[i]-b[i]);
    }
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

use std::cmp::Ordering;

#[derive(PartialEq, Debug)]
struct Point {
    i: usize,
    c: f64
}

impl PartialOrd for Point {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        match self.c.partial_cmp(&other.c) {
            Some(Ordering::Less) => Some(Ordering::Greater),
            Some(Ordering::Greater) => Some(Ordering::Less),
            other => other
        }
    }
}

impl Eq for Point { }

impl Ord for Point {
    fn cmp(&self, other: &Self) -> Ordering {
        self.partial_cmp(&other).unwrap()
    }
}

use std::collections::BinaryHeap;
use std::f64;

fn main() {
    let (xs, ys, xt, yt) = get!(f64, f64, f64, f64);
    let n = get!(usize);
    let mut xyr = get!(f64, f64, f64; n);
    xyr.push((xs, ys, 0.0));
    xyr.push((xt, yt, 0.0));

    let mut mincs = vec![f64::INFINITY; n+2];
    mincs[n] = 0.0;
    let mut q = BinaryHeap::new();
    q.push(Point { i: n, c: 0.0 });

    let mut ds = vec![vec![0.0; n+2]; n+2];
    for i in 0..n+1 {
        for j in i+1..n+2 {
            let (x1, y1, r1) = xyr[i];
            let (x2, y2, r2) = xyr[j];
            let d = ((x1 - x2).powi(2) + (y1 - y2).powi(2)).sqrt();
            let d = if d < r1 + r2 { 0.0 } else { d - (r1 + r2) };
            ds[i][j] = d;
            ds[j][i] = d;
        }
    }

    while let Some(Point { i, c }) = q.pop() {
        if i == n+1 {
            println!("{:.10}", mincs[n+1]);
            return;
        }
        for j in 0..n+2 {
            if i == j { continue };
            let d = c + ds[i][j];
            if mincs[j] > d {
                mincs[j] = d;
                q.push(Point { i: j, c: d });
            }
        }
    }
}

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

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
int n, k;
int arr[103];

void testCase() {
    cin >> n >> k;
    for (int i=1; i<=n; i++)
        cin >> arr[i];
    sort (arr+1, arr+n+1);
    int dp[k+3][2];
    for (int i=0; i<=k; i++) 
        dp[i][0] = dp[i][1] = 0;
    dp[0][0] = 1;
    dp[0][1] = 0;
    for (int i=1; i<=k; i++) {
        int v1, v2;
        v1 = 1;
        v2 = 0;
        for (int j=1; j<=n; j++) {
            if (i-arr[j] >= 0) {
                v1 = min (dp[i-arr[j]][1], v1);
                v2 = max (dp[i-arr[j]][0], v2);
            }
            else {
                break;
            }
        }
        dp[i][0] = v1;
        dp[i][1] = v2;
    }    
    if (dp[k][0] == 0)
        cout << "First" << endl;
    else
        cout << "Second" << endl;
}

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string.h>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	long long a;
	char s[4];
	cin>>a>>s;
	int bb =(s[0]-'0')*100 +(s[2]-'0')*10+(s[3]-'0');
	long long ans =bb*a/100;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3640
while True:
    a, b = map(int, input().split())
    
    if a == 0 and b == 0:
        break
    
    for i in range(a):
        for j in range(b):
            if (i + j) % 2 == 0:
                print("#", end = "")
            else:
                print(".", end = "")
        print()
    print()


Measured memory_bytes: 7008
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n;
  cin >> n;
  string a;
  ll cnt=0;
  ll A=0,B=0,both=0;
  rep(i,n){
    cin >> a;
    ll k=a.size();
    rep(i,k-1){
      if(a[i]=='A'&&a[i+1]=='B'){
        cnt++;
      }
    }
    if(a[0]=='B'&&a[k-1]=='A'){
      both++;
    }
    else if(a[k-1]=='A'){
      A++;
    }
    else if(a[0]=='B'){
      B++;
    }
  }
  //cout << A << " " << B << " " << both << " " << cnt << endl;
  ll ans=cnt;
  ans+=min(A,B);
  ans+=both;
  if(max(A,B)==0&&both!=0){
    ans--;
  }
  cout << ans << endl;
}

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

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

    int a[5], k;
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;

    bool ans = true;
    for (int i = 0; i < 5; i++)
    {
        for (int j = 0; j < 5; j++)
        {
            if (abs(a[i] - a[j]) > k)
            {
                ans = false;
                break;
            }
        }
    }

    if (ans)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    ll A,B,C,D;
    ll X[4];
    string S,T;
int main(){
    cin>>X[0]>>X[1]>>X[2];
    sort(X,X+3);
    cout<<X[0]+X[2]*10+X[1];
    return 0;
}


Measured memory_bytes: 764
n, m, xx, yy = map(int, input().split())
x = sorted(list(map(int, input().split())))
y = sorted(list(map(int, input().split())))
for i in range(xx + 1, yy):
    if x[-1] < i <= y[0]:
        print("No War")
        break
else:
    print("War")

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
    int a[5],k;
    for(int i=0;i<5;i++){
        cin>>a[i];
    }
    cin>>k;
    for(int i=0;i<5;i++){
        for(int j=i+1;j<5;j++){
            if(a[j]-a[i]>k){
                cout<<":(";
                return 0;
            }

        }
    }
    cout<<"Yay!";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <iomanip>

using namespace std;


int main(void)
{
    while(1){
        int h,m,s;
        cin>>h>>m>>s;
        if(s==-1&&m==-1&&h==-1)break;
        int tape1=120*60;
        int tape2=120*60*3;
        tape1-=h*3600+m*60+s;
        tape2=tape1*3;
        
        cout<<tape1/3600/10<<tape1/3600%10<<":"<<(tape1%3600)/60/10<<(tape1%3600)/60%10<<":"<<(tape1%3600)%60/10<<(tape1%3600)%60%10<<endl;
        cout<<tape2/3600/10<<tape2/3600%10<<":"<<(tape2%3600)/60/10<<(tape2%3600)/60%10<<":"<<(tape2%3600)%60/10<<(tape2%3600)%60%10<<endl;

    }
    
}

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

using ll = long long;

#define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())

string brucik(int a, int b, int c, int d) {
	int n = a + b;
	pair<int,string> rs;
	rs = {n + 1, ""};
	REP(mask, 1<<n) {
		int ca, cb;
		ca = cb = 0;
		int mx = 0, last = -1, cur = 0;
		string curS;
		REP(i, n) {
			int bit = (mask >> i) & 1;
			if (bit) ++cb; else ++ca;
			if (bit) curS += 'B'; else curS += 'A';
			if (bit != last) cur = 0;
			++cur;
			last = bit;
			mx = max(mx, cur);
		}
		if (ca != a || cb != b) continue;
		pair<int,string> here = {mx, curS};
		rs = min(rs, here);
	}
	return rs.second.substr(c, d-c+1);
}

string solve(int a, int b, int c, int d) {
	int rv = 0;
	// brucik(a, b, c, d);
	if (a < b) {
		swap(a, b);
		c = a + b - c - 1;
		d = a + b - d - 1;
		swap(c, d);
		rv = 1;
	}
	string result;
	int r = (a + b) / (b + 1);
	if (r == 1) {
		for (int i = c; i <= d; ++i) {
			result += i % 2 ? 'B' : 'A';
		}
	} else {
		int x = (r*(a+1)-b-1)/(r*r-1);
		int y = ((a-r*x+1)*r - (b-x))/r;
		x *= r+1;
		y += x;
		for (int i = c; i <= d; ++i) {
			int now = i;
			if (now < x) {
				result += now % (r + 1) == r ? 'B' : 'A';
			} else 
			if (now < y) {
				result += 'A';
			} else {
				now -= y;
				now = a + b - now - 1;
				now -= y;
				result += now % (r + 1) == r ? 'A' : 'B';
			}
		}
	}
	if (rv) {
		reverse(result.begin(), result.end());
		for (auto& c : result) c = 'A' + 'B' - c;
	}
	return result;
}

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

	// cout << solve(11, 9, 0, 19) << endl;
	// cout << brucik(11, 9, 0, 19) << endl;

	// for (int a = 1; a <= 12; ++a) {
	// 	for (int b = 1; b <= 12; ++b) {
	// 		if (solve(a, b, 0, a + b - 1) != brucik(a, b, 0, a + b - 1)) {
	// 			cout << a << ' ' << b << endl;
	// 			cout << solve(a, b, 0, a + b - 1) << ' ' << brucik(a, b, 0, a + b - 1) << endl;
	// 			return 0;
	// 		}
	// 	}
	// }

	int t;
	cin >> t;
	REP(i, t) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		--c; --d;
		cout << solve(a, b, c, d) << '\n';
	}

	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	double t1,t2;
	while(scanf("%lf%lf",&t1,&t2)>0)
	{
		if(t1<35.5&&t2<71)
			printf("AAA\n");
		else if(t1<37.5&&t2<77)
			printf("AA\n");
		else if(t1<40&&t2<83)
			printf("A\n");
		else if(t1<43&&t2<89)
			printf("B\n");
		else if(t1<50&&t2<105)
			printf("C\n");
		else if(t1<55&&t2<116)
			printf("D\n");
		else if(t1<70&&t2<148)
			printf("E\n");
		else
			printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 0
N, M, Q = map(int, input().split())
X = []
for _ in range(Q):
    a, b, c, d = map(int, input().split())
    X.append((a, b, c, d))

from itertools import combinations_with_replacement

ans = 0

for p in combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    p = list(p)
    for a, b, c, d in X:
        if p[b-1] - p[a-1] == c:
            tmp += d
    
    ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 9196
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// How to use 「map」
/*
  - 宣言
    map<{key_type}, {value_type}> salary;
  - 要素の挿入
    salary["Alice"] = 1000;
  - 要素の取得 O(logn)
    salary.at("Alice");
  - 要素の削除
    salary.erase("Alice");
  - キー検索
    salary.find("Alice"); -> true
    salary.find("Bob");   -> false
  - イテレーション
    for(auto& [key, value] : salary) {...}
 */
// -------------------------------------


// How to use 「lower_bound」, 「upper_bound」
/*
  vector<int> a = {1, 2, 3, 4, 5};
  auto iter1 = lower_bound(all(a), 3);  <- 第二引数「以上」の最小イテレータが返る
  auto iter2 = upper_bound(all(a), 3);  <- 第二引数「より大きい」最小のイテレータが返る
 */
// -------------------------------------


// How to use 「struct sort」
/*
  struct Person {
    string name;
    int age;

    Person(string _name, int _age) {
      name = _name;
      age = _age;
    }

    bool operator<(const Person &another) const {
      return age < another.age;
    }
  };

  vector<Person> people;
  people.pb(Person("Alice", 20));
  people.pb(Person("Bob", 19));
  people.pb(Person("John", 40));
  people.pb(Person("Chris", 30));
  sort(all(people));
 */
 // -------------------------------------

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



int main() {
  vector<double> a;
  a.pb(0);

  int n, k;
  cin >> n >> k;

  rep(i, n) {
    int p;
    cin >> p;

    double p1 = ((p + 1) / 2.0);
    a.pb(a[i] + p1);
  }

  double ans = 0.0;
  rep(i, n-k+1) {
    ans = max(ans, a[i+k] - a[i]);
  }

  printf("%.15f\n", ans);

  return 0;
}

Measured memory_bytes: 2420
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N, K = in_nn()
    x = in_nl()

    ans = 10**9 + 7
    for i in range(N - K + 1):
        left = x[i]
        right = x[i + K - 1]
        if right <= 0:
            ans = min(ans, abs(left))
        elif left >= 0:
            ans = min(ans, abs(right))
        else:
            ans = min(ans, abs(left) + abs(right) + min(abs(left), abs(right)))

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18988
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl

/*--------------------template--------------------*/

int main()
{
	vi v1, v2, v3, v4;
	ll x, y, n;
	cin >> x >> y >> n;
	v1.push_back(sum);
	v2.push_back(x);
	v3.push_back(sum);
	v4.push_back(y);
	REP(i, n)
	{
		ll a, b, c;
		cin >> a >> b >> c;
		if (c == 1) {
			v1.push_back(a);
		} else if (c == 2) {
			v2.push_back(a);
		} else if (c == 3) {
			v3.push_back(b);
		} else if (c == 4) {
			v4.push_back(b);
		}
	}
	sort(ALL(v1));
	sort(ALL(v2));
	sort(ALL(v3));
	sort(ALL(v4));
	ans = (v2.front() - v1.back())*(v4.front() - v3.back());
	if (ans < 0) {
		ans = 0;
	}
	if (v2.front() - v1.back() < 0 || (v4.front() - v3.back() < 0))
	{
		ans = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
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;}
int in(){int a;scanf("%d",&a);return a;}
ll lin(){ll a;scanf("%lld",&a);return a;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int n;
int a[200010], b[200010];
int bit[200010];
map<int, int> m;

int sum(int i)
{
    int s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}

void add(int i, int x)
{
    while (i <= n) {
        bit[i] += x;
        i += i & -i;
    }
}

int main()
{
    cin >> n;

    rep(i, n) cin >> a[i], b[i] = a[i];

    sort(b, b+n);

    rep(i, n) {
        m[b[i]] = i+1;
    }

    ll ans = 0;

    rep(i, n) {
        ans += i - sum(m[a[i]]);
        add(m[a[i]], 1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 14864