akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int t;
    cin >> t;
    REP(_, 0, t)
    {
        int n;
        cin >> n;
        vector<pair<ll, ll>> a1, a2;
        ll K, L, R, ans = 0;
        REP(_, 0, n)
        {
            cin >> K >> L >> R;
            ans += min(L, R);
            if (L > R)
            {
                a1.emplace_back(K, L - R);
            }
            else
            {
                if (K == n)
                    continue;
                a2.emplace_back(K, R - L);
            }
        }

        sort(a1.rbegin(), a1.rend());
        priority_queue<ll> pq;
        REP(i, 1, n + 1)
        {
            while (!a1.empty() && a1.back().first == i)
            {
                ans += a1.back().second;
                pq.emplace(-a1.back().second);
                a1.pop_back();
            }
            while (pq.size() > i)
            {
                ans += pq.top();
                pq.pop();
            }
        }

        sort(a2.begin(), a2.end());
        pq = priority_queue<ll>();
        REPR(i, n, 0)
        {
            while (!a2.empty() && a2.back().first == i - 1)
            {
                ans += a2.back().second;
                pq.emplace(-a2.back().second);
                a2.pop_back();
            }
            while (pq.size() > n - i + 1)
            {
                ans += pq.top();
                pq.pop();
            }
        }

        cout << ans << "\n";
    }
}


Measured memory_bytes: 8168
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
typedef pair<int, int> P;
int l[2005];
int rl[4005];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> l[i];
	rep(i, n) {
		rl[l[i]]++;
	}
	rep(i, 4004)rl[i + 1] += rl[i];
	sort(l, l + n);
	int cnt = 0;
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			int km = abs(l[i]-l[j]);
			int kn = l[i] + l[j];
			int p = rl[kn-1] - rl[km];
			if (km < l[i] && l[i] < kn)p--;
			if (km < l[j] && l[j] < kn)p--;
			cnt += p;
	//		cout << p << endl;
		}
	}
	cout << cnt/3 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b,c,i,sum=0;
  scanf("%d",&a);
  scanf("%d",&b);
  c=b-a;
  for(i=1;i<=c;i++){
    sum+=i;
  }
  printf("%d\n",sum-b);
  return (0);
}

Measured memory_bytes: 128
from operator import itemgetter
n = int(input())
lst = [0] * n
for i in range(n):
  lst[i] = tuple(map(int, input().split()))
lst.sort(key=itemgetter(1))
t = 0
for i in range(n):
  t += lst[i][0]
  if t > lst[i][1]:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 37524
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		int[] b = new int[2];
		for(int i=0;i<3;i++){
			a[i] = sc.nextInt();
		}
		for(int i=0;i<2;i++){
			b[i] = sc.nextInt();
		}
		int c=2000,d = 2000;
		for(int i=0; i<3;i++){
			if(a[i]<c){
				c = a[i];
			}
		}
		for(int i=0; i<2;i++){
			if(b[i]<d){
				d = b[i];
			}
		}
		
		
		System.out.printf("%d%n", c+d-50);
	}
}

Measured memory_bytes: 26344
//Slimes
#include <iostream>
#include <string>
using namespace std;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int sum=1;
    for(int i=0; i<(n-1); i++){
        if(s[i]!=s[i+1]){
            sum+=1;
        }
    }
    cout << sum << endl;
    return 0;

}

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

bool Palindrome(string s) {
  int half_length = (s.length() + 1) / 2;
  bool flag = true;
  for (int i = 0; i < half_length; i++) {
    if (s[i] != s[s.length()-1-i]) {
      flag = false;
      break;
    }
  }
  return flag;
}

int main() {
  string s;
  bool flag = true;
  cin >> s;

  if (Palindrome(s) && Palindrome(s.substr(0, (s.length()/2))) && Palindrome(s.substr((s.length()+3)/2-1, s.length()))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main(){
 int h,w,i,n;
while(true){
 cin>>h>>w;
  if (h==0 && w==0) break;
  i=1;
  n=1;
  while(i<=w){
   cout<<"#";
   i++;
  } cout<<endl;
  n=2;
  i=1;
  while(2<=n && n<=(h-1)){
   cout<<"#";
   i=2;
    while(2<=i && i<=(w-1)){
     cout<<".";
     i++;
    }
  cout<<"#"<<endl;
  n++;
  }
 i=1;
 while(i<=w){
   cout<<"#";
   i++;
 } cout<<endl;
 cout<<endl;
}
   
return 0;
}

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

int main(){
  int N,W,H;
  cin>>N>>W>>H;
  int x[W]={},y[H]={};
  for(int a=0;a<N;a++){
    int xval,yval,w;
    cin>>xval>>yval>>w;
    int i=xval-w,j=xval+w;
      if(0<=i&&i<W){x[i]+=1;}
      else{x[0]+=1;}

      if(0<=j&&j<W){x[j]-=1;}

    int k=yval-w,l=yval+w;
      if(0<=k&&k<H){y[k]+=1;}
      else{y[0]+=1;}

      if(0<=l&&l<H){y[l]-=1;}
  }

  bool xjudge=false,yjudge=false;
  int val=0;
  for(int i=0;i<W;i++){
    x[i]+=val;
    if(x[i]<=0) xjudge=true;
    val=x[i];
  }
  val=0;
  for(int i=0;i<H;i++){
    y[i]+=val;
    if(y[i]<=0) yjudge=true;
    val=y[i];
  }
  if(xjudge==true&&yjudge==true){
    cout<<"No"<<endl;
  }else {
    cout<<"Yes"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3892
#include<stdio.h>
#include<vector>
#include<string>
using namespace std;

int main(){
  int n, m, c;
  scanf("%d", &n); scanf("%d", &m); scanf("%d", &c);
  int b[m+3];
  for(int i = 0; i < m; i++) scanf("%d", &b[i]);
  int a[n+3][m+3];
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++){
      scanf("%d", &a[i][j]);
    }
  }
  //////////入力
  int res = 0;
  int gap = 0 - c;
   for(int i = 0; i < n; i++) {
     int buf = 0;
    for(int j = 0; j < m; j++){
      buf += a[i][j] * b[j];
    }
    if (buf > gap) res++;
  }
  printf("%d\n", res);
}

Measured memory_bytes: 128
import math

n = int(input())
a = [int(xi) for xi in input().split()]

L=[a[0]]
gcdl = a[0]
R=[a[n-1]]
gcdr = a[n-1]
for xi in range(1,n):
    gcdl = math.gcd(gcdl,a[xi])
    L.append(gcdl)

for xi in range(n-2,-1,-1):
    gcdr = math.gcd(gcdr,a[xi])
    R.append(gcdr)

R.reverse()

# print("R", R)
# print("L", L)
m = []
m.append(R[1])
m.append(L[n-2])
# print(m)

if n>2:
    for xi in range(1,n-1):
        m.append(math.gcd(L[xi-1],R[xi+1]))
        # print(xi, R[xi+1],L[xi-1])

# print(m)
print(max(m))


Measured memory_bytes: 24616
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.Scanner;

public class Main {

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

			while(sc.hasNext()) {
				int y1 = sc.nextInt();
				int m1 = sc.nextInt();
				int d1 = sc.nextInt();
				int y2 = sc.nextInt();
				int m2 = sc.nextInt();
				int d2 = sc.nextInt();

				if (y1 <= -1 || m1 <= -1 || d1 <= -1 ||
						y2 <= -1 || m2 <= -1 || d2 <= -1) {
					break;
				}

				LocalDateTime ld1 = LocalDateTime.of(y1, m1, d1, 0, 0, 0, 0);
				LocalDateTime ld2 = LocalDateTime.of(y2, m2, d2, 0, 0, 0, 0);

				Duration res = Duration.between(ld1, ld2);

				System.out.println(res.toDays());
			}
		sc.close();
	}

}


Measured memory_bytes: 32388
let rec loop a p = function
  [] -> a | ((l,r)::xs) -> if p < l then loop (a+1) (r-1) xs else loop a p xs
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  Array.init m (fun _ -> Scanf.scanf " %d %d" (fun x y -> x,y)) |> Array.to_list
  |> List.sort (fun (a,b) (c,d) -> compare (b,a) (d,c)) |> loop 0 (-1)
  |> Printf.printf "%d\n"

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  int sm = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sm ^= a[i];
  }
  for (int i = 0; i < n; i++) {
    cout << (sm ^ a[i]) << " \n"[i == n - 1];
  }
  return 0;
}


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

#define ll long long
#define ar array

const int mxN=1e5;
int x, y, a, b, c, p[mxN+1], q[mxN+1], r[2*mxN];
ll ans;

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

    cin >> x >> y >> a >> b >> c;
    for(int i=0; i<a; ++i)
        cin >> p[i];
    sort(p, p+a);
    for(int i=0; i<b; ++i)
        cin >> q[i];
    sort(q, q+b);
    p[a]=q[b]=1e9;
    for(int i=0; i<c; ++i)
        cin >> r[i];
    c=max(x+y, c);
    sort(r, r+c);
    for(int i=0; i<x; ++i)
        ans+=p[a-1-i];
    for(int i=0; i<y; ++i)
        ans+=q[b-1-i];
    for(int i=0, j1=a-x, j2=b-y; i<x+y; ++i) {
        if(r[c-1-i]<=p[j1]&&r[c-1-i]<=q[j2])
            break;
        ans+=r[c-1-i];
        if(p[j1]<q[j2])
            ans-=p[j1++];
        else
            ans-=q[j2++];
    }
    cout << ans;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll N, A, B, K;
ll mod = 998244353;

struct ModComb {
    vector<long long> fact, rfact;
    long long max, mod;
    ModComb(long long ma, long long mod) :fact(ma, 0), rfact(ma, 0), max(ma), mod(mod) {
        fact[0] = 1;
        for (long long i=1; i<max; ++i) {
            fact[i] = fact[i-1]*i;
            fact[i] %= mod;
        }
        rfact[max-1] = mod_inverse(fact[max-1], mod);
        for (long long i=max-2; i>=0; --i) {
            rfact[i] = rfact[i+1]*(i+1);
            rfact[i] %= mod;
        }
    }
    long long mod_pow(long long x, long long n, long long mod) {
        long long a = 1LL;
        while (n) {
            if (n%2) a = ((a%mod)*(x%mod))%mod;
            x = ((x%mod)*(x%mod))%mod;
            n /= 2LL;
        }
        return a;
    }

    long long mod_inverse(long long a, long long m) {
        return mod_pow(a, m-2, m);
    }

    long long operator()(long long n, long long r) {
        if (n < r) return 0;
        return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
    }
};


int main() {
    cin >> N >> A >> B >> K;
    ll ans = 0;
    ModComb mc(N+1, mod);
    for (ll i=0; i<=N; ++i) {
        ll b = (K - A*i);
        if (b < 0 or b%B != 0) continue;
        b /= B;
        if (b > N) continue;
        ll tmp = 1;
        tmp *= mc(N, i)%mod;
        tmp *= mc(N, b)%mod;
        ans += tmp;
        ans %= mod;
    }
    cout << (ans+mod)%mod << endl;
    return 0;
}


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

public class Main {

	private static Scanner in;

    private static int n, k;
    private static int[] a;
    private static long[][] dp;
    private static int MOD = (int)1e9+7;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        n = in.nextInt();
        k = in.nextInt();
        a = new int[n];
        for(int i=0; i<n; i++) a[i] = in.nextInt();

        dp = new long[n+1][k+1];

        dp[n][0] = 1; //dp[n][kLeft] = 0 for all other kLeft

        long[] pre = new long[k+1];
        Arrays.fill(pre, 1);

        for(int i=n-1; i>=0; i--) {
            for(int kLeft=0; kLeft<=k; kLeft++) {
                dp[i][kLeft] += (pre[kLeft]-(kLeft-a[i]-1>=0?pre[kLeft-a[i]-1]:0)+MOD)%MOD;
            }

            pre[0] = dp[i][0];

            for(int j=1; j<pre.length; j++) {
                pre[j] = (pre[j-1]+dp[i][j])%MOD;
            }
        }

        System.out.println(dp[0][k]);


    }
    
    
}


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

int main(){
  int n;
  cin >> n;
  if(n==3) cout << "2 5 63" << endl;
  else{
    cout << "2 4 3 9";
    if(n<=10003){
      for(int i=1;i<=(n-4)/2;i++){
        cout << " " << 6*i+2 << " " << 6*i+4;
      }
      if(n%2) cout << " " << 6 << endl;
    }else if(n<=15001){
      for(int i=1;i<5000;i++){
        cout << " " << 6*i+2 << " " << 6*i+4;
      }
      for(int i=1;i<=(n-10002)/2;i++){
        cout << " " << 12*i+3 << " " << 12*i+9;
      }
      if(n%2) cout << " " << 6 << endl;
    }else{
      for(int i=1;i<5000;i++){
        cout << " " << 6*i+2 << " " << 6*i+4;
      }
      for(int i=1;i<2500;i++){
        cout << " " << 12*i+3 << " " << 12*i+9;
      }
      for(int i=1;i<=n-15000;i++){
        cout << " " << 6*i;
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 384
import sys

input = sys.stdin.readline

s = input()[:-1]
t = input()[:-1]

ans = len(t)
for i in range(len(s) - len(t) + 1):
    tmp = sum(s[i + j] != t[j] for j in range(len(t)))
    ans = min(ans, tmp)
print(ans)


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    int n;
    cin >> n;
    if (n < 1000) {
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }
    return 0;
}

Measured memory_bytes: 3540
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))

import itertools
all=[]
seq=list(range(1,n+1))
for ptn in itertools.permutations(seq):
  all.append(list(ptn))

ans=abs(all.index(p)-all.index(q))

print(ans)

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

bool is_ok(const vector<string>& s) {
    for (int i = 0; i < (int)s.size(); i++) {
        for (int j = i; j < (int)s.size(); j++) {
            if (s[i][j] != s[j][i]) return false;
        }
    }
    return true;
}

void rotation(vector<string>& s) {
    for (int i = 1; i < (int)s.size(); i++) {
        swap(s[i-1], s[i]);
    }
}

int main() {
    int n, ans = 0;
    cin >> n;
    vector<string> s(n);
    for (auto& e : s) cin >> e;
    
    for (int _ = 0; _ < n; _++) {
        if (is_ok(s)) ans += n;
        rotation(s);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <sstream>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum, cnt;

int main(){
	ll x,y;
	cin>>x>>y;
	if(x>=0 && y>=0){
		if(y>=x) cout<<y-x;
		else if(y>0)cout<<(x-y)+2;
		else cout<<x+1;
	}
	else if(x>=0 && y<0){
		if(abs(y)>=x) cout<<(abs(y)-x)+1;
		else cout<<(x-abs(y))+1;
	}
	else if(x<0 && y>=0){
		if(y>=abs(x)) cout<<(y-abs(x))+1;
		else if(y>0) cout<<(abs(x)-y)+1;
		else if(y==0) cout<<abs(x);
	}
	else if(x<0 && y<0){
		if(abs(x)>=abs(y)) cout<<abs(x)-abs(y);
		else cout<<(abs(y)-abs(x))+2;
	}
	
	
}


Measured memory_bytes: 256
import math
def combinations_count(n, r):
    return math.factorial(n) \
           // (math.factorial(n - r) * math.factorial(r))

n, p = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
# print(sorted(a))
# まず偶数の袋binaryと奇数の袋nonBinaryの数を算出
binary = 0
nonBinary = 0
for i in range(n):
    if a[i] % 2 == 0:
        binary += 1
    else:
        nonBinary += 1
if p == 0:
    count = 0
    for i in range(nonBinary+1):
        if i % 2 == 0:
            count += combinations_count(nonBinary, i)
    count *= 2 ** binary
    print(count)
else:
    count = 0
    for i in range(1, nonBinary + 1):
        if i % 2 == 1:
            count += combinations_count(nonBinary, i)
    count *= 2 ** binary
    print(count)


Measured memory_bytes: 3064
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
  
def main():
  k,x = map(int,input().split())
  P = []
  
  for i in range(x-k+1,x+k):
    P.append(i)
  
  print(*P)
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int h,w;
int a[12][1005];
int p[12][1005];
int sum(int x1, int x2, int y1, int y2){
    return p[x2][y2] - p[x2][y1-1] - p[x1-1][y2] + p[x1-1][y1-1];
}
int main(){
    int h,w,k;
    scanf("%d%d%d",&h,&w,&k);
    for (int i = 1; i <=  h; i++){
        for (int j = 1; j <= w; j++){
            char x;
            scanf(" %c",&x);
            a[i][j] = x-'0';
            p[i][j] = a[i][j] + p[i-1][j] + p[i][j-1] - p[i-1][j-1];
        }
    }
    int ans = 10000;
    for (int mask = 0; mask < (1<<(h-1)); mask++){
        int num = 0;
        vector<int> pos;
        pos.push_back(0);
        for (int i = 0; i < h; i++){
            if (mask & (1<<i)) {
                num++;
                pos.push_back(i+1);
            }
        }
        pos.push_back(h);
        int lastcut = 1;
        for (int i = 1; i <= w; i++){
            for (int j = 1; j < pos.size(); j++){
                int CUR = pos[j];
                int LAST = pos[j-1]+1;
                int SUM = sum(LAST,CUR,lastcut,i);
                //printf("sum %d %d, %d %d = %d\n",LAST,CUR,lastcut,i,SUM);
                if (sum(LAST,CUR,i,i) > k){
                    //printf("CANNOT\n");
                    goto next;
                }
                else if (SUM > k){
                    //printf("OVER\n");
                    num++;
                    lastcut = i;
                    break;
                }
            }
        }
        //printf("mask %d num %d\n",mask,num);
        ans = min(ans,num);
        next:;
    }
    printf("%d",ans);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,a,n) for(int i=a; i<(n); i++)
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;


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

int  a[4000][4000];

const int c = 2000;

bool isp[1234567];


pii p[4000][4000];
int v[4000][4000];





int main(){

	rep(i,1234567) isp[i] = true;
	isp[0] = isp[1] = false;
	rep(i, 1234567){
		if(!isp[i])continue;
		for(int j=i*2; j<1234567; j+=i){
			isp[j] = false;
		}
	}


	for(;;){
		int n,m;
		cin >> n >> m;
		if(n==0) break;
		
		rep(i,4000)rep(j,4000) a[i][j] = 0;

		a[c][c] = 1;
		if(n>1) a[c][c+1] = 2;

		int d = 2;
		int x = 1;
		int y = -1;
		reps(i, 3, n+1){
			a[c+y][c+x] = i;
			int X=x;
			int Y=y;
			X += dx[(d+1)%4];
			Y += dy[(d+1)%4];
			if(a[c+Y][c+X] == 0){
				d++; d%=4;
			}
			x += dx[d];
			y += dy[d];
		}
/*
		reps(i, -10, 11){
			reps(j, -10, 11){
				printf("%3d", a[c+i][c+j]);
			}
			puts("");
		}puts("");
*/
		rep(i, 4000) rep(j, 4000){
			v[i][j] = -4000;
			if(a[i][j]==m) v[i][j] = 0;
		}
/*
		reps(i, -10, 11){
			reps(j, -10, 11){
				printf("%6d", v[c+i][c+j]);
			}
			puts("");
		}puts("");
		*/
		int ma = -1;
		int mi = 0;
		reps(i, 1, 3999) reps(j, 1,3999){
			int A = v[i-1][j-1];
			int B = v[i-1][j];
			int C = v[i-1][j+1];
			
			v[i][j] = max(max(max(A,B),C),v[i][j]) + isp[a[i][j]];

			if(ma <= v[i][j]){
				if(ma != v[i][j]){
					ma = v[i][j];
					mi = 0;
				}
				if(isp[a[i][j]]) mi = max(mi,a[i][j]);
			}
		}
		cout << ma << " "<<mi <<endl;

	}

	return 0;
}

Measured memory_bytes: 129284
import java.util.*;
public class Main {
    static int days[]={31,29,31,30,31,30,31,31,30,31,30,31};
    static String name[]={"Monday","Tuesday","Wednesday","Thursday",
    					  "Friday","Saturday","Sunday"};
    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        while(true){
            int m=s.nextInt(),d=s.nextInt();
            if(m==0&&d==0)break;
            System.out.println(solve(m,d));
        }
    }
    static String solve(int month, int date){
        int cur=3;
        for(int i=0;i<month-1;i++) cur+=days[i];
        cur += date-1;
        return name[cur%7];
    }
 
}

Measured memory_bytes: 11000
def splitmozi(n , s):

    spmozi = ""
    s = list(map(str , s))

    for i in range(len(s)):
        spmozi += s[(-n) + i]

    return spmozi

def String_Rotation(s , t):

    ans = "No"
    for i in range(len(s)):
        spmozi = splitmozi(i , s)
        if spmozi == t:
            ans = "Yes"

    return ans

def main():
    s = str(input())
    t = str(input())
    print(String_Rotation(s , t))

if __name__ == '__main__':
    main()

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

using namespace std;

using ll=long long;

const ll MOD=1e9+7;

ll n,m;

void func(vector<vector<ll>>obstacleGrid)
{
     if(obstacleGrid[0][0]==1)
        {
            cout<<"0"<<endl;
            return ;
        }

        vector<vector<ll>>v(n,vector<ll>(m,0));

        for(int j=0;j<m;j++)
        {
            if(obstacleGrid[0][j]!=1)
            v[0][j]=1;
            else
            break;
        }
        for(int i=0;i<n;i++)
        {
            if(obstacleGrid[i][0]!=1)
            v[i][0]=1;
            else
            break;
        }

        for(int i=1;i<n;i++)
        {
            for(int j=1;j<m;j++)
            {
               if(obstacleGrid[i][j]==1)
                    continue;
                else
                    v[i][j]=(v[i][j-1]%MOD+v[i-1][j]%MOD)%MOD;
            }
        }
    cout<<v[n-1][m-1]<<endl;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr); 
  
  cin>>n>>m;
   vector<vector<ll>>obstacleGrid(n,vector<ll>(m,0));
   char ch;
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<m;j++)
       {
           cin>>ch;
           if(ch=='.')
            obstacleGrid[i][j]=0;
           else if(ch=='#')
            obstacleGrid[i][j]=1;
       }
   }
   func(obstacleGrid);
}


Measured memory_bytes: 23808
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
//#define all(v) ((v).begin(),(v).end())
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    int n;cin>>n;
    ll x; cin>>x;
    vector<ll> v(n);
    ll ans=0,sum=0;
    rep(i,0,n){
        cin>>v[i];
        sum+=v[i];
    }
    if(sum==x){
        cout<<n<<endl;
        return 0;
    }
    Sort(v);
    rep(i,0,n-1){
        if(x>=v[i]){
            x-=v[i];
            ans++;
        }
    }
    if(x==v[n-1])ans++;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a; i<b; i++)
#define dep(i,a,b) for(int i=a; i>=b; i--)
#define sq(a) (a)*(a)
#define ms(a,v)	memset(a,v,sizeof a)
using namespace std;
const long long INF = 1e18 , MAXN =1e5, MOD = 1e9 + 7;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef map<string, string> mss;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a,b,c;  cin>>a>>b>>c;
  cout<<c<<" "<<a<<" "<<b<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int n,int left,int mid,int right){
  int i,j,k;
  int n1=mid-left;
  int n2=right-mid;
  for (i=0; i<n1; i++) {
    L[i]=A[left+i];
  }
  for (i=0; i<n2; i++) {
    R[i]=A[mid+i];
  }
  L[n1].value=R[n2].value=SENTINEL;
  i=j=0;
  for (k=left; k<right; k++) {
    if (L[i].value<=R[j].value) {
      A[k]=L[i++];
    } else {
      A[k]=R[j++];
    }
  }
}
void mergeSort(struct Card A[],int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}
int partition(struct Card A[],int n,int p,int r){
  int i,j;
  struct Card t,x;
  x=A[r];
  i=p-1;
  for (j=p; j<r; j++) {
    if (A[j].value<=x.value) {
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}
void quickSort(struct Card A[],int n,int p,int r){
  int q;
  if(p<r){
    q=partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}
int main() {
  int n,i,v;
  struct Card A[MAX],B[MAX];
  char S[10];
  int stable=1;
  scanf("%d",&n);
  for (i=0; i<n; i++) {
    scanf("%s %d",S,&v);
    A[i].suit=B[i].suit=S[0];
    A[i].value=B[i].value=v;
  }
  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);
  for (i=0; i<n; i++) {
    if (A[i].suit!=B[i].suit) {
      stable=0;
    }
  }
  if (stable==1) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }
  for (i=0; i<n; i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }
  return 0;
}



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

typedef struct{
  double xcordi;
  double ycordi;
}Koch;

Koch Start,Finish;

void MakeCurve(int ,Koch ,Koch);

int main(){
  int depth=0;
  
  Start.xcordi=0;
  Start.ycordi=0;

  Finish.xcordi=100;
  Finish.ycordi=0;

  scanf("%d",&depth);

  printf("%0.8f %0.8f\n",Start.xcordi,Start.ycordi);

  MakeCurve(depth,Start,Finish);

  printf("%0.8f %0.8f\n",Finish.xcordi,Finish.ycordi);
  
  return 0;
}

void MakeCurve(int depth,Koch Start,Koch Finish){
  Koch Init,Med,End;
  
  if(depth==0){
    return;
  }

  Init.xcordi=(Start.xcordi*2+Finish.xcordi*1)/3;
  Init.ycordi=(Start.ycordi*2+Finish.ycordi*1)/3;

  Med.xcordi=(Start.xcordi*1+Finish.xcordi*2)/3;
  Med.ycordi=(Start.ycordi*1+Finish.ycordi*2)/3;

  End.xcordi=cos(M_PI/3)*(Med.xcordi-Init.xcordi)-sin(M_PI/3)*(Med.ycordi-Init.ycordi)+Init.xcordi;
  End.ycordi=sin(M_PI/3)*(Med.xcordi-Init.xcordi)+cos(M_PI/3)*(Med.ycordi-Init.ycordi)+Init.ycordi;
  
  MakeCurve(depth-1,Start,Init);

  printf("%0.8f %0.8f\n",Init.xcordi,Init.ycordi);

  MakeCurve(depth-1,Init,End);
  
  printf("%0.8f %0.8f\n",End.xcordi,End.ycordi);

  MakeCurve(depth-1,End,Med);

  printf("%0.8f %0.8f\n",Med.xcordi,Med.ycordi);

  MakeCurve(depth-1,Med,Finish);
  
}



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

using namespace std;

int main()
{
	long long int A, B, K;

	cin >> A >> B >> K;

	if (A >= K)
		A = A - K;
	else
	{
		K = K - A;
		A = 0;
		if (B >= K)
			B = B - K;
		else
			B = 0;
	}
	cout << A << ' ' << B << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define LL long long
map<int, int> Get;
vector<int> side;
int n;
LL ans;
int main () {
    scanf ("%d", &n);
    for (int i = 0; i < n; i++) {
        int temp;
        scanf ("%d", &temp);
        if (Get[temp]) {
            side.push_back (temp);
            Get[temp] = 0;
        }
        else {
            Get[temp] = 1;
        }
    }
    sort (side.begin(), side.end());
    int sz = side.size();
    if (sz <= 1) {
        printf ("0\n");
    }
    else {
        ans = (LL)side[sz-1] * (LL)side[sz-2];
        printf ("%lld\n", ans);
    }
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
 
 
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-10;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


//ここから編集
 
const int MAX = 2000010;
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N, K; cin >> N >> K;
  COMinit();

  for(int i=1; i<=K; i++){
    // K個の青いボール, N-K個の赤いボール
    // cout << COM(N-K+1, i) << endl;
    cout << (COM(N-K+1, i)  *COM(K-1, i-1))%MOD << endl;
  }
  return 0;
}

Measured memory_bytes: 50484
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
int main(void){
    int n,x;
    int cnt,i,j;
    int t;
    
    while(true){
        cin>>n>>x;
        if(n==0&&x==0) break;
        t=100;
        cnt=0;
        for(i=1;i<=n;i++){
            for(j=i+1;j<t;j++){
                t=x-i-j;
                if(j<t&&t<=n) cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    
    
    
    return 0;
}



Measured memory_bytes: 3100
X,Y=map(int, input().split())

#2n+n==X+Y
#x-n, y-n
#n=(X+Y)//3
#(x-n+y-n)C(x-n)
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
  fact.append((fact[-1] * i) % p)
  inv.append((-inv[p % i] * (p // i)) % p)
  factinv.append((factinv[-1] * inv[-1]) % p)

#print(cm(n, r, p))

if (X+Y)%3!=0:
  print(0)
else:
  n=(X+Y)//3
  print(cmb(X+Y-2*n, X-n, p))

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

int main() {
  int a, n;

  cin >> n >> a;
  cout << n * n - a << endl;
  return 0;
}



Measured memory_bytes: 256
def ABC106_B():
    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
    N = I()
    ans = 0
    for i in range((N+1)//2):
        cur = i*2+1
        if len(make_divisors(cur))==8:
            ans += 1
    print(ans)
    return

def ABC122_B():
    S = SI()
    ans = 0
    cur = 0
    d = {"A","C","G","T"}
    for s in S:
        if s in d:
            cur += 1
        else:
            ans = max(ans,cur)
            cur = 0
    ans = max(ans,cur)
    print(ans)
    return

def paken2019_C():
    N, M = LI()
    A = [LI()for _ in range(N)]
    T = [i for i in range(M)]
    ans = 0
    for t1,t2 in itertools.permutations(T,2):
        cur = 0
        for i in range(N):
            cur += max(A[i][t1],A[i][t2])
        ans = max(ans,cur)
    print(ans)
    return

def ABC95_C():
    A, B, C, X, Y = LI()
    if A+B<=C*2:
        ans = A*X+B*Y
    else:
        if X>Y:
            ans = Y*C*2 + min(A,C*2)*(X-Y)
        else:
            ans = X*C*2 + min(B,C*2)*(Y-X)
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    ABC95_C()

"""

"""

Measured memory_bytes: 4844
#include<stdio.h>
#define NMAX 100000
#define MAX(a,b) ((a) > (b) ? (a) : (b))

int heap[NMAX], heapsize;
void mindownheap(int);
void minupheap(int);
void maxdownheap(int);
void maxupheap(int);
int main(void)
{
  int i, n, a[NMAX*3];
  long long int ans, pre[NMAX+1] = {0}, suf[NMAX+1] = {0};
  scanf("%d", &n);
  for (i = 0; i < 3 * n; i++) scanf("%d", &a[i]);
  heapsize = 0;
  for (i = 0; i < n; i++) {
    heap[heapsize] = a[i];
    heapsize++;
    minupheap(heapsize-1);
    pre[0] += a[i];
  }
  for (i = n; i < 2 * n; i++) {
    pre[i+1-n] = pre[i-n];
    if (a[i] > heap[0]) {
      pre[i+1-n] += a[i] - heap[0];
      heap[0] = heap[heapsize-1];
      heapsize--;
      mindownheap(0);
      heap[heapsize] = a[i];
      heapsize++;
      minupheap(heapsize-1);
    }
  }
  heapsize = 0;
  for (i = 3 * n - 1; i > 2 * n - 1; i--) {
    heap[heapsize] = a[i];
    heapsize++;
    maxupheap(heapsize-1);
    suf[n] += a[i];
  }
  for (i = 2 * n - 1; i > n - 1; i--) {
    suf[i-n] = suf[i+1-n];
    if (a[i] < heap[0]) {
      suf[i-n] += a[i] - heap[0];
      heap[0] = heap[heapsize-1];
      heapsize--;
      maxdownheap(0);
      heap[heapsize] = a[i];
      heapsize++;
      maxupheap(heapsize-1);
    }
  }
  ans = pre[0] - suf[0];
  for (i = 0; i < n; i++) ans = MAX(ans, pre[i+1] - suf[i+1]);
  printf("%lld\n", ans);
}
void mindownheap(int k)
{
  int j, v = heap[k];
  while (k < heapsize / 2) {
    j = 2 * k + 1;
    if (j < heapsize - 1 && heap[j] > heap[j+1]) j++;
    if (v <= heap[j]) break;
    heap[k] = heap[j];
    k = j;
  }
  heap[k] = v;
}
void minupheap(int j)
{
  int k, v = heap[j];
  while (j > 0) {
    k = (j + 1) / 2 -1;
    if (v >= heap[k]) break;
    heap[j] = heap[k];
    j = k;
  }
  heap[j] = v;
}
void maxdownheap(int k)
{
  int j, v = heap[k];
  while (k < heapsize / 2) {
    j = 2 * k + 1;
    if (j < heapsize - 1 && heap[j] < heap[j+1]) j++;
    if (v >= heap[j]) break;
    heap[k] = heap[j];
    k = j;
  }
  heap[k] = v;
}
void maxupheap(int j)
{
  int k, v = heap[j];
  while (j > 0) {
    k = (j + 1) / 2 -1;
    if (v <= heap[k]) break;
    heap[j] = heap[k];
    j = k;
  }
  heap[j] = v;
}

Measured memory_bytes: 3328
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    long K=gl();
	    long[] A=new long[N];
	    long[] B=new long[N];
	    Map<Long, Long> map=new TreeMap<Long, Long>();

	    for(int i=0; i<N;i++) {
	    	A[i]=gl();
	    	B[i]=gl();
	    	if (map.containsKey(A[i])) {
	    		long v=map.get(A[i])+B[i];
	    		map.put(A[i], v);
	    	}else {
	    		map.put(A[i], B[i]);
	    	}
	    }

	    long m=0;
	    long r=0;
	    for(Long k: map.keySet()) {
	    	long v=map.get(k);
	    	m+=v;
	    	r=k;
	    	if(K<=m) {
	    		break;
	    	}

	    }
        System.out.print(r);

//        if (m%2==0) {
//        	System.out.println(m/2);
//        }else{
//        	System.out.println((m+1)/2);
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

using namespace std;

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

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

    int q;
    cin >> q;
    while (q--) {
        int k;
        cin >> k;
        cout << binary_search(vt.begin(), vt.end(), k) << endl;
    }
    return 0;
}


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

int main(){
  char str[1200];
  int pos = 0;
  vector<string> ans;

  fgets(str,1200,stdin);

  while(1){
    string word;
    while(str[pos] != '.' && str[pos] != ' ' && str[pos] != ',' && str[pos] != '\n')word.push_back(str[pos++]);
    
    if(str[pos] == '\n')break;
    
    if( 2<(int)word.size() && (int)word.size()<7)ans.push_back(word);
    pos++;
  }
    
  for(int i=0;i<(int)ans.size()-1;i++){
    cout << ans[i] << " ";
  }
  if((int)ans.size())cout << ans[(int)ans.size()-1] << endl;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

a = int(input())
#桁数ごとのリストを作成
nums = [3,5,7]
digit_l = [[3,5,7]]
digit = 2
#9桁目までの全パターン列挙
while digit <= 9:
    #digit桁の数を生成
    temp = []
    ta = temp.append
    base = 10**(digit-1)
    for i in nums:
        for j in digit_l[digit-2]:
            ta(j+base*i)
    digit_l.append(temp)
    digit+=1
candidate = []
for i in digit_l:
    candidate += i
candidate_str = list(map(str,candidate))

check_753 = lambda x:1 if "3" in x and "5" in x and "7" in x else 0
candidate_check = list(map(check_753,candidate_str))

#2分探索, nibuntansaku,二分探索
from bisect import bisect_right
print(sum(candidate_check[0:bisect_right(candidate,a)]))

Measured memory_bytes: 7020
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int n = cin.nextInt();
    int[] A = new int[n];
    int[] B = new int[n];

    for (int i=0;i<n;i++) {
      A[i] = cin.nextInt();
    }
    for (int i=0;i<n;i++) {
      B[i] = cin.nextInt();
    }
//    System.out.println(Arrays.toString(A));
//    System.out.println(Arrays.toString(B));
    long sumA = 0;
    long sumB = 0;

    for (int i : A)
      sumA += i;
    for (int i : B)
      sumB += i;

    if (sumA<sumB) {
      System.out.println(-1);
      return;
    }
    int mark = 0;
    int[] diff = new int[n];
    for (int i=0;i<n;i++) {
      if (A[i]<B[i]) {
        mark = 1;

      }
      diff[i] = A[i] - B[i];
    }

    if (mark == 0) {
      System.out.println(0);
      return;
    }
    else {

      Arrays.sort(diff);
//      System.out.println(Arrays.toString(diff));
      int zero = 0;
      int nega = 0;
      long negaSum = 0;
      int posi = 0;
      long posiSum = 0;
      for (int i=0;i<diff.length;i++) {
        if (diff[i]==0) zero++;
        else if (diff[i]>=0) {
          posi++;
          posiSum+=diff[i];
        }
        else {
          nega++;
          negaSum+=diff[i];
        }
      }
      // if total diff = 0
      long totalDidff = negaSum+posiSum;
//      System.out.println("totalDidff "+totalDidff);
      int count = 0;
      for (int i=0;i<diff.length;i++) {
        if (diff[i]>0) {
          totalDidff-=diff[i];
          count++;
        }
        if (totalDidff<0) break;
      }
      System.out.println(nega+posi-count+1);

    }

  }

}

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

typedef long long int ll;
typedef vector<int> vi;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;

#define pvec(v) for(auto e: v) cout << e << " ";
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i, a, b) for(int i = (a); i<(b); ++i)
#define pb push_back
#define INF 1000000005
#define MOD 1000000007
#define all(v) v.begin(), v.end()

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

ll power(ll x, ll y, ll p = MOD){  
  ll res = 1LL; 
  x = x % p;
  if (x == 0) return 0;
  while (y > 0){
    if (y & 1LL)  
      res = (res*x) % p;
    y = y>>1LL; 
    x = (x*x) % p;  
  }  
  return res;  
}  

int main(){
	IO
	string s;
	cin >> s;
	if(s.back() == 's') {
		cout << s + "es" << endl;
	}
	else {
		cout << s + "s" << endl;
	}
	return 0;
}

Measured memory_bytes: 3660
#include<iostream>
using namespace std;
int N,cnt[1<<17];
long mod=1e9+7,ans=1;
main()
{
  cin>>N;
  for(int i=0;i<N;i++)
  {
    int a;cin>>a;cnt[a]++;
  }
  for(int i=N-1;i>0;i-=2)
  {
    if(cnt[i]!=2)ans=0;
    ans=ans*2%mod;
  }
  if(N%2==1)ans*=cnt[0]==1;
  cout<<ans<<endl;
}

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

int main()
{
ll n ;
cin >> n ;
vector<ll> b(n-1);
rep(i, n-1){
  cin >> b[i];
}
rep(i,n-2){
  ans+=min(b[i],b[i+1]);
}
ans+=b[0]+b[n-2];
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include <numeric>
using namespace std;

int main()
{	
	long long int H, W, K;
	
	scanf("%lld %lld %lld", &H, &W, &K);

	long long int fi[9];
	fi[0]=0;
	fi[1]=1;
	fi[2]=1;
	fi[3]=2;
	fi[4]=3;
	fi[5]=5;
	fi[6]=8;
	fi[7]=13;
	fi[8]=21;
	
	long long int A[H+1][W+2];
	long long int z=0;
	A[0][0]=0;
	A[0][1]=1;
	for(long long int j=2;j<W+2;j++){
		A[0][j]=0;
	}
	for(long long int i=1;i<H+1;i++){
		A[i][0]=0;
		A[i][W+1]=0;
		for(long long int j=1;j<W+1;j++){
		
			A[i][j]=(A[i-1][j]*fi[j]*fi[W-j+1]+A[i-1][j-1]*fi[j-1]*fi[W-j+1]+A[i-1][j+1]*fi[W-j]*fi[j])%1000000007;
		}
	}
	
	printf("%lld", A[H][K]);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define sc(m) scanf("%d",&m);
#define scl(m) scanf("%lld",&m);
#define scd(m) scanf("%lf",&m);
#define pf(res) printf("%d",res);
#define pfl(res) printf("%lld",res);
#define pfd(res) printf("%lf",res);
using namespace std;

int arr[1005];
int main()
{
    string a,b;
    cin>>a>>b;
    int len=a.size();
    int c=0;
    for(int i=0;i<len;i++)
    {
        if(a[i]!=b[i])
        {
            c=1;
            break;
        }
    }
    if(c==0) cout<<"Yes";
    else cout<<"No";


}





Measured memory_bytes: 3596
#include <iostream>

using namespace std;

int64_t f(int64_t N, int64_t tmp) {
    return N / tmp;
}

int main(void) {
    int64_t N;
    cin >> N;
    if(N%2 == 1) {
        cout << 0 << endl;
    } else {
        int64_t ans = 0;
        int64_t tmp = 10;
        for(int i=0; i<25; i++) {
            ans += f(N, tmp);
            tmp *= 5;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a=inp()
        a-=1
        g[i].append(a)
        g[a].append(i)
    return n,g

def main():
    h, w = map(int, input().split())
    maze = [tuple(input()) for _ in range(h)]
    # h,w = inpm()
    # maze = []
    # for _ in range(h):
    #     s = tuple(input())
    #     maze.append(s)
    ans = 0
    dx = (1,0,-1,0)
    dy = (0,1,0,-1)

    for sx in range(h):
        for sy in range(w):
            if maze[sx][sy] == '#':
                continue
            else:
                d = [[-1 for _ in range(w)] for _ in range(h)]
                que = deque()
                d[sx][sy] = 0
                que.append((sx,sy))
                M = 0
                while que:
                    (qx,qy) = que.popleft()
                    for i in range(4):
                        nx=qx+dx[i]
                        ny=qy+dy[i]
                        if nx >= 0 and h>nx and ny>=0 and w>ny and maze[nx][ny]=="." and d[nx][ny]==-1:
                            d[nx][ny]=d[qx][qy]+1
                            if d[qx][qy]+1>M:
                                M= d[qx][qy]+1
                            que.append((nx,ny))
                ans = max(ans,M)
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 47064
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;cin>>s;
	int flag=0;
	for(int i=0;i<s.size();i++)
	{
		if(flag==1&&s[i]=='F')
		{
			cout<<"Yes"<<endl;
			return 0;
		}
		if(s[i]=='C') flag=1;
	}
	cout<<"No"<<endl;
	
}

Measured memory_bytes: 256