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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

int main(){
    ll N, K;
    cin >> N >> K;
    vector<pair<int, int>>a(N);
    REP(i, N){
        cin >> a.at(i).first >> a.at(i).second;
    }
    sort(all(a));
    REP(i, N){
        K -= a.at(i).second;
        if(K <= 0) {
            print(a.at(i).first);
            return 0;
        }
    }
}


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

const int N = (int) 2e5 + 10;
const int inf = (int) 2e9;

int arr[N], n, tree[3 * N];

void build(int node, int b, int e) {
    if (b == e) {
        tree[node] = arr[b];
        return;
    }
    int lft = 2 * node, rt = lft + 1, mid = (b + e) / 2;
    build(lft, b, mid);
    build(rt, mid + 1, e);
    tree[node] = __gcd(tree[lft], tree[rt]);
}

int query(int node, int b, int e, int i, int j) {
    if (e < i || b > j) return 0;
    if (b >= i && e <= j) return tree[node];
    int lft = 2 * node, rt = lft + 1, mid = (b + e) / 2;
    int p = query(lft, b, mid, i, j);
    int q = query(rt, mid + 1, e, i, j);
    return (__gcd(p, q));
}

int solve(int l, int r) {
    if (l > r) return 0;
    return query(1, 1, n, l, r);
}

int main() {
//    freopen("in.txt", "r", stdin);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &arr[i]);
    }
    build(1, 1, n);
    int answer = tree[1];
    for (int i = 1; i <= n; i++) {
        answer = max(answer, __gcd(solve(1, i - 1), solve(i + 1, n)));
    }
    printf("%d\n",answer);
    return 0 ;
}


Measured memory_bytes: 1664
flag = 0
n = int(input())
s = [input() for i in range(n)]
if len(set(s)) != n:
    flag = 1
for i in range(n-1):
    if s[i][-1] != s[i+1][0] :
        flag = 1
if flag == 1:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 3060
import math
n,m=map(int,input().split())
mod=10**9+7

if abs(n-m)>1:
    print(0)
    quit()

ans=0
if n==m:
    ans=2*math.factorial(n)*math.factorial(n)
else:
    ans=math.factorial(n)*math.factorial(m)
print(ans%mod)

Measured memory_bytes: 54768
#include <stdio.h>
#include <stdlib.h>

int main(){
	int N, i;
	double ans = 0;
	scanf("%d", &N);
	double *d1 = (double *)malloc(sizeof(double) * (N + 1));
	double *x = (double *)malloc(sizeof(double) * (N + 1));
	scanf("%lf%lf", &d1[N], &x[N]);
	for(i = N; i > 1; i--){
		d1[i - 1] = (2 * (i + 1) * d1[i] + 5 * x[i]) / (2 * i);
		x[i - 1] = ((i + 2) * x[i]) / i;
	}
	for(i = 1; i <= N; i++){
		ans += d1[i] + ((2 * i - 1) * x[i]) / 2;
	}
	printf("%.12lf\n", ans);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vl a(n-1);
    rep(i,n-1) cin >> a[i];
    vl ans(n);
    rep(i,n-1){
        ans[--a[i]]++;
    }
    rep(i,n){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 6364
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

double yosupot(double a, double b)
{
	return sqrt(a * a + b * b);
}

bool isok(double a, double b, double c, double r)
{
	double B = acos((a * a + c * c - b * b) / (2 * a * c));
	double A = acos((b * b + c * c - a * a) / (2 * b * c));
	return 2 * r + r / tan(A / 2) + r / tan(B / 2) <= c;
}

double solve(double a, double b, double c)
{
	double left = 0, right = 2000;
	for (int i = 0; i < 60; ++i) {
		double mid = (left + right) / 2;
		if (isok(a, b, c, mid)) {
			left = mid;
		} else {
			right = mid;
		}
	}
	return (left + right) / 2;
}

int main()
{
	int a, b, c, d, e, f;
	scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
	double u = yosupot(a - c, b - d), v = yosupot(c - e, d - f), w = yosupot(e - a, f - b);
	double ret = 0;
	ret = max(ret, solve(u, v, w));
	ret = max(ret, solve(v, w, u));
	ret = max(ret, solve(w, u, v));
	printf("%.10f\n", ret);

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<LL, int> PLL;
typedef vector<int> VI;
const LL MOD = 1000000007LL;

int main() {
	int N, P;
	cin >> N >> P;
	int even = 0;
	rep(i, N) {
		int A;
		cin >> A;
		if (A % 2 == 0) even++;
	}
	if (even == N) {
		if (P) cout << 0 << endl;
		else cout << (1LL << N) << endl;
	}
	else {
		cout << (1LL << (N - 1)) << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>

using namespace std;

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mis map<int,string>
#define msi map<string,int>
#define mll map<ll,ll>
#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 all(c) c.begin(),c.end()
#define srta(a) sort(all(a))
#define srtd(a) sort(all(a),greater<ll>())
#define rvs(s) reverse(all(s))
#define psb push_back
#define ppb pop_back
#define isu isupper
#define isl islower
#define lb(a,k) lower_bound(all(a),k)
#define ub(a,k) upper_bound(all(a),k)
#define bs(a,k) binary_search(all(a),k)

const int I_INF = 1001001001;
const ll LL_INF = 1001001001001001001;
const ld EPS = 0.001;



int main() {
    ll N;
    cin >> N;
    vl a(N);
    rep (i, N) cin >> a[i];

    srtd(a);
    ll ans = 0, cnt = 0, cur = 0;
    rep (i, N-1) {
        if (i == 0) {
            ans += a[i];
        } else {
            cnt++;
            if (cnt == 2) {
                ans += a[cur];
                cnt = 0, cur++;
            } else {
                cur = cur == 0 ? i : cur;
                ans += a[cur];
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4824
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int r; cin >> r;
    cout << 2 * r * 3.14159265358979323846;
    cout << endl;
    return 0;
}

Measured memory_bytes: 3780
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println(a/b);
		System.out.println(a%b);
		System.out.printf("%f\n", (double)a/b);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 26476
#include<iostream>
#include<cmath>
#include<numeric>
#include<string>
#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++)
#define int64 long long
#define yokuwaruprime (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int a[3],b[3],c[3];
  rep(i,3){
    cin>>a[i]>>b[i]>>c[i];
  }
  int shingi=1;
  rep(i,2){
    if(a[i+1]-a[i]!=b[i+1]-b[i] || b[i+1]-b[i]!=c[i+1]-c[i]){
      shingi=0;
    }
  }
  if(shingi){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    ll A, V, B, W, T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;
    ll d1 = abs(A - B);
    ll d2 = max(V - W, 0LL) * T;
    if (d2 >= d1) {
        cout << "YES" << endl;
    } else {
        cout << "NO\n";
    }
}


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

int main(){
  int n,k;
  cin >> n;
  string s;
  cin >> s;
  cin >> k;
  int moji=s[k-1];
  for(int i=0;i<n;++i){
    if(s[i]==moji){
      cout << s[i];
    }else{
      cout << '*';
    }
  }
  cout << endl;
  return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    int C[M];
    for (int i = 0; i < M; ++i) cin >> C[i];

    int ans[N + 1];
    ans[0] = 0;
    ans[1] = 1;
    for (int i = 2; i <= N; ++i) {
        int mini = N + 1;
        for (int j = 0; j < M; ++j) {
            if (C[j] <= i) {
                int tmp = 1 + ans[i - C[j]];
                mini = (tmp >= mini)? mini : tmp;
            }
        }
        ans[i] = mini;
    }

    cout << ans[N] << endl;
    
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	while(cin >> n) {
		int ret = 0;
		for(int i = 0; i < 10; i++) {
			for(int j = 0; j < 10; j++) {
				for(int k = 0; k < 10; k++) {
					for(int l = 0; l < 10; l++) {
						if(i + j + k + l == n) ret++;
					}
				}
			}
		}
		cout << ret << endl;
	}
	return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

#define MAX_N 100000

bool IsPrime(ll num) {
    if (num < 2) {
        return false;
    } else if (num == 2) {
        return true;
    } else if (num % 2 == 0) {
        return false;
    }

    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i+=2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll Q;
    cin >> Q;

    vector<ll> a(MAX_N, 0);
    for (ll i = 0; i <= MAX_N; i++) {
        if (IsPrime(i) && IsPrime((i+1)/2)) {
            a[i] = 1;
        } else {
            a[i] = 0;
        }
    }

    vector<ll> s(MAX_N+1, 0);
    for (ll i = 0; i <= MAX_N+1; i++) {
        s[i+1] = s[i] + a[i];
    }

    rep (i, Q) {
        ll l, r;
        cin >> l >> r;
        cout << s[r+1] - s[l] << endl;
    }

    return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 1e5 + 7;
int n;
int V[N], a[N];
int main() {
#ifndef ONLINE_JUDGE
#endif
	n = gi();
	rep(i, 1, n) a[i] = V[i] = gi();
	sort(V + 1, V + 1 + n);
	rep(i, 1, n) a[i] = lower_bound(V + 1, V + 1 + n, a[i]) - V;
	int ans = 0;
	rep(i, 1, n) if(abs(a[i] - i) & 1) ++ans;
	printf("%d\n", ans / 2 + (ans & 1));
	return 0;
}

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

int main() {
    string S, T;
    cin >> S >> T;

    bool flag = false;
    for (int i=0; i<S.size(); ++i) {
        string S_;
        for (int j=1; j<S.size(); ++j) {
            S_ += S[j];
        }
        S_ += S[0];
        if (S_ == T) {
            flag = true;
            break;
        } else {
            S = S_;
            S_ = "";
        }
    }

    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}




Measured memory_bytes: 256
from scipy.misc import comb

n, k = tuple(map(int, input().split(' ')))
for i in range(1, k+1):
    # 青玉k個をi個の群に分割する。これはk個の青玉の間のk-1箇所のいずれかからi-1個を選んで仕切りとすることで可能
    # これはk-1Ci-1
    # その上で、できたi個の群の前後i+1箇所に赤玉を埋めていく
    # はじめに、i個の群の内側であるi-1箇所には必ず1つ以上赤玉が存在しなければならないので、予めi-1個の赤玉を配置したものとみなす
    # 結局、n-k-(i-1)=n-k-i+1個の赤玉をi+1箇所のどこかにおいていくことと同値
    # これはn-k-i+1個の赤玉とi個の仕切りの並べ方であるので、(n-k+1)Ci
    # 以上より、求める答えはk-1Ci-1 * (n-k+1)Ci
    s = comb(k-1, i-1, exact=True) * comb(n-k+1, i, exact=True)
    print(int(s) % (10 ** 9 + 7))
    

Measured memory_bytes: 13560
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int *a=new int[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int t,f1=1;
    for(int i=0;i<n;i++){
    	if(a[i]==1){t=i;
    	f1=0;
    	break;
		}
	}
	if(f1==0){
		int count=1,temp=1;
		for(int i=t;i<n;i++){
			if(a[i]==temp+1){
				count++;
				temp++;
			}
		}
		cout<<n-count;
	}
	else cout<<-1;
	return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
//B - Trained?
int main() {
  int n;
  cin >> n;
  
  vector<int> btns(n);
  for(int i = 0; i < n; i++){ cin >> btns.at(i); }
  
  int indx = -1, count = 1;
  for (int i = 0; i < n; i++){
    if(i==0) indx = 0;
    else     indx = btns.at(indx) - 1;
      
    //cout << indx << " " << btns.at(indx) << endl;
    
    if( btns.at(indx) == 2)
      break;
    else
      count++;
  }
  
  if(n < count)
    cout << -1 << endl;
  else
    cout << count << endl;
}


Measured memory_bytes: 640
s=input()
t=input()
u='UNRESTORABLE'
a=[]
if len(s)>=len(t):
  for i in range(len(s)-len(t)+1):
    f=0
    for j in range(i,i+len(t)):
      if s[j]!='?' and s[j]!=t[j-i]:
        f=1
    if f==0:
      m=s[:i]+t+s[i+len(t):]
      m=m.replace('?','a',50)
      a.append(m)
if len(a)==0:
  print(u)
else:
  a.sort()
  print(a[0])

Measured memory_bytes: 3064
/******************************************************************************
 
рассвет. 
 
*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define all(a) (a).begin(),(a).end()
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define pll pair <lli,lli> 
#define vplli vector <pair <lli,lli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (int i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (lli i = a; i < (n); ++i)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
 
const lli MOD=1e9+7;
const lli MAXN=1e7+1;
const lli INF=2e18;
const ld PI=acos(-1);
 
int main(){
    rapgame
    //freopen("brokeday.in", "r", stdin);
    //freopen("richday.out", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        readll(n);
        lli ans=0;
        frbig(i,n){
            lli k=n/(i+1);
            ans+=(i+1)*((k*(k+1)/2));
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 3608
def main():
    n, q = map(int, input().split())
    s = list(input())
    pos = [[int(i)-1 for i in input().split()] for _ in range(q)]

    s = ['a' if s[i] == 'A' and s[i+1] == 'C' else s[i]
         for i in range(n-1)] + [s[n-1]]
    dp = [0] * n
    for i in range(n-1)[::-1]:
        dp[i] = dp[i+1]
        if s[i] == 'a':
            dp[i] += 1
    for l, r in pos:
        print(dp[l] - dp[r])


main()


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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<int> dp(n);
    dp[n-1] = 0;
    dp[n-2] = abs(h[n-1] - h[n-2]);

    if(n >= 3){
        for(int i=n-3;i>=0;i--){
            dp[i] = min(abs(h[i] - h[i+1])+dp[i+1], abs(h[i] - h[i+2])+dp[i+2]);
        }
    }

    cout << dp[0] << endl;

    return 0;
}

Measured memory_bytes: 1024
n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
def f(x,y,z):
    return x**2 + y**2 +z**2 +x*y+y*z+z*x
dic={}
for i in range(1,n+1):
    dic[i]=0
for x in range(1,101):
    for y in range(1,100):
        for z in range(1,100):
            if f(x,y,z)<=n:
                dic[f(x,y,z)]=dic.get(f(x,y,z),0)+1
for i in range(1,n+1):
    print(dic[i])

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll ;

const ll inf = 1e18 + 17;
const int maxn = 1e5 + 10;
const int maxq = 1e2 + 10;
const int alf = 26;
const ll dlm = 1e9 + 7;
const int del = 998244353 ;
const int eps = 1e-7 ;

vector<int> g[maxn];
vector<int> vr[maxn];
int mark[maxn];
vector<pair<int,int> > f;
//          -f   vertex
int dp[maxn];

int cnt = 0;
int dfs(int v){
    mark[v] = 1;
    for(int i=0;i<g[v].size();i++){
        int u = g[v][i] ;
        if(mark[u]==1)continue;
        dfs(u);
    }
    cnt++;
    f.push_back({-cnt,v});
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int v,u;
        cin>>v>>u;
        g[v].push_back(u);
        vr[u].push_back(v);
    }
    for(int i=1;i<=n;i++){
        if(mark[i]==1)continue;
        dfs(i);
    }
    sort(f.begin(),f.end());
    int ans = 0;
    for(int i=0;i<f.size();i++){
        int v = f[i].second;
        for(int j = 0;j<vr[v].size();j++){
            int u = vr[v][j];
            dp[v] = max(dp[v],dp[u]+1);
            ans = max(ans,dp[v]);
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 15608
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h,w,k;
	cin >> h >> w >> k;
	vector<string> mas(h);
	vector<vector<int> > ans(h,vector<int>(w));
	vector<bool> nothing(h);
	int sp = INF;
	rep(i,h){
		bool flg = false;
		cin >> mas[i];
		rep(j,w){
			if(mas[i][j] == '#') flg = true;
		}
		if(!flg){
			nothing[i] = true;
		}
		else chmin(sp,i);
	}
	for(int i = sp;i < h;++i){
		bool flg = false;
		rep(j,w){
			if(nothing[i]){
				ans[i][j] = ans[i-1][j];
			}
			else{
				if(mas[i][j] == '#'){
					if(flg) --k;
					else flg = true;
				}
				ans[i][j] = k;
				if(j == w-1) --k;
			}
		}
	}
	for(int i = sp-1;i >= 0;--i){
		rep(j,w){
			ans[i][j] = ans[i+1][j];
		}
	}
	rep(i,h){
		rep(j,w){
			cout << (j == 0 ? "" : " ") << ans[i][j];
		}
		cout << '\n';
	}

	return 0;
}



Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll x,ll y){
    ll r;
    while((r=x%y) !=0){
        x=y;
        y=r;
    }
    return y;
}

ll lcm(ll x, ll y){
    x /= gcd(x,y);
    y /=gcd(x,y);
    return (x*y);
}

bool prime(int n){
    if(n<=1) return false;
    for(int i=2;i*i<n;i++){
        if(n%i==0) return false;
    }
    return true;
}

int main(){
    int x,y;
    cin >> x;
    y=x;
    while(!prime(y)){
        y+=1;
    }
    cout << y << endl;
    return 0;
}

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

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

    int flag = 1,num=0;
    while(flag){
        flag = 0;
        for(int j=n-1;j>0;j--){
            if(a[j]<a[j-1]){
                swap(a[j],a[j-1]);
                num++;
                flag=1;
            }
        }
    }
    rep(i,n){
        cout << a[i];
        if(i<n-1) cout << " ";
    }
    cout << endl << num <<endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

int MOD=1e9+7;
ll INF=1e18;

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

int d[110][110];
int pre[110][110];

void warshall_floyd(int n){
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            pre[i][j] = i;
        }
    }

	for(int k=0; k<n; k++){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
                if(d[i][j] > d[i][k] + d[k][j]){
				    d[i][j] = d[i][k] + d[k][j];
                    pre[i][j] = pre[k][j];
                }
			}
		}
	}
}

int main(){
    int n, m; cin>>n>>m;

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(i == j) d[i][j]=0;
            else d[i][j]=MOD;
        }
    }

    for(int i=0; i<m; i++){
        int a, b, c; cin>>a>>b>>c;
        a--, b--;
        d[a][b]=c;
        d[b][a]=c;
    }

    bool visited[110][110];
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(d[i][j] == 0 || d[i][j] == MOD) visited[i][j]=true;
            else visited[i][j]=false;
            //cout << d[i][j] << " ";
        }
        //cout << endl;
    }

    warshall_floyd(n);

    for(int s=0; s<n; s++){
        for(int g=0; g<n; g++){
            if(s == g) continue;

            int save[110];
            int i=0;
            for(int cur=g; cur!=s; cur=pre[s][cur]){
                save[i]=cur;
                i++;
                //cout << cur << " ";
            }
            //cout << s << endl;
            save[i]=s;

            for(int j=0; j<i; j++){
                visited[save[j]][save[j+1]]=true;
                visited[save[j+1]][save[j]]=true;
            }
        }
    }

    int cnt=0;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(!visited[i][j]) cnt++;
        }
    }
    cout << cnt / 2 << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    if(b==1) {
        cout<<0<<"\n";
    }
    else {
        int count=1;
        int temp=a;
        while(temp<b) {
            temp+=(a-1);
            count++;
        }
        cout<<count<<"\n";
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define PI (long double)3.1415926535

int main(){
    FAST
    double r; cin >> r;
    cout << setprecision(20) << 2*PI*r;
    return 0;
}


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key,vi a) {
    int left = -1;
    int right = (int)a.size();
    while (right - left > 1) {
        int mid = left + (right - left) / 2;
        
        if (isOK(mid, key,a)) right = mid;
        else left = mid;
    }
    return right;
}

int modpow(int a,int b,int p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,c,k;
    cin >> n >> c >> k;
    vi t(n);
    rp(i,n){
        cin >> t[i];
    }
    sort(t);
    int ans=0;
    rp(i,n){
        int p=upper_bound(t.begin(),t.end(),t[i]+k)-t.begin();
        if(p>=i+c){
            i=i+c-1;
            ans++;
        }else{
            i=p-1;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, K = map(int, input().split())
    have = [0]*N
    for _ in range(K):
        d = int(input())
        A = list(map(int, input().split()))
        for a in A:
            have[a-1]=1
    print(N-sum(have))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9196
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	int a, b;
	char x;
	cin >> a >> x >> b;
	if(x == '+') cout << a + b << endl;
	else cout << a - b << endl;
	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 int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

// 2^n
mint f(int n){
	if(n == 0) return 1;
	mint x = f(n/2);
	x *= x;
	if(n%2 == 1) x *= 2;
	return x;
}

// nCa
mint choose(int n, int a){
	mint x = 1, y = 1;
	rep(i,a){
		x *= n-i;
		y *= i+1;
	}
	return x / y;
}

struct Combination{
	vector<mint> fact, ifact;
	Combination(int n):fact(n+1),ifact(n+1){
		assert(n < mod);
		fact[0] = 1;
		for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
		ifact[n] = fact[n].inv();
		for(int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
	}
	mint operator()(int n, int k){
		if(k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
};

int loc[100005];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	Combination comb(n+1);
	memset(loc, -1, sizeof(loc));
	int p1 = -1, p2 = -1;
	rep(i,n+1){
		int a;
		cin >> a;
		if(loc[a] == -1) loc[a] = i;
		else{
			p1 = loc[a];
			p2 = i;
		}
	}
	for(int k = 1; k <= n+1; ++k){
		mint ans = comb(n+1, k) - comb(n-p2+p1, k-1);
		cout << ans.x << endl;
	}
	return 0;
}


Measured memory_bytes: 5228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Piont;

int arr[200000+10];
void inite(){
	for (int i = 0; i < 200000+10; ++i){
		arr[i] = i;
	}
}

int find(int idx){
	return arr[idx]==idx?idx:arr[idx] = find(arr[idx]);
}
bool merge(int a, int b){
	int x = find(a);
	int y = find(b);
	arr[x] = y;
	return x!=y;
}

main(){
	ios::sync_with_stdio(false);
	ll a,v,b,w,t;
	while(cin>>a>>v>>b>>w>>t){
		bool ans = abs(a-b) <= (v-w)*t;
		cout << (ans?"YES":"NO") << endl;
	}
}


Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;
#define mod 1000000007;

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

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

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <sstream>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define SZ(x) (int)(x.size())
#define F0(i,n) for(int i=0;i<n;i++)
#define F1(i,n) for(int i=1;i<=n;i++)
#define CL(a,x) memset(x, a, sizeof(x));
#define P(x) cerr << #x << "=" << x << endl

const int MOD = 1000002013;
const double pi = atan(1.0)*4.0;
const double eps = 1e-8;
ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x; }
int bc(int n) { return n ? bc((n-1)&n)+1 : 0; }

int i, j, k, m, n, l;
int a[200001], pos[200001];


int main() {
    //freopen("x.in", "r", stdin);

    while (cin >> n) {
        F1(i, n) { cin >> a[i]; pos[a[i]] = i; }
        int last = -1;
        int ans = 0;
        int cnt = 0;
        F1(i, n) if (pos[i] > last) {
            cnt++;
            ans = max(ans, cnt);
            last = pos[i];
        } else {
            cnt = 1;
            ans = max(ans, cnt);
            last = pos[i];
        }

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


Measured memory_bytes: 1792
N,W=map(int,input().split())
taple=[]
for i in range(N):
    w,v=map(int,input().split())
    taple.append((w,v))
dp=[[10**22]*(N*(10**3)+1) for i in range(N+1)]
dp[0][0]=0
for i in range(1,N+1):
    w,v=taple[i-1]
    for j in range(N*(10**3)+1):
        if j>=v:
            dp[i][j]=min(dp[i-1][j-v]+w,dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
for i in range(N*(10**3),-1,-1):
    if dp[N][i]<=W:
        print(i)
        break


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    int n;
    cin >> n;
    int num = sqrt(n);

    // 処理
    cout << num * num << endl;

    // 出力

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    int A,B;
    cin >> A >> B;
    cout << max(A-B, max(A+B, A*B)) << endl;
}

Measured memory_bytes: 256
import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n, m;
    readf("%s %s", &n, &m);
    readln;

    Tuple!(int, int)[] jobs;
    foreach (_; 0 .. n) {
        int a, b;
        readf("%s %s", &a, &b);
        readln;
        
        jobs ~= tuple(a, b);
    }
    
    auto rbt = make!(RedBlackTree!(int, "a < b", true));
    
    jobs.sort();
    
    debug { jobs.writeln; }
    
    long ans = 0;
    int j = 0;
    foreach (d; (m+1).iota.dropOne) {
        while (j < n && jobs[j][0] <= d) {
            rbt.insert(jobs[j][1]);
            ++j;
        }
       
        if (!rbt.empty()) {
            ans += rbt.back();
            rbt.removeBack();
        }
    }
    
    ans.writeln;
}

Measured memory_bytes: 8060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=105;
ll d[N][N],f[N][N],e[N][N],ifa[N];
ll expo(ll a,int b,ll p){
    ll c=1ll;
    while(b){
        if(b&1)c=c*a%p;
        b>>=1; a=a*a%p;
    }
    return c;
}
int main(){
    ll w=1ll,ww,p;
    int n,m,q,K,k,t,i,j,h;
    scanf("%d%d%d%lld",&n,&m,&q,&p);t=n<m?m:n;
    for(i=1;i<=t;++i)w=w*i%p;
    ifa[t]=w=expo(w,p-2ll,p);
    for(i=t;i;--i)ifa[i-1]=w=w*i%p;
    for(i=1;i<=q;++i){
        e[i][0]=w=1ll;
        for(j=1;j<=t;++j)e[i][j]=w=w*i%p;
    }
    for(i=1;i<=q;++i){
        for(j=1;j<=t;++j)if((f[i][j]=e[i][j]-e[i-1][j])<0ll)f[i][j]+=p;
    }
    d[0][0]=1ll;
    for(k=1,K=q;K;++k,--K){
        for(j=0;j<=m;++j){
            w=e[K][j]*f[k][m-j]%p;
//          printf("j=%d w=%lld\n",j,w);
            for(i=n-1;~i;--i){
                ww=d[i][j];
                for(h=i+1;h<=n;++h){
                    ww=ww*w%p;
                    d[h][j]=(d[h][j]+ww*ifa[h-i])%p;
                }
            }
        }
        /*
        printf("\nk=%d K=%d\n",k,K);
        for(i=0;i<=n;++i){
            for(j=0;j<=m;++j){
                printf("%d ",d[i][j]);
            }
            printf("\n");
        }*/
        for(i=0;i<=n;++i){
            w=f[K][i]*e[k][n-i]%p;
            for(j=m-1;~j;--j){
                ww=d[i][j];
                for(h=j+1;h<=m;++h){
                    ww=ww*w%p;
                    d[i][h]=(d[i][h]+ww*ifa[h-j])%p;
                }
            }
        }
        /*
        printf("\nk=%d K=%d\n",k,K);
        for(i=0;i<=n;++i){
            for(j=0;j<=m;++j){
                printf("%d ",d[i][j]);
            }
            printf("\n");
        }*/
    }
    w=d[n][m];
    for(i=1;i<=n;++i)w=w*i%p;
    for(i=1;i<=m;++i)w=w*i%p;
    printf("%lld",w);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define sz(v) (ll)v.size()
using namespace std;

ll MOD=1e9+7;
ll g,h,l;
const ll N=100005;

ll add(ll a,ll b); ll mul(ll a,ll b); ll binpo(ll a,ll b);

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    float n,m;
    cin>>n>>m;
    vector<float> v(n);
    float sum=0;
    repn(i,n){
        cin>>v[i];
        sum+=v[i];
    }
    sort(all(v));
    reverse(all(v));
    if(v[m-1]<sum/(4.0*m)){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
}

ll add(ll a,ll b)
{
    return (a%MOD+b%MOD)%MOD ;
}
ll mul(ll a,ll b)
{
    return (a* 1ll *b)%MOD ;
}
ll binpo(ll a,ll b)
{
    int ans = 1 ;
    while(b)
    {
        if( b % 2 != 0)
        {
            ans = mul(ans,a);
        }
        a = mul(a,a);
        b = b/2;
    }
    return ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for (ll i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (ll i = (begin)-1; i >= (end); i--)
#define IREP(i, n) IFOR(i, n, 0)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(), greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v)                                                              \
  cout << #v << "=(" << v[0];                                                  \
  FOR(i_debug, 1, v.size()) { cout << "," << v[i_debug]; }                     \
  cout << ")" << endl;
#define mdebug(m)                                                              \
  cout << #m << "=" << endl;                                                   \
  REP(i_debug, m.size()) {                                                     \
    REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; }    \
    cout << endl;                                                              \
  }
#define Lower_bound(v, x)                                                      \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x)                                                      \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
// #define f first
// #define s second
#define mp make_pair
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;

template <typename T> void readv(vector<T> &a) { REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a) {
  REP(i, a.size()) {
    cin >> a[i];
    a[i]--;
  }
}

ll mod = 1000000007;

int main() {
  ll A, B, C, K;

  cin >> A >> B >> C >> K;

  ll ans = 0;
  if (K <= A + B) {
    ans = min(K, A);
  }

  else {
    ans = A - (K - A - B);
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
	llong N, A, B;
	cin >> N >> A >> B;

	if ((B - A) % 2 == 0) {
		cout << (B - A)/2 << endl;
	}
	else {
		cout << min(A + (B - A - 1)/2, (N - B + 1) + (B - A - 1)/2) << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String t = sc.nextLine();
        int n = s.length();
        
        s = s + t.charAt(n);
        
        // System.out.println(s+" "+t);
        
        if(s.equals(t)){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
        
    }
    
}

Measured memory_bytes: 38976
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int main(){
  long long int A;
  cin >> A;
  long long int num1 = A/11;
  int num2 = A%11;
  if(num2>6) num1 = num1*2 + 2;
  else if(num2>0)num1 = num1*2 +1;
  else num1 = num1*2;
  cout << num1 << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cctype>
#include <utility>
#include <string>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	string s, b;
	for (int n; (n = in());) {
		scan(s);
		while (n--) {
			b = "";
			char p = ' ';
			int q = 0;
			for (char c: s) {
				if (c == p)
					q++;
				else {
					if (q)
						b += to_string(q) + p;
					q = 1;
					p = c;
				}
			}
			if (q)
				b += to_string(q) + p;
			s = b;
		}
		outl(s);
	}
}


Measured memory_bytes: 2688
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    T = SI()
    print(T.replace('?','D'))

if __name__ == '__main__':
    main()

Measured memory_bytes: 75864
##愚直に組合せを計算すると、O(N^3）になるので、1番目の条件を満たして、
##2番目を満たないものを除算する方式をとる
n = int(input())
s = list(input())
##総数を計算
ans = s.count("R")*s.count("G")*s.count("B")
#(i,j)を固定してkを算出
for i in range(n):
    for j in range(i+1,n):
        k = 2*j - i
        ##indexはn-1までなのでkがn以上になるとbreak
        if k >= n:
           break
        ##kは2番目の条件を満たしていないものであるので、ここで条件1番が満たされているかをチェック
        if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
          ans -= 1
       ##満たされていればこれは1番目を満たし、2番目を満たしていないものとなる　　　
print(ans)

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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long a;

    cin >> a;

    long long b;

    cin >> b;

    long long c;

    cin >> c;

    swap(a,b);

    swap(a,c);

    cout << a << ' ' << b << ' ' << c << '\n';

    return 0;

}



Measured memory_bytes: 3636