akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int N, L, a[1000010];
deque<int> deq;

int main() {
    cin >> N >> L;
    rep(i, N) cin >> a[i];

    // init
    int i;
    for (i = 0; i < L; i++) {
        while (!deq.empty() && a[i] <= a[deq.back()]) {
            deq.pop_back();
        }
        deq.push_back(i);
    }

    for (; i < N; i++) {
        cout << a[deq.front()] << " ";
        while (!deq.empty() && deq.front() <= i-L) {
            deq.pop_front();
        }
        while (!deq.empty() && a[i] <= a[deq.back()]) {
            deq.pop_back();
        }
        deq.push_back(i);
    }
    cout << a[deq.front()] << endl;
}



Measured memory_bytes: 7076
s = input()
if len(s) == 2 and s[0] == s[1]:
  print(1, 2)
  exit()
r = -1
for i in range(0, len(s)-2):
  if s[i] == s[i+1] or s[i] == s[i+2] or s[i+1] == s[i+2]:
    r = i
    break
if r < 0:
  print(-1, -1)
else:
  print(r+1, r+3)


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

int main()
{
    int n, k;
    cin >> n >> k;
    int h;
    int ans = 0;
    rep(i, n) {
        cin >> h;
        if (h >= k) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

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

	vector<int32_t> A(N), left(N), right(N);
	for (int32_t i = 0; i < N; i++) {
		cin >> A[i];
		if (i == 0)
			left[i] = A[i];
		else
			left[i] = max(left[i - 1], A[i]);
	}
	for (int32_t i = N - 1; i >= 0; i--) {
		if (i == N - 1)
			right[i] = A[i];
		else
			right[i] = max(right[i + 1], A[i]);
	}

	for (int32_t i = 0; i < N; i++) {
		int32_t res;
		if (i == 0)
			res = right[1];
		else if (i == N - 1)
			res = left[N - 2];
		else
			res = max(left[i - 1], right[i + 1]);
		cout << res << endl;
	}

	return 0;
}


Measured memory_bytes: 3968
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

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

typedef long long ll;

int main()
{
    ll s,w;
    cin>>s>>w;
    if(w>=s)
      cout<<"unsafe";
  else
    cout<<"safe";

    return 0;
}


Measured memory_bytes: 3560
// ABC056 B - NarrowRectanglesEasy;
'use strict';

function Main(input) {
    const tmp = input.trim().split('\n')[0].split(' ');
    const W = Number(tmp[0]);
    const a = Number(tmp[1]);
    const b = Number(tmp[2]);
    // console.log(W, a, b);

    let result;
    result = Math.abs(a - b) - W;
    if (result < 0) {
        result = 0;
    }
    console.log(result);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

// Main(`3 2 6`); // 1
// Main(`3 1 3`); // 0
// Main(`5 10 1`); // 4


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, P;
  cin >> N >> P;
  vector<int> A(N);
  for (auto& x : A) cin >> x;
  u64 ne = 1, no = 0;
  REP(i, N) {
    if (A[i] % 2 == 0) {
      ne = ne * 2;
      no = no * 2;
    } else {
      ne = no = no + ne;
    }
  }
  if (P) {
    cout << no << endl;
  } else {
    cout << ne << endl;
  }
}

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

int main(){
  int n, p; cin >> n >> p;
  string s; cin >> s;
  ll ans = 0;
  // s[i] = (i桁目の数) となると嬉しいので逆順に
  reverse(s.begin(),s.end());

  // 例外処理
  if(p == 2 || p == 5){
    rep(i,n) {
      int num = s[i]-'0';
      if(num%p == 0){
        // i 桁目の数が p で割り切れるなら、それを先頭にした連続部分列は全部 p で割り切れる
        ans += n-i;
      }
    }
    cout << ans << endl;
    return 0;
  }

  vl a(n);
  ll mul = 1;
  rep(i,n) {
    int num = s[i]-'0';
    a[i] = (num * mul) % p;
    mul = (mul * 10) % p;
  }

  vl sum(n+1);
  rep(i,n) sum[i+1] = (sum[i] + a[i]) % p;
  map<int,int> C;
  rep(i,n+1) {
    ans += C[sum[i]];
    C[sum[i]]++;
  }

  cout << ans << endl;
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

    int ans = 0;
    rep(i,n){
        if(h[i] >= k) ans++;
    }

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

Measured memory_bytes: 3632
// Enjoy your stay.

#include <bits/stdc++.h>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

//
int par_uf[100010],rank_uf[100010];

void init(int n){for(int i=0;i<n;i++){par_uf[i]=i;rank_uf[i]=0;}}
int find(int x){if(par_uf[x]==x)return x;else return par_uf[x]=find(par_uf[x]);}
void unite(int x,int y){x=find(x);y=find(y);if(x==y)return;if(rank_uf[x]<rank_uf[y])par_uf[x]=y;else{par_uf[y]=x;if(rank_uf[x]==rank_uf[y])rank_uf[x]++;}}
bool same(int x,int y){return find(x)==find(y);}
//

int N,M,x[10010],y[10010];
pair<double,pi> e[100010];

#define sq(x) ((x)*(x))

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>N>>M;
	rep(i,N)cin>>x[i]>>y[i];
	double ans=0;
	rep(i,M){
		int p,q;
		cin>>p>>q;
		p--;q--;
		double len=sqrt(sq(x[p]-x[q])+sq(y[p]-y[q]));
		ans+=len;
		e[i]=mp(-len,mp(p,q));
	}
	sort(e,e+M);
	init(N);
	rep(i,M){
		int p=e[i].sec.fir,q=e[i].sec.sec;
		if(!same(p,q)){
			ans+=e[i].fir;
			unite(p,q);
		}
	}
	cout<<fixed<<setprecision(16)<<ans<<endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	int x,y;
	cin>>x>>y;
	cout<<(x+y/2)<<endl;
	return 0;
}

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

int main(){
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> a(N+2, 0);
  for(int i=0; i<Q; i++){
    int q;
    cin >> q;
    a.at(q-1)++;
  }
  for(int i=0; i<N; i++){
    if(a.at(i) > Q-K){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, n = map(int, readline().split())

if n >= b:
    x = b - 1
else:
    x = n

ans = (a * x) // b - a * (x // b)
print(ans)

Measured memory_bytes: 9176
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#define REP(i, m, n) for(long long i = m; i < n; ++i)
#define CO(n) cout << n << endl
using namespace std;

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


int main()
{
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    if (C % gcd(A,B) == 0) CO("YES");
    else CO("NO");
    return 0;
}

Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}
 
int N;
string str(ll n){
    stringstream ss;
    ss << n;
    string s;
    ss >> s;
    return s;
}
 
bool check(ll n,ll N) {
    return (n <= N && str(n) <= str(N)) ||
        (n > N && str(n) > str(N));
}
 
bool ask(ll n){
    printf("? %lld\n",n);
    fflush(stdout);
#ifdef LOCAL
    return check(n , N);
#endif
    static char s[100];
    scanf("%s",s);
    return s[0] == 'Y';
}
 
void answer(ll x){
    printf("! %lld\n",x);
    exit(0);
}
 
int main(){
    srand(time(NULL));
    N = rand() + 1;
    ll x = 1 , l = -1 , r = -1;
    rep(i,0,11) {
        if(!ask(x) && l == -1) {
            l = x , r = x * 10;
        }
        x *= 10;
    }
    if(l == -1) {
        for(ll x=10;;x*=10) {
            if(ask(x - 1)) {
                answer(x / 10);
            }
        }
    } else {
        while(l + 1 < r) {
            ll m = (l + r) >> 1;
            if(ask(m)) r = m;
            else l = m;
        }
        answer(r / 10);
	}
    return 0;
}


Measured memory_bytes: 648
// ABC097
// A - Colorful Transceivers
#include<bits/stdc++.h>

using namespace std;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if((abs(a-b)<=d && abs(b-c)<=d) || abs(a-c)<=d) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

bool listen_numbers(int &,int &);

class Nums
{
private:
	int a,b;//a>=b
	int gcd;
	int lcm;
	
	void calc_gcd();
	void calc_lcm();
public:
	Nums(int,int);
	void echo_gcd();
	void echo_lcm();
};

Nums::Nums(int x,int y)
{
	if(x>=y)
	{
		this->a=x;
		this->b=y;
	}
	else
	{
		this->a=y;
		this->b=x;
	}
	
	this->gcd=0;
	this->lcm=0;
	
}

void Nums::calc_gcd()
{
	int rest1=this->a;
	int rest2=this->b;
	
	int tmp;
	while(rest1!=0 && rest2!=0)
	{
		tmp=rest1%rest2;
		rest1=rest2;
		rest2=tmp;
	}
	this->gcd=rest1;
}

void Nums::calc_lcm()
{
	if(this->gcd==0)
	{
		this->calc_gcd();
	}
	
	this->lcm=(int)((double)this->a*this->b/this->gcd);
}

void Nums::echo_gcd()
{
	if(this->gcd==0)
	{
		this->calc_gcd();
	}
	std::cout<<this->gcd;
}

void Nums::echo_lcm()
{
	if(this->lcm==0)
	{
		this->calc_lcm();
	}
	std::cout<<this->lcm;
}

int main()
{
	int a,b;
	
	for(;listen_numbers(a,b);)
	{
		Nums num=Nums(a,b);
		
		num.echo_gcd();
		std::cout<<" ";
		
		num.echo_lcm();
		std::cout<<std::endl;
	}
	
	return 0;
}

bool listen_numbers(int &a,int &b)
{
	using namespace std;
	
	cin>>a>>b;
	
	if(cin.eof())
	{
		return false;
	}
	else
	{
		return true;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cassert>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  ll n, a, b; cin >> n >> a >> b;
  vector<int> p(n);
  rep(i, n) {
    int pos; cin >> pos;
    pos--;
    p[pos] = 2*i+1;
  }

  int k = 2*n+1;
  vector<ll> dp(k);

  rep(i, n) {
    ll mi = LLONG_MAX;
    rep(j, k) {
      chmin(mi, dp[j]);
      if (j < p[i]) {
        dp[j] = mi+b;
      } else if (j == p[i]) {
        dp[j] = mi;
      } else {
        dp[j] = mi+a;
      }
    }
  }

  ll ans = LLONG_MAX;
  rep(i, k) {
    chmin(ans, dp[i]);
  }
  cout << ans << endl;
}

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

signed main()
{
    int n;
    cin>>n;
    int a[n+1];
    for (int i = 1; i <= n; ++i) {
        cin>>a[i];
    }

    int dp[n+1][n+1]={};
    for (int i = n; i >=1 ; --i) {
        dp[i][i]=a[i];

        for (int j = i+1; j <=n ; ++j) {
            dp[j][i]=max(a[i]-dp[j][i+1],a[j]-dp[j-1][i]);
        }
    }

    cout<<dp[n][1];
}

Measured memory_bytes: 70656
#include <cstdio>
using namespace std;
int main(){
    int x=1,y=1;
    int n;
    scanf("%d",&n);
    for(int i=3;i<=n;i++){
        if(i%2==0)
            x++;
        else
            y++;
    }
    printf("%d\n",x*y);
    return 0;
}


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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
constexpr int INF = 0x3f3f3f3f; constexpr ll BINF = 0x3f3f3f3f3f3f3f3fLL;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	int n, m; cin >> n >> m;
	vvi g(n);
	vi inDe(n);
	for (int i=0;i<m;i++) {
		int u, v; cin >> u >> v;
		g[u].push_back(v); inDe[v]++;
	}
	vi ans;
	queue<int> q;
	for (int i=0;i<n;i++) if (inDe[i] == 0) q.push(i);
	while (!q.empty()) {
		int u = q.front(); q.pop();
		ans.push_back(u);
		for (int v : g[u]) {
			inDe[v]--;
			if (inDe[v] == 0) q.push(v);
		}
	}
	cout << (int(ans.size()) != n) << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


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


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,k;
  cin >> n >> k;
  ll a[n],b[n];
  rep(i,n) {
    R a[i];
    a[i]--;
  }
  rep(i,n) R b[i];
  ll ans=-MAXL;
  rep(i,n) {
    vector<ll> d;
    ll x=i;
    while(1) {
      x=a[x];
      d.pb(b[x]);
      if(x==i) break;
    }
    ll c=k/d.size();
    if(c) c--;
    ll sum=0;
    rep(j,d.size()) sum+=d[j]*c;
    sum=max(0LL,sum);
    ll m=k-c*d.size();
    rep(j,m) {
      sum+=d[j%d.size()];
      ans=max(ans,sum);
    }
    sum=0;
    rep(j,d.size()) {
      sum+=d[j];
      if(j<k) ans=max(ans,sum);
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3800
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> a(n); rep (i, n) cin >> a[i];
    vector<ll> ans(n + 1); rep (i, n) ans[i + 1] = 2 * a[i] - ans[i];
    rep (i, n + 1) eprintf("%d ", ans[i]); eprintf("\n");
    ll f = ans[n] / 2;
    rep (i, n) ans[i] += f * (i % 2 == 0 ? 1LL : -1LL);
    rep (i, n) cout << ans[i] << (i != i_len - 1 ? ' ' : '\n');
    return 0;
}

Measured memory_bytes: 2944
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		int num1 = sc.nextInt();
		int num2 = sc.nextInt();
		int num3 = sc.nextInt();
		int num4 = sc.nextInt();
		int num5 = sc.nextInt();

		List<Integer> list = new ArrayList<Integer>();

		list.add(num1);
		list.add(num2);
		list.add(num3);
		list.add(num4);
		list.add(num5);

		Collections.sort(list);
		Collections.reverse(list);

		for(int i = 0; i < 4; i++){

			System.out.print(list.get(i) + " ");
		}

		System.out.println(list.get(4));
	}

}

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


int main(){
    string s, t;
    cin >> s >> t;
    int ss = s.size(), ts = t.size();
    vector<vector<int>> dp(ss+1, vector<int>(ts+1, 0));
    rep(i,ss){
        rep(j,ts){
            if(s[i] == t[j]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);
        }
    }
    string res = "";
    while (ss > 0 && ts > 0)
    {
        if(dp[ss][ts] == dp[ss-1][ts]) --ss;
        else if (dp[ss][ts] == dp[ss][ts-1]) --ts;
        else{
            res = s[ss-1] + res;
            --ss, --ts;
        }
    }
    cout << res << endl;
}


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

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795

ll no_of_div(ll a)
{
  ll cnt=0,i;
  if (a==2)return 1;
  for(i=2;i*i<a;i++)
  {
if(a%i==0)cnt+=2;
  }
  if(i*i==a)cnt++;
  return cnt;
}

//vl a(1001);

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}





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


ll a,b,c;
cin>>a>>b>>c;


for(int i=1;i<b;i++)
{
if(a*i%b==c)
{
  cout<<"YES"<<"\n";
  return 0;
  }
}


cout<<"NO"<<"\n";



  return 0;


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>

using namespace std;

int main()
{
  int A,B,C;cin>>A>>B>>C;
  string ret="No";

  int flg1=0,flg2=0,flg3=0;

  if(A==B) {flg1=1;}
  if(B==C) {flg2=1;}
  if(A==C) {flg3=1;}

  if(flg1+flg2+flg3==1) {ret="Yes";}

  cout<<ret<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
typedef pair<int, int> pii;
#define FI first
#define SE second
#define all(s) s.begin(),s.end()

/*
 struct UF {
 int n;
 vector<int> par;
 UF(int n_) :
 n(n_), par(n_) {
 rep(i,n)
 {
 par[i] = i;
 }
 }
 bool same(int x, int y) {
 return root(x) == root(y);
 }
 void unite(int x, int y) {
 par[root(x)] = root(y);
 }
 int root(int x) {
 if (par[x] == x)
 return x;
 else
 par[x] = root(par[x]);
 }
 };
 */
int N;
string S;
int res[100100]; //1s2w

bool check() {
	int prev = res[N - 1];
	for (int i = 1; i < N - 1; ++i) {
		if (S[i] == 'o') {
			if (res[i] == 1) {
				//hitsuji
				res[i + 1] = res[i - 1];
			} else {
				//okami
				res[i + 1] = res[i - 1] == 1 ? 2 : 1;
			}
		} else {
			if (res[i] == 1) {
				//hitsuji
				res[i + 1] = res[i - 1] == 1 ? 2 : 1;
			} else {
				//okami
				res[i + 1] = res[i - 1];
			}
		}
	}
	if (prev != res[N - 1])
		return false;
	if (S[N - 1] == 'o') {
		if (res[N - 1] == 1) {
			//hitsuji
			if (res[0] != res[N - 2])
				return false;
		} else {
			//okami
			if (res[0] == res[N - 2])
				return false;
		}
	} else {
		if (res[N - 1] == 1) {
			//hitsuji
			if (res[0] == res[N - 2])
				return false;
		} else {
			//okami
			if (res[0] != res[N - 2])
				return false;
		}
	}
	return true;
}

void display() {
	rep(i,N)
	{
		char s;
		if (res[i] == 1)
			s = 'S';
		else
			s = 'W';
		cout << s;
	}
	cout << endl;
}

signed main() {
	cin >> N;
	cin >> S;
	if (S[0] == 'o') {
		res[0] = 1;
		res[1] = 1;
		res[N - 1] = 1;
		if (check()) {
			display();
			return 0;
		}
		memset(res, 0, sizeof(res));
		res[0] = 1;
		res[1] = 2;
		res[N - 1] = 2;
		if (check()) {
			display();
			return 0;
		}
		memset(res, 0, sizeof(res));
		res[0] = 2;
		res[1] = 1;
		res[N - 1] = 2;
		if (check()) {
			display();
			return 0;
		}
		memset(res, 0, sizeof(res));
		res[0] = 2;
		res[1] = 2;
		res[N - 1] = 1;
		if (check()) {
			display();
			return 0;
		}
		memset(res, 0, sizeof(res));
	} else {
		res[0] = 2;
		res[1] = 1;
		res[N - 1] = 1;
		if (check()) {
			display();
			return 0;
		}
		memset(res, 0, sizeof(res));
		res[0] = 2;
		res[1] = 2;
		res[N - 1] = 2;
		if (check()) {
			display();
			return 0;
		}
		memset(res, 0, sizeof(res));
		res[0] = 1;
		res[1] = 1;
		res[N - 1] = 2;
		if (check()) {
			display();
			return 0;
		}
		memset(res, 0, sizeof(res));
		res[0] = 1;
		res[1] = 2;
		res[N - 1] = 1;
		if (check()) {
			display();
			return 0;
		}
		memset(res, 0, sizeof(res));
	}
	cout << -1 << endl;
}


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

using namespace std;

typedef long long int64;
const int maxn = 1e5 + 9;

struct dsu {
	vector<int> parent, size;
	dsu(int n) : parent(n + 1), size(n + 1) {
		for (int i = 0; i < n + 1; i++) {
			parent[i] = i;
			size[i] = 1;
		}
	}
	int find(int u) {
		if (u == parent[u]) return u;
		return parent[u] = find(parent[u]);
	}
	int64 merge(int u, int v) {
		u = find(u); v = find(v);
		if (u == v) return -1LL;
		int size_u = size[u], size_v = size[v];
		parent[u] = v;
		size[v] += size[u];
		size[u] = 0;
		return size_u * (size_u - 1LL) * 1LL / 2LL + size_v * (size_v - 1LL) * 1LL / 2LL;
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	dsu uf(n);
	vector<pair<int, int> > edges;
	int64 ans[maxn];
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		edges.push_back(make_pair(u, v));
	}
	int64 tmp = n * (n - 1LL) * 1LL / 2LL;
	for (int i = 0; i < m; i++) {
		ans[m - i - 1] = tmp;
		pair<int, int> edge = edges[m - i - 1];
		int64 delta = uf.merge(edge.first, edge.second);
		if (delta == -1LL) continue;
		tmp += delta;
		int size = uf.size[uf.find(edge.first)];
		tmp -= size * (size - 1LL) * 1LL / 2LL;
	}
	for (int i = 0; i < m; i++) {
		cout << ans[i] << '\n';
	}
	return 0;
}


Measured memory_bytes: 3828
n = int(input())
s = str(n)
len_s = len(s)

ans = 0

for i in range(10):
    char = str(i)
    for i in range(len_s):
        num = i*"9" + char + (len_s-i-1)*"9"
        if int(num) <= n:
            tmp = sum([int(i) for i in num])
            ans = max(ans, tmp)
print(ans)
        

Measured memory_bytes: 38896
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        d[int(input())] += 1
    ans = 0
    for i in d.values():
        if i%2==1:
            ans +=1
    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int N;
	cin >> N;
	int ans = N;
	int tmp;
	rep1(i,sqrt(N)+1) {
		if (N % i == 0) {
			tmp = i + N / i - 2;
			ans = min(ans, tmp);
		}
	}
	print(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, base[3], ans = 1000000000;
  int l[8];
  cin >> n >> base[0] >> base[1] >> base[2];
  for(int i=0; i<n; i++)
    cin >> l[i];
  for(int i=0, pat = pow(4,n); i<pat; i++){
    bool testa[3] = {}, cont = false;
    int now = i, cost = 0, leng[3] = {}, j = -1;
    while(now != 0){
      int tar = (now % 4) - 1;
      now /= 4;
      j++;
      if(tar < 0)
        continue;
      if(leng[tar] > 0) cost += 10;
      leng[tar] += l[j];
      testa[tar] = true;
    }
    for(int k=0;k<3;k++){
      if(!testa[k]) cont = true;
    }
    if(cont) continue;
    for(int k=0;k<3;k++){
      cost += abs(base[k] - leng[k]);
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const int INF=100000000LL;
const ll r197=1000000007;
typedef pair<ll,ll>P;
typedef pair<P,P>Pa;
vector<ll> v[100001];
ll C[100001];
struct edge{ll time,posi,abe,he;};
ll h,w;
char a[1001][1001];
int b[1001][1001]={};
int dp[1001][1001][16];
int main() {
	int n;
	cin>>n;
	ll a[100001];
	rep(i,0,n){
		cin>>a[i];
	}
	sort(a,a+n);
	ll ans=0;
	if(n%2==0){
		ll t1=0,t2=0;
		rep(i,0,n/2){
			t1+=a[i];
		}
		rep(i,n/2,n){
			t2+=a[i];
		}
		ans=(t2*2-a[n/2])-(t1*2-a[n/2-1]);
	}else{
		ll t1=0,t2=0;
		rep(i,0,n/2){
			t1+=a[i];
		}
		rep(i,n/2,n){
			t2+=a[i];
		}
		ans=(t2*2-a[n/2]-a[n/2+1])-(t1*2);
		t1=0;
		t2=0;
		rep(i,0,n/2+1){
			t1+=a[i];
		}
		rep(i,n/2+1,n){
			t2+=a[i];
		}
		ll ans2=(t2*2)-(t1*2-a[n/2]-a[n/2-1]);
		ans=max(ans,ans2);
	}
	cout<<ans<<endl;

}


Measured memory_bytes: 4224
import heapq
import sys

N, M = map(int, input().split())
A = list(map(int, input().split()))

if N == 1:
    for i in range(M):
        A[0] = A[0] // 2
    print(sum(A))
    sys.exit()
h = []
for i in range(N):
    heapq.heappush(h, -A[i])

for i in range(M):
    tmp = heapq.heappop(h)
    tmp = -(-tmp // 2)
    heapq.heappush(h, tmp)


print(-sum(h))

Measured memory_bytes: 14184
def solve(n):
	for i in range(1,10000):
		cnt=0
		for j in range(1,i+1):
			if i%j==0:
				cnt+=1
		if cnt==n:
			return(i)
while True:
	try:
		n=int(input())
		print(solve(n))
	except EOFError:
		break

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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define rall(a) (a).rbegin(),(a).rend()
using vi  = vector<int>;
constexpr int inf = 1ll<<30;
template<class T>bool chmax(T &a, const T &b) { if(a<b){a=b; return true;} return false;}

int main(){
  int n,m; cin >> n >> m;
  vi a(m); rep(i,m) cin >> a[i]; sort(rall(a));
  vi num = {6,2,5,5,4,5,6,3,7,6};

  vi dp(n+10,-inf);
  dp[0] = 0;
  rep(i,n) rep(j,m) chmax(dp[i + num[a[j]]], dp[i] + 1);

  int i = n;
  while(1){
    if(not i) break;
    rep(j,m){
      if(i-num[a[j]] >= 0 and dp[i-num[a[j]]] == dp[i]-1){
	cout << a[j];
	i -= num[a[j]];
	break;
      }
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N; cin >> N;
  int a;
  ll cond = 1, pow3 = 1;
  rep(i,N) {
    cin >> a;
    cond *= (a%2 ? 1 : 2);
    pow3 *= 3;
  }
  cout << pow3 - cond << endl;
  



  // cout << fixed << setprecision(6);
  return 0;
}



Measured memory_bytes: 256
using System;
using System.Linq;

namespace ABC127A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] AB = CIN.IntArray();

            if (AB[0] > 12)
            {
                Console.WriteLine(AB[1]);
                return;
            }

            if (AB[0] > 5)
            {
                Console.WriteLine(AB[1]/2);
                return;
            }
            Console.WriteLine(0);
        }
    }

    internal static class CIN
    {
        public static string String()
        {
            return Console.ReadLine();
        }

        public static int Int()
        {
            return int.Parse(Console.ReadLine());
        }

        public static int[] IntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }

        public static long Long()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] LongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] DoubleArray()
        {
            return Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
    }
}

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

ans = 0

for i in range(N):
    deme = i+1
    point = deme
    m = 0
    while(True):
        if point >= K:
            break
        point *= 2
        m += 1
    ans += (1/N) * (1/2)**m

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{
    string str;
    string tmp;
    int sum;

    while(1)
    {
        cin >> str;
        if(str == "0") break;
        sum = 0;
        for(int i=0;i<str.size();i++)
        {
            tmp = str[i];
            int num = atoi(tmp.c_str());
            sum += num;
        }
        
        cout << sum << endl;
    }
    return 0;
}



Measured memory_bytes: 3236
var
  n,i,j,k,t,x,p1,p2,q1,q2,maxa1,maxa2,maxb1,maxb2:longint;
  a,b:array[1..100000] of longint;
function max(x,y:longint):longint;
  begin
    if x>y
      then exit(x)
      else exit(y);
  end;
begin
  readln(n);
  for i:=1 to n do
    begin
      read(x);
      if i mod 2=0
        then inc(b[x])
        else inc(a[x]);
    end;
  for i:=1 to 100000 do
    begin
      if a[i]>maxa1
        then
          begin
            maxa2:=maxa1;
            maxa1:=a[i];
            p1:=i;
          end
        else
      if a[i]>maxa2
        then maxa2:=a[i];
    end;
  for i:=1 to 100000 do
    begin
      if b[i]>maxb1
        then
          begin
            maxb2:=maxb1;
            maxb1:=b[i];
            q1:=i;
          end
        else
          if b[i]>maxb2
            then maxb2:=b[i];
    end;
  if p1<>q1
    then writeln(n-maxa1-maxb1)
    else writeln(n-max(maxa1+maxb2,maxa2+maxb1));
end.


Measured memory_bytes: 896
#include <iostream>

using namespace std;

int main(){
	int n, x;
	
	while(cin >> n >> x){
		int cnt = 0;
		if(n == 0 & x == 0) break;
	
		for(int i = 1; i < n - 1;i++){
			for(int j = i + 1; j < n; j++){
				for(int k = j + 1; k <= n;k++){
					if(i + j + k == x)  cnt++;
				}
			}
		}
		
		cout << cnt << endl;
		
	}
	return 0;
}	

Measured memory_bytes: 3056
#from fractions import gcd
#mod = 10 ** 9 + 7
#N = int(input())
#a = list(map(int,input().split()))
#a,b,c = map(int,input().split())

N, M = map(int,input().split())

ans = [0] * N
for i in range(M):
    a,b= map(int,input().split())
    ans[a-1] += 1
    ans[b-1] += 1

for i in range(N):
    print(ans[i])


Measured memory_bytes: 2940
#include <iostream>
#include <map>

using namespace std;

map<int, int> mp;

void factorization(int n){
    
    for (int i = 2; i*i <= n; i++){
        if (n % i) continue;
        
        int count = 0;
        
        while (n % i == 0){
            count++;
            n /= i;
        }
        mp[i] = count;
    }
    
    // is n is a prime number
    if (n != 1) mp[n]++;
}

int main(){
    int n;
    cin >> n;
    
    factorization(n);
    
    cout << n << ":";
    for (auto p : mp){
        
        for (int i = 0; i < p.second; i++){
            cout <<  " " << p.first;
        }
    }
    cout << endl;
}


Measured memory_bytes: 3132
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}



use std::cmp;
use std::iter::Iterator;

fn main() {
    input! {
        a:usize,
        b:usize,
    }

    if a >= 13{
        println!("{}", b)
    }else if a <= 5{
        println!("{}", "0")
    }else{
        println!("{}", b /2)
    }

}



Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<list>
#include<vector>
#include<queue>
using namespace std;

void visit(vector<vector<int> > &counta, vector<vector<list<pair<int,int> > > > adj){
    counta[0][0] = 1;
    queue<pair<int,int> > que;
    que.push(make_pair(0,0));
    pair<int,int> p;
    list<pair<int,int> >::iterator t;
    while(!que.empty()){
        p = que.front();
        que.pop();
        for(t = adj[p.first][p.second].begin(); t != adj[p.first][p.second].end(); ++t){
            if(counta[(*t).first][(*t).second] < 0){
                counta[(*t).first][(*t).second] = counta[p.first][p.second] + 1;
                que.push(make_pair((*t).first,(*t).second));
            }
        }
    }
}

int main(){
    //input
    int H, W;
    cin >> H >> W;
    int i,j;
    vector<char> A;
    vector<vector<char> > AA; 
    for(i = 0; i < H; i++){
        string S;
        const char *s = NULL;
        cin >> S;
        s = S.c_str();
        A.assign(s, s + S.length());
        AA.push_back(A);
    }

    //calc
    int kurosum = 0;
    for(i = 0; i < H; i++){
        for(j = 0; j < W; j++){
            if(AA[i][j] == '#'){
                kurosum++;
            }
        }
    }
    list<pair<int,int> > intint_subsub;
    vector<list<pair<int,int> > > intint_sub;
    for(j = 0; j < W; j++){
        intint_sub.push_back(intint_subsub);
    }
    vector<vector<list<pair<int,int> > > > adj;
    for(i = 0; i < H; i++){
        adj.push_back(intint_sub);
    }
    for(i = 0; i < H; i++){
        for(j = 0; j < W-1; j++){
            if(AA[i][j] == '.' && AA[i][j+1] == '.'){
                adj[i][j].push_back(make_pair(i,j+1));
                adj[i][j+1].push_back(make_pair(i,j));
            }
        }
    }
    for(j = 0; j < W; j++){
        for(i = 0; i < H-1; i++){
            if(AA[i][j] == '.' && AA[i+1][j] == '.'){
                adj[i][j].push_back(make_pair(i+1,j));
                adj[i+1][j].push_back(make_pair(i,j));
            }
        }
    }
    vector<int> int_sub;
    for(j = 0; j < W; j++){
        int_sub.push_back(-1);
    }
    vector<vector<int> > counta;
    for(i = 0; i < H; i++){
        counta.push_back(int_sub);
    }
    visit(counta,adj);

    //answer
    if(counta[H-1][W-1]>0){
        cout << H*W - kurosum - counta[H-1][W-1] << endl;
    }else{
        cout << -1 << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int a,b,sum=1;
  cin >> a >>b;
  for(int i =0;i < a;i++) {
    if(sum<b) sum*=2;
    else sum+=b;
}
  cout << sum <<endl;
}

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

int main(void){
  int i,j,a,out,base,point;
  char event[8];

  scanf("%d",&a);

  for(i=0;i<a;i++){
    point=0;
    base=0;
    out=0;
    while(1){

      scanf("%s",event);
      
      if(!strcmp(event,"OUT")){
	//printf("1\n");
	out++;
	if(out==3)break;
      }

      if(!strcmp(event,"HIT")){
	//printf("2\n");
	if(base<3)base++;
	else {
	  point++;
	}
      }
      
      if(!strcmp(event,"HOMERUN")){
	//printf("3\n");
	point+=base+1;
	base=0;
      }

    }
    printf("%d\n",point);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rint register int
#define rep(i,a,b) for (rint i=(a),_E=(b); i<=_E; ++i)
#define per(i,a,b) for (rint i=(a),_E=(b); i>=_E; --i)
#define REP(i,n) for (rint i=0,_E=(n); i<_E; ++i)
#define pb push_back
#define cmin(x,y) (y<x?x=y:0)
#define cmax(x,y) (y>x?x=y:0)
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int N = 100005;
int c[32], x, n, res, cnt, ans;

int main() {
	scanf("%d", &n);
	rep (i, 1, n) {
		scanf("%d", &x);
		res ^= x;
		cnt = 0;
		while (x && (x % 2 == 0))
			x >>= 1, ++ cnt;
		c[cnt] = 1;
	}
	per (i, 30, 0)
		if (res >> i & 1) {
			res ^= (1 << (i + 1)) - 1;
			++ ans;
			if (!c[i]) return puts("-1"), 0;
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
N,K = (int(x) for x in input().split())
mod = 10**9+7 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

K1 = K-1
NK = N-K+1
a = list(map(int, input().split()))
a.sort()
ans = 0
maxs = 0
mins = 0
for i in range(N):
    if i < K1:continue
    maxs += a[i] * cmb(i,K1,mod)
    maxs = maxs%mod
for i in range(NK):
    mins += a[i] * cmb(N-i-1,K1,mod)
    mins = mins%mod
print((maxs - mins)%mod)

Measured memory_bytes: 26660
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll; 

struct UnionFind {
    public: 
    int N;

    vector<int> par;
    vector<int> fam;

    UnionFind(int n) : N(n) {
        par.resize(n);
        fam.resize(n);
        for(int i = 0; i < n; i++) {
            par[i] = i;
            fam[i] = 1;
        }
    }

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

    void unite(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
        fam[ry] += fam[rx];
    }

    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return fam[root(x)];
    }

};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    UnionFind tree(N);
    vector<ll> ans(M);

    ans[M-1] = 1LL * N * (N-1) / 2;

    for (int i = M-1; i > 0; i--){
        if(tree.same(A[i], B[i])){
            ans[i-1] = ans[i];
        }
        else {
            ans[i-1] = ans[i] - tree.size(A[i]) * tree.size(B[i]);
        }
        tree.unite(A[i], B[i]);
    }

    for (int i = 0; i < M; i++){
        cout << ans[i] << endl;
    }

    return 0;    
}

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

typedef long long ll;

ll a[100][10];//m桁の最高位nのルンルン数の数


int search(vector<int> &ans, ll m, ll cnt, ll K)
{
    if(m==0)
    {
        return 0;
    }

    for(int i=1; i>=-1; i--)
    {
        int j = ans[ans.size()-1];
        j += i;

        if(0 <= j && j <=9)
        {
            cnt -= a[m-1][j];

            if(cnt < K)
            {
                cnt += a[m-1][j];
                ans.push_back(j);
                search(ans, m-1, cnt, K);
            }
        }
    }

    return 0;
}

int main()
{
    ll K;
    cin >> K;


    for(int i=0; i<10; i++)
    {
        a[0][i] = 1;
    }
    ll cnt = 0;
    ll m = 0;
    bool isFound = false;
    for(;;)
    {
#if 0 
        for(int i=0; i<10; i++)
        {
            cout << keta << "," << i << "," << a[i] << endl;
        }
#endif
        //ルンルン数の累積数
        for(int i=1; i<10; i++)
        {
            cnt += a[m][i];
            if(cnt >= K)
            {
                isFound = true;
                //cout << m << "," << i << "," << cnt - K << endl;
                
                vector<int> ans;
                ans.push_back(i);
                search(ans, m, cnt, K);

                for(int i=0; i<=m; i++)
                {
                    cout << ans[i];
                }
                cout << endl;

                break;
            }
        }

        if(isFound)
        {
            break;
        }

        //最高位の数ごとにルンルン数を集計
        a[m+1][0] = a[m][0] + a[m][1];
        for(int i=1; i<9; i++)
        {
            a[m+1][i] = a[m][i-1] + a[m][i] + a[m][i+1];
        }
        a[m+1][9] = a[m][8] + a[m][9];

        //桁を更新
        m++;
    }

    
    return 0;
}


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

int main(){
    string s, ans;
    cin >> s;
    rep(i, s.size()){
        if(s[i] != 'B') ans.push_back(s[i]);
        else if(ans.size()!=0)ans.pop_back();
    }
    cout << ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
int main() {
  int x;
  cin >> x;
  cout << x * x * x << endl;
  return 0;
}

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

typedef long long ll;
typedef long long ld;
typedef vector<int> vi;
typedef pair<ll, ll> pii;

struct Node
{
    int node, len;
    Node() {node = len = 0;}
    Node(int node, int len) {this -> node = node, this -> len = len;}
};
typedef vector<Node> vg;

#define MAX 1
#define NON 0
#define MOD 1000000007

#define FOR(type, i, a, b) for(type i = a; i < b; i++)
#define FORR(type, i, b, a) for(type i = b; i > a; i--)
#define FORE(type, i, a, b) for(type i = a; i <= b; i++)
#define FORRE(type, i, b, a) for(type i = b; i >= a; i--)

#define testBit(n, bit) ((n >> bit) & 1)
#define flipBit(n, bit) (n ^ (1ll << bit))
#define randomize mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    map<string, bool> m;
    int n; cin >> n;
    FORE(int, i, 1, n){
        string s; cin >> s;
        m[s] = true;
    }
    cout << m.size();
}

Measured memory_bytes: 19216
#include<stdio.h>

int main()
{
  int W,H,x,y,r;
  scanf("%d %d %d %d %d\n",&W,&H,&x,&y,&r);

  if(x - r < 0 || x + r > W || y - r < 0 || y + r > H)
    puts("No");

  else
    puts("Yes");
  

return 0;
}


Measured memory_bytes: 1972