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

int main(){
	int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    for(int i=0; i<n; i++){
        if (i == k-1){
            putchar(tolower(s[i]));  
            }
        else {
            cout << s[i];
        }
    }cout << endl;
    return 0;
}

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

using namespace std;

inline bool inRange(int a, int x, int b) {
    return a <= x && x < b;
}

void fill(vector<vector<int> > &v, int r, int c) {
    v[r][c] = 0;
    for(int dr = -1; dr <= 1; ++dr) {
        for(int dc = -1; dc <= 1; ++dc) {
            int nr = r + dr;
            int nc = c + dc;
            if(inRange(0, nr, v.size()) && inRange(0, nc, v[0].size()) && v[nr][nc]) {
                fill(v, nr, nc);
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(0);

    while(true) {
        int C, R;
        cin >> C >> R;
        if(!C && !R) break;

        vector<vector<int> > v(R, vector<int>(C));
        for(int i = 0; i < R; ++i) 
            for(int j = 0; j < C; ++j)
                cin >> v[i][j];

        int cnt = 0;
        for(int r = 0; r < R; ++r) {
            for(int c = 0; c < C; ++c) {
                if(v[r][c]) {
                    ++cnt;
                    fill(v, r, c);
                }
            }
        }

        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 1488
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	counters := make([]int, 26)
	for i := 0; i < 26; i++ {
		counters[i] = 50
	}
	for i := 0; i < n; i++ {
		s := getNextString(scanner)
		counter := make([]int, 26)
		for j := 0; j < len(s); j++ {
			counter[s[j]-'a']++
		}
		for j := 0; j < 26; j++ {
			if counters[j] > counter[j] {
				counters[j] = counter[j]
			}
		}
	}
	for i := 0; i < 26; i++ {
		for j := 0; j < counters[i]; j++ {
			fmt.Fprintf(writer, "%c", int('a')+i)
		}
	}

	writer.Flush()
}


Measured memory_bytes: 640
def main():
    N, M, C = map(int, input().split())
    B = list(map(int, input().split()))
    A = [0 for i in range(N)]
    ans = 0
    for i in range(N):
        A[i] = list(map(int, input().split()))
    for i in range(N):
        ab = 0
        for j in range(M):
            ab += A[i][j]*B[j]
        if ab + C > 0:
            ans += 1
    print(ans)
main()


Measured memory_bytes: 3064
#include <iostream>
using namespace std ;
int main()
{

  int x,z,y;
  cin>>x;
  cin>>z;
  cin>>y;
  if(z==x&&x==y&&y==z||z!=x&&x!=y&&y!=z)
  {
      cout<<"No"<<endl;
  }
    else if (x==z&&z!=y||x==y&&y!=z||z==y&&y!=x)
    {
        cout<<"Yes"<<endl;
    }






}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

typedef pair<int, int> P; 


int main(){
    int n;
    cin >> n;
    if(n % 2 == 0) {
        cout << n/2 << endl;
    } else {
        cout << n/2+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
int main()
{
    fastio();
  
    ll n,k;
    cin>>n>>k;
    ll dp[n+1]={0},pre[n+1]={0};
    dp[1]=1;
    pre[1]=1;
    std::vector<pair<int,int>> v(k);
    for(int i=0;i<k;i++)
        cin>>v[i].ff>>v[i].ss;
    for(int i=2;i<=n;i++)
    {
        //cout<<i<<endl;
        for(int j=0;j<k;j++)
        {
            int r = i-v[j].ff,l = max(i-v[j].ss-1,0);
            //cout<<j<<" "<<l<<" "<<r<<endl;
            if(r<0)
                continue;
           // cout<<dp[r]<<" "<<dp[l]<<endl;
            dp[i] += pre[r]-pre[l]+MOD2*3LL;
            dp[i]%= MOD2;
            
            pre[i]%=MOD2; 
        }
        pre[i] = dp[i]+pre[i-1];
    }
   // oa(dp,n+1);
    //oa(pre,n+1);
    cout<<dp[n]<<endl;
    
}

Measured memory_bytes: 6764
#include<stdio.h>
int main()
{
	int N,a,b,c,i,j;
	int a1[1000];
	int b1[1000];
	int c1[1000];
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d %d %d",&a,&b,&c);
		a1[i]=a;b1[i]=b;c1[i]=c;
	}
	for(i=0;i<N;i++)
	{
		if((a1[i]*a1[i])+(b1[i]*b1[i])==(c1[i]*c1[i]))
		{
			printf("YES");
		}
		else if((b1[i]*b1[i])+(c1[i]*c1[i])==(a1[i]*a1[i]))
		{
			printf("YES");
		}
		else if((c1[i]*c1[i])+(a1[i]*a1[i])==(b1[i]*b1[i]))
		{
			printf("YES");
		}
		else
		{
			printf("NO");
		}
		puts("");
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	vector <int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
	}	
	set <ll> st;
	for(int i = 0; i < n; i++){
		ll curr = 0;
		for(int j = i; j < n; j++){
			curr += v[j];
			st.insert(curr);
		}
	}
	ll res = 0;
	for(int i = 63; i >= 0; i--){
		int cnt = 0;
		for(auto x : st){
			if(x & (1LL << i)) cnt++;
		}
		if(cnt >= k){
			res += (1LL << i);
			for(auto it = st.begin(); it != st.end();){
				if(!(*it & (1LL << i))) it = st.erase(it);
				else it++;
			}
		}
	}
	cout << res;
}

Measured memory_bytes: 23680
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mod 1000000007
using namespace std;
ll binpow(ll x,ll y)/* (x^y)%p in O(log y) */{ll res=1;while (y > 0){if(y&1)res=(res*x);y = y>>1;x=(x*x);}return res;}
ll binpowmod(ll x,ll y,ll p)/* (x^y)%p in O(log y) */{ll res=1;x=x%p;while (y > 0){if(y&1)res=(res*x)%p;y = y>>1;x=(x*x)%p;}return res;}
ll mod_inverse(ll n,ll p)/* Returns n^(-1) mod p */{return binpowmod(n,p-2,p);}
ull gcd(ull x,ull y)
{
    if(y==0)
        return x;
    return gcd(y,x%y);
}
bool comp(pair<int,int> x,pair<int,int> y)
{
    if(x.first<y.first)
        return true;
    else if(x.first==y.first)
        return x.second>y.second;
    else
        return false;
}
bool comp_pairs_by_s(pair<ll,ll> &x ,pair<ll,ll> &y)
{
    return x.second<y.second;
}
bool isPowerOfTwo (ll x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}

class cmp      //comparator for priority_queue 
{               //declaration: priority_queue<int,vector<int>,cmp>
public:         
    bool operator()(pair<int,int> A,pair<int,int> B)
    {
        if(abs(A.first-A.second)==abs(B.first-B.second))
            return A.first>B.first;
        return abs(A.first-A.second)<abs(B.first-B.second);
    }
};
// int prime[100005]={0};
// void sieve(void)
// {
//  int i,j;
//  for(i=0;i<100005;i++)
//         prime[i]=1;
//  prime[0]=0,prime[1]=0;
//  for(i=2;i<=sqrt(100005);i++){
//      if(prime[i]){
//          for(j=i*i;j<100005;j+=i){
//              prime[j]=0;
//          }
//      }
//  }
    
// }
void swap(int &x,int &y){
    int temp=x;
    x=y;
    y=temp;
}
vector<ll> stree;
ll dp[2000001];
void solve()
{   
    int n;
    cin>>n;
    vector<int> h(n);
    vector<ll> a(n);
    for(auto &it : h)
        cin>>it;
    for(auto &it : a)
        cin>>it;
    int base=1;
    while(base<=n)
        base*=2;
    stree.resize(2*base,0);
    //cout<<base;
    for(int i=0;i<n;i++){
        //find the max height in [0,h[i])
        int r=h[i]+base;
        ll best=0;
        while(r>0){
            if(r%2)
                best=max(best,(ll)stree[--r]);
            r/=2;
        }
        dp[h[i]]=best+a[i];
        //update segment tree with dp[h[i]];
        r=h[i]+base;
        stree[r]=dp[h[i]];
        r/=2;
        while(r>0){
            stree[r]=max(stree[2*r],stree[2*r+1]);
            r/=2;
        }
    }
    ll ans=0;
    for(int i=0;i<2000001;i++){
        ans=max(ans,dp[i]);
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}


Measured memory_bytes: 8320
n=int(input())
d=list(map(int,input().split()))
mod=998244353
from collections import Counter
q=Counter(d)
if q[0]!=1 or d[0]!=0:
	print(0)
	exit()
ans=1
for i in range(1,max(q)+1):
    ans *=pow(q[i-1],q[i],mod)
    ans %=mod
print(ans)

Measured memory_bytes: 18932
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */


/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    
    public static void main (String[] args) throws java.lang.Exception
    {
        Scanner s=new Scanner(System.in);
        
            
            int n=s.nextInt();
  
            int a[]=new int[n];
            int b[]=new int[n];
      for(int i=0;i<n;i++){
                a[i]=s.nextInt();
        b[i]=s.nextInt();
      }
      double d=0.0;
      
      for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
          d+=Math.sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]));
        }
      }
      System.out.format("%.6f",(2*d)/n);
    }
}

Measured memory_bytes: 21716
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  char a, b;
  cin >> a >> b;
  cout << (a == b ? 'H' : 'D') << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
//#include<string.h>
//#include<math.h>
//#include<algorithm>
//using namespace std;
int main()
{
	long long int n,c;
	int i,sum,t;
	while(scanf("%d",&n)!=EOF)
	{
		sum=0;
		c=n;
		while(c)
		{
			t=c%10;
			c=c/10;
			sum+=t;
		}
		if(n%sum==0) printf("Yes\n");
		else   printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main() {
    int ans=0;
    vi a(10,0);
    string s;
    cin>>s;
    rep(i,s.size()){
        if(s.at(i)=='A'||s.at(i)=='C'||s.at(i)=='G'||s.at(i)=='T'){
            a.at(i)=1;
        }
    }
    rep2(i,1,10){
        if(a.at(i)==1)a.at(i)+=a.at(i-1);
    }
    rep(i,10){
        ans=max(ans,a.at(i));
    }
    cout<<ans<<endl;
    
}



Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	int n;
	scanf("%d",&n);
	ll arr[n];

	for(int i=0;i<n;i++) scanf("%lld",&arr[i]);

	for(int i=n-1;i>=0;i-=2) cout<<arr[i]<<" ";
	int idx = 1;
	if(n%2==0) idx = 0;

	for(idx;idx<n;idx+=2) cout<<arr[idx]<<" ";
	
}

Measured memory_bytes: 3712
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let (n,m) = get!(usize, usize);
    let a = get!([usize]);
    let sum = a.iter().sum::<usize>();

    let mut count = 0usize;
    for e in a {
        if e*4*m >= sum {
            count += 1;
        }
    }
    if count >= m {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 8572
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    A.sort()
    from collections import Counter, defaultdict
    c = defaultdict(int)
    for k, v in Counter(A).items():
        c[k] = v
    ans = 0
    for i in range(10**5+1):
        if i != 0:
            cur = c[i] + c[i-1] + c[i+1]
        else:
            cur = c[i] + c[i+1]
        ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
	int A, B, C, X, ans = 0; cin >> A >> B >> C >> X;
	
	for( int a = 0; a <= A; a++ )
	for( int b = 0; b <= B; b++ )
	for( int c = 0; c <= C; c++ ){
		if( 500*a + 100*b + 50*c == X) ans++;
	}
	
	
	cout << ans << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
dice = [int(i+1) for i in range(n)]
point = 0
prob = 0
ans = 0
for i in range(n):
    point += dice[i]
    prob += 1/n

    while point <= k-1:
        point *= 2
        prob *= 0.5

    ans += prob
    point = 0
    prob = 0

print(ans)


Measured memory_bytes: 7064
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n;
    cin >> n;
    if (n >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3132
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<math.h>
#include<queue>
#include<functional>
#include<limits.h>
#define int long long
using namespace std;

signed main() {
	int a, b; cin >> a >> b;
	int ans = LLONG_MAX;
	if (a % 3 == 0 || b % 3 == 0)ans = 0;
	ans = min({ ans,a,b });
	for (int i = 1; i < a; i++) {
		ans = min(ans, max(b*i, (b - b / 2)*(a - i)) - min(b*i, b / 2 * (a - i)));
	}
	for (int j = 1; j < b; j++) {
		ans = min(ans, max(a*j, (a - a / 2)*(b - j)) - min(a*j, a / 2 * (b - j)));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f[5050],a[5050],n,k,sum=0;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]),a[i]=min(a[i],k),sum+=a[i];
    sort(a+1,a+n+1);f[0]=1;
	for(int i=n;~i;--i){
        bool check=true;
        for(int j=k-1;j>=k-sum&&j>=0;--j)if(f[j]){check=false;break;}
        if(check){printf("%d",i);return 0;}
        for(int j=k;j>=a[i];--j)f[j]|=f[j-a[i]];
        sum-=a[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef unsigned long ul;



char rot(int n, char c){
  map<int, char> t;
  t[0] = 'A';
  t[1] = 'B';
  t[2] = 'C';
  t[3] = 'D';
  t[4] = 'E';
  t[5] = 'F';
  t[6] = 'G';
  t[7] = 'H';
  t[8] = 'I';
  t[9] = 'J';
  t[10] = 'K';
  t[11] = 'L';
  t[12] = 'M';
  t[13] = 'N';
  t[14] = 'O';
  t[15] = 'P';
  t[16] = 'Q';
  t[17] = 'R';
  t[18] = 'S';
  t[19] = 'T';
  t[20] = 'U';
  t[21] = 'V';
  t[22] = 'W';
  t[23] = 'X';
  t[24] = 'Y';
  t[25] = 'Z';
  map<char, int> tinv;
  tinv['A'] = 0;
  tinv['B'] = 1;
  tinv['C'] = 2;
  tinv['D'] = 3;
  tinv['E'] = 4;
  tinv['F'] = 5;
  tinv['G'] = 6;
  tinv['H'] = 7;
  tinv['I'] = 8;
  tinv['J'] = 9;
  tinv['K'] = 10;
  tinv['L'] = 11;
  tinv['M'] = 12;
  tinv['N'] = 13;
  tinv['O'] = 14;
  tinv['P'] = 15;
  tinv['Q'] = 16;
  tinv['R'] = 17;
  tinv['S'] = 18;
  tinv['T'] = 19;
  tinv['U'] = 20;
  tinv['V'] = 21;
  tinv['W'] = 22;
  tinv['X'] = 23;
  tinv['Y'] = 24;
  tinv['Z'] = 25;
  return t[(tinv[c] + n)%26];
}

int main(int argc, char const *argv[]) {
  int N;
  string S, ans;
  cin >> N;
  cin >> S;
  for(int i = 0; i < S.length(); i++){
    ans.push_back(rot(N, S[i]));
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
//
// Created by yamunaku on 2019/11/05.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n;
    ll k;
    cin >> n >> k;
    vl a(n),f(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> f[i];
    }
    sort(all(a));
    sort(all(f),greater<ll>());
    ll l=-1, r=LINF;
    while(r-l>1){
        ll mid = (l+r)/2;
        ll cost = 0;
        rep(i,n){
            cost+=max(0ll,a[i] - mid/f[i]);
        }
        if(cost>k){
            l = mid;
        }else{
            r = mid;
        }
    }
    cout << l+1 << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    if(n==1 && m==1) cout << 1 << endl;
    else if(n==1) cout << m-2 << endl;
    else if(m==1) cout << n-2 << endl;
    else cout << (n-2)*(m-2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S;
    cin>>S;
    if(S[0]=='Y'&&S[1]=='A'&&S[2]=='K'&&S[3]=='I'){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

int main(){fastio
    
    ll a[8]={2,3,4,6,8,9,10,12};
    ll n;cin>>n;
    
    if(n==3){
        cout<<"2 5 63"<<endl;return 0;
    }
    if(n==4){
        cout<<"2 5 20 63"<<endl;return 0;
    }
    
    rep(i,1,n/8){
        rep(j,0,7){
            cout<<(i-1)*12+a[j]<<" ";
        }
    }
    ll add=(n/8)*12;
    rep(i,0,(1<<8)-1){
        ll sum=0;
        ll c=0;
        rep(j,0,7){
            if((i>>j)&1){
                sum+=a[j];
                c++;
            }
        }
        if(abs(c-n)%8==0){
            if(sum%6==0){
                rep(j,0,7){
                    if((i>>j)&1){
                        cout<<add+a[j]<<" ";
                    }
                }
                return 0;
            }
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 384
-- We love math.
import Control.Applicative
shichigosan :: Int -> String
shichigosan 3 = "YES"
shichigosan 5 = "YES"
shichigosan 7 = "YES"
shichigosan x = "NO"
main :: IO ()
main = do
    a <- readLn
    --整数

    putStrLn (shichigosan a)


Measured memory_bytes: 508
#include "bits/stdc++.h"

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)
typedef long long ll;

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);
ll gcd(ll a, ll b);

int main() {
    ll n, k;
    cin >> n >> k;

    ll numerator = 0;
    ll denominator = 1;

    for(ll i=1; i<=n; i++) {
        ll tmp = i;
        int deno = 0;
        while(tmp < k) {
            tmp *= 2;
            deno++;
        }
        ll common_multiple = denominator * pow(2, deno);
        numerator = numerator * (common_multiple / denominator) + common_multiple / pow(2, deno);
        denominator = common_multiple; 
        ll gcd_ = gcd(denominator, numerator);
        numerator /= gcd_;
        denominator = denominator/gcd_;
        //cout << "deno: " << deno << endl;
        //cout << "common: " << common_multiple << endl;
        //cout << "numerator: " << numerator << endl;
        //cout << "denominator: " << denominator << endl << endl;
    }
    cout << setprecision(14)  << (double(numerator) / denominator) / (double) n  << endl;
    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

int sum_digits(int num) {
    int rtn = 0;
    while(num != 0) {
        int tmp = num % 10; 
        rtn += tmp;
        num /= 10; 
    }   
    return rtn;
}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}

// ユークリウッドの互除法
ll gcd(ll a, ll b) {
    if(b==0) return a;
    else return gcd(b, a % b);
}



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

using namespace std;

#define int long long

const int N = 1e5 + 10;

vector<int> g[N];
int dp[N], ans = 0;

void dfs(int v)
{
	dp[v] = 1;
	for (auto to: g[v])
	{
		if (!dp[to])
			dfs(to);
		dp[v] = max(dp[v], dp[to] + 1);
	}

	ans = max(ans, dp[v]);
}

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

	int n, m, a, b;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
	}

	for (int i = 0; i < n; i++)
		if (!dp[i])
			dfs(i);
	cout << ans - 1 << endl;

	return 0;
}


Measured memory_bytes: 8576
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <cmath> 
#include <algorithm>
using namespace std; 
inline int gi() {
    register int data = 0, w = 1;
    register char ch = 0;
    while (!isdigit(ch) && ch != '-') ch = getchar(); 
    if (ch == '-') w = -1, ch = getchar(); 
    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); 
    return w * data; 
} 
const int MAX_N = 1e5 + 5; 
int N, MAX, a[MAX_N], b[MAX_N]; 
long long goal_rank;
int c[MAX_N << 2]; 
inline int lb(int x) { return x & -x; } 
void add(int x, int v) { while (x <= MAX) c[x] += v, x += lb(x); } 
int sum(int x) { int res = 0; while (x) res += c[x], x -= lb(x); return res; } 
bool check(int mid) { 
	static int s[MAX_N]; 
	for (int i = 1; i <= N; i++) { 
		int op; 
		if (a[i] > mid) op = 1; 
		if (a[i] <= mid) op = -1; 
		s[i] = s[i - 1] + op; 
	} 
	long long res = 0; 
	MAX = N << 2; 
	int T = N << 1; 
	for (int i = 1; i <= N; i++) { 
		int pos = s[i] + T; 
		res += sum(MAX) - sum(pos); 
		add(pos, 1); 
	} 
	memset(c, 0, sizeof(c)); 
	return res >= goal_rank; 
} 
bool cheque(int mid) { 
	static int s[MAX_N]; 
	for (int i = 1; i <= N; i++) { 
		int op; 
		if (a[i] > mid) op = 1; 
		if (a[i] < mid) op = -1; 
		if (a[i] == mid) op = 0; 
		s[i] = s[i - 1] + op; 
	} 
	long long res = 0; 
	MAX = N << 2; 
	int T = N << 1;
	add(T, 1); 
	for (int i = 1; i <= N; i++) { 
		int pos = s[i] + T; 
		res += sum(MAX) - sum(pos); 
		add(pos, 1); 
	} 
	memset(c, 0, sizeof(c)); 
	return res >= goal_rank; 
} 

int main () {
	N = gi(); for (int i = 1; i <= N; i++) a[i] = b[i] = gi(); 
	sort(&b[1], &b[N + 1]); 
	goal_rank = 1ll * N * (N - 1) / 2 + N; 
	goal_rank = goal_rank / 2; 
	int l = 1, r = N, ans = 1; 
	while (l <= r) {
		int mid = (l + r) >> 1;  
		if (check(b[mid])) r = mid - 1, ans = mid; 
		else l = mid + 1; 
	}
	l = 1, r = N;
	int res = 1; 
	while (l <= r) { 
		int mid = (l + r) >> 1;  
		if (cheque(b[mid])) r = mid - 1, res = mid; 
		else l = mid + 1; 
	} 
	printf("%d\n", b[min(ans, res)]); 
    return 0; 
} 

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

int main() {
    string s, t;
    cin >> s >> t;
    int ans = t.size();
    rep(i, s.size()) {
        if(i + t.size() > s.size()) break;
        int cnt = 0;
        rep(j, t.size()) if(s[i + j] != t[j]) cnt++;
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3564
n, b, r = map(int, input().split())
i = 0
hoge = n // (b+r)
count = hoge*b
n = n - hoge*(b+r)
if n == 0:
    print(count)
while (n>i):
    count += b
    i += b
    if n<=i:
        print(count - (i-n))
        break
    i += r
    if n<=i:
        print(count)

Measured memory_bytes: 3064
//package atcoder;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(System.in);
        final int x1 = in.nextInt();
        final int x2 = in.nextInt();
        final int x3 = in.nextInt();
        final int x4 = in.nextInt();
        final int x5 = in.nextInt();
        if (x1 == 0) {
            System.out.println(1);
        }
        if (x2 == 0) {
            System.out.println(2);
        }
        if (x3 == 0) {
            System.out.println(3);
        }
        if (x4 == 0) {
            System.out.println(4);
        }
        if (x5 == 0) {
            System.out.println(5);
        }
    }
}


Measured memory_bytes: 35616
a_list=[]
b_list=[]
while True:
  a,b = map(int, input().split())
  if a == 0 and b == 0: 
    break
  a_list.append(a)
  b_list.append(b)


  

for (alist, blist) in zip(a_list,b_list):
  if alist < blist:
    print(alist, blist)
  else:
    print(blist,alist)
  


Measured memory_bytes: 6120
#include <iostream>	

struct Rect {
	int width;
	int height;
	int max_width;
	int max_height;
	Rect() : width(0), height(0), max_width(0), max_height(0) {}
};

void show(Rect** DP, int H, int W)
{
	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) std::cout << DP[i][j].width << "," << DP[i][j].height << " ";
		std::cout << std::endl;
	}
}

int main()
{
	int W, H;
	while (std::cin >> H >> W) {
		
		if (W==0) break;
	
		char** board = new char*[H];
		for (int i=0; i<H; i++) board[i] = new char[W];
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) std::cin >> board[i][j];
		}
		
		Rect** DP = new Rect*[H];
		for (int i=0; i<H; i++) DP[i] = new Rect[W];
		
		int max = 0;
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) {
				if (board[i][j] == '*') continue;
				if (i>0) {
					if (j>0) {
						DP[i][j].max_width = DP[i][j-1].max_width + 1;
						DP[i][j].max_height = DP[i-1][j].max_height + 1;
						int w = DP[i][j].max_width;
						int max_area = DP[i][j].max_height; // DP[i][j].max_height * 1
						int max_w = 1;
						int max_h = DP[i][j].max_height;
						for (int h=2; h<=DP[i][j].max_height; h++) {
							w = std::min(w, DP[i-h+1][j].max_width);
							if (max_area < h*w) {
								max_area = h*w;
								max_w = w;
								max_h = h;
							}
						}
						DP[i][j].width = max_w;
						DP[i][j].height = max_h;
					}
					else { // j==0
						DP[i][j].height = DP[i-1][j].height + 1;
						DP[i][j].max_height = DP[i-1][j].max_height + 1;
						DP[i][j].width = 1;
						DP[i][j].max_width = 1;
					}
				}
				else { // i==0
					DP[i][j].height = 1;
					DP[i][j].max_height = 1;
					if (j>0) {
						DP[i][j].width = DP[i][j-1].width + 1;
						DP[i][j].max_width = DP[i][j-1].max_width + 1;
					} else {
						DP[i][j].width = 1;
						DP[i][j].max_width = 1;
					}
				}
				
				if (max < DP[i][j].width * DP[i][j].height) {
					max = DP[i][j].width * DP[i][j].height;
				}
			}
		}
		//show(DP, H, W);
		std::cout << max << std::endl;
		
		for (int i=0; i<H; i++) delete[] board[i];
		delete[] board;
		for (int i=0; i<H; i++) delete[] DP[i];
		delete[] DP;
	}
	
	return 0;
}




Measured memory_bytes: 6952
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  string str;
  cin>>str;
  ll n=str.size();
  ll sum=0;
  for(ll i=0;i<n;i++)
    sum+=str[i]-'0';
  if(sum%9==0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3724
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br =  new BufferedReader(new InputStreamReader(System.in));
		
		for(int i = 1; i <= 9; i++){
			for(int j = 1; j <= 9; j++){
				System.out.println(i + "x" + j + "=" + (i * j));
			}
		}
	}

}

Measured memory_bytes: 16868
let rec list_sum res = function | [] -> res | l::ls -> list_sum (l+res) ls

let _ =
  let n, m, c = Scanf.scanf "%d %d %d\n" (fun n m c -> (n, m, c)) in
  let res = Array.make n 0 in
  let bs = Array.make m 0 in
  for i=0 to m-1 do
    Scanf.scanf (if i=(m-1) then "%d\n" else "%d ") (fun b -> bs.(i) <- b)
  done;
  for i=0 to n-1 do
    let temp = ref 0 in
    for j=0 to m-1 do
      Scanf.scanf (if j=(m-1) then "%d\n" else "%d ") 
        (fun a -> temp := !temp + a * bs.(j))
    done;
    res.(i) <- if !temp + c > 0 then 1 else 0
  done;
  list_sum 0 (Array.to_list res) |> print_int

Measured memory_bytes: 512
while True:
    try:
        x=input()
        a=b=0
        for i in range(len(x)-2):
            if x[i]=="J" and x[i+1]=="O" and x[i+2]=="I":
                a+=1
            if x[i]=="I" and x[i+1]=="O" and x[i+2]=="I":
                b+=1
        print(a)
        print(b)
    except EOFError: break


Measured memory_bytes: 5572
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    int N;

    gc(N);

    vector<int> X(100000, 0);

    int mx = -1;

    for (int i = 0; i < N; i++)
    {
        int tmp;
        gc(tmp);

        if (tmp - 1 < 0)
        {
            X[tmp]++;
            X[tmp + 1]++;

            mx = max(X[tmp], mx);
            mx = max(X[tmp + 1], mx);
        }
        else if (100000 <= tmp + 1)
        {
            X[tmp - 1]++;
            X[tmp]++;

            mx = max(X[tmp - 1], mx);
            mx = max(X[tmp], mx);
        }
        else
        {
            X[tmp - 1]++;
            X[tmp]++;
            X[tmp + 1]++;

            mx = max(X[tmp - 1], mx);
            mx = max(X[tmp], mx);
            mx = max(X[tmp + 1], mx);
        }
    }

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


Measured memory_bytes: 640
#pragma region include
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <cstdio>
#include <tuple>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD 1000000007
#define INF 1000000000
#define LLINF 4000000000000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename F, typename... R>void input(F& f, R&... r) { cin >> f; input(r...); }
template<typename F, typename... R>void input(vector<F>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

int main() {
    int X, A;
    cin >> X >> A;
    if (X < A) {
        cout << 0 << endl;
    }
    else{
        cout << 10 << endl;
    }
    getchar(); getchar();
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int, int> prii;

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

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    int N;
    cin >> N;

    ll dp[90];
    dp[0] = 2, dp[1] = 1;
    REP(i, 2, N+1) {
        dp[i] = dp[i-1] + dp[i-2];
    }

    cout << dp[N] << endl;
    return 0;
}


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

using namespace std;

bool check(int x, int k, int n, int* arr){
	int op = 0;
	int rem[n];
	for(int i = 0 ; i < n ; i++){
		rem[i] = arr[i] % x;
	}	
	sort(rem, rem + n);
	int left = 0, right = n - 1;
	while(left < right){
		if(rem[left] <= x - rem[right]){
			op += rem[left];
			rem[right] += rem[left];
			++left;
		}else{
			op += x - rem[right];
			rem[left] -= x - rem[right];
			--right;
		}
	}
	if(op > k) 
		return false;
	return true;
}

int main(){
	int n, k, sum = 0, ans = 0;
	scanf("%d %d", &n, &k);
	int a[n];
	for(int i = 0 ; i < n ; i++){
		scanf("%d", a + i);
		sum += a[i];
	}
	for(int i = 1 ; i * i <= sum ; i++){
		if(sum % i == 0){
			if(check(i, k, n, a)){
				ans = max(ans, i);
			}
			if(check(sum / i, k, n, a)){
				ans = max(ans, sum / i);
			}
		}		
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
N=int(input())
listA=list(map(int,input().split()))
listB=[abs(i) for i in listA]
MAX=max(listA)
MIN=min(listA)
ans=sum(listB)
if MAX<=0:
  print(ans+MAX*2)
elif MIN<=0:
  print(ans)   
else:
  print(ans-MIN*2)
listC=sorted(listA)  
for i in range(len(listA)-2):
  if listC[i+1]>=0:
    print(MIN,listC[i+1])
    MIN=MIN-listC[i+1]
  else:
    print(MAX,listC[i+1])
    MAX=MAX-listC[i+1]
print(MAX,MIN)

Measured memory_bytes: 14144
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
typedef pair<long, long> P;

bool cmp(P a, P b)
{
  return a.first < b.first;
}

int main()
{
  long N, M;
  cin >> N >> M;
  vector<P> vc(N);
  for (int i = 0; i < N; i++)
  {
    long A, B;
    cin >> A >> B;
    vc[i] = make_pair(A, B);
  }
  sort(vc.begin(), vc.end(), cmp);
  long ans = 0;
  for (int i = 0; i < N; i++)
  {
    long t = min(M, vc[i].second);
    ans += vc[i].first * t;
    M -= t;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1920
// template.cpp {{{
#include <bits/stdc++.h>
using namespace std;

using lint = long long;
#define reps(i, a, n) for (lint i = (a); i < (lint)(n); ++i)
#define rep(i, n) reps(i, 0, n)
struct pre_{pre_(){cin.tie(0);ios::sync_with_stdio(0);}} pre__;
// }}}
bool used[10];
vector<int> t(9);
int res = 0;

void check(vector<int> m) {
  int g = 0, h = 0, i = 0;
  i += m[0] + m[2] + m[5];
  h += i / 10;
  i %= 10;
  h += m[1] + m[4];
  g += h / 10;
  h %= 10;
  g += m[3];
  if (g == m[6] && h == m[7] && i == m[8]) {
    res++;
  }
}

void dfs(int idx, vector<int> v) {
  if (idx == 10) {
    check(v);
    return;
  }
  if (t[idx] != -1) {
    dfs(idx + 1, v);
  }
  rep(i, 9) {
    if (!used[i + 1]) {
      used[i + 1] = true;
      v[idx] = i + 1;
      dfs(idx + 1, v);
      used[i + 1] = false;
    }
  }
}

signed main() {
  rep(i, 9) {
    cin >> t[i];
    if (t[i] == -1) continue;
    used[t[i]] = true;
  }
  dfs(0, t);

  cout << res << endl;
}

Measured memory_bytes: 3204
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int s = sc.nextInt();
        boolean flag = s == Math.pow(10, 9);
        for (int i = 0; i < k; i++) {
            System.out.print(s + " ");
        }
        for (int i = 0; i < n-k; i++) {
            if (flag) {
                System.out.println(1 + " ");
            } else {
                System.out.println(s+1 + " ");
            }
        }
    }
}

Measured memory_bytes: 55396
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int a, b, c;
int k;

bool solve() {
    int p = 0;
    while (b <= a) {
        b *= 2;
        p++;
    }
    while (c <= b) {
        c *= 2;
        p++;
    }
    return p <= k;
}

void input() {
    cin >> a >> b >> c >> k;
}

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

    input();
    cout << (solve()?"Yes":"No") << endl;
}


Measured memory_bytes: 3072
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){
    int n;
    cin >> n;
    int x[n]={};
    int y[n]={};
    
    for (int i=0;i<n;i++){
        cin >> x[i];
    }
    for (int j=0;j<n;j++){
        cin >> y[j];
    }
    double D1,D2,sum2,D3,sum3,Dinf;
    double a[n] = {};
    for (int k=0;k<n;k++){
        a[k] = fabs(x[k] - y[k]);
        D1 += a[k];
        sum2 += a[k]*a[k];
        sum3 += a[k]*a[k]*a[k];
        if (Dinf < a[k]){
            Dinf = a[k];
        }
    }
    
    D2 = sqrt(sum2);
    D3 = cbrt(sum3);
    printf("%.5f\n",D1);
    printf("%.5f\n",D2);
    printf("%.5f\n",D3);
    printf("%.5f\n",Dinf);
    
    return 0;
}


Measured memory_bytes: 3396
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s[3]{"Sunny","Cloudy","Rainy"},m;
    cin>>m;int i;
    for(i=0;i<3;i++)
        if(m==s[i])break;
    cout<<s[(i+1)%3];
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>//我爱万能头 
using namespace std;
string a[101];int n,i;
int main(){
    scanf("%d%*d",&n);//sao操作所在地 
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);//虽然会其他排序方法但懒得打QwQ 
    for(i=0;i<n;i++)
        cout<<a[i];
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin >> n >> k;
	int c[60];
	for(int i=0;i<n;i++){
		cin >> c[i];
	}
	sort(c,c+n);
	reverse(c,c+n);
	int count=0;
	for(int i=0;i<k;i++){
		count+=c[i];
	}
	cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
N,K=map(int, sys.stdin.readline().split())
A=[ int(sys.stdin.readline().strip()) for _ in range(N) ]
max_A=max(A)

# 処理する区間の長さはmax_A
N0 = 2**(max_A).bit_length()
init_val = 0
data = [init_val]*(2*N0)
# a_k の値を x に更新
def update(k, x):
    k += N0-1
    data[k] = x
    while k > 0:
        k = (k - 1) / 2
        data[k] = max(data[2*k+1], data[2*k+2])
# 区間[l, r)の最大値
def query(l, r):
    L = l + N0; R = r + N0
    s = init_val
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])

        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

for i,a in enumerate(A):
    update(a,query(max(a-K,0),min(a+K+1,max_A+1))+1)

print query(0,max_A+1)


Measured memory_bytes: 123592
N = int(input())
ans = [11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381]
print(' '.join(map(str, ans[:N])))

Measured memory_bytes: 3064
//Shivam gupta (Codeforces handle : shivam_1999)

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define ll long long
#define ld long double
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef pair<long long, long long> pii;
typedef vector<pair<long long, long long>> vpii;
typedef map<long long, long long> mii;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(x) x.begin(), x.end()
#define sorta(x) sort(x.begin(),x.end())
#define sortd(v) sort(all(v), greater<ll>())
#define el cout << endl;
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define cpresent(container, element) (find(all(container), element) != container.end())
#define deb(x) cout << #x << x << endl;
#define fl(i,n) for(ll i=0;i<n;i++)
#define fls(i,x,n) for(ll i=x;i<n;i++)
#define flr(i,n)  for(ll i=n-1;i>=0;i--)
#define fla(i,v)  for(auto i:v)    
#define in(v) for(auto &i:v){cin>>i;}
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define tt    \
    int T;    \
    cin >> T; \
    while (T--)

int main()
{   fast
    ll n;
    cin >> n;
    vi a(n),b(n),c(n);
    fl(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }
    ll dp[n][3];
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    fls(i,1,n){
        fl(j,3){
            if (j == 0)
                dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
            if (j == 1)
                dp[i][j] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
            if (j == 2)
                dp[i][j] = max(dp[i - 1][1], dp[i - 1][0]) + c[i];
        }
    }
    cout << max3(dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]) << endl;
}

Measured memory_bytes: 7936