akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};

UF<101010> uf;
int N,M;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		uf(x-1,y-1);
	}
	int num=-1;
	FOR(i,N) if(uf[i]==i) num++;
	cout<<num<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 4424
#include<stdio.h>

int month[]={31,29,31,30,31,30,31,31,30,31,30,31};

int main(){
  while(1){
    int a, b, i, sum = 0;
    scanf("%d%d", &a, &b);
    if(a == 0 && b == 0)return 0;
    for(i = 0;i < a - 1;i++)sum += month[i];
    sum += b;
    switch(sum % 7){
    case 0:
      puts("Wednesday");
      break;
    case 1:
      puts("Thursday");
      break;
    case 2:
      puts("Friday");
      break;
    case 3:
      puts("Saturday");
      break;
    case 4:
      puts("Sunday");
      break;
    case 5:
      puts("Monday");
      break;
    case 6:
      puts("Tuesday");
      break;
    }
  }
}

Measured memory_bytes: 584
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

int main(void)
{
    int n;
    vector<string> s;
    cin >> n;
    s.resize(n);
    for(auto& e : s) cin >> e;
    
    map<string, int> m;
    for(auto& e : s) m[e]++;
    int max = 0;
    for(auto& e : m)
    {
        if(max < e.second) max = e.second;
    }
    vector<string> o;
    for(auto& e : m)
    {
        if(max == e.second)
        {
            o.push_back(e.first);
        }
    }
    ::sort(o.begin(), o.end());
    for(auto& e : o)
    {
        cout << e << endl;
    }
}


Measured memory_bytes: 28404
#include <stdio.h>
int main(void){
    int n, flag = 0;
    scanf("%d", &n);

    for (int cake = 0; cake < 101; cake++){
        for (int donuts = 0; donuts < 101; donuts++){
            if (4 * cake + 7 * donuts == n){
                flag = 1;
            }
        }
    }

    if (flag == 1){
        printf("%s\n", "Yes");
    }
    else {
        printf("%s\n", "No");
    }

    return 0;
}


Measured memory_bytes: 128
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(b + w < a){
            System.out.println(a-b-w);
        }else if(a + w < b){
            System.out.println(b-a-w);
        }else{
            System.out.println("0");
        }
    }     
}

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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N,D,X; cin >> N >> D >> X;
    VI A(N); REP(i,N) cin >> A[i];
    int ans = X;
    REP(i,N){
        int day = 1;
        while(day <= D){
            ans++;
            day += A[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N ,K  , A;
  cin >> N >> K;
  A = 1 ;
  
  for(int i = 0; i< N ; i++){
    if( A < K){
      A *= 2;
    }else{
      A += K;
    }
  }

  cout << A << endl;
}



Measured memory_bytes: 256
//
// Created by yamunaku on 2019/08/30.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

vector<vector<ll>> comb;
vector<vector<ll>> rui;

void buildComb(int n){
    comb = vector<vector<ll>>(n + 1, vector<ll>(n + 1, 0));
    for(int i = 0; i <= n; i++){
        comb[i][0] = comb[i][i] = 1;
        for(int j = 1; j < i; j++){
            comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD1;
        }
    }
    rui = vector<vector<ll>>(n + 1, vector<ll>(n + 1, 0));
    for(int i = 0; i <= n; i++){
        rui[i][0] = 1;
        for(int j = 1; j <= i; j++){
            rui[i][j] = (rui[i][j - 1] + comb[i][j]) % MOD1;
        }
    }
}


int main(){
    int a, b;
    cin >> a >> b;
    buildComb(b);
    mtl dp(a + 1, vl(b + 1));
    rep(i, a + 1) dp[i][0] = 1;
    repl(i, 1, b + 1){
        dp[0][i] = 1;
        repl(j, 1, a + 1){
            dp[j][i] = (dp[j - 1][i] + rui[i - 1][min(i - 1, j)]) % MOD1;
        }
    }
    ll ans = 0;
    rep(i, a + 1){
        rep(j, min(a - i, b - 1) + 1){
            ans = (ans + comb[b - 1][j] * dp[a - i - j][j] % MOD1) % MOD1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int h, n;

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

    cin >> h >> n;
    int sum = 0;
    for(int i = 0; i < n; i++) {
        int num;
        cin >> num;
        sum += num;
    }

    if(h > sum) cout << "No" << '\n';
    else cout << "Yes" << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);


int g[15][15];
const int INF = 1001001001;
const int di[] = { -1,0,1,0 };
const int dj[] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int main() {
	int n;
	cin >> n;
	map<string, int>mp;
	rep(i, n) {
		string s;
		cin >> s;
		mp[s]++;
	}
	int mx = 0;
	for (auto p : mp)mx = max(mx, p.second);
	for (auto p : mp) {
		if (p.second != mx)continue;
		cout << p.first << endl;
	}
	return 0;
}


Measured memory_bytes: 25216
#include <stdio.h>
int main()
{
        int i, j;
	for(i = 1; i <= 9; i++)
	{
		for(j = 1; j <= 9; j++)
		{
			printf("%dx%d=%d\n", i, j, i*j);
		}
	}
	return 0;
}

Measured memory_bytes: 524
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=(input.trim()).split("\n");
var x=arr[0]-0;
for(var i=1;i<arr.length;i=i+2){
if(arr[i]=="=")break;
if(arr[i]=="+")x+=(arr[i+1]-0);
if(arr[i]=="-")x-=(arr[i+1]-0);
if(arr[i]=="*")x*=(arr[i+1]-0);
if(arr[i]=="/")x/=(arr[i+1]-0);
x=x.toFixed(0)-0;
}
console.log(x);

Measured memory_bytes: 7648
import java.util.*

// https://atcoder.jp/contests/dp/tasks/dp_a
fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()
    val heights = IntArray(n)
    for (i in 0 until n) {
        heights[i] = sc.nextInt()
    }

    val dp = IntArray(n)
    dp[1] = Math.abs(heights[0] - heights[1])

    for (i in 2 until n) {
//        dp[i] = Math.min(dp[i-1] + Math.abs(heights[i] - heights[i-1]), dp[i-2] + Math.abs(heights[i] - heights[i-2]))
        dp[i] = dp[i - 1] + Math.abs(heights[i] - heights[i - 1])

        for (j in k downTo 2) {
            if (i - j >= 0) dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(heights[i] - heights[i - j]))
        }
    }
    println(dp[n-1])
}






Measured memory_bytes: 51420
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

double dp[3010][3010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    double p[3010];
    rep(i, N) cin >> p[i];
    dp[0][0] = 1.0;
    rep(i, N) {
        rep(j, i + 1) {
            dp[i + 1][j + 1] += dp[i][j] * p[i];
            dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
        }
    }

    double ans = 0.0;
    REP(i, (N + 1) / 2, N) {
        ans += dp[N][i];
    }
    cout << fixed << setprecision(12) << ans << endl;


    return 0;
}


Measured memory_bytes: 49912
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define TRACE(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << endl;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]";
	err(++it, args...);
}

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)
#define BASE 29

int n;

struct Node
{
	bool is_end = 0;
	Node* ch[26] = {NULL};
};

Node* head = NULL;

void add(string s)
{
	auto cur = head;
	
	for (int i = 0; i < s.size(); ++i)
	{
		if(cur->ch[s[i]-'a'] == NULL)
			cur->ch[s[i]-'a'] = new Node;
		cur = cur->ch[s[i]-'a'];
	}

	cur->is_end = true;
}

int count(Node* node)
{
	int res = node->is_end;
	for (int i = 0; i < 26; ++i)
		if(node->ch[i])
			res += count(node->ch[i]);
	return res;
}

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	head = new Node;

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		string a;
		cin >> a;
		add(a);
	}

	cout << count(head) << endl;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

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

using namespace std;
using ll = long long;
using P = pair<int, uint>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 2;


void solve(){
    string s; cin >> s;
    if (s[0] == s.back()) {
        if (s.size() % 2 == 1) puts("Second");
        else puts("First");
    }
    else {
        if (s.size() % 2 == 1) puts("First");
        else puts("Second");
    }
}



int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 512
#include <atcoder/scc>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    atcoder::scc_graph graph(N);
    for (int z = 0; z < M; z++) {
        int a, b;
        scanf("%d %d", &a, &b);
        graph.add_edge(a, b);
    }
    vector<vector<int>> scc = graph.scc();
    printf("%d\n", (int)scc.size());
    for (vector<int> group : scc) {
        printf("%d", (int)group.size());
        for (int v : group) {
            printf(" %d", v);
        }
        printf("\n");
    }
}


Measured memory_bytes: 40092
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N, X, L;
	cin >> N;
	vector<pair<int, int>> a(N);
	for (pair<int, int>& i : a) {
		cin >> X >> L;
		i.first = X - L;
		i.second = X + L;
	}
	sort(a.begin(), a.end(), [](pair<int, int>& a, pair<int, int>& b) { return a.second < b.second; });
	vector<pair<int, int>> b{ a.front() };
	for (int i = 1; i < N; i++) {
		if (b.back().second <= a[i].first) b.push_back(a[i]);
	}
	cout << b.size();
}

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

int main()
{
	long long int n,m;
	cin>>n>>m;

	long long int temp=max(m,n),temp2=min(m,n);
	
	for(long long int i=0;i<temp;i++)
	{
		cout<<temp2;
	}
	
	return 0;
}

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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    int n, k;
    cin >> n >> k;
    map<int, int> dict;
    rep(i, k) {
        int d;
        cin >> d;
        vi a(d);
        rep(j, d) cin >> a[j];
        rep(j, d) dict[a[j]]++;
    }

    int ans = 0;
    rep(i, n) if (dict[i + 1] == 0) ans++;
    out(ans);

    return 0;
}


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

typedef struct node {
  int x;
  struct node* prev;
  struct node* next;
} list;

typedef struct {
  list* head;
  list* tail;
} Graph;
Graph graph[100001];

list* newnode(int x) {
  list* res = (list*)malloc(sizeof(list));
  res->x = x;
  res->prev = NULL;
  res->next = NULL;
  return res;
}
void deletenode(list* p) {
  p->prev->next = p->next;
  p->next->prev = p->prev;
  free(p);
}
void init_graph(Graph* g) {
  g->head = newnode(-1);
  g->tail = newnode(-1);
  g->head->next = g->tail;
  g->tail->prev = g->head;
}
void insert(Graph* g, int x) {
  list* p = newnode(x);
  p->next = g->head->next;
  p->prev = g->head;
  g->head->next->prev = p;
  g->head->next = p;
}
void clear_graph(Graph* g) {
  while(g->head->next != g->tail) {
    deletenode(g->head->next);
  }
  free(g->head);
  free(g->tail);
}

#define Q_LEN 1000000
int queue[Q_LEN];
int qhead, qtail;
void enque(int i) {
  if((qtail+1)%Q_LEN == qhead) return;
  queue[qtail] = i;
  qtail++;
  qtail %= Q_LEN;
}
int deque() {
  int res;
  if(qhead == qtail) return -1;
  res = queue[qhead];
  qhead++;
  qhead %= Q_LEN;
  return res;
}
int empty() {
  return qhead == qtail;
}
void clear_queue() {
  while(!empty()) deque();
}

int col[100001];

int main() {
  int n, m, q;
  int i, j;

  scanf("%d %d", &n, &m);

  for(i = 0; i < n; i++) init_graph(&graph[i]);

  for(i = 0; i < m; i++) {
    int s, t;
    scanf("%d %d", &s, &t);
    insert(&graph[s], t);
    insert(&graph[t], s);
  }

  /*
  for(i = 0; i < n; i++) {
    list* p;
    printf("%d -> ", i);
    for(p = graph[i].head->next; p != graph[i].tail; p = p->next) {
      printf("%d,", p->x);
    }
    puts("");
  }
  */

  memset(col, -1, sizeof(col));

  int c = 0;
  for(i = 0; i < n; i++) {
    if(~col[i]) continue;
    clear_queue();
    col[i] = ++c;
    enque(i);
    while(!empty()) {
      list* p;
      int u = deque();
      for(p = graph[u].head->next; p != graph[u].tail; p = p->next) {
	if(col[p->x] == -1) {
	  enque(p->x);
	  col[p->x] = c;
	}
      }
    }
  }

  //for(i = 0; i < n; i++) printf("%d = %d\n", i, col[i]);

  scanf("%d", &q);
  for(i = 0; i < q; i++) {
    int s, t;
    scanf("%d %d", &s, &t);
    puts((col[s] == col[t] ? "yes" : "no"));
  }

  for(i = 0; i < n; i++) clear_graph(&graph[i]);

  return 0;
}

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

const int MAXN = 1000005;

int h[MAXN], max_length = 0;

int main() {
    
    int N;
    cin >> N;
    
    for (int i=0; i<N; i++){
        int x;
        cin >> x;

        int lo = lower_bound(h,h+max_length,x) - h;
        h[lo] = x;
        
        max_length = max(lo+1,max_length);
    }
    
    cout << max_length << endl;

    return 0;
}

Measured memory_bytes: 1552
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    int q;
    cin >> q;
    for( int i = 0; i < q; ++i ) {
        int c, a, n;
        cin >> c >> a >> n;
        int res = 0;

        while( a && n && c ) {
            ++res;
            --a; --n, --c;

        }
        while( a && c >= 2 ) {
            ++res;
            --a; c -= 2;

        }
        while( c >= 3 ) {
            ++res;
            c -= 3;

        }
        cout << res << endl;

    }
    return 0;
}



Measured memory_bytes: 3136
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

H, W, K = mapint()

query = [list(input()) for _ in range(H)]
ans = 0
for i in range(1<<H):
    for j in range(1<<W):
        cnt = 0
        for h in range(H):
            for w in range(W):
                if not (i>>h)&1 and not (j>>w)&1:
                    if query[h][w]=='#':
                        cnt += 1
        if cnt==K:
            ans += 1

print(ans)

Measured memory_bytes: 68324
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 3010;
inline char get() {
	static char buf[10000], *S = buf, *T = buf;
	if (S == T) {
		T = (S = buf) + fread(buf, 1, 10000, stdin);
		if (S == T) return EOF;
	}
	return *S++;
}
char c;
inline void read(int &x) {
	x = 0; int sgn = 0;
	for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1;
	for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0';
	if (sgn) x = -x;
}
inline void read(string& s) {
  for (c = get(); c == ' ' || c == '\n'; c = get());
  for (; c != ' ' && c != '\n'; c = get()) s.push_back(c);
}

string s, t;
int dp[N][N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  read(s); read(t);
  int n = s.size(), m = t.size();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      if (s[i-1] == t[j-1]) {
        dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
      }
    }
  }
  string ans;
  int ci = n, cj = m;
  while (ci && cj) {
    if (dp[ci-1][cj] == dp[ci][cj]) {
      ci--;
    } else if (dp[ci][cj-1] == dp[ci][cj]) {
      cj--;
    } else {
      //assert(s[ci-1] == t[cj-1] && dp[ci-1][cj-1] + 1 == dp[ci][cj]);
      ans.push_back(s[ci-1]);
      ci--;
      cj--;
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans << nl;
  return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int ans=0;
    int c[5];
    for(int i=a;i<=b;i++){
        int num = i;
        int j = 0;
        while(num>0){
            c[j++] = num % 10;
            num /= 10;
        }
        if(c[0]==c[4] && c[1]==c[3]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int i,a[100001],N;
    int sum=0,t,x;
    scanf("%d",&N);
    memset(a,0,sizeof(a));
    for(i=1;i<=N/2;i++)
    {
        t=i;
        x=N-t;
        sum=0;
        while(t>0)
        {
            sum+=t%10;
            t/=10;
        }
        while(x>0)
        {
            sum+=x%10;
            x/=10;
        }
        a[i]=sum;

    }
    int minn=999999;
    for(i=1;i<=N/2;i++)
        if(a[i]<minn)
        minn=a[i];

printf("%d\n",minn);
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main()
{
  string serve;
  int a_point;
  int b_point;
  int size_str;
  
  while(cin >> serve){

    if(serve=="0")break;

    a_point=0;
    b_point=0;
    size_str=serve.size();
    
    for(int i=1;i<size_str+1;i++){

      if(serve[i-1]==serve[i] && serve[i]=='A')
	a_point++;
      else if(serve[i-1]!=serve[i] && serve[i]=='A')
	a_point++;
      else if(serve[i-1]==serve[i] && serve[i]=='B')
	b_point++;
      else if(serve[i-1]!=serve[i] && serve[i]=='B')
	b_point++;

      // cout << a_point << " " << b_point << endl;
    }
    
    if(a_point>b_point)
      cout << a_point+1 << " " << b_point << endl;
    else if(a_point<b_point)
      cout << a_point << " " << b_point+1<< endl;
     

  }

  return 0;
}


  



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

int main(void){
    int n = 0, x = 0, t = 0, ans = 0; 

    scanf("%d%d%d", &n, &x, &t);

    if(n % x == 0){
        ans = (n / x) * t;
    }else{
        ans = ((n / x) + 1) * t;
    }

    printf("%d\n", ans);

    return 0;

} 


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

int main(){
    string S;
    cin >> S;
    string T;
    cin >> T;
    int count = 0;
    for (int i = 0; i < 3;i++){
        if(S[i] == T[i])
            count++;
    }
    cout << count << endl;
    return 0;
}

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

typedef long long ll;

ll gcd(ll x, ll y) { return y ? gcd(y, x%y) : x;}

vector<pair<ll, int>> factorize(ll n) {
    vector<pair<ll, int>> res;
    for(ll i = 2; i*i <= n; i++) {
        if(n%i) continue;
        res.emplace_back(i, 0);
        while(n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}
int main() {
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;

    return 0;

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

ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a,b);
  auto f = factorize(g);
  int ans = f.size() + 1;
  cout << ans << endl;
  return 0;
}
*/


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#include<iomanip>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using lll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i, N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
template <typename T>
T gcd(T m, T n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}
int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll> A(N);
  FOR(i,N){
    cin>>A[i];
  }
  sort(A.begin(),A.end(),greater<ll>());
  ll sum=0;
  for(ll i=K;i<N;++i){
    sum+=A[i];
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
    int m, f, r;
    while (1)
    {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;
        int sum = m + f;
        if (m == -1 || f == -1){
            cout << "F" << endl;
        }
        else if (sum >= 80){
            cout << "A" << endl;
        }
        else if (65 <= sum && sum < 80){
            cout << "B" << endl;
        }
        else if (50 <= sum && sum < 65){
            cout << "C" << endl;
        }
        else if (30 <= sum && sum < 50){
            if (r >= 50){
                cout << "C" << endl;
            }else{
                cout << "D" << endl;
            }
        }
        else if (sum < 30){
            cout << "F" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3092
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
vector<int> G[100100];

signed main(){
    char b;
    cin >> b;
    if(b == 'A')cout << 'T';
    if(b == 'C')cout << 'G';
    if(b == 'G')cout << 'C';
    if(b == 'T')cout << 'A';
    cout << endl;
    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_d
// rm -r -f test;oj dl http://abc122.contest.atcoder.jp/tasks/abc122_a

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

using namespace std;

char data[12][6];
bool vis[12][6];
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

void drop(){
  for(int j=0;j<6;j++){
    int h = 11;
    for(int i=11;i>=0;i--){
      if(data[i][j] != '.'){
        data[h][j] = data[i][j];
        if(h != i) data[i][j] = '.';
        h--;
      }
    }
  }
}

int calcCount(int y, int x, char col){
  int res = 1;
  vis[y][x] = true;
  for(int i=0;i<4;i++){
    int ny = y + dy[i];
    int nx = x + dx[i];
    if(ny<0 || ny>=12) continue;
    if(nx<0 || nx>=6) continue;
    if(vis[ny][nx]) continue;
    if(data[ny][nx] != col) continue;
    res += calcCount(ny, nx, col);
  }
  return res;
}

void remove(int y, int x, char col){
  data[y][x] = '.';
  for(int i=0;i<4;i++){
    int ny = y + dy[i];
    int nx = x + dx[i];
    if(ny<0 || ny>=12) continue;
    if(nx<0 || nx>=6) continue;
    if(data[ny][nx] == 'O') data[ny][nx] = '.';
    if(data[ny][nx] != col) continue;
    remove(ny, nx, col);
  }
}

bool clear(){
  bool res = false;
  fill(vis[0], vis[12], false);
  for(int i=0;i<12;i++){
    for(int j=0;j<6;j++){
      if(data[i][j] != '.' && !vis[i][j] && data[i][j] != 'O'){
        int cnt = calcCount(i, j, data[i][j]);
        if(cnt >= 4){
          remove(i, j, data[i][j]);
          res = true;
        }
      }
    }
  }
  return res;
}

int solve(){
  int res = 0;
  while(clear()){
    drop();
    res++;
  }
  return res;
}

main(){
  int T;
  cin >> T;
  while(T--){
    for(int i=0;i<12;i++){
      for(int j=0;j<6;j++){
        cin >> data[i][j];
      }
    }
    cout << solve() << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);


int main(){
  int n;
  cin >> n;
  rep(i,n){
    char c;
    cin >> c;
    if(c=='Y'){
      cout<<"Four"<<endl;
      return 0;
    }
  }
  cout<<"Three"<<endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,y;
    cin>>n>>y;
    for(int i=0;i<n+1;i++){
        for(int j=0;j<n+1;j++){
            if(i*10000+j*5000+(n-i-j)*1000==y&&n-i-j>=0){
                cout<<i<<" "<<j<<" "<<n-i-j<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
}

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


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 2010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,m,ans;

char st[maxn][maxn];

int up[maxn][maxn],S[maxn],top;

void Work(){
	ans=max(n,m);
	REP(i,1,n-1){
		top=0;
		REP(j,1,m){
			while(top&&up[i][S[top]]>=up[i][j]){
				ans=max(ans,(j-S[top-1])*(up[i][S[top]]+1));
				top--;
			}
			S[++top]=j;
		}
	}
	iout(ans);
}

void Init(){
	read(n,m);
	REP(i,1,n)scanf("%s",st[i]+1);
	REP(i,1,n-1)REP(j,1,m-1)up[i][j]=((st[i][j]==st[i][j+1])==(st[i+1][j]==st[i+1][j+1]))?up[i-1][j]+1:0;
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 19968
import std.algorithm;
import std.array;
import std.conv;
import std.numeric;
import std.stdio;
import std.string;

void main()
{
    long n;
    long sum;
    
    n = readln.chomp.to!(long);
    
    sum = 0;
    
    for (long i = 1; i <= n; i++) {
        for (long j = 1; j <= n; j++) {
            for (long k = 1; k <= n; k++) {
                sum += gcd(i, gcd(j, k));
            }
        }
    }
    
    writeln(sum);
}


Measured memory_bytes: 2724
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC049C solver = new ABC049C();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC049C {
        static String[] strs = {
                "dream",
                "dreamer",
                "erase",
                "eraser"
        };

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();

            s = s.replaceAll(strs[3], "-");
            s = s.replaceAll(strs[2], "-");
            s = s.replaceAll(strs[1], "-");
            s = s.replaceAll(strs[0], "-");
            s = s.replaceAll("-", "");

            if (s.length() == 0) {
                out.println("YES");
            } else {
                out.println("NO");
            }

        }

    }
}



Measured memory_bytes: 29488
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

#include <iostream>

int main()
{
	int N,A,B;
	cin >> N >> A >> B;

	cout << min(N*A,B) << endl;

}


Measured memory_bytes: 256
input()
x = list(map(int, input().split()))
y = list(map(int, input().split()))
l = []
for a, b in zip(x, y):
  l += [abs(a - b)]
print("{0:.6f}".format(sum(l)))
print("{0:.6f}".format(sum([e ** 2 for e in l]) ** 0.5))
print("{0:.6f}".format(sum([e ** 3 for e in l]) ** (1/3)))
print("{0:.6f}".format(max(l)))


Measured memory_bytes: 5656
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int n;

int main() {
	cin >> n;
	if(n < 1200) puts("ABC");
	else if(n >= 1200 && n < 2800) puts("ARC");
	else puts("AGC");
}

Measured memory_bytes: 256
# coding: utf-8
a,b,ab,x,y=map(int,input().split())
ans=0
if a+b>ab*2:
    mn=min(x,y)
    ans+=ab*2*mn
    x-=mn
    y-=mn
if a>ab*2:
    ans+=x*ab*2
    y-=x
else:
    ans+=x*a
if y>0:
    if b>ab*2:
        ans+=y*ab*2
    else:
        ans+=y*b
print(ans)

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

    double p;
    if( N % 2 == 0){
        p = 0.5;
    }
    else {
        p = (N+1.0) / (2.0*N);
    }
    cout << p << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int a,b,c[1001][1001],d[1001],e[1001],m,mm,i,j,g=1;
int main(void)
{
	scanf("%d",&a);
	while(a!=0){
		m=0;
		mm=0;
		scanf("%d",&b);
		for(i=0;i<=b;i++){
			for(j=0;j<=a;j++){
				c[i][j]=-1;
			}
		}
		for(i=0;i<b;i++){
				scanf("%d,%d",&d[i],&e[i]);
		}
		c[0][0]=0;
		for(i=0;i<b;i++){
			for(j=0;j<=a;j++){
				if(c[i][j]>=0 && c[i][j]+d[i]>c[i+1][j+e[i]] && j+e[i]<=a){
					c[i+1][j+e[i]]=c[i][j]+d[i];
				}
				if(c[i][j]>=0 && c[i+1][j]<c[i][j]){
					c[i+1][j]=c[i][j];
				}
			}
			
		}
		for(j=0;j<=a;j++){
			if(c[b][j]>m){
				m=c[b][j];
				mm=j;
				//printf("c=%d j=%d\n",c[b][j],j);
			}
		}
		/*for(i=0;i<=b;i++){
			for(j=0;j<=a;j++){
				printf("%4d",c[i][j]);
			}
			printf("\n");
		}
		printf("%d\n",c[b][49]);*/
		printf("Case %d:\n%d\n%d\n",g,m,mm);
		g++;
		scanf("%d",&a);
	}	
	return 0;
}

Measured memory_bytes: 4948
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    for(int i=1; i<=100000000; ++i){
        bool ok = true;
        for(int j=0; j<n; ++j){
            if(a[j] % i != 0)
                ok = false;
        }

        if(ok)
            cout << i << endl;
    }

    return 0;
}

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

const int nm = 2e5;
int n, k, a[nm], b[nm + 1];
bool flag = 1;

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	++k;
	while (--k && flag) {
		fill(b, b + n, 0);
		for (int i = 0; i < n; ++i) {
			++b[max(0, i - a[i])];
			--b[min(n, i + a[i] + 1)];
		}
		for (int i = 0; i < n - 1; ++i)
			b[i + 1] += b[i];
		flag = 0;
		for (int i = 0; i < n; ++i) {
			a[i] = b[i];
			if (a[i] != n)
				flag = 1;
		}
	}
	for (int i = 0; i < n; ++i)
		cout << a[i] << (i < n - 1 ? " " : "\n");
}


Measured memory_bytes: 5156
S = input()
flag = False
count0 = 0
count1 = 0
count2 = 0
count3 = 0
for i in S:
    if i == S[0]:
        count0 += 1
    if i == S[1]:
        count1 += 1
    if i == S[2]:
        count2 += 1
    if i == S[3]:
        count3 += 1

if count0==2 and count1 == 2 and count2 == 2 and count3 == 2:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
from collections import deque
import sys
H,W=map(int,input().split())
maze=[input() for i in range(H)]

bl_cnt = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            bl_cnt += 1

def bfs():
    log=[[0 for _ in range(W)] for _ in range(H)]
    queue=deque([[0,0]])
    while queue:
        y,x = queue.popleft()
        for j,k in ([1,0],[-1,0],[0,1],[0,-1]):
            next_y,next_x = y+j, x+k

            if 0 > next_y or next_y >= H or 0 > next_x or next_x >= W:
                continue
            elif log[next_y][next_x] == 0 and \
                maze[next_y][next_x] != '#':
                log[next_y][next_x] = log[y][x] + 1
                queue.append([next_y,next_x])
    
    return log[H-1][W-1]

min_wh = bfs()

if min_wh == 0:
    print('-1')
    sys.exit()

ans = (W*H - min_wh - 1) - bl_cnt

print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

int main(){
	string S;
	cin >> S;
	string S1 = S.substr(0,1);
	string S2 = S.substr(1,1);
	string S3 = S.substr(2,1);
	string S4 = S.substr(3,1);
	if(S1 == S2 && S3 == S4){
		if(S2 != S3){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
		}
	}
	else if(S2 == S3 && S1 == S4){
		if(S2 != S1){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	else if(S1 == S3 && S2 == S4){
		if(S1 != S2){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int ar[5];
  	int k;
  	for(int i=0;i<5;i++){
    	cin>>ar[i];
    }
  	sort(ar,ar+5);
  	cin>>k;
  	if(ar[4]-ar[0]>k) cout<<":(";
  	else cout<<"Yay!";
}

Measured memory_bytes: 256
// g++ -std=c++11 temp.cpp
#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3

#define MAX_N 1000

int n,m;
int ball[100000];
bool red[100000];
int res = 0;

int main(){
	cin>>n>>m;
	REP(i,n){
		red[i] = false;
		ball[i] = 1;
	}
	red[0] = true;
	REP(i,m){
		int x,y;
		cin>>x>>y;
		x--; y--;
		ball[x]--; ball[y]++;
		if(red[x]){
			red[y] = true;
			if(ball[x]==0) red[x]=false;
		}
	}
	REP(i,n){
		if(red[i]) res++;
	}
	cout<<res<<endl;
	return 0;
}




Measured memory_bytes: 768
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
// also tink all answers possible for a question
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
#define sz 100005
ll inf = 1e9;
ll power(ll x, ll n, ll mod)
{
  ll res = 1;
  x %= mod;
  while (n)
  {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res%mod;
}
int main()
{
 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  ll a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  if(a[0]==a[1] && a[1]!=a[2])
  {
    cout<<"Yes\n";
  }
  else if(a[1]==a[2] && a[0]!=a[1])
  {
    cout<<"Yes\n";
  }
  else
    cout<<"No\n";
  return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;

const int mod = 1000000007;
ll modpow(ll a,ll n){
    ll res=1;
    while(n>0){
        if(n&1){
            res=res*a%mod;
        }
        a=a*a%mod;
        n>>=1;
    }
    return res;
}
ll modchoose(int n,int a){
    ll x=1,y=1;
    rep(i,a){
        x=(x*(n-i))%mod;
        y=(y*(i+1))%mod;
    }
    return (x*modpow(y,mod-2))%mod; // x/y
}
int main(){
    ll x,y;
    cin>>x>>y;
    ll ans=0;
    ll a=(2*x-y)/3;
    ll b=(2*y-x)/3;
    if((2*x-y)%3!=0||(2*y-x)%3!=0||a<0||b<0){
        ans=0;
    }
    else if(a+2*b==y&&2*a+b==x){
        //cout<<a<<" "<<b<<endl;
        ans=modchoose(a+b,min(a,b))%mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3604
#include <stdio.h>

int main(void)
{
  int n[5000], x[5000], count, i, j, k, l, ans, tmpAns[5000][3];
  for (i = 0; i < 5000; i++)  {
    scanf("%d %d", &n[i], &x[i]);
    if (n[i] == 0 && x[i] == 0)  {
      break;
    }
  }
  count = i;

  for (i = 0; i < count; i++)  {
    ans = 0;
    for (j = 1; j <= n[i]; j++)  {
      for (k = j + 1; k <= n[i]; k++)  {
        for (l = k + 1; l <= n[i]; l++)  {
          if (j != k && k != l && l != j && j + k + l == x[i])  {
            ans++;
          }
        }
      }
    }
    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
int a;
int main(){
  cin>>a;
  int b=a/1000,c=a%1000/100,d=a%100/10,e=a%10;
  if((b==c&&c==d&&d==e)||(b==c&&c==d)||(c==d&&d==e))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int main(){
	cin>>n;
	REP(i,n){
		int a;
		cin>>a;
		if(a%2==1){
			cout<<"first"<<endl;
			return 0;
		}
	}
	cout<<"second"<<endl;
	return 0;
}
		

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

const int A = 80;

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

    int n, m;
    cin >> n >> m;
    int a[n][m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            int b;
            cin >> b;
            a[i][j] -= b;
        }
    }

    int am = (n + m - 2) * A + 1;

    bool dp[n][m][am];
    fill(&dp[0][0][0], &dp[n][0][0], false);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (i == 0 && j == 0) {
                dp[i][j][abs(a[i][j])] = true;
            } else {
                for (int q = -1; q <= 1; q += 2) {
                    if (i > 0) {
                        for (int k = 0; k < am - A; k++) {
                            if (dp[i-1][j][k]) {
                                dp[i][j][abs(k+q*a[i][j])] = true;
                            }
                        }
                    }
                    if (j > 0) {
                        for (int k = 0; k < am - A; k++) {
                            if (dp[i][j-1][k]) {
                                dp[i][j][abs(k+q*a[i][j])] = true;
                            }
                        }
                    }
                }
            }
        }
    }

    int ans = am;
    for (int i = 0; i < am; i++) {
        if (dp[n-1][m-1][i]) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 79360