akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <list>
#include <stack>
#include <queue>

using namespace std;

int main()
{
    
    
    string s;
    cin >>  s;
    
    
    int s1;
    int s2;
    
    
    if((s[0]=='0'&& s[1]!='0') ||(s[0]=='1'&&s[1]=='0')||(s[0]=='1'&&s[1]=='1')||(s[0]=='1'&&s[1]=='2'))
        s1 =1;
    
    else s1=0;
    
    
    if((s[2]=='0'&& s[3]!='0') ||(s[2]=='1'&&s[3]=='0')||(s[2]=='1'&&s[3]=='1')||(s[2]=='1'&&s[3]=='2'))
        s2 =1;
    
    else s2=0;
    
    if(s1==1&&s2==1) cout << "AMBIGUOUS";
    else if(s1==1&&s2==0) cout << "MMYY";
    else if(s1==0&&s2==1) cout << "YYMM";
    else  cout << "NA";
    
    
}


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

using namespace std;

int main(){

  int n;
  
  cin >> n;
  
  for(int i = 0;i < n;++i){
	string num;
	cin >> num;
	
	char m = '1';
	
	for(int j = 0;j < num.size();++j){
	  int nn = num[j] - '0';
	  
	  if(nn == 1){
		if(m == '1' || m == ' ')
		  m = '.';
		else if(m == '.')
		  m = ',';
		else if(m == ',')
		  m = '!';
		else if(m == '!')
		  m = '?';
		else if(m == '?')
		  m = ' ';
	  }
	  else if(nn == 2){
		if(m == '1' || m == 'c')
		  m = 'a';
		else if(m == 'a')
		  m = 'b';
		else if(m == 'b')
		  m = 'c';
	  }
	  else if(nn == 3){
		if(m == '1' || m == 'f')
		  m = 'd';
		else if(m == 'd')
		  m = 'e';
		else if(m == 'e')
		  m = 'f';
	  }
	  else if(nn == 4){
		if(m == '1' || m == 'i')
		  m = 'g';
		else if(m == 'g')
		  m = 'h';
		else if(m == 'h')
		  m = 'i';
	  }
	  else if(nn == 5){
		if(m == '1' || m == 'l')
		  m = 'j';
		else if(m == 'j')
		  m = 'k';
		else if(m == 'k')
		  m = 'l';
	  }
	  else if(nn == 6){
		if(m == '1' || m == 'o')
		  m = 'm';
		else if(m == 'm')
		  m = 'n';
		else if(m == 'n')
		  m = 'o';
	  }
	  else if(nn == 7){
		if(m == '1' || m == 's')
		  m = 'p';
		else if(m == 'p')
		  m = 'q';
		else if(m == 'q')
		  m = 'r';
		else if(m == 'r')
		  m = 's';
	  }
	  else if(nn == 8){
		if(m == '1' || m == 'v')
		  m = 't';
		else if(m == 't')
		  m = 'u';
		else if(m == 'u')
		  m = 'v';
	  }
	  else if(nn == 9){
		if(m == '1' || m == 'z')
		  m = 'w';
		else if(m == 'w')
		  m = 'x';
		else if(m == 'x')
		  m = 'y';
		else if(m == 'y')
		  m = 'z';
	  }
	  else if(nn == 0){
		if(m != '1')
		  cout << m;
		m = '1';
	  }
	}
	cout << endl;	
  }
  
}



Measured memory_bytes: 3224
while True:
	N = int(raw_input())
	if N == 0: break
	asum = 0
	bsum = 0
	for i in range(0, N):
		a, b = map(int, raw_input().split())
		if a > b: asum += a+b
		elif a < b: bsum += a+b
		else:
			asum += a
			bsum += b
	print str(asum) + ' ' + str(bsum)


Measured memory_bytes: 4808
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define nmax_def 110000
using namespace std;
typedef long long ll;

int main() {
	int i, j;
	int N, K, ans;
	cin >> N >> K;
	if (K == 1)
		ans = 0;
	else
	{
		ans = N - K;
	}
	cout << ans << endl;
	return 0;
}

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

namespace _20190308_02 {
    class Program {
        static void Main(string[] args) {
            var n = int.Parse(Console.ReadLine());
            var list = new string[n, 2];
            for (int i = 0; i < n; i++) {
                var line = Console.ReadLine().Split(' ').ToArray();
                list[i, 0] = line[0];
                list[i, 1] = line[1];
            }
            var sum = 0.0;
            for (int i = 0; i < n; i++) {
                if (list[i, 1] == "JPY") {
                    sum += double.Parse(list[i, 0]);
                } else {
                    sum += double.Parse(list[i, 0]) * 380000.0;
                }
            }
            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 };
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define sortr(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(), (v).end()
#define MAX 10000005
constexpr int inf = 100000000;

int main() {
	stack<int> s1;
    stack<P> s2;
	vector<int> ans;
	int sum = 0;
	char ch;
	for(int i=0;cin>>ch;i++){
		if(ch=='\\'){
			s1.push(i);
		}
        else if(ch=='/'&&s1.size()>0){
            int j=s1.top();s1.pop();
            int a=i-j;
            sum+=a;
            while(s2.size()>0&&s2.top().first>j){
                a+=s2.top().second;s2.pop();
            }
            s2.push(make_pair(j,a));
        }
	}
    while(s2.size()>0){
        ans.push_back(s2.top().second);
        s2.pop();
    }
    reverse(ans.begin(),ans.end());
    cout<<sum<<endl;;
    cout<<ans.size();
    for(int i=0;i<ans.size();i++){
        cout<<" "<<ans[i];
    }
    cout<<endl;
	return 0;
}












Measured memory_bytes: 3212
# F(0,x)を求める
def f(x):
    res = 0 if x % 2 == 1 else x
    res ^= 0 if (x + 2 - 1) // 2 % 2 == 0 else 1
    return res

A, B = map(int,input().split())

ans = f(A - 1) ^ f(B)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long LL;
const int N = 200010;

LL n, a[20];
unordered_map<LL,LL> dp[19][19]; 

LL dfs(int l,int r,LL xl,LL xr){
	if(l+1==r) return 0ll;
	LL k = (xl<<30)+xr;
	if(dp[l][r][k]) return dp[l][r][k];
	dp[l][r][k] = 1ll<<55;
	rep(i,l+1,r-1) dp[l][r][k] = min(dp[l][r][k], dfs(l,i,xl,xl+xr) + dfs(i,r,xl+xr,xr) + a[i]*(xl+xr) );
	return dp[l][r][k];
}

int main(){
	cin>>n;
	rep(i,1,n)cin>>a[i];
	cout<<dfs(1,n,1,1)+a[1]+a[n]<<endl;
	return 0;
}

Measured memory_bytes: 11264
N = int(input())
Card_n = list(map(int, input().split()))

Card_n.sort()

A_n = []
B_n = []

for i in range(len(Card_n)):
    if not i%2 == 0:
        A_n.append(Card_n.pop())
    else:
        B_n.append(Card_n.pop())

#print(A_n)
#print(B_n)
print(abs(sum(A_n) - sum(B_n)))


Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
int main() {


	int n,t;
	std::cin >>n >> t;
	std::vector<unsigned long long int> ac;
	std::vector<unsigned long long int> at;
	ac.resize(n);
	at.resize(n);

	int c_max = 10000;

	for (int i = 0; i < n; ++i)
	{
		std::cin >> ac[i] >> at[i];
		if ((t >= at[i]) && (c_max >= ac[i]))
			c_max = ac[i];
	}

	if (c_max >= 10000) {
		std::cout << "TLE" << std::endl;
	}
	else {
		std::cout << c_max << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob
int n,m,u,v,pre[maxn];
vector<int> adj[maxn];
queue<int> q;
bool vis[maxn];

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> m;
	rep(m){
		cin >> u >> v;
		u--,v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	q.push(0);
	vis[0]=true;
	pre[0]=-1;
	while(!q.empty()){
		u=q.front();
		rep(sz(adj[u])){
			v=adj[u][i];
			if(vis[v]) continue;
			q.push(v);
			vis[v]=true;
			pre[v]=u;
		}
		q.pop();
	}
	print1("Yes");
	rep(n-1) print1(pre[i+1]+1);
	return 0;
}

Measured memory_bytes: 13160
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sn = new Scanner(System.in);
        int a = sn.nextInt();
        int b = sn.nextInt();
        int k = sn.nextInt();
        
        List<Integer> commonDiviserList = new ArrayList<>();
        int c = a > b ? b : a;
        for (int i = c; i >= 1; i--){
            if(a % i == 0 && b % i == 0){
                commonDiviserList.add(i);
            }
        }
        
        System.out.println(commonDiviserList.get(k - 1));        
    }
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 107;
int v[MAXN];
int wit[MAXN];
int dp[MAXN][10007];
int main()
{
//    freopen("in.txt", "r", stdin);
    int n, w;
    scanf("%d %d", &n, &w);
    for(int i = 1; i <= n; i++){
        scanf("%d %d", &v[i], &wit[i]);
    }
    for(int j = 0; j <= w; j++){
        dp[0][j] = 0;
    }
    for(int i = 0; i <= n; i++){
        dp[i][0] = 0;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= w; j++){
            int notget = dp[i-1][j];
            int get;
            if(j>=wit[i]) get = dp[i-1][j-wit[i]]+v[i];
            else get = dp[i-1][j];
            dp[i][j] = max(notget, get);
        }
    }

    printf("%d\n", dp[n][w]);

    return 0;
}



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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars
    }
    if s[0] == 'S' {
        println!("Cloudy");
    } else if s[0] == 'C' {
        println!("Rainy");
    } else {
        println!("Sunny");
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
#define MOD 1000000007
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll f[200010],finv[200010],meth[200010];
ll qpow(ll a,ll b){
	ll re=1;
	while(b){
		if(b&1) re=(re*a)%MOD;
		a=a*a%MOD;b>>=1;
	}
	return re;
}
void init(){
	ll i,len=200000;
	f[0]=f[1]=finv[0]=finv[1]=1;
	for(i=2;i<=len;i++) f[i]=f[i-1]*i%MOD;
	finv[len]=qpow(f[len],MOD-2);
	for(i=len;i>2;i--) finv[i-1]=finv[i]*i%MOD;
}
int n,a[200010],vis[200010],cir[200010],cntcir=0,in[200010],bst[200010],siz[200010];
ll ans=1;
vector<int>s;
vector<int>nd[200010];
bool cmp(int l,int r){
	return siz[l]<siz[r];
}
ll C(ll x,ll y){
	return f[x]*finv[y]%MOD*finv[x-y]%MOD;
}
int main(){
	n=read();int i,j;ll tmp,c,cc;
	init();
	meth[0]=1;
	for(i=1;i<=n;i++) meth[i]=C(i*2,i)*f[i]%MOD*qpow(qpow(2,MOD-2),i)%MOD;

	for(i=1;i<=n;i++) a[i]=read(),in[a[i]]++;
	for(i=1;i<=n;i++){
		j=i;
		while(!vis[j]) vis[j]=i,j=a[j];
//		cout<<"get "<<i<<' ' <<j<<'\n';
		if(vis[j]^i) continue;
//		cout<<"getnew "<<i<<' ' <<j<<'\n';
		cntcir++;
		while(!cir[j]){
//			if(cntcir==20) cout<<"getcir "<<j<<' '<<a[j]<<' '<<cntcir<<'\n';
			cir[j]=cntcir,nd[cntcir].push_back(j),siz[cntcir]++,j=a[j];
		}
	}
	memset(vis,0,sizeof(vis));
	for(i=1;i<=n;i++){
		if(in[i]) continue;
		j=i;
		while(!cir[j]&&!vis[j]) j=a[j];
		if(vis[j]){
			puts("0");return 0;
		}
//		cout<<"find "<<i<<' '<<j<<'\n';
		bst[cir[j]]=1;tmp=cir[j];
		j=i;c=0;
		while(!cir[j]) cir[j]=tmp,c++,vis[j]=1,j=a[j];
		vis[j]=c;
//		cout<<"finish add "<<cir[j]<<' '<<c<<'\n';
	}
	for(i=1;i<=cntcir;i++){
//		cout<<"check link "<<i<<' '<<bst[i]<<'\n';
		if(!bst[i]){s.push_back(i);continue;}
		for(j=0;j<nd[i].size();j++) if(vis[nd[i][j]]) break;
		tmp=j;
		do{
			c=j;cc=1;
			j--;
			(j+=(int)nd[i].size());
			j%=(int)nd[i].size();
			for(;!vis[nd[i][j]];j--,j=((j<0)?j+nd[i].size():j)) cc++;
//			cout<<"	end "<<c<<' '<<j<<' '<<cc<<' '<<vis[nd[i][c]]<<'\n';
			if(vis[nd[i][c]]>cc){
				puts("0");return 0;
			}
//			cout<<"survive "<<ans<<"\n";
			if(vis[nd[i][c]]<cc) (ans*=2)%=MOD;
		}while(tmp!=j);
	}
	sort(s.begin(),s.end(),cmp);
	for(i=0;i<s.size();i+=c){
		j=i;tmp=0;
		while(siz[s[j]]==siz[s[i]]&&j<s.size()) j++;
//		cout<<"circles "<<i<<' '<<j<<'\n';
		c=j-i;
		for(j=0;j<=c/2;j++){
			(tmp+=C(c,2*j)*meth[j]%MOD*qpow(siz[s[i]],j)%MOD*qpow(2,(c-2*j)*(siz[s[i]]!=1)*(siz[s[i]]&1))%MOD)%=MOD;
//			cout<<'	'<<j<<' '<<tmp<<'\n';
		}
		ans=ans*tmp%MOD;
	}
	printf("%lld\n",ans);
}

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

using namespace std;
int ara[11];
int main() {
    int n, caseno = 0, cases = 3;
    while( cases-- ) {
        scanf("%d", &n);
        ara[n]++;
        if(ara[n]==2) caseno = 1;
        if(ara[n]==3) caseno = 0;
    }
    if(caseno==1) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

vector<vector<int>>Graph;
vector<int>counter;
int N,Q;

void dfs(int v,int p, int count){
  counter[v] += count;
  count = counter[v];
  for(auto e : Graph[v]){
    if(e == p) continue;
    dfs(e,v,count);
  }
}

int main(){
  int N,Q;
  cin>>N>>Q;
  Graph.resize(N);
  counter.resize(N);
  rep(i,N-1){
    int a,b;
    cin >> a >> b;
    a--,b--;
    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }

  rep(i,Q){
    int p,x;
    cin >> p >> x;
    p--;
    counter[p] += x;
  }

  dfs(0,-1,0);

  rep(i,N) cout << counter[i] << ' ';

}


Measured memory_bytes: 23424
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstdio>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> dp(N, 0);
    int start[N];
    fill(start, start + N, 0);
    auto graph = vector<vector<int>>(N);
    auto reverse_graph = vector<vector<int>>(N);
    for (int i = 0; i < M; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        x--;
        y--;
        graph[x].push_back(y);
        reverse_graph[y].push_back(x);
        start[y] += 1;
    }
    queue<int> qu;
    for (int i = 0; i < N; i++) {
        if (start[i] == 0) {
            qu.push(i);
        }
    }
    vector<int> topological_sort;
    while (!qu.empty()) {
        int x = qu.front();
        qu.pop();
        topological_sort.push_back(x);
        for (auto nxt : graph[x]) {
            start[nxt]--;
            if (start[nxt] == 0) {
                qu.push(nxt);
            }
        }
    }
    for (auto v : topological_sort) {
        for (auto k : reverse_graph[v]) {
            dp[v] = max(dp[v], dp[k] + 1);
        }
    }

    cout << *max_element(dp.begin(), dp.end());
}

Measured memory_bytes: 12544
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;

int dp[100010];
int deg[100010];
vector<vector<int> > G;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,M,x,y;
    cin >> N >> M;
    G.resize(N);
    REP(i,M){
        cin >> x >> y;
        --x; --y;
        G[x].push_back(y);
        ++deg[y];
    }
    queue<int> q;
    REP(i,N) if(deg[i]==0) q.push(i);
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(int nv : G[v]){
            --deg[nv];
            chmax(dp[nv],dp[v]+1);
            if(deg[nv]==0) q.push(nv);
        }
    }
    int ans = 0;
    REP(i,N) chmax(ans,dp[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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)*}
    };
}

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)*}
    };
}

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")
    };
}

fn main() {
    input! {
        n: usize,
        xu: [(f64, String); n]
    }

    let ans = xu
        .into_iter()
        .map(|(x, u)| if u == "BTC" { x * 380000.0 } else { x })
        .sum::<f64>();
    println!("{}", ans);
}


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

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
pair< T, int > dfs(const WeightedGraph< T > &g, int idx, int par) {
  pair< T, int > ret(0, idx);
  for(auto &e : g[idx]) {
    if(e.to == par) continue;
    auto cost = dfs(g, e.to, idx);
    cost.first += e.cost;
    ret = max(ret, cost);
  }
  return ret;
}

template< typename T >
T tree_diameter(const WeightedGraph< T > &g) {
  auto p = dfs(g, 0, -1);
  auto q = dfs(g, p.second, -1);
  return (q.first);
}

int main() {
  int N;
  cin >> N;
  WeightedGraph< int > g(N);
  for(int i = 1; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].emplace_back(y, 1);
    g[y].emplace_back(x, 1);
  }
  if(tree_diameter(g) % 3 != 1) cout << "First" << endl;
  else cout << "Second" << endl;

}




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

string s;
int N;
int c;

int expr();
int term();
int factor();
int num();

void debug(string text){
	return;
	cout << text + " ";
	for(int i = 0; i < N; i++){
		if(i == c) cout << '[' << s[i] << ']';
		else cout << s[i];
	}
	cout << endl;
}

int expr(){
	debug("expr");
	int x = term();
	while(c < N && (s[c] == '+' || s[c] == '-')){
		if(s[c] == '+'){
			c++;
			x += term();
		}
		else{
			c++;
			x -= term();
		}
	}
	return x;
}

int term(){
	debug("term");

	int x = factor();
	while(c < N && (s[c] == '*' || s[c] == '/')){
		if(s[c] == '*'){
			c++;
			x *= factor();
		}
		else{
			c++;
			x /= factor();
		}
	}
	return x;
}

int factor(){
	debug("factor");

	if(s[c] == '('){
		c++;
		int ret = expr();
		assert(s[c] == ')');
		c++;
		return ret;
	}
	return num();
}

int num(){
	debug("num");

	int ret = 0;
	while(c < N && isdigit(s[c])){
		ret = ret * 10 + s[c] - '0';
		c++;
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int n;
	cin >> n;
	while(n--){
		cin >> s;
		s.pop_back();
		N = s.size();
		c = 0;
		cout << expr() << endl;
	}
}

Measured memory_bytes: 3160
N,K=map(int,input().split())
A=list(map(int,input().split()))
sa=len(set(A))-K
if sa>0:
    As={}
    for i in range(N):
        if A[i] in As:
            As[A[i]]+=1
        else:
            As[A[i]]=1
    Ass=sorted(As.values())
    print(sum(Ass[:sa]))
else:
    print(0)

Measured memory_bytes: 36788
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#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 F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

const int N = 1007, INF = 1e9 + 7;

bool f[N][N], used[N][N];
int dist[N][N];
pi dx[4] = { {0, -1}, {-1, 0}, {0, 1}, {1, 0} };
pi ddx[20] = { {-2, -2}, {-2, -1}, {-2, 0}, {-2, 1}, {-2, 2}, {-1, -2}, {-1, -1}, {-1, 1}, {-1, 2}, {0, -2}, {0, 2}, {1, -2}, {1, -1}, {1, 1}, {1, 2}, {2, -2}, {2, -1}, {2, 0}, {2, 1}, {2, 2} };

void bfs(int sx, int sy) {
    dist[sx][sy] = 0;
    deque <pi> q;
    q.pb({ sx, sy });
    while (!q.empty()) {
        int x = q.front().F, y = q.front().S;
        q.pop_front();
        if (used[x][y])
            continue;
        used[x][y] = 1;
        loop(i, 4) {
            int nx = x + dx[i].F, ny = y + dx[i].S;
            if (f[nx][ny] && dist[nx][ny] > dist[x][y]) {
                dist[nx][ny] = dist[x][y];
                q.push_front({ nx, ny });
            }
        }
        loop(i, 20) {
            int nx = x + ddx[i].F, ny = y + ddx[i].S;
            if (f[nx][ny] && dist[nx][ny] > dist[x][y] + 1) {
                dist[nx][ny] = dist[x][y] + 1;
                q.push_back({ nx, ny });
            }
        }
    }
}

void solve() {
    loop(i, N)
        loop(j, N)
            dist[i][j] = INF;
    int n, m;
    cin >> n >> m;
    int si, sj, fi, fj;
    cin >> si >> sj >> fi >> fj;
    for (int i = 2; i <= n + 1; ++i) {
        for (int j = 2; j <= m + 1; ++j) {
            char c; cin >> c;
            f[i][j] = (c == '.');
        }
    }
    bfs(si + 1, sj + 1);
    cout << (dist[fi + 1][fj + 1] < INF ? dist[fi + 1][fj + 1] : -1);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 9604
#include<iostream>
using namespace std;
 
int main(){
 
int a,b;
 
cin >> a>>b;
 
if(a>b) cout<<"a > b"<<endl;
else if(a<b) cout<<"a < b"<<endl;
else cout<<"a == b"<<endl;
 
 
return 0;
 
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  for (auto &v : s) {
    if (v == '1') cout << 9;
    else cout << 1;
  }
  cout << endl;
  return 0;
}


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

using namespace std;

int N, M, C;

int main() {
	cin >> N >> M >> C;
	vector<int> B(M);
	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}

	int ans = 0;
	for (int i = 0; i < N; i++) {
		int sum = 0;
		for (int j = 0; j < M; j++) {
			int a;
			cin >> a;
			sum += a*B[j];
		}
		sum += C;
		if (sum > 0)ans++;
	}
	cout << ans << endl;
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int64_t i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int64_t i=(a),_b=(b);i>=_b;--i)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

const ll md = 1000000007;

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    ll n;
    cin >> n;
    string ans;
    while (n > 0) {
    	ll k = n % (ll) 26;
    	ans.pb('a' + (k - 1 + 26) % 26);
    	if (k == 0) {
    		n = n / (ll) 26 - 1;
    	} else {
    		n = n / (ll) 26;
    	}
    }
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 3592
import javax.swing.*;
    import java.util.*;
    import java.io.*;


    public class Main {
        public static class FastReader {
            BufferedReader br;
            StringTokenizer st;

            public FastReader() {
                br = new BufferedReader(new InputStreamReader(System.in));
            }

            String nextLine() {
                String str = "";
                try {
                    str = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return str;
            }

            int nextInt() {
                return Integer.parseInt(next());
            }

            long nextLong() {
                return Long.parseLong(next());
            }

            double nextDouble() {
                return Double.parseDouble(next());
            }

            String next() {
                while (st == null || !st.hasMoreElements()) {
                    try {
                        st = new StringTokenizer(br.readLine());
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                return st.nextToken();
            }


        }
        public class pair {
            int a;
            int b;

            pair(int p, int q) {
                a = p;
                b = q;
            }
            public int hashCode() {
                return new Integer(a).hashCode() * 31 + new Integer(b).hashCode();
            }
        }

        public static int gcd(int a, int b) {
            if (a == 1 || b == 1)
                return 1;
            if (a == 0)
                return b;
            if (b == 0)
                return a;
            return gcd(b % a, a);
        }






        public static void main(String[] args) {
            FastReader s=new FastReader();
            int a=s.nextInt();
           int[] arr=new int[a];
           for(int i=0;i<a;i++)
           {
               arr[i]=s.nextInt();
           }
           int flag=0;
           for(int i=0;i<a;i++)
           {
               if(arr[i]%2==0)
               {
                   if(arr[i]%3!=0 && arr[i]%5!=0)
                   {
                       flag=1;
                       break;
                   }
               }
           }
           if(flag==0)
               System.out.println("APPROVED");
           else
               System.out.println("DENIED");
        }
        




    }









Measured memory_bytes: 24660
#include <iostream>

using namespace std;
long long a[1010],sum[1010][1010] = {0},ans = 1099511627775;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long i,j,l,n,k;
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	for(i=0;i<n;i++){
		for(j=i;j<n;j++){
			if(j==0) sum[i][j] = a[j];
			else sum[i][j] += sum[i][j-1] + a[j];
		}
	}
	//ans = 0;
	for(l=40;l>=0;l--){
		int cnt = 0;
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				if((1LL<<l)&sum[i][j]) cnt++;
			}
		}
		if(cnt>=k){
			//ans |= 1LL<<l;
			for(i=0;i<n;i++){
				for(j=i;j<n;j++){
					if(!((1LL<<l)&sum[i][j])) sum[i][j] = 0;
				}
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=i;j<n;j++){
			if(sum[i][j]) ans &= sum[i][j];
		}
	}
	cout << ans << endl;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	cout << n*(n-1)/2-n/2 << endl;
	if(n%2==0){
		for(int i=1; i<=n; i++){
			for(int j=i+1; j<=n; j++){
				if(i+j!=n+1) cout << i << " " << j << endl;
			}
		}
	}else{
		for(int i=1; i<=n; i++){
			for(int j=i+1; j<=n; j++){
				if(i+j!=n) cout << i << " " << j << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef double db;
#define mk make_pair
#define pa pair<int,int>
using namespace std;

inline int rd() {
	int x=0,f=1;char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-1;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
ll N,X;
ll ans;
void solve(ll a,ll b) {
	if(a<b) swap(a,b);
	if(a%b==0) {
		ans+=a/b*b*2-b;
		return;
	}
	ans+=a/b*b*2;
	solve(b,a%b);
}
//main=============================
int main() {
	scanf("%lld%lld",&N,&X);
	ans=N;
	solve(N-X,X);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import collections
N = int( input() )
char_list = []
ans = 0 
for i in range(N):
    c = sorted( input() ) 
    c_new = "".join(c)
    char_list.append(c_new)
    
t = collections.Counter(char_list)

for i in t.values():
    if i != 1:
        ans += int( ( i * (i - 1) ) / 2 )
        
print(ans)

Measured memory_bytes: 19752
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FL          freopen("in", "r", stdin),freopen("out", "w", stdout);
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-9;
//int dx[] = {1, 0}, dy[] = {0, 1};
//int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int n, k;
int v[N];
int dp[N];
int f(int i){
    if(i == n - 1)return 0;
    int &ans = dp[i];
    if(ans != -1)return ans;
    ans = 1e9;
    for(int j = 1; j <= 2; j++){
        if(i + j < n)
            ans = min(ans, f(i + j) + abs(v[i] - v[i + j]));
    }
    return ans;
}
int main(){
    //FL;
    FIN;
    cin >> n;
    fore(i, 0, n)cin >> v[i];
    cls(dp, -1);
    cout << f(0) << '\n';
    EjecuteTime;
    return 0;
}       

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
vi f;
int n;
signed main()
{
    cin >> n;
    f.resize(n + 1, 0);
    for (int i = 1; i <= 100; i++)
    {
        for (int j = 1; j <= 100; j++)
        {
            for (int k = 1; k <= 100; k++)
            {
                int val = (i + j) * (i + j) + (j + k) * (j + k) + (k + i) * (k + i);
                val /= 2;
                if (val <= n)
                    f[val]++;
            }
        }
    }
    for (int i = 1; i <= n; i++)
        cout << f[i] << endl;
    return 0;
}

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

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

    int R[M];
    int L[M];
    for(int i=0; i<M; i++){
        cin >> L[i] >> R[i];
    }

    int min_R = *max_element(L, L+M);
    int max_R = *min_element(R, R+M);

    int count = max_R - min_R + 1;
    if(count < 0){
        count = 0;
    }

    cout << count << endl;
    return 0;
    
}

Measured memory_bytes: 4348
#import numpy as np
#import functools
#import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm
#import collections as C #most_common
#import math
#import sympy

N = int(input())
#A,B= map(int,input().split())
#P = list(map(int,input().split()))
#S = str(input())
#T = str(input())
for i in range(1000):
    if 1000*i - N >= 0:
        print(1000*i - N)
        exit()


Measured memory_bytes: 9148
import java.io.*;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {
	    InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        TaskB solver = new TaskB();
        solver.solve(in, out);

        out.close();
    }

    static class TaskB {
        public void solve(InputReader in, PrintWriter out) {
            int cases = in.nextInt();
            solveIt(cases, in, out);
        }

        private void solveIt(int cases, InputReader in, PrintWriter out) {
            int[] layers = new int[cases];
            for (int i = 0; i < cases; i++) {
                layers[i] = in.nextInt();
            }

            out.println(Arrays.stream(layers).distinct().count());
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public String[] input;
        public int current;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            input = null;
            current = 0;
        }

        public String next() {
            while (input == null || current == input.length) {
                try {
                    current = 0;
                    input = reader.readLine().split("\\s");
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }

            return input[current++];
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

Measured memory_bytes: 26836
#include<cstdio>
int d[500010],pos[500010],ans[500010];
int min(int a,int b){return a<b?a:b;}
int diff(int a,int b){return a>b?a-b:b-a;}
int main(){
	int N,Q;
	scanf("%d%d",&N,pos);
	for(int i=0;i<N;i++){
		scanf("%d",d+i);
		pos[i+1]=min(pos[i],diff(pos[i],d[i]));
	}
	for(int i=N;i--;){
		if(ans[i+1]<d[i]/2)ans[i]=ans[i+1];
		else ans[i]=ans[i+1]+d[i];
	}
	scanf("%d",&Q);
	while(Q--){
		int q;scanf("%d",&q);
		puts(pos[q-1]>ans[q]?"YES":"NO");
	}
}

Measured memory_bytes: 7680
class Integer
    def pow(y, m)
      return 1 if y == 0
      res = self.pow(y/2, m)
      res * res % m * (y.odd? ? self : 1) % m
    end
end

M=(10**9+7)
l=gets.chomp
 
sum=0;
n=0;
(0..l.size).each{|idx|
    if(l[idx]=="1")
        sum += 2.pow(n,M)*3.pow(l.size-idx-1,M)
        n+=1
    end
}
sum+=2.pow(n,M)
 
 
p sum % M

Measured memory_bytes: 1916
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();

    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let C = buf_it.next().unwrap().parse::<isize>().unwrap();
    let XV = (0..N).map(|_| 
        (buf_it.next().unwrap().parse::<isize>().unwrap(),
         buf_it.next().unwrap().parse::<isize>().unwrap())
    ).collect::<Vec<_>>();

    let mut R = (0..N).map(|_| 0).collect::<Vec<_>>();
    let mut L = (0..N).map(|_| 0).collect::<Vec<_>>();
    R[0] = XV[0].1 - XV[0].0;
    L[N-1] = XV[N-1].1 - (C - XV[N-1].0);
    let mut ans = max(0,max(R[0],L[N-1]));
    for i in 1..N{
        R[i] = R[i-1] + XV[i].1 - (XV[i].0 - XV[i-1].0);
        let j = N-1-i;
        L[j] = L[j+1] + XV[j].1 - (XV[j+1].0 - XV[j].0);
        ans = max(ans,max(R[i],L[j]));
    }
    for i in 1..N{
        R[i] = max(R[i-1],R[i]);
        let j = N-1-i;
        L[j] = max(L[j+1],L[j]);
    }

    for i in 0..N-1{
        let tmp = R[i] - XV[i].0 + L[i+1];
        ans = max(ans,tmp);
    }
    for i in 0..N-1{
        let j = N-1-i;
        let tmp = L[j] - (C - XV[j].0) + R[j-1];
        ans = max(ans,tmp);
    }
    println!("{}",ans);
}

Measured memory_bytes: 12280
#include <bits/stdc++.h>
using namespace std;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
bool dame[10];
bool check(int n) {
    while(n > 0) {
        if(dame[n % 10]) return true;
        n /= 10;
    }
    return false;
}
int main() {
    int n, k; cin >> n >> k;
    memset(dame, 0, sizeof(dame));
    rep(i, k) {
        int t; cin >> t;
        dame[t] = true;
    }
    for(;;++n) {
        if(!check(n)) break;
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
s = gets.chomp.split('')

abc = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'
abc = abc.upcase
result = ''

s.each do |char|
  result += abc[abc.index(char)+n]
end

puts result


Measured memory_bytes: 19708
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,h[200001],dp[200001]={0};
    cin>>n;
    rep(i,n) cin>>h[i];
    dp[1]=abs(h[0]-h[1]);
    rep(i,n-2) dp[i+2]=min(dp[i]+abs(h[i]-h[i+2]),dp[i+1]+abs(h[i+1]-h[i+2]));
    cout<<dp[n-1];
}


Measured memory_bytes: 1408
#include<stdio.h>

#define MAX 200000

#define N -1

struct treeNode{
  int p;
  int l;
  int r;
};

struct treeNode T[MAX];

int doKansu(int);

void doKansu2(int);

int n,H,D[MAX];  
 
int main(){

  int i,j,d,v,c,l;
 
  scanf("%d",&n);
 
  for (i = 0;i < n;i ++)
    {
      T[i].p = T[i].l = T[i].r = N;
    }
 
  for (i = 0;i < n;i ++)
    {

      scanf("%d %d",&v,&d);
      
      for (j = 0;j < d;j ++)
	{
	  scanf("%d",&c);

	  if(j == 0)
	    {
	      T[v].l = c;
	      T[c].p = v;
	    }
	  else if(j == 1)
	    {
	      T[v].r = c;
	      T[c].p = v;
	    }
	  else T[c].p = v;
	}
    }
  
  for (i = 0;i < n;i ++)
    {
      D[i] = doKansu(i);
    }
  
  for(i = 0;i < n;i ++)
    {
      doKansu2(i);
    }
  
  return 0;
}

int doKansu(int u){

  int d = 0;
  
  while(T[u].p != -1)
    {
      u = T[u].p;
      d ++;
    }
  
  return d;
 
}
 
void doKansu2(int u){

  int i = 0;
  int count = 0;
  
  printf("node %d: parent = %d, depth = %d, ",u,T[u].p,D[u]);
  
  if(T[u].p == -1)
    {
      printf("root, [");
    
      if(T[u].l != -1 )
	{
	  printf("%d",T[u].l);
	
	  if(T[u].r != -1) printf(", %d",T[u].r);

	  for (i = 0;i < n;i ++)
	    {
	      if(T[i].p==u && T[u].l != i && T[u].r != i)
		{
		  printf(", %d",i);
		}       
	    }
	}
      printf("]\n");
    }
   
  else{
    if(T[u].l != -1)
      {
	printf("internal node, [%d",T[u].l);    
	if(T[u].r != -1 )
	  {
	    printf(", %d",T[u].r);
	  
	    for (i=0; i<n; i++)
	      {
		if(T[i].p==u && T[u].l!=i && T[u].r!=i)
		  {
		    printf(", %d",i);
		  }
	      }
	  }
	printf("]\n");
      }
    else printf("leaf, []\n");
  }
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int a,b; cin >> a >> b;
    cout<<(a-1)*(b-1)<<endl;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
#define int long long

int M, K;

signed main() {
  cin >> M >> K;
  if (M == 0) {
    if (K == 0) {
      cout << 0 << " " << 0 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }

  if ((1 << M) <= K) {
    cout << -1 << endl;
    return 0;
  }

  if (K == 0) {
    for (int i = 0; i < (1 << (M + 1)); i++) {
      if (i != 0) cout << " ";
      cout << i / 2;
    }
    cout << endl;
    return 0;
  }

  int tmp = 0;
  for (int i = 0; i < (1 << M); i++) {
    if (i != K) tmp ^= i;
  }

  if (tmp != K) {
    cout << -1 << endl;
    return 0;
  }

  vector<int> v;
  for (int i = 0; i < (1 << M); i++) {
    if (i != K) v.push_back(i);
  }
  vector<int> rev = v;
  reverse(rev.begin(), rev.end());
  v.push_back(K);
  rev.push_back(K);

  for (auto x : v) cout << x << " ";
  for (int i = 0; i < rev.size(); i++) {
    if (i != 0) cout << " ";
    cout << rev[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int dp[N],array1[N],n,k;
int solution(int i){
    if(i>=n){
        return 0;
    }
    if(dp[i]!=-1){
        return dp[i];
    }
    int mini=OO;
    for(int j=1;j<=min(k,n-i-1);++j){
        mini=min(mini,abs(array1[i]-array1[i+j])+solution(i+j));
    }
    if(mini==OO){
        return 0;
    }
    return dp[i]=mini;
}
int main()
{
memset(dp,-1,sizeof(dp));
int i;
scanf("%d %d",&n,&k);
for(i=0;i<n;++i){
    scanf("%d",&array1[i]);
}
printf("%d\n",solution(0));



    return 0;
}


Measured memory_bytes: 12308