akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int N=2e5+100;
const int mod=1e9+7;
typedef long long ll;


typedef pair<int,int> pa;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n,k;
    cin>>n>>k;
    if(k==0) {
        cout<<1ll*n*n<<endl;
        return 0;
    }
    ll ans=0;
    for(int i=k+1;i<=n;i++){
        int x=n/i;
        int y=n%i;
        ans+=1ll*x*(i-k);
        if(y>=k )
        ans+=y-k+1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

Measured memory_bytes: 1920
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 if l<H and A[i]<A[l]:g=l
 else:g=i
 if r<H and A[g]<A[r]:g=r
 if g!=i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 64172
N=int(input())
S=input()
MOD=10**9+7
ALP='qazwsxcedrfvtgbyhnujmikolp'
cnt={}
for s in ALP:
  cnt[s]=0
for s in S:
  cnt[s]+=1
ans=1
for s in ALP:
  ans*=cnt[s]+1
ans-=1
print(ans%MOD)

Measured memory_bytes: 3188
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
#include <map>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<int> vecint;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)




int main() {
	ll i, N, M, j,k;
//	vector<int> A;
	deque<int> A;
	cin >> N ;
	rep(i, 0, N) {
		int a;
		cin >> a;
		if (i & 1)
			A.push_front(a);
		else
			A.push_back(a);
	}
	if (N & 1) {
		for (i = N - 1; i >= 0; --i)
			cout << A[i] << endl;
	
	}
	else {
		rep(i, 0, N) {
			cout << A[i] <<" ";
		}
	}
		
	return 0;
}



Measured memory_bytes: 2944
#include <iostream>

using namespace std;

int taxed(int a, int x) {
    return a * (100+x) / 100;
}

int solve(int x, int y, int s) {
    int ans = 0;
    for(int a=1;a<s;++a) {
        for(int b=1;b<=s-a;++b) {
            if(taxed(a, x) + taxed(b, x) == s) {
                ans = max(ans, taxed(a, y) + taxed(b, y));
            }
        }
    }

    return ans;
}

int main() {
    int x,y,s;
    while(cin >> x >> y >> s,x) {
        cout << solve(x,y,s) << endl;
    }
}


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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int q; cin >> q;
  map<string, int> mp;
  for(int i=0;i<q;++i) {
    int t; cin >> t;
    if(t == 0) {
      string key;int x; cin >> key >> x;
      mp[key] = x;
    } else if(t == 1) {
      string key; cin >> key;
      cout << mp[key] << endl;
    } else {
      string key; cin >> key;
      mp.erase(key);
    }
  }
}


Measured memory_bytes: 27676
#include<bits/stdc++.h>
#define    ll      long long int
#define    Fori(a,b) for (ll i = a ; i<b ;i++ )
#define    Forj(a,b) for (ll j = a ; j<b ;j++ )
#define    Fork(a,b) for (ll k = a ; k<b ;k++ )
#define    W       while
#define    pb      push_back
#define    nl      cout<<endl
#define    mod     1000000007
#define    I       cin>>
#define    Out     cout<<
#define    DOD(i)  cout<<setprecision(i)<<fixed<<
#define    XXX     return 0
#define    Fast    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
int main()
{
   Fast;
   ll r;I r;
    double pi=22.0/7;
    cout<<setprecision(14)<<fixed<<2*pi*r;
   XXX;
}




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

int main(void) {
    int N,D,X;
    int d,a,sum=0;
    cin >> N >> D >> X;
    for(int i=0;i<N;i++) {
        cin >> a;
        for(int j=0;(j*a+1)<=D;j++) {
            sum++;
        }
    }

    cout << sum + X << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_NC = 200005;
const ll MOD = 1e9+7;
ll c[MAX_NC],colorsum[MAX_NC],dp[MAX_NC];

int main()
{
	int N;
	cin >> N;
	dp[0] = 1;
	rep(i,N)
	{
		cin >> c[i];
		dp[i+1] = dp[i];
		if (i == 0 || c[i] != c[i-1])
		{
			dp[i+1] = (dp[i+1] + colorsum[c[i]]) % MOD;
			colorsum[c[i]] = (colorsum[c[i]] + dp[i]) % MOD;
		}
	}
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 8324
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

//-------------------------------------------------------------------
int M=1;
std::vector<int> seg;
void init(int N){
  while(M<N) M*=2;
  M=M*2-1;
  for(int i=0;i<M;i++) {
    seg.push_back(0);
  }
}
void update(int l, int r, int k){
  k+=(M+1)/2-1;
  seg[k]++;
  while(k>0){
    k = (k-1)/2;
    seg[k]++;
  }
}
ll query(int a, int b, int l, int r, int k){
  if(r<=a || b<=l) return 0;
  if(a<=l && r<=b) return seg[k];
  ll A = query(a, b, l, (l+r)/2, k*2+1);
  ll B = query(a, b, (l+r)/2, r, k*2+2);
  return A + B;
}
//-------------------------------------------------------------------

int main(int argc, char const *argv[]) {
  ll N, K, ans = 0;
  std::cin >> N >> K;
  std::vector<ll> A(N), S(N);
  init(N+1);
  for(int i=0;i<N;i++) {
    std::cin >> A[i];
    A[i]-=K;
  }
  set<ll> tmp;
  map<ll, ll> num;
  tmp.insert(0);
  for(int i=0;i<N;i++){
    S[i] = (i==0?0:S[i-1]) + A[i];
    if(tmp.find(S[i])==tmp.end()) tmp.insert(S[i]);
  }
  int c = 0;
  for(auto itr=tmp.begin();itr!=tmp.end();itr++, c++) {
    //std::cout << *itr << '\n';
    num.emplace(*itr, c);
  }
  update(0, (M+1)/2, num.at(0));
  for(int i=0;i<N;i++){
    ans += query(0, num.at(S[i])+1, 0, (M+1)/2, 0);
    update(0, (M+1)/2, num.at(S[i]));
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 27248
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+9
#define MOD 1000000007
using namespace std;


int main(){
    string S;
    cin >> S;
    
    string T;
    T=S;
    if(T[0]=='0'){
        T[0]='1';
    }else{
        T[0]='0';
    }
    
    
    int ans1=0;
    for(int i=1; i<S.length(); i++){
        if(S[i]==S[i-1]){
            ans1++;
            if(S[i]=='0'){
                S[i]='1';
            }else{
                S[i]='0';
            }
        }
    }
    
    int ans2=1;
    for(int i=1; i<T.length(); i++){
        if(T[i]==T[i-1]){
            ans2++;
            if(T[i]=='0'){
                T[i]='1';
            }else{
                T[i]='0';
            }
        }
    }
    
    cout<<min(ans1,ans2)<<endl;
    return 0;
}


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

using namespace std;

int main(void)
{
	int n;
	cin >>n;
	int l,r;
	int sum=0;
	while(n--)
	{
		cin >> l >> r;
		sum+=r-l+1;
	}
	cout << sum <<endl;
} 

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		int time = 0;
		int num = c;
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (num >= c || arr[i] > time + k) {
				count++;
				num = 1;
				time = arr[i];
			} else {
				num++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 50908
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)
constexpr int INF = 0x3f3f3f3f;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, 0, h) cin >> s[i];

  vector<vector<int>> d(h, vector<int>(w, INF));
  queue<pair<int, int>> q;
  rep(i, 0, h) rep(j, 0, w) if (s[i][j] == '#') {
    q.emplace(i, j);
    d[i][j] = 0;
  }

  int dx[4]{-1, 0, 1, 0};
  int dy[4]{0, -1, 0, 1};
  while (!q.empty()) {
    auto [y, x] = q.front();
    q.pop();
    rep(i, 0, 4) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (0 <= nx && nx < w && 0 <= ny && ny < h && d[ny][nx] == INF) {
        d[ny][nx] = d[y][x] + 1;
        q.emplace(ny, nx);
      }
    }
  }

  int ans = 0;
  rep(i, 0, h) rep(j, 0, w) ans = max(ans, d[i][j]);
  cout << ans << endl;
  return 0;
}

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

int main(void)
{
  double r, s, c;

  scanf("%lf",&r);
	c = 2.0 * r * M_PI;
	s = M_PI * r * r;

  printf("%lf %lf\n", s, c);

  return 0 ;
}

Measured memory_bytes: 648
D,G=map(int,input().split())
#x問解いたときに得られる得点の最大値でDP
table=[(0,0)]*D
s=0
for i in range(D):
    p,c=map(int,input().split())
    table[i]=(p,c)
    s+=p
dp=[-1]*(s+1)
dp[0]=0
t=0
for i in range(D):
    for j in range(t,-1,-1):
        for k in range(1,table[i][0]+1):
            if k<table[i][0]:
                dp[j+k]=max(dp[j+k],dp[j]+100*(i+1)*k)
            else:
                dp[j+k]=max(dp[j+k],dp[j]+100*(i+1)*k+table[i][1])
    t+=table[i][0]
    #print(dp)
for i in range(s+1):
    if dp[i]>=G:
        print(i)
        break

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

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int N;  cin >> N;
    map<int, int> mp;
    for(int i = 1 ; i <= 100000 ; i++)  mp[i] = 0;

    for(int i = 0 ; i < N ; i++){
      int A;  cin >> A;
      mp[A] += 1;
    }

    ll keep = 0;
    for(int i = 1 ; i <= 100000 ; i++)  keep += (mp[i] == 0) ? 0 : mp[i] - 1;

    int ans = N - keep;
    if(keep % 2)  ans -= 1;

    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int64_t A,V,B,W,T;
  cin>>A>>V>>B>>W>>T;
  if(abs(A-B)>(V-W)*T)
    cout<<"NO"<<endl;
  else
    cout<<"YES"<<endl;
}

Measured memory_bytes: 3632
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

# num: 検索対象の数字, items: 検索範囲
def binary_search(num, items):
    low = 0
    high = len(s) - 1
    while low <= high:
        mid = (low + high) // 2
        guess = items[mid]
        if guess == num:
            return True
        if guess > num:
            high = mid -1
        else:
            low = mid + 1
    return False

cnt = 0
for i in range(q):
    if binary_search(t[i], s):
        cnt += 1
print(cnt)


Measured memory_bytes: 16712
s = [int(x) for x in input()]
 
def f(c, n):
    if n == 4:
        if eval(c) == 7:
            return c + "=7"
        else:
            return None
    v = s[n]
    for o in ['+', '-']:
        ret = f('%s%s%d' % (c,o,v), n + 1)
        if ret:
            return ret
print(f(str(s[0]), 1))

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

const int MAX_N = 100005;
int S[MAX_N];

vector< char > rec(int i, int a, int b, int c, vector< char > path) {
    if ((a < 0) || (b < 0) || (c < 0)) {
        return path;
    }
    if (S[i] == 0) {
        path.push_back('Z');
        return path;
    }

    int s = S[i];
    ++i;
    if (s == 1) {
        vector< char > ret = rec(i, a + 1, b - 1, c, path);
        if (ret.size() > 0) {
            ret.push_back('A');
            return ret;
        }
        ret = rec(i, a - 1, b + 1, c, path);
        if (ret.size() > 0) {
            ret.push_back('B');
            return ret;
        }
        return ret;
    } else if (s == 2) {
        vector< char > ret = rec(i, a, b + 1, c - 1, path);
        if (ret.size() > 0) {
            ret.push_back('B');
            return ret;
        }
        ret = rec(i, a, b - 1, c + 1, path);
        if (ret.size() > 0) {
            ret.push_back('C');
            return ret;
        }
        return ret;
    } else {
        vector< char > ret = rec(i, a + 1, b, c - 1, path);
        if (ret.size() > 0) {
            ret.push_back('A');
            return ret;
        }
        ret = rec(i, a - 1, b, c + 1, path);
        if (ret.size() > 0) {
            ret.push_back('C');
            return ret;
        }
        return ret;
    }
}

int main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    rep(i, MAX_N) S[i] = 0;
    rep(i, N) {
        string s;
        cin >> s;
        if (s == "AB") {
            S[i] = 1;
        } else if (s == "BC") {
            S[i] = 2;
        } else {
            S[i] = 3;
        }
    }
    vector< char > res;
    res = rec(0, A, B, C, res);
    if (res.size() > 0) {
        cout << "Yes" << endl;
        // rep(i, res.size()) cout << res[i] << endl;
        for (int i = res.size() - 1; i >= 1; --i) {
            cout << res[i] << endl;
        }
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 26016
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()
B = LIST()

S1 = []
S2 = []
for i in range(3):
    if A[i] < B[i]:
        S1.append(i)
    else:
        S2.append(i)
        A[i], B[i] = B[i], A[i]

def calc(cnt, i):
    d = cnt // A[i]
    m = cnt % A[i]
    return d * B[i] + m

def count(S, N):
    if len(S) == 0:
        return N
    elif len(S) == 1:
        return calc(N, S[0])
    elif len(S) == 2:
        res = 0
        for x in range(N+1):
            y = N - x
            if y < 0:
                break
            cnt = calc(x, S[0]) + calc(y, S[1])
            res = max(res, cnt)
        return res
    else:
        res = 0
        for x in range(N+1):
            for y in range(N+1):
                z = N - x - y
                if z < 0:
                    break
                cnt = calc(x, S[0]) + calc(y, S[1]) + calc(z, S[2])
                res = max(res, cnt)
        return res

N2 = count(S1, N)
ans = count(S2, N2)
print(ans)


Measured memory_bytes: 41932
import java.util.Scanner;

/**
 * Count ABC
 */
public class Main {

	public static void main(String...args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			String[] s = sc.next().split("");

			int count = 0;
			for (int i = 0; i < n - 2; i++) {
				if (s[i].equals("A") && s[i+1].equals("B") && s[i+2].equals("C")) {
					count ++;
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 22996
#include <ctype.h>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <string>

using namespace std;

namespace {

int stackptr = -1;
int stack[100];

const char* p = nullptr;

int ParseNum(const char* end) {
  int n = 0;
  for (; p <= end; ++p) {
    if (!isdigit(*p))
      break;
    int x = *p - '0';
    for (ptrdiff_t i = 0; i < end - p; ++i)
      x *= 10;
    n += x;
  }
  return n;
}

void Op(std::function<int(int, int)> binary_op) {
  const int b = stack[stackptr--];
  const int a = stack[stackptr--];
  stackptr++;
  stack[stackptr] = binary_op(a, b);
}

}  // namespace

int main() {
  auto add = [](int a, int b) -> int {
    return a + b;
  };
  auto sub = [](int a, int b) -> int {
    return a - b;
  };
  auto mult = [](int a, int b) -> int {
    return a * b;
  };

  string line;
  while (cin >> line) {
    p = line.data();
    const char* end = line.data() + line.length();

    for (; p && p < end; ++p) {
      if (isspace(*p))
        continue;

      if (isdigit(*p)) {
        const int n = ParseNum(end - 1);
        stackptr++;
        stack[stackptr] = n;
        continue;
      }

      switch (*p) {
        case '+':
          Op(add);
          break;
        case '-':
          Op(sub);
          break;
        case '*':
          Op(mult);
          break;
        default:
          fprintf(stderr, "unknown operator = 0x%x\n", *p);
          exit(1);
      }
    }
  }

  printf("%d\n", stack[0]);
  return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#define ll long long
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)
using namespace std;
const int maxn=500000;
const int INF=2e9;
const int mod=10007;
class Point
{
public:
    double x,y;
    Point(double x=0,double y=0):x(x),y(y) {}
    Point operator + (Point p) {return Point(x+p.x,y+p.y);}
    Point operator - (Point p) {return Point(x-p.x,y-p.y);}
    Point operator * (double a) {return Point(a*x,a*y);}
    Point operator / (double a) {return Point(x/a,y/a);}
    double abs() {return sqrt(norm());}
    double norm() {return x*x+y*y;}
    bool operator < (const Point &p) const {
        return x!=p.x?x<p.x:y<p.y;
    }
    bool operator == (const Point &p) const{
        return fabs(x-p.x)<EPS&&fabs(y-p.y)<EPS;
    }
};

typedef Point Vector;
struct Segment
{
    Point p1,p2;
};
double dot(Vector a,Vector b)
{
    return a.x*b.x+a.y*b.y;
}
double cross(Vector a,Vector b)
{
    return a.x*b.y-a.y*b.x;
}
bool isOrthogonal(Vector a,Vector b)
{
    return equals(dot(a,b),0.0);
}
bool isOrthogonal(Point a1,Point a2,Point b1,Point b2)
{
    return isOrthogonal(a1-a2,b1-b2);
}
bool isParallel(Vector a,Vector b)
{
    return equals(cross(a,b),0.0);
}
bool isParallel(Point a1,Point a2,Point b1,Point b2)
{
    return isParallel(a1-a2,b1-b2);
}
double norm(Vector a)
{
    return a.x*a.x+a.y*a.y;
}
Point project(Segment s,Point p)
{
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base)/norm(base);
    return s.p1+base*r;
}

int main()
{
    Segment l;
    scanf("%lf %lf %lf %lf",&l.p1.x,&l.p1.y,&l.p2.x,&l.p2.y);
    int n;
    scanf("%d",&n);
    while(n--)
    {
        Point a,ret;
        scanf("%lf %lf",&a.x,&a.y);
        ret=project(l,a);
        printf("%.10lf %.10lf\n",ret.x,ret.y);
    }
    return 0;
}



Measured memory_bytes: 3232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int x = scan.nextInt();
		int l = 0;
		int cnt = 1;

		for (int i = 0; i < n; i++) {
			l += scan.nextInt();

			if (l > x) {
				break;
			}
			cnt++;
		}

		System.out.println(cnt);

	}
}

Measured memory_bytes: 23892
#include<vector>
#include<iostream>
#include<list>
#include<string>
#include<map>
#include<algorithm>
#include<unordered_set>


using namespace std;

int ctoi(char c) {

	switch (c)
	{
	case'0':
		return 0;
	case'1':
		return 1;
	case'2':
		return 2;
	case'3':
		return 3;
	case'4':
		return 4;
	case'5':
		return 5;
	case'6':
		return 6;
	case'7':
		return 7;
	case'8':
		return 8;
	case'9':
		return 9;
	default:
		break;
	};
}
using ull = unsigned long long;
using ll =long long;


int H, W,M;
vector<unordered_set<int>> p;
vector<int> sum_yoko, sum_tate;
int main() {
	cin >> H >> W >> M;
	sum_yoko.resize(H);
	sum_tate.resize(W);
	p.resize(H);
	for (int i = 0; i < H; ++i)sum_yoko[i] = 0;
	for (int i = 0; i < W; ++i)sum_tate[i] = 0;
	for (int i = 0; i < M; ++i) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		p[a].insert(b);
		sum_yoko[a]++;
		sum_tate[b]++;
	}

	vector<pair<int, int>> yoko;
	for (int i = 0; i < H; ++i) yoko.push_back(pair<int, int>(i, sum_yoko[i]));
	vector<pair<int, int>> tate;
	for (int i = 0; i < W; ++i) tate.push_back(pair<int, int>(i, sum_tate[i]));

	auto cmp = [](pair<int, int> a, pair<int, int> b) {
		return a.second > b.second;
	};

	auto cmp2 = [](pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
		return a.second > b.second;
	};

	std::sort(yoko.begin(), yoko.end(), cmp);
	std::sort(tate.begin(), tate.end(), cmp);


	int size = min(M + 1, H * W);
	vector<pair<pair<int, int>, int>> v;
	int idxy = 0;
	int idxt = 0;
	for (int i = 0;; ++i) {
		v.push_back(pair<pair<int, int>, int>(pair<int, int>(yoko[idxy].first, tate[idxt].first), yoko[idxy].second + tate[idxt].second));
		if (p[yoko[idxy].first].count(tate[idxt].first) > 0) v.back().second--;

		if (i == size - 1) break;
		if (idxy == H - 1) {
			if (idxt == W - 1) break;

			idxt++;
		}
		else if(idxt == W-1){

			idxy++;
		}
		else {

			if (yoko[idxy + 1].second + tate[idxt].second > yoko[idxy].second + tate[idxt + 1].second) {
				idxy++;
			}
			else idxt++;

		}
	}

	sort(v.begin(), v.end(), cmp2);

	cout << v.begin()->second << endl;

	return 0;
}

Measured memory_bytes: 60660
fn read_usizepair() -> (usize, usize) {
    let mut input = String::new();
    let _ = std::io::stdin().read_line(&mut input);
    let v: Vec<usize> = input
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    (v[0], v[1])
}

fn read_vec() -> Vec<i64> {
    let mut input = String::new();
    let _ = std::io::stdin().read_line(&mut input);
    input.trim().split_whitespace().map(|x| x.parse().unwrap()).collect()
}

fn main() {
    let (n, k) = read_usizepair();
    let x_list = read_vec();
    let mut cost: i64 = i64::max_value();

    for i in 0..(n - k + 1) {
        let low = i;
        let high = i + k - 1;
        if x_list[high].abs() < x_list[low].abs() {
            if x_list[high].abs() + x_list[high] - x_list[low] < cost {
                cost = x_list[high].abs() + x_list[high] - x_list[low];
            }
        } else {
            if x_list[low].abs() + x_list[high] - x_list[low] < cost {
                cost = x_list[low].abs() + x_list[high] - x_list[low];
            }
        }
    }

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

Measured memory_bytes: 6396
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define MXN 100010

int n,
	a[MXN];

/*
[Discretization] by.YXH_XianYu
void Discretization(int a[], int n);
	a[] : Array that will be Modified
	n   : the Length of Array a
This function can discretize a[]. 
(It can't Remove duplicate elements)
 */
void Discretization(int a[], int n){
	struct Sort{
		int va,no;
		bool operator < (const Sort &cp) const {
			return va<cp.va;}
	}s[MXN];
	for(int i=1;i<=n;i++)
		s[i].va=a[i],
		s[i].no=i;
	std::sort(s+1,s+n+1);
	for(int i=1;i<=n;i++)
		a[s[i].no]=i;
	return;
}



int main(){
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	Discretization(a,n);
	int ans=0;
	for(int i=1;i<=n;i++)
		if( (a[i]-i)&1 )
			ans++;
	printf("%d\n",ans/2);
	//system("pause");
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n;i>=0;i--)
#define For(i,m,n) for(int i=m;i<n;i++)
#define Forr(i,m,n) for(int i=m;i>n;i--)
#define Sort(a) sort(a.begin(),a.end())
#define pb push_back
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define INF 999999999999

int main(){
  int N,D,cnt=0;
  cin>>N>>D;

  while(N>0){
    N-=2*D+1;
    cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
s = list(input())
Flg = True
if len(s) % 2 == 1:
    Flg = False
for i in range(len(s)-1):
    if i % 2 == 0:
        if s[i] == 'h' and s[i+1] == 'i':
            pass
        else:
            Flg = False
if Flg:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
def prepare(n):
    global MOD
    modFacts = [0] * (n + 1)
    modFacts[0] = 1
    for i in range(n):
        modFacts[i + 1] = (modFacts[i] * (i + 1)) % MOD

    invs = [1] * (n + 1)
    invs[n] = pow(modFacts[n], MOD - 2, MOD)
    for i in range(n, 1, -1):
        invs[i - 1] = (invs[i] * i) % MOD

    return modFacts, invs
        

N, M = map(int, input().split())

MOD = 10 ** 9 + 7
modFacts, invs = prepare(max(N, M))

ans = 0
for i in range(N + 1):
    Ti = (modFacts[N] * invs[i] * invs[N - i]) % MOD
    Ti *= (modFacts[M] * invs[M - i]) % MOD
    Ti %= MOD
    Ti *= pow(modFacts[M - i] * invs[(M - i) - (N - i)], 2, MOD)
    Ti %= MOD
    ans += pow(-1, i) * Ti
    ans %= MOD

print(ans)

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

bool norm_int(std::vector<int> &point1, std::vector<int> &point2, int d){
    int nijo=0;
    double vec_norm;
    for(int i=0; i < d; i++){
        nijo += pow(point1.at(i)-point2.at(i), 2);
    }
    vec_norm = sqrt(nijo);
    return (vec_norm - floor(vec_norm) < 1e-6);
}

int main(){
    int N, D;
    cin >> N >> D;
    std::vector<std::vector<int> > points(N, std::vector<int>(D));
    for(int i=0; i < N; i++){
        for(int j=0; j < D; j++){
            cin >> points.at(i).at(j);
        }
    }
    int count = 0;
    for(int i=0; i < N - 1; i++){
        for(int j=i+1; j < N; j++){
            if(norm_int(points.at(i), points.at(j), D)){
                count ++;
            }
        }
    }
    cout << count << endl;
    return 0;


}


Measured memory_bytes: 256
n = gets.to_i
bits = [0, 0, 0]
3.times do |i|
    gets.split.map(&:to_i)[1..-1].each do |j|
        bits[i] |= (1 << (j - 1))
    end
end
a, b, c = bits
x = (c - (c & a)) | (c & b)
puts x.to_s(2).count(?1)


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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define R(i,n) for(int i = 0; i < (n); i++)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}

template<class T> ostream &operator<<(ostream& os, set<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 2e5 + 10;
int n;
int gd[MAX];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  R(i,n){
    int pom;
    cin >> pom;
    gd[pom-1] = i;
  }
  int res = 1;
  int ak = 0;
  R(i,n){
    if(i && gd[i] > gd[i-1]){
      ak++;
      maxi(res,ak);
    }else{
      ak = 1;
    }
  }
  cout << n - res << "\n";
}




Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <math.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define INF 1001001
using namespace std;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int attack_t=0, attack_a=0;
  if(c%b==0){
    attack_t = c/b;
  }else{
    attack_t = c/b+1;
  }
  if(a%d==0){
    attack_a = a/d;
  }else{
    attack_a = a/d+1;
  }

  if(attack_t <= attack_a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  

  
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<cstring>
using namespace std;


int main()
{
	int i, j, k,l, H, W, D, Q,sum1,sum2;
	char S[100001];
	cin >> S;
	int setsu[100000];
	int ans[100000] = {};
	k = 1;
	setsu[0] = 0;
	sum1 = sum2 = 0;
	l = strlen(S);
	for (i = 1; i < l; i++) {
		if (S[i] != S[i - 1]) {
			setsu[k] = i;
			k++;
		}
	}
	setsu[k] = strlen(S);

	if (k == 1) {
		cout << strlen(S) << endl;
	}
	else {
		for (i = 1; i <= k-1 ; i++) {
			ans[i-1] = fmax(setsu[i], setsu[k] - setsu[i]);
			
		}
	
	sort(ans, ans + k-1);
	cout << ans[0] << endl;}
    return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a, b;

signed main() {
	cin >> n;
	if (n==1) return cout << "Hello World" << endl, 0;
	cin >> a >> b;
	cout << a+b << endl;
}


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

using namespace std;
struct pos
{
    int i, j;
} a[900001];
vector <int>v[900001];
int n,m,d,q, x, y, last, nxt, sum;

int main()
{
    cin>>n>>m>>d;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
        {
            int x;
            cin>>x;
            a[x].i=i;
            a[x].j=j;
        }
    for(int i=0; i<d; i++)
    {
        last=i;
        nxt=i+d;
        sum=0;
        while(nxt<=n*m)
        {
            v[i].push_back(sum);
            if (last!=0)
                sum=sum+abs(a[last].i-a[nxt].i)+abs(a[last].j-a[nxt].j);
            last=nxt;
            nxt+=d;
        }
        v[i].push_back(sum);
    }
    cin>>q;
    while(q--)
    {
        cin>>x>>y;
        cout<<v[x%d][y/d]-v[x%d][x/d]<<'\n';
    }
    return 0;
}


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

using namespace std;

int main() {
    int n;

    cin >> n;

    int num[n];
    for (int i = 0; i < n; i++) {
        cin >> num[i];
    }
    
    int max = INT_MIN;
    int min = num[0];
    for (int i = 1; i < n; i++) {
        int d = num[i] - min;
        if (d > max) max = d;
        if (num[i] < min) min = num[i];
    }

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 3876
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void) {
    int n;
    int sgn = 1;

    string ans = "";

    cin >> n;

    if (n == 0) {
        cout << "0" << endl;
        return 0;
    }

    while (n != 0) {
        if (n % 2 != 0) {
            n = (n-(sgn*1))/2;
            ans += '1';
        } else {
            n = n/2;
            ans += '0';
        }

        sgn *= -1;
    }

    reverse(ans.begin(), ans.end());

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    h, w, m = map(int, input().split())
    bomb_row = [0] * h
    bomb_col = [0] * w
    # 座標だけはsetで格納
    bomb_pos = set()
    # 爆弾情報を行と列ごとで格納
    for _ in range(m):
        r, c = [int(i) - 1 for i in input().split()]
        bomb_row[r] += 1
        bomb_col[c] += 1
        bomb_pos.add((r,c))

    bomb_row_max = max(bomb_row)
    bomb_col_max = max(bomb_col)

    row_index = [i for i, v in enumerate(bomb_row) if v == bomb_row_max]
    col_index = [i for i, v in enumerate(bomb_col) if v == bomb_col_max]
    ans = bomb_col_max + bomb_row_max
    for row in row_index:
        for col in col_index:
            if (row, col) not in bomb_pos:
                print(ans)
                return
    print(ans-1)
main()

Measured memory_bytes: 83428
#include <iostream>
using namespace std;
int main(void){
	int r, g, b;
    cin >> r >> g >> b;
    int s = r * 100 + g * 10 + b;
    
    if (s % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<list>
#include <array>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define INF I64_MAX
#define MOD 1000000007



void solve(void)
{
  string str;
  cin>>str;
  int check = 0;
  int check_index;
  if(str.size () == 2)
  {
    if(str[0]==str[1])
    {
      cout<<1<<" "<<2<<endl;
      return;
    }
    else
    {
      cout<<-1<<" "<<-1<<endl;
      return;
    }
    
  }

  for (int i = 0; i < str.size()-1; i++)
  {
    if(str[i] == str[i+1]) {check = 1;
    check_index = i;}
  }

  for (int i = 0; i < str.size()-2; i++)
  {
    if(str[i] == str[i+2]) {check = 1;
    check_index = i;}
  }

  if(check==0)
  {
    cout<<-1<<" "<<-1<<endl;
  }
  else
  {
    cout<<check_index+1<<" "<<check_index+3<<endl;
    cout<<endl;    
  }
  
  
  
  
  return;
}



int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // std::cout << std::fixed;
  // std::cout << std::setprecision(8);

  solve();

 
  return 0;
}

Measured memory_bytes: 512
h,w=map(int,input().split());print(min(min(min(max((i*w,(h-i)//2*w,(h-i-(h-i)//2)*w))-min((i*w,(h-i)//2*w,(h-i-(h-i)//2)*w)),max((i*w,w//2*(h-i),(h-i)*(w-w//2)))-min((i*w,w//2*(h-i),(h-i)*(w-w//2))))for i in range(h)),min(min(max((h*i,(w-i)//2*h,h*(w-i-(w-i)//2)))-min((h*i,(w-i)//2*h,h*(w-i-(w-i)//2))),max((h*i,h//2*(w-i),(h-h//2)*(w-i)))-min((h*i,h//2*(w-i),(h-h//2)*(w-i))))for i in range(w))))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int N;
    cin >> N;
    vector<int> vec(N);
    REP(i, N) cin >> vec.at(i);
    
    // calculation
    int A = 0, B = 0;
    sort(vec.begin(), vec.end(), greater<int>());  // int big -> small
    
    for (int j = 0; j < N; ++j) {
        if (j%2 == 0) {
            A += vec[j];
        } else{
            B += vec[j];
        }
    }
    
    cout << A - B << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#define fi first
#define sec second
#define INF 1000000000
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int r, w[2], h[2], x[2], y[2];
int s, e, mid;
int cell[2][500][500];
bool used[500][500];
int dp[2][250001];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
priority_queue<PP, vector<PP>, greater<PP> >  que;

int A(int u, int Y, int X, int p){
	if(used[Y][X]) return 0;
	if(cell[u][Y][X] > p){
		que.push(PP(cell[u][Y][X],P(Y,X)));
		return 0;
	}
	int ret = 1;
	used[Y][X] = true;
	for(int i = 0; i < 4; i++){
		if(0<=Y+dy[i]&&Y+dy[i]<h[u]&&0<=X+dx[i]&&X+dx[i] < w[u]){
			ret += A(u,Y+dy[i],X+dx[i],p);
		}
	}
	return ret;
}

void solve(){
	for(int i = 0; i < 2; i++){
		dp[i][0] = 0;
	}
	for(int i = 1; i < 250001; i++){
		dp[0][i] = INF; dp[1][i] = INF;
	}
	for(int u = 0; u < 2; u++){
		scanf("%d%d%d%d", &w[u], &h[u], &x[u], &y[u]);
		x[u]--; y[u]--;
		for(int i = 0; i < h[u]; i++){
			for(int j = 0; j < w[u]; j++){
				scanf("%d", &cell[u][i][j]);
			}
		}
	}
	for(int u = 0; u < 2; u++){
		que.push(PP(1,P(y[u],x[u])));
		memset(used,0,sizeof(used));
		int cnt = 0;
		while(true){
			int tmp = que.top().fi;
			while(true){
				if(que.size() == 0) break;
				if(tmp != que.top().fi) break;
				PP p = que.top(); que.pop();
				cnt += A(u,p.sec.fi,p.sec.sec,p.fi);
			}
			dp[u][cnt] = tmp;
			if(que.size() == 0) break;
		}
	}
	for(int u = 0; u < 2; u++){
		for(int i = w[u]*h[u]-1; i >= 0; i--){
			dp[u][i] = min(dp[u][i],dp[u][i+1]);
		}
	}
	int ans = INF;
	for(int i = 0; i <= r; i++){
		if(i > w[0]*h[0] || r-i > w[1]*h[1]) continue;
		ans = min(ans,dp[0][i]+dp[1][r-i]);
	}
	printf("%d\n", ans);
}

int main(){
	while(scanf("%d", &r),r) solve();
}

Measured memory_bytes: 6040
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  ll cnt = 0;

  rep(i, 100){
    if(A < B) break;

    B *= 2;
    cnt++;
  }

  rep(i, 100){
    if(B < C) break;

    C *= 2;
    cnt++;
  }

  if(cnt <= K)
    cout << "Yes\n";
  else
    cout << "No\n";
  
  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

typedef long long ll;



// int main()
// {
// 	ll n,a1,start=1,end=n;
// 	cin>>n;
// 	ll dp[n+1],a[n+1];
// 	for (int i = 1; i <= n; ++i)
// 	{
// 		cin>>a[i];
// 	}
// 	dp[1]=max(a[1],a[n]);
// 	if(dp[1]==a[1])
// 	{
// 		start=2;
// 		end=n;
// 	}
// 	else
// 	{
// 		start=1;
// 		end=n-1;
// 	}
// 	//cout<<dp[1];
// 	for (int i = 2; i <= n; ++i)
// 	{
// 		if(i%2==1)
// 		{
// 			dp[i]=max(dp[i-1]+a[start],dp[i-1]+a[end]);
// 			if(dp[i]==dp[i-1]+a[start])
// 				start++;
// 			else
// 				end--;
// 		}
// 		else
// 		{
// 			cout<<a[start]<<a[end];
// 			dp[i]=min(dp[i-1]-a[start],dp[i-1]-a[end]);
// 			if(dp[i]==dp[i-1]-a[start])
// 				start++;
// 			else
// 				end--;

// 		}
// 		cout<<dp[i]<<endl;
// 	}
// 	if(n==1)
// 	{
// 		cout<<dp[1]<<endl;
// 	}
// 	else
// 	{
// 		cout<<dp[n]<<endl;
// 	}
// }

int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	bool dp[k+1]={0};
	for (int i = 1; i <= n; ++i)
	{
		cin>>a[i];
	}
	for (int i = 0; i <= k; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			if(i>=a[j] && !dp[i-a[j]])
				dp[i]=1;
		}
	}
	if(dp[k]==1)
		cout<<"First"<<endl;
	else
		cout<<"Second"<<endl;
}

Measured memory_bytes: 384
from collections import Counter
n=int(input())
name=[]
initial={"M":0,
         "A":0,
         "R":0,
         "C":0,
         "H":0}
for _ in range(n):
    s=input()
    if s[0] in ["M","A","R","C","H"]:
        initial[s[0]]+=1
num=[v for k,v in initial.items()]

if len(num)<3:
    print(0)
else:
    ans=0
    for i in range(len(num)-2):
        for j in range(i+1,len(num)-1):
            for k in range(j+1,len(num)):
                #print(i,j,k)
                ans+=num[i]*num[j]*num[k]
    print(ans)


Measured memory_bytes: 3316
from bisect import bisect_right

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
#A to B
AtoB = []
for e in A:
    b_search = bisect_right(B,e)
    b_pattern = N-b_search
    AtoB.append(b_pattern)
BtoC = []
for e in B:
    c_search = bisect_right(C,e)
    c_pattern = N-c_search
    BtoC.append(c_pattern)
cs = [0]
for e in reversed(BtoC):
    cs.append(e+cs[-1])
cs = cs[1:]
for e in AtoB:
    if e == 0:
        continue
    ans += cs[e-1]
print(ans)

Measured memory_bytes: 29172
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int A,B,C,D,E;
    while(cin>>A>>B>>C>>D>>E)
    {
        int a[5]= {0};
        if(A%10)
            a[0]=10-A%10;
        if(B%10)
            a[1]=10-B%10;
        if(C%10)
            a[2]=10-C%10;
        if(D%10)
            a[3]=10-D%10;
        if(E%10)
            a[4]=10-E%10;
        sort(&a[0],&a[5]);
        int sum=0;
        sum=A+B+C+D+E+a[0]+a[1]+a[2]+a[3];
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);
	int n,a,b,c,d;
	cin>>n;
	d = n%10;
	n/=10;
	c = n%10;
	n/=10;
	b = n%10;
	n/=10;
	a = n%10;
	if(a+b+c+d == 7)
	{
		cout<<a<<'+'<<b<<'+'<<c<<'+'<<d<<'='<<'7';
	}
	else if(a-b-c-d == 7)
	{
		cout<<a<<'-'<<b<<'-'<<c<<'-'<<d<<'='<<'7';
	}
	else if(a+b+c-d == 7)
	{
		cout<<a<<'+'<<b<<'+'<<c<<'-'<<d<<'='<<'7';
	}
	else if(a+b-c+d == 7)
	{
		cout<<a<<'+'<<b<<'-'<<c<<'+'<<d<<'='<<'7';
	}
	else if(a-b+c+d == 7)
	{
		cout<<a<<'-'<<b<<'+'<<c<<'+'<<d<<'='<<'7';
	}
	else if(a+b-c-d == 7)
	{
		cout<<a<<'+'<<b<<'-'<<c<<'-'<<d<<'='<<'7';
	}
	else if(a-b-c+d == 7)
	{
		cout<<a<<'-'<<b<<'-'<<c<<'+'<<d<<'='<<'7';
	}
	else if(a-b+c-d == 7)
	{
		cout<<a<<'-'<<b<<'+'<<c<<'-'<<d<<'='<<'7';
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using ll=long long;
using ld=long double;
#define inf INT_MAX  
const ll infll=1ll*inf*inf;
#define mode 998244353
#define mod 1000000007
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define ub upper_bound 
#define lb lower_bound 
#define far(i,a,b) for (ll i = a; i <= b; i++)
#define rev(i,a,b) for (ll i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define sz(a) int((a).size())
#define ftr(c,i) for(auto i = begin(c); i != end(c); i++)
#define rtr(c,i) for(auto i = rbegin(c); i != rend(c); i++)
#define pre(c,x) ((c).find(x) != (c).end())
#define cpre(c,x) (find(all(c),x) != (c).end())
#define mii map<int,int>
#define mll map<ll,ll>
#define vs vector<string>
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define vii vector<pii >
#define vll vector<pll >
#define vvl vector<vector<ll> >
#define vvi vector< vector<int > >
#define wh(t) while(t --)
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout <<(ll)(it-arr.begin()) << ')' <<  *it << ' '; cout << endl;
#define printii(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << it->ff<<' '<<it->ss << endl; cout << endl;
#define MID(i,j) ((i)+(j))/2
#define nl '\n' 
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
ll max(ll a,ll b) {return (a>b? a:b);}
ll min(ll a,ll b) {return (a>b? b:a);}
ll gcd(ll a,ll b) {return (b==0)? a:gcd(b,a%b); }
ll gcd(ll a,ll b,ll & x,ll & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll modinv(ll a,ll b){
	ll x,y;
	gcd(a, b, x, y);
	return (x%b + b)%b;
}
ll ceiling(ll a,ll b){ 
        if(a%b==0) return a/b;
        else return a/b+1;
}
ll bpow(ll a,ll b,ll m){
	a%=m;
	ll res=1;
	while(b>0){
		if(b&1) res=(res*a)%m;
		b>>=1;
		a=a*a%m;
	}
	return res;
}
vvl mat_mul(vvl mat1,vvl mat2,ll mod1){
        vvl res(sz(mat1),vl(sz(mat2[0]),0));
        far(i,0,sz(mat1)-1){
                far(j,0,sz(mat2[0])-1){
                        far(k,0,sz(mat1[0])-1){
                                res[i][j]=(res[i][j]+(mat1[i][k]*mat2[k][j])%mod1)%mod1;          
                        }   
        }   
        }   
        return res;
}
vvl mat_exp(vvl mat,ll p,ll mod1){ 
        vvl res(sz(mat),vl(sz(mat[0]),0));
        far(i,0,sz(mat)-1) res[i][i]=1;
        while(p>0){
                if(p&1) res=mat_mul(res,mat,mod1);   
                mat=mat_mul(mat,mat,mod1);
                p>>=1;
        }   
        return res;
}
const int N=2*1e5+5;
ll n,m,q,t,k,x,y,z,ans;

int main()
{
	fio;
	string s;
	cin >> s;
	far(i,0,2) 
	if(s[i]==s[i+1]){
		cout << "Bad" << nl;
		return 0;
	}
	cout << "Good" << nl;

}


Measured memory_bytes: 256
// C - Fennec vs Monster
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
template<class T> vector<T> inarr(int s,int e, T init=0){
	vector<T> v;T x;
	rp(i,0,s)v.push_back(init);
	rp(i,s,e){cin>>x;v.push_back(x);}
	return v;
}
int N,K;
vi H;

ll solve(){
	sort(allr(H));
	ll ans = 0;
	if(N>K) rp(i,K,N) ans += H[i];
	return ans;
}

int main(){
	cin>>N>>K;
	H = inarr<int>(0,N);
	cout<< solve() <<endl;
}

Measured memory_bytes: 1400