akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <sstream>
#include <array>
#include <cmath>
#include <deque>

template <typename T, typename U>
inline std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <typename T, typename U>
inline std::istream& operator>>(std::istream& os, std::pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <typename T>
inline std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
    if (v.empty()) {
        return os;
    }
    if (v.begin() != v.end()) {
        os << v.front();
    }
    for (auto it = ++v.begin(); it != v.end(); ++it) {
        os << ' ' << *it;
    }
    return os;
}
template <typename T>
inline std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (auto& i : v) {
        is >> i;
    }
    return is;
}

void Solve(std::istream& is, std::ostream& os) {
    std::string input;
    char next = is.get();
    while (next != EOF) {
        if (next != 'B') {
            input.push_back(next);
        } else if (!input.empty()) {
            input.pop_back();
        }
        next = is.get();
    }
    os << input;
}

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


Measured memory_bytes: 256
n, a, b, c = map(int, input().split())

abc = [a, b, c]

def yes():
    print('Yes')
    for c in ans:
        print(chr(c+ord('A')))

def no():
    print('No')
    exit()

def move(s, t):
    ans.append(s)
    abc[s] += 1
    abc[t] -= 1

play = []

for i in range(n):
    s = bytes(input(), 'ascii')
    s, t = s[0]-ord('A'), s[1]-ord('A')

    play.append((s, t))

ans = []
for i, (s, t) in enumerate(play):
    if abc[s] == 0 and abc[t] == 0:
        no()
        break
    if abc[s] == abc[t]:
        if s in play[(i+1)%n]:
            move(s, t)
        else:
            move(t, s)
    elif abc[s] < abc[t]:
        move(s, t)
    else:
        move(t, s)

yes()

Measured memory_bytes: 88072
use proconio::{fastout, input};

fn main() {
    input! {
        n: usize,
        c_str: String,
    };
    let mut left = 0;
    let mut right = n - 1;

    let mut ans = 0;
    let mut c_chars: Vec<char> = c_str.chars().collect();
    'outer: while left < right {
        while c_chars[left] == 'R' {
            left += 1;
            if left >= right {
                break 'outer;
            }
        }
        while c_chars[right] == 'W' {
            right -= 1;
            if left >= right {
                break 'outer;
            }
        }
        c_chars.swap(left, right);
        ans += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 3244
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265359
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  int K, N;
  cin >> K >> N;
  int A[N];
  rep(i, N) { cin >> A[i]; }
  int B[N];
  rep(i, N - 1) { B[i] = A[i + 1] - A[i]; }

  B[N - 1] = K - A[N - 1] + A[0];

  int max_ = 0;

  rep(i, N) {
    if (B[i] >= max_) max_ = B[i];
  }

  cout << K - max_ << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pii pair<int, int>
using namespace std;
const int MAXN = 1e6 + 7;
const int INF = 1e9;
vector<pii>vec;
char s[MAXN];
stack<char>stk;
int N, a[MAXN], v[MAXN];
    
#define lson (rt << 1)
#define rson (rt << 1 | 1)
struct node{int val, pos;} T[MAXN << 2];
node merge(node &x, node &y) {
    if (x.val > y.val) return x;
    else return y;
}
void pushup(int rt) {T[rt] = merge(T[lson], T[rson]);}
void build(int rt, int l, int r) {
    if (l == r) {T[rt] = {v[l], l}; return;}
    int mid = (l + r) >> 1;
    build(lson, l, mid);
    build(rson, mid + 1, r);
    pushup(rt);
}
void update(int rt, int l, int r, int pos, int v) {
    if (l == r) {T[rt] = {v, l}; return;}
    int mid = (l + r) >> 1;
    if (pos <= mid) update(lson, l, mid, pos, v);
    else update(rson, mid + 1, r, pos, v);
    pushup(rt);
}
node query(int rt, int l, int r, int L, int R) {
    if (L <= l && r <= R) return T[rt];
    int mid = (l + r) >> 1;
    node resl = {-INF, -1}, resr = {-INF, -1};
    if (L <= mid) resl = query(lson, l, mid, L, R);
    if (mid <  R) resr = query(rson, mid + 1, r, L, R);
    return merge(resl, resr);
}
    
int main() {
    int n; scanf("%d", &n);
    int sum1 = 0, sum2 = 0;
    for (int k = 1; k <= n; k++) {
        scanf(" %s", s);
        int len = strlen(s);
        for (int i = 0; i < len; i++) {
            if (s[i] == '(') stk.push(s[i]);
            else {
                if (stk.size() && stk.top() == '(') stk.pop();
                else stk.push(s[i]);
            }
        }
        pii item = {0, 0};
        while (stk.size()) {
            if (stk.top() == '(') item.second++;
            else item.first++;
            stk.pop(); 
        }
        if (item.first == 0) sum1 += item.second;
        else if (item.second == 0) sum2 += item.first;
        else vec.push_back(item);
    }
    sort(vec.begin(), vec.end());
    N = vec.size();
    for (int i = 1; i <= N; i++) {
        a[i] = vec[i - 1].first;
        v[i] = vec[i - 1].second - vec[i - 1].first;
    }
    if (N > 0) build(1, 1, N);
    for (int i = 1; i <= N; i++) {
        int p = upper_bound(a + 1, a + 1 + N, sum1) - a - 1;
        if (p == 0) {puts("No"); return 0;}
        node res = query(1, 1, N, 1, p);
        if (res.pos == -1 || sum1 < a[res.pos]) {puts("No"); return 0;}
        sum1 += v[res.pos];
        update(1, 1, N, res.pos, -INF);
    }
    sum1 == sum2 ? puts("Yes") : puts("No");
    return 0;
}

Measured memory_bytes: 10608
# -*- coding: utf-8 -*-
"""
D - Lamp
https://atcoder.jp/contests/abc129/tasks/abc129_d

"""
import sys


def solve(H, W, grid):
    res_x = [[0]*W for _ in range(H)]
    x, y = 0, 0
    while y < H:
        while x < W:
            if grid[y][x] == '#':
                x += 1
                continue
            rx = x
            while rx < W and grid[y][rx] != '#':
                rx += 1
            for xx in range(x, rx):
                res_x[y][xx] = rx-x
            x = rx
        x = 0
        y += 1

    res_y = [[0]*W for _ in range(H)]
    x, y = 0, 0
    while x < W:
        while y < H:
            if grid[y][x] == '#':
                y += 1
                continue
            ry = y
            while ry < H and grid[ry][x] != '#':
                ry += 1
            for yy in range(y, ry):
                res_y[yy][x] = ry-y
            y = ry
        y = 0
        x += 1

    ans = 0
    for y in range(H):
        for x in range(W):
            t = res_x[y][x] + res_y[y][x] - 1
            if t > ans:
                ans = t
    return ans


def main(args):
    H, W = map(int, input().split())
    grid = [input() for _ in range(H)]
    ans = solve(H, W, grid)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 126808
n = int(input())
result = "Yes"
w = []
s = input()
w.append(s)
for i in range(n - 1):
  s = input()
  if s in w:
    result = "No"
    break
  elif s[0] != w[-1][-1]:
    result = "No"
    break
  else:
    w.append(s)
print(result)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
 
#define REP(i,s,N) for (int i=s;i<(N); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


ll ans=0;

int main(){
	string S;
	cin >> S;
	size_t size = S.length();
	for(int i=0;i<size;++i){
		if(S[i]!=S[size-1-i]){
			ans++;
			S[size-1-i]=S[i];
	}
    }
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define exit(x)     cout<<x<<"\n",return
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
ll T=1;
//cin>>T;
while(T--)
  {
 // string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;

  char ch;
  cin>>ch;
if(ch=='A')
{
  cout<<"T";
}
if(ch=='T')
{
  cout<<"A";
}
if(ch=='C')
{
  cout<<"G";
}
if(ch=='G')
{
  cout<<"C";
}

 }
}

signed main(){
     
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      solve();
      return 0;
    }


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

int main(){
	int w,h,n,i,j,x,y,a,xl,xr,yl,yr;
	cin >> w >> h >> n;
	xl=0; xr=w; yl=0; yr=h;
	for(i=0; i<n; i++){
		cin >> x >> y >> a;
		if(a==1) xl=max(xl,x);
		if(a==2) xr=min(xr,x);
		if(a==3) yl=max(yl,y);
		if(a==4) yr=min(yr,y);
	}
	cout << max(0,xr-xl)*max(0,yr-yl);
}

Measured memory_bytes: 256
N = int(input())
s_list = [input() for _ in range(N)]
ans = 0
ans_list = [0, 0, 0]
for s in s_list:
  ans += s.count('AB')
  if s[0] == 'B' and s[-1] == 'A':
    ans_list[0] += 1
  elif s[0] == 'B':
    ans_list[1] += 1
  elif s[-1] == 'A':
    ans_list[2] += 1

if ans_list[1] == 0:
  if ans_list[0] != 0:
    if ans_list[2] != 0:
      ans += ans_list[0]
    else:
      ans += ans_list[0]-1
else:
  if ans_list[0] != 0:
    if ans_list[2] != 0:
      ans += ans_list[0] + min(ans_list[1], ans_list[2])
    else:
      ans += ans_list[0]
  else:
    ans += min(ans_list[1], ans_list[2])
print(ans)
	

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

int n, m;
int main(){
	cin >> n >> m;
	if(n == 1) n = 10000;
	if(m == 1) m = 10000;
	
	if(n > m) cout << "Alice" << endl;
	else if(n < m) cout << "Bob" << endl;
	else cout << "Draw" << endl;
	return 0;
}

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

int main() {
    int N, K, a = 1;
    cin >> N >> K;

    for (int i = 0; i < N; i++)
        a = (a * 2 > a + K) ? a + K : a * 2;
    cout << a << endl;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int,input().split()))

tairyoku = []
for i in range(1, 101, 1):
  all_tairyoku = 0
  for j in range(N):
    all_tairyoku += (X[j] - i) ** 2
  else:
    tairyoku.append(all_tairyoku)
else:
  print(min(tairyoku))

Measured memory_bytes: 3060
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int max(int x, int y);
int min(int x, int y);
int gcd(int x, int y);	/*最大公約数*/
int lcm(int x, int y);	/*最小公倍数*/
void swap(int* x, int* y);	/*値の交換*/
void downsort(int* a, int n);	/*降順ソート*/
void upsort(int* a, int n);	/*昇順ソート*/

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*/

int e_gcd(int x, int y)
{
	if (x < y) e_gcd(y, x);

	int r;
	r = x % y;
	while (r) {
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}

/*ここからmain関数*/

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

	if (N == 2)
	{
		cout << max(A[0], A[1]);
		return 0;
	}

	int cli, all, ans;

	int p[3];
	p[0] = e_gcd(A[1], A[2]);
	p[1] = e_gcd(A[0], A[2]);
	p[2] = e_gcd(A[0], A[1]);
	if (p[0] >= p[1] && p[0] >= p[2])
	{
		cli = 0;
	}
	else if (p[1] >= p[0] && p[1] >= p[2])
	{
		cli = 1;
	}
	else
	{
		cli = 2;
	}
	ans = p[cli];
	all = e_gcd(p[0], A[0]);

	for (int i = 3;i < N;i++)
	{
		if (all > e_gcd(ans, A[i]))
		{
			ans = all;
			cli = i;
			all = e_gcd(all, A[i]);
		}
		else if (all == e_gcd(ans, A[i]))
		{
			ans = all;
			all = e_gcd(all, A[i]);
		}
		else
		{
			ans = e_gcd(ans, A[i]);
			all = e_gcd(all, A[i]);
		}
	}

	cout << ans;


	return 0;
}

/*2数の大きい方を返す*/
int max(int x, int y)
{
	int max;

	if (x < y)
		max = y;
	else
		max = x;

	return max;
}

/*2数の小さい方を返す*/
int min(int x, int y)
{
	int min;

	if (x < y)
		min = x;
	else
		min = y;

	return min;
}

/*2数の最大公約数を返す*/
int gcd(int x, int y)
{
	int m;
	int gcd = 1;

	m = min(x, y);

	for (int i = 1;i <= m; i++)
	{
		if (x%i == 0 && y%i == 0)
			gcd = i;
	}

	return gcd;
}

/*2数の最小公倍数を返す*/
int lcm(int x, int y)
{
	int m;

	for (int i = 1;i <= y;i++)
	{
		if ((x*i) % y == 0) {
			m = x * i;
			break;
		}
	}

	return m;
}

/*2数の値を交換する*/
void swap(int* px, int* py)
{
	int temp;

	temp = *px;
	*px = *py;
	*py = temp;
}

/*クイックソートによる降順並べ替え*/
void downsort(int* a, int n)
{
	//初期設定
	int l = 0, r = n - 1;

	// ピボットの決定
	int piv = *a;

	//ピボットより大を左に、ピボット以下を右に
	while (l < r)
	{
		if (*(a + l) > piv)
			l++;
		else if (*(a + r) <= piv)
			r--;
		else
			swap(a + l, a + r);
	}

	//再帰処理
	if (n == 2)
		return;
	else if (l == 1 || l == 0)
		downsort(a + 1, n - 1);
	else if (r == n - 1)
		downsort(a, n - 1);
	else
	{
		downsort(a, l);
		downsort(a + l, n - l);
	}
}

/*クイックソートによる昇順ソート*/
void upsort(int* a, int n)
{
	downsort(a, n);

	for (int i = 0;i < n / 2;i++)
		swap(a[i], a[n - 1 - i]);
}


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

int main(int argc, char const *argv[])
{	
	int n,k;
	int ans = 0;
	cin >> n >> k;
	vector<int> L(n);
	for (int i = 0; i < n; ++i)	cin >> L.at(i);
	sort(L.begin(), L.end());
	reverse(L.begin(), L.end());
	for (int i = 0; i < k; ++i)	ans += L.at(i);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  bool found = false;
  for (int i = 1; i < 4; ++i) {
    if (s[i] == s[i - 1]) found = true;
  }
  if (found) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
  return 0;
}


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

int main(){
    for(int i=0;i<1e6;i++){
        cerr<<"Wrong Answer"<<endl;  
    }
    long long x,y; cin>>x>>y;
    cout<<(x%y==0 ? -1 : x)<<endl;
    return 0;
}

Measured memory_bytes: 384
#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;

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue
#define    nl           "\n"
#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()

#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define repab(i,a,b) for(int i=(a);i<=(b);i++)
#define reprab(i,a,b) for(int i=(a);i>=(b);i--)
#define repll(i,a,b) for(ll i=(a);i<=(b);i++)
#define rep(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)
#define tc int t;cin>>t;while(t--)
template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
    double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
    time_taken *= 1e-9;
    cout << "\nExecuted in: " << fixed
         << time_taken << setprecision(9);
    cout << " sec";
#endif
}

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

ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................


int main()
{   
     auto start = chrono::high_resolution_clock::now();
    fast
    ll x;
    cin>>x;
    ll cnt=1;
    ll sum=x;
    while(sum%360!=0){
        sum=sum+x;
        cnt++;
    }
    cout<<cnt<<nl;
    auto end = chrono::high_resolution_clock::now();
    TIME(start, end);
    return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define gc getchar()
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
const int mod = 1e9+7;
inline int read(){char ch=gc;int w=1,s=0;while(!isdigit(ch)){if(ch=='-') w=-1;ch=gc;};while(isdigit(ch)){s=s*10+ch-'0';ch=gc;} return w*s;}
int A[100010],n,m,fac[2000010],Ifac[2000010];
int f[18][1<<17];
inline int C(int p,int q)
{
	return 1ll*fac[p]*Ifac[q]%mod*Ifac[p-q]%mod;
}
inline ll ksm(ll x,ll y){ll res=1; while(y){if(y&1) res=res*x%mod;x=x*x%mod;y>>=1;} return res;}
inline void Init()
{
	Ifac[0]=1;fac[0]=1;
	for(rint i=1;i<=2e6;++i) fac[i]=1ll*fac[i-1]*i%mod;
	Ifac[2000000]=ksm(fac[2000000],mod-2);
	for(rint i=(2e6)-1;i;--i) Ifac[i]=1ll*Ifac[i+1]*(i+1)%mod;
}inline bool cmp(int a,int b) {return a>b;}
inline ll add(ll a,ll b){a+=b;if(a>=mod) a-=mod;return a;}
int main()
{
	n=read(),m=read();
	for(rint i=1;i<=m;++i) A[i]=read();
	sort(A+1,A+m+1,cmp);Init();
	f[0][0]=1;int Max=1<<n;
	for(rint i=1;i<=m;++i)
	{
		for(rint j=0;j<Max;++j) f[i][j]=add(f[i][j],f[i-1][j]);
		for(rint j=0;j<Max;++j)
		{
//			int total=0;
//			for(rint k=1;k<=n;++k)
//			{
//				if((1<<k-1)&j) total+=(1<<k-1);
//			}
			int rest=(1<<n)-j-A[i];
			for(rint k=1;k<=n;++k)
			{
				if((1<<k-1)&j) continue;
				else 
				{
					if((1<<k-1)-1>rest) continue;
					f[i][j|(1<<k-1)]=add(f[i][j|(1<<k-1)],1ll*f[i-1][j]*C(rest,(1<<k-1)-1)%mod*fac[1<<k-1]%mod);
				}
			}
		}
	}ll res=0;
	for(rint i=0;i<Max;++i)
	{
//		cout<<f[m][i]<<"\n";
		int cnt=__builtin_popcount(i);
		if(cnt&1)
		{
			res=add(res,mod-1ll*f[m][i]*fac[ksm(2,n)-i-1]%mod);
		}
		else res=add(res,1ll*f[m][i]*fac[ksm(2,n)-i-1]%mod);
	}cout<<1ll*res*ksm(2,n)%mod<<"\n";
	return 0;
}

Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vl a(n);
	cin>>a;
	vvl dp(n+1,vl(5,LINF));
	dp[0]={0,0,0,0,0};
	rep(i,n){
		rep(j,5){
			ll diff=0,diff2=0;
			if(j%4==0 and a[i]!=0)diff=a[i];
			if(j%2==1 and a[i]%2!=0)diff=1;
			if(j%2==1 and a[i]==0)diff=2;
			if(j==2 and a[i]%2!=1)diff=1;
			rep(k,j+1)chmin(dp[i+1][j],dp[i][j-k]+diff);
		}
	}
	//rep(i,n+1)puta(dp[i]);
	puta(min(dp[n]));
	return 0;
}

Measured memory_bytes: 17920
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<vector<int>> e(n);
    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        e[a].emplace_back(b);
        e[b].emplace_back(a);
    }
    vector<int> mini(n, -INF), maxi(n, INF), color(n, -1), pv(n, -1);
    auto coloring = [&](auto f, int curr, int prev) -> void {
        for (auto &to: e[curr]) {
            if (to == prev) continue;
            color[to] = !color[curr];
            f(f, to, curr);
        }
    };

    bool ok = true;
    int k, st; cin >> k;
    for (int i = 0; i < k; i++) {
        int v, p; cin >> v >> p; v--;
        mini[v] = maxi[v] = pv[v] = p;
        if (i == 0) {
            st = v;
            color[v] = p & 1;
            coloring(coloring, v, -1);
        } else {
            if ((p & 1) != color[v]) ok = false;
        }
    }
    auto dfs = [&](auto f, int curr, int prev) -> void {
        for (auto &to: e[curr]) {
            if (to == prev) continue;
            f(f, to, curr);
            mini[curr] = max(mini[curr], mini[to] - 1);
            maxi[curr] = min(maxi[curr], maxi[to] + 1);
        }
        if (mini[curr] > maxi[curr]) ok = false;
        if (pv[curr] != -1) {
            if (!(mini[curr] <= pv[curr] && pv[curr] <= mini[curr])) ok = false; 
        }
    };
    dfs(dfs, st, -1);
    if (!ok) cout << "No\n";
    else {
        cout << "Yes\n";
        auto dfs2 = [&](auto f, int curr, int prev) -> void {
            if (pv[curr] == -1) {
                if (mini[curr] <= pv[prev] + 1 && pv[prev] + 1 <= maxi[curr]) pv[curr] = pv[prev] + 1;
                else pv[curr] = pv[prev] - 1;
            }
            for (auto &to: e[curr]) {
                if (to == prev) continue;
                f(f, to, curr);
            }
        };
        dfs2(dfs2, st, -1);
        for (int i = 0; i < n; i++) {
            cout << pv[i] << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 14208
#include<stdio.h>
#include<limits.h>

#define N 100


void MatrixChainOrder(int[N] ,int);
int Mini(int, int);
int A[N][N];

int main(){

  int n,i,a,p[N];

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  MatrixChainOrder(p,n);

printf("%d\n",A[1][n]);

  return 0;
}

void MatrixChainOrder(int p[N] , int n){

  int i,j,l,k,q;

  for(i=1;i<=n;i++) A[i][i]=0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      A[i][j]=INT_MAX;
      for(k=i;k<j;k++){
	q=A[i][k]+A[k+1][j]+p[i-1]*(p[k])*(p[j]);
	A[i][j]=Mini(A[i][j],q);
      }
    }
  }

}

int Mini(int a , int b){

  if(a < b) return a;
  else return b;
} 

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

using namespace std;

typedef long long int ll;
#define pb push_back
#define ALL(a) (a).begin() , a.end()

int mod = 1e9 + 7;
int add(int a, int b){
	if(a + b >= mod)return a+ b - mod;
	return a + b;
}
int mul(int a, int b){
	return 1LL * a * b  % mod;
}
int const N = 100 * 1010;

/********************i**********************************/
void solve(){
	int n, m;
	cin >> n;
	vector<vector<long double>> dp(n+1, vector<long double> (n + 1, 1));
	vector<long double> vec(n);
	for(auto &a : vec)cin >> a;
	dp[1][1] = vec[0];
	dp[1][0] = 1.0 - vec[0];
	for(int x  =1; x<n; x++){
		long double d = 1.0 - vec[x];
		for(int y = 0; y<=x; y++)
		{
			dp[x+1][y] = dp[x][y] * d;
			if(y > 0)
			dp[x+1][y] += dp[x][y-1] * vec[x];
		}
		dp[x+1][x+1] = dp[x][x] * vec[x];
	}
	long double ans = 0;
	for(int x = n/2+1; x<= n; x++)ans += dp[n][x];
	cout << setprecision(15) << fixed << ans;
}


/******************************************************/
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	int t;
	t = 1;
	// cin >> t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 141056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(int i=int(x);i<int(y);++i)
#define For(i,x,y)  for(int i=int(x);i<=int(y);++i)
#define FOr(i,x,y)  for(int i=int(x);i>=int(y);--i)
#define pi acos(-1) 
#define mk make_pair
#define pa pair<ll,ll>
#define lf else if
#define IL inline
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
#define Add(x,y)    ((x)=((x)+(y))%mod)
#define Max(x,y)    ((x)=((x)<(y)?(y):(x)))
#define Min(x,y)    ((x)=((x)>(y)?(y):(x)))
#define E(x)        return writeln(x),0
#define LL			(long long)
#define p(x)        printf("~%lld~\n",LL(x))
#define pp(x,y)     printf("~~%lld %lld~~\n",LL(x),LL(y))
#define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",LL(x),LL(y),LL(z))
#define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",LL(a),LL(b),LL(c),LL(d))
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define fi first
#define se second
#define GuYue		puts("\nGuYueNa________________________________________________________________________________")
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_; 
#endif 
#define NEG 1
    static const int GYN=2333333;
    char SZB[GYN],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,GYN,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,g=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') g=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*g; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);}
	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);}
	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);}
	void writeln(ll x){write(x);puts("");}
}using namespace SHENZHEBEI;
ll a[200010];
map<ll,ll>mp;
ll n,ans;
int main(){
	n=read();++mp[0];
	For(i,1,n){
		a[i]=read()+a[i-1];
		ans+=mp[a[i]]++;
	}writeln(ans);
}

Measured memory_bytes: 16384
#include<stdio.h>

int main(void){
 int n,d,sum=0,num=0;
 int cnt[100000]={};
  scanf("%d",&n);
 for(int i=0;i<n;i++){
   scanf("%d",&d);
   cnt[d]++;
 }
 for(int i =0;i<100000;i++){
   sum += cnt[i];
   if(sum > n/2)break;
   if(sum == n/2)num++;
 }
  printf("%d",num);
 return 0;   
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	/* several useful subroutines */
	private static BufferedReader brStdin = new BufferedReader(new InputStreamReader(System.in));
	private static String[] readBuf = null;
	private static int readPtr = 0;
	private static String getString() throws IOException {
		while ( readBuf == null || readPtr >= readBuf.length ) {
			readBuf = brStdin.readLine().split(" ");
			readPtr = 0;
		}
		return readBuf[readPtr++];
	}
	private static int getInt() throws IOException {
		return Integer.parseInt(getString());
	}
	private static long getLong() throws IOException {
		return Long.parseLong(getString());
	}
	private static BigDecimal getBD() throws IOException {
		return new BigDecimal(getString());
	}
	@SuppressWarnings("unused")
	private static String[] getStringArray(int size) throws IOException {
		String stringArray[] = new String[size];
		for (int i = 0; i < stringArray.length; i++) {
			stringArray[i] = getString();
		}
		return stringArray;
	}
	@SuppressWarnings("unused")
	private static int[] getIntArray(int size) throws IOException {
		int intArray[] = new int[size];
		for (int i = 0; i < intArray.length; i++) {
			intArray[i] = getInt();
		}
		return intArray;
	}
	@SuppressWarnings("unused")
	private static long[] getLongArray(int size) throws IOException {
		long longArray[] = new long[size];
		for (int i = 0; i < longArray.length; i++) {
			longArray[i] = getLong();
		}
		return longArray;
	}
	@SuppressWarnings("unused")
	private static BigDecimal[] getBDArray(int size) throws IOException {
		BigDecimal bdArray[] = new BigDecimal[size];
		for (int i = 0; i < bdArray.length; i++) {
			bdArray[i] = getBD();
		}
		return bdArray;
	}
	@SuppressWarnings("unused")
	private static long calculateLCM(long a, long b) throws IOException {
		if ( a  < b ) {
			long t = a;
			a = b;
			b = t;
		}
		while ( b > 0 ) {
			long t = b;
			b = a % b;
			a = t;
		}
		return a;
	}

	
	/* main routine */
	
	public static void main(String args[]) throws IOException {
		int n = getInt();
		char s[] = getString().toCharArray();

		int cnt = 1;
		for ( int i = 1 ; i < n ; i++ ) {
			if ( s[i] != s[i-1] ) {
				cnt++;
			}
		}
		
		System.out.println(cnt);
	}
}


Measured memory_bytes: 23252
#include<iostream>
#include<set>
using namespace std;
int main()
{
	int n, m;

	cin >> n >> m;
	multiset<long, greater<long> > a;

	int i, j, k;
	long tmp;
	for (i = 0; i < n; i++) {
		cin >> tmp;
		a.insert(tmp);
	}

	multiset<long, greater<long> >::iterator it;
	for (i = 0; i < m; i++) {
		it = a.begin();
		a.insert((*it) / 2);
		a.erase(it);
	}

	long ans = 0;
	for (it = a.begin(); it != a.end(); it++) {
		ans += (*it);
	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 4992
// C.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;
typedef long long LL;

int main(int argc, char *argv[])
{
	string s;
	cin >> s;
	bool ans = true;
	for (int i = 0; i != s.length(); ) {
		if (i <= (s.length() - 5)) {
			if (strncmp(s.c_str() + i, "dream", 5) == 0) {
				if (i <= (s.length() - 8)) {
					if (strncmp(s.c_str() + i, "dreamera", 8) == 0) {
						i += 5;
						continue;
					}
				}
				i += 5 + ((i <= (s.length() - 7) && s[i + 5] == 'e' && s[i + 6] == 'r') ? 2 : 0);
				continue;
			}
			if (strncmp(s.c_str() + i, "erase", 5) == 0) {
				i += 5 + ((i <= (s.length() - 6) && s[i + 5] == 'r') ? 1 : 0);
				continue;
			}
		}
		ans = false;
		break;
	}
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main(){
int N;
cin>>N;
int K;
cin>>K;
vector<int> dp(N, INT_MAX);
vector<int> h(N);
for(int i=0;i<N;++i)
{
	cin>>h[i];
}
dp[0] = 0;
dp[1] = abs(h[1] -h[0]);

for(int i = 2; i < N; ++i)
{
  for(int k = 1; k <= min(K, i); ++k)
  {
    dp[i] = min(dp[i - k]+abs(h[i]-h[i-k]), dp[i]);
  }
}
cout<<dp[N - 1]<<endl;
}


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

using namespace std;
int main (){
    string s;
    cin >> s;
    int len = s.size();
    int num[len];
    for (int i = 0; i < len; i++){
        num[i] = s[i];
        num[i]-=48;
    }
    int comp;
    int min=999;
    for (int i = 0; i < len-2; i++){
        comp=std::abs(num[i]*100+num[i+1]*10+num[i+2]-753);
        if(comp<min) min=comp;
    }
    cout << min << "\n";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    
    if(n / 10 / 111 * 111 == n / 10 || n % 1000 / 111 * 111 == n % 1000){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


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

const int N = 1e6 + 100;

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    int t = n/2;
    string ss;
    while(t--) ss += "hi";
    if(s == ss) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



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

int main(){
	int n;
	int cnt = 0;
	scanf("%d",&n);
	for(int i = 1;i < n/2+1;i++){
		int j = n - i;
		if(j != i) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	string date1[36],date2[36];
	for(int i = 0; i < n; i++){
		cin >> date1[i];
		date2[i] = date1[i];
	}

	for(int i = 0; i < n; i++)
        for(int j = n -1; j > i; j--)
            if(date1[j-1][1] > date1[j][1])
                swap(date1[j-1],date1[j]);
    
	for(int i = 0; i < n - 1; i++){
        int min = i;
        for(int j = i + 1; j < n; j++)
            if(date2[min][1] > date2[j][1])
                min = j;
        
        if(min != i) 
            swap(date2[i],date2[min]);
    }
 
	for(int i = 0; i < n - 1; i++) cout << date1[i] << " "; cout << date1[n-1] << endl;
	cout << "Stable" << endl;
	for(int i = 0; i < n - 1; i++) cout << date2[i] << " "; cout << date2[n-1] << endl;
	int flag = 0;
	for(int i = 0; i < n; i++)
		if(date1[i] != date2[i]){flag++; break;}

	if(!flag) cout << "Stable";
	else cout << "Not stable";
	cout << endl;
}

Measured memory_bytes: 1216
dic = {}
N = int(input())

for n in range( N ):
    s = input()
    s1 = list( s )     
    s1.sort()
    s2 = ''.join(s1)

    if s2 in dic:
        dic[ s2 ] += 1
    else:
        dic[ s2 ] = 1

total = 0
for n in dic.values():
    if n >= 2:
        num = n * ( n - 1 ) // 2
        total += num

print( total )


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

int main() {
	int w,n;cin>>w>>n;
	int a[w+1];
	for(int i=1;i<=w;i++)a[i]=i;
	int b,c;
	for(int i=0;i<n;i++)
	{
		scanf("%d,%d",&b,&c);
		swap(a[b],a[c]);
	}
	for(int i=1;i<=w;i++)cout<<a[i]<<endl;
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
using namespace std; 
int main() { 
  int a[3], count[3]={}, check=0;  
  while(cin >> a[0] >> a[1] >> a[2]) { 
    if(check==0) { 
      sort(a, a+3);   
      if(a[0]+a[1]<=a[2]) {  
	check = 1; 
	continue;  
      }   
      if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]) count[0]++;   
      else if(a[0]*a[0]+a[1]*a[1] > a[2]*a[2]) count[1]++; 
      else if(a[0]*a[0]+a[1]*a[1] < a[2]*a[2]) count[2]++; 
    }
  } 
  cout << count[0]+count[1]+count[2] << " " << count[0] << " " << count[1] << " " << count[2] << endl;
  return 0;
}


Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}
ll RepeatSquaring(ll n, ll p, ll m) {
  if (p == 0) return 1;
  if (p%2 == 0) {
    ll t = RepeatSquaring(n, p/2, m);
    return (t*t)%m;
  }
  return (n*RepeatSquaring(n, p-1, m))%m;
}

int main() {
  ll n;
  cin >> n;
  if (n%2 == 1) {
    cout << n/2 + 1 << endl;
  } else {
    cout << n/2 << endl;
  }
}

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

using namespace std;

int main() {
    
    int n;
    string s;
    cin >> n >> s;

    for (char x: s) {
        int y = x - 'A';
        int v = (y + n) % 26;
        cout << (char)(v + 'A');
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#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=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll n;
    cin >> n;
    VL a(n);
    REP(i,n){
        a[i] = in();
    }
    sort(ALL(a));
    reverse(ALL(a));

    int x = 1;
    while (x < n - 1 && a[x] > 0) x++;

    ll sum = a[x];
    vector<PL> ans;
    FORR(i,x-1,1){
        ans.push_back(PL(sum, a[i]));
        sum -= a[i];
    }
    ans.push_back(PL(a[0], sum));
    sum = a[0] - sum;
    FOR(i,x+1,n-1){
        ans.push_back(PL(sum, a[i]));
        sum -= a[i];
    }

    cout << sum << endl;
    REP(i,n-1){
        printf("%lld %lld\n", ans[i].first, ans[i].second);
    }
    return 0;
}


Measured memory_bytes: 4336
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int main() {
	int A[50];
	int n, l, r;
	while (cin >> n >> l >> r, n) {
		for (int i = 0; i < n; i++) cin >> A[i];
		int ans = 0;
		for (int i = l; i <= r; i++) {
			int idx = -1;
			for (int j = 0; j < n; j++) {
				if (i%A[j] == 0) {
					idx = j + 1;
					break;
				}
			}
			if (idx == -1) {
				if (n % 2 == 0) ans++;
			}
			else {
				if (idx % 2) ans++;
			}
		}
		cout << ans << endl;
	}
}


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

namespace ABC147C
{
    class Program
    {
        static int ans = 0;
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            List<int> x = new List<int>();
            List<int> y = new List<int>();
            for(int i = 0; i < N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
                for(int j = 0; j < A[i]; j++)
                {
                    string[] xy = Console.ReadLine().Split(' ');
                    x.Add(int.Parse(xy[0]));
                    y.Add(int.Parse(xy[1]));
                }
            }
            int[] s = new int[N];
            tansaku(s, N, 0, A, x, y, 0);
            tansaku(s, N, 0, A, x, y, 1);
            Console.WriteLine(ans);
        }
        static void tansaku(int[] s, int N, int count, int[] A, List<int> x, List<int> y, int m)
        {
            if (count == N)
            {
                int l = s.Length;
                bool hantei = true;
                int syoujiki = 0;
                int num = 0;
                for (int j = 0; j < l; j++)
                {
                    if (s[j].ToString() == "1")
                    {
                        syoujiki += 1;
                        for (int k = num; k < num + A[j]; k++)
                        {
                            if (s[x[k] - 1] != y[k])
                            {
                                hantei = false;
                            }
                        }
                        num += A[j];
                    }
                    else
                    {
                        num += A[j];
                    }
                }

                if (hantei == true)
                {
                    if (syoujiki > ans)
                    {
                        ans = syoujiki;
                    }
                }
            }
            else
            {
                s[count] = m;
                tansaku(s, N, count + 1, A, x, y, 0);
                tansaku(s, N, count + 1, A, x, y, 1);

            }

        }
    }
}


Measured memory_bytes: 27824
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N;
  cin>>N;
  ll ans = 0;
  ll num;
  for(ll i=1;i<=N;++i) {
    num = N/i;
    ans += i*num*(num+1)/2;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define N 1000000
using namespace std;
typedef long long ll;
ll a[N],b[N],c[N];
int n;
int get(int l,int r,int s,ll x,ll y){
	if (c[r]<x||y<c[l])return 0;
	if (x<=c[l]&&c[r]<=y)return r-l+1;
	return get(l,(l+r)/2,s+s,x,y)+get((l+r)/2+1,r,s+s+1,x,y);
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<=n;i++)cin>>a[i];
	for (int i=1;i<=n;i++)cin>>b[i];
	ll ans=0;
	for (unsigned long long i=1;i<(1<<30);i<<=1){
		for (int j=1;j<=n;j++)c[j]=b[j]%(i<<1);
		sort(c+1,c+n+1);
		bool sig=0;
		ll l1=i,r1=(i<<1)-1,l2=i+(i<<1),r2=(i<<2)-1;
		for (int j=1;j<=n;j++){
			ll v=a[j]%(i<<1);
			sig^=((get(1,n,1,l1-v,r1-v)+get(1,n,1,l2-v,r2-v))&1);
		}
		ans+=sig*i;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int l[maxn],r[maxn];
int main()
{
	int n,m;
	int r=1000000,l=-1;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		l=max(l,x);
		r=min(r,y);
	}
	if(l>r) cout<<0;
	else cout<<r-l+1;
	return 0;
}

Measured memory_bytes: 256
import fractions


def run(n, a):
    '''
    g = a[0]
    for j in range(1, len(a)):
        g = int(g * a[j] / fractions.gcd(g, a[j]))
    m = g
    tmp_f = 0
    f = 0
    for i in range(1, m+1):
        tmp_f = 0
        for j in range(len(a)):
            tmp_f += i % a[j]
        f = max(f, tmp_f)
    '''
    f = 0
    for i in range(len(a)):
        f += a[i] - 1
    return f


def read_line():
    n = int(input())
    a = list(map(int, input().split()))
    return (n, a)


def main():
    n, a = read_line()
    print(run(n, a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5340
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int a, b, c, x, y;
	int min = 1000000;
	cin >> a >> b >> c;

	min = a + b;
	x = a + c;
	if (min > x) {
		min = x;
	}

	y = b + c;
	if (min > y) {
		min = y;
	}
	
	cout << min << endl;
}

Measured memory_bytes: 256
from collections import Counter
n, k, l = map(int, input().split())
def find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x], par)
        return par[x]
def unite(x, y, par):
    p = find(x, par)
    q = find(y, par)
    if p == q:
        return None
    if p > q:
        p, q = q, p
    par[p] += par[q]
    par[q] = p
def same(x, y):
    return find(x) == find(y)
def size(x):
    return -par[find(x)]
road_par = [-1 for i in range(n + 1)]
train_par = [-1 for i in range(n + 1)]
for i in range(k):
    p, q = map(int, input().split())
    unite(p, q, road_par)
for i in range(l):
    r, s = map(int, input().split())
    unite(r, s, train_par)
ans = []
for i in range(n):
    ans.append((find(i + 1, road_par), find(i + 1, train_par)))
c = Counter(ans)
for i in ans:
    print(c[i], end=" ")

Measured memory_bytes: 52736
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, M1);
    IN(ll, D1);
    IN(ll, M2);
    IN(ll, D2);
    YES(M1 < M2, "1", "0");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
using namespace std;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

int main()
{
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if (k > a){
        k -= a;
        ans = a;
        k -= b;
        if (k > 0)
        {
            ans -= k;
        }
    }
    else
    {
        cout << k << endl;
        return 0;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    long n,ans=0,cnt=0;
    cin >> n;
    long a[n];
    rep(i,n) cin >> a[i];
    rep(i,n){
       if(a[i]!=0) cnt += a[i];
       if(a[i]==0||i==n-1){
           ans += cnt/2;
           cnt = 0;
       }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
n = int(input())
l = list(map(int,input().split()))

j = 0
new = []
while True:
    for m,i in enumerate(l):
        if i % 2 == 0:
            l[m] = i/2
            
            if m+1 == n:
                j +=1
        else:
            print(j)
            exit()
        


Measured memory_bytes: 2940