akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e3+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }

   void solve() {
	        string s,p="";
	        cin>>s;
	        int q,ct=0;
	        cin>>q;
	          
	        vector<char> v[2];
	        
	        int f=0;
	        rep(i,0,q) {
				   int x,y;
				   char c;
				   cin>>x;
				   if(x==1)				      
					      ct^=1;				   
					   
				   else {
					      cin>>y>>c;
					      --y;
					      v[ct^y].pb(c);					        
			           }			           
				   }
				   
				   for(int i=sz(v[0])-1;i>=0;i--)
				     p+=v[0][i];
				   for(auto to:s)
				     p+=to;
				   for(auto to:v[1])
				     p+=to;    
				     
				     if(ct) reverse(all(p));
				     cout<<p<<endl;				   		   
	   }

    
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	solve();


return 0;	   
}


Measured memory_bytes: 1484
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const bool debug = 0;
//---------------------------------//

int N;
vector<int> g[200];
int col[200];
string S[200];

int solve(int st) {
	memset(col, -1, sizeof(col));
	
	int res = 0;
	col[st] = 0;
	
	queue<int> que;
	que.push(st);
	while (!que.empty()) {
		for (int t = que.size() - 1; t >= 0; t--) {
			int u = que.front(); que.pop();
			
			for (int v : g[u]) {
				if (col[v] != -1) {
					if (col[v] < res - 1) return -1;
					continue;
				}
				que.push(v);
				col[v] = res + 1;
			}
		}
		res++;
	}
	
	REP(i, N) REP(j, N) if (S[i][j] == '1' && col[i] == col[j]) return -1;
	return res;
}


int main() {
	cin >> N;
	REP(i, N) {
		cin >> S[i];
		REP(j, N) if (S[i][j] == '1') g[i].emplace_back(j);
	}
	
	int ans = -1;
	REP(i, N) chmax(ans, solve(i));
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
# https://atcoder.jp/contests/agc018/submissions/2152627
# 写経

from collections import deque
from operator import itemgetter


def solve(n, m, prefers):
    def sub(prefers, canceled):
        ret = [0] * m
        for pref in prefers:
            while canceled[pref[0]]:
                pref.popleft()
            ret[pref[0]] += 1
        return max(enumerate(ret), key=itemgetter(1))

    canceled = [False] * m
    ret = n
    for _ in range(m):
        s, c = sub(prefers, canceled)
        canceled[s] = True
        ret = min(ret, c)
    return ret


if __name__ == '__main__':
    n, m = map(int, input().split())
    prefers = [deque(int(x) - 1 for x in input().split()) for _ in range(n)]
    print(solve(n, m, prefers))


Measured memory_bytes: 4588
#include <stdio.h>
int main(){
  int n;
  int sum=0;
  int v[50];
  int c[50];
  scanf("%d",&n);
  for(int s=0;s<n;s++){
    scanf("%d",&v[s]);
  }
    for(int t=0;t<n;t++){
    scanf("%d",&c[t]);
  }
    for(int i=0;i<n;i++){
    if(v[i]>c[i]){
      sum+= (v[i]-c[i]);
  }
    }
      printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>

void Push(int a[], int sp, int value) {
	a[sp] = value;
}

int Pop(int a[], int sp) {
	int bufsp = sp;
	return a[bufsp];
}

int main() {
	int A[100]; 
	int sp = 0;
	char s[100];
	int buff1, buff2;
	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			sp--;
			buff1 = Pop(A, sp);
			sp--;
			buff2 = Pop(A, sp);
			Push(A, sp, buff1 + buff2);
			sp++;
		}
		else if (s[0] == '-') {
			sp--;
			buff1 = Pop(A, sp);
			sp--;
			buff2 = Pop(A, sp);
			Push(A, sp, buff2 - buff1);
			sp++;
		}
		else if (s[0] == '*') {
			sp--;
			buff1 = Pop(A, sp);
			sp--;
			buff2 = Pop(A, sp);
			Push(A, sp, buff2*buff1);
			sp++;
		}
		else {
			Push(A, sp, atoi(s)); sp++;
		}
	}
	printf("%d\n", A[0]);
	return 0;
}


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

int main()
{
    int A, B;
    long long V, W, T;
    cin >> A >> V >> B >> W >> T;
    bool c = false;
    if (A < B)
    {
        long long A_t = A + T * V, B_t = B + T * W;
        if (A_t >= B_t)
            c = true;
    }
    else
    {
        long long A_t = A - T * V, B_t = B - T * W;
        if (A_t <= B_t)
            c = true;
    }
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

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

	int ans = 0;

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(n <= i * j) break;
			else ans++;
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

const int N=1e5+5;
int n,m,nowx,nowy,a[N],ans[N],tmp[N],tl;

int main()
{
	int i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i) scanf("%d",&a[i]);
	for(i=1;i<=m;++i)
		if(a[i]&1)
		{
			if(nowy) { printf("Impossible\n"); return 0; }
			if(nowx) nowy=i;
			else nowx=i;
		}
	
	if(!nowy&&!nowx);
	else if(!nowy)
	{
		tl=0;
		for(i=1;i<=m;++i) if(a[i]&1) tmp[++tl]=a[i];
		for(i=1;i<=m;++i) if(!(a[i]&1)) tmp[++tl]=a[i];
		for(i=1;i<=m;++i) a[i]=tmp[i];
	}
	else
	{
		tl=0;
		for(i=1;i<=m;++i) if(a[i]&1) { tmp[++tl]=a[i]; break; }
		for(i=1;i<=m;++i) if(!(a[i]&1)) tmp[++tl]=a[i];
		for(i=m;i;--i) if(a[i]&1) { tmp[++tl]=a[i]; break; }
		for(i=1;i<=m;++i) a[i]=tmp[i];
	}
	
	if(m==1)
	{
		printf("%d\n",a[1]);
		if(a[1]>1)
		{
			printf("2\n");
			printf("%d %d\n",1,a[1]-1);
		}
		else
		{
			printf("1\n");
			printf("%d\n",a[1]);
		}
		return 0;
	}
	
	tl=0;
	for(i=1;i<=m;++i) printf("%d ",a[i]);printf("\n");
	if(a[1]>1) ans[++tl]=a[1]-1;
	for(i=2;i<m;++i) ans[++tl]=a[i];
	ans[++tl]=a[m]+1;
	
	printf("%d\n",tl);
	for(i=1;i<=tl;++i) printf("%d ",ans[i]);printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/rope>

using namespace __gnu_pbds; 
using namespace __gnu_cxx;
using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define precision(n) fixed<<setprecision(n)

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}

template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}


template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

 

const int mod = 1e9;
const int N = 3e5 + 5;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 mt(seed);

template <typename T>
long long myrand(T m) {
    long long mod = m;
    long long x = mt()%mod;

    return x;
}

int main() {
    io();
    int n;
    cin >> n;
    for(ll i = -1000; i <= 1000; i++) {
        for(ll j = -1000; j <= 1000; j++) {
            ll x = i * i * i * i * i;
            x -= (j * j * j * j * j);
            if(x == n) {
                cout << i << " " << j;
                return 0;
            } 
        }
    }
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,t; cin>>a>>b>>t;
  cout<<t/a*b<<endl;
}


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int K=in();
    vector<int> H;
    int h;
    REP(i,N){
        cin>>h;
        H.pb(h);
    }
    sort(all(H));
    ll ans=0;
    if(K>=N){
        cout<<0<<endl;
        return 0;
    }else{
        
        REP(i,N-K){
            ans+=H[i];
        }
        cout<<ans<<endl;
        return 0;
    }
}


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

int main() {
	int N, A, B; cin >> N >> A >> B;
	int P, Q[3];
	for(int i=0; i<3; ++i) Q[i]=0;
	for(int i=0; i<N; ++i){
	    cin >> P;
	    if(P<=A) ++Q[0];
	    else if(P>B) ++Q[2];
	    else ++Q[1];
	}
	cout << min(Q[0], min(Q[1], Q[2])) << endl;
	return 0;
}


Measured memory_bytes: 256
// AOJ 0307: Nisshinkan Marathon Club
// 2017.10.31 bal4u@uu

#include <stdio.h>
#include <string.h>

typedef struct { int c, p; } T;
T tbl[1002];
int e[1002], f[1002];

int main()
{
	int n, r, t, i, j, k, ans;

	scanf("%d%d%d", &n, &r, &t);
	for (i = 0; i < n; i++) scanf("%d", &tbl[i].p);
	for (ans = 0, i = 1; i <= t; i++) {
		for (j = 0; j < n; j++) {
			tbl[j].c = k = (tbl[j].c + tbl[j].p) % r;
			if (i > 1) e[k]++;
			if (f[k] > 0) f[k]--;
			else ans++;
		}
		for (j = 0; j < r; j++) {
			if (e[j] > 0) f[j] += e[j], e[j] = 0;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1820
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
    ll k;cin>>k;
    cout<<50<<endl;
    vector<ll> ans(50,49+k/50);

    ll x=k%50;

    for(int i=0;i < 50;i++)
    {
        if(i<x){
            ans[i]+=50-(x-1);
        }else{
            ans[i]-=x;
        }
    }

    rep(i,50){
        cout<<ans[i]<<" ";
    }
}

Measured memory_bytes: 256
// 解説に倣って
#include<bits/stdc++.h>
using namespace std;

int64_t modinv(int64_t a, int64_t m){
  int64_t b=m, u=1, v=0;
  while (b){
    int64_t t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  u%=m;
  if (u<0) u+=m;
  return u;
}

int64_t factorial(int64_t n, int64_t M){
  int64_t ans=1;
  while(n){
    ans=ans*n%M;
    n--;
  }
  return ans;
}

int64_t comb(int64_t n, int64_t r, int64_t M){
  return factorial(n,M)*modinv(factorial(n-r,M),M)%M*modinv(factorial(r,M),M)%M;
}

int64_t calc(int n, int m, int M){
  int64_t ans=0;
  for(int64_t d=1; d<n; d++){
    ans+=d*(n-d)*m*m;
    ans%=M;
  }
  return ans;
}

int main(){
  int M=1e9+7;
  int n,m,k;
  cin>> n >> m >> k;
  
  cout<< (calc(n,m,M)+calc(m,n,M)) * comb(n*m-2,k-2,M) % M <<endl;
}
// 考え方難しかった

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
  int X,N;
  cin>>N>>X;
  int L[N],sum[N];
  int s=0;
  for(int i=0;i<N;i++){
    cin>>L[i];
    s+=L[i];
    sum[i]=s;
  }
  int cnt=1;
  for(int i=0;i<N;i++){
    if(sum[i]<=X){
      cnt++;
    }
  }
  cout<<cnt;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=998244353;
const int MAX=1000010;

vector<vector<ll> >G(100010);
vector<ll>cycle(0);
vector<ll>color(100010,-1);

bool dfs(ll i,ll p){
    bool res=1;
    for(auto e:G[i]){
        if(p==e)continue;
        if(color[e]>=0){
            if(color[i]==color[e]){
                res=0;
                cycle.pb(e);
                break;
            }
            continue;
        }
        color[e]=1-color[i];
        bool d=dfs(e,i);
        res&=d;
        if(res==0)break;
    }
    if(res)return 1;
    else{
        cycle.pb(i);
        return 0;
    }
}

signed main(){
    ll n,m;cin>>n>>m;
    map<pll,ll>v;
    rep(i,m){
        ll a,b;cin>>a>>b;
        ll s;cin>>s;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
        v[mp(a,b)]=s;
        v[mp(b,a)]=s;
    }
    color[0]=0;
    bool f=dfs(0,-1);
    if(f){
        //2部グラフ
        vector<ll>x(n,-inf*inf);
        x[0]=0;
        queue<ll>q;
        q.push(0);
        bool k=1;
        while(!q.empty()){
            ll i=q.front();
            q.pop();
            for(auto e:G[i]){
                ll s=v[mp(i,e)];
                if(x[e]!=-inf*inf){
                    if(x[e]+x[i]!=s)k=0;
                    continue;
                }
                x[e]=s-x[i];
                q.push(e);
            }
        }
        ll ma=inf*inf;
        ll mi=-inf*inf;
        rep(i,n){
            if(color[i]){
                ma=min(ma,x[i]-1);
            }else{
                mi=max(mi,1-x[i]);
            }
        }
        ll ans=max(0LL,ma-mi+1);
        if(!k)ans=0;
        cout<<ans<<endl;
    }else{
        ll d=0;
        ll c=cycle[0];
        rep(i,cycle.size()){
            if(i%2==0){
                d+=v[mp(cycle[i],cycle[i+1])];
            }else{
                d-=v[mp(cycle[i],cycle[i+1])];
            }
            if(cycle[i+1]==c)break;
        }
        ll ans;
        if(d<=0||d%2==1){
            ans=0;
        }else{
            ans=1;
            vector<ll>x(n,-inf*inf);
            x[c]=d/2;
            queue<ll>q;
            q.push(c);
            while(!q.empty()){
                ll i=q.front();
                if(x[i]<=0)ans=0;
                q.pop();
                for(auto e:G[i]){
                    ll s=v[mp(i,e)];
                    if(x[e]!=-inf*inf){
                        if(x[e]+x[i]!=s)ans=0;
                        continue;
                    }
                    x[e]=s-x[i];
                    q.push(e);
                }
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 30564
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    [h, w] <- map read.words <$> getLine :: IO [Int]
    m <- B.concat <$> replicateM h B.getLine
    print $ solve h w m

inf :: Int
inf = 0x3f3f3f3f

solve :: Int -> Int -> B.ByteString -> Int
solve h w bs
    | dist == inf = -1
    | otherwise = h * w - numBlock - dist
  where
    numBlock = B.length$B.filter(== '#')bs
    isOK (x, y) = B.index bs (x*w+y) == '.'
    idx ::Int -> Int -> Int
    idx x y = x * w + y
    inBoard (x,y) = 0<=x&&x<h&&0<=y&&y<w
    neighbors x y=filter inBoard[(x+1,y),(x-1,y),(x,y+1),(x,y-1)]
    dist = runST $ do
        d <- UM.replicate (h*w) inf
        let bfs ((x,y):fs) rs = do
                dxy <- UM.unsafeRead d (idx x y)
                forM_ (filter isOK $ neighbors x y) $ \(nx,ny) -> do
                    dnxny <- UM.unsafeRead d (idx nx ny)
                    if dxy + 1 < dnxny
                    then do
                            UM.unsafeWrite d (idx nx ny) $ dxy + 1
                            bfs fs ((nx,ny):rs)
                    else bfs fs rs
            bfs [] [] = return ()
            bfs [] rs = bfs (reverse rs) []
        UM.unsafeWrite d (idx 0 0) 1
        bfs [(0,0)] []
        UM.unsafeRead d (idx (h-1) (w-1))



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

int main()
{
	int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  int c=0;
  for(int i=1;i+1<n;i++)
  {
    if((a[i]>a[i-1] && a[i]<a[i+1])  or (a[i]<a[i-1] && a[i]>a[i+1]))
      c++;
  }
	cout<<c;
  return 0;
}

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

int main(){
  int n, q;
  string s;
  cin >> n >> q >> s;
  vector<pair<int, int>>p(q);
  for(int i=0; i<q; ++i){
    cin >> p[i].first >> p[i].second;
  }
  
int dp[n];
for(int i=0; i<n; ++i){
  dp[i]=0;
}

 for(int i=0; i<n; ++i){
   if(s[i]=='A' && s[i+1]=='C')
     dp[i+1]=dp[i]+1;
   else
     dp[i+1]=dp[i];
   
 }
 for(int i=0; i<q; ++i){
   cout << dp[p[i].second-1]-dp[p[i].first-1] << endl;
 }
}

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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]= {-1,0,1,-1,1,-1,0,1};
//int dy[]= {1,1,1,0,0,-1,-1,-1};




LL a[200005];
LL cnt[200005];

int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    set<LL>st;
    int i,n;
    LL ans=0;
    cin >> n;
    for(i=0;i<n;i++)cin >> a[i],++cnt[a[i]],st.insert(a[i]);
    for(LL x : st)ans+=(cnt[x]*(cnt[x]-1LL))/2LL;
    for(i=0;i<n;i++)cout << ans-cnt[a[i]]+1LL << '\n';
    return 0;
}


Measured memory_bytes: 10624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a == b) {
			System.out.println("Draw");
		} else if(a == 1) {
			System.out.println("Alice");
		} else if(b == 1) {
			System.out.println("Bob");
		} else {
			if(a > b) {
				System.out.println("Alice");
			} else {
				System.out.println("Bob");
			}
		}
	}
}



Measured memory_bytes: 35696
x,y=map(int,input().split())
if x < y: x, y = y, x
while x % y != 0:
    x, y = y, x % y
ans=1
for i in range(2,int(y**0.5)+1):
    if y%i==0:
        ans+=1
        while y%i==0:
            y//=i
if y>1:ans+=1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
#include<functional>
#include<list>
#include<bitset>
#include<numeric>
#include<utility>
#define INF (int)1e9
#define MOD 1000000007
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> p;

struct unionfind {
	// 親ノードと木の高さ
	// rankは根のindexに対してのみ意味を持つ
	vector<int> par, rank;
	unionfind(int n) {
		par = vector<int>(n);
		rank = vector<int>(n, 0);
		for (int i = 0; i < n; i++) {
			par[i] = i;
		}
	}
	int root(int i) {
		if (par[i] == i) {
			return i;
		}
		return par[i] = root(par[i]);
	}
	bool same(int i, int j) {
		return root(i) == root(j);
	}
	void unite(int i, int j) {
		int ri = root(i);
		int rj = root(j);
		if (ri == rj) {
			return;
		}
		// 高さが高い方の木の根を低い方の根の親とする
		// 高さが同じ場合は最終的な親の高さがプラス1
		if (rank[ri] < rank[rj]) {
			par[ri] = rj;
			return;
		}
		par[rj] = ri;
		if (rank[ri] == rank[rj]) {
			rank[ri]++;
		}
	}
};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	unionfind u = unionfind(n);
	int x, y;
	for (int i = 0; i < m; i++) {
		cin >> x >> y;
		x--;
		y--;
		u.unite(x, y);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (u.same(p[i], i)) {
			ans++;
		}
	}
	cout << ans;
}





// 解説AC

Measured memory_bytes: 1408
#include<cstdio>
#include<cstring>
#define inlien inline
#define retrun return
#define cpnst const
int n,m;
int a[111];
bool v[222222];
typedef long long ll;
const ll mod=1e9+7;
ll F[22][222222],fac[222222],inv[222222];
inline ll qpow(ll x,ll k)
{ll r=1;for(;k;k>>=1,(x*=x)%=mod)if(k&1)(r*=x)%=mod;return r;}
inline ll C(ll n,ll r)
{return fac[n]*inv[r]%mod*inv[n-r]%mod;}
int bit[222222];
int main()
{
	scanf("%d%d",&n,&m);
	int k=1<<n;
	register int i,ii,iii,iiii;
	fac[0]=1;
	for(i=1;i<=200000;i++)fac[i]=fac[i-1]*i%mod;
	for(i=199999,inv[i+1]=qpow(fac[i+1],mod-2);~i;i--)
		inv[i]=inv[i+1]*(i+1)%mod;
	for(i=1;i<=m;i++)
		scanf("%d",a+i),v[a[i]]=1;
	F[m][0]=1;
	for(i=1;i<k;i++)bit[i]=bit[i>>1]+(i&1);
	for(i=k,ii=m-1;i>1;i--)
	{
		if(v[i])
		{
			for(iii=0;iii<k;iii++)
			{
				for(iiii=0;iiii<n;iiii++)
				{
					if((1<<iiii)&iii)continue;
					int S=(1<<iiii)|iii,sz=k-i+1,rm=sz-S;
					if(rm<0)continue;
					ll sel=fac[(1<<iiii)]*C(rm+(1<<iiii)-1,rm)%mod;
					(F[ii][S]+=F[ii+1][iii]*sel)%=mod;
				}(F[ii][iii]+=F[ii+1][iii])%=mod;
			}ii--;
		}
	}ll ans=0;
	for(i=0;i<k;i++)
		(F[0][i]*=fac[k-i-1])%=mod,(bit[i]&1)?ans-=F[0][i]:ans+=F[0][i];
	((ans%=mod)*=k)%=mod,printf("%lld\n",(ans+mod*mod)%mod);
}
/*
Giving the world a better yourself is giving yourself a better world. 
*/

Measured memory_bytes: 32384
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%d",&a)
#define sf2(a,b) scanf("%d %d",&a,&b)
#define sf3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pf2(a,b) printf("%d %d",a,b)
#define pf3(a,b,c) printf("%d %d %d",a,b,c)
#define sfl(a) scanf("%lld",&a)
#define sfl2(a,b) scanf("%lld %lld",&a,&b)
#define sfl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pfl(a) printf("%lld",a)
#define pfl2(a,b) printf("%lld %lld",a,b)
#define pfl3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
#define tz 100000
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
main()
{
    timesave;
    int a,b;
    while(cin>>a>>b)
    {
        if(a*500<b)
            cout<<"No"<<endl;
        else
            cout<<"Yes"<<endl;
    }
}





Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  int cnt;
  
  cnt = scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  int cnt;
  
  cnt = scanf("%lld %lld", n, k);

  return;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;


int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}

int main()
{
  int cnt;
  int64 A, B;
  int64 unused = 1;
  int64 taps = 0;
  int result = 0;

  get_NK(&A, &B);

  while (unused < B) {
    unused--;
    taps++;
    unused += A;
  }

  printf("%lld", taps);

  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pp pair<ll,ll>
#define vi vector<pair<pp,pp> >
#define pq_min priority_queue<ll,vector<ll>,greater<ll> >
#define pq_max priority_queue<ll>
#define forx(i,a,b) for(ll i=0;i<a;i++)
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair<pp,pp> ppll;
const ll mod=1e9 + 7;

string s;
ll k;
ll dp[100][4][2]; // dp[pos][check][count]
vector<ll> num;
ll call(ll pos,ll check,ll cnt)
{
	if(cnt>k) return 0;
	
	if(pos==num.size())
	{
		if(cnt==k) return 1;
		return 0;
	}
	
	if(dp[pos][cnt][check]!=-1) return dp[pos][cnt][check];
	
	ll res=0;
	ll limit;
	
	if(check==0) //digits we places so far is matches with the prefix of b (boundry)
	{
		 // so we place max digit is b[pos]
		 limit=num[pos];
	}
	else // the number is already become smaller than b so we can put any digit
	{
		limit=9;
	}
	
	/* Direct use range between a and b:
	ll l=0,r=9;
	
	if(big==0) l=xx[pos];
	if(small==0) r=yy[pos];
	
	for(ll i=l;i<=r;i++)
	{
		ll nbig=big;
		ll nsmall = small;
		
		if(i>l) nbig=1;
		if(i<r) nsmall=1;
	}
	*/
	
	for(ll digit = 0 ; digit <= limit ;digit++)
	{
		ll ncheck = check;
		ll ncnt = cnt;
		if(check==0 && digit < limit) ncheck=1; // the number is getting smaller at this position
		
		if(digit>0) ncnt++;
		if(ncnt <= k) res += call(pos+1 , ncheck , ncnt);
	}
	return dp[pos][cnt][check]=res;
}


ll solve()
{
	num.clear();
	for(ll i=0;i<s.length();i++)
	{
		num.pb(s[i]-'0');
	}
	memset(dp,-1,sizeof(dp));
	ll res=call(0,0,0);
	return res;	
}

int main()
{
	cin>>s>>k;
    ll res=solve();
    cout<<res;
	return 0;
}

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

int main() {
	int bn, len, ans = 0;
	vector<int> nums;
	cin >> len;
	for (int i = 0; i < len; i++) {
		cin >> bn;
		nums.emplace_back(bn);
	}
	for (int j = 1; j < len - 1; j++) {
		if ((nums[j - 1] < nums[j] && nums[j] < nums[j + 1]) || (nums[j - 1] > nums[j] && nums[j] > nums[j + 1])) {
			ans++;
		}
	}
	cout << ans;
}

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

int main(){
    int n,d,x;
    int a[101];
    int sum = 0;
    cin >> n >> d >> x;
    for(int i = 1;i<=n;i++){
        cin >> a[i];
        sum += ceil(1.0 * d / a[i]);
    }
    sum += x;
    cout << sum << endl;
}

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

int main() { 
	int N;
	vector<int> X,Y;

	cin >> N;
	for (int i = 0; i < N; i++) {
		int x; cin >> x; X.push_back(x); Y.push_back(x);
	}

	sort(X.begin(), X.end());

	for(int i=0;i<N;i++){
		if (Y.at(i) <= X.at(N / 2 -1)) {
			cout << X.at(N / 2 ) << endl;
		}
		else {
			cout << X.at(N / 2 - 1) << endl;
		}
	}

	return 0; 
}

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

using namespace std;
typedef long long int ll;
#define LL_HALFMAX 9223372036854775807 / 2	

int main()
{
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n);
    for(ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll result = LL_HALFMAX;
    ll addcost = 0;
    for(ll bit = 0; bit <(1<<n); bit++)
    {
        ll cost = 0;
        ll look = 0;
        ll hmax = a[0] - 1;
        for(ll i = 0; i < n; i++)
        {
            if(a[i] > hmax)
            {
                hmax = a[i];
                look++;
            }
            else if(bit&(1<<i))
            {
                addcost = hmax - a[i] + 1;
                look++;
                hmax += 1;
                cost += addcost;
            }
        }
        if(look >= k)
        {
            result = min(result,cost);
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 3596
import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)

N, K = map(int,input().split())
mod = 10**9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

ans = 0

#M = np.zeros(K+1, dtype=int)
M = [0 for _ in range(K+1)]

for i in range(K, 0, -1):
#    print(i)
    M[i] += pow(K//i, N, mod)
    
    for j in range(2,K//i+1):
        j *= i
        M[i] -= M[j]
        M[i] %= mod
    
    ans += (M[i] * i) % mod
    ans %= mod
    
print(ans)

Measured memory_bytes: 29400
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <math.h>
#include <bitset>
#include <queue>

using namespace std;

void solve() {
    int p, q, r;
    cin >> p >> q >> r;
    int minm = 10000;
    minm = min(minm, p + q);
    minm = min(minm, r + q);
    minm = min(minm, r + p);
    cout << minm;
}

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

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

int main() {
  int N;
  cin >> N;
  vector<long int> T(N),A(N),B(N);
  for (int i=0;i<N;i++) {
    cin >> T.at(i) >> A.at(i);
  }
  for (int i=0;i<N-1;i++) {
    B.at(i+1) = max( (T.at(i)-1) / T.at(i+1) , (A.at(i)-1) / A.at(i+1)) + 1;
    T.at(i+1) = T.at(i+1) * B.at(i+1);
    A.at(i+1) = A.at(i+1) * B.at(i+1);
  }
  cout << T.at(N-1) + A.at(N-1) << endl;
}

Measured memory_bytes: 256
# ABC 133: B – Good Distance
N, D = [int(s) for s in input().split()]
X = [[int(s) for s in input().split()] for _ in range(N)]

count = 0

for i in range(N):
    for j in range(i + 1, N):
        distance = (sum([(X[i][k] - X[j][k]) ** 2 for k in range(D)])) ** 0.5
        if distance ** 2 == (int(distance)) ** 2:
            count += 1

print(count)

Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

vector<int> G[200200],V[200200];
int N,M; char S[200200];
int C[2][200200],U[200200],K[200200];

int main()
{
	scanf ("%d %d",&N,&M);
	scanf ("%s",S+1);

	for (int i=0;i<M;i++){
		int x,y; scanf ("%d %d",&x,&y);
		C[S[x]-'A'][y]++;
		C[S[y]-'A'][x]++;
		G[x].push_back(y);
		G[y].push_back(x);
	}

	queue<int> Q;
	for (int i=1;i<=N;i++) if (C[0][i] == 0 || C[1][i] == 0){
		Q.push(i); K[i] = 1;
	}
	while (!Q.empty()){
		int x = Q.front(); Q.pop();
		for (auto &y : G[x]) if (C[0][y] && C[1][y] && K[y] == 0){
			C[S[x]-'A'][y]--;
			C[S[y]-'A'][x]--;
			if (C[0][y] == 0 || C[1][y] == 0){
				Q.push(y); K[y] = 1;
			}
		}
	}

	int ans = 0;
	for (int i=1;i<=N;i++) if (K[i]) ans++;
	puts(ans<N?"Yes":"No");
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=1'000'000'007;
const double EPS=1e-14;
const bool DEBUG=true;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////


void answer(){
    int a;
    cin>>a;
    if(a==0){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }

    return;
}

/////

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.precision(16);

    answer();

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define szof(s) (int)s.size()
#define all(s) s.begin(), s.end()
#define pii pair<int, int>
#define all(s) s.begin(), s.end()
#define prev myrza4321
#define y1 myrza1234
#define OK() puts("OK")
using namespace std;

const int N = (int)1e5 + 5;
const int INF = (int)1e9 + 7;

main() {
  int a, b;
  cin >> a >> b;
  for (int i = 1; i <= 2000; i++) {
    double da = i;
    double db = i;
    da *= 0.08;
    db *= 0.1;
    da = (int)da;
    db = (int)db;
    if (da == a && db == b) {
      return cout << i, 0;
    }
  }
  cout << -1;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

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

typedef long long ll;

int main() {
	//入力;
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a * b) / 2 << endl;

	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
ll n, m, t, a[100005];
vector< ll > adj[100005];
#define ari for( int i = 0 ; i < n ; i++ ) cin >> a[i];
#define ginp for( int i = 0 ; i < m ; i++ ){ int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u);}

int main(){
	cin >> n;
	string s;
	while( n ){
		if( n % 26 )
			s.push_back( (char)( 96 + n % 26 ));
		else{
			s.push_back('z');
			n--;
		}
		n = n / 26;
	}
	for(int i = (int)s.size() - 1 ; i > -1 ; i--)
		cout << s[i];
	cout << endl;
	return(0);
}

Measured memory_bytes: 5968
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define krep(n) for(ll k=0;k<(n);k++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 1000000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } 

void solve(ll ts){
    ll a,b,c,d; cin>>a>>b>>c>>d;
    cout<<max({a*c,a*d,b*c,b*d})<<endl;
} 

//
int main(){
    ffast
    ll t=1;
//    cin>>t;
    rep(t) solve(i+1);
}
 
 
// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)

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

using namespace std;
using ll=long long;
using vi=vector<int>;

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

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n;cin>>n;
  vi vec(n);
  Inparray(vec,n);
  int ans=0;
  rep(i,n) ans+=vec[i]-1;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7

N = int(input())

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

# import random
# N = 200_000
# A = [random.randint(1, 2000) for i in range(N)]

res = 0

cum_sum = sum(A)

for i in range(N - 1):
    cum_sum -= A[i]
    res += (A[i] * cum_sum) % MOD

res %= MOD

print(res)

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

int main(){ 
  string s, t;
  cin >> s >> t;
  s += s;
  int n = sz(t);
  bool ok = false;
  for (int i = 0; i < n; i++) {
    bool tmp = true;
    for (int j = i; j < i+n; j++) {
      if (s[j] != t[j-i]) tmp = false;
    }
    ok |= tmp;
  }
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
} 

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


int main() {
    string S;
    Int N;
    cin >> S;
    N = S.size();

    vector<string> s(4);
    s[0] = "maerd";
    s[1] = "remaerd";
    s[2] = "esare";
    s[3] = "resare";

    reverse(S.begin(),S.end());

    while(S.size() > 0) {
        bool flag = false;
        rep (i,4) {
            if (S.substr(0,s[i].size()) == s[i]) {
                flag = true;
                S = S.substr(s[i].size());
                break;
            }
        }
        if (!flag) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

signed main(){
	cout<<fixed<<setprecision(7);
	
	int n, h, w, x, ans = 0;
	int temp[110000] = {};
	
	cin>>n>>h>>w;
	
	
	for(int i = 0; i < n; i++){
		cin>>x;
		int t = w*i;
		if(i%2){
			t -= x;
			for(int j = 0; j < w; j++){
				if(t+j >= 0)temp[t+j] = true;
			}
		} else {
			t += x;
			for(int j = 0; j < w; j++){
				if(t+j <= n*w)temp[t+j] = true;
			}	
		}
	}
	for(int i = 0; i < w*n; i++){//cout<<i<<" "<<temp[i]<<endl;
		ans += !temp[i];
	}
	// cout<<h<<" "<<ans<<endl;
	cout<<h*ans<<endl;
	
	return 0;
}


Measured memory_bytes: 3964
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    double a,b,t;cin >> a >> b >> t;
    int time = (t+0.5)/a;
    cout << b*time << endl;
}


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



int main(){
    int x;cin>>x;
    bool f = false;
    rep(i,-200,200){
        rep(j,-200,200){
            if (pow(i,5)-pow(j,5)==x){
                cout<<i<<" "<<j<<endl;
                f = true;
            }
        }
        if (f) break;
    }
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define dd double
#define ld long double
#define f(i,a,b) for(ll i = a; i < b; i++)
#define fr(i,a,b) for(ll i = b;i>=a;i--)
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define vpll vector< pii >
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define Sort(v) sort(v.begin(), v.end(), sortbysec)
#define MEM(a, b) memset(a, (b), sizeof(a))

ll power(ll x, ll y, ll p)  
{  
    ll res = 1;      
    x = x % p; 
                
    while (y > 0)  
    {   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}  

 

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

ll n;
cin>>n;

if(n%1000)
cout<<1000-n%1000<<endl;
else
cout<<0<<endl;




}


Measured memory_bytes: 3560
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	double a;
	cin >> a;

	double b = a / 3.0;

	printd(b * b * b, 12);
}


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

using namespace std;

int main()
{
	int a[3];

	for (int i = 0; i < 3; i++)
	{
		cin >> a[i];
	}

	sort(a, a + 3);

	for (int i = 0; i < 3; i++)
	{
		cout << (i == 0 ? "" : " ") << a[i];
	}

	cout << endl;
}


Measured memory_bytes: 3052
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int a;
	cin>>a;
	if( a<1200){
		cout<<"ABC"<<endl;
	}
	else if(a < 2800){
		cout<<"ARC"<<endl;
	}
	else{
		cout<<"AGC"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, a, n) for (int i = a; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eps 1e-15

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef tuple<int, int, int> ti3;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

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 main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;

	//nをm個に分けたときそれぞれの個数のgcdの最大値

	for (int i = m / n; i >= 1; --i) {
		if (m % i == 0) {
			dunk(i);
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256