akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N,M;
    cin>>N>>M;
    vector<int>a(N);
    vector<int>b(N);
    vector<int>c(M);
    vector<int>d(M);
    for(int i=0;i<N;i++){
        cin>>a.at(i)>>b.at(i);
    }
    for(int i=0;i<M;i++){
        cin>>c.at(i)>>d.at(i);
    }

    for(int i=0;i<N;i++){
        int64_t dis=999999999;int num=0;
        for(int j=0;j<M;j++){
        if(dis>(abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j)))){
            dis=abs(a.at(i)-c.at(j))+abs(b.at(i)-d.at(j));num=j;}     
        }
        cout<<num+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int sum1 = 0;
		int sum2 = 0;

		for (int i = 0; i < a; i++) {
			String b = scanner.next();
			String c = scanner.next();
			if (b.compareTo(c) > 0)
				sum1 += 3;
			else if (b.compareTo(c) < 0)
				sum2 += 3;
			else {
				sum1 += 1;
				sum2 += 1;
			}
		}
		System.out.println(String.format("%d %d", sum1, sum2));
	}
}

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

int main() {
    string S;
    cin >> S;
    int N = S.size() + 1;
    vector<int> A(N,0);
    for(int i = 0; i < N-1; ++i) {
        if(S[i] == '<') A[i+1] = max(A[i+1], A[i]+1);
    }
    for(int i = N-2; i >= 0; --i) {
        if(S[i] == '>') A[i] = max(A[i], A[i+1]+1);
    }
    long long res = 0LL;
    for(auto &p: A) res += p;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2820
a,b,k= map(int,input().split())
ans = []
for i in range(k):
    if a+i <= b:
        ans.append(a+i)
for i in range(k):
    if (b-(k-1)+i)>=a:
        ans.append(b-(k-1)+i)
anset=list(set(ans))
anset.sort()
for i in range(len(anset)):
    print(anset[i])

Measured memory_bytes: 3316
n = int(input())
a = list(map(int, input().split()))

A = [0]
for i in range(n):
    A.append(A[i] + a[i])

MOD = 10**9+7
ans = 0
for i in range(n-1):
    ans += (a[i] * (A[-1]-A[i+1])) % MOD

print(ans%MOD)

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

typedef pair<int, int> pii;

const int maxn = (int)(1e5) + 5;
pii a[maxn];
int mk[maxn], good[maxn];

int main() {
  int n, K;
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &a[i].second, &a[i].first);
  }
  sort(a + 1, a + n + 1, greater<pii>());
  int cnt = 0, p = K, q = K + 1;
  long long su = 0, ret = 0;
  for (int i = 1; i <= K; ++i) {
    su += a[i].first;
    int ty = a[i].second;
    if (!mk[ty]) mk[ty] = 1, good[i] = 1, ++cnt;
  }
  ret = su + 1LL * cnt * cnt;
  for (int i = cnt + 1; ; ++i) {
    while (p >= 1 && good[p]) --p;
    while (q <= n && mk[a[q].second]) ++q;
    if (p < 1 || q > n) break;
    mk[a[q].second] = 1;
    ++cnt; su -= a[p].first; su += a[q].first; --p; ++q;
    ret = max(ret, su + 1LL * cnt * cnt);
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
int main() {
	int x[10000],i,cnt=0;
	for (i = 0; i < 10000; ++i) {
		scanf("%d", &x[i]);
		if (x[i] == 0) break;
		cnt++;
	}
	for (i = 0; i < cnt; ++i) printf("Case %d: %d\n", i+1, x[i]);
	return 0;
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    string S;
    cin >> S;
    REP(i, S.length())
    {
        if (S[i] == '1')
            cout << 9;
        else
            cout << 1;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
cnt = 0
while max(a) != 0:
  # print(a,cnt)
  betweenZero = True
  for i in range(n):
    if a[i] != 0:
      a[i] -= 1
      betweenZero = False
    elif betweenZero == False:
      cnt += 1
      betweenZero = True
  if betweenZero == False:
    cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

struct Dice{
    int f[6];
    void roll(char temp){
        switch (temp)
      {
        int temp_1;
        case 'S':
          temp_1 = f[4];
          f[4] = f[5];
          f[5] = f[1];
          f[1] = f[0];
          f[0] = temp_1;
          break;
        case 'N':
            temp_1 = f[1];
            f[1] = f[5];
            f[5] = f[4];
            f[4] = f[0];
            f[0] = temp_1;
            break;
        case 'W':
            temp_1 = f[2];
            f[2] = f[5];
            f[5] = f[3];
            f[3] = f[0];
            f[0] = temp_1;
            break;
        case 'E':
            temp_1 = f[2];
            f[2] = f[0];
            f[0] = f[3];
            f[3] = f[5];
            f[5] = temp_1;
            break;
        case 'R':
            temp_1=f[1];
            f[1]=f[2];
            f[2]=f[4];
            f[4]=f[3];
            f[3]=temp_1;
            break;
      
        default:
            break;
      }
    }
    int top(){
        return f[0];
    }
    int right(){
        return f[2];
    }
    int left(){
        return f[3];
    }
    int front(){
        return f[1];
    }
    int back(){
        return f[4];
    }
    int bottom(){
        return f[5];
    }
};
bool check_dice_same(Dice d1,Dice d2){
    bool res = false;
    if(d1.left() == d2.left() && d2.right() == d2.right() && d1.top() == d2.top()
    && d1.front() == d2.front() && d1.back() == d2.back() && d1.bottom() == d2.bottom()){
        res = true;
    }else{
        res = false;
    }
    return res;
}

int main(){
  Dice d1;
  Dice d2;
  for(int i = 0;i<6;i++){
      cin>>d1.f[i];
  }
  for(int i = 0;i<6;i++){
      cin>>d2.f[i];
  }
  string order = "NNNNWNNNWNNNENNNENNNWNNN";
  for(int i = 0;i< order.size();i++){
      d1.roll(order[i]);
      if(check_dice_same(d1,d2)){
          cout<<"Yes"<<endl;
          return 0;
      }
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;cin>>k;
    string s;cin>>s;
    int n=s.size();
    int dp[n][n];
    for(int i=0;i<n;i++) for(int j=0;j<n;j++) dp[i][j]=0;
    int max_=0;
    for(int i=1;i<n;i++)
    {
        if(s[i]==s[0]) {dp[0][i]=1; max_=1;}
    }

    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(s[i]==s[j]) {dp[i][j]=min(j-i,1+dp[i-1][j-1]); max_=max(max_,dp[i][j]);}
        }
    }
    cout<<max_;
    /*
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cout<<dp[i][j]<<' ';
        }cout<<endl;
    }
    */


    return 0;
}


Measured memory_bytes: 97920
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;

vector<int> ra(MX,0);
vector<int> par(MX,0);
using P = pair<int, int>;
using ll = long long;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int find(int x) {
    if(par[x] == x) {
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x==y) return;
    if(ra[x]<ra[y]) {
        par[x] = y;
    }else {
        par[y] = x;
        if(ra[x]==ra[y]) {
            ra[x]++;
            
        }
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int a[MX];
int c[10][1000];

signed main(){
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(), l.end());
    int ans = 0;
    FOR(mid, 1, n-1) {
        rep(sml, mid) {
            int big = l[mid]+ l[sml];
            int right = lower_bound(l.begin(), l.end(), big) - l.begin();
            int left =  mid+1;
            ans += right-left;
        }
    }
    cout << ans << endl;

    return 0;

}



Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
const int maxn = 1e5+10;
#define int ll
int n, a[maxn];
#define yn(i) ((i)?"First":"Second")
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for (int i = 1;i <= n;++i)
		cin >> a[i];
	sort(a+1, a+1+n, greater<int>());
	int x = 1;
	bool res = false;
	while (x < n && a[x+1] >= x+1)
		++x;
	res = (x + a[x] - 1) % 2 == 0;
	//cout << "X " << x << '\n';
	int y = x;
	while (y < n && a[y+1] >= x)
		++y;
	res |= (y + a[y] - 1) % 2 == 0;
	//cout << "X " << y << '\n';
	puts(yn(res));
}


Measured memory_bytes: 1024
fn main() {
    use std::io;
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("cannot read input");
    let input = input.trim().parse::<usize>().unwrap();
    let mut result = String::from("No");
    for i in 0..26 {
        for j in 0..16 {
            if input == i * 4 + j * 7 {
                result = String::from("Yes");
            }
        }
    }
    println!("{}", result);
}

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

bool nonprime[1000000];

int main(){
	long i,j,n;
	for(i=2;i<=999999;i++){
		for(j=2;i*j<=999999;j++) nonprime[i*j]=1;
	}
	while(scanf("%ld",&n)!=EOF){
		j=0;//j?????????????????¨?????????????????????
		for(i=2;i<=n;i++) if(!nonprime[i]) j++;
		cout << j << endl;
	}
	return 0;
}

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

int main() {
  int n; cin >> n;
  int ans = 0;
  rep(i,n) {
    int ai; cin >> ai;
    while(ai % 2 != 1) {
      ai /= 2;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3576
n,m=map(int, input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf=UnionFind(n)
for i in range(m):
    a,b=map(int, input().split())
    uf.union(a-1,b-1)
ans=0
for i in uf.roots():
    ans=max(ans,uf.size(i))
print(ans)

Measured memory_bytes: 18476
#include <iostream>
#include <vector>
#include <set>
using namespace std;
void saiki(int&,int,vector<set<int>>&,vector<bool>&);
int main(){
    int n,m;
    cin >> n >> m;
    vector<set<int>> friends(n);
    vector<bool> flag(n,false);
    for(int i =0;i < m;i++){
        int a,b;
        cin >> a >> b;
        friends[a-1].insert(b-1);
        friends[b-1].insert(a-1);
    }
    int max_member = 0;
    for(int i = 0;i < n;i++){
        if(flag[i]){
            continue;
        }
        int member = 1;
        saiki(member,i,friends,flag);
        max_member = max(max_member,member);
    }
    cout << max_member;
    return 0;



}
void saiki(int &member,int num,vector<set<int>>& friends,vector<bool>& flag){
    flag[num] = true;
    for(auto i:friends[num]){
        if(!flag[i]){
            member ++;
            saiki(member,i,friends,flag);
        }
    }
    return;
}


Measured memory_bytes: 43816
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int MAXN = 2e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl


struct node
{
    long long value, lazy;
} tree[4 * MAXN];
long long a[MAXN];
int h[MAXN];
void pushup(int id)
{
    tree[id].value = max(tree[2 * id].value, tree[2 * id + 1].value);
}
void createtree(int id, int s, int t)
{
    tree[id].lazy = 0;
    if (s == t)
        tree[id].value = 0;
    else
    {
        int mid = s + (t - s) / 2;
        createtree(2 * id, s, mid);
        createtree(2 * id + 1, mid + 1, t);
        pushup(id);
    }
}
void pushdown(int id, int s, int t)
{
    if (tree[id].lazy != 0)
    {
        int mid = s + (t - s) / 2;
        tree[2 * id].lazy += tree[id].lazy;
        tree[2 * id + 1].lazy += tree[id].lazy;
        tree[2 * id].value += tree[id].lazy;
        tree[2 * id + 1].value += tree[id].lazy;
        pushup(id);
        tree[id].lazy = 0;
    }
}
long long query(int id, int ns, int nt, int qs, int qt)
{
    if (qs > nt || qt < ns)
        return 0;
    if (qs <= ns && qt >= nt)
        return tree[id].value;
    pushdown(id, ns, nt);
    int mid = ns + (nt - ns) / 2;
    return max(query(2 * id, ns, mid, qs, qt), query(2 * id + 1, mid + 1, nt, qs, qt));
}
void singleupdate(int id, int ns, int nt, int index, long long value)
{
    if(ns == nt)
    {
        if(index == ns)
            tree[id].value += value;
        return;
    }
    int mid = ns + (nt - ns) / 2;
    if(index <= mid)
        singleupdate(2 * id, ns, mid, index, value);
    else
        singleupdate(2 * id + 1, mid + 1, nt, index, value);
    pushup(id);
}

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

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

    for(int i = 0; i < n; i++)  scanf("%d", &h[i]);
    for(int i = 0; i < n; i++)  scanf("%lld", &a[i]);

    createtree(1, 1, n);

    for(int i = 0; i < n; i++)
    {
        ll temp = query(1, 1, n, 1, h[i] - 1);
        singleupdate(1, 1, n, h[i], a[i] + temp);
    }

    ll answer = query(1, 1, n, 1, n);

    printf("%lld\n", answer);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

int main() {
	int n,m,l,r;
	cin>>n>>m;
	int mi=n+1,ma=0;
	for(int i=0;i<m;i++)
	{
	    cin>>l>>r;
	    if(l>=ma&&l<=mi)
	    ma=l;
	    else if(l>mi){
	    cout<<0<<endl;return 0;}
	    if(r<=mi&&r>=ma)
	    mi=r;
	    else if(r<ma)
	    {
	        cout<<0<<endl;
	        return 0;
	    }
	    //cout<<mi-ma+1<<endl;
	}
	cout<<mi-ma+1<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
if 1 <= n <= 9:
    print(n)
elif 10 <= n <= 99:
    print(9)
elif 100 <= n <= 999:
    print(n-99+9)
elif 10**3 <= n <= 9999:
    print(909)
elif 10**4 <= n <= 99999:
    print(n-9999+909)
else:
    print(90909)


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
#include <cstdint>
#include <bitset>
#include <iomanip>
using namespace std;



int main() {
	int n, a[100000], ans;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int dif = INT32_MAX;
	for (int i = 0; i < n-1; i++) {
		if (a[n - 1] % 2 == 0) {
			if (dif > abs(a[i] - (a[n - 1] / 2))) {
				dif = abs(a[i] - (a[n - 1] / 2));
				ans = i;
			}
			else {
				break;
			}
		}
		else {
			if (dif > min(abs(a[i] - (a[n - 1] / 2 + 1)), abs(a[i] - (a[n - 1] / 2)))) {
				dif = min(abs(a[i] - (a[n - 1] / 2 + 1)), abs(a[i] - (a[n - 1] / 2)));
				ans = i;
			}
			else {
				break;
			}
		}
	}
	cout << a[n - 1] << ' ' << a[ans] << endl;
	return 0;
}




Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>


using namespace std;

int main() {
	long long n;
	int k;
	cin >> n >> k;
	long long ans = 1;
	
	while(n / k){
		ans++;
		n = n / k;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int mod(int a)
{
    if(a<0)
    {
        return -1*a;
    }
    return a;
}
int main()
{
    int n;
    cin>>n;
    vector <int> arr(n);
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    vector <int> dp(n);
    dp[0]=0;
    if(n==1)
    {
        cout<<0<<endl;
        return 0;
    }
    dp[1]=mod(arr[1]-arr[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(mod(arr[i-1]-arr[i])+dp[i-1], mod(arr[i-2]-arr[i])+dp[i-2] );
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long X,Y,Z,K;
vector<long>A,B,C,ABC;
int main(){
  cin>>X>>Y>>Z>>K;
  A.resize(X);
  B.resize(Y);
  C.resize(Z);
  for(int i=0;i<X;i++)cin>>A[i];
  for(int i=0;i<Y;i++)cin>>B[i];
  for(int i=0;i<Z;i++)cin>>C[i];

  sort(A.rbegin(),A.rend());
  sort(B.rbegin(),B.rend());
  sort(C.rbegin(),C.rend());

  for(int x=0;x<X;x++){
    for(int y=0;y<Y;y++){
      if((x+1)*(y+1)>K)break;
      for(int z=0;z<Z;z++){
        if((x+1)*(y+1)*(z+1)>K)break;
        ABC.push_back(A[x]+B[y]+C[z]);
      }
    }
  }

  sort(ABC.rbegin(),ABC.rend());
  for (int i=0;i<K;i++)cout<<ABC[i]<<endl;
}


Measured memory_bytes: 1404
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int g = sc.nextInt();
        int[] p = new int[d];
        int[] c = new int[d];
        int[] sum = new int[d];
        long ans = 0;
        for (int i = 0; i < d; i++) {
            p[i] = sc.nextInt();
            c[i] = sc.nextInt();
            sum[i] = p[i] * (i + 1) * 100 + c[i];
            ans += p[i];
        }
        int maxpos = -1;
        int kaisuu = 0;

        for (int bit = 0; bit < (1 << d); bit++) {
            long wa = 0;
            maxpos = 0;
            kaisuu = 0;
            for (int i = 0; i < d; i++) {
                if ((bit & (1 << (d - 1 - i))) != 0) {

                    wa += sum[i];
                    kaisuu += p[i];
                } else {
                    maxpos = i;
                }
            }
            if (wa < g) {
                // maxposを追加していく
                for (int j = 0; j < p[maxpos]; j++) {
                    wa += (maxpos + 1) * 100;
                    kaisuu++;
                    if (wa >= g) {
                        if (kaisuu < ans) {
                            ans = kaisuu;
                            break;
                        }
                    }
                }
            } else {
                if (kaisuu < ans) {
                    ans = kaisuu;

                }
            }

        }
        System.out.println(ans);

        sc.close();
    }
}


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

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  long long money=1000LL;
  long long stock=0LL;
  for(int i=0;i<n;i++){
    if(i==n-1){
      money+=stock*(a.at(i));
    }
    else if((a.at(i)<a.at(i+1))&&(money!=0LL)){
      stock+=money/(a.at(i));
      money=money%(a.at(i));
    }
    else if((a.at(i)>a.at(i+1))&&(stock!=0LL)){
      money+=stock*(a.at(i));
      stock=0LL;
    }
  }
  cout<<money<<endl;
}


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

#define st first
#define nd second
#define pb push_back
#define mp make_pair
typedef pair< int ,int > pii;
typedef vector< pii > vii;
typedef long long ll;
typedef map<int,int> mii;
typedef set<pii> sii;
typedef set<int> si;
typedef vector< int > vi;

const ll MOD = 119 << 23 | 1;

ll gcd(ll x, ll y){
    if(!y)
        return x;
    return gcd(y,x%y);
}

ll inv(ll x) {
    ll r = 1ll, t = x, k = MOD - 2ll;
    while (k) {
        if (k & 1ll) r = (long long) r * t % MOD;
        t = (long long) t * t % MOD;
        k >>= 1;
    }
    return r;
}

const int nax = 2e5+13;

void read(){

}

void solve(){
    multiset<pair<ll,int>>s;
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    ll z;
    for(int i=0; i<a; i++){
        cin >> z;
        s.insert({-z,2});
    }
    for(int i=0; i<b; i++){
        cin >> z;
        s.insert({-z,1});
    }
    for(int i=0; i<c; i++){
        cin >> z;
        s.insert({-z,0});
    }
    ll res=0ll;
    int r=0,tx=0,ty=0;
    for(auto el:s){
        if(el.nd==0 && r<x+y){
            r++;
            res+=(-el.st);
        }else if(el.nd==2 && tx<x){
            r++;
            tx++;
            res+=(-el.st);
        }else if(el.nd==1 && ty<y){
            r++;
            ty++;
            res+=(-el.st);
        }
        if(r>=x+y)
            break;
    }
    cout << res<<endl;
}

int main() {

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

    return 0;
}


Measured memory_bytes: 19072
import sys
f = sys.stdin


while True:
    x, h = (int(f.readline()) for i in range(2))
    if x == h == 0:
        break
    triangle_height = (h ** 2 + (x / 2) ** 2) ** 0.5
    s = x ** 2 + 4 * x * triangle_height / 2
    print('{:.6f}'.format(s))

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

int main(void){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    
    ll ans = max(a*c,b*d);
    ans = max(ans,a*d);
    ans = max(ans,b*c);
    cout << ans << endl;
}

Measured memory_bytes: 3668
s=list(map(len,input().split("T")))
x,y=map(int,input().split())
def f(t,w):
    m=[{} for i in range(len(t)+1)]
    m[0][0]=1
    for i in range(len(t)):
        for z in m[i]:
            m[i+1][z+t[i]]=1
            m[i+1][z-t[i]]=1
    return w in m[len(t)]
print(["No","Yes"][f(s[2::2],x-s[0]) and f(s[1::2],y)])

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

// マクロ
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス
using lint = long long;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;

// 関数
lint gcd(lint a, lint b) {
    lint t;
    while (b != 0) {
        t = a % b; a = b; b = t;
    }
    return a;
}

int main() {

	lint N, M;
	cin >> N >> M;
    cou(N * M / gcd(N, M));
	
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
s = input()
AClist = [0] * N

for i in range(N - 1):
  AClist[i + 1] = AClist[i] + int(s[i:i + 2] == "AC")
  
for i in range(Q):
  l, r = map(int, input().split())
  print(AClist[r - 1] - AClist[l - 1])

Measured memory_bytes: 9412
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int N, K;
	cin >> N >> K;
	vector<int>A(N);
	rep(i, N)cin >> A[i];
	for (int i = K ; i < N; i++) {
		if (A[i - K] < A[i])cout << "Yes" << endl;
		else cout << "No" << endl;
	}
}

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

using namespace std;

long long dfs(long long K, long long A, long long B, long long C) {
    if (K == 0) {
        return A + B + C;
    }

    long long a = dfs(K - 1, 2 * A, B, C);
    long long b = dfs(K - 1, A, 2 * B, C);
    long long c = dfs(K - 1, A, B, 2 * C);
    return max(max(a, b), c);
}

void Main() {
    long long A, B, C;
    cin >> A >> B >> C;
    long long K;
    cin >> K;

    long long ans = dfs(K, A, B, C);
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  char a[4];
  cin>>a[0]>>a[1]>>a[2]>>a[3];
  sort(a,a+4);
  if(a[0]==a[1] && a[2]==a[3] && a[1]!=a[2]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 764
fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line);
    let mut tok = line.split_whitespace();
    let mut s: i64 = tok.next().unwrap().parse().unwrap();
    let mut w: i64 = tok.next().unwrap().parse().unwrap();
    if s <= w {
        println!("unsafe");
    } else {
        println!("safe");
    }
}


Measured memory_bytes: 2108
use std::io::*;

fn main() {
	let input = {
		let mut buf = vec![];
		stdin().read_to_end(&mut buf);
		unsafe { String::from_utf8_unchecked(buf) }
	};
	let mut lines = input.split('\n');

	let input = lines.nth(1).unwrap();
	let s_vec: Vec<u32> = input.split(' ').map(|s| s.parse().unwrap()).collect();

	let input = lines.nth(1).unwrap();
	let t_iter = input.split(' ').map(|s| s.parse::<u32>().unwrap());

	let c = t_iter.filter(|i| s_vec.contains(i)).count();

	println!("{}", c);
}



Measured memory_bytes: 5024
n = input()
a = [int(i) for i in input().split()]
even = []
num = []
for i in a:
    if i % 2 == 0:
        even.append(i)
for k in even:
    if k % 3 == 0 or k % 5 == 0:
        num.append(k)
if len(even) == len(num):
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
int main() {
	unsigned int D, N;
	cin >> D >> N;
	int ans = 0, X = 0;
	int i = 1;
	while (X != N) {
		if (D == 0) {
			if (i % 100 != 0) X++;
			ans = i;
		}
		else if (D == 1) {
			if (i % 100 == 0 && i % 10000 != 0) {
				X++;
			}
			ans = i;
		}
		else {
			if (i % 10000 == 0 && i % 1000000 != 0) {
				X++;
			}
			ans = i;
		}
		i++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,x;
long long a[59];
long long dp[59][2509][59];
long long bt(int id,long long sum,int k){
	if(id==n){
		if(k==0)return 0;
		if(sum/k==x && sum%k==0){
			return 1;
		}
		return 0;
	}
	long long &ret=dp[id][sum][k];
	if(ret!=-1)return ret;
	ret=bt(id+1,sum+a[id],k+1)+bt(id+1,sum,k);
	return ret;
}
int main(){
	memset(dp,-1,sizeof(dp));
	cin>>n>>x;
	for(int i=0;i<n;i++)cin>>a[i];
	cout<<bt(0,0,0)<<endl;
}


Measured memory_bytes: 68480
n=int(input())
b=list(map(int,input().split()))
a=[]
for i in range(n):
    for j in range(n-i-1,-1,-1):
        if b[j]==j+1:
            a.append(b.pop(j))
            break
if len(a)<n:
    print(-1)
    exit()
a.reverse()
for i in a:
    print(i)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,j,k) for(ll i = j; i < k; ++i)
#define per(i,j,k) for(ll i = j; i > k; --i)
int main() {
        ll x, y; cin >> x >> y;
        if(x % y == 0) return 0 * printf("-1\n");
        printf("%lld\n",x*y-x);
        return 0;
}


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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
	int n, i, j;
	cin >> n;
	vl x(n), s(n);
	for (i = 0; i < n; i++) {
		cin >> x[i] >> s[i];
	}
	vl sum(n + 1);
	vl left(n), right(n);
	sum[0] = 0;
	for (i = 0; i < n; i++) {
		sum[i + 1] = sum[i] + s[i];
		left[i] = sum[i] - x[i];
		right[i] = sum[i + 1] - x[i];
	}
	/*
	DEBUG_VEC(left);
	DEBUG_VEC(right);
	*/
	ll ans = -INF;
	deque<ll> dqr;
	for (i = 0; i < n; i++) {
		while (!dqr.empty() && right[dqr.back()] < right[i]) {
			dqr.pop_back();
		}
		dqr.push_back(i);
	}
	

	for (i = 0; i < n; i++) {
		/*
		for (j = 0; j < dqr.size(); j++) {
			cout << dqr[j] << " ";
		}
		cout << endl;
		*/
		ans = max(ans, right[dqr[0]] - left[i]);
		while (!dqr.empty() && dqr.front() <= i) {
			dqr.pop_front();
		}
	}
	cout << ans << endl;
}

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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 2e5 + 5;

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

  ll n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  ll happy = 0, unhappy = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'L'){
      if(i - 1 >= 0 && s[i - 1] == 'L') happy++;
      else unhappy++;
    }else{
      if(i + 1 < n && s[i + 1] == 'R') happy++;
      else unhappy++;
    }
  }

  for(int i = 0; i < k; i++){
    if(unhappy > 2) unhappy -= 2;
    else if(unhappy == 2){
      unhappy--;
      break;
    }
  }

  cout << n - unhappy << endl;
}


Measured memory_bytes: 512
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    ll ans = 0;
    int tmp;
    char trg;
    int r=0, g=0 , b=0;
    int n;
    cin >> n;
    string s;
    cin >> s;
    REP(i, s.size()){
        if(s[i] == 'R') r++;
        if(s[i] == 'G') g++;
        if(s[i] == 'B') b++;
    }
    REP(i, s.size() - 1){
        for(int j = i + 1; j < s.size(); j++){
            
            if(s[i] == s[j]) continue;
            else if(s[i] != 'R' && s[j] != 'R') tmp = r, trg = 'R';
            else if(s[i] != 'G' && s[j] != 'G') tmp = g, trg = 'G';
            else if(s[i] != 'B' && s[j] != 'B') tmp = b, trg = 'B';
            if((j - i)%2 == 0 && s[(i+j)/2] == trg) tmp--;
            if(j + (j - i) < s.size() && s[j+j-i] == trg) tmp--;
            if(i - (j - i) >= 0 && s[i-(j-i)] == trg) tmp--;
            ans += (ll) tmp;
            //cout << i << " " << j << " " << tmp << endl;
        }
    }
    cout << ans / 3 << endl;
}

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

using namespace std;

int main()
{
	const long long mod = 1000000007;

	int N;
	long long ans;
	string S[2];
	cin >> N;

	vector<int> A;

	cin >> S[0] >> S[1];

	for (int i = 0; i < N; i++)
	{
		if (S[0][i] == S[1][i])
			A.push_back(0);
		else
		{
			A.push_back(1);
			i++;
		}
	}

	if (A[0] == 0)
		ans = 3;
	else
		ans = 6;

	for (int i = 0; i < A.size() - 1; i++)
	{
		switch (A[i])
		{
		case 0:
			ans = (ans * 2) % mod;
			break;
		case 1:
			if (A[i + 1] == 1)
				ans = (ans * 3) % mod;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, yellow;
  string S;
  cin >> N;
  yellow = 0;
  
  for(int i = 0; i < N; i++){
    cin >> S;
    if(S == "Y"){
      yellow++;
    }
  }
  
    if(yellow == 0){
      cout << "Three" << endl;
    }
    else{
      cout << "Four" << endl;
    }
  
}

Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int get_gcd(int x, int y) {
	if (x < y) {
		swap(x, y);
	}

	int m = x % y;

	while (m != 0) {
		x = y;
		y = m;
		m = x % y;
	}

	return y;
}

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

	ll ans = 0;

	for (int i=1; i<=K; i++) {
		for (int j=1; j<=K; j++) {
			for (int k=1; k<=K; k++) {
				ans += get_gcd(i, get_gcd(j, k));
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

const int M = 1e5;

int n, h[M], w[M], pre[M], mod = 1e9 + 7, half, big = 2e9;
pair<int, int> seg[4 * M];

int add(int a, int b) { return a + b - (a + b >= mod) * mod; }
int sub(int a, int b) { return a - b + (a - b < 0) * mod; }
int mul(int a, int b) { return (1ll * a * b) % mod; }
int powM(int n, int p) { return (!p ? 1 : (p & 1) ? mul(n, powM(n, p - 1)) : powM(mul(n, n), p / 2)); }
int divM(int a, int b) { return mul(a, powM(b, mod - 2)); }

pair<int, int> build(int l, int r, int i) {
    if (l == r)
        seg[i] = {h[l], l};
    else
        seg[i] = min(build(l, (l + r) / 2, i * 2 + 1), build((l + r) / 2 + 1, r, i * 2 + 2));
    return seg[i];
}
pair<int, int> q(int l, int r, int L, int R, int i) {
    if (l > R || r < L)
        return {big, big};
    if (L >= l && R <= r)
        return seg[i];
    return min(q(l, r, L, (L + R) / 2, i * 2 + 1), q(l, r, (L + R) / 2 + 1, R, i * 2 + 2));
}

int summation(int x) { return mul(mul(x, add(x, 1)), half); }
int rects(int l, int w) { return mul(summation(l), summation(w)); }

int solve(int l, int r, int bef) {
    if (l > r)
        return 0;

    int curW = sub(pre[r], l ? pre[l - 1] : 0), minH, last = l, ans = 0;
    pair<int, int> cur = q(l, r, 0, n - 1, 0);
    minH = cur.first;

    while (cur.first == minH) {
        ans = add(ans, solve(last, cur.second - 1, minH));
        last = cur.second + 1;

        if (last > r)
            break;

        cur = q(last, r, 0, n - 1, 0);
    }

    ans = add(ans, solve(last, r, minH));
    ans = add(ans, sub(rects(curW, minH), rects(curW, bef)));
    return ans;
}

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

    int x, y;
    map<int, int> mp;
    cin >> x >> y;

    mp[1] = 300000;
    mp[2] = 200000;
    mp[3] = 100000;

    cout << mp[x] + mp[y] + (x == y && x == 1) * 400000 << '\n';
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    int L;
    cin >> L;
    int N = 0;
    int pow = 1;
    while(pow <= L) pow *= 2, N++;
    int M = (N-1)*2 + __builtin_popcount(L) - 1;

    cout << N << " " << M << endl;
    rep(i, 0, N-1) {
        cout << i+1 << " " << i+2 << " " << 0 << endl;
        cout << i+1 << " " << i+2 << " " << (1<<i) << endl;
    }
    int cur = 1<<(N-1);
    for(int i = N-2; i >= 0; i--) {
        if (L & (1<<i)) {
            cout << i+1 << " " << N << " " << cur << endl;
            cur += (1<<i);
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b,x; cin >> a >> b >> x;
    cout << ((a<= x&& a+b >= x) ? "YES":"NO") << 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 REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

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

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

template<class T>
T Sq(const T& t){
	return t*t;
}

int main(){
	int h=read(),w=read();
	vector<string> board;
	REP(i,h)
		board.PB(readString());
	ll ans=0;
	vector<vi> cost(2*h+1,vi(h));
	vector<vi> dp(h+1,vi(h+1));
	const int inf=INT_MAX/3;
	REP(i,w-1){
		FOR(j,-h,h+1){
			int c=0;
			REP(k,h){
				if(0<=k+j&&k+j<h&&board[k][i]==board[k+j][i+1])
					c++;
				cost[j+h][k]=c;
			}
		}
		REP(j,h+1)REP(k,h+1)
			dp[j][k]=inf;
		dp[h][h]=0;
		for(int j=h;j>=0;j--)
			for(int k=h;k>=0;k--){
				if(j+1<=h){
					int dif=k-(j+1);
					chmin(dp[j][k],dp[j+1][k]+cost[dif+h][j]);
				}
				if(k+1<=h){
					int dif=k+1-j;
					chmin(dp[j][k],dp[j][k+1]+(j>0?cost[dif+h][j-1]:0));
				}
			}
		ans+=dp[0][0];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int d[101010];
int ans[16];
int dp[1 << 16];
int dat[1 << 16];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb, zc;
		scanf("%d%d%d", &za, &zb, &zc);
		d[za] ^= zc, d[zb] ^= zc;
	}
	for (int i = 0; i < num; i++)ans[d[i]]++;
	int r = 0, cnt = 0;
	int x = 0;
	for (int i = 1; i < 16; i++)r += ans[i] / 2, ans[i] %= 2, cnt += ans[i], x += ans[i] << i;
	ans[0] = 0;
	for (int i = 0; i < (1 << 16); i++)
	{
		for (int j = 0; j < 16; j++)if (i&(1 << j))dat[i] ^= j;
	}
	fill(dp, dp + (1 << 16), -1000000000);
	dp[0] = 0;
	for (int p = 0; p < (1 << 16); p++)
	{
		if ((x&p) != p)continue;
		int mask = (1 << 16) - 1 - p;
		int now = mask;
		for (;;)
		{
			if (now == 0)break;
			if (dat[now] == 0)dp[p + now] = max(dp[p + now], dp[p] + 1);
			now--;
			now &= mask;
		}
	}
	printf("%d\n", r + cnt - dp[x]);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> mypair;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
void dfs(vector<vector<bool> > &map,set<mypair> &ans,mypair now){
	int x = now.first;
	int y = now.second;
	map[x][y] = false;
	for(int i=0;i<4;i++){
	int nx = x+dx[i];
	int ny = y+dy[i];
	if(map[nx][ny]){
		mypair next = mypair(nx,ny);
		ans.insert(next);
		dfs(map,ans,next);
	}
	}
	return ;
}

int main(){
	while(1){
	int w,h;
	cin>>w>>h;
	if(w==0)break;
	vector<vector<bool> > mapb(h+2,vector<bool>(w+2,false) ) ,mapw(h+2,vector<bool>(w+2,false) );
	vector<mypair> brack,white;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
		{
			char a;
			cin>>a;
			if(a=='.'){
				mapb[i][j] = true;
				mapw[i][j] = true;
			}else if(a=='W')white.push_back(mypair(i,j) );
			else brack.push_back(mypair(i,j) );
		}
	set<mypair> ansb,answ;
	for(int i=0;i<brack.size();i++)dfs(mapb,ansb,brack[i]);
	for(int i=0;i<white.size();i++)dfs(mapw,answ,white[i]);
	int cntb=0,cntw=0;
	for(auto i:ansb){
		auto it = answ.find(i);
		if(it==answ.end())cntb++;
	}
	for(auto i:answ){
		auto it = ansb.find(i);
		if(it==ansb.end())cntw++;
	}
	cout<<cntb<<' '<<cntw<<endl;
	}

	return 0;
}



Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp

signed main(){
	long double w,h; cin>>w>>h;
	long double x,y; cin>>x>>y;
	long double ans=0;
	ll cnt=0;
	ans=(w/2)*h;
	if(w/x==h/y) cnt=1;
	if(x==w || x==0 || y==0 || y==h) cnt=0;
	cout<<ans<<" "<<cnt;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pp = pair<int, int>;

int main() {
    int H,W,D; cin >> H >> W >> D;
    vector<vector<int>> A(H, vector<int>(W));
    map<int, pair<int, int>> pos;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            cin >> A[i][j];
            pos[A[i][j]] = pp(i, j);
        }
    }
    vector<vector<long long>> sum(D, vector<long long>());
    vector<pp> prev(D);
    for(auto p : pos) {
        int f = p.first % D;
        if(p.first <= D) {
            sum[f].push_back(0);
            prev[f] = p.second;
        } else {
            int tmp = sum[f].back();
            sum[f].push_back(tmp + abs(p.second.first - prev[f].first) + abs(p.second.second - prev[f].second));
            prev[f] = p.second;
        }
    }
    
    int Q; cin >> Q;
    while(Q--) {
        int l, r; cin >> l >> r;
        cout << sum[r % D][(r - 1) / D] - sum[r % D][(l - 1) / D] << '\n';
    }
}

Measured memory_bytes: 12032
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;
struct point{
    int x,y;
};

struct line{
    point s,t;
};
struct bec{
    int x,y;
};

double suichoku(point p, line l){
    bec p1p,p1p2;
    p1p.x=p.x-l.s.x; p1p.y=p.y-l.s.y;
    p1p2.x=l.t.x-l.s.x; p1p2.y=l.t.y-l.s.y;
    double c,dp,dp2,k,ansx,ansy;
    dp=sqrt((double)p1p.x*(double)p1p.x+(double)p1p.y*(double)p1p.y);

    if(dp==0) return 0;

    dp2=sqrt((double)p1p2.x*(double)p1p2.x+(double)p1p2.y*(double)p1p2.y);
    c=((double)p1p.x*(double)p1p2.x+(double)p1p.y*(double)p1p2.y)/(dp*dp2);
    k=dp*c;
    ansx=l.s.x+k*(p1p2.x/dp2);
    ansy=l.s.y+k*(p1p2.y/dp2);
    return sqrt((p.x-ansx)*(p.x-ansx)+(p.y-ansy)*(p.y-ansy));
    
}

void solve(line l, line m){
    double d1,d2,w,ansx,ansy;
    d1=suichoku(l.s,m);
    d2=suichoku(l.t,m);
    w=d1/(d1+d2);
    bec lp;
    lp.x=l.t.x-l.s.x; lp.y=l.t.y-l.s.y;
    ansx=l.s.x+lp.x*w;
    ansy=l.s.y+lp.y*w;

    printf("%.8f %.8f\n",ansx,ansy);

}

int main(){
    int x0,x1,x2,x3,y0,y1,y2,y3,n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x0>>y0>>x1>>y1>>x2>>y2>>x3>>y3;
        point s1,s2,t1,t2;
        line l,m;
        s1.x=x0; s1.y=y0;
        t1.x=x1; t1.y=y1;
        s2.x=x2; s2.y= y2;
        t2.x=x3; t2.y=y3;
        l.s=s1; l.t=t1;
        m.s=s2; m.t=t2;
        solve(l,m);
    }
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=702;
 
inline int Get(int x){ return x*(x-1)>>1;}
 
int num[3],n,m,ans=1<<30,uu,vv,col[N],now;
bool f[N][N],g[N][N];
 
bool dfs(int x,int c){
	col[x]=c,num[c]++;
	
	for(int i=1;i<=n;i++) if(!g[x][i])
	    if(!col[i]){ if(!dfs(i,3-c)) return 0;}
	    else if(col[i]==c) return 0;
	
	return 1;
}
 
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	    scanf("%d%d",&uu,&vv),g[uu][vv]=g[vv][uu]=1;
	
	f[0][0]=1;
	for(int i=1;i<=n;i++) g[i][i]=1;
	
	for(int i=1;i<=n;i++) if(!col[i]){
		num[1]=num[2]=0;
		if(!dfs(i,1)){ puts("-1"); return 0;}
		
		now++;
		for(int j=0;j<=n;j++) if(f[now-1][j]) f[now][j+num[1]]=f[now][j+num[2]]=1;
	}
	
	for(int i=0;i<=n;i++) if(f[now][i]) ans=min(ans,Get(i)+Get(n-i));
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1152
import sys

H = int(input())
heap = [None] + [int(i) for i in input().split()]

for i in range(1, H + 1):
    if i == 1:
        if 2 * i <= H and 2*i + 1 <= H:
            print('node {}: key = {}, left key = {}, right key = {}, '.format(
                    i, heap[i], heap[2 * i], heap[2*i + 1]))
        elif 2 * i <= H:
            print('node {}: key = {}, left key = {}, '.format(
                    i, heap[i], heap[2 * i]))
        else:
            print('node {}: key = {}, '.format(
                    i, heap[i]))
    elif 2 * i <= H and 2*i + 1 <= H:
        print('node {}: key = {}, parent key = {}, left key = {}, right key = {}, '.format(
                    i, heap[i], heap[i // 2], heap[2 * i], heap[2*i + 1]))
    elif 2 * i <= H:
        print('node {}: key = {}, parent key = {}, left key = {}, '.format(
                    i, heap[i], heap[i // 2], heap[2 * i]))
    else:
        print('node {}: key = {}, parent key = {}, '.format(
                    i, heap[i], heap[i // 2]))

Measured memory_bytes: 7704
n = int(input())
case = [int(x) for x in input().split(' ')]
approve = True
for i in case:
  if i % 2 == 0:
    if i % 3 != 0 and i % 5 != 0:
      approve = False
      break

if approve:
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 2940
import copy
S = list(input())
Ss = copy.deepcopy(S)
ans0 = 0
ans1 = 0
for i in range(1, len(S)):
    if S[i-1] == "0" and S[i] == "0":
        ans0 += 1
        S[i] = "1"
    elif S[i-1] == "1" and S[i] == "1":
        ans0 += 1
        S[i] = "0"

for i in range(1, len(Ss)):
    if Ss[0] == "0":
        Ss[0] = "1"
        ans1 += 1
    elif Ss[0] == "1":
        Ss[0] == "0"
        ans1 += 1
            
    if Ss[i-1] == "0" and Ss[i] == "0":
        ans1 += 1
        Ss[i] = "1"
    elif Ss[i-1] == "1" and Ss[i] == "1":
        ans1 += 1
        Ss[i] = "0"

print(min(ans0, ans1))

Measured memory_bytes: 5160