akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<assert.h>

using namespace std;
 
#define pb push_back
#define mp make_pair
#define f first
#define s second
 
#define all(s) s.begin(),s.end()
#define spresent(s,v) ((s).find(v)!=s.end())
#define present(s,v) (find(all(s),v)!=s.end())
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL)
 
#define fill_1d(a,val) fill(a,a+sizeof(a)/sizeof(a[0]),val)
#define fill_2d(a,val) fill(&a[0][0],&a[0][0]+sizeof(a)/sizeof(a[0][0]),val)
#define fill_nd(a,p2f,val) fill(p2f,p2f+sizeof(a)/sizeof(*p2f),val)
 
#define deb(x) cout<<#x<<" = "<<x<<endl
#define dout(i,s) cout<<"Case #"<<i<<": "<<s<<"\n"
#define hout(i) cout<<"Case #"<<i<<": "

#define For(a,n) for(int i=a; (a<n?i<n:i>n) ; (a<n?++i:--i))
 
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
 
typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;

struct House{
	int start, end, height;
};
ostream& operator << (ostream &os, const House &s) {
	return (os << "Start: " << s.start << ", End: " << s.end << ", Height: " << s.height);
}

struct Segment{
	int start, end, height;
	ll perimeter;
};
ostream& operator << (ostream &os, const Segment &s) {
	return (os << "Start: " << s.start << ", End: " << s.end << ", Height: " << s.height << ", Perimeter: " << s.perimeter);
}
bool operator <(const Segment& x, const Segment& y) {
    return x.start < y.start;
}



const int N = 50;
const int MOD = 1e9+7;



void solve(){


}


int main() {

	ll max = 0;
	ll sum = 0;

	int n;
	cin>>n;

	for(int i=0;i<n;++i){
		int cur;
		cin>>cur;

		if(cur<max){
			sum+=max-cur;
		}
		else
			max=cur;

	}

	cout<<sum;








	return 0;
}





Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int main(){
  string s;cin>>s;
  bool C =false,F=false;
  for(int i = 0; s.size() > i; i++){
    if(!C && s[i] == 'C')C=true;
    if(C && s[i] == 'F') F = true;
  }
  if(F)cout << "Yes" <<endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;
bool ispallindrome(string str)
{
int n=str.size();
for(int i=0;i<n/2;i++)
    if(str[i]!=str[n-i-1])
        return false;
return true;
}

int main()
{
    string str;
    cin>>str;
    int n=str.size();
    if(ispallindrome(str.substr(0,(n-1)/2))&&ispallindrome(str))
        cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
def from_n_to_k(n, k):
  keta = []
  while n >= k:
    a = n % k
    keta.append(a)
    n = n // k
  return len(keta) + 1

num = [int(n) for n in input().split()]

r = from_n_to_k(num[0], num[1])
print(r)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

template<class T>struct UnionFind {
  vector<int> parent; vector<T> _diff;
  UnionFind(int n) {
    parent.resize(n, -1);
    _diff.resize(n, 0); // 親との差
  }
  int root(int x) {
    if (parent[x] == -1)
      return x;
    int r = root(parent[x]);
    _diff[x] += _diff[parent[x]];
    return parent[x] = r;
  }
  T weight(int x) {
    root(x);
    return _diff[x];
  }
  bool merge(int x, int y, T w) {
    if (same(x, y))
      return false;
    T d = weight(x) - weight(y) + w;
    x = root(x); y = root(y);
    parent[y] = x;
    _diff[y] = d;
    return true;
  }
  T diff(int x, int y) {
    return weight(y) - weight(x);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

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

  UnionFind<long long> T(N);
  rep(i, M) {
    int l, r, d; cin >> l >> r >> d;
    --l, --r;
    if (!T.merge(l, r, d) && T.diff(l, r) != d) {
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 1408
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[100005]={},x,ans=0;
  cin >> n >> x;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  if(a[0]>x) {
    ans+=a[0]-x;
    a[0]=x;
  }
  for(int i=0; i<n-1; i++) {
    if(a[i]+a[i+1]>x) {
      ans+=a[i]+a[i+1]-x;
      a[i+1]-=a[i]+a[i+1]-x;
    }
  }
  cout << ans << "\n";
}


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

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


    return 0;
}

Measured memory_bytes: 764
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    S = i2s()
    a = 0
    b = 0
    t = ['0', '1']
    for i, s in enumerate(S):
        if s == t[i & 1]:
            a += 1
        else:
            b += 1
    n = min(a, b)
    print(n)

main()


Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int n;
    cin >> n;
    long long int a[n];
    for ( long long int i = 0; i < n; i++ )
        cin >> a[i];
    
    int ans = 0;
    while (1)
    {
        bool existOdd = false;
        
        for ( long long int i = 0; i < n; i++ )
            if ( a[i] % 2 == 1 )
                existOdd = true;
        
        if ( existOdd )
            break;
        
        for ( long long int i = 0; i < n; i++ )
            a[i] /= 2;
        
        ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef map<int, int> mii;
    typedef map<char,int> mci;
    typedef vector<int> vi;
    typedef vector<vi> vvi;
    typedef vector<ll> vll;
    typedef vector<pair<int,int>> vii;
    typedef vector<char> vc;
    typedef vector<bool> vb;
    typedef vector<vb> vvb;
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define pb push_back
    #define F first
    #define S second
    #define in insert
    const int INF = 1e9 + 7;

    int main(){
        int n, m;  cin>>n>>m;
        vector<vii> v(n+1,vii());
        for(int i = 1; i <= m; i++){
            int p, y; cin>>p>>y;
            v[p].pb({y,i});
        }
        vii ans(m+1);
        for(int i = 1; i <= n; i++){
            sort(all(v[i]));
            for(int j = 0; j < v[i].size(); j++){
                ans[v[i][j].S] = {i, j+1};
            }
        }
        for(int i = 1; i <= m; i++){
            int a = ans[i].F;
            stringstream ss;
            ss << ans[i].F;
            string str = ss.str();
            for(int i = 1; i <= 6-str.size(); i++) cout<<0;
            cout<<ans[i].F;
            stringstream ss2;
            ss2 << ans[i].S;
            str = ss2.str();
            for(int i = 1; i <= 6-str.size(); i++) cout<<0;
            cout<<ans[i].S<<endl;
        }
    }

Measured memory_bytes: 7808
<?php

fscanf(STDIN, '%d', $n);

for ($i = 1; $i <= $n; $i++) {
    if ($i % 3 != 0 && strpos($i, '3') === FALSE) { continue; }

    $result[] = sprintf(' %d', $i);
}

printf('%s%s', implode('', $result), PHP_EOL);

Measured memory_bytes: 8848
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_imports)]

use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

const EMPTY: usize = 2;

// 参考
// https://atcoder.jp/contests/abc126/submissions/5458839

fn main() {
    input! {
        n: usize,
        uvw: [(usize1, usize1, u64); n-1]
    }
    let mut graph = vec![vec![]; n];
    for i in uvw.iter() {
        let u = i.0;
        let v = i.1;
        let w = i.2;
        graph[u].push((v, w));
        graph[v].push((u, w));
    }
    let mut color = vec![EMPTY; n];
    color[0] = 0;
    dfs(0, &graph, &mut color);
    for c in color.into_iter() {
        println!("{}", c);
    }
}

fn dfs(v: usize, graph: &Vec<Vec<(usize, u64)>>, color: &mut Vec<usize>) {
    for &(next, weight) in graph[v].iter() {
        let next_color = if weight % 2 != 0 {
            // 1 だったら 0, 0 だったら 1 になる。
            color[v] ^ 1
        } else {
            color[v]
        };
        if color[next] != EMPTY {
            assert_eq!(color[next], next_color);
        } else {
            color[next] = next_color;
            dfs(next, graph, color);
        }
    }
}

Measured memory_bytes: 28668
#include<iostream>

using namespace std;
int main(){
  int n;
  while(cin >> n){
    if(n==0) break;
    int p[25],ohajiki=31;
    for(int i=0; i<n; i++) cin >> p[i];
    int count=0;
    cout << ohajiki << endl;
    while(ohajiki!=1){
      if(count == n) count=0;
      ohajiki-=p[count];
      cout << ohajiki << endl;
      count++;
      ohajiki-=(ohajiki-1)%5;
      cout << ohajiki << endl;
    }
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
n=int(input())
A=list(map(int,input().split()))
mod=10**9+7

B=[[] for i in range(n)]
for i in range(n):
    B[i]= [((A[i]>>(59-j))) & 1 for j in range(60)]
    B[i] = [0]*(60-len(B[i]))+B[i]

TB=[[0]*n for i in range(60)]
for i in range(60):
    TB[i] = [B[j][i] for j in range(n)]
        
# import numpy as np
#print(TB)
ans=0
for i in range(60):
    now=TB[i]
    q=sum(now)
    
    ans+= ((pow(2,59-i,mod)* (q*(n-q)))%mod)%mod
    ans%=mod


print((ans)%mod)
    
     


Measured memory_bytes: 689972
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int A,B,C;
	string S;
	cin >> A >> B >> S;
	C=count(S.cbegin(), S.cend(), '-');
	if(S.size()==A+B+1&&S[A]=='-'&&C==1){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

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

ll dsum(string s){
    ll sum = 0;
    rep(i,s.length()){
        sum += s.at(i) - '0';
    }
    return sum;
}

int main() {
    vector<string> c;
    while(1){
        string in;
        cin >> in;
        if(in == "0")break;
        else c.push_back(in);
    }
    rep(i,c.size())cout << dsum(c[i]) << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
#include <cstdlib>
#define INT_MAX 2147483647
#define INT_MIN -2147483646
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
void fastios() { ios_base::sync_with_stdio(0); cin.tie(0); }

static const int N = 10005;

struct vertex {
	int id;
	int p;
	int d;
	bool operator<(const vertex & another) const {
		return (d != another.d ? d>another.d : id>another.id);
	}
};

struct edge {
	int end;
	int w;
};

int main() {
	fastios();
	int n;
	cin >> n;
	vector<vector<edge>> E(N);
	Loop(i, n) {
		int u, k;
		cin >> u >> k;
		Loop(i, k) {
			int v, c;
			cin >> v >> c;
			E[u].push_back({ v,c });
		}
	}
	//
	priority_queue<vertex> pq;
	vi color(N, 0), dist(N, 0);
	pq.push({ 0,-1,0 });
	int cnt = 0;
	while (pq.size() > 0) {
		if (cnt == n) break;
		vertex v = pq.top();
		pq.pop();
		if (color[v.id] == 1) continue;
		dist[v.id] = v.d;
		color[v.id] = 1;
		cnt++;
		Loop(j, E[v.id].size()) {
			pq.push({ E[v.id][j].end, v.id, dist[v.id] + E[v.id][j].w });
		}
	}
	Loop(i, n) {
		cout << i << " " << dist[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 14076
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

void dfs(string s, string tmp, int cnt, vector<string> &ret) {
    if ((int)s.size() == cnt) {
        //cout << tmp << endl;
        ret.push_back(tmp);
        return;
    }
    dfs(s, tmp+s[cnt], cnt+1, ret);
    if (cnt != 0) dfs(s, tmp+"+"+s[cnt], cnt+1, ret);
    return;
}

int main() {
    string s;
    cin >> s;
    vector<string> ret;
    dfs(s, "", 0, ret);
    ll ans = 0;
    for (auto a: ret) {
        int idx = 0;
        //cout << (int)a.size() << endl;
        while(idx < (int)a.size()){
            string tmp = "";
            while(a[idx]!='+' && idx < (int)a.size()) {
                tmp += a[idx];
                ++idx;
            }
            reverse(tmp.begin(), tmp.end());
            ll num = 0;
            ll keta = 1;
            rep(i, (int)tmp.size()) {
                num += (tmp[i] - '0') * keta;
                keta *= 10LL;
            }
            //cout << num << endl;
            ans += num;
            ++idx;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<map>
#define N 110000
#define M 3100
#define LL long long
using namespace std;
LL p[M],a[N],r[N];
int pl,n,ans;
bool b[M];
map<LL,int> ma;
map<LL,bool> v;
void pre()
{
	for(int i=2;i<M;i++)
	{
		if(b[i]==0) p[++pl]=i;
		for(int j=1;j<=pl;j++)
		{
			if(i*p[j]>=M) break;
			b[i*p[j]]=1;
			if(i%p[j]==0) break;
		}
	}
}
LL cal(LL x)
{
	if(x==1)
	{
		ans=1;
		return 1;
	}
	LL res=1;
	for(int i=1;i<=pl;i++)
		if(x%p[i]==0)
		{
			LL t=p[i]*p[i];
			if(x%t==0) x/=t,res*=p[i];
			else x/=p[i],res*=t;
		}
	LL q=sqrt(x);
	while(q*q>x) q--;
	if(q*q==x) res*=q;
	else res*=x*x;
	return res;
}
int main()
{
	pre();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		LL x;scanf("%lld",&x);
		for(int j=1;j<=pl;j++)
		{
			LL t=p[j]*p[j]*p[j];
			if(t>x) break;
			while(x%t==0) x/=t;
		}
		a[i]=x;r[i]=cal(x);
	}
	for(int i=1;i<=n;i++) v[a[i]]=v[r[i]]=0,ma[a[i]]=ma[r[i]]=0;
	for(int i=1;i<=n;i++) ma[a[i]]++;
	v[1]=1;
	for(int i=1;i<=n;i++)
	{
		if(v[a[i]]) continue;
		v[a[i]]=v[r[i]]=1;
		ans+=max(ma[a[i]],ma[r[i]]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 26880
#include<bits/stdc++.h>
#define pb push_back
#define It set<node>::iterator
#define endl '\n'
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int arr[10];

int main(){
	cin>>arr[1]>>arr[2]>>arr[3];
	sort(arr+1,arr+3+1);
	if(arr[1]==arr[2]&&arr[2]!=arr[3]||arr[1]!=arr[2]&&arr[2]==arr[3]) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
"""
author : halo2halo
date : 16, Jan, 2020
"""

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
P = list(map(int, read().split()))

print(sum(P) + max(P) // 2-max(P))


Measured memory_bytes: 12396
#include <stdio.h>

constexpr char* S_OUT[31] = {
    "0\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n",
    "11\n", "12\n", "13\n", "14\n", "15\n", "16\n", "17\n", "18\n", "19\n", "20\n",
    "21\n", "22\n", "23\n", "24\n", "25\n", "26\n", "27\n", "28\n", "29\n", "30\n"
};

constexpr unsigned int InputSize = 1e6;
constexpr unsigned int OutputSize = 3e5;
char Input[InputSize];
char* pointer = Input;
char Output[OutputSize];
char* m_buffer = Output;

inline unsigned int getInt(void){
    unsigned int res = 0;
    do{ res = 10 * res + (*(pointer++) - '0'); } while(*pointer >= '0');
    return res;
}

inline void out(int v){
    char* str = S_OUT[v];
    while(*str) *(m_buffer++) = *(str++);
}

unsigned int n;
unsigned int N;
constexpr unsigned int SIZE = (1U << 19) + 1;
unsigned int data[2 * SIZE];

inline void set(void){
    n = getInt(); N = 1U << (31 - __builtin_clz(n)); while(N < n) N <<= 1;
    ++pointer; // \n
    unsigned int i, j;
    for(i = 0, j = N; i < n; ++i, ++j) data[j] = 1U << (*(pointer++) - 'a');
    for(i = N - 1; i ; --i) data[i] = data[i << 1] | data[(i << 1) | 1U];
}

inline void query(void){
    pointer += 3;
    if(*(pointer - 2) == '1'){
        unsigned int index = getInt() - 1;
        unsigned char idx = *((++pointer)++) - 'a';
        data[index += N] = 1U << idx;
        while(index >>= 1) data[index] = data[index << 1] | data[(index << 1) | 1U];
    }
    else{
        unsigned int l = getInt() + N - 1; pointer++;
        unsigned int r = getInt() + N;
        unsigned int res = 0;
        while(l < r){
            if(l & 1) res |= data[l++]; l >>= 1;
            if(r & 1) res |= data[--r]; r >>= 1;
        }
        out(__builtin_popcount(res));
    }
}

int main(void){
    fread(Input, sizeof(char), InputSize, stdin);
    set(); ++pointer;
    unsigned int q = getInt();
    while(q--) query();
    fwrite(Output, sizeof(char), m_buffer - Output, stdout);
    return 0;
}

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

 using namespace std;

 int main() {
   int N, M, i, sum;
   cin >> N;

   vector<int> T(N + 1);

   for (i = 1; i <= N; i++) cin >> T.at(i);
   sum = 0;
   for (i = 1; i <= N; i++) sum += T.at(i);

   cin >> M;

   vector<int> P(M + 1);
   vector<int> X(M + 1);

   for (i = 1; i <= M; i++) cin >> P.at(i) >> X.at(i);



   for (i = 1; i <= M; i++) {
     cout << sum - T.at(P.at(i)) + X.at(i) << endl;
   }

 }


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

using ll = long long;

const ll INF = 1001001001;
const ll mod = 1000000007;

int N;
double dp[301][301][301];

double rec(int i, int j, int k) {
	if (i + j + k == 0) return 0;
	if (dp[i][j][k] > 0) return dp[i][j][k];
	double p0 = (double)(N - i - j - k) / N;
	double p1 = (double)i / N;
	double p2 = (double)j / N;
	double p3 = (double)k / N;
	double res = 1;
	if (i > 0) res += rec(i - 1, j, k) * p1;
	if (j > 0) res += rec(i + 1, j - 1, k) * p2;
	if (k > 0) res += rec(i, j + 1, k - 1) * p3;
	res /= 1 - p0;
	return dp[i][j][k] = res;
}

int main() {
	cin >> N;
	int a[3] = {};
	for (int i = 0; i < N; ++i) {
		int x;
		cin >> x;
		x--;
		a[x]++;
	}
	printf("%.10f\n", rec(a[0], a[1], a[2]));
}

Measured memory_bytes: 213248
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int s=0;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    s+=a[i];
  }
  cout<<s-n;
}
  

Measured memory_bytes: 3652
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
bool vis[100004];
vector <int> v[100004];
void dfs(int x){
	vis[x]=1;
	for (int i=0;i<v[x].size();i++) if (!vis[v[x][i]])
		dfs(v[x][i]);
}
int main(){
	int n,m;
	cin>>n>>m;
	for (int i=0;i<m;i++){
		int x,y,z;
		cin>>x>>y>>z;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int ans=0;
	for(int i=1;i<=n;i++) if (!vis[i]){
		ans++;
		dfs(i);
	}
	cout<<ans;
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
template<class T> inline bool chmin(T& a, T b){
    if(a>b){a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){
    if(a<b){a=b;return true;}return false;}
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll N,W;cin>>N>>W;
    vvl dp(N+1,vl(W+1,inf));
    rep(i,W+1)dp[0][i]=0;
    repl(i,1,N+1){
        ll w,v;cin>>w>>v;
        rep(j,W+1){
            if(j>=w)dp[i][j]=max(dp[i-1][j],dp[i-1][j-w]+v);
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[N][W]<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    int N;
    vector<int> A, B, Ans;
    
    cin >> N;
    A.resize(N);
    for(int i = 0; i < N; ++i)
      cin >> A[i];
    
    cin >> N;
    B.resize(N);
    for(int i = 0; i < N; ++i)
      cin >> B[i];
      
      
    set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(Ans, Ans.end()));
    
    for(auto x : Ans)
      cout << x << endl;
    
    return 0;
}


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

int main() {

  int N;
  cin >> N;

  string S;
  vector<string> vec(N);

  for (int i = 0; i < N; i++) {
    cin >> S;
    sort(S.begin(), S.end());
    vec.at(i) = S;
  }

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

  long long ans = 0;
  int ctr = 0;

  for (int i = 1; i < N; i++) {
    if (vec.at(i - 1) == vec.at(i)) {
      ctr ++;
      ans += ctr;
    }
    else {
      ctr = 0;
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

#define rep(i,n) for(int i=0;i<(n);i++)

int main(){
    int A,B,K,D,E;
    cin>>A>>B>>K;
    if(B-A<K){
        D=B+1;
        E=B+1;
    }else{
        D=A+K;
        E=B-K+1;
    }
    for(int i=A;i<D;i++){
        cout<<i<<endl;
        if(i+1==E) break;
    }
    for(int i=E;i<=B;i++){
        cout<< i<< endl;
    }
    return 0;
}

//a=97,z=122

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

void print(int n, int A[]){
    
    for(int i = 0; i < n; i++){
        cout << A[i] << (i != n-1 ? " " : "\n");
    }
    
}

void bubble_sort(int n, int A[]){
    
   int i = n - 1, count = 0, position = 0;
   
   while(i > position){
       
       int j = i;
       
       while(j > position){
           if(A[j] < A[j - 1]){
               swap(A[j], A[j - 1]);
               count++;
           }
            j--;
        }
        
        position++;
   }

   
    print(n, A);
    cout << count << endl;
    
}

int main(void){
    
    int n, A[100] = {};
    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    
    bubble_sort(n, A);
    
    
}



Measured memory_bytes: 3116
card = [[0 for i in range(3)] for j in range(3)]

for i in range(3):
    a,b,c = map(int,input().split())
    card[i][0] = a
    card[i][1] = b
    card[i][2] = c

op = [[False for i in range(3)] for j in range(3)]

n = int(input())

for l in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if card[i][j] == b:
                op[i][j] = True

flag = False

for i in range(3):
    if op[i][0] and op[i][1] and op[i][2]:
        flag = True
    if op[0][i] and op[1][i] and op[2][i]:
        flag = True

if op[0][0] and op[1][1] and op[2][2]:
    flag = True


if op[0][2] and op[1][1] and op[2][0]:
    flag = True

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
string s;
int main()
{
	cin>>s;
	int size=s.length();
	for(int i=0;i<size;i++)
	{
		if(s[i]!=',')
		cout<<s[i];
		else cout<<" "; 
	}
	cout<<endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
  using tsii=tuple<string,int,int>;
  int N;
  cin>>N;
  vector<tsii> vec(N);
  string a;
  int b,c;
  rep(i,N){
    cin>>a>>b;
    c=i;
    vec.at(i)=make_tuple(a,100-b,c);
  } 
  sort(vec.begin(),vec.end());
  rep(i,N) cout<<get<2>(vec.at(i))+1<<endl;
}

Measured memory_bytes: 256
n,x,t=map(int,input().split())
count=0
a=0
a=x
if(n<=x):
        print(t,end='\n')
        
elif(x==1):
        print((n)*t)
else:    
    while(x<n):
        count=count+1
        x=x+a    
    print((count+1)*t)

Measured memory_bytes: 8972
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int k;
    string s;
    cin>>k>>s;
    int n=s.length();
    rep(i,min(k,n))cout<<s[i];
    if(n>k)cout<<"...";
    cout<<endl;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
	int n;
	while(cin >> n){
		bool s=false;
		bool l=false,r=false;
		int ans=0;
		if(n==0)
			break;
		rep(i,n){
			string in;
			cin >> in;
			if(in=="lu")
				l=true;
			if(in=="ld")
				l=false;
			if(in=="ru")
				r=true;
			if(in=="rd")
				r=false;

			if((~s)&l&r){
				s=true;
				ans++;
			}
			if(s&(~l)&(~r)){
				s=false;
				ans++;
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,i1,n) for(int i=(int)(i1);i<(int)(n);i++)
#define ll long long
#define vi vector<int>
#define vl vector<long long>

int main() {
  int n=0;
  cin>>n;
  if(n%1000!=0){
  cout<<1000-n%1000;
  }else{
    cout<<0;
  }
}

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

int main(){
  for(int a,b,c,ans;cin >> a >> b;){
  ans=1;
  c=a+b;
  if(c>=10){
    ans++;
  }
  if(c>=100){
    ans++;
  }
  if(c>=1000){
    ans++;
  }
  if(c>=10000){
    ans++;
  }
  if(c>=100000){
    ans++;
  }
  if(c>=1000000){
    ans++;
  }
  cout << ans<<endl;
}
  return 0;
}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

int CheckRange(int a, int b);

int main()
{
    int A,B;
    cin >> A >> B;

    if(CheckRange(A, B) == 1)
    {
        cout << A * B << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}

int CheckRange(int num1, int num2)
{
    int num[2];
    num[0] = num1;
    num[1] = num2;

    for(int i = 0; i < 2; i++)
    {
        if(num[i] > 9)
        {
            return -1;
        }
    }
    return 1;
}

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

using myTuple = std::tuple<long long, long long, long long>;

long long myABS( long long x, long long y )
{
	return ( x < y ? y - x : x - y );
}

long long myMIN( long long x, long long y )
{
	return ( x < y ? x : y );
}

long long myMAX( long long x, long long y )
{
	return ( x < y ? y : x );
}

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

	std::vector<long long> v( N );

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

	// 累積和を先に計算する
	std::vector<long long> sum( N + 1 );
	sum[0] = 0;
	for ( int i = 0; i < N; i++ )
	{
		sum[i + 1] = sum[i] + v[i];
	}

	// ( P, Q, R, S )を管理する -> ( left, mid, right )
	std::vector<myTuple> vT;

	// まず中央（QとRを分ける位置）を決める
	// -> 最低でも左側に2要素、右側に2要素必要
	int midL, rightL, bestL = 1;
	int leftR, midR, bestR = 3;
	long long result;

	for ( int i = 2; i <= N - 2; i++ )
	{
		// i番目の要素が中央の仕切りの時の(P, Q)を求める
		result = std::numeric_limits<long long>::max();
		midL = bestL;
		rightL = i;

		while ( midL < rightL )
		{
			long long tmpP = sum[midL] - sum[0];
			long long tmpQ = sum[rightL] - sum[midL];
			long long d = myABS( tmpQ, tmpP );

			// 差分が一番小さい時が最適な仕切り位置
			if ( d <= result )
			{
				// resultを更新
				result = d;

				// 最適な仕切り位置を更新する
				bestL = midL;
			}
			else
			{
				// これ以上良い値は見つからないはず？
				break;
			}

			midL++;	//	左側2要素の中央の仕切りを右に移動する
		}

		// i番目の要素が中央の仕切りの時の(R, S)を求める
		result = std::numeric_limits<long long>::max();
		leftR = i;
		if ( bestR <= i )
		{
			// 最低でも1要素ないとダメなので、仕切りの隣の要素からスタート
			midR = i + 1;
		}
		else
		{
			midR = bestR;
		}

		while ( midR < N )
		{
			long long tmpR = sum[midR] - sum[leftR];
			long long tmpS = sum[N] - sum[midR];
			long long d = myABS( tmpS, tmpR );

			// 差分が一番小さい時が最適な仕切り位置
			if ( d <= result )
			{
				// resultを更新
				result = d;

				// 最適な仕切り位置を更新する
				bestR = midR;
			}
			else
			{
				// これ以上良い値は見つからないはず？
				break;
			}

			midR++;	//	右側2要素の中央の仕切りを右に移動する
		}

		// 左側と右側の最適なmidの位置が決まってP/Q/R/Sが求められたので、
		// vectorに突っ込む（左仕切り位置、中央仕切り位置、右仕切り位置）
		vT.emplace_back( std::make_tuple( bestL, i, bestR ) );
	}

	// 最適なP/Q/R/Sの候補を計算し終えたので、最適解を出力する
	long long output = std::numeric_limits<long long>::max();
	for ( auto &&it : vT )
	{
		long long tmpLeft = std::get<0>( it );
		long long tmpCenter = std::get<1>( it );
		long long tmpRight = std::get<2>( it );

		long long tmpP = sum[tmpLeft];
		long long tmpQ = sum[tmpCenter] - sum[tmpLeft];
		long long tmpR = sum[tmpRight] - sum[tmpCenter];
		long long tmpS = sum[N] - sum[tmpRight];

		long long tmpMIN = myMIN( myMIN( tmpP, tmpQ ), myMIN( tmpR, tmpS ) );
		long long tmpMAX = myMAX( myMAX( tmpP, tmpQ ), myMAX( tmpR, tmpS ) );
		long long tmpABS = myABS( tmpMIN, tmpMAX );

		if ( tmpABS < output )
		{
			output = tmpABS;
		}
	}

	std::cout << output << std::endl;

	return ( 0 );
}


Measured memory_bytes: 11632
n=int(input());s=[*input()]
count=s.count('R')*s.count('G')*s.count('B')
for i in range(n+1):
  for j in range(i,n+1):
    k=2*j-i
    if k<n:
      if s[i]!=s[j] and s[j]!=s[k] and s[i]!=s[k]:
        count-=1
print(count)

Measured memory_bytes: 9048
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <unordered_map>
#include <queue>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;


int main(){
    ll N;
    cin >> N;
    if (N==1){
        cout << 0 << endl;
        return 0;
    }
    cout << N * (N-1) / 2 << endl;
}

Measured memory_bytes: 256
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

a,b,c = ip()
k = inp()

ct = 0
while b <= a:
    b *= 2
    ct += 1
while c <= b:
    c *= 2
    ct += 1

if ct <= k:
    print("Yes")
else:
    print("No")





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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    ll ans = 0;
    rep1(i, n) {
        if (i%3==0) continue;
        if (i%5==0) continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

void solve(){
    int n;
    cin >> n;
    int c = 0;
    while(n--){
        int x, y;
        cin >> x >> y;
        if(x == y){
            ++c;
            if(c == 3){
                cout << "Yes\n";
                return;
            }
        }else
            c = 0;
    }
    cout << "No\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3608
fun main(args: Array<String>){
val (K,N) = readLine()!!.split(" ").map{ it.toInt() }
val list = readLine()!!.split(" ").map{ it.toInt() }
val seiri = list.sorted()
  var ans = 0
  for(i in 1..N){
    ans = ans + seiri[i-1]
    
  }
println(ans)
}

Measured memory_bytes: 40508
# D - String Formation
from collections import deque
S = input()
Q = int(input())
now = 1
tmp = [deque([]),deque([])]
for _ in range(Q):
    t = list(input().split())
    if t[0]=='1':
        now = 1+(now==1)
    else:
        if int(t[1])==now:
            tmp[0].append(t[2])
        else:
            tmp[1].append(t[2])
ans = ''
if now==1:
    i,j = 0,1
else:
    i,j = 1,0
while len(tmp[i])>0:
    ans += tmp[i].pop()
if now==2:
    S = S[::-1]
ans += S
while len(tmp[j])>0:
    ans += tmp[j].popleft()
print(ans)

Measured memory_bytes: 11460
pub fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut graph: Vec<Vec<(usize, u64)>> = vec![vec![];n];
    for _ in 0..n-1 {
        let a: usize = iter.next().unwrap().parse::<usize>().unwrap() - 1;
        let b: usize = iter.next().unwrap().parse::<usize>().unwrap() - 1;
        let c: u64 = iter.next().unwrap().parse().unwrap();
        graph[a].push((b, c));
        graph[b].push((a, c));
    }

    let q: usize = iter.next().unwrap().parse().unwrap();
    let k: usize = iter.next().unwrap().parse::<usize>().unwrap() - 1;
    
    
    // k -> i
    let mut costs: Vec<Option<u64>> = vec![None;n];
    costs[k] = Some(0);

    for _ in 0..q {
        let x: usize = iter.next().unwrap().parse::<usize>().unwrap() - 1;
        let y: usize = iter.next().unwrap().parse::<usize>().unwrap() - 1;
        let s = len(&graph, &mut costs, k, x, std::usize::MAX);
        let t = len(&graph, &mut costs, k, y, std::usize::MAX);
        println!("{}", s.unwrap() + t.unwrap());
    }
}

fn len(graph: &[Vec<(usize,u64)>], costs: &mut [Option<u64>], k: usize, cur: usize, pre: usize) -> Option<u64> {
    if let Some(v) = costs[cur] {
      return Some(v);
    }

    let mut ret: Option<u64> = None;
    for &(v, cost) in &graph[cur] {
        if pre == v {continue;}
        if let Some(rest) = len(graph,costs,k,v,cur) {
            if let Some(rr) = ret {
                ret = Some(std::cmp::min(rr, cost + rest));
            } else {
                ret = Some(cost + rest);
            }
        }
    }
    costs[cur] = ret;
    ret
}


Measured memory_bytes: 36340
import java.util.BitSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		BitSet set = new BitSet();
		boolean hasWild = false;
		while ((n != k) && (n != 0)) {
			set.clear();
			hasWild = false;
			for (int i = 0; i < k; i++) {
				final int nextInt = in.nextInt();
				if (nextInt != 0) {
					set.set(nextInt);
				} else {
					hasWild = true;
				}
			}
			int start = set.nextSetBit(0);
			int sizeMax = 0;
			while (start != -1) {
				int end = start;
				while (set.get(end + 1)) {
					end++;
				}
				int nextstart = set.nextSetBit(end + 1);
				if (hasWild && set.get(end + 2)) {
					end += 2;
					while (set.get(end + 1)) {
						end++;
					}
				}
				final int size = (end - start)+1;
				sizeMax = Math.max(sizeMax, size);
				start = nextstart;
			}
			System.out.println(sizeMax);
			n = in.nextInt();
			k = in.nextInt();
		}

	}
}

Measured memory_bytes: 61804
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            const int priceA = 380, volA = 200;
            const int priceB = 550, volB = 300;
            const int priceC = 850, volC = 500;

            while (true)
            {
                int volume = int.Parse(Console.ReadLine());

                if (volume == 0) break;

                int minPrice = int.MaxValue;

                for (int c = 0; c * volC <= volume; c++)
                {
                    int restB = volume - c * volC;

                    for (int b = 0; b * volB <= restB; b++)
                    {
                        int restA = restB - b * volB;

                        if (restA % volA != 0) continue;

                        int a = restA / volA;

                        int price = a * priceA + b * priceB + c * priceC;

                        int setA = a / 5;
                        int setB = b / 4;
                        int setC = c / 3;

                        int discount = setA * 380 + setB * 330 + setC * 306;

                        price -= discount;

                        minPrice = Math.Min(minPrice, price);
                    }
                }
                sb.AppendLine(minPrice.ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9196
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    long double ans = 0;
    pair<long double, string> xu;
    for (int i = 0; i < n; i++) {
        cin >> xu.first >> xu.second;
        if (xu.second == "BTC") {
            ans += xu.first * 380000.0;
        } else {
            ans += xu.first;
        }
    }

    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
 
class DandA {
    static void Main(string[] args) {
        int[] nm = ReadLineIntArray();
        List<long> aList = ReadLineLongList();
        aList.Sort();
        aList.Reverse();
 
        while(nm[1] > 0) {
            aList[0] /= 2;
            nm[1]--;
            if (nm[1] == 0) {break;}
            for (int i = 1; i < nm[0]; i++) {
                if (aList[0] > aList[i]) {
                    aList.Sort();
                    aList.Reverse();
                    break;
                } else {
                    aList[i] /= 2;
                    nm[1]--;
                    if (nm[1] == 0) {break;}
                }
            }
        }
        Console.WriteLine(aList.Sum());
    }
 
    static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static string[] strAry = new string[] {"L", "R", "U", "D"};
    static int[] intArray = new int[10];
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private long ReadLineLong() {return long.Parse(Console.ReadLine());}
    static private double ReadLineDouble() {return double.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private List<long> ReadLineLongList() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToList();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private double[] ReadLineDoubleArray() {return Console.ReadLine().Trim().Split().Select(a => double.Parse(a)).ToArray();}
    static private decimal[] ReadLineDecimalArray() {return Console.ReadLine().Trim().Split().Select(a => decimal.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
 
    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
  
    static private string IntToNString(int x, int n) {
        var nstring = "";
        var numbers = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
        int r = 1;
        int q = x;
        while (q > 0) {
            r = q % n;
            nstring += numbers[r];
            q = q / n;
        }
        return string.Join("",nstring.Reverse());
     }
}

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

int a[3]={1,2,3};
int n;
int m;
int main() {
  cin>>n;
  cin>>m;
  if (n+m==3){
    cout<<3;
  }  
  if (n+m==5){
    cout<<1; 
     }
  if (n+m==4){
    cout<<2;
  }
  
}

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

A.sort()
B.sort()
A=A[::-1]
B=B[::-1]
flag=False
for i in range(1,N):
    if A[i]==A[i-1]:
        flag=True
        break
for i in range(1,M):
    if B[i]==B[i-1]:
        flag=True
        break
    

i=0
j=0

now_max = N*M

prob=1
row = 0
col = 0
if flag:
    print(0)
else:
    while i<N or j<M:
        if i==N:
            if B[j]==now_max:
                now_max-=1
                j+=1
                prob=(prob*col)%(10**9 + 7)
                row+=1
            else:
                prob=(prob*max(col*row-(N*M-now_max),0))%(10**9 + 7)
                now_max-=1
        elif j==M:
            if A[i]==now_max:
                now_max-=1
                i+=1
                prob=(prob*row)%(10**9 + 7)
                col+=1
            else:
                prob=(prob*max(col*row-(N*M-now_max),0))%(10**9 + 7)
                now_max-=1
                
        else:
            if A[i]==now_max and B[j]==now_max:
                now_max-=1
                i+=1
                j+=1
                row+=1
                col+=1
            elif A[i]==now_max:
                now_max-=1
                i+=1
                prob=(prob*row)%(10**9 + 7)
                col+=1
            elif B[j]==now_max:
                now_max-=1
                j+=1
                prob=(prob*col)%(10**9 + 7)
                row+=1
            else:
                prob=(prob*max(col*row-(N*M-now_max),0))%(10**9 + 7)
                now_max-=1
                
        
    
    for i in range(1,now_max+1):
        prob=(prob*i)%(10**9 + 7)
    print(prob)

Measured memory_bytes: 3192