akhauriyash/Code-Regression huggingface dataset:
n,a,b = map(int,input().split())

def ceil(a, b):
   return a // b + (a % b > 0)

if (a - b) % 2 == 0:
   print((b-a) // 2)
else:
   x = a - 1
   y = n - b
   p1 = x + ceil(b-a, 2)
   p2 = y + ceil(b-a, 2)
   print(min(p1,p2))

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 1000001;

int N;
str S;
// R, G, B
int a[3][4000];
ll ans;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> N >> S;
    
    F0R(i, N) {
        if (S[i] == 'R') a[0][i]++;
        else if (S[i] == 'G') a[1][i]++;
        else a[2][i]++;
        if (i > 0) {
            F0R(j, 3) a[j][i] += a[j][i - 1];
        }
    }
    
    F0R(i, N) {
        FOR(j, i + 1, N) {
            char fC = S[i], sC = S[j];
            if (sC < fC) swap(fC, sC);
            if (fC == sC) continue;
            if (fC == 'B' && sC == 'G') {
                ans += a[0][N - 1] - a[0][j];
                int diff = j - i;
                if (j + diff < N && S[j + diff] == 'R') ans--;
            } else if (fC == 'B' && sC == 'R') {
                ans += a[1][N - 1] - a[1][j];
                int diff = j - i;
                if (j + diff < N && S[j + diff] == 'G') ans--;
            } else {
                ans += a[2][N - 1] - a[2][j];
                int diff = j - i;
                if (j + diff < N && S[j + diff] == 'B') ans--;
            }
        }
    }
    cout << ans;
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 3684
#include<stdio.h>

int main()
{
    int a, b, i, j;
    
    while(1){
        scanf("%d%d", &a, &b);

	if(a ==0 && b ==0) break;

        for(i =1; i <=a;i++){
            if(i == 1 || i == a){
                for(j=1; j <b;j++) printf("#");
                printf("#\n");
                }
            else {for(j=1;j <= b; j++){
                      if(j == 1) printf("#");
                      else if(j == b) printf("#\n");
                      else printf(".");   
                } 
            }
        }printf("\n");

    }
    return 0;
}


Measured memory_bytes: 1924
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

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

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 )




X, Y = map(int, input().split())

if (X + Y) % 3 != 0 or 2*Y < X or Y > 2*X:
    ans = 0
else:
    n = (X+Y) // 3
    r = X - n

    ans = cmb(n, r, mod)

print(ans)

Measured memory_bytes: 122016
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
ll n,m,i,a,b,maxi,j,dp[1005][1005];
string str[1005];
ll dfs(ll x,ll y)
{
	if(x==n||y==m)
		return 0;
	if(dp[x][y]!=-1)
		return dp[x][y];
	if(x==n-1&&y==m-1)
		return 1;
	if(str[x][y]=='#')
		return 0;
	dp[x][y]=(dfs(x,y+1)%MOD+dfs(x+1,y)%MOD)%MOD;
	return dp[x][y];
}

int main()
{
	cin>>n>>m;
	for(i=0;i<n;i++)
		cin>>str[i];
	memset(dp,-1,sizeof(dp));
	cout<<dfs(0,0)%MOD;
	return 0;
}

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

// 辞書式に並べる
int num(int n, int p[]) {
	int ans = 0, i, j;
	for (i = 0; i < n - 1; i++) {
		for (j = i; j < n; j++)
			if (p[i] > p[j])
				ans++;
		ans *= n - i - 1;
	}
	return ans;
}

int main(void) {
	int N;
	int P[8], Q[8];
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%d", &P[i]);
	for (int i = 0; i < N; i++)
		scanf("%d", &Q[i]);
	printf("%d", abs(num(N, P) - num(N, Q)));

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  map<int, int> m;
  REP(i, N) m[A[i]]++;

  map<int, int> cnt1;
  map<int, int> cnt2;
  int sum = 0;
  for(auto p : m){
    cnt1[p.first] = p.second*(p.second-1)/2;
    cnt2[p.first] = (p.second-2)*(p.second-1)/2;
    sum += cnt1[p.first];
  }

  REP(i, N){
    cout << sum-cnt1[A[i]]+cnt2[A[i]] << endl;
  }

  return 0;
}

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

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main(){
    int n, m; cin >> n >> m;
    Graph g(n);
    for(int i=0; i<m; ++i){
        int a, b; cin >> a >> b; a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    seen.resize(n);
    seen.assign(n, false);
    int cnt = 0;  int size = 0;
    for(int i=0; i<n; ++i){
        if(seen[i]){continue;}
        dfs(g, i);
      	//for(int j=0; j<n; ++j){cout << seen[i] << ",";} cout << endl;
      	
      	for(int j=i; j<n; ++j){
            if(seen[j]){size++;} //cout << i << "," << j << "," << size << endl;
        	else{break;}
        }
      	if(size!=n){cnt++;}
    }
   // cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 9504
#include<cmath>
#include<cstdio>
#include<complex>

using namespace std;

typedef	complex<double> P;

int main(){
	for(int n,d;scanf("%d%d",&n,&d),n;){
		P cen(0,0),v(0,1);

		for(int i=0;i<n;i++){
			int ls,rs,t;	scanf("%d%d%d",&ls,&rs,&t);
			double larc=2*M_PI*abs((double)ls)*t/360;
			double rarc=2*M_PI*abs((double)rs)*t/360;

			if(ls==rs){	// go straight/back
				if(ls>0)		cen+=larc*v;
				else if(ls<0)	cen-=larc*v;
			}
			else{
				P rotc;
				double theta;

				P u=v*P(0,-1);
				if(ls==0){
					rotc=cen-(double)d*u;
					if(rs>0)	theta=rarc/(2*d);
					else		theta=-rarc/(2*d);
				}
				else if(rs==0){
					rotc=cen+(double)d*u;
					if(ls>0)	theta=-larc/(2*d);
					else		theta=larc/(2*d);
				}
				else if(ls*rs>0){
					if(larc>rarc){
						double x=2*d*rarc/abs(larc-rarc);
						rotc=cen+(d+x)*u;
						if(ls>0)	theta=-rarc/x;
						else		theta=rarc/x;
					}
					else{	// rarc>larc
						double x=2*d*larc/abs(larc-rarc);
						rotc=cen-(d+x)*u;
						if(rs>0)	theta=larc/x;
						else		theta=-larc/x;
					}
				}
				else{	// ls*rs<0
					double x=2*d*rarc/(larc+rarc);
					rotc=cen+(d-x)*u;
					if(ls>0)	theta=-rarc/x;
					else		theta=rarc/x;
				}

				cen=(cen-rotc)*exp(P(0,theta))+rotc;
				v*=exp(P(0,theta));
			}
		}

		printf("%.9f\n%.9f\n",cen.real(),cen.imag());
	}

	return 0;
}

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

int main(){
    int N,M,Q; cin >> N >> M >> Q;
    vector<int> a(Q),b(Q),c(Q),d(Q);
    rep(i,0,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }

    ll ans = 0;
    for(ll bit=0; bit < (1<<M); ++bit){
        ll sum = 0;
        int p = __builtin_popcount(bit);
        if(p == N){
            vector<int> A;
            rep(i,0,M){
                if(bit & (1<<i)) A.push_back(i+1);
            }
            rep(i,0,Q){
                if(A[b[i]] - A[a[i]] == c[i]) sum += d[i];
            }
            ans = max(ans,sum);

        }else if(p < N){
            vector<int> v;
            rep(i,0,M){
                if(bit & (1<<i)) v.push_back(i+1);
            }
            rep(i,0,M){
                if(bit & (1<<i)) v.push_back(i+1);
            }

            vector<int> A(N);
            // 考え得るかぎりのA(N)を作って、sumを全探索
            for(ll mask = 0; mask < (1<<N); ++mask){
                if(__builtin_popcount(mask) == p-1){
                    int x = 0;
                    rep(i,0,N){
                        if(x == p) break;
                        A[i] = v[x];
                        if(mask & (1<<i)) x++; 
                    }
                    rep(i,0,Q){
                        if(A[b[i]] - A[a[i]] == c[i]) sum += d[i];
                    }
                    ans = max(ans,sum);
                    sum = 0;
                }
            }
            
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3564
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

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

    int n, k;
    cin >> n >> k;

    modint ans = modint(k).pow(n);
    vector<modint> cnt(k + 5);
    for(int i = k; i > 1; --i){
        modint foo = modint(k / i).pow(n);
        for(int j = 2 * i; j <= k; j += i){
            foo -= cnt[j];
        }
        cnt[i] = foo;
        ans -= foo;
        ans += modint(i) * foo;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define ri register int
using namespace std;
const int rlen = 1 << 20 | 5;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() (((ib == ob) && (ob = (ib = buf) + fread(buf, 1, rlen, stdin))), ib == ob ? -1 : *ib++)
#define pb push_back
#define rez resize
#define ppp pop_back
inline int read() {
  static int ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
inline int Read(char *s) {
  static int top;
  static char ch;
  for (ch = gc(), top = 0; !isalpha(ch); ch = gc());
  while (isalpha(ch)) s[++top] = ch, ch = gc();
  return top;
}
typedef long long ll;
typedef pair <int, int> pii;
#define fi first
#define se second
inline ll readl() {
  static ll ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
template <typename T> inline void exgcd(T a, T b, T &x, T &y) {
  if (!b) { x = 1, y = 0; return; }
  exgcd(b, a - a / b * b, y, x), y -= a / b * x;
}
namespace modular {
  const int mod = 998244353;
  int ret;
  inline int add(int a, int b) { return a < mod - b ? a + b : a - mod + b; }
  inline int dec(int a, int b) { return a < b ? a - b + mod : a - b; }
  inline int mul(int a, int b) { return (ll) a * b % mod; }
  inline void Add(int &a, int b) { a = a < mod - b ? a + b : a - mod + b; }
  inline void Dec(int &a, int b) { a = a < b ? a - b + mod : a - b; }
  inline void Mul(int &a, int b) { a = (ll) a * b % mod; }
  inline int ksm(int a, int p) { for (ret = 1; p; p >>= 1, Mul(a, a)) (p & 1) && (Mul(ret, a), 1); return ret; }
  inline int fix(int x) {
    x <= -mod || x >= mod ? x %= mod : 0;
    return x < 0 ? x + mod : x;
  }
  inline int Inv(int a) {
    static int x, y;
    return exgcd(a, mod, x, y), fix(x);
  }
}  using namespace modular;
int a1 = 0, b1 = 0, a2 = 1000000000, b2 = 1, a3, b3;
ll S;
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  S = readl();
  a3 = a2 - ((S - 1) % a2 + 1);
  b3 = (S - 1) / a2 + 1;
  cout << a1 << ' ' << b1 << ' ' << a2 << ' ' << b2 << ' ' << a3 << ' ' << b3 << '\n';
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  prllf("%d",x);
#define pl(x)  prllf("%lld",x);
#define pf(x)  prllf("%.10lf",x);
#define ps(x)  prllf("%s",x);
#define en() prllf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

int main()
{

  ll a,b,c;
  cin>>a>>b>>c;
  ll temp=min(a,c);
  a-=temp;
  c-=temp;
  ll temp2=min(b,c);
  b-=temp2;
  c-=temp2;
  cout<<a<<" "<<b<<endl;


}


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

int main() {
  int n,k;
  cin >> n >> k;
  int64_t ans=k;
  rep(i,n-1)
    ans *=(k-1);
  cout << ans << endl;
    
}

Measured memory_bytes: 256
N = int(input())
H = [int(x) for x in input().split()]
ans = 0
if N == 1:
  print('Yes')
else:
  for i in reversed(range(1, N)):
    if H[i] - H[i - 1] == -1:
      H[i - 1] -= 1
    elif H[i] - H[i - 1] <= -2:
      ans += 1
      break
  if ans == 1:
    print('No')
  else:
    print('Yes')

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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
#define int long long
//#define double long double

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

    int n = 100, x, ans = 1;
    cin >> x;
    while (true)
    {
        n += n / 100;
        if (n >= x)
            cout << ans << '\n', exit(0);
        ans++;
    }

    return 0;
}

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

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


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    int N; cin >> N;
    string S1; string S2;
    cin >> S1;
    cin >> S2;

    int A[N] = {0}; 
    int count = 0;

    for (int i = 0; i < N; i++) {
        if (S1[i] == S2[i]) {
            A[count++] = 1;
        } else {
            A[count++] = 2; i++;
        }
    }
    ll ans;
    if (A[0] == 1) ans = 3;
    else ans = 6;
    for (int i = 1; i < count; i++) {
        if (A[i-1] == 1 && A[i] == 1) ans *= 2;
        if (A[i-1] == 2 && A[i] == 1) ans *= 1;
        if (A[i-1] == 1 && A[i] == 2) ans *= 2;
        if (A[i-1] == 2 && A[i] == 2) ans *= 3;
        ans = ans % mod;
    }
    cout << ans << endl;
    return 0;
}

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

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

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

int H,W;
V<V<char>> m;

int bfs() {

    int cnt = 0;
    queue<int> x, y, c;
    REP(i,H) REP(j,W) {
        if(m[i][j] == '#') {
            y.push(i);
            x.push(j);
            c.push(0);
            cnt++;
        }
    }

    if(cnt == H*W) {
        return 0;
    }

    while(!x.empty()) {
        int cy = y.front(); y.pop();
        int cx = x.front(); x.pop();
        int cc = c.front(); c.pop();
        REP(i,4) {
            int ny = cy + dy[i];
            int nx = cx + dx[i];
            if(!IN(0,ny,H) || !IN(0,nx,W)) continue;
            if(m[ny][nx] == '#') continue;
            m[ny][nx] = '#';
            y.push(ny);
            x.push(nx);
            c.push(cc+1);
            cnt++;
            if(cnt == H*W) {
                return cc+1;
            }
        }
    }

    return -1;
}

int main(){
    INIT;
    cin >> H >> W;
    m.resize(H);
    REP(i,H) {
        REP(j,W) {
            char c; cin >> c;
            m[i].push_back(c);
        }
    }

    cout << bfs() << "\n";
}

Measured memory_bytes: 13568
#ifndef CLASS_MODINT
#define CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::int64_t n_) : n((n_ >= 0 ? n_ : mod - (-n_) % mod) % mod) {};
	static constexpr std::uint32_t get_mod() { return mod; }
	std::uint32_t get() const { return n; }
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint inv() const { return (*this).pow(mod - 2); }
	modint pow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
};

#endif // CLASS_MODINT

#include <vector>
#include <iostream>
#include <functional>
using namespace std;
using modulo = modint<1000000007>;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, pA, pB, pC;
	cin >> N >> pA >> pB >> pC;
	vector<modulo> fact(2 * N + 1), inv(2 * N + 1), factinv(2 * N + 1);
	fact[0] = 1; inv[1] = 1; factinv[0] = 1;
	for (int i = 1; i <= 2 * N; ++i) fact[i] = fact[i - 1] * i;
	for (int i = 2; i <= 2 * N; ++i) inv[i] = inv[modulo::get_mod() % i] * modulo(-int(modulo::get_mod() / i));
	for (int i = 1; i <= 2 * N; ++i) factinv[i] = factinv[i - 1] * inv[i];
	function<modulo(int, int)> comb = [&](int x, int y) {
		return fact[x] * factinv[y] * factinv[x - y];
	};
	modulo A = modulo(pA) * modulo(100).inv();
	modulo B = modulo(pB) * modulo(100).inv();
	modulo C = modulo(pC) * modulo(100).inv();
	modulo ans = 0;
	for (int i = 0; i < N; ++i) {
		modulo prob = comb(N + i - 1, i);
		modulo contri = prob * (modulo(N + i) * (modulo(1) - C).inv());
		ans += contri * (A.pow(N) * B.pow(i) + A.pow(i) * B.pow(N)) * (modulo(1) - C).pow(N + i).inv();
	}
	cout << ans.get() << endl;
	return 0;
}

Measured memory_bytes: 2560
main=interact$unwords.map show.tail.f.map read.words;f[a,b,c,d,e,f]=maximum[[(9^9)*s`div`(s+100*w),s+100*w,s]|x<-[0,a..30],w<-[x,x+b..30],w>0,let l=min(e*w)(f-100*w),y<-[0,c..l],let s=div(l-y)d*d+y]

Measured memory_bytes: 4856
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = [7,5,3]
    if n in a:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    s = S()
    ans = inf
    for i in range(len(s) - 2):
        ans = min(ans, abs(753-int("".join(s[i:i + 3]))))
    print(ans)
    return

#C
def C():
    s = II()
    n = len(str(s))
    ans = 0
    for i in range(3,n+1):
        c = itertools.product(["3", "5", "7"], repeat=i)
        for ci in c:
            if len(set(ci)) < 3:
                continue
            if int("".join(ci)) <= s:
                ans += 1
    print(ans)

        
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 44528
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
//整数値の入力
int n;
cin >> n;
tuple<int, int, int> data[n];
//xy高さ

for (int i = 0; i < n; ++i) {
     int x, y,h;
        cin >> x >> y >> h;
        data[i] = make_tuple(x, y, h);
}

int ans[3]={};

for (int x = 0;x<101;++x){
    for (int y = 0;y<101;++y){

        int  p, q, h,maxh;

        for(int i=0;i<n;++i){
            tie(p, q, h) = data[i];
            if(h>0){maxh=h+abs(x-p)+abs(y-q);}
        }
        bool hantei=1;
        
        for(int i=0;i<n;++i){
            tie(p, q, h) = data[i];
            int temp;
            temp=max(maxh-abs(x-p)-abs(y-q),0);
            if(temp!=h){hantei=0;}
        }
        if(hantei){ans[0]=x;ans[1]=y;ans[2]=maxh;}
    }
}
//回答
cout << ans[0] << " "<<ans[1] <<" "<<ans[2]<< endl;
return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<ll, ll>;

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

    int n;
    cin >> n;
    priority_queue<ll> minus;
    priority_queue<ll, vector<ll>, greater<ll>> plus;
    for (int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        if (a < 0)
            minus.push(a);
        else
            plus.push(a);
    }
    vector<P> ans;
    ll ret;
    if (plus.size())
    {
        if (minus.size())
        {
            while (plus.size() > 1)
            {
                ll t = plus.top();
                plus.pop();
                ll v = minus.top();
                minus.pop();
                ans.emplace_back(v, t);
                minus.push(v - t);
            }
            ret = plus.top();
            while (!minus.empty())
            {
                ll val = minus.top();
                minus.pop();
                ans.emplace_back(ret, val);
                ret -= val;
            }
        }
        else
        {
            ll v = plus.top();
            plus.pop();
            while (plus.size() > 1)
            {
                ll t = plus.top();
                plus.pop();
                ans.emplace_back(v, t);
                v -= t;
            }
            ret = plus.top() - v;
            ans.emplace_back(plus.top(), v);
        }
    }
    else
    {
        ret = minus.top();
        minus.pop();
        while (!minus.empty())
        {
            ll val = minus.top();
            minus.pop();
            ans.emplace_back(ret, val);
            ret -= val;
        }
    }
    cout << ret << endl;
    for (auto p : ans)
    {
        cout << p.first << " " << p.second << endl;
    }
}


Measured memory_bytes: 4976
use std::io::*;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn main() {
    let v = read_vec::<i64>();
    let (a,b,k) = (v[0],v[1],v[2]);
    for i in a..cmp::min(a+k,b+1) {
        println!("{}",i);
    }
    let m = cmp::max(a+k,b-k+1);
    if m <= b {
        for i in m..b+1 {
            println!("{}",i);
        }
    }
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.StringTokenizer;
 
public class Main {
	
	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		int t = 1;
		while(t-->0) solver.solve(1, scan, out);
		out.close();
	}
	
	static class Task {
		public void solve(int testNumber, FastReader scan, PrintWriter out) {
			int n = scan.nextInt();
			out.println(n*n*n);
		}
		
	}
	
	static void shuffle(int[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
	static void shuffle(long[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
 
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}
 
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
 
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    int n;
    cin >> n;
    For(c,1,n){
        int to = n - c;
        for(int a=1; a*a<=to; a++){
            if((n-c) % a == 0){
                ans++;
                if(a*a!=to){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"



int main(){
    ll a,b,n;
    cin >> a >> b >> n;
    ll num = ((a*min(b-1,n))/b)-a*(min(b-1,n)/b);
    COUT(num);
    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#define SIZE 1000
#define INF 999999

int N;
int max(int a[]){
    int i,m=0;
    for(i=0;i<N;i++)
        if(m<a[i]) m=a[i];
    return m;
}
int min(int a[]){
    int i,m=INF;
    for(i=0;i<N;i++)
        if(m>a[i]) m=a[i];
    return m;
}

int main(void){
    int i,p,q;
    int x[SIZE],y[SIZE]; //x[i],y[i]??????????????????i???????????£?????¢?????§?¨?
    int dx[] = {-1, 0, 1, 0}; //x???????§????
    int dy[] = {0, 1, 0, -1}; //y???????§????
    for(;;){
        scanf("%d", &N);
        if(N==0) break;
        x[0] = y[0] = 0; //???????????????(0,0)
        for(i=1;i<N;i++){
            scanf("%d %d", &p,&q); //p?????£?????¢???q???????????????
            x[i]=x[p]+dx[q];
            y[i]=y[p]+dy[q];
        }
        //??\?????????????????????x,y????????????????????§?????¨????°????????????¢????????§???????????????
        printf("%d %d\n", max(x)-min(x)+1, max(y)-min(y)+1);
    }
    return 0;
}

Measured memory_bytes: 608
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 15 21:05:46 2020

@author: NEC-PCuser
"""

N = int(input())

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

L.sort()

count = 0

for i in range(len(L)):
	for j in range(i + 1, len(L)):
		if L[i] == L[j]:
			continue
		for k in range(j + 1, len(L)):
			if L[j] == L[k]:
				continue
			if L[i] + L[j] > L[k]:
				count += 1
			else:
				break
print(count)

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007
int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);

    int a,b,c,k;
    cin>>a>>b>>c>>k;
    while(b<=a&&k!=0){
        b*=2;
        k--;
        if(k==0)break;
    }
    while(c<=b&&k!=0){
        c*=2;
        k--;
        if(k==0)break;
    }
    if(b>a&&c>b){
        cout<<"Yes\n";
    }else{
    cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 3632
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

yakusu = divisor(M)
yakusu.sort(reverse=True)

ans = 0
for y in yakusu:
    if y <=  M / N:
        ans = y
        break
print(ans)

Measured memory_bytes: 5204
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {

    let s1 = read_line();
    let s2 = read_line();

    for i in 0..s1.len() {
        let len = s1.len();
        let c1 = s1.chars().nth(i).unwrap();
        let c2 = s2.chars().nth(len - 1 - i).unwrap();
        if c1 != c2 {
            println!("NO");
            return
        }
    }
    println!("YES");
}


Measured memory_bytes: 4352
n, t = map(int, input().split())
*a, = map(int, input().split())
purchase = a[0]
profit = []
for i in range(len(a)):
  profit.append(a[i] - purchase)
  if a[i] < purchase:
    purchase = a[i]
profit.sort()
Answer = profit.count(profit[-1])
print(Answer)

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

int main(){
    ll n, x, m;
    cin >> n >> x >> m;
    set<ll> s;
    deque<ll> vec;
    ll a = x;
    ll sum = 0;
    ll loop_start;
    for (int i = 0; i <= m; i++) {
        if (s.count(a)) {
            loop_start = a;
            break;
        }
        s.insert(a);
        vec.push_back(a);
        sum += a;
        a = a * a % m;
    }

    ll ans = 0;
    if (s.count(0)) {
        ans = sum;
    }
    else {
        while (vec.front() != loop_start) {
            ans += vec.front();
            sum -= vec.front();
            vec.pop_front();
            n--;
        }
        ll loop = vec.size();
        ans += sum * (n / loop);
        for (int i = 0; i < n % loop; i++) {
            ans += vec[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6224
A = list(map(int, input().split()))
H = A[0]
W = A[1]
K = A[2]

colors = []
for line in range(H):
    color = input()
    color = list(color)
    colors.append(color)
ans = 0
for i in range(2**H):
    for j in range(2**W):
        cnt = 0
        for k in range(H):
            for l in range(W):
                if list(format(i,"0"+str(H)+"b"))[k] == "0" and list(format(j,"0"+str(W)+"b"))[l] == "0":
                    if colors[k][l] == "#":
                        cnt += 1
        if cnt == K:
            ans+= 1
print(ans)

Measured memory_bytes: 9160
// reference:https://atcoder.jp/contests/abc122/submissions/4691493

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll dp[111][4][4][4];
const int A=0,C=1,G=2,T=3;

int main(){
  int n;
  cin >> n;
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
        if(i==A && j==C && k==G)continue;
        if(i==A && j==G && k==C)continue;
        if(i==G && j==A && k==C)continue;
        dp[3][i][j][k]++;
      }
    }
  }
  ll ans=0;
  for(int i=4;i<=n;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
        for(int l=0;l<4;l++){
          for(int m=0;m<4;m++){
            if(k==A && l==G && m==C)continue;
            if(k==A && l==C && m==G)continue;
            if(k==G && l==A && m==C)continue;
            if(j==A && l==G && m==C)continue;
            if(j==A && k==G && m==C)continue;
            // debugged:%mod => %=mod
            (dp[i][k][l][m]+=dp[i-1][j][k][l])%=mod;
          }
        }
      }
    }
  }
  for(int i=0;i<4;i++){
    for(int j=0;j<4;j++){
      for(int k=0;k<4;k++){
        (ans+=dp[n][i][j][k])%=mod;
      }
    }
  }
    cout << ans%mod << endl;
return 0;}

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

using namespace std;

int find(string s, char c) {
	int i;
	for (i = 0; i < s.length(); i++) {
		if (s[i] == c) {
			break;
		}
	}
	return i;
}

int main()
{
	int temp;
	string s,y,m,d;
	int h = 0;

	cin >> s;

	temp = find(s, '/');
	y = s.substr(0, temp);
	// 5 yyyy
	s = s.substr(++temp);
	temp = find(s, '/');
	m = s.substr(0, temp);
	d = s.substr(++temp);

	h = stoi(y) * 10000 + stoi(m) * 100 + stoi(d);

	if (h <= 20190430) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  int s[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &s[i]);
  }
  int all = 0;
  int min = -1;
  for (int i = 0; i < n; i++) {
    all += s[i];
    if (s[i]%10 != 0) {
      if (min == -1 || s[i] < min) {
        min = s[i];
      }
    }
  }
  if (all%10 != 0) {
    printf("%d\n", all);
  } else {
    if (min == -1) {
      printf("0\n");
    } else {
      printf("%d\n", all-min);
    }
  }

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main() {
	int num[4], x;
	int i, j;

	for (i = 0; i<4; ++i)
		scanf("%d", &num[i]);


	for (i = 0; i < 4; i++) {
		for (j = i + 1; j < 4; j++) {
			if (num[i] > num[j]) {
				x = num[i];
				num[i] = num[j];
				num[j] = x;
			}
		}
	}
	if (num[0] != 1) {
		printf("NO");
	}
	else if (num[1] != 4) {
		printf("NO");
	}
	else if (num[2] != 7) {
		printf("NO");
	}
	else if (num[3] != 9) {
		printf("NO");
	}
	else { printf("YES"); }

}

Measured memory_bytes: 128
S = str(input())
 
for i in range((len(S)+1)//2):
  if S[2*i] == 'R' or S[2*i] == 'U' or S[2*i] == 'D':
    pass
  else:
    print('No')
    exit()

for j in range(len(S)//2):
  if S[2*j+1] == 'L' or S[2*j+1] == 'U' or S[2*j+1] == 'D':
    pass
  else:
    print('No')
    exit()

print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

int main(){
  fastIO();
  ll a,b,c,k,ans=0;
  cin>>a>>b>>c>>k;
  ans+=min(a,k);
  k-=min(a,k);
  k-=min(b,k);
  ans-=min(c,k);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3572
#include<cstdio>
int main()
{
    int a=0,b=0,n,i;
    char s[100],c;
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0;s[i]!='\0';i++)
    {
        if(s[i]==')') if(a==0) b++; else a--;
        if(s[i]=='(') a++;
    }
    for(i=0;i<b;i++)
        printf("(");
    printf("%s",s);
    for(i=0;i<a;i++)
        printf(")");
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl;
#define mod 1000000007
#define pb push_back

int main()
{
	long long a,b,k;
	cin>>a>>b>>k;
	
	long long ans =0;
	if(a>=k)
	{
		a-=k;

	}
	else
	{
		b=b+a-k;
		if(b<0) b=0;
		a=0;

	}
	cout<<a<<" "<<b<<endl;
} 

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

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> wa(n);
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    for(int i=0;i<n;i++){
        cin>>b.at(i);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(j<i){
                wa.at(i)+=a.at(j);
            }
            if(j==i){
                wa.at(i)+=a.at(j);
                wa.at(i)+=b.at(j);
            }
            if(j>i){
                wa.at(i)+=b.at(j);
            }
        }
        
        ans=max(ans,wa.at(i));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                   \
  ifstream in("atcoder-problems/abc111_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v) \
rep(l, v.size()) { cout << v[l] << " "; } \
cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18+100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S;
  cin >> S;

  int N = S.size();

  rep(i, N) {
    if (S[i] == '1')
      S[i] = '9';
    else
      S[i] = '1';
  }

  cout << S << endl;
}

Measured memory_bytes: 3624
N = int(input())
alp = [chr(i) for i in range(ord('a'), ord('z')+1)]
ans = []

while N > 0:
    res = N % 26
    ans.append(alp[res - 1])
    N //= 26
    if res == 0:
        N -= 1

ans = ans[::-1]
print(''.join(ans))

Measured memory_bytes: 9188
#include <iostream>
  #include <iomanip>
  #include <algorithm>
  #include <cmath>
  #include <queue>
  #include <list>
  #include <limits>
  #include <string>
  #include <vector>
  #include <stack>
  using namespace std;
  typedef long long ll;

  typedef pair<ll, ll> curr;
  const int MOD = 998244353;

int combi(int n, int k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

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

  ll calc(int a, int b, int p){
    if(b == 0) return 1;
    if(b % 2 == 0){
      ll d = calc(a, b/2, p);
      return (d*d)%p;
    }else{
      return (a*calc(a, b-1, p))%p;
    }

  }
  int main(){
    int primenumber[25] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
    int divi[100] = {};
    int N,count = 0;
    cin >> N;
    for(int i=2;i<=N;i++){
      for(int j=2;j<=N;j++){
        if(i%j != 0) continue;
        for(int k=0;k<25;k++){
          if(j == primenumber[k]){
            int curr = i,count = 0;
            while(curr % j == 0){
              count++;
              curr /= j;
            }
            divi[primenumber[k]] += count;
          }
        }
      }
    }
    int count74 = 0, count24 = 0, count14 = 0, count4 = 0, count2 = 0;
    for(int i=0;i<25;i++){
      if(divi[primenumber[i]] >= 74) count74++;
      if(divi[primenumber[i]] >= 24) count24++;
      if(divi[primenumber[i]] >= 14) count14++;
      if(divi[primenumber[i]] >= 4) count4++;
      if(divi[primenumber[i]] >= 2) count2++;
    }
    if(count4 != 0) count += combi(count4,2)*(count2-2);
    count += count14*(count4-1);
    count += count24*(count2-1);
    count += count74;
    cout << count;
  }


Measured memory_bytes: 384