akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
    using namespace std;
    typedef int sign;
    typedef long long ll;
    #define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
    #define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
    const int N=100+5;
    template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
    template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
    template<typename T>T read()
    {
    	T ans=0,f=1;
    	char ch=getchar();
    	while(!isdigit(ch)&&ch!='-')ch=getchar();
    	if(ch=='-')f=-1,ch=getchar();
    	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
    	return ans*f;
    }
    template<typename T>void write(T x,char y)
    {
    	if(x==0)
    	{
    		putchar('0'),putchar(y);
    		return;
    	}
    	if(x<0)
    	{
    		putchar('-');
    		x=-x;
    	}
    	static char wr[20];
    	int top=0;
    	for(;x;x/=10)wr[++top]=x%10+'0';
    	while(top)putchar(wr[top--]);
    	putchar(y);
    }
    void file()
    {
    #ifndef ONLINE_JUDGE
    	freopen("in","r",stdin);
    	freopen("out","w",stdout);
    #endif
    }
    int u[N],v[N],w[N],cnt;
    void work()
    {
    	int L=read<int>();
    	int k=0;
    	while(1<<k <= L)k++;
    	For(i,0,k-2)
    	{
    		u[++cnt]=i+1,v[cnt]=i+2,w[cnt]=1<<i;
    		u[++cnt]=i+1,v[cnt]=i+2,w[cnt]=0;
    	}
    	Fordown(i,k-2,0)if((L>>i)&1)
    	{
    		u[++cnt]=i+1,v[cnt]=k,w[cnt]=L>>(i+1)<<(i+1);
    	}
    	printf("%d %d\n",k,cnt);
    	For(i,1,cnt)printf("%d %d %d\n",u[i],v[i],w[i]);
    }
    int main()
    {
    //	file();
    	work();
    	return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n],b[n],c[n-1];
    rep(i,0,n-1) cin>>a[i];
    rep(i,0,n-1) cin>>b[i];
    rep(i,0,n-2) cin>>c[i];

    int ans=0;
    int tmp=0;
    rep(i,0,n-1){
        ans += b[a[i]-1];
        if(tmp==a[i]-1){
            ans += c[tmp-1];
        }
        tmp = a[i];
    }    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int n, m;
	cin >> n >> m;
		cout << ((n-1)*n/2+(m-1)*m/2);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string s;
	cin >> s;
	int num_8[N], num_9[N];
	memset(num_8, 0, sizeof(num_8));
	memset(num_9, 0, sizeof(num_9));

	string rsl = s;

	ll count = 0;
	rep(i, 0, N) {
		if(s[i] == ')') {
			num_8[i] = count;
		} else {
			count++;
		}
	}
	count = 0;
	for(int i = N - 1; i >= 0; i--) {
		if(s[i] == '(') num_9[i] = count;
		else count++;
	}

	rep(i, 0, N) {
		if(s[i] == ')') {
			if(num_8[i] == 0) rsl = '(' + rsl;
			else rep(j, i, N) num_8[j]--;
		}
	}

	for(int i = N - 1; i >= 0; i--) {
		if(s[i] == '(') {
			if(num_9[i] == 0) rsl = rsl + ')';
			else for(int j = i; j >= 0; j--) num_9[j]--;
		}
	}

	cout << rsl << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	string S;
	cin >> S;
	bool ans = true;
	int i = S.size()-1;
	while (i >= 0)
	{
		if (i >= 4 && S.substr(i-4, 5) == "dream")
			i -= 5;
		else if (i >= 4 && S.substr(i-4, 5) == "erase")
			i -= 5;
		else if (i >= 6 && S.substr(i-6, 7) == "dreamer")
			i -= 7;
		else if (i >= 5 && S.substr(i-5, 6) == "eraser")
			i -= 6;
		else
		{
			ans = false;
			break ;
		}
	}
	cout << (ans ? "YES" : "NO") << endl;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    int a,b,c; cin >>a >> b >>c;
    if (a+b+c>=22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}

Measured memory_bytes: 256
//062
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n; i++)

using namespace std;
int main(void){
    int a, b;
    cin >>a >>b;
    vector<string>L;
    string tmp;
    rep(i, a){
        cin >> tmp;
        L.push_back(tmp);
    }
    rep(i, b+2) cout << '#';
    cout << endl;
    rep(i, a){
        cout << '#';
        cout << L[i];
        cout << '#' << endl;
    }
    rep(i, b+2) cout << '#';

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpi = vector<pii>;

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * c, max(b * d, max(a * d, c * b))) << "\n";

    return 0;
}

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

int n;
vector<int>cnt(4);


int main() {
	cin >> n;
	
	for(int i = 0; i < n; ++i)
	{
	    int a;
	    cin >> a;
	    cnt[a]++;
	}
	double dp[301][301][301];
	dp[0][0][0] = 0;
	int cnt1 = cnt[1] + cnt[2] + cnt[3];
	int cnt2 = cnt[2] + cnt[3];
	int cnt3 = cnt[3];
	double t = 0;
	for(int k = 0; k <= cnt3; ++k)
	{
	    for(int j = 0; j <= cnt2 - k; ++j)
	    {
	        for(int i = 0; i <= cnt1-j-k; ++i)
	        {
	            t = i+j+k;
	            if(t > 0)
	                dp[i][j][k] = n/double(t);
	            if(k > 0)
	                dp[i][j][k] += (double(k)/t)*dp[i][j+1][k-1];
                if(j > 0)
                    dp[i][j][k] += (double(j)/t)*dp[i+1][j-1][k];
                if(i > 0)
                    dp[i][j][k] += (double(i)/t)*dp[i-1][j][k];
	        }
	    }
	}
	cout << fixed << setprecision(10) << dp[cnt[1]][cnt[2]][cnt[3]];
	return 0;
}


Measured memory_bytes: 111036
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int a, b;
        a = sc.nextInt();
        b = sc.nextInt();

        String strA, strB;
        strA = String.valueOf(a);
        strB = String.valueOf(b);

        String strCon = strA + strB;
//        System.out.println(strCon);

        //数字をつなげた数
        int con = Integer.parseInt(strCon);

        //平方数
        double conSqrt;
        conSqrt = Math.sqrt(con);

        //四捨五入
        conSqrt = Math.round(conSqrt);

        if(conSqrt * conSqrt == con){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 39324
fun main(args: Array<String>) {
    val (n, y) = readLine()!!.split(" ").map { it.toInt() }

    for (i in (0..n)) {
        for (j in (0..n-i)) {
            if (10000*i + 5000*j + 1000*(n-i-j) == y) {
                println("$i $j ${n-i-j}")
                return
            }
        }
    }
    println("-1 -1 -1")
}

Measured memory_bytes: 38028
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;
const int N = 2e5 + 500;
#define ll long long
int main(){
	int n, m;
	cin >> n >> m;
	int sum = 0;
	for(int i = 1; i <= m; i++){
		int x;
		cin >> x;
		sum += x;		
	}
	if(sum > n) cout << -1 << endl;
	else cout << n - sum << endl;
}

Measured memory_bytes: 3636
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <stack>
#include <random>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;

long long INF = 200000100;
long long n, m, R, r[10], pu[210][210], ra[210][210], a, b , c, mi = INF, tec = 0;
vector<long long> we;

int main()
{
#if _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("capital.in", "r", stdin);
	//freopen("capital.out", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin >> n >> m >> R;
	for (long long i = 0; i < R; i++)
	{
		we.push_back(i);
	}
	for (long long i = 0; i <= n; i++)
	{
		for (long long j = 0; j <= n; j++)
		{
			if (i == j)
				continue;
			ra[i][j] = INF;
			pu[i][j] = INF;
		}
	}
	for (long long i = 0; i < R; i++)
	{
		cin >> r[i];
		r[i]--;
	}
	for (long long i = 0; i < m; i++)
	{
		cin >> a >> b >> c;
		a--;
		b--;
		ra[a][b] = min(ra[a][b], c);
		ra[b][a] = min(ra[b][a], c);
	}
	for (long long k = 0; k<n; ++k)
		for (long long i = 0; i<n; ++i)
			for (long long j = 0; j<n; ++j)
				ra[i][j] = min(ra[i][j], ra[i][k] + ra[k][j]);
	do
	{
		tec = 0;
		for (long long i = 1; i < R; i++)
		{
			tec += ra[r[we[i - 1]]][r[we[i]]];
		}
		mi = min(mi, tec);
	} while (next_permutation(we.begin(), we.end()));
	cout << mi;
	return 0;
}

Measured memory_bytes: 896
import math
N,Y = map(int, input().split())
x = -1
y = -1
z = -1
a = math.floor(Y/10000)
for i in range(a, -1, -1):
    money = Y - i*10000
    b = math.floor(money/5000)
    if i+b > N:
        b = N - i
    for j in range(b, -1, -1):
        money = Y - i*10000
        money = money - j*5000
        c = math.floor(money/1000)
        money = money - c*1000
        if (money == 0) and (i+j+c == N):
            print('{} {} {}'.format(i, j, c))
            exit()
print('{} {} {}'.format(x,y,z))


Measured memory_bytes: 3064
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

S=gets.chomp
if S=~/^A?KIHA?BA?RA?$/
    puts "YES"
else
    puts "NO"
end

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

int main(void)
{
	int N;
	cin >> N;

	vector<vector<int>> abc(N, vector<int>(3));
	for(int i=0; i<N; i++)
		for(int j=0; j<abc[i].size(); j++)
			cin >> abc[i][j];

	vector<vector<long long>> dp(N+1, vector<long long>(abc[0].size(), 0));
	for(int i=0; i<N; i++){
		for(int j=0; j<abc[i].size(); j++){
			for(int k=0; k<abc[i].size(); k++){
				if(j == k)
					continue;

				dp[i+1][k] = max(dp[i+1][k], dp[i][j] + abc[i][k]);
			}
		}
	}

	long long ret = *max_element(dp[N].begin(), dp[N].end());
	cout << ret << endl;

	return 0;
}


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

int main()
{
    int A,B;
    cin>>A>>B;
    if(B%A==0)
    {
        cout<<A+B;
    }
    else if(B%A!=0)
    {
        cout<<B-A;
    }

    return 0;
}


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

using namespace std;

const int INF = 1 << 30;

int main()
{
  int N, M, K, D[16], A[100][100];
  int black[100];
  memset(black, -1, sizeof(black));

  cin >> N >> M >> K;
  for(int i = 0; i < M; i++) {
    cin >> D[i];
    black[--D[i]] = i;
  }
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < K; j++) {
      cin >> A[i][j];
      --A[i][j];
    }
  }

  int dp[1 << 16];
  fill_n(dp, 1 << 16, -1);
  queue< int > que;
  que.push((1 << M) - 1);
  dp[(1 << M) - 1] = 0;

  while(!que.empty()) {
    int i = que.front();
    que.pop();
    if(i == 0) break;
    for(int j = 0; j < K; j++) {
      int bitMask = 0;
      for(int k = 0; k < M; k++) {
        if((i >> k) & 1 && ~black[A[D[k]][j]]) bitMask |= 1 << black[A[D[k]][j]];
      }
      if(dp[bitMask] == -1) {
        que.push(bitMask);
        dp[bitMask] = dp[i] + 1;
      }
    }
  }
  cout << dp[0] << endl;
}

Measured memory_bytes: 3552
////////////////////////////////////
///     Please Give Me AC!!!     ///
////////////////////////////////////

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

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

    int ans = 0;
    for(int i = 1; i<N; i++){
        if(N % i == 0){
            ans += (N / i) - 1;
        }else{
            ans += (N / i);
        }
    }
    cout<< ans << endl;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    string s;
    cin >> s;

    deque<char> dq;

    for(char c:s){
        if(c == '0'){
            dq.push_back('0');
        }
        if(c == '1'){
            dq.push_back('1');
        }
        if(c == 'B'){
            if(!dq.empty()) dq.pop_back();
        }
    }

    while(!dq.empty()){
        cout << dq.front();
        dq.pop_front();
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    int ans = 0;
    for(int i=0; i<n; i++){
        ans += a[i]-1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{   
   int i,r,x;
     long long n,ctr=0,c;
  cin>>n;
     for(i=1;i<=n;i++)
     {
        x=i;
       c=0;
       while(x>0)
           {
              r=x%10;
              x=x/10;
              c++;
           }                                                                                                      
             if(c%2!=0)
               ctr++;
     }
        cout<<ctr; 
}


Measured memory_bytes: 256
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  ios_base :: sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  ll L; cin >> L;
  double x = L / 3.0;
  cout << fixed << setprecision(10) << (x * x * x);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define V vector
#define W V<long>
using namespace std;long E,M=2e17,a,b;W A;W S(V<W>p){if(!E)return{1,0};V<V<W>>T(2);for(W x:p){T[x[1]&1].push_back({x[0]/2,x[1]/2});if(x[0]&1)T[x[1]&1].push_back({x[0]/2,++x[1]/2});}for(long i;i<2;i++){a=0;for(W x:T[!i])a^=(2*x[0]+x[1])%3+1;if(!a){E--;A=S(T[i]);A[0]*=2;A[1]*=2;A[1]+=i;return A;}}for(W&v:p)v[0]++;A=S(p);A[0]--;return A;}int main(){cin>>E;V<W>p(E);while(E--,cin>>a>>b)p[E]={a+M,b+M};E=70;W x=S(p);cout<<x[0]-M<<" "<<x[1]-M;}

Measured memory_bytes: 62908
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main()
{
    int N;
    cin >> N;
    map<string, int> list;

    rep2(i, 1, N + 1)
    {
        string numst = to_string(i);
        char a = numst.at(0);
        char z = numst.at(numst.size() - 1);
        string key = "";
        key.push_back(a);
        key.push_back('_');
        key.push_back(z);
        if (list.count(key))
        {
            list.at(key) += 1;
        }
        else
        {
            list[key] = 1;
        }
    }

    int cnt = 0;

    rep(i, 10)
    {
        rep(j, 10)
        {
            string key1 = "";
            key1.push_back(char(i + 48));
            key1.push_back('_');
            key1.push_back(char(j + 48));

            string key2 = "";
            key2.push_back(char(j + 48));
            key2.push_back('_');
            key2.push_back(char(i + 48));

            if (list.count(key1) && list.count(key2))
            {
                cnt += list.at(key1) * list.at(key2);
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;

int main(){
  ll n;
  cin >> n;
  ll ans = 1e12;
  for(ll i=1;i*i<=n;i++){
    if(n%i!=0)continue;
    ll j = n/i;
    ans = min(ans,i+j-2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($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, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        x: i64, y: i64,
    }
    if y % 2 == 0 && x <= y / 2 && y / 2 <= 2 * x {
        puts!("Yes\n");
    } else {
        puts!("No\n");
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

template<class T>
void xmin(T &a, T b){if(a>b)a=b;}

int n;
int b[100];

void solve(){
    cin>>n;
    int ans=0;
    for(int i=0; i<n-1; i++){
        cin>>b[i];
    }
    ans+=b[0];
    for(int i=0; i<n-2; i++){
        ans+=min(b[i],b[i+1]);
    }
    cout<<ans+b[n-2]<<endl;
}

int main(){
    //while(1)
    solve();
}

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

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

    int x = 1;
    int count = 0;

    while (x != 0 && x != 2) {
        int y = x;
        x = a.at(x - 1);
        a.at (y - 1) = 0;
        if (x == 0) count = -1;
        else count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define all(v) v.begin(), v.end()
typedef int64_t lint;
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; }

int main() {
	int H, W, M;
	cin >> H >> W >> M;
	int a=0, b=0, c=0, x, y, z;
	vector<int> vh(H);
	vector<int> vw(W);
	vector<vector<int>> vv(H);
	rep(i, M) {
		cin >> x >> y;
		x--, y--;
		vh.at(x)++, vw.at(y)++;
		vv.at(x).push_back(y);
	}

	vector<int> bh, bw;
	rep(i, H) {
		chmax(a, vh.at(i));
	}
	rep(i, H) {
		if (vh.at(i) == a) bh.push_back(i);
	}
	rep(i, W) {
		chmax(b, vw.at(i));
	}
	rep(i, W) {
		if (vw.at(i) == b) bw.push_back(i);
	}

	c = a + b;
	rep(i, H) {
		sort(all(vv.at(i)));
	}
	rep(i, bh.size()) {
		rep(j, bw.size()) {
			bool f = true;
			x = 0, y = vv.at(bh.at(i)).size();
			rep(k, vv.at(bh.at(i)).size()) {
				if (x == y) break;
				z = (x+y)/2;
				if (vv.at(bh.at(i)).at(z) == bw.at(j)) {
					f = false;
					break;
				} else if (vv.at(bh.at(i)).at(z) > bw.at(j)) {
					y = z;
				} else {
					x = z;
				}
			}
			if (f) {
				std::cout << c << '\n';
				return 0;
			}
		}
	}
	std::cout << c-1 << '\n';
}


Measured memory_bytes: 26188
#include <iostream>
#include <algorithm>

using namespace std;

#define MAX 110
#define MAX_E 10100

struct Edge{
  int u,v,cost;
  Edge(){}
  Edge(int u,int v,int cost) : u(u),v(v),cost(cost) {}
  bool operator < (const Edge &e)const{
    return cost < e.cost;
  }
};

int par[MAX],rank[MAX];

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

int find(int x){
  if(par[x] == x){
    return x;
  }
  return par[x] = find(par[x]);
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y){
    return;
  }
  if(rank[x] < rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rank[x] == rank[y]){
      rank[x]++;
    }
  }
}

bool same(int x,int y){
  return (find(x) == find(y));
}

Edge e[MAX_E];

int kruskal(int E){
  sort(e,e+E);
  int res = 0;
  for(int i = 0 ; i < E ; i++){
    if(!same(e[i].u,e[i].v)){
      unite(e[i].u,e[i].v);
      res += e[i].cost;
    }
  }
  return res;
}

int main(){
  int N,M,a,b,c;
  while(cin >> N >> M,N){
    init(N);
    for(int i = 0 ; i < M ; i++){
      cin >> a >> b >> c;
      e[i] = Edge(a,b,c);
    }
    cout << kruskal(M) << endl;
  }
  return 0;
}

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

using namespace std;

template<typename T>
bool binary_search(vector<T> S, T t) {
    uint32_t b = 0, e = S.size() - 1;
    while (b <= e) {
        uint32_t h = (b + e) / 2;
        if (S[h] == t) {
            return true;
        } else if (S[h] > t) {
            e = h - 1;
        } else {
            b = h + 1;
        }
    }

    return false;
}

int main() {
    uint32_t n, q, count = 0;

    cin >> n;
    vector<uint32_t> S(n);
    for (uint32_t &s : S) cin >> s;

    cin >> q;
    while (q--) {
        uint32_t t;
        cin >> t;
        if (binary_search(S, t)) count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

using namespace std;

int main(){

    int h,w;
    cin >> h >> w;

    int c[10][10] = {};

    rep(i,10){
        rep(j,10){
            int tmp;
            cin >> tmp;
            c[i][j] = tmp;
        }
    }

    rep(k,10){
        rep(i,10){
            rep(j,10){
                c[i][j] = min(c[i][j], c[i][k]+ c[k][j]);
            }
        }
    }

    int ans = 0;

    rep(i,h){
        rep(j,w){
            int tmp;
            cin >> tmp;

            if(tmp != -1){
                //cerr << "from:" << tmp << " to:1 cost:" << c[tmp][1] << endl; 
                ans += c[tmp][1];
            }
        }
    }

    //cerr << "from:8" << " to:9 cost:" << c[8][9] << endl;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = {}
maxvalue = -1
for i in range(n):
    sn = input()
    if(s.get(sn) == None):
        s[sn] = 0
    else:
        s[sn] += 1
    maxvalue = max(maxvalue,s[sn])

answers = []
for key in s.keys():
    if s[key] == maxvalue:
        answers.append(key)

answers.sort()

for ans in answers:
    print(ans)

Measured memory_bytes: 35388
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define MAX_V 1000
#define INF 1<<29
using namespace std;
 
 
//  geometry
 
 
typedef double D;
typedef complex<D> P;
const D EPS = 1e-9;
#define X real()
#define Y imag()
 
//  flow
 
 
struct edge{int to,cap,rev;};
vector<edge>G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}
void bfs(int s){
  memset(level,-1,sizeof(level));
  queue<int>q;
  level[s]=0;
  q.push(s);
  while(!q.empty()){
    int v=q.front();q.pop();
    for(int i=0;i<G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[e.to]<0){
    level[e.to]=level[v]+1;
    q.push(e.to);
      }
    }
  }
}
int dfs(int v,int t,int f){
  if(v==t)return f;
  for(int &i=iter[v];i<G[v].size();i++){
    edge &e=G[v][i];
    if(e.cap>0&&level[v]<level[e.to]){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
    e.cap-=d;
    G[e.to][e.rev].cap+=d;
    return d;
      }
    }
  }
  return 0;
}
int max_flow(int s,int t){
  int flow=0;
  while(1){
    bfs(s);
    if(level[t]<0)return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,INF))>0){
      flow+=f;
    }
  }
}
 
void init(){
  r(i,MAX_V)G[i].clear();
  r(i,MAX_V)level[i]=0;
  r(i,MAX_V)iter[i]=0;
}
 
int n,m;
double xx,yy,vv[101];
double di[101][101];
vector<P>v,vp;
 
int main(){
  while(cin>>n>>m,n){
    vp.clear();
    v.clear();
    r(i,n){
      cin>>xx>>yy>>vv[i];
      v.push_back(P(xx,yy));
    }
    r(i,m){
      cin>>xx>>yy;
      P pt=P(xx,yy);
      vp.push_back(pt);
    }
    r(i,n)r(j,m)di[i][j]=abs(vp[j]-v[i])/vv[i];
    D l=0,r=1e9;
    r(i,77){
       
      init();
      D mid=(l+r)/2;
       
      r(j,n)r(k,m)if(di[j][k]<=mid){
        add_edge(j+1,k+201,1);
      }
      r(j,n)add_edge(0,j+1,1);
      r(j,m)add_edge(j+201,500,1);
 
      int ans=max_flow(0,500);
 
      if(ans==m)r=mid;
      else l=mid;
    }
    printf("%.8f\n",l);
  }
}

Measured memory_bytes: 3476
package main

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

func main() {
	N := nextInt()
	Ls := nextInts(N)
	sum := Sum(Ls...)
	max := Max(Ls...)
	if sum-max > max {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func Sum(slice ...int) int {
	sum := 0
	for _, v := range slice {
		sum += v
	}
	return sum
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}


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

#define lugan "GRID1"
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define endl '\n'
#define _io ios_base::sync_with_stdio(0);   cin.tie(NULL); cout.tie(NULL);

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e3+7;
const int oo = 1e9+7;

inline void initf()
{
    freopen(lugan".inp", "r", stdin);
    freopen(lugan".out", "w", stdout);
}

int n, m, dp[N][N];
char a[N][N];

int main()
{
    _io
    cin >> n >> m;
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
            cin >> a[i][j];
    dp[1][0] = 1;
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
            if (a[i][j] == '.')
                dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % oo;
            else dp[i][j] = 0;
    cout << dp[n][m];
    return 0;
}



Measured memory_bytes: 5248
#include <iostream>
using namespace std;
typedef long long ll;
#define INF 1145141919810
int main() {
	ll n,weight,dp[101][100001],w[101],v[101],ans,VV=0;
	cin>>n>>weight;
	for(int i=1;i<=n;i++){
      cin>>w[i]>>v[i];
      VV+=v[i];
    }
	dp[0][0]=0;
	for(int i=1;i<=VV;i++)dp[0][i]=INF;
	for(int i=1;i<=n;i++){
	    for(int val=0;val<=VV;val++){
	        if(val-v[i]<0){
	            dp[i][val]=dp[i-1][val];
	        }
	        else{
	            dp[i][val]=min(dp[i-1][val-v[i]]+w[i],dp[i-1][val]);
	        }
	    }
	}
	for(int i=0;i<=VV;i++){
	    if(dp[n][i]<=weight){
	        ans=i;
	    }
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 79104
io = STDIN
n,tt=io.gets.chomp.split.map(&:to_i)
t=io.gets.chomp.split.map(&:to_i)
tot=0
t.each_cons(2) do |a,b|
  if b-a > tt
    tot+=tt
  else
    tot+=b-a
  end
end
tot+=tt
puts tot

Measured memory_bytes: 17924
MOD = 10 ** 9 + 7
n = int(input())
s = list(map(int, input().split()))
acu = [0]
t = s[::-1]
for i in range(n):
    acu.append(acu[-1] + t[i])
u = acu[::-1]

res = 0
for i in range(1, n):
    res += s[i - 1] * u[i]
    res %= MOD
print(res)


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

int main() {
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i=0; i<n; i++) {
    cin >> a.at(i);
  }
  bool flag = true;
  for(int j=0; j<100; j++) {
    for(int i=0; i<n; i++) {
      if(a.at(i) % 2 == 0) {
        a.at(i) /= 2;
      }
      else {
        flag = false;
        cout << j << endl;
        break;
      }
    }
    if(flag == false)
      break;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

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

    vector<string> S;
    map<string,int> m;


    rep(i,s.size())for(int j = i;j < s.size();j++){
        if(j-i > 5)continue;
        string ans = s.substr(i,j-i+1);
        if(m[ans] > 0)continue;
        m[ans]++;
        S.push_back(ans);
    }

    sort(all(S));

    cout << S[K-1] << endl;
}

Measured memory_bytes: 2556
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int B = line[1];
            int C = line[2];
            int ans = 0;
            if (A == B)
            {
                ans = C;
            }
            else if (A == C)
            {
                ans = B;
            }
            else
            {
                ans = A;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin >> n >> m;
vector<int>wa(n+1);
vector<int>ac(n+1);
int ca = 0 , p = 0;
for(int i = 0; i < m; ++i){
int tmp; 
cin >> tmp;
string ver;
cin >> ver;
if(ver == "AC"){
	if(ac[tmp]){
    	continue;
    }
  	else{
    	p+=wa[tmp];
      	ca+=1;
      	ac[tmp]++;
    }
}
else{
	wa[tmp]++;
}

}
cout << ca <<" " << p <<"\n";
return 0;

}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>

using namespace std;

char str[1000];

int ispal(int s,int e)
{
    if(s>=e)
        return 1;
    if(str[s]==str[e])
        return ispal(s+1,e-1);
    return 0;
}

int main()
{
    int m;
    cin>>str;
    m=strlen(str);
    (ispal(0,m-1)&&ispal(0,m/2-1)&&ispal(m/2+1,m-1))?cout<<"Yes":cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

 
int main() {
    int h, w;
    cin >> h >> w;
    vint c(26, 0);
    map<char, int> mp;
    rep(i, h) rep(j, w) {
        char a;
        cin >> a;
        c[a-'a']++;
    }
    vint rm;
    int sum = 0;
    rep(i, 26) {
        int num = c[i]%4;
        if (num != 0) {
            rm.push_back(num);
            sum += num;
        }
    }
    if (h%2 == 0 && w%2 == 0) {
        if (rm.size() == 0) puts("Yes");
        else puts("No");
    }
    else if (h%2 == 1 && w%2 == 1) {
        int odd = 0;
        for (int r : rm) if (r%2 == 1) odd++;
        if (odd == 1 && sum <= h+w-1) puts("Yes");
        else puts("No");
    }
    else if (h%2 == 1) {
        int odd = 0;
        for (int r : rm) if (r%2 == 1) odd++;
        if (odd == 0 && sum <= w) puts("Yes");
        else puts("No");
    }
    else {
        int odd = 0;
        for (int r : rm) if (r%2 == 1) odd++;
        if (odd == 0 && sum <= h) puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long k = sc.nextLong();
    int[] a = new int[n];
    int[] first_time = new int[n];
    boolean[] flag = new boolean[n];

    for(int i=0; i<n; i++){
      a[i] = sc.nextInt()-1;
    }

    int here_start = 0;
    int here = here_start;
    int times = 1;
    flag[0] = true;
    first_time[0] = times;
    times += 1;
    int period = 0;
    int not_period = 0;
    int start_node = 0;

    while(true){
      here = a[here];
      if(flag[here]==false){
        flag[here] = true;
        first_time[here] = times;
      }else{
        period = times - first_time[here];
        not_period = times - period -1;
        start_node = here;
        break;
      }

      times ++;
    }

    // System.out.println(period);
    // System.out.println(not_period);

    int ans = 0;

    if(k<not_period){
      here = here_start;
      for(int i=0; i<k; i++){
        here = a[here];
      }
      System.out.println(here+1);
    }else{
      long bb = (k - not_period) % period;
      for(int i=0; i<bb; i++){
        start_node = a[start_node];
      }
      System.out.println(start_node+1);
    }



  }
}

Measured memory_bytes: 61144
#include <bits/stdc++.h>
using namespace std;
 
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;
}
 
int main(){
      int a,b;
      cin >> a >> b;
      int x,y;
      extgcd(a,b,x,y);
      cout << x << " " << y << endl;
 
}

Measured memory_bytes: 3100
from collections import deque
H, W = map(int, input().split())
A = [[1 if a == "#" else 0 for a in input()] for _ in range(H)]

dd = [(0, 1), (0, -1), (1, 0), (-1, 0)]
def BFS():
    Q = deque([(0, 0)])
    D = [[-1] * W for _ in range(H)]
    D[0][0] = 0
    while Q:
        i, j = Q.popleft()
        for di, dj in dd:
            ni, nj = i + di, j + dj
            if 0 <= ni < H and 0 <= nj < W:
                if D[ni][nj] == -1 and A[ni][nj] == 0:
                    D[ni][nj] = D[i][j] + 1
                    Q.append((ni, nj))
    return D

print(H * W - sum([sum(a) for a in A]) - BFS()[-1][-1] - 1 if BFS()[-1][-1] >= 0 else -1)

Measured memory_bytes: 3436
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
const double pi = 3.1415926535;
/*
https://codeforces.com/contest/1106/problems
https://codeforces.com/contest/1106/submit
*/
const ll mod = 1e9+7;
//快速幂 (a^b)%mod
//如果求逆元，则b = mod-2;
ll pow_quick(ll a,ll b){
    ll r = 1,base = a;
    while(b){
        if(b & 1){
            r *= base;
            r %= mod;
        }
        base *= base;
        base %= mod;
        b >>= 1;
    }
    return r;
}
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
long long ans;
int MOD=1e9+7;
int n;
int brr[100005];
int main()
{
    scanf("%d",&n);
    bool flag=true;
    int x;
    memset(brr,0,sizeof(brr));
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&x);
        brr[x]++;
    }
    if(n%2==0)
    {
        if(brr[0]>0)
        {
            printf("0\n");
            return 0;
        }
        for(int i=1;i<=n-1;i+=2)
        {
            if(brr[i]!=2)
            {
                printf("0\n");
                return 0;
            }
        }
    }
    else
    {
        if(brr[0]!=1)
        {
            printf("0\n");
            return 0;
        }
        for(int i=2;i<=n-1;i+=2)
        {
            if(brr[i]!=2)
            {
                printf("0\n");
                return 0;
            }
        }
    }
    ans=1;
    for(int i=1;i<=n/2;i++)
        ans=((ans%MOD)*2)%MOD;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1272
#include <iostream>
int main(){
	int x;
	int y;
	while(true){
		std::cin >> x >> y;
		if(x == 0 && y == 0)break;
		if(x > y){
			std::cout << y <<" "<< x <<std::endl;
		}else{
			std::cout << x <<" "<< y <<std::endl;
		}
	}}

Measured memory_bytes: 2972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    ll ans = 0;
    vector<int> L(N), R(N);
    for(int i = 0; i < N; ++i) {
        cin >> L[i] >> R[i];
    }
    sort(L.begin(), L.end());
    sort(R.begin(), R.end());
    ll now = 0;
    for(int i = 0; i <= N / 2; i++) {
        now += 2 * L[N - i - 1];
        ans = max(ans, now);
        if(i * 2 + 1 >= N)
            break;
        now -= 2 * R[i];
        ans = max(ans, now);
    }
    now = 0;
    for(int i = 0; i <= N / 2; i++) {
        now -= 2 * R[i];
        ans = max(ans, now);
        if(i * 2 + 1 >= N) break;
        now += 2 * L[N - i - 1];
        ans = max(ans, now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
N, M, Q = gets.chomp.split.map(&:to_i)
a = Q.times.map{gets.split.map(&:to_i)}
ans = []
sum = 0

ary = [*1..M].repeated_combination(N).to_a

ary.each do |n|
  a.each do |(a, b, c, d)| 
    if n[b-1] - n[a-1] == c
      sum += d
    end
  end
ans << sum
sum = 0
end

puts ans.max

Measured memory_bytes: 29048
#include<iostream>
#include<queue>
#include<algorithm>

using namespace std;

static const int MAX = 10000;
static const int UNVISITED = 0;
static const int VISITING = 1;
static const int VISITED = 2;

static const int INFTY = (1 << 30 );


int n;
vector<pair<int, int> > adj[MAX];

void Dijkstra() {
   
   priority_queue<pair<int, int> > PQ;
   
   int d[MAX], s[MAX];
   for( int i = 0; i < n; i++) {
    	d[i] = INFTY;
       	s[i] = UNVISITED;
    }

    d[0] = 0;
    PQ.push(make_pair(0, 0));

    while( !PQ.empty() ) {
       	pair<int, int > f = PQ.top(); PQ.pop();
       	int u = f.second;
       	s[u] = VISITED;
        
        if ( d[u] < f.first * (-1) ) continue;

        for( int j = 0; j < adj[u].size(); j++ ) {
        	int v = adj[u][j].first;
        	if( s[v] != VISITED ) {
        		if( d[v] > d[u] + adj[u][j].second ){
        			d[v] = d[u] + adj[u][j].second;
        			PQ.push(make_pair((-1) * d[v], v ));
        		}
        		
        	}
        }

    }

   for(int i = 0; i < n; i++ ) {
   	   	cout << i << ' ' << d[i] << endl;
   }
   	
   
}


int main() {
      
   int u, k, v, c;

   cin >> n;
   for( int i = 0; i < n; i++) {
   	cin >> u >> k;
   	while( k-- ) {
   		cin >> v >> c;
   		adj[u].push_back( make_pair(v, c));
   	}
   }

    Dijkstra() ;

   return 0;
}




Measured memory_bytes: 8080
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

r = n - m + 1
for i_r in range(r):
    for j_r in range(r):
        ok = True
        for i in range(m):
            for j in range(m):
                if a[i_r + i][j_r + j] != b[i][j]:
                    ok = False
        if ok:
            print('Yes')
            exit(0)

print('No')


Measured memory_bytes: 9104
#include<iostream>

int main() {
	char s[11];
	bool flag = false;
	int i;

	std::cin >> s;

	for (i = 0; s[i]!='\0'; i++) {
		if (i % 2 == 0 && s[i] == 'h')flag = true;
		else if (i % 2 != 0 && s[i] == 'i')flag = true;
		else {
			flag = false;
			break;
		}
	}
	if (i < 2 || i % 2 != 0)flag = false;

	if (flag)std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;

	return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val (H,W) = readLine()!!.split(" ").map(String::toInt)
    val power = 0.until(10).map {
        readLine()!!.split(" ").map(String::toInt)
    }

    val A = (1..H).map{
        val row = readLine()!!.split(" ").map(String::toInt)
        assert(row.size == W)
        row
    }

    var costs = Array(10) {i-> Array(10) {j-> power[i][j]}}
    for(i in 0..9) {
        for(j in 0..9) {
            for(k in 0..9) {
                costs[j][k] = arrayOf(costs[j][k],costs[j][i]+costs[i][k]).min()!!
            }
        }
    }
    val min_costs = Array(10) {costs[it][1]}
    // min_costs.joinToString(",").let(::println)
    A.fold(0L) {sum,row -> 
    sum + row
    .filter{it != -1}
    .fold(0L) {acc,index->
        acc + min_costs[index]
    }}.let {
        println(it)
    }
}


Measured memory_bytes: 43460
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NK = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, K) = (NK[0], NK[1]);
        var A = new int[K][];
        var notHave = new bool[N];

        for (int i = 0; i < K; i++)
        {
            var d = int.Parse(ReadLine());

            A[i] = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        }

        foreach (var Ai in A)
        {
            foreach (var a in Ai)
            {
                notHave[a - 1] = true;
            }
        }

        var ans = notHave.Where(x => !x).Count();

        WriteLine(ans);
    }
}


Measured memory_bytes: 28436