akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	int n; cin>>n;
	vi xs(n),ys(n);
	rep(i,n) cin>>xs[i]>>ys[i];
	
	vi ps(n),qs(n);
	rep(i,n){
		ps[i]=xs[i]+ys[i];
		qs[i]=xs[i]-ys[i];
	}
	
	int pmin=min_element(all(ps))-ps.begin(),pmax=max_element(all(ps))-ps.begin();
	int qmin=min_element(all(qs))-qs.begin(),qmax=max_element(all(qs))-qs.begin();
	
	int res1=0,res2=0;
	rep(i,n){
		res1=max(res1,min(
			max(max(abs(ps[i]-ps[pmin]),abs(ps[i]-ps[qmin])),
				max(abs(qs[i]-qs[pmin]),abs(qs[i]-qs[qmin]))),
			max(max(abs(ps[i]-ps[pmax]),abs(ps[i]-ps[qmax])),
				max(abs(qs[i]-qs[pmax]),abs(qs[i]-qs[qmax])))
		));
		res2=max(res2,min(
			max(max(abs(ps[i]-ps[pmax]),abs(ps[i]-ps[qmin])),
				max(abs(qs[i]-qs[pmax]),abs(qs[i]-qs[qmin]))),
			max(max(abs(ps[i]-ps[pmin]),abs(ps[i]-ps[qmax])),
				max(abs(qs[i]-qs[pmin]),abs(qs[i]-qs[qmax])))
		));
	}
	cout<<min(res1,res2)<<endl;
	
	return 0;
}

Measured memory_bytes: 2588
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


bool solve(){
  int m, n_min, n_max, p[SIZE];

  cin >> m >> n_min >> n_max;

  if(m == 0) return false;
  
  int ans_max = 0, ans = -1;
  
  for(int i=0;i<m;i++){
    cin >> p[i];
    if(i > 0 && n_min <= i && i <= n_max){
      if(ans_max <= p[i-1] - p[i]){
        ans_max = p[i-1] - p[i];
        ans = i;
      }
    }
  }

  cout << ans << endl;
  
  return true;
}

int main(){
  while(solve());
}



Measured memory_bytes: 3088
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;
	
	long go(long a, long b, long c) {
		if (a < 0 || b < 0 || c < 0) {
			return Long.MIN_VALUE;
		}
		
		return a + b + c - (a & 1) - (b & 1) - (c & 1);
	}

	void solve() throws IOException {
		long i = nextLong();
		long o = nextLong();
		long t = nextLong();
		long j = nextLong();
		long l = nextLong();
		long s = nextLong();
		long z = nextLong();
		
		long ans = o + Math.max(go(i, j, l), go(i - 1, j - 1, l - 1) + 3);
		
		out.println(ans);
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 8276
using System;
using System.Linq;

namespace AtCoderGrandContest043
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputs = ReadIntArray();
			var height = inputs[0];
			var width = inputs[1];
			var map = new bool[inputs[0], inputs[1]];
			for (var i = 0; i < inputs[0]; i++)
			{
				var str = ReadString();
				for (var j = 0; j < str.Length; j++)
				{
					if (str[j] == '.')
					{
						map[i, j] = true;
					}
					else
					{
						map[i, j] = false;
					}
				}
			}

			var result = new int[inputs[0], inputs[1]];
			if (!map[0, 0])
			{
				result[0, 0] = 1;
			}

			for (var i = 1; i < height; i++)
			{
				if (map[i - 1, 0] && !map[i, 0])
				{
					result[i, 0] = result[i - 1, 0] + 1;
				}
				else
				{
					result[i, 0] = result[i - 1, 0];
				}
			}

			for (var i = 1; i < width; i++)
			{
				if (map[0, i - 1] && !map[0, i])
				{
					result[0, i] = result[0, i - 1] + 1;
				}
				else
				{
					result[0, i] = result[0, i - 1];
				}
			}

			for (var i = 1; i < height; i++)
			{
				for (var j = 1; j < width; j++)
				{
					var row = 0;
					if (map[i, j - 1] && !map[i, j])
					{
						row = result[i, j - 1] + 1;
					}
					else
					{
						row = result[i, j - 1];
					}

					var colum = 0;
					if (map[i - 1, j] && !map[i, j])
					{
						colum = result[i - 1, j] + 1;
					}
					else
					{
						colum = result[i - 1, j];
					}

					result[i, j] = Math.Min(row, colum);
				}
			}

			Console.WriteLine(result[height - 1, width - 1]);
		}

		public static int ReadInt()
			=> int.Parse(Console.ReadLine());

		public static int[] ReadIntArray()
			=> Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

		public static long ReadLong()
			=> long.Parse(Console.ReadLine());

		public static long[] ReadLongArray()
			=> Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

		public static string ReadString()
			=> Console.ReadLine();

		public static string[] ReadStringArray()
			=> Console.ReadLine().Split();
	}
}


Measured memory_bytes: 13396
fun main(args:Array<String>) {
 val N = readLine()!!.toInt()
 val AB= (1..N).map {
    val arr=readLine()!!.split(" ").map(String::toLong)
    Pair(arr[0],arr[1])
  }.sortedBy{ it.first}
  // println(AB)
(  1.until(N).map { 
    AB[it].first - AB[it-1].first
}.fold(0L) { sum,ele -> sum+ele}+AB[N -1 ].second + AB[0].first  ).let { 
    println(it)
  }
}

Measured memory_bytes: 85416
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

bool ma[128][128]={0};
int n, m, d;
char c;

int main(){

	while(cin >> n, n){
		
		queue<char> com;
		int x=10, y=10;
		
		memset(ma, 0, sizeof(ma));
		
		int a, b;
		
		for(int i=0; i<n; ++i){
			cin >> a >> b;
			ma[b][a] = true;
		}
		
		cin >> m;
		
		for(int i=0; i<m; ++i){
			
			cin >> c >> d;
			
			for(int i=0; i<d; ++i){	
				com.push(c);
			}	
		}
		
		if(ma[y][x]){
			n--;
			ma[y][x]=false;
		}
		
		while(!com.empty()){
			
			c = com.front();
			com.pop();
			
			if(c=='N')
				y++;
			else if(c=='E')
				x++;
			else if(c=='W')
				x--;
			else if(c=='S')
				y--;
				
			if(ma[y][x]){
				n--;
				ma[y][x]=false;
			}
		}
		
		cout << (!n?"Yes":"No") << endl;

	}

	return 0;
}

Measured memory_bytes: 1216
S = input()
n = len(S)
dp = [[0] * 2 for _ in range(n)]
s = int(S[0])
dp[0][s] = 0
dp[0][1-s] = 1
for i, s in enumerate(S[1:], 1):
    s = int(s)
    dp[i][s] = dp[i-1][1-s]
    dp[i][1-s] = dp[i-1][s] + 1
print(min(dp[n-1]))


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

//mod逆元を使ったnCkの計算(速)
const ll MAX = 3000010;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
 
// 二項係数計算
ll COM(ll n, ll k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
//繰り返し二乗法
ll powmod(ll x, ll n) { 
  ll ans = 1;
  while (n > 0) {
    if ((n & 1) == 1) {
      ans = ans * x;
      ans %= MOD;
    }
    x = x * x;//一周する度にx, x^2, x^4, x^8となる
    x %= MOD;
    n >>= 1; //桁をずらす n = n >> 1
  }
  return ans;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    COMinit();
    ll a=powmod(10,n)%MOD;
    ll b=powmod(9,n)%MOD;
    b=(2*b)%MOD;
    ll ans=a-b;
    if(ans<0) ans+=MOD;
    ll c=powmod(8,n)%MOD;
    ans+=c;
    ans=ans%MOD;
    cout << ans << "\n";
    return 0;
}   

Measured memory_bytes: 73956
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a, b) << " " << max(a + b - n, 0) << endl;
}

Measured memory_bytes: 256
void main() {
	auto H = readAs!long;
	ulong cnt;
	long[] queue = [H];

	long[long] m;
	m[1] = 1;
	long dfs(long n) {
		if(n in m) return m[n];
		return m[n] = 2*dfs(n/2) + 1;
	}
	dfs(H).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

struct Rectangle {
	ll h, w;
	Rectangle(ll _h, ll _w) :h(_h), w(_w) {}
	bool operator<(const Rectangle& r) {
		if (h * h + w * w == r.h * r.h + r.w * r.w) {
			return h < r.h;
		}
		else {
			return h * h + w * w < r.h * r.h + r.w * r.w;
		}
	}
};
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int kkt = 89;
	vector<Rectangle> vr;
	for (int i = 1; i <= 300; i++) for (int j = i + 1; j <= 300; j++) vr.emplace_back(i, j);
	sort(vr.begin(), vr.end());
	while (kkt) {
		ll H, W; scanf("%lld %lld", &H, &W);
		if (H == 0) break;
		ll left = -1;
		ll right = (ll)vr.size() - 1;
		while (right - left > 1) {
			ll mid = (left + right) >> 1;
			if (Rectangle(H,W) < vr[mid]) {
				right = mid;
			}
			else {
				left = mid;
			}
		}
		cout << vr[right].h << " " << vr[right].w << "\n";
	}

	return 0;

}


Measured memory_bytes: 3684
#include<iostream>
#include<vector>
#define SIZE 30

using namespace std;
struct Queue
{
  int list[SIZE];
  int head,tail;
  void init(){ head=tail=0; }
  bool isEmpty(){ return head==tail; }
  bool isFull(){ return head==(tail+1)%SIZE; }
  void enqueue(int x)
  {
    if(isFull()){
      cout << "ERROR(Over flow)" << endl;
      //exit(1);
    }
    list[tail] = x;
    tail++;
    tail %= SIZE;
  }
  int dequeue()
  {
    if(isEmpty()){
      cout << "ERROR(Under flow)" << endl;
      //exit(1);
    }
    int x = list[head];
    head++;
    head%=SIZE;
    return x;
  }
};
struct Node
{
  int p,s,dep,deg,h,r,l;
  string type; 
  void init(){ p=-1; s=-1; h=-1; }
};
Queue q;

void print(vector<Node>& nodes)
{
  int i;
  for(i=0;i<nodes.size();i++){
    cout<<"node "<<i<<": parent = "<<nodes[i].p<<", sibling = "<<nodes[i].s<<", degree = "<<nodes[i].deg<<", depth = "<<nodes[i].dep<<", height = "<<nodes[i].h<<", "<<nodes[i].type<<endl;
  }
}
void bfs(vector<Node>& nodes)
{
  int i,now=q.dequeue();
  nodes[now].dep=(nodes[now].p>=0 ? nodes[ nodes[now].p ].dep+1 : 0);
  if(nodes[now].p<0) nodes[now].type="root";
  else if(nodes[now].deg>0) nodes[now].type="internal node";
  else nodes[now].type="leaf";
  
  if(nodes[now].r>=0) q.enqueue(nodes[now].r); if(nodes[now].l>=0) q.enqueue(nodes[now].l);
  if(!q.isEmpty()) bfs(nodes);
}

void calcHeight(vector<Node>& nodes)
{
  int h=0,now=q.dequeue(); 
  nodes[now].h=h;
  while(1){
    if(nodes[now].type=="root") break;
    h++;
    if(h > nodes[ nodes[now].p ].h) nodes[ nodes[now].p ].h=h;
    now=nodes[now].p;
    if(nodes[now].p==-1) break;
  }
   if(!q.isEmpty()) calcHeight(nodes);
}
int main()
{
  int i,n,id,deg;
  vector<Node> nodes;
  cin>>n;
  nodes.resize(n);
  for(i=0;i<n;i++) nodes[i].init();
  
  for(i=0;i<n;i++){
    cin>>id;
    cin>>nodes[id].l>>nodes[id].r;
    nodes[ nodes[id].l ].p=id; nodes[ nodes[id].r ].p=id;
    nodes[ nodes[id].l ].s=nodes[id].r;
    nodes[ nodes[id].r ].s=nodes[id].l;
    deg=0;
    if(nodes[ nodes[id].r ].s>=0) deg++;
    if(nodes[ nodes[id].l ].s>=0) deg++;
    nodes[id].deg=deg;
  }
  
  for(i=0;i<n;i++) if(nodes[i].p==-1) id=i;
  q.init(); 
  q.enqueue(id); 
  bfs(nodes);
  
  for(i=0;i<n;i++) if(nodes[i].type=="leaf") q.enqueue(i);
  if(q.isEmpty()) q.enqueue(0);
  calcHeight(nodes);
  
  print(nodes);
  
  return 0;
}



Measured memory_bytes: 3204
N, K = gets.chomp.split.map(&:to_i)
MOD = 998244353

LRs = []
K.times do
    LRs << gets.chomp.split.map(&:to_i)
end

dp = Array.new(N+1, 0)
dp[0] = 1
dp[1] = -1

N.times do |i|
    if i > 0 then
        dp[i] += dp[i-1]
        dp[i] %= MOD 
    end
    LRs.each do |l, r|
        if i+l < N then
            dp[i+l] += dp[i]
            dp[i+l] %= MOD
        end
        if i+r+1 < N then
            dp[i+r+1] -= dp[i]
            dp[i+r+1] %= MOD
        end
    end
end

puts dp[N-1]

Measured memory_bytes: 15916
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
k = 0
for i in range (N):
    if A[i] >= B[i]:
        k += B[i]
    else:
        if i < (N-1):
            k += A[i]
            yoo = B[i] - A[i]
            if yoo > A[i + 1]:
                k += A[i + 1]
                A[i + 1] = 0
            else:
                A[i + 1] -= (B[i] - A[i])
                k += yoo
        else:
            k += A[N-1]
            yo = B[N-1] - A[N-1]
            if yo > A[N]:
                k += A[N]
            else:
                k += yo
print(k)


Measured memory_bytes: 19004
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  string s; cin >> s;
  string t = s;
  reverse(begin(t), end(t));
  cout << (s == t ? "Yes" : "No") << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>
 int main()
{
 int h,w,i,j;
 
 for(;;){
         scanf("%d%d",&h,&w);
         if(h+w==0)break;

         for(i=1;i<=h;i++){
                          for(j=1;j<=w;j++)
                          if((i+j)%2==0)
                                 printf("#");
                          else
                                 printf(".");
                          printf("\n");
                          }
         printf("\n");
         }
 return 0;
}
         


Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;


int MOD=1000000007;
int main(void){
	int N;
	cin >> N;
	string S,T;
	cin >> S >> T;
	for(int i=0; i<N; i++){
		cout <<S[i] << T[i];
	}
	cout << endl;
}


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

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

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

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int h, w;;
	cin >>h >>w;
	
	vector<string> ba(h, string(w, ' '));
	vector<VI> dp(h, VI(w));
	rep(i,h) rep(j,w) cin >>ba[i][j];
	
	for(int i=0; i<h && ba[i][0] =='.'; i++) dp[i][0]=1;
	for(int i=0; i<w && ba[0][i] =='.'; i++) dp[0][i]=1;

	rep2(i,1,h) rep2(j,1,w) if(ba[i][j] =='.'){
		dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
	}
	
	cout << dp[h-1][w-1] <<"\n";
	//for(auto xl: dp){for(auto x :xl) printf("%d ",x); puts("");}

	return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
//#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
ll N, X;
vector<ll> b, l, u;

bool IsOK(ll total)
{
    vector<pair<ll, int>> v;
    rep(i, 0, N)
    {
        v.emplace_back(u[i] * (X - b[i]) + l[i] * b[i], i);
    }
    sort(v.begin(), v.end(), greater<pair<ll, int>>());

    const ll xNum = total / X;

    ll score = 0;
    rep(i, 0, N)
    {
        const int idx = v[i].second;

        if (i < xNum)
        {
            score += u[idx] * (X - b[idx]);
        }
        else
        {
            score += l[idx] * (0 - b[idx]);
        }
    }

    const ll remainder = total % X;

    ll best = - N * X;
    rep(i, 0, N)
    {
        const int idx = v[i].second;

        if (i < xNum)
        {
            ll tmp = score;
            tmp -= (u[idx] * (X - b[idx]));
            tmp += (remainder > b[idx] ? u[idx] : l[idx]) * (remainder - b[idx]);
            if (xNum < N)
            {
                const int idx2 = v[xNum].second;
                tmp -= l[idx2] * (0 - b[idx2]);
                tmp += u[idx2] * (X - b[idx2]);
            }
            chmax(best, tmp);
        }
        else
        {
            ll tmp = score;
            tmp -= (l[idx] * (0 - b[idx]));
            tmp += (remainder > b[idx] ? u[idx] : l[idx]) * (remainder - b[idx]);
            chmax(best, tmp);
        }
    }

    return best >= 0;
}

void _main()
{
    cin >> N >> X;
    b.resize(N); l.resize(N); u.resize(N);
    rep(i, 0, N) cin >> b[i] >> l[i] >> u[i];

    ll ng = -1;
    ll ok = N * X;
    while (abs(ng - ok) > 1)
    {
        const ll mid = (ng + ok) / 2;

        if (IsOK(mid))
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    cout << ok << endl;
}


Measured memory_bytes: 6292
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
using namespace std;
using ll = long long;

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

    int N;
    cin >> N;

    cout << N*N << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
#define rep(i,x,n) for(int i=x;i<n;i++)
#define reprev(i,n,x) for(int i=n;i>=x;i--)
#define mp(a,b) make_pair(a,b)
#define mod 998244353
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#pragma GCC target ("sse4.2")
using namespace std; 
void grayserge()
{
   int n;
   cin>>n;
   int k;
   cin>>k;
   int h[n];
   for(int i=0;i<n;i++){
    cin>>h[i];
   }
   int dp[n];
   dp[0]=0;
   dp[1]=abs(h[1]-h[0]);
   for(int i=2;i<n;i++){
    dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
    for(int j=2;j<=min(k,i);j++){
      dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]),dp[i]);
    }
    // dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
   }
   cout<<dp[n-1];
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    int t=1;
    // cin>>t;
    while(t--){
      grayserge();
    }
    cerr<<"time taken: "<<(float)clock()/CLOCKS_PER_SEC<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(){

// DECLARAÇÃO
int N,M;
int multiplicacao,soma,subtracao;
int maior;

// INSTRUÇÕES
scanf ("%d %d",&M,&N);

multiplicacao = M*N;
maior = multiplicacao;

soma = M+N;

if (soma > maior)
    maior = soma;

subtracao = M-N;
if (subtracao > maior)
    maior = subtracao;

printf ("%d",maior);

return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
double calc(int *p,int *q,double r)
{
  double ans=0;
  for(int i=0;i<6;i++){
    ans+=max(r*p[i]/100.,(1-r)*q[i]/100.);
  }
  return ans;
}

int main()
{
  int p[6],q[6];
  for(int i=0;i<6;i++){
    scanf("%d",p+i);
  }
  for(int i=0;i<6;i++){
    scanf("%d",q+i);
  }
  double r0=0.,r3=1.;
  while(r3-r0>1e-12){
    double r1=(2*r0+r3)/3,r2=(r0+2*r3)/3;
    double d1=calc(p,q,r1),d2=calc(p,q,r2);
    if(d1<d2){
      r3=r2;
    }
    else{
      r0=r1;
    }
  }
  printf("%.12lf\n",calc(p,q,(r0+r3)/2.));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (i=a;i<n;i++)
#define per(i,a,n) for (i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE 1000001
#define ONLINE_JUDGE
#define rd
#define PI acos(-1)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
auto clk=clock(); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;

int main(){
	//srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(2);
	#ifndef rd
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif	

	

	// Write after this

	int r;
	cin>>r;
	cout<<2*PI*r;

	// End code here


	#ifndef ONLINE_JUDGE
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
	#endif
	return 0;
}

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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)

int a, b;

int main()
{
	cin >> a >> b;
	if (a < 9 && b < 9) cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,z;
string s[234567];
pair<int,string> p[234567];
int main(){
    cin>>n;
    
    for(int i=0;i<n;i++)cin>>s[i];
    if(n==1){
        cout<<s[0]<<endl;
        return 0;
    }
    sort(s,s+n);
    string S=s[0];
    int j=0;
    p[0].second=s[0];
    while(n>z){
        if(S==s[z]){
            p[j].first++;
            
        }
        else{
            j++;
            p[j].first++;
            p[j].second=s[z];
            S=s[z];
        }z++;
        
    }
    sort(p,p+j+1);
    int a=p[j].first;
    for(int i=0;i<n;i++){
        if(p[i].first==a)cout<<p[i].second<<endl;
    }
}


Measured memory_bytes: 18176
import copy
n = int(input())
inf = 10**18
g = [[]]
for i in range(n):
    g.append([0]+list(map(int, input().split())))

g2 = copy.deepcopy(g)
for k in range(1, n+1):
    for i in range(1, n+1):
        for j in range(1, n+1):
            if g[i][k] == 0 or g[k][j] == 0:
                continue
            if g[i][j] == g[i][k] + g[k][j]:
                g[i][j] = 0

ans = 0
for i in range(1, n+1):
    ans += sum(g[i])

for i in range(1, n+1):
    for j in range(1, n+1):
        if g[i][j] == 0:
            g[i][j] = inf
    g[i][i] = 0

for k in range(1, n+1):
    for i in range(1, n+1):
        for j in range(1, n+1):
            g[i][j] = min(g[i][k] + g[k][j], g[i][j])

if g != g2:
    ans = -1

print(ans//2)


Measured memory_bytes: 57948
x, y = map(int, raw_input().split())

d = abs(abs(x) - abs(y))

if x * y > 0:
    if x <= y:
        print d
    else:
        print d + 2
elif x * y == 0:
    if x <= y:
        print d
    else:
        print d + 1
else:
    print d + 1


Measured memory_bytes: 2568
from operator import itemgetter
n=int(input())
r=[list(map(int,input().split())) for i in range(n)]
b=[list(map(int,input().split())) for i in range(n)]
r.sort()
b.sort()
ct=0
for i in range(n):
  x=b[i][0];y=b[i][1]
  L=[]
  for j in range(len(r)):
    if r[j][0]<x and r[j][1]<y:
      L.append(r[j])
    L=sorted(L,key=itemgetter(1))
  if len(L)>0:
    r.remove(L[len(L)-1])
    ct+=1
print(ct)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,cnt=0;
  cin>>n;
  vector<int> a(n+1),b(n+1,0);
  for(int i=1;i<n+1;i++) cin>>a[i];

  for(int i=n;i>0;i--){
    int sum=0;
    for(int j=i+i;j<=n;j+=i){
      if(j%i==0) sum+=b[j];
    }
    if(sum%2!=a[i]){
      b[i]=1;
      cnt++;
    }
  }
  
  cout<<cnt<<endl;
  for(int j=1;j<n+1;j++){
    if(b[j]==1) cout<<j<<" ";
  }
  return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,x;
  cin>>n>>x;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];

  vector<Int> s(n+1,0);
  for(Int i=0;i<n;i++) s[i+1]=s[i]+a[i];

  Int ans=0;
  for(Int k=50;k>=0;k--){
    ans|=1LL<<k;
    Int cnt=0;
    for(Int l=0;l<n;l++)
      for(Int r=l+1;r<=n;r++)
        if(((s[r]-s[l])&ans)==ans) cnt++;
    if(cnt<x) ans^=1LL<<k;
  }  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
using namespace std;
char stone[200005];
ll cr[200005];
ll cw[200005];

int main(){
   ll n;
   cin>>n>>(stone+1);
   ll ans=n;
   for(ll i=1;i<=n;i++)cw[i]=cw[i-1]+(stone[i]=='W');
   for(ll i=n;i>=1;i--)cr[i]=cr[i+1]+(stone[i]=='R');
   
   for(ll i=0;i<=n;i++) {
   	  ans=min(ans,max(cw[i],cr[i+1]));
   	  ans=min(ans,cw[i]+cr[i+1]);
    }
   cout<<ans;
   
   
   
}
	
 
    

Measured memory_bytes: 6904
#include<iostream>
enum{N=100002,M=100000007};long long d[N+1][2],t,i,j,l[2]={3,5};main(){for(;t<2;t++){for(d[1][t]=i=1;i++<l[t];)d[i][t]=d[i-1][t]*2;for(i=l[t];i++<N;)for(d[i][t]=1,j=0;j++<l[t];)d[i][t]=(d[i][t]+d[i-j][t])%M;}for(std::string s;std::cin>>s,s!="#";printf("%d\n",t))for(s+=(t=j=i=1);i<s.size();i++)s[i-1]-s[i]?(t=t*d[j][s[i-1]-56&&s[i-1]-48]%M),j=1:j++;}

Measured memory_bytes: 2712
#122-A
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
b=input()
if b=="A":
    print("T")
elif b=="T":
    print("A")
elif b=="G":
    print("C")
elif b=="C":
    print("G")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=0; i<(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
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(){
    string S; cin >> S;
    ll cnt=1;
    rep(i,S.size()-1){
        if (S[i]!=S[i+1]) cnt++;
    }
    cout << cnt-1 << endl;
    return 0;
}

Measured memory_bytes: 512
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
d = Counter(S[0])
for s in S:
    c = Counter(s)
    for k, v in d.items():
        if c[k] < v:
            d[k] = c[k]
answer = []
for k, v in d.items():
    answer.extend([k] * v)
answer.sort()
print(*answer, sep='')    



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

using namespace std;
typedef long long ll;
const int maxn = 2e3 + 5;


struct Node {
    int val, pos;

    bool operator < (const Node &rhs) const {
        return val > rhs.val;
    }
} a[maxn];


ll dp[maxn][maxn], res;
// dp[i][j] 表示左边放i个右边放j个的最大值

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        a[i].val = x;
        a[i].pos = i;
    }

    sort(a + 1, a + 1 + n);

    for (int k  = 1, j; k <= n; k++) {
        for (int i = 0; i < k; i++) {
            j = k - i - 1;
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 1ll * a[k].val * (a[k].pos - (i + 1)));
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + 1ll * a[k].val * (n - j - a[k].pos));
        }
    }

    for (int i = 0; i < n; i++) res = max(res, dp[i][n - i]);
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 26492
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {

    ll N, M;
    cin >> N >> M;
    ll ac_flag[100010] = {0};
    ll wa_flag[100010] = {0};

    ll ac_count = 0;
    ll wa_count = 0;
    ll num;
    string res;
    for (int i = 0; i < M; i++) {
        cin >> num >> res;
        if (res == "AC" && ac_flag[num] == 0) {
            ac_flag[num] = 1;
            ac_count++;
            wa_count += wa_flag[num];
        }
        if (res == "WA" && ac_flag[num] == 0) {
            wa_flag[num]++;
        }
    }

    cout << ac_count << " " << wa_count << endl;

    return 0;
}


Measured memory_bytes: 1920
# print('input >>')
N, K = map(int,(input().split()))
As = []
okashi = [0] * N

for _ in range(K):
    d = input()
    As.append(list(map(int,(input().split()))))

for A in As:
    for a in A:
        okashi[a-1] += 1

ans = 0
for okashi_ in okashi:
    if okashi_ == 0:
        ans += 1

# print('-----output-----')
print(ans)

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

int main()
{
  int N, A[3][3];
  for(int i = 0; i < 3; ++i)
  {
    for(int j = 0; j < 3; ++j)
    {
      cin >> A[i][j];
    }
  }

  bool punch[3][3] = {false};
  cin >> N;
  for(int i = 0; i < N; ++i)
  {
    int a;
    cin >> a;
    for(int r = 0; r < 3; ++r)
    {
      for(int c = 0; c < 3; ++c)
      {
        if(A[r][c] == a)
        {
          punch[r][c] = true;
        }
      }
    }
  }
  
  bool bingo = false;
  for(int i = 0; i < 3; ++i)
  {
    if(punch[i][0] && punch[i][1] && punch[i][2])
    {
      bingo = true;
    }
    if(punch[0][i] && punch[1][i] && punch[2][i])
    {
      bingo = true;
    }
  }
  if((punch[0][0] && punch[1][1] && punch[2][2]) ||
     (punch[0][2] && punch[1][1] && punch[2][0]))
  {
    bingo = true;
  }
  
  if(bingo)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  
}

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

typedef long long int ll;
typedef pair<ll,ll> P;
int cc[2002];

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    for(int i=0;i<=n;i++){
        cc[i]=0;
    }
    for(int a=1;a<=n;a++){
        for(int b=a+1;b<=n;b++){
            cc[min(b-a,abs(a-x)+abs(b-y)+1)]++;
        }
    }
    for(int i=1;i<n;i++){
        cout<<cc[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n;
    cin >> n;
    vector<vector<int>> dist(n, vector<int>(n));
    rep(i,n)rep(j,n)dist[i][j] = abs(i-j);
    int l, r;
    cin >> l >> r;
    --l; --r;
    rep(i,n)rep(j,n){
        dist[i][j] = min(dist[i][j], dist[i][l] + dist[r][j] + 1);
        dist[i][j] = min(dist[i][j], dist[i][r] + dist[l][j] + 1);
    }
    vector<int> cnt(n);
    rep(i,n)rep(j,n)cnt[dist[i][j]]++;
    rep(i,n-1)cout << cnt[i+1] / 2 << endl;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	cout<<(n%2==0?n:2*n)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

//using namespace std;
using std::cin, std::cout, std::endl, std::string;
using ll = long long;

#define rep(countName, left, right, up) for (auto countName = left; countName < right; countName += up)
#define REP(countName, end) for (auto countName = 0; countName < end; countName++)
#define rev(countName, right, left, down) for (auto countName = right; countName >= left; countName -= down)
#define REV(countName, end) for (auto countName = end; countName >= 0; countName--)

auto solve1(ll a, ll b, ll n)
{
    auto min = std::min(b - 1, n);
    return ((a * min) / b) - a * (min / b);
}

int main(void)
{
    ll a, b, n;
    cin >> a >> b >> n;
    cout << solve1(a, b, n) << endl;

    return 0;
}


Measured memory_bytes: 3632
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include<time.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
struct edge {
	int to,Next;
}Edge[maxn<<1];
int Head[maxn],tot;
bool vis[maxn];
ll val[maxn],sum[maxn],sz[maxn],rev[maxn];
void Add(int from, int to) {
	Edge[tot]={to,Head[from]};
	Head[from]=tot++;
	Edge[tot]={from,Head[to]};
	Head[to]=tot++;
}
void dfs(int u, int fa) {
	sz[u]=1;
	ll num=sum[val[u]];
	ll Last=sum[val[u]];
	for (int i=Head[u]; ~i; i=Edge[i].Next) {
		int v=Edge[i].to;
		if (v==fa) continue;
		dfs(v,u);
		sz[u]+=sz[v];
		ll cnt=sz[v]-(sum[val[u]]-Last);
		rev[val[u]]+=(1+cnt)*cnt/2;
		Last=sum[val[u]];
	}
	sum[val[u]]+=sz[u]-(sum[val[u]]-num);
} 
int main(){
	memset(Head,-1,sizeof(Head));
    int n;
    scanf("%d",&n);
    for (int i=1; i<=n; i++) {
    	scanf("%lld",&val[i]);
    	vis[val[i]]=true;
	}
    for (int i=1; i<n; i++) {
    	int u,v;
    	scanf("%d%d",&u,&v);
    	Add(u,v);
	}
    dfs(1,0);
    ll Max=1ll*n*(n+1)/2;
    for (int i=1; i<=n; i++) {
    	if (sum[i]<n&&vis[i]) {
    		ll cnt=n-sum[i];
    		rev[i]+=(cnt+1)*cnt/2;
		}
	}
	for (int i=1; i<=n; i++) printf("%lld\n",vis[i]?Max-rev[i]:0ll);
    return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N; cin >> N;
	vll A(N), B(N); cin >> A >> B;

	ll sum = 0;
	ll cnt = 0;
	priority_queue<ll> dat;
	for (int i = 0; i < N; i++) {
		if (A[i] < B[i]) {
			sum += B[i]-A[i];
			cnt++;
		}
		if (A[i] > B[i]) {
			dat.push(A[i]-B[i]);
		}
	}
	while (!dat.empty() && sum > 0) {
		cnt++;
		sum -= dat.top(); dat.pop();
	}
	if (sum > 0) {
		cout << -1 << endl;
	} else {
		cout << cnt << endl;
	}
}

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


Measured memory_bytes: 5456
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
void solve();
signed main(){
#ifdef Sprinkle
   clock_t clock_start=clock();assert(freopen("test.txt","r",stdin));
#else
   ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#endif
   solve();
#ifdef Sprinkle
   cerr<<"Running Time: "<<((clock()-clock_start) *1.0 / CLOCKS_PER_SEC)<<"s\n";
#endif
}
#ifdef Sprinkle
void err(){cerr<<"\n";}template<typename T,typename...U>void err(const T&hd,const U&...tl){cerr<<hd<<(sizeof...(tl)?", ":"");err(tl...);}
#define debug(x...) cerr<<""#x" = ";err(x)
#else
#define debug(...) 0
#endif
void solve(){
    int a,b;
    cin>>a>>b;
    cout<<max(0,a-2*b)<<endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(nil, 100000000)

	n := nextFloat64()
	np := math.Ceil(n * 100 / 108)
	if n == math.Floor(np*1.08) {
		fmt.Println(np)
	} else {
		fmt.Println(":(")
	}
}


Measured memory_bytes: 1772
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
int main(){
  double N,M;
  cin>>N>>M;
  if(N>=M/2){
    cout<<setprecision(12);
    cout<<floor(M/2);
  }else{
    cout<<setprecision(12);
    cout<<floor((2*N+M)/4);
  }
  return 0;
}


Measured memory_bytes: 256
import math
import sys

N = int(input())
A = list(map(int, input().split()))

li = [0] * N
count = 0

if N % 2 == 0:
  t = 1
else:
  t = 0

for a in A:
  if a == 0:
    li[math.floor((N-1)/2)] += 1
    count += 1
    
    if count == 2:
      print(0)
      sys.exit()

    continue

  li[math.floor((N-1)/2)-math.floor(a/2)] += 1
  li[math.floor((N-1)/2)+math.floor(a/2)+t] += 1

ans = 1

for i in range(0, math.floor(N/2)):
  ans *= li[i]

print(ans % (10**9 + 7))

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

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

# 予め基準になる合計値を出しておく
sum1 = sum(tests)

for i in range(M):
    p, x = map(int, input().split())
    # 先に出しておいた基準からの差分で算出
    print(sum1 + (x - tests[p-1]))

Measured memory_bytes: 3060
// #include <boost/multiprecision/cpp_int.hpp>
// using boost::multiprecision::cpp_int;
#include <bits/stdc++.h>
using namespace std;
// ¯\_(ツ)_/¯
#define f first
#define s second
#define p push
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define foi(i, a, n) for (i = (a); i < (n); ++i)
#define foii(i, a, n) for (i = (a); i <= (n); ++i)
#define fod(i, a, n) for (i = (a); i > (n); --i)
#define fodd(i, a, n) for (i = (a); i >= (n); --i)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(v) v.begin(), v.end()
#define sz(x) ((int)(x).size())
#define endl " \n"
#define newl cout<<"\n"
#define MAXN 100005
#define MOD 1000000007LL
#define EPS 1e-13
#define INFI 1000000000             // 10^9
#define INFLL 1000000000000000000ll //10^18
// ¯\_(ツ)_/¯
#define l long int
#define d double
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define vvll vector<vll>
//vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of 10 rows and 20 columns, with value 500.
#define mii map<int, int>
#define mll map<long long, long long>
#define pii pair<int, int>
#define pll pair<long long, long long>

#define fast_io()                   \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

ll tc, n, m, k;
// ll ans = 0, c = 0;
// ll i, j;
// ll a, b;
// ll x, y;




int main()
{
    fast_io();
#ifndef ONLINE_JUDGE
    //freopen("../input.txt", "r", stdin);
    //freopen("../output.txt", "w", stdout);
#endif

    cin>>n;
    vvll act(n, vll(3, 0));
    vvll dp(n, vll(3, 0));

    rep(i, 0, n) rep(j, 0, 3) cin>>act[i][j];
    rep(i, 0, 3) dp[0][i] = act[0][i];

    rep(i, 1, n)
        rep(j, 0, 3)
            dp[i][j] = max(dp[i][j], act[i][j] + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]));

    auto it = max_element(all(dp[n-1]));
    cout<<*it;
    return 0;
}

Measured memory_bytes: 11264
//
//  main.cpp
//  atcoder-walk3
//
//  Created by r on 6/4/19.
//  Copyright © 2019 r. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

long long add(long long a, long long b) {
    a += b;
    if(a >= MOD) {
        a -= MOD;
    }
    return a;
}
long long sub(long long a, long long b) {
    a -= b;
    if(a < 0) {
        a += MOD;
    }
    return a;
}
void add_self(long long& a, long long b) {
    a = add(a, b);
}
void sub_self(long long& a, long long b) {
    a = sub(a, b);
}

long long N, K;

struct M {
    long long t[60][60];
    M operator * (M m2) {
        M res;
        memset(res.t, 0, sizeof(res.t));
        for (long long i = 0; i<N; i++) {
            for (long long j = 0; j<N; j++) {
                for (long long k = 0; k<N; k++) {
                    add_self(res.t[i][j], (t[i][k]*m2.t[k][j])%MOD);
                }
            }
        }
        return res;
    }
};


M m;

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    for (long long i = 0; i<N; i++) {
        for (long long j = 0; j<N; j++) {
            cin >> m.t[i][j];
        }
    }
    M ans;
    memset(ans.t, 0, sizeof(ans.t));
    for (long long i = 0; i<N; i++) {
        ans.t[i][i] = 1;
    }
    for (long long i = 0; i<60; i++) {
        if (K & (1LL << i)) {
            ans = ans*m;
        }
        m = m*m;
    }
    long long res = 0;
    for (long long i = 0; i<N; i++) {
        for (long long j = 0; j<N; j++) {
            add_self(res, ans.t[i][j]);
        }
    }
    cout << res << endl;
    return 0;
}





Measured memory_bytes: 384