akhauriyash/Code-Regression huggingface dataset:
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAXH 32
#define MAXW 32

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int w, h;
int field[MAXH][MAXW];
int sy, sx, gy, gx, ans = INF;

void dfs(int y, int x, int cnt) {
    if (cnt >= 10) return;
    for (int i = 0; i < 4; i++) {
        int ny = y + dy[i], nx = x + dx[i];
        if (field[ny][nx] == 1) continue;
        while (0 <= nx && nx < w && 0 <= ny && ny < h && field[ny][nx] == 0) {
            nx = nx + dx[i];
            ny = ny + dy[i];
        }
        if (nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
        if (nx == gx && ny == gy) ans = min(ans, cnt+1);
        else {
            field[ny][nx] = 0;
            nx -= dx[i];
            ny -= dy[i];
            dfs(ny, nx, cnt+1);
            field[ny+dy[i]][nx+dx[i]] = 1;
        }
    }
}

int main(void) {
    while (1) {
        cin >> w >> h;
        if (w == 0 && h == 0) break;
        ans = INF;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> field[i][j];
                if (field[i][j] == 2) {
                    sy = i; sx = j;
                    field[i][j] = 0;
                }
                if (field[i][j] == 3) {
                    gy = i; gx = j;
                }
            }
        }
        dfs(sy, sx, 0);
        if (ans < INF) cout << ans << endl;
        else cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1164
// C program to convert a number from any base
// to decimal
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define fore(i, l, n) for(int i = l; i < n; i++)

using namespace std;
using mii=map<int, int>;
using mll=map<ll, ll>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;

int main()
{
    fastIO
    int n;
    cin >> n;
    vector<int> arr(n, 0);

    fore(i, 0, n)
        cin >> arr[i];

    sort(arr.begin(), arr.end());

    ll ans = 0;

    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            int num = arr[i] + arr[j];
            auto it = upper_bound(arr.begin(), arr.end(), num - 1);
            it--;

            ll ind = it - arr.begin();
            if(ind <= j)
                continue;
            else
                ans += (ind - j);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.math.*;
 
public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] str = br.readLine().split(" ");
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		int c = Integer.parseInt(str[2]);
		int cnt = 0;
		if(a==b)
			cnt++;
		if(a==c || b==c)
			cnt++;
		sb.append(3-cnt);
		System.out.print(sb);
	}
}

Measured memory_bytes: 8148
import std.stdio, std.array;

void main() {
  for(int t; readf("%d\n", &t), t != 0;) {
    int a_point = 0, b_point = 0;
    foreach(i; 0..t) {
      int a, b;
      readf("%d %d\n", &a, &b);
      if (a == b) {a_point += a; b_point += b;}
      else if (a > b) {
        a_point += (a + b);
      }
      else {
        b_point += (a + b);
      }
    }
    writeln(a_point, " ", b_point);
  }
}

Measured memory_bytes: 1068
#include<iostream>
#include<string>
using namespace std;
int main() {
	string A, B;
	cin >> A >> B;
	if (A.size() > B.size()) {
		cout << "GREATER" << endl;
	}
	else if (A.size() < B.size()) {
		cout << "LESS" << endl;
	}
	else {
		if (A > B) {
			cout << "GREATER" << endl;
		}
		else if (A < B) {
			cout << "LESS" << endl;
		}
		else {
			cout << "EQUAL" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int number[3];
  scanf("%d %d %d",&number[0],&number[1],&number[2]);
  int tmp;
  for (int i=0; i<3; ++i) {
    for (int j=i+1; j<3; ++j) {
      if (number[i] > number[j]) {
        tmp =  number[i];
        number[i] = number[j];
        number[j] = tmp;
      }
    }
  }
  
  printf("%d\n",number[2]-number[0]);
  return 0;
}


Measured memory_bytes: 1696
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

int a, b, k;

int main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cin >> a >> b >> k;
    for (int i = std::max(a, b); i; --i)
    	if (!(a % i) && !(b % i))
    	{
    		if (!(--k))
    		{
    			std::cout << i << "\n";
    			break;
			}
		}
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt()-1;
        int y = sc.nextInt()-1;
        int[][] d = new int[n][n];
        int ans[] = new int[n];

        for(int i=0;i<n;i++)for(int j=0;j<n;j++)d[i][j]=0;

        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                int dXY = Math.abs(i-x)+Math.abs(j-y)+1;
                d[i][j]=Math.min(j-i,dXY);
            }
        }

        for(int i=0;i<n;i++)for(int j=0;j<n;j++){
            //System.out.println(i+"to"+j+" "+d[i][j]);
            ans[d[i][j]]++;
        }
        for(int i=1;i<n;i++) System.out.println(ans[i]);
    }

}


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

def vital(P,Xi):
    return (Xi -P)**2

l.sort()
a, b = l[0],l[-1]
#print(a,b)

x = []
y = 0
for i in range(a,b+1):
    for j in range(n):
        y += (l[j] - i)**2
    x.append(y)
    y = 0
print(min(x))


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

typedef long long ll;

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#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(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	string o,e;
	cin >> o >> e;
	FOR(i,0,(int)min(o.size(),e.size()))cout << o[i] << e[i];
	if(o.size() != e.size())cout << o[o.size()-1];
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stack>
#include<cstring>
#include<utility>
#include<algorithm>
using namespace std;
typedef long long ll;

struct node {
  int l,r;
  int ll,lr;
  int rl,rr;
};

bool cmp(const node &a, const node &b) {
  if (a.l == b.l) {
    return (a.r > b.r);
  }
  return (a.l < b.l);
}


void printIt(vector<node> ranges) {
  for(int i=0; i<ranges.size(); ++i) {
    cout<< "L : " << ranges[i].l << " , " << " R : " <<  ranges[i].r << "\t";
    cout<< "Left L : " << ranges[i].ll << " , " << " Left R : " <<  ranges[i].lr << "\t";
    cout<< "Right L : " << ranges[i].rl << " , " << " Right R : " <<  ranges[i].rr << endl;
  }
}


void updateLeftToRight(vector<node> &ranges) {
  if (ranges.size() == 0 ) {
    return;
  }
  ranges[0].ll = ranges[0].l;
  ranges[0].lr = ranges[0].r;
  for (int i=1; i<ranges.size(); ++i) {
    ranges[i].ll = ranges[i].l;
    ranges[i].lr = min(ranges[i].r,ranges[i-1].lr);
  }
}

void updateRightToLeft(vector<node> &ranges) {
  if (ranges.size() == 0 ) {
    return;
  }
  int n = ranges.size();
  ranges[n-1].rl = ranges[n-1].l;
  ranges[n-1].rr = ranges[n-1].r;
  for (int i=n-2; i>=0; --i) {
    ranges[i].rl = ranges[i+1].rl;
    ranges[i].rr = min(ranges[i].r,ranges[i+1].rr);
  }
}

int getAns(vector<node> &ranges) {
  int ans = 0;
  for(int i=0; i<ranges.size(); ++i) {
    if (i > 0) {
        ans = max(ans,max(0,ranges[i-1].lr -ranges[i-1].ll + 1) + max(0,ranges[i].rr -ranges[i].rl + 1));
    }
  }
  for(int i=0; i<ranges.size(); ++i) {
    if (i < ranges.size() - 1) {
        ans = max(ans,max(0,ranges[i].lr -ranges[i].ll + 1) + max(0,ranges[i+1].rr -ranges[i+1].rl + 1));
    }
  }
  int tmpl,tmpr;
  for(int i=0; i<ranges.size(); ++i) {
    if (i>0) {
      tmpl = ranges[i-1].ll;
      tmpr = ranges[i-1].lr;
    }
    if (i+1 < ranges.size()) {
      if (i==0) {
        tmpl = ranges[i+1].rl;
        tmpr = ranges[i+1].rr;
      } else {
        tmpl = max(tmpl, ranges[i+1].rl);
        tmpr = min(tmpr, ranges[i+1].rr);
      }
    }
    ans = max(ans,max(0,ranges[i].r -ranges[i].l + 1) + max(0,tmpr - tmpl + 1));
  }
  return ans;
}

int main() {
  int n;
  cin>>n;
  vector<node> ranges;
  int l,r;
  for(int i=0; i<n; ++i) {
    cin>>l>>r;
    node curr;
    curr.l  = l;
    curr.r = r;
    ranges.push_back(curr);
  }
  sort(ranges.begin(),ranges.end(),cmp);


  updateLeftToRight(ranges);
  updateRightToLeft(ranges);

  // printIt(ranges);
  cout << getAns(ranges) << endl;

  return 0;
}


Measured memory_bytes: 5000
#include<iostream>
#include<vector>
#define int long long
using namespace std;
const int N=1e5+1;
int dp[101][N],w[N],v[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,z,max1=0;
	cin>>n>>z;
	for(i=1;i<=n;i++){
		cin>>w[i]>>v[i];
	}
	for(i=1;i<=n;i++){
		for(j=0;j<=z;j++){
			dp[i][j]=dp[i-1][j];
			if(j>=w[i]){
				dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
			}
			if(i==n){
				max1=max(max1,dp[i][j]);
			}
		}
	}
	cout<<max1;
}


Measured memory_bytes: 78720
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4,sse4.1,sse4.2,avx,tune=native")
#include <bits/stdc++.h>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a = max<T>(a, b);}


int main(){
	cin.tie(0); ios_base::sync_with_stdio(false);
	int x, y, z, k;
	cin >>x >>y >>z >>k;
	VL a(x), b(y), c(z);
	rep(i, x) cin >>a[i];
	rep(i, y) cin >>b[i];
	rep(i, z) cin >>c[i];
	
	VL ab; ab.reserve(x*y);
	rep(i, x) rep(j, y) ab.push_back(a[i]+b[j]);
	sort(ab.rbegin(), ab.rend());
	if(sz(ab) > k) ab.resize(k);
	
	VL abc; abc.reserve(z*sz(ab));
	rep(i, sz(ab)) rep(j, z) abc.push_back(ab[i]+c[j]);
	sort(abc.rbegin(), abc.rend());
	
	rep(i, k) cout << abc[i] <<"\n";
	return 0;
}


Measured memory_bytes: 31616
import java.util.*;
public class Main {



	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int k=0;
		if(s.equals("RRR")) {
			k=3;
		}else if(s.equals("RRS")||s.equals("SRR"))  {
			k=2;
		}else if(s.equals("SSS"))  {
			k=0;
		}else {
			k=1;
		}
		System.out.println(k);

	}

}


Measured memory_bytes: 35464
import math
from itertools import permutations

N = int(input())
town_index = [i for i in range(N)]
town = []
sum_length = 0
for i in range(N):
    x, y = map(int, input().split())
    town.append([x, y])

all_routes = list(permutations(town_index))
for root in all_routes:
    length = 0
    for i in range(1, N):
        length += math.sqrt((town[root[i-1]][0] - town[root[i]][0]) ** 2 + (town[root[i-1]][1] - town[root[i]][1]) ** 2)
    sum_length += length

print(sum_length / len(all_routes))


Measured memory_bytes: 45808
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define all(c) (c).begin(), (c).end()

template<typename T> inline T sqr(T x){return x * x;}

void sieve(vector<int>& v, int n){
    v.assign(n, 0); iota(all(v), 2);
    for(auto div=v.begin(); sqr(*div)<=v.back(); ++div){
        v.erase(remove_if(div+1, v.end(), [&](int x){return x % *div == 0;}), v.end());
    }
}

vector<int> primes;

int solve(int N, int P){
    int k = upper_bound(all(primes), N) - primes.begin();
    vector<int> M;
    for(int i=k; i<k+P; ++i){
        for(int j=k; j<=i; ++j)M.push_back(primes[i] + primes[j]);
    }
    sort(all(M));
    return M[P-1];
}

int main(){
    sieve(primes, 120000);
    int N, P;
    while(cin >> N >> P, ~N|~P)cout << solve(N, P) << '\n';
    return 0;
}

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

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1000;
const int M = 1e6+5;

int n,m;
struct point{
	int x,y;
	LL v;
}a[N];
struct edge{
	int x,f,nxt;
	LL c;
}e[M];
int h[N],tot,ss,tt;
int pt;
struct cons{
	int ty;
	int x,v;
}c[N];
int lx[N],rx[N],ly[N],ry[N];
int sum[N];

void addedge(int x,int y,int f,LL c){
	e[++tot].x=y;e[tot].f=f;e[tot].c=c;e[tot].nxt=h[x];h[x]=tot;
}

void inse(int x,int y,int f,LL c){
	addedge(x,y,f,c);
	addedge(y,x,0,-c);
}

void add(int x,int y,int l,int r,LL v){
	inse(x,y,r-l,v);
	if (l){
		inse(ss,y,l,v);
		inse(x,tt,l,0);
	}
}

LL dis[N];
int que[N],lst[N];
bool pd[N];

LL spfa(int ss,int tt){
	fo(i,1,pt)pd[i]=0,dis[i]=1e18;
	dis[ss]=0;
	int he=0,ta=1;
	pd[que[1]=ss]=1;
	for(;he!=ta;){
		int x=que[he=he%pt+1];
		pd[x]=0;
		for(int p=h[x];p;p=e[p].nxt)
			if (e[p].f&&dis[e[p].x]>dis[x]+e[p].c){
				dis[e[p].x]=dis[x]+e[p].c;
				lst[e[p].x]=p;
				if (!pd[e[p].x])pd[que[ta=ta%pt+1]=e[p].x]=1;
			}
	}
	return dis[tt]<1e18;
}

LL aug(int ss,int tt){
	LL ret=dis[tt];
	for(int x=tt;x!=ss;x=e[lst[x]^1].x){
		e[lst[x]].f--;
		e[lst[x]^1].f++;
	}
	return ret;
}

int main(){
	n=get();
	fo(i,1,n){
		a[i].x=get();a[i].y=get();
		cin>>a[i].v;
	}
	m=get();
	fo(i,1,m){
		char ch;
		while(ch=getchar(),ch<'A'||ch>'Z');
		if (ch=='L')c[i].ty=1;
		if (ch=='R')c[i].ty=2;
		if (ch=='D')c[i].ty=3;
		if (ch=='U')c[i].ty=4;
		c[i].x=get();c[i].v=get();
	}
	LL ans=0;
	fo(all,1,n){
		fo(i,0,100)lx[i]=ly[i]=0,rx[i]=ry[i]=i;
		fo(i,1,m){
			int x=c[i].x,v=c[i].v;
			if (c[i].ty==1)rx[x]=min(rx[x],v);
			if (c[i].ty==2)lx[x-1]=max(lx[x-1],all-v);
			if (c[i].ty==3)ry[x]=min(ry[x],v);
			if (c[i].ty==4)ly[x-1]=max(ly[x-1],all-v);
		}
		rx[100]=min(rx[100],all);
		ry[100]=min(ry[100],all);
		if (rx[100]<all||ry[100]<all)continue;
		bool can=1;
		fo(i,0,100)can&=(lx[i]<=rx[i]&&ly[i]<=ry[i]);
		if (!can)continue;
		pt=404;
		fo(i,1,pt)h[i]=sum[i]=0;
		tot=1;
		ss=403,tt=404;
		int s=401,t=402;
		int key=0;
		fo(i,1,100){
			if (i==100){
				add(s,i,lx[i],rx[i],0ll);
			}
			else add(i+1,i,lx[i],rx[i],0ll);
			add(i,100+i,0,n,0ll);
		}
		fo(i,1,n)add(100+a[i].x,200+a[i].y,0,1,LL(1e15)-a[i].v);
		fo(i,1,100){
			if (i==100)add(300+i,t,ly[i],ry[i],0ll);
			else add(300+i,300+i+1,ly[i],ry[i],0ll);
			add(200+i,300+i,0,n,0ll);
		}
		add(t,s,0,1e9,0);
		LL tmp=0;
		int tim=0;
		for(;spfa(ss,tt);){
			tmp=tmp+aug(ss,tt);
		}
		for(int p=h[ss];p;p=e[p].nxt)if (e[p].f){can=0;break;}
		if (!can)continue;
		h[t]=e[h[t]].nxt;
		h[s]=e[h[s]].nxt;
		for(;spfa(s,t);){
			tmp=tmp+aug(s,t);
		}
		tmp=LL(1e15)*all-tmp;
		for(int p=h[s];p;p=e[p].nxt)if (e[p].x==100){key=p;break;}
		if (!e[key].f)ans=max(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        N: usize,
        W: i64,
        wvs: [(i64, i64); N],
    }

    const MAX_N: usize = 100;
    const MAX_W: usize = 10_0000;

    // dp[n][w] : n番以下の品物を選んで、それまでの重さがw(まで?)の条件で選んだ時の最大の価値
    let mut dp: Vec<Vec<i64>> = Vec::new();
    for _n in 0..MAX_N {
        let vec = vec![0i64; MAX_W + 1];
        dp.push(vec);
    }

    let w0 = wvs[0].0;
    let v0 = wvs[0].1;
    for w in w0..(W + 1) {
        dp[0][w as usize] = v0;
    }

    for n in 1..N {
        let this_w = wvs[n].0;
        let this_v = wvs[n].1;

        for w in 0..(W + 1) {
            let cand_stay = dp[n - 1][w as usize];
            let cand_take = if w - this_w >= 0 {
                dp[n - 1][(w - this_w) as usize] + this_v
            } else {
                0
            };

            dp[n][w as usize] = std::cmp::max(cand_stay, cand_take);
        }
    }

    let ans = dp[N - 1][W as usize];
    println!("{}", ans);
}


Measured memory_bytes: 80324
#include<bits/stdc++.h>
#define LL long long
#define db double

using namespace std;
const int N=2000+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int to[N<<5],nt[N<<5],hd[N<<4],tot=1;
void adde(int x,int y)
{
	++tot,to[tot]=y,nt[tot]=hd[x],hd[x]=tot;
	++tot,to[tot]=x,nt[tot]=hd[y],hd[y]=tot;
}
int n,t,a[N],vs[N<<4],mk[N<<4],ti,ban[N<<4],dl[N],sq[N],ts,ff[N];
int findf(int x){return ff[x]==x?x:ff[x]=findf(ff[x]);}
vector<int> an[N],ls,nl;
map<int,int> id;
void clr(int x)
{
	mk[x]=ti,vs[x]=vs[0];
	for(int i=hd[x];i;i=nt[i])
	{
		int y=to[i];
		if(ban[i>>1]||mk[y]==ti) continue;
		clr(y);
	}
}

int main()
{
	n=rd(),t=n;
	for(int i=1;i<=n;++i)
	{
		a[i]=rd();
		int x=a[i],sqt=sqrt(x);
		for(int j=2;j<=sqt;++j)
			if(x%j==0)
			{
				if(!id[j]) id[j]=++t;
				adde(i,id[j]);
				while(x%j==0) x/=j;
			}
		if(x>1)
		{
			if(!id[x]) id[x]=++t;
			adde(i,id[x]);
		}
	}
	memset(vs,0x3f3f3f,sizeof(vs));
	a[0]=1<<30;
	int rs=n;
	while(rs--)
	{
		int sx=0;
		for(int i=1;i<=n;++i)
			if(!dl[i]&&vs[sx]>vs[i]) sx=i;
		if(!sx)
		{
			for(int i=1;i<=n;++i)
				if(!dl[i]&&a[sx]>a[i]) sx=i;
		}
		else
		{
			for(int i=1;i<=n;++i)
				if(!dl[i]&&vs[i]==vs[sx]&&a[sx]>a[i]) sx=i;
		}
		dl[sx]=1,sq[++ts]=sx;
		++ti,clr(sx);
		for(int i=hd[sx];i;i=nt[i])
		{
			int y=to[i];
			ban[i>>1]=1;
			for(int j=hd[y];j;j=nt[j])
			{
				if(ban[j>>1]) continue;
				int z=to[j];
				vs[z]=ts;
			}
		}
	}
	for(int i=1;i<=n;++i) ff[i]=i,an[i].push_back(a[i]);
	while(ts)
	{
		int x=sq[ts--];
		ls.clear();
		for(int i=hd[x];i;i=nt[i])
		{
			int y=to[i];
			ban[i>>1]=0;
			for(int j=hd[y];j;j=nt[j])
			{
				if(ban[j>>1]) continue;
				int z=to[j];
				if((z=findf(z))!=findf(x))
				{
					int nn=ls.size(),mm=an[z].size(),p=0,q=0,r=0;
					nl.clear(),nl.resize(nn+mm);
					while(p<nn&&q<mm)
					{
						if(ls[p]>an[z][q]) nl[r++]=ls[p],++p;
						else nl[r++]=an[z][q],++q;
					}
					while(p<nn) nl[r++]=ls[p],++p;
					while(q<mm) nl[r++]=an[z][q],++q;
					ls=nl;
					ff[z]=x;
				}
			}
		}
		int nn=ls.size();
		for(int i=0;i<nn;++i) an[x].push_back(ls[i]);
	}
	ls.clear();
	for(int i=1;i<=n;++i)
		if(findf(i)==i)
		{
			int nn=ls.size(),mm=an[i].size(),p=0,q=0,r=0;
			nl.clear(),nl.resize(nn+mm);
			while(p<nn&&q<mm)
			{
				if(ls[p]>an[i][q]) nl[r++]=ls[p],++p;
				else nl[r++]=an[i][q],++q;
			}
			while(p<nn) nl[r++]=ls[p],++p;
			while(q<mm) nl[r++]=an[i][q],++q;
			ls=nl;
		}
	for(int i=0;i<n;++i) printf("%d ",ls[i]);
	return 0;
}


Measured memory_bytes: 13952
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
using namespace std;
typedef long long ll;
// cd test ; rm -R ./*; cd ..


int main(void) {
  int n;
  cin >> n;
  
  for (int i = 1; i <= 50000; i++) {
    if ((int)floor(i * 1.08) == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
l= [[int(i) for i in input().split()] for j in range(3)]

a = [0]
b = []

for i in range(3):
    b.append(l[0][i]-a[0])

for i in range(1,3):
    a.append(l[i][0]-b[0])


for i in range(3):
    for j in range(3):
        if a[i] + b[j] != l[i][j]:
            print("No")
            exit()

print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <queue>

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
const int INFTY=1<<29;

struct State{
	int i,j,dir,cost;
	State(){}
	State(int i,int j,int d,int c):i(i),j(j),dir(d),cost(c){}
	bool operator<(const State& s)const{return cost<s.cost;}
	bool operator>(const State& s)const{return cost>s.cost;}
};

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		int grid[30][30];
		rep(i,h) rep(j,w)
			cin>>grid[i][j];
		int c[4];
		rep(i,4)
			cin>>c[i];
		
		int cost[30][30][4];
		rep(i,h) rep(j,w) rep(k,4)
			cost[i][j][k]=INFTY;
		
		priority_queue<State,vector<State>,greater<State> > pq;
		pq.push(State(0,0,0,0));
		while(pq.size()){
			State cur=pq.top(); pq.pop();
			if(cost[cur.i][cur.j][cur.dir]!=INFTY)
				continue;
			cost[cur.i][cur.j][cur.dir]=cur.cost;
			
			int di[]={0,-1,0,1},dj[]={1,0,-1,0};
			{ // straight
				int d=cur.dir,ni=cur.i+di[d],nj=cur.j+dj[d],f=grid[cur.i][cur.j]!=0;
				if(0<=ni && ni<h && 0<=nj && nj<w)
					pq.push(State(ni,nj,d,cur.cost+f*c[0]));
			}
			{ // right
				int d=(cur.dir+3)%4,ni=cur.i+di[d],nj=cur.j+dj[d],f=grid[cur.i][cur.j]!=1;
				if(0<=ni && ni<h && 0<=nj && nj<w)
					pq.push(State(ni,nj,d,cur.cost+f*c[1]));
			}
			{ // back
				int d=(cur.dir+2)%4,ni=cur.i+di[d],nj=cur.j+dj[d],f=grid[cur.i][cur.j]!=2;
				if(0<=ni && ni<h && 0<=nj && nj<w)
					pq.push(State(ni,nj,d,cur.cost+f*c[2]));
			}
			{ // left
				int d=(cur.dir+1)%4,ni=cur.i+di[d],nj=cur.j+dj[d],f=grid[cur.i][cur.j]!=3;
				if(0<=ni && ni<h && 0<=nj && nj<w)
					pq.push(State(ni,nj,d,cur.cost+f*c[3]));
			}
		}
		
		int res=INFTY;
		rep(i,4)
			res=min(res,cost[h-1][w-1][i]);
		cout<<res<<endl;
	}
	
	return 0;
}

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second
#define m_p make_pair

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

    ll a,b,c;
    cin >> a >> b >> c;
    if(b-a==c-b) cout << "YES" << "\n";
    else cout << "NO" << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	cin >> a;
	for (int i = 0; i < n - k; ++i) {
		if (a[i] < a[i + k]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 4780
# Aizu Problem 0057: Number of Area
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


for line in sys.stdin:
    n = int(line)
    print(1 + n * (n + 1) // 2)

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

int main(){
    long long int N;
    cin >> N;
    int ans = 0;
    for(long long int i=2;i*i<=N;i++){
        int cur = 0;
        while (N % i == 0) {
            cur++;
            N /= i;
        }
        for(long long int j=1;j<=cur;j++) {
            ans++; cur -= j;
        }
    }
    if(N>1) ans++;
    cout << ans << endl;

	return 0;

}





Measured memory_bytes: 3576
#include<cstdio>
#include<algorithm>
using namespace std;
static const int MAX_N = 100;
static const int MAX_W = 10000;

int N, W;
int v[MAX_N], w[MAX_N];
int dp[MAX_N + 1][MAX_W + 1];

void solve(){
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= W; j++){
			if(j < w[i]){
				dp[i + 1][j] = dp[i][j];
			}else{
				dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
			}
		}
	}
	printf("%d\n", dp[N][W]);
}

int main(){
	scanf("%d %d", &N, &W);
	for(int i = 0; i < N; i++){
		scanf("%d %d", &v[i], &w[i]);
	}
	solve();
	return 0;
}

Measured memory_bytes: 6672
#include<cstdio>
typedef long long ll;const int N=1e5+7;
int n,a[N],i;ll res1=2,res2=2;
int main(){
	for(scanf("%d",&n),i=1;i<=n;++i)scanf("%d",a+i);
	for(i=n;i;--i){
		if(res1%a[i]){res1/=a[i];res1++;res1*=a[i];}
		res2/=a[i];res2*=a[i];
		if(res2<res1)return 0*puts("-1");
		res2+=a[i]-1;
	}
	printf("%lld %lld\n",res1,res2);
	return 0;
} 

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <deque>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define ctoi(c) c - '0'
#define tos(s) to_string(s)

typedef long long ll;


int main() {
    ll a,v,b,w,t;
    cin >> a >> v >> b >> w >> t;
    if (a == b) {
        cout << "YES" << endl;
    } else if (v > w && abs(a-b) <= (v - w)*t) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

/*
ACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACAC                                                                              
                                   ******,  .,, .,, ,,,    ****.**              
                                   ** . .,,,,,,,,,,,,,,,,,,,,,. .,*             
                                   **,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.            
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                    ****      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,      
              ***************,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,    
         ********************,,,,,,,,,,,,,,@@@,,,,,,,,,,,/@@@,,,,,,,,,,,,,,,    
        ******************,,,,,,,,,,,,,,,,,,(,,.         ,,,,,,,,,,,,,,,,,,,    
       ********************,,,,,,,,,,,*,,,,,.     %&&&     .,,,,*,,,,,,,,,,,,.  
       ***,,,,,,,,,,,,,,*,,,,,,,,,,,,,,,,,,,,               ,,,,,,,,,,,,,,,,,   
       ,,,,,,,,,,,,,,,,,,,**,,,,,,,,,,.......      ##(     ........,,,,,,,,,,.  
     .,,,,,,,,,,,,,,,,,,**,,,,,,,,,,..............    ..............,,,,,,,,    
    .,,,,,,,,,,,,,,,,,,,**,,,,,,,,,.................................,,,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,***,,,,,,,....................................,,,,,,,,,  
   ,,,,,,,,,,,,,,,,,,,,**,,,,,,,,.....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,**,,,,,,,,....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,,,     
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,.,,,,,     
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,        
     ,,,,,,,,,,,,,,,,,,,,,,,,,,,,....................................,,,        
      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,          
       ..,,,,,,,,,,,,,,,,,,,,,,,,,,.................................,           
       .........**.....       ,,,,,..............................               
        .......*......                  ****,**,       ,..****                  
        .......*,....                   .......        ......                   
          .......*....                   .....          .....                   
                                         ......          .....                  
*/

Measured memory_bytes: 3000
def c_align(N, A):
    """
    作る数列を p_1, ..., p_N としたとき、 p_{i-1} < p_i < p_{i+1} または
    p_{i-1} > p_i > p_{i+1} となるようなiは存在しないとしてよい。なぜなら、
    その他の要素の相対的順序を保ったままp_iを列の末尾に移しても、隣り合う項の
    差の絶対値の和は不変なため(末尾に移してそのようなiができたときは、
    末尾から2番めの要素を末尾に移せばよい)。

    このとき、ありうるパターンは (1) p_1>=p_2<=p_3>= ... または
    (2) p_1<=p_2>=p_3<= ... のいずれかなので、両方試して小さくない方の値を
    解とすればよい。求めたい値は
    (p_1-p_2)+(p_3-p_2)+(p_3-p_4)+(p_5-p_4)+... = \sum_{i=1}^N c_ip_i
    となる。

    Nが偶数のとき、 (1) のパターンでは c_1=1, c_N=-1, c_{2k}=-2, c_{2k+1}=2、
    (2) のパターンでは c_1=-1, c_N=1, c_{2k}=2, c_{2k+1}=-2 となる。
    (1) のパターンに基づくと、 N-1, N-3, ..., 5, 3, 1, N, N-2, ..., 4, 2 番目に
    元の数列の値が大きなものから入れていけばよい。
    (2) のパターンに基づくと、 2, 4, ..., N-2, N, 1, 3, 5, ..., N-3, N-1 番目に
    元の数列の値が大きなものから入れていけばよい。
    が、これは(1) のパターンに基づいて作った数列を逆順にしたものである。
    なので、どちらを出力してもよい。

    Nが奇数のとき、 (1) のパターンでは c_1=1, c_N=1, c_{2k}=-2, c_{2k+1}=2、
    (2) のパターンでは c_1=-1, c_N=-1, c_{2k}=2, c_{2k+1}=-2 となる。
    (1) のパターンに基づくと、 N-2, N-4, ..., 3, 1, N, N-1, N-3, ..., 4, 2 番目に
    元の数列の値が大きなものから入れていけばよい。
    (2) のパターンに基づくと、 2, 4, ..., N-3, N-1, N, 1, 3, ..., N-4, N-2 番目に
    元の数列の値が大きなものから入れていけばよい。
    この2つの数列は互いに逆順の関係というわけではないので、両方試して
    値が小さくない方を出力しなければならない。
    """
    A.sort()
    seq = [0] * N
    # コメントでは1-indexedだが、ここでは0-indexedである
    if N % 2 == 0:
        for k in range(N - 2, -1, -2):
            seq[k] = A.pop()
        for k in range(N - 1, 0, -2):
            seq[k] = A.pop()
        ans = 0
        for k in range(N - 1):
            ans += abs(seq[k] - seq[k + 1])
    else:
        tmp = A[:]
        for k in range(N - 3, -1, -2):
            seq[k] = tmp.pop()
        seq[N - 1] = tmp.pop()
        for k in range(N - 2, 0, -2):
            seq[k] = tmp.pop()

        seq2 = [0] * N
        tmp = A[:]
        for k in range(1, N - 1, 2):
            seq2[k] = tmp.pop()
        seq2[N - 1] = tmp.pop()
        for k in range(0, N - 2, 2):
            seq2[k] = tmp.pop()

        ans1, ans2 = 0, 0
        for k in range(N - 1):
            ans1 += abs(seq[k] - seq[k + 1])
        for k in range(N - 1):
            ans2 += abs(seq2[k] - seq2[k + 1])
        ans = max(ans1, ans2)
    return ans

N = int(input())
A = [int(input()) for _ in range(N)]
print(c_align(N, A))

Measured memory_bytes: 9488
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        int a, b;
        try (Scanner cin = new Scanner(System.in)) {
            a = cin.nextInt();
            b = cin.nextInt();
        }
        System.out.println(IntStream.of(a + b, a - b, a * b).max().orElse(0));
    }
}


Measured memory_bytes: 26836
N = int(input())
S = input()

sl_E = []
sl_W = []
for i, s in enumerate(S):
    E = 1 if s == "E" else 0
    W = 1 if s == "W" else 0
    s_E = sl_E[i - 1] + E if i != 0 else E
    s_W = sl_W[i - 1] + W if i != 0 else W
    sl_E.append(s_E)
    sl_W.append(s_W)

_min = sl_E[-1]
for i in range(1, N):
    count = sl_W[i - 1]
    count += sl_E[-1] - sl_E[i]
    if count < _min:
        _min = count

print(_min)


Measured memory_bytes: 117904
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p.at(i);
  sort(ALLR(p));
  int sum = p.at(0)/2;
  rep(i,n-1) sum+=p.at(i+1);
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    int R;
    cin >> R;
    double ret = R * 2 * M_PI;
    printf("%.8f\n", ret);
    return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
ll A[MAX_N], B[MAX_N];

void solve() {
	cin >> N;
	ll res = 0; ll mv = linf;
	bool same = true;
	rep(i, 0, N) {
		cin >> A[i] >> B[i];
		res += B[i];
		if(A[i] > B[i]){
			MIN(mv, B[i]);
		}
		if(A[i] != B[i]) same = false;
	}
	if(same) cout << 0 << "\n";
	else cout << res - mv << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  if(N%1000) cout << 1000 - (N%1000) << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 3632
from functools import reduce

# 入力
N = int(input())
P = [int(input()) for _ in range(N)]

INF = 10**15

# Pの逆写像
Q = {p: i for i, p in enumerate(P, 1)}

# j以上の整数を末尾に移動する場合に、先頭に移動すべき整数の個数を求める
ans = reduce(
    lambda acc, j: (
        min(
            acc[0],
            acc[1] + N - j + 1
        ),
        acc[1] if j > N or Q[j - 1] < Q[j] else
        j - 1
    ),
    range(2, N + 2),
    (INF, 0)
)[0]

# 出力
print(ans)


Measured memory_bytes: 35576
N = int(input())
a = list(map(int, input().split()))

b = [0] * N
for i in range(N):
  tmp = 0
  n = N-i
  for j in range(n*2-1, N, n):
    if b[j] == 1:
      tmp += 1
  if a[n-1] != tmp%2:
    b[n-1] = 1

ans = []
for i in range(N):
  if b[i] == 1:
    ans.append(i+1)
if ans != []:
  print(len(ans))
  print(*ans)
else:
  print(0)

Measured memory_bytes: 17844
//In the Name of God
//Ya Ali

#include <bits/stdc++.h>

#define int long long

#define err(A) cout << #A << " = " << (A) << endl

using namespace std;

const int mod = 1e9 + 7;
const int maxn = (1 << 21) + 10;

int n;
vector<int> g[maxn];

int b[maxn];
int w[maxn];

void dfs(int v, int par=-1)
{
  b[v] = 1;
  w[v] = 1;
  
  for (int u: g[v])
    if (u != par)
      {
	dfs(u, v);
	b[v] = b[v] * w[u] % mod;
	w[v] = w[v] * (w[u] + b[u]) % mod;
      }
}

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

  cin >> n;

  for (int i = 0; i < n - 1; i ++)
    {
      int v, u;
      cin >> u >> v;
      u --;
      v --;
      g[v].push_back(u);
      g[u].push_back(v);
    }

  dfs(0);

  cout << ((w[0] + b[0]) % mod) << endl;
    
  return 0;
}


Measured memory_bytes: 60928
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main(){
   ll ans=0;
   ll n,m;cin >>m>>n;
   if(2*m>n)ans+=n/2;
   else{
       ans+=m;
       n-=2*m;
       m=0;
       ans+=n/4;
   }
   cout <<ans <<endl;
}


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

int main() {
  int N;
  cin >> N;
  string c;
  cin >> c;
  int ans = 0;
  int l = 0, r = N-1;
  while (true) {
    if (l > r) break;
    else if (c[l] == 'R') ++l;
    else if (c[r] == 'W') --r;
    else {
      c[l] = 'R';
      c[r] = 'W';
      ++ans;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

	int ans = 0;
	for (int i = 1; i <= sqrt(x); i++)
	{
		for (int j = 2; j <= 10; j++)
		{
			int tmp = pow(i, j);
			if (tmp <= x)
			{
				ans = max(ans, tmp);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    int ans = 0;
    if(n >= 3 * 5 * 7) ans++;
    if(n >= 3 * 5 * 9) ans++;
    if(n >= 3 * 5 * 11) ans++;
    if(n >= 3 * 5 * 13) ans++;
    if(n >= 3 * 7 * 9) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>

int main() {
  std::string s;
  unsigned long long k;
  std::cin >> s >> k;

  unsigned long long i = 0;
  while (s[i] == '1' && i <= k) {
    i++;
  }

  if (k <= i) {
    std::cout << '1' << std::endl;
  } else {
    std::cout << s[i] << std::endl;
  }
}

Measured memory_bytes: 256
import functools
import math
def gcd_2(*vals):
    return functools.reduce(math.gcd, vals)
K = int(input())
ANS = 0
L = list(range(1, K+1))
M = list(range(1, K+1))
N = list(range(1, K+1))



for i in range(K):
    for j in range(K):
        for k in range(K):
            ANS = ANS + gcd_2(L[i], M[j], N[k])

print(ANS)

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

int main(){
	int n, m, a[1000], b[1000], vote[1000]={0};
	scanf(" %d %d", &n, &m);
	for(int i=0; i<n; ++i) scanf(" %d", &a[i]);
	for(int i=0; i<m; ++i) scanf(" %d", &b[i]);
	
	sort(b,b+m, greater<int>());
	
	int now=0;
	for(int i=0; i<m; ++i){
		for(int j=now; j<n; ++j){
			if(a[j] <= b[i]){
				++vote[j];
				now=j;
				//printf("::%d\n",j);
				break;
			} 
		}
	}
	
	int ans=0, max=0;
	for(int i=0; i<n; ++i){
		if(max < vote[i]){
			max=vote[i];
			ans=i+1;
		}
	}
	
	printf("%d\n", ans);
		
	return 0;
}

Measured memory_bytes: 1216
#include <iostream>
using namespace std;
int main() {
    int N, M; cin >> N >> M;
    int s[N][2], c[M][2];
    for(int i = 0; i < N; i++) cin >> s[i][0] >> s[i][1];
    for(int i = 0; i < M; i++) cin >> c[i][0] >> c[i][1];
    for(int i = 0; i < N; i++) {
        int min_d = 400000001, min_idx = 0;
        for(int j = 0; j < M; j++) {
            int d = abs(s[i][0]-c[j][0])+abs(s[i][1]-c[j][1]);
            if(d >= min_d) continue;
            min_d = d;
            min_idx = j+1;
        }
        cout << min_idx << endl;
    }
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)

int M, N, P[10010], S[10010], C[555], E[555];
int dp[10010];

int main() {
	scanf("%d %d", &M, &N);
	for_(i,0,M) scanf("%d", &P[i]);
	for_(i,0,N) scanf("%d %d", &C[i], &E[i]);
	
	sort(P, P+M);
	
	S[0] = 0;
	for_(i,0,M) S[i + 1] = S[i] + P[M - i - 1];
	
	fill(dp, dp + M + 1, 1e9);
	dp[0] = 0;
	
	for_(i,0,N) for_rev(j,M+C[i],C[i]) {
		int nx = min(j, M);
		dp[nx] = min(dp[nx], dp[j - C[i]] + E[i]);
	}
	
	int ans = 0;
	for_(i,0,M+1) ans = max(ans, S[i] - dp[i]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1344
#include<stdio.h>
int main()
{
    int a[100]={0},i,n;
    scanf("%d",&n);
    for(i=0;i<=n-1;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=n-1;i>=1;i--)
    {
        printf("%d ",a[i]);
    }
    printf("%d", a[0]);
    printf("\n");
    return 0;
}

Measured memory_bytes: 600
/*
貪欲
後ろから見る
DP
順位表をチェック
二分探索
不変なもの・偶奇に注目

*/
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include<tuple>
#include<set>
using namespace std;
#define INF 1100000000000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;
//typedef pair< pair<int,int>,pair<int,int> > p;
#define int ll
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());

signed main(){
    int N;
    cin>>N;
    vector<P> V(N);
    for(int i=0;i<N;i++){
        cin>>V[i].first;
        V[i].second=i;
    }
    sort(V.begin(),V.end());

    int count=0;
    for(int i=0;i<N;i++){
        if(V[i].second%2!=i%2) count++;
    }
    cout<<count/2<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m;
	while(1){
		cin >> n >> m;
		if(n==0&&m==0)break;
		vector<int> a(n),w(m);
		for(int i=0;i<n;i++){
			cin >> a[i];
		}
		for(int j=0;j<m;j++){
			cin >> w[j];
		}
		set<int> s;
		for(int i=0;i<pow(3,m);i++){
			int x=0,y=0;
			int cp=i;
			for(int j=0;j<m;j++){
				if(cp%3==0){
					x+=w[j];
				}
				else if(cp%3==1){
					y+=w[j];
				}
				cp/=3;
			}
			s.insert(x-y);
		}
		vector<int> v;
		for(int i=0;i<n;i++){
			if(s.find(a[i])==s.end())v.push_back(a[i]);
		}
		if(v.size()==0){
			cout << 0 << endl;
			continue;
		}
		set<int> st;
		for(auto p:s){
			st.insert(abs(p-v[0]));
			st.insert(abs(p+v[0]));
		}
		for(auto q:v){
			if(st.empty())break;
			set<int> st2;
			for(auto p:st){
				if(s.count(q+p)!=0||s.count(-q+p)!=0||s.count(-q-p)!=0||s.count(q-p)!=0){
					st2.insert(p);
				}
			}
			st=st2;
		}
		cout << (st.empty()?-1:*st.begin()) << endl;
	}
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1000000000;

int main(){
   int N,M,X;
   cin >> N >> M >> X;
   int ans = 0;
   rep(i,M){
      int A;
      cin >> A;
      if(A < X){
         ans++;
      }else{
         break;
      }
   }
   cout << min(ans,M-ans) << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <vector>
#include <deque>
#include <climits>
#define scanf scanf_s
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007, N = 500010;

ll min2(ll v1, ll v2) { if (v1 == -1)return v2; if (v2 == -1)return v1; return min(v1, v2); }
ll pw(ll v1, ll v2, ll mod = 1000000007) {
	ll v3 = 1;
	for (; v2 != 0; v1 = (v1 * v1) % mod, v2 = (v2 >> 1))
		if (v2 & 1)v3 = (v3 * v1) % mod;
	return v3;
}

ll n, a[N], ans;
vector<int> ls[1 << 20];
int main() {
	cin >> n;
	ls[0].pb(0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] ^= a[i - 1];
		ls[a[i]].pb(i);
	}
	if (a[n] == 0) {
		ll v1 = 1;
		for (int i = 0; i < ls[0].size() - 2; i++)v1 = (v1 * 2) % MOD;
		ans += v1;
	}
	for (int s = 1; s < (1 << 20); s++) {
		ll dp[2] = { 1,1 };
		if (a[n] != 0 && a[n] != s)continue;
		if (ls[s].size() == 0)continue;
		ll i1 = 1, i2 = upper_bound(ls[0].begin(), ls[0].end(), ls[s][0]) - ls[0].begin() - (ll)1;
		for (; i1 < ls[s].size();i1++) {
			int i2_2 = upper_bound(ls[0].begin(), ls[0].end(), ls[s][i1]) - ls[0].begin() - 1;
			ll v1 = (dp[1] * (i2_2 - i2)) % MOD;
			dp[0] = (dp[0] + v1) % MOD;
			dp[1] = (dp[0] + dp[1]) % MOD;
			i2 = i2_2;
		}
		ll v2 = (dp[1] * (ls[0].size() - 1 - i2)) % MOD;
		dp[0] = (dp[0] + v2) % MOD;

		if (a[n] == 0)ans = (ans + dp[1] + MOD) % MOD;
		else ans = (ans + dp[0]) % MOD;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 38388
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(a<b){
    cout<<"a < b"<<endl;
    }else if(a>b){
        cout<<"a > b"<<endl;
        
    }else if(a==b){
        cout<<"a == b"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3016
#include<iostream>
#include<vector>
#include<string>
#include<stdio.h>
using namespace std;

string daylist[7] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
string timelist[2] = {"Day","Night"};
int s,n,t,p,m;
string weekday,tim;

double solve(int sweek,int stime){
	double ans = 1;
	for(int i=0;i<m;i++){
		bool flag = true;
		int tindex=0;
		if(stime >= 6*60 && stime < 18*60){
			tindex = 0;
		}else{
			tindex = 1;
		}
		if(weekday == "All" || daylist[sweek] == weekday){
			if(tim == "All" || timelist[tindex] == tim){
				;
			}else{
				flag = false;
			}
		}else{
			flag = false;
		}

		stime += s;
		if(stime >= 24*60){
			sweek++;
			if(sweek == 7){
				sweek = 0;
			}
			stime -= 24*60;
		}

		if(stime >= 6*60 && stime < 18*60){
			tindex = 0;
		}else{
			tindex = 1;
		}
		if(weekday == "All" || daylist[sweek] == weekday){
			if(tim == "All" || timelist[tindex] == tim){
				;
			}else{
				flag = false;
			}
		}else{
			flag = false;
		}


		if(flag){
			for(int j=0;j<n;j++){
				ans *= 1-1.0/p;
			}
		}

		stime += (t-s);
		if(stime >= 24*60){
			sweek++;
			if(sweek == 7){
				sweek = 0;
			}
			stime -= 24*60;
		}
	}
	return 1-(double)ans;
}

int main(){
	while(true){
		cin >> s >> n >> t >> weekday >> tim >> p >> m;
		if(s == 0){
			break;
		}

		double ans=0;
		for(int i=0;i<7;i++){
			for(int j=0;j<(24*60);j++){
				ans = max (ans,solve(i,j));
			}	
		}
		printf("%.10f\n",ans);
	}
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD 998244353
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
struct edge{//グラフに使うヤツ
    ll from,to,cost;
};
typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main(){
    ll n;
    cin >> n;
    ll a[n];
    for (ll i=0;i<n;i++){
        cin >> a[i];
    }
    ll ans=0,right=0,sum=0;
    for (ll left=0;left<n;left++){
        while(right<n and (sum+a[right])==(sum^a[right])){
            sum+=a[right];
            right++;
        }
        ans+=(right-left);
        sum-=a[left];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5156