akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

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

    int n, m;
    cin >> n >> m;

    vector< pair<int, int> > a(m);
    int b;
    rep (i, m)
    {
        int val;
        int key = 0;
        cin >> val >> b;
        rep (j, b)
        {
            int c;
            cin >> c;
            --c;
            key |= 1 << c;
        }
        a[i] = make_pair(val, key);
    }

    vector< vs32 > dp((1 << n), vs32(m + 1));
    rep (i, (1 << n))
    {
        rep (j, m + 1)
        {
            if (i == 0) dp[i][j] = 0;
            else dp[i][j] = (int)1e9;
        }
    }

    for (int j = 1; j <= m; ++j)
    {
        int val = a[j - 1].first;
        int key = a[j - 1].second;
        rep (i, (1 << n))
        {
            dp[i][j] = MIN(dp[i][j - 1], dp[i & (~key)][j - 1] + val);
        }
    }

    if (dp[(1 << n) - 1][m] == (int)1e9)
    {
        cout << "-1\n";
    }
    else
    {
        cout << dp[(1 << n) - 1][m] << "\n";
    }
    return 0;
}



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

using namespace std;
const int N = 1e5 + 5;
int arr[N];

int main() {
    //freopen("in.txt", "rt", stdin);
    int n, k;
    scanf("%d %d", &n, &k);
    double ans = 0;
    for (int i = 1; i <= n; ++i) {
        double v = 1.0 / n;
        int s = i;
        while (s < k) {
            s *= 2;
            v *= 0.5;
        }
        ans += v;
    }
    printf("%.10lf",ans);
}

Measured memory_bytes: 384
from enum import Enum
from queue import Queue
import collections

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

def bubbleSort(A):
    count = 0
    for i in range(1,len(A)):
        for j in range(1,len(A)-i+1):
            if A[j] < A[j-1]:
                A[j],A[j-1] = A[j-1],A[j]
                count += 1
    return A,count

def merge(A, left, mid, right):
    count = 0

    L = A[left:mid] + [BIG_NUM]
    R = A[mid:right] + [BIG_NUM]
    i = 0
    j = 0
    for k in range(left,right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1
            count += len(L)-1-i
    return count

def mergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right)//2
        cnt1 = mergeSort(A, left, mid)
        cnt2 = mergeSort(A, mid, right)
        cnt3 = merge(A, left, mid, right)
        return cnt1+cnt2+cnt3
    else:
        return 0

n = int(input())
A = list(map(int,input().split()))
cnt=0
cnt = mergeSort(A,0,n)
#print(*A)
print(cnt)



Measured memory_bytes: 29632
#![allow(non_snake_case, unused_imports)]

// Input
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)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        X: i64,
        A: [i64; N],
    }
    let mut A = A;
    let mut ans:i64 = 0;
    // 初項だけで超過しているなら取り除く
    if A[0]>X{
        ans += A[0]-X;
        A[0] = X; 
    }
    // 第1項から順番にみて、一つ手前との合計がXを超えた分だけ取り除く
    for i in 1..N{
        let r:i64 = max(0,A[i]+A[i-1]-X);
        ans += r;
        A[i] -= r;
    }

    println!("{}", ans);
}

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

int main() {
  string s;
  cin >> s;
  int cnt = 0;
  if(s[0]=='1') cnt++;
  if(s[1]=='1') cnt++;
  if(s[2]=='1') cnt++;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int main(){
	int N,a[200001];
	int sum=0;
	scan(N);
	rep(i,N){
		scan(a[i]);
		sum^=a[i];
	}
	rep(i,N){
		printf("%d ",(sum^a[i]));
	}
	kaigyo;
	return 0;
}


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

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 2100;
ll dp[maxn][maxn];
struct node
{
    ll num;
    ll pos;
};
node a[maxn];
bool cmp(const node &a, const node &b)
{
    return a.num > b.num;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n;
    cin >> n;
    //vector<ll> a(n + 1);
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].num;
        a[i].pos = i;
    }
    sort(a + 1, a + 1 + n, cmp);
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j + i < n; j++)
        {
            ll now = i + j + 1;
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a[now].num * abs(a[now].pos - i - 1));
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + a[now].num * abs(a[now].pos - (n - j)));
        }
    }
    ll ans = 0;
    for (int i = 0; i <= n; i++)
    {
        ans = max(dp[i][n - i], ans);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 26592
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
using namespace std;
// #include "prettyprint.hpp"

typedef long long ll;
typedef pair<int, pair<int, int>> PPAIR;

int main()
{
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    vector<int> section;
    int now = 1; // Assume that string begins with "1"
    int cnt = 0;
    for (int i = 0; i < N; ++i)
    {
        if (S[i] == (char)('0' + now))
        {
            ++cnt;
        }
        else
        {
            section.push_back(cnt);
            now = 1 - now; // exchange 01
            cnt = 1;
        }
    }
    if (cnt != 0)
    {
        section.push_back(cnt);
    }

    // if (section.size() % 2 == 0)
    // {
    //     section.push_back(0);
    // }

    int ans = 0;
    int left = 0, right = 0;
    int tmp = 0;
    int Add = 2 * K + 1;

    // Reverse 0. So, it calculates even number. (section starts '0' sum);
    for (int i = 0; i < section.size(); i += 2)
    {
        int next_left = i;
        int next_right = min(i + Add, (int)section.size());

        while (next_left > left)
        {
            tmp -= section[left];
            left++;
        }
        while (next_right > right)
        {
            tmp += section[right];
            right++;
        }

        ans = max(ans, tmp);
        // cout << ans << endl;
    }
    // cout << section << endl;
    cout << ans << endl;
}

Measured memory_bytes: 1020
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    a,b = map(int, sys.stdin.readline().split())
    if a==b:
        print(a+b)
    else:
        n=max(a,b)
        m=min(a,b)
        if n > m+1:
            print(2*n-1)
        else:
            print(a+b)




Measured memory_bytes: 5072
//√.
//本代码经过lm开光处理。
#include<bits/stdc++.h>
using namespace std;
int ans,sum=0;
string a;
void init()
{
	cin>>a;
}
void work()
{
	ans=0;
	for(int i=0;i<a.length();i++)
	{
		if(a[i]=='S')
		{
			ans++;
		}
		else
		{
			ans--;
			if(ans<0)
			{
				sum+=-ans;
				ans=0;
			}
		}
	}
	if(ans!=0)
	{
		sum+=ans;
	}
}
void print()
{
	printf("%d",sum);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	init();
	work();
	print();
	return 0;
}


Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int main(){
    vector<string> s(3);
    for (auto i = 0; i < 3; i++) {
        cin >> s[i];
    }

    int turn = 0;
    vector<int> index(3, 0);
    while(true){
        if(index[turn] == s[turn].size()) break;
        int next = s[turn][index[turn]] - 'a';
        index[turn]++;
        turn = next;
        // cout << turn << endl;
    }

    cout << (char)('A' + turn) << endl;
    return 0;
}

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

using int64 = long long;

int main() {
  int64 n;
  cin >> n;
  unordered_map<string, int64> mp;
  for (int64 i = 0; i < n; ++i) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    mp[s] = mp[s] + 1;
  }
  int64 ret = 0;
  for (auto& p : mp) {
    int64 k = p.second;
    ret += k * (k - 1) / 2;
  }
  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 10660
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
			int a =sc.nextInt();
			double sum=a+Math.pow(a,2)+Math.pow(a,3);
			//int sum1 = (int)sum;
			System.out.println((int)sum);
		
		}
	
	
	
	}


Measured memory_bytes: 35376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>

#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;

using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }

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

  if (s == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (s == "Cloudy") {
    cout << "Rainy" << endl;
  } else if (s == "Rainy") {
    cout << "Sunny" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
// Problem : F - path pass i
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//QWsin
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

const int maxn=200000+10;
const int maxm=400000+10;
int col[maxn];

int first[maxn],nxt[maxm],ecnt;
struct Edge{int u,v;Edge(int u=0,int v=0):u(u),v(v){}}e[maxm];
void add_edge(int u,int v){
	nxt[ecnt]=first[u];first[u]=ecnt;e[ecnt++]=Edge(u,v);
	nxt[ecnt]=first[v];first[v]=ecnt;e[ecnt++]=Edge(v,u);
}

int sz[maxn],father[maxn];
queue<int>q[maxn];
vector<int>sons[maxm+maxn];
int to[maxn];
void dfs(int u,int fa)
{
	sz[u]=1;father[u]=fa;
	for(int i=first[u];i!=-1;i=nxt[i]){
		int v=e[i].v;
		if(v==fa)continue;
		int t=to[col[u]];
		to[col[u]]=i;
		dfs(v,u);
		sz[u]+=sz[v];
		to[col[u]]=t;
	}
	sons[to[col[u]]].push_back(u);
}

ll ans;
ll calc(int siz){return 1ll*siz*(siz-1)/2+siz;}
void DFS(int u)
{
	for(int i=first[u];i!=-1;i=nxt[i]){
		int v=e[i].v;
		if(v==father[u]) continue;
		int siz=sz[v];
		for(int j=0;j<sons[i].size();++j){
			siz-=sz[sons[i][j]];
		}
		ans+=calc(siz);
		for(int j=0;j<sons[i].size();++j){
			DFS(sons[i][j]);
		}
	}
}

int main()
{ 
	int n;cin>>n;
	rep(i,1,n) first[i]=-1;
	rep(i,1,n) cin>>col[i];
	rep(i,1,n-1){
		add_edge(read(),read());
	}
	rep(i,1,n) to[i]=maxm+i;
	dfs(1,1);
	rep(i,1,n){
		ans=0;
		int siz=n;
		for(int j=0;j<sons[maxm+i].size();++j)
		{
			int t=sons[maxm+i][j];
			siz-=sz[t];
			DFS(t);
		}
		cout<<calc(n)-calc(siz)-ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 182460
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
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;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

int table[26];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N;cin>>N;
    cout << N*(N+1)/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n,w;
	cin>>n>>w;
	ll wt[n+1],val[n+1];
	ll totval=0;
	for(ll i=0;i<n;i++)
	{
		cin>>wt[i]>>val[i];
		totval+=val[i];
	}
	ll dp[n+1][totval+1]={0};
	for(ll i=1;i<=totval;i++)
		dp[0][i]=1e14;
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<=totval;j++)
		{
			if(j-val[i-1]>=0)
				dp[i][j]=min(dp[i-1][j],wt[i-1]+dp[i-1][j-val[i-1]]);
			else
				dp[i][j]=dp[i-1][j];
			if(dp[i][j]<=w)
				ans=max(ans,j);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 82484
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

n = ini()
k = ini()
x = ini()
y = ini()


def solve():
    ans = min(k, n) * x
    if n > k:
        ans += (n - k) * y

    return ans


print(solve())


Measured memory_bytes: 9048
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n;
	cin >> n;
	if( n % 2 ){
		cout << "0";
		return 0;
		
	}
	int ans = 0;
	int curr = 5;
	while(curr <= n/2){
		ans += n/(curr*2);
		curr = curr  * 5;
	}
	cout << ans;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<stdlib.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int sz=1e5;
int qLen,qHead,Q[sz],*cave[sz];
void PUSH(int n){Q[(qHead+qLen)%sz]=n;qLen++;}
int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%sz;return q;}
int main(void)
{
  int A,B,N,M,x,y;
  x=scanf("%d %d",&N,&M);
  int room[N],path[N];
  rep(i,N)path[i]=0,room[i]=-1;
  rep(i,M)
  {
    x=scanf("%d %d",&A,&B);A--,B--;
    cave[A]=(int*)realloc(cave[A],sizeof(int)*(path[A]+1));
    cave[A][path[A]]=B;path[A]++;
    cave[B]=(int*)realloc(cave[B],sizeof(int)*(path[B]+1));
    cave[B][path[B]]=A;path[B]++;
  }
  room[0]=0;PUSH(0);
  while(qLen)
  {
    x=POP();
    rep(i,path[x]){y=cave[x][i];if(!(room[y]<0))continue;room[y]=x,PUSH(y);}
  }
  puts("Yes");rep(i,N-1)printf("%d\n",room[i+1]+1);
}

Measured memory_bytes: 8824
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

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

    int n, q, k[100];
    string s;

    cin >> n >> s >> q;
    REP(i, q)
    cin >> k[i];

    REP(i, q)
    {
        ll res = 0;

        int l = 0, r = 0;
        ll d = 0, m = 0, dm = 0;

        while (r < n)
        {
            if (s[r] == 'C')
            {
                res += dm;
                //cout << "#" << res << endl;
            }

            if (s[r] == 'D')
            {
                d++;
            }

            if (s[r] == 'M')
            {
                m++;
                dm += d;
            }

            if (r + 1 - l < k[i])
            {
                r++;
            }
            else
            {
                if (s[l] == 'D')
                {
                    d--;
                    dm -= m;
                }

                if (s[l] == 'M')
                    m--;

                r++;
                l++;
            }
        }

        cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 1948
n = int(input())
a = [int(i) for i in input().split()]
order = [0 for i in range(n)]
for i in range(n):
    order[a[i] - 1] = i + 1
for i in range(n - 1):
    print(str(order[i]), end=' ')
print(order[n - 1])

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

//拡張ユークリッドの互除法
int extgcd(int a, int b, int& x, int& y) {
    int d = a;
    if (b != 0) {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    } else {
        x = 1;
        y = 0;
    }
    return d;
}

// mod逆元
int mod_inverse(int a, int m) {
    int x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

// 階乗、階乗逆元テーブル
int fact[1100000], fact_inv[1100000];
int mod_fact(int n, int m) {
    fact[0] = fact_inv[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = fact[i - 1] * i % m;
        fact_inv[i] = mod_inverse(fact[i], m);
    }
}

int N, K, M;
int A[33000];
int one_table[33000][440], dp[33000][440];
int imos[33000];
int mod = 1e9 + 7;

signed main() {
    cin >> N >> K >> M;
    for (int i = 0; i < M; i++)cin >> A[i];
    int whole = N - M + 1;
    for (int i = 0; i < N - M; i++)(whole *= K) %= mod;
    for (int i = 0; i < M - K + 1; i++) {
        vector<bool> check(440);
        for (int j = 0; j < K; j++) {
            if (check[A[i + j]])goto nene;
            check[A[i + j]] = true;
        }
        cout << whole << endl;
        return 0;
nene:;
    }

    one_table[0][1] = 1;
    for (int i = 1; i < 33000; i++) {
        for (int j = K - 1; j >= 1; j--)one_table[i][j] = (one_table[i - 1][j] + one_table[i][j + 1]) % mod;
        for (int j = K - 1; j >= 2; j--)(one_table[i][j] += one_table[i - 1][j - 1] * (K - j + 1) % mod) %= mod;
    }
    for (int i = 1; i < 33000; i++)dp[i][1] = imos[i] = one_table[i][1];
    for (int i = 2; i <= K - 1; i++) {
        int gy = mod_inverse(K - i + 1, mod);
        for (int j = 1; j <= 33000 - i; j++) {
            dp[j][i] = (dp[j + 1][i - 1] - imos[j] + mod) % mod * gy % mod;
            (imos[j] += dp[j][i]) %= mod;
        }
    }

    bool distinct = true;
    vector<bool> check(440);
    for (int i = 0; i < M; i++) {
        if (check[A[i]])distinct = false;
        check[A[i]] = true;
    }
    if (distinct) {
        mod_fact(33000, mod);
        int ans = 0, f = fact[K - M] * fact_inv[K] % mod;
        for (int i = 0; i < N; i++) {
            int a = ans;
            for (int j = M; j <= K - 1; j++)(ans += one_table[i][j] * dp[N - i][j] % mod) %= mod;
        }
        cout << (whole - (ans * K % mod * f % mod) + mod) % mod << endl;
        return 0;
    }

    int l, r;
    check.clear();
    check.resize(440);
    for (l = 0; l < M; l++) {
        if (check[A[l]])break;
        check[A[l]] = true;
    }
    check.clear();
    check.resize(440);
    for (r = 0; r < M; r++) {
        if (check[A[M - r - 1]])break;
        check[A[M - r - 1]] = true;
    }
    int ans = 0;
    for (int i = 0; i < N - M + 1; i++) {
        (ans += dp[i + 1][l] * dp[N - M + 1 - i][r] % mod) %= mod;
    }
    cout << (whole - ans + mod) % mod << endl;

}


Measured memory_bytes: 231680
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var H, W int

func main() {
	sc.Split(bufio.ScanWords)

	H, W = nextInt(), nextInt()
	C := make([]string, H)

	buf := bufio.NewWriter(os.Stdout)
	for i := 0; i < H; i++ {
		C[i] = nextStr()
		buf.Write([]byte(fmt.Sprintf("%s\n", C[i])))
		buf.Write([]byte(fmt.Sprintf("%s\n", C[i])))
	}

	buf.Write([]byte("\n"))
	buf.Flush()
}


Measured memory_bytes: 768
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>

using namespace std;

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

  int n;
  cin >> n;
  string s;
  cin >> s;
  n = s.length();
  int wr = count(s.begin(), s.end(), '.');
  int bl = 0;
  int res = wr;
  for (int i = 0; i < n; i++) {
    if (s[i] == '.') wr--;
    else bl++;
    res = min(res, bl+wr);
  }
  cout << res << endl;
}


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

#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

using Graph = vector<vector<int>>;
Graph g;

void dfs(int v, vector<bool> &seen, int &res) {
  bool end = true;
  rep(i,seen.size()) {
    if (!seen[i] && i != v) {
      end = false;
    }
  }
  if (end) {
    ++res;
    return;
  }

  seen[v] = true;
  for (auto nv : g[v]) {
    if (seen[nv]) continue;
    dfs(nv, seen, res);
  }
  seen[v] = false;
}

int main() {
  int n, m;
  cin >> n >> m;
  g.assign(n, vector<int>());
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<bool> seen(n, false);
  int res = 0;
  dfs(0, seen, res);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    int a, b, c, d;
    cin >> s;
    a = s[0] - '0';
    b = s[1] - '0';
    c = s[2] - '0';
    d = s[3] - '0';
    
    bool flag = false;
    
    int result;
    rep(i, 8){
        switch(i){
            case 0:
            result = a + b + c + d;
            if(result == 7){
                cout << a << "+" << b << "+" << c << "+" << d << "=" << result << endl;
                flag = true;
                break;
            }
            
            case 1:
            result = a + b + c - d;
            if(result == 7){
                cout << a << "+" << b << "+" << c << "-" << d << "=" << result << endl;
                flag = true;
                break;
            }
            
            case 2:
            result = a + b - c + d;
            if(result == 7){
                cout << a << "+" << b << "-" << c << "+" << d << "=" << result << endl;
                flag = true;
                break;
            }
            
            case 3:
            result = a - b + c + d;
            if(result == 7){
                cout << a << "-" << b << "+" << c << "+" << d << "=" << result << endl;
                flag = true;
                break;
            }
            
            case 4:
            result = a + b - c - d;
            if(result == 7){
                cout << a << "+" << b << "-" << c << "-" << d << "=" << result << endl;
                flag = true;
                break;
            }
            
            case 5:
            result = a - b + c - d;
            if(result == 7){
                cout << a << "-" << b << "+" << c << "-" << d << "=" << result << endl;
                flag = true;
                break;
            }
            
            case 6:
            result = a - b - c + d;
            if(result == 7){
                cout << a << "-" << b << "-" << c << "+" << d << "=" << result << endl;
                flag = true;
                break;
            }
            
            case 7:
            result = a - b - c - d;
            if(result == 7){
                cout << a << "-" << b << "-" << c << "-" << d << "=" << result << endl;
                flag = true;
                break;
            }
        }
        if(flag)    break;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# DSL_2_F: RMQ and RUQ
# Range Minimum Query and Range Update Query


class SegmentTree:
    INITIAL_VALUE = 2**31 - 1
    DIVIDED = -1

    def __init__(self, n):
        size = 1
        while size < n:
            size *= 2
        self.size = 2*size - 1
        self.data = [-1] * self.size
        self.data[0] = self.INITIAL_VALUE

    def set_range(self, lo, hi, v):
        def _set_range(r, i, j, vv):
            if j < lo or i > hi:
                if vv != self.DIVIDED:
                    self.data[r] = vv
            elif lo <= i and j <= hi:
                self.data[r] = v
            else:
                if self.data[r] != self.DIVIDED:
                    if vv == self.DIVIDED:
                        vv = self.data[r]
                    self.data[r] = self.DIVIDED
                mid = i + (j - i)//2
                _set_range(r*2 + 1, i, mid, vv)
                _set_range(r*2 + 2, mid+1, j, vv)

        _set_range(0, 0, self.size//2, self.DIVIDED)

    def min(self, i, j):
        def _min(r, lo, hi):
            if j < lo or i > hi:
                return self.INITIAL_VALUE
            elif self.data[r] != self.DIVIDED:
                return self.data[r]
            else:
                mid = lo + (hi - lo)//2
                return min(_min(r*2 + 1, lo, mid),
                           _min(r*2 + 2, mid+1, hi))

        return _min(0, 0, self.size//2)


def run():
    n, q = [int(i) for i in input().split()]

    tree = SegmentTree(n)

    for _ in range(q):
        com, *args = input().split()
        if com == '0':
            s, t, x = [int(i) for i in args]
            tree.set_range(s, t, x)
        elif com == '1':
            s, t = [int(i) for i in args]
            print(tree.min(s, t))


if __name__ == '__main__':
    run()



Measured memory_bytes: 8704
#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)--)
vvi adj;
vb visited;
void dfs(int v)
{
    visited[v] = true;
    for (auto it : adj[v])
    {
        if (!visited[it])
            dfs(it);
    }
    return;
}
signed main()
{
    int n, u, v, m, k = 0, z;
    cin >> n >> m;
    adj.resize(n + 1);
    visited.resize(n + 1);
    while (m--)
    {
        cin >> u >> v >> z;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for (int i = 1; i <= n; i++)
    {
        if (!visited[i])
        {
            dfs(i);
            k++;
        }
    }
    cout << k << endl;
    return 0;
}


Measured memory_bytes: 8832
$N = int(<>);
@p = split(/\s+/, <>);

for $i (1..$N) {
    next if $i == $p[$i-1];
    for $j (($i+1)..$N) {
	next if $j == $p[$j-1];
	if ($p[$j-1] != $i) {
	    print "NO\n";
	    exit;
	}
    }
    print "YES\n";
    exit;
}
print "YES\n";


Measured memory_bytes: 512
#include <stdio.h>

static void PrintArray(int A[], int N) {
    int i;

    for ( i = 0; i < N; i++ ) {
        printf("%d", A[i]);

        if ( i < N - 1 ) {
            printf(" ");
        }
    }
    printf("\n");

    return;
}

static void InsersionSort(int A[], int N) {
    int i;

    for ( i = 1; i < N; i++ ) {
        int v = A[i];
        int j = i - 1;

        while ( (j >= 0) && (A[j] > v) ) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        PrintArray(A, N);
    }

    return;
}

int main(int argc, char* argv[]) {
    int N;
    int A[1000];
    int i;

    fscanf(stdin, "%d\n", &N);
    for ( i = 0; i < N; i++ ) {
        fscanf(stdin, "%d", &A[i]);
    }

    PrintArray(A, N);

    InsersionSort(A, N);

    return 0;
}



Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
int  check(int no)
{
    int happy=0;
    while( (no/500) > 0)
    {
        happy+=(no/500)*1000;
        no-=(no/500)*500;
    }
    while(no/5 > 0)
    {
        happy+=(no/5)*5;
        no-=(no/5)*5;
    }
    return happy;
}
int main()
{
    int x;
    cin>>x;
    int res=check(x);
    cout<<res;
    return 0;
       
}

Measured memory_bytes: 256
while True:
    mid, term, add = map(int, input().split())
    if mid == -1 and term == -1 and add == -1:
        break
    if mid == -1 or term == -1:
        rank = 'F'
    elif mid + term >= 80:
        rank = 'A'
    elif mid + term >= 65:
        rank = 'B'
    elif mid + term >= 50:
        rank = 'C'
    elif mid + term >= 30:
        if add >= 50:
            rank = 'C'
        else:
            rank = 'D'
    else:
        rank = 'F'
    print(rank)

Measured memory_bytes: 7680
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n; cin >>n;
  ll a[n],cnt=0,sum=0,mn=MOD;
  for(int i=0; i<n; i++){
    ll x; cin >>x; a[i]=x;
    if(x<=0) cnt++;
    mn=min(mn,abs(x));
    sum+=abs(x);
  }
  if(cnt%2) sum-=2*mn;
  cout <<sum;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 4360
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int n=in.nextInt();
			if(n==1)
				return;
			boolean  a[]=new boolean[300001];
			Arrays.fill(a, true);
			for(int i=2;i<=300000;i++)
			{
				if(!a[i])
					continue;
				if(i%7==1||i%7==6)
					for(int j=i+i;j<=300000;j+=i)
						a[j]=false;
			}
			for(int i=0;i<=300000;i++)
			{
				if(i%7!=1&&i%7!=6)
					a[i]=false;
			}
			System.out.print(n+":");
			for(int i=2;i<=n;i++)
			{
				if(a[i])
					if(n%i==0)
						System.out.print(" "+i);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <fstream>
#include <list>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <list>

#define EMPTY 999999

using namespace std;

vector<pair<int,int>> t;

int root(int n) {
    int x = n,z = n,zz;
    while(t[x].second != EMPTY)
        x = t[x].second;
    while(t[z].second != EMPTY) {
        zz = t[z].second;
        t[z].second = x;
        z = zz;
    }
    return x;
}

void u_tree(int a,int b) {
    if(root(a) != root(b))
        t[root(a)].second = root(b);
}

int main(void) {
    int n,m,a,b;
    cin >> n >> m;
    for(int i = 0;i < n;i++){
        cin >> a;
        t.push_back(make_pair(a-1,EMPTY));
    }
    for(int i = 0;i < m;i++) {
        cin >> a >> b;
        u_tree(a-1, b-1);
    }
    int ans = 0;
    for(int i = 0;i < n;i++) {
        if(root(t[i].first) == root(i))
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int h,w;
  cin >> h >> w;
  string s;
  int map[h][w];
  ll d[h][w];
  for(int i=0;i<h;i++){
    cin >> s;
    for(int j=0;j<w;j++){
      if(s[j] == '#') map[i][j] = 1;
      else map[i][j] = 0;
      d[i][j] = MOD;
    }
  }
  d[0][0] = MOD;
  priority_queue<pair<int,pair<int,int> > > q;
  q.push(make_pair(0,make_pair(0,0)));
  while(!q.empty()){
    pair<int,int> now = q.top().second;
    int value = q.top().first;
    q.pop();
    int x = now.first;
    int y = now.second;
    if(-1*value >= d[x][y]) continue;
    d[x][y] = -1*value;
    int p;
    if(x < h-1){
      p = 0;
      if(map[x][y] == 0 && map[x+1][y] == 1) p++;
      q.push(make_pair(-1*d[x][y]-p,make_pair(x+1,y)));
    }
    if(y < w-1){
      p = 0;
      if(map[x][y] == 0 && map[x][y+1] == 1) p++;
      q.push(make_pair(-1*d[x][y]-p,make_pair(x,y+1)));
    }
  }
  int ans = d[h-1][w-1];
  ans += map[0][0];
  cout << ans << endl;
  return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

map<string,set<string>> mp;
vector<string> tt;

int solve(string str){
  // cout << str << endl;
  auto itr=mp.find(str);
  list<set<string>::iterator> ers;
  list<string> psh;
  for(auto s=itr->second.begin();s!=itr->second.end();s++){
    auto itr2=mp.find(*s);
    if(itr2!=mp.end()){
      solve(itr2->first);
      for(auto t=itr2->second.begin();t!=itr2->second.end();t++){
        psh.push_back(*t);
      }
      ers.push_back(s);
    }
  }
  for(auto s:ers){
    itr->second.erase(s);
  }
  for(auto s:psh){
    itr->second.insert(s);
  }
  return itr->second.size();
}

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) return 0;
    tt=vector<string>(n);
    mp=map<string,set<string>>();
    string s,t;
    int j,pre;
    for(int i=0;i<n;i++){
      cin >> s;
      j=0;
      for(;j<s.length();j++){
        if(s[j]==':'){
          t=s.substr(0,j);
          j++;
          pre=j;
          break;
        }
      }
      // cout << t << endl;
      mp[t]=set<string>();
      tt[i]=t;
      for(;j<s.length();j++){
        if(s[j]==','||s[j]=='.'){
          mp[t].insert(s.substr(pre,j-pre));
          // cout << s.substr(pre,j-pre) << endl;
          j++;
          pre=j;
        }
      }
    }
    cout << solve(tt[0]) << endl;
  }
  return 0;
}



Measured memory_bytes: 3412
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	float total = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		total += a[i];
	}
	total /= 4 * m;
	int count = 0; 
	for (int i = 0; i < n; i++) {
		if (a[i] >= total) count++;
	}
	if (count >= m) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

namespace ConsoleApp57
{
    class Program
    {
        static long A, B, N;
        static void Main(string[] args)
        {

            var l =  Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

            A = l[0];
            B = l[1];
            N = l[2];
          long x = 0;
            if ( B -1 > N)
            {
                x = N;
            }
            else
            {
                x = B - 1;
            }

            var min = (A * (x)) / B;




            Console.WriteLine(min);
          //  Console.ReadKey();

        }
    }
}


Measured memory_bytes: 28088
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;

#define rep(i, a, b) for(ll i = a; i < ll(b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    ll n;
    cin>>n;
    if(n%2==1) cout<<0<<endl;
    else{
        ll ans = 0;
        ll pw = 10;
        rep(i,0,25){
            ans += n/pw;
            pw*=5;
        }
        cout<<ans<<endl;
    }
}

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

typedef struct Node
{
    int parent;
    int left;
    int right;
} Node;

class RT
{
private:
    Node *rt;
    int num;

public:
    RT(int n)
    {
        rt = (Node *)calloc(n, sizeof(Node));
        num = n;
        for (int i = 0; i < n; i++)
            rt[i].parent = rt[i].left = rt[i].right = -1;
    };

    void setParent(int n, int p)
    {
        rt[n].parent = p;
    };

    void setRight(int n, int r)
    {
        rt[n].right = r;
    };

    void setleft(int n, int l)
    {
        rt[n].left = l;
    };

    int getDepth(int n)
    {
        int depth = 0;
        int id = n;
        while (rt[id].parent != -1)
        {
            depth++;
            id = rt[id].parent;
        }
        return depth;
    };

    int getParent(int n)
    {
        return rt[n].parent;
    };

    void printChildren(int n)
    {
        int id = rt[n].left;
        while (id != -1)
        {
            printf("%d", id);
            id = rt[id].right;
            if (id != -1)
                printf(", ");
        }
    };

    void printType(int n)
    {
        if (rt[n].parent == -1)
            printf("root");
        else if (rt[n].left == -1)
            printf("leaf");
        else
            printf("internal node");
    };

    void printInfo(int n)
    {
        printf("node %d: parent = %d, depth = %d, ", n, getParent(n), getDepth(n));
        printType(n);
        printf(", [");
        printChildren(n);
        printf("]\n");
    };

    void printAll()
    {
        for (int i = 0; i < num; i++)
            printInfo(i);
    }
};

int main()
{
    int n;
    cin >> n;
    RT rt(n);
    for (int i = 0; i < n; i++)
    {
        int id, j;
        cin >> id >> j;
        int c, r;
        for (int k = 0; k < j; k++)
        {
            cin >> c;
            if (k == 0)
                rt.setleft(id, c);
            else
                rt.setRight(r, c);
            r = c;
            rt.setParent(c, id);
        }
    }

    rt.printAll();
}



Measured memory_bytes: 4308
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N;
  cin >> N;

  long H[N];
  for (long i = 0; i < N; i++) {
      cin >> H[i];
  }

  for (long i = 0; i < N-1; i++) {
      if (H[i] > H[i+1] ) {
          cout << "No" <<endl;
          return 0;
      }else if (H[i] < H[i+1] ) {
          H[i+1] -= 1;
      }
  }

  cout << "Yes" <<endl;
}

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

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

    int rating = r;
    if (n < 10)
    {
        rating = r + 100 * (10 - n);
    }
    cout << rating  << endl;
    return 0;
}


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

using namespace std;

string s, t;

int main()
{
    cin>>s>>t;
    for(int i = s.size() - t.size(); i >= 0; i--)
    {
        bool flag = true;
        for(int j = 0; j < t.size(); j++)
        {
            if(!(s[i + j] == '?' || s[i + j] == t[j]))
            {
                flag = false;
            }
        }
        if(flag)
        {
            for(int j = 0; j < i; j++)
            {
                if(s[j] == '?') putchar('a');
                else printf("%c", s[j]);
            }
            cout<<t;
            for(int j = i + t.size(); j < s.size(); j++)
            {
                if(s[j] == '?') putchar('a');
                else printf("%c", s[j]);
            }
            return 0;
        }
    }
    puts("UNRESTORABLE");
    return 0;
}


Measured memory_bytes: 256