akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize(2)
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
    int f=1,x=0;char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return f==1?x:-x;
}
#define lch (i<<1)
#define rch (i<<1|1)
#define MAXN 100000
#define INF 0x3f3f3f3f
struct node{
	int a,b;
	friend bool operator < (node x,node y){return x.b==y.b?x.a>y.a:x.b>y.b;}
}task[MAXN+5];
int tree[5*MAXN+5];
void Build(int i,int L,int R){
	if(L==R){
		tree[i]=L;
		return ;
	}
	int Mid=(L+R)>>1;
	Build(lch,L,Mid);
	Build(rch,Mid+1,R);
	tree[i]=max(tree[lch],tree[rch]);
	return ;
}
int Query(int i,int L,int R,int ql,int qr){
	if(ql<=L&&R<=qr)
		return tree[i];
	int Mid=(L+R)>>1,ret=-1;
	if(ql<=Mid) ret=max(ret,Query(lch,L,Mid,ql,qr));
	if(Mid+1<=qr) ret=max(ret,Query(rch,Mid+1,R,ql,qr));
	return ret;
}
void Insert(int i,int L,int R,int p){
	if(L==R){
		tree[i]=-1;
		return ;
	}
	int Mid=(L+R)>>1;
	if(p<=Mid) Insert(lch,L,Mid,p);
	else Insert(rch,Mid+1,R,p);
	tree[i]=max(tree[lch],tree[rch]);
	return ;
}
int main(){
	int n=read(),m=read();
	for(int i=1;i<=n;i++){
		int a=read(),b=read();
		task[i]=(node){a,b};
	}
	Build(1,0,m);
	int t=0;
	LL ans=0;
	sort(task+1,task+n+1);
	for(int i=1;i<=n;i++){
		if(m-task[i].a<0)
			continue;
		int tmp=Query(1,0,m,0,m-task[i].a);
		if(tmp==-1)
			continue;
		Insert(1,0,m,tmp);
		ans+=task[i].b;
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 2048
#include<stdio.h>
#include<math.h>
int main(void){
    int s[1005]={0};
    int n=0;
    double ave=0.0,ans=0.0,sum=0.0;
    double temp=0.0;
    int i;
    while(1){
        sum=0.0;
        temp=0.0;
        scanf("%d",&n);
        if(n==0)
            break;
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
            sum+=s[i];
        }
        ave=sum/n;
        for(i=0;i<n;i++)
            temp+=(s[i]-ave)*(s[i]-ave);
        ans=sqrt(temp/n);
        printf("%lf\n",ans);
    }
    return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)


struct Edge{
    int from;
    int to;
    int dist;
};

using Graph = vector<vector<Edge>>;

int main(){
    int n;
    cin>>n;
    Graph G(n);
    
    int u,v,w;
    for(int i=0;i<n-1;i++){
        cin>>u>>v>>w;
        Edge hen;
        hen.from = u-1, hen.to = v-1, hen.dist = w % 2;
        G[u-1].push_back(hen);
        hen.from = v-1, hen.to = u-1, hen.dist = w % 2;
        G[v-1].push_back(hen);
    }

    vector<int> distance(n,-1);
    queue<int> que;

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

    vector<int> ans(n,0);

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

        for(auto nv : G[pv]){
            if(distance[nv.to] != -1) continue;

            distance[nv.to] = distance[pv] + nv.dist;
            if(distance[nv.to] % 2 == 0) ans[nv.to] = 0;
            else ans[nv.to] = 1;

            que.push(nv.to);
        }
    }

    for(int i=0;i<n;i++) cout<<ans[i]<<endl;
}

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

using namespace std;

int w,h;
char F[52][52][2];
int check(int x, int y, char a, int wb)
{
    if(F[x-1][y][wb] == '.')
    {
        F[x-1][y][wb] = a;
        check(x-1,y,a,wb);
    }
    if(F[x+1][y][wb] == '.')
    {
        F[x+1][y][wb] = a;
        check(x+1,y,a,wb);
    }
    if(F[x][y-1][wb] == '.')
    {
        F[x][y-1][wb] = a;
        check(x,y-1,a,wb);
    }
    if(F[x][y+1][wb] == '.')
    {
        F[x][y+1][wb] = a;
        check(x,y+1,a,wb);
    }
}
int main()
{
    int flag;
    int nw, nb;
    char a, b;
    while(cin >> w >> h && w && h)
    {
        nw = 0; nb = 0;
        for(int j=1;j<=h;++j){
            F[0][j][0]='A';
            F[0][j][1]='A';
            F[w+1][j][0]='A';
            F[w+1][j][1]='A';
            for(int i=1;i<=w;++i){
                F[i][0][0]='A';
                F[i][0][1]='A';
                F[i][h+1][0]='A';
                F[i][h+1][1]='A';
                cin >> F[i][j][0];
                F[i][j][1] = F[i][j][0];
            }
        }
        for(int k=0;k<2;++k){
            if(k==0) a='w', b='W';
            if(k==1) a='b', b='B';
            for(int j=1;j<=h;++j){
                for(int i=1;i<=w;++i){
                    if(F[i][j][k] == b) check(i,j,a,k);
                }
            }
        }
        for(int j=1;j<=h;++j){
            for(int i=1;i<=w;++i){
                if(F[i][j][0] == 'w' && F[i][j][1]== '.') ++nw;
                else if(F[i][j][1] == 'b' && F[i][j][0] == '.')++nb;
            }
        }
        cout << nb << " " << nw << endl;
    }
}

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 998244353;



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

	VI a(n);
	

	REP(i, n) {
		cin >> a[i];
	}

	ll ans = a[0] - 1;
	a[0] = 1;

	
	int di = 1;

	REP(i, n) {
		if (di > a[i])continue;
		if (di == a[i]) {
			di++;
			continue;
		}
		if (a[i] % di == 0) {
			ans += a[i] / di - 1;
		}
		else {
			ans += a[i] / di;
		}
	}
	cout << ans << endl;


}




Measured memory_bytes: 640
#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: 11888
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(6);
    double pi=3.141592653589793238462643;
    double r;cin>>r;
    cout<<2*r*pi<<endl;
    return 0;
}


Measured memory_bytes: 3800
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

public class Cell
{
    public int X { get; set; }
    public int Y { get; set; }
    public string CellType { get; set; }
    public int Step { get; set; }

    public static Cell[] GetCells(char[] row, int y)
    {
        var cells = Enumerable.Range(0, row.Length).Select(x => new Cell
        {
            X = x + 1,
            Y = y,
            CellType = Convert.ToString(row[x]),
            Step = -1,
        });
        return cells.ToArray();
    }

}


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var n = Read();
        var input = Reads();
        var t = input[0];
        var a = input[1];
        input = Reads();
        var d = new long[n];
        for(int i = 0; i < n; i++)
        {
            d[i] = (long)(Math.Abs(a-(t - input[i] * 0.006))*1000);
        }
        long min=0;
        for(int i = 0; i < n; i++)
        {
            if (d.Min() == d[i])
            {
                min = i;
            }
        }
        Console.WriteLine(min + 1);

        Console.Out.Flush();
    }
}


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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("C.in", "r", stdin);
	freopen ("C.out", "w", stdout);
#endif
}

const int N = 1e3 + 1e2, Mod = 1e9 + 7;

bool isprime[N];

int main () {

	File();

	int n = read(), ans = 1;

	Set(isprime, true);
	For (i, 2, n) if (isprime[i]) {
		int cur = 1;
		for (int j = i; j <= n; j += i) {
			isprime[j] = false;
			for (int x = j; !(x % i); x /= i) ++ cur;
		}
		ans = 1ll * ans * cur % Mod;
	}
	printf ("%d\n", ans);

    return 0;

}

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

long long cnt;
int l, A[1000000], n;
vector<int> G;

//間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g) {
	for (int i = g; i < n; i++) {
		int v = A[i];
		int j = i - g;
		while(j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j -= g;
			cnt++;
		}
		A[j + g] = v;
	}
}

void shellSort(int A[], int n) {
	//数列G = {1, 4, 13, 40, 121, 364, 1093, ...}
	for (int h = 1; ; ) {
		if (h > n) break;
		G.push_back(h);
		h = 3 * h + 1;
	}

	for (int i = G.size() - 1; i >= 0; i--) { //逆順にG[i] = gを指定
		insertionSort(A, n, G[i]);
	}
}

int main() {
	cin >> n;
	//より速い入力scanf関数を使用
	for (int i = 0; i < n; i++) scanf("%d", &A[i]);
	cnt = 0;

	shellSort(A, n);

	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--) {
		printf("%d", G[i]);
		if (i) printf(" ");
	}
	printf("\n");
	printf("%d\n", cnt);
	for (int i = 0; i < n; i++) printf("%d\n", A[i]);

	return 0;
}


Measured memory_bytes: 7180
n=int(input())
w=n
for i in range(0,n+1,6):
    i2=n-i
    s=0
    for j in range(6):#1入らない
        ds=i//6**(6-j)
        s+=ds
        i-=ds*6**(6-j)
    for  j in sorted(range(6),reverse=True):
        ds=i2//9**j
        s+=ds
        i2-=ds*9**j
    if s<w:
        w=s
print(w)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main()
{
	int a, b;
	while(true)
	{
		cin >> a >> b;
		if(a == 0 && b == 0)
			break;
		for(int i = 0;i < a;i++)
		{
			if(i == 0 || (i == (a - 1)))
			{
				for (int j = 0; j < b; j++)
					cout << "#";
			}else
			{
				cout << "#";
				for(int j = 1;j < b - 1;j++)
					cout << ".";
				if (b > 1)
					cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>
#include<math.h>
int prime(int);

int main(void){
    int n;
    scanf("%d",&n);
    int a,ans=0;
    for(a=1;a<=n;a++){
        int num;
        scanf("%d",&num);
        if(prime(num)==0){
            ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

int prime(int b){
    int i=2;
    while(i<=sqrt(b)){
        if(b%i==0){
            return 1;
        }else{
            i++;
        }
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <iterator>
#include <cstdio>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <chrono>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		} else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right) {
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;

int main(void) {
	int a;
	cin >> a;
	judge_outer(a > 999, "ABD", "ABC");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,h[100001],a,sum,i,b,box[100001];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&h[i]);
	}
	box[1]=0;
	box[2]=h[1]-h[2];
	if(box[2]<0){
		box[2]=-box[2];
	}
	for(i=3;i<=n;i++){
		a=h[i-2]-h[i];
		b=h[i-1]-h[i];
		if(a<0){
			a=-a;
		}
		if(b<0){
			b=-b;
		}
		a=a+box[i-2];
		b=b+box[i-1];
		if(a<b){
			box[i]=a;
		}
		else{
			box[i]=b;
		}
	}
    printf("%d\n",box[n]);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

int s[510][510];

int main(void){
    int n,m,q,l,r;
    cin>>n>>m>>q;
    for(int i=0;i<m;i++){
        cin>>l>>r;
        s[l][r]++;
    }
    for(int i=0;i<=500;i++){
        for(int j=0;j<=500;j++){
            s[i][j+1]+=s[i][j];
        }
    }
    for(int i=0;i<q;i++){
        cin>>l>>r;
        int ans=0;
        for(int j=l;j<=r;j++){
            ans+=s[j][r]-s[j][l-1];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 1920
#include<cstdio>
#include<set>
using namespace std;
set<int>s;
set<int>:: iterator it;

int ans=0,i,n,x;
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%d",&x);
		//it=s.find(x);
		if (s.count(x)==1)
		{
			it=s.find(x);
			s.erase(it);
			ans--;
		}
		else
		{
			ans++;
			s.insert(x);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 4864
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n, a, b string
	fmt.Scan(&n, &a, &b)
	N, _ := strconv.ParseInt(n, 10, 64)
	A, _ := strconv.ParseInt(a, 10, 64)
	B, _ := strconv.ParseInt(b, 10, 64)

	var res int64
	// fmt.Println(N, A, B)

	if (B-A)%2 == 0 {
		res = (B - A) / 2
	} else {
		oneA := A - 1
		oneB := B - 1
		AN := N - A
		BN := N - B

		ABDistance := oneA + oneB
		// fmt.Println(ABDistance)
		ANBNDistance := AN + BN
		// fmt.Println(ANBNDistance)
		var distance int64

		if ABDistance > ANBNDistance {
			distance = ANBNDistance
		} else {
			distance = ABDistance
		}

		if distance%2 == 0 {
			res = distance / 2
		} else {
			res = (distance + 1) / 2
		}

	}
	fmt.Println(res)
}


Measured memory_bytes: 512
// 2020-07-15 23:13:36
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

vector<int> vs;
int dp[55][55][105];
int rec(int l, int r, int k) {
  if(dp[l][r][k] >= 0) return dp[l][r][k];
  chmax(dp[l][r][k], 0);
  if(l == r) return dp[l][r][k];
  if(k >= 1) {
    chmax(dp[l][r][k], rec(l+1, r, k-1) + vs[l]);
    chmax(dp[l][r][k], rec(l, r-1, k-1) + vs[r-1]);
  }
  if(k >= 2) {
    chmax(dp[l][r][k], rec(l+1, r, k-2));
    chmax(dp[l][r][k], rec(l, r-1, k-2));
  }
  return dp[l][r][k];
}
void answer() {
  int n, k;
  cin >> n >> k;
  vs.resize(n);
  rep(i, n) cin >> vs[i];
  repc(i, n) repc(j, n) repc(ki, k) dp[i][j][ki] = -1;
  cout << rec(0, n, k) << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 4760
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define pld pair <ld, ld>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >
#define cld complex <double>

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 1e6 + 100;

ll n, m, k, t;

int main() {
    pyshnapyshnakaa
    ll q, w, e, a, b, c;
    cin >> a >> b >> c;
    cout << min(b + c, (a + b + 1) + b);
    return 0;
}


Measured memory_bytes: 3584
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

 
a, b = ri(), ri()
if a == b:
  print('EQUAL')
elif a > b:
  print('GREATER')
else:
  print('LESS')







  







Measured memory_bytes: 27192
# coding: utf-8

if __name__ == "__main__":
    s = input()
    ud = set(['U', 'D'])
    o = list(set(s[0::2]) - ud)
    e = list(set(s[1::2]) - ud)
    if 'L' in o or 'R' in e: print("No")
    else: print("Yes")

Measured memory_bytes: 3060
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

LL A[100005];

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

	int last = 0;
	for (int i = 1; i <= n; i++) {
		if (last) {
			if (A[i]) {
				A[i]--;
				last = 0;
				ans++;
			}
		}
		ans += A[i] / 2;
		last = A[i] % 2;
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_DEPRECATE
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <bitset>
#include <cmath>
#include <ctime>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <chrono>
#include <functional>
#include <random>
#include <numeric>
#include <tuple>
#include <bitset>
using namespace std;
#define sz(v) ((int)((v).size()))
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef pair<int, int> ii;
template<class T> string toString(T x) { ostringstream ss; ss << x; return ss.str(); }
void solve();
int main() {
#ifdef LOCAL_COMP
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);
	solve();
#ifdef LOCAL_COMP
	cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec" << endl;
#endif
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const ll INF = ll(4e18);
const int MAXP = 16;

vector<ll> get(const vector<ll>& a) {
	const int n = sz(a);
	vector<vector<ll>> dp(n, vector<ll>(MAXP, INF));
	for (int p = 0; p < MAXP; p++) {
		dp[n - 1][p] = p * 2;
	}
	for (int i = n - 2; i >= 0; i--) {
		ll cur = a[i];
		for (int p = 0; p < MAXP; p++) {
			ll nxt = a[i + 1];
			for (int np = 0; np < MAXP; np++) {
				if (cur <= nxt) {
					dp[i][p] = min(dp[i][p], dp[i + 1][np] + p * 2);
				}
				nxt *= 4;
			}
			cur *= 4;
		}
		for (int p = 1; p < MAXP; p++) {
			for (int pp = 0; pp < p; pp++) {
				dp[i][p] = min(dp[i][p], dp[i][pp] + 2 * (p - pp) * (n - i));
			}
		}
	}
	vector<ll> ans(n, INF);
	for (int i = 0; i < n; i++) {
		for (int p = 0; p < MAXP; p++) {
			ans[i] = min(ans[i], dp[i][p]);
		}
	}
	return ans;
}

void solve() {
	int n;
	while (cin >> n) {
		vector<ll> a(n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		vector<ll> suff = get(a);

		vector<ll> b(n);
		for (int i = 0; i < n; i++) {
			b[i] = a[n - i - 1] * 2;
		}
		vector<ll> pref = get(b);
		reverse(all(pref));

#ifdef LOCAL_COMP
		for (ll x : pref) cerr << x << " "; cerr << endl;
		for (ll x : suff) cerr << x << " "; cerr << endl;
#endif

		ll ans = INF;
		for (int cntNeg = 0; cntNeg <= n; cntNeg++) {
			ll t;
			if (cntNeg == 0) {
				t = suff[0];
			} else if (cntNeg == n) {
				t = n + pref[n - 1];
			} else {
				t = cntNeg + pref[cntNeg - 1] + suff[cntNeg];
			}

#ifdef LOCAL_COMP
			cerr << cntNeg << " -> " << t << endl;
#endif

			ans = min(ans, t);
		}

		cout << ans << endl;
	}
}


Measured memory_bytes: 39380
<?php
  
  fscanf(STDIN,"%d",$N);
$w_list = explode(" ",trim(fgets(STDIN)));


$sum1=0;
$sum2=0;
$m=array();



for($i=0;$i<$N;$i++){
  for($j=0;$j<=$i;$j++){
    $sum1+=$w_list[$j];
  }
  for($j=$i+1;$j<$N;$j++){
    $sum2+=$w_list[$j];
  }
    $m[] = abs($sum1-$sum2);
  $sum2=0;
  $sum1=0;
  
}


echo min($m)."\n";



 





Measured memory_bytes: 4604
n, m = map(int, input().split())
a = sorted(map(int, input().split()), reverse = True)
total = sum(a)
cnt = 0
for i in a:
  if i * 4 * m >= total:
    cnt += 1
  else:
    break
if cnt >= m:
  print("Yes")
else:
  print("No")

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

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

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

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	string s;
	cin >> s;
	vector<llong> pos[26];
	for(int i = 0; i < (int)s.size(); i++){
		pos[s[i] - 'a'].push_back(i);
	}

	int len;
	for(int i = 0; i < 26; i++){
		for(int j = 0; j < pos[i].size(); j++)
			for(int k = j+1; k < pos[i].size(); k++){
				len = pos[i][k] - pos[i][j] + 1;
				if(len / 2 < k-j+1){
					cout << pos[i][j]+1 << " " << pos[i][k]+1 << endl;
					return 0;
				}
			}
	}

	cout << "-1 -1" << endl;

	return 0;
}

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


typedef long long ll;
#define INF 1LL<<60
#ifdef _MSC_VER
inline unsigned int __builtin_clz(unsigned int x) { unsigned long r; _BitScanReverse(&r, x); return 31 - r; }
inline int __lg(int __n) { return sizeof(int) * 8 - 1 - __builtin_clz(__n); }
#endif
template<class T> struct IRMXQ {
    vector<T> A; vector<vector<int> > M, X; int N;
    IRMXQ() {}
    IRMXQ(const vector<T> &A_) : A(A_) {
        N = A.size(); int LOGN = __lg(N) + 1;
        M.resize(LOGN); X.resize(LOGN);
        for (int i = 0; i<LOGN; i++) { M[i].resize(N); X[i].resize(N); }
        for (int j = 0; j<N; j++) M[0][j] = X[0][j] = j;
        for (int i = 0; i<LOGN - 1; i++) {
            for (int j = 0; j + (1 << i)<N; j++) {
                if (A[M[i][j + (1 << i)]] < A[M[i][j]]) M[i + 1][j] = M[i][j + (1 << i)];
                else M[i + 1][j] = M[i][j];
                if (A[X[i][j]] < A[X[i][j + (1 << i)]]) X[i + 1][j] = X[i][j + (1 << i)];
                else X[i + 1][j] = X[i][j];
            }
        }
    }
    // 全て[l,r)
    T min_v(int l, int r) { return A[min_i(l, r)]; }
    int min_i(int l, int r) {
        r = min(N, r);
        int d = __lg(r - l);
        if (A[M[d][r - (1 << d)]] < A[M[d][l]]) return M[d][r - (1 << d)];
        else return M[d][l];
    }
    T max_v(int l, int r) { return A[max_i(l, r)]; }
    int max_i(int l, int r) {
        r = min(N, r);
        int d = __lg(r - l);
        if (A[X[d][l]] < A[X[d][r - (1 << d)]]) return X[d][r - (1 << d)];
        else return X[d][l];
    }
};
//-----------------------------------------------------------------------------------
int N, X[201010], Y[201010];
//-----------------------------------------------------------------------------------
int R[201010], B[201010];
ll solve1() {
    rep(i, 0, N) {
        R[i] = (min(X[i], Y[i]));
        B[i] = (max(X[i], Y[i]));
    }
    sort(R, R + N);
    sort(B, B + N);

    return 1LL * (R[N - 1] - R[0]) * (B[N - 1] - B[0]);
}
//-----------------------------------------------------------------------------------
pair<int, int> XY[201010];
ll solve2() {
    rep(i, 0, N) XY[i] = { min(X[i], Y[i]), max(X[i], Y[i]) };
    sort(XY, XY + N);

    vector<int> r, b;
    rep(i, 0, N) r.push_back(XY[i].first);
    rep(i, 0, N) b.push_back(XY[i].second);

    IRMXQ<int> rseg(r);
    IRMXQ<int> bseg(b);

    ll ans = INF;
    rep(i, 1, N) {
        int Rmax = max(rseg.max_v(0, i), bseg.max_v(i, N));
        int Rmin = min(rseg.min_v(0, i), bseg.min_v(i, N));
        int Bmax = max(bseg.max_v(0, i), rseg.max_v(i, N));
        int Bmin = min(bseg.min_v(0, i), rseg.min_v(i, N));

        ll a = 1LL * (Rmax - Rmin) * (Bmax - Bmin);
        ans = min(ans, a);
    }
    return ans;
}
//-----------------------------------------------------------------------------------
int main() {
    cin >> N;
    rep(i, 0, N) scanf("%d%d", &X[i], &Y[i]);

    cout << min(solve1(), solve2()) << endl;
}

Measured memory_bytes: 64244
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
counter = 0
n = int(input())
list = [0] * (n + 1)
for l in range(1, n + 1):
    for m in range(1, n + 1):
        list[gcd(l, m)] += 1
for l in range(1, n + 1):
    for m in range(1, n + 1):
        counter += gcd(l, m) * list[l]

print(counter)

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

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

using namespace std;

int main(){
	string s; cin>>s;
	int n=s.length();
	int ans=999;
	rep(i,n-2) ans=min(ans,abs(stoi(s.substr(i,3))-753));
	cout<<ans<<endl;

	return 0;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int A, B, C, X,Y; cin>>A>>B>>C>>X>>Y;

    int min_XY = X>Y? Y : X;
    int max_XY = X>Y? X : Y;
    int max_price = X>Y? A : B;

    if(A+B<=2*C){
        cout<<X*A + Y*B<<endl;
        return 0;
    }else{
        if(max_price>2*C){
            cout<<max_XY*C*2<<endl;
        }else{
            cout<<min_XY*C*2+ max_price*(max_XY-min_XY)<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
vector<int> ans;
vector<int> a1,a2;
int co;
int dep[100005];
bool st[100005];
int wuf;
int k;
void dfs(int i,int j,vector<int> gra[],int d)
{
	if(dep[i]==0)
	{
		st[i]=1;
		dep[i]=d;
		FOR(k,0,gra[i].size())
		{
			if(gra[i][k]!=j)
			dfs(gra[i][k],i,gra,d+1);
			if(wuf!=0)
			{
				if(wuf<d)
				ans.pb(i);
				break;
			}
		}
		st[i]=0;
	}
	else
	{
//		cout<<i<<' '<<d<<' '<<dep[i]<<' '<<k<<'\n';
		if((d-dep[i])<=k && st[i]==1)
		{
			wuf=dep[i];
			ans.pb(i);
		}
	}
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int x,n;
		cin>>x>>n;
		int p;
		bool c[102]={0};
		FOR(i,0,n)
		{
			cin>>p;
			c[p]=1;
		}
		
		int u=100;
		int v;
		FOR(i,0,102)
		{
			if(abs(x-i)<u && c[i]==0)
			{
				u=abs(x-i);
				v=i;
			}
		}
		cout<<v;
	}
	return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;
    public class Main{
    	public static void main(String[] args){
        	Scanner sc = new Scanner(System.in);
          	int n = sc.nextInt() % 500;
          	int a = sc.nextInt();
          	System.out.println( (a >= n) ? "Yes" : "No");
        }
    }

Measured memory_bytes: 23380
#include<stdio.h>
int main(void){
  int n,i,j;
  scanf("%d",&n);
  char a[n];
 
    scanf("%s",a);
  
  if(n%2==1){
    printf("No");
    return 0;
  }
  for(i=0,j=(n/2);i<n/2;i++,j++){
    if(a[i]!=a[j]){
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
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; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int ans = 100000000;

int main(){
    int H, W; cin >> H >> W;

    vector<string> s(H);
    rep(i,H) {
        cin >> s[i];
    }
    int sharp_count = 0;
    rep(i,H){
        rep(j,W){
            if (s[i][j] == '#') sharp_count++;
        }
    }

    vector<vector<int>> dist(H, vector<int>(W, -1));
    queue<pair<int, int>> que;
    dist[0][0] = 0;
    que.push(make_pair(0,0));

    int xd[4] = {-1,0,1,0};
    int yd[4] = {0,-1,0,1};
    while(!que.empty()){
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        rep(i,4){
            int nx = x + xd[i];
            int ny = y + yd[i];

            if(nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
            if(s[ny][nx] == '#') continue;
            if(dist[ny][nx] == -1){
                dist[ny][nx] = dist[y][x] + 1;
                que.push(make_pair(nx,ny));
            }
        }
    }
    if (dist[H-1][W-1] != -1){
        cout << H*W - dist[H-1][W-1] - sharp_count -1 << endl; 
    }
    else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

ll l, r;
int dp[61][2][2][2], mod = 1e9 + 7;

int solve(int bit, bool a, bool b, bool s){
    if(bit == -1) return 1;
    int &ret = dp[bit][a][b][s];
    if(ret != -1) return ret;
    ret = 0;
    // 0 0
    if(a || ((l >> bit) & 1) == 0) ret += solve(bit - 1, a, b || ((r >> bit) & 1), s);
    if(ret >= mod) ret -= mod;
    // 0 1
    if(s && (a || ((l >> bit) & 1) == 0) && (b || ((r >> bit) & 1) == 1)) ret += solve(bit - 1, a, b, s);
    if(ret >= mod) ret -= mod;
    // 1 1
    if(b || ((r >> bit) & 1) == 1) ret += solve(bit - 1, a || ((l >> bit) & 1) == 0, b, 1);
    if(ret >= mod) ret -= mod;
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(dp, -1, sizeof dp);
    cin >> l >> r;
    cout << solve(60, 0, 0, 0) << endl;
}


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

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		char[] s = stdIn.next().toCharArray();
		
		for(int i = 0; i < s.length;i++) {
			int x = s[i] - 'A';
			x = (x+n)%26;
			char a = (char)(x+'A');
			System.out.print(a);
			
		}	
	}

}


Measured memory_bytes: 25428
#include<stdio.h>
#include<iostream>
using namespace std;
int main(void)
{
	int n,a[101]={0},b[101]={0},c[101]={0},x,X,y,Y,z,Z,h,i;
cin>>n;
cin>>x;
for(i=0;i<x;i++){
cin>>X;
a[X]=1;
}
cin>>y;
for(i=0;i<y;i++){
cin>>Y;
b[Y]=1;
}
cin>>z;
for(i=0;i<z;i++){
cin>>Z;
c[Z]=1;
}
h=0;
for(i=1;i<=n;i++){
if(a[i]!=1&&c[i]==1){
h++;
}
else if(b[i]==1&&c[i]==1){
h++;
}
}
cout<<h<<endl;
return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N, K;
    cin >> N >> K;
    ll H[N];
    rep(i, N) cin >> H[i];
    sort(H, H+N, greater<ll>());
    ll ans = 0;
    rep2(i, K, N-1){
        ans += H[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long
#define endl "\n"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll N = 1e5 + 10, inf = 1e18 + 10, mod = 1e9 + 7;
ll u[N], d[N][2];
vector <int> g[N];
void dfs(int v)
{
    d[v][1] = d[v][0] = 1;
    u[v] = 1;
    for(int i = 0; i < g[v].size(); i++)
    {
        int to = g[v][i];
        if(!u[to])
        {
            dfs(to);
            d[v][1] *= d[to][0];
            d[v][0] *= d[to][1] + d[to][0];
            d[v][1] %= mod;
            d[v][0] %= mod;
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("prices.in", "r", stdin);
    //freopen("prices.out", "w", stdout);
    ll n;
    cin >> n;
    for(int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs(1);
    cout << (d[1][0] + d[1][1]) % mod;
}


Measured memory_bytes: 13696
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

h, w = MAP()
c = []
for i in range(10):
    c.append(LIST())
a = []
for i in range(h):
    a.append(LIST())

chk = True
while chk:
    chk = False
    for i in range(10):
        for j in range(10):
            for k in range(10):
                if c[i][j] > c[i][k]+c[k][j]:
                    c[i][j] = c[i][k]+c[k][j]
                    chk = True

ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] != -1:
            ans += c[a[i][j]][1]
print(ans)

Measured memory_bytes: 10588
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if ((a < c && c < b) || (b < c && c < a) ) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,x;
	cin>>a>>b;
	x=a+b;
	if((a>=0)&&(b<=23))
	
	if(x<24){
	cout<<x;}
	else {
	x=x-24;
	cout<<x;}
	else
	return 0;
	
}



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

int main(){
  string s;
  cin >> s;
  int ans = 0;
 for(int i =0 ; i < s.size(); i++){
    if(s.at(i) == '+'){ ans++;}
    else{ ans--;}
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  A += B;
  C += D;
  if (A > C) cout << "Left" << endl;
  else if (A == C) cout << "Balanced" << endl;
  else cout << "Right" << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = input().split()
B = A[:]

def BubbleSort(A, N):
    for i in range(N):      # iは未ソートの部分列の先頭のインデックス
        for j in range(N-1, i, -1):     # 隣接要素を比較するのは未ソート部分列の末尾から先頭まで
            if A[j-1][1] > A[j][1]:           # 隣接要素を比較
                A[j-1], A[j] = A[j], A[j-1]     # 大小関係が逆の場合、交換
    return A


def SelectionSort(B, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if B[minj] [1]> B[j][1]:
                minj = j
        B[i], B[minj] = B[minj], B[i]       
    return B

ans_b = BubbleSort(A, N)
print(*ans_b)
print("Stable")
ans_s = SelectionSort(B, N)
print(*ans_s)
if ans_b == ans_s:
    print("Stable")
else:
    print("Not stable")


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000000
#define MAX 200001
#define MOD 1000000007

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int N, Q;
    cin >> N >> Q;
    vector<tuple<ll, ll, ll>> event;
    vector<ll> ans(Q);
    multiset<ll> s;
    for(int i = 0; i < N; i++){
        int s, t, x;
        cin >> s >> t >> x;
        event.push_back({s - x, 0, x});
        event.push_back({t - x, 1, x});
    }
    for(int i = 0; i < Q; i++){
        int d;
        cin >> d;
        event.push_back({d, 2, i});
    }
    sort(event.begin(), event.end());
    for(auto e: event){
        if(get<1>(e) == 0){
            s.insert(get<2>(e));
        }
        else if(get<1>(e) == 1){
            s.erase(s.find(get<2>(e)));
        }
        else{
            if(s.empty()) ans[get<2>(e)] = -1;
            else ans[get<2>(e)] = *s.begin();
        }
    }
    for(int i = 0; i < Q; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 29380
score = 0
def main():

    N, M, Q = map(int, input().split())
    ABCD = [list(map(int, input().split())) for i in range(Q)]
    global score
    for i in range(1, M+1):
        dfs([i], N, M, ABCD)
    print(score)


def dfs(l, N, M,ABCD):
    # 末端まで探索したか判定
    if judge_end(l, N):
        global score
        tmp_score = calc_score(ABCD, l)
        score = max(tmp_score, score)
        return
    else:
        # 現時点から選べる選択肢の列挙と探索
        nexts = listup_next(l[-1], M)
        for x in nexts:
            dfs(l+[x], N, M, ABCD)


def judge_end(l, N):
    return len(l) == N


def calc_score(ABCD, l):
    s = 0
    for a, b, c, d in ABCD:
        if l[b-1] - l[a-1] == c:
            s += d
    return s


def listup_next(m, M):
    return range(m, M+1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
I = [int(_) for _ in open(0).read().split()]
N, Q=I[:2]
C = I[2:2 + N]
LR = I[2 + N:]
2 ** 40
2 ** 20
Query = []
for i, lr in enumerate(zip(LR[::2], LR[1::2])):
    l, r = lr
    Query += [r * 2 ** 40 + l * 2 ** 20 + i]
for i, c in enumerate(C):
    Query += [(i + 1) * 2 ** 40 + c]
Query.sort()
c_i = [-1] * (N + 1)

class SegmentTree():
    def __init__(self, array, f, ti):
        """
        Parameters
        ----------
        array : list
            to construct segment tree from
        f : func
            binary operation of the monoid
        ti : 
            identity element of the monoid
        """
        self.f = f
        self.ti = ti
        self.n = n = 2**(len(array).bit_length())
        self.dat = dat = [ti] * n + array + [ti] * (n - len(array))
        for i in range(n - 1, 0, -1):  # build
            dat[i] = f(dat[i << 1], dat[i << 1 | 1])
 
    def update(self, p, v):  # set value at position p (0-indexed)
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = v
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])
 
    def operate_right(self, p, v):  # apply operator from the right side
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = f(dat[p], v)
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])
 
    def operate_left(self, p, v):  # apply operator from the left side
        f, n, dat = self.f, self.n, self.dat
        p += n
        dat[p] = f(v, dat[p])
        while p > 1:
            p >>= 1
            dat[p] = f(dat[p << 1], dat[p << 1 | 1])
 
    def query(self, l, r):  # result on interval [l, r) (0-indexed)
        f, ti, n, dat = self.f, self.ti, self.n, self.dat
        vl = vr = ti
        l += n
        r += n
        while l < r:
            if l & 1:
                vl = f(vl, dat[l])
                l += 1
            if r & 1:
                r -= 1
                vr = f(dat[r], vr)
            l >>= 1
            r >>= 1
        return f(vl, vr)
 

ans = [0] * Q
st = SegmentTree([0] * (N + 5), lambda x,y:x+y, 0)
for q in Query:
    x, yz = divmod(q, 2 ** 40)
    y, z = divmod(yz, 2 ** 20)
    if y==0:
        if c_i[z] != -1:
            st.operate_right(c_i[z], -1)
        c_i[z] = x
        st.operate_right(x, 1)
    else:
        ans[z] = st.query(y, x + 1)
print(*ans, sep='\n')


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

const int MAX = 100005;
std::vector<int> V[MAX];
int D[MAX], G[MAX];

void DFSb(int v, int p, int d) {
    D[v] = d;
    for (int u : V[v]) {
        if (u != p) DFSb(u, v, d+1);
    }
}

int max = 0;
void update(int v) {
    max = std::max(D[v]-1, max);
}

void DFSa(int v, int p, int d) {
    G[v] = d;
    update(v);
    for (int u : V[v]) {
        if (u != p && D[u] > d) DFSa(u, v, d+1);
    }
}

int main() {
    std::ios_base::sync_with_stdio(0);
    int n,u,v;
    std::cin >> n >> u >> v;
    if (u == v) { std::cout << 0 << std::endl; return 0; }
    for (int i=1;i<n;++i) {
        int a,b;
        std::cin >> a >> b;
        V[a].push_back(b);
        V[b].push_back(a);
    }
    DFSb(v, -1, 0);
    DFSa(u, -1, 0);
    std::cout << max << std::endl;
    return 0;
}

Measured memory_bytes: 10624
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <iomanip>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
	ll n,sum=0;cin>>n;
	loop(n,i,0){
		int x;cin>>x;
		sum+=x;
	}
	cout<<sum-n<<endl;
	return 0;
}



Measured memory_bytes: 256
k,a[1<<17],s,S,i;main(n){for(;scanf("%d%d",&n,&k)*n;s>S?S=s:0,s=i=!printf("%d\n",S))for(S=-1e9;i++<n;i<k||(s-=a[i-k],s>S?S=s:0))scanf("%d",a+i),s+=a[i];}

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

using ll = long long;

int main() {
  ll X, K, D;
  cin >> X >> K >> D;

  ll ans = 0;
  if ( abs(X/D) <= K) {
    K -= abs(X/D);
    X %= D;

    if (K%2==0) ans = X;
    else ans = min(abs(X-D),abs(X+D));
  } else {
    if (X>0){
      ans = X - K*D;
    } else {
      ans = X + K*D;
    }
  }

  cout << abs(ans) << endl;

  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define ll int64_t
using namespace std;
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (ll I = (A); I <= (B); I++)
#define fo(i,n) for(ll i=0;i<n;i++)
#define sz(a) ll((a). size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
#define scan(char_array) scanf("%[^\n]s",&char_array)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    IOS
    ll n;
    cin>>n;
    vector<ll> a(n);
  map<ll,ll> mp;
    map<ll,ll> map2;
    fo(i,n) cin>>a[i];

    fo(i,n){
        mp[a[i]]++;
        map2[a[i]]++;
    }


    for(auto jj:mp){
        
        ll tmp=jj.first;
       
        if(mp[tmp]<=0) continue;
        for(ll i=2;i*tmp<=1000005;i++){
            if(mp.count(i*tmp)&&mp[i*tmp]>0) mp[i*tmp]=0;
        }
    }
    ll cnt=0;
    fo(i,n){
        //dbg(mp[a[i]]);
        if(map2[a[i]]>1) continue;
        else{
            if(mp[a[i]]==1&&map2[a[i]]==1) cnt++;
        }
    }
   cout<<cnt<<endl;

   
}

Measured memory_bytes: 29852