akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    queue<vector<int>> que;
    que.push(l);
    int ans = 1 << 16;
    while (!que.empty()) {
        vector<int> front = que.front();
        que.pop();
        int sz = front.size();
        sort(front.begin(), front.end());
        if (sz == 3) {
            int score = abs(front[0] - c) + abs(front[1] - b) + abs(front[2] - a) + 10 * (n - sz);
            ans = min(ans, score);
        } else {
            int sm = 1 << 16;
            for (int i = 0; i < sz - 2; i++) {
                for (int k = i + 1; k < sz - 1; k++) {
                    for (int l = k + 1; l < sz; l++) {
                        int cur = abs(front[i] - c) + abs(front[k] - b) + abs(front[l] - a);
                        sm = min(sm, cur);
                    }
                }
            }
            ans = min(ans, 10 * (n - sz) + sm);
            for (int i = 0; i < sz - 1; i++) {
                for (int k = i + 1; k < sz; k++) {
                    vector<int> nw = front;
                    nw[i] = front[i] + front[k];
                    nw.erase(nw.begin() + k);
                    que.push(nw);
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 32760
using namespace std;
int M=1000001;
int ish[1000001],nh[1000001];
int main(){
	for(int i=1;i<M;i*=2)for(int j=i;j<M;j*=3)for(int k=j;k<M;k*=5)ish[k]=1;
	for(int i=1;i<M;i++)nh[i]=nh[i-1]+ish[i];
	
	int n,m;
	while(cin>>m>>n,m)cout<<nh[n]-nh[m-1]<<endl;
	return 0;
}

Measured memory_bytes: 0
n = int(input())
s = input()
count =[[0 for i in range(3)] for i in range(n+1)]
for i in range(1,n+1):
    if s[i-1] == 'R':
        count[i][0] = count[i-1][0] + 1
    else:
        count[i][0] = count[i-1][0]
    if s[i-1] == 'G':
        count[i][1] = count[i-1][1] + 1
    else:
        count[i][1] = count[i-1][1]
    if s[i-1] == 'B':
        count[i][2] = count[i-1][2] + 1
    else:
        count[i][2] = count[i-1][2]
ans = 0
words = set(['R','G','B'])
for i in range(n):
    for j in range(i+1,n):
        k = set([s[i],s[j]])
        if len(k) == 2:
            remain = (words - k)
            remain = list(remain)[0]
            d = j-i
            if remain == 'R':
                if j + d < n and s[j + d] == 'R':
                    ans += count[-1][0] - count[j][0] - 1
                else:
                    ans += count[-1][0] - count[j][0]
            elif remain == 'G':
                if j + d < n and s[j + d] == 'G':
                    ans += count[-1][1] - count[j][1] - 1
                else:
                    ans += count[-1][1] - count[j][1]
            else:
                if j + d < n and s[j + d] == 'B':
                    ans += count[-1][2] - count[j][2] - 1
                else:
                    ans += count[-1][2] - count[j][2]
print(ans)



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

int main() {
  int a, b;

  cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using ll=long long int;

int main() {
    string s;
    cin >> s;
    int m = stoi(s.substr(5, 2));
    int d = stoi(s.substr(8, 2));

    if (m < 4 || (m == 4 && d <= 30)) {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }

    return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<<#x<<":"<<x<<'\n'

//↓0-originか1-originでn回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}

int inf = 1e9+1; 
/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int n, m, l; cin >> n >> m >> l;
    vii matrix(n, vi(n, inf));
    rep(i,m) {
        int a,b,c; cin >> a >> b >> c; a--; b--; //1-index -> 0-index
        matrix[a][b] = c;
        matrix[b][a] = c;
    }
  /*rep(i,n) {
        rep(j,n) {
            debug(matrix[i][j]);  //デバッグ
        }
    }*/

//Step1 : 最短距離を求める
    vii dist = matrix;
    //warshall floyd
    for(int k = 0; k < n; k++) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(dist[i][k] == inf || dist[k][j] == inf) continue;
                chmin(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
  /*rep(i,n) {
        rep(j,n) {
            debug(dist[i][j]);  //デバッグ
        }
    }*/

//Step2 : 最小限の補給回数を求める(通れるところだけ使って行く行き方とその補給回数を考えてる)
    //回数最適化用グラフ(距離l以下のところだけ1'回'で通れるよ。を表すグラフ)
    vii chargecount(n, vi(n, inf));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(dist[i][j] <= l) {
                chargecount[i][j] = 1;
                chargecount[j][i] = 1;
            }
        }
    }
  /*rep(i,n) {
        rep(j,n) {
            debug(chargecount[i][j]);  //デバッグ
        }
    }*/

    //実際に補給回数を数え上げるwarshall floyd
    vii answer = chargecount;
    for(int k = 0; k < n; k++) {
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(answer[i][k] == inf || answer[k][j] == inf) continue;
                chmin(answer[i][j], answer[i][k] + answer[k][j]);
            }
        }
    }
  /*rep(i,n) {
        rep(j,n) {
            debug(answer[i][j]);  //デバッグ
        }
    }*/
    int q; cin >> q;
    rep(i,q) {
        int s,t; cin >> s >> t; s--; t--;  //1-index -> 0-index
        cout << (answer[s][t] != inf ? answer[s][t]-1 : -1) << '\n';
    }
}

Measured memory_bytes: 2048
import Data.Bits
import Data.List
import Control.Monad
import qualified Data.Vector.Unboxed as V
import Control.Monad.ST
import Data.Maybe (fromMaybe)
import qualified Data.ByteString.Lazy.Char8 as B
import Debug.Trace

f :: [Int] -> Int
f [] = 0
f (a:as) = a + (g as)

g :: [Int] -> Int
g [] = 0
g (a:as) = (-a) + (f as)


main :: IO ()
main = do
  n <- readLn :: IO Int
  as <- map read.words <$> getLine :: IO [Int]
  forM_ (take ((length (scanl (\x a -> (2*) $ a - (x `div` 2)) (f as) as)) - 1) (scanl (\x a -> (2*) $ a - (x `div` 2)) (f as) as)) $ \x -> putStr (show x) >> putStr " "
  putStrLn ""


Measured memory_bytes: 83324
#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>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;
 
int main() {
    string s;
    cin >> s;
    if (s.back() == 's') s += "es";
    else s+="s";
    cout << s << endl;
 
    return 0;
}

Measured memory_bytes: 3500
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b >= 10)puts("error");
	else cout << a + b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main (void)


{


int n,i,ai,max,min;


double sum;


sum=0.0;


max=-1000000;


min=1000000;


scanf("%d",&n);


for(i=0;i<n;i++){


scanf("%d",&ai);


if(ai<min){


min=ai;


}


if(max<ai){


max=ai;


}


sum=sum+ai;


}


printf("%d %d %.0lf\n",min,max,sum);


return 0;


}

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

namespace ABC_Training
{
    public class WaterContainer
    {
        int _a, _b, _c;
        public WaterContainer(int a, int b, int c)
        {
            _a = a;
            _b = b;
            _c = c;
        }

        public int RemainWaterInB => Math.Max(_c - (_a - _b), 0);
    }
    class Program
    {
        static void Main(string[] args)
        {
            var abc = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];

            var waterContainer = new WaterContainer(a, b, c);
            int result = waterContainer.RemainWaterInB;

            Console.WriteLine(result);
        }

    }
}


Measured memory_bytes: 13268
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define F first
#define S second
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;

#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;
int res[N];
std::vector<int > adj[N];
int vis[N];

int dfs(int u){
	vis[u] = 1;
	for(auto v: adj[u])
		if(vis[v]==0){
			res[v] += res[u];
			dfs(v);
		}

}


int solve() 
{
	//happy coding

  	int n,m;
  	cin>>n>>m;
  	for(int i=0;i<n-1;i++){
  		int u,v;
  		cin>>u>>v;
  		adj[u].pb(v);
  		adj[v].pb(u);
  	}

  	for(int i=0;i<m;i++){
  		int v,x;
  		cin>>v>>x;
  		res[v] += x;
  	}

  	dfs(1);

  	for(int i=1;i<=n;i++){
  		cout<<res[i]<<" ";
  	}cout<<endl;

  
	return 0;
}
int main(){
	int test = 1;
  	//scanf("%d", &test);
  	while (test--)solve();return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N ; i++){
        cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    for(int i=1; i<N; i++){
        if (A.at(i-1) == A.at(i)){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 1024
fn main() {
    let n = read::<usize>();
    if n % 2 == 0 {
        println!("{}", n);
    } else {
        println!("{}", n * 2);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 100 + 5;
int vis[N];

int main(){
	int n,k;
	cin >> n >> k;
	for(int i = 1; i <= k; i++){
		int d;
		cin >> d;
		for(int i = 1; i <= d; i++){
			int a;
			cin >> a;
			vis[a] = 1;
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(!vis[i])
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
n = gets.strip.to_i
h = gets.strip.split.map(&:to_i)

h[h.length] = 10**9

(1..n).each do |i|
  if h[i] - h[i-1] >= 1
    h[i] -= 1
  elsif h[i] - h[i-1] < 0
    puts 'No'
    exit 0
  end
end
puts 'Yes'


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

int		main(void)
{
	string s;

	cin >> s;
	int x = -1000;

	for (int i = 0; i < s.size() - 2; i++)
	{
		int tmp = stoi(s.substr(i, 3));

		if (abs(tmp - 753) < abs(x - 753))
			x = tmp;
	}
	cout << abs(x - 753) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m,to[200001],next[200001],tot,col[100001],head[100001],sum[3],cnt;
long long ans;
bool vis[100001],flag;
void add(int u,int v){to[++tot]=v,next[tot]=head[u],head[u]=tot;}
void dfs(int x,int color){
	++cnt;
	col[x]=color;
	sum[color]++;
	vis[x]=true;
	for(int i=head[x];i;i=next[i]){
		if(!vis[to[i]])dfs(to[i],3-color);
		else if(col[x]==col[to[i]])flag=true;
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	for(int i=1;i<=n;i++)if(!vis[i]){
		dfs(i,1);
		if(!flag)ans+=1LL*sum[1]*sum[2];
		else ans+=1LL*cnt*(cnt-1)/2;
		sum[1]=sum[2]=flag=cnt=0;
	}
	printf("%lld\n",ans-m);
	return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String T = sc.nextLine();
		int cnt = 0;
		for(int i=0; i < 3; i++) {
			if(S.charAt(i) == T.charAt(i)) {
				cnt += 1;
			}
		}
		// 出力
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
char st[222222];
int main() {
	deque<int> dq;
	int n, k;
	scanf("%d%d", &n, &k);
	scanf("%s", st);
	int rev(0);
	for(int i(0); i < n; i++)
		dq.push_back(st[i] == 'A');
	if(k > 2 * n) {
		k = 2 * n + (k % 2);
	}
	for(int i(1); i <= k; i++) {
		if(dq.front() ^ rev) {
			dq.pop_front();
			dq.push_front(rev);
		}else {
			dq.pop_front();
			rev ^= 1;
			dq.push_back(1 ^ rev);
		}
	}
	for(int i(0); i < n; i++) {
		putchar(rev ^ dq.front() ? 'A' : 'B');
		dq.pop_front();
	}
}


Measured memory_bytes: 1536
h,w,a,b = map(int,input().split())
ans = []
for _ in range(h-b):
    l = '0' * (w-a) + '1' * a
    ans.append(l)
for _ in range(b):
    l = '1' * (w-a) + '0' * a
    ans.append(l)
for i in range(h):
    print(''.join(ans[i]))

Measured memory_bytes: 9764
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val monsterHP = BigInt(sc.next())

    var ans = BigInt(1)

    while (ans <= monsterHP) {
      ans *= 2
    }

    println(s"${ans - 1}")
  }
}


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

string join(const vector<int>& v, const char* delim = 0) {
  string s = to_string(v[0]);
  for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) {
    if (delim) s += delim;
    s += to_string(v[i]);
  }
  return s;
}

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  vector<int> rep(N);

  for (int i = 0; i < N; i++) {
    rep.at(vec.at(i) - 1) = i + 1;
  }

  cout << join(rep, " ") << endl;
}

Measured memory_bytes: 5080
#include<iostream>
//#include<cmath>
#include<math.h>

using namespace std;

int main()
{
    // 入力
    int A,B,H,M;
    int hun;
    double sa_a, ans, ang_a, ang_b;
    const double w_a = 0.5;
    const double w_b = 6.0;
    const double pi = 3.141592653589793;

    cin >> A >> B >> H >> M;

    hun = H*60+M;
    ang_a = (w_a*double(hun));
    ang_b = double(int(w_b*hun)%360);
    sa_a = pi/180.0*double(ang_b - ang_a);
    // cout << hun << endl;
    // cout << ang_a << endl;
    // cout << ang_b << endl;
    // cout << sa_a * 180/pi << endl;

    if(abs(sa_a) >= pi){
        ans = pow(A,2)+pow(B,2)-double(2*A*B*cos(-1.*sa_a));
        
    }else{
        ans = pow(A,2)+pow(B,2)-double(2*A*B*cos(sa_a));
    }
    printf("%.10lf",sqrt(ans));  
    
    return 0;
}

Measured memory_bytes: 4164
import java.io.*;
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    
    int max = A + B;
    if (A - B > max) {
      max = A - B;
    }
    if (A * B > max)  {
      max = A * B;
    }
    
    System.out.println(max);
  }
}

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

int main() {

    int n;
    while ( cin >> n && n != 0 ) {

	vector<int> b;
	int v;
	for ( int i=0; i<n; ++i ) {
	    cin >> v;
	    b.push_back( v );
	}

	int cnt = 0;
	while ( cnt <= 10000 ) {

	    //三角形になっているか
	    bool tri_num = true;
	    if ( b[0] != 1 ) tri_num = false;
	    for ( int i=1; i<b.size(); ++i ) {
		if ( b[i] != b[i-1]+1 ) {
		    tri_num = false;
		    break;
		}
	    }
	    if ( tri_num ) break;

	    vector<int> b_tmp;
	    for ( int i : b ) {
		if ( i > 1 ) b_tmp.push_back( i-1 );
	    }
	    b_tmp.push_back( b.size() );
	    b = b_tmp;;

	    ++cnt;
	}

	if ( cnt > 10000 ) cout << -1 << endl;
	else cout << cnt << endl;

    }

    return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>


using namespace std;
string yn(bool a)
{
  if (a){return "Yes";}
  else{return "No";}
}

bool sosuu(int n)
{
  int i=3;
  if(n==1){return false;}
  if(n==2){return true;}
  if(n%2==0){return false;}
  while(true)
  {
    if(n%i==0&&n!=i){return false;}
    if(i>sqrt(n)+1){break;}
    i+=2;
  }
  return true;

}

int main()
{
  ios::sync_with_stdio(false);
  long int x,y;
  cin >> x>>y;
  int result=0;
  while(x<=y)
  {
    x*=2;
    result++;
  }
  cout<<result;

}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7
    #epsilon = 10**-9

    h,w,k = map(int, input().split())
    c = [list(input().rstrip()) for _ in range(h)]
    res = 0

    def calc(tate, yoko):
        cnt = 0
        for i in range(h):
            if i in tate:
                continue
            for j in range(w):
                if j in yoko:
                    continue
                if c[i][j] == '#':
                    cnt += 1
        if cnt == k:
            return True
        else:
            return False


    for i in range(h+1):
        for tate in combinations(range(h), i):
            for j in range(w+1):
                for yoko in combinations(range(w), j):
                    if calc(tate, yoko):
                        res += 1
    
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9476
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  int a,b;
  cin>>a>>b;
  int ans = max(a,b);
  if(ans==a)a--;
  else if(ans==b)b--;
  ans+=max(a,b);
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

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

//v.erase(unique(v.begin(),v.end()),v.end());

int main(){
	int n;
	cin>>n;
	vint v(n);
	rep(i,n*(n-1)/2){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		a--;
		b--;
		if(c>d){
			v[a]+=3;
		}
		else if(c<d){
			v[b]+=3;
		}
		else{
			v[a]++;
			v[b]++;
		}
	}
	vector<pii> vp;
	rep(i,n){
		vp.PB(mkp(-v[i],i));
	}
	sort(ALL(vp));
	int t1=vp[0].F,t2=1;
	rep(i,n){
		if(t1==vp[i].F){
			v[vp[i].S]=t2;
		}
		else{
			t1=vp[i].F;
			v[vp[i].S]=i+1;
			t2=i+1;
		}
	}
	rep(i,n){
		cout<<v[i]<<endl;
	}
}

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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque
//stack…FILO
//queue…FIFO
//priority_queue…格納された最大値から順に取り出す
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, char index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}

template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}

template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

ull ans = 0;
/*
int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}
*/
int main() {
    ull n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    string s;
    cin >> s;

    rep(i, a-1, c-2) {
        if (s[i] == '#' && s[i+1] == '#') {
            cout << "No" << endl;
            return 0;
        }
    }
    rep(i, b-1, d-2) {
        if (s[i] == '#' && s[i+1] == '#') {
            cout << "No" << endl;
            return 0;
        }
    }

    if (c < d) {
        cout << "Yes" << endl;
        return 0;
    }

    rep(i, b-1, min(c, d)-1) {
        if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

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

int main(){
	int n,l;

	cin >>n >>l;
	l=0;
	string array[n];
	for(int i=0;i<n;i++)cin >>array[i];
	sort(array,array+n);
	for(int i=0;i<n;i++)cout<<array[i];
	cout<<'\n';
	return 0;
}

Measured memory_bytes: 256
tim = int(input())
A   = [int(A) for A in input().split()]
for i in range(tim) :
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v :
        A[j + 1] = A[j]
        j -= 1
        A[j + 1] = v
    A2 = list(map(str, A))
    print(' '.join(A2))

Measured memory_bytes: 7748
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;
typedef long double ld;

int A, B, C, D, E, F;
vector<int> w;

ld calc(ld water, ld sugar) {
  return (sugar / (water+sugar)) * 100;

}

int main() {
  scanf("%d %d %d %d %d %d", &A, &B, &C, &D, &E, &F);
  
  //水の量全列挙
  for (int a = 0; a <= F; a += A*100) {
    for (int b = 0;  a + b <= F; b += B*100) {
      if (a == 0 && b == 0) continue;
      w.pb(a+b);
    }
  }
  sort(w.bg, w.en);
  
  //砂糖の量を全探索
  //砂糖を入れられる最低限の水量が濃度を最大にする
  ld max_density = 0.0;
  int max_water = w[0];
  int max_sugar = 0;
  for (int c = 0; c <= F / 100 * E; c += C) {
    for (int d = 0;  c + d <= F / 100 * E; d += D) {
      int sugar = c + d;
      int need = (sugar+E-1) / E * 100;
      auto itr = lower_bound(w.bg, w.en, need);
      int water = *itr;
      if (water+sugar > F || itr == w.en) continue;
     
      ld density = calc((ld)water, (ld)sugar);
      
      if (density >= max_density) {
        max_water = water;
        max_sugar = sugar;
        max_density = density;
      }
      
    }
  }
  
  printf("%d %d\n", max_water+max_sugar, max_sugar);

}

Measured memory_bytes: 256
#include <iostream>

typedef long long ll;

const ll MOD = 998244353;

ll N, K, dp[200005], dps[200005];
int S[11][3];

ll sum(ll l, ll r) {
  if (r < 1)  return 0;
  ll ans = dps[r];
  if (l > 1) ans = (ans - dps[l-1] + MOD) % MOD;
  return ans;
}

int main() {
  std::cin >> N >> K;
  for (int i = 0; i < K; ++i)
    std::cin >> S[i][0] >> S[i][1];

  dps[0] = 0;
  dp[1] = 1, dps[1] = 1;
  for (int i = 2; i <= N; ++i) {
    dp[i] = 0;
    for (int k = 0; k < K; ++k)
      dp[i] = (dp[i] + sum(i - S[k][1], i - S[k][0])) % MOD;
    dps[i] = (dp[i] + dps[i-1]) % MOD;
  }

  std::cout << dp[N] << "\n";

  return 0;
}


Measured memory_bytes: 6748
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

UInt GreatestCommonDivisor(UInt a, UInt b) {
    if (b == 0) {
        return a;
    } else {
        if (a < b) {
            std::swap(a, b);
        }
        return GreatestCommonDivisor(b, a % b);
    }
}
UInt LeastCommonMultiple(UInt a, UInt b) {
    Int gcd = GreatestCommonDivisor(a, b);
    return a / gcd * b;
}
#define GCD GreatestCommonDivisor
#define LCM LeastCommonMultiple

int main(void) {
    Int a, b, c, d, e;
    cin >> a >> b >> c >> d;
    a--;
    e = LCM(c, d);

    Int s = b - b / c - b / d + b / e;
    Int t = a - a / c - a / d + a / e;
    cout << s - t << endl;
    return 0;
}


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

typedef long long ll;

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

    double l;
    cin >> l;
    double a,b,c;
    a = b = c = l / 3;
    printf("%.12lf\n",a*b*c);
    return 0;
}

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

int main() {
  int X;
  cin >> X;
  if (X / 100 == 1) {
    cout << 9;
  }
  else {
    cout << 1;
  }
  if ((X % 100) / 10 == 1) {
    cout << 9;
  }
  else {
    cout << 1;
  }
  if (X % 10 == 1) {
    cout << 9;
  }
  else {
    cout << 1;
  }
  cout << endl;
}

Measured memory_bytes: 3520
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace ARC089D
{
    public class Program
    {
        int N;
        int K;
        int K2;
        int[,] imos;

        void Add(int lx, int ty, int rx, int by)
        {
            lx %= K2;
            ty %= K2;
            rx %= K2;
            by %= K2;

            if (lx > rx)
            {
                Add(lx, ty, K2 - 1, by);
                Add(0, ty, rx, by);
                return;
            }
            if (ty > by)
            {
                Add(lx, ty, rx, K2 - 1);
                Add(lx, 0, rx, by);
                return;
            }

            imos[ty, lx]++;
            imos[by + 1, lx]--;
            imos[ty, rx + 1]--;
            imos[by + 1, rx + 1]++;
        }

        void Solve(StreamScanner ss, StreamWriter sw)
        {
            //---------------------------------
            N = ss.Next(int.Parse);
            K = ss.Next(int.Parse);
            K2 = K * 2;
            imos = new int[K2 + 1, K2 + 1];

            for (var i = 0; i < N; i++)
            {
                var X = ss.Next(int.Parse);
                var Y = ss.Next(int.Parse);
                var C = ss.Next(String);
                if (C == "B") X += K;

                Add(X, Y, X + K - 1, Y + K - 1);
                Add(X + K, Y + K, X + K2 - 1, Y + K2 - 1);
            }

            for (var i = 0; i <= 2 * K; i++)
            for (var j = 0; j <= 2 * K; j++)
            {
                if (i != 0) imos[i, j] += imos[i - 1, j];
                if (j != 0) imos[i, j] += imos[i, j - 1];
                if (i != 0 && j != 0) imos[i, j] -= imos[i - 1, j - 1];
            }

            var max = 0;
            foreach (var value in imos) max = Math.Max(max, value);
            sw.WriteLine(max);
            //---------------------------------
        }

        static void Main()
        {
            var ss = new StreamScanner(new StreamReader(Console.OpenStandardInput()));
            var sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            new Program().Solve(ss, sw);
            sw.Flush();
        }

        static readonly Func<string, string> String = s => s;
    }

    public class StreamScanner
    {
        static readonly char[] Sep = {' '};
        readonly Queue<string> buffer = new Queue<string>();
        readonly TextReader textReader;

        public StreamScanner(TextReader textReader)
        {
            this.textReader = textReader;
        }

        public T Next<T>(Func<string, T> parser)
        {
            if (buffer.Count != 0) return parser(buffer.Dequeue());
            var nextStrings = textReader.ReadLine().Split(Sep, StringSplitOptions.RemoveEmptyEntries);
            foreach (var nextString in nextStrings) buffer.Enqueue(nextString);
            return Next(parser);
        }
    }
}

Measured memory_bytes: 30816
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define PI 3.14159265
#define MOD 1000000007
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n;
ll ans;

int main(){
    ios::sync_with_stdio(0);
    cin >> n;
    ans = 1;
    forn(i,n){
        ans = (ans*(i+1))%MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3640
N,K = map(int,input().split())
p = list(map(int,input().split()))

l = []
for i in p:
    l.append((1/2*i*(i+1))/i)

s = [0]*len(l)
s[0] = l[0]
for i in range(1,len(l)):
    s[i] = s[i-1]+l[i]

ans = 0
for i in range(K,len(s)):
    ans = max(ans,s[i]-s[i-K])

if N == K:
    print(max(s))
    exit()

print(ans)

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

int main() {
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    vector<string> divisors{"dream", "dreamer", "erase", "eraser"};
    for (int i = 0; i < 4; i++)
        reverse(divisors[i].begin(), divisors[i].end());

    for (int i = 0; i < S.size();) {
        bool flag = false;
        for (int j = 0; j < 4; j++) {
            string t = divisors[j];
            if (S.substr(i, t.size()) == t) {
                flag = true;
                i += t.size();
            }
        }
        if (!flag) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define EPS (1e-5)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 110000

int N, K;
int A[MAX];
int hoge[100];
int fuga[100];

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	cin>>N>>K;
	
	rep(i,N){
		cin>>A[i];
		int num = A[i];
		
		for(int i = 0; num; i++){
			if(num%2)hoge[i]++;
			num /= 2;
		}
	}
	
	// for(int i = 0; i <= 20; i++){
		// cout<<i<<" "<<hoge[i]<<endl;
	// }
	
	
	int t = 1ll<<42, ans = 0;
	
	for(int i = 0, r = 1; i <= 42; i++, r *= 2){
		fuga[i] += max(hoge[i],N-hoge[i])*r;
		fuga[i+1] += fuga[i];
	}
		
	for(int i = 42, temp = 0; i >= 0; i--, t>>=1){
		if((K>>i)&1){
			if(i)ans = max(ans,temp+fuga[i-1]+hoge[i]*t);
			// temp += max(hoge[i],N-hoge[i])*t;
			temp += (N-hoge[i])*t;
			// cout<<" <-> <->"<<endl;
		} else {
			temp += hoge[i]*t;
			// cout<<" <o> <o>"<<endl;
		}
		
		if(!i) ans = max(ans,temp);
		// cout<<i<<" "<<fuga[i]<<" "<<ans<<" "<<temp<<endl;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
#include <string.h>
using namespace std;

int main() {
	long long int N,t=0,p=0,k=0,C[500-1]={},S[500-1]={},F[500-1]={};
	cin>>N;
	for(int i=0;i<N-1;i++){
		cin>>C[i]>>S[i]>>F[i];
	}
	for(int i=0;i<N-1;i++)
	{
		for(int j=i;j<N-1;j++)
		{
			p=S[j];
			k=0;
			while(t>p)
			{
				if(k==0){
					p+=((t-p)/F[j]*F[j]);
			//cout<<((t-p)/F[j]*F[j])<<endl;
					}
				else {
					p+=F[j];
					//cout<<"Y";
					}
				k++;
			}
			//cout<<p<<" "<<t<<endl;
			p+=C[j];
			t=p;
		}
		cout<<t<<endl;
		t=0;
	}
	cout<<"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 N = sc.nextInt();

		int[] num = new int[N];

		for(int i = 0;i < N;i++){
			num[i]= sc.nextInt();
		}

		int max = num[0];
		int min = num[0];

		for(int i = 0;i < N;i++) {
			if(max < num[i]) {
				max = num[i];
			}
		}

		for(int i = 0;i < N;i++) {
			if(min > num[i]) {
				min = num[i];
			}
		}
		System.out.println(max - min);
	}
}


Measured memory_bytes: 21844
import java.util.*
import kotlin.math.*

fun int() = readLine()!!.toInt()
fun list() = readLine()!!.split(" ").map {it.toInt()}

fun main() {
	val n = int()
	val a = list().sortedDescending()

	val l = PriorityQueue<Int>(reverseOrder())
	l.add(min(a[0],a[1]))
	l.add(min(a[0],a[1]))

	var r = a[0].toLong()
	for(i in 2 until n) {
		val v = l.poll()
		r += v
		l.add(min(v,a[i]))
		l.add(min(v,a[i]))
	}
	println(r)
}


Measured memory_bytes: 74172
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,c;
  cin >> N;
  vector<pair<string,pair<int,int>>> in(N);
  for(int i=0;i<N;i++){
    cin >> in[i].first >> c;
    in[i].second.first = c * -1;
    in[i].second.second = i+1;
  }
  sort(in.begin(),in.end());
  for(pair x : in) cout << x.second.second << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n, x, y;
	cin >> n >> x >> y;
	vector<int> cnt(n);
	for(int i = 1; i < n; i++) {
		for(int j = i+1; j <=n; j++) {
			int d = min(j-i, abs(x-i)+abs(y-j)+1);
			cnt[d]++;
		}
	}
	for(int i = 1; i < n; i++) cout << cnt[i] << endl;
	return 0;
}



Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<cstdio>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<stack>
#include<iterator>
#include<functional>
#include<string.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//namespace mp = boost::multiprecision;


int main() {
	int n, q;
	cin >> n;
	vector<int>s(n);
	int count = 0;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	cin >> q;
	vector<int>t(q);
	for (int i = 0; i < q; i++) {
		cin >> t[i];
		int sd = find(s.begin(), s.end(), t[i])-s.begin();
		//cout << sd << endl;
		if (0<=sd&&sd<=s.size()-1) {
			count++;
		}
	}
	cout << count << endl;
}


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

int main() {
    int n;
    cin >> n;
    int Alice = 0, Bob = 0;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a), greater<int>());
    rep(i,n) {
        if(i%2==0) Alice+= a[i];
        else Bob += a[i];
    }
    cout << Alice - Bob << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
// cmath ではない
#include <math.h>
#include <iomanip> // for setprecision

using namespace std;

int main()
{
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    double dist = sqrt( pow(x2-x1, 2)+pow(y2-y1, 2) );
    // 小数点下表示桁数指定
    cout << fixed << setprecision(6) << dist << endl;

    return 0;
}


Measured memory_bytes: 3260
import sys
n = int(input())
f_ls = []
p_ls = []
INF= 1e10
for j in range(n):
    f = [int(i) for i in sys.stdin.readline().split()]
    f_ls.append(f)
for j in range(n):
    p = [int(i) for i in sys.stdin.readline().split()]
    p_ls.append(p)

best = -INF
for i in range(1,1<<10):
    score = 0
    for shop in range(n):
        cnt = 0
        p = p_ls[shop]
        for ind, (j,k) in enumerate(zip(bin(i)[2:].zfill(10), f_ls[shop])):
            if j == "1" and k == 1:
                cnt += 1
        score += p[cnt]
    if best < score:
        best = score
print(best)

Measured memory_bytes: 42860
#include<stdio.h>
int main(){
    int a[210000],i,n,j,k;
	
	scanf("%d%d", &k,&n);
	for(i=0; i<n;i++){
		scanf("%d", &a[i]);
	}
  
  j=a[0]+k-a[n-1];
  for(i=0;i<n-1;i++){
    if(a[i+1]-a[i]>=j){
      j=a[i+1]-a[i];
    }

  }
	    printf("%d\n",k-j);
    return 0;
	
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <string>
using namespace std;
int a[501];
typedef long long ll;
int main(){
	ll n;
	while(cin>>n&&n!=0){
		fill(a,a+501,0);
		ll tmp=n;
		ll cnt=0;
		if(n>=0){
			// ºÌ©çÉ
			while(tmp){
				if(cnt%2==0)
					a[cnt]+=(tmp%10);
				// »ÌÌÝÅìé±ÆªÅ«È¢½ßAãÌÌÍðg¤
				else{
					if(tmp%10!=0){
						a[cnt+1]++;
						a[cnt]+=10-(tmp%10);
					}
				}
				tmp/=10;
				cnt++;
			}
		}
		else{
			tmp=abs(tmp);
			// ÈºvC³
			// ºÌ©çÉ
			while(tmp){
				if(cnt%2)
					a[cnt]+=(tmp%10);
				// »ÌÌÝÅìé±ÆªÅ«È¢½ßAãÌÌÍðg¤
				else{
					if(tmp%10!=0){
						a[cnt+1]++;
						a[cnt]+=10-(tmp%10);
					}
				}
				tmp/=10;
				cnt++;
			}
		}
		// 10ðz¦Ä¢éÌ
		for(int i = 0; i < 501; i++){
			if(a[i]>=10){
				// ãÌÅLZÅ«éÈçs¤
				int t=a[i]/10;
				if(a[i+1]>=t){
					a[i+1]-=t;
					a[i]-=t*10;
				}
			}
			if(a[i]>=10){
				if((i%2)==0){
					ll lf=a[i];
					a[i]=lf%10;
					a[i+2]+=(lf/100);
					if(((lf/10)%10)>0){
						a[i+2]++;
						a[i+1]+=(10-((lf/10)%10));
					}
				}
				else{
					ll lf=a[i];
					a[i]=10-(lf%10);
					if(a[i]==10)
						a[i]=0;

					ll t=a[i]/100;
					a[i+2]+=t;

					if((lf/10)%10!=0){
						a[i+2]++;
						a[i+1]+=(10-(lf/10)%10);
					}
				}
			}
		}
		// ³
		string str;
		for(int i = 0; i < 501; i++)
			str+=(char)(a[i]+'0');
		reverse(str.begin(),str.end());
		int idx=-1;
		for(int i = 0; i < str.size(); i++){
			if(str[i]!='0'){
				idx=i;
				break;
			}
		}
		if(idx!=-1)
			str=str.substr(idx);
		cout<<str<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
class SegTree:

    def __init__(self, init_val, n, ide_ele, seg_func):
        self.segfunc = seg_func
        self.num = 2**(n-1).bit_length()
        self.ide_ele = ide_ele
        self.seg=[self.ide_ele]*2*self.num
        for i in range(n):
            self.seg[i+self.num-1]=init_val[i]    
        for i in range(self.num-2,-1,-1) :
            self.seg[i]=self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
        
    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k+1:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1],self.seg[k*2+2])
        
    def query(self, p, q):
        if q<=p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res=self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res,self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res,self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res,self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res,self.seg[p]),self.seg[q])
        return res

n = int(input())
xs = list(map(int, input().split()))
x2i = {}
for i, x in enumerate(xs):
    x2i[x] = i
ss1 = SegTree([n] * n, n, n, min)
ss2 = SegTree([-1] * n, n, -1, max)

r = 0
for x in range(n):
    x = n - x
    rmi2 = ss1.query(x2i[x]+1, n)
    if rmi2 != n:
        ss1.update(rmi2, n)
    rmi = ss1.query(x2i[x]+1, n)
    if rmi2 != n:
        ss1.update(rmi2, rmi2)

    lmi = ss2.query(0, x2i[x])
    if lmi != -1:
        ss2.update(lmi, -1)
    lmi2 = ss2.query(0, x2i[x])
    if lmi != -1:
        ss2.update(lmi, lmi)
    a,b,c,d =(x2i[x] - lmi), (lmi - lmi2), (rmi - rmi2), (rmi2 - x2i[x])
    r += (a*c + b*d) * x
#    print(x, r)
#    print(rmi, rmi2, lmi, lmi2)
    ss1.update(x2i[x], x2i[x])
    ss2.update(x2i[x], x2i[x])
print(r)


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int R, G, B, N;
int m[3001][3001] = {0};
int dfs(int r, int g) {
  int ans = 0;
  if (m[r][g] == 1) return 0;
  else m[r][g] = 1;
  if (N - (R * r + G * g) < 0) return 0;
  if (N - (R * r + G * g) >= 0 && (N - (R * r + G * g)) % B == 0) ans = 1;
  return ans + dfs(r + 1, g) + dfs(r, g + 1);
}
int main() {
  cin >> R >> G >> B >> N;
  cout << dfs(0, 0) << endl;
}


Measured memory_bytes: 35328
//Bimmillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int t,n,i,j,count=0,cunt,x,sum;
    char arr[10];
    vector <int> vec;
    string st;
    cin >> st;
    for(i=0;i<3;i++)
    {
        if(st[i]=='R')
        {
            count++;
        }
        else
        {
            count=0;
        }
        vec.push_back(count);
    }
    cout << *max_element(vec.begin(),vec.end()) << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = (ll)9e18;
int N, T;
int sum_v;
vi W, V;
vector<vl> dp;

void input_init(void) {
	cin >> N >> T;
	W.resize(N + 1);
	V.resize(N + 1);
	sum_v = 0;
	for (int i = 1; i <= N; ++i) {
		cin >> W[i] >> V[i];
		sum_v += V[i];
	}
	dp.resize(N + 1, vl(sum_v + 1, INF));
	dp[0][0] = 0;
}

void solve(void) {
	for (int i = 1; i <= N; ++i) {
		for (int j = 0; j <= sum_v; ++j) {
			if (j + V[i] <= sum_v)
				dp[i][j + V[i]] = min(dp[i - 1][j] + W[i], dp[i][j + V[i]]);
			dp[i][j] = min(dp[i - 1][j], dp[i][j]);
		}
	}
}

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

	input_init();
	solve();
	int ans = 0;
	for (int j = 1; j <= sum_v; ++j) {
		if (dp[N][j] <= T)
			ans = j;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 80256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner (System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int ans=0;
	Integer l[]=new Integer[n];
		for(int i=0;i<n;i++)l[i]=sc.nextInt();
		Arrays.sort(l,Comparator.reverseOrder());
		for(int i=0;i<m;i++)ans+=l[i];
		System.out.println(ans);
	}
}

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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,b,a)     for(int i=b;i>=a;i--)
#define endl '\n'

#define ll long long int

int n;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    
    cin>>n;
    n%=10;
    if(n==2 || n==4 || n==5 || n==7 || n==9)
    	cout<<"hon";	 
    else if(n==0 || n==1 || n==6 || n==8)
    	cout<<"pon";
    else
    	cout<<"bon";
}
	

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

int main() {
	string T;
	cin >> T;
	bool isPossible[T.size()+1];
	string words[4] = {"dream", "dreamer", "erase", "eraser"};
	isPossible[0] = true;
	for (int i = 1;i <= T.size();i++) {
		if(i >= 5) {
			bool found = false;
			for (int j = 0;j < 4 && !found;j++) {
				if(words[j].size() > i) continue;
				int l = 0, k;
				for(k = words[j].size()-1;k >= 0 && words[j][k] == T[i-1-l];k--, l++) ;
				//cout << i << " " << k << " " << words[j] << endl;
				if(k < 0 && isPossible[i-words[j].size()]) {
					found = true;
				}
			}
			isPossible[i] = found;
		}
		//cout << i << " " << isPossible[i] << endl;
	}
	cout << (isPossible[T.size()]?"YES":"NO") << endl;
	return 0;
}

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

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    double out=0;
    rep(i, n){
        if(i<k){
            out += pow((double)1/2, ceil(log2((double) k/(i+1))));
        }else{
            out += 1;
        }
    }
    printf("%.18lf\n",out/n);
    return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

const MOD: u64 = 1000000007;

fn modpow(a: u64, n: u64) -> u64 {
    let mut res: u64 = 1;
    let mut b: u64 = a;
    let mut m: u64 = n;
    loop{
        if m == 0 {
            break;
        }
        if m % 2 == 1 {
            res = (res * b) % MOD;
        }
        b = (b * b) % MOD;
        m = m / 2;
    }
    res
}

#[fastout]
fn main() {
    input! {
        n: usize,
    }
    let mut v: Vec<usize> = vec![0; 60];
    for _ in 0..n {
        input! {
            mut a: u64,
        }
        for i in 0..60 {
            if a % 2 == 1 {
                v[i] += 1;
            }
            a = a / 2;
        }
    }

    let mut w: Vec<u64> = vec![0; 60];
    for i in 0..60 {
        w[i] = ((v[i] * (n - v[i])) as u64) % MOD;
    }

    let mut ans: u64 = 0;

    for i in 0..60 {
        ans = (ans + (modpow(2,i) * w[i as usize]) % MOD) % MOD;
    }

    println!("{}",ans);

}


Measured memory_bytes: 7820