akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    auto J = make_v(h+1, w+1, 0);
    auto O = J, I = J;
    for (int i = 1; i <= h; ++i) {
        string s;
        cin >> s;
        for (int j = 1; j <= w; ++j) {
            if(s[j-1] == 'J') J[i][j]++;
            else if(s[j-1] == 'O') O[i][j]++;
            else I[i][j]++;
        }
    }
    for (int i = 0; i < h+1; ++i) {
        for (int j = 1; j < w+1; ++j) {
            J[i][j] += J[i][j-1];
            O[i][j] += O[i][j-1];
            I[i][j] += I[i][j-1];
        }
    }
    for (int i = 1; i < h+1; ++i) {
        for (int j = 0; j < w+1; ++j) {
            J[i][j] += J[i-1][j];
            O[i][j] += O[i-1][j];
            I[i][j] += I[i-1][j];
        }
    }
    for (int i = 0; i < k; ++i) {
        int a, b, c, d;
        scanf("%d %d %d %d", &a, &b, &c, &d);
        int ans1 = J[c][d]-J[a-1][d]-J[c][b-1]+J[a-1][b-1],
            ans2 = O[c][d]-O[a-1][d]-O[c][b-1]+O[a-1][b-1],
            ans3 = I[c][d]-I[a-1][d]-I[c][b-1]+I[a-1][b-1];
        printf("%d %d %d\n", ans1, ans2, ans3);
    }
    return 0;
}



Measured memory_bytes: 14424
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,k,m[220000];
int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;++i) scanf("%d",&m[i]);
	sort(m+1,m+n+1);
	long long ans=0;
	for (int i=1;i<=n-k;++i) ans+=m[i];
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 1024
n = int(input())


def memorizer(f):
    memo = [ [None] * n for _ in range(n) ]
    for i in range(n):
        memo[i][i] = 0

    def inner_memo(a, b):
        if memo[a][b] is not None:
            return memo[a][b]
        rslt = memo[a][b] = f(a, b)
        return rslt

    return inner_memo

@memorizer
def minimum(a, b):
    return min(minimum(a, i) + minimum(i + 1, b) + l[a] * l[i + 1] * l[b + 1] for i in range(a, b))



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

l = []
l.append(a)
l.append(b)

n1 = n - 1

while n1 != 0:
    a, b = map(int, input().split())
    l.append(b)
    n1 -= 1

print(minimum(0, n - 1))




Measured memory_bytes: 6072
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

struct P {
	int from, cost, coupon;

	bool operator >(const P& p) const {
		return cost > p.cost;
	}
};

int ecost[101][101];
int ccost[101][11];
int c, n, m, s, d;
int i;

int main() {
	while(cin >> c >> n >> m >> s >> d, c|n|m|s|d) {
		fill_n((int *)ecost, 101*101, -1);
		fill_n((int *)ccost, 101*11, 1e8);
		for(i=0; i<11; i++) ccost[s][i] = 0;
		for(i=0; i<m; i++){
			int a, b, f;
			cin >> a >> b >> f;
			ecost[a][b] = f;
			ecost[b][a] = f;
		}
		priority_queue<P, vector<P>, greater<P>> q;
		q.push((P){s, 0, 0});
		int dcost;
		while(!q.empty()){
			P p = q.top(); q.pop();
			// cout << "pos=" << p.from << endl;
			// goal
			if(p.from == d) {
				dcost = p.cost;
				break;
			}
			//
			for(i=0; i<n+1; i++){ // i:to
				if(ecost[p.from][i] != -1){
					bool ifpush = true;
					for(int j=0; j <= p.coupon; j++) ifpush = ifpush && p.cost + ecost[p.from][i] < ccost[i][j];
					if(ifpush) {
					//if(p.cost + ecost[p.from][i] < ccost[i][p.coupon]){
						ccost[i][p.coupon] = p.cost + ecost[p.from][i];
						q.push((P){i, p.cost + ecost[p.from][i], p.coupon});
					}
					if(p.coupon+1 <= c) {
						bool ifpush = true;
						for(int j=0; j <= p.coupon+1; j++) ifpush = ifpush && p.cost + ecost[p.from][i]/2 < ccost[i][j];
						if(ifpush) {
						// if(p.cost + ecost[p.from][i]/2 < ccost[i][p.coupon+1]){
							ccost[i][p.coupon+1] = p.cost + ecost[p.from][i]/2;
							q.push((P){i, p.cost + ecost[p.from][i]/2, p.coupon+1});
						}
					}
				}
			}
		}
		cout << dcost << endl;
	}
	return 0;
}

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

int main(){
	int a, b,count=0,i;
	cin >> a >> b;
	string str;
	cin >> str;
	for (i = 0; str[i] != '\0'; i++) {
		if (str[i] >= '0' && str[i] <= '9') {
			count++;
		}
	}
	if ((count == (a + b)) && (str[a] == '-')) {
		cout << "Yes";
	}
	else { cout << "No"; }

	return 0;
}

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

int main(){
  string n; cin >>n;
  int p =n.size();

  if(n[p-1] == '3')  cout << "bon" <<endl;

  else if(n[p-1] == '0' || n[p-1] == '1' || n[p-1] =='6' ||n[p-1] =='8') cout << "pon" <<endl;

  else cout <<  "hon" <<endl;





}

Measured memory_bytes: 3628
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp {
	char name[100];
	int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue() {
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b) {
	return a < b ?  a : b;
}

int main() {
	int elaps = 0, c;
	int i, q;
	P u;
	scanf("%d %d", &n, &q);

	for (i = 1; i <= n; i++) {
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}
	head = 1; tail = n + 1;

	while (head != tail) {
		u = dequeue();
		c = min(q, u.t);
		u.t -= c;
		elaps += c;
		if (u.t > 0) enqueue(u);
		else {
			printf("%s %d\n", u.name, elaps);
		}
	}
	return 0;
}


Measured memory_bytes: 12888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int INF = INT32_MAX;
int idir[4] = {1, 0, -1, 0};
int jdir[4] = {0, 1, 0, -1};

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

    vector<vector<int>> dist(H, vector<int>(W, INF));
    queue<pair<int, int>> que;
    auto update = [&](int i, int j, int x) { //点(i,j)のコスト更新+queへの代入
        if (dist[i][j] != INF)
            return;
        dist[i][j] = x;
        que.push(make_pair(i, j));
    };
    update(0, 0, 0); //初期値
    while (!que.empty())
    {
        int i = que.front().first;
        int j = que.front().second;
        que.pop();
        rep(dir, 4)
        {
            int ni = i + idir[dir];
            int nj = j + jdir[dir];
            if (ni < 0 || ni >= H || nj < 0 || nj >= W)
                continue;
            if (c[ni][nj] == '#')
                continue;
            update(ni, nj, dist[i][j] + 1);
        }
    }

    int min_dist = dist[H - 1][W - 1];
    int w_cnt = 0;

    rep(i, H) rep(j, W)
    {
        if (c[i][j] == '.')
            w_cnt++;
    }
    int ans = w_cnt - (min_dist + 1);
    if (min_dist == INF)
        ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
let alphabet = "abcdefghijklmnopqrstuvwxyz"
let () =
  Scanf.scanf "%d" @@ fun n ->
  let arr = Array.make n 0 in
  let rec dfs i j =
    if i = n then (
      Array.iter (fun c -> Printf.printf "%c" alphabet.[c]) arr;
      print_newline ()
    ) else (
      for c = 0 to j do
        arr.(i) <- c;
        dfs (i+1) (max (c+1) j);
      done;
    )
  in
  dfs 0 0


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl
#define POSS(n) cout<<((n)?"POSSIBLE":"IMPOSSIBLE")<<endl



int main(){
    string a[3];
    cin>>a[0]>>a[1]>>a[2];
    int c[3]={};
    int t=0;
    
    for(;;){
        if(c[t]==a[t].size()){
            cout<<(char)('A'+t)<<endl;
            break;
        }
        t=a[t][c[t]++]-'a';
    }
    return 0;
}


Measured memory_bytes: 256
import math

N = int(input())

town = []

for _ in range(N):
    x, y = map(int, input().split())
    town.append((x, y))

ret = 0

for i in range(N):
    for j in range(i + 1, N):
        dx = town[i][0] - town[j][0]
        dy = town[i][1] - town[j][1]

        ret += 2 / N * math.sqrt(dx ** 2 + dy ** 2)

print(ret)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <iomanip>
#include <math.h>
#include <algorithm>
using namespace std;
//My macros............................!
#define hmm "\n"
#define test() int t; cin>>t; while(t--)
#define ll long long int
#define ull unsigned long long
#define read_i(x)	scanf("%d",&x)
#define read_l(x)	scanf("%lld",&x)
#define read_s(s)	scanf("%s",s)
#define print_i(x)	printf("%d\n",x)
#define print_l(x)	printf("%lld\n",x)
#define print_s(s)	printf("%s\n",s)
#define INF (int)1e9
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
//#define RFOR(i, j, k, in) for (int i = j; i >= k; i -= in)
//#define REP(i, j) FOR(i, 0, j, 1)
//#define RREP(i, j) RFOR(i, j, 0, 1)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ps(x,y) fixed<<setprecision(y)<<x;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

//Functions poto type........................!

bool is_prime(int n);   // return bool value. Is it prime or not? 
int absolutey(int a);   //returns absolute value of an integer
string eliminateAt(string x, int num);  //eliminates a single substring of a string in a given position
ll factorial(int num);
ll to_the_power(int x,int y);

void solve()    
{
    ll a,b,c,d,x,y;
    cin>>a>>b>>c>>d;
    x= max(a*c,a*d);
    y=max(b*c,b*d);
    cout<<max(x,y);
}

///My main function.........................!
int main()
{
//#ifndef ONLINE_JUDGE
	//freopen("r.txt", "r", stdin);
	//freopen("w.txt", "w", stdout);
//#endif

    fastIO
    //test()
        solve();
}



// Functions.................................!!

bool is_prime(int n){ // return bool value. Is it prime or not? 
    if(n<2)
        return 0;
    if(n==2)
        return 1;
    if(n%2==0)
        return 0;
    int r= sqrt(n);
    for(int i=3; i<=r; i+=2){
        if(n%i==0) 
            return 0;
    }
    return 1;
}
int absolutey(int a) //returns absolute value of an integer
{   
    return ((a<0 ? (a*-1): a));
}
string eliminateAt(string x, int num)//eliminates a single substring of a string in a given position
{
    if(num==0){
        return x.substr(1,x.length()-1);
    }
    else if(num==x.length()-1){
        return x.substr(0,x.length()-1);
    }
    else{
        return x.substr(0,num)+x.substr(num+1,x.length()-1);
    }
}
ll factorial(int num){
    if(num==0)
        return 1;
    return (num*factorial(num-1));
}
ll to_the_power(int x,int y){
    ll result=1;
    while (y>0)
    {
        if(y%2==1) result*=x;
        x*=x;
        y/=2;
    }
    return result;
}

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

#define db long double
const db eps = 1e-6;
int sgn(db a, db b = 0) {
	a -= b;
	return (a > eps) - (a < -eps);
}

struct poi {
	db x, y;
	void r() { cin >> x; cin >> y; }
	void w() { cout << x << ' ' << y << '\n'; }
	poi operator -(poi p) {
		return {x - p.x, y - p.y};
	}
	poi operator +(poi p) {
		return {x + p.x, y + p.y};
	}
	poi operator *(db d) {
		return {x * d, y * d};
	}
	poi operator /(db d) {
		return {x / d, y / d};
	}
	bool operator ==(poi p) {
		return !sgn(x, p.x) && !sgn(y, p.y);
	}
	db dot(poi p) {
		return x * p.x + y * p.y;
	}
	db cross(poi p) {
		return x * p.y - y * p.x;
	}
	db len() { return sqrt(x * x + y * y); }
	db len2() { return x * x + y * y; }
	poi proj(poi p, poi q) {
		db s = (*this - p).dot(q - p) / (q - p).len2();
		return p + (q - p) * s;
	}
	db dis(poi p, poi q) {
		if((*this - p).dot(q - p) < 0) return (*this - p).len();
		if((*this - q).dot(p - q) < 0) return (*this - q).len();
		return abs((*this - p).cross(q - p) / (q - p).len());
	}
};
db xmul(poi a, poi b, poi c) {
	return (b - a).cross(c - a);
}

int ccw(poi a, poi b, poi c) {
	poi u = b - a, v = c - a;
	if(u.cross(v) > eps) return 1;
	if(u.cross(v) < -eps) return -1;
	if(u.dot(v) < -eps) return -2;
	if(u.len2() + eps < v.len2()) return 2;
	return 0;
}
bool si(poi a, poi b, poi c, poi d) {
	return ccw(a, b, c) * ccw(a, b, d) <= 0 &&
		ccw(c, d, a) * ccw(c, d, b) <= 0;
}
poi li(poi a, poi b, poi c, poi d) {
	db u = xmul(c, d, a), v = xmul(c, d, b);
	return (a * v - b * u) / (v - u);
}

const int N = 111;
poi p[N];

int main() {
	ios :: sync_with_stdio(false);
	int n; cin >> n;
	for(int i = 0; i < n; i ++)
		p[i].r();
	p[n] = p[0];
	bool conv = true;
	for(int i = 0; i < n - 1; i ++)
		if(ccw(p[i], p[i + 1], p[i + 2]) == -1)
			conv = false;
	cout << conv << '\n';

	return 0;
}

Measured memory_bytes: 3280
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
#print(A)
cnt = 0
prev = 0
candidates = []
for i in A:
    if i == prev:
        cnt += 1
        prev = i
    elif i != prev:
        prev = i
        cnt = 0
    if cnt >= 3:
        print(i**2)
        exit()
    if cnt == 1:
        candidates.append(i)
    if len(candidates) == 2:
        print(candidates[0]*candidates[1])
        exit()

print(0)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
#define maxn 3005
#define ll long long
 
int n,m,k;
char s[maxn][maxn];
int h[maxn][maxn],w[maxn][maxn];
int maxx;

int main()
{
	scanf("%d %d",&n,&m);
	getchar();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)
			scanf("%c",&s[j][i]);
		getchar();
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			if(s[j][i]=='#'){
				for(int k=j-1;k>=j-w[j-1][i];k--)
					w[k][i]=w[j-1][i];
				w[j][i]=0;
			}
			else w[j][i]=w[j-1][i]+1;
			if(j==m&&s[j][i]=='.'){
				for(int k=j;k>=j-w[j][i];k--)
					w[k][i]=w[j][i];
			}
		}
	for(int j=1;j<=m;j++)
		for(int i=1;i<=n;i++){
			if(s[j][i]=='#'){
				for(int k=i-1;k>=i-h[j][i-1];k--)
					h[j][k]=h[j][i-1];
				h[j][i]=0;
			}
			else h[j][i]=h[j][i-1]+1;
			if(i==n&&s[j][i]=='.'){
				for(int k=i;k>=i-h[j][i];k--)
					h[j][k]=h[j][i];
			}
		}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			maxx=max(maxx,w[j][i]+h[j][i]-1);
		}
	printf("%lld",maxx);
	return 0;
}

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

#define  ll long long
#define  il inline
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define pb push_back

const int mod = 1e9 + 7;
const int maxn = 1e3 + 10;
const int maxm = 2e5 + 10;
const double PI = acos(-1.0);

struct point{
	double x,y;
}s[maxn];

bool cmp(point &a, point &b) {
	if(atan2(a.y,a.x) != atan2(b.y,b.x)) return atan2(a.y,a.x) < atan2(b.y,b.x);
	return a.x < b.x;
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
   	int n;
   	cin >> n;
   	rep(i,1,n) cin >> s[i].x >> s[i].y;
   	sort(s + 1, s + 1 + n , cmp);
   	rep(i,1,n) s[i + n] = s[i];
   	double ans = 0;
   	rep(i,1,n) {
   		double xx = 0, yy = 0;
   		rep(j,i,i + n - 1) {
   			 xx += s[j].x;
   			 yy += s[j].y;
   			 ans = max(ans, xx * xx + yy * yy);
   		}
   	}
   	cout << setprecision(30) << sqrt(ans) << endl;
    return 0;
}

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


int main() {
  int64_t n;
  cin >> n;

  vector<int> a(n+1), b(n);
  for(int i = 0; i<n+1; i++){
    cin >> a.at(i);
  }
  for(int i = 0; i<n; i++){
    cin >> b.at(i);
  }

  int64_t count = 0;

  for(int i = 0; i<n; i++){
    if(b.at(i) < a.at(i)){
      count += b.at(i);
    }else if(b.at(i) < (a.at(i) + a.at(i+1))){
      count += b.at(i);
      a.at(i+1) = a.at(i) + a.at(i+1) - b.at(i);
    }else{
      count += a.at(i) + a.at(i+1);
      a.at(i+1) = 0;
    }
  }

  cout << count << endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N,M;
    cin >> N >> M;
    vector<char> A(N*N);
    vector<char> T(M*M);
    for(int i = 0;i < N*N ;i++){
        cin >> A[i];
    }
    for(int i = 0;i < M*M;i++){
        cin >> T[i];
    }
    int ans = 0;
    if(N == M && N == 1){
        if(A[0] == T[0]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
    for(int i = 0 ;i < N - M;i++){
        for(int j = 0;j < N - M;j++){
            bool judje = 1;
            for(int k = 0;k < M;k++){
                for(int l = 0;l < M;l++){
                    if(T[l+k*M] != A[i*N+j+k*N+l]) judje = 0;
                }
            }
            if(judje) ans++;
        }
    }
    if(ans > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define pri 1000000007
#define all(x) x.begin(),x.end()
#define mnx 1000001
#define pr pair<ll,ll>
using namespace std;

void masterstroke(){
string a;
cin>>a;
ll x=a.length();
for(ll i=1;i<x;i++){
	if(a[i]==a[i-1]){cout<<"Bad";return;}
}
cout<<"Good";

}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)masterstroke();
}

Measured memory_bytes: 256
/*
Author-KUSHAGRA SINGH
Birla Institute of Technology Mesra
CS K18
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

//#define mp make_pair
#define pb emplace_back
#define vll vector<ll>
#define vpll vector< pair <ll,ll> >
#define pll pair <ll,ll>
#define pq priority_queue< int >
#define khtm "\n"
#define F first
#define S second
#define fr(i,a,n) for(i=a;i<n;i++)
#define mem(arr,l) memset(arr,l,sizeof arr)
#define ALL(x) x.begin(), x.end()
#define frr(i,a,n) for(i=n-1;i>=a;i--)
//#define mod 1000000007
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase ll T; cin>>T; while(T--)
const int MAX = 1e6 +2;

/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 3e5 + 5, md = 1e9 + 7;

inline int add(int x, int y) {
    x += y;
    if(x >= md) x -= md;
    return x;
}

inline int sub(int x, int y) {
    x -= y;
    if(x < 0) x += md;
    return x;
}

inline int mul(int x, int y) { return 1ll * x * y % md; }

inline int fpow(int x, int y) {
    int ans = 1;
    while(y) {
        if(y & 1) ans = mul(ans, x);
        y >>= 1; x = mul(x, x);
    }
    return ans;
}

ll a[N];
int n, ans;

int main() {
   
  
  cin>>n;
for(register int i = 1; i <= n; i++)
	cin>>a[i];

 
 for(register int j = 0; j < 60; j++) {
	 int cnt = 0;
        for(register int i = 1; i <= n; i++)
		cnt += ((a[i]>>j)&1);
	//ll temp = 1LL<<j;
	//ans= (ans + ((temp % mod) * (cnt*(n-cnt)) ) % mod);
	ans = add (ans , mul((1LL << j) %md , mul(cnt,n-cnt)));
}

cout<<ans;
    return 0;
}


Measured memory_bytes: 2560
use std::io::Read;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let n: usize = s.trim().parse().unwrap();
    let mut mp = std::collections::HashMap::<(u8, u8), u64>::new();
    let mut ans = 0u64;
    for i in 1..n + 1 {
        let s: Vec<u8> = i
            .to_string()
            .chars()
            .map(|c| c.to_digit(10).unwrap() as u8)
            .collect();
        let cnt = mp.entry((s[0], s[s.len() - 1])).or_insert(0);
        *cnt += 1;
    }
    for i in 1..10 {
        for j in 1..10 {
            match (mp.get(&(i, j)), mp.get(&(j, i))) {
                (Some(val1), Some(val2)) => ans += val1 * val2,
                _ => (),
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <iomanip>
#include <map>
#include <cmath>
#include <cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    cin.tie(0);
    int n,m,c=0;
    cin >> n >> m;
    int d[n][m];

    rep(i,n){
        for(int j=0; j<m; j++){
            cin >> d[i][j];
        }
    }
    rep(i,n){
        for(int k=i+1;k<n;k++){
            int r=0;
            for(int j=0;j<m;j++)
                r += pow(d[i][j] - d[k][j], 2);
            float ans = sqrt(r);
            if(ceil(ans)==floor(ans)) c++;
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=998244353;
const LL LINF=1LL<<60;
const int INF=1<<20;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


vector<LL> divi(LL K){
    vector<LL> v;
    for(int i=1;i*i<=K;i++){
        if(K%i) continue;
        v.pb(i);
        v.pb(K/i);
    }
    sort(ALL(v));
    v.erase(unique(ALL(v)),v.end());
    return v;
}


int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<vector<LL>> dp(n+1,vector<LL> (2,0));
    dp[0][1] = 1;
    for (int i = 0; i < n; i++) {
        for (int f = 0; f < 2; f++) {
            if(f){
                int x = s[i] - '0';
                for (int j = 0; j <= x; j++) {
                    if(j==x) dp[i+1][1] = (dp[i+1][1] + dp[i][1])%mod;
                    else dp[i+1][0] = (dp[i+1][0] + dp[i][1])%mod;
                }
            }
            else{
                dp[i+1][0] = (dp[i+1][0] + 2 * dp[i][0])%mod;
            }
        }
    }
    LL ans = 0, count = (dp[n][0] + dp[n][1])%mod;
    ans = count * n % mod * 2 % mod;
    auto p = divi(n);
    reverse(ALL(p));
    vector<LL> dp2(n+1,0);
    for(auto a:p){
        LL x = n / a;
        if(n % 2 == 0){
            if(x % 2) continue;
            if(x % 2 || n / x % 2 == 0) continue;
        }
        string t = "";
        for (int j = 0; j < n; j++) {
            if(j / x % 2){
                t += '0' + (s[j % x] ^ '1');
            }
            else{
                t += s[j % x];
            }
        }
        LL sum = 0;
        if(t <= s){
            dp2[x] = (dp[x][0] + dp[x][1])%mod;
        }
        else{
            dp2[x] = dp[x][0];
        }
        for(auto b:p){
            LL y = n / b;
            if(x % y == 0 && x != y) dp2[x] = (dp2[x] - dp2[y] + mod) %mod;
        }
        ans = (ans - ((2 * (n - x + mod)%mod) * dp2[x] %mod) + mod)%mod;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 13440
#include <stdio.h>
#include <ctype.h>
#include <string.h>
 
typedef struct _node {
  int key;
  struct _node *next;
  struct _node *prev;
} NODE, *PNODE;
 
PNODE root;
 
void init(void) {
  root = malloc(sizeof(NODE));
  root->next = root;
  root->prev = root;
}
 
void insert(key) {
  PNODE t = malloc(sizeof(NODE));
  t->key = key;
  t->next = root->next;
  t->prev = root;
  root->next->prev = t;
  root->next = t;
}
 
void deleteNode(PNODE node) {
  if (node == root) {
    return;
  }
  node->next->prev = node->prev;
  node->prev->next = node->next;
  free(node);
}
 
void delete(key) {
  PNODE cur = root->next;
  while (cur != root) {
    if (cur->key == key) {
      deleteNode(cur);
      return;
    }
    cur = cur->next;
  }
}
 
void deleteFirst(void) {
  deleteNode(root->next);
}
 
void deleteLast(void) {
  deleteNode(root->prev);
}
 
void printNodes(void) {
  PNODE cur = root->next;
  while (1) {
    printf("%d", cur->key);
    cur = cur->next;
    if (cur != root) {
      putchar(' ');
    } else {
      break;
    }
  }
  putchar('\n');
}
 
void release(void) {
  PNODE tmp, cur = root->next;
  while (cur != root) {
    tmp = cur;
    cur = cur->next;
    deleteNode(tmp);
  }
  free(root);
} 
 
int main(void) {
  char cmd[100];
  int n, i, f;
  int key;
 
  init(); 
 
  scanf("%d", &n);
 
  f = 0;
  while (scanf("%s", cmd) > 0) {
    if (cmd[0] == 'i') {
      f = 1;
    } else if (cmd[0] == 'd') {
      switch (cmd[6]) {
      case '\0':
    f = 2;
    break;
      case 'F':
    deleteFirst();
    break;
      case 'L':
    deleteLast();
    break;
      }
    } else {
      key = atoi(cmd);
      if (f == 1) {
    insert(key);
      } else if (f == 2) {
    delete(key);
      }
    }
  }
 
  printNodes();
 
  release();
 
  return 0;
}

Measured memory_bytes: 31852
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt() - 1;
		}
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = sc.nextInt();
		}
		sc.close();

		long ans = Long.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int idx = i;
			long max = Long.MIN_VALUE;
			long one = 0;
			for (int j = 1; j <= k; j++) {
				idx = p[idx];
				one += c[idx];
				max = Math.max(max, one);
				if (idx == i) {
					if (one > 0) {
						long x = k / j;
						long val = one * (x - 1);
						long r = k % j + j;
						one = 0;
						long max2 = 0;
						for (int j2 = 0; j2 < r; j2++) {
							idx = p[idx];
							one += c[idx];
							max2 = Math.max(max2, one);
						}
						val += max2;
						max = Math.max(max, val);
					}
					break;
				}
			}
			ans = Math.max(ans, max);
		}
		System.out.println(ans);
	}
}


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

int main()
{
int A,B,C,r=0;
  cin>>A>>B;
  if(B==1){
cout<<0<<endl;
    exit(0);
  }
  for(int i=1;i<21;i++){
C=i*A-(i-1);
    r++;
    if(C>=B){
cout<<r<<endl;
      exit(0);
    }
  }
}
       

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ld, ld> pdd;

void solve();

const int N = 1e5 + 10;

int main() {
    fast_cin();

    int t=1;
    // cin >> t;
    while(t--) {
        solve();
    }
}

void solve() {
    int n;
    cin >> n;
    int a[N][4], dp[N][4]={};
    for (int i=1; i <= n; i++) { 
        for (int j=1; j <= 3; j++) {
            cin >> a[i][j];
        }
    }
    
    for (int i=1; i <= n; i++) {
        for (int j=1; j <= 3; j++) {
            for (int k=1; k <= 3; k++) {
                if (j != k) {
                    dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
                }
            }
        }
    }
    
    cout << max({dp[n][1], dp[n][2], dp[n][3]}) << '\n';
}


Measured memory_bytes: 3328
import java.util.Scanner;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a;
		int b;
		int c;
		int d;
		for(d=0;d<7;d++){
		a = sc.nextInt();
		b = sc.nextInt();
		System.out.println(a-b);
		}
	}
	}

Measured memory_bytes: 17312
#include<stdio.h>
#define N 500000
#define S 1000000000
 

void Merge(int, int, int);
void Sort(int, int);
int A[N], cnt = 0;


int main(void){
  int n, i;
 
  scanf("%d", &n);
  for(i=0; i < n; i++) scanf("%d", &A[i]);

  Sort(0, n);
 
  for(i = 0; i < n; i++){
    printf("%d", A[i]);
    if(i < n - 1)printf(" ");
  }
 
  printf("\n%d\n", cnt);

  return 0;
}

void Merge(int left, int mid, int right){
  int i, k, j;
  int n1 = mid - left, n2 = right - mid;
  int l[n1], r[n2];
 
  for(i = 0; i < n1; i++) l[i] = A[left + i];
  for(i = 0; i < n2; i++) r[i] = A[mid + i];
 
  l[n1] = S;
  r[n2] = S;
  i = 0;
  j = 0;
 
  for(k = left; k < right; k++){
    if(l[i] <= r[j]){
      A[k] = l[i];
      i++;
    }
    else{
      A[k] = r[j];
      j++;
    }
    cnt++;
  }
}
void Sort(int left, int right){
  int mid;

  if(left + 1 < right){

    mid = (left + right) / 2;
    Sort(left, mid);
    Sort(mid, right);
    Merge(left, mid, right);
  }
}

Measured memory_bytes: 4504
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#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;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    ll a, b, k; cin>>a>>b>>k;

    ll nxta = max(a - k, 0LL);
    k -= (a - nxta);
    ll nxtb = max(b - k, 0LL);

    cout << nxta << " " << nxtb << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;


int main() {
	int Q; cin >> Q;
	for (int iter = 0; iter < Q; iter++) {
		ll A, B; cin >> A >> B;
		ll lo = 0, hi = 3e9;
		while (hi - lo > 1) {
			ll mid = lo + (hi - lo) / 2;
			ll m = 0;
			for (ll i = max(1LL, mid/2 - 1000LL); i <= min(mid, mid/2 + 1000LL); i++) {
				ll a = i + (i >= A);
				ll b = mid + 1 - i + (mid + 1 - i >= B);
				m = max(m, a*b);
			}
			if (m < A*B) lo = mid;
			else hi = mid;
		}
		cout << lo << endl;
	}
	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 vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int A, B;
    cin >> A >> B;
    if(A<=5){
        B = 0;
    }else if(A>=13){
    }else{
        B = B / 2;
    }
    cout << B << endl;
}

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

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> G[N];
    for (int i = 0; i < M; i++)
    {
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        G[s].push_back(t);
        G[t].push_back(s);
    }
    vector<int>ans(N, -1);
    queue<int> que;

    ans[0] = 0;
    que.push(0);

    while(!que.empty()){
        int v = que.front();
        que.pop();

        for (auto nv : G[v])
        {
            if (ans[nv] != -1) continue;
            que.push(nv);
            ans[nv] = v;
        }
        
    }
    cout << "Yes" << "\n";
    for (int v = 1; v < N; ++v) cout << ans[v] + 1 << "\n";

    /*for (int i = 1; i < N; i++)
    {
        if (dist[i] == -1)
        {
            cout << "No" << "\n";
            return 0;
        }
        
    }
    cout << "Yes" << "\n";
    for (int v = 1; v < N; ++v){
        cout << key[v] + 1 << "\n";
    }*/
    /*
    if (find(dist.begin(), dist.end(), -1) != dist.end()){
		cout << "No" << "\n";
    }else{
		cout << "Yes" << "\n";
        for (int v = 1; v < N; ++v){
            cout << key[v] + 1 << "\n";
        }
    }*/
    return 0;
}

Measured memory_bytes: 10132
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<functional>
#include<algorithm>
#include<list>
#include<string>
#include<vector>

using namespace std;

#define LL long long

int main() {
	list<int>ls;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		char c[50];
		scanf("%s",&c);
		if(c[0]=='i'){
			int x;
			std::scanf("%d",&x);
			ls.insert(ls.begin(),x);
		}
		else if(c[6]=='L'){
			ls.pop_back();		
		}
		else if(c[6]=='F'){
			ls.pop_front();		
		}
		else {
			int x;
			std::scanf("%d",&x);
			for(auto i=ls.begin();i!=ls.end();i++){
				if(*i==x){
					ls.erase(i);
					break;
				}
			}
		}
	}

	for(auto i=ls.begin();i!=ls.end();i++){
		if(i!=ls.begin())putchar(' ');
		printf("%d",*i);
	}
	printf("\n");
	return 0;
}

//15:30


Measured memory_bytes: 34436
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[100002][4];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    int hz[n + 1][4];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= 3; j++)
            cin >> hz[i][j];
    dp[1][1] = hz[1][1];
    dp[1][2] = hz[1][2];
    dp[1][3] = hz[1][3];
    for (int i = 2; i <= n; i++)
        for (int j = 1; j <= 3; j++)
        {
            if(j == 1)
            {
                dp[i][j] = max(dp[i - 1][2] + hz[i][j], dp[i][j]);
                dp[i][j] = max(dp[i - 1][3] + hz[i][j], dp[i][j]);
            }
            else if(j == 2)
            {
                dp[i][j] = max(dp[i - 1][1] + hz[i][j], dp[i][j]);
                dp[i][j] = max(dp[i - 1][3] + hz[i][j], dp[i][j]);
            }
            else
            {
                dp[i][j] = max(dp[i - 1][2] + hz[i][j], dp[i][j]);
                dp[i][j] = max(dp[i - 1][1] + hz[i][j], dp[i][j]);
            }
        }
    cout << max(dp[n][1], max(dp[n][2], dp[n][3]));

}


Measured memory_bytes: 8316
#include<bits/stdc++.h>
using namespace std;
int a[10000];
int main()
{
int i, n, mx,mn;

scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d", &a[i]);
}
mx= a[0]; mn = a[0];
for (i = 1; i < n; i++)
{
if (mn > a[i])mn = a[i];
if (mx < a[i])mx = a[i];
}
int res=0;
res=mx-mn;
printf("%d",res);
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define mod 1000000007
#define ll long long int
#define int int64_t
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SORT(x) sort(all(x));
#define DSORT(x) sort(all(x), greater<>());
#define PI 3.14159265358979323846264338327950288
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;
bool prime(int n){for(int i=2;i<=sqrt(n);i++){if(n%i==0){return 0;}}return 1;}
void normal(int &a) {a=a%mod;(a<0)&&(a=a+mod);}
int Add(int a,int b) {a=a%mod,b=b%mod; normal(a),normal(b); return (a+b)%mod; }
int Sub(int a,int b) {a=a%mod,b=b%mod; normal(a),normal(b); a=a-b; normal(a); return a; }
int Mul(int a,int b) {a=a%mod,b=b%mod; normal(a),normal(b); return (a*b)%mod;}
int Pow(int n,int x){int res=1; while(x){ if(x&1) res=Mul(res,n); n=Mul(n,n); x=x>>1;} return res;} 
int modInverse(int n){return Pow(n,mod-2);}
int Div(int a,int b) { return Mul(a, modInverse(b));}
const int E3 = 1e3 + 7;
const int E4 = 1e4 + 7;
const int E5 = 1e5 + 7;
const int E6 = 1e6 + 7;
const int E9 = 1e9 + 7;
vector<int> adj[E5];
bool vis[E5];
void dfs(int node){
    vis[node]=1;
    for(auto it:adj[node]){
        if(!vis[it]){
            dfs(it);
        }
    }
}
signed main(){
    fio;
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int cnt=-1;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
            cnt++;
        }
    }
    cout<<cnt;
    return 0;
}



Measured memory_bytes: 10396
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int P,Q,R,S,N; cin>>P>>Q>>R>>S>>N;
  int X=min(4*P,min(2*Q,R));
  if(2*X<=S)
    cout<<N*X<<endl;
  else{
    int Y=N/2;
    if(N%2==0)
      cout<<Y*S<<endl;
    else
    cout<<Y*S+X<<endl;
  }
  }



Measured memory_bytes: 256
#include<stdio.h>
#define N 200000
int main(){

  int i,j,R[N],n,maxv=0,minv;

  scanf("%d",&n);

  for(j=0;j<n;j++) scanf("%d",&R[j]);

  minv = R[0];
  maxv = R[1] - R[0];
  for(j=1;j<n;j++){
    if( maxv < R[j]-minv ) maxv = R[j] - minv;
    else maxv = maxv;
    if( minv < R[j] ) minv = minv;
    else minv = R[j];
  }

  printf("%d\n",maxv);
  return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string s;

int main(void){
    
    cin >> s;
    int sum = (s[0] == 'o') * 100 + (s[1] == 'o') * 100 + (s[2] == 'o') * 100;
    printf("%d\n", sum + 700);
    
    return 0;
}

Measured memory_bytes: 256
io = DATA.eof? ? STDIN : DATA
h,w,m=io.gets.split.map(&:to_i)
rc=m.times.map{io.gets.split.map(&:to_i)}
r,c=rc.transpose
rtally= r.tally
ctally= c.tally
rmax= rtally.values.max
cmax= ctally.values.max
rct=rtally.count{|r,maxct|maxct==rmax}
cct=ctally.count{|c,maxct|maxct==cmax}
if rct*cct>rc.count{|r,c|rtally[r]==rmax && ctally[c]==cmax}
  puts rmax+cmax
else
  puts rmax+cmax-1
end
__END__


Measured memory_bytes: 72960
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int main(){
    int N;
    double ans = 0;
    cin >> N;
    REP(i,N){
        double x;
        string u;
        cin >> x >> u;
        if (u == "BTC") x = x * 380000.0;
        ans = ans + x;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#define rep(i,j,k) for(int i = j; i <= k; i++) 
#define dow(i,j,k) for(int i = j; i >= k; i--) 

using namespace std;
const int N = 2e5 + 100;
int n, a[N];
vector<pair<int,int> > mp;

bool check(int index) {
	mp.clear();
	mp.push_back(make_pair(0,0));
	int sz = 0, p;
	for (int i = 2; i <= n; i++) {
		if (a[i] > a[i-1]) continue;
		while (mp[sz].first > a[i]) mp.pop_back(), sz--;
		//int j = mp.size() - 1;
		for (p = a[i]; p; p--) {
			if (mp[sz].first < p) mp.push_back(make_pair(p,0)), sz++;
			if (++mp[sz].second == index) mp.pop_back(), sz--;
			else break;
		}

		if (!p) return 0;
	}
	return 1;
}


int main() {
	ios::sync_with_stdio(0);
	cin >> n;
	int flag = 1;
	//n = 2e5 ;
	rep(i,1,n) cin >> a[i];//a[i] = 100000000 - i * 10 ;//cin >> a[i];
	rep(i,2,n) flag &= (a[i] > a[i - 1]);
	if (flag) {
		cout << 1 << endl;
		return 0;
	}
	int l = 2, r = n;
	while (l < r) {
		int mid = l + r >> 1;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	cout << l << endl;
}
	

Measured memory_bytes: 1024
#include <atcoder/dsu>
#include <cstdio>

using namespace std;
using namespace atcoder;

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    dsu d(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        scanf("%d %d %d", &t, &u, &v);
        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                printf("1\n");
            } else {
                printf("0\n");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
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; }

ll solve(ll H, ll W){
    ll ans = 1e18;
    //Wに平行な二本で分割
    if(H % 3 == 0) chmin(ans, 0LL);
    else chmin(ans, W);

    //Wに平行な一本で分割し、さらにHと平行な一本で分割
    for (ll i = 1; i <= H - 1; ++i){
        ll mx = max({i * (W / 2), i * (W - W / 2), (H - i) * W});
        ll mn = min({i * (W / 2), i * (W - W / 2), (H - i) * W});
        chmin(ans, mx - mn);
    }

    return ans;
}

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

    ll H, W;
    cin >> H >> W;

    print(min(solve(H, W), solve(W, H)));

    return 0;
}

Measured memory_bytes: 256
n1 = int(input())
s1 = input()

r1 = 0
r2 = 0
for i1 in range (n1):
    if n1 - (r1 * 2) - i1 < 0:
        break
    for i2 in range(n1 - r1):
        t2 = r1 + i2 + 1
        if s1[i1:i1 + t2] in s1[i1 + t2:] and s1[i1:i1 + t2] != "":
            continue
        else:
            r1 = max(r1, r1 + i2)
            break


print(r1)


Measured memory_bytes: 3188
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    int arr[n];
    for (int i=0;i<n;i++){
        cin >> arr[i];
    }
    vector<int> dp(n,INT_MAX);
    dp[0] = 0;
    for (int i=1;i<n;i++){
        for (int j=i-1;j>=0 && j>i-1-k;j--){
            dp[i] = min(dp[i],abs(arr[i]-arr[j])+dp[j]);
        }
    }
    cout << dp[n-1] << endl;
}


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

using namespace std;

int a,b;
int s=1;

int main()
{
    ios::sync_with_stdio(false);
    cin>>a>>b;
    if(a>1&&b>1)
    {
        a--;
        b--;
        s=a*b;
    }
    else s=0;
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
N=int(input()) # マスの個数、マスの番号が1-N
A=list(map(int,input().split(" "))) # マスのリスト
An=[i for i in range(1,N+1)] # マスの番号のリスト

count=0 # 条件を満たすマスの数

# 各マスについて見てゆく
for ai in range(len(A)):
    if (A[ai]%2==1) and (An[ai]%2==1): # 条件
        count+=1 # カウントをインクリメント

print(count)

Measured memory_bytes: 9056