akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

bool check(long long N, long long K, vector<long long> A, vector<long long> F, long long x) {
    long long left = K;
    rep(i,N) {
        long long minimum = x / F[i];
        if (A[i] > minimum) left -= A[i] - minimum;
        if (left < 0) return false;
    }
    return true;
}

int main() {

    long long N, K;
    cin >> N >> K;
    vector<long long> A(N), F(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> F[i];

    sort(A.begin(), A.end(), greater<int>());
    sort(F.begin(), F.end());

    long long bottom = 0;
    long long top = A[0] * F[N - 1];

    while (bottom != top) {
        long long x = bottom + (top - bottom) / 2;
        if (check(N, K, A, F, x)) top = x;
        else bottom = x + 1;
    }

    cout << bottom << endl;

    return 0;
}

Measured memory_bytes: 6552
using System;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            long sum = 0;
            for(int i=1;i<N;i++)
            {
                sum += i;
                //sum += i % (i + 1);
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 13140
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	S = input[0];
	T = input[1];

	var inS = [];
	var inT = [];

	var counter = function(str,seq){
		return str.split(seq).length - 1;
	}

	var first = "a", last = "z";
	for(var i = first.charCodeAt(0); i <= last.charCodeAt(0); i++) {
		inS[i] = counter(S, eval("String.fromCharCode(" + i + ")"));
		inT[i] = counter(T, eval("String.fromCharCode(" + i + ")"));
	}

	inS.sort(function(a,b){
        if( a > b ) return -1;
        if( a < b ) return 1;
		return 0;
	});

	inT.sort(function(a,b){
        if( a > b ) return -1;
        if( a < b ) return 1;
		return 0;
	});


	if (inS.toString() == inT.toString()) {
		console.log('Yes');
	} else {
		console.log('No');
	}
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
  int X; cin >> X;
  int a, b; a = X / 100, b = X % 100;
  int cnt = 0;
  for(int i = 5; i >= 1; i--) {
    while(b >= i) {
      b -= i;
      cnt++;
    }
    if(b == 0 && cnt <= a) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long f(long long a) {
    if (a % 4 == 0) {
        return a * 1LL;
    } else if (a % 4 == 1) {
        return 1LL;
    } else if (a % 4 == 2) {
        return a * 1LL + 1LL;
    } else {
        return 0LL;
    }
}

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

    long long a, b;
    cin >> a >> b;
    cout << (f(b * 1LL) ^ f(a * 1LL - 1LL)) << '\n';

    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<pair<int, int>> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i).first;
        A.at(i).second = i;
    }
    sort(A.begin(), A.end());
    int x = 0;
    for (int i = 0; i < N; i++)
    {
        if (A.at(i).second % 2 != i % 2)
        {
            x++;
        }
    }
    cout << x / 2 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int p[N],s[N],a[N];
int gcd(int x,int y)
{
  if(y==0) return x;
  return gcd(y,x%y);
}
int main()
{
  int n,ans=0;
  cin>>n;
  p[0]=s[n+1]=0;
  for(int i=1;i<=n;i++)
  {
    cin>>a[i];
    p[i]=gcd(p[i-1],a[i]);
  }
  for(int i=n;i>=1;i--) s[i]=gcd(s[i+1],a[i]);
  for(int i=1;i<=n;i++) ans=max(ans,gcd(p[i-1],s[i+1]));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1408
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner s=new Scanner(System.in);
    int n,a,res=0;
    
   
    n=s.nextInt();
    for(int i=1;i<=n;i++)
    {
      a=s.nextInt();
      if(a%2!=0 && i%2!=0)
      {
        res++;
      }
    }
    System.out.println(res);
  }
}
      
      

Measured memory_bytes: 35900
#include<iostream> 
using namespace std;
int main()
{
	int maxx=0,sum=0,n;
	char s;
	cin>>n;
	while(n--){
		cin>>s;
		s=='I'?(sum++):(sum--);
		maxx=max(maxx,sum);
	}cout<<maxx;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
 
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long max = a * c;
  if(max < a * d){
	max = a * d;
  }
  if(max < b * c){
    max = b * c;
  }
  if(max < b * d){
    max = b * d;
  }
  
  cout << max << endl;
  
 return 0; 
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    int N; cin >> N;
    int A[N + 2]; rep(i, N) cin >> A[i + 1];
    A[0] = 0;
    A[N + 1] = 0;
    int sum = 0;
    rep(i, N + 1) sum += abs(A[i + 1] - A[i]);
    rep(i, N) {
        //A[i + 1]抜き
        int ans = sum - abs(A[i + 1] - A[i]) - abs(A[i + 1] - A[i + 2]) + abs(A[i + 2] - A[i]);
        cout << ans << endl;
    }
}


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

struct Node{
  int key;
  struct Node *right,*left,*parent;
};

void insert(int);
void inorder(struct Node *);
void preorder(struct Node *);


struct Node *root,*NIL;

int main(){

  int n,i,x;
  char com[10];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",com);
    if(strcmp(com,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(com,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

void insert(int k){
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  
  z=((struct Node *)malloc(sizeof(struct Node)));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }

  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(z->key < y->key){
      y->left=z;
    }
    else{
      y->right=z;
    }
  }
}

void inorder(struct Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

Measured memory_bytes: 24040
import sys
A1,A2,A3 = map(int,input().split())
if not ( 1 <= A1 <= 13 and 1 <= A2 <= 13 and 1 <= A3 <= 13 ): sys.exit()
if not ( isinstance(A1,int) and isinstance(A2,int) and isinstance(A3,int) ): sys.exit()
print('bust') if A1 + A2 + A3 >= 22 else print('win')

Measured memory_bytes: 9216
import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val s = Iterator.continually(in.readLine)
    .take(n)
    .map(_.split(" "))
    .map(_.toBuffer)
    .toArray

  for(i <- 1 to n) {
    s(i-1) :+= i.toString
  }

  val ss = s.sortBy(e => e(1).toInt * -1)
    .sortBy(e => e(0))
    .map(e => e(2))
    .map(s => s.toInt)

  println(ss.mkString("\n"))

}

Measured memory_bytes: 25424
#include<bits/stdc++.h>
using namespace std;
int v[55];
int temp[55];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&v[i]);
	int ans=0;
	for(int l=0;l<=n;l++){
		for(int r=n+1;r>l;r--){
			int cnt=0,sum=0;
			for(int i=1;i<=l;i++)
				temp[++cnt]=v[i];
			for(int i=n;i>=r;i--)
				temp[++cnt]=v[i];
			if(k<cnt)	
				continue;
			sort(temp+1,temp+cnt+1);
			for(int i=cnt;i>=0;i--){
				if(i<=k-cnt)
					sum+=max(temp[i],0);
				else sum+=temp[i];
			}
			ans=max(ans,sum);
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		if (N % 500 <= A) {
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		sc.close();
	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

int main() {
    int X, Y, A, B, C; 
    cin>>X>>Y>>A>>B>>C;
    vector<int> P(A, 0), Q(B, 0), R(C, 0);
    vector<pair<int, char>> PQR;
    REP(i, 0, A){
        cin >> P[i];
        PQR.push_back({P[i], 'A'});
    }
    REP(i, 0, B){
        cin >> Q[i];
        PQR.push_back({Q[i], 'B'});     
    }
    REP(i, 0, C){
        cin >> R[i];
        PQR.push_back({R[i], 'C'});
    }
    sort(P.begin(), P.end());
    sort(Q.begin(), Q.end());
    sort(R.begin(), R.end());
    sort(PQR.begin(), PQR.end());
    reverse(PQR.begin(), PQR.end());
    
    int count_X=0; int count_Y=0; int count_Z=0;
    long ans = 0; int next = 0;
    while(count_X + count_Y + count_Z < X + Y){
        if(PQR[next].second == 'A' && count_X < X){
            ans += PQR[next].first;
            count_X++;
        }
        else if(PQR[next].second == 'B' && count_Y < Y){
            ans += PQR[next].first;
            count_Y++;
        }
        else if(PQR[next].second == 'C'){
            ans += PQR[next].first;
            count_Z++;
        }
        next++;
    }
    cout << ans << endl;      
}

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

/* macros */
#define inf 1e9
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define gtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": " << solve() << "\n";TC++;}
#define gvtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": "; vsolve(); TC++;}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())
#define rsrt(x) sort(x.rbegin(), x.rend())

void solve() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans = a*c;
    ans = max(ans, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    cout << ans << "\n";
}

int32_t main(){
    fastio
    notc
    ret
}


Measured memory_bytes: 3556
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#main
n=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
A=[a for a in range(1,n+1)]
B=list(itertools.permutations(A))
ans=0
for a in range(len(B)):
    B[a]=list(B[a])
    if B[a]==P:
        ans+=a+1
    if B[a]==Q:
        ans-=a+1
print(abs(ans))

Measured memory_bytes: 14704
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    

    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;

  
    rep(i,0,n){
	if(i+1 == k)cout << (char)(s[i] + ('a' - 'A'));
	else cout << s[i];
    }
    cout << endl;
    return  0;
}


Measured memory_bytes: 256
#include <stdio.h>

int     main(coid)
{
    int S;
    int h;
    int m;
    int s;
    
    scanf("%d", &S);
    h = S / 60 / 60;
    m = S / 60 % 60;
    s = S % 60 % 60;
    printf("%d:%d:%d\n", h, m, s);
    return (0);
}


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

int main(){
  int N;
  cin>>N;
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  sort(A.begin(),A.end());
  
  bool b=false;
  for(int i=0;i<N-1;i++){
    if(A.at(i)==A.at(i+1)){b=true; break;}
  }
  
  if(b){cout<<"NO"<<endl;}
  else{cout<<"YES"<<endl;}
}




Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
const int maxn = 2e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int a[maxn];
int main(){
	int n=read();
	for(register int i=1;i<=n;i++){
		a[i]=read();
	}
	int ans=0;
	for(register int i=n;i>=1;i--){
		for(register int j=2;j*i<=n;j++){
			a[i]=a[i]^a[i*j];
		}
		if(a[i]==1)ans++;
	}
	printf("%d\n",ans);
	for(register int i=1;i<=n;i++){
		if(a[i]==1)printf("%d ",i);
	}
	return 0;
}

Measured memory_bytes: 1792
s = gets.chomp.to_s
q_n = gets.chomp.to_i
q = []

now_r = 0
q_n.times do
  t,f,c = gets.chomp.split(' ').map(&:to_s)
  if t.to_i === 1
    now_r += 1
  else
    q << [now_r, t.to_i, f.to_i, c]
  end
end

is_even_total_r = now_r.even?
unless is_even_total_r
  s.reverse!
end

def add_front?(is_even_total_r, now_r, f)
  if now_r.even?
    if is_even_total_r
      return f === 1 ? true : false
    else
      return f === 1 ? false : true
    end
  else
    if is_even_total_r
      return f === 1 ? false : true
    else
      return f === 1 ? true : false
    end
  end
end

fronts = []
backs = []
q.each do |query|
  now_r,t,f,c = query
  if add_front?(is_even_total_r, now_r, f)
    fronts.unshift c
  else
    backs << c
  end
end

result = fronts.join + s + backs.join


puts result


Measured memory_bytes: 41856
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[200000];

LL ans = -INF;

void solve(){
	// if(N%2==0){
	// 	LL cand1 = 0;
	// 	LL cand2 = 0;
	// 	for(int i=0;i<N;i++){
	// 		if(i%2==0) cand1 += A[i];
	// 		if(i%2==1) cand2 += A[i];
	// 	}
	// 	ans = max(cand1,cand2);
	// 	return;
	// }
	//dp[i][j][k]
	//i個目まで見て
	//j=1ならi個目をとったことを表し、j=0ならとっていないことを表す
	//i個の中からk個選ぶ
	vector<vector<map<LL,LL>>> dp(N+1,vector<map<LL,LL>>(2));
	dp[0][0][0] = 0;
	auto chmax = [&](int i,int j,int k,LL new_value){
		if(dp[i][j].count(k)==1) dp[i][j][k] = max(dp[i][j][k],new_value);
		else dp[i][j][k] = new_value;
	};
	auto show_dp = [&](){
		for(int i=0;i<=N;i++){
			for(int j=0;j<=1;j++){
				for(auto iter=dp[i][j].begin();iter!=dp[i][j].end();iter++){
					printf("dp[%d][%d][%lld]=%lld,",i,j,iter->first,iter->second);
				}
				cout << endl;
			}
			cout << endl;
		}
	};
	//ばらまく
	for(int i=0;i<N;i++){
		for(int k=i/2-1;k<=i/2+1;k++){
			if(k<0 || k>N/2) continue;
			if(dp[i][0].count(k)==1){
				chmax(i+1,1,k+1,dp[i][0][k]+A[i]);
				chmax(i+1,0,k,dp[i][0][k]);
			}
			if(dp[i][1].count(k)==1) chmax(i+1,0,k,dp[i][1][k]);
		}
	}

	for(int j=0;j<=1;j++){
		for(auto iter=dp[N][j].begin();iter!=dp[N][j].end();iter++){
			if((iter->first)==N/2) ans = max(ans,iter->second);
		}
	}
	//show_dp();
}

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

    solve();

    cout << ans << endl;
    return 0;
}

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

int main(void) {
  char T[100001];
  int N, Q;
  int i;
  int f0 = 0, f1 = 0;
  char col, inv;

  scanf("%s", T);
  N = strlen(T);
  // printf("%d\n", N);

  col = T[0];
  if (col == '0')
    inv = '1';
  else
    inv = '0';
  for (i = 1; i < N; i++) {
    if (col == T[i]) {
      // T[i] = inv;
      f0++;
    }
    col = inv;
    if (col == '0')
      inv = '1';
      else
      inv = '0';
  }
  // printf("%s\n", T);

  inv = T[0];
  if (inv == '0')
    col = '1';
  else
    col = '0';
  for (i = 0; i < N; i++) {
    if (col == T[i]) {
      // T[i] = inv;
      f1++;
    }
    col = inv;
    if (col == '0')
      inv = '1';
      else
      inv = '0';
  }
  // printf("%s\n", T);

  // printf("%d %d\n", f0, f1);
  if (f0 < f1)
    printf("%d\n", f0);
  else
    printf("%d\n", f1);
  return 0;
}


Measured memory_bytes: 256
from collections import deque

n = int(input())
s = [input() for _ in range(n)]

# 二部グラフ判定
memo = [-1] * n
memo[0] = 0
q = deque([(0, -1)])
while q:
    v, p = q.popleft()
    for nv in range(n):
        if s[v][nv] == '1':
            if nv == p:
                continue
            if memo[nv] == -1:
                memo[nv] = (memo[v] + 1) % 2
                q.append((nv, v))
            else:
                if memo[nv] == memo[v]:
                    print(-1)
                    exit()

# ワーシャルフロイドでグラフの直径を求めてもよし
INF = float('inf')
dp = [[1 if c == '1' else INF for c in row] for row in s]

for i in range(n):
    dp[i][i] = 0

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

dist = 0
for i in range(n):
    d = 0
    for j in range(n):
        d = max(d, dp[i][j])
    dist = max(d, dist)

print(dist+1)

Measured memory_bytes: 68192
#include<cstdio>
#include<stack>
#include<ctime>
using namespace std;
#define N 1050
#define M 200500
int head[N],cnt,scc[N],dfn[N],low[N],f[N][13],s[M][2],as[M],vl[N],ct,ct2,vis[N][N],id[N],ct1,dep[N],is[N],n,m,ct3;
struct edge{int t,next,id;}ed[M];
void adde(int f,int t,int id){ed[++cnt]=(edge){t,head[f],id};head[f]=cnt;}
stack<int> tp,tp2,v[N],tp3;
void dfs1(int u)
{
	dfn[u]=low[u]=++ct1;
	tp.push(u);
	for(int i=head[u];i;i=ed[i].next)
	{
		if(!dfn[ed[i].t])dfs1(ed[i].t),low[u]=min(low[u],low[ed[i].t]);
		else if(!scc[ed[i].t])low[u]=min(low[u],dfn[ed[i].t]);
	}
	if(dfn[u]==low[u])
	{
		int s=tp.top(),id=++ct2;tp.pop();
		scc[s]=id;
		while(s!=u)
		s=tp.top(),tp.pop(),scc[s]=id;
	}
}
void dfs2(int u,int s){for(int i=head[u];i;i=ed[i].next)if(!vis[s][ed[i].t])vis[s][ed[i].t]=1,dfs2(ed[i].t,s);else vis[s][ed[i].t]++;}
int LCA(int x,int y){if(dep[x]<dep[y])x^=y^=x^=y;for(int i=10;i>=0;i--)if(dep[x]-dep[y]>=(1<<i))x=f[x][i];if(x==y)return x;for(int i=10;i>=0;i--)if(f[x][i]!=f[y][i])x=f[x][i],y=f[y][i];return f[x][0];}
void dfs3(int u,int fa)
{
	dfn[u]=1;dep[u]=dep[fa]+1;f[u][0]=fa;vl[u]=0;for(int i=1;i<=10;i++)f[u][i]=f[f[u][i-1]][i-1];
	for(int i=head[u];i;i=ed[i].next)
	if(!dfn[ed[i].t])tp.push(ed[i].id),dfs3(ed[i].t,u),vl[u]+=vl[ed[i].t];
	else{int s=LCA(u,ed[i].t);vl[u]++;vl[s]--;tp2.push(ed[i].id);}
}
bool check(int x)
{
	for(int i=1;i<=n;i++)dfn[i]=scc[i]=head[i]=0;
	cnt=0;ct2=0;
	for(int i=1;i<=m;i++)if(i!=x)adde(s[i][0],s[i][1],-1);else adde(s[i][1],s[i][0],-2);
	for(int i=1;i<=n;i++)if(!dfn[i])dfs1(i);
	return ct2!=ct3;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d%d",&s[i][0],&s[i][1]),adde(s[i][0],s[i][1],1);
	for(int i=1;i<=n;i++)if(!dfn[i])dfs1(i);ct3=ct2;
	for(int i=1;i<=n;i++)head[i]=0;cnt=0;
	for(int i=1;i<=m;i++)if(scc[s[i][0]]!=scc[s[i][1]])adde(scc[s[i][0]],scc[s[i][1]],-3);
	for(int i=1;i<=ct2;i++)dfs2(i,i);
	for(int i=1;i<=n;i++)head[i]=0;cnt=0;
	for(int i=1;i<=m;i++)if(scc[s[i][0]]!=scc[s[i][1]])as[i]=vis[scc[s[i][0]]][scc[s[i][1]]]>1;else v[scc[s[i][0]]].push(i);
	for(int i=1;i<=ct2;i++)
	{
		for(int j=1;j<=n;j++)dfn[j]=0,head[j]=0;
		ct1=0;cnt=0;
		for(int j=1;j<=n;j++)if(scc[j]==i)id[j]=++ct1;
		while(!v[i].empty())
		{
			int q=v[i].top();v[i].pop();
			adde(id[s[q][0]],id[s[q][1]],q);
		}
		dfs3(1,0);
		while(!tp2.empty())
		{
			int st=tp2.top();tp2.pop();
			int l=id[s[st][0]],r=id[s[st][1]];
			r=LCA(l,r);
			int fg=0;
			while(l!=r)fg|=(vl[l]==1),l=f[l][0];
			as[st]=fg;
		}
	}
	while(!tp.empty()){int st=tp.top();tp.pop();as[st]=check(st);}
	for(int i=1;i<=m;i++)printf("%s\n",as[i]?"diff":"same");
}///

Measured memory_bytes: 11520
#include<iostream>
#include<algorithm>
#include<set>
#include <string>
using namespace std;

int main(){
    for(int i = 0; i<3; i++){
        int h,m,s,h_o,m_o,s_o,h_a,m_a,s_a;
        int O;
        cin>>h>>m>>s>>h_o>>m_o>>s_o;
        O =h_o*3600 +m_o*60 + s_o;
        O -= h*3600 + m*60 + s;
        h_a = O/3600;
        m_a = (O%3600)/60;
        s_a = O%60;
        cout<<h_a<<" "<<m_a<<" "<<s_a<<endl;
    }
}



Measured memory_bytes: 3088
#include <iostream>
#include <string.h>
using namespace std;

int main(void) {
	char sstr[101], pstr[101];
	int i, j, slen, plen, flag = 0;
	cin >> sstr >> pstr;
	slen = strlen(sstr);
	plen = strlen(pstr);
	for (i = 0; i < slen; i++) {
		for (j = 0; sstr[(i+j)%slen] == pstr[j] && j != plen; j++);
		if (j == plen)
			flag = 1;
	}
	if (flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

int main() {
  long long N, p;
  cin >> N;
  vector<int> P(N);

  for (int i = 0; i < N; i++) {
    cin >> P.at(i);    
  }
  
  vector<int> Ptmp = P;  
  sort(Ptmp.begin(), Ptmp.end());
  
  if (Ptmp == P)
    cout << "YES" << endl;
  else {
    long long cnt = 0;
    for (int i = 0; i < N; i++) {
      if (Ptmp.at(i) != P.at(i))
        cnt++;
    }
    if (cnt == 2)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }

}

Measured memory_bytes: 256
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <random>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))

#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;
using ull = __uint128_t;

using sc = signed char;
using si = signed int;
using sl = signed long long int;
using sll = __int128_t;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

namespace std {
  template <>
  struct is_integral<__int128_t> {
    constexpr static bool value = true;
  };
};

const static sl NMAX = 100000;

static sl N, M;
static vector<pair<sl, sl>> rooms;
static vector<set<sl>> Paths;

void bfs() {
  deque<pair<sl, sl>> que;
  que.emplace_back(0, 0);
  while (!que.empty()) {
    sl cur = que.front().first;
    sl depth = que.front().second;
    que.pop_front();
    FORITER(Paths[cur], it) {
      if (rooms[*it].second > depth) {
        rooms[*it].first = cur;
        rooms[*it].second = depth;
        que.emplace_back(*it, depth + 1);
      }
    }
  }
}

void solve(void) {
  FOR0(i, N) {
    rooms[i].second = NMAX + 1;
  }
  rooms[0].second = 0;
  bfs();
  cout << "Yes" << endl;
  FORi(i, 1, N) {
    cout << rooms[i].first + 1 << endl;
  }
}

int main(void) {
  cin >> N >> M;
  rooms.resize(N);
  Paths.resize(N);
  sl x, y;
  FOR0(i, M) {
    cin >> x >> y;
    x--;
    y--;
    if (Paths[x].count(y) == 0) {
      Paths[x].insert(y);
    }
    if (Paths[y].count(x) == 0) {
      Paths[y].insert(x);
    }
  }
  solve();
  return 0;
}

Measured memory_bytes: 29720
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string s[101];
int s2[101];
string t[101];

int main()
{
	int n, m;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		s2[i] = 0;
	}
	cin >> m;
	for (int j = 0; j < m; j++)
		cin >> t[j];

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)
			if (s[i] == s[j])
				s2[i] += 1;
		for (int k = 0; k < m; k++)
			if (s[i] == t[k])
				s2[i] -= 1;
	}
	sort(s2, s2 + 101);
	reverse(s2, s2 + 101);
	if (s2[0] < 0)
		cout << 0;
	else
		cout << s2[0];
}

Measured memory_bytes: 888
n = int(input())
w = list(map(int, input().split()))

half = sum(w) / 2
sum1 = 0
for i in w:
    if abs(half - sum1) > abs(half - (sum1 + i)):
        sum1 += i
    else:
        print(abs(sum(w) - 2 * sum1))
        break

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  s+=s[0];
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      string a;
      a+=(i?'S':'W');
      a+=(j?'S':'W');
      for(int k=2;k<=n+1;k++){
	if(s[k-1]=='o'){
	  if(a[k-1]=='S')a+=a[k-2];
	  else a+=(a[k-2]=='W'?'S':'W');
	}else{
	  if(a[k-1]=='S')a+=(a[k-2]=='W'?'S':'W');
	  else a+=a[k-2];
	}
      }
      //cout<<a<<endl;
      if(a[0]==a[n]&&a[1]==a[n+1]){
	for(int i=0;i<n;i++)cout<<a[i];
	cout<<endl;
	return 0;
      }
    }
  }
  cout<<-1<<endl;
  return 0;
}

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


int main() {
	string S;
	cin >> S;
	int a = 0;
	int b = 0;
	for(int i = 0; i < S.size(); i++){
		if(S[i] == '0'){
			a++;
		}
		else{
			b++;
		}
	}
	cout << 2 * min(a, b) << endl;
	return 0;
}

Measured memory_bytes: 512
n = int(input())
A = [int(i) for i in input().split()]

c = 0
for i in A: c += 1 if i<3200 else 0
Am = set()
for i in A:
    if i<3200:
        Am.add(i//400)

minc = len(Am) if c>0 else len(Am)+1

AM = set([int(v)//400 if v<3200 else i+50 for i, v in enumerate(A)])
maxc = len(AM)

print(minc, maxc)

Measured memory_bytes: 3064
n, c, k = map(int, input().split())
t = [int(input()) for _ in range(n)]

t.sort()

waitP = 1
l = t[0]
ans = 0

for i in range(1, n):
    if waitP == c:
        ans += 1
        l = t[i]
        waitP = 1
        if i == n - 1:
            ans += 1
    elif waitP != c:
        if t[i] - l <= k:
            waitP += 1
            if i == n - 1:
                ans += 1
        elif t[i] - l > k:
            ans += 1
            l = t[i]
            waitP = 1
            if i == n - 1:
                ans += 1

print(ans)

Measured memory_bytes: 7384
def main():

    A, B, M = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    dis = [list(map(int, input().split())) for _ in range(M)]

    a_min, b_min = min(a), min(b)
    val_min = a_min + b_min

    for i in range(M):
        val = a[dis[i][0] - 1] + b[dis[i][1] - 1] - dis[i][2]
        if val < val_min:
            val_min = val

    print(val_min)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int64_t x,y;
  cin >> x  >> y;
  int64_t ans=0;
  while(x<=y){
    x*=2;
    ans++;
  }
  cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    char[] ch = (sc.next()).toCharArray();
	    String str = "";

	    for(int i = 0; i < ch.length; i++){
		if(ch[i] == '@'){
		    int n = Integer.parseInt(""+ch[++i]);
		    i++;
		    for(int j = 0; j < n; j++)
			str += String.valueOf(ch[i]);
		} else {
		    str += String.valueOf(ch[i]);
		}
	    }

	    System.out.println(str);
	}
    }

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

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

int main( void ) {
    
    int a, b, c;
    cin >> a >> b >> c;
    
    if( a > c )
        swap( a, c );
    if( b > c )
        swap( b, c );
    
    if( c == a + b )
        cout << "Yes\n";
    else
        cout << "No\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = (1LL << 59);
const int iINF = (1 << 31)-1;
const double dINF = 1000000000000000000.0;
const int MAX_N = 1 << 17;

int main(){
	int k, s; cin >> k >> s;
	int ans = 0;
	for (int x = 0; x <= k; x++) {
		int l, h;
		l = max(0, s - x - k);
		h = min(k, s - x);
		ans += max(0, h - l+1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N, M, Q;
  while (cin >> N >> M >> Q) {
    const int MAX = 600;
    vec<int, 2> sum = make_v(MAX, MAX, 0);
    for (int i = 0; i < M; i++) {
      int L, R;
      cin >> L >> R;
      ++sum[L][R];
    }
    for (int i = 1; i < MAX; i++) {
      for (int j = 1; j < MAX; j++) {
        sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      }
    }
    for (int i = 0; i < Q; i++) {
      int p, q;
      cin >> p >> q;
      int res = sum[MAX - 1][q] - sum[p - 1][q];
      cout << res << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 2304
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

int n,k,s;

signed main(){
	read(n,k,s);
	for(int i=1;i<=k;i++) write(s),putchar(' ');
	for(int i=1;i<=n-k;i++) write(s==1000000000?999999999:1000000000),putchar(' ');
}

Measured memory_bytes: 3616
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

uint64_t N, C, K;
vector<uint64_t> Ts;

uint64_t count() {

  uint64_t ret = 0;

  uint64_t c = 0;
  uint64_t w = Ts[0];
  for (auto t : Ts) {
    if (w + K < t) {
      w = t;
      c = 1;
      ++ret;
    } else if (c == C) {
      w = t;
      c = 1;
      ++ret;
    } else {
      ++c;
    }
  }

  return ret + 1;
}

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

  Ts.reserve(N);
  for (uint64_t i = 0; i < N; ++i) {
    uint64_t n;
    cin >> n;
    Ts.push_back(n);
  }

  sort(Ts.begin(), Ts.end());
  cout << count() << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define PI 3.14159265358979323846
using namespace std;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   /// https://ideone.com/Fd5s8n
string s,t;
cin>>s>>t;
int ans =t.length();
for(int i=0;i<=s.length()-t.length();i++){
    int diff=0;
    for(int j=0;j<t.length();j++){
        if(t[j]!=s[i+j])
            diff++;
    }
    ans =min(ans,diff);
}
cout << ans << endl;
    return 0;

}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <utility>
#include <algorithm>
using namespace std;


int main()
{
    ios::sync_with_stdio(0);
    int n,h,t=0,c=0,ans=0;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>h;
        if(h<=t)
        {
            c++;
        }
        else
        {
            c=0;
        }
        t=h;
        ans=max(ans,c);

    }
    cout<<ans;
}
//lvl 1

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  int cnt = 0;
  for(int i=0; i<n; i++){
    int a, b; cin>>a>>b;
    if(a==b)
      cnt++;
    else
      cnt = 0;
    if(cnt>=3){
      cout<<"Yes\n";
      return 0;
    }
  }
  cout<<"No\n";
return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include<string.h>
#include<iomanip>
using namespace std;
 
int main(){
  int a,b,ans;
  string op;
  while(1){
    cin >> a >> op >> b;
    if(op.compare("?") == 0){
      break;
    } else if(op.compare("+") == 0){
      ans = a+b;
    } else if(op.compare("-") == 0){
      ans = a-b;
    } else if(op.compare("*") == 0){
      ans = a*b;
    } else if(op.compare("/") == 0){
      ans = a/b;
    }
    cout << ans << endl;
  }
 
}


Measured memory_bytes: 3156
from collections import deque
import math; floor,ceil = math.floor,math.ceil
import sys; input = lambda: sys.stdin.readline().rstrip()
aint = lambda: int(input()); ints = lambda: list(map(int, input().split()))
Yes = lambda boolean: print('Yes') if boolean else print('No')
YES = lambda boolean: print('YES') if boolean else print('NO')
is_even = lambda x: True if x%2==0 else False

def main():
  n,m = ints()
  a = ints()
  s = sum(a)
  print(max(-1,n-s))

if __name__ == '__main__':
  main()

Measured memory_bytes: 9964
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;


int main(){
    int a, b;
    cin >> a >> b;
    if(a > 9 || b > 9)cout << -1 << endl;
    else cout << a * b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n), b(n);
    ll sum_a = 0, sum_b = 0;
    REP(i,n) {
        cin >> a[i];
        sum_a += a[i];
    }
    REP(i,n) {
        cin >> b[i];
        sum_b += b[i];
    }
    bool ans = true;
    if(sum_a > sum_b) ans = false;
    else {
        ll cnt = sum_b - sum_a;
        ll x = 0, y = 0;
        REP(i,n) {
            if(a[i]>b[i]) y += a[i]-b[i];
            else {
                x += (b[i]-a[i])/2;
                if((b[i]-a[i])%2==1) {
                    ++ x, ++ y;
                }
            }
        }
        ans = (x <= cnt && y <= cnt);
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 384
import sys

s = input()

rud1 = ["R","U","D"]
lud2 = ["L","U","D"]


for val in range(0,len(s),2):
    if s[val] not in rud1:
        print("No")
        sys.exit(0)

for val in range(1,len(s),2):
    if s[val] not in lud2:
        print("No")
        sys.exit(0)
print("Yes")


Measured memory_bytes: 38512
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    map<int, int> mp;
    for(int i = 0; i < n; i++) {
        int a; cin >> a;
        mp[a]++;
    }

    int ans = 0;
    for(int i = -1; i <= 100000; i++) {
        int temp = mp[i - 1] + mp[i] + mp[i + 1];
        ans = max(ans, temp);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
char X,Y,A,B,C,D,E,F;
scanf("%c %c",&X,&Y);
A=10;
B=11;
C=12;
D=13;
E=14;
F=15;
if(X==Y){
	printf("=\n");
}
if(X>Y){
		printf(">\n");
}
if(X<Y)
	printf("<\n");
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
 int i, j, k, m, kosuu, box, a[101];

 scanf("%d", &kosuu);
 for(i = 1;i <= kosuu;i++){
   scanf("%d", &a[i]);
 }
 for(m = 1;m < kosuu;m++) {
   printf("%d ", a[m]);
 }
 printf("%d\n", a[kosuu]);
 
 for(i = 2;i <= kosuu;i++) {
   for(j = 1;j <= i-1;j++) {
     if (a[i] < a[j]) {
       box = a[i];
       for(k = i - 1;k >= j;k--) {
       a[k + 1] = a[k];
       }
       a[j] = box;
     }
   }
   for(m = 1;m < kosuu;m++) {
     printf("%d ", a[m]);
   }
   printf("%d\n", a[kosuu]);
 }

 return 0;
}

Measured memory_bytes: 1828
class SegmentTree():
  def __init__(self,size,f=lambda x,y:x+y,default=0):
    self.size=pow(2,(size-1).bit_length())
    self.f=f
    self.default=default
    self.data=[default]*(self.size*2)
  def update(self,i,x):
    i+=self.size
    self.data[i]=x
    while i:
      i>>=1
      self.data[i]=self.f(self.data[i*2],self.data[i*2+1])
  # 区間[l,r)へのクエリ
  def query(self,l,r):
    l,r=l+self.size,r+self.size
    lret,rret=self.default,self.default
    while l<r:
      if l&1:
        lret=self.f(self.data[l],lret)
        l+=1
      if r&1:
        r-=1
        rret=self.f(self.data[r],rret)
      l>>=1
      r>>=1
    return self.f(lret,rret)
  def get(self,i):
    return self.data[self.size+i]
  def add(self,i,x):
    self.update(i,self.get(i)+x)



n,k=map(int,input().split())
a=[int(input()) for _ in range(n)]
maxa=max(a)
st=SegmentTree(maxa+1,max,0)
for x in a:
  l,r=x-k,x+k+1
  l=max(0,l)
  r=min(r,maxa+1)
  tmp=st.query(l,r)
  st.update(x,tmp+1)
print(st.query(0,maxa+1))

Measured memory_bytes: 137452
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC152_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(nm[0] == nm[1] ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<vector>
using namespace std;
int  main(){
    int n;  
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int sum=0;
    for(int i=0;i<n;i++)
    {
        sum+=v[i]-1;
    }
    cout<<sum;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll MOD = 1000000007;
const int MAX = 100000;

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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }


int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){ cin >> a[i];}
    deque<int> q;
    for (int i=0;i<n;i++){
        if(i%2==0){
            q.push_back(a[i]);
        }else{
            q.push_front(a[i]);
        }
    }
    if(n%2==0){
        for (int i=0;i<n;i++){
            cout << q[i] << " ";
        }
    }else{
        for (int i=n-1;i>=0;i--){
            cout << q[i] << " ";
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3712
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N = int(input())
S = list(input())
Q = int(input())
q_list = [list(input().split()) for _ in range(Q)]

bit_tree = [[0] * (N+1) for _ in range(26)]
def BIT_add(i, tree):
    while i <= N:
        tree[i] += 1
        i += i&(-i)

def BIT_sub(i, tree):
    while i <= N:
        tree[i] -= 1
        i += i&(-i)

def BIT_sum(i, tree):
    s = 0
    while i:
        s += tree[i]
        i -= i&(-i)
    return s

for i in range(N):
    x = ord(S[i]) - ord('a')
    BIT_add(i + 1, bit_tree[x])

for q in range(Q):
    line = q_list[q]
    if line[0] == '1':
        i, c = line[1:]
        i = int(i) - 1
        old_c = ord(S[i]) - ord('a')
        new_c = ord(c) - ord('a')
        BIT_sub(i + 1, bit_tree[old_c])
        BIT_add(i + 1, bit_tree[new_c])
        S[i] = c
    else:
        l, r = map(int, line[1:])
        now = 0
        for i in range(26):
            cnt = BIT_sum(r, bit_tree[i]) - BIT_sum(l - 1, bit_tree[i])
            if cnt > 0:
                now += 1
        print(now)

Measured memory_bytes: 212504
def divide_by_2(num):
	cnt = 0		

	while True:
		if num % 2 != 0:
			break
		num /= 2
		cnt += 1
	
	return cnt



def main():
	N = int(input())

	max_cnt = -1
	ans = 0

	for num in range(1, N + 1):
		cnt = divide_by_2(num)

		if max_cnt < cnt:
			max_cnt = cnt
			ans = num

	print(ans)


  
if __name__ == "__main__":
  	main()

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

int main(){

    long long n, x; cin >> n >> x;
    vector<long long> a(n);

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

    long long num = 0;

    for(long long i = 1; i < n; i++){

        if(a[i - 1] + a[i] > x){
            long long over = a[i - 1] + a[i] - x;
            if(over > a[i]) over = a[i];
            a[i] -= over;
            num += over;
        }
    }

    if(a[0] > x){
        num += a[0] - x;
    }

    /*for(int i = 0; i < n; i++){
        cout << a[i] << " ";
    }
    cout <<endl;*/
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 1024