akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

int mainmain(){
	string s;
	cin>>s;
	int n = s.size();
	int l = 0;
	int r = n-1;
	int ans = 0;
	while(1){
		if(s[l]==s[r]) l++,r--;
		else if(s[l]!='x'&&s[r]!='x') return -1;
		else if(s[l]=='x'){
			ans++;
			l++;
		}
		else{
			ans++;
			r--;
		}
		if(l>=r) return ans;
	}
	// while(1){
	// 	int a = 0;
	// 	int b = 0;
	// 	while(l<n&&s[l]=='x') l++,a++;
	// 	while(r>=0&&s[r]=='x') r--,b++;
	// 	if(l==r){
	// 		ans += max(a,b);
	// 		return ans;
	// 	}
	// 	else if(r<l){
	// 		return ans;
	// 	}
	// 	else{
	// 		if(s[l] != s[r]) return -1;
	// 	}
	// 	ans += max(a,b);
	// 	l++;
	// 	r--;
	// }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    cout<<mainmain()<<endl;
}

Measured memory_bytes: 512
n, k = map(int,input().split())
s = input()
l = s[k - 1]
if l == "A":
    x = s[:(k - 1)] + "a" + s[k:]
elif l == "B":
    x = s[:(k - 1)] + "b" + s[k:]
else:
    x = s[:(k - 1)] + "c" + s[k:]
print(x)

Measured memory_bytes: 9180
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String sb1 = s.substring(0, 2);
		String sb2 = s.substring(2);
		
		int first = Integer.parseInt(sb1);
		int second = Integer.parseInt(sb2);
		
		String ans = "NA";
		if(first > 0 && first <= 12 && second > 0 && second <= 12) ans = "AMBIGUOUS";
		else if(first > 0 && first <= 12) ans = "MMYY";
		else if(second > 0 && second <= 12) ans = "YYMM";
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

    cin>>n;

    for(i=1; i<=n; i++)
    {
        str=to_string(i);

        if(str.size()&1)ans++;
    }

    cout<<ans<<endl;













}



Measured memory_bytes: 3668
#include <stdio.h>

int num(int n)
{
	int cnt;
	
	if (n < 0){
		return (0);
	}
	if (n == 0){
		return (1);
	}
	
	cnt = (num(n - 3) + num(n - 2) + num(n - 1));
	
	return (cnt);
}

int main(void)
{
	int n, m;
	
	while (scanf("%d", &n), n != 0){
		m = num(n);
		m = m / 3650 + (m % 3650 > 0);
		
		printf("%d\n", m);
	}
	
	return (0);
}

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

void Push(int);
int Pop();
int t,P[199];
int main(int argc,char *argv[]){
  int a,b;
  char p[100];
  t=0;
  while(scanf("%s",p)!=EOF){
    if(p[0]=='+'){
      a=Pop();
      b=Pop();
      Push(a+b);
    }
    else if(p[0]=='-'){
      b=Pop();
      a=Pop();
      Push(a-b);
    }
    else if(p[0]=='*'){
      a=Pop();
      b=Pop();
      Push(a*b);
    }
    else Push(atoi(p));
  }
  printf("%d\n",Pop());
  return 0;
}

void Push(int a){
  P[++t]=a;
}

int Pop(){
  t--;
  return P[t+1];
}



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

int main() {
	int N, M;

	cin >> N >> M;
	vector<int>A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}
	vector<pair<int, int>>BC( M );
	for( int i = 0; i < M; i++ ) {
		cin >> BC[i].second >> BC[i].first;
	}

	sort( A.begin(), A.end() );
	sort( BC.begin(), BC.end(), greater<pair<int, int>>() );
	vector<int>D;
	for( int i = 0; i < M; i++ ) {
		int c = BC[i].first;
		for( int j = 0; j < BC[i].second; j++ ) {
			if( D.size() >= N ) {
				break;
			}
			if( c < A[D.size()] ) {
				break;
			}
			D.push_back( c );
		}
	}
	long long ans = 0;
	for( int i = 0; i < D.size(); i++ ) {
		ans += D[i];
	}
	for( int i = D.size(); i < N; i++ ) {
		ans += A[i];
	}

	cout << ans << endl;

	return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

ll gcd(ll a,ll b){
	if(a<b){
		swap(a,b);
	}

	while(ll r=(a%b)){
		a = b;
		b = r;
	}
	return b;
}

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

	int N=in();
	vector<ll> A(N);
	ll neg_num = 0;
	ll min_abs = 1e9+7;
	ll sum = 0;
	REP(i,N){
		A[i] = in<ll>();
		min_abs = min(min_abs,abs(A[i]));
		if(A[i]<0) neg_num++;
		sum += abs(A[i]);
	}
	if(neg_num%2 && min_abs){
		sum -= 2*min_abs;
	}

	cout << sum << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

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

    string s,t;
    int a,b;
    string u;
    cin>>s>>t>>a>>b>>u;
    if(s==u)
        a--;
    else
        b--;
    cout<<a<<" "<<b;
}


Measured memory_bytes: 256
use std::io::{self, BufRead};
fn main() {
    let stdin = io::stdin();
    let mut handle = stdin.lock();
    let mut buf = String::new();
    handle.read_line(&mut buf).unwrap();
    let tmp = buf
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<usize>().unwrap())
        .collect::<Vec<_>>();
    let N = tmp[0];
    let M = tmp[1];
    buf.clear();

    let LRD = {
        let mut ret = Vec::with_capacity(M);
        for i in 0..M {
            handle.read_line(&mut buf).unwrap();
            let tmp = buf
                .trim()
                .split_whitespace()
                .map(|x| x.parse::<usize>().unwrap())
                .collect::<Vec<_>>();
            ret.push((tmp[0] - 1, tmp[1] - 1, tmp[2] as i64));
            buf.clear();
        }
        ret
    };

    let mut edges = Vec::new();
    for _ in 0..N {
        edges.push(vec![]);
    }
    for &(l, r, d) in &LRD {
        edges[l].push((r, d));
        edges[r].push((l, -d));
    }

    use std::collections::{HashMap, HashSet, VecDeque};
    let mut visited = HashSet::new();
    for i in 0..N {
        if visited.contains(&i) {
            continue;
        }
        let mut rel_pos = HashMap::new();
        let mut queue = VecDeque::new();
        queue.push_back((i, 0));
        while let Some((n, pos)) = queue.pop_front() {
            if visited.contains(&n) {
                continue;
            }
            rel_pos.insert(n, pos);
            visited.insert(n);
            for &(to, d) in &edges[n] {
                if let Some(&r) = rel_pos.get(&to) {
                    if pos + d != r {
                        println!("No");
                        return;
                    }
                }
                queue.push_back((to, pos + d));
            }
        }
    }
    println!("Yes");
}


Measured memory_bytes: 39232
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String o = scan.next();
        String e = scan.next();
        int min = o.length();
        char a = 'a';
        if(e.length() < min){
            min = e.length();
            a = 'o';
        }else if(e.length() > min){
            a = 'e';
        }
        for(int i = 0; i < min; i++){
            System.out.print(o.charAt(i));
            System.out.print(e.charAt(i));
        }
        if(a == 'o'){
            System.out.print(o.charAt(o.length() - 1));
        }else if(a == 'e'){
            System.out.print(e.charAt(e.length() - 1));
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>>pri(0, vector<int>(2));
	int i = 1;
	while (i <= sqrt(m)) {
		if (m % i == 0) {
			pri.push_back({ i,m / i });
			pri.push_back({ m / i,i });
		}
		i++;
	}
	sort(pri.begin(), pri.end());
	int pos;
	for (int i = 0; i < pri.size(); i++) {
		if (pri.at(i).at(0) >= n) {
			pos = pri.at(i).at(1);
			break;
		}
	}
	cout << pos << endl;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    
    const numberArray = input[0].split(' ');
    let priceArray = input[1].split(' ');
    const num = Number(numberArray[1]);

    var sum = 0;
    for (let i = 0; i<num; i++) {
        const min = Math.min(...priceArray);
        sum += min;
        var index = priceArray.indexOf(String(min));
        if (index > -1) {
           priceArray.splice(index, 1);
        }
    }
    console.log(sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29924
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int n;
    ll ans = 0;
    int m = 0;

    cin >> n;

    vector<int> h(n);

    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
        if (h[i] >= m)
        {
            ans++;
        }

        m = max(h[i], m);
    }

    cout << ans << endl;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int x1 = scan.nextInt();
        int x2 = scan.nextInt();
        int x3 = scan.nextInt();
        int x4 = scan.nextInt();
        int x5 = scan.nextInt();
        
        System.out.println((15)-(x1+x2+x3+x4+x5));
    }
    
    // private static  helper(int node, Map<Integer, List<Integer>> tree, int color, int parentColor) {
   
    // }
}

Measured memory_bytes: 35688
nab = list(map(int, input().split())) 
s=0

s  = nab[0]//(nab[2]+nab[1])*nab[1]
am = nab[0]%(nab[1]+nab[2])

if am>nab[1]:
    s +=  nab[1]
elif nab[1]==0 :
    s = 0
else:
    s+= am

print(int(s))


Measured memory_bytes: 3060
Q,H,S,D=map(int,input().split())
N=int(input())
if H > 2*Q:
    H=2*Q
if S > 2*H:
    S=2*H
if D < 2*S:
    ans = N//2*(D)+(N%2)*S
else:
    ans = N*S
print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using static System.Math;

class Program
{
    static int n;
    static long[] s;

    static void Main()
    {
        n = int.Parse(Console.ReadLine());
        s = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long ans = 0;
        for (int c = 1; c < n - 1; c++) // 各c=a-bについて
        {
            long mi = (n - 1) / c - 1;
            if ((n - 1) % c == 0) mi--;
            long[] sum1 = new long[mi + 1]; // 0,c,2c...の累積和
            sum1[0] = s[0];
            for (int i = 1; i < sum1.Length; i++)
                sum1[i] = sum1[i - 1] + s[i * c];
            long[] sum2 = new long[mi + 1]; // n-1,n-1-c,n-1-2c,...の累積和
            sum2[0] = s[n - 1];
            for (int i = 1; i < sum2.Length; i++)
                sum2[i] = sum2[i - 1] + s[n - 1 - i * c];
            long[] scores = new long[mi + 1];
            for (int i = 0; i < scores.Length; i++)
            {
                if ((n - 1) % c == 0 && (n - 1) / c <= 2 * i) continue;
                scores[i] = sum1[i] + sum2[i];
            }
            ans = Max(ans, scores.Max());
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 40084
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <bitset>
#include<vector>
#include<utility>
#include<fstream>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,k) for(i=0;i<k;i++)
#define P pair<int,int>
ll n,p, k, b, c, i, j, x, y, z = 1, m = 0;
ll a[100000] = {}, yy[100000] = {};
string s;
P pp[100000];
vector<ll> v;
char cc[100000][10];
int main() {

	cin >> s;
	b = s.size();

	rep(i, b - 1) {
		//cout << i << " " << z << "\n";
		if (m == 1) {
			m = 0;
			z++;
			z++;
			continue;
		}
		if (s[i] == s[i + 1]) {
			m = 1;
			i++;
			continue;
		}
		m = 0;
		z++;

	}
	if (m == 1 && i==b-1)z++;

	cout << z;

	return 0;
}


Measured memory_bytes: 640
from bisect import bisect_right
def find_gt(a, x):
  i = bisect_right(a, x)
  if i != len(a):
    return a[i]
  print(-1)
  exit()

S = list(map(lambda x: ord(x) - ord("a"), input())) * 2
T = list(map(lambda x: ord(x) - ord("a"), input()))

l = [[] for i in range(26)]

for i in range(len(S)):
  l[S[i]].append(i)

ans = 0
cur = -1

for i in range(len(T)):
  fge = find_gt(l[T[i]], cur)
  ans += fge - cur
  cur = fge
  if cur >= len(S)//2:
    cur -= len(S)//2

print(ans)

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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};

int main() {
    int N;
    cin >> N;
    vector<pair<int,int>> x(N);
    vector<int> ans(N);
    for(int i = 0; i < N; ++i) {
        int tmp;
        cin>>tmp;
        x[i]={tmp,i};
    }

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

    for (int j = 0; j < N; ++j) {
        if(j<N/2) ans[x[j].second]=x[N/2].first;
        else ans[x[j].second]=x[N/2-1].first;
    }

    for (int j = 0; j < N; ++j) {
        cout<<ans[j]<<endl;
    }
    return 0;
}


Measured memory_bytes: 4480
#include<stdio.h>

int main()
{
	int n, A[10001];
	scanf("%d", &n);
	int i;
	for (i = 0; i <= n - 1; i++)
	{
		scanf("%d ", &A[i]);
	}
	long int min = 1000001, max = -1000001, total = 0;
	for (i = 0; i <= n - 1; i++)
	{
		if (min > A[i]) min = A[i];
		if (max < A[i]) max = A[i];
		total = total + A[i];
	}
	printf("%ld %ld %ld\n", min, max, total);
	return 0;
}

Measured memory_bytes: 1072
#include <stdio.h>
int main(){
  int n,a,cnt=1,sum=0;
  scanf("%d",&n);
  
  for(int i=0; i<n; i++){
    scanf("%d",&a);
    if( a==cnt ){ cnt++; }
    else		{ sum++; }
  }
  if(sum==n){ printf("-1\n");      }
  else	    { printf("%d\n", sum); }
  return 0;
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, M;
	cin >> N >> M;
	vector<int> p(M);
	vector<string> S(M);
	for(int i = 0; i < M; i++)
		cin >> p.at(i) >> S.at(i);

	vector<bool> flg(N, 0);
	vector<int> ac(N, 0), wa(N, 0);
	// int ac = 0, wa = 0;
	for(int i = 0; i < M; i++){
		if(flg.at(p.at(i)-1) == 0){
			if(S.at(i) == "AC"){
				ac.at(p.at(i)-1)++;
				flg.at(p.at(i)-1) = 1;
			}else
				wa.at(p.at(i)-1)++;
		}
	}
	int wasum = 0, acsum = 0;
	for(int i = 0; i < N; i++)
		if(ac.at(i)){
			acsum++;
			wasum += wa.at(i);
		}
	cout << acsum << ' ' << wasum << endl;
}

Measured memory_bytes: 6912
n = gets.to_i
a = gets.split.map(&:to_i)
b = (n*(n+1))/2
sum = a.inject(:+)
t = sum/b
c = 0
ans = true
ans = false if t*b != sum
if ans
  for i in 0..n-1
    if a[i]-t < a[i-1]
      if (a[i-1]-a[i]+t)%n == 0
        c += (a[i-1]-a[i]+t)/n
      else
        ans = false
      end
    end
  end
end
puts c == t && ans ? "YES" : "NO"

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

int main()
{
int n;
cin>>n;
string a[n];
int ac=0,wa=0,tle=0,re=0;
for(int i=0;i<n;i++)
{
    cin>>a[i];
    if(a[i]=="AC")
        ac++;
    else if(a[i]=="WA")
        wa++;
    else if(a[i]=="TLE")
        tle++;
    else
        re++;

}

cout<<"AC"<<" "<<"x"<<" "<<ac<<endl;
cout<<"WA"<<" "<<"x"<<" "<<wa<<endl;
cout<<"TLE"<<" "<<"x"<<" "<<tle<<endl;
cout<<"RE"<<" "<<"x"<<" "<<re<<endl;
return 0;
}


Measured memory_bytes: 6720
#include<iostream>

int main(void)
{
	char str[4];
	int counter = 0;

	std::cin >> str;

	for(int i=0; i<3;i++){
		if(str[i] == 'o') counter++;
	}

	std::cout << 700 + 100*counter << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
using namespace std;

signed main()
{
   cin.tie(0), ios::sync_with_stdio(false);
   int a, b;
   cin >> a >> b;
   cout << a * b << ' ' << 2 * (a+b) << endl;
}




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

int a, b, n, w;
std::string s;
int c = 0;

int main() {
    while (true) {
        std::cin >> w;
        if (w == 0) {
            return 0;
        }
        std::cin >> n;
        std::vector<std::pair<int, int>> things;
        for (int i = 0; i < n; i++) {
            std::cin >> s;
            std::sscanf(s.c_str(), "%d,%d", &a, &b);
            things.push_back({a, b});
        }
        std::vector<std::vector<int>> dp(n+1, std::vector<int>(w+1, 0));
        for (int j = 0; j < n; j++) {
            for (int p = 1; p <= w; p++) {
                if (things[j].second <= p) {
                   dp[j+1][p] =  std::max(dp[j][p], dp[j][p-things[j].second] + things[j].first);
                }
                else {
                    dp[j+1][p] = dp[j][p];
                }
            }
        }
        int weight = 0;
        int thief_value = 0;
        for (int i = 0; i <= w; i++) {
            if (dp[n][i] > thief_value) {
                weight = i;
                thief_value = dp[n][i];
            }
        }
        c++;
        std::cout << "Case "<< c <<":" << std::endl << dp[n][w] << std::endl << weight << std::endl;
    }
}


Measured memory_bytes: 6816
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define ll  long long
#define ld long double
#define ms(a,v) memset(a,v,sizeof a)
#define pii pair<int, int>
/* * * *   * * *   	* * * */
/* *
 *
 * Author: Hamkor
 *
 * */

int main(){
	ll n; scanf("%Ld", &n);
	ll a[n+1], b[n];
	for (int i=0; i<=n; ++i) scanf("%Ld", a+i);
	for (int i=0; i<n; ++i) scanf("%Ld", b+i);
	ll ans=0;
	for (int i=0; i<n; ++i){
		ans+=min(b[i], a[i]); b[i]-=min(b[i], a[i]);
		ans+=min(b[i], a[i+1]); a[i+1]-=min(b[i], a[i+1]);
	}
	printf("%Ld\n", ans);
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int ax[202][102]= {0};
    a--,b--;
    for(int i=51; i<=100; i++)
    {
        for(int j=1; j<=100; j++)
        {
            ax[i][j]=1;
        }
    }
    for(int i=1; i<50; i+=2)
    {
        for(int j=1; j<=100; j+=2)
        {
            if(a==0)
                break;
            ax[i][j]=1;
            a--;
        }
        if(a==0)
            break;
    }
    for(int i=52; i<=100; i+=2)
    {
        for(int j=1; j<=100; j+=2)
        {
            if(b==0)
                break;
            ax[i][j]=0;
            b--;
        }
        if(b==0)
            break;
    }
    cout<<100<<" "<<100<<endl;
    for(int i=1; i<=100; i++)
    {
        for(int j=1; j<=100; j++)
        {
            if(ax[i][j]==0)
                cout<<"#";
            else
                cout<<".";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<=(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const double Pi = acos(-1);
const ll mod=1e9+7;

int main(){
    int x[5];
    rep(i,5){
        cin >>x[i];
        if(x[i]==0){
            cout << i+1 <<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
#define ifaxb(a, x, b) if (a < x && x < b)
#define toInt(x) (x - '0')
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vvs vector<vs>
#define all(x) x.begin(), x.end()
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
  string S;
  cin >> S;
  int ans = 0;
  rep(i, 0, 4) {
    if (S[i] == '+') {
      ans++;
    } else {
      ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int A[500005],i,H;
void maxHeapify(int p)
{
    int l=p*2+1;
    int r=p*2+2;
    int lg=p;
    if(l<=H&&A[l]>A[lg])
        lg=l;
    if(r<=H&&A[r]>A[lg])
        lg=r;
    if(lg!=p){

        r=A[p];
        A[p]=A[lg];
        A[lg]=r;
        maxHeapify(lg);
    }
}
int main()
{
    scanf("%d",&H);
    for(i=0;i<H;i++)
        scanf("%d",A+i);
    for(i=H/2;i>=0;i--)
        maxHeapify(i);
    for(i=0;i<H;i++)
        printf(" %d",A[i]);
	puts("");
    return 0;
}



Measured memory_bytes: 3640
#include <stdio.h>

int main(){
  int i,j;
  int k;
  for(i = 1;i < 10;i++){
    k = 0;
    for(j = 1;j < 10;j++){
      k += i;
      printf("%dx%d=%d\n",i,j,k);
    }}
  
    return 0;
}

Measured memory_bytes: 524
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int N, M; cin >> N >> M;
    cout << ((1900 * M + 100 * (N - M)) << M) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stack>
#include<algorithm>
using namespace std;
int t[1000][1000];
int table[1000][1000];
int L[1000][1000];
int R[1000][1000];
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		int b=5,c=5;
		//scanf("%d%d",&b,&c);
		for(int i=0;i<b;i++){
			for(int j=0;j<c;j++){
				//char y[2];
				//scanf("%s",y);
				//if(y[0]=='F')t[i][j]=1;
				//else t[i][j]=0;
scanf("%d",&t[i][j]);
			}
		}
		for(int i=0;i<c;i++){
			int now=0;
			for(int j=0;j<b;j++){
				if(t[j][i])now++;
				else now=0;
				table[j][i]=now;
			}
		}
		for(int i=0;i<b;i++){
			stack<int> S;
			for(int j=0;j<c;j++){
				while(S.size()&&table[i][S.top()]>=table[i][j])S.pop();
				if(S.size()==0)L[i][j]=0;
				else L[i][j]=S.top()+1;
				S.push(j);
			}
			while(S.size())S.pop();
			for(int j=c-1;j>=0;j--){
				while(S.size()&&table[i][S.top()]>=table[i][j])S.pop();
				if(S.size()==0)R[i][j]=c-1;
				else R[i][j]=S.top()-1;
				S.push(j);
			}
		}
		int ret=0;
		for(int i=0;i<b;i++)
			for(int j=0;j<c;j++)
				ret=max(ret,table[i][j]*(R[i][j]-L[i][j]+1));
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 7192
#include <bits/stdc++.h>
using namespace std;
/*
 *  GUST KEEP GOING
 */
#define endl			'\n'
#define ll				long long
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define vi				vector <int>
#define vl				vector <ll>
#define ii				pair <ll,ll>
#define vii				vector <ii>
#define PI				double PPPPPP = 3.14159265358979323846;
#define bit(mask,i) ((mask>>i)&1)

vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
void run() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
int n,w;
ll dp[101][100001];
vector<pair<int,int>> v;
ll sol(int i, int w){
    if(i == n || w==0)
        return 0;
    ll &ret = dp[i][w];
    if(~ret)
        return ret;
    if(v[i].first<=w){
        return ret=max(sol(i+1,w),v[i].second+sol(i+1,w-v[i].first));
    }
    return ret=sol(i+1,w);
}
int main() {
/*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    ///freopen("output.txt", "w", stdout);
#endif*/
    run();
    cin >> n >> w;
    v.resize(n);
    for (auto &i:v) {
        cin >> i.first >> i.second;
    }
    memset(dp, -1, sizeof(dp));
    cout << sol(0, w) << endl;
    return 0;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n,m;
    cin>>n>>m;
    priority_queue<int>q;
    rep(i,n){
        int a;
        cin>>a;
        q.push(a);
    }
    rep(i,m){
        int x=q.top()/2;
        q.pop();
        q.push(x);
    }
    ll ans=0;
    while(!q.empty()){
        ans+=q.top();
        q.pop();
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 892
import java.util.*;

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

		int N = sc.nextInt();
		int M = N*(N-1)/2 - N/2;
		System.out.println(M);
		for(int i=1; i<N; i++) {
			for(int j=i+1; j<=N; j++) {
				if(i+j != (N/2*2+1))
					System.out.println(i+" "+j);
			}
		}
		
		sc.close();
	}
}


Measured memory_bytes: 26580
def main():
    INP = list(map(int, input().split()))
    list1 = [INP[0],INP[1]]
    list2 = [INP[2],INP[3]]
    if INP[0] < 0 and INP[1] > 0:
        list1.extend([-1,0,1])
    if INP[2] < 0 and INP[3] > 0:
        list2.extend([-1,0,1])
    ans = -(10**18)
    for item in list1:
        for item2 in list2:
            ans = max(ans,item*item2)
    print(ans)     


if __name__ == '__main__':
    main()

Measured memory_bytes: 9072
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int N;
    scanf("%d",&N);
    int* p = calloc(N,sizeof(int));
    for(int i = 0;i < N;i++)
       scanf("%d",&p[i]); 
    int M = 0;
    for(int i = 1;i < N;i++){
        if(p[M] < p[i])
            M = i;
    }
    int sum = 0;
    for(int i = 0;i < N;i++){
        if(M != i)
            sum += p[i];
        else
            sum += p[i]/2;
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
while True: 
    n = int(input())
    S = []
    if n==0:
        break
    for i in range(n):
        S.append(int(input()))
    #print(S)
    S.sort()
    #print(S)
    S.pop(0)
    S.pop()
    #print(S)

    print(sum(S)//(n-2))


Measured memory_bytes: 5596
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define INF ((1LL<<62)-(1LL<<31))

//*
//プラキュー（二分ヒープ）（最低限バージョン）
//int PQhikaku(int i,int j);//jの方が優先度が高いならtrueを返す
int PQhikaku(ll*heap,int i,int j){return heap[j]>heap[i];}
void heap_utod(ll*heap,int n){
	if(2*n>heap[0])return;
	int rflag=(2*n+1<=heap[0])&&(PQhikaku(heap,2*n,2*n+1));
	if(PQhikaku(heap,n,2*n+rflag)){
		ll temp=heap[2*n+rflag];
		heap[2*n+rflag]=heap[n];
		heap[n]=temp;
		heap_utod(heap,2*n+rflag);
	}
}
void heap_dtou(ll*heap,int n){
	if(n==1||PQhikaku(heap,n,n/2))return;
	ll temp=heap[n];
	heap[n]=heap[n/2];
	heap[n/2]=temp;
	heap_dtou(heap,n/2);
}
ll PQpop(ll*heap){
	ll rr=heap[1];
	heap[1]=heap[heap[0]--];
	heap_utod(heap,1);
	return rr;
}
void PQpush(ll*heap,ll n){
	heap[++heap[0]]=n;
	heap_dtou(heap,heap[0]);
}
//*/

int idx[200010];
int t[200010],k[200010],x[200010];
ll ans[200010];
ll heap[200010];

int c(const void*a,const void*b){
	if(k[*(int*)a]<k[*(int*)b])return -1;
	if(k[*(int*)a]>k[*(int*)b])return 1;
	if(*(int*)a<*(int*)b)return -1;
	return 1;
}

int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	for(int i=0;i<q;i++){
		scanf("%d%d",t+i,k+i);
		if(t[i]==0)scanf("%d",x+i);
		idx[i]=i;
		ans[i]=INF;
	}
	qsort(idx,q,sizeof(int),c);
	for(int ii=0;ii<q;ii++){
		int i=idx[ii];
		if(t[i]==0)PQpush(heap,x[i]);
		else if(t[i]==1&&heap[0])ans[i]=heap[1];
		else if(t[i]==2&&heap[0])PQpop(heap);
		
		if(k[i]!=k[idx[ii+1]])heap[0]=0;
	}
	for(int i=0;i<q;i++)if(ans[i]!=INF)printf("%lld\n",ans[i]);
}


Measured memory_bytes: 7888
#include<iostream>
#include<queue>
using namespace std;
int inf = 1000001;
class mt {
public:
	int num,high;
	pair<int, int> use;
	mt() :num(0), use(pair<int, int>(-1, -1)), high(inf) {

	}
};
int main() {
	int H, W;
	mt **map;
	cin >> H >> W;
	map = new mt*[W + 2];
	for (int i = 0; i < W + 2; ++i) {
		map[i] = new mt[H + 2];
	}
	int dummy;
	for (int y = 1; y <= H; ++y) {
		for (int x = 1; x <= W; ++x) {
			cin >> dummy;
			map[x][y].high = dummy;
		}
	}
	int movex[]{ 1,0,-1,0 }, movey[]{ 0,1,0,-1 };
	for (int y = 1; y <= H; ++y) {
		for (int x = 1; x <= W; ++x) {
			int num = 0;
			for (int i = 0; i < 4; ++i) {
				if (map[x + movex[i]][y + movey[i]].high > map[x][y].high) {
					++num;
				}
			}
			if (num == 4) {
				pair<int, int> point = pair<int, int>(x, y);
				queue<pair<int, int> > que;
				que.push(pair<int, int>(x, y));
				while (!que.empty()) {
					pair<int, int>  stock = que.front(); que.pop();
					for (int i = 0; i < 4; ++i) {
						if (map[stock.first + movex[i]][stock.second + movey[i]].high != inf&&map[stock.first + movex[i]][stock.second + movey[i]].high > map[stock.first][stock.second].high&&map[stock.first + movex[i]][stock.second + movey[i]].use != point&&++map[stock.first + movex[i]][stock.second + movey[i]].num < 3) {
							que.push(pair<int, int>(stock.first + movex[i], stock.second + movey[i]));
							map[stock.first + movex[i]][stock.second + movey[i]].use = point;
						}
					}
				}
			}
		}
	}
	int answer = 0;
	for (int y = 1; y <= H; ++y) {
		for (int x = 1; x <= W; ++x) {
			if (map[x][y].num >= 2) {
				++answer;
			}
		}
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 18828
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, x;

  long long c = 0, a[111111], s;

  std::cin >> N >> x;

  for (int i = 0; i < N; i ++)
    std::cin >> a[i];

  for (int i = 0; i < N - 1; i ++) {
    s = a[i] + a[i + 1];

    if (s > x) {
      long long y = std::min(a[i + 1], s - x);

      c += y;

      a[i + 1] -= y;
      s        -= y;
    }

    if (s > x) {
      long long y = std::min(a[i], s - x);

      c += y;
        
      a[i] -= y;
      s    -= y;
    }
  }

  std::cout << c << std::endl;
  
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
 
class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    //階級
    int rate = sc.nextInt();
    if(rate <= 599){
      System.out.println('8');
    }else if(rate <= 799){
      System.out.println('7');
    }else if(rate <= 999){
      System.out.println('6');
    }else if(rate <= 1199){
      System.out.println('5');
    }else if(rate <= 1399){
      System.out.println('4');
    }else if(rate <= 1599){
      System.out.println('3');
    }else if(rate <= 1799){
      System.out.println('2');
    }else if(rate <= 1999){
      System.out.println('1');
    }
  }
}

Measured memory_bytes: 35708
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
#pragma comment("-Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){int ret=1;do{if(y&1)ret=(ll)ret*x%md;x=(ll)x*x%md;}while(y>>=1);return ret;}
int x,y,z;
signed main(){
	cin>>x>>y>>z;
	if(4ll*x*y<(z-x-y)*(z-x-y)&&z-x-y>=0){
		cout<<"Yes";
	}else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())

g = [["#"]*100 for _ in range(50)] + [["."]*100 for _ in range(50)]

for i in range(A-1):
    x, y = (i%50)*2, (i//50)*2
    g[y][x] = "."
for i in range(B-1):
    x, y = (i%50)*2, 51+(i//50)*2
    g[y][x] = "#"

print(100, 100)
for g_i in g:
    print("".join(g_i))


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

int main(){
  int N;
  cin>>N;
  vector<string> s(N);
  vector<int> t(N);
  
  for(int i=0;i<N;i++){
    cin>>s.at(i)>>t.at(i);
  }
  string X;
  cin>>X;
  int sum=0;
  int flag=0;
  for(int i=0;i<N;i++){
    if(flag==1){
      sum+=t.at(i);
    }
    if(s.at(i)==X){
      flag=1;
    }
  }
  cout<<sum<<endl;
  return 0;
}
    

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

constexpr int MAX = 200010;

ll subcalc(ll x) { return x * (x + 1) / 2; }

int n;
int c[MAX];
vector<int> G[MAX];

int sz[MAX];
vector<int> last[MAX];
ll ans[MAX];

// 部分木のサイズを求める
void dfs1(int v, int p) {
    sz[v] = 1;
    for(int u : G[v]) {
        if(u != p) {
            dfs1(u, v);
            sz[v] += sz[u];
        }
    }
}

// 答えの計算
void dfs2(int v, int p) {
    if(v == 0) {
        for(int i = 1; i <= n; i++)
            last[i].push_back(n);
        dfs2(1, 0);
        for(int i = 1; i <= n; i++)
            ans[i] += subcalc(last[i].back());
    } else {
        last[c[v]].back() -= sz[v];

        for(int u : G[v]) {
            if(u != p) {
                last[c[v]].push_back(sz[u]);
                dfs2(u, v);
                ans[c[v]] += subcalc(last[c[v]].back());
                last[c[v]].pop_back();
            }
        }
    }
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
        last[i].push_back(n);
    }
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs1(1, 0);
    dfs2(0, 0);

    for(int i = 1; i <= n; i++)
        cout << subcalc(n) - ans[i] << endl;

    return 0;
}

Measured memory_bytes: 44856
#include <stdio.h>
int main(){
    int N;
    int tmp;
    int A, B;

    scanf("%d",&N);
    int array[N];
    scanf("%d %d",&A,&B);
    int a,b,c;
    a=0;
    b=0;
    c=0;
    int i;
    for(i=0; i<=N-1; i++){
        scanf("%d",&tmp);
        if(1<=tmp && tmp<=A) a++;
        if(A<tmp && tmp<=B) b++;
        if(B<tmp && tmp<=20) c++;
    }
    int min = a;
    if(min>b){
        min = b;
    }
    if(min>c){
        min = c;
    }
    printf("%d\n",min);

    return 0;

}

Measured memory_bytes: 128
//============================================================================
// Name        : HairetuTest.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int a,x;
	a=1;
	while(1){
		cin>>x;
		if(x==0)break;
		cout<<"Case "<<a<<": "<<x<<endl;
		a++;
	}

}



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

int main() {

  int N, M;
  cin >> N >> M;

  vector<pair<int,int>> sc(N);
  for (int i = 0; i < M; i++) {
    cin >> sc[i].first >> sc[i].second;
  }

  map<int,int> v;
  for (int i = 1; i <= N; i++) {
    v[i] = -1;
  }
  bool flg = true;
  for (int i = 0; i < M; i++) {
    int i_ = sc[i].first;
    if (v[i_] == -1) {
      v[i_] = sc[i].second;
    } else if (v[i_] != sc[i].second){
      flg = false;
      break;
    }
  }

  if (v[1] == 0) {
    if (N != 1) {
      flg = false;
    }
  } else if (v[1] == -1) {
    if (N == 1) {
      v[1] = 0;
    } else {
      v[1] = 1;
    }
  }

  int answer = -1;
  
  if (flg) {
    answer = 0;
    for (int i = 1; i <= N; i++) {
      if (v[i] != -1) {
        answer += v[i] * pow(10, N - i);
      }
    }
  }

  cout << answer << endl;

  return 0;

}

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

import bisect

a = list(range(1,n*20000+1,20000))
b = a[::-1]

#seg_tree
def init(n, init_num=0):
    num = len(str(bin(n-1))) -2
    seg = [init_num] * (2**(num+1))
    seg_num = 2**num
    return seg, seg_num

def calc_sum(head, tail):
    head += seg_num
    tail += seg_num
    l = []
    while(head <= tail):
        if(head == tail):
            l.append(head)
            break

        if(head % 2 == 1):
            l.append(head)
            head += 1
        head = head //2

        if(tail % 2 == 0):
            l.append(tail)
            tail -= 1
        tail = tail //2

    ans = 0
    for i in l:
        ans += seg[i]
    return(ans)

def update(i,x):
    i += seg_num
    seg[i] = x
    while(i > 1):
        i = i//2
        seg[i] = seg[2*i] + seg[2*i+1]

seg,seg_num = init(n)

for i in p:
    i -= 1
    a[i] += calc_sum(0,i-1)
    b[i] += calc_sum(i+1,n-1)
    update(i,1)

print(' '.join(map(str, a)))
print(' '.join(map(str, b)))

Measured memory_bytes: 53632
import java.util.*;

public class Main {
    public static final Scanner scn = new Scanner(System.in);
    
    public static void main(String[] args) {
        ArrayList<Integer> ali = new ArrayList<>();
        while(scn.hasNextInt()) {
            ali.add(scn.nextInt());
        }
        Collections.sort(ali);
        Collections.reverse(ali);
        for(int i = 0; i < 3; i++) {
            System.out.println(ali.get(i));
        }
    }
}

Measured memory_bytes: 26048
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define mp make_pair
#define F first
#define S second
#define mod ((ll)(1e9+7))
#define ll long long int

using namespace std;

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string res;
    for(int i = sy; i < ty ; i++ ){
        res += 'U';
    }
    for(int i = sx ; i < tx ; i++){
        res += 'R';
    }
    for(int i = sy; i < ty ; i++ ){
        res += 'D';
    }
    for(int i = sx ; i < tx ; i++){
        res += 'L';
    }
    res += 'L';
    for(int i = sy ; i <= ty ; i++){
        res += 'U';
    }
    for(int i = sx ; i <= tx ; i++){
        res += 'R';
    }
    res += "DR";
    for(int i = sy ; i <= ty ; i++){
        res += 'D';
    }
    for(int i = sx ; i <= tx ; i++){
        res += 'L';
    }
    res += 'U';
    //string s = "UURRURRDDDLLDLLULUUURRURRDDDLLDL";
    cout << res;
    return 0;
}










Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<utility>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define P pair<int, int>

using namespace std;
char field[20][20];
int W, H,sx,sy,nx,ny;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int cnt = 1;


void bfs(){
	queue<P> que;
	que.push(P(sx, sy));

	while (1){

		if (que.empty()){
			break;
		}
		P p = que.front();
		que.pop();
		
		rep(i, 4){
			nx = p.first + dx[i];
			ny = p.second + dy[i];
			if (nx >= 0 && nx < W && 0 <= ny && ny < H && field[ny][nx] == '.'){
				field[ny][nx] = '#';
				que.push(P(nx, ny));
				cnt++;
			}

		}

		/*

		rep(i, H){
			rep(j, W){
				cout << field[i][j];
			}
			cout << endl;
		}

		*/
	}



}





int main(){
	while (1){
		cin >> W >> H;
		if (W == 0 && H == 0){
			break;
		}
		rep(i, H){
			rep(j, W){
				cin >> field[i][j];
				if (field[i][j] == '@'){
					sx = j;
					sy = i;
				}
			}
		}
		bfs();
		cout << cnt << endl;
		cnt = 1;
	}
}

Measured memory_bytes: 1212
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans=0;
		for(int i=1;i<=N;i++) {
			int temp = sum(i);
			if(temp>=a &&  temp <=b) ans+=i;
		}
		System.out.println(ans);
	}

	public static int sum(int num) {
		int res = 0;
		while(num!=0) {
			res += num%10;
			num/=10;
		}
		return res;
	}
}


Measured memory_bytes: 23892
#define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1000000007; 
const int INF = 1000000000; //1e9
const int NIL = -1;
const long long LINF = 1000000000000000000; // 1e18
const long double EPS = 1E-10;

template<class T, class S>
inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S>
inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}






int main(){
    int S, W; std::cin >> S >> W;
    std::cout << ((S <= W) ? "unsafe" : "safe") << std::endl;
    return 0;
}


Measured memory_bytes: 3592
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,K = map(int, readline().split())
    A = [int(i) for i in readline().split()]

    ans = []
    for i in range(N-K):
        if A[i+K] > A[i]:
            ans.append("Yes")
        else:
            ans.append("No")
    
    print("\n".join(ans))


if __name__ == "__main__":
    main()


Measured memory_bytes: 31464
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;


int main(void){
	int a, b, c, x, y, z, n, t;
	string s;
	cin >> a >> b;
	if(a % 2 == 1 && b % 2 == 1){
		cout << "Odd" << endl;
	}else{
		cout << "Even" << endl;
	}
	return 0;
}

Measured memory_bytes: 504
#include<iostream>
using namespace std;
int main(){
	int x,i;
	for(i=1;;i++){
	cin>>x;	
	if(x==0){
			break;
		}
		else{
			cout<<"Case"<<" "<<i<<":"<<" "<<x<<endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3072
import java.util.ArrayList;
import java.util.Scanner;

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

		int n = Integer.parseInt(sc.next());

		ArrayList<Integer> primeList = new ArrayList<Integer>();
		ArrayList<Integer> ans = new ArrayList<Integer>();
		primeList.add(2);

		for (int i = 3; i <= 55555; i++) {

			boolean primeFlg = true;

			for (int prime : primeList) {
				if (i % prime == 0) {
					primeFlg = false;
					break;
				}
			}

			if (primeFlg) {
				primeList.add(i);
				if (i % 5 == 1)
					ans.add(i);
			}

			if (ans.size() == n)
				break;
		}

		for (int a : ans) {
			System.out.print(a + " ");
		}

	}

}


Measured memory_bytes: 22612
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define newline cout<<"\n"
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define INF (ll)1e14+5
#define nax (ll)5e4+3
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define MAX_N 3005
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;
// look for  all edge cases
//search for a pattern




int main(){
	fast;
	ll a,b,n;
	cin >> a >> b >> n;
	if(n >= b || n == b-1){
		cout<<(a*(b-1))/b;
	}
	else{
		cout<<((a*n)/b);
	}
	
 	
	return 0;
}

	


Measured memory_bytes: 3620