akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            long N = cin.ReadLong;
            long[] A = cin.ReadLongArray(N + 1);
            long[] B = cin.ReadLongArray(N);
            long ans = 0;
            for(long i = 0; i < N; i++)
            {
                if (B[i] <= A[i])
                {
                    ans += B[i];
                }
                else{
                    ans += A[i];
                    B[i] -= A[i];
                    if (B[i] <= A[i + 1])
                    {
                        ans += B[i];
                        A[i + 1] -= B[i];
                    }
                    else
                    {
                        ans += A[i + 1];
                        A[i + 1] = 0;
                    }
                }

            }
            Console.WriteLine(ans);
        }
            

                
    }  
            


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}


Measured memory_bytes: 31836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n,m;cin>>n>>m;
    vector<bool> a(n+10,true);
    rep(i,m){
        int b;cin>>b;
        a[b] = false;
    }
    vector<ll> dp(100100,0);
    dp[0] = 1;
    if(a[1]) dp[1] = 1;
    for(int i=2;i<=n;i++){
        if(!a[i]) continue;
        dp[i] = (dp[i-1] + dp[i-2])%MOD;
    }
    cout << dp[n] << endl;
}

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

#define int long long

int MOD;

vector<vector<int>> pro(vector<vector<int>>& a, vector<vector<int>>& b){
  vector<vector<int>> c(a.size(), vector<int>(b.size()));
  
  for(int i = 0; i < a.size(); i++){
    for(int j = 0; j < b[0].size(); j++){
      for(int k = 0; k < b.size(); k++){
        c[i][j] += a[i][k]*b[k][j];
        c[i][j] %= MOD;
      }
    }
  }

  return c;
}

vector<vector<int>> power(vector<vector<int>> a, int t){
  vector<vector<int>> res(a.size(), vector<int>(a.size()));
  
  for(int i = 0; i < a.size(); i++){
    res[i][i] = 1;
  }

  while(t){
    // cout<<t<<endl;
    if(t&1){
      res = pro(res, a);
    }
    a = pro(a,a);
    t >>= 1;
  }

  return res;
}

signed main(){
  
  while(true){
    int n, A, B, C, T;
    vector<vector<int>> mat, ans;

    cin>>n>>MOD>>A>>B>>C>>T;

    if(!n) break;

    ans.resize(n,vector<int>(1,0));
    mat.resize(n,vector<int>(n,0));
    
    for(int i = 0; i < n; i++){
      int S;
      
      cin>>S;
      
      ans[i][0] = S;
    }

    for(int i = 1; i < n-1; i++){
      mat[i][i-1] = A;
      mat[i][i] = B;
      mat[i][i+1] = C;
    }
    
    mat[0][0] = B;
    mat[0][1] = C;
    mat[n-1][n-2] = A;
    mat[n-1][n-1] = B;
    
    // cout<<"power "<<endl;
    
    mat = power(mat, T);
    
    //  cout<<"pro "<<endl;
    ans = pro(mat, ans);
    
    //cout<<"<> "<<endl;
    for(int i = 0; i < n; i++){
      if(i) cout<<" ";
      cout<<ans[i][0];
    }
    cout<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3100
#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define N 101

int main(int argc, char const *argv[])
{
	int i;
	char str[N];
	// 対称な行をカウントする変数
	int cnt = 0;
	// 対称かどうか判断する変数
	int issame = 0;

	// while(fgets(str, N, stdin) != NULL) {
	while(scanf("%s", str) != EOF) {
		int len = strlen(str);
		// 配列の後ろから文字を調べるための変数
		int j = len - 1;

		// デバッグ
		// printf("len = %d j = %d\n", len, j);

		for(i = 0; i < len; i++) {
			if(isalpha(str[i])) {
				if(str[i] == str[j]) {
					issame = 1;
				}
				else {
					issame = 0;
					break;
				}
			}
			// 数字が紛れていればカウントしない
			else {
				issame = 0;
				break;
			}
			j--;
			
			// 配列の要素数の半分を超えたらループから抜ける
			if (i > j)
				break;
			
		}

		if(issame == 1)
			cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 540
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 100000000

using namespace std;
typedef long long ll;

int main(){
    string s;
    getline(cin,s);
    int len=s.size();
    for(int i=0;i<len;i++) {
        if('a'<=s[i] && s[i]<='z')s[i]+='A'-'a';
    }
    cout<<s<<endl;
}

Measured memory_bytes: 1172
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, R);
    OUT(2 * 3.1415 * R);
}


Measured memory_bytes: 3784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int N, M;
  int a, b;
  cin >> N >> M;
  vector<vector<int>> graph(N);
  rep(i,M){
    cin >> a >> b;
    a--; b--;
    graph[a].pb(b);
    graph[b].pb(a);
  }
  vector<int>d(N); rep(i,N) d[i]=-1;
  queue<int> q;
  q.push(0);
  d[0]=0;
  while(!q.empty()){
    int now = q.front(); q.pop();
    rep(i,(int)graph[now].size()){
 	    if(d[graph[now][i]]>=0)continue;
      q.push(graph[now][i]);
      d[graph[now][i]]=d[now]+1;
    }
  }
  if(d[N-1]==2) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}


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

int main()
{
    int n, x;
    int a[100];
    cin >> n >> x;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);

    int num = 0;
    for(int i = 0; i < n; i++)
    {
        if (x >= a[i])
        {
            x -= a[i];
            num++;
        }
        else
        {
            break;
        }
    }
    if (x > 0)
    {
        if (num > 0 && num == n)
        {
            num--;
        }
    }
    cout << num << endl;

    return 0;
}




Measured memory_bytes: 256
A,B,C = map(int,input().split())
count = 0

if A == B and B == C and A%2 == 0:
  print(-1)

else:
  while True:
    if A%2 == 1 or B%2 == 1 or C%2 == 1:
      break
    else:
      A2 = A
      B2 = B
      C2 = C
      A = B2/2 + C2/2
      B = A2/2 + C2/2
      C = A2/2 + B2/2
      count += 1
  print(count)

Measured memory_bytes: 9096
s = input()
a = "0"
b = "1"
for _ in range(len(s)-1):
    if a[-1] == '1':
        a += '0'
    else:
        a += '1'
    
    if b[-1] == '1':
        b += '0'
    else:
        b += '1'
        
a_ans, b_ans = 0, 0
for i in range(len(s)):
    if a[i] != s[i]:
        a_ans += 1
    if b[i] != s[i]:
        b_ans += 1

print(min(a_ans, b_ans))

Measured memory_bytes: 3316
#include <iostream>

int main(){
	int n;
	scanf("%d", &n);
	if( n == 1  ) {
		printf("Hello World\n");
	}else{
		int a, b;
		scanf("%d", &a);
		scanf("%d", &b);
		printf("%d\n", a + b);
	}
	return 0;
}


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

using namespace std;

int a[100010], n;
int x = 0, y = 0;

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a, a + n);

    for (int i = 0; i < n; ++i) {
        int t = a[i] / 2;
        auto it = lower_bound(a, a + n, t);
        //cout << a[i] << " " << *it << endl;
        if (a + i == it) --it;
        t = *it;
        for (int k = 0; k < 4 && it >= a; ++k, --it)
            if (a[i] - max(a[i] - t, t) < a[i] - max(a[i] - *it, *it)) t = *it;
        if (a[i] - max(a[i] - t, t) >= x - max(x - y, y)) x = a[i], y = t;
    }
    cout << x << " " << y;
}


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

#define LL long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define vecprint(vec) for (int i=0;i<vec.size();i++)printf("%d ",vec[i]);
#define all(x) x.begin(),x.end()
#define sc(x) scanf("%lld",&x)
#define scl(x) scanf("%lld",&x)
#define MEM(v,x) memset(v,x,sizeof v)

const double eps=1e-7,PI=3.1415926;
const int N=2e5+10;

using namespace std;

LL n,q,m,k,x,y,a[N],mx=-1,mn=1e9,sum,t;
char c[N];
string s,s1,s2;
map < LL , LL > mp;
vector < LL > vec;

int main(){
    cin>>n>>m;
    if (n*500>=m)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
//using namespace atcoder;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
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; }
const ll INF = 1e18;


#define debug(v) cout<<#v<<": ",prt(v);
template <typename A,typename B>
inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";}
template <typename A,typename B,typename C>
inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";}
inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';}
template <typename T> 
inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template<typename T> 
inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } }
template <typename T> 
inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename A,typename B>
inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}
template <typename T> 
inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';}

ll n,t;
vector<P>v;

ll dp[3100][6010];

int main(){
    cin >> n >> t;
    v.resize(n);
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        v[i]={a,b};
    }
    sort(v.begin(),v.end());
    rep(i,n){
        rep(j,t){
            chmax(dp[i+1][j],dp[i][j]);
            chmax(dp[i+1][j+v[i].first],dp[i][j]+v[i].second);
        }
    }
    ll ans = 0;
    rep(i,3100)rep(j,6010)chmax(ans,dp[i][j]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 117648
#include<bits/stdc++.h>
using namespace std;
#define N 100000
#define int long long
int f[N];
main(){
    int n,W;
    int w[100],v[100];
    cin>>n>>W;
    for(int i=0;i<n;i++)cin>>w[i]>>v[i];
    for(int i=0;i<n;i++){
        for(int j=W;j>=w[i];j--){
            if(f[j-w[i]]+v[i]>f[j])f[j]=f[j-w[i]]+v[i];

        }
    }

    //for(int i=0;i<=W;i++)cout<<f[i]<<"\n";

    cout<<f[W]<<"\n";
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
static const int N = 100;
void trace(int A[], int n){
    for(int i = 0; i < n; i++){
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
}
void BubbleSort(int A[], int n){
    int cnt = 0, flag = 1;
    while(flag){
        flag = 0;
        for(int j = n-1; j >= 1; j--){
            if(A[j] < A[j-1]){
                int tmp;
                tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
                cnt ++;
            }
        }
    }
    trace(A,n);
    cout << cnt << endl;
}
int main(){
    int n;
    int A[N+1];
    cin >> n;
    for(int i = 0; i < n; i++) cin >> A[i];
    BubbleSort(A,n);
}

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

typedef long long i64;

int main() {
  i64 a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;
  if ((v - w) * t >= abs(b - a))
    cout << "YES\n";
  else
    cout << "NO\n";
}


Measured memory_bytes: 3616
#include<stdio.h>
#include<math.h>

double p(int n){
  double x=(double)n;
  return x*x;
}

double hoftr(int x,int h){
  return sqrt(p(x)/4+p(h));
}

double pyramid(int x,int h){
  return ((double)p(x))+((double)(2*x))*hoftr(x,h);
}

void ans(){
  int x,h;
  scanf("%d",&x);
  scanf("%d",&h);
  if((x!=0)||(h!=0)){
    double a=pyramid(x,h);
    printf("%f\n",a);
    ans();
  }
}

int main(){
  ans();
  return 0;
}

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

using namespace std;

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

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

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int MAXN = 2013;

int INF;

int add(int a, int b)
{
    a += b; if (a >= INF) a -= INF; return a;
}
int mul(int a, int b)
{
    return (ll) a * b % INF;
}
int sub(int a, int b)
{
    a -= b; if (a < 0) a += INF; return a;
}
int pwr(int a, int b)
{
    int res = 1;
    while(b > 0)
    {
        if (b & 1) res = mul(res, a);
        b >>= 1;
        a = mul(a, a);
    }
    return res;
}
int inv(int a)
{
    return pwr(a, INF - 2);
}
int dvd(int a, int b)
{
    return mul(a, inv(b));
}

int N;
int dp[3 * MAXN][9 * MAXN / 2];
int DIF = 3 * MAXN;
int ans;

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    //condition: for all x, # of guys <x right of x is at most 3.
    cin >> N >> INF;
    dp[0][DIF] = 1;
    FOR(i, 0, 3 * N)
    {
        FOR(j, DIF - i - 1, DIF + (i / 2) + 1)
        {
            //add a 1.
            dp[i + 1][j - 1] = add(dp[i + 1][j - 1], dp[i][j]);
            //add a 2.
            dp[i + 2][j + 1] = add(dp[i + 2][j + 1], mul(dp[i][j], i + 1));
            //add a 3.
            dp[i + 3][j] = add(dp[i + 3][j], mul(dp[i][j], (i + 1) * (i + 2)));
        }
    }
    FOR(i, 0, DIF + 1)
    {
        ans = add(ans, dp[3 * N][i]);
    }
    cout << ans << '\n';
    return 0;
    //each # must be record max.
    //dp[length][#2s - #1s] = #ways
    // cin >> N >> INF;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

int main(int argc, char const* argv[])
{
    string S,T;
    cin >> S >> T;

    vector<string> cand;
    if (S.size() < T.size()) {
        cout << "UNRESTORABLE" << endl;
    }else{
        for (int i = 0; i < sz(S)-sz(T)+1; i++) {
            string str = S;
            for (int j = 0; j < sz(T); j++) {
                if (S[i+j] == '?' || S[i+j] == T[j]) {
                    str[i+j] = T[j];
                }else{
                    str = "";
                    break;
                }
            }
            if (str != "") {
                for (int i = 0; i < sz(S); i++) {
                    if (str[i] == '?') {
                        str[i] = 'a';
                    }
                }
                cand.push_back(str);
            }

        }
        if (sz(cand) == 0) {
            cout << "UNRESTORABLE" << endl;
        }else{
            sort(all(cand));
            cout << cand[0] << endl;
        }
    }
    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


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

int main(){
  while(true){
    int n, x, count = 0;
    cin >> n >> x;
    if(n == 0 && x == 0) break;

    for(int i = n; i >= 3; i--){
      for(int j = i - 1; j >= 2; j--){
        for(int k = j - 1; k >= 1; k--){
          if( i == j || j == k || k == i) continue;
          if((i + j + k) == x) count += 1;
        }
      }
    }

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

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

int main() {
  int N, M, K; cin >> N >> M >> K;
  if (K == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      int tmp = i * M + j * N - 2 * i * j;
      if (tmp == K) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string con;
    cin >> con;
    if(con == "ABC") cout << "ARC" << "\n";    
    else             cout << "ABC" << "\n";
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if((a*10+b)<a*10+a)
        printf("%d\n",a-1);
    else
        printf("%d\n",a);
    //printf("%d\n",((a*10+b)-10)/10+1);
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) {

        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);

        String strN[] = new String[6];

        PrintWriter out = new PrintWriter(System.out);
        try {

        	for (int i=0 ; i<6 ; i++) {
        		strN[i] = br.readLine();
        	}

            boolean bResult = true;

        	int distD = Integer.parseInt(strN[5]);

        	int intN[] = new int[5];

        	for (int i=0 ; i<4 ; i++) {
        		intN[i] = Integer.parseInt(strN[i]);
        	}

        	Arrays.sort(intN);
        	int dist1 = Integer.parseInt(strN[0]);
        	int dist2 = Integer.parseInt(strN[4]);

        	if (dist2 - dist1 > distD) {
        		bResult = false;
        	}

        	if (bResult)
        		System.out.println("Yay!");
        	else
        		System.out.println(":(");


            out.flush();


        } catch (IOException e) {

        }


    }

}

Measured memory_bytes: 22612
l, r = map(int, input().split())
"""
もしl~rの範囲に2019の倍数を含むならば、2019の倍数をi,jのいずれかに設定して0を得る。
それ以外の場合、l~rの範囲は高々2019程度なので、全探索で間に合う
"""
if r//2019 - l//2019 > 0:
    print(0)
else:
    ans = 2019
    for i in range(l, r):
        for j in range(l+1, r+1):
            ans = min(ans, (i*j)%2019)
            if ans == 0:
                break
    print(ans)

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

#define _LL long long

int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) cin >> ans[i];
    return ans;
}

_LL _f[100004];

int main()
{
    int n, m;
    cin >> n >> m;
    int *a = inputint(m);
    _f[0] = 1;
    int index = 0;
    if(a[index] == 1 )
    {
        _f[1] = 0;
        index++;
    }
    else
    {
        _f[1] = 1;        
    }
    
    for( int i = 2; i <= n; i++ )
    {
        if( a[index] == i )
        {
            index++;
            _f[i] = 0;
        }
        else
        {
            _f[i] = (_f[i - 2] + _f[i - 1]) % 1000000007;
        }        
    }

    cout << _f[n];
}

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

using namespace std;

//long long dp[50][50][2501];

int main() {
  int n , a ; cin>>n>>a;
  vector<int>v(n);
  int s = 0;
  for(int& i : v){
    cin>>i;
    s += i;
  }
  //dp[0][0][0] = 1;
  vector<vector<long long>> dp(n + 1 , vector<long long>(2500 + 1, 0));
  dp[0][0] = 1;
  for(int i = 0 ; i < n; ++i){
    vector<vector<long long>> new_dp(n + 1 , vector<long long>(2500 + 1, 0));
    for(int j = 0 ; j < n; ++j){
      for(int k = 0 ;k <= 2500; ++k){
        if(dp[j][k]){
          new_dp[j + 1][k + v[i]] += dp[j][k];
          new_dp[j][k] += dp[j][k];
          // dp[i + 1][j + 1][k + v[i]] += dp[i][j][k];
          // dp[i + 1][j][k] += dp[i][j][k];
        }
      }
    }
    swap(dp , new_dp);
  }
  long long ans = 0;
  for(int i = 1; i <= n; ++i){
    ans += dp[i][i * a];
  }
  cout<<ans<<"\n";
}

Measured memory_bytes: 2316
#include<stdio.h>

int main(){
  int n,m,i,j,k,p;

  scanf("%d",&n);

  int A[n+1][n+1];

  for(i = 1;i <= n;i++){
    for(j = 1;j <= n;j++) A[i][j] = 0;
  }
  
  for(i = 1;i <= n;i++){
    scanf("%d",&m);
    scanf("%d",&p);
    for(j = 0;j < p;j++){
      scanf("%d",&k);
      A[m][k] = 1;
    }
  }

  for(i = 1;i <= n;i++){
    for(j = 1;j <= n;j++){
      printf("%d",A[i][j]);
      if(j != n) printf(" ");
    }
    printf("\n");
  }
  return 0;
}



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

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define REP2(i,n) for(int i=0;i<(int)(n);i++)
#define REP3(i,m,n) for(int i=m;i<(int)(n);i++)
#define REP4(i,m,n,s) for(int i=m;(s>0 and i<(int)(n)) or (s<0 and i>(int)(n));i+=s)
#define REP(...) GET_MACRO(__VA_ARGS__, REP4, REP3, REP2)(__VA_ARGS__)
#define REPIT(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define PIS(x) printf("%d ",x)
#define PN() putchar('\n')
#define MP make_pair
#define PB push_back
#define EB emplace_back

typedef pair<int,int> PII;
typedef long long LL;
typedef unsigned long long ULL;

void RI() {}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
void print() {putchar('\n');}
template<typename T, typename... U>
void print(T head, U... tail) {
    cout << head << " ";
    print(tail...);
}

const int MOD = 1000000007;
#define MAX_N 100005
int n, d1n, cut = -1, black = 0;
vector<int> G[MAX_N];
bool visited[MAX_N];

bool dfs(int v, int depth) {
    if(visited[v]) {
        return false;
    }
    visited[v] = true;
    if(v == n) {
        d1n = depth;
        return true;
    }

    REPIT(ii, G[v]) {
        bool ret = dfs(*ii, depth + 1);
        if(ret) {
            if(depth == d1n / 2) {
                cut = *ii;
            }
            return true;
        }
    }
    return false;
}

void dfs2(int v) {
    if(visited[v] or v == cut) {
        return;
    }
    visited[v] = true;
    black += 1;
    //print("black", v);
    REPIT(ii, G[v]) {
        dfs2(*ii);
    }
}

int main()
{
    RI(n);
    REP(i, n-1) {
        int a, b;
        RI(a, b);
        G[a].PB(b);
        G[b].PB(a);
    }
    dfs(1, 0);
    //print(d1n, cut);
    memset(visited, false, sizeof(visited));
    dfs2(1);
    //print(black);
    if(black > n/2) {
        printf("Fennec\n");
    } else {
        printf("Snuke\n");
    }
    return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b; cin >> a >> b;
  int ans;

  if(b==1){
    cout << "0" << endl;return 0;
  }
  int test=a;
  ans = 1;
  while(test<b){
    test--;
    test+=a;
    ans++;
  }
  
  cout << ans << endl;
  
  return 0;
}


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

int main(){
    int a,b,m; cin >> a >> b >> m;
    vector<int> A(a); vector<int> B(b);
    int mina = 1000000,minb = 1000000;
    for(int i=0;i<a;i++){
        cin >> A[i];
        mina = min(mina,A[i]);
    }
    for(int i=0;i<b;i++){
        cin >> B[i];
        minb = min(minb,B[i]);
    }

    int ans = mina + minb;
    for(int i=0;i<m;i++){
        int x,y,c;
        cin >> x >> y >> c;
        int sum;
        sum = A[x-1] + B[y-1] - c;
        ans = min(ans,sum);
    }

    cout << ans << endl;
}



Measured memory_bytes: 1024
import java.util.*;
import java.util.Queue;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int w = sc.nextInt();
            int h = sc.nextInt();
            if(w==0 && h==0) break;
            int s_wall[][] = new int[h][w-1];
            int v_wall[][] = new int[h-1][w];
            for(int i = 0; i<h; i++){
                for(int j = 0; j<w-1; j++){
                    s_wall[i][j] = sc.nextInt();
                }
                for(int j = 0; j<w; j++){
                    if(i!=h-1) v_wall[i][j] = sc.nextInt();
                }
            }
            Queue <ArrayList<Integer>> q = new ArrayDeque <ArrayList<Integer>> ();
            int dist[][] = new int[h][w];
            //-1
            for(int i = 0; i<h; i++){
                for(int j = 0; j<w; j++){
                    dist[i][j] = -1;
                }
            }
            //DFS
            Boolean ok = false;
            dist[0][0] = 0;
            q.add(new ArrayList<Integer>(Arrays.asList(0,0)));
            while(!(q.isEmpty())){
                ArrayList<Integer> v = q.poll();
                int v1 = v.get(0);
                int v2 = v.get(1);
                if(v1 == h-1 && v2 == w-1){
                    ok = true;
                    break;
                }
                int d = dist[v1][v2];
                if(v2 < w-1){
                    if(s_wall[v1][v2] == 0){
                        if(dist[v1][v2+1] == -1){
                            q.add(new ArrayList<Integer>(Arrays.asList(v1,v2+1)));
                            dist[v1][v2+1] = d+1;
                        }
                    }
                }
                if(v2>0){
                    if(s_wall[v1][v2-1]==0){
                        if(dist[v1][v2-1] == -1){
                            q.add(new ArrayList<Integer>(Arrays.asList(v1,v2-1)));
                            dist[v1][v2-1] = d+1;
                        }
                    }
                }
                if(v1>0){
                    if(v_wall[v1-1][v2] == 0){
                        if(dist[v1-1][v2] == -1){
                            q.add(new ArrayList<Integer>(Arrays.asList(v1-1,v2)));
                            dist[v1-1][v2] = d+1;
                        }
                    }
                }
                if(v1 < h-1){
                    if(v_wall[v1][v2]==0){
                        if(dist[v1+1][v2]==-1){
                            q.add(new ArrayList<Integer>(Arrays.asList(v1+1,v2)));
                            dist[v1+1][v2] = d+1;
                        }
                    }
                }
            }
            if(ok)System.out.println(dist[h-1][w-1]+1);
            else System.out.println(0);
        }
        sc.close();
    }
}


Measured memory_bytes: 69808
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

from collections import deque

def main():
	n,m=MI()

	G=[[] for _ in range(n+1)]

	for _ in range(m):
		a,b=MI()
		G[a].append(b)
		G[b].append(a)

	ans=[0]*(n+1)

	Q=deque([1])
	sumi=set()

	while Q:
		now=Q.popleft()

		for next in G[now]:
			if next in sumi:
				continue
			else:
				Q.append(next)
				ans[next]=now
				sumi.add(next)

	print("Yes")

	print(*ans[2:],sep="\n")






































if __name__ == "__main__":
	main()


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

using namespace std;

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

    int da=0,db=0,dc=0;
    for (int i=0;i<n;++i){
        int a,b,c;
        cin >> a >> b >> c;
        int na=max(db,dc)+a;
        int nb=max(da,dc)+b;
        int nc=max(da,db)+c;
        da=na,db=nb,dc=nc;
    }
    cout << max(da,max(db,dc));
}

Measured memory_bytes: 3160
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

static long gcd(long a, long b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

long long int facctorialMethod(int k){//階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

long long int tousasum(long long int n){//等差数列
    return n*(n+1)/2;
}

unsigned GetDigit(unsigned num){//桁数
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

bool IsPrime(int num)//素数判定
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

map< long long int, long long int > prime_factor(long long int n) {//素因数分解
    map< long long int, long long int > ret;
    for(long long int i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}



int main() {

    long long int N,M;
    cin >> N >> M;

       if(N==1){

             if(M==1){
                 cout << 1 << endl;
             }else{
                 cout << M-2 <<endl;
             }

       }else{

           if(M==1){
               cout << N-2 << endl;
           }else{
               cout << (M-2)*(N-2) << endl;
           }


   }
}


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

int main(int argc, char const *argv[])
{
	ll x; cin >> x;
	ll ans = 1;
	for (int i = 1; i <= x; ++i) {
		for (int j = 2; j <= x; ++j) {
			if ((ll)pow(i, j) <= x) ans = max(ans, (ll)pow(i, j));
			else break;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
int main() {
    int x,y; cin>>x>>y;
    int c,t;
    //c+t=x,2c+4t=y -> c=(4x-y)/2,t=(y-2x)/2
    if((4*x-y)%2==0&&(y-2*x)%2==0&&(4*x-y)>=0&&(y-2*x)>=0)
    printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 3600
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> num;
    UnionFind(int N) : par(N), rank(N), num(N) {
        for(int i = 0; i < N; i++) {
            par[i] = i;
            rank[i] = 0;
            num[i] = 1;
        }
    }
    
    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        num[x] += num[y];
        num[y] = 0;
        return true;
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
};

struct edge {
    int s, t, weight;
};

bool comp_edge(edge &a, edge &b) {
    return a.weight < b.weight;
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int V, E; cin >> V >> E;
    
    vector<edge> es(E);
    for (int i = 0; i < E; i++) {
        int s, t, w; cin >> s >> t >> w;
        es[i] = {s, t, w};
    }
    
    sort(es.begin(), es.end(), comp_edge);
    
    int ans = 0;
    UnionFind tree(V);
    for (int i = 0; i < E; i++) {
        int s = es[i].s, t = es[i].t, w = es[i].weight;
        if (tree.same(s, t)) continue;
        tree.unite(s, t);
        ans += w;
    }
    
    cout << ans << endl;
    
    return 0;
}



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

using namespace std;

#define ll long long int

ll fact[(int)2e5 + 2];

const ll MOD = 1e9 + 7;

void generate() {

	fact[0] = 1; fact[1] = 1;

	for(ll i = 2; i <= 2e5 + 1; i++)
		fact[i] = fact[i-1]*i % MOD;
}

ll fastpow(ll n, ll power) {

	if(!power)return 1;

	if(power % 2) return n*fastpow(n,power-1) % MOD;

	ll x = fastpow(n,power/2) % MOD;

	return (x*x) % MOD;
}

ll combine(ll a, ll b) {

	if(a < 0 || b < 0)return 0;
	if(a < b)return 0;

	return (fact[a]*fastpow(fact[b],MOD-2) % MOD)*fastpow(fact[a-b],MOD-2) % MOD;
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0); generate();

	ll h,w,a,b; cin >> h >> w >> a >> b;

	ll ans = 0;

	for(ll i = b; i < w; i++) {

		ll goToBorder = combine(i+h-a-1,i);
		ll goToFinish = combine(a-1+(w-i-1),a-1);

		ans += (goToBorder*goToFinish) % MOD;
		ans %= MOD;
	}

	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 1920
#include <cstdio>
int max(int a,int b)
{
	if (a>b)
		return a;
	return b;
}
int main(void)
{
	int a[4],upbd,sum;
	scanf("%d%d%d",a,a+1,a+2);
	upbd=max(max(a[0],a[1]),a[2])*3;
	sum=a[0]+a[1]+a[2];
	if((upbd-sum)%2==0)
		printf("%d\n",(upbd-sum)/2);
	else
	{
		upbd+=3;
		printf("%d\n",(upbd-sum)/2);
	}
	return 0;
}

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

#include<cstdio>
// #include<cstring>

int main(){
  int count[26]={};
  char ch;

  while(scanf("%c", &ch)!=EOF){
    if (islower(ch)) count[ch-'a']++;
    if (isupper(ch)) count[ch-'A']++;
  }

  for (int i=0; i<26; i++){
    printf("%c : %d\n", i+'a', count[i]);
  }

  return 0;
}

Measured memory_bytes: 3164
import java.util.Scanner;

/**
 * @author kep
 * @date 2019-10-17
 */
public class Main {

    private static  int[] parent  = new int[200005];
    private static  int[] count = new int[200005];
    private static int findRoot(int x){
        if(parent[x] == 0){
            return x;
        }
        parent[x] = findRoot(parent[x]);
        return parent[x];
    }

    private static void add(int a,int b){
        if(a < b){
            int tmp = a;
            a = b;
            b = tmp;
        }
        if(a == b){
            return;
        }
        parent[a] = b;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        for(int i = 0;i<m;i++){
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int root_a = findRoot(a);
            int root_b = findRoot(b);
            add(root_a,root_b);
        }
        int ans = 0;
        for(int i = 1;i<=n;i++){
            int root_i = findRoot(i);
            count[root_i]++;
            ans = Math.max(count[root_i],ans);
        }
        System.out.println(ans);

    }



}


Measured memory_bytes: 61940
n = gets.chomp.split("")
check = 0
if n[0] == "k"
  if n[1] == "e" && n[2] == "y" && n[3] == "e" && n[4] == "n" && n[5] == "c" && n[6] == "e"
    puts "YES"
    exit
  end
  if n[1] == "e" && n[2] == "y" && n[3] == "e" && n[4] == "n" && n[5] == "c" && n[-1] == "e"
    puts "YES"
    exit
  end
  if n[1] == "e" && n[2] == "y" && n[3] == "e" && n[4] == "n" && n[-2] == "c" && n[-1] == "e"
    puts "YES"
    exit
  end
  if n[1] == "e" && n[2] == "y" && n[3] == "e" && n[-3] == "n" && n[-2] == "c" && n[-1] == "e"
    puts "YES"
    exit
  end
  if n[1] == "e" && n[2] == "y" && n[-4] == "e" && n[-3] == "n" && n[-2] == "c" && n[-1] == "e"
    puts "YES"
    exit
  end
  if n[1] == "e" && n[-5] == "y" && n[-4] == "e" && n[-3] == "n" && n[-2] == "c" && n[-1] == "e"
    puts "YES"
    exit
  end
  if n[-6] == "e" && n[-5] == "y" && n[-4] == "e" && n[-3] == "n" && n[-2] == "c" && n[-1] == "e"
    puts "YES"
    exit
  end
else
  if n[-7] == "k" && n[-6] == "e" && n[-5] == "y" && n[-4] == "e" && n[-3] == "n" && n[-2] == "c" && n[-1] == "e"
    puts "YES"
    exit
  end
end
puts "NO"


Measured memory_bytes: 1788
#include <iostream>
#include <map>
#include <queue>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdlib>
#define all(a) a.begin(),a.end()
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=(int)k;i<(int)n;i++)
using namespace std;
typedef pair<int,int> pii;

int main()
{
	int n;
	cin>>n;
	FORI(j,1,n+1)
	{
		int m[20][20]={};
		
		FORI(i,0+4,8+4)
		{
			string s;
			cin>>s;
			FORI(l,0+4,8+4)
			{
				m[i][l]=s[l-4]=='1';
			}
		}
		
		
		
		
		
		int sx,sy;
		cin>>sx>>sy;
		sx+=3;sy+=3;
		m[sy][sx]=false;
		queue<pii> que;
		que.push(pii(sy,sx));
		while(!que.empty())
		{
			int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
			pii now=que.front();que.pop();
			
			FOR(i,4)
			{
				FORI(l,1,4)
				{
					int x,y;
					y=now.first+dy[i]*l;
					x=now.second+dx[i]*l;
					if(m[y][x])
					{
						m[y][x]=false;
						pii next(y,x);
						que.push(next);
					}
				}
			}
			
		}
		cout<<"Data "<<j<<":"<<endl;
		FORI(i,0+4,8+4)
		{
			FORI(l,0+4,8+4)
			{
				cout<<m[i][l];
			}
			cout<<endl;
		}
	}
	
}

Measured memory_bytes: 1212
#!/usr/bin/env python3
import sys
INF = float('inf')

def solve(N: int, A: int, B: int, C: int, l: "List[int]"):
    target = [A, B, C]
    def calc(group):
        ret = 0
        for i in range(3):
            elms = group[i]
            if len(elms) < 1:
                return INF
            ret += (len(elms) - 1) * 10
            total = 0
            for e in elms:
                total += l[e]
            ret += abs(total - target[i])
        return ret

    def rec(idx, group):
        if idx >= N:
            return calc(group)
        ret = INF
        for i in range(4):
            group[i].append(idx)
            ret = min(ret, rec(idx + 1, group))
            group[i].remove(idx)
        return ret

    ret = rec(0, [[] for i in range(4)])
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    l = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A, B, C, l)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>

#define abs(x) ((x)<0?-(x):(x))
int main()
{
	int i,n,y;
	double D1,D2,D3,D4;
	D1=D2=D3=D4=0.0;
	
	scanf("%d",&n);
	
	int x[n];
	int sa;
	int sum=0;
	int sum2=0;
	
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	for(i=0;i<n;i++){
		scanf("%d",&y);
		sa=abs(x[i]-y);
		D1 += sa;
		D2 += sa*sa;
		D3 += sa*sa*sa;
		if(D4<sa)
			D4=sa;
	}
	
	D2 = sqrt(D2);
	
	D3=pow(D3,1.0/3.0);
	
	printf("%lf\n",D1);
	printf("%lf\n",D2);
	printf("%lf\n",D3);
	printf("%lf\n",D4);
	
	return 0;
}


Measured memory_bytes: 2092
def dfs(grid, start, wall, h, w):
    stack = []
    push, pop = stack.append, stack.pop
    push(start)
    grid[start[0]][start[1]] = wall
    dxy = [(0,1), (1,0)]

    while stack:
        h, w = pop()
        cnt = 0
        for dx,dy in dxy:
            x, y = w+dx, h+dy
            if grid[y][x] == wall:
                continue
            push((y,x))
            grid[y][x] = wall
            cnt += 1
        if cnt > 1:
            return False
    for i in range(1, h+1):
        for j in range(1, w+1):
            if grid[i][j] != wall:
                return False
    return True


def resolve():
    h, w = map(int, input().split())
    grid = {}
    wall = '.'
    edges = [wall] * (w+2)
    grid = [edges]
    for i in range(h):
        s = input()
        grid.append([wall] + list(s) + [wall])
    grid.append(edges)
    print("Possible" if dfs(grid, (1, 1), wall, h, w) else "Impossible")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9168
n, yen = [int(s) for s in input().split()]
yen //= 1000
for x in range(n + 1):
    p_x = 10 * x
    if p_x > yen:
        break
    for y in range(n - x + 1):
        p_x_y = p_x + 5 * y
        if p_x_y > yen:
            break
        z = n - x - y
        p_x_y_z = p_x_y + z
        if p_x_y_z == yen:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 3064
import sys

class Board():
    
    def __init__(self):
        self.B = [0 for _ in range(12 * 12)]
        
        for i in range(0, 12):
            self.B[i] = -1
        for i in range(12, 12 * 12, 12):
            self.B[i] = -1
        for i in range(11, 11 * 12, 12):
            self.B[i] = -1
        for i in range(12 * 11, 12 * 12):
            self.B[i] = -1
    
    def print(self):
        cnt = 0
        for b in self.B:
            if b == 0:
                cnt += 1
        
        print(cnt)
        print(max(self.B))
    
    def inc_if_non_wall(self, x, y):
        idx = (y + 1) * 12 + (x + 1)
        
        if self.B[idx] != -1:
            self.B[idx] += 1
    
    def drop_s(self, x, y):
        self.inc_if_non_wall(x, y)
        self.inc_if_non_wall(x, y - 1)
        self.inc_if_non_wall(x - 1, y)
        self.inc_if_non_wall(x + 1, y)
        self.inc_if_non_wall(x, y + 1)
    
    def drop_m(self, x, y):
        self.drop_s(x, y)
        self.inc_if_non_wall(x - 1, y - 1)
        self.inc_if_non_wall(x + 1, y - 1)
        self.inc_if_non_wall(x - 1, y + 1)
        self.inc_if_non_wall(x + 1, y + 1)
    
    def drop_l(self, x, y):
        self.drop_m(x, y)
        
        idx = (y + 1) * 12 + (x + 1)
        if 12 * 3 < idx:
            self.inc_if_non_wall(x, y - 2)
        if idx < 12 * 9:
            self.inc_if_non_wall(x, y + 2)
        
        self.inc_if_non_wall(x - 2, y)
        self.inc_if_non_wall(x + 2, y)
    

if __name__ == "__main__":
    B = Board()
    for l in sys.stdin:
        x, y, s = map(int, l.split(','))
        if s == 1:
            B.drop_s(x, y)
        elif s == 2:
            B.drop_m(x, y)
        elif s == 3:
            B.drop_l(x, y)
    
    B.print()



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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back


int main(void){
  string s;
  cin >> s;
  for(int i= 0; i < s.size(); ++i){
    cout << s[i];
    if(i == 3)cout << ' ';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  char s[11];
  cin>>s;
  if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return(0);
}

Measured memory_bytes: 256
def chk(mat,exp,y,x)
  if mat[y][x]==1
    exp.push([x,y])
    mat[y][x]=0
  end
  return mat,exp
end
ds,cnt=gets.to_i,0
ds.times do
  mat,=[],gets
  8.times{mat << gets.chomp.split("").map(&:to_i)}
  exp=[[gets.to_i-1,gets.to_i-1]]
  while !exp.empty?
    e=exp.pop
    mat[e[1]][e[0]]=0
    3.times do |i|
      mat,exp=chk(mat,exp,[e[1]-3+i,0].max,e[0])
      mat,exp=chk(mat,exp,e[1],[e[0]-3+i,0].max)
      mat,exp=chk(mat,exp,[e[1]+1+i,7].min,e[0])
      mat,exp=chk(mat,exp,e[1],[e[0]+1+i,7].min)
    end
  end
  puts "Data #{cnt+=1}:"
  mat.each{|i|
    puts i.join
  }
end

Measured memory_bytes: 8784