akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
def main():
    import bisect
    N = int(input())
    As = sorted(list(map(int, input().split())))
    Bs = sorted(list(map(int, input().split())))
    Cs = sorted(list(map(int, input().split())))

    c_under_b = [0]*N #b(i)の下に置けるcの数
    a_on_b = [0]*N #b(i)の上に置けるaの数

    for i in range(len(Bs)):
        c_under_b[i] = N - bisect.bisect_right(Cs, Bs[i])

    for i in range(len(Bs)):
        a_on_b[i] = bisect.bisect_left(As, Bs[i])

    count = 0
    for i in range(len(Bs)):
        count += c_under_b[i] * a_on_b[i]
    print(count)

def main5():
    """ AC """
    import bisect
    N = int(input())
    As = sorted(list(map(int, input().split())))
    Bs = sorted(list(map(int, input().split())))
    Cs = sorted(list(map(int, input().split())))

    c_under_b = [] #b(i)の下に置けるcの数
    a_on_b = [] #b(i)の上に置けるaの数

    for b in Bs:
        i = bisect.bisect_right(Cs, b)
        c_under_b.append(N - i)

    for b in Bs:
        i = bisect.bisect_left(As, b)
        a_on_b.append(i)

    count = 0
    for i in range(len(Bs)):
        count += c_under_b[i] * a_on_b[i]
    print(count)

def main4():
    """ TLE """
    import bisect
    N = int(input())
    As = sorted(list(map(int, input().split())))
    Bs = sorted(list(map(int, input().split())))
    Cs = sorted(list(map(int, input().split())))

    c_under_b = [] #b(i)の下に置けるcの数
    a_on_b = [] #b(i)の上に置けるaの数

    for b in Bs:
        i = bisect.bisect_right(Cs, b)
        c_under_b.append(len(Cs[i:]))

    for b in Bs:
        i = bisect.bisect_left(As, b)
        a_on_b.append(len(As[:i]))

    count = 0
    for i in range(len(Bs)):
        count += c_under_b[i] * a_on_b[i]
    print(count)

def main3():
    """ TLE """
    import itertools
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))

    As.sort()
    Bs.sort()
    Cs.sort()
    count = 0
    for c in Cs:
        for b in Bs:
            if c <= b:
                break
            for a in As:
                if b <= a:
                    break
                if c > b > a:
                    count += 1
    print(count)

def main2():
    """ TLE """
    import itertools
    N = int(input())
    As = list(map(int, input().split()))
    Bs = list(map(int, input().split()))
    Cs = list(map(int, input().split()))

    count = 0
    for c in Cs:
        for b in Bs:
            for a in As:
                if a < b < c:
                    count += 1
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24232
import math

class Pos:
	def __init__(self, x, y):
		self.x = x
		self.y = y
	def __str__(self):
		return str(self.x) + ' ' + str(self.y)

def koch_curve(i, n, start, end):
	if i < n:
		f = get_pos(start, end, 1/3)
		t = get_pos(start, end, 2/3)
		s = get_sec_pos(start, end, f, t)
		koch_curve(i + 1, n, start, f)
		print(f)
		koch_curve(i + 1, n, f, s)
		print(s)
		koch_curve(i + 1, n, s, t)
		print(t)
		koch_curve(i + 1, n, t, end)

def get_pos(start, end, m):
	dX = (end.x - start.x) * m
	dY = (end.y - start.y) * m
	return Pos(start.x + dX, start.y + dY)

def get_sec_pos(start, end, f, t):
	if f.y == t.y:
		x = start.x + (end.x - start.x) / 2
		len = math.fabs(t.x - f.x)
		h = math.sqrt(len**2 - (len/2)**2)
		if start.x < end.x:
			y = start.y + h
		else:
			y = start.y - h
	elif f.x < t.x and f.y < t.y:
		x = start.x
		y = t.y
	elif f.x > t.x and f.y < t.y:
		x = end.x
		y = f.y
	elif f.x > t.x and f.y > t.y:
		x = start.x
		y = t.y
	else:
		x = end.x
		y = f.y
	return Pos(x, y)
	
n = int(input())
start = Pos(0, 0)
end = Pos(100, 0)
print(start)
koch_curve(0, n, start, end)
print(end)



Measured memory_bytes: 5724
s = input()
l = len(s)
bo=s[::2].count('0')
be=s[1::2].count('0')
ans = 0
if be>=bo:
    ans += l//2-be + bo
elif l%2!=0:
    ans += l//2+1-bo + be
else:
    ans += l//2-bo + be
print(ans)

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

int main() {
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
  int D,T,S;
  cin>>D>>T>>S;
  if(D<=T*S)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 3592
#include<stdio.h>
int main (void)
{ int n,i,j,k,max;
 long long int a[200000],sum;
 
 max=0;sum=0;
 scanf("%d",&n);
 for(i=0;i<n;i++){scanf("%lld",&a[i]);}
 max=a[0];
 //for(i=0;i<n;i++){printf("%lld\n",a[i]);}
 
 for(i=0;i<n;i++)
 {
   if(max<=a[i]){max=a[i];}
   else{sum=sum+max-a[i];}
 }
 printf("%lld",sum);
  return 0;
}

Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
int N, A, B;
int main()
{
  scanf("%d%d%d", &N, &A, &B);
  if(N > 1LL*A*B || N < A+B-1){ puts("-1"); return 0;}
  for(int i=B; i>=1; --i) printf("%d ", i);
  //(N-B)/A
  int nex = B+1;
  for(int i=0; i<A-1; ++i)
  {
    int nex2 = nex+(N-B+i)/(A-1);
    for(int j=nex2-1; j>=nex; --j)
      printf("%d ", j);
    nex = nex2;
  }
  return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main()
{
	int a, b;
	int x, y;
	double z;
	scanf("%d %d", &a, &b);
	x = a / b;
	y = a % b;
	z =  (double) a / (double) b;
	printf("%d %d %lf\n", x, y, z);
	return 0;

}





Measured memory_bytes: 2144
#include <stdio.h>
int main(){
  int n,m,k,i,j,f,r=0,c=0,a[900];
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++)for(scanf("%d",&k);k;k--){
    scanf("%d",&a[c]);
    c++;
  }
  for(i=1;i<=m;i++){
    f=0;
    for(j=0;j<c;j++)if(i==a[j])f++;
    if(f==n)r++;
  }
  printf("%d",r);
  return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}



int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string s;cin >> s;
    int m = 0;
    for(auto c : s){
        m += (c-'0');
    }
    cout << max(m, (int)((s[0]-'0'-1)+9*(s.size()-1))) << endl;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
ans = 0
drink = M
a, b = [], []
INF = float('inf')
for n in range(N):
    a.append(list(map(int, input().split())))
a.sort()
for i in a:
    if drink > i[1]:
        ans += i[0] * i[1]
        drink -= i[1]
    else:
        ans += i[0] * drink
        break
print(ans)

Measured memory_bytes: 27760
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <=0){
                return false;
            }
        }
        return true;
    }

    private int readByte(){
        if(hasNextByte())return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c){
        return 33<=c && c<=126;
    }
    public boolean hasNext(){
        while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
        return hasNextByte();
    }

    public String next(){
        if(!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b<='9'){
                n*=10;
                n+=b-'0';
            }else if(b==-1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDoutble(){return Double.parseDouble(next());}
}

class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();

        int n = fs.nextInt();
        int[] h = new int[n];
        for(int i=0;i<n;i++)h[i] = fs.nextInt();

        int[] dp = new int[n];
        dp[1] = Math.abs(h[0]-h[1]);
        for(int i=2;i<n;i++){
            dp[i] = Math.min(dp[i-1]+Math.abs(h[i]-h[i-1]),dp[i-2]+Math.abs(h[i]-h[i-2]));
        }

        System.out.println(dp[n-1]);
        System.out.flush();
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

string change(string s){
    string word;
    rep(i,s.size()){
        if(s[i] >= 'A' && s[i] <= 'Z'){
            s[i] += 32;
        }
        if(s[i] >= 'a' && s[i] <= 'z'){
            word += s[i];
        }
    }
    return word;
}

int main(){
    string w, t;
    while(cin >> w){
        int ans = 0;
        w = change(w);
        while(cin >> t){
            if(t == "END_OF_TEXT") break;
            t = change(t);
            if(w == t) ans++;
        }
        cout << ans << endl;
    }
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;

int main() {
    LL N, K;
    cin >> N >> K;
    LL x[N];
    REP(i, N) {
        cin >> x[i];
    }
    LL res = LINF;
    REP(i, N - K + 1) {
        int l = i;
        int r = l + K - 1;
        LL d = min(abs(x[r]) + abs(x[r] - x[l]), abs(x[l]) + abs(x[r] - x[l]));
        res = min(d, res);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
  int univ[4][3][10] = {0};
  int n, b, f, r, v;
  int i;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d %d %d %d", &b, &f, &r, &v);
    univ[b - 1][f - 1][r - 1] += v;
  }

  for (b = 0; b < 4; b++) {
    for (f = 0; f < 3; f++) {
      for (r = 0; r < 10; r++) {
        printf(" %d", univ[b][f][r]);
      }
      putchar('\n');
    }
    if (b >= 0 && b <= 2) puts("####################");
  }

  return 0;
}

Measured memory_bytes: 612
function Main(input) {
  var a = input.split('').map(n => parseInt(n, 10));
    if(a[0]==9 || a[1]==9) {
      console.log('Yes');

    } else {
      console.log('No');
    }
 }
  Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(a>=b){
        for(int i=0;i<a;i++) cout<<b;
    }
    else{
        for(int i=0;i<b;i++) cout<<a;
    }
}


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

using namespace std;

int main(void){
  string s;
  cin >> s;
  int l = 0;
  int r = s.length() - 1;
  while(s[l] != 'A') l++;
  while(s[r] != 'Z') r--;
  cout << r - l + 1 << endl;
  return 0;
}


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

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


Measured memory_bytes: 3092
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        while(true){
            if(isPrime(n)) {out.println(n);break;}
            ++n;
        }
        
    }
    public static boolean isPrime(int n){
        for(int i=2;i*i<=n;i++){
            if(n%i==0) return false;
        }
        return true;
    }
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 22228
//
//  main.cpp
//  
//
//  Created by yataka on 2018/10/11.
//

#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    string S;
    cin >> S;
    string oddS = "";
    int len = S.size();
    for(int i = 0; i < len; i = i + 2){
        oddS += S[i];
    }
    cout << oddS << endl;
    return 0;
}


Measured memory_bytes: 512
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		//int a = int.Parse(Console.ReadLine());
		// スペース区切りの整数の入力
		//string[] input = Console.ReadLine().Split(' ');
		//int b = int.Parse(input[0]);
		//int c = int.Parse(input[1]);
		// 文字列の入力
		//string s = Console.ReadLine();
		//出力
		//Console.WriteLine((a+b+c) + " " + s);
		
		string[] inputs = Console.ReadLine().Split(' ');
		if(int.Parse(inputs[0]) % 2 == 0)
		{
			Console.WriteLine("Even");
			return;
		}
		if(int.Parse(inputs[1]) % 2 == 0)
		{
			Console.WriteLine("Even");
			return;
		}
		
		Console.WriteLine("Odd");
	}
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF 10000000
#define MOD 998244353
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

int main(){
  int N;
  cin>>N;
  vector<vector<int>>a(N,vector<int>(3));
  for(int i=0;i<N;i++)cin>>a[i][0]>>a[i][1]>>a[i][2];
  vector<vector<int>>dp(N,vector<int>(3,0));
  for(int i=0;i<3;i++)dp[0][i]=a[0][i];
  for(int i=1;i<N;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j==k)continue;
        dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
      }
    }
  }
  int ans=0;
  for(int i=0;i<3;i++)ans=max(ans,dp[N-1][i]);
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
const int N = 4005, P = 1e9 + 7;
int n, m, k, s, f[N][N], ans;

int main () {
	scanf("%d%d%d", &n, &m, &k);
	s = (n + m - 1) / (k - 1);
	f[0][0] = 1;
	for (int i = 1; i <= s; ++i) {
		for (int j = 0, sum = 0; j <= m; ++j) {
			sum = (sum + f[i - 1][j]) % P;
			if (i > 1) { if (j >= k) sum = (sum - f[i - 1][j - k] + P) % P; }
			else { if (j >= k - 1) sum = (sum - f[i - 1][j - k + 1]) % P; }
			f[i][j] = sum;
//			if ((m - j) % (k - 1) == 0 && (n + j) % (k - 1) == 0 && (i - 1) * (k - 1) + k - j <= n) ans = (ans + f[i][j] - f[i - 1][j]) % P;
			if (n + j - (k - 1) * i < 0 || j >= m) { f[i][j] = 0;  }
			if ((m - j - 1) % (k - 1) == 0 && (n + j) % (k - 1) == 0) ans = (ans + f[i][j]) % P;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 62080
#include <iostream>
#include <vector>
#include <utility>
#include <map>
using namespace std;

int H, W, D, Q;

int main()
{
    scanf("%d%d%d", &H, &W, &D);
    map<int, pair<int, int>> mp;
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            int a;
            scanf("%d", &a);
            mp[a - 1] = make_pair(i + 1, j + 1);
        }
    }

    vector<vector<int>> calc(D);

    for (int i = 0; i < D; i++)
    {
        auto p = mp[i];
        pair<int, int> q;
        for (int j = i; j <= H * W; j += D, p = q)
        {
            q = mp[j];
            calc[i].push_back(abs(p.first - q.first) + abs(p.second - q.second));
        }
        for (int j = 0; j + 1 < calc[i].size(); j++)
            calc[i][j + 1] += calc[i][j];
    }

    scanf("%d", &Q);
    for (int i = 0; i < Q; i++)
    {
        int L, R;
        scanf("%d%d", &L, &R);
        L--, R--;
        printf("%d\n", calc[L % D][R / D] - calc[L % D][L / D]);
    }
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;
const int MOD = 1000000007;
//sort(all(x))とするとソートできるよ

//  操作の特性上数値集合の中にある因数2をワンループで一つ使うことになる。
//  つまり、全体に存在する因数2の数がそのまま答えなので、各数字の持つ因数2の数をカウントして和をとればおｋ。


int main(){
    int N;cin >> N;
    vector<LL> a(N);
    rep(i,N)cin >> a[i];
    LL ans;
    LL tmp;
    rep(i,N){
        while(!(a[i] % 2)){
            ans++;
            a[i] /= 2;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
"""
https://atcoder.jp/contests/dp/tasks/dp_a
"""
from sys import stdin

n = int(input())
h = list(map(int, stdin.readline().strip().split()))

dp = [float('inf') for _ in range(n)]

dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, n):
    dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]),
                dp[i - 2] + abs(h[i] - h[i - 2]))

print(dp[n - 1])


Measured memory_bytes: 52712
#include <cstdio>
#include <cstring>
#include <vector>

const int N = 300 + 10, MOD = 1000000007;

int n, f[2][N][N];
std::vector<std::pair<int, int>> pool[N];

void init() {
  int m;
  for (scanf("%d%d", &n, &m); m--;) {
    int l, r, x;
    scanf("%d%d%d", &l, &r, &x);
    pool[r].emplace_back(l, x);
  }
}

int main() {
  init();
  f[0][0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    int c = i & 1;
    memset(f[c], 0, sizeof f[c]);
    for (int j = 0; j < i; ++j) {
      for (int k = 0; k < i; ++k) {
        int cur = f[!c][j][k];
        if (!cur) continue;
        (f[c][j][k] += cur) %= MOD;
        (f[c][i - 1][k] += cur) %= MOD;
        (f[c][j][i - 1] += cur) %= MOD;
      }
    }
    for (auto it : pool[i])
      for (int j = 0; j < i; ++j)
        for (int k = 0; k < i; ++k)
          if ((it.first <= j) + (it.first <= k) + 1 != it.second) f[c][j][k] = 0;
  }
  int ans = 0;
  for (int j = 0; j <= n; ++j)
    for (int k = 0; k <= n; ++k)
      (ans += f[n & 1][j][k]) %= MOD;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N;
  string S;
  cin >> N >> S;
  if (N%2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  else {
    rep(i,N/2) {
      if (S[i] != S[N/2+i]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3020
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if (abs(c-a)<=d)
        cout<<"Yes"<<endl;
    else
        if (abs(b-a)<=d && abs(c-b)<=d)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        String s = sc.next();

        if (a>=3200){
            System.out.println(s);
        }else{
            System.out.println("red");
        }

    }
}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    map<ll,ll> mp;
    rep(i,X){
        cin >> A[i];
    }
    rep(i,Y){
        cin >> B[i];
    }
    rep(i,Z){
        cin >> C[i];
    }
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());
    priority_queue<Pll> que;
    vector<ll> ans;
    que.push(Pll(A[0]+B[0]+C[0], 0));
    mp[0]++;
    rep(i,K){
        Pll t = que.top();
        que.pop();
        ans.push_back(t.fi);
        ll a = ((t.se >> 0) & ((1LL << 10) - 1));
        ll b = ((t.se >> 10) & ((1LL << 10) - 1));
        ll c = ((t.se >> 20) & ((1LL << 10) - 1));
        //cout << a << " " << b <<" " << c << endl;
        if(!mp.count((t.se + 1)) && a < X-1){
            que.push(Pll(A[a+1]+B[b]+C[c], t.se + 1));
            mp[t.se + 1]++;
        }
        if(!mp.count(t.se + (1LL << 10LL)) && b <Y-1){
            que.push(Pll(A[a]+B[b+1]+C[c], t.se + (1LL << 10)));
            mp[t.se + (1LL << 10LL)]++;
        }
        if(!mp.count(t.se + (1LL << 20LL)) && c < Z-1){
            que.push(Pll(A[a]+B[b]+C[c+1], t.se + (1LL << 20)));
            mp[t.se + (1LL << 20LL)]++;
        }
    }
    rep(i,K){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4124
N = int(input())
A = list(map(int,input().split()))
flag = 0
count = 0
while flag == 0:
    for i in range(N):
        if A[i]%2 == 0:
            A[i] = A[i]//2
        else:
            flag = 1
    if(flag ==0):
        count = count +1
print(count)

Measured memory_bytes: 3060
#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 <atcoder/all>

using namespace std;
using namespace atcoder;

#define all(v) (v).begin(),(v).end()
using ll = long long;
constexpr ll INF = 1e18;

ll op(ll a, ll b) {return max(a, b);}
ll e() {return 0;}
int main(void) {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    segtree<ll, op, e> seg(300000+1);
    for (ll i = 0; i < N; i++) {
        ll p = seg.prod(max(0LL, A[i]-K), min(300001LL, A[i]+K+1));
        seg.set(A[i], p+1);
    }
    cout << seg.all_prod() << endl;

    return 0;
}


Measured memory_bytes: 15848
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

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

    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int q;
    cin >> q;
    int res = 0;
    while (q--) {
        int x;
        cin >> x;
        rep(i, n) if (x == a[i]) {
            res++;
            break;
        }
    }
    cout << res << endl;
}



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

int main(){
  	int x = 0;
  	int y = 0;
    bool flg = true;
	while (flg) {
    	cin >> x >> y;
    	
      if (x == 0 && y == 0) {
      	flg = false;
        break;
      }
      
      for (int i = 0; i < x; i ++) {
      	for (int j = 0; j < y; j++) {
          if (j + 1 == y) {
          	cout << "#" << endl;
          } else {
            cout << "#";
          }
        }
      }
      
      cout << endl;
    }
  	
    return 0;
}




Measured memory_bytes: 3060
#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=100005;
//i_am_noob
int n,k,a[maxn],ans=4e18;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> k;
	rep(n) cin >> a[i];
	sort(a,a+n);
	rep(n-k+1) ans=min(ans,a[i+k-1]-a[i]);
	print1(ans);
	return 0;
}


Measured memory_bytes: 1024
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)// for macro
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define CIN(x) int x;cin>>x;
#define COUT(x) cout<<(x)<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define P pair<int,int>
#define V vector<int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    CIN(a);CIN(b);CIN(c);
    int sum=a+b+c;
    int max_=max({a,b,c});
    Yes(sum==max_*2);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = [ int(n)-1 for n in input().split() ]
B = [ int(n) for n in input().split() ]
C = [ int(n) for n in input().split() ]

score = 0
for b in B:
    score += b
for i in range(N-1):
    if A[i]+1 == A[i+1]:
        score += C[A[i]]
        
print(score)

Measured memory_bytes: 38384
// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vector<int> tree[N];
	int C[N-1];
	rp(i, 0, N-1){
		int p; scanf("%d%d", &p, C+i); p--,C[i]--;
		tree[p].push_back(C[i]);
	}

	int K = 0;
	int colors[N]; rp(i, 0, N) colors[i] = 0;

	queue<int> q;
	q.push(0);
	colors[0] = -1;
	while(!q.empty()){
		int p = q.front(); q.pop();
		int color = 1;
		for(auto c:tree[p]){
			if(colors[c]) continue;
			q.push(c);
			colors[c] = color==colors[p]? ++color: color;
			K = max(K, color++);
		}
	}

	printf("%d\n", K);
	for(int c:C) printf("%d\n", colors[c]);
}

Measured memory_bytes: 5248
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
  	if(n % i == 0) {
		ret.push_back(i);
		if(i * i != n) ret.push_back(n / i);
		}
	}

    sort(begin(ret), end(ret));
	return (ret);
}

vector<int> Eratosthenes( const int N ){
	vector<bool> is_prime( N + 1 );
	for( int i = 0; i <= N; i++ ){
		is_prime[ i ] = true;
    }
	vector<int> P;
	for( int i = 2; i <= N; i++ ){
		if( is_prime[ i ] ){
			for( int j = 2 * i; j <= N; j += i ){
				is_prime[ j ] = false;
			}
			P.emplace_back( i );
		}
	}
	return P;
}

vector<pair<long long, long long> > prime_factorize(long long N){
	vector<pair<long long, long long> > res;
	for(long long a = 2; a*a <= N; ++a){
		if(N%a != 0) continue;

		long long ex = 0;
		while(N%a == 0){
			++ex;
			N /= a;
		}
		
		res.push_back({a, ex});
	}
		
	if(N != 1) res.push_back({N, 1});
	return res;
}

int main(){
	long long N;
	cin >> N;
	const auto &res =  prime_factorize(N);

	int count = res.size();
	for(int i = 0; i < res.size(); i++){
		int ex = res[i].second;
		int used = 1;
		int used_all = 0;
		if(ex >= 3){
			count--;
			while(ex > used_all){
					count++;
					used++;
					used_all += used;
			}
		}
	}
	cout << count << endl;
}




Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#include <vector>

using namespace std;

int calcPoints(string str, vector<string> s, vector<string> t){
  int points = 0;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == str) points++;
  }
  for(int i = 0; i < t.size(); i++) {
    if(t[i] == str) points--;
  }
  return points;
}

vector<string> deleteSame(vector<string> vec){
  for(int i = 0; i < vec.size(); i++){
    if(vec[i] == "") continue;
    for(int j = i + 1; j < vec.size(); j++){
     if(vec[i] == vec[j]) vec[j] = ""; 
    }
  }
  return vec;
}

int main(){
  int ans = 0;
  int N, M;
  cin >> N;
  vector<string> s(N, "");
  for (int i = 0; i < N; i++) cin >> s[i];
  cin >> M;
  vector<string> t(M, "");
  for (int i = 0; i < M; i++) cin >> t[i];
  vector<string> cs(N);
  
  cs = deleteSame(s);
  sort(cs.begin(), cs.end(), greater<string>() );
  for(int i = 0; i < cs.size(); i++){
    if(cs[i] == "") break;
    ans = max(calcPoints(cs[i], s, t), ans);
  }
  cout << ans;
}

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

int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> a(n);
    int i;
    priority_queue<int> q;
    for(i=0;i<n;i++)
    {
        cin>>a.at(i);
        q.push(a.at(i));
    }
    int now;
    while(m>0)
    {
        now = q.top()/2;
        q.pop();
        m--;
        q.push(now);
    }
    long long sum = 0;
    while(!q.empty())
    {
        now = q.top();
        sum+=now;
        q.pop();
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 1276
#include <iostream>
using namespace std;
#define rep(i,q) for(int i = 0; q > i; i++)
int main(){
  int a;
  cin >> a;
  if(a == 7 || a == 5 || a == 3) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;

namespace Main
{
  class Program
  {
    static void Main(string[] args)
    {
      string[] lines = Console.ReadLine().Split(' ');
      int a = int.Parse(lines[0]);
      int b = int.Parse(lines[1]);
      int k = int.Parse(lines[2]);

      StringBuilder buf = new StringBuilder();
      if (b - a < k * 2)
      {
        for (int i = a; i <= b; i++)
            buf.Append(i).Append('\n');
      }
      else
      {
        for (int i = a; i < a + k; i++)
          buf.Append(i).Append('\n');
        for (int i = b - k + 1; i <= b; i++)
          buf.Append(i).Append('\n');
      }

      Console.Write(buf);
    }
  }
}


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

using namespace std;

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.14159265358979323846;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int N, M;
int dp[110000];
vint G[110000];

int dfs(int x) {
    if (dp[x] != -1)return dp[x];
    int ret = 0;
    for (int i = 0; i < G[x].size(); i++)ret = max(ret, dfs(G[x][i]) + 1);
    return dp[x] = ret;
}

signed main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
    }
    fill(dp, dp + N + 1, -1);
    int ans = 0;
    for (int i = 1; i <= N; i++)ans = max(ans, dfs(i));
    cout << ans << endl;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int dp[111][111][2];
char S[111][111];
struct masu{
  int r,c,pre;
};

int dr[2]={0,1};
int dc[2]={1,0};

int main(){
  int H,W; cin>>H>>W;
  rep(i,H) rep(j,W) cin>>S[i][j];
  rep(i,111) rep(j,111) dp[i][j][0]=dp[i][j][1]=1e9;
  
  queue<masu> que;
  if(S[0][0]=='#'){
    que.push({0,0,1});
    dp[0][0][1]=1;
  }else{
    que.push({0,0,0});
    dp[0][0][0]=0;
  }
  
  while(que.size()){
    masu cur=que.front(); que.pop();
    rep(i,2){
      int j=cur.r+dr[i],k=cur.c+dc[i];
      if(j>=H||k>=W) continue;
      int val=dp[cur.r][cur.c][cur.pre];
      if(S[j][k]=='#'){
        if(cur.pre==1){
          if(dp[j][k][1]>val){
            dp[j][k][1]=val;
            que.push({j,k,1});
          }
        }else{
          if(dp[j][k][1]>val+1){
            dp[j][k][1]=val+1;
            que.push({j,k,1});
          }
        }
      }else{
        if(dp[j][k][0]>val){
          dp[j][k][0]=val;
          que.push({j,k,0});
        }
      }
    }
  }
  if(S[H-1][W-1]=='#') cout<<dp[H-1][W-1][1]<<endl;
  else cout<<dp[H-1][W-1][0]<<endl;
  return 0;
}

Measured memory_bytes: 384
import math
import numpy as np

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**6
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )





x,y = map(int,input().split()) 

if (x+y) % 3 == 0:

    A = np.array([[1, 2],
                  [2, 1]])

    b = np.array([x, y])

    N = np.linalg.solve(A, b)


    if N[0].is_integer() == True and N[1].is_integer() == True and N[0] >=0 and N[1] >=0:
          
        print(cmb(int(N[0]+N[1]),int(N[0]),mod))

    else:
        print(0)

else:
    print(0)

Measured memory_bytes: 132924
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
  int N;
  cin >> N;
  int R;
  cin >> R;
  int real;
  if(N>=10){
    real = R;
  }else{
    real=R+100*(10-N);
  }
  cout << real << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var list = new List<int>();
        for (int i = 0; i < n; i++)
        {
            list.Add(int.Parse(Console.ReadLine()));
        }
        list = list.OrderBy(f => f).ToList();
        Console.WriteLine(list.Sum() - list.Last() / 2);
    }
}

Measured memory_bytes: 13396
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll d, n, m;
	cin >> n >> m >> d;
	double ans = 1.0;
	if (d == 0) {
		ans /= n;
		ans *= m - 1;
		printf("%.7f\n", ans);
	}
	else {
		ans *= 2 * (n - d);
		ans /= n * n;
		ans *= (m - 1);
		printf("%.7f\n", ans);
	}
}


Measured memory_bytes: 256
S = input()

x = int(S[:2])
y = int(S[2:])

flg1 = False
flg2 = False

if x >= 1 and x <= 12:
    flg1 = True

if y >= 1 and y <= 12:
    flg2 = True

if flg1 == True and flg2 == True:
    print('AMBIGUOUS')

elif flg1 == False and flg2 == True:
    print('YYMM')

elif flg1 == True and flg2 == False:
    print('MMYY')

else:
    print('NA')


Measured memory_bytes: 3060
// 作者：杨成瑞先生
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

	public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        Long[] a = new Long[n];
        Long[] b = new Long[n];

        for(int i=0;i<n;i++) {
            a[i] = sc.nextLong();
            b[i] = a[i] - (i + 1);
        }
        Arrays.sort(b);

        long m = b[n/2];
        long ans = 0;

        for(int i=0;i<n;i++) {
            ans += Math.abs(a[i] - m - i - 1);
        }
        
        pw.println(ans);
        pw.close();
	}

}

Measured memory_bytes: 57084
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// INSERT ABOVE HERE
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    vector<int> as(n), fs(n);
    REP(i, n) cin >> as[i];
    REP(i, n) cin >> fs[i];
    sort(ALL(as));
    sort(ALLR(fs));

    auto check = [&](int x) -> bool {
        int cnt = 0;
        REP(i, n) {
            if (cnt > k)
                return false;
            int ub = x / fs[i];
            cnt += max(0LL, as[i] - ub);
        }
        return cnt <= k;
    };

    int L = -1, R = as.back() * fs.front();
    while (R - L > 1) {
        int M = (L + R) / 2;
        if (check(M))
            R = M;
        else
            L = M;
    }
    cout << R << endl;
    return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int a[4];
char s[1010];
int get(char c)
{
	if (c=='N') return 0; else if (c=='W') return 1;
	else if (c=='S') return 2; else return 3;
}
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	for (int i=0;i<len;i++) 
		a[get(s[i])]=1;
	if (((a[0]+a[2])%2==0)&&((a[1]+a[3])%2==0)) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x = I()
if x == 0:
    print(1)
else:
    print(0)

Measured memory_bytes: 65344
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int P = 1000000007;

int n, k;
int a[2010];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]);
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (a[i] < a[j]) {
        if (i < j)
          ans = (ans + k * (k - 1LL) / 2) % P;
        else
          ans = (ans + k * (k + 1LL) / 2) % P;
      }
  printf("%d\n", ans);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

#define MOD 1000000007

uint add(uint a, uint b) { return a+b < MOD ? a+b : a+b-MOD; }
uint sub(uint a, uint b) { return a < b ? a+MOD-b : a-b; }
uint mul(uint a, uint b) { return (ull)a*b%MOD; }
uint sqr(uint a) { return mul(a, a); }

#define M 65536
#define K 128
#define l fir
#define r sec

int x[M];
uint dp[K][M];

int main()
{
    canhazfast();

    int n, k, m = 0;

    cin >> n >> k;
    for (int p = 1; ; ++p) {
        int q = n/p;
        brif(q < p);
        x[m++] = p;
        if (q != p) x[m++] = q;
    }
    //cerr << "m = " << m << '\n';
    sort(x, x+m);
    fill_n(dp[0], m, 1);
    for (int i = 1; i <= k; ++i) {
        for (int j = 0, last = 0; j < m; ++j) {
            dp[i][j] = mul(dp[i-1][m-1-j], x[j]-last);
            last = x[j];
        }
        for (int j = 1; j < m; ++j) dp[i][j] = add(dp[i][j], dp[i][j-1]);
    }
    cout << dp[k][m-1] << '\n';

    return 0;
}


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

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()


int main(){
  int n,x; cin >> n >> x;
  if(x == 1 || x == 2*n-1){
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  if(n == 2){
    rep(i,3) cout << i+1 << endl;
    return 0;
  }

  vi ans(2*n-1,-1);
  vector<bool> used(2*n,false);
  if(x > 2){
    ans[n-2] = 1;
    used[1] = true;
    ans[n-1] = x;
    used[x] = true;
    ans[n] = x+1;
    used[x+1] = true;
    ans[n+1] = 2;
    used[2] = true;
  }
  else{
    ans[n-2] = x+2;
    used[x+2] = true;
    ans[n-1] = x;
    used[x] = true;
    ans[n] = x-1;
    used[x-1] = true;
    ans[n+1] = x+1;
    used[x+1] = true;
  }

  int num = 1;
  rep(i,2*n-1) {
    if(ans[i] != -1) continue;
    while(used[num]) num++;
    ans[i] = num;
    used[num] = true;
  }

  rep(i,2*n-1) cout << ans[i] << endl;

}

Measured memory_bytes: 2304