akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;


int main() {

	ll N;
	cin >> N;
	vector<ll> P(N), Q(N);
	for (int i = 0; i < N; ++i) { cin >> P[i]; --P[i]; }
	for (int i = 0; i < N; ++i) Q[P[i]] = i;

	ll ans = 0, val = 0;
	ll prev = -1;
	for (int i = 0; i < N; ++i) {
		if (prev < Q[i]) ans = max(ans, ++val);
		else val = 1;
		prev = Q[i];
	}

	cout << N - ans << endl;
}

Measured memory_bytes: 3328
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

// 1. dp?????????
// dp[??????]?????\?????????
int dp[1001][1001];
// 2. n?????????
int N,M;
int D[1001];
int C[1001];
// 7. calc?????????
int calc(int k,int p){
	// 8. dp???????????°??????
	if(dp[k][p]>=0)return dp[k][p];
	// 9. dp????¨????

	if(k==p){
		dp[k][p]=calc(k-1,p-1)+D[k]*C[p];
	}else{
		dp[k][p]=min(calc(k,p-1),calc(k-1,p-1)+D[k]*C[p]);
	}

	return dp[k][p];
}
int main() {
	cin>>N>>M;

	//3.?????????
	for(int i=1;i<1001;i++){
		for(int j=1;j<1001;j++){
			dp[i][j]=-1;
		}
	}
	//4.??\???
	for(int i=1;i<N+1;i++){
		cin>>D[i];
	}
	for(int j=1;j<M+1;j++){
		cin>>C[j];
	}

	//5.???????????¨???

	for(int j=1;j<M+1;j++){
		dp[0][j]=0;
	}
	//6.??????
	cout<<calc(N,M)<<endl;

	return 0;
}

Measured memory_bytes: 7024
object Main extends App {
  import java.util.Arrays
  val p = new java.io.PrintWriter(System.out)

  val n = MyPredef.nextInt
  val X = Array.fill(n)(MyPredef.nextInt)
  val Xs = X.clone()
  Arrays.sort(Xs)
  val halfB = Xs(n / 2 - 1) // before
  val halfA = Xs(n / 2) // after

  MyPredef.rep(n, i => {
    if (X(i) <= halfB) {
      p.println(halfA)
    } else {
      p.println(halfB)
    }
  })
  p.flush()
}


object MyPredef {
  @inline def rep(n: Int, f: => Unit): Unit = { var c = 0; while (c < n) { f; c += 1 } }
  @inline def rep(n: Int, f: Int => Unit): Unit = { var c = 0; while (c < n) { f(c); c += 1 } }

  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}


Measured memory_bytes: 41220
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K,*A = map(int,read().split())

dp = [0]*(K+1) # bitset
for n in range(K):
    if not dp[n]:
        for a in A:
            if n+a>K:
                break
            dp[n+a]=1

answer = 'First' if dp[-1] else 'Second'
print(answer)

Measured memory_bytes: 3828
import java.util.*;
import java.lang.*;
import java.io.*;
 
class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        String u, nl = System.getProperty("line.separator");
        StringBuilder
            p = new StringBuilder(1000),
            d = (new StringBuilder(100)).append('.'),
            s = (new StringBuilder(100)).append('#'),
            k = (new StringBuilder(100)).append('#');
        Scanner r = new Scanner(System.in);
        d.append(d.append(d)).append(d.append(d));
        s.append(s.append(s)).append(s.append(s));
        int h, w, ww = d.length();
        while (0 != ((h = r.nextInt()) | (w = r.nextInt()))) {
            while (w > ww) {
                d.append(d);
                s.append(s);
                ww = d.length();
            }
            p.append(u = s.substring(0, w)).append(nl);
            k.setLength(1);
            k.append(d.substring(2, w)).append('#').append(nl);
            while (2 != h--) {
                p.append(k);
            }
            p.append(u).append(nl).append(nl);
        }
        System.out.print(p);
    }
}

Measured memory_bytes: 18376
#include <iostream>

using namespace std;

int a, b, c, d, ta, ao, q;

int main()
{
  cin >> a >> b >> c >> d;
  if ((a + d - 1) / d >= (c + b - 1) / b)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


Measured memory_bytes: 3592
import java.io.IOException;
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
//import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        while (sc.hasNext()){
            list.add(sc.nextInt());
        }
        for (int i = n - 1; i > 0; i--){
            System.out.print(list.get(i)+" ");
            System.out.flush();
        }
        System.out.println(list.get(0));
    }
}

Measured memory_bytes: 19680
// https://cf17-final.contest.atcoder.jp/tasks/cf17_final_d
#include<iostream>
#include<vector>
#include<algorithm>


int main(){
	std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
	int nPlayer;std::cin>>nPlayer;
	struct player{int height,power;};
	std::vector<player> players(nPlayer);
	for(player& p:players)std::cin>>p.height>>p.power;

	std::sort(players.begin(),players.end(),[](player a,player b){
		return a.height+a.power<b.height+b.power;
	});
	std::vector<long long> minHeight(nPlayer+1,1e18);
	minHeight[0]=0;
	for(player p:players){
		auto it=std::upper_bound(minHeight.begin(),minHeight.end(),p.height);
		while(it!=minHeight.begin()){
			*it=std::min(*it,p.power+*std::prev(it));
			--it;
		}
	}
	std::cout<<std::lower_bound(minHeight.begin(),minHeight.end(),1e18)-minHeight.begin()-1<<'\n';
}

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

int gcd(long long a, long long b){
  long long M = max(a, b), m = min(a, b);
  while(m != 0){
  	long long r = M%m;
    M = m; m = r;
  }
  return M;
}

int digit_sum(long long n){
  long long ans;
  while(n != 0){
  	ans += n%10;
  	n /= 10;
  }
  return ans;
}

int main(){
  int n;
  cin >> n;
  
  cout << (long long)n*(n-1)/2 << endl;
}

Measured memory_bytes: 256
import math

n=int(input())

# create a list of 2 ... n
primes = list(range(2, 2000))
root_n = int(2000 ** (1/2)) + 1
# check each of numbers
i = j = 0
for p, q in enumerate(primes):
    if q >= root_n:
        break
    elif q:
        for r in range(p + q, 2000 - 2, q):
            if primes[r]:
                primes[r] = 0
result = [str(2)]
Plist = [primes[x] for x in range(len(primes)) if primes[x] > 0 and primes[x]%5 == 1]
for i in range(n-1):
    result.append(str(Plist[i]))
print(' '.join(result))

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

// #define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
// template<typename T> void view(T e){std::cout << e << std::endl;}
// template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
// template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

// from graph/types.cpp
template<typename T>
using Matrix = vector<vector<T>>;

// from graph/graph_factory.cpp
template<typename T>
struct MatrixFactory {
    MatrixFactory(int n, bool directed = true) : n(n), directed(directed) {
        g.resize(n, vector<T>(n, numeric_limits<T>::max()));
        for (int i = 0; i < n; ++i) g[i][i] = 0;
    }
    // from and to are 0-indexed.
    void add_edge(int from, int to, T cost = 1) {
        g[from][to] = cost;
        if (!directed) g[to][from] = cost;
    }
    Matrix<T> build() {
        return g;
    }
private:
    int n;
    bool directed;
    Matrix<T> g;
};


template<typename T>
struct WarshallFloyd {
    WarshallFloyd(const Matrix<T> &g) : n(g.size()), g(g), dp(g) {
        for (int k = 0; k < n; ++k) {
            for (int i = 0; i < n; ++i) {
                for (int j = 0; j < n; ++j) {
                    if (dp[i][k] == inf() || dp[k][j] == inf()) continue;
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                }
            }
        }
    }
    bool has_negative_cycle() {
        for (int i = 0; i < n; ++i) if (dp[i][i] < 0) return true;
        return false;
    }
    T shortest_path_value(int s, int t) {
        return dp[s][t];
    }
    bool is_unreachable(int s, int t) {
        return dp[s][t] == inf();
    }
    vector<int> shortest_path(int s, int t) {
        vector<int> res;
        if (is_unreachable(s, t)) return res;
        res.push_back(s);
        int cur = s;
        int cnt = 0;
        while (cur != t && cnt < n) {
            for (int i = 0; i < n; ++i) {
                if (i != cur && g[cur][i] + dp[i][t] == dp[cur][t]) {
                    cur = i;
                    res.push_back(i);
                    break;
                }
            }
            ++cnt;
        }
        return res;
    }
private:
    int n;
    Matrix<T> g, dp;
    T inf() {
        return numeric_limits<T>::max();
    }
};

/*
    verified
    https://atcoder.jp/contests/atc001/tasks/unionfind_a
*/
int main() {
    int v, e; cin >> v >> e;
    MatrixFactory<int> mf(v);
    for (int i = 0; i < e; ++i) {
        int s, t, d; cin >> s >> t >> d;
        mf.add_edge(s, t, d);
    }
    WarshallFloyd<int> wf(mf.build());
    if (wf.has_negative_cycle()) {
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }
    for (int i = 0; i < v; ++i) {
        for (int j = 0; j < v; ++j) {
            if (j != 0) cout << " ";
            if (wf.is_unreachable(i, j)) cout << "INF";
            else cout << wf.shortest_path_value(i, j);
            // cout << endl;
            // debug(wf.shortest_path(i, j));
        }
        cout << endl;
    }
}



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

int main() {
    int64_t H,W;
    cin >> H >> W;
    if((H==1) || (W==1)){
        cout << 1 << endl;
    } else if ((H%2==1) &&(W%2==1)){
        cout << H*W/2 + 1 << endl;
    }else{
        cout << H*W/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
#define watch(x) cout << (#x)<<" = "<<x<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}


int main() {
	file();
	fast();
	int n; cin >> n;
	cout << ((n + 1000 - 1) / 1000) * 1000 - n << endl;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main (){
    int a;
    int b;
    int c;
    cin>>a>>b>>c;
    if(a < b && b < c){
        cout<< "Yes" <<endl;
    }
    else{
        cout<< "No" <<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef pair<ll,ll> P;
#define se second
#define fi first
struct PP{ll fi;ll se;ll th;};
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[0].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
  ll n,k;cin>>n>>k;
  vi v(n);
  rep(i,n){
    cin>>v[i];
    v[i]--;
  }
  v[0]%=k;
  vector<P> x(n);
  x[0]=P(v[0]%k,(ll)(1));
  REP(i,1,n){
    x[i].fi=v[i]+x[i-1].fi;
    x[i].fi%=k;
    x[i].se=i+1;
  }
  x.eb(0,0);
  sort(all(x));
  ll ans=0;
  int w=0;
  while(w<n){
    vi d;
    d.pb(x[w].se);
    while(w<n){
      if(x[w+1].fi==x[w].fi)d.pb(x[w+1].se);
      else break;
      w++;
    }
    int m=d.size();
    sort(all(d));
    rep(l,m){
        int r=lb(d,d[l]+k)-1;
        ans+=r-l;
    }
    w++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 10112
#include <iostream>

using namespace std;
using ll = long long;

ll a[3010];
pair<ll, ll> dp[3010][3010];
bool visited[3010][3010];

pair<ll, ll> sim(int l, int r) {
    if (r < l) return make_pair(0, 0);
    if (visited[l][r]) return dp[l][r];

    visited[l][r] = true;

    pair<ll, ll> lres = sim(l + 1, r);
    swap(lres.first, lres.second);
    lres.first += a[l];

    dp[l][r] = lres;

    pair<ll, ll> rres = sim(l, r - 1);
    swap(rres.first, rres.second);
    rres.first += a[r];

    if (lres.first - lres.second < rres.first - rres.second) {
        dp[l][r] = rres;
    }

    return dp[l][r];
}

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

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

    pair<ll, ll> res = sim(0, N - 1);
    cout << res.first - res.second << endl;
    return 0;
}


Measured memory_bytes: 150016
n = int(input())
a = list(map(int,input().split()))
dic_S = {0:[0]}
S = 0
ans = 0
for i in range(n):
    S += a[i]
    if S not in dic_S:
        dic_S[S] = []
    else:
        pass
    dic_S[S].append(a[i])
    

for k in dic_S.keys():
    I = len(dic_S[k])
    if 3 <= I:
        ans += (I*(I-1))// 2
    elif I == 2:
        ans += 1
    else:
        pass
print(ans)


Measured memory_bytes: 54780
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()


bool pC(const P & a, const P & b) {
	return a.second > b.second;
}
int main() {
	int n;
	cin >> n;
	vector<P> r(n);
	vector<P> b(n);
	rep(i, n)cin >> r[i].first >> r[i].second;
	rep(i, n)cin >> b[i].first >> b[i].second;
	sort(r.begin(), r.end(),pC);
	sort(b.begin(), b.end());
	vector<bool> used(n, false);
	int ans=0;
	rep(i, n) {
		rep(j, n) {
			if (!used[j]&&b[i].first > r[j].first&& b[i].second > r[j].second) {
				ans++;
				used[j] = true;
				//cout << b[i].first << " " << b[i].second << endl;
				//cout << r[j].first << " " << r[j].second << endl;
				//cout << endl;
				break;
			}
		}
	}
	cout << ans << endl;
}



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

int main(){
    int W, H;
    int x, y, r;
    cin >> W >> H >> x >> y >> r;
    if (x - r < 0 || x + r > W){
        cout << "No" << endl;
    }
    else if (y - r < 0 || y + r > H){
        cout << "No" << endl;
    }
    else if (x - r >= 0 || x + r <= W){
        cout << "Yes" <<endl;
    }
    else if (y - r >= 0 || y + r <= H){
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 3128
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstdio>
#define lson (k<<1)
#define rson ((k<<1)|1)
#define mid ((l+r)>>1)
using namespace std;
int n,tot,ans,cnt,top,kuai,maxx,minn,v1,v2,js;
const int N=1000010,inf=0x3f3f3f3f;
int dfn[N],low[N],zhan[N],c[N],head[N],pos[N];
bool vis[N];
struct bian
{
	int to,nt;
}e[N<<1];
struct rec
{
	int v,p;
	rec(){}
	rec(int a,int b)
	{
		v=a;p=b;
	}
	friend bool operator <(const rec &x,const rec &y)
	{
		return x.v<y.v;
	}
}z[N];
inline int read()
{
    int res=0;char ch=getchar();bool XX=false;
    for(;!isdigit(ch);ch=getchar())(ch=='-') && (XX=true);
    for(;isdigit(ch);ch=getchar())res=(res<<3)+(res<<1)+(ch^48);
    return XX?-res:res;
}
void add(int f,int t)
{
	e[++tot].to=t;
	e[tot].nt=head[f];
	head[f]=tot;
}
void tarjan(int x)
{
	dfn[x]=low[x]=++cnt;
	zhan[++top]=x;vis[x]=1;
	for(int i=head[x];i;i=e[i].nt)
	{
		if(!dfn[e[i].to])
		{
			tarjan(e[i].to);
			low[x]=min(low[x],low[e[i].to]);
		}
		else if(vis[e[i].to])low[x]=min(low[x],dfn[e[i].to]);
	}
	if(low[x]==dfn[x])
	{
		int k;++kuai;
		do
		{
			k=zhan[top--];
			vis[k]=0;
			c[k]=kuai;
		}while(k!=x);
	}
}
void build(int k,int l,int r)
{
	if(l==r)
	{
		add(k+(n<<1),z[l].p<=n?z[l].p+n:z[l].p-n);
		return;
	}
	build(lson,l,mid);
	build(rson,mid+1,r);
	add(k+(n<<1),lson+(n<<1));
	add(k+(n<<1),rson+(n<<1));
}
void Insert(int k,int l,int r,int x,int y,int p)
{
	if(x<=l&&r<=y)
	{
		add(p,k+(n<<1));
		return;
	}
	if(x<=mid)Insert(lson,l,mid,x,y,p);
	if(mid+1<=y)Insert(rson,mid+1,r,x,y,p);
}
bool check(int k)
{
	memset(dfn,0,sizeof(dfn));
	memset(head,0,sizeof(head));
	top=tot=kuai=0;
	build(1,1,n<<1);
	int l=1,r=1;
	for(int i=1;i<=(n<<1);++i)
	{
		int op,p=z[i].p;
		if(p<=n)op=pos[p+n];
		else op=pos[p-n];
		while(r<=i&&z[r].v<=z[i].v-k)r++;
		if(r<i&&r>=1&&z[r].v>z[i].v-k)
		{
			if(op>=r&&op<=i-1)
			{
				if(op>r)Insert(1,1,n<<1,r,op-1,z[i].p);
				if(op<i-1)Insert(1,1,n<<1,op+1,i-1,z[i].p);
			}
			else Insert(1,1,n<<1,r,i-1,z[i].p);	
		}
		while(l<=(n<<1)&&z[l].v<z[i].v+k)++l;
		--l;
		if(l>i&&l<=(n<<1)&&z[l].v<z[i].v+k)
		{
			if(op>=i+1&&op<=l)
			{
				if(op>i+1)Insert(1,1,n<<1,i+1,op-1,z[i].p);
				if(op<l)Insert(1,1,n<<1,op+1,l,z[i].p);
			}
			else Insert(1,1,n<<1,i+1,l,z[i].p);
		}
	}
	for(int i=1;i<=(n<<1);++i)
		if(!dfn[i])tarjan(i);
	for(int i=1;i<=n;++i)
	{
		if(c[i]==c[i+n])return 0;
	}
		
	return 1;
}
int main()
{
	/*freopen("disaster.in","r",stdin);
	freopen("disaster.out","w",stdout);*/
	cin>>n;
	maxx=-inf;minn=inf;
	for(int i=1;i<=n;++i)
	{
		v1=read();v2=read();
		z[++js]=rec(v1,i);
		z[++js]=rec(v2,i+n);
		maxx=max(maxx,max(v1,v2));
		minn=min(minn,min(v1,v2));
	}
	if(maxx-minn+1<n)
	{
		cout<<"0";
		return 0;
	}
	sort(z+1,z+1+(n<<1));
	for(int i=1;i<=(n<<1);++i)pos[z[i].p]=i;
	int l=0,r=1000000001;
	while(l+1<r)
	{
		if(check(mid))l=mid;
		else r=mid;
	}
	cout<<l;
	fclose(stdin);fclose(stdout);
	return 0;
}
/*
3
1 2 3 4 5 6
*/


Measured memory_bytes: 29696
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Stack;

class sushi {
	public int t;
	public long d;

	public sushi(int t, long d) {
		this.t = t;
		this.d = d;
	}

	public long getD() {
		return this.d;
	}
}

public class Main {

	static Scanner sc = new Scanner(System.in);
	static Stack st = new Stack();
	static int N = sc.nextInt();
	static int K = sc.nextInt();
	static sushi[] S = new sushi[N];
	static boolean[] used = new boolean[N + 1];
	static long sum_t = 0;
	static long sum_d = 0;
	static long ans = 0;

	public static void main(String[] args) {
		for(int i = 0; i < N; i++) {
			int t = sc.nextInt();
			long d = sc.nextLong();
			sushi su = new sushi(t, d);
			S[i] = su;
		}

		Arrays.sort(S, Comparator.comparing(sushi::getD).reversed());

		for(int i = 0; i < K; i++) {
			if(used[S[i].t]) {
				st.push(S[i].d);
			} else {
				used[S[i].t] = true;
				sum_t++;
			}
			sum_d += S[i].d;
		}
		ans = sum_d + sum_t * sum_t;

		for(int i = K; i < N; i++) {
			if(st.empty())
				break;
			if(used[S[i].t])
				continue;
			used[S[i].t] = true;
			sum_t++;
			sum_d += S[i].d - (long) st.pop();
			ans = Math.max(ans, sum_d + sum_t * sum_t);
		}

		System.out.println(ans);
	}
}

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

int main(){
    int N, M, Q;
    int p[100000], q[100000];
    int lrcount[501][501] = {};
    int s[501][501] = {};
    cin >> N >> M >> Q;
    for(int i = 0; i < M; i++){
        int L, R;
        scanf("%d %d", &L, &R);
        lrcount[L][R]++;
    }
    for(int i = 0; i < Q; i++){
        scanf("%d %d", &p[i], &q[i]);
    }
    for(int l = 0; l <= 500; l++){
        s[l][l] = lrcount[l][l];
        for (int r = l+1; r <= 500; r++){
            s[l][r] = s[l][r-1] + lrcount[l][r];
        }
    }
    for(int i = 0; i < Q; i++){
        int ans = 0;
        for(int l = p[i]; l <= q[i]; l++){
            ans += s[l][q[i]] - s[l][p[i]-1];
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3712
# -*- coding: utf-8 -*-
# 標準入力を取得
m, n = list(map(int, input().split()))

# 求解処理
def modpow(a: int, b: int, mod: int) -> int:
    ans = 1
    while b > 0:
        if (b & 1):
            ans = ans * a % mod
        a = a * a % mod
        b >>= 1
    return ans

ans = modpow(m, n, 1000000007)

# 結果出力
print(ans)


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

int main(){
  int N, L[10];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> L[i];
  
  int max = 0;
  int sum = 0;
  for (int i = 0; i < N; i++)
  {
    sum += L[i];
    if (max < L[i]) max = L[i];
  }
  sum -= max;
  
  if (max < sum) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
using namespace std;
long long a,h,i,x,s,v[200001];
int main()
{
    cin>>h>>a;
    for(i=1;i<=h;i++)
    {
        cin>>v[i];
    }
    sort(v,v+h+1);
    for(i=1;i<=h-a;i++)
    {
        s=s+v[i];
    }
    cout<<s;
    return 0;
}


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

using namespace std;

const int N = 1e5+5;

long long x;

int main(){
    scanf("%lld" , &x);
    long long ansA = 1e18;
    long long ansB = -1;
    for(long long i = -1000; i <= 1000; i++){
        for(long long j = -1000; j <= 1000; j++){
            if(i*i*i*i*i - j*j*j*j*j == x ){
                ansA = i;
                ansB = j;
                break;
            }
        }
        if(ansA != 1e18)
            break;
    }
    assert(ansA != 1e18);
    printf("%lld %lld\n" , ansA , ansB);
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define umapi unordered_map<ll, ll>
#define umapc unordered_map<char, int>
#define endl "\n"
using namespace std;
 
 
void solve()
{
    int k;
    cin >> k;
    int a[1000001];
    a[1] = 7 % k;
 
    for(int i = 2; i <= k; i++) {
        a[i] = (a[i - 1] * 10 + 7) % k;
    }
 
    for(int i = 1; i <= k; i++) {
        if(a[i] == 0) {
            cout << i << endl;
            return ;
        }
    }
 
    cout << -1 << endl;
    return ;
    
}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
  //  cin >> t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 7556
import sys

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


def main():
    D, T, S = map(int, readline().split())

    if D <= S * T:
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 61944
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
#include<set>
#include<vector>
using namespace std;
int main(){

    int n,t;
    cin>>n>>t;
    vector<pair<int,int>> v;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        v.push_back(make_pair(a,b));
    }
    int mi=1e9;
    for(int i=0;i<n;i++){
        if(v[i].second<=t){
            mi=min(mi,v[i].first);
        }
    }
    if(mi==1e9){
        cout<<"TLE"<<endl;
    }else{
        cout<<mi<<endl;
    }




return 0;
}



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

int main() {

  int N;
  cin >> N;

  vector<int64_t> L(N+1);
  L.at(0) = 2;
  L.at(1) = 1;
  for (int i = 2; i <= N; i++) {
      L.at(i) = L.at(i-2) + L.at(i-1);
  }

  cout << L.at(N) << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
 
using namespace std;
int main()
{
    long long a,b;
    int c;
    cin >> a >> b >> c;
    long long d = c-a-b;
    
    if(d>0 && d*d > 4*a*b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int MAX = 200010;
class shuturyoku_unko {
public:
	char C[MAX * 7 + 10];
	int K[MAX + 10];
	constexpr shuturyoku_unko() : C(), K() {
		auto di = C + 1;
		C[0] = '0';
		K[0] = 0;
		K[1] = 1;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			*di++ = '\n';
			K[i + 1] = K[i] + keta + 1;
		}
	}
} f;
const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(int X) {
	for (int i = f.K[X]; i < f.K[X + 1]; i++)* di++ = f.C[i];
}

int A[200001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N, K, C;
	scanf("%d %d %d ", &N, &K, &C);

	if (N == K) {
		fwrite(f.C + 1, 1, f.K[N + 1] - f.K[1], stdout);
		return 0;
	}

	char S[200010];
	fread(S, 1, N, stdin);

	int kari = K;
	for (int i = N - 1; i >= 0; i--) {
		if (S[i] == 'o') {
			A[i] = kari--;
			i -= C;
		}
	}
	kari = 1;
	rep(i, N) {
		if (S[i] == 'o') {
			if (A[i] == kari++) putint(i + 1);
			i += C;
		}
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstring>
#include<queue>
#include<tuple>
#include<utility>
#include<map>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll X,K,D;	cin>>X>>K>>D;
	ll M,P,c = abs(X)/D;
	if(K<c){
		if(X>=0) cout<<abs(X-K*D)<<endl;
		else	cout<<abs(X+K*D)<<endl;
		return 0;
	}
	if(X>=0){
		P=X-c*D;
		M=P-D;
		if((K-c)%2)	cout<<abs(M)<<endl;
		else cout<<abs(P)<<endl;
	}else{
		M=X+c*D;
		P=M+D;
		if((K-c)%2)	cout<<abs(P)<<endl;
		else cout<<abs(M)<<endl;
	}





    return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, Q, W, H, T, X, Y, S;

int main()
{
    cin >> N;
    vector<int> times(N);
    for (auto& t : times) {
        cin >> t;
    }

    cin >> M;
    vector<int> out;
    for (int i = 0; i < M; ++i) {
        int x, p;
        cin >> x >> p;
        int sum = 0;
        for (int i = 0; i < N; ++i)
            if (i+1 == x)
                sum += p;
            else
                sum += times[i];
        out.push_back(sum);
    }
    for (auto s : out)
        cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N,A,B;cin>>N>>A>>B;
    cout<<min(N*A,B)<<"\n";
}

Measured memory_bytes: 256
n = int(input())

dices = []

successive_cnt = 0

for i in range(n):
    d, e = [int(x) for x in input().split(' ')]

    if d == e:
        successive_cnt += 1
    else:
        successive_cnt = 0

    if successive_cnt == 3:
        break

if successive_cnt == 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9184
#!/usr/bin/env python
import sys
import re
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor
sys.setrecursionlimit(1000000)


def main():
    #N, M = map(int, input().split())
    N, K = map(int, input().split())
    ps = list(map(int, input().split()))

    ps = sorted(ps)

    print(sum(ps[:K]))


if __name__ == '__main__':
    main()


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

int main() {
    int N,Q; cin >> N >> Q;
    string S; cin >> S;
    int a[100010]; int b[100010];
    int AC[100010]; int ans=0;
    rep(i,N){
        if(i==0);
        else{
            if(S[i-1]=='A' && S[i]=='C'){
                ans++;
            }
        }
        AC[i]=ans;
    }
    rep(i,Q){
        cin >> a[i] >> b[i];
    }
    rep(i,Q){ 
        cout << AC[b[i]-1]-AC[a[i]-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 2176
n = gets.strip.to_i
a = n.times.map { gets.strip }

correct = 'Yes'
if a.uniq.size == n
  last_word = a[0][0]
  a.each do |s|
    unless last_word.eql?(s[0])
      correct = 'No'
      break
    end
    last_word = s[-1]
  end
else
  correct = 'No'
end

puts correct


Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(false)
#define For(i, x, y) for(int i = x; i <= y; i++)
#define For_(i, x, y) for(int i = x; i >= y; i--)
const int inf = 0x3f3f3f3f;
const ll Inf = 1e18;

string ss;

int main(void)
{
	cin >> ss;
	if (ss[2] == ss[3] && ss[4] == ss[5]) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int l, r;
    for (l = 0; l < s.size(); l++) {
        if (s[l] == 'A') break;
    }
    for (r = s.size() - 1; r > 0; r--) {
        if (s[r] == 'Z') break;
    }
    cout << r - l + 1 << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 500050
#define M 200020
int mx = 0, n, m, b[N], ans[N], tree[N << 1], last[N], h[N << 1];
struct node { int x, y, num; }a[M];
bool cmp(node x, node y) { return x.y < y.y || (x.y == y.y && x.x < y.x); }
void insert(int x, int y) { for (; x <= n; x += x & -x) tree[x] += y; }
int query(int x) {
    int y = 0; for (; x; x -= x & -x) y += tree[x];
    return y;
}
int main() {
    scanf("%d", &n); scanf("%d", &m);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]), last[i] = h[b[i]], h[b[i]] = i, mx = max(mx, b[i]);
    int q = sqrt(n);
    for (int i = 1; i <= m; i++) scanf("%d%d", &a[i].x, &a[i].y), a[i].num = i;
    sort(a + 1, a + m + 1, cmp); int tmp = 0;
    for (int i = 1; i <= m; i++) {
        while (tmp < a[i].y) {
            tmp++; if (last[tmp]) insert(last[tmp], -1);
            insert(tmp, 1);
        }ans[a[i].num] = query(tmp) - query(a[i].x - 1);
    }for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
    return 0;
}

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

typedef long long int llint;

llint lucas(int n){
	static map<int,llint> memo;
	if(memo.count(n)==0){
		if(n==0){
			memo[n]=2;
		}else if(n==1){
			memo[n]=1;
		}else{
			memo[n]=lucas(n-1)+lucas(n-2);
		}
	}
	return memo[n];
}

int main(){
	int N;
	cin >> N;
	cout << lucas(N) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d",&a,&b);
	c=a+b;
	if (a%3==0)
	{
		printf("Possible\n");
	}else if (b%3==0)
	{
		printf("Possible\n");
	}else if (c%3==0)
	{
		printf("Possible\n");
	}else
	{
		printf("Impossible\n");
	}

}

Measured memory_bytes: 128
#include <cstdio>

bool vt[1000010];
int k, a = 7, ans = 1;

int main() {
    scanf("%d", &k);
    while (!vt[a %= k]) {
        if (!a) {
            printf("%d", ans);
            return 0;
        }
        vt[a] = true;
        a = a * 10 + 7, ans++;
    }
    printf("-1");
}


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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){
    int A,B,C,K,count=0;

    cin>>A>>B>>C>>K;

    while(A>=B){
        B=B*2;
        count++;
    }
    while(B>=C){
        C=C*2;
        count++;
    }

    if(K >= count){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }


    return 0;
}



Measured memory_bytes: 3636
N = int(input())
dic, rst = {}, []
for i in range(N):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
max_val = max(dic.values())
rst = [ key for key, val in dic.items() if val == max_val ]
[ print(i) for i in sorted(rst) ]

Measured memory_bytes: 36388
#include<bits/stdc++.h>
#define speed_up ios_base::sync_with_stdio(false); cin.tie(NULL)
#define ll long long
#define ara(A,N) sort(A,A+N)
#define rev(A,N) sort(A,A+N,greater<long long>())
using namespace std;
int main()
{
  speed_up;
  ll n, m, i, j, k, x;
  ll M = 1e9 + 7;

    cin >> n;
    map<ll, ll> a;
    for(k = 2; k <= n; ++k)
    {
        ll cnt = 0;
        ll num = k;
        while(num % 2 == 0) {
            ++cnt;
            num /= 2;
        }
        if(cnt) a[2] += cnt;
        for(i = 3; sqrt(i) <= num; i += 2) {
            if(num % i == 0) {
                cnt = 0;
                while(num % i == 0) {
                    ++cnt;
                    num /= i;
                }
                a[i] += cnt;
            }
        }
        if(num > 1) a[num]++;
    }

    ll tot = 1;
    for(auto t : a)
    {
        tot *= (t.second + 1);
        tot %= M;
    }
    cout << tot << endl;




return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
int main() {
	char str;
	int n[3]={},ans=0,x;
	while(cin>>str){
		if(str=='J'&&n[1]==0&&n[2]==0)n[0]++;
		else if(str=='O'&&n[1]<n[0]&&n[2]==0)n[1]++;
		else if(str=='I'&&n[2]<min(n[0],n[1])){
			n[2]++;
			if(n[2]==min(n[0],n[1]))ans=max(ans,min(n[0],n[1]));
		}
		else if(n[0]>0){
			for(int i=0;i<3;i++)n[i]=0;
			if(str=='J')n[0]=1;
		}
	}
	cout<<ans<<endl;
}

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

#define endl '\n'

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

    string s;
    cin >> s;
    for(char c : s) {
        if(c == '9') {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 文字列の入力
		String[] sList = sc.next().split("");
        int ans = 0;
        for(String s : sList) {
          if (s.equals("2")) {
            ans++;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;




int main(){
  string sa,sb;
  int n;
  cin >> n;
  cin >> sa;
  cin >> sb;
  ll sum = 0;
  int p = 0;
  REP(i,sa.size()){
    if(i == 0){
      if(sa[i] == sb[i]){
	sum = 3;
	p = 1;
      }
      else{
	sum = 6;
	i++;
	p = -1;
      }
    }
    else{
      if(sa[i] == sb[i]){
	if(p == -1){
	  
	}
	else{
	  sum *= 2;
	  sum = sum%1000000007;
	}
	p = 1;
      }
      else{
	if(p == -1){
	  sum *= 3;
	  sum = sum%1000000007;
	}
	else{
	  
	  sum *= 2;
	  sum = sum%1000000007;
	}
	p = -1;
	i++;
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
while 1:
    b, r, g, c, s, t = map(int, input().split())
    if t == 0:
        break
    ans = 100

    ans += (15 - 2) * (5*b) + (15 - 3) * b
    t -= 6*b

    ans += (15 - 2) * (3*r) + (15 - 3) * r
    t -= 4*r

    ans += (7 - 3) * g
    t -= g

    ans += (2 - 3) * c
    t -= c

    t -= s

    ans += (0 - 3) * t

    print(ans)


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

typedef long long ll;
const int maxn = 1e4 + 10;

int n, a[maxn], b[maxn];

bool solve() {
    ll opA = 0;
    ll opB = 0;
    for(int i = 1; i <= n; ++i)
	if(a[i] < b[i]) {
	    ll d = b[i] - a[i];
	    opA += d / 2;
	    if(d % 2) ++opA, ++opB;
	}
	else
	    if(a[i] > b[i]) opB += a[i] - b[i];
    if(opA < opB) return false;
    return true;
}

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for(int i = 1; i <= n; ++i) scanf("%d", &b[i]);
    if(solve()) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;


int main(){
    int n;  cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    vector<ll> s(n, 0);
    s[0] = a[0];   s[1] = a[1];
    for(int i = 2; i < n; i++){
        s[i] += s[i-2] + a[i];
    }

    if(n % 2 == 0){
        vector<vector<ll>> dp(n, vector<ll>(2, LONG_LONG_MIN / 3));
        dp[0][0] = a[0];
        dp[1][1] = a[1];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 2; j++){
                if(j == 0){
                    if(i + 2 < n) dp[i+2][0] = max(dp[i+2][0], dp[i][j] + a[i+2]);
                    if(i + 3 < n) dp[i+3][1] = max(dp[i+3][1], dp[i][j] + a[i+3]);
                }
                if(j == 1){
                    if(i + 2 < n) dp[i+2][1] = max(dp[i+2][1], dp[i][j] + a[i+2]);
                }
            }
        }

        cout << max(dp[n-2][0], dp[n-1][1]) << endl;
        return 0;
    }

    vector<vector<ll>> dp(n, vector<ll>(3, LONG_LONG_MIN / 3));
    dp[0][0] = a[0];
    dp[1][1] = a[1];
    dp[2][2] = a[2];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(j == 0){
                if(i + 2 < n) dp[i+2][0] = max(dp[i+2][0], dp[i][j] + a[i+2]);
                if(i + 3 < n) dp[i+3][1] = max(dp[i+3][1], dp[i][j] + a[i+3]);
                if(i + 4 < n) dp[i+4][2] = max(dp[i+4][2], dp[i][j] + a[i+4]);
            }
            if(j == 1){
                if(i + 2 < n) dp[i+2][1] = max(dp[i+2][1], dp[i][j] + a[i+2]);
                if(i + 3 < n) dp[i+3][2] = max(dp[i+3][2], dp[i][j] + a[i+3]);
            }
            if(j == 2){
                if(i + 2 < n)   dp[i+2][2] = max(dp[i+2][2], dp[i][j] + a[i+2]);
            }
        }
    }

    cout << max(dp[n-3][0], max(dp[n-2][1], dp[n-1][2])) << endl;


    return 0;
}


Measured memory_bytes: 17252
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;


int main()
{
	int n,k;
	string s;
	ll ans=0;
	cin>>n>>k;
	cin>>s;
	s[k-1]-=('A'-'a');
	cout<<s<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

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

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    ll n;

	cin >> n;

	if (n % 2 == 0) Out(n);
	else Out(n * 2);
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        for(int i=0;i<10;i++){
            if(s.replaceAll(Integer.toString(i)+Integer.toString(i), "").length()!=4){
                System.out.println("Bad");
                return;
            }
        }
        System.out.println("Good");

    }


}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        if(b - a == c - b){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}


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

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

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

  set<int> q;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;

    if (q.count(x) > 0) {
      q.erase(x);
    }
    else {
      q.insert(x);
    }
  }

  cout << q.size() << endl;

  return 0;
}

Measured memory_bytes: 4864
N, M = map(int, input().split())
if N==1:
    if M==1:
        print(1)
    elif M==2:
        print(0)
    else:
        print(M-2)
else:
    if M==1:
        print(N-2)
    else:
        print((M-2) * (N-2))


Measured memory_bytes: 3068
sd = input()
t = input()
oks = []
if len(sd) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(sd)-len(t)+1):
        sdd = sd[i:i+len(t)]
        f = True
        for j,sddj in enumerate(sdd):
            if sddj == "?":
                continue
            elif sddj != t[j]:
                f = False
                break
        if f:
            oks.append(i)
    if oks:
        k = oks[-1]
        print((sd[:k]+t+sd[k+len(t):]).replace("?","a"))
    else:
        print("UNRESTORABLE")

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

using namespace std;
//int arr[109][3];
int arr[10050];
int main() {
 /*   vector<string> s;
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int num;
        cin >> num;
        string str;
        cin >> str;
        s.push_back(str);
        for (int j = 0; j < num; ++j) {
            int count = 0;
            string a;
            cin >> a;
            a.erase(a.begin() + 2);
            a.erase(a.begin() + 4);
            string q;
            for (int k = 0; k < 6; ++k)
                q += a[0];
            if (q == a) {
                arr[i][0]++;
            }else {
                for (int l = 0; l < 5; ++l)
                    if (a[l] > a[l + 1])
                        count++;
                if (count < 5)
                    arr[i][2]++;
                else
                    arr[i][1]++;

            }
        }
    }

*/
int n;
cin>>n;
    for (int i = 1; i <=105 ; ++i) {
        for (int j = 1; j <=105 ; ++j) {
            for (int k = 1; k <=105 ; ++k) {
                int x=pow(i,2)+pow(j,2)+pow(k,2)+i*j+k*j+i*k;
                if(x<10050)
                    arr[x]++;

            }
        }
    }
    for (int i =1; i <=n ; ++i) {
        cout<<arr[i]<<endl;
    }
}


Measured memory_bytes: 3628
N, M, K = map(int, input().split())
A = list(map(int,input().split()))
B = list(map(int, input().split()))
a = [0]
b = [0]

ans = 0
j = M

for i in range(N):
  a.append(a[i] + A[i])

for i in range(M):
  b.append(b[i] + B[i])

for i in range(N+1):
  if a[i] > K:
    break
  while a[i] + b[j] > K:
    j -= 1
  ans = max(ans, i+j)

print(ans)

Measured memory_bytes: 47376