akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case,unused_imports)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
    
fn bfs_dist_grid_start_q(H:usize,W:usize,Map:&Vec<Vec<bool>>,start_q:Vec<(usize,usize)>) -> Vec<Vec<i32>>{
    let mut d = Vec::new();
    for i in 0..H{
        d.push(Vec::new());
        for _ in 0..W{
            d[i].push(-1);
        }
    }
    let mut q = start_q;
    for &(i,j) in &q{
        d[i][j] = 0;
    }
    let mut qq;
    while q.len()>0{
        qq = Vec::new();
        while q.len()>0{
            let (i,j) = q.pop().unwrap();
            let dCur = d[i][j];
            for (di,dj) in vec![(-1,0),(1,0),(0,-1),(0,1)]{
                let i = di + i as isize;
                let j = dj + j as isize;
                if i<0 || i >= H as isize {continue;}
                if j<0 || j >= W as isize {continue;}
                let i = i as usize;
                let j = j as usize;
                if !Map[i][j] {continue;}
                if d[i][j]!=-1 {continue;}
                d[i][j] = dCur+1;
                qq.push((i,j));
            }
        }
        q = qq;
    }
    d
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let H = iter.next().unwrap().parse().unwrap();
    let W:usize = iter.next().unwrap().parse().unwrap();
    let mut C = Vec::new();
    let mut start = Vec::new();
    for i in 0..H{
        let m:Vec<char> = iter.next().unwrap().chars().collect();
        C.push(Vec::new());
        for (j,&n) in m.iter().enumerate(){
            C[i].push(n != '#');
            if n=='#'{
                start.push((i,j));
            }
        }
    }
    let d = bfs_dist_grid_start_q(H, W, &C, start);
    let ans = d.iter().map(|x| x.iter().max().unwrap()).max().unwrap();
    println!("{}",ans);
}

Measured memory_bytes: 26880
import itertools

my_dict = dict()
my_dict['m'] = 0
my_dict['a'] = 0
my_dict['r'] = 0
my_dict['c'] = 0
my_dict['h'] = 0
n = int(input())
for i in range(n):
    s = input()
    if s.startswith("M"):
        my_dict['m'] += 1
    elif s.startswith("A"):
        my_dict['a'] += 1
    elif s.startswith("R"):
        my_dict['r'] += 1
    elif s.startswith("C"):
        my_dict['c'] += 1
    elif s.startswith("H"):
        my_dict['h'] += 1

seq = ('m', 'a', 'r', 'c', 'h')
ret = 0

for item in itertools.combinations(seq, 3):
    tmp = 1
    for val in item:
        tmp *= my_dict[val]
    ret += tmp

print(ret)


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t a, b;
  std::cin >> a >> b;

  std::cout << 6 / a / b << std::endl;
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::Ordering;

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

use std::cmp::min;
struct DepthFirstSearch {
    n: usize,
    h: Vec<i32>,
    memo: Vec<i32>,
}
impl DepthFirstSearch {
    fn rec(&mut self, k: usize) -> i32 {
        if self.memo[k] != -1 {
            return self.memo[k];
        }
        let res = if k + 1 == self.n {
            0
        } else if k + 2 == self.n {
            self.rec(k + 1) + (self.h[k + 1] - self.h[k]).abs()
        } else {
            let val1 = self.rec(k + 1) + (self.h[k + 1] - self.h[k]).abs();
            let val2 = self.rec(k + 2) + (self.h[k + 2] - self.h[k]).abs();
            min(val1, val2)
        };
        self.memo[k] = res;
        res
    }
}

fn main() {
    input! {
        n: usize,
        h: [i32; n],
    }
    let memo: Vec<i32> = vec![-1; n];
    let mut dfs = DepthFirstSearch{ n: n, h: h, memo: memo };
    println!("{}", dfs.rec(0));
} 


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

int main()
{
  int n,a,b,c;
  cin >> n;
  while(n>0){
    n--;
    cin >> a >> b >> c;
    if(a*a == b*b+c*c || b*b == a*a+c*c || c*c == a*a+b*b){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;
int N;
ll dp[3010][3010] = {},A[3010];

ll rec(int i,int j){
	if(i==j) return N%2==1? A[i]:-A[i];
	if(abs(dp[i][j])!=(ll) 1e18) return dp[i][j];
	if((N-(j-i))%2==1) dp[i][j] = max(rec(i+1,j)+A[i],rec(i,j-1)+A[j]);
	else dp[i][j] = min(rec(i+1,j)-A[i],rec(i,j-1)-A[j]);
	return dp[i][j];
}

int main(){
	cin >> N;
	for(int i=1;i<=N;i++){
		cin >> A[i];
	}
	for(int i=1;i<N;i++){
		for(int j=i+1;j<=N;j++){
			if((N-(j-i))%2==1) dp[i][j] = 1e18;
			else dp[i][j] = -1e18;
		}
	}
	cout << rec(1,N) << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, t; cin >> n >> t;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  vector<vector<int>> dp1(n+1, vector<int>(t+1, 0)), dp2(n+1, vector<int>(t+1, 0));

  rep(i, n) {
    for(int sum_t = 0; sum_t <= t; ++sum_t) {
      if(sum_t-a[i] >= 0) chmax(dp1[i+1][sum_t], dp1[i][sum_t-a[i]]+b[i]);
      chmax(dp1[i+1][sum_t], dp1[i][sum_t]);
    }
  }
  reverse(ALL(a));
  reverse(ALL(b));

  rep(i, n) {
    for(int sum_t = 0; sum_t <= t; ++sum_t) {
      if(sum_t-a[i] >= 0) chmax(dp2[i+1][sum_t], dp2[i][sum_t-a[i]]+b[i]);
      chmax(dp2[i+1][sum_t], dp2[i][sum_t]);
    }
  }

  reverse(ALL(a));
  reverse(ALL(b));

  int ans = 0;

  for(int i = 1; i <= n; ++i) {
    for(int sum_t = 0; sum_t < t; ++sum_t) {
      chmax(ans, dp1[i-1][sum_t]+dp2[n-i][t-1-sum_t]+b[i-1]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 73696
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll N, v[51] = {};
double ans = 0;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++)cin >> v[i];
	stable_sort(v, v + N + 1);
	ans = v[1];
	for (int i = 2; i <= N; i++)ans = (ans + v[i]) / 2;
	cout << ans << endl;
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n, greater<int>());
	long long resp = a[0];
	for (int i = 2; i < n; i++) {
		resp += 1ll * a[i / 2];
	}
	cout << resp << endl;
	return 0;
}

Measured memory_bytes: 4400
N, L = map(int, input().split())
original_pi_taste = sum([L + i - 1 for i in range(1, N + 1)])
incomplete_pis_tastes = [original_pi_taste - (L + i - 1) for i in range(1, N + 1)]
taste_diffs = [abs(original_pi_taste - incomplete_pi_taste) for incomplete_pi_taste in incomplete_pis_tastes]
print(incomplete_pis_tastes[taste_diffs.index(min(taste_diffs))])


Measured memory_bytes: 3060
def _main(x, p_list):
    p_set = set(p_list)
    diff = 0
    while True:
        t_minu = x - diff
        if t_minu not in p_set:
            print(t_minu)
            break

        t_plus = x + diff
        if t_plus not in p_set:
            print(t_plus)
            break
        diff += 1


# if __name__ == "__main__":
x_a, n_a = map(int, input().split())
p_list_a = map(int, input().split())
_main(x_a, p_list_a)


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


long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){
string s;
cin>>s;

for(int i=0;i<s.size();i++){
if(i%2==0){
    if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
        continue;
    }
    else{
        cout<<"No"<<endl;
        return 0;
    }
}

if(i%2==1){
    if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
        continue;
    }
    else{
        cout<<"No"<<endl;
        return 0;
    }
}

}

cout<<"Yes"<<endl;

 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace Flandle_Scarlet
{
    #define N 300100
    int n,m;
    class BIT
    {
        public:
            int tree[N];
            int len;
            void BuildTree(int _len)
            {
                len=_len;
            }
            void Add(int pos,int x)
            {
                while(pos<=len)
                {
                    tree[pos]+=x;
                    pos+=(pos&(-pos));
                }
            }
            void RAdd(int l,int r,int x)
            {
                Add(l,x),Add(r+1,-x);
            }
            int Query(int pos)
            {
                int ans=0;
                while(pos>0)
                {
                    ans+=tree[pos];
                    pos-=(pos&(-pos));
                }
                return ans;
            }
    }T;
    struct node
    {
        int l,r;
    }c[N];bool operator<(node a,node b){return a.r-a.l<b.r-b.l;}

    void Input()
    {
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;++i)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            c[i]=(node){l,r};
        }
        sort(c+1,c+n+1);
    }

    int ans[N];
    void Soviet()
    {
        T.BuildTree(m);
        int now=0;
        for(int d=1;d<=m;++d)
        {
            int ans=n-now;
            for(int i=d;i<=m;i+=d)
            {
                ans+=T.Query(i);
            }
            printf("%d\n",ans);
            while(now<n and c[now+1].r-c[now+1].l<=d)
            {
                T.RAdd(c[now+1].l,c[now+1].r,1);
                ++now;
            }
        }
    }
    void IsMyWife()
    {
        if (0)
        {
            freopen("","r",stdin);
            freopen("","w",stdout);
        }
        Input();
        Soviet();
    }
};
int main()
{
    Flandle_Scarlet::IsMyWife();
    return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	char a,b;
	cin >> a >> b;
	if(b=='H'&&a=='H'){
		cout << 'H' << endl;
	}
	if(b=='H'&&a=='D'){
		cout << 'D' << endl;
	}
	if(b=='D'&&a=='D'){
		cout << 'H' << endl;
	}
	if(b=='D'&&a=='H'){
		cout << 'D' << endl;
	}
}


Measured memory_bytes: 256
// C - Grand Garden
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);i++)
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
// #define all(x) (x).begin(),(x).end()
#define mp(a,b) make_pair(a,b)

using PI = pair<int,int>;
using QPI = queue<PI>;

void q_print(QPI qq){
	while(!qq.empty()){
		PI lr = qq.front();qq.pop();
		int l,r;tie(l,r)=lr;
		cout<<l<<","<<r<<"\n";
	}ote("---");
}


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

	vi H(N);
	rp(i,N) cin>>H[i];
	QPI q;
	int l=0, r=N;
	int lr = l;
	while(lr < r){
		if(H[lr]<=0){
			if(l!=lr){
				q.push(mp(l,lr));
			}
			l = lr+1;
			lr = l;
		}
		else{
			lr++;
		}
	}
	if(l<r) q.push(mp(l,r));



	int ans = 0;

	while(q.size()>0){

		// q_print(q);///

		tie(l,r) = q.front(); q.pop();

		if(l==r){
			continue;
		}

		ans++;

		int lr = l;
		while(lr<r){
			// cout<<l<<","<<lr<<","<<r<<"\n";///

			H[lr]--;
			if(H[lr]<=0){
				if(l!=lr){
					// ote("push");
					q.push(mp(l,lr));
				}
				l = lr+1;
				lr = l;
			}
			else{
				lr++;
			}

		}

		if(l<r) q.push(mp(l,r));

	}

	ote(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int sco,p,g;char s;
int main()
{
    while(cin>>s)
    {
        if(s=='p'&&p<g){p++;continue;}
        if(s=='p'&&p==g){g++;sco--;continue;}
        if(s=='g'&&p<g){p++;sco++;continue;}
        if(s=='g'&&p==g){g++;continue;}
    }
    cout<<sco;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int N;	//データ数
	int hen[3], hen2[3], a;	//辺の長さ,hen2はhenの2乗の値を代入
	int i, j, k;	//ループ用変数

	scanf("%d", &N);

	for (k = 0; k < N; k++){
		scanf("%d %d %d", &hen[0], &hen[1], &hen[2]);
		for (i = 0; i < 2; i++){	//データを降順に並び替える
			for (j = i + 1; j < 3; j++){
				if (hen[i] < hen[j]){
					a = hen[i];
					hen[i] = hen[j];
					hen[j] = a;
				}
			}
		}
		for (i = 0; i < 3; i++){
			hen2[i] = hen[i] * hen[i];
		}
		if (hen2[0] == hen2[1] + hen2[2]){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}

	return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;

	for( int i = 0; i < n; ++i ) {
		vector<int> a( 10 );
		for( auto& v: a ) { cin >> v; }

		bool result = true;
		int x = 0;
		int y = 0;

		for( int j = 0; j < 10; ++j ) {
			if( a[j] > x ) {
				x = a[j];
			}
			else if( a[j] > y ) {
				y = a[j];
			}
			else {
				result = false;
				break;
			}
		}

		cout << (result ? "YES" : "NO") << '\n';
	}
}



Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 105

using namespace std;

int main()
{
    ll n,x,ev=0,od=0,re=0;

    scanf("%lld",&n);

    while(n--)
    {
        scanf("%lld",&x);

        if(x%4==0)
            re++;

        else if(x%2==0)
            ev++;

        else if(x%2!=0)
            od++;
    }

    if(ev==0)
    {
        if(re>=(od-1))
            printf("Yes\n");

        else
            printf("No\n");
    }

    else
    {
        if(re>=od)
            printf("Yes\n");

        else
            printf("No\n");
    }

    return (0);
}




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

typedef long long int ll;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    
    if (is_sorted(a.begin(), a.end()))
    {
        cout << "YES\n";
        return 0;
    }
    else
    {
        for (int i = 0; i < n; ++i)
        {
            for (int j = i + 1; j < n; ++j)
            {
                vector<int> b = a;
                swap(b[i], b[j]);
                
                if (is_sorted(b.begin(), b.end()))
                {
                    cout << "YES\n";
                    return 0;
                }
            }
        }
    }
    
    cout << "NO\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int x,r,s,t,u,v,w;
    cin>>x;
    r=x/500;
    s=r*1000;
    t=x%500;
    v=t/5;
    w=v*5;
    cout<<w+s;
    return 0;
}


Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

long double PI = 3.1415926535897932;

// Cooley–Tukey FFT algorithm O(N log N)
vector<complex<long double>> fft(vector<complex<long double>> a, bool inverse = false) {
    int n = a.size();
    int h = 0; // h = log_2(n)
    for (int i = 0; 1 << i < n; i++) h++;
    // バタフライ演算用の配置入れ替え
    for (int i = 0; i < n; i++) {
        int j = 0;
        for (int k = 0; k < h; k++) j |= (i >> k & 1) << (h - 1 - k);
        if (i < j) swap(a[i], a[j]);
    }
    // バタフライ演算
    for (int b = 1; b < n; b *= 2) {
        // 第 log_2(b) + 1 段
        // ブロックサイズ = b * 2
        for (int j = 0; j < b; j++) {
            // ブロック内 j 個目
            // 重み w = (1 の原始 2b 乗根の j 乗)
            complex<long double> w =
                polar(1.0, (2 * M_PI) / (2 * b) * j * (inverse ? 1 : -1));
            for (int k = 0; k < n; k += b * 2) {
                // k を先頭とするブロック
                complex<long double> s = a[j + k];         // 前
                complex<long double> t = a[j + k + b] * w; // 後
                a[j + k] = s + t;                     // 前の更新
                a[j + k + b] = s - t;                 // 後の更新
            }
        }
    }
    // 逆変換時にサイズで割る調整
    if (inverse)
        for (int i = 0; i < n; i++) a[i] /= n;
    return a;
}
// Cooley–Tukey FFT algorithm O(N log N)
vector<complex<long double>> fft(vector<long double> a, bool inverse = false) {
    vector<complex<long double>> a_complex(a.size());
    for (int i = 0; i < a.size(); i++) a_complex[i] = complex<long double>(a[i], 0);
    return fft(a_complex, inverse);
}
 
// FFT による畳み込み O(N log N)
vector<long double> convolve(vector<long double> a, vector<long double> b) {
    int s = a.size() + b.size() - 1; // 畳み込み結果のサイズ
    int t = 1; // FFT に使う配列のサイズ（2 の累乗）
    while (t < s) t *= 2;
    a.resize(t); // FFT するためにリサイズ
    b.resize(t); // FFT するためにリサイズ
    vector<complex<long double>> A = fft(a);
    vector<complex<long double>> B = fft(b);
    for (int i = 0; i < t; i++) {
        A[i] *= B[i]; // 畳み込み結果の FFT 結果を得る
    }
    A = fft(A, true); // IFFT で畳み込み結果を得る
    a.resize(s);      // 畳み込み結果を入れるためにリサイズ
    for (int i = 0; i < s; i++) a[i] = A[i].real(); // 実部が答え
    return a;
}

int main(void){
    cout << setprecision(20);
    //入力
    long long N,M;scanf("%lld %lld",&N,&M);
    vector<long long> A(N);
    for(int i = 0;i < N;i++)scanf("%lld",&A[i]);
    vector<long double> a(100010,0.0),b(100010,0.0);
    for (int i = 0; i < N; ++i)
    {
        a[A[i]] += 1.000;
        b[A[i]] += 1.000;
    }

    auto c = convolve(a,b);
    long long sz = c.size();

    long long ans = 0;
    for(long long i = sz-1;i >= 0;i--){
        ll X = (ll)(c[i] + 0.5);
        if(X <= M){
            ans += i * X;
            M -= X;
        }else{
            ans += i * M;
            break;
        }
    }

    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 41024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int k;
	string s;
	string ans = "";
	vector<string> ss;
	cin >> s;
	cin >> k;
	rep(i, s.size()) {
		range(j, i, s.size()) {
			if (j - i + 1 > k)continue;
			ss.push_back(s.substr(i, j - i + 1));
		}
	}
	sort(all(ss));
	int t = 0;
	rep(i, k) {
		while (1) {
			if (ans != ss[t]) {
				ans = ss[t];
				t++;
				break;
			}
			t++;
		}
	}
	cout << ans << endl;;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ub upper_bound
#define int long long
#define vbe(sdk) sdk.begin(), sdk.end()
#define pb push_back
#define loop(i, a, b) for (int i = a; i < b; ++i)
#define rloop(i, a, b) for (int i = a; i >= b; --i)
#define mp make_pair
#define mod 1000000007
#define endl '\n'
#define vvll vector<vector<int>>
#define vll vector<int>
#define mint map<int, int>
#define arry(x) (int)x.size()
#define sll set<int>
#define pll pair<int, int>
#define F first
#define S second
#define pi 3.14159265358979323846
using namespace std;
const int MAX = 100001;


void solve()
{
      int n,d;
      cin>>n>>d;
      d=pow(d,2);
      int cnt=0;
      int x=0,y=0;
      loop(i,0,n)
      {
          cin>>x>>y;
          if(x<0)
          x=-x;
          if(y<0)
          y=-y;
          int z= pow(x,2)+pow(y,2);
          if(z<=d)
          {
              cnt++;
          }
      }  
      cout<<cnt<<"\n";

}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #else
    // // online submission
    // #endif


    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a;
    cin >>a;
    if(a>=1200)printa("ARC");
    else printa("ABC");
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  int Ans=1;
  for(int i=0; i<S.size(); i++){
    if(i%2==0 && S.at(i)=='L'){
      Ans=0;
      break;
    }
    if(i%2==1 && S.at(i)=='R'){
      Ans=0;
      break;
    }
  }
  if(Ans==1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

using LL = long long;

template<typename T>
ostream& operator << (ostream& out, const vector<T>& v) {
    out << "[";
    for(auto& x : v) {
        out << x << ", ";
    }
    return out << "]";
}

template<typename S, typename T>
ostream& operator << (ostream& out, const pair<S, T>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}

const LL MOD = 998244353;
LL dp[3100][3100];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    LL A, B, C, D;
    cin >> A >> B >> C >> D;
    dp[A][B] = 1;
    for(int i = A; i <= C; ++i) {
        for(int j = B; j <= D; ++j) {
            if(i == A and j == B) {
                continue;
            }
            dp[i][j] = dp[i - 1][j] * j + dp[i][j - 1] * i - dp[i - 1][j - 1] * (i - 1) * (j - 1);
            dp[i][j] = ((dp[i][j] % MOD) + MOD) % MOD;
        }
    }
    
    cout << dp[C][D] << "\n";
    
    return 0;
} 


Measured memory_bytes: 76108
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=998244353;
int main()
{
	int a,b;
	sc(a);sc(b);
	pf("%d\n",a*b);
}


Measured memory_bytes: 3828
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define PI (2 * acos((double)0))
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

#define TWO(X) (1LL<<(X))
#define CONTAIN(S,X) ((S) & TWO(X))

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

bool res[5011];

int32_t main() {
    int a, b;
    cin >> a >> b;
    if (a <= b) cout << "Impossible" << endl;
    else {
        int n = a + b;
        int good = 0, sum = 0;
        REP(x,n) {
            if (sum <= 0) good = x, sum = 0;

            cout << "? " << x << ' ' << good << endl;
            char response; cin >> response;

            if (response == 'Y') ++sum;
            else --sum;
        }

        REP(x,n) {
            cout << "? " << good << ' ' << x << endl;
            char response; cin >> response;
            res[x] = (response == 'Y');
        }
        cout << "! ";
        REP(i,n) cout << res[i];
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 848
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

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

    long long A = 0;
    long long B = 0;

    for(long long i = -500; i < 500; i++){
        for(long long j= -500; j < 500; j++){

            if(X == (i * i * i * i * i) - (j * j * j * j * j)){
                A = i;
                B = j;
            }
               
        }
    }

    cout << A << " " << B << endl;

}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ld long double
#define ll long long
#define ull unsigned ll
#define pll pair<ll, ll>
#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'
#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout);
#define M 1000000007
#define N 200000
#define INF 101111111111111
using namespace std;
map<string, ll> cnt;
main(){
    FAST;
    ll n;
    cin >> n;
    for(ll i = 0;i<n;i++){
    	string s;
    	cin >> s;
    	sort(itr(s));
    	cnt[s]++;
    }
    ll res = 0;
    for(auto i : cnt){
		res += max((i.y*(i.y-1))/2, 0ll);
    }
    cout << res;
}

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

using namespace std;

int main(void)
{
    int a, b;
    while(cin >> a >> b){
        int temp, ans = 0;
        temp = (a + b);
        while(temp > 0){
            temp = temp/10;
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}    

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

int main() {
    
    int N;
    cin >> N;
    int v[N];
    for(int i = 0; i < N; i++){
        cin >> v[i];
    }
    sort(v, v+N);
    vector<double> d;
    double ans = 0.0;
    for(int i = 0; i < N - 1; i++){
        if(i == 0){
            d.push_back((v[i] + v[i+1]) / 2.0);
            ans = (v[i] + v[i+1]) / 2.0;
        } else {
            double tmp = (d[i-1] + v[i+1]) / 2.0;
            d.push_back(tmp);
            ans = tmp;
        }
    }
        printf("%20.20f\n",ans);
    
    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define N 1000010
#define int long long
int h[N],v[N],nxt[N],w[N],ec,n,mn[N];
struct no{
	int x,y;
};
int c1(no x,no y){
	return x.x<y.x;
}
int c2(no x,no y){
	return x.y<y.y;
}
vector<no>f[N];
void add(int x,int y,int z){v[++ec]=y;w[ec]=z;nxt[ec]=h[x];h[x]=ec;}
void mg(vector<no>&r,vector<no>a,vector<no>b,int md){
	if(a.empty()||b.empty())return;
	if(a.size()>b.size())swap(a,b);
	sort(a.begin(),a.end(),c2);
	sort(b.begin(),b.end(),c1);
	mn[0]=b[0].y;
	for(int i=1;i<b.size();i++)
		mn[i]=min(mn[i-1],b[i].y);
	int j=(int)b.size()-1;
	for(int i=0;i<a.size();i++){
		while(j>=0&&a[i].y+b[j].x>md)j--;
		if(j>=0)r.push_back((no){a[i].x,mn[j]});
	}
	sort(a.begin(),a.end(),c1);
	sort(b.begin(),b.end(),c2);
	mn[0]=b[0].x;
	for(int i=1;i<b.size();i++)
		mn[i]=min(mn[i-1],b[i].x);
	j=(int)b.size()-1;
	for(int i=0;i<a.size();i++){
		while(j>=0&&a[i].x+b[j].y>md)j--;
		if(j>=0)r.push_back((no){mn[j],a[i].y});
	}
}
void dfs(int x,int md){
	f[x].clear();
	if(!h[x]){
		f[x].push_back((no){0,0});
		return;
	}
	for(int i=h[x];i;i=nxt[i])
		dfs(v[i],md);
	for(int i=h[x];i;i=nxt[i])
		for(auto &y:f[v[i]])
			y.x+=w[i],y.y+=w[i];
	if(h[x])mg(f[x],f[v[h[x]]],f[v[nxt[h[x]]]],md);
}
signed main(){
	cin>>n;
	for(int i=2;i<=n;i++){
		int x,y;
		cin>>x>>y;
		add(x,i,y);
	}
	int l=0,r=1e9,ans=1e9;
	while(l<=r){
		int md=(l+r)/2;
		dfs(1,md);
		if(f[1].empty())l=md+1;
		else ans=md,r=md-1;
	}
	cout<<ans;
}

Measured memory_bytes: 58220
package main

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

func main() {
	var sc = bufio.NewScanner(os.Stdin)
	var in_str string
	var a, b int
	var op string
	var ans string
	if sc.Scan() {
		in_str = sc.Text()
	}

	params := strings.Split(in_str, " ")
	a, _ = strconv.Atoi(params[0])
	op = params[1]
	b, _ = strconv.Atoi(params[2])

	if op == "+" {
		ans = strconv.Itoa(a + b)
	} else {
		ans = strconv.Itoa(a - b)
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define double ld
#define faster ios_base::sync_with_stdio(false);
typedef pair<int,int> pii;
///------------------------------------------------------------------------
const int inf=1e18;
const int mod=1e9+7;
ifstream in("input.txt");
ofstream out("output.txt");
signed main()
{
    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int>vec(n);
    for(int i=0; i<n; i++)
        cin>>vec[i];
    vector<int>dp(n,inf);
    dp[0]=0;
    dp[1]=abs(vec[1]-vec[0]);
    for(int i=2; i<n; i++)
    {
        for(int j=1; j<=k; j++)
        {
            if(i-j<0)
                break;
            dp[i]=min(dp[i],dp[i-j]+abs(vec[i]-vec[i-j]));
        }
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1792
# coding: utf-8
# Your code here!

import collections
a = int(input())
li1 = []
 
for i in range(a):
    li1.append(str(input()))
 
c = collections.Counter(li1)
 
sorted_items = sorted(
  c.most_common(),
  key = lambda x:(x[1],x[0]), reverse=True)
 
key, value = zip(*sorted_items)
li2 = []
li2.append(key[0])
for i in range(1,len(key)):
    if(value[0] == value[i]):
        li2.append(key[i])
    else:
        break;

list.sort(li2)

for i in range(len(li2)):
    print(li2[i])

Measured memory_bytes: 62448
import java.io.*;
import java.util.*;
class Main {
	
	BufferedReader in;
	PrintWriter ob;
	StringTokenizer st;
	
	public static void main(String args[]) throws IOException {
		new Main().run();
	}
	void run() throws IOException {
		in = new BufferedReader( new InputStreamReader( System.in ) );
		ob = new PrintWriter( System.out );
		solve();
		ob.flush();
	}
	
	void solve() throws IOException {
		char s[] = nextToken().toCharArray();
		char t[] = nextToken().toCharArray();
		
		int n = s.length;
		int m = t.length;
		int dp[][] = new int[n+1][m+1];
		for(int i=1 ; i<=n;  i++) {
			for(int j=1 ; j<=m ; j++) {
				if( s[i-1] == t[j-1] )
					dp[i][j] = 1 + dp[i-1][j-1];
				else
					dp[i][j] = Math.max( dp[i-1][j] , dp[i][j-1] );
			}
		}
		
		int i=n , j = m;
		String res = "";
		while( i>0 && j>0 ) {
			if( s[i-1] == t[j-1] ) {
				res = s[i-1] + res;
				i--;
				j--;
			}
			else if( dp[i-1][j] > dp[i][j-1] )
				i--;
			else 
				j--;
		}
		ob.println(res);
	}
	
	int ni() throws IOException {
		return Integer.parseInt( nextToken() );
	}
	
	String nextToken() throws IOException {
		if( st == null || !st.hasMoreTokens() )
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
}

Measured memory_bytes: 82872
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N, A, B;
int main()
{
    cin >> N >> A >> B;
    int a = min(A, B);
    cout << a << " " << max(0, (A + B) - N) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
int main(){
    int N , M , K;
    cin >> N >> M >> K;
    ll A[N + 1] = {0} , B[M + 1] = {0};
    for (int i = 1 ; i <= N ; i++){
        cin >> A[i];
        A[i] += A[i - 1];
    }
    for (int i = 1 ; i <= M ; i++){
        cin >> B[i];
        B[i] += B[i - 1];
    }

    int j = M , ans = 0;
    for (int i = 0 ; i <= N ; i++){
        while(j > 0 && B[j] > K - A[i])
            --j;
        if (A[i] + B[j] <= K){
            ans = max(ans , i + j);
        }
        else break;
    }
    cout << ans << endl;
}


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

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

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    int ans = 0;
    int count = 1;
    for(int i=1; i<n; i++){
        if(a[i] == a[i-1]) count += 1;
        if(a[i] != a[i-1]){
            ans += (count % 2);
            count = 1;
        }
    }
    cout << ans + count % 2 << endl;
    return 0;
}

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

using namespace std;

///////////////////////////////////////////
//const long long int INF = 1000000000000000000LL;
const long long int INF = 1000000;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(    v[0])>()) //降順でVをソート
///////////////////////////////////////////

vi v,v2;
string s,t;
ll n,m;
ll ans=0;

int main(){
    cin>>s;
    ll x= stoi(s);
    switch(s[0]){
        case '1':
            n = 1;
            break;
        case '2':
            n = 2;
            break;
        case '3':
            n = 3;
            break;
        case '4':
            n = 4;
            break;
        case '5':
            n = 5;
            break;
        case '6':
            n = 6;
            break;
        case '7':
            n = 7;
            break;
        case '8':
            n = 8;
            break;
        case '9':
            n = 9;
            break;
    }
    ll mm=0;
    ll k =n;
    rep(i,s.size()){
        mm+=n;
        n*=10;
    }
    if(x>mm){
        k++;
        mm=0;
        rep(i,s.size()){
            mm+=k;
            k*=10;
        }
        cout<<mm<<endl;
    }else{
        cout<<mm<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

int main() {
    int N;
    cin >> N;
    vint C(N);
    rep(i, N) {
        cin >> C[i];
    }
    vll dp(N + 1, 0);
    dp[0] = 1;
    ll p = 1000000007;
    unordered_map<int, ll> pre_sum;

    vint newC;
    newC.push_back(C[0]);
    REP(i, 1, N) {
        if (C[i] != C[i - 1])
            newC.push_back(C[i]);
    }
    N = newC.size();
    C = newC;
    REP(i, 1, N + 1) {
        dp[i] = dp[i - 1] + pre_sum[C[i - 1]];
        dp[i] %= p;
        pre_sum[C[i - 1]] += dp[i - 1];
        pre_sum[C[i - 1]] %= p;
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 11672
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

const int MAX = 1000000;

int main() {
    string str;
    getline(cin, str);
    int j=0, o=0, i=0;
    int ans = 0;
    REP(t, str.length()) {
        if (str[t]=='J') {
            if (t>0 && str[t-1]=='O') j=0;
            j++;
            o=0;
            i=0;
        } else if (str[t]=='O') {
            o++;
            i=0;
            if (o>j) {
                j=0;
                o=0;
            }
        } else {
            i++;
            j=0;
            if (i>o) {
                o=0;
                i=0;
            }
            if (i==o) ans = max(ans, i);
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 2056
import scala.io.StdIn._
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val a,b = sc.nextInt
  if(a+b<a-b){
    if(a-b<a*b){
      println(a*b)
    }
    else{
      println(a-b)
    }
  }
  else{
    if(a+b<a*b){
      println(a*b)
    }
    else{
      println(a+b)
    }
  }
}

Measured memory_bytes: 27344
#include <bits/stdc++.h>
//#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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



int main(){fastio
    ll n;cin>>n;
    string a,b,c;cin>>a>>b>>c;
    ll ans=0;
    for(ll i=n-1;i>=0;i--){
        if(a[i]==b[i]&&a[i]==c[i]){
            continue;
        }else if(a[i]!=b[i]&&a[i]!=c[i]&&b[i]!=c[i]){
            ans+=2;
        }else{
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    _ = input()
    a = sorted(list(map(int, input().split())), reverse=True)
    if a[-1] == 0:
        print(0)
        return
    x = 1
    m = 10 ** 18
    for i in a:
        if i < 2:
            continue
        x *= i
        if x > m:
            print(-1)
            return
    print(-1 if x > 10 ** 18 else x)


if __name__ == '__main__':
    main()

Measured memory_bytes: 84668
n = int(input())
a = input().split()
b = input().split()
c = input().split()

manzoku_do = 0
i = 0

manzoku_do = 0
i = 0

manzoku_do += int(b[int(a[i]) - 1])
i += 1

while i < n:
  manzoku_do += int(b[int(a[i]) - 1])
  
  if int(a[i - 1]) -1  == int(a[i])-1 - 1:
    manzoku_do += int(c[int(a[i -1]) -1 ])
  i += 1
    
    
print(manzoku_do)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

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

int main(){

    int N; cin >> N;
    vector<int> D(N);
    vector<ll> num(N,0);
    for (int i=0;i<N;i++){
        cin >> D[i];
        num[D[i]]++;
    }
    if (D[0]!=0 || num[0]!=1){
        cout << 0 << endl;
        return 0;
    }
    ll max = -1;
    for(int i=0;i<N;i++){
        if(D[i]>max){
            max = D[i];
        }
    }
    ll sum=1;
    for(int i=1;i<=max;i++){
        ll tmp = num[i-1];
        for (int j=0;j<num[i]-1;j++){
            tmp = (tmp*num[i-1]) % mm;
        }
        cerr << "i=" << i << " :" << num[i-1] << " " << num[i] << "=" << tmp << endl;
        sum = (sum * tmp) % mm;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main()
{
  int valuePlace100, valuePlace10, valuePlace1;
  cin >> valuePlace100 >> valuePlace10 >> valuePlace1;
  int sum = (valuePlace100)*100+(valuePlace10)*10+valuePlace1;
  if(sum % 4 == 0)
  cout << "YES";
  else
  cout << "NO";
  return 0;
}

Measured memory_bytes: 256