akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_pair tree<pair<int,int>,null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set_mutiset tree<int,null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> pi; 
#define PI 3.1415926535897932384
#define FOR(i,vv,n) for(int i=vv;i<n;i++)
#define FORR(i,n,vv) for(int i=n-1;i>=vv;i--)
#define ve vector 
#define maxind(v) (max_element(v.begin(),v.end())-v.begin())
#define minind(v) (min_element(v.begin(),v.end())-v.begin())
#define maxe(v) *max_element(v.begin(),v.end())
#define mine(v) *min_element(v.begin(),v.end())
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mp make_pair
#define M 1000000007ll
#define INF 1000000000000000000ll
#define PRECISE cout.precision(18);
#define all(v) v.begin(),v.end()
#define BS(v,n) binary_search(all(v),n)
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(all(v),greater <ll>())
#define uni(v) v.resize(unique(all(v)-v.begin())
#define F first
#define S second
#define GET(i,p) get<p>(i)
int h,w,k;
bool ok(ll a,ll b){
if(a>=0&&a<h&&b>=0&&b<w)
	return 1;
return 0;
}


int main(){

    FAST
//	PRECISE


cin>>h>>w>>k;
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
x1--;y1--;x2--;y2--;

ve <ve <int> > used(h,ve <int> (w,-1) );
FOR(i,0,h){
	string s;
	cin>>s;
	FOR(j,0,w){
		if(s[j]=='@'){
			used[i][j]=M;
		}
	}
} 

set <tuple<int,int,int> > s;// val,x,y
s.insert({0,x1,y1});
used[x1][y1]=0;

while(!s.empty()){
	tuple <int,int,int> t=*s.begin();
	s.erase(s.begin());
	int val=GET(t,0);
	int x=GET(t,1);
	int y=GET(t,2);
	FOR(i,x+1,h){
		if(i-x<=k){
		if(ok(i,y)&&(used[i][y]==-1||used[i][y]==val+1)){
			used[i][y]=val+1;
			s.insert({used[i][y],i,y});
		}
		else
			break;}
		else
			break;
	}
		FORR(i,x,0){
			if(x-i<=k){
		if(ok(i,y)&&(used[i][y]==-1||used[i][y]==val+1)){
			used[i][y]=val;
				used[i][y]++;
			s.insert({used[i][y],i,y});
		}
		else{
			break;}
		}
		else
			break;
	}
		FOR(j,y+1,w){
			if(j-y<=k){
		if(ok(x,j)&&(used[x][j]==-1||used[x][j]==val+1)){
			used[x][j]=val;
				used[x][j]++;
			s.insert({used[x][j],x,j});
		}
		else
			break;}
		else
			break;
	}
		FORR(j,y,0){
			if(y-j<=k){
		if(ok(x,j)&&(used[x][j]==-1||used[x][j]==val+1)){
			used[x][j]=val;
				used[x][j]++;
			s.insert({used[x][j],x,j});
		}
		else
			break;}
		else
			break;
	}
}


cout<<used[x2][y2];




return 0;
 }



Measured memory_bytes: 14992
#include <cstdio>
#include <queue>
#include <set>
#include <algorithm>
using namespace std;

typedef long long lld;

int n_cakes[3], K;
lld cakes[3][1005];
set <int> chk;

int main() {

    int i, j, k;
    
    scanf("%d%d%d%d", &n_cakes[0], &n_cakes[1], &n_cakes[2], &K);
    for(i = 0; i < 3; i ++) {
        for(j = 0; j < n_cakes[i]; j ++) {
            scanf("%lld", &cakes[i][j]);
        }
        sort(cakes[i], cakes[i] + n_cakes[i]);
        reverse(cakes[i], cakes[i] + n_cakes[i]);
    }
    
    priority_queue<pair<lld, int> > que;
    que.push(make_pair(cakes[0][0] + cakes[1][0] + cakes[2][0], 0));
    chk.insert(0);
    for(k = 0; k < K; k ++) {
        lld val = que.top().first;
        int idx = que.top().second, idxs[3];
        que.pop();

        printf("%lld\n", val);

        idxs[0] = idx % 1000;
        idxs[1] = (idx % 1000000) / 1000;
        idxs[2] = idx / 1000000;
        int mul = 1;
        for(i = 0; i < 3; i ++) {
            if(idxs[i] + 1 < n_cakes[i] && !chk.count(idx + mul)) {
                que.push(make_pair(val + cakes[i][idxs[i]+1] - cakes[i][idxs[i]],
                                   idx + mul));
                chk.insert(idx + mul);
            }
            mul *= 1000;
        }
    }


    return 0;
}


Measured memory_bytes: 768
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	h := getNextInt(scanner)
	w := getNextInt(scanner)
	n := getNextInt(scanner)

	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	var grid [100][100]int

	i := 0
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			if y%2 == 0 {
				grid[y][x] = i + 1
			} else {
				grid[y][w-1-x] = i + 1
			}
			aa[i]--
			if aa[i] == 0 {
				i++
			}
		}
	}
	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			fmt.Fprint(writer, grid[y][x])
			if x < w-1 {
				fmt.Fprint(writer, " ")
			}
		}
		fmt.Fprintln(writer, "")
	}

	writer.Flush()
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
using namespace std;

typedef long long ll;

int dp[42][402][402];

int main() {
	int n, ma, mb; cin >> n >> ma >> mb;
	vector<int> a(n + 2), b(n + 2), c(n + 2);
	for (int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];

	for (int t = 0; t <= n; t++) {
		for (int i = 0; i <= 400; i++) {
			for (int j = 0; j <= 400; j++) {
				dp[t][i][j] = 1e9;
			}
		}
	}
	for (int t = 0; t <= n; t++) dp[t][0][0] = 0;

	for (int t = 1; t <= n; t++) {
		for (int i = 0; i <= 400; i++) {
			for (int j = 0; j <= 400; j++) {
				dp[t][i][j] = dp[t - 1][i][j];
				if (i - a[t] >= 0 && j - b[t] >= 0) {
					dp[t][i][j] = min(dp[t][i][j], dp[t - 1][i - a[t]][j - b[t]] + c[t]);
				}
			}
		}
	}
	int ia = ma, ib = mb;
	int ans = 1e9;
	while (ia <= 400 && ib <= 400) {
		ans = min(ans, dp[n][ia][ib]);
		ia += ma; ib += mb;
	}

	if (ans == (int)1e9) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 26112
#include <stdio.h>

int main() {
	int a[5], idx,min = 10,sum=0;
	for(int i =0 ;i <5;i++){
	    scanf("%d\n",&a[i]);
	    if (a[i]%10 <min && a[i]%10 ){min = a[i] %10,idx =i;}  
	}
	for (int i=0;i<5;i++){
	    if (i==idx || a[i]%10==0){
	        sum+=a[i];
	    }else{
	        sum+=10*(a[i]/10 + 1 );
	    }
	}
	printf("%d",sum);
	
	
	return 0;
}

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

using namespace std;

int main() {
	int n, m, a[101][101], b[101], c;
	cin >> n >> m >> c;
	for (int i = 1; i <= m; ++i) cin >> b[i];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			cin >> a[i][j];
	int res = 0;
	for (int i = 1; i <= n; ++i) {
		int S = 0;
		for (int j = 1; j <= m; ++j)
			S += a[i][j] * b[j];
		if (S + c > 0) res++;
	}
	cout << res;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
bool b[200005]={0};
bool a[200005]={0};
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=n;i>0;i--)
    {
        if(b[i]!=a[i])
        {
            b[i]=1;
            for(int j=1;j<=sqrt(i);j++)
            {
                if(i%j==0)
                {
                    a[j]=!a[j];
                    if(j==i/j) continue;
                    a[i/j]=!a[i/j];
                }
            }
        }

    }
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(b[i]) cnt++;
    }
    cout<<cnt<<'\n';
    for(int i=1;i<=n;i++)
    {
        if(b[i]) cout<<i<<' ';
    }
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;
const int N=10;
int n,x[N],y[N],den;
vector <int> v;
double num;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++) cin>>x[i]>>y[i],v.push_back(i);

	do
	{
		for(int i=1;i<n;i++)
			num+=sqrtl((x[v[i]]-x[v[i-1]])*(x[v[i]]-x[v[i-1]])+(y[v[i]]-y[v[i-1]])*(y[v[i]]-y[v[i-1]]));
		den++;
	}
	while(next_permutation(v.begin(),v.end()));

	cout<<fixed<<setprecision(10)<<num/den;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int s,w;
    cin >> s >> w;
    if(w >= s)cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    int N = S.size();

    // dp[i][j] : S[i-1]まで使って"ABC"のj文字目まで使った場合の決め方の数
    vector<vector<ll>> dp(N+1, vector<ll>(4));
    dp[0][0] = 1;

    for(int i = 1; i <= N; i++){
        for(int j = 3; j >= 0; --j){
            // transition
            // S[i-1]を使わない場合
            // '?'->3通り, 'A','B','C'-> 1通り
            dp[i][j] = dp[i-1][j] * (S[i-1] == '?' ? 3LL : 1LL);
            // S[i-1]を使う場合
            // j-1 -> j への遷移は
            // S[i-1] = '?' or "ABC"[j-1] であれば良い
            if(0 < j && (S[i-1] == '?' || S[i-1] == "ABC"[j-1])){
                dp[i][j] += dp[i-1][j-1];
            }
            dp[i][j] %= mod;
        }
    }
    cout << dp[N][3] << endl;
}


Measured memory_bytes: 10380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int arr[105];
int dp[N][2];
int n, k;
int solve(int k, int turn) {
    if (dp[k][turn] != -1)
        return dp[k][turn];
    if (turn == 0) {
        int res = 1e5;
        for (int i = 0; i < n; i++)
            if (arr[i] <= k)
                res = min(res, solve(k - arr[i],  (turn ^ 1)));
        if (res == 1e5)
            return dp[k][turn] = (turn ^ 1);
        else
            return dp[k][turn] = res;
    }
    else {
        int res = -1;
        for (int i = 0; i < n; i++)
            if (arr[i] <= k)
                res = max(res, solve(k - arr[i], (turn ^ 1)));
        if (res == -1)
            return dp[k][turn] = (turn ^ 1);
        else
            return dp[k][turn] = res;
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    memset(dp, -1, sizeof dp);
    if (solve(k, 0) == 0)
        cout << "First";
    else
        cout << "Second";
    return  0;
}

Measured memory_bytes: 8064
N = int(input())
Main = list(map(int,input().split()))
S = list(map(int,input().split()))
S_2 = list(map(int,input().split()))
ans = sum(S)
p = 0

for i in range(N-1):
    if Main[i+1] == Main[i]+1:
        p = Main[i]-1
        ans = ans + S_2[p]

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define LL long long 
using namespace std;
const int P = 998244353;
const int M = 1500000;
int n,m,k,a[M],f[M];
LL res,S;

int qick(int x,int y)
{
	int z=1;
	for(;y;y>>=1, x=(LL)x*x%P) if(y&1) z=(LL)z*x%P;
	return z;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d",&k), a[k]++;
		m=max(m,k); S+=(LL)k;
	}
	
	for(int j=m;j>=1;j--)
	{
		for(int k=j;k<=m;k+=j) f[j]=(f[j]+(LL)a[k]*k%P)%P;
		if(!f[j]) continue;
		f[j]=(LL)f[j]*f[j]%P;
		for(int k=j+j;k<=m;k+=j) f[j]=(f[j]-f[k]+P)%P;
		res=(res+(LL)f[j]*qick(j,P-2))%P;
	}

	cout<<((LL)res-S%P+P)*((P+1ll)/2ll)%P;
}

Measured memory_bytes: 10496
#include<stdio.h>
int main(){
  int A,B,C,D;
  scanf("%d%d%d%d",&A,&B,&C,&D);
  while(A!=0 || C!=0){
    C=C-B;
    if(C<=0){
      printf("Yes");
      break;}
    A=A-D;
    if(A<=0){
      printf("No");
      break;}
  }
  return 0;
}
    

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

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

int main(void) {
    Int x;
    cin >> x;
    Int score[9] = {400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000};
    for (Int i = 0; i < 9; ++i) {
        if (x < score[i]) {
            cout << 9 - i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string S;
stack<int> s1;
stack<pair<int, int>>s2;
vector<int> ans;
int flag = 0;
int sum = 0;
int main() {
	cin >> S;
	for (int i = 0; i < S.length(); i++) {
		char ch = S[i];
		if (ch == '\\')  //\\才能表示'\'
			s1.push(i);
		else if (ch == '/' && !s1.empty()) {
			int j = s1.top();
			sum += i - j;
			int a = i - j;
			s1.pop();
			pair<int, int> x;
			while (!s2.empty() && s2.top().first > j) {
				a += s2.top().second; s2.pop();
			}
			x.first = j, x.second = a;
			s2.push(x);
		}
	}
	cout << sum << endl;
	int cnt=0;
	while (!s2.empty()) {
		ans.push_back(s2.top().second);
		s2.pop();
		cnt++;
	}
	cout << cnt;
	for (int i = cnt - 1; i >= 0; i--) {
		printf(" %d", ans[i]);
	}
	cout << endl;
}



Measured memory_bytes: 3348
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
constexpr long long INF = 2e18 + 100;

using namespace std;
int main(){
  long long N, T, Q;
  cin >> N >> T >> Q;
  vector<pair<long long,int>> V;
  for(int i = 0; i < N; ++i){
    long long a, d;
    cin >> a >> d;
    V.emplace_back(a,d);
  }
  vector<int> X(Q);
  for(int i = 0; i < Q; ++i) cin >> X[i], --X[i];
  vector<long long> W;
  for(int i = 1; i < N; ++i){
    if(V[i].second == 2 and V[i-1].second == 1){
      // cerr << i << endl;
      long long m = (V[i].first+V[i-1].first)/2;
      W.emplace_back(m);
    }
  }
  W.emplace_back(INF);
  W.emplace_back(-INF);
  sort(W.begin(),W.end());
  for(int i = 0; i < Q; ++i){
    long long a = V[X[i]].first;
    long long a_ = V[X[i]].first;
    if(V[X[i]].second == 1){
      a_ += T;
      int idx = upper_bound(W.begin(),W.end(),a) - W.begin();
      long long w = W[idx];
      // cerr << a << " " << a_ << " " << w << endl;
      // if(w >= a) a_ = w;
      // cout << a_ << endl;
      cout << min(w, a_) << endl;
    }else{
      a_ -= T;
      int idx = upper_bound(W.begin(),W.end(),a) - W.begin() - 1;
      long long w = W[idx];
      // if(w >= a) a_ = w;
      // cout << a_ << endl;
      cout << max(w, a_) << endl;
    }
  }
}



Measured memory_bytes: 4944
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
// #include <bits/extc++.h>
using namespace std;

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a, val) memset(a, val, sizeof (a))
#define PB push_back
#define endl '\n'
typedef long long ll;

inline int myrand(int l, int r) {
    int ret = rand(); ret <<= 15; ret ^= rand();
    if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
    return ret;
}

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

typedef pair<int, int> ii;

template<typename T> using min_pq =
    std::priority_queue<T, vector<T>, greater<T> >;

//int dx[] = {-1, +0, +1, +0};
//int dy[] = {+0, +1, +0, -1};

const int maxn = 1e5 + 5;

int h[maxn], dp[maxn], n;

int32_t main () {
    // freopen("in", "r", stdin);
    memset(dp, (1 << 7) - 1, sizeof dp);
    cin >> n;
    for(int i = 0; i <= n; i++) {
        cin >> h[i];
    }
    dp[0] = 0;
    for(int i = 0; i < n; i++) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cstdio>
#include <map>
typedef long long ll;
using namespace std;
int n, k, a[200000], sum[2000010];
long long ans = 0;
map<int, ll> m;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    a[i] %= k;
    sum[i + 1] = sum[i] + a[i];
    sum[i + 1] %= k;
  }
  m.insert({0, 1});
  for (int i = 1; i <= n; i++) {
    if (i >= k) {
      m[((sum[i - k] - i % k) + k) % k]--;
    }
    if (m.find((sum[i] - i % k + k) % k) == m.end()) {
      m.insert({(sum[i] - i % k + k) % k, 1});
    } else {
      ans += m[(sum[i] - i % k + k) % k];
      m[(sum[i] - i % k + k) % k]++;
    }
  }
  printf("%lld\n", ans);
}

Measured memory_bytes: 16000
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		while(scan.hasNext()){
			int a = scan.nextInt();
			int b = scan.nextInt();
			int c = a + b;
			String d = String.valueOf(c);
			int len = d.length();
			list.add(len);
		}

		for(int n : list){
			System.out.printf("%d\n", n);
		}
	}
}

Measured memory_bytes: 26392
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 0), 1000000001*3)
	sc.Split(bufio.ScanWords)

	var n, m, s, t int
	fmt.Scan(&n, &m, &s, &t)
	s, t = s-1, t-1

	gy := make([][]Edge, n)
	gs := make([][]Edge, n)
	for i := 0; i < n; i++ {
		gy[i] = make([]Edge, 0)
		gs[i] = make([]Edge, 0)
	}

	for i := 0; i < m; i++ {
		u, v, a, b := nextInt()-1, nextInt()-1, nextInt(), nextInt()
		gy[u] = append(gy[u], Edge{to: v, cost: a})
		gy[v] = append(gy[v], Edge{to: u, cost: a})
		gs[u] = append(gs[u], Edge{to: v, cost: b})
		gs[v] = append(gs[v], Edge{to: u, cost: b})
	}

	cy := dijkstra(gy, s)
	cs := dijkstra(gs, t)
	co := make([]int, n)
	for i := 0; i < n; i++ {
		co[i] = cy[i] + cs[i]
	}
	for i := n - 2; i >= 0; i-- {
		co[i] = min(co[i], co[i+1])
	}
	for i := 0; i < n; i++ {
		fmt.Println(1e15 - co[i])
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func dijkstra(g [][]Edge, from int) []int {
	n := len(g)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		d[i] = 1e15
	}

	var pq PriorityQueue
	heap.Init(&pq)

	heap.Push(&pq, &Item{pos: from, cost: 0})
	d[from] = 0

	for len(pq) > 0 {
		s := heap.Pop(&pq).(*Item)
		if d[s.pos] < s.cost {
			continue
		}
		for _, e := range g[s.pos] {
			if d[e.to] > s.cost+e.cost {
				d[e.to] = s.cost + e.cost
				heap.Push(&pq, &Item{pos: e.to, cost: d[e.to]})
			}
		}
	}

	return d
}

// Edge .
type Edge struct {
	to, cost int
}

// https://golang.org/pkg/container/heap/

// An Item is something we manage in a priority queue.
type Item struct {
	pos  int // The value of the item; arbitrary.
	cost int // The priority of the item in the queue.
	// The index is needed by update and is maintained by the heap.Interface methods.
	index int // The index of the item in the heap.
}

// A PriorityQueue implements heap.Interface and holds Items.
type PriorityQueue []*Item

func (pq PriorityQueue) Len() int { return len(pq) }

func (pq PriorityQueue) Less(i, j int) bool {
	// We want Pop to give us the highest, not lowest, priority so we use greater than here.
	return pq[i].cost < pq[j].cost
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

// Push .
func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

// Pop .
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

var sc *bufio.Scanner

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


Measured memory_bytes: 27264
//ΔARC 084E
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int N = 3e5+35;
int k,n,ans[N],nn;
void prev(){
	int i;
	i=nn;
	while(ans[i]==0){
		i--;
	}
	nn=i;
	ans[i]--;
	if(ans[i]){
		i++;
		while(i<=n){
			ans[i]=k;
			i++;
		}
		nn=n;
	}
}
int main()
{
	int i;
	scanf("%d%d",&k,&n);
	if(k%2==0){
		cout<<k/2<<' ';
		for(i=2;i<=n;i=i+1)
			cout<<k<<' ';
		return 0;
	}
	for(i=1;i<=n;i=i+1)
		ans[i]=(k+1)/2;
	nn=n;
	for(i=1;i<=n/2;i=i+1)
		prev();
	for(i=1;i<=n;i=i+1)
		if(ans[i])
			cout<<ans[i]<<' ';
	return 0;
}
// 299999 299999


Measured memory_bytes: 3456
N, W = map(int, input().split())
data = tuple(tuple(map(int, input().split())) for _ in range(N))
d = {0: 0}
for n in range(N):
    weight, value = data[n]
    for w, now in d.copy().items():
        if w + weight <= W:
            d[w + weight] = max(d.get(w + weight, 0), now + value)
print(max(d.values()))

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    int n,m;
    cin >> n >> m;
    vector<vector<int>> s(m);
    vector<int> p(m);
    REP(i,m){
        int k;
        cin >> k;
        REP(j,k){
            int input;
            cin >> input;
            s[i].push_back(input - 1);
        }
    }
    REP(i,m){
        cin >> p[i];
    }

    int ans = 0;
    for(uint state = (1<<n)-1; state >= 0 ;state--){
        bool out_flag = false;
        REP(j,m){
            int onsum = 0;
            REP(u,s[j].size()){
                uint ons = pow(2,s[j][u]);
                if(state & ons){
                    onsum++;
                }
            }
            if(onsum % 2 != p[j]){
                out_flag = true;
                break;
            }  
        }
        if(!out_flag){
            ans++;
        }
        if(state == 0){
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
S = input()
 
N = len(S)
ans = 'No'
 
# 文字列strの反転は、str[::-1]
if S == S[::-1] and S[:(N-1)//2] == S[:(N-1)//2][::-1] and S[(N+1)//2:] == S[(N+1)//2:][::-1]:
  ans = 'Yes'
  
print(ans)

Measured memory_bytes: 9120
#include<stdio.h>
 
 
 
int p[100],m[100][100];
void MCM(int n){
  int i,l,j,k,b;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i + l - 1;
      m[i][j] = 100000;
      for(k=i;k<j;k++){
        b = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
        if(m[i][j]>b) m[i][j]=b;
      }
    }
  }
}
 
int main(){
  int n,i,j;
 
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }
 
  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
  MCM(n);
  printf("%d\n",m[1][n]);
 
  return 0;
}


Measured memory_bytes: 2048
import sys


def test(a):
    if len(a) % 2:
        if a[0]:
            return False

        del a[0]

    for i in range(0, len(a) - 2, 2):
        if a[i] != a[i + 1] or a[i + 2] - a[i] != 2:
            return False

    return True


input()
a = sorted(list(map(int, input().split())))

if a[:2] == [0, 0]:
    print(0)
    sys.exit(0)

elif a == [0]:
    print(1)
    sys.exit(0)

elif a == [0, 1, 1] or a == [1, 1]:
    print(2)
    sys.exit(0)

print((2 ** round(len(a) / 2)) % (10 ** 9 + 7) if test(a) else 0)

Measured memory_bytes: 14008
s = input()[::-1]

t = [x[::-1] for x in ['dream', 'dreamer', 'erase', 'eraser']]

i = 0
while i < len(s):
    if s[i] == 'm':
        if s[i: i + 5] == t[0]:
            i += 5
            continue
    elif s[i] == 'e':
        if s[i: i + 5] == t[2]:
            i += 5
            continue
    elif s[i] == 'r':
        if s[i: i + 6] == t[3]:
            i += 6
            continue
        elif s[i: i + 7] == t[1]:
            i += 7
            continue
    break

print('YES' if i == len(s) else 'NO')



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<pair<int, int>> tasks(N);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    tasks[i] = make_pair(b, a);
  }
  sort(tasks.begin(), tasks.end());
  int now = 0;
  for (int i = 0; i < N; i++) {
    now += tasks[i].second;
    if (now > tasks[i].first) {
      cout << "No" << '\n';
      return 0;
    }
  }
  cout << "Yes" << '\n';
  return 0;
}


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

int main(){
  ll x, y;
  cin >> x >> y;
  x *= -1; y *= -1;
  ll r1 = 2 + (x <= y ? y - x : 1e18);
  y *= -1;
  ll r2 = 1 + (x <= y ? y - x : 1e18);
  x *= -1; y *= -1;
  ll r3 = 1 + (x <= y ? y - x : 1e18);
  y *= -1;
  ll r4 = 0 + (x <= y ? y - x : 1e18);
  cout << min({r1, r2, r3, r4}) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

    int a,b,c;
    scanf("%d %d", &a,&b);

    if(b % a == 0) {
        c = a + b;
        printf("%d", c);
    } else {
        c = b - a;
        printf("%d", c);
    }

    return 0;
}

Measured memory_bytes: 1728
#include<cstdio>
#include<algorithm>
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	int n[a];
		for(int i=0;i<a;i++)
		{
			scanf("%d",&n[i]);
		}
		std::sort(n , n+a);
		int ans=0;
		for(int i=a;i>a-b;i--)
		{
			ans+=n[i-1];
		}
		printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
h,w=map(int,input().split())
a2=[]
for i in range(h):
    a=list(input())
    if '#' in a:
        a2.append(a)
for i in range(w):
    x=[row[i] for row in a2]
    if '#' not in x:
        for j in range(len(a2)):
            a2[j][i]=''
for i in a2:
    print(*i,sep='')

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

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...);
}
 
#ifdef LOCAL
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define db(...) 42
#endif

const int N = 1e5;

int p[N+1];

void init() {
  for (int i = 0; i <= N; i++) {
    p[i] = i;
  }
}

int par(int x) {
  return p[x] == x ? x : p[x] = par(p[x]);
}

void unite(int a, int b) {
  a = par(a);
  b = par(b);
  if (a != b) {
    p[b] = a;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  cin >> n;
  vector<pair<int, int>> X(n), Y(n);
  for (int i = 0; i < n; i++) {
    cin >> X[i].first >> Y[i].first;
    X[i].second = Y[i].second = i;
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  
  vector<array<int, 3>> e;
  
  for (int i = 1; i < n; i++) {
    e.push_back({X[i].first - X[i-1].first, X[i].second, X[i-1].second});
    e.push_back({Y[i].first - Y[i-1].first, Y[i].second, Y[i-1].second});
  }
  sort(e.begin(), e.end(), [](auto &i, auto &j) {
    return i[0] < j[0];
  });
  init();
  ll ans = 0;
  for (int i = 0; i < (int)e.size(); i++) {
    if (par(e[i][1]) != par(e[i][2])) {
      unite(e[i][1], e[i][2]);
      ans += e[i][0];
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 7928
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int siz[100010];
int par[100010];
int depth[100010];
void init(int n){
  for(int i=0;i<=n;i++){
      par[i]=i;
      depth[i]=0;
  }
  rep(i,n+1){
      siz[i]=1;
  }
}
int root(int x){
  return par[x]==x?x:par[x]=root(par[x]);
}
bool same(int x,int y){
  return root(x)==root(y);
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  ll sx=siz[x];
  ll sy=siz[y];
  if(x==y)return;
  if(depth[x]<depth[y]){
      par[x]=y;
  }else{
      par[y]=x;
      if(depth[x]==depth[y])depth[x]++;
  }
  siz[root(x)]=sx+sy;
}
signed main(){
    ll n;cin>>n;
    init(n);
    vector<pll>p(n);
    vector<pll>pp(n);
    rep(i,n){
        ll a;cin>>a;
        p[i].se=a;
    }
    rep(i,n){
        ll b;cin>>b;
        p[i].fi=b;
    }
    sort(all(p));
    rep(i,n){
        pp[i].fi=p[i].se;
        pp[i].se=i;
    }
    sort(all(pp));
    bool f=1;
    rep(i,n){
        if(p[i].fi<pp[i].fi)f=0;
    }
    if(!f){
        cout<<"No"<<endl;
        return 0;
    }
    bool b=0;
    rep(i,n){
        if(pp[i].se==i){
            b=1;
        }
        if(i){
            if(p[i-1].fi>=pp[i].fi)b=1;
        }
    }
    rep(i,n){
        unite(pp[i].se+1,i+1);
    }
    if(siz[root(1)]<n-1)b=1;
    if(b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 5760
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int sum = a + b;
    if (sum % 2 == 0){
        cout << "Alice" << endl;
    } else {
        cout << "Borys" << endl;
    }
}


Measured memory_bytes: 256
n, m = gets.chomp.split(' ').map(&:to_i)

if m > 0
  x, y, z = [], [], []
  x2, y2, z2 = [], [], []
  (0...n).each do |i|
    temp = gets.chomp.split(' ').map(&:to_i)
    x[i] = temp[0]
    y[i] = temp[1]
    z[i] = temp[2]
    x2[i] = -temp[0]
    y2[i] = -temp[1]
    z2[i] = -temp[2]
  end

  puts (0...8).map { |i|
    (0...n).map { |j|
      (i & 4 == 0 ? x2[j] : x[j]) + (i & 2 == 0 ? y2[j] : y[j]) + (i & 1 == 0 ? z2[j] : z[j])
    }.sort.last(m).inject(&:+)
  }.max
else
  puts 0
end


Measured memory_bytes: 2040
n=int(input())
s=list(range(1,14))
h=list(range(1,14))
c=list(range(1,14))
d=list(range(1,14))
for i in range(n):
    nyuuryoku=list(input())
    egara=nyuuryoku[0]
    if len(nyuuryoku)==4:
        suuji=nyuuryoku[2]+nyuuryoku[3]
    else:
        suuji=nyuuryoku[2]
    if egara=='S':
        for i in s:
            if int(suuji)==i:
                s.remove(i)
    if egara=='H':
        for i in h:
            if int(suuji)==i:
                h.remove(i) 
    if egara=='C':
        for i in c:
            if int(suuji)==i:
                c.remove(i) 
    if egara=='D':
        for i in d:
            if int(suuji)==i:
                d.remove(i) 
for i in range(len(s)):
    print('S',s[i])
for i in range(len(h)):
    print('H',h[i])  
for i in range(len(c)):
    print('C',c[i])
for i in range(len(d)):
    print('D',d[i]) 


Measured memory_bytes: 5608
n = int(input())

if n%2:
    m = (n-1-2)*(n-1)//2 + n-1 
else:
    m = (n-2)*n//2
l = []
if n%2:
    for i in range(1,(n-1)//2+1):
        l.append((i,n-i))
    l.append((n,))
else:
    for i in range(1,n//2+1):
        l.append((i,n+1-i))

print(m)
for i in range(len(l)):
    for j in range(i+1,len(l)):
        p = l[i]
        o = l[j]
        for point in p:
            for other in o:
                print(str(point)+" "+str(other))



Measured memory_bytes: 3340
s = str(input())
t = str(input())
 
s_ = list(s)
t_ = list(t)
 
s_.sort()
t_.sort(reverse = True)
 
s_sorted = ""
for S in s_:
  s_sorted += S
 
t_sorted =""
for T in t_:
  t_sorted += T
 
if s_sorted < t_sorted:
  print('Yes')
  
else:
  print('No')
 

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
signed main() {
  double a,b,h,m;
  double c,d,s,x,y;
  
  cin >> a >> b >> h >> m;

  c = 0.5 * m + 30.0 * h;
  d = 6.0 * m;
  s = max(c,d) - min(c,d);

  if(s > 180){
    s = 360 - s;
  }
  
  y = s * (M_PI / 180);
  x = sqrt((a*a + b*b) - (2 * a * b * cos(y)));
  printf("%.20f\n", x);
  return 0;
}


Measured memory_bytes: 4152
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
    int X, Y;
    cin >> X >> Y;

    for (int i = 0; i < X + 1; i++) {
        int c = i;
        int t = X - i;
        if (c * 2 + t * 4 == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


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

int main()
{
	int a, b, c; cin >> a >> b >> c;
	
	string ans = "NO";

	if (a == 5 && b == 5 && c == 7) ans = "YES";
	if (a == 5 && b == 7 && c == 5) ans = "YES";
	if (a == 7 && b == 5 && c == 5) ans = "YES";

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
	
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)
 


int main(){
	double r;
    cin >> r;
    double ans = 2*M_PI*r;
    cout << setprecision(10) << ans;
    
}


Measured memory_bytes: 3776
#include <stdio.h>
#include <string.h>

int main(void){
        char s[7];
        scanf ("%s\n",s);
        if (s[2] == s[3] && s[4] == s[5]){
                printf("Yes\n");
        }else{
                printf("No\n");
        }
        return 0;
}

Measured memory_bytes: 1644
x=int(input())
y=[]
for i in range(0,x):
  y.append(str(input()))
m=0
a=0
r=0
c=0
h=0

for i in y:
  if i[0]=='M':
    m+=1
  elif i[0]=='A':
    a+=1
  elif i[0]=='R':
    r+=1
  elif i[0]=="C":
    c+=1
  elif i[0]=="H":
    h+=1

s=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h

print(s)


Measured memory_bytes: 9772
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
using namespace std;

const ll inf = 1e17;
const ll N = 10;
const ll bits = 30;
const ll mod = 1e9+7;

struct point{
    ld x,y;
    int index;
};


ld cal(point a,point b){
    return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
}


ld sum;


// This code was taken from geeksforgeeks https://www.geeksforgeeks.org/heaps-algorithm-for-generating-permutations/

void printArr(vector<point> &a,int n) 
{ 
    ld dist =0;

    for (int i=0; i+1<n; i++) {
        dist+=cal(a[i],a[i+1]);
        // cout<<a[i].index<<" ";
    }

    // cout<<": "<<dist<<"\n";

    sum+=dist;
} 
  
// Generating permutation using Heap Algorithm 
void heapPermutation(vector<point> &a, int size, int & n) 
{ 
    // if size becomes 1 then prints the obtained 
    // permutation 
    if (size == 1) 
    { 
        printArr(a, n); 
        return; 
    } 
  
    for (int i=0; i<size; i++) 
    { 
        heapPermutation(a,size-1,n); 
  
        // if size is odd, swap first and last 
        // element 
        if (size%2==1) 
            swap(a[0], a[size-1]); 
  
        // If size is even, swap ith and last 
        // element 
        else
            swap(a[i], a[size-1]); 
    } 
} 
  
// Driver code 
int main() 
{   FASTIO;
    PRECISION;
    
    int n;
    cin>>n;
    vector< point >arr(n);
    ld fact=1;

    for(int i=0;i<n;i++){
        fact*=(i+1);
        cin>>arr[i].x>>arr[i].y;
        arr[i].index = i;
    }
    // cout<<"\n\n"<<fact<<"\n";
    heapPermutation(arr, n, n); 

    ld ans = sum/fact;
    cout<<ans<<"\n";
    return 0; 
} 

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int ans[100000];
int main()
{
	int num, a, b;
	scanf("%d%d%d", &num, &a, &b);
	string s;
	cin >> s;
	a += b;
	fill(ans, ans + 100000, 0);
	for (int i = 0; i < num; i++)
	{
		if (s[i] == 'a')
		{
			if (a > 0)
			{
				a--;
				ans[i] = 1;
			}
		}
		else if (s[i] == 'b')
		{
			if (a > 0 && b > 0)
			{
				a--;
				b--;
				ans[i] = 1;
			}
		}
	}
	for (int i = 0; i < num; i++)
	{
		if (ans[i] == 1)printf("Yes\n");
		else printf("No\n");
	}
}

Measured memory_bytes: 1280
#include <iostream>
#include <queue>
using namespace std;
typedef struct P{
  int first;
  int second;
} PAIR;

int main(void){
  int w, h, sx, sy, x, y, i,ans;
  char mp[22][22];
  bool visited[22][22];
  queue<PAIR> que;
  int dx[4] = {0, 1, 0, -1};
  int dy[4] = {1, 0, -1, 0};
  PAIR next, tmp;

  while(1){
    cin >> w >> h;
    if(w == 0) break;
    for(y=0;y<h+2;y++){
      if(y == 0 || y == h + 1){
        for(x=0;x<w+2;x++) mp[y][x] = '#';
      }else{
        for(x=0;x<w+2;x++){
          if(x == 0 || x == w + 1){
            mp[y][x] = '#';
          }else{
            cin >> mp[y][x];
          }
        }
      }
    }
    for(y=0;y<h+2;y++){
      for(x=0;x<w+2;x++){
        if(mp[y][x] == '@'){
          sx = x;
          sy = y;
        }
        visited[y][x] = false;
      }
    }
    que.push(PAIR{sx, sy});

    visited[sy][sx] = true;
    ans = 1;
    
    while(!que.empty()){
      next = que.front();
      que.pop();
      for(i=0;i<4;i++){
        if((!visited[next.second+dy[i]][next.first+dx[i]]) && (mp[next.second+dy[i]][next.first+dx[i]] == '.')){
          ans++;
          visited[next.second+dy[i]][next.first+dx[i]] = true;
          que.push(PAIR{next.first+dx[i], next.second+dy[i]});
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3080
# include <iostream>
# define MAX 100003
# define mod 1000000007

using namespace std;

long long H, W, K;
long long Fib[10];
// 高さ 1, 幅 W のあみだくじの数は、Fib[W]
// Fib[0] = 1,  Fib[1] = 1, Fib[2] = 2,...

long long comb[10] = {};
long long prev_comb[10];

int main(){
    Fib[0] = 1;
    Fib[1] = 1;
    for ( int i = 2; i < 10; i++ ){
        Fib[i] = Fib[i-1] + Fib[i-2];
    }
    
    cin >> H >> W >> K;
    
    comb[1] = 1;
    for ( int j = 1; j <= H; j++ ){
        
        prev_comb[0] = 0;
        for( int i = 1; i<= W; i++){
            prev_comb[i] = comb[i];
        }
        prev_comb[W+1] = 0;
        
        for( int i = 1; i <= W; i++){
            comb[i]
            = ( Fib[i-2] * Fib[W-i] * prev_comb[i-1]
            + Fib[i-1] * Fib[W-i] * prev_comb[i]
            + Fib[i-1] * Fib[W-i-1] * prev_comb[i+1] ) % mod;
        }
    }
    
    cout << comb[K];
}

Measured memory_bytes: 256
import sys
a,b=map(int,input().split())
b=b+1
l=[0]*(a)
List=list(map(int,input().split()))
i=0
j=1
while l[i]==0 and j<b:
  l[i]+=j
  j+=1
  i=List[i]-1
if j==b:
  print(i+1)
  sys.exit()
roop=j-l[i]
c=(b-j)%roop
for y in range(len(l)):
  if l[y]==c+l[i]:
    print(y+1)
    sys.exit()

Measured memory_bytes: 33940
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
class DIJ{
	public:
	vvi G;
	int n;
	vvi d;//distance
	vp in;
	DIJ(int size){
		n=size;
		in=vp(n);
		G=vvi(n);
	}
	void add_ver(int a,int b,int c){
		in[a]=pii(b,c);
	}
	void add_edge(int a,int b){
		G[a].pb(b);
		G[b].pb(a);
	}
	void dij(int s){
		d=vvi(n,vi(n+1,inf));
		d[s][0]=0;//now oktime ->time
		priority_queue<pip>q;
		q.push(pip(0,pii(s,0)));//coat now last
		while(!q.empty()){
			pip p=q.top();
			q.pop();
			int pos=p.second.first;
			int cost=-p.first;
			int nu=p.second.second;
			if(cost>d[pos][nu])continue;
			rep(i,G[pos].size()){
				int to=G[pos][i];
				int nowcost=cost;
				int nownu=nu-1;
				if(nownu>=0&&nowcost<d[to][nownu]){
					d[to][nownu]=nowcost;
					q.push(pip(-nowcost,pii(to,nownu)));
				}
				nowcost=in[pos].first+cost;
				nownu=in[pos].second-1;
				if(nowcost<d[to][nownu]){
					d[to][nownu]=nowcost;
					q.push(pip(-nowcost,pii(to,nownu)));
				}
			}
		}
	}
};
int main(){
	int n,m;
	cin>>n>>m;
	DIJ dij(n);
	rep(i,n){
		int a,b;
		cin>>a>>b;
		dij.add_ver(i,a,b);
	}
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		dij.add_edge(a,b);
	}
	dij.dij(0);
	int out=inf;
	rep(i,n+1)out=min(out,dij.d[n-1][i]);
	cout<<out<<endl;
}

Measured memory_bytes: 197156
#include <stdio.h>

int main(void)
{
	char a[4];
	int x=0,i;
	scanf("%s",a);
	for(i=0;i<4;i++){
		if(a[i]=='+'){
			x++;
		}
	}
	printf("%d",-4+2*x);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
  
#define AMAX 20
#define MMAX 200
 
int A[AMAX+1];
int n, q;
 
int solve( int p, int t )
{
    if( 0 == t ) { return 1; }
    if( p < n ) {
    	return  solve( p+1, t-A[p] ) || solve( p+1, t ) ;
    } else {
    	return 0;
    }
}
 
int main( void ) 
{
    int i;
    int num;
     
    scanf( "%d", &n );  
    for( i=0; i<n; i++ ) {
        scanf( "%d", &A[i] );
    }   
    scanf( "%d", &q );
    for( i=0; i<q; i++ ) {
        scanf( "%d", &num );
        if( solve( 0, num ) ) {
            printf( "yes\n" );      
        } else {
            printf( "no\n" );
        }
    }
  
    return 0;
}

Measured memory_bytes: 580
#include <algorithm>
#include <cmath>
#include <iostream>
#include <deque>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> len;

	for (int i = 0; i < n; ++i)
	{
		int l;
		cin >> l;
		len.emplace_back(l);
	}

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

	long long sum = 0;

	for (int i = 0; i < n; ++i)
	{
		for (int j = i + 1; j < n; ++j)
		{
			int rangeEnd = distance(len.begin(), lower_bound(len.begin(), len.end(), len.at(i) + len.at(j))) - 1;
			if (rangeEnd <= j)
			{
				continue;
			}
			int rangeBegin = distance(len.begin(), upper_bound(len.begin(), len.end(), len.at(j) - len.at(i))) - 1;
			sum += max(0, rangeEnd - max(j,rangeBegin));
		}
	}

	cout << sum << endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> load(m,vector<int> (2));
  for (int i = 0; i < m; i ++) {
    for (int j = 0; j < 2; j ++) {
      cin >> load[i][j];
    }
  }
  for (int i = 1; i <= n; i ++) {
    int ans = 0;
    for (int j = 0; j < m; j ++) {
      for (int k = 0; k < 2; k ++) {
        if (i == load[j][k]) ans ++;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <algorithm>

int main() {
  intmax_t X, Y;
  scanf("%jd %jd", &X, &Y);

  if (X < Y)
    std::swap(X, Y);

  printf("%s\n", (X-Y>1)? "Alice":"Brown");
}


Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var A, B int
	fmt.Scan(&A, &B)
	fmt.Println(XOR(A-1) ^ XOR(B))
}

func XOR(A int) int {
	cnt1 := ((A + 1) / 2) % 2
	if A%2 == 0 {
		return cnt1 ^ A
	}
	return cnt1
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
class Card
{
    public:
    char suit;
    int num;
};
void BubbleSort(Card icards[],int n)
{
    for(int i=0;i<n;i++)
    for(int j=n-1;j>=i+1;j--)
    {
        if(icards[j-1].num>icards[j].num)
        {
            Card t;
            t=icards[j-1];
            icards[j-1]=icards[j];
            icards[j]=t;
        }
    }
}
void SelectionSort(Card icards[],int n)
{
    for(int i=0;i<n;i++)
    {
        int minj=i;
        for(int j=i;j<n;j++)
        if(icards[j].num<icards[minj].num)
        {
            minj=j;
        }
        Card t=icards[i];
        icards[i]=icards[minj];
        icards[minj]=t;
    }
}
int isStable(Card cards1[],Card cards2[],int n)
{
    int flag=1;
    for(int i=0;i<n;i++)
    {
        if(cards1[i].suit!=cards2[i].suit)
        flag = 0;
    }

return flag;
}
int main()
{
    Card cards[36];
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>cards[i].suit;
        cin>>cards[i].num;
    }

    Card ocards1[36];
    Card ocards2[36];
    for(int i=0;i<n;i++)
    {
    ocards1[i]=cards[i];
    ocards2[i]=cards[i];
    }
    BubbleSort(ocards1,n);
    SelectionSort(ocards2,n);
    for(int i=0;i<n;i++)
    {
        if(i) cout<<" ";
        cout<<ocards1[i].suit<<ocards1[i].num;
    }
    cout<<endl;
    cout<<"Stable"<<endl;
        for(int i=0;i<n;i++)
    {
        if(i) cout<<" ";
        cout<<ocards2[i].suit<<ocards2[i].num;
    }
    cout<<endl;
    if(isStable(ocards2,ocards1,n))
    {
        cout<<"Stable"<<endl;
    }
    else
    {
        cout<<"Not stable"<<endl;
    }



//cin>>输入进去char 忽略空格！
}



Measured memory_bytes: 3092
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;


int main()
{
	int m, n1, n2;
	while (cin >> m >> n1 >> n2&&m)
	{
		vi a;
		FOR(i, m)
		{
			inin(x);
			a.push_back(x);
		}
		sort(a.rbegin(), a.rend());

		int g = -1, ans;
		for (int i = n1-1; i < n2;i++)
		{
			if (a[i]- a[i+1] >= g)
			{
				g = a[i] - a[i+1];
				ans = i+1;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 158, task c, 2020/08/13
//ms,
/*
*/

int main(void){
  int a, b;

  cin >>a >>b;

  int i;
  for(i=0;i<1500;i++){
    if(((int)(i*0.080)) == a && ((int)(i*0.10)) == b) goto OUT;
  }
  i=-1;
  OUT:
    cout <<i;
  return 0;
}
/*
*/


Measured memory_bytes: 3596