akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

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

	string s;
	cin >> s;

	auto fc = [&](string q) {
		if (q.size() > s.size())return false;
		if (s.substr(s.size() - q.size(), q.size()) == q) {
			rep(i, q.size()) s.pop_back(); return true;
		}
		return false;
	};

	while (s.size()) {
		if (fc("dream"))continue;
		if (fc("dreamer"))continue;
		if (fc("erase"))continue;
		if (fc("eraser"))continue;
		cout << "NO" << endl; return 0;
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int n,p[1<<15],a[1<<15],b[1<<15];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int c;cin>>c;p[c]=i+1;
	}
	for(int i=0;i++<n;)cout<<(n+1)*i<<(i==n?"\n":" ");
	for(int i=0;i++<n;)cout<<(n+1)*(n-i)+p[i]<<(i==n?"\n":" ");
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
int w, h, xs, ys, xg, yg;
int mp[110][110];

bool dfs(int x, int y, int f) {
  if (x >= w || y >= h || x < 0 || y < 0 || mp[y][x] != f)
    return false;
  if (y == yg && x == xg && mp[y][x] == f)
    return true;
  mp[y][x] = 9;
  return dfs(x + 1, y, f) || dfs(x - 1, y, f) || dfs(x, y + 1, f) ||
         dfs(x, y - 1, f);
}

int main() {
  while (cin >> w >> h) {
    if (w == 0 && h == 0)
      break;
    int n;
    cin >> xs >> ys >> xg >> yg >> n;
    xs--;
    ys--;
    xg--;
    yg--;
    int c, d, x, y;
    rep(i, n) {
      cin >> c >> d >> x >> y;
      if (d == 0) {
        for (int i = y - 1; i < y + 1; i++)
          for (int j = x - 1; j < x + 3; j++) {
            mp[i][j] = c;
          }
      } else {
        for (int i = y - 1; i < y + 3; i++)
          for (int j = x - 1; j < x + 1; j++) {
            mp[i][j] = c;
          }
      }
    }
    cout << (dfs(xs, ys, mp[ys][xs]) ? "OK" : "NG") << endl;
  }
  return 0;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
                       ///****   Hasebul Hassan Chowdhury ***////
#define ms(a,v)        memset(a,v,sizeof a)
#define lll            long long
#define FOR(i,a,b)     for(int i=a;i<=b;i++)
#define fast           ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Read           freopen("input.txt", "r", stdin)
#define Write          freopen("output.txt", "w", stdout)
#define INF            1e18


void solve()
{
   int n;
   cin>>n;
   long long total=0;
   for(int i=1;i<=(1e7);i++)
   {
      total=(total*10+7)%n;
      if(total==0) { cout<<i<<endl; return; }
   }
   cout<<"-1"<<endl;
}

int main()
{
    fast
    #ifndef ONLINE_JUDGE
    //Read;
    //Write;
    #endif
    //sieve();
    //int cnt=1;
    //int t; scanf("%d",&t); while(t--) solve();
    solve();
}


Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DEBUG_OUTPUT_ENABLED 1
	#define DBG(X) dout << #X << "=" << (X) << '\n';
	#define SAY(X) dout << (X) << '\n';
#else
	#define DEBUG_OUTPUT_ENABLED 0
	#define DBG(X) 42;
	#define SAY(X) 42;
#endif

#define dout   debug::instance

using namespace std;

template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
namespace debug {
	struct DebugStream {
		private:
			bool is_first;
		public:
			DebugStream(bool _is_first): is_first(_is_first) {}
			template<typename T> DebugStream operator<<(const T& value) const {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				cout << value;
				return DebugStream(false);
			};

			template<typename T> DebugStream printArray(T* l, T* r) {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				while(l != r) {
					cout << (*l);
					++l;
					if(l == r) {
						cout << '\n';
					} else {
						cout << ' ';
					}
				}
				return DebugStream(false);
			}
	};
	DebugStream instance(true);
};

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	ll a = fetch<ll>();
	ll b = fetch<ll>();
	ll c = fetch<ll>();
	swap(a, b);
	swap(a, c);
	cout << a << ' ' << b << ' ' << c << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            var AB = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var gcd = GCD(AB[0], AB[1]);

            var isPrime = new bool[(int)Math.Sqrt(gcd) + 1];
            for (int i = 2; i < isPrime.Length; i++) isPrime[i] = true;
            isPrime[0] = false; isPrime[1] = false;
            for (int i = 2; i < isPrime.Length; i++)
            {
                if (isPrime[i]) continue;
                for (int j = 2; i * j < isPrime.Length; j++) isPrime[i * j] = false;
            }

            var primefactor = new List<int>();
            for (int i = 2; i <= Math.Sqrt(gcd); i++)
            {
                if (!isPrime[i]) continue;
                if (gcd % i != 0) continue;
                primefactor.Add(i);
                while (gcd % i == 0) gcd /= i;
            }
            if (gcd != 1) primefactor.Add((int)gcd);
            Console.WriteLine(primefactor.Count + 1);
        }

        static long GCD(long A, long B)
        {
            if (B > A) return GCD(B, A);
            if (A % B == 0)
            {
                return B;
            }
            else
            {
                return GCD(B, A % B);
            }
        }
    }
}


Measured memory_bytes: 13260
#include <cstdio>

using namespace std;

int main()
{
    int times = 4;
    while( times > 0 )
    {
        int t,num = 0;
        scanf( "%d %d\n", &t, &num );
        if( t == 1 )
        {
            printf( "%d\n", num * 6000 );
        }
        if( t == 2 )
        {
            printf( "%d\n", num * 4000 );
        }
        if( t == 3 )
        {
            printf( "%d\n", num * 3000 );
        }
        if( t == 4 )
        {
            printf( "%d\n", num * 2000 );
        }
        times--;
    }
}


Measured memory_bytes: 2712
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<string>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
using namespace std;
typedef long long LL;
   
inline int read() {
	int x=0,f=1; char ch=getchar();
	while (!(ch>='0'&&ch<='9')) {if (ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') {x=x*10+(ch-'0'); ch=getchar();}
	return x*f;
}

const int N = 500010;

int n,q,D,d[N],A[N],B[N],ans[N];//What we ONLY need to judge is just a bounder -> B[i] the minimum dis if we don't want to reach the goal
   
int main() {
	
	#ifndef ONLINE_JUDGE
	//	freopen("data.in","r",stdin);
	//	freopen("data.out","w",stdout);
	#endif
	
	n=read(),D=read(); A[0]=D;
	rep(i,1,n) d[i]=read();
	int dis=D;
	rep(i,1,n) A[i]=dis=min(dis,abs(dis-d[i]));
	B[n+1]=1;
	per(i,n,1) {
		if (B[i+1]<=d[i]/2) B[i]=B[i+1];
		else B[i]=B[i+1]+d[i];
		if (A[i-1]>=B[i+1]) ans[i]=1;
		else ans[i]=0;
	}
	int Q=read();
	while (Q--) {
		int x=read();
		if (ans[x]) puts("YES"); else puts("NO");
	}
	
	return 0;
}

Measured memory_bytes: 9856
import sys
def f(a,b,c):
  if b==1:return 1
  x=sum([f(a-e,b-1,c-9)for e in range(max(a-c,0),min(a+1,10))])
  return x
for n in map(int,sys.stdin):print f(n,4,3*9)

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

ll dp[2][102];

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

	ll n;
  cin>>n;
  vll a(n);
  REP(i,n)cin>>a[i];
  
  ll all=1;
  ll odd=1;
  REP(i,n){
    all*=3;
    if(a[i]%2==0)
      odd*=2;
  }
  
  ll ans=all-odd;
  cout<<ans<<endl;
    


}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, x,sum=0;
  cin >> A >> B;
  x=A;
  while(x <= B){
    int x1, x2, x3, x4;
	x1 = x % 10;
    x2 = (x/10) % 10;
    x3 = (x/1000) % 10;
    x4 = (x/10000) % 10;
    
	if(x1 == x4 && x2 == x3){
	  sum++;
    }
    
	x++;
  } 
  
  cout << sum << endl;    
}




Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))

increase_flag=False
decrease_flag=False
answer=0
if n!=1:
  for i in range(len(a)-1):
    if increase_flag==False and decrease_flag==False:
      #旗が下がっているときに、二値を見ることで単調増加か、単調減少を見極める。

      if a[i+1]>a[i]:
        increase_flag=True
        answer+=1
      elif a[i+1]<a[i]:
        decrease_flag=True
        answer+=1
      
    else:
      #単調増加と単調減少から変わる時旗を下げるだけです。次の値が単調増加になる可能性があるから。
      if decrease_flag==True and a[i+1]>a[i]:
        decrease_flag=False
      elif increase_flag==True and a[i+1]<a[i]:
        increase_flag=False
  
  #index=-1とindex=-2より、旗を下げた場合、残りの値が一つのグループとなるため+=1。
  if increase_flag==False and decrease_flag==False:
    if a[-1]>a[-2]:
      increase_flag=True
      answer+=1
    elif a[-1]<a[-2]:
      decrease_flag=True
      answer+=1
  print(answer)
else:
  print(1)
    

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

int main() {
	string s,t;
	long a,b;
	cin>>s>>t;
	cin>>a>>b;
	string u;
	cin>>u;
	if(s==u) --a;
	else --b;
	cout<<a<<" "<<b<<endl;
	return 0;
}

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

int help(int n,int mval){
    int ans = 0 ;
    int mt = 1 ;
    while(n>0){
        ans+=mt*mval;
        mt*=10;
        n--;
    }
  return ans ;
}

int main()
{
    int a,b ;
    cin >> a >> b ;
  
    int aa = help(b,a);
    int bb = help(a,b);

    string aaa = to_string(aa) ;
    string bbb = to_string(bb) ;

   if(aaa<bbb){
         cout << aaa << endl ;
   }else{
              cout << bbb << endl ;
   }

     return 0;       
}


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

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	vector<int> a(n);
	rep(i,n) {
		cin >> p[i];
		a[p[i]-1] = i;
	}
	int renzokuStart = 0;
	int renzokuTimes = 1;
	int maxRenzokuStart = 0;
	int maxRenzokuTimes = -1;
	for(int i=1; i<n; i++) {
		if(a[i-1] < a[i]) {
			renzokuTimes++;
		}
		if(a[i-1] > a[i]) {
			if(renzokuTimes > maxRenzokuTimes) {
				maxRenzokuStart = renzokuStart;
				maxRenzokuTimes = renzokuTimes;
			}
			renzokuStart = i;
			renzokuTimes = 1;
		}
	}
	chmax(maxRenzokuTimes, renzokuTimes);
	cout << n - maxRenzokuTimes << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;
    vector<int> A(N);

    for (int i = 0; i < N; ++i)
        cin >> A[i];
    sort(A.begin(), A.end());

    int ans = N;
    vector<bool> isng(1000005);
    for (int i = 0; i < N; ++i) {
        if (isng[A[i]]) {
            ans--;
            continue;
        }
        for (int j = 1; j * A[i] <= 1000000; ++j)
            isng[j * A[i]] = true;
        if (i + 1 < N && A[i] == A[i + 1])
            ans--;
    }

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


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
int A[MAX_N];

int main2() {
  int N = nextInt();
  int M = nextInt();

  int odd = 0;
  REP(i, M) { 
    A[i] = nextInt();
    if (A[i] % 2 == 1) ++odd;
  }

  vector<int> ans;
  if (M == 1) {
    if (A[0] <= 2) { ans.push_back(A[0]); }
    else {
      ans.push_back(1);
      ans.push_back(A[0]-1);
    }
  } else if (odd <= 2) {
    for (int i = 0; i < M; i++) {
      if (A[i] % 2 == 1) {
        if (i > 0) swap(A[i], A[0]);
        break;
      }
    }
    for (int i = M - 1; i >= 0; i--) {
      if (A[i] % 2 == 1) {
        if (i != M-1) swap(A[i], A[M-1]);
        break;
      }
    }

    for (int i = 0; i < M; i++) {
      if (i == 0) ans.push_back(A[i]+1);
      else if (i == M-1) ans.push_back(A[i]-1);
      else ans.push_back(A[i]);
    }
  } else {
      // cout << "Impossible" << endl;
  }

  vector<int> tmp = ans;
  ans.clear();
  REP(i, tmp.size()) if (tmp[i] > 0) ans.push_back(tmp[i]);


  if (ans.size() == 0) {
    cout << "Impossible" << endl;
  } else {
    REP(i, M) {
      if (i > 0) cout << " ";
      cout << A[i];
    }
    cout << endl;

    cout << ans.size() << endl;
    REP(i, ans.size()) {
      if (i > 0) cout << " ";
      cout << ans[i];
    }
    cout << endl;

  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  bool h = false;//heisei? tbd?
  int year = stoi(s.substr(0,4));
  int month = stoi(s.substr(5,2));
  int day = stoi(s.substr(8,2));
  //cout << year << "," << month << "," << day << endl;

  if(year < 2019) h = true;
  else if(year > 2019)  h = false;
  else if(year == 2019 && month < 4) h = true;
  else if(year == 2019 && month > 4) h = false;
  else if((year == 2019 && month == 4) && day <= 30) h = true;
  else h = false; 


  if(h) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SMI(): return input().split()
def SLI(): return list(input())

def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')

# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    S = SLI()
    l = len(S)
    MOD = 1000000007
    dp = [[0]*13 for _ in range(l+1)]
    dp[0][0] = 1
    mul = 1
    S = S[::-1]
    for i in range(l):
        # s = S[-(i + 1)]
        s = S[i]
        if s == '?':
            for q in range(10):
                for j in range(13):
                    dp[i+1][(q*mul + j)%13] += dp[i][j]
                    dp[i+1][(q*mul + j)%13] %= MOD
        else:
            for j in range(13):
                k = int(s)
                dp[i+1][(k*mul + j)%13] += dp[i][j]
                dp[i+1][(k*mul + j)%13] %= MOD

        mul = mul * 10 % 13
    # print(dp[-1])
    print(dp[-1][5] % MOD)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 66040
<?php

$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
sort($A);

$a = (int) ceil(($A[1] - $A[0]) / 2);
$cnt = $a;
$A[0] += $a * 2;

if ($A[0] != $A[1]) {
    $cnt++;
    $A[1]++;
    $A[2]++;
}

$cnt += $A[2] - $A[1];

echo $cnt, PHP_EOL;


Measured memory_bytes: 16260
from collections import deque
h,w = (int(i) for i in input().split())

M = [input() for i in range(h)]
N = [[False]*w for i in range(h)]

cnt = 0
for i in range(h):
    for j in range(w):
        if M[i][j] == "#":
            cnt += 1


que = deque([[0,0,1]])
while que:
    x,y,c = que.popleft()

    if M[y][x] == "#":
        continue
    elif N[y][x]:
        continue
    elif x == w-1 and y == h-1:
        
        print(h*w-(c+cnt))
        quit()

    else:
        N[y][x]=True
        A = [[x+1,y,c+1],[x-1,y,c+1],[x,y+1,c+1],[x,y-1,c+1]]
        for a in A:
            if 0<=a[0]<=w-1 and 0<=a[1]<=h-1:
                que.append(a)
                
print(-1)

Measured memory_bytes: 3316
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int n,k,q;
  cin>>n>>k>>q;
  vector<int> a(n);
  rep(i,0,n) a[i]=0;
  int hoge=0;
  rep(i,0,q){
    cin>>hoge;
    a[hoge-1]++;
  }
  rep(i,0,n){
    cout<<(k-(q-a[i])>0?"Yes":"No")<<endl;
  }
    
  

}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


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

const int maxn = 1e5 + 5;
int n;
int a[maxn];
int f[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),	cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i];
	memset(f, 0x3f, sizeof(f));
	f[0] = f[1] = 0, f[2] = abs(a[2] - a[1]);
	for(int i = 3; i <= n; ++i){
		f[i] = min(f[i], f[i-1] + abs(a[i] - a[i-1]));
		f[i] = min(f[i], f[i-2] + abs(a[i] - a[i-2]));
	}
	cout << f[n];
}

Measured memory_bytes: 4356
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
vi p;
vector<vi> s;
int n, m;
vb isLight;
int ans = 0;
bool isRight(){
    int c = 0;
    for(int i = 0; i < m; i++){
        int cnt = 0;
        for(int j = 0; j < s[i].size(); j++){
            if(isLight[s[i][j]]) cnt++;
        }
        if(cnt % 2 == p[i]) c++;
    }
    if(c == m) return true;
    return false;
}
void f(int idx){
    if(idx == n){
        if(isRight()) ans++;
        return;
    }
    isLight[idx] = true;
    f(idx+1);
    isLight[idx] = false;
    f(idx+1);
}
int main(){
    cin >> n >> m;
    isLight.resize(n);
    s.resize(m, vi());
    p.resize(m);
    for(int i = 0; i < m; i++){
        int k;
        cin >> k;
        vi a(k);
        for(int j = 0; j < k; j++) {
            cin >> a[j];
            a[j]--;
        }
        s[i] = a;
    }
    for(int i = 0; i < m; i++) cin >> p[i];
    f(0);
    cout << ans;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    -- k;

    vector<int> dp(w, 0);
    dp[0] = 1;
    for(int y=0; y<h; ++y){
        vector<int> nextDp(w, 0);
        for(int i=0; i<(1<<(w-1)); ++i){
            bitset<7> bs(i);
            bool ng = false;
            for(int j=0; j<w-2; ++j){
                if(bs[j] && bs[j+1])
                    ng = true;
            }
            if(ng)
                continue;

            for(int x=0; x<w; ++x){
                if(x > 0 && bs[x-1])
                    (nextDp[x-1] += dp[x]) %= MOD;
                else if(x < w - 1 && bs[x])
                    (nextDp[x+1] += dp[x]) %= MOD;
                else
                    (nextDp[x] += dp[x]) %= MOD;
            }
        }
        dp = move(nextDp);
    }
    cout << dp[k] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define N 100000

int main(void){ 
    int A[N],B[N],M[N],x[N],y[N],c[N];
    int i,j,a,b,m,ans;
    scanf("%d%d%d",&a,&b,&m);
    for(i=0; i<a; i++){
        scanf("%d",&A[i]);
    }
    for(i=0; i<b; i++){
        scanf("%d",&B[i]);
    }
    for(i=0; i<m; i++){
        scanf("%d%d%d",&x[i],&y[i],&c[i]);
    }

    ans = A[x[0]-1] + B[y[0]-1] - c[0];
    for(i=0; i<m; i++){
        if(A[x[i]-1] + B[y[i]-1] - c[i] < ans){
            ans = A[x[i]-1] + B[y[i]-1] - c[i];
        }
    }
    int mina,minb;
    mina = A[0];
    minb = B[0];
    for(i=0; i<a; i++){
        if (A[i] < mina){
            mina = A[i];
        }
    }  
    for(i=0; i<b; i++){
        if (B[i] < minb){
            minb = B[i];
        }
    }   
        if(mina + minb < ans) {
           ans = mina + minb;
        }
   
    printf("%d\n",ans);
    return 0;
    }
    


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if(m1 != m2)  cout << 1 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
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*b/gcd(a,b);}
const int INF=1e9;
const ll llINF=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  ll l,r;
  cin>>l>>r;
  if(r-l>=4038){
    cout<<0<<endl;
    return 0;
  }
  ll ans=llINF;
  for(ll i=l;i<r;i++){
    for(ll j=i+1;j<=r;j++){
      ll cnt=(i*j)%2019;
      mins(ans,cnt);
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main()
{
	vector<long long int>D(1000001 , 1);
	D[0] = 0;
	D[1] = 0;
	for(long long int i = 2; i <= sqrtl(1000001); i++)
	{
		if(D[i])
		{
			long long int j = 2;
			while(i*j < 1000001)
			{
				D[i*j] = 0;
				j++;
			}
		}
	}
	for(long long int i = 1; i < 1000001; i++)
	{
		D[i] += D[i - 1];
	}
	long long int n;
	while(cin >> n)cout << D[n] << endl;
	return 0;
}

Measured memory_bytes: 8980
{-# LANGUAGE OverloadedStrings, ViewPatterns #-}
import qualified Data.ByteString.Char8 as B
import Data.Maybe

main :: IO ()
main = B.getLine >>= main'
    where
        main' s = B.getLine >>= B.putStrLn . solve s

solve :: B.ByteString -> B.ByteString -> B.ByteString
solve s t
    | isNothing res = "UNRESTORABLE"
    | otherwise = recf s 0 $ fromJust res
    where
        res = checks t s

        recf xxs@(B.uncons -> Just (x, xs)) m n
            | m == n = t `B.append` recf (B.drop len xxs) (m + len) n
            | x == '?' = B.cons 'a' $ recf xs (m + 1) n
            | otherwise = B.cons x $ recf xs (m + 1) n

        recf _ _ _ = B.empty

        len = B.length t

check :: B.ByteString -> B.ByteString -> Bool
check (B.uncons -> Just (x, xs)) (B.uncons -> Just (y, ys))
    | y == '?' || x == y = check xs ys
    | otherwise = False
check _ _ = True

checks :: B.ByteString -> B.ByteString -> Maybe Int
checks t s = recf s 0
    where
        recf xxs@(B.uncons -> Just (_, xs)) n
            | tl > sl - n = Nothing
            | check t xxs = ef n $ recf xs (n + 1)
            | otherwise = recf xs (n + 1)
        recf _ _ = Nothing

        ef x (Just y) = return $ max x y
        ef x _ = return x

        tl = B.length t
        sl = B.length s


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
const long mod=1e9+7;

int main() {
  long K,A,B;
  cin >> K >> A >> B;
  if(A>=B-2)cout << K+1;
  else cout << (K-A+1)/2*(B-A)+(K-A+1)%2+A;
}






Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}

int main(){
    long h,w;
    long ans;
    long w_times;
    
    scanf("%ld %ld",&h,&w);
    
    w_times = w/2;
    long h_times = h/2;
    
    if(h == 1 || w == 1) {
        printf("1\n");
        return 0;
    }
    
    if(w % 2 == 0 && h % 2 == 0){
        printf("%ld\n",h*w/2);
//      printf("1\n");
        return 0;
    }else if(w % 2 == 0 && h % 2 == 1){
        printf("%ld\n",(w/2)*h);
//        printf("2\n");
    }else if(w % 2 == 1 && h % 2 == 0){ // h4 w5
        w_times++;
        ans = ((w_times*2)-1) * (h/2);
        printf("%ld\n",ans);
//        printf("3\n");
    }else{
        w_times++;
        ans = ((w_times*2)-1) * (h/2);
        ans += w_times;
        printf("%ld\n",ans);
//        printf("4\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>

int main() 
{
	char str[10];
	char ans[10];
	int i;
	for (i = 0;i < 3;i++)
	{
		scanf("%s", str);
		ans[i] = str[i];
	}
	ans[i] = '\0';
	printf("%s\n", ans);
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const ll MOD=1e9+7;
const int N=102, K=1e5+5;
ll f[N][K], n, k, A[N];
void upd(ll *f, int i, ll v){
	for(++i;i<K;i+=i&-i){f[i]+=v;if(f[i]>=MOD)f[i]-=MOD;}
}
ll sum(ll *f, int i){
	if(i<0)return 0;
	ll r=0; for(++i;i;i-=i&-i){r+=f[i];if(r>=MOD)r-=MOD;} return r;
}

int main(){FIN;
	cin >> n >> k;
	fore(x,0,n)cin>>A[x];
	upd(f[n],0,1);
	for(int x=n-1; x>=0; x--){
		fore(j,0,k+1){
			ll ans = sum(f[x+1],j)-sum(f[x+1],j-A[x]-1)+MOD;
			if(ans>=MOD)ans-=MOD;
			upd(f[x],j,ans);
		}
	}
	cout << (sum(f[0],k) - sum(f[0],k-1) + MOD)%MOD<< "\n";
}

Measured memory_bytes: 78464
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
typedef pair<int, int> pr;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
int fast_pow(int x, int y, int p);


void solve() {
    int n;cin>>n;
    int m;cin>>m;
    int sum=0;
    for(int i=0;i<m;i++){
        int x;cin>>x;
        sum+=x;
    }
    int ans=max(-1ll,n-sum);
    cout<<ans<<endl;
}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
//        cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}
int fast_pow(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

Measured memory_bytes: 3652
N,M = map(int,input().split())
s = []
ans = 0

for i in range(M):

    S = list(map(int,input().split()))
    del S[0]

    s.append(S)

p = list(map(int,input().split()))


for i in range(2 ** N):

    now = format( i , "b" )
    now = now.zfill(N)

    lis = [0] * M

    for j in range(M):

        for k in s[j]:

            if now[k-1] == "1":
                lis[j] += 1

    flag = True

    for j in range(M):

        if p[j] != ( lis[j] % 2 ):
            flag = False

    if flag:
        ans += 1

print (ans)


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



int main() {
ll A, B, C, X, Y;
cin >>A >> B >> C >> X >> Y;
ll ans = 1000000009;
for(int i = 0; i <= 500000000; i = i+2){
    ll a;
if(i/2 > X) a = 0;
else a = X - i/2; 
ll b;
if(i/2 > Y) b = 0;
else b = Y - i/2; 

ll sumkari = A*a + B*b + C*i;
ans = min(ans, sumkari);

}

cout << ans << endl;

}




Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <cassert>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

pair<int,int>  dp[1 << 18][2];

void solve()
{
    int n;
    scanf("%d", &n);
    vector<int> a(1 << n);
    map<int, vector<int> > cnt;
    int i;
    for (i = 0; i < (1 << n); i++) {
        scanf("%d", &a[i]);
        cnt[a[i]].push_back(i);
    }
    
    for (i = 0; i < (1 << n); i++) {
        dp[i][0] = dp[i][1] = make_pair(-INF, 0);
    }
    dp[0][0] = make_pair(a[0],0);
    for (i = 1; i < (1 << n); i++) {
        set<pair<int, int> > z;
        z.insert(make_pair(a[i], i));

        int j;
        for (j = 0; j < n; j++) {
            if (i & (1 << j)) {
                int tmp = (i & ~(1<<j));
                z.insert(dp[tmp][0]);
                z.insert(dp[tmp][1]);
            }
        }
        auto it = z.rbegin();
        dp[i][0] = (*it);
        it++;
        dp[i][1] = (*it);
    }
    ll prev = -LINF;
    for (i = 1; i < (1 << n); i++) {
        ll ans = (ll)dp[i][0].first + dp[i][1].first;
        ans = MAX(ans, prev);
        printf("%lld\n", ans);
        prev = ans;
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 36864
N, K = map(int, input().split())

max_num = (N - 1) * (N - 2) // 2

if K > max_num:
    print(-1)
else:
    edges = []
    for i in range(2, N + 1):
        edges.append((1, i,))

    add = max_num - K

    candidates = []
    for i in range(2, N):
        for j in range(i + 1, N + 1):
            candidates.append((i, j,))

    for i in range(add):
        edges.append(candidates[i])

    print(len(edges))
    for edge in edges:
        print(' '.join(map(str, edge)))


Measured memory_bytes: 3716
N = list(input())

if int(N[0]) + int(N[1]) + int(N[2]) + int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"+"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) - int(N[1]) + int(N[2]) + int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"+"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) + int(N[1]) - int(N[2]) + int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"-"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) + int(N[1]) + int(N[2]) - int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"+"+N[2]+"-"+N[3]+"=7")
elif int(N[0]) - int(N[1]) - int(N[2]) + int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"-"+N[2]+"+"+N[3]+"=7")
elif int(N[0]) - int(N[1]) + int(N[2]) - int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"+"+N[2]+"-"+N[3]+"=7")
elif int(N[0]) + int(N[1]) - int(N[2]) - int(N[3]) == 7:
    print(N[0]+"+"+N[1]+"-"+N[2]+"-"+N[3]+"=7")
elif int(N[0]) - int(N[1]) - int(N[2]) - int(N[3]) == 7:
    print(N[0]+"-"+N[1]+"-"+N[2]+"-"+N[3]+"=7")
else:
    pass

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

const int Maxn = 105;

int n;
int B[Maxn];
int A[Maxn];

int main()
{
    cin >> n;
    fill(A, A + n, 1000000000);
    for (int i = 0; i < n - 1; i++) {
        scanf("%d", &B[i]);
        A[i] = min(A[i], B[i]);
        A[i + 1] = min(A[i + 1], B[i]);
    }
    int res = 0;
    for (int i = 0; i < n; i++)
        res += A[i];
    cout << res << endl;
    return 0;
}


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

void _129() {
    int p, q, r;
    cin >> p >> q >> r;

    cout << min(p + q, min(q + r, p + r)) << endl;
}

void _128() {
    int a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
}

void _127() {
    int a, b;
    cin >> a >> b;
    if (a >= 13)
        cout << b << endl;
    else if (a >= 6)
        cout << b / 2 << endl;
    else
        cout << 0 << endl;
}

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



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

namespace std {

template<class Fun>
class y_combinator_result {
	Fun fun_;
public:
	template<class T>
	explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}

	template<class ...Args>
	decltype(auto) operator()(Args &&...args) {
		return fun_(std::ref(*this), std::forward<Args>(args)...);
	}
};

template<class Fun>
decltype(auto) y_combinator(Fun &&fun) {
	return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

} // namespace std

using ll = long long;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	vector<ll> vcost(n);
	for(int i = 0; i < n; i++) cin >> vcost[i];
	vector<vector<pair<int, ll> > > edges(n);
	for(int i = 0; i < n-1; i++){
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;
		edges[a].push_back({b, c});
		edges[b].push_back({a, c});
	}
	vector<pair<pair<int,int>, ll> > dfs_order;
	y_combinator([&](auto self, int v, int p) -> void {
		for(auto e : edges[v]){
			int w = e.first;
			if(w == p) continue;
			dfs_order.push_back({{w, v}, e.second});
			self(w, v);
		}
	})(0, -1);
	vector<pair<pair<int, int>, ll> > reverse_order = dfs_order;
	reverse(reverse_order.begin(), reverse_order.end());

	ll total_cost = 0;
	vector<vector<int> > cc_edges(n);
	while(true){
		vector<int> vis(n, false);
		vector<vector<int> > ccs;
		vector<int> which_cc(n, -1);
		for(int i = 0; i < n; i++){
			if(vis[i]) continue;
			vector<int> cc = {i};
			vis[i] = true;
			int s = 0;
			while(s < (int)cc.size()){
				int v = cc[s];
				s++;
				for(int w : cc_edges[v]){
					if(vis[w]) continue;
					vis[w] = true;
					cc.push_back(w);
				}
			}
			int k = (int)ccs.size();
			for(int v : cc) which_cc[v] = k;
			ccs.push_back(cc);
		}
		if(ccs.size() == 1) break;
		vector<vector<pair<ll, int> > > best(n, vector<pair<ll, int> >(2, {1e18, -1}));
		for(int v = 0; v < n; v++) best[v][0] = {vcost[v], which_cc[v]};
		auto prop_edge = [&](int v, int w, ll ecost) -> void {
			for(int j = 0; j < 2; j++){
				if(best[v][j].second == best[w][0].second) swap(best[w][0], best[w][1]);
				best[w][1] = min(best[w][1], {best[v][j].first + ecost, best[v][j].second});
				if(best[w][1] < best[w][0]) swap(best[w][0], best[w][1]);
			}
		};
		for(auto e : reverse_order) prop_edge(e.first.first, e.first.second, e.second);
		for(auto e : dfs_order) prop_edge(e.first.second, e.first.first, e.second);
		vector<pair<ll, int> > cc_best(ccs.size(), {1e18, -1});
		for(int v = 0; v < n; v++){
			for(int j = 0; j < 2; j++){
				if(best[v][j].second != which_cc[v]){
					cc_best[which_cc[v]] = min(cc_best[which_cc[v]], 
						{best[v][j].first + vcost[v], best[v][j].second});
				}
			}
		}
		for(int k = 0; k < (int)ccs.size(); k++){
			int l = cc_best[k].second;
			if(cc_best[l].second == k && l < k) continue;
			total_cost += cc_best[k].first;
			cc_edges[ccs[k].front()].push_back(ccs[l].front());
			cc_edges[ccs[l].front()].push_back(ccs[k].front());
		}
	}
	cout << total_cost << '\n';
}

Measured memory_bytes: 72552
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int main(){
  int num_word;
  while(~scanf("%d",&num_word)) {
    if (num_word == 0) break;
    
    vector<string> words;
    for (int word_i = 0; word_i < num_word; word_i++) {
      string word;
      cin >> word;
      words.push_back(word);
    }
    int res = 0;
    for (int start = 0; start < num_word; start++) {
      bool has_end[256];
      memset(has_end, 0, sizeof(has_end));
      int pos = 0;
      for (int word_i = start; word_i < num_word; word_i++) {
	pos += words[word_i].size();
	has_end[pos] = true;
      }

      if (has_end[5] && has_end[5 + 7] && has_end[5 + 7 + 5]
	  && has_end[5 + 7 + 5 + 7] && has_end[5 + 7 + 5 + 7 + 7]) {
	res = start + 1;
	break;
      }
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 3068
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
using namespace std;
int n,a[200050],b[200050],c[200050];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	for(int i=1;i<=n;i++){
		if(a[i]>b[n/2]) c[i]=b[n/2];
		else c[i]=b[n/2+1];
	}
	for(int i=1;i<=n;i++){
		if(i!=n) printf("%d ",c[i]);
		else printf("%d\n",c[i]);
	}
}

Measured memory_bytes: 4480
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    x = 0
    max_x = 0
    n = read_int()
    for c in input().strip():
        if c == 'I':
            x += 1
        else:
            x -= 1
        max_x = max(max_x, x)
    return max_x


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 61732
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	string S;
	cin >> S;
	int ans = INF32;

	for (int i = 0; i + 2 < S.size(); i++)
	{
		ans = min(abs(753 - (S[i] - '0') * 100 - (S[i + 1] - '0') * 10 - (S[i + 2] - '0')), ans);
	}

	cout << ans << endl;

	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    string s,t;
    cin>>s>>t;
    for (int i=0;i<150;i++){
        rotate(s.rbegin(), s.rbegin() + 1, s.rend());
        if (s==t){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 1000000
#define MIN -1000000

int main(void) {
    int a, max = MIN, min = MAX;
    long long sum = scanf("%*d");
    while(~scanf("%d", &a)) {
        min > a && (min = a);
        max < a && (max = a);
        sum += a;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;
public class Main {
  public static void main( String[] args ) {
	  Scanner scan = new Scanner(System.in);
	  int N = scan.nextInt();
	  int Y = scan.nextInt();
	  boolean isloop = true;
	  int cnt = 0;
	  int c = 0;
	  int a_maisuu = -1;
	  int b_maisuu = -1;
	  int c_maisuu = -1;
	  int kingaku = 0;
	  for( int a = 0; a <= N; a++ ) {
		  for( int b = 0; b + a <= N; b++ ) {
			  c = N - a - b;
			  cnt++;
			  kingaku = 10000 * a + 5000 * b + 1000 * c;
			  if( a + b + c == N && kingaku == Y && c >= 0 ) {
				  a_maisuu = a;
				  b_maisuu = b;
				  c_maisuu = c;
				  isloop = false;
				  break;
			  }
			  if( !isloop )break;
		  }
		  if( !isloop )break;
	  }
	  System.out.println( a_maisuu + " " + b_maisuu + " " + c_maisuu );
  }
}


Measured memory_bytes: 22740
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int i, o, j, l, v;
	cin >> i >> o >> v >> j >> l >> v >> v;
	if (i >= 2) {
		int k = i % 2 + 2;
		o += i - k;
		i = k;
	}
	if (j >= 2) {
		int k = j % 2 + 2;
		o += j - k;
		j = k;
	}
	if (l >= 2) {
		int k = l % 2 + 2;
		o += l - k;
		l = k;
	}
	int p = 0;
	for (int a = 0; a <= 3; a++) {
		for (int b = 0; b <= 1; b++) {
			for (int c = 0; c <= 1; c++) {
				for (int d = 0; d <= 1; d++) {
					if (a + b * 2 <= i && a + c * 2 <= j && a + d * 2 <= l) {
						p = max(p, a * 3 + b * 2 + c * 2 + d * 2);
					}
				}
			}
		}
	}
	cout << o + p << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]
ans = 0
for i in range(N-1):
    ans += (A[i] + A[i+1])//2
    A[i+1] = min(A[i+1], (A[i] + A[i+1]) % 2)
if N == 1:
    print(A[0]//2)
    exit()
print(ans)


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

const int N = 1e4 + 10;

int n, q;
int par[N];

int root(int v) {
	return (par[v] == -1? v: par[v] = root(par[v]));
}

int main() {
	ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	cin >> n >> q;
	for (int i = 0; i < n; i++)
		par[i] = -1;
	for (int i = 0; i < q; i++) {
		int c, a, b;
		cin >> c >> a >> b;
		if (c == 0) {
			if (root(a) != root(b))
				par[root(a)] = root(b);
		}
		else {
			if (root(a) == root(b))
				cout << 1 << endl;
			else
				cout << 0 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3264
N = int(input())

if N < 10:
    print(N)
    exit()

N_list = list(map(int, list(str(N))))

if N % 10 == 0:
    if N_list[0] == 1:
        print(10)
    else:
        print(N_list[0])
else:
    print(sum(list(map(int, list(str(N))))))

Measured memory_bytes: 3060
from collections import deque
S = deque(list(input().strip()))
Q = int(input())
cnt = 0
for i in range(Q):
    q = list(input().split())
    if len(q)==1:
        cnt += 1
    else:
        F = int(q[1])
        C = q[2]
        if cnt%2==0:
            if F==1:
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if F==1:
                S.append(C)
            else:
                S.appendleft(C)
if cnt%2==0:
    print("".join(S))
else:
    S = list(S)[::-1]
    print("".join(S))

Measured memory_bytes: 74600