akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

vector<vector<int> > a;
void manju(vector<int>& b, int prev, int sum, const vector<int>& x)
{
    if(sum > 10)
        return;
    if(sum == 10){
        if(accumulate(b.begin(), b.end(), 0) > 2)
            a.push_back(b);
        return;
    }

    for(int i=prev; i<=9; ++i){
        if(x[i] == 0)
            continue;
        ++ b[i];
        sum += i;
        manju(b, i, sum, x);
        sum -= i;
        -- b[i];
    }
}

vector<map<vector<int>, int> > memo;
int solve(const vector<int>& x, int k)
{
    if(k >= a.size())
        return 0;

    if(memo[k].find(x) != memo[k].end())
        return memo[k][x];

    int ret = solve(x, k+1);

    vector<int> y = x;
    bool ok = true;
    for(int i=1; i<=9; ++i){
        y[i] -= a[k][i];
        if(y[i] < 0)
            ok = false;
    }
    if(ok)
        ret = max(ret, solve(y, k) + 1);

    return memo[k][x] = ret;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        int ret = 0;
        vector<int> x(10, 0);
        for(int i=0; i<n; ++i){
            int y;
            cin >> y;
            if(x[10-y] > 0){
                -- x[10-y];
                ++ ret;
            }else{
                ++ x[y];
            }
        }

        a.clear();
        vector<int> b(10, 0);
        manju(b, 1, 0, x);

        memo.assign(a.size(), map<vector<int>, int>());
        ret += solve(x, 0);
        cout << ret << endl;
    }
}

Measured memory_bytes: 29000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define inf 2e18
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007
#define lop0(n) for(ll i=0;i<n;i++)
#define lopj(n) for(ll j=0;j<n;j++)
#define lop1(n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(),v.end()
ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

main()
{
    ll n;
    cin>>n;
    ll mx=0,ans=0;
    while(n--)
    {
        ll a;
        cin>>a;
        mx=max(mx,a);
        ans+=mx-a;
    }
    cout<<ans;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main()
{
	int x, y, z;
	cin >> x >> y >> z;
	mp[x]++;
	mp[y]++;
	mp[z]++;
	bool flag = false;
	for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++)
	{

		if (it->second == 2)
			flag = true;


	}
	if (flag)
		cout << "Yes";
	else
		cout << "No";

}

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

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

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

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

int main(){
	llong N, A, B;
	vector<llong> P;

	cin >> N >> A >> B;
	P.resize(N);
	int a = 0, ab = 0, b = 0;
	for(int i = 0; i < N; i++){
		cin >> P[i];
		if(P[i] <= A)
			a++;
		else if(P[i] > B)
			b++;
		else ab++;
	}

	cout << min({a,b,ab}) << endl;

	return 0;
}

Measured memory_bytes: 256
def move_time(x1,y1,x2,y2):
    return abs(x1-x2)+abs(y1-y2)

n = int(input())
t1 = 0
x1 = 0
y1 = 0
isYes = True
for i in range(n):
    t2,x2,y2 = map(int,input().split())
    tm = move_time(x1,y1,x2,y2)
    #print(tm,t2,x2,y2)
    if tm>(t2-t1):
        isYes = False
    elif ((t2-t1)-tm)%2==1:
        isYes = False
    t1 = t2
    x1 = x2
    y1 = y2

if isYes:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 9160
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        List<int> a = new List<int>();
        List<int> b = new List<int>();
        List<int> c = new List<int>();
        a = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        b = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
        c = Console.ReadLine().Split(' ').Select(int.Parse).ToList();

        a.Sort();
        c.Sort();

        long ans = 0;
        for (int i = 0; i < a.Count; i++)
        {
            long s = LowerBound(a, b[i]);
            long t = UpperBound(c, b[i]);
            if (t < n) ans += s * (n - t);
        }

        Console.WriteLine(ans);
    }

    static long LowerBound(List<int> list, int item)
    {
        int min = 0;
        int max = list.Count - 1;
        while (min <= max)
        {
            int mid = (min + max) / 2;
            if (item > list[mid]) min = mid + 1;
            else max = mid - 1;
        }
        return min;
    }

    static long UpperBound(List<int> list, int item)
    {
        int min = 0;
        int max = list.Count - 1;
        while (min <= max)
        {
            int mid = (min + max) / 2;
            if (item >= list[mid]) min = mid + 1;
            else max = mid - 1;
        }
        return min;
    }
}

Measured memory_bytes: 40860
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 */

/**
 * @author cthanh
 *
 */
public class Main {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	        String str = br.readLine();

	    String[] strAry = str.split(" ");
	    int H = Integer.parseInt(strAry[0]);
	  	int W = Integer.parseInt(strAry[1]);
        int i,j ;

        while (H != 0 || W != 0){
        for ( i = 0 ; i<H && H!= 0; i++ ){
	  		for ( j=0; j< W && W !=0; j++){
	  			System.out.printf("#");

	  		}
	  		 System.out.printf("\n");

	  	}
	  	 System.out.printf("\n");
	       str = br.readLine();

		   strAry = str.split(" ");
		   H = Integer.parseInt(strAry[0]);
		   W = Integer.parseInt(strAry[1]);

	}
	}
}

Measured memory_bytes: 59376
#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>;

void Main()
{
  ll N, M; cin >> N >> M;
  if (N == 2 || M == 2) {cout << 0 << endl; return;}
  if (N == 1) {
    if (M==1) {cout << 1 << endl; return;}
    cout << max(M-2,(ll)0) << endl; return;
  }
  if (M==1) {
    if (N==1) {cout << 1 << endl; return;}
    cout << max(N-2,(ll)0) << endl; return;
  }
  cout << M*N - (2*M + 2*N - 4) << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
  string s, t="keyence";
  cin>>s;
  for(int i=0; i<8; i++){
    if(s.substr(0,i)+s.substr(s.length()-(7-i))==t){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}

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

int main(){
	long long N;
	vector<long double> x,y;
	long double sum = 0;
	cin >> N;

	for (int i = 0; i < N; i++){
		long long tmp_x,tmp_y;
		cin >> tmp_x >> tmp_y;
		x.push_back(tmp_x);
		y.push_back(tmp_y);
	}
	
	for (int i = 0; i < N; i++){
		for (int j = 0; j < N; j++){
			if (i == j){
				continue;
			}
			long double tmp = pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2);
			sum += sqrt(tmp);
		}
	}

	long long divide = 1;
	for (int i = 2; i <= N; i++){
		divide *= i;
	}
	cout.precision(17);
	cout << sum / (double)N << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
    public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[]ss = S.toCharArray();
        ArrayList<Integer>ans  = new ArrayList<>();

        int cou = 0;
        for(int i=0; i<S.length(); i++) {
        if(ss[i]=='A' || ss[i]=='C' || ss[i]=='G' || ss[i]=='T') {
        	cou++;
        }else {
        	ans.add(cou);
                cou = 0;
        }
        }
        ans.add(cou);
        Collections.sort(ans, Comparator.reverseOrder());
        System.out.println(ans.get(0));
    }
}



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

#define PI acos(-1)
#define pb push_back
#define int long long int
#define mp make_pair
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 100001
#define MAXL 20
#define mod 998244353
#define INF 9999999

int n;
vector<int> m[MAXN];

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  vector<int> v(n);
  int curr = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> v[i];
    curr += v[i];
    m[v[i]].pb(i);
  }
  int q, l = 0, r = n - 1;
  cin >> q;
  while (q--)
  {
    int c, b;
    cin >> b >> c;
    for (auto const &i : m[b])
    {
      curr += (c - b);
      m[c].pb(i);
    }
    m[b].clear();
    cout << curr << endl;
  }
  return 0;
}

Measured memory_bytes: 53408
def matchColumn(i,j)
  odd = $h%2
  ha = {}
  (0...$h).each do |k|
    ha[$sArr[k][i]+$sArr[k][j]] = ha[$sArr[k][i]+$sArr[k][j]].to_i + 1
  end
  ha.each do |k,v|
    if k == k.reverse
      if ha[k]%2 == 1
        odd -= 1
        if odd < 0
          return false
        end
      end
    elsif ha[k.reverse] != v
      return false
    end
  end
  return true
end

def compColumn
  odd = $w%2
  match = [false] * $w 
  (0...$w).each do |i|
    if match[i]
      next
    end
    (i+1...$w).each do |j|
      if !match[j] && matchColumn(i,j)
        match[i] = true
        match[j] = true
        break
      end
    end
    if !match[i]
      odd -= 1
      if odd < 0
        return false
      end
      match[i] = true
    end
  end
  return true
end

def matchRow(i,j)
  odd = $w%2
  ha = {}
  (0...$w).each do |k|
    ha[$sArr[i][k]+$sArr[j][k]] = ha[$sArr[i][k]+$sArr[j][k]].to_i + 1
  end
  ha.each do |k,v|
    if k == k.reverse
      if ha[k]%2 == 1
        odd -= 1
        if odd < 0
          return false
        end
      end
    elsif ha[k.reverse] != v
      return false
    end
  end
  return true
end

def compRow
  odd = $h%2
  match = [false] * $h 
  (0...$h).each do |i|
    if match[i]
      next
    end
    (i+1...$h).each do |j|
      if !match[j] && matchRow(i,j)
        match[i] = true
        match[j] = true
        break
      end
    end
    if !match[i]
      odd -= 1
      if odd < 0
        return false
      end
      match[i] = true
    end
  end
  return true
end

$h,$w = gets.split.map(&:to_i)
$sArr = []
(0...$h).each do |i|
  $sArr[i] = gets.chomp.split("")
end

if compRow && compColumn
  printf("YES\n")
else
  printf("NO\n")
end

Measured memory_bytes: 3836
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int r;

int main() {
  cin >> r;
  cout << r * r;
}


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

int k,s,ans;

int main(){
    cin>>k>>s;
    for(int i=0;i<=k;i++){
        for(int u=0;u<=k;u++){
            if(k>=s-i-u&&s-i-u>=0)ans++;
        }
    }
    cout<<ans<<endl;
}


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


void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
  long long prev = A[0];
  long long acc = B[A[0]-1];

  for(long long i = 1; i < N; i++) {
    acc += B[A[i]-1];

    if(prev + 1 == A[i]) acc+= C[prev-1];
    prev = A[i];
  }

  cout << acc << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  std::vector<long long> B(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&B[i]);
  }
  std::vector<long long> C(N-1);
  for(int i = 0 ; i < N-1 ; i++){
    scanf("%lld",&C[i]);
  }
    solve(N, std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans=0;
struct node{
	int x,y;
}oi[100005];
int f[100005],k[100005];
vector<int> g[100005],p[100005];
int rt[100005],rtl;

bool cmp(node u,node v){
	return u.y<v.y;
}

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

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d %d",&oi[i].x,&oi[i].y);
		p[oi[i].x].push_back(oi[i].y);
	}
	for(int i=1;i<=100000;i++) f[i]=i,k[i]=1;
	sort(oi+1,oi+n+1,cmp);
	for(int i=2;i<=n;i++){
		if(oi[i-1].y==oi[i].y){
			int hh=find(oi[i-1].x);
			int xx=find(oi[i].x);
			if(hh==xx) continue;
			if(hh<xx){
				f[xx]=hh;
				k[hh]+=k[xx];
			}
			else{
				f[hh]=xx;
				k[xx]+=k[hh];
			}
		}
	}
	for(int i=1;i<=100000;i++){
		int ll=find(i);
		g[ll].push_back(i);
	}
	for(int i=1;i<=100000;i++){
		rtl=g[i].size();
		int cnt=0;
		for(int j=0;j<rtl;j++){
			int v=g[i][j];
			for(int u=0;u<p[v].size();u++){
				rt[++cnt]=p[v][u];
			}
		}
		if(cnt==0) continue;
		sort(rt+1,rt+cnt+1);
		int dd=1;
		for(int j=2;j<=cnt;j++){
			if(rt[j]!=rt[j-1]) dd++;
		}
		ans+=1LL*k[i]*dd;
	}
	printf("%lld\n",ans-1LL*n);
	
	return 0;
}

Measured memory_bytes: 10496
N = int(input())
b = list(map(int, input().split()))
ans = []
while len(b) > 0:
    ok = True
    for i in range(len(b)-1, -1, -1):
        if b[i] == i+1:
            ans.append(b.pop(i))
            break
        else:
            if i == 0:
                ok = False
    if not ok:
        break
if len(ans) != N:
    print(-1)
else:
    for i in range(N-1, -1, -1):
        print(ans[i])


Measured memory_bytes: 3064
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func main() {
	scanner.Split(bufio.ScanWords)

	nBalls := nextInt()
	nBoxes := nextInt()

	if nBalls > nBoxes {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}



Measured memory_bytes: 1096
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = [0] + list(map(int, input().split()))
    B = [0] * (n + 1)
    res = []

    for i in reversed(range(1, n + 1)):
        if B[i] % 2 != A[i]:
            res.append(i)
            for j in range(1, int(pow(i, 0.5)) + 1):
                if i % j == 0:
                    B[j] += 1
                    if j != i // j:
                        B[i // j] += 1

    print(len(res))
    if len(res) != 0:
        print(*res[::-1])


if __name__ == '__main__':
    resolve()


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

int main(){
    int d,g;
    cin >> d >> g;
    pair<int,int> p[d];
    int sum[d];
    for(int i=0;i<d;i++){
        cin >> p[i].first >> p[i].second;
        sum[i]=(i+1)*100*p[i].first+p[i].second;
    }
    int ans=1e9;
    int tmp;
    int count;
    for(int i=0;i<(1<<d);i++){
        tmp=0;
        count=0;
        for(int j=0;j<d;j++)if(i & (1<<j)){
            tmp+=sum[j];
            count+=p[j].first;
        }
        if(tmp<g){
            for(int j=d-1;j>=0;j--){
                if(!(i & (1<<j))){
                    count+=min((g-tmp+j*100)/((j+1)*100),p[j].first);
                    tmp+=min(g-tmp,p[j].first*(j+1)*100);
                    break;
                }
            }
        }
        if(tmp>=g)ans=min(count,ans);
    }
    cout << ans;
}

Measured memory_bytes: 3636
from collections import Counter

n = int(input())

e = []
o = []
for i, v in enumerate(input().split(' ')):
    if i % 2 == 0:
        e.append(int(v))
    else:
        o.append(int(v))

if len(set(e + o)) == 1:
    print(int(len(e + o) / 2))
    exit()

if Counter(o).most_common()[0][0] == Counter(e).most_common()[0][0]:
    ans = min(len(o) - Counter(o).most_common()[1][1] + len(e) - Counter(e).most_common()[0][1], len(o) - Counter(o).most_common()[0][1] + len(e) - Counter(e).most_common()[1][1])
    print(ans)
else:
    print(len(o) - Counter(o).most_common()[0][1] + len(e) - Counter(e).most_common()[0][1])



Measured memory_bytes: 16732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k%2 == 1) cout <<-1*(a-b) << endl;
    else cout << a-b << endl;
}

Measured memory_bytes: 3540
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
int main() {
   string s;
   cin>>s;
   bool flag=true;
   if(s.size()%2!=0){
      s=s.erase(s.size()-1);
   }
   else{
      s=s.erase(s.size()-2,2);
   }
   while(flag){
      string tes1,tes2;
      tes1=s.substr(0,s.size()/2);
      tes2=s.substr(s.size()/2,s.size()/2);
      //cout<<tes1<<endl<<tes2<<endl;
      if(tes1==tes2){
         cout<<s.size()<<endl;
         flag=false;
      }
      else{
         s=s.erase(s.size()-2,2);
      }
   }

}



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

int n, a[100005], c, mx;
int main() {
	int i;
	cin >> n;
	for(i=0; i<n; i++) scanf("%d", &a[i]);
	for(i=n-2; i>=0; i--) {
		if(a[i] >= a[i+1]) c++, mx = max(mx, c);
		else c = 0;
	}
	cout << mx;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (i != n - 1) {
                if (array[i] == i + 1) {
                    int tmp = array[i + 1];
                    array[i + 1] = array[i];
                    array[i] = tmp; 
                    cnt++;
                }   
            } else {
                if (array[i] == i + 1) {
                    int tmp = array[i - 1];
                    array[i - 1] = array[i];
                    array[i] = tmp;
                    cnt++;
                } 
            }
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 50568
n, m = map(int, input().split())
an = [int(input()) for _ in range(m)]

dp = [0 for _ in range(n+1)]
dp[0] = 1
mod = 10**9 + 7

if m == 0:
    dp[0] = 1
    dp[1] = 1
    for i in range(2, n+1):
        dp[i] = (dp[i-1] + dp[i-2]) % mod
    print(dp[n])
    exit()

if an[0] == 1:
    dp[1] = 0
    a = 1
    if len(an) == 1:
        a = 0
else:
    dp[1] = 1
    a = 0

for i in range(2, n+1):
    if i == an[a]:
        dp[i] = 0
        a += 1
        if a == len(an):
            a -= 1
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod

print(dp[n])


Measured memory_bytes: 13724
#include <iostream>

#include <string.h>

using namespace std;

int main()
{
	int dp[31];

	memset(dp, 0, sizeof(dp));

	dp[0] = 1;
	dp[1] = 1;
	dp[2] = 2;
	
	for (int i = 3; i < 31; i++) { dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3]; }


	const int DATASETS = 1000;

	int n[DATASETS], C = 0;


	while (true)
	{
		cin >> n[C];

		if (n[C] == 0){ goto Exit; }

		C++;
	}

Exit:;

	for (int i = 0; i < C; i++)
	{
		cout << (dp[n[i]] - 1) / 3650 + 1 << endl;
	}

	return 0;
}

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

int main() {
    ll a, b;
    cin >> a >> b;
    ll k = (a+b)/2;
    if (abs(a-k) == abs(b-k)) cout << k << endl;
    else cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int MN = 100005;

int N, K;
struct per {
	int a[MN];
	per() {}
	int & operator [] (const int &i) { return a[i]; }
	friend per operator ~ (per A) {
		per C;
		for (int i = 1; i <= N; ++i) C[A[i]] = i;
		return C;
	}
	friend per operator * (per A, per B) {
		per C;
		for (int i = 1; i <= N; ++i) C[i] = A[B[i]];
		return C;
	}
	friend per operator ^ (per B, int E) {
		per A;
		for (int i = 1; i <= N; ++i) A[i] = i;
		for (; E; E >>= 1, B = B * B)
			if (E & 1) A = A * B;
		return A;
	}
} p, q, ip, iq, qip, iqp, qipiqp, ans;

int main() {
	scanf("%d%d", &N, &K);
	for (int i = 1; i <= N; ++i) scanf("%d", &p[i]);
	for (int i = 1; i <= N; ++i) scanf("%d", &q[i]);
	ip = ~p, iq = ~q;
	qip = q * ip, iqp = iq * p;
	qipiqp = qip * iqp;
	ans = qipiqp ^ (K / 6);
	if (K % 6 == 0) ans = ans * iqp * ~ans;
	if (K % 6 == 1) ans = ans * p * ~ans;
	if (K % 6 == 2) ans = ans * q * ~ans;
	if (K % 6 == 3) ans = ans * qip * ~ans;
	if (K % 6 == 4) ans = ans * qip * iq * ~ans;
	if (K % 6 == 5) ans = ans * qip * iqp * iq * ~ans;
	for (int i = 1; i <= N; ++i) printf("%d%c", ans[i], " \n"[i == N]);
	return 0;
}

Measured memory_bytes: 23296
//Love and Freedom.
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#define ll long long
#define inf 20021225
using namespace std;
int read()
{
	int s=0,t=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')	t=-1; ch=getchar();}
	while(ch>='0' && ch<='9')	s=s*10+ch-'0',ch=getchar();
	return s*t;
}
int k,a[501][501];
int main()
{
	k=read();
	if(k<=500)
	{
		printf("%d\n",k);
		for(int i=1;i<=k;i++,puts(""))	for(int j=1;j<=k;j++)
			printf("%d ",j);
		return 0;
	}
	int n=500; int x=1,y=1; int dn=k,c=1,d=2;
	int w=n;
	while(w--)
	{
		int s=n;
		while(s--)
		{
			a[x][y]=s&1?c:d;
			x--; if(!x) x=n;
			y++; if(y>n) y=1;
		}
		x--; if(!x)	x=n;
		if(c==d)	c++,d++;
		else
		{
			dn-=2; c+=2,d+=2;
			if(dn==w)	d=c;
		}
	}
	printf("%d\n",n);
	for(int i=1;i<=n;i++,puts(""))	for(int j=1;j<=n;j++)
		printf("%d ",a[i][j]);
	return 0;
}

Measured memory_bytes: 2048
n=int(input())
info=[]
for i in range(n):
    info.append(int(input()))

info2=sorted(info,reverse=True)
max1=info2[0]
max2=info2[1]

for i in range(n):
    if info[i]==max1:
        print(max2)
    else:
        print(max1)

Measured memory_bytes: 15012
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int n, l, min, result, sign;
    scanf("%d %d", &n, &l);
    min = abs(l);
    sign = 1;
    result = 0;

    for (int i = 1; i < n + 1; i++) {

        if (abs(l + i - 1) < min) {
            min = abs(l + i - 1);
            if (l + i - 1 < 0) {
                sign = -1;
            } else {
                sign = 1;
            }
        }
        result += (l + i - 1);
    }

    result -= min * sign;
    printf("%d\n", result);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long n;
  Solver() {
    S002 r;
    r >= n;
  }
  void solve() {
    printf("%ld\n", n * (n + 1) / 2);
  }
};
 
int main() {
  for(;;) std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;

int main(){
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}



Measured memory_bytes: 3628
# -*- coding: utf-8 -*-
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if 0 in a:
        return 0

    border = 10**18
    ans = 0
    temp = 1
    for i in a:
        temp *= i
        if temp > border:
            ans = -1
            break
        else:
            ans = temp

    return ans


if __name__ == '__main__':
    ans = main()
    print(ans)


Measured memory_bytes: 21644
#include <bits/stdc++.h> 
#define int long long
#define deb(x) cout<<#x <<" = "<<x<<"\n";
using namespace std; 
signed main() 
{
	//freopen("input.txt", "r", stdin);
	
	int n, a, b;
	cin >> n >> a >> b;
	cout << (n / (a+b)) * a + min( (n % (a+b)), a);
	
	
	
	
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
	char S[20];
  	char T[20];
  	int length;
  	scanf("%s", S);
  	scanf("%s", T);
  	strcat(S, "a");
  	if (strcmp(S, T) == 0) printf("Yes\n");
  	else{
      	length = strlen(S);
    	while (1){
          S[length - 1]++;
          if (strcmp(S,T) == 0){
            printf("Yes\n");
            return (0);
          }
          if (S[length - 1] == 'z'){
            printf("No\n");
            return (0);
          }
        }
    }
          return (0);
  
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))

using namespace std;
using ll = long long;


int main() {
    int n, k; cin >> n >> k;
    vector<ll> num(k, 0);
    for (int i = 1; i <= n; ++i) num[i % k]++;
    ll ans = 0;
    for (int a = 0; a < k; ++a) {
        int b = (k - a) % k;
        int c = (k - a) % k;
        if ((b + c) % k != 0) continue;
        ans += num[a] * num[b] * num[c];
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;

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

    int N, A, B, C;
    cin >> N >> A >> B >> C;
    int L[N];
    for (auto &l: L) {
        cin >> l;
    }

    int min_sum = A + B + C;
    for (int i = 0; i < pow(4, N); ++i) {
        int sum = 0;
        int a = 0;
        int b = 0;
        int c = 0;
        int a_merge = -1;
        int b_merge = -1;
        int c_merge = -1;
        int num = i;
        for (auto l: L) {
            switch (num % 4) {
                case 1:
                    a += l;
                    a_merge++;
                    break;
                case 2:
                    b += l;
                    b_merge++;
                    break;
                case 3:
                    c += l;
                    c_merge++;
                    break;
            }
            num /= 4;
        }
        if (a_merge > 0) sum += a_merge * 10;
        if (b_merge > 0) sum += b_merge * 10;
        if (c_merge > 0) sum += c_merge * 10;
        sum += abs(A - a) + abs(B - b) + abs(C - c);
      	if (a > 0 && b > 0 && c > 0) {
            min_sum = min(min_sum, sum);
        }
    }
    
    cout << min_sum << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>

#define N 50

using namespace std;

struct C
{
  const char *s;
  int n;
  int d;

  int
  operator> (
    const struct C &x
    )
  const
  {
    int res;

    res = n * x.d - x.n * d;
    if ( res ) return ( res > 0 );

    return ( strcmp ( s, x.s ) < 0 );
  }
};

int
main (
  )
{
  int i, j;

  for ( ; ; )
  {
    struct C d[ N ];
    char sd[ N ][ 32 ];
    int n;

    scanf ( " %d", &n );
    if ( !( n ) ) break ;

    for ( i = 0; i < n; ++i )
    {
      int p, pt = 0, t = 0, f, s, m;
      scanf ( " %s %d", sd[ i ], &p );
      for ( j = 0; j < 3; ++j )
      {
        int G__21;

        scanf ( " %d", &G__21 );
        pt += G__21;
      }
      for ( j = 0; j < 2; ++j )
      {
        int G__23;

        scanf ( " %d", &G__23 );
        t += G__23;
      }
      scanf ( " %d %d %d", &f, &s, &m );

      d[ i ].s = sd[ i ];
      d[ i ].n = f * s * m - p;
      d[ i ].d = pt + t * m;
    }
    sort ( d, d + n, greater<struct C> ( ) );

    for ( i = 0; i < n; ++i )
    {
      puts ( d[ i ].s );
    }
    puts ( "#" );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    string s;
    size_t a, z;
    cin >> s;
    a = s.find('A');
    z = s.rfind('Z');
    cout << z - a + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int aa, bb, ab, x, y;
    cin >> aa >> bb >> ab >> x >> y;
    x *= 2; y *= 2;
    //cout << "aa:" << aa << " bb:" << bb << " ab:" << ab << ln;
    //cout << "x:" << x << " y:" << y << ln;

    int res = 0;
    if(2 * ab < aa + bb){
        res += min(x, y) * ab;
        //cout << "res:" << res << ln;
        int value;
        if(x > y) value = aa; else value = bb;
        //cout << "value:" << value << " 2ab:" << ab * 2 << ln;
        if(value < 2 * ab)
            res += value * abs(x-y) / 2;
        else
            res += ab * abs(x-y);
    } else{
        res += aa * x / 2 + bb * y / 2;
    }
    cout << res << ln;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int H,W;
char str[105];

int main(){
  scanf("%d %d",&H,&W);
  for(int i=0;i<H;i++){
    int cnt=-1;
    scanf("%s",str);
    for(int j=0;j<W;j++){
      if(str[j]=='c')cnt=0;
      else if(cnt!=-1)cnt++;
      printf("%d",cnt);
      printf(j+1==W?"\n":" ");
    }
  }
  return 0;
}

Measured memory_bytes: 1192
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<((int)n);i++)
#define REP(i,n)	for(int i=0;i<=((int)n);i++)
#define srep(i,a,n)	for(int i=a;i<((int)n);i++)
#define SREP(i,a,n)	for(int i=a;i<=((int)n);i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
template<typename T> istream & operator >> (istream & is, vector<T> & vec) {
	for (T& x : vec)	is >> x;
	return is;
}
template<typename T> ostream& operator << (ostream & os, vector<T> & vec) {
	os << "[";
	rep(i, vec.size())	os << (i ? ", " : "") << vec[i];
	os << "]";
	return os;
}
template<typename T> istream & operator >> (istream & is, pair<T, T> & p) {
	is >> p.first >> p.second;
	return is;
}
template<typename T> ostream& operator << (ostream & os, pair<T, T> & p) {
	os << p.first << " " << p.second;
	return os;
}
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll sqrtll(ll x) {
	ll left = 0, right = x;
	rep(i, 100) {
		ll mid = (left + right) >> 1;
		if (mid * mid <= x)	left = mid;
		else	right = mid;
	}
	return left;
}
ll gcd(ll a, ll b) {
	return b == 0 ? a : gcd(b, a % b);
}
#define debug(x)	printf("Case #%d: ", x)
#define DEBUG 0
const ld infl = 1e100;
const ll mod = 1e9 + 7;
const ld eps = 1e-9;
const ll inf = 1e18;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

int main() {
	string s;	cin >> s;
	int cnt = 0;
	rep(i, s.size()) {
		if (s[i] == 'x')	cnt++;
	}
	cout << (cnt >= 8 ? "NO" : "YES") << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[][] room=new int[12][10];
		for(int i=0; i<12; i++) {
			Arrays.fill(room[i],0);
		}
		for(int i=0; i<N; i++) {
			int tou=sc.nextInt();
			int kai=sc.nextInt();
			int heya=sc.nextInt();
			int ninzu=sc.nextInt();
			room[(tou-1)*3+kai-1][heya-1]+=ninzu;
		}
		o(room);
	}
	public static void o(int[][] a) {
		for(int i=0; i<4; i++) {
			for(int j=0; j<3; j++) {
				for(int k=0; k<9; k++) {
					System.out.print(" "+a[i*3+j][k]);
				}
				System.out.println(" "+a[i*3+j][9]);
			}
			if(i!=3) {
				System.out.println("####################");
			}
		}
	}
}


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


 int main(){
	 
	 int h;
	 while(1){
		 int p=0;
		 int flag=1;
		 int x;
		cin >> h;
		if(h == 0) break;
		vector<vector<int>> A(5);
		for(int j = h-1; j >= 0; j--){
			for(int i = 0; i< 5; i++){
				cin >> x;
				A[i].push_back(x);
			}
		}
		for(int i = 0; i< 5; i++){
			reverse(A[i].begin(), A[i].end());
			}


		while(1){
			int flag=0;
		for(int i = 0; i < h; i++){
			int count=0;
			int mem=-1;
			//一行の処理開始
			for(int j=0; j< 5;j++){
				if(mem==A[j][i]) count++;
				else {
					mem =A[j][i];
					count = 0;
				}
				if(count > 1) {
					A[j-2][i] +=10;
					A[j-1][i] +=10;
					A[j][i] +=10;
					if(mem!=0) flag =1;
				}
			}
			for(int k = 0; k < 5 ; k++){
				if(A[k][i] >=10){
					p += A[k][i]%10;
					A[k][i]=0;
				}
			}//一行の処理終了
		}
		for(int i= 0; i < 5 ; i++){
			vector<int> B(A[i]);
			int counter=0;
			for(int j = 0 ; j < h ; j++){
				if(B[j] !=0){
					A[i][counter] = B[j];
					counter+=1;
				}
			}
			for(;counter<h; counter++){
				A[i][counter] = 0;
			}
		} 
		if(flag == 0) break;
		}
		cout <<p <<endl;
	 }
		 



	return 0;
 }

Measured memory_bytes: 1212
#include <iostream>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)

int H, W;

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

    while (1) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break ;
        }
        REP(i, H) {
            REP(j, W) {
                if ((i + j) % 2) {
                    cout << '.';
                } else {
                    cout << '#';
                }
            }
            cout << '\n';
        }
        cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;


int main(void){
  int a,b,q,i,j,k;
  ll s[100005],t[100005],x,co1,co2,ans;
  ll *p1,*p2;
  
  cin >> a >> b >> q;
  for (i=0;i<a;i++) cin >> s[i];
  for (i=0;i<b;i++) cin >> t[i];
  
  for (i=0;i<q;i++){
    vector<ll> ap,bp;
    cin >> x;
    
    p1=lower_bound(s,s+a,x);
    p2=lower_bound(t,t+b,x);
    
    if (p1!=s) ap.push_back(*(p1-1)-x);
    if (p1!=s+a) ap.push_back(*p1-x);
    if (p2!=t) bp.push_back(*(p2-1)-x);
    if (p2!=t+b) bp.push_back(*p2-x);
    
    ans=1e12;
    for (j=0;j<ap.size();j++) for (k=0;k<bp.size();k++){
      co1=abs(ap[j])+abs(ap[j]-bp[k]);
      co2=abs(bp[k])+abs(bp[k]-ap[j]);
      ans=min({ans,co1,co2});
    }
    
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

const int MAX = 100005;
int counter[MAX];

int main() {
  int n;
  cin >> n;
  ll a[n];
  ll fsum = 0;
  for (int i = 0; i < MAX; ++i) {
    counter[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    counter[a[i]]++;
    fsum += a[i];
  }
  int q;
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; ++i) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; ++i) {
    ll cur = counter[b[i]];
    counter[b[i]] = 0;
    counter[c[i]] += cur;
    fsum += (ll)((c[i]-b[i])*cur);
    cout << fsum << endl;
  }

  return 0;
}

Measured memory_bytes: 5576
#include <stdio.h>

#define SQ(X) \
  ( (X) * (X) )
#define SQD(X,Y) \
  ( SQ(X) + SQ(Y) )

int zcos (
  double x1,
  double y1,
  double x2,
  double y2
  )
{
  double pred = ( x1 * y2 - y1 * x2 );

  if ( pred > 0. )
  {
    return ( 1 );
  }
  else if ( pred < 0. )
  {
    return ( -1 );
  }
  
  return ( 0 );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  double x[ 4 ], y[ 4 ];
  int i;

  while ( scanf ( " %lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
                    x, y, x + 1, y + 1, x + 2, y + 2, x + 3, y + 3 ) == 8 )
  {
    int positive = 0, negative = 0;

    for ( i = 0; i < 4; ++i )
    {
      int pred = zcos ( x[ ( i + 1 ) % 4 ] - x[ i ],
                        y[ ( i + 1 ) % 4 ] - y[ i ],
                        x[ ( i + 2 ) % 4 ] - x[ ( i + 1 ) % 4 ],
                        y[ ( i + 2 ) % 4 ] - y[ ( i + 1 ) % 4 ] );
      
      positive += !!( pred > 0 );
      negative += !!( pred < 0 );
    }

    puts ( positive && negative ? "NO" : "YES" );
  }

  return ( 0 );
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sc(x) scanf("%lld",&x)
#define pr(x) printf("%lld\n",x)
#define clr(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
typedef pair<ll, ll> pii;
typedef vector< ll > vl;
typedef vector< pii > vpii;

//DONT WASTE YOUR TIME
//prove yourself
//remember....fuck ps&&as hard....show them your are better then them
//Be confident.....dont lose hope.......You can do it.....
//dimaag  khoob h tere meh ....bas concentration ki kami h
//CONCENTRATE
//A,B,C dimaag nhi ...observation h .....zyaada mat sochna unme.....bas observe karna dhyaan se aur implement kar daal jitni jaldi ho sake

//capture it

const ll N= 1e6+55,mod = 1e9+7;

int main() {
 	//freopen("task.in","r",stdin);freopen("task.out","w",stdout);
	ll i,j,k,x,y,z,a,b,c,s,n;
	s=0;
	sc(n);sc(a);sc(b);	
	for(i=1;i<=n;i++){
		x=i;
		y=0;
		while(x>0){
			y+=(x%10);
			x=x/10;
		}
		if(y>=a && y<=b){
			s+=i;
		}
	}
	pr(s);
}

Measured memory_bytes: 256
import sys

N, M = map(int, sys.stdin.readline().split())
a_list = list(map(int, sys.stdin.readline().split()))
items = []
for i in range(M):
    items.append(tuple(map(int, sys.stdin.readline().split())))

from heapq import *

que = []

for i in range(N):
    a = a_list[i]
    heappush(que, (-a, 1))

for b, c in items:
    heappush(que, (-c, b))

cnt = 0
ans = 0
while cnt < N:
    k, v = heappop(que)
    if cnt + v <= N:
        cnt += v
        ans += -(k * v)
    else:
        ans += -(k) * (N-cnt)
        cnt = N
print(ans)


Measured memory_bytes: 43068
X, Y, A, B, C = map(int, input().split())
P = sorted(map(int, input().split()), reverse=True)[:X]
Q = sorted(map(int, input().split()), reverse=True)[:Y]
R = sorted(map(int, input().split()), reverse=True)

PQ = sorted(P+Q)
ans = sum(PQ)
for r, pq in zip(R, PQ):
    if r > pq:
        ans += r - pq
print(ans)


Measured memory_bytes: 28308
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

LL re(LL a, LL b, LL c) {
	return max({ a,b,c }) - min({ a,b,c });
}

int main() {
	LL h, w; cin >> h >> w;

	LL c1 = inf;
	if (h % 3 == 0 || w % 3 == 0)c1 = 0;
	else c1 = min(h, w);

	LL c2 = inf;
	FOR(i, 1, h) {
		LL a = i * w, b = w / 2 * (h - i), c = h * w - a - b;
		c2 = min(c2, re(a, b, c));
	}
	LL c3 = inf;
	FOR(i, 1, w) {
		LL a = i * h, b = h / 2 * (w - i), c = h * w - a - b;
		c3 = min(c3, re(a, b, c));
	}

	Cout(min({ c1,c2,c3 }));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  ll n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  ll s = a[0];
  int r = 0;
  for (int l = 0; l < n; l++) {
    while (r < n-1 && ((s ^ a[r+1]) == s + a[r+1])) {
//      cerr << s << " ^ " << a[r+1] << ": " << (s ^ a[r+1]) << " == " << s + a[r+1] << endl;
      r++;
      s += a[r];
    }
//    cerr << "l: " << l << "  r: " << r << endl;
    ans += (r - l + 1);
    s -= a[l];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << endl;
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define wh while
#define ve vector
#define mp make_pair
#define tp tuple
#define mt make_tuple
#define pb push_back
#define pof pop_front
#define pob pop_back
#define pf push_front
#define fr front
#define ft first
#define sc second
#define tos to_string
#define len length
#define rt return
#define br break
#define con continue
#define lcm(n, m) (n * m / __gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m) - 1;i>=(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) n.begin(), n.end()
#define allr(n) n.rbegin(), n.rend()
#define sp(n) cout << fixed << setprecision(n)
#define pi 3.14159265359
#define inf 1000000007
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

ve<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};

int main() {
  int k;
  st s;
  ci(k, s);
  if(sz(s) <= k){
    co(s);
    rt 0;
  }
  else{
    rep(i, k){
      cout << s.at(i);
    }
  }
  cout << "..." << endl;
}

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

int main(){
    int a,b,c;
    cin>>a>>b;
    if(a==1)a=14;
    if(b==1)b=14;
    if(a>b)cout<<"Alice"<<endl;
    else if(b>a)cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;



return 0;
}


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

typedef long long ll;
const int N = 500005;
const int M = 1000000007;

int n;
char s[N];

int nxt[N], nxtr[N];
void getnxt(char *x, int m, int nxt[]) {
  int i = 0, j = -1; nxt[0] = -1;
  while (i < m) {
    while (j != -1 && x[i] != x[j]) { j = nxt[j]; }
    nxt[++i] = ++j;
  }
}

inline bool isloop(int len, int nxt[]) {
  return nxt[len] && len % (len - nxt[len]) == 0;
}

int main() {
  while (~scanf("%s", s)) {
    n = strlen(s);
    getnxt(s, n, nxt);
    if (!isloop(n, nxt)) { printf("1\n1\n"); continue; }
    if (nxt[n] == n - 1) { printf("%d\n1\n", n); continue; }
    reverse(s, s + n);
    getnxt(s, n, nxtr);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      ans += (!isloop(i, nxt) && !isloop(n - i, nxtr));
    }
    printf("2\n%d\n", ans);
  }
}


Measured memory_bytes: 4608
N, M = map(int, input().split())

AB = []

for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

AB.sort()

ans = 0
cnt = 0

for ab in AB:
    for b in range(ab[1]):
        ans += ab[0]
        cnt += 1
        if cnt==M:
            break
    if cnt==M:
        break

print(ans)

Measured memory_bytes: 20064