akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main()
{   
    int h,w;
    while(1){
        cin >> h >> w;
        if (h == 0 && w ==0){
            break;
        }else{
            for (int i=0;i<h;i++){
                if (i%2 ==0){
                    for (int i =0;i<w;i++){
                        if (i%2==0){
                            printf("#");
                        }else{
                            printf(".");
                        }         
                    }
                    printf("\n");
                }else{
                    for (int i =0;i<w;i++){
                        if (i%2==0){
                            printf(".");
                        }else{
                            printf("#");
                        }         
                    }
                    printf("\n");
                }
            }
            printf("\n");
        }

    }
}


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

bool provera(vector<long long> &niz,int &m,long long &x)
{
    for (int i=0;i<m;i++)
        if(niz[i]<x)
            return false;
    return true;
}

long long f(vector<vector<long long>> &v,vector<long long> &cene,int &n,int &m,long long &x,vector<long long> niz,int index,long long cena)
{
    if(index==n)
    {
        if(provera(niz,m,x))
            return cena;
        else
            return LLONG_MAX;
    }
    long long m1,m2;
    m1=f(v,cene,n,m,x,niz,index+1,cena);
    for (int i=0;i<m;i++)
        niz[i]+=v[index][i];
    cena+=cene[index];
    m2=f(v,cene,n,m,x,niz,index+1,cena);
    return min(m1,m2);
}

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,m;
    long long x,resenje;
    cin >> n >> m >> x;
    vector<long long> cena(n);
    vector<vector<long long>> v(n,vector<long long>(m));
    for (int i=0;i<n;i++)
    {
        cin >> cena[i];
        for (int j=0;j<m;j++)
            cin >> v[i][j];
    }
    vector<long long> niz(m,0);
    resenje=f(v,cena,n,m,x,niz,0,0);
    if(resenje==LLONG_MAX)
        cout << -1;
    else
        cout << resenje;
}


Measured memory_bytes: 3600
#include<cstdio>
int main()
{
	int n;
	int ge,shi,bai,qian;
	scanf("%d",&n);
	qian = n/1000;
	bai = (n-(1000*qian))/100;
	shi = (n%100)/10;
	ge = (n%10);
	if(qian==bai&&qian==shi)
	{
		printf("Yes\n");
	}
	else if(bai==shi&&bai==ge)
	{
		printf("Yes\n");
	}
	else 
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
const double PI = 3.14159265359;

int main(void) {
	ll a; cin >> a;
	ll ans = 0;
	for (int i = 1; pow(i, 2) <= a; i++)
		ans = pow(i, 2);
	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 256
require 'prime'
def divisors(n)
  n.prime_division.inject([1]) do |ary, (p, e)|
    (0..e).map{ |e1| p ** e1 }.product(ary).map{ |a, b| a * b }
  end.sort
end
#x以下の２数の積になるか？
def div2(n,x)
  div_ls=divisors(n)
  div_len=div_ls.length
  if div_ls[div_len/2]<x
    return [div_ls[div_len/2-1], div_ls[div_len/2]]
  else
    return false
  end
end
S = gets.to_i
N=Math.sqrt(S).ceil
n=N
####S=N^2-abとできればよい
while(1)
  ab=n*n-S
  ###ab=0か？
  if ab==0
    puts [0,0,0,n,n,0].join(' ')
    break
  end
  ab_ls=div2(ab,2*n-1)
  ###abが2n-1以下の2数の積か？
  if ab_ls!=false
    puts [0,0,ab_ls[0],n,n,ab_ls[1]].join(' ') 
    break
  end
  n=n+1
end
    


Measured memory_bytes: 2044
#include <stdio.h>
#include <string.h>

int main(void) {
  int i, j, ans = 0, n;
  char s[400];
  scanf("%s", s);
  n = strlen(s);
  for(i = 0; i < n / 2; ++i) {
    if((s[i] == 'i' && s[n - i - 1] != 'i') || (s[i] == 'w' && s[n - i - 1] != 'w') || (s[i] == '(' && s[n - i - 1] != ')') || (s[i] == ')' && s[n - i - 1] != '(')) ++ans;
  }
  if(n % 2 && s[n / 2] != 'i' && s[n / 2] != 'w') ++ans;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2752
#include <bits/stdc++.h>
using namespace std;
map <int,int>mp;
int a[1000];
int b[100000];
typedef long long ll;
int main()
{
    //m=gcd(i=0....n)-1;
    int n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++){
        int temp;
        cin>>temp;
        ans+=temp;
    }
    ans-=n;
    cout<<ans<<endl;
}



Measured memory_bytes: 256
from sys import stdin, setrecursionlimit, stdout
#setrecursionlimit(1000000) #use "python" instead of "pypy" to avoid MLE
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
#from heapq import heapify, heappop, heappush, heapreplace, heappushpop
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
#mod=1000000007
res=['YES', 'NO']





test_case=1
while test_case:
    test_case-=1

    a=w=t=r=0


    for _ in range(ii()):
        x=lsi()
        if x[0]=='A':
            a+=1
        elif x[0]=='W':
            w+=1
        elif x[0]=='T':
            t+=1
        else:
            r+=1
    print('AC x', a)
    print('WA x', w)
    print('TLE x', t)
    print('RE x', r)

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

using namespace std;

typedef long long ll;

int main(){
    ll N,K;
    cin>>N>>K;

     ll ans =  (N/K)*(N/K)*(N/K);

     if(K%2==0&&K/2<=N)
        ans +=  ((N - K / 2) / K + 1)*((N - K / 2) / K + 1)*((N - K / 2) / K + 1);

    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<map>
#include<iomanip>
using namespace std;
typedef long long ll;
const int maxn = 300005;
const int inf = 1000000007;

int gcd(int x, int y) {
    if(y==0)return x;
    return gcd(y,x%y);
}

int main() {
   // freopen("in.cpp","r",stdin);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x = abs(a-c);
    int y = abs(b-d);
    if(x==0||y==0)cout<<0<<endl;
    else {
        int tt = gcd(x,y);
        x/=tt,y/=tt;
        ll ret=tt*(ll)(x+y-1);
        cout<<ret<<endl;
    }
    return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

string arr[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

void solve()
{
    string S;
    cin >> S;
    int d = 7;
    for (auto a : arr)
    {
        if (a == S)
        {
            std::cout << d << endl;
            return;
        }
        d--;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


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

int const MAXH = 100000;
int const MAXW = 100000;
int const MAXN = 3000;
uint64_t MOD = 1000000007;

int H, W, N;
struct P { int x, y; };
bool operator< (P const& p1, P const& p2) {
  if(p1.x < p2.x) return true;
  if(p1.x > p2.x) return false;
  return p1.y < p2.y;
}
P b[MAXN];

uint64_t fact[MAXH+MAXW+1];
uint64_t dp[MAXN];

void init_fact(int x) {
  fact[0] = 1;
  for(int i = 1; i <= x; ++i) {
    fact[i] = fact[i-1]*(uint64_t)i%MOD;
  }
}

uint64_t mod_inv(uint64_t x) {
  int64_t a0 = 0, a1 = 1;
  int64_t y = MOD;
  while(x > 1) {
    int64_t q = y/x, r = y%x;
    int64_t t = a0; a0 = a1; a1 = t - a1*q;
    y = x; x = r;
  }
  if(a1 < 0) a1 += MOD;
  return a1;
};

uint64_t mod_ways(int x, int y) {
  uint64_t ret = fact[x+y]*mod_inv(fact[x])%MOD;
  ret = ret*mod_inv(fact[y])%MOD;
  return ret;
}

int main() {
  std::cin >> H >> W >> N;
  for(int i = 0; i < N; ++i) {
    std::cin >> b[i].x >> b[i].y;
    --b[i].x; --b[i].y;
  }
  std::sort(b, b+N);

  init_fact(H+W-2);
  uint64_t ans = mod_ways(H-1, W-1);
  for(int i = 0; i < N; ++i) {
    dp[i] = mod_ways(b[i].x, b[i].y);
    for(int j = 0; j < i; ++j) {
      int dx = b[i].x - b[j].x, dy = b[i].y - b[j].y;
      if(dx >= 0 && dy >= 0) {
        uint64_t diff = dp[j]*mod_ways(dx, dy)%MOD;
        dp[i] = (dp[i] + MOD - diff)%MOD;
      }
    }
    uint64_t diff = dp[i]*mod_ways(H-1-b[i].x, W-1-b[i].y)%MOD;
    ans = (ans + MOD - diff)%MOD;
  }
  std::cout << ans << std::endl;
  return 0;
}


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

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

long long int n,m,a[200005],b[200005],i,count,result,t;
cin>>n>>m>>count>>result>>t;
i=abs((n*60+m)-(count*60+result));

cout<<abs(i-t)<<endl;
    return 0;
}


Measured memory_bytes: 3648
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;


//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}
int main(){
        _
        string s; cin >> s;
        int ans = inf;
        for(int i = 0; i<sz(s)-2; i++){
            string x;
            x+=s[i];
            x+=s[i+1];
            x+=s[i+2];
            int a = to_int(x);
            ans = min(ans, abs(753-a));
        }
        cout<<ans<<endl;
return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int MAX=100;

void trace(int a[],int n){
for(int i=0;i<n;i++){
if(i>0)cout<<" ";
cout<<a[i];
}
cout<<endl;
}

void insertionSort(int a[],int n){
int j,i,v;
for(i=1;i<n;i++){
v=a[i];
j=i-1;
while(j>=0 && a[j]>v){
a[j+1]=a[j];
j--;
}
a[j+1]=v;
trace(a,n);
}
}

int main(){
int n,a[MAX];
cin>>n;
for(int i=0;i<n;i++)cin>>a[i];
trace(a,n);
insertionSort(a,n);
return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int64_t lucas(int n, vector<int64_t> &memo) {
  if (n == 0) return 2;
  if (n == 1) return 1;
  if (n == 2) return 3;
  if (memo.at(n) != -1) return memo.at(n);

  memo.at(n) = lucas(n-1, memo) + lucas(n-2, memo);
  return memo.at(n);
}

int main() {
  int n;
  cin >> n;
  vector<int64_t> memo = vector<int64_t>(n+1, -1);

  cout << to_string(lucas(n, memo)) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
#include<map>
#include<vector>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=55;
int N,a[maxn],cnt=0;
int main(){
	//freopen("in","r",stdin);
	N=read();
	for(int i=1;i<=N;i++){
		a[i]=read();
		if(a[i]!=i)
			cnt++;
	}
	if(cnt>2)
		printf("NO\n");
	else
		printf("YES\n");
	return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;

bool linearSearch(vector<int> &a, int x)
{
	a.at(a.size() - 1) = x;

	int i;
	for (i = 0; a.at(i) != x; i++);

	return i != a.size() - 1;
}

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

	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a.at(i));
	}
	a.push_back(0);



	int q;
	cin >> q;

	int cnt = 0;
	for (int i = 0; i < q; i++)
	{
		int x;
		scanf("%d", &x);

		if (linearSearch(a, x))
		{
			cnt++;
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 3280
package main

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

func main() {
	N := ReadInt()
	H := ReadInts(N)
	H[0]--
	for i := 1; i < N-1; i++ {
		if H[i-1] < H[i] {
			H[i]--
		}
	}
	for i := 0; i < N-1; i++ {
		if H[i] > H[i+1] {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

const int N = 505;

int n;
int p[N*N];

int viewer[N][N];
int dist[N][N];

int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};

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

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      viewer[i][j] = 1;
      dist[i][j] = min(
        min(i+1, j+1),
        min(n-i, n-j)
      );
    }
  }

  int ans = 0;
  for (int i = 0; i < n*n; ++i) {
    int p;
    scanf("%d", &p);
    --p;

    int x = p / n, y = p % n;
    viewer[x][y] = 0;
    ans += --dist[x][y];

    deque<pair<int, int>> q;
    q.push_back(make_pair(x, y));
    while (q.size()) {
      int x, y;
      tie(x, y) = q.front();
      q.pop_front();

      for (int k = 0; k < 4; ++k) {
        int nx = x + dx[k], ny = y + dy[k];
        if (nx < 0 || nx >= n || ny < 0 || ny >= n) continue;
        if (dist[nx][ny] <= dist[x][y] + viewer[nx][ny]) continue;

        dist[nx][ny] = dist[x][y] + viewer[nx][ny];

        if (viewer[nx][ny]) q.push_back(make_pair(nx, ny));
        else q.push_front(make_pair(nx, ny));
      }
    }
  }

  printf("%d\n", ans);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 6740
a = [float(input()) for i in range(5)]
sum = 0
amari = 10
index = 0
for i in range(5):
    if a[i] % 10 < amari and a[i] % 10 != 0:
        index = i
        amari=a[i] % 10
        # print(index)
# print(index)
for i in range(5):
    if i == index:
        pass
    else:
        if a[i] % 10 != 0:
            sum += a[i]+10 - a[i] % 10
        else:
            sum += a[i]
sum += a[index]
print(int(sum))


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


main(){
	int n,m,s,dp[21][11][160];
	while(cin >> n >> m >> s, s){
		REP(i, n+1)REP(j, m+1)REP(k, s+1) dp[i][j][k] = !(i+j+k);
		REP(i, n)REP(j, m)REP(k, s+1){
			if(j<m && k+i<s) dp[i+1][j+1][k+i+1] += dp[i][j][k];
			dp[i+1][j][k] += dp[i][j][k];
		}
		int ans=0;
		REP(i, n+1) ans+=dp[i][m][s];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1300
//Belief yourself,Respect yourself

#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define rep(i,intial,n) for(int i=intial; i<(n) ; i++)
#define REP(i,intial,n) for(int i=intial; i<=(n) ; i++)
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define MP make_pair
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007

//Bit Operation
bool checkBit(LL n, int i)
{
    return n&(1LL<<i);    //AND
}
LL setBit(LL n, int i)
{
    return n|(1LL<<i);;    //OR
}
LL resetBit(LL n, int i)
{
    return n&(~(1LL<<i));    //OFF
}

template<typename T> T POW(T b,T p)          //Pow calculation
{
    T r=1;
    while(p)
    {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

LL big_mod(LL n, LL p)
{
    if(p==0) return 1;
    if(!(p&1))
    {
        LL r = big_mod(n,p/2) % MOD;
        return ( (r%MOD) * (r%MOD) ) % MOD;
    }
    else return ( ( n%MOD) * (big_mod(n,p-1) %MOD)) % MOD;
}

long long gcd(long long a, long long b)
{
    while (b != 0)
    {
        long long t = a % b;
        a = b;
        b = t;
    }
    return a;
}

//||--------------------------->||Main_Code_Start_From_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    int n,ar[100010],value[100010];
    while(cin>>n)
    {
        int maximum=0;
        memset(ar,0,sizeof(ar));
        rep(i,0,n)
        {
            cin>>value[i];
            if((value[i]-1)>=0)
            {
            ar[value[i]-1]++;
            }
            ar[value[i]+1]++;
            ar[value[i]]++;

        }

         rep(i,0,n)
         {
             maximum=max(maximum,ar[value[i]]);
         }


        cout<<maximum<<endl;
    }

}



Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e18;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    s += "0";
    int n = s.size();
    vector<vector<ll>> dp(1000005, vector<ll>(2, INF));
    dp[0][0] = 0;
    rep(i,n){
        rep(j,2){
            int now = (s[i] - '0') + j;
            rep(k,10){
                int ni = i+1, nj = 0;
                int r = k - now;
                if(r < 0){
                    nj = 1;
                    r += 10;
                }
                chmin(dp[ni][nj], dp[i][j]+k+r);
            }
        }
    }
    cout << dp[n][0] << endl;
    return 0;
}


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


void solve(long long N, std::vector<long long> l, std::vector<long long> r){
    int ans = 0;
    for (int i=0; i<N; i++) {
        ans += r[i] -l[i] + 1;
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
bool card[4][14];
int main(){
    int n, a;
    char type[2];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> type >> a;
        // S H C D
        if(type[0] == 'S') card[0][a] = true;
        else if(type[0] == 'H') card[1][a] = true;
        else if(type[0] == 'C') card[2][a] = true;
        else if(type[0] == 'D') card[3][a] = true;
    }
    for(int i = 1; i <= 13; i++){
        if(!card[0][i]) printf("S %d\n", i);
    }
    for(int i = 1; i <= 13; i++){
        if(!card[1][i]) printf("H %d\n", i);
    }

    for(int i = 1; i <= 13; i++){
        if(!card[2][i]) printf("C %d\n", i);
    }
    for(int i = 1; i <= 13; i++){
        if(!card[3][i]) printf("D %d\n", i);
    }


}



Measured memory_bytes: 3196
#include<cstdio>
#include<iostream>
using namespace std;
int ans=0;
inline int read(){
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')
		  w=-1;
		ch=getchar();
	}
	while(ch>=48&&ch<='9'){
		s=s*10+ch-48;
		ch=getchar();
	}
	return s*w;
}
int main(){
	int k,s;
	k=read(),s=read();
	for(int x=0;x<=k;x++){
		for(int y=0;y<=k;y++){
			if(s-x-y>=0&&s-x-y<=k)
			  ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node{
	int x,y;
}a[100005];
bool cmp(node b, node c){
	return b.y < c.y;
}
int main()
{
	int n;
	cin >> n;
	for(int i=1;i<=n;i++){
		a[i].x=i;
		cin >> a[i].y;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<n;i++){
		printf("%d ",a[i].x);
	}
	printf("%d",a[n].x);
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std ;
typedef  long long int ll ;
#define inf ll(1e9)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a,ll n,ll m) ;
ll power(ll a,ll n,ll m)
{  if(n==0)
   return 1 ;
   ll x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}
int sieve [10000001] ;
double PI=3.14159265357 ;
int32_t main()
{ ll n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,a,temp;
  ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  cin>>n ;
  for(i=2;i<=10000000;i++)
  {
      sieve[i]=i ;
  }
  for(i=2;i*i<=10000000;i++)
  {
      if(sieve[i]==i)
      {
          for(j=i*i;j<=10000000;j+=i)
          {
              if(sieve[j]==j)
                sieve[j]=i ;
          }
      }
  }
  cnt=1 ;
  for(i=2;i<=n;i++)
  {  //cout<<i<<" " ;
     // map<ll,ll> p ;
      x=i ;
      y=sieve[x] ;
      sum=1 ;
      ll ans=0 ;
      while(x!=1)
      {   if(sieve[x]!=y)
           {

               sum=sum*(ans+1) ;
                ans=0 ;
           }
           y=sieve[x] ;
          x=x/sieve[x] ;
          ans++ ;
      }
      sum=sum*(ans+1) ;
      cnt+=i*sum ; }
  cout<<cnt ;
  return 0; }


Measured memory_bytes: 42672
def main():
    n, m = [int(x) for x in input().split()]
    k = []
    s = []
    for i in range(m):
        input_arr = [int(x) for x in input().split()]
        # print(input_arr[0])
        k.append(input_arr[0])
        # print(input_arr[1:])
        s.append(input_arr[1:])

    p = [int(x) for x in input().split()]
    # print()
    ans = 0
    for i in range(1 << n):
        cnt = 0
        for l in range(m):
            cc = 0
            for j in range(k[l]):
                ss = s[l][j]-1
                # print(l, ss)
                if i & (1 << ss):
                    cc ^= 1
            if cc == p[l]:
                # print(l+1)
                cnt += 1
        if cnt == m:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


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

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


int main() {
  // int ;
  string s,t,ans="Yes";
  cin >> s >> t;
  rep(i,s.size()) {
    if (s[i]!=t[i]) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second
const int N = 2e5+5;

/*
ll n , k , a[N] , zr , pos , neg , mod=1e9+7;
set< pair<ll,ll> > st;

void done(ll tmp)
{
    cout << tmp << '\n';
    exit(0);
}

void solve()
{
    set< pair<ll,ll> > ::iterator it;
    it = st.end();
    it--;
    ll s = 0 , tmp=1 , mnPos=2e9 , mnNeg=2e9 , tmpNeg=0 , tmpPos=0 , tmpp=0 , b=0 , b2=0;

    for(int i=1; i<=k; i++)
    {
        if ((*it).s == -1) s ^= 1 , mnNeg = min(mnNeg , ((*it).f));
        else mnPos = min(mnPos , (*it).f);
        it--;
        tmp = ((tmp%mod)*( ((*it).s*(*it).f)%mod+mod) )%mod;
    }

    if (s==0) done(tmp);
    else
    {
        for(int i=1; i<=n-k; i++)
        {
            if ((*it).s == -1 && mnPos!=2e9 && tmpNeg==0) //instead of pos
            {
                tmpNeg = (*it).f;
                b=1;
            }
            else if ((*it).s == 1 && mnNeg!=2e9 && tmpPos==0)
            {
                tmpPos = (*it).f;
                b2=1;
            }
        }
        if (b && !b2)
        {

        }
    }
}
*/

ll n;
vector<ll> v;

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

    cin >> n;
    for(int i=1; i<=n; i++)
    {
        ll x;
        cin >> x;
        v.push_back(x);
    }

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

    if (n <= 3)
    {
        ll ans = 0;
        while(v.size() > 1)
        {
            ans += v.back();
            v.pop_back();
        }
        return cout << ans << '\n' , 0;
    }

    priority_queue<ll> q;
    q.push(v.back()) , v.pop_back();

    ll ans = 0;
    while(v.size())
    {
        ans += q.top();
        q.pop();
        q.push(v.back()) , q.push(v.back());
        v.pop_back();
    }
    cout << ans << '\n';

    /*
    cin >> n >> k;
    for(int i=1; i<=n; i++)
    {
        cin >> a[i];
        if (a[i] > 0)
        {
            pos++;
            st.insert({a[i],1});
        }
        else if (a[i] < 0)
        {
            neg++;
            st.insert({abs(a[i]),-1});
        }
        else zr=1;
    }

    if (pos==0 && zr) return cout << "0\n" , 0;
    solve();

     */
    return 0;
}

Measured memory_bytes: 7964
N,Q=map(int,input().split())

A=[0]+list(map(int,input().split()))

LEN=N+1
BIT=[0]*(LEN+1) # 1-indexedなtree

def update(v,w): # index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v)) # 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v): # [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v)) # 自分より小さい2ベキのノードへ. たとえばv=3→v=2へ
    return ANS

for i in range(1,N+1):
    update(i,A[i])

for i in range(Q):
    q,p,x=map(int,input().split())
    if q==0:
        p+=1
        update(p,x)
    else:
        l=p+1
        r=x+1

        print(getvalue(r-1)-getvalue(l-1))

Measured memory_bytes: 65228
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
 
int main() {

    int n,k;
    cin>>n>>k;

    int i=0;
    while(1) {
        if(pow(k,i)>n) {
            cout<<i<<endl;
            return 0;
        }
        i++;
    }
    

 
 return 0;
}

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

int N,M,Q;
vector<long long> a,b,c,d;

long long score(const vector<int> &V){
    long long res = 0;
    for(int i = 0;i < Q;i++){
        if(V[b[i]] - V[a[i]] == c[i]) res += d[i];
    }
    return res;
}

long long dfs(vector<int> &V){ 
    if(V.size() == N){
        return score(V);
    }
    long long res = 0;
    int last = V.empty() ? 0 : V.back();
    for(int i = last;i < M;i++)
    {
        V.push_back(i);
        res = max(res,dfs(V));
        V.pop_back();
    }
    return res;
}

void calculate(){
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    for(int i = 0;i < Q;++i){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    vector<int> v;
    cout << dfs(v) << '\n';
}

int main(int, char**) {
    calculate();
    return 0;
}


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


int main() {
  int arr[3][3];
  for(int i = 0; i < 3; i++)
    for(int j = 0; j < 3; j++)
      cin >> arr[i][j];

  int N, k;
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> k;

    for(int i = 0; i < 3; i++)
      for(int j = 0; j < 3; j++)
        if(arr[i][j] == k) arr[i][j] = 0;
  }

  bool flag = false;
  for(int i = 0; i < 3; i++) {
    if(!arr[i][0] && !arr[i][1] && !arr[i][2]) flag = true;
    if(!arr[0][i] && !arr[1][i] && !arr[2][i]) flag = true;
  }
  if(!arr[0][0] && !arr[1][1] && !arr[2][2]) flag = true;
  if(!arr[2][0] && !arr[1][1] && !arr[0][2]) flag = true;
  cout << (flag ? "Yes" : "No");
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <queue>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i, start, end) for(ll i=(ll)start; i<(ll)end; i++)
#define print(a) cout << a << endl;
#define printarray(a, len) rep(i,0,len) cout << a[i] << " ";
 
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  print(max(0, c - (a - b)));
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=1e6+10;
int a[maxn];
int pri[maxn],vis[maxn];
int gcd(int a, int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
bool work(){
    for(int i=0; i<maxn; i++)pri[i]=1;
    pri[1]=pri[0]=0;
    for(int i=2; i<maxn; i++){
        if(pri[i]){
            int val=0;
            val+=vis[i];
            if(val>1)return false;
            for(int j=i*2; j<maxn; j+=i){
                pri[j]=0;
                val+=vis[j];
               if(val>1)return false;
            }
        }
    }
    return true;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)cin>>a[i],vis[a[i]]++;
    if(work()){
        cout<<"pairwise coprime"<<endl;
        return 0;
    }
    int ans=a[1];
    for(int i=1; i<=n; i++)ans=gcd(ans,a[i]);
    if(ans==1)cout<<"setwise coprime"<<endl;
    else cout<<"not coprime"<<endl;
    return 0;
}


Measured memory_bytes: 14736
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    s = S()
    if n % 2 == 1:
        print("No")
        return
    if s[:n//2] == s[n//2:]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
N,Y = map(int,input().split())

arr = []

for i in range(N+1):
    for j in range(N+1):
        k = N-i-j
        if i*10000+j*5000+k*1000 == Y and k>=0:
            arr.append([i,j,k])
if len(arr) >0:
    print(arr[0][0],arr[0][1],arr[0][2])
else:
    print(-1,-1,-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    string a,b;
    a="";
    b="";
    cin >> s;
    int sz=s.size();
    int i,j;
    for(i=0;i<sz;i++){
        s.erase(s.size()-1);
        if(s.size()%2==0){
            for(j=0;j<(s.size()/2);j++){
                a=a+s.at(j);
            }
            for(j=(s.size()/2);j<s.size();j++){
                b=b+s.at(j);
            }
            if(a==b){
                cout << s.size() << endl;
                return 0;
            }
        }
        a="";
        b="";
    }
    return 0;
}

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

using namespace std;
char str[20];
int len;

bool isPath()
{
    if(len % 2 != 0)    return false;
    for(int i = 0;i < len;i++)
        if((i % 2 == 0 &&str[i] != 'h') || (i%2!= 0 && str[i] != 'i'))
            return false;
    return true;
}
int main()
{

    scanf("%s",str);
    len = strlen(str);
    if(isPath())
        puts("Yes");
    else
        puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include<algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;
int main()
{
	int n,ans=0,x=0,j=2;
	cin >> n;
	if (n != 1) {
		for (int i = 2; i <= sqrt(n); i++) {
			j = 2;
			while (pow(i,j) <= n) {
				x = pow(i, j);
				if (ans < x&&x <= n) ans = x;
				j++;
			}
		}
		cout << ans << endl;
	}
	else cout << "1" << endl;
    return 0;
}

Measured memory_bytes: 256
def bfs(cost, s, d, c)
  n = cost.size
  memo = Array.new(n){Array.new(c+1, 5000000)}
  memo[s][c] = 0
  q = Array.new.push([s, c])
  until q.empty? do
    town, ticket = q.pop
    n.times do |nextTown|
      next unless cost[town][nextTown]
      nextCost = memo[town][ticket] + cost[town][nextTown]
      if nextCost < memo[nextTown][ticket]
        memo[nextTown][ticket] = nextCost
        q.push([nextTown, ticket])
      end
      next if ticket == 0
      nextCost = memo[town][ticket] + cost[town][nextTown]/2
      if nextCost < memo[nextTown][ticket-1]
        memo[nextTown][ticket-1] = nextCost
        q.push([nextTown, ticket-1])
      end
    end
  end
  memo[d].min
end

until (c,n,m,s,d=gets.split.map(&:to_i)).all?(&:zero?) do
  cost = Array.new(n) {Array.new(n)}
  m.times do
    a, b, f = gets.split.map(&:to_i)
    cost[a-1][b-1] = cost[b-1][a-1] = f
  end
  p bfs(cost, s-1, d-1, c)
end

Measured memory_bytes: 6168
#pragma GCC optimize ("O3")
//#pragma GCC target ("tune=native")
#pragma GCC target ("avx2")
#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<int> VI; typedef pair<int,int> pii; typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <class F,class ...S> void dbg(const F& f, const S&...s){cerr <<f <<": "; dbg(s...);}

struct chtime{
	chrono::system_clock::time_point stm;
	auto nget() { return chrono::system_clock::now();}
	chtime() { stm = nget();}
	uint64_t gtm(){
		return chrono::duration_cast<chrono::milliseconds>(nget()-stm).count();
	}
	void disp(){ cerr << gtm() <<"\n";}
};
chtime tmq;

ll CTM;
const ll TLMT = 2 *1000 - 50;
mt19937 mran((unsigned)time(nullptr)); //(20200528);
int D;
VI C(26), USD(26);
vector<VI> S(366, VI(26));

inline int xran(int su){ return mran() % su;}
inline int xran2(int su){ return mran() & su ;} //su = (2^n)-1
inline ll xran9(ll su){ return mran() & su ;}

vector<double> mkfq(int n = 100){
	if(n==0) n=1;
	vector<double> zzx(n+1);
	rep(i, n+1)  zzx[i] = 1 -(1 - i /(1.0*n)) * (1 - i/(1.0*n));
	return zzx;
}

inline ll clpt(const VI& t){
	VI usd(27, 0);
	//VL rtn(D);
	ll ans = 0;
	rep(i, D){
		ans += S[i][t[i]];
		usd[t[i]] = i+1;
		rep(j, 26){
			ans -= (ll)C[j] * (i+1 - usd[j]);
		}
		//dbg(i, ans);
	}
	return ans;
}

inline ll dpt2(const VI& t, int dy, int rt){
	ll ans = 0;
	ans +=S[dy][rt];
	int q1=dy, q2=dy;
	for(q1=dy; q1>=0 && t[q1] !=rt; q1--);
	for(q2=dy; q2 <D && t[q2] !=rt; q2++);
	ans += 1LL * C[rt] * (dy-q1) * (q2-dy);
	return ans;
}




int main()
{
	typedef pair<ll, VI> LVI;
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >>D;
	rep(i, 26) cin >> C[i];
	rep(i, D) rep(j, 26) cin >>S[i][j];
	auto fqd = mkfq(100);
	for(auto& z: fqd) z /= 100;
	int tct =0, chcnt =0, upcnt =0;
	rep(i, 99) xran2(1023);
	
	
	
	VI idt(D);
	rep(i, D) idt[i] = xran(26);//(i+3)%26;
	auto mypt = clpt(idt);
	dbg("Init",mypt);
	LVI BST = LVI(mypt, idt);
	auto ALBST = BST;
	for(; (tct &511) != 509 || (CTM = tmq.gtm()) < TLMT; tct++){
	
		int d1 = xran(D), p2 = xran(26);
		while(idt[d1]==p2) p2 = xran(26);
		int op1 = idt[d1];
		ll df = dpt2(idt, d1, p2); 
		idt[d1] = p2;
		df -= dpt2(idt, d1, op1);
		if(df >= 0){
			mypt += df;
			BST = LVI(mypt, idt); upcnt++;
		}else{
			double zan = 1.0 - 1.0 * CTM / TLMT; 
			int qw= zan*100;
			qw = max(0, min(99, qw));
			if(xran2(1023) < fqd[qw] * 1023  && BST.first > 1 &&
				abs((BST.first - mypt) / BST.first)  < fqd[qw]  ){
				mypt += df;
				BST = LVI(mypt , idt); chcnt++;
			}else{
				idt[d1] = op1;
			}
		}
		ALBST =max(ALBST, BST);
		
	}
	dbg("res",ALBST.first, BST.first, tmq.gtm(), "cnt=", tct, upcnt, chcnt);
	rep(i, D) cout << ALBST.second[i] +1 <<"\n";
	dbg(clpt(ALBST.second));
	return 0;
}
// gpp mar.cpp && a < tester\sample2.in.txt


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}

// 素因数分解
map<ll, ll> prime_factor(ll n){
	map<ll, ll> res;
	for(ll i = 2; i*i <= n; i++){
		while(n % i == 0){
			res[i]++;
			n /= i;
		}
	}
	if(n > 1) res[n]++;
	return res;
}
void mainsolve(){

	ll n;
	cin >> n;
	map<ll,ll> pf = prime_factor(n);
	cout << n << ":";
	
	for(auto itr = pf.begin(); itr != pf.end(); itr++){
		P now = *itr;
		rep(j,now.second){
		    cout << " ";
		    cout << now.first;
		}
	}
	cout << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}


Measured memory_bytes: 3112
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x) {
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

int inp[N];
int arr[N];

int main(){
  ll a = 0, b = 0;
  int n; fastScan(n);
  for(int i = 1; i <= n; i++){
    fastScan(inp[i]);
    a += inp[i];
  }
  for(int i = 1; i <= n; i++){
    fastScan(arr[i]);
    b += arr[i];
  }
  if(a < b) puts("-1");
  else {
    int ans = 0;
    ll need = 0;
    vector < int > v;
    for(int i = 1; i <= n; i++){
      if(inp[i] >= arr[i]){
        v.pb(inp[i] - arr[i]);
      } else {
        need += arr[i] - inp[i];
        ans++;
      }
    }
    sort(v.rbegin(), v.rend());
    for(int i = 0; i < v.size() && need > 0; i++){
      need -= v[i];
      ans++;
    }
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 1660
/*Chtholly is the happiest girl in the world*/
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
const int INF = 1e9;
int n,i,j,group1,group2,bash,counti;
int depth[N];
int ans[N];
int run[4];
vector<vector<int>> tree;
stack<int> st;

int main()
{
    cin>>n;
    for(i=0;i<n;i++)
    {
        vector<int> v;
        tree.push_back(v);
        depth[i] = INF;
        ans[i] = INF;
    }
    for(i=0;i<n-1;i++)
    {
        int a,b;
        cin>>a>>b;
        tree[a-1].push_back(b-1);
        tree[b-1].push_back(a-1);
    }
    st.push(0); depth[0] = 1;
    while(!st.empty())
    {
        int here = st.top();
        st.pop();
        for(auto it: tree[here])
        {
            if(depth[it]==INF)
            {
                depth[it] = depth[here]+1;
                st.push(it);
            }
        }
    }
    for(i=0;i<n;i++)
    {
        if((depth[i])%2==0)
            group2++;
        else
            group1++;
    }
    if(group1>=(n+2)/3)
        bash = 1;
    else
        bash = 0;
    counti=0;
    for(i=0;counti<(n+2)/3;i++)
    {
        if((depth[i])%2==bash)
        {
            counti++;
            ans[i] = 1;
            if(bash==1)
                group1--;
            else
                group2--;
        }
    }
    if(group1>=(n+1)/3)
        bash = 1;
    else
        bash = 0;
    counti=0;
    for(i=0;counti<(n+1)/3;i++)
    {
        if((depth[i])%2==bash && ans[i]==INF)
        {
            counti++;
            ans[i] = 2;
            if(bash==1)
                group1--;
            else
                group2--;
        }
    }
    for(i=0;i<n;i++)
    {
        if(ans[i]==1)
        {
            cout<<3*run[1]+1<<" ";
            run[1]++;
        }
        else if(ans[i]==2)
        {
            cout<<3*run[2]+2<<" ";
            run[2]++;
        }
        else
        {
            cout<<3*run[3]+3<<" ";
            run[3]++;
        }
    }
    return 0;
}


Measured memory_bytes: 16620
import java.util.Scanner;

public class Main{
    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        if(a<b){
            System.out.println("a < b");
        }else if(a==b){
            System.out.println("a == b");
        }else{
            System.out.println("a > b");
        }
        
    }
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e18;
const int MOD = 1e9 + 7;

int dp[100001];

signed main(){
    int N; cin >> N;
    vector<int> h( N );
    REP( i, N ) cin >> h[i];

    fill( dp, dp + 100001, INF );
    dp[0] = 0;
    dp[1] = abs( h[1] - h[0] );

    FOR( i, 2, N ){
        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] << endl;

}


Measured memory_bytes: 1792
N, K = [int(zz) for zz in input().split()]
A = [int(zz) for zz in input().split()]

A.sort(reverse=True)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

P = make_divisors(sum(A))
P.sort(reverse=True)

for p in P:
    z = 0
    for i in range(N):
        z += A[i] % p
    if z % p == 0:
        B = [i % p for i in A]
        B.sort(reverse=True)
        q = z//p
        j = 0
        for i in range(q):
            j += p-B[i]
        if K >= j:
            print(p)
            exit()
            
print(p)


Measured memory_bytes: 3188
#include<stdio.h>
int main(void){
  int n,c,sum=0;
  scanf("%d",&n);
  c=n;
  while(c){
    sum+=(c%10);
    c/=10;
  }
  if(n%sum){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return(0);
}


Measured memory_bytes: 128
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[3][200000];
int main(){
 int n;
 cin>>n;
 for(int i=0;i<n;i++)cin>>dp[0][i]>>dp[1][i]>>dp[2][i];
for(int i=1;i<n;i++){
    dp[0][i]+=max(dp[1][i-1],dp[2][i-1]);
    dp[1][i]+=max(dp[0][i-1],dp[2][i-1]);
    dp[2][i]+=max(dp[0][i-1],dp[1][i-1]);
}
cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=3005;
//i_am_noob
int n,k,a[maxn],dp[maxn][maxn];

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> k;
	rep(n) cin >> a[i];
	rep(k+1) dp[0][i]=0;
	dp[0][0]=1;
	rep2(i,1,n+1) rep1(j,k+1){
	    dp[i][j]=2*dp[i-1][j]%MOD;
	    if(j>=a[i-1]) dp[i][j]=add(dp[i][j],dp[i-1][j-a[i-1]]);
	}
	print1(dp[n][k]);
	return 0;
}


Measured memory_bytes: 74132