akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
 
typedef long long ll;
typedef pair<int, int> ii;
 
int main(){

	int n;
	cin >> n;
	rep(i, n){
		double x1, y1, x2, y2, x3, y3;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		double vx21, vx31, vy21, vy31, tmp1, tmp2;
		vx21 = 2 * (x1 - x2);
		vx31 = 2 * (x1 - x3);
		vy21 = 2 * (y1 - y2);
		vy31 = 2 * (y1 - y3);
		tmp1 = x1 * x1 + y1 * y1 - x2 * x2 - y2 * y2;
		tmp2 = x1 * x1 + y1 * y1 - x3 * x3 - y3 * y3;
		
		double x, y, r;
		x = -(vy21 * tmp2 - vy31 * tmp1) / (vy31 * vx21 - vy21 * vx31);
		y = -(vx21 * tmp2 - vx31 * tmp1) / (vx31 * vy21 - vx21 * vy31);
		r = sqrt((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
		
		printf("%.3lf %.3lf %.3lf\n", x, y, r);
		
	}
 
	return 0;
}

Measured memory_bytes: 3196
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);
const int zero = 12826;

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll a[2222],s[2222];

int main(void){
	int n,i,j;
	ll x,tmp,ans=INFLL;
	cin >> n >> x;
	fill(s,s+n,INFLL);
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	for(j=0; j<n; ++j){
		tmp = x*j;
		for(i=0; i<n; ++i){
			s[i] = min(a[(i-j+n)%n],s[i]);
			tmp += s[i];
		}
		ans = min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <string>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <queue>
#include<iomanip>
#include<bitset>
#include<stack>
#include<set>
#include<limits>
#include <complex>
#include<cstdlib>
using namespace std;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};
struct aUnionFind {
	vector<pair<int, long long int>> data;
	aUnionFind(int size) : data(size, make_pair(-1, 0)) { }
	bool unionSet(int x, int y, long long int w) {
		const int rx(root(x).first), ry(root(y).first);
		if (rx != ry) {
			data[rx].first += data[ry].first; data[ry].first = rx;
			data[ry].second =-data[y].second - w + data[x].second;
		}
		return rx != ry;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	pair<int, int> root(int x) {
		if (data[x].first < 0) {
			return make_pair(x, 0);
		}
		else {
			pair<int, long long int>ndata;
			ndata.first = root(data[x].first).first;
			ndata.second =data[x].second+ root(data[x].first).second;
			return data[x]=ndata;
		}
	}
	int size(int x) {
		return -data[root(x).first].first;
	}
};



int main() {
	while (1) {
		int N, M; cin >> N >> M;
		if (!N)break;
		vector<pair<int,int>>weis(N,make_pair(-1,-1));
		aUnionFind uf(N);
		for (int i = 0; i < M; ++i) {
			char c; cin >> c;
			if (c == '!') {
				int a, b, w; cin >> a >> b >> w;
				a--; b--;
				uf.unionSet(a, b,w);
				
				
			}
			else {
				int a, b; cin >> a >> b;
				a--; b--;
				if (uf.root(a).first == uf.root(b).first) {
					int aa=uf.root(a).second - uf.root(b).second;
					cout << aa << endl;
				}
				else {
					cout << "UNKNOWN" << endl;
				}
			}
		}
	}
	
	return 0;
}

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

#define ll long long
int main()
{
	int n, x, y; cin >> n >> x >> y;
	int d[n]={0};
	for(int i=1; i<=n; ++i){
		for(int j=i+1; j<=n; ++j){
			int v1 = j-i;
			int v2 = abs(x-i)+1+abs(y-j);
			if(i<=y) d[min(v1, v2)]++;
			else d[v1]++;
		}
	}
	for(int i=1; i<n; ++i) cout << d[i] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

int main()
{
        ll N, K;
        cin >> N >> K;
        ll ans = 0;
        if (K == 0) {
                cout << N * N << endl;
                return 0;
        }
        rep(b, 1, N+1) {
                ll t1 = max(0LL, N/b * (b - K));
                ll t2 = max(0LL, N%b - K + 1);
                ans += t1 + t2;
        }
        cout << ans << endl;
}


Measured memory_bytes: 3568
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int get(int x) {
	int ans = 0;
	while (x) {
		ans += x % 10;
		x /= 10;
	}
	return ans;
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	int n;
	cin >> n;
	int ans = 100000;
	for (int a = 1; a < n; ++a) {
		int b = n - a;
		ans = min(ans, get(a) + get(b));
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 256
import math

n, a, b = map(int, input().split())

sum_all = 0
for i in range(1, n + 1):
    sum_n = 0
    m = i
    while(m > 0):
        sum_n += math.floor(m % 10)
        m /= 10
    if a <= sum_n <= b:
        sum_all += i

print(sum_all)

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

class SegmentTree(object):
 
    def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7):
 
        self.seg_func = seg_func
        self.seg_func_null = seg_func_null
        self.n = 1
        while self.n < len(init_array):
            self.n *= 2
        self.dat = [0] * (2 * self.n - 1)
        for i in range(len(init_array)):
            self.dat[self.n - 1 + i] = init_array[i]
        for i in range(self.n - 2, -1, -1):
            self.dat[i] = self.seg_func(self.dat[2 * i + 1], self.dat[2 * i + 2])
 
    def update(self, k, a):
        k += self.n - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = self.seg_func(self.dat[k * 2 + 1], self.dat[k * 2 + 2])
 
    def query(self, p, q):
        # [p, q)
        if q <= p:
            return self.seg_func_null
 
        p += self.n - 1
        q += self.n - 2
        res = self.seg_func_null
 
        while q - p > 1:
            if p & 1 == 0:
                res = self.seg_func(res, self.dat[p])
            if q & 1 == 1:
                res = self.seg_func(res, self.dat[q])
                q -= 1
            p = p // 2
            q = (q-1) // 2
        if p == q:
            res = self.seg_func(res, self.dat[p])
        else:
            res = self.seg_func(self.seg_func(res, self.dat[p]), self.dat[q])
 
        return res

#seg = SegmentTree(L) #RminQ
#seg = SegmentTree(L, max, -1) #RmaxQ
#seg.query(i,j)
#seg.update(i,a)

N = int(input())
XD = [None]*N
for i in range(N):
    X, D = (int(i) for i in input().split())
    XD[i] = (X, D)
XD.sort()

seg = SegmentTree(list(range(N)), max, -1)
L = list(range(N))

import bisect
for i in range(N)[::-1]:
    x, d = XD[i]
    b = bisect.bisect_left(XD, (x+d-0.5, d))-1
    m = seg.query(i,b+1)
    seg.update(i,m)
    L[i] = m

ans = [0]*N
res = 1
for i in range(N)[::-1]:
    if L[i] == i:
        ans[i] = res
        res *= 2
    else:
        ans[i] = ans[L[i]]
        res += ans[i]
    res %= 998244353
print(res)

Measured memory_bytes: 83164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;


int main()
{
	int  A, B, T;
	cin >> A >> B >> T;

	int ans = (T / A) * B; 

	printf("%d", ans);

	return 0;
}



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

int main()
{
  int n,b,f,r,v;
  int people[5][4][11]={0};
  cin >> n;
  
  for(int i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    people[b][f][r] +=v;
  }
  
  for(int i=1;i<=4;i++){
    for(int j=1;j<=3;j++){
      for(int k=1;k<=10;k++){
	if(people[i][j][k]<0){
	  people[i][j][k]=0;
	}
	if(i!=0 && j!=0 && k!=0){
	  cout << " " << people[i][j][k];
	}
      }
      cout << endl;
    }
    if(i!=4){
      cout << "####################" << endl;
    }
  }
  return 0;
}

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

int main() {
  int H,W,K,Z=0;
  cin>>H>>W>>K;
  int A=1;
  for(int i=0;i<H+W;i++){
    A*=2;
  }
  vector<vector<char>> p(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>p[i][j];
    }
  }
  for(int i=0;i<A;i++){
    vector<int> a(H);
    vector<int> b(W);
    for(int j=0;j<H+W;j++){
      if(i&(1<<j)){
        if(j<H){
          a[j]++;
        }
        else{
          b[j-H]++;
        }
      }
    }
    int Q=0;
    for(int j=0;j<H;j++){
      for(int k=0;k<W;k++){
        if(p[j][k]=='#'&&a[j]+b[k]==0){
          Q++;
        }
      }
      
    }
    if(Q==K){
      Z++;
    }
    
  }
  cout<<Z<<endl;
    
}



Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <iomanip>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()


using namespace std;
typedef long long ll;

const ll Inf = (1L << 31) - 1;

class RMQ {
  int n;
  ll *dat;

  ll q(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return Inf;
    if (a <= l && r <= b) return dat[k];
    else {
      ll lhs = q(a, b, k*2+1, l, (l+r)/2);
      ll rhs = q(a, b, k*2+2, (l+r)/2, r);
      return min(lhs, rhs);
    }
  }

 public:

  explicit RMQ(int n_) {
    n = 1;
    while (n < n_) n <<= 1;
    dat = new ll[n*2];
    REP(i,n*2) dat[i] = Inf;
  }

  ~RMQ() { delete[] dat; }

  void update(int k, int a) {
    k += n-1;
    dat[k] = a;
    while (k > 0) {
      k = --k / 2;
      dat[k] = min(dat[k*2+1], dat[k*2+2]);
    }
  }

  // Returns the min value of [a, b)
  ll query(int a, int b) {
    return q(a, b, 0, 0, n);
  }
};


int main(int argc, char *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
    
  int n, q, c, x, y;
  cin >> n >> q;
  RMQ rmq(n);
  REP(i,q){
    cin >> c >> x >> y;
    if (c == 0) {
      rmq.update(x, y);
    } else {
      cout << rmq.query(x, y+1) << '\n';
    }
  }
  cout << flush;

  return 0;
}

Measured memory_bytes: 3108
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, M, H[112345], A[112345], B[112345];
vector<vector<int>> R;

int main() {

	cin >> N >> M;

	R.resize(N);
	rep(i, N) cin >> H[i];
	rep(i, M) cin >> A[i] >> B[i];

	rep(i, M) {
		R[A[i] - 1].push_back(B[i] - 1);
		R[B[i] - 1].push_back(A[i] - 1);
	}

	int ans = 0;
	rep(i, N) {
		bool f = true;
		for (auto r : R[i]) {
			if (H[i] <= H[r]) f = false;
		}
		if (f) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9572
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000



int main(){
	
	int N;
	cin>>N;
	
	string S;
	cin>>S;
	
	int x = 0;
	int ans = 0;
	
	for(int i=0;i<N;i++){
		if(S[i]=='I')x++;
		else x--;
		
		ans = max(ans,x);
	}
	
	cout<<ans<<endl;
	
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define dscf(n) scanf("%lf",&n)
#define lpri(n) printf("%lld ",n)
#define dpri(n) printf("%lf ",n)
#define dprin(n) printf("%lf\n",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;
 
void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

int main()
{
    ll n;
    lscf(n);
    string s;
    cin>>s;
    ll cr=0,cw=0,c=0;
    rep(i,0,n)
    {
        if(s[i]=='R')
        cr++;
        else
        {
            cw++;
        }
    }
    rep(i,0,n-cw)
    if(s[i]=='W')
    c++;
    pri(min(cw,min(cr,c)));
return 0;
}

Measured memory_bytes: 3900
n,m = gets.chomp.split.map(&:to_i)
min,max = 0
ans = 0
l,r = 0,0
m.times do |i|
  l,r = gets.chomp.split.map(&:to_i)
  min = l if min < l
  max = r if i == 0 || max > r
end
ans = max - min + 1 if max >= min
print ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,min,h[100005],dp[100005]={};
  cin>>n>>k;
  for(int i=0; i<n; i++){
    cin>>h[i];
  }


  for(int i=1; i<n; i++){
    min=abs(h[i]-h[i-1])+dp[i-1];
    for(int j=2; j<=k; j++){
      if(i>=j){
	if(min>abs(h[i]-h[i-j])+dp[i-j]){
	  min=abs(h[i]-h[i-j])+dp[i-j];
	}
      }
    }
    dp[i]=min;
  }
  cout<<dp[n-1]<<'\n';
  return 0;
}


Measured memory_bytes: 1024
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    if(a[0] > 0){
        cout << - 1 << endl;
        return 0;
    }

    for(int i = 0; i < n; i++){
        if(i != n - 1){
            if(a[i] < a[i + 1]){
                if(a[i + 1] - a[i] > 1){
                    cout << -1 << endl;
                    return 0;
                }
            }
        }
    }
    ll ans = 0;
    for(int i = 1; i < n; i++){
        if(a[i - 1] + 1 == a[i]){
            ans++;
        } else {
            ans += a[i];
        }

    }
    cout << ans << endl;
    
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int n;
vi a;

int solve(int ave){
  int ans = 0;
  rep(i,n){
    ans += (ave-a[i])*(ave-a[i]);
  }
  return ans;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
int sum = 0;
rep(i,n){
int tmp;
cin >> tmp;
a.push_back(tmp);
sum += tmp;
}
  int ave = sum/n;
  int ans1 = 0;
  int ans2 = 0;
  rep(i,n){
    ans1 += (ave-a[i])*(ave-a[i]);
    ans2 += (ave+1-a[i])*(ave+1-a[i]);
  }
cout << (ans1 > ans2 ? ans2 : ans1) << endl;
	return 0;
}


Measured memory_bytes: 256
# -*- coding utf-8 -*-

N, K = map(int, input().split())
VN = list(map(int, input().split()))

VN = [0] + VN + [0]

score_a = 0
neg_l = []

ans = 0
for a in range(len(VN)):
    l = VN[a]
    score_a += l
    if l < 0:
        neg_l.append(l)

    score_b = 0
    neg_r = []
    for b in range(len(VN)):
        r = VN[N + 1 - b]
        score_b += r
        if r < 0:
            neg_r.append(r)

        if a + b > K or a + b > N:
            break
        else:
            negs = neg_l + neg_r
            negs.sort()
            score_cd = sum(negs[:min(len(negs), K - a - b)])
            score = score_a + score_b - score_cd
            ans = max(ans, score)
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
   int a;
   int b;
   int c;
   scanf("%d", &a);
   scanf("%d", &b);
   scanf("%d", &c);

   if(a < b){
     if(b < c){
       printf("Yes\n");
     }else{
       printf("No\n");
     }
   }else{
     printf("No\n");
   }

   return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define fi first
#define se second
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}
template<class T> void contout(const T &v){for(auto it=v.begin();it!=v.end();++it,cout<<(it!=v.end()?" ":"\n"))cout<<*it;}

void solve(){
  ll n; cin>>n;
  auto A=make_v(n,0),B=A,C=A;
  rep(i,n) cin>>A[i]>>B[i]>>C[i];
  ll a,b,c; a=A[0],b=B[0],c=C[0];
  rep(i,1,n){
    ll newa=0,newb=0,newc=0;
    chmax(newa,max(b,c)+A[i]);
    chmax(newb,max(c,a)+B[i]);
    chmax(newc,max(a,b)+C[i]);
    a=newa,b=newb,c=newc;
  }
  cout<<max(max(a,b),c)<<"\n";
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }
            var line = Console.ReadLine();
            var sa = line.Split(' ');
            int s = int.Parse(sa[0]);
            int w = int.Parse(sa[1]);

            proc(s, w);
        }

        private static void proc(int s, int w)
        {
            Console.WriteLine(s > w ? "safe" : "unsafe");
        }
    }
}


Measured memory_bytes: 27476
X, Y = map(int, input().split())

if (2 * X - Y) % 3 == 0:
    a = int((2 * X - Y) / 3)
else:
    a = 'No'
if (2 * Y - X) % 3 == 0:
    b = int((2 * Y - X) / 3)
else:
    b = 'No'

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

if a == 'No' or a < 0 or b == 'No' or b < 0:
    print(0)
else:
    ans = cmb(a + b, a)
    print(ans % (10 ** 9 + 7))

Measured memory_bytes: 102156
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()

if s == "A":
    print("T")
if s == "T":
    print("A")
if s == "G":
    print("C")
if s == "C":
    print("G")

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n;
  cin>>n;
  int i,j,a[n+1]={0};
for(i=2;i<=n;i++)
{ cin>>j;
  a[j]++;
}
  for(i=1;i<=n;i++)
cout<<a[i]<<'\n';
}


Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    string a,b,c;
    int count=0,ans=-1;
    cin>>a>>b>>c;
    ll i=0,j=0,k=0;
    char ch=a[0];
    
    i++;
    while(i<=a.length()&&j<=b.length()&&k<=c.length())
    {
       count++;
    
       int cc=ch-'a';
       //cout<<ch<<" "<<cc<<endl;

      switch(cc)
      {
        
        case 0 : 
            {
              //cout<<"zero"<<endl;
              ch=a[i];
              i++;
              break;
          }


        case 1 :
           
           {
            ///cout<<"one"<<endl;
            ch=b[j]; 
            j++;
            break;
          }


        case 2 :
           {
            //cout<<"two"<<endl;
            ch=c[k];
            k++;
            break;
          }

      }
    }
    if(i>a.length())cout<<"A"<<endl;
    else if(j>b.length())cout<<"B"<<endl;
    else cout<<"C"<<endl;
}
return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

def main():
    N = II()
    C = []
    for _ in range(N):
        c = II()
        if len(C) == 0 or c != C[-1]:
            C.append(c)
    global ans
    ans = 0
    dp = [1] + [0] * N
    from collections import defaultdict
    cnt_clr = defaultdict(int)
    for i, c in enumerate(C):
        ret = dp[i]
        ret += cnt_clr[c]
        cnt_clr[c] = ret
        dp[i + 1] = ret % MOD

    ans = dp[len(C)]

    return ans % MOD

print(main())

Measured memory_bytes: 31404
#include <stdio.h>

int main(void) {
	int num[5];
	int tmp;
	char buf[256];
	
	fgets(buf, sizeof(buf), stdin);
	sscanf(buf, "%d %d %d %d %d", &num[0], &num[1], &num[2], &num[3], &num[4]);
	
	for (int i=0; i<5-1; i++) {
		for (int j=i+1; j<5; j++) {
			if (num[i] < num[j]) {
				tmp = num[i];
				num[i] = num[j];
				num[j] = tmp;
			}
		}
	}
	
	printf("%d %d %d %d %d\n", num[0], num[1], num[2], num[3], num[4]);
	
	return 0;
}

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

int main() {
	ll a,b;
	cin>>a>>b;
	if(a>=1 && a<=9 && b>=1 && b<=9)
	cout<<a*b;
	else
	cout<<"-1";
	return 0;
}

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

char str[201];
string s[201];


int main()
{
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    int r = 0;
    while(x--) str[r++] = 'a';
    while(y--) str[r++] = 'b';
    while(z--) str[r++] = 'c';

    for(int i = 0; i < r; i++) s[i] += str[i];
    while(r > 1)
    {
        sort(s, s+r);
        s[0] += s[r-1];
        r--;
    }
    cout << s[0] << endl;
    return 0;

}


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

int main() {
int n;
  cin >> n;
  vector<int> p(n);
  for(int i = 0; i<n; ++i){
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  p.at(n-1) /=2;
  int total = 0;
  for(int i= 0;i<n; ++i){
    total += p.at(i);
  }
  cout << total << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int  N; 
    cin>>N;

    
    vector<int> vec(N);
    for (int i = 0; i < N; i++){
        cin >> vec.at(i);
    }

    int a=0;
    int b=0;
       
    sort(vec.begin(),vec.end());//並び替え
    reverse(vec.begin(),vec.end());//おおきい順
     for(int i=0; i<N;i++){
      if(i%2==0){
       a=a+vec.at(i);
    }
      else{
       b=b+vec.at(i);
    }
  }
    cout<<a-b<<endl;
   }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,M,C;cin>>N>>M>>C;
	int A[N][M],B[M];
	for(int i=0;i<M;i++){
		cin>>B[i];
	}for(int j=0;j<N;j++){
		for(int k=0;k<M;k++){
			cin>>A[j][k];
		}
	}int sum,count=0;
	for(int i=0;i<N;i++){
		sum=C;
		for(int j=0;j<M;j++){
			sum+=A[i][j]*B[j];
		}if(sum>0){
			count++;
		}
	}cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

struct elem {
    int a, b, cost;
} V[50];

struct pd {
    int posibil, costminim;
} dp[405][405];

int main() {
   // #ifndef ONLINE_JUDGE
   // freopen("input.txt","r",stdin);
   // #endif // ONLINE_JUDGE

    int N, M1, M2;

    cin >> N >> M1 >> M2;

    for(int i = 1; i <= N; ++i) {
        cin >> V[i].a >> V[i].b >> V[i].cost;
    }

    int mx1 = 0, mx2 = 0;

    dp[0][0].posibil = 1;

    for(int obiect = 1; obiect <= N; ++obiect) {
        for(int i = mx1; i >= 0; --i) {
            for(int j = mx2; j >= 0; --j) {
                if(dp[i][j].posibil) {
                    int na = i + V[obiect].a;
                    int nb = j + V[obiect].b;
                    mx1 = max(mx1, na);
                    mx2 = max(mx2, nb);
                    int cost = V[obiect].cost + dp[i][j].costminim;

                    if(dp[na][nb].posibil == 0) {
                        dp[na][nb].posibil = 1;
                        dp[na][nb].costminim = cost;
                    }
                    else {
                        dp[na][nb].costminim = min(dp[na][nb].costminim, cost);
                    }
                }
            }
        }
    }

    int gasit = 0;
    int ans = 2e9;
    for(int p = 1; p * M1 <= 400 && p * M2 <= 400; ++p) {
        if(dp[p * M1][p * M2].posibil) {
            gasit = 1;
            ans = min(ans, dp[p * M1][p * M2].costminim);
        }
    }

    if(gasit) {
        cout << ans << '\n';
    }
    else {
        cout << -1 << '\n';
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N;
vector<int> A;

int main(){
  cin >> N;
  A.resize(N);
  rep(i,0,N - 1) cin >> A[i];
  cout << *max_element(all(A)) - *min_element(all(A)) << endl;;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  while(1){
    int n ,p;
    cin >> n >> p ;
    if(n==0&&p==0)break;
    int N[50]={0};
    int T;
    T=p;
    int mayor=-1;
    while(1){
      for(int i=0;i<n;i++){
        if(T==0){
          T=N[i];
          N[i]=0;
        }else{
          N[i]++;
          T--;
          if(N[i]==p){
            mayor=i;
            break;
          }
        }
      }
      if(mayor!=-1)break;
    }
    cout << mayor << endl;
  }
}



Measured memory_bytes: 2988
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int n,k;
llong T[MAX];


int check(llong P) {
    int i = 0;
    for ( int j = 0; j < k; j++ ) {
        llong s = 0;
        while( s + T[i] <= P ) {
            s += T[i];
            i++;
            if ( i==n ) return n;
         }
    }
     return i;
}

int solve() {
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while (right - left > 1 ){
        mid = (left + right)/2;
        int v = check(mid); 
        if ( v >= n ) right = mid;
        else left = mid;
    }
    
    return right;
}

int main() {
    cin >> n >> k;
    for ( int i = 0; i < n; i++ ) cin >> T[i];
    llong ans = solve();
    cout << ans << endl;
}


Measured memory_bytes: 3872
#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 n, k;
	cin>>n>>k;
	double ans=0;
	FOR(i, 1, n+1){
		if(i>=k){
			ans+=1/(double)n;
		}
		else{
			double tmp=1/(double)n;
			int now=i;
			while(now<k){
				now*=2;
				tmp/=2;
			}
			ans+=tmp;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Bool (bool)

main :: IO ()
main = do
  n <- readLn
  solve <$> replicateM n getLine >>= putStrLn

solve :: [String] -> String
solve ss = bool "No" "Yes" $ b1 && b2
  where
    b1 = all (\(x, y) -> head x == last y) $ zip (tail ss) ss
    b2 = all ((== 1) . length) . group . sort $ ss


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

import sys


def main():
    # inf = float('inf')              # sys.float_info.max = 1.79e+308
    inf = 2 ** 63 - 1             # (for fast JIT compile in PyPy) 9.22e+18
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input():  return sys.stdin.readline().rstrip()
    def ii():     return int(input())
    def isp():    return input().split()
    def mi():     return map(int, input().split())
    def mi_0():   return map(lambda x: int(x)-1, input().split())
    def lmi():    return list(map(int, input().split()))
    def lmi_0():  return list(map(lambda x: int(x)-1, input().split()))
    def li():     return list(input())
    def debug(x): print(x, file=sys.stderr)



    def calc_score(start):
        order = [None] * n
        accum = [None] * n
        order[start] = 0
        accum[start] = 0
        place = start
        cnt = 0
        current_score = 0
        M = -inf

        while cnt < k:
            place = P[place]    # 移動
            cnt += 1    # 移動回数
            current_score += C[place]    # 移動後の index でスコアに追加
            M = max(M, current_score)    # [スタートの次点, 現在地] まで任意の場所をゴールに選ぶときのスコア最大値
            if order[place] is None:
                # 未訪問
                order[place] = cnt
                accum[place] = current_score
            else:
                # 訪問ずみ (loop)
                head_len = order[place]
                loop_len = cnt - head_len
                head_score = accum[place]
                loop_gain = current_score - accum[place]
                if loop_gain <= 0:
                    # debug('encountered loop, but non-positive loop.')
                    return M
                else:
                    # debug('encountered positive loop.')
                    loop_times, res = divmod(k - head_len, loop_len)
                    # place からスタートして "0 以上" res 以下だけ進むときの
                    res_score = 0    # 稼ぐ最大スコア
                    tmp_score = 0    # 現在の累積スコア
                    tmp_place = place    # 現在地
                    for _ in range(res):
                        tmp_place = P[tmp_place]
                        tmp_score += C[tmp_place]    # 移動後の index でスコアに追加
                        res_score = max(res_score, tmp_score)
                    # 限界まで loop を回した上で 0 ~ res だけ貪欲に稼ぐ vs 限界 - 1 回 loop を回し確実にもう一回好きなところでとめられるようにして稼ぐ
                    loop_score = head_score + loop_times * loop_gain + res_score
                    stop_score = M + (loop_times - 1) * loop_gain
                    return max(loop_score, stop_score)

        # debug('never encountered loop.')
        return M
            

    n, k = mi()
    P = lmi_0()
    C = lmi()

    ans = -inf
    for i in range(n):
        score = calc_score(i)
        # debug(f'start: {i} ans: {score}')
        ans = max(ans, score)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 90388
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Word
import qualified Data.ByteString as BSW
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM

-- Input: s t
-- Output: arr
--   arr ! (i,j) == length of lcs of (drop i s, drop j t)
lcsTable2 :: BS.ByteString -> BS.ByteString -> U.Vector Word16
lcsTable2 s t = U.create $ do
  let !m = BS.length s
      !n = BS.length t
      !n' = n+1
  arr <- UM.replicate ((m+1) * n') 0
  forM_ [m-1,m-2..0] $ \ !i -> do
    let !x = BSW.index s i
        loopY !j !v
          -- v = UM.read arr $ i*n'+(j+1)
          | j < 0 = return ()
          | otherwise = do
              let !y = BSW.index t j
              if x == y
                then do l2 <- UM.read arr $ (i+1)*n'+(j+1)
                        let !l = l2 + 1
                        UM.write arr (i*n'+j) l
                        loopY (j-1) l
                else do l0 <- UM.read arr $ (i+1)*n'+j
                        let !l = max l0 v
                        UM.write arr (i*n'+j) l
                        loopY (j-1) l
    loopY (n-1) 0
  return arr

main = do
  s <- BS.getLine
  t <- BS.getLine
  -- BS.length s <= 3000, BS.length t <= 3000, BS.all isAsciiLower s, BS.all isAsciiLower t
  let !table = lcsTable2 s t
      !m = BS.length s
      !n = BS.length t
      !n' = n+1
  let recon !i !j | i >= m || j >= n = Nothing
                  | x == y = let !i' = i+1 ; !j' = j+1
                             in Just (x, (i', j'))
                  | table U.! ((i+1)*n'+j) >= table U.! (i*n'+(j+1)) = reconY y (i+1) j
                  | otherwise = reconX x i (j+1)
        where x = BSW.index s i
              y = BSW.index t j
      reconX !x !i !j | j >= n = Nothing
                      | x == y = let !i' = i+1 ; !j' = j+1
                                 in Just (x, (i', j'))
                      | table U.! ((i+1)*n'+j) >= table U.! (i*n'+(j+1)) = reconY y (i+1) j
                      | otherwise = reconX x i (j+1)
        where y = BSW.index t j
      reconY !y !i !j | i >= m = Nothing
                      | x == y = let !i' = i+1 ; !j' = j+1
                                 in Just (x, (i', j'))
                      | table U.! ((i+1)*n'+j) >= table U.! (i*n'+(j+1)) = reconY y (i+1) j
                      | otherwise = reconX x i (j+1)
        where x = BSW.index s i
      (result, _) = BSW.unfoldrN (fromIntegral $ table U.! 0) (\(!i,!j) -> recon i j) (0,0)
  BS.putStrLn result


Measured memory_bytes: 19324
from itertools import accumulate

N, K = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(K):
    if A == [N] * N:
        break
    B = [0] * (N+1)
    for i, a in enumerate(A):
        start = max(0, i - a)
        end = min(N-1, i + a) + 1
        B[start] += 1
        B[end] -= 1
    A = list(accumulate(B))[:-1]
print(' '.join(map(str, A)))



Measured memory_bytes: 181800
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let q: usize = input();
    let lr: Vec<(i64, i64)> = (0..q)
        .map(|_| {
            let l = input();
            let r = input();
            (l, r)
        })
        .collect();

    let mut v = vec![];
    for i in 2..100001 {
        if i % 2 == 0 {
            continue;
        }
        if is_prime(i) && is_prime((i + 1) / 2) {
            v.push(i);
        }
    }

    let mut ans = vec![0; q];
    for i in 0..q {
        let (l, r) = lr[i];
        let a = v.binary_search(&l);
        let b = v.binary_search(&r);
        if let Ok(a) = a {
            if let Ok(b) = b {
                ans[i] = b - a + 1;
            } else if let Err(b) = b {
                ans[i] = b - a;
            }
        } else if let Err(a) = a {
            if let Ok(b) = b {
                ans[i] = b - a + 1;
            } else if let Err(b) = b {
                ans[i] = b - a;
            }
        }
    }

    for i in 0..q {
        println!("{}", ans[i]);
    }
}

fn is_prime(x: i64) -> bool {
    let mut ok = true;
    for i in 2..x {
        if i * i > x {
            break;
        }
        if x % i == 0 {
            ok = false;
            break;
        }
    }
    ok
}


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

int n,k,cnt,ans;
string s;

int main()
{
	cin >> n >> k;
	cin >> s;
	s=' '+s+' ';
	for(int i=1;i<s.length();i++)
	{
		if(s[i]=='L'&&s[i-1]=='L') ans++; 
		else if(s[i]=='R'&&s[i+1]=='R') ans++;
	}
	cnt=n-ans-1;
	ans+=min(cnt,k*2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    /*
    let v = read_vec::<usize>();
    let (a, b) = (v[0], v[1]);
    if a <= 5 {
        println!("0");
    } else if a <= 12 {
        println!("{:?}", b / 2);
    } else {
        println!("{:?}", b);
    }
    */
    /*
    let v = read_vec::<i64>();
    let (r, d, mut x) = (v[0], v[1], v[2]);
    for i in 0..10 {
        x = r * x - d;
        println!("{:?}", x);
    }
    */
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut min_card_idx = 1;
    let mut max_card_idx = n;
    for i in 0..m {
        let v = read_vec::<usize>();
        min_card_idx = max(min_card_idx, v[0]);
        max_card_idx = min(max_card_idx, v[1]);
    }
    if max_card_idx >= min_card_idx {
        println!("{:?}", max_card_idx - min_card_idx + 1);
    } else {
        println!("0");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    string s;
    cin>>k>>s;
    if(s.length()<=k){
        cout<<s<<"\n";
    }   
    else{
        for(int i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"..."<<"\n";
    }
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

// bit全探索を用いるらしい
int bitscount(int bits){
    int cnt=0;
    while(bits!=0){
        if(bits&1) cnt++;
        bits=(bits>>1);
        // cout<<"bits:"<<bits<<"\n";
    }
    return cnt;
}

int main(){
    int N;
    cin>>N;
    int A[N];
    int x[N][N],y[N][N];
    rep(i,N){
        cin>>A[i];
        rep(j,A[i]){
            cin>>x[i][j]>>y[i][j];
            x[i][j]--;
        }
    }
    int ans=0;
    for(int bits=1; bits<(1<<N); bits++){
        bool ok = true;
        rep(i,N){
            if(!(bits&(1<<i))) continue;
            rep(j,A[i]){
                if(((bits>>x[i][j])&1)^y[i][j]) ok=false;
            }
        }
        if(ok) ans=max(ans,bitscount(bits));
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <cstring>
#include <climits>
#include <cstdio>

#define nl '\n'

using namespace std;

double l, s;

int main(){

    cin >> l;

    s = l/3;

    cout << setprecision(7) << s*s*s;


}
 
//g++ -std=c++14 comp.cpp -o c && c.exe
//g++ -std=c++14 comp.cpp -o c; ./c.exe
//g++ -std=c++14 comp.cpp && ./a.out


//Surely this is going to AC

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<pair<T, T>>& vp) {
	for (int i = 0; i < vp.size(); ++i) {
		s << "(" << vp[i].first << "," << vp[i].second << ")" << ( i+1 == vp.size() ? "" : ",\t" );
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	int r;
	cin >> r;
	cout << r*r << endl;
	return 0;
}


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

#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)

using namespace std;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

inline void File() {
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
}

const int N = 1e2 + 10;
int a[N], sta[N], tp, n, m, lst, sum, cnt, ans[N];

int main() {

	n = read(), m = read();
	For(i, 1, m) {
		a[i] = read();
		if (a[i] & 1) sta[++ tp] = i;
	}

	if (tp > 2) return puts("Impossible"), 0;

	if (tp > 0) swap(a[1], a[sta[1]]);
	if (tp > 1) swap(a[m], a[sta[2]]);

	For(i, 1, m) printf("%d ", a[i]); puts("");

	ans[cnt = 1] = lst = a[1] - 1; sum = 1;
	For(i, 1, m) sum += a[i], ans[++ cnt] = sum - lst, lst = sum;
	ans[cnt] -= 1;

	int tt = 0; For(i, 1, cnt) if (ans[i] == 0) ++ tt;		

	printf("%d\n", cnt - tt);
	For(i, 1, cnt) if (ans[i]) printf("%d ", ans[i]); puts("");

	return 0;
}


Measured memory_bytes: 256