akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int ans[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	LL sum = 0;
	for (int i = 1; i <= n; i++)
	{
		sum += i;
		if (sum >= n)
		{
			cout << i << endl;
			exit(0);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
    int n;
    cin>>n;
    V<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]=-a[i];
    }
    multiset<int> s;
    int ans=0;
    for(int i=0;i<n;i++){
        auto ite=s.upper_bound(a[i]);
        if(s.size()==0||ite==s.end())ans++;
        s.insert(a[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 10368
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
long long ans[100000];
long long sum=1;
long long pd=1000000000000000000;
int main()
{
    int k=0;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>ans[i];
        if(ans[i]==0)
        {
            k=1;
        }
    }
    if(k==1)
    {
        cout<<0<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
        if(ans[i]>pd/sum)
        {
            cout<<-1<<endl;
            return 0;
        }
        sum=sum*ans[i];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 4416
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;

int main()
{
    string S;
    char sko1 = '9';
    char sko2 = '9';
    string res = "No";

    cin >> S;

    ll ko1 = 0;
    ll ko2 = 0;


    REP(i,4)
    {
        if(ko1 == 0 && ko2 == 0)
        {
            sko1 = S[i];
            ko1++;
        }
        else
        {
            if(S[i] == sko1)
            {
                ko1++;
            }
            else if(ko2 == 0)
            {
                sko2 = S[i];
                ko2++;
            }
            else if(S[i] == sko2)
            {
                ko2++;
            }
        }
    }
    if(ko1 == 2 && ko2 == 2)res = "Yes";

    cout << res << endl;

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int cnt[maxn];
int is[maxn];
int32_t main(){
	fastio();
	int n,m;
	cin >> n >> m;
	for(int i = 1; i <= m; i++){
		int x;
		cin >> x;
		is[x] = 1;
	}
	cnt[0] = 1;
	for(int i = 1; i <= n; i++){
		if(is[i]) continue;
		if(i - 1 >= 0) cnt[i] += cnt[i - 1];
		cnt[i] %= mod;
		if(i - 2 >= 0) cnt[i] += cnt[i - 2];
		cnt[i] %= mod;
	}
	cout <<cnt[n];
}

Measured memory_bytes: 5152
<?php

$input = trim(fgets(STDIN));
$a = explode(' ',$input);

$W = $a[0];
$H = $a[1];
$x = $a[2];
$y = $a[3];
$r = $a[4];
	
if((0 <= ($x-$r) && ($x+$r) <= $W) && (0 <= ($y-$r) && 	($y+$r) <= $H)){

	echo "Yes";
	
}else{
	echo "No";
}

?>

Measured memory_bytes: 15324
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.min;
import static java.lang.System.exit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void sortBy(int a[], int n, long v[]) {
		if (n == 0) {
			return;
		}
		for (int i = 1; i < n; i++) {
			int j = i;
			int ca = a[i];
			long cv = v[ca];
			do {
				int nj = (j - 1) >> 1;
				int na = a[nj];
				if (cv <= v[na]) {
					break;
				}
				a[j] = na;
				j = nj;
			} while (j != 0);
			a[j] = ca;
		}
		int ca = a[0];
		for (int i = n - 1; i > 0; i--) {
			int j = 0;
			while ((j << 1) + 2 + Integer.MIN_VALUE < i + Integer.MIN_VALUE) {
				j <<= 1;
				j += (v[a[j + 2]] > v[a[j + 1]]) ? 2 : 1;
			}
			if ((j << 1) + 2 == i) {
				j = (j << 1) + 1;
			}
			int na = a[i];
			a[i] = ca;
			ca = na;
			long cv = v[ca];
			while (j != 0 && v[a[j]] < cv) {
				j = (j - 1) >> 1;
			}
			while (j != 0) {
				na = a[j];
				a[j] = ca;
				ca = na;
				j = (j - 1) >> 1;
			}
		}
		a[0] = ca;
	}

	static void solve() throws Exception {
		int n = scanInt(), x = scanInt();
		int b[] = new int[n], l[] = new int[n], u[] = new int[n], idx[] = new int[n];
		long v[] = new long[n];
		long s = 0;
		for (int i = 0; i < n; i++) {
			b[i] = scanInt();
			l[i] = scanInt();
			u[i] = scanInt();
			v[i] = (long) u[i] * (x - b[i]) + (long) l[i] * b[i];
			s += (long) l[i] * b[i];
			idx[i] = i;
		}
		sortBy(idx, n, v);
		long ans = 0;
		int i;
		for (i = n - 1; i >= 0; i--) {
			if (s < v[idx[i]]) {
				break;
			}
			s -= v[idx[i]];
			ans += x;
		}
		if (s > 0) {
			long ans2 = x;
			for (int j = 0; j <= i; j++) {
				long cl = l[idx[j]], cb = b[idx[j]], cu = u[idx[j]];
				if (s <= cl * cb + cu * (x - cb)) {
					ans2 = min(ans2, s <= cl * cb ? (s - 1) / cl + 1 : cb + (s - cl * cb - 1) / cu + 1);
				}
			}
			for (int j = i + 1; j < n; j++) {
				long cl = l[idx[j]], cb = b[idx[j]], cu = u[idx[j]];
				long cs = s + v[idx[j]] - v[idx[i]];
				if (cs <= cl * cb + cu * (x - cb)) {
					ans2 = min(ans2, cs <= cl * cb ? (cs - 1) / cl + 1 : cb + (cs - cl * cb - 1) / cu + 1);
				}
			}
			ans += ans2;
		}
		out.print(ans);
	}

	static int scanInt() throws IOException {
		return parseInt(scanString());
	}

	static long scanLong() throws IOException {
		return parseLong(scanString());
	}

	static String scanString() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	public static void main(String[] args) {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Throwable e) {
			e.printStackTrace();
			exit(1);
		}
	}
}

Measured memory_bytes: 46088
#include<iostream>
#include<algorithm>
#include<vector>

#define FRAMES 10
#define SCORES 21

using namespace std;
class Student{
public:
	Student(){
		id = 0;
		for(int i = 0; i < SCORES; ++i){
			scores[i] = 0;
		}
	}
	int id;
	int scores[SCORES];
	void calculateScore(){
		int nScore = 0;
		int frame = 0;
		for(int i = 0; i < SCORES; ++frame){
			if( frame != FRAMES-1 ){
				int a = scores[ i ];
				int b = scores[ i + 1 ];
				if( a == 10 ){
					nScore += a + b + scores[ i + 2 ];
					++i;
				}else if( a + b == 10 ){
					nScore += a + b + scores[ i + 2 ];
					i+=2;
				}else{
					nScore += a + b;
					i+=2;
				}
			}else{
				nScore += scores[ i ] + scores[ i + 1 ] + scores[ i + 2 ];
				break;
			}
		}
		score = nScore;
	}
	int score;
};
bool operator < ( const Student &t1, const Student &t2 ){
	if( t1.score == t2.score ){
		return t1.id < t2.id;
	}else
		return t1.score > t2.score;
}
istream & operator >> (istream &is, Student &std){
	int i = 0;
	is >> std.id;
	while( true ){
		is >> std.scores[i++];
		if( is.get() == '\n' )
			break;
	}
	return is;
}
ostream & operator << (ostream &os, Student &std){
	os << std.id << ' ' << std.score;
	return os;
}

int main()
{

	while( true ){
		int n;
		vector< Student > vStudents;
		cin >> n;
		if( n == 0 ) break;
		for(int i = 0; i < n; ++i){
			Student t;
			cin >> t;
			t.calculateScore();
			vStudents.push_back( t );
		}
		sort( vStudents.begin() , vStudents.end() );
		for(int i = 0; i < n; ++i){
			cout << vStudents[i] << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 0
n, m, x, y = map(int, input().split())
x_list = list(map(int, input().split()))
y_list = list(map(int, input().split()))
x_max = max(x_list)
y_min = min(y_list)
if x_max < y_min and x < y_min and x_max < y: print("No War")
else: print("War")

Measured memory_bytes: 3060
import sys
input=sys.stdin.readline

n=int(input().rstrip())
a=[list(map(int,input().split())) for _ in range(2)]

ans=0
for i in range(n):
    now=sum(a[0][:i+1])+sum(a[1][i:])
    ans=max(ans,now)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <algorithm>
#define ll long long
using namespace std;

const int mod = 1000000000 + 7;
const double eps = 1e-9;


int main()
{


	ll N, A, B;

	cin>>N>>A>>B;

	if(A > B)
	{
		cout<<0<<endl;
		return 0;
	}

	if(N == 1)
	{
		if(A == B)
		{
			cout<<1<<endl;
		}
		else
		{
			cout<<0<<endl;
		}
		return 0;
	}

	ll ans = (N - 2) * (B - A) + 1;

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int64 INF = 1LL << 40 - 1;
constexpr int64 LINF = 1LL << 60 + 1;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;
    
// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;
    
// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;
    
// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
    
    
signed main() {
    INIT;
    VAR(int, n);
    map< int, int > mp;
    vector< int > a;
    REP(i, n) {
        VAR(int, j);
        a.push_back(j);
        mp[j]++;
    }
    
    sort(ALL(a));
    a.erase(unique(ALL(a)), a.end());
    
    int ans = 0;
    RREP(i, a.size()) {
        RREP(j, 31) {
            if (mp[a[i]] == 0) break;
            if (2LL * a[i] > 1LL << j) break;
            int target = (1 << j) - a[i];
            if (target == a[i]) {
                int tmp = mp[target] / 2;
                mp[target] -= tmp * 2;
                ans += tmp;
            } else {
                int tmp1 = mp[target];
                int tmp2 = mp[a[i]];
                mp[target] -= min(tmp1, tmp2);
                mp[a[i]] -= min(tmp1, tmp2);
                ans += min(tmp1, tmp2);
            }
        }
    }
    
    OUT(ans)BR;
    
    return 0;
}

Measured memory_bytes: 36720
#include <iostream>
#include <string>
using namespace std;
bool f(){
}
int main(){
  int n,m,h,d;
  while(cin>>n&&n){
    cin>>m>>h>>d;
    string s[d];
    int x=m-1,y=h-1;
    for(int i=0;i<d;++i){
      cin>>s[i];
      if(x<n-1&&s[i][x]=='1') ++x;
      else if(x-1>=0&&s[i][x-1]=='1') --x;
    }
    if(x==h-1){
      cout<<0<<endl;continue;
    }
    x=m-1;
    for(int i=d-1;i>=0;--i){
      if(y<n-1&&s[i][y]=='1') ++y;
      else if(y-1>=0&&s[i][y-1]=='1') --y;
    }
    bool f=true;
    for(int i=0;i<d;++i){
      if(x==y-1&&s[i][x]=='0'&&(x==0||s[i][x-1]=='0')&&(x==n-2||s[i][x+1]=='0')){
	cout<<i+1<<" "<<x+1<<endl;f=false;break;
      }
      else if(x==y+1&&s[i][x-1]=='0'&&(x==1||s[i][x-2]=='0')&&(x==n-1||s[i][x]=='0')){
	cout<<i+1<<" "<<x<<endl;f=false;break;
      }
      if(x<n-1&&s[i][x]=='1') ++x;
      else if(x-1>=0&&s[i][x-1]=='1') --x;
      if(y<n-1&&s[i][y]=='1') ++y;
      else if(y-1>=0&&s[i][y-1]=='1') --y;
    }
    if(f) cout<<1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long N, M;
  cin >> N >> M;
  multimap<long long, long long> AB;
  for (long long i = 0; i < N; ++i) {
    long long a, b;
    cin >> a >> b;
    AB.insert(make_pair(a, b));
  }
  long long money = 0;
  long long rest_drink = M;  // 残り本数
  for (auto itr = AB.begin(); itr != AB.end(); ++itr) {
    if (rest_drink <= itr->second) {
      money += itr->first * rest_drink;
      break;
    }
    if (rest_drink > itr->second) {
      money += itr->first * itr->second;
      rest_drink = rest_drink - itr->second;
    }
  }
  cout << money << endl;
  return 0;
}


Measured memory_bytes: 6528
n = int(input())
A = [0] + list(map(int, input().split())) + [0]

cost = 0
for i in range(n+1):
    cost += abs(A[i] - A[i+1])

for i in range(1, n+1):
    ans = cost
    ans -= abs(A[i] - A[i-1])
    ans -= abs(A[i] - A[i+1])
    ans += abs(A[i-1] - A[i+1])
    print(ans)

Measured memory_bytes: 20632
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
int h[100000];
int dp[100001];
int main() {
  int n;
  cin >> n;
  rep(i, n) cin>> h[i];
  int INF = 1 << 30;
  reps(i, n) dp[i] = INF;
  dp[0] =0;
  dp[1] = abs(h[1]-h[0]);
  for(int i = 2; i < n; i++){
    chmin(dp[i], dp[i - 1] + abs(h[i - 1] - h[i]));
    chmin(dp[i], dp[i - 2] + abs(h[i - 2] - h[i]));
  }
  cout << dp[n - 1] << endl;
  return 0;  
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    long long int a, b, x;
    cin >> a >> b >> x;

    long long int aWaru = a / x;
    long long int bWaru = b / x;

    if (a % x == 0) {
        cout << bWaru - aWaru + 1;
    } else {
        cout << bWaru - aWaru;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> d(n);
	vector<int> s(n);
	for (int i = 0;i < n;i++) {
		cin >> d[i];
		if (i == 0)s[i] = d[i];
		else s[i] = s[i - 1] + d[i];
	}

	long long ans = 0;
	for (int i = 0;i < n;i++) {
		ans += d[i] * (s[n - 1] - s[i]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int r = scan.nextInt();
        int c = scan.nextInt();
        int sumH = 0;
        int sumV = 0;
        int[][] l = new int[r + 1][c + 1];

        for (int v = 0; v < r; v++) {
            for (int h = 0; h < c; h++) {
                l[v][h] = scan.nextInt();
            }
        }

        for (int v = 0; v < r; v++) {
            for (int h = 0; h < c; h++) {
                sumH += l[v][h];
            }
            l[v][c] = sumH;
            sumH = 0;
        }


        for (int h = 0; h < c +1; h++) {
            for (int v = 0; v < r +1; v++) {
                sumV += l[v][h];
            }
            l[r][h] = sumV;
            sumV = 0;
        }

        for (int v = 0; v < r + 1; v++) {
            for (int h = 0; h < c + 1; h++) {
                if (h == c) {
                    System.out.print(l[v][h]);
                } else {
                    System.out.print(l[v][h] + " ");
                }
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 42020
#include "bits/stdc++.h"
#include<assert.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
const int inf = 1e17;
const int mod = 1000000007;
typedef pair<int, int> P;
typedef pair<int, P> PP;
string a[100], b[100];
signed main() {
	int n, m; cin >> n >> m;
	rep(i, n)cin >> a[i];
	rep(i, m)cin >> b[i];
	rep(i, n - m+1) {
		rep(j, n - m + 1) {
			int cnt = 0;
			rep(k, m) {
				rep(l, m) {
					if (a[i + k][j + l] != b[k][l])cnt++;
				}
			}
			if (!cnt) {
				puts("Yes"); return 0;
			}
		}
	}
	puts("No");
}

Measured memory_bytes: 256
T=int(input())
for TT in range(T):
	a,b,c,d=map(int,input().split(' '))
	l,x,y,out=(a+b)//(min(a,b)+1),0,0,""
	if a*l<=b:y=a+b
	elif b*l<=a:x=a+b
	else:x,y=(a*l-b)//(l-1),(b*l-a)//(l-1) 
	for i in range(c,d+1):out+=("AB"[i%(l+1)==0]) if i<=x else "BA"[(a+b-i+1)%(l+1)==0] if a+b-i+1<=y else "AB"[a-x+x//(l+1)-y//(l+1)==0]
	print(out)

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

typedef long long ll;
ll a[10], ans;

int main() {
    rep(i, 1, 7) cin >> a[i];
    ans = a[2];
    if (!(a[1] && a[4] && a[5]))
        ans += a[1] / 2 * 2, ans += a[4] / 2 * 2, ans += a[5] / 2 * 2;
    else
        ans += a[1] + a[4] + a[5] - !(a[1] % 2 == a[4] % 2 && a[4] % 2 == a[5] % 2);
    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int a;
	string s;
	cin>>a>>s;
	cout<<(a>=3200 ? s : "red")<<'\n';
	return 0;
}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int main() {
  int x , ans = 1 , temp ;
  cin >> x ;

  for(int b = 2 ; b*b <=x; b++){
    temp = b ;
    for(int p = 1 ; ;p++){
      temp*=b ;
      if(temp<=x){
        if(temp>ans)ans = temp ;
      }
      else break ;
    }
  }
  cout << ans << endl ;
	
  return 0 ;
}

Measured memory_bytes: 256
def stack(layer, length):
  if layer==1:
    return "BPPPB"[:length].count("P")
  else:
    if length==(lengths[layer-1]+1)/2:
      return ps[layer-2]+1
    elif length<(lengths[layer-1]+1)/2:
      return stack(layer-1, length-1)
    else:
      return ps[layer-2]+1+stack(layer-1, length-lengths[layer-2]-2)
    
inp = input().split()
layer = int(inp[0])
length = int(inp[1])
lengths = [5]
ps = [3]
for i in range(49):
  lengths.append(lengths[i]*2+3)
  ps.append(ps[i]*2+1)
print(stack(layer, length))

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        int v=a[i];
        if(i!=0){
            for(int j=i-1;0<=j;j--){
                if(a[j]>v) {
                    a[j+1]=a[j];
                    a[j]=v;
                }
                else{
                    a[j+1]=v;
                    break;
            } 
            
        }
        }
        for(int i=0;i<n;i++){
            if(i==0){
                cout<<a[i];
            }
            else cout<<" "<<a[i];
        }
        cout<<endl;
        
    }
}


Measured memory_bytes: 3120
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
using namespace std;


set<int> v;
bool hai(int n){
	if(v.find(n)!=v.end()){
		return false;
	}
	return true;
}

bool valid(int n){
	while(n){
		if(!(hai(n%10))){
			return false;
		}
		n/=10;
	}
	return true;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	
	map<char,int> mp;
	string a;cin>>a;
	for(int i=0;i<a.length();i++){
		mp[a[i]]++;
	}
	for(auto x:mp){
		if(x.second&1){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <iostream>
#include <stdio.h>

#define MAX_D 10

using namespace std;

int P[MAX_D]{};
int C[MAX_D]{};

int main() {
  int D, G;
  cin >> D >> G;
  for (int i = 0; i < D; ++i) {
    cin >> P[i] >> C[i];
  }

  int res = 1000;
  for (int i = 0; i < (1 << D); ++i) {
    bitset<1000> b(i);
    int s = 0;
    int cnt = 0;
    int k = 0;
    for (int j = 0; j < D; ++j) {
      if (b.test(j)) {
        s += 100 * (j + 1) * P[j] + C[j];
        cnt += P[j];
      } else {
        k = j;
      }
    }
    if (s >= G) {
      res = min(res, cnt);
    } else {
      for (int l = 0; l < P[k] - 1; ++l) {
        s += 100 * (k + 1);
        ++cnt;
        if (s >= G) {
          res = min(res, cnt);
          break;
        }
      }
    }
  }
  printf("%d\n", res);
}

Measured memory_bytes: 3180
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N, M;
vector<tuple<ll, ll, ll>> ABC;
ll solve(int a, int b, int c)
{
    vector<ll> tmp;
    for (int i = 0; i < N; i++)
    {
        ll A, B, C;
        tie(A, B, C) = ABC[i];
        if (a == 1)
        {
            A *= -1;
        }
        if (b == 1)
        {
            B *= -1;
        }
        if (c == 1)
        {
            C *= -1;
        }
        tmp.push_back(A + B + C);
    }
    sort(tmp.rbegin(), tmp.rend());
    ll res = 0;
    for (int i = 0; i < M; i++)
    {
        res += tmp[i];
    }
    return res;
}
int main()
{
    cin >> N >> M;
    for (int i = 0; i < N; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        ABC.emplace_back(mt(a, b, c));
    }
    ll result = -LL_INF;
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            for (int k = 0; k < 2; k++)
            {
                result = max(result, solve(i, j, k));
            }
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let ma = a.iter().max().unwrap().clone();
    let mi = a.iter().min().unwrap().clone();
    let mut ans = std::i64::MAX;
    for i in mi..(ma+1) {
        let mut sum = 0;
        for j in a.iter() {
            sum += (j-i) * (j-i);
        }
        ans = min(ans, sum);
    }
    println!("{}", ans);
}

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

int main() {
  string s;
  cin >> s;
  int klen = 7;

  // 先頭から削り
  for (int i = 0; i < s.size(); i++) {
    string ss(s.begin() + i, s.end());
    if (ss == "keyence") {
      puts("YES");
      return 0;
    }
  }

  // 後方から削り
  for (int i = 0; i < s.size(); i++) {
    string ss(s.begin() + s.size() - 1 - i, s.end());
    if (ss == "keyence") {
      puts("YES");
      return 0;
    }
  }

  // 左右分割
  for (int i = 1; i < s.size() - 1; i++) {
    string l = s.substr(0, i);
    for (int j = 0; j < s.size() - i; j++) {
      string r(s.begin() + i + j, s.end());
      if (l + r == "keyence") {
        puts("YES");
        return 0;
      }
    }
  }

  puts("NO");
  return 0;
}

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

int main(){
    int n;

    cin >> n;

    // cout << n << endl;a

    int ary[n];

    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        ary[i] = x;
    }

    for(int i = n - 1; 0 <= i; i--){
        if(n - 1 != i){
            cout << " ";
        }
        cout << ary[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val s = Scanner(System.`in`)
    val n = s.nextInt()
    val a = LongArray(n) { s.nextLong() }


    val h = LongArray(n)
    val t = LongArray(n)
    h[0] = a[0]
    t[n - 1] = a[n - 1]
    (1 until n).forEach { i ->
        h[i] = gcd(h[i - 1], a[i])
        t[n - 1 - i] = gcd(t[n - i], a[n - i - 1])
    }

    val ret = (0 until n)
        .map { index ->
            if (index == 0) t[1]
            else if (index == n - 1) h[n - 2]
            else gcd(h[index - 1], t[index + 1])
        }
        .max()


    println(ret)
}

fun gcd(a: Long, b: Long): Long {
    val x = Math.max(a, b)
    val y = Math.min(a, b)
    val c = x % y
    return if (c == 0L) y else gcd(y, c)
}

Measured memory_bytes: 55252
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	private static String YES = "Yes";
	private static String NO = "No";

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		long monsterHP = scan.nextLong();
		long nunberSPATK = scan.nextLong();

		List<Long> listInput = new ArrayList<Long>();
		for (int i = 0; i < nunberSPATK; i++) {
			listInput.add(scan.nextLong());
		}

		scan.close();

		for(int i = 0; i < nunberSPATK; i++) {
			monsterHP -= listInput.get(i);
			if (monsterHP <= 0) {
				System.out.println(YES);
				return;
			}
		}
		System.out.println(NO);
	}
}


Measured memory_bytes: 62516
h, k = [list(map(int, input().split())) for i in range(2)]
a, b, aa, bb = map(int, input().split())

hp = h[0]*a + h[1]*b
hp += h[0]//10*aa + h[1]//20*bb

kp = k[0]*a + k[1]*b
kp += k[0]//10*aa + k[1]//20*bb

if kp!=hp: print("hkiernojsihrio"[kp>hp::2])
else: print("even")


Measured memory_bytes: 5604
#include<stdio.h>
int N;
long long W;
long long w[105],v[105],dp[105][100005];
long long max(long long a,long long b)
{
	if(a>b)return a;
	else
		return b;
}
long long f(int  pos,long long wei)
{
	if(dp[pos][wei]!=-1)
		return dp[pos][wei];
	else if(wei>W)return 0;
	else if(pos>N)return 0;
	else
	{
		long long var;
		var=wei+w[pos];
		if(var<=W)
		return dp[pos][wei]=max(v[pos]+f(pos+1,var),f(pos+1,wei));
		else
			return dp[pos][wei]=f(pos+1,wei);


	}
}
int main()
{
	scanf("%d %Ld",&N,&W);
	for(int i=1;i<=N;i++)
	{
		scanf("%Ld %Ld",&w[i],&v[i]);
	}
	for(int i=0;i<105;i++)
	{
		for(int j=0;j<100005;j++)
		{
			dp[i][j]=-1;
		}
	}
	printf("%Ld\n",f(1,0));
	return 0;
}


		



Measured memory_bytes: 82176
marks=[]
while True:
    s=input().split()
    marks.append(s)
    if ["-1","-1","-1"] in marks:
        break
marks=marks[:-1]
for i in marks:
    if int(i[0])==-1 or int(i[1])==-1:
        print("F")
    elif int(i[0])+int(i[1])>=80:
        print("A")
    elif 65<=int(i[0])+int(i[1])<80:
        print("B")
    elif 50<=int(i[0])+int(i[1])<65:
        print("C")
    elif 30<=int(i[0])+int(i[1])<50:
        if int(i[2])>=50:
            print("C")
        else:
            print("D")
    elif int(i[0])+int(i[1])<30:
        print("F")


Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  int k;
  cin >> k;
  vector<ll> a(k);
  rep(i,k) cin >> a[i];
  reverse(a.begin(), a.end());

  bool f = true;
  ll l=2,r=2;
  rep(i,k){
    ll temp = l;
    l = (l+a[i]-1)/a[i]*a[i];
    if(l<temp||r<l){
      f = false;
      break;
    }
    r = r/a[i]*a[i]+a[i]-1;
  }

  if(f) cout << l << " " << r << "\n";
  else cout << -1 << "\n";
  
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int i, j , number[10] ={0}, x;
    
    for(i = 0; i < 4; i++){
           cin >> x;
           number[x] = 1;
    }
    if(number[1] != 1){
        cout << "NO" << endl;
    }
    else if(number[4] != 1){
        cout << "NO" << endl;
    } 
    else if(number[7] != 1){
        cout << "NO" << endl;
    }
    else if(number[9] != 1){
        cout << "NO" << endl;
    }
    else{
        cout << "YES" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define INF 1e+9
using namespace std;

struct edge{ int to; int cost; };
typedef pair<int,int> P;

vector<edge> graph[100];
int cost[10][100];
int V;

void dijkstra(int dijk_s,int a){
	priority_queue<P,vector<P>,greater<P> > dijk_que;
	for(int i = 0;i < V;i++) cost[a][i] = INF;
	cost[a][dijk_s] = 0;
	dijk_que.push(make_pair(0,dijk_s));
	while(!dijk_que.empty()){
		P dijk_p = dijk_que.top();
		dijk_que.pop();
		int dijk_v = dijk_p.second;
		//if(cost[a][dijk_v] < dijk_p.first) continue;
		for(int i = 0;i < graph[dijk_v].size();i++){
			edge dijk_e = graph[dijk_v][i];
			int cmin;
			if(a == 0) cmin = cost[a][dijk_v] + dijk_e.cost;
			else cmin = min(cost[a][dijk_v] + dijk_e.cost,cost[a - 1][dijk_v] + dijk_e.cost / 2);
			if(cost[a][dijk_e.to] > cmin){
				cost[a][dijk_e.to] = cmin;
				dijk_que.push(make_pair(cost[a][dijk_e.to],dijk_e.to));
			}
		}
	}
}

int main(){
	int c,m,s,d;
	while(1){
	cin >> c >> V >> m >> s >> d;
	if(c == 0) break;
	for(int i = 0;i < m;i++){
		int a,b,f;
		cin >> a >> b >> f;
		graph[a - 1].push_back({b - 1,f});
		graph[b - 1].push_back({a - 1,f});
	}
	for(int i = 0;i <= c;i++){
		dijkstra(s - 1,i);
	}
	cout << cost[c][d - 1] << endl;
	for(int i = 0;i < V;i++) graph[i].clear();
	}
	return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15



signed main()
{
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {
        int n;
        cin >> n;

        vector<int> a(n);
        rep(i,0,n) cin >> a[i];
        sort(all(a));

        int ans = 0;
        int cnt = 1;
        ans = a.back();
        int i = n-2;
        int f = 0;

        while(cnt < n - 1){
               // cout<<i<<endl;
            ans += a[i];
            f++;
            cnt++;
            if(f == 2){
                f = 0;
                i--;
            }
            // trace(ans);
        }

        cout << ans << endl;
    }

}


Measured memory_bytes: 4776
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]
ans = 0
S = []
for i in AB:
  ans -= i[1]
  S.append(i[0] + i[1])
S = sorted(S)[::-1]
for i in range(0,N,2):
  ans += S[i]
print(ans)

Measured memory_bytes: 33040
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    /* code */
    vector<int> bar;
    int n,k;
    int sum;

    cin >> n >> k;

    for (int i = 0; i < n; ++i)
    {
        int tmp;
        cin >> tmp;
        bar.push_back(tmp);
    }

    sort(bar.begin(),bar.end());
    reverse(bar.begin(),bar.end());

    for (int i = 0; i < k; ++i)
    {
        sum += bar[i];
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long unsigned int ll;
typedef pair<ll,ll> P;
 
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(2*(a*b+b*c+c*a)<c*c+a*a+b*b&&c==max(c,max(a,b))){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}

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

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

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

using namespace std;

int main() {
  int N;
  long long int M;
  cin >> N >> M;
  vector<long long int> A(N);
  vector<long long int> Asum(N+1, 0);
  int Cnt[200001]={0};
  for(int n=0; n<N; n++) {
    cin >> A[n];
    Cnt[A[n]]++;
  }

  sort(A.begin(), A.end(), greater<long long int>());
  for(int n=0; n<N; n++) {
    Asum[n+1] = Asum[n]+A[n];
  }

  for(int i=199999; i>=0; i--) {
    Cnt[i] += Cnt[i+1];
  }
  // for(int i=40; i>=0; i--) {
  //     cout << i << ": " << Cnt[i] << endl;
  // }

    
  long long int l=1, r=200001;
  long long int counter=0;
  long long int ans;
  long long int X;
  map<long long int, long long int> mp;
  while(r-l>1) {
    X=(l+r)/2;
    long long int counter=0;
    ans=0;
    for(int n=0; n<N; n++) {
      counter += Cnt[(int)max(X-A[n], (long long int)0)];
            
      ans += (Asum[Cnt[(int)max(X-A[n], (long long int)0)]]+A[n]*Cnt[(int)max(X-A[n], (long long int)0)]);
    }
        
    if(counter>=M) {
      l = X;
    } else {
      r = X;
    }
        
    mp[X] = counter;
  }

  if(l==X) {
    cout << ans-abs(M-mp[l])*l << endl;
  } else if(r==X) {
    cout << ans+abs(M-mp[r])*l << endl;
  }

  return 0;
    
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
 
#define barsik ios::sync_with_stdio(false)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
 
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair <int, int> pii;
typedef std::unordered_set <int> u_si;
 
using namespace std;

void solve(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll tmp = a;
    a = max(1ll * 0, a - c);
    if(a == 0){
        cout << a << ' ' << max(1ll * 0, b - (c - tmp));
    }
    else cout << a << ' ' << b;
    
    
}

 
int main(){
    barsik;
    //freopen("file.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(ll i = 1; i <= q; i++){
        solve();
    }
}


Measured memory_bytes: 256
N = int(input())
D = [int(d) for d in input().split()]
Dcount = [0] * 13

for i in range(13):
    Dcount[i] = D.count(i)
if Dcount[0] > 0 or Dcount[12] > 1: print(0)
else:
    for i in Dcount[1:12]:
        if i >= 3:
            print(0)
            break
    else:
        base = [0, 24]
        if Dcount[12] == 1: base.append(12)
        Single = []
        for i in range(1, 12):
            if Dcount[i] == 2:
                base.append(i)
                base.append(24-i)
            elif Dcount[i] == 1:
                Single.append(i)
        lensingle = len(Single)
        minmax = 0
        for i in range(2**lensingle):
            Clock = base.copy()
            bit = format(i, "b").zfill(lensingle)
            for j in range(lensingle):
                if bit[j] == "0": Clock.append(Single[j])
                else: Clock.append(24 - Single[j])
            Clock.sort()
            minsub = 24
            for j in range(1, len(Clock)):
                minsub = min(minsub, Clock[j] - Clock[j-1])
            minmax = max(minmax, minsub)
        print(minmax)

Measured memory_bytes: 3192
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int count = 1;
    String str = sc.next();
    char ch, temp;
    temp = str.charAt(0);
    for(int i = 1; i < n; i++) {
      ch = str.charAt(i);
      if(ch != temp) {
        count++;
        temp = ch;
      }
    }
    System.out.println(count);
  }
}


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

int n;
string str;
int have[10], field;

int main()
{
	while (cin >> n, n){
		cin >> str;
		memset(have, 0, sizeof(have));
		field = 0;
		
		for (int i = 0; i < str.size(); i++){
			int p = i % n;
			if (str[i] == 'M') have[p]++;
			else if (str[i] == 'S'){
				field += 1 + have[p];
				have[p] = 0;
			}
			else {
				have[p] += 1 + field;
				field = 0;
			}
		}
		
		sort(have, have + n);
		for (int i = 0; i < n; i++){
			printf("%d ", have[i]);
		}
		printf("%d\n", field);
	}
}

Measured memory_bytes: 1216
/*
貪欲
後ろから見る
DP
順位表をチェック
二分探索


*/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
#include<set>
using namespace std;
#define INF 1100000000000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
//typedef pair<int,int> P;
//typedef pair< pair<int,int>,pair<int,int> > p;
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());

//https://betrue12.hateblo.jp/entry/2018/07/15/010448

//計算量はO(log max(a,b))
ll gcd(ll x,ll y){
  ll mindata,maxdata;
  mindata=min(x,y);
  maxdata=max(x,y);
  while(maxdata%mindata!=0){
    ll temp;
    temp=maxdata%mindata;
    maxdata=mindata;
    mindata=temp;
  }
  return mindata;
}


int main(){
    int T;
    cin>>T;
    while(T--){
        ll A,B,C,D;
        cin>>A>>B>>C>>D;
        if(A<B || D<B) cout<<"No"<<endl;
        else if(C>=B-1) cout<<"Yes"<<endl;
        else{
            ll g=gcd(B,D);
            A=A%B;
            ll t=C/g*g+A%g;
            if(t>C && t<B) cout<<"No"<<endl;
            else if(t+g<B) cout<<"No"<<endl;
            else cout<<"Yes"<<endl;
        }
    }
}


Measured memory_bytes: 256
def count_i(i, k):
    sum_num = i
    counter = 0
    while k > sum_num:
        sum_num *= 2
        counter += 1
    return counter


def main():
    n, k = [int(e) for e in input().split()]
    prob_sum = 0
    for i in range(1, n+1):
        prob = 1 / n * (1 / 2) ** count_i(i, k)
        prob_sum += prob
    print(prob_sum)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    lli n, a;
    cin >> n >> a;
    vector<lli> x(n);
    REP(i, 0, n) {
        cin >> x[i];
    }
    sort(begin(x), end(x));
    REP(i, 0, n) {
        a -= x[i];
        if (a < 0) {
            cout << i << endl;
            return 0;
        }
    }
    if (a != 0) {
        n--;
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sp ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define cps CLOCKS_PER_SEC
#define mod (int)(1000000007)
#define f first
#define s second
#define debug1(x) cerr<<x<<"\n"
#define debug2(x,y) cerr<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cerr<<x<<" "<<y<<" "<<z<<"\n"
#define nl cerr<<"\n";
#define pq priority_queue
#define inf 9999999999999999
#define test cerr<<"abcd\n";
#define pi pair<int,int>
#define pii pair<int,pi>
#define pb push_back
#define mxn 4015
#define mxnn 2000005
int black[mxn][mxn],white[mxn][mxn],bpos[mxn],wpos[mxn],dp[mxn][mxn];
int32_t main(){
sp;
int n,k,q;
cin >>n >>k >>q;
int arr[n+1];
for(int i = 1;i<=n;i++) cin >>arr[i];
int mx = 0,mn = inf;
for(int i = 1;i<=n;i++){
    mx = max(mx,arr[i]);
    mn = min(mn,arr[i]);
}
int ans = inf;
for(int y = 1; y<=n;y++){
    int x = arr[y];
    vector<vector<int> >v;
    int i = 1;
    while(i<=n){
            vector<int>a;
        while(i<=n&&arr[i]>=x){
            a.pb(arr[i]);
            i++;
        }
        v.pb(a);
        i++;
    }
    vector<int>c;
    for(int i = 0;i<v.size();i++){
        sort(v[i].begin(),v[i].end());
        vector<int>p;
        if(v[i].size()>=k){
            for(int j = 0;j<=v[i].size()-k;j++){
                c.pb(v[i][j]);
            }
        }
    }
    sort(c.begin(),c.end());
    if(c.size()>=q){
        int mxx = 0;
        for(int i = 0;i<q;i++) mxx = max(mxx,c[i]);
        ans = min(ans,mxx-x);
    }
}
cout<<ans;
return 0;
}


Measured memory_bytes: 384