akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
struct edge{ll to;};
struct graph{
    ll N;
    vector<vector<edge> > G;
    vector<bool> used;
    vector<ll> depth;
    ll maxd=-1;
    ll dnode;

    graph(ll n): N(n), G(N), used(N,false), depth(N,-1) {}

    void add_edge(ll s, ll t){
        G[s].emplace_back((edge){t});
        G[t].emplace_back((edge){s}); //無向ならON
    }

    void dfs(ll v=0, ll d=0){
        used[v]=true;
        depth[v]=d;
        if(maxi(maxd,d)) dnode=v; //一番深いノードを更新
        for(auto E : G[v]){
            if(!used[E.to]){
                dfs(E.to, d+1);
            }
        }
    }

    ll delimiter(){
        dfs();
        rep(i,N) used[i]=false;
        dfs(dnode);
        return maxd;
    }
};
//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    graph g(N);
    rep(i,N-1){
        ll a,b; cin>>a>>b;
        g.add_edge(--a,--b);
    }
    ll x=g.delimiter();
    cout<< ( x%3!=1 ? "First" : "Second" )<<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 18304
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func do(m [][]int, ci []int, c int, preChanged []int) ([]int, int, []int, bool) {
	ci2 := make([]int, len(ci))
	copy(ci2, ci)
	checked := make([]bool, len(m))
	changed := make([]int, 0, len(m))
	flag := false
	j := len(m[0])
	for _, i := range preChanged {
		if checked[i] {
			continue
		}
		if ci[i] >= j {
			continue
		}
		n := m[i][ci[i]]
		if checked[n-1] {
			continue
		}
		if ci[n-1] >= j {
			flag = false
			break
		}
		if m[n-1][ci[n-1]] == i+1 {
			ci[i] = ci[i] + 1
			checked[i] = true
			ci[n-1] = ci[n-1] + 1
			checked[n-1] = true
			flag = true
			c++
			changed = append(changed, i)
			changed = append(changed, n-1)
		}
	}
	if !flag {
		return nil, c, nil, true
	}
	return ci, c, changed, false
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	var n int
	fmt.Scan(&n)
	m := make([][]int, n)
	for i := 0; i < n; i++ {
		v := nextInts(n - 1)
		m[i] = v
	}
	var day int
	var c int
	ci := make([]int, len(m))
	max := (n * (n - 1)) / 2
	preChanged := make([]int, 0, len(m))
	for i := 0; i < len(m); i++ {
		preChanged = append(preChanged, i)
	}
	for c < max {
		// ci2 := make([]int, len(ci))
		// copy(ci2, ci)
		checked := make([]bool, len(m))
		changed := make([]int, 0, len(m))
		flag := false
		j := len(m[0])
		for _, i := range preChanged {
			if checked[i] {
				continue
			}
			if ci[i] >= j {
				continue
			}
			n := m[i][ci[i]]
			if checked[n-1] {
				continue
			}
			if ci[n-1] >= j {
				flag = false
				break
			}
			if m[n-1][ci[n-1]] == i+1 {
				ci[i] = ci[i] + 1
				checked[i] = true
				ci[n-1] = ci[n-1] + 1
				checked[n-1] = true
				flag = true
				c++
				changed = append(changed, i)
				changed = append(changed, n-1)
			}
		}
		if !flag {
			day = -1
			break
		}
		preChanged = changed
		day++
	}
	fmt.Println(day)
}


Measured memory_bytes: 18304
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin >> a;
    vector<int> A(a);
    for(int i=0;i<a;i++)
      cin >> A.at(i);
    int sum = 0;
    for(int i = 0;i<a;i++){
        for(int j = i + 1;j<a;j++){
            sum += A.at(i)*A.at(j);
        }
    }
    cout << sum << endl;
} 
    

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 1000005
int n, A[N], num[N];
char S[N];
int Abs(int x){return x < 0 ? -x : x;}
int Getval(int n, int m){return num[n] - num[m] - num[n - m];}
int main()
{
	scanf("%d", &n);
	scanf("%s", S + 1);
	n--;
	for (int i = 1; i <= n; i++)
		A[i] = Abs(S[i] - S[i + 1]);
	if (n == 1)
	{
		printf("%d\n", A[1]);
		return 0;
	}
	for (int i = 1; i <= n; i++)
	{
		num[i] = num[i - 1];
		int x = i;
		while (x % 2 == 0)
			num[i]++, x /= 2;
	}
	int flg = 0, val = 0;
	for (int i = 1; i <= n; i++)
	{
		if (A[i] == 1)
		{
			flg = 1;
			val ^= (Getval(n - 1, i - 1) == 0);
		}
	}
	if (flg)
	{
		printf("%d\n", val);
		return 0;
	}
	for (int i = 1; i <= n; i++)
		if (A[i] == 2)
			val ^= (Getval(n - 1, i - 1) == 0);
	printf("%d\n", val * 2);
}


Measured memory_bytes: 9088
#include <iostream>
#include <vector>

using namespace std;

class HighWidth {
public:
	int h;
	int w;
	HighWidth() {}
	~HighWidth() {}
};

int main(void) {
	int H, W;

	vector<HighWidth> v;
	while (cin >> H >> W) {
		if (H == 0 && W == 0) {
			break;
		}
		
		HighWidth work;
		work.h = H;
		work.w = W;

		v.push_back(work);
	}

	bool plaidflg;
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].h; j++) {
			if (j % 2 == 0) {
				plaidflg = true;
			}
			else {
				plaidflg = false;
			}

			for (int k = 0; k < v[i].w; k++) {
				if (plaidflg) {
					cout << "#";
				}
				else {
					cout << ".";
				}
				plaidflg = !plaidflg;
			}

			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);



void solve() {
	int n; cin >> n;
	vector<int> b(n);
	rep(i, n-1) {
		cin >> b[i];

	}
	int sum = 0;
	rep(i, n) {
		int mi = mod;
		if (i < n - 1) {
			mi = min(mi, b[i]);
		}
		if (i > 0) {
			mi = min(mi, b[i - 1]);
		}
		sum += mi;
	}
	cout << sum << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(50);
	//init();
	solve();

	//cout << "finish" << endl;
	//stop
		return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    if (a > 0) {
        if (k >= a) {
            k -= a;
            a = 0;
        }
        else {
            a -= k;
            printf("%lld %lld\n",a, b);
            return 0;
        }
    }
    if (b > 0) {
        if (k >= b) {
            b = 0;
        }
        else {
            b -= k;
        }
    }
    printf("%lld %lld\n", a, b);
    return 0;
}

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

int gcd(int p, int q) {
  if (p % q == 0) {
    return q;
  }
  return gcd(q, p%q);
}

int main() {
  int N;
  cin >> N;
  int sum = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      for (int k = 1; k <= N; k++) {
        sum += gcd(i, gcd(j, k));
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3580
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

vector<int> getInt() {
	char c = getchar();
	vector<int> res;
	while (c >= '0' && c <= '9') {
		res.push_back(c - '0');
		c = getchar();
	}
	return res;
}
int main() {
	vector<int> nn = getInt();
	int n = nn.size(); // n <= 100
	int k;
	cin >> k;
	LL **f = new LL*[n + 1];
	for (int i = 0; i <= n; ++i) {
		f[i] = new LL[4];
	}
	f[0][0] = f[0][1] = f[0][2] = f[0][3] = 0;
	for (int i = 1; i <= n; ++i) {
		f[i][1] = f[i - 1][1] + 9;
		f[i][2] = f[i - 1][2] + f[i - 1][1] * (LL)(9);
		f[i][3] = f[i - 1][3] + f[i - 1][2] * (LL)(9);
		// cout << f[i][1] << ' ' << f[i][2] << ' ' << f[i][3] << endl;
	}
	// f[1][...]: 1...9
	// f[2][...]: 1 ... 99
	// f[100][...] 1 ... 10^100 - 1
	// f[n - 1][k]: 1...10^[n - 1] - 1
	// then we need 10^(n - 1) ... nn
	LL res = f[n - 1][k];
	if (k == 1) {
		res += nn[0];
	}
	if (k == 2) {
		res += (nn[0] - 1) * f[n - 1][1];
		//if (n >= 2) {
		int kk = 1;
		while (kk < nn.size() && nn[kk] == 0) { 
			++kk;
		}
		if (kk != nn.size()) {
			res += (nn[kk] * 1 + f[n - kk - 1][1]);
		}
		//}
	}
	if (k == 3) {
		res += (LL)(nn[0] - 1) * f[n - 1][2];
		// cout << "res = " << res << endl;
		int k1, k2;
		k1 = 1;
		while (k1 < nn.size() && nn[k1] == 0) {
			++k1;
		}
		// cout << "k1 = " << k1 << endl;
		if (k1 != nn.size()) {
			res += ((LL)(nn[k1] - 1) * f[n - k1 - 1][1] + f[n - k1 - 1][2]);
			k2 = k1 + 1;
			while (k2 < nn.size() && nn[k2] == 0) {
				++k2;
			}
			if (k2 != nn.size()) {
				res += ((LL)(nn[k2]) * 1 + f[n - k2 - 1][1]);
			}
		}
	}
	cout << res << endl;
	return 0;
}

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

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> c(h);
  for(int i = 0; i < h; i++)cin >> c.at(i);
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++)cout<<c.at(i).at(j);
    cout<<endl;
    for(int j = 0; j < w; j++)cout<<c.at(i).at(j);
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int ,input().split()))
b = [0]*n
b[0] = a[0]
for i in range(1,n):
  b[i] = b[i-1]+a[i]
s = sum(a)
ans = s
for i in range(n):
  ans = min(ans, abs(s-b[i] - b[i]))
  
print(ans)

Measured memory_bytes: 26224
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    int x = 0, f = 1;
    while (n--){
        string s;
        cin >> s;
        if (s == "A") x++;
        else x--;
        if (x < 0) f = 0;
    }
    if (x != 0) f = 0;
    cout << (f ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define _K ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld long double
#define ll long long
#define pb push_back
#define pi acos(-1)
#define eps 1e-7
#define F first
#define S second
#define X real()
#define Y imag()
#define cross(a,b) (conj(a)*(b)).X
#define dot(a,b) (conj(a)*(b)).Y
#define all(f) (f).begin(),(f).end()
#define allr(f) (f).rbegin(),(f).rend()
const int mod = 1e9+7 , A = 1e5 ;
typedef complex <ld> point ;
typedef vector <point> polygon ;
typedef tuple <int , int , int> line ;
//====================================
ll n , k , ans[100005] , h[100005] ;
ll solve(ll ind)
{
	if (ind >= n)
		return 1e10 ;
	if (ind == n-1)
		return 0 ;
	if (ans[ind] != -1)
		return ans[ind] ;
	ll val = 1e10 ;
	for (int i = ind + 1 ; i <= min(ind + k , n-1) ; i++)
		val = min(val , abs(h[ind] - h[i]) + solve(i)) ;
	ans[ind] = val ;
	return val ;
}
int main()
{
	_K
	cin >> n >> k ;
	memset(ans , -1 , sizeof ans) ;
	for (int i =0 ; i < n ; cin >> h[i++]) ;
	cout << solve(0) ;
	return 0 ;
}

Measured memory_bytes: 6528
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)
for i in range(M):
    xi, yi, ci = map(int, input().split())
    ans = min(ans, a[xi - 1] + b[yi - 1] - ci)
print(ans)


Measured memory_bytes: 18736
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())


//INT_MAX
//INT_MIN
//LLONG_MAX
//LLONG_MIN
//DBL_MIN
//DBL_MAX
//LDBL_MIN
//LDBL_MAX

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3, x4, y3, y4;
    int dx = x2 - x1;
    int dy = y2 - y1;
    x3 = x2 - dy;
    y3 = y2 + dx;
    x4 = x3 - dx;
    y4 = y3 - dy;
    cout << x3 << ' ' << y3  << ' ' << x4  << ' ' << y4 << ' '  << endl;
}


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

int N;

vector<int> func(int a){
  vector<int>ret;
  for(int i = 1 ; i*i <= a ; i++){
    if(a%i == 0){
      ret.push_back(i);
      if(i != a/i)ret.push_back(a/i);
    }
  }
  sort(ret.begin(),ret.end());
  return ret;
}

int main(){
  cin >> N;
  vector<int>vec[N];
  for(int i = 0 ; i < N ; i++){
    int tmp;
    cin >> tmp;
    vec[i] = func(tmp);
  }

  vector<int>res,tmp;
  res = vec[0];
  
  for(int i = 1 ; i < N ; i++){
    tmp.clear();
    for(int j = 0 ; j < res.size() ; j++){
      for(int k = 0 ; k < vec[i].size() ; k++){
        if(res[j] == vec[i][k]){
          tmp.push_back(res[j]);
        }
      }
    }
    res = tmp;
  }

  for(int i = 0 ; i < res.size() ; i++){
    cout << res[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <algorithm>
using namespace std;
	
int main(){
  int n;
  scanf("%d",&n);
  int a[n],b[n],c[n];
  for(int i = 0; i < n; ++i){
    scanf("%d %d %d",&a[i],&b[i],&c[i]);
  }
  int dp[n][3]{0};
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  for(int i = 1;i<n;++i){
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c[i];
  }
  int m = dp[n-1][0];
  for(auto x: dp[n-1]){
    m = max(m,x);
  }
  printf("%d",m);
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X) for(long int I=X;I>=0;I--)
#define INF 1e9+7
using namespace std;

bool water[3000];
bool sugar[3000];

int main(){
  int A,B,C,D,E,F,a=0,b=0;
  cin >> A >> B >> C >> D >> E >> F;
  for(int i = 0;i*A <= F;i+=100){
    for(int j = 0;i*A+j*B <= F;j+=100){
      water[i*A+j*B]=1;
    }
  }
  for(int i = 0;i*C <= F;i++){
    for(int j = 0;i*C+j*D <= F;j++){
      sugar[i*C+j*D]=1;
    }
  }
  FOR(i,0,3000)FOR(j,0,3000){
    if(water[i] && sugar[j] && i + j <= F){
      if(j*(100+E)<=E*(i+j) && j*(a+b)>=b*(i+j)){
        a = i;
        b = j;
      }
    }
  }
  cout << a+b << " " << b << endl;
}


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

 vector<bool> valid(222222,true);


class UnionFind{
    public:
    vector<int> parent;

    UnionFind(int N){
        parent = vector<int>(N,-1);
    }

    int root(int A){
        if(parent[A] < 0) return A;
        return parent[A]=root(parent[A]);
    }

    int size(int A){
        return -parent[root(A)];
    }

    bool unite(int A, int B) {
    
        A = root(A);
        B = root(B);

        if(A == B) return false; 


        if(size(A) < size(B)) swap(A,B);


        parent[A] += parent[B];
        parent[B] = A;
        if(valid[B] == 0) valid[A] = 0;

        return true;
    }

    bool same(int A, int B){
        return root(A)==root(B);
    } 
};
 
signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);
 
    int n,h,w;
    cin>>n>>h>>w;
    pair<ll,pair<int,int>> v[n];
    for(int i=0;i<n;i++){
        ll r,c,a;
        cin>>r>>c>>a;
        v[i] = make_pair(a,make_pair(r-1,c-1 + h));
    }
    sort(v,v+n,greater<pair<ll,pair<int,int>>>());

    UnionFind uni(h+w+1);

    ll ans = 0;
    
    int cnt=0;

    for(int i=0;i<n;i++){
        pair<int,int> p = v[i].second;
        int t=uni.root(p.first),s = uni.root(p.second);
        if(!valid[t] && !valid[s]) continue;
        
        if(!uni.same(s,t)){
            uni.unite(s,t);
            ans += v[i].first;
            cnt++;
        }    
        else if(valid[uni.root(t)] && valid[uni.root(s)]){
            ans += v[i].first;
            valid[uni.root(t)]=0,valid[uni.root(s)]=0;
            cnt++;
        }
        if(cnt==h+w+1) break;

    }
    cout<<ans<<endl;
    
    
}

Measured memory_bytes: 2688
#include <stdio.h>
#include <math.h>

int main() {
	int i, N, M, ans; int s = 0;
  	scanf("%d%d", &N, &M);
	int A[100000];
    for(i=0; i<M; i++){
    	scanf("%d", &A[i]);
      	s += A[i];
    }
	ans = N - s;
    if(ans > -1){
    	printf("%d\n", ans);
    }else{
    	printf("-1\n");
    }
    return 0;
}

Measured memory_bytes: 1736
N,M,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c=[0]
d=[0]
a.each{|x|c << c[-1]+x}
b.each{|y|d << d[-1]+y}
ans=0
j=M
c.each_with_index do |c,i|
    break if c > k
    while d[j] > k-c
        j -= 1
    end
    ans=[ans,i+j].max
end
puts ans


Measured memory_bytes: 45184
let n = stdin.ReadLine() |> int
let a = stdin.ReadLine().Split() |> Array.map int |> Array.toList

let rec f x ls =
 match ls with
 |[] -> x
 |hd :: tl -> (if x = hd then (f (x + 1) tl) else (f x tl))

let mae = f 1 a

if (mae = 1) then -1 else ((n - mae) + 1)
|>stdout.WriteLine

Measured memory_bytes: 37328
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

# print(f'{n} {m} {k}')

arr1 = [0] * (n + 1)
arr2 = [0] * (m + 1)
for i in range(0, n):
    arr1[i + 1] = arr1[i] + a[i]
for i in range(0, m):
    arr2[i + 1] = arr2[i] + b[i]

# print(arr1)
# print(arr2)

ans = 0

j = n
for i in range(m + 1):
    if k < arr2[i]:
        break
    
    # print(arr1[j])
    # print(arr2[i])
    while arr1[j] > k - arr2[i]:
        # print(j)
        # print(i)
        j -= 1
    ans = max(ans, i + j)


print(ans)

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

int c[10][10];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int head, teal;
	for(int i = 1; i <= n; i++){
		head = i;
		while(head/10 > 0){head /= 10;}
		teal = i%10;
		c[head][teal]++;
	}
	long long ans = 0;
	for(int i = 1; i <= 9; i++){
		for(int j = 1; j <= 9; j++){
			ans += c[i][j] * c[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}

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


int main(){
  int h,w;
  cin >> h >> w;
  vector<string> a(h);
  for(int i=0;i<h;++i){
    cin >> a[i];
  }
  int n=a[0].size();
  for(int i=0;i<n+2;++i){
    cout << "#";
  }
  cout << endl;
  for(int i=0;i<h;++i){
    cout << "#" << a[i] << "#" << endl;
  }
  for(int i=0;i<n+2;++i){
    cout << "#";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a,b;
  	cin>>a>>b;
  
  	//桁数を比較する
  	if(a.size()>b.size()){
      cout<<"GREATER";
      return 0;
    }
  	
  	if(a.size()<b.size()){
      cout<<"LESS";
      return 0;
    }
  	
  	//桁数が同じ・・abまったく同じとき
  	if(a==b) {
      cout<<"EQUAL";
       return 0;
    }
  
  	//桁数は同じ・・abの数字が違う
	if(a>b){
      cout<<"GREATER";
      return 0;
    }
  
  	if(a<b){
      cout<<"LESS";
      return 0;
    }
  
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    P = [0] * (2 * N)
    for i in range(N):
        a, b = map(int, readline().split())
        P[i] = (a, b, 0)
    for i in range(N, 2 * N):
        c, d = map(int, readline().split())
        P[i] = (c, d, 1)

    P.sort(reverse=True)

    vec = [0] * (2 * N + 1)
    ans = 0

    for x, y, p in P:
        if p == 0:
            for i in range(y + 1, 2 * N + 1):
                if vec[i] > 0:
                    vec[i] -= 1
                    ans += 1
                    break
        else:
            vec[y] += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
 
#define IOS  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int  long long

vector <int> a, b, c, d;
int ans;
int n, m, q;

void dfs(vector <int> A)
{
	if(A.size() == n)
	{
		int sm = 0;
		for(int i = 0; i < q; i++)
		{
			if(A[b[i]] - A[a[i]] == c[i]) sm += d[i];
		}
		ans = max(ans, sm);
		return ;
	}
	int t = (A.size() ? A.back() : 1);
	for(int i = t; i <= m; i++)
	{
		A.push_back(i);
		dfs(A);
		A.pop_back();
	}
}

int32_t main()
{	
	IOS
	cin >> n >> m >> q;
	a = b = c = d = vector<int>(q);
	for(int i = 0; i < q; i++) 
	{
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}
	vector <int> A;
    dfs(A);
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
N,M=list(map(int,input().split()))
s=1
m=N
for i in range(M):
    a,b=list(map(int,input().split()))
    if s<a:
        s=a
    if m>b:
        m=b
    #ans &=tmp
ans=m-s+1
if ans>0:
    print(ans)
else:
    print(0)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD 1000000007
using namespace std;

int main(){
ll a,b;
cin>>a>>b;

ll ans =0;
ll tmp=1;
while(1){

if(tmp>=b){
  break;
}

ans++;
tmp=tmp+a-1;


}
cout<<ans<<endl;

}


Measured memory_bytes: 256
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
typedef pair<string, int> P;
typedef pair<P, int> Rest;
int main() {
	int N;
	cin >> N;
	vector<Rest> rest;
	rep(i, N) {
		string s;
		int p;
		cin >> s >> p;
		rest.emplace_back(P(s, -p), i + 1);
	}
	sort(ALL(rest));
	rep(i, N) cout << rest[i].second << endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

int main() {
    ll ans = 0;
    int n;
    vi v, c;

    cin >> n;

    v.resize(n);
    c.resize(n);

    REP(i,n) cin>>v[i];
    REP(i,n) cin>>c[i];

    REP(i,n) {
        ans += max(0, v[i] - c[i]);
    }
    
    cout << ans << endl;
    return 0;
}

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

int main() {
  u32 l, r, d;
  cin >> l >> r >> d;
  cout << r / d - (l - 1) / d;

  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long ll;

int main(int argc, char const *argv[]) {
    ll a, b;
    char op;
    std::cin >> a >> op >> b;
    if (op == '+') {
        std::cout << a + b << '\n';
    } else {
        std::cout << a - b << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.{readLine,readInt}

object Main {

  def main(args: Array[String]) = {
    val n = readInt
    val a = Array.ofDim[Int](4,3,10)

    1 to n foreach { _ =>
      val Array(b,f,r,v) = readLine.split(" ").map(_.toInt)
      a(b-1)(f-1)(r-1) += v
    }

    for(i <- 0 to 3) {
      for(j <- 0 to 2) {
        for(k <- 0 to 9) {
          print(" "+a(i)(j)(k))
        }
        println()
      }
      if(i<3) {
        println("####################")
      }
    }
  }
}

Measured memory_bytes: 44220
#include<stdio.h>
#include<iostream>
#include<string>
#include<iostream>


using namespace std;

int main(void){

int a,b,c,x;

cin >> a;
cin >> b;
cin >> c;
cin >> x;

int counter = 0;

for (int i = a; i >= 0; i--){
  int v = x;
  v -= i*500;
  if(v==0){
    counter++;
    continue;
  }
  if(v<0)continue;
  for(int h = b; h >= 0; h--){
    int k = v;
    k -= h*100;
    if(k==0){
      counter++;
      continue;
    }
    if(k<0)continue;
    if(k/50 <= c){
      counter++;
      continue;
    }
    else{break;}
  }

}

cout << counter << endl;



return 0;

}


Measured memory_bytes: 256
using System;
namespace _141c
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] read = Console.ReadLine().Split();
            int N = int.Parse(read[0]);
            long K = long.Parse(read[1]);
            long Q = long.Parse(read[2]);
            int[] A = new int[Q];
            for(int i = 0; i < Q;i++){
                A[i] = int.Parse(Console.ReadLine());
            }
            long[] resArray = new long[N];
            for(int i = 0;i<N;i++){
                resArray[i] = K-Q;
            }
            for(int i = 0; i < Q; i++){
                resArray[A[i]-1]++;
            }
            for(int i=0;i<N;i++){
                Console.WriteLine(resArray[i]>0?"Yes":"No");
            }
        }
    }
}

Measured memory_bytes: 18268
import math


def get_max(n, p):
    factors = []
    counts = []

    count = 0
    while p % 2 == 0:
        count += 1
        p = p / 2

    if count > 0:
        factors.append(2)
        counts.append(count)

    for i in xrange(3, int(math.sqrt(p)) + 1, 2):
        # print i

        count = 0
        while p % i == 0:
            count += 1
            p = p / i

        if count > 0:
            factors.append(i)
            counts.append(count)

    if p > 2:
        factors.append(p)
        counts.append(1)

    if len(factors) == 0:
        return 1

    i = len(factors) - 1

    ans = 1

    while i >= 0:

        # print counts[i], n

        if counts[i] >= n:

            power = int(counts[i]/n)
            ans *= factors[i]**power

        i -= 1

    return ans

N, P = map(int, raw_input().split())
print get_max(N, P)

Measured memory_bytes: 2820
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;

int main(void)
{
    int ans = 0;

    int k, n;
    scanf("%d%d", &k, &n);

    int a[n + 1];
    rep(i, n)
        scanf("%d", &a[i]);
    a[n] = k + a[0];

    int max = 0;
    rep(i, n)
        max = max(max, a[i + 1] - a[i]);

    printf("%d", k - max);

    return 0;
}

Measured memory_bytes: 896
from collections import Counter

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


N = int(input())
matched = [False] * N
s = [None] * N
for i in range(N):
    moji = list(input())
    moji.sort()
    tmp = "".join(moji)
    s[i]= tmp

s.sort()
#print(s)
ans = 0
i = 0
j = 1
while i < N-1:
    cnt = 0
    #print("ss",i,j)
    if j == N:
        break
    while j <= N-1:
        #print("aa",i,j)
        if s[i] == s[j]:
            cnt += 1
            j += 1
            continue
        else:

            i = j
            j = i+1
            break
    if cnt >= 1:
        ans += cmb(cnt+1,2)
    

print(ans)

Measured memory_bytes: 58584
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;

import static java.lang.Integer.parseInt;

/**
 * Battle Town
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		int t = parseInt(br.readLine());
		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int h = parseInt(line.substring(0, line.indexOf(' ')));
			int w = parseInt(line.substring(line.indexOf(' ') + 1));

			char map[][] = new char[h + 2][w + 2];
			Tank tank = null;

			for (int i = 0; i < h + 2; i++) {
				Arrays.fill(map[i], 'x');
			}

			for (int i = 1; i < h + 1; i++) {
				line = br.readLine();
				for (int j = 0; j < w; j++) {
					map[i][j + 1] = line.charAt(j);
					if ("^v<>".indexOf(map[i][j + 1]) > -1) {
						// init tank.
						tank = new Tank(map[i][j + 1], map, new int[]{i, j + 1});
						map[i][j + 1] = '.';
					}
				}
			}

			// sim
			br.readLine();
			line = br.readLine();
			for (char c : line.toCharArray()) tank.command(c);
			tank.finish();
			t--;

			// solve
			for (int i = 1; i < h + 1; i++) {
				for (int j = 1; j < w + 1; j++) {
					System.out.print(map[i][j]);
				}
				System.out.println();
			}
			if (t > 0) {
				System.out.println();
			}

		} //end while
	} //end main
}

class Tank {

	static HashMap<Character, Character> cmds = new HashMap<Character, Character>() {
		{
			put('U', '^');
			put('D', 'v');
			put('L', '<');
			put('R', '>');
		}
	};
	static HashMap<Character, int[]> dirs = new HashMap<Character, int[]>() {
		{
			put('^', new int[]{-1, 0});
			put('v', new int[]{1, 0});
			put('<', new int[]{0, -1});
			put('>', new int[]{0, 1});
		}
	};

	private char dir;
	private char[][] map;
	private int[] pos;

	Tank(char dir, char[][] map, int[] pos) {
		this.dir = dir;
		this.map = map;
		this.pos = pos;
	}

	void command(char cmd) {
		if (cmd != 'S') {
			move(cmd);
		} else {
			shoot();
		}
	}

	private void move(char cmd) {
		this.dir = cmds.get(cmd);
		int[] next = new int[]{this.pos[0], this.pos[1]};
		next[0] += dirs.get(this.dir)[0];
		next[1] += dirs.get(this.dir)[1];
		if (map[next[0]][next[1]] == '.') {
			this.pos[0] = next[0];
			this.pos[1] = next[1];
		}
	}

	private void shoot() {
		int[] shell = new int[]{this.pos[0], this.pos[1]};
		while (true) {
			shell[0] += dirs.get(this.dir)[0];
			shell[1] += dirs.get(this.dir)[1];
			switch (map[shell[0]][shell[1]]) {
				case '.':
				case '-':
					continue;
				case '*':
					map[shell[0]][shell[1]] = '.';
				case '#':
				case 'x':
			}
			break;
		}
	}

	void finish() {
		map[this.pos[0]][this.pos[1]] = this.dir;
	}

}

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

Measured memory_bytes: 256
import java.util.*;

public class Main {
	static int N,W,Data[][];
	
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		N=in.nextInt();W=in.nextInt();
		Data=new int[N][2];
		int V=0;
		
		for(int i=0;i<N;i++) {
			Data[i][0]=in.nextInt();
			Data[i][1]=in.nextInt();
			V+=Data[i][0];
		}
		
		int dp[][]=new int[N+1][V+1];
		for(int i=0;i<=N;i++) {
			for(int j=0;j<=V;j++)dp[i][j]=-1;
		}
		dp[0][0]=W;
		
		for(int i=0;i<N;i++) {
			int v=Data[i][0],w=Data[i][1];
			
			for(int j=0;j<=V;j++) {
				if(dp[i][j]>=0) {
					dp[i+1][j]=Math.max(dp[i+1][j],dp[i][j]);
					if(dp[i][j]-w>=0) {
						dp[i+1][j+v]=Math.max(dp[i+1][j+v], dp[i][j]-w);
					}
				}
			}
		}
		
		int p=0,min=W;
		
		for(int i=0;i<=N;i++) {
			for(int j=0;j<=V;j++) {
				//ystem.out.printf("%2d ",dp[i][j]);
				if(dp[i][j]>=0 && j>p) {
					p=j;
					min=dp[i][j];
				}
			}
			//System.out.println();
		}
		System.out.println(p);
	}

}



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

typedef long long ll;

const int inf = 1000000;

int main() {
    char s;
    string s1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string s2 = "abcdefghijklmnopqrstuvwxyz";
    cin >> s;
    for (int i = 0; i < 26; i++) {
        if (s == s1[i]) {
            cout << "A" << endl;
            return 0;
        }
    }
    for (int i = 0; i < 26; i++) {
        if (s == s2[i]) {
            cout << "a" << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3620
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int n) { return n & 1; }
constexpr bool even(const int n) { return ~n & 1; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

class UFTree {
  std::vector<int> data, rank, _size;

public:
  UFTree(const int n) : data(n), rank(n), _size(n, 1) { iota(all(data), 0); }

  int root(const int x) { return data[x] == x ? x : data[x] = root(data[x]); }

  bool same(const int a, const int b) { return root(a) == root(b); }

  void unite(int a, int b) {
    a = root(a), b = root(b);
    if (a == b) return;
    if (rank[a] < rank[b]) std::swap(a, b);
    data[b] = a;
    _size[a] += _size[b];
    if (rank[a] == rank[b]) rank[a]++;
  }

  int sizeOf(int x) { return _size[root(x)]; }

  int size() { return data.size(); }
};

main {
  int n, k;
  while (cin >> n >> k, n) {
    vi a(k);
    cin >> a;
    sort(all(a));
    bool hasZero = any_of(all(a), [](int x) { return x == 0; });
    UFTree uf(n + 1);
    loop(i, 1 + hasZero, k) if (a[i] - a[i - 1] == 1) uf.unite(a[i], a[i - 1]);
    int maxi = -INF;
    loop(i, 1, n + 1) cmax(maxi, uf.sizeOf(i));
    if (hasZero) {
      maxi++;
      loop(i, 2, n) if (uf.sizeOf(i) == 1) cmax(maxi, uf.sizeOf(i - 1) + uf.sizeOf(i + 1) + 1);
    }
    cout << maxi << endl;
  }
}

Measured memory_bytes: 5700
import sys

sys.path.append("/home/contestant/.local/lib/python3.8/site-packages")

import networkx as nx

N, Q = [int(x) for x in input().split()]
UF = nx.utils.UnionFind()
for t, u, v in [[int(x) for x in input().split()] for i in range(Q)]:
    if t == 0:
        UF.union(u, v)
    else:
        print(int(UF[u] == UF[v]))


Measured memory_bytes: 181440
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  vector<int64_t> a(n+1);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  a[n]=10000000000;
  int deep=0;
  vector<int> s(n);
  
  for(int i=0;i<n+1;i++){
    if(a[i]>=a[i+1]){
      deep++;
    }
    else {
      s[i]=deep;
      deep=0;
      
    }

  }

  sort(s.begin(),s.end());
  cout<<s[n-1]<<endl;

}

Measured memory_bytes: 1408
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=4005;

int a[N],b[N],pre[N],nxt[N];
char s1[N],s2[N];
int n,ans,cnt;

il bool all0(int *a){
	rep(i,1,n) if(a[i]) return false;
	return true;
}

il void upd(int &a,const int &b){
	if(b==-1) return;
	if(a==-1) a=b;else getmin(a,b);
}

il void calc(int d,int l,int r){
	upd(ans,cnt+2*r+l+abs(l-d)); 
	d=n-d;
	upd(ans,cnt+2*l+r+abs(r-d));
}

int main(){
	scanf("%s%s",s1+1,s2+1);
	n=strlen(s1+1);
	rep(i,1,n){
		a[i]=s1[i]-'0';
		b[i]=s2[i]-'0';
	}
	if(all0(b)) return puts(all0(a)?"0":"-1"),0;
	rep(i,1,n){
		int j=i;
		while(!b[j]){
			++pre[i];
			j=(j==1?n:j-1);
		}
		j=i;
		while(!b[j]){
			++nxt[i];
			j=(j==n?1:j+1);
		}
	}
	ans=-1;
	//lsh 0~n-1
	rep(d,0,n-1){
		cnt=0;
		vector<pii> v;
		v.clear();
		rep(i,1,n){
			int j=(i+d-1)%n+1;
			if(a[j]==b[i]) continue;
			++cnt;
			v.pb(mp(pre[j],nxt[j]));
		}
		if(v.empty()){
			upd(ans,cnt+qmin(d,n-d));
			continue;
		}
		upd(ans,cnt+n+qmin(d,n-d));
		sort(v.begin(),v.end());
		int mx=0;
		calc(d,v[v.size()-1].X,0);
		per(i,v.size()-1,0){
			getmax(mx,v[i].Y);
			calc(d,!i?0:v[i-1].X,mx);
		}
	}
	printf("%d\n",ans);
	return 0;
}


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

int main() {
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	bool ans1 = 0, ans2 = 0, ans3 = 0, ans4 = 0;
	for (int i = a, j = b, l = -1, r = -1; i != j; ) {
		if (i + l == 0) l = 1;
		if (i + l == j) {
			ans1 = 0;
			break;
		}
		i += l;
		if (j + r == i) {
			ans1 = 1;
			break;
		}
		j += r;
	}
	for (int i = a, j = b, l = -1, r = 1; i != j; ) {
		if (i + l == 0) l = 1;
		if (i + l == j) {
			ans2 = 0;
			break;
		}
		i += l;
		if (j + r > n) r = -1;
		if (j + r == i) {
			ans2 = 1;
			break;
		}
		j += r;
	}
	for (int i = a, j = b, l = 1, r = -1; i != j; ) {
		if (i + l == 0) l = 1;
		if (i + l == j) {
			ans3 = 0;
			break;
		}
		i += l;
		if (j + r > n) r = -1;
		if (j + r == i) {
			ans3 = 1;
			break;
		}
		j += r;
	}
	for (int i = a, j = b, l = 1, r = 1; i != j; ) {
		if (i + l == 0) l = 1;
		if (i + l == j) {
			ans4 = 0;
			break;
		}
		i += l;
		if (j + r > n) r = -1;
		if (j + r == i) {
			ans4 = 1;
			break;
		}
		j += r;
	}
	if ((ans1 && ans2) || (ans3 && ans4))
		puts("Alice");
	else 
		puts("Borys");
}

Measured memory_bytes: 256
using namespace std;

#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void solve() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << ((a + b) * h) / 2 << endl;;
}

int main() {
    #ifdef _DEBUG27_
        if (1)
            freopen("input.txt", "r", stdin);
    #else
        if (0) {
            freopen("weapons.in", "r", stdin);
            freopen("weapons.out", "w", stdout);
        }
    #endif

    solve();

    #ifdef _DEBUG27_
        cout << endl << "Time: " << clock() / 1000.0 << " ms";
    #endif
    return 0;
}

/** CLEARING BUFFER

    cout << VAL << flush;

    OR

    printf(VAL);
    fflush(stdout);
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;



void solve(){
    int n;
    cin >> n;
    int x,y;
    x = n*800;
    y = (n/15) * 200;
    cout << x-y << endl;
}

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {
	
	private class Node<T> {
		T value;
		Node<T> left;
		Node<T> right;
		public Node(T value) {
			this.value = value;
			left = right = null;
		}
		public String toString() {
			return value.toString();
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] pre = new int[n];
		int[] in = new int[n];
		StringTokenizer st1 = new StringTokenizer(reader.readLine());
		StringTokenizer st2 = new StringTokenizer(reader.readLine());
		int rootId = 0;
		for (int i = 0; i < n; i++) {
			pre[i] = Integer.parseInt(st1.nextToken());
			in[i] = Integer.parseInt(st2.nextToken());
			if (i == 0) {
				rootId = pre[i];
			}
		}
		reader.close();
		
		Node<Integer> rootNode = new Node<Integer>(rootId);
		for (int i = 1; i < n; i++) {
			Node<Integer> current = new Node<Integer>(pre[i]);
			addNode(rootNode, current, in);
		}
		
		postOrder(rootNode);
	}

	private void postOrder(Node<Integer> rootNode) {
		StringBuilder sb = new StringBuilder();
		Stack<Node<Integer>> stack = new Stack<Node<Integer>>();
		Node<Integer> current = rootNode;
		Node<Integer> lastVisited = null;
		while (current != null || !stack.isEmpty()) {
			if (current != null) {
				stack.push(current);
				current = current.left;
			} else {
				Node<Integer> peekNode = stack.peek();
				if (peekNode.right != null && peekNode.right != lastVisited) {
					current = peekNode.right;
				} else {
					if (sb.length() == 0) {
						sb.append(peekNode);
					} else {
						sb.append(" " + peekNode);
					}
					lastVisited = stack.pop();
				}
			}			
		}
		System.out.println(sb.toString());
	}

	private void addNode(Node<Integer> rootNode, Node<Integer> newNode, int[] in) {
		int pos1 = findPos(in, newNode.value);
		Stack<Node<Integer>> stack = new Stack<Node<Integer>>();
		stack.push(rootNode);
		while (!stack.isEmpty()) {			
			Node<Integer> current = stack.pop();
			int pos2 = findPos(in, current.value);
			if (pos1 < pos2) {
				if (current.left == null) {
					current.left = newNode;
					return;
				} else {
					stack.push(current.left);
				}
			} else {
				if (current.right == null) {
					current.right = newNode;
					return;
				} else {
					stack.push(current.right);
				}
			}
		}
	}

	private int findPos(int[] in, int id) {
		for (int i = 0; i < in.length; i++) {
			if (in[i] == id) {
				return i;
			}
		}
		return -1;
	}
}



Measured memory_bytes: 24180
#include <stdio.h>
int main(void)
{
	int n, i;
	int a, b, c;

	scanf("%d", &n);

	for(i=0; i<n; i++){
		scanf("%d %d %d", &a, &b, &c);
	
	
	if(a*a+b*b==c*c)
		printf("YES\n");
	else if(b*b+c*c==a*a)
		printf("YES\n");
	else if(c*c+a*a==b*b)
		printf("YES\n");
	else
		printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 580
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //StringBuilder bd = new StringBuilder();
        ArrayList<String> A = new ArrayList<String>();
        //int[] A = new int[26];
        //Arrays.fill(A, 0);
        String str;

        int count = 0;

        String W = sc.nextLine();

        while (true) {
            str = sc.nextLine();
            if (str.equals("END_OF_TEXT")) {
                while (A.contains(W)) {
                    A.remove(A.indexOf(W));
                    count++;
                }
                System.out.println(count);
                break;
            }
            str = str.toLowerCase();


            String[] S = str.split(" ");
            for (int i=0; i<S.length; i++) {
                A.add(S[i]);
            }
        }
        

    }
}


Measured memory_bytes: 26236
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a((1ll<<n));
	REP(i,(1ll<<n)) cin>>a[i];
	vector<pair<P,P>> dp((1ll<<n),make_pair(P(-1,-1),P(-1,-1)));
	FOR(bit,1,(1ll<<n)) {
		bitset<18> bi(bit);
		priority_queue<P> q;
		q.push(P(a[bit],bit));
		REP(i,18) {
			if(bi[i]==0) continue;
			bi[i]=0;
			if(bi.to_ullong()==0) {
				q.push(P(a[0],0));
				continue;
			}
			q.push(dp[bi.to_ullong()].first);
			q.push(dp[bi.to_ullong()].second);
			bi[i]=1;
		}
		P a=q.top();
		q.pop();
		while(q.top()==a) q.pop();
		P b=q.top();
		dp[bit].first=a;
		dp[bit].second=b;
	}
	ll maxi=0;
	REP(i,(1ll<<n)) {
		if(i==0)continue;
		maxi=max(maxi,dp[i].first.first+dp[i].second.first);
		cout<<maxi<<endl;
	}
}


Measured memory_bytes: 13312
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;

template<typename T>
void invec(vector<T> &A){rep(i, 0, A.size()) cin >> A[i];}

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

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

int H, W; cin >> H >> W;
VVI a(H, VI(W)); 
rep(i, 0, H) rep(j, 0, W) cin >> a[i][j];

int N = 0;
VVI ope; // 操作履歴
rep(h, 0, H) rep(w, 0, W-1)
    if (a[h][w] % 2){
        --a[h][w];
        ++a[h][w+1];
        ++N;
        ope.emplace_back(VI{h+1, w+1, h+1, w+2});
    }

rep(h, 0, H - 1)
    if (a[h][W-1] % 2){
        --a[h][W-1];
        ++a[h+1][W-1];
        ++N;
        ope.emplace_back(VI{h+1, W, h+2, W});
    }


cout << N << "\n";
for (VI v: ope) 
    cout << v[0] << ' ' <<  v[1] << ' ' << v[2] << ' ' << v[3] << "\n";


}
// 書いて考える．場合分け
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 12976