akhauriyash/Code-Regression huggingface dataset:
use std::cmp;
use std::collections::*;
use std::i32;
use std::io::{self, Read};
use std::mem;

const MOD: usize = 1000000007;

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let h: usize = sc.read().unwrap();
    let w: usize = sc.read().unwrap();
    let mut b = sc.read_board(h).unwrap();

    loop {
        let mut f = false;

        // 行
        for i in 0..h {
            let mut j = 0;
            let mut l = false;
            while j < w && b[i][j] != '#' {
                l = l || b[i][j] == '.';
                j = j + 1;
            }

            if l && j == w {
                for jj in 0..w {
                    b[i][jj] = '-';
                }
                f = true;
            }
        }

        // 列
        for j in 0..w {
            let mut i = 0;
            let mut l = false;
            while i < h && b[i][j] != '#' {
                l = l || b[i][j] == '.';
                i = i + 1;
            }

            if l && i == h {
                for ii in 0..h {
                    b[ii][j] = '-';
                }
                f = true;
            }
        }

        if !f {
            break;
        }
    }

    for l in b {
        let mut p = false;
        for c in l {
            if c != '-' {
                p = true;
                print!("{}", c);
            }
        }

        if p {
            println!("");
        }
    }
}

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse()
            .ok()
    }

    fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Option<Vec<T>> {
        (0..n).map(|_| self.read()).collect()
    }

    fn read_vec2d<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Option<Vec<Vec<T>>> {
        (0..m).map(|_| self.read_vec(n)).collect()
    }

    fn read_board(&mut self, n: usize) -> Option<Vec<Vec<char>>> {
        (0..n)
            .map(|_| {
                self.read::<String>()
                    .map(|s| s.chars().collect::<Vec<char>>())
            })
            .collect()
    }
}


Measured memory_bytes: 4352
import java.math.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> num = new ArrayList<>();
        for (int i = 0; i < n; i++)
            num.add(sc.nextInt());
        int cnt = 0;
        int p=1;
        for(int i=0;i<n;i++){
            if(num.get(i)!=p){
                cnt++;
            }
            else{
                p++;
            }
        }
        if(p==1){
            System.out.println(-1); 
        }else{
        System.out.println(cnt);
        }
    }
}


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

using namespace std;

int main() {
  int N;
  while(cin>>N,N) {
    vector<int> r(N),w(N);
    int maxi=0,rsum=0,wsum=0;
    for(int i=0; i<N; i++) {
      cin >> r[i] >> w[i];
      maxi = ((r[i]>r[0])?i:0);
      rsum += r[i];
      wsum += w[i];
    }
    swap(r[0],r[maxi]);
    swap(w[0],w[maxi]);
    if(r[0]*2<=rsum){
      cout << rsum+wsum << endl;
    }else{
      int ds = r[0]*2-rsum;
      vector<vector<int> > dp(N, vector<int>(ds+1,0));
      for(int n=1; n<N; n++)
	for(int s=1; s<=ds; s++)
	  dp[n][s] = max(dp[n-1][s],(s<w[n]?0:dp[n-1][s-w[n]]+w[n]));
      cout << r[0]*2+wsum-dp[N-1][ds] << endl;
    }
  }
}

Measured memory_bytes: 1348
#include<iostream>
using namespace std;
int main()
{
	int a,b; cin>>a>>b;
	if(a<=b){
		for(int i=1;i<=b;i++)
			cout<<a;
	}
	else{
		for(int i=1;i<=a;i++)
			cout<<b;
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	if(n % 2){
		for(int i = 1; i <= m; i++){
			cout << i << " " << 2 * m + 1 - i << endl;
		}
	}else{
		int num = min(n / 4, m);
		for(int i = 1; i <= num; i++){
			cout << i << " " << 2 * num + 1 - i << endl;
		}
		int num2 = m - num;
		for(int i = 1; i <= num2; i++){
			cout << 2 * num + i << ' ' << 2 * num + 2 * num2 + 2 - i << endl;
		}
	}
}

Measured memory_bytes: 3656
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<double> a(N);
	for (int i = 0; i < N; i++) cin >> a[i];
	double ave = accumulate(a.begin(), a.end(), 0.0) / N;
	for (int i = 0; i < N; i++) a[i] = abs(a[i] - ave);

	cout << min_element(a.begin(), a.end()) - a.begin() << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
typedef pair<int,int> P;
int main(){
	P p,tp;
	vector<P> v,rank;
	char c;
	int a,b,r = 1;
	while(cin >> a >> c >> b,a){
		p.first = b;
		p.second = a;
		v.push_back(p);
	}
	sort(v.begin(),v.end(),greater<P>());
	for(int i = 0;i < v.size();++i){
		tp.first = v[i].second;
		if(r == 1){
			tp.second = r;
			rank.push_back(tp);
			++r;
		}
		else {
			if(v[i - 1].first == v[i].first){
				tp.second = r - 1;
				rank.push_back(tp);
			}
			else {
				tp.second = r;
				rank.push_back(tp);
				++r;
			}
		}
	}
	while(cin >> a){
		for(int i = 0;i < rank.size();++i){
			if(rank[i].first == a) cout << rank[i].second << endl;
		}
	}
	return 0;
}

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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] X = new int[100010];
		int ans = -1;

		for (int i = 0; i < N; i++) {
			int ai = sc.nextInt() + 1;
			X[ai-1]++;
			X[ai]++;
			X[ai+1]++;
		}

		Arrays.sort(X);
		System.out.println(X[X.length-1]);
	}

}


Measured memory_bytes: 49048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define repd(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;
using pint = pair<int, int>;
using Graph = vector<vector<int>>; // グラフ型

// https://drken1215.hatenablog.com/entry/2019/12/14/171657

int N;
vector<vector<pint>> testimonies;

bool judge(int bits)
{
    rep(i, N)
    {
        if (!(bits & (1 << i)))
        {
            continue;
        }

        for (pint xy : testimonies[i])
        {
            int x = xy.first;
            int y = xy.second;

            if (y == 1 && !(bits & (1 << x)))
            {
                return false;
            }
            if (y == 0 && (bits & (1 << x)))
            {
                return false;
            }
        }
    }
    return true;
}

int main()
{
    cin >> N;
    testimonies.resize(N);
    rep(i, N)
    {
        int a;
        cin >> a;
        testimonies[i].resize(a);
        rep(j, a)
        {
            cin >> testimonies[i][j].first >> testimonies[i][j].second;
            --testimonies[i][j].first;
        }
    }
    int ans = 0;

    for (int bits = 0; bits < (1 << N); ++bits)
    {
        if (judge(bits))
        {
            int count = 0;
            rep(i, N)
            {
                if (bits & (1 << i))
                {
                    count++;
                }
            }
            ans = max(ans, count);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <unordered_map>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long int

using namespace std;

int main()
{
  int d[100000];
  int a[100000], b[100000];
  int n = 0;
  cin >> n;
  REP(i, n)
  {
    cin >> a[i];
  }
  REP(i, n)
  {
    cin >> b[i];
    d[i] = a[i] - b[i];
  }

  int result = 0;
  ll sum = 0;
  ll minus = 0;
  REP(i, n)
  {
    sum += d[i];
    if (d[i] < 0)
    {
      minus += d[i];
      result++;
    }
  }
  if (sum < 0)
  {
    cout << -1 << endl;
    return 0;
  }

  sort(d, d + n, greater<int>());

  REP(i, n)
  {
    if (minus >= 0)
    {
      break;
    }
    minus += d[i];
    result++;
  }

  cout << result << endl;
}


Measured memory_bytes: 1912
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>

using namespace std;


int main() {
	
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;


int main() {
    int n,m;
    cin >> n >> m;
    vector<vector<ll>> s(8);
    rep(i,n) {
        vector<ll> x(3);
        cin >> x[0] >> x[1] >> x[2];
        rep(bit,8) {
            ll total=0;
            rep(k,3) {
                if (bit & (1<<k)) total+=-x[k];
                else total+=x[k];
            }
            s[bit].push_back(total);
        }
    }
    ll ans=-1e9;
    rep(j,8) {
        sort(s[j].begin(),s[j].end(),greater<>());
        ll tans=0;
        rep(i,m) tans+=s[j][i];
        ans=max(ans,tans);
    }
    cout << ans << endl;
}

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

int dp[100005];
int frog2(int *arr, int i, int n, int k){
    if(dp[i]!=-1){
        return dp[i];
    }
    if(i>=n-1){
        return 0;
    }
    int ans = INT_MAX;
    for(int j =1;j<=k;j++){
        if(i+j<n){
            ans = min(ans,abs(arr[i]-arr[i+j]) +  frog2(arr,i+j, n, k));
        }
    }

    return dp[i] = ans;
}

int frog2BU(int *arr, int n, int k){
    int dp[100005] = {-1};

    dp[0] = 0;
    dp[1] = abs(arr[0]-arr[1]);

    for(int i=2;i<n;i++){
        int ans = INT_MAX;
        for(int j=1;j<=k;j++){
            if(i-j>=0)
                ans = min(ans, dp[i-j]+abs(arr[i]-arr[i-j]));
        }
        dp[i] = ans;
    }

    return dp[n-1];
}

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

    int *arr = new int[n];
    for(int i=0;i<n;i++){
        cin >> arr[i];
    }

    for(int i=0;i<100005;i++){
        dp[i] = -1;
    }

    //cout << frog2(arr,0, n, k)<<endl;
    cout << frog2BU(arr, n, k)<<endl;
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
using P = pair<int, int>;

vector<int> to[100005];
int cost[100005];
signed main(){
    int n;
    cin >> n;
    vector<long long> a(n);
    rep(i,n) cin >> a[i];
    long long ans = 0;
    rep(i,60) {
        long long x = 0;
        rep(j, n) {
             if(a[j]>>i&1) ++x;
        }
        //cout << x << endl;
        long long tmp = x*(n-x)%mod;
        rep(j, i) tmp = tmp*2%mod;
        tmp %= mod;
        ans += tmp;
        ans %= mod;
    }
    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int ans = 0;
		if (n % 10 == 0) {
			ans = 10;
		} else {
			while (n > 0) {
				ans += n % 10;
				n = n / 10;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

vector<vector<int> > calcNext(const string &S) {
    int n = (int)S.size();
    vector<vector<int> > res(n+1, vector<int>(10, n));
    for (int i = n-1; i >= 0; --i) {
        for (int j = 0; j < 10; ++j) res[i][j] = res[i+1][j];
        res[i][S[i]-'0'] = i;
    }
    return res;
}

void add(long long &a, long long b) {
    a += b;
}

int main()
{
    ll N;
    string S;
    cin >> N >> S;

    vector<vector<int>> next = calcNext(S);
    // DP
    vector<vector<ll>> dp(N + 1, vector<ll>(4, 0));
    dp[0][0] = 1;

     for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 10; ++j) {
            for (int k = 0; k < 3; k++) {
                if (next[i][j] >= N) continue; // 次の文字 j がもうない場合はスルー
                add(dp[next[i][j] + 1][k + 1], dp[i][k]);
            }
        }
    }

    long long res = 0;
    for (int i = 0; i <= N; ++i) add(res, dp[i][3]);

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 4480
for _ in[0]*int(input()):
 r=o=s=0
 while 1:
  a=input()[1]
  if'I'==a:
   if r<3:r+=1
   else:s+=1
  elif'O'==a:s+=r+1;r=0
  else:
   if o<2:o+=1
   else:print(s);break


Measured memory_bytes: 5600
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

N = int(input())
A = [0] + list(map(int, input().split())) + [0]

S = 0
for i in range(N+1):
    S += abs(A[i+1]-A[i])

for i in range(1,N+1):
    ans = S + abs(A[i+1]-A[i-1]) - (abs(A[i+1]-A[i]) + abs(A[i]-A[i-1]))
    print(ans)

Measured memory_bytes: 22844
orders = []
5.times do
  orders << STDIN.gets.chomp.to_i
end

min_time = 643

orders_permutation = orders.permutation(5).to_a.uniq

orders_permutation.length.times do |i|
  current_time = 0

  orders_permutation[i].each do |o|
    ceil = current_time % 10
    current_time = current_time - ceil + (ceil.zero? ? 0: 10)
    current_time += o
  end

  if current_time < min_time
    min_time = current_time
  end
end

puts min_time

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;

int main() {
	int a;
	cin >> a;
	cout << a / 30 << " " << a % 30 / 30.0 * 60 << endl;
	return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long int ll;
#define mod 1000000007


void solve()
{
	int arr[3];
	cin >> arr[0] >> arr[1] >> arr[2];

	sort(arr, arr + 3);

	if (arr[0] == 5 && arr[1] == 5 && arr[2] == 7)
		cout << "YES";
	else
		cout << "NO";
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("1input.txt", "r", stdin);
	freopen("1output.txt", "w", stdout);
#endif

	int t = 1;
	// cin >> t;

	while (t--)
	{
		solve();
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 3604
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int main() {
	long long n;
	cin >> n;
	long long a = 2;
	long long b = 1;
		for (int i = 0;i < n;++i) {
			long long c = a + b;
			a = b;
			b = c;
		}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 888
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        long ans = 1;
        for(int i = 0; i < n; i++){
            if(i == 0){
                ans *= k;
            }else{
                ans *= k-1;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21972
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2**20)

class Node():
    def __init__(self):
        self.p = None
        self.l_ch = None
        self.r_si = None

def SetDepth(u, p):
    D[u] = p
    if T[u].r_si != None:
        SetDepth(T[u].r_si, p)
    if T[u].l_ch != None:
        SetDepth(T[u].l_ch, p+1)

def SetAttribute():
    for i in range(n):
        if T[i].p == -1:
            A[i] = 'root'
        elif T[i].l_ch == None:
            A[i] = 'leaf'
        else:
            A[i] = 'internal node'

n = int(input())
T = [None] * n
for i in range(n):
    temp = Node()
    T[i] = temp
C = [[] for i in range(n)]

for i in range(n):
    L = [int(x) for x in input().split()]
    v, d = L[0], L[1]
    C[v] = L[2:]
    for j, c in enumerate(L[2:]):
        if j == 0:
            T[v].l_ch = c
        else:
            T[l].r_si = c
        l = c
        T[c].p = v

D = [0] * n
for i in range(n):
    if T[i].p == None:
        T[i].p = -1
        r = i
SetDepth(r, 0)

A = [''] * n
SetAttribute()

for i in range(n):
    print('node {}: parent = {}, depth = {}, {}, {}'.format(i, T[i].p, D[i], A[i], C[i]))


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

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());

        for (int i = 0; i < n; i++) {
            String line = br.readLine();
            String res = line.substring(0, 1);
            line = line.substring(1);
            int index = 0;
            for (;;) {
                if (line.length() == 0)
                    break;

                if (line.substring(0, 2).equals("<-")) {
                    index--;
                } else if (line.substring(0, 2).equals("->")) {
                    index++;
                }
                line = line.substring(2);
                String next = line.substring(0, 1);
                line = line.substring(1);

                if (index < 0) {
                    res = next + res;
                    index++;
                } else if (index >= res.length()) {
                    res = res + next;
                } else {
                    // do nothing.
                }
            }

            System.out.println(res);
        }
    }
}


Measured memory_bytes: 46224
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
 

//result = Math.pow(num1, num3)
//StringBuffer str = new StringBuffer(hoge1);
//String hoge2 = str.reverse().toString();
//map.containsKey(A)
//Map<String, Integer> map = new HashMap<String, Integer>(n);
//ArrayList<String> cc = new ArrayList<>(n);

public class Main {
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	//static String eikomoji[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
	
	
	public static void main(String[] args) {
	int h=sc.nextInt();
	int n=sc.nextInt();
	int damage=0;
	for(int i=0;i<n;i++) {
		int t=sc.nextInt();
		damage+=t;
	}
	if(damage>=h) {
		p("Yes");
	}else {
		p("No");
	}
 }
}

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

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

    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N - 1);

    for (int &a : A)
    {
        cin >> a;
        a--;
    }

    for (int &b : B)
    {
        cin >> b;
    }

    for (int &c : C)
    {
        cin >> c;
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        ans += B[A[i]];
        if (i > 0 && (A[i] == A[i - 1] + 1))
        {
            ans += C[A[i] - 1];
        }
    }

    cout << ans << endl;
}


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

int main(){
  pair<pair<string, int>, int> p[110];
  int n;
  cin >> n;
  for(int i = 0; i < n; ++i){
    string s;
    int a;
    cin >> s >> a;
    p[i] = make_pair(make_pair(s, -a), i);
  }
  sort(p, p+n);
  for(int i = 0; i < n; ++i){
    cout << p[i].second + 1 << endl;
  }
  return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n;
	cin>>n;
	int ans=1;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			ll t=n;
			while(t%i==0){
				t/=i;
			}
			if((t-1)%i==0){
				ans++;
			}
			t=n;
			if(i*i==n)continue;
			ll x=n/i;
			while(t%x==0){
				t/=x;
			}
			if((t-1)%x==0){
				ans++;
			}
		}
	}
	n--;
	if(n>1)ans++;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			ans+=2;
			if(i*i==n)ans--; 
		}
	}
	cout<<ans;
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
B = [0 for i in range(N)]
i = N

j = 0
while i>0:
    sum1=0
    j = i + i
    while j<=N:
        sum1 += B[j-1]
        sum1=(sum1+2)%2
        j=j+i
    B[i-1]+=(A[i-1]+sum1)
    B[i-1]=(B[i-1]+2)%2
    i=i-1
count=0
for s in B:
  if s == 1 :
    count+=1
print(count)
for i in range(N):
  if B[i]==1:
    print(i+1,end=" ")

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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	ll ans = -1 * (1e18);

	chmax(ans, a*c);
	chmax(ans, a*d);
	chmax(ans, b*c);
	chmax(ans, b*d);

	cout << ans << endl;

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

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



int main(){
  //入力
  int A,B,M; cin>>A>>B>>M;
  vector<int> a(A); for(int i=0;i<A;i++) cin>>a.at(i);
  vector<int> b(B); for(int i=0;i<B;i++) cin>>b.at(i);
  
  //まずは(冷蔵庫の最安値)+(レンジの最安値を求める)
  int mina=*min_element(a.begin(),a.end());
  int minb=*min_element(b.begin(),b.end());
  
  int ans=mina+minb;//割引券なしの最小値ペアが求まった
  
  //割引券込みのを求める
  for(int i=0;i<M;i++){
    int x,y,c; cin>>x>>y>>c; x--,y--;//入力、添え字調整
    int sub_ans=a.at(x)+b.at(y)-c;//i番目の割引込みの値段
    ans=min(ans,sub_ans);//最小値更新
  }
  
  cout<<ans<<endl;
  
  /*
  補足
  for文は書きにくいのでrepに差し替えてもいい
  最大値更新、最小値更新はある程度慣れたらchmin,chmaxを使った方がやりやすい、
  chmax,chminについては↓の2を参照
  https://qiita.com/drken/items/dc53c683d6de8aeacf5a
  */

  return 0;
}


Measured memory_bytes: 4016
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf
#define sf scanf
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define sz(a) int(a.size())
#define ff first
#define ss second
#define endl "\n"
#define forch(it,s) for(auto it:s)
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >


int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
void solve(){
    rep1(i,1,5){
        int a;
        cin>>a;
        if(a==0){
            cout<<i<<endl;
            return;
        }
    }
}

signed main()

{
    IOS;
    /*#ifndef ONLINE_JUDGE
        freopen ("data.in","r",stdin);
        freopen ("data.out","w",stdout);
    #endif*/
    int t;
    t=1;
    while(t--){
        solve();
    }

     return 0;

}
///Alhamdulillah




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

using namespace std;

int main()
{
    int n , x ;
    cin>>n>>x ;
    vector<int>arr ;
    for(int i = 0 ; i < n ; ++i)
    {
        int a ;
        cin>>a ;
        arr.push_back(a);
    }
    arr.push_back(x);
    sort(arr.begin() , arr.end());
    if(n == 1)
        return cout<<abs(arr[1] - arr[0]) , 0 ;
    int ans = arr[1] - arr[0];
    for(int i = 2 ; i <= n ; ++i)
     ans = __gcd(ans , arr[i] - arr[i-1]);
    return cout<<ans , 0 ;
}


Measured memory_bytes: 892
array = gets.split

if array[0].to_i > array[1].to_i
 array[0],array[1] = array[1],array[0]
end

if array[1].to_i > array[2].to_i
 array[1],array[2] = array[2],array[1]
end

if array[0].to_i > array[1].to_i
 array[0],array[1] = array[1],array[0]
end

puts "#{array[0]} #{array[1]} #{array[2]}"

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

int main() {
  int N, K, a[200000] = {};
  cin >> N >> K;
  for (int i = 0; i < N; i++){
    cin >> a[i];
  }
  for (int j = K; j<N; j++){
    if(a[j-K] < a[j]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 4416
# coding: utf-8

# https://atcoder.jp/contests/abc085/tasks/abc085_c
# 19:24-19:38


def main():
    N, Y = map(int, input().split())
    y = Y // 1000

    for b in range(N+1):
        if (y-N-4*b) >= 0 and (y-N-4*b) % 9 == 0:
            c = (y-N-4*b) // 9
            a = N - b - c
            if a >= 0:
                return "{} {} {}".format(c, b, a)

    return "-1 -1 -1"


print(main())


Measured memory_bytes: 3060
#include <iostream>
#include <set>

using namespace std;

int main() {
  int N, ans{};
  string A, B, C;
  cin >> N >> A >> B >> C;
  set<char> s;
  for (auto i = 0; i != N; ++i) {
    s.clear();
    s.insert({A[i],B[i],C[i]});
    ans += s.size() - 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		for (int i = X - K + 1; i <= X + K - 1; i++) {
			if (i != X + K - 1) {
				System.out.print(i + " ");
			} else {
				System.out.println(i);
			}
		}
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<1000000007> mint;

vector<mint> fact, factinv;
void nCr_computeFactinv(int N) {
	N = min(N, mint::Mod - 1);
	fact.resize(N + 1); factinv.resize(N + 1);
	fact[0] = 1;
	reg(i, 1, N) fact[i] = fact[i - 1] * i;
	factinv[N] = fact[N].inverse();
	for (int i = N; i >= 1; i --) factinv[i - 1] = factinv[i] * i;
}
mint nCr(int n, int r) {
	if (n >= mint::Mod)
		return nCr(n % mint::Mod, r % mint::Mod) * nCr(n / mint::Mod, r / mint::Mod);
	return r > n ? 0 : fact[n] * factinv[n - r] * factinv[r];
}
mint nPr(int n, int r) {
	if (r<0)return 0;
	return r > n ? 0 : fact[n] * factinv[n-r];
}
mint nHr(int n, int r) { return r == 0 ? 1 : nCr(n + r - 1, r); }

ll n,k;
V<ll> v[100010];
mint ans=1;

void init(){
	cin>>n>>k;
	rep(i,n-1){
		ll a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	nCr_computeFactinv(100010);
}

int main(void){
	init();
	queue<pair<ll,ll>> Q;  // 頂点と親
	Q.push({1,0});
	while(!Q.empty()){
		pair<ll,ll> p = Q.front();Q.pop();
		ll m=v[p.first].size();
		if(p.second==0){
			ans*=nPr(k,m+1);  // 根とその子を塗る
		}else{
			ans*=nPr(k-2,m-1);  // 自分と親が塗られているときに子を塗る
		}
		for(int q:v[p.first]){
			if(q!=p.second){
				Q.push({q,p.first});
			}
		}
	}
	cout<<ans.get()<<endl;
	return 0;
}

Measured memory_bytes: 8948
#include<iostream>
#include<deque>
using namespace std;
deque<deque<int>> s(100);
deque<bool> seen;
int d;
int t = 0;
int n;
void dfs(int a){
    d++;
    seen[a] = true;
    if(d == n)t++;
    for(auto i : s[a]){
        if(seen[i])continue;
        else dfs(i);
        }
    seen[a] = false;
    d--;
}    
        
int main(){

int m;cin >> n >> m;

for(int i = 0; i < m; i++){
    int x,y;cin >> x >> y;
    s[y].push_back(x);
    s[x].push_back(y);
    }
d = 0;
seen.assign(n, false);
dfs(1);

cout << t << "\n";
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <random>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
                    c>0?i<b:\
                    i>b;\
                    i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = false;
#else 
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

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

template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
	return accumulate(begin, end, 0ll);
}

string reverse_str(string s) {
	reverse(all(s));
	return s;
}

int n;

void solve() {
	cin >> n;
	int res = INFL;
	rep2(a, 1, n + 1) {
		if (n < a * a) break;
		if (n % a != 0) continue;
		int b = n / a;
		chmin(res, max(to_string(a).size(), to_string(b).size()));
	}
	cout << res << endl;
}

signed main() {
	srand(time(NULL));
	int T = (int)1e15;
	solve();
	cout << fixed << setprecision(15);
	rep(i, T) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, a, b, c, d;
    cin >> N;
    a = N % 10;
    b = (N % 100) / 10;
    c = (N % 1000) / 100;
    d = N / 1000;

    if(a == b && b == c || b == c && c == d)
         cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3592
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def dfs(x):
    for p in g[x]:
        # print(p[0])
        if color[p[0]] != -1:
            continue
        if p[1] % 2: #odd
            if color[x]: #pre=white
                color[p[0]] = 0
            else:
                color[p[0]] = 1
        else:
            if color[x]: #pre=white
                color[p[0]] = 1
            else:
                color[p[0]] = 0
        dfs(p[0])
n = inp()
g = [[] for i in range(n)]
#0:黒 1:白 -1:未訪問
color = [-1] * n

for i in range(n-1):
    u,v,w = inpl()
    g[u-1].append([v-1,w])
    g[v-1].append([u-1,w])
# print(g)
color[0] = 0
dfs(0)
for i in range(1,n):
    if color[i] != -1:
        continue
    dfs(i)
for i in range(n):
    print(color[i])

Measured memory_bytes: 86756
#include <bits/stdc++.h>
#define ll long long
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define per(i, a, b) for (ll i = a; i > b; i--)
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define a(v) (v.begin(), v.end())
#define intlimit 2e9 + 69
#define longlimit 8e18 + 69
#define MOD 1000000007
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vi v(n),v1;
    rep(i, 0, n)
    {
        cin >> v[i];
    }
    v1 = v;
    vi klo;
    rep(i, 2, 1000)
    {
        int b = 0;
        for (int j = 2; j * j <= i; j++)
        {
            if (i % j == 0)
            {
                b = 1;
                break;
            }
        }
        if (!b)
        {
            klo.pb(i);
        }
    }
    int b = 0;
    rep(j, 0, klo.size())
    {
        int coco = 0;
        rep(i, 0, n)
        {
            if (v[i] % klo[j] == 0){
                coco++;
                while(v[i]%klo[j]==0){
                    v[i]/=klo[j];
                }
            }
        }
        if (coco > 1)
        {
            b = 1;
            break;
        }
    }
    vi tk(1000001, 0);
    rep(i, 0, n)
    {
        tk[v[i]]++;
        if (tk[v[i]] > 1 && v[i]>1)
        {
            b = 1;
            break;
        }
    }
    if (!b)
    {
        cout << "pairwise coprime";
        return 0;
    }
    int g = v1[0];
    rep(i,1,n){
        g = gcd(g,v1[i]);
    }
    if(g==1){
        cout << "setwise coprime";
    }else{
        cout << "not coprime";
    }
}


Measured memory_bytes: 15076
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

bool isPrime(int n) {
    if (n == 1) return false;
    if (n == 2) return true;
    if (n % 2 == 0) return false;
    for (int i = 3; i * i <= n; i += 2) {
        if (n % i == 0) return false;
    }
    return true;
}

void calc(int n) {
    auto ans = recurrence!"a[n-1] + 1"(1)
        .filter!(isPrime)
        .filter!(e => e % 5 == 1)
        .take(n);
    writeln(ans.map!text.join(' '));
}

void main() {
    int n; scan(n);
    calc(n);
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 5, M = 1e9 + 7;
int main()
{
    ll a, b;
    cin >> a;
    for (ll i = 1; i < 10; i++)
        for (ll j = 1; j < 10; j++)
            if (i * j == a)
                return cout << "Yes", 0;
    cout << "No";
}


Measured memory_bytes: 256
N, M = map(int, input().split())
G = [list(map(int, input().split())) for i in range(M)]
L = 1
R = N
for i in range(M):
  if G[i][0] > L:
    L = G[i][0]
  if G[i][1] < R:
    R = G[i][1]
  if L > R:
    print(0)
    break
if L <= R:
  print(R-L+1)


Measured memory_bytes: 59864
/*Program from Luvwgyx*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define int long long
using namespace std;
char s[10];
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);puts("");}
void query(int x){printf("? %lld\n",x);fflush(stdout);scanf("%s",s);}
signed main()
{
    int x=1000000000;
    query(x);
    if (s[0]=='Y')
    {
        for (int i=8;~i;i--)
        {
            query(x-1);
            if (s[0]=='N') break;
            x/=10;
        }
        printf("! %lld\n",x);
        return 0;
    }
    for (int i=8;~i;i--)
    	{
        x/=10;
        query(x);
        if (s[0]=='Y')
        {
            break;
        }
    }
    int l=x+1,r=x*10-1,ans;
    while(l<=r)
    {
        ll mid=(l+r)>>1;
        query(mid*10);
        if (s[0]=='Y') ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("! %lld\n",ans);
    return 0;
}


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

int main(){
  int a,b,c,x,y;
  std::cin >> a>>b>>c>>x>>y;
  int val=0;
  if(2*c<a+b){
    val+=min(x,y)*c*2;
    int m=min(x,y);
    x-=m;
    y-=m;
    if(x!=0){
      val+=min(x*a,c*x*2);
    }
    if(y!=0){
      val+=min(y*b,c*y*2);
    }
  }else{
    if(x!=0){
      val+=min(x*a,c*x*2);
    }
    if(y!=0){
      val+=min(y*b,c*y*2);
    }
  }
  std::cout << val << std::endl;
}

Measured memory_bytes: 256
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define endl "\n"

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

signed main() {
	crap;

	string str;
	cin >> str;

	for (auto &x : str) {
		if (x == '?')
			x = 'D';
	}

	cout << str << endl;

	// int n = str.size();
	// int cnt = 0;
	// for (int i = 0; i < n; i++) {
	// 	if (str[i] == 'D')
	// 		cnt++;
	// 	if (i + 1 < n and str[i] == 'P' and str[i + 1] == 'D')
	// 		cnt++;
	// }

	// cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<set>
#define endl '\n'
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len = s.size();
    set<char>a;
    for(int i = 0; i<len; i++){
        a.insert(s[i]);
    }
    int m = a.size();
    if(len != m)puts("no");
    else puts("yes");
    return 0;
}


Measured memory_bytes: 256
n = int(input())
*P, = map(float, input().split())
DP = [0 for j in range(n+1)]
DP[0] = 1
for i in range(n):
    DP_ = []
    DP_.append(DP[0]*(1-P[i]))
    for j in range(1, n+1):
        DP_.append(DP[j]*(1-P[i])+DP[j-1]*P[i])
    DP = DP_
print(sum(DP[(n+1)//2:]))


Measured memory_bytes: 46684
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =   998244353  ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////
ll power( ll x , ll n){
    if(n==0) return 1 ;
    ll y = power(x,n/2);
    if(n&1) return multiply(y,multiply(y,x));
    return multiply(y,y);
}
///////////////////////////////////////////////////////////////
void solve(){
    int n , s;
    cin >> n >> s ;
    vector < int > a(n) ;
    for( int i = 0 ; i < n ; i++) cin >> a[i] ;
//    vector < vector < map < int , int >  > > dp(n,vector<map < int , int > >(s+1));
//    dp[0][0][0] = 1 ;
//    if(a[0]<=s)
//        dp[0][a[0]][1] = 1 ;
//    for( int i = 1 ; i < n ; i++){
//        for( int j = 0 ; j <= s ; j++){
//            if(j>=a[i]){
//                for(auto x : dp[i-1][j-a[i]]){
//                    dp[i][j][x.ff+1] = x.ss ;
//                }
//            }
//            for(auto x : dp[i-1][j]){
//                dp[i][j][x.ff] = add(dp[i][j][x.ff],x.ss) ;
//            }
//        }
//    }
    vector < vector < int >  > dp(n,vector< int >(s+1));
    ll x = power(2,mod-2);
    dp[0][0] = 1 ;
    if(a[0]<=s)
        dp[0][a[0]] = x ;
    for( int i = 1 ; i < n ; i++){
        for( int j = 0 ; j <= s ; j++){
            if(j>=a[i]){
                dp[i][j] = add(dp[i-1][j] , multiply(dp[i-1][j-a[i]],x));
            }
            else{
                dp[i][j] = dp[i-1][j] ;
            }
        }
    }
//    for( int i = 0 ; i < n ; i++){
//        for( int j = 0 ; j <= s ; j++){
//            cout << dp[i][j] << " " ;
//        }
//        cout << "\n";
//    }
    ll ans = 0 ;
//    for(auto x : dp[n-1][s]){
//        ans = add(ans,multiply(x.ss , power(2,n-x.ff)));
//    }
//cout << multiply(3,power(4,mod-2)) << " " ;
    cout << multiply(power(2,n),dp[n-1][s]) ;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
   // cin >> t ;
    while(t--){
        solve( );
    }
}




Measured memory_bytes: 38560
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0  # 何もしないと0なので、ansの初期値は0


# pick->取り出す操作をする回数(listより多く取り出さないように注意)
for pick in range(min(K+1, N+1)):
    # 右から取り出す数
    for right in range(pick+1):
        left = pick-right  # 左から取り出す数
        pick_list = V[:right]+V[N-left:]

        # queueに戻す操作
        pick_list = sorted(pick_list)
        tmp_ans = sum(pick_list)  # 戻す前の合計値
        rem = min(K-pick, len(pick_list))  # 戻す操作をできる回数
        for i in range(rem):  # 負の値のものをできるだけ戻す
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans)
print(ans)


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  while(1) {
    c -= b;
    if(c<= 0){
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
    if(a<=0){
      cout << "No" << endl;
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>

using namespace std;

int n,m,a[100005];
long long c;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 0; i < n; i++) {
		if (a[i] + a[i + 1] > m) {
			c += a[i] + a[i + 1] - m;
			a[i + 1] = m - a[i];
		}
	}
	printf("%lld\n", c);
}


Measured memory_bytes: 512
#include<cstdio>

const int p = 1000000007;
const int MAX_N = 2000;
const int MAX_LEN = 100000;

long long dp[MAX_N+1][MAX_N+1];
int s[MAX_LEN], t[MAX_LEN];

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	dp[0][0] = 1;
	for(int i=0;i<n;i++) {
		scanf("%d", &s[i]);
		dp[i+1][0] = 1;
	}
	for(int i=0;i<m;i++) {
		scanf("%d", &t[i]);
		dp[0][i+1] = 1;
	}
	for(int i=0;i<n;i++) for(int j=0;j<m;j++) {
		dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1];
		if(s[i] != t[j]) dp[i+1][j+1] += p - dp[i][j];
		dp[i+1][j+1] %= p;
	}
	printf("%d\n", dp[n][m]);
	return 0;
}


Measured memory_bytes: 31488