akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

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

    modint<1000000007> count(10);
    for (int i =0; i < n-1; i++) {
        count *= 10;
    }

    modint<1000000007> count0(9);
    for (int i = 0; i < n-1; i++) {
        count0 *= 9;
    }

    modint<1000000007> count1(8);
    for (int i =0; i < n-1; i++) {
        count1 *= 8;
    }

    cout << (count-count0-count0+count1).value() << endl;
    return 0;
}

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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 10;
ll mod;

int n;
ll dp_up[maxN], dp_down[maxN];
vi adj[maxN], child[maxN];
vector <ll> pre[maxN], suf[maxN];

template <class T>
T mul(T &a, T b)
{
    return a = a * b % mod;
}

void DFS(int u, int p)
{
    dp_down[u] = 1;
    for (auto &v: adj[u])
    {
        if (v != p)
        {
            DFS(v, u);
            mul(dp_down[u], dp_down[v] + 1);
            pre[u].eb(dp_down[u]);
            child[u].eb(v);
        }
    }
    ll tmp = 1;
    ford(k, child[u].size())
    {
        int v = child[u][k];
        mul(tmp, dp_down[v] + 1);
        suf[u].eb(tmp);
    }
    reverse(all(suf[u]));
}

void recal(int u)
{
    for0(k, child[u].size())
    {
        int v = child[u][k];
        dp_up[v] = dp_up[u];
        if (k > 0)
        {
            mul(dp_up[v], pre[u][k - 1]);
        }
        if (k < (int)child[u].size() - 1)
        {
            mul(dp_up[v], suf[u][k + 1]);
        }
        dp_up[v] = (dp_up[v] + 1) % mod;
        recal(v);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> mod;
    for1(i, n - 1)
    {
        int u, v;
        cin >> u >> v;
        adj[u].eb(v);
        adj[v].eb(u);
    }
    DFS(1, 0);
    dp_up[1] = 1;
    recal(1);
    for1(i, n)
    {
        cout << (dp_down[i] * dp_up[i]) % mod << '\n';
    }
    return 0;
}


Measured memory_bytes: 30208
def f(x):
    result=""
    while x>=1:
        result+=str(x%4)
        x=int(x/4)
    result=result[::-1]
    return(result)
    
l=[]
MP=[]
N,A,B,C=map(int,input().split())
for _ in range(N):
    l.append(int(input()))

for n in range(4**N-1):
    state=f(n).zfill(N)
    a=state.count("1")
    b=state.count("2")
    c=state.count("3")
    if a==0 or b==0 or c==0:
        pass
    else:
        p,q,r=A,B,C
        ans=(a+b+c-3)*10
        for j in range(N):
            if state[j]=="0":
                pass
            elif state[j]=="1":
                p-=l[j]
            elif state[j]=="2":
                q-=l[j]
            else:
                r-=l[j]
        ans+=abs(p)+abs(q)+abs(r)
        MP.append(ans)

print(min(MP))

Measured memory_bytes: 4992
n,m = map(int, input().split())
xy = []

for i in range(m):
  x,y = map(int, input().split())
  xy.append([x-1,y-1])

box = [1 for i in range(n)]

chk = [False for i in range(n)]
chk[0] = True
for i in range(m):
  x, y = xy[i][0],xy[i][1]
  if chk[x]:
    if box[x] >= 2:
      chk[y] = True 
    else:
      chk[y] = True
      chk[x] = False
  box[y] += 1
  box[x] -= 1
cnt = 0
for i in range(n):
  cnt += chk[i]
print (cnt)

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

int main(){

    int a,b,c;
    int k;
    int max;
    int sum;

    cin >> a >> b >> c >> k ;

    int exponent = pow(2,k);

    max=a;
    sum = a+b+c;
    if (max<b) max=b;
    if (max<c) max=c;

    cout << exponent*max+sum-max;
}

Measured memory_bytes: 256
import Data.Int
modNum = 1000000007

main = do
  nm <- map (read :: String -> Int) . words <$> getLine
  inputX <- map (read :: String -> Int) . words <$> getLine
  inputY <- map (read :: String -> Int) . words <$> getLine
  let n = head nm
      m = last nm
      x = flip mod modNum . sum . zipWith (solve (length inputX)) [1..n] $ inputX
      y = flip mod modNum . sum . zipWith (solve (length inputY)) [1..m] $ inputY
  putStrLn . show $ (flip mod modNum $ x * y)

solve :: Int -> Int -> Int -> Int
solve n k = (flip mod modNum) . ((*) (2 * k - n - 1))


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

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

    static class AColorfulSlimes2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int count = 0;
            int last = -1;
            for (int i = 0; i < n; i++) {
                int color = in.nextInt();
                if (color == last) {
                    count++;
                    last = -1;
                } else {
                    last = color;
                }
            }
            out.println(count);
        }

    }
}



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

using namespace std;
int main(){
    int a[3];
    int k;
    cin >> a[0] >> a[1] >> a[2] >> k;

    sort(a, a+3);
    int ans = a[2];
    for(int i =0; i<k; i++){
        ans = ans * 2;
    }
    ans = ans + a[0] + a[1];
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cout << a[i] << " "; cout << "\n"; }
ll dbgt = 1; void err() { cout << "passed " << dbgt++ << "\n"; }
template<class H, class... T> void err(H&& h,T&&... t){ cout<< h << (sizeof...(t)?" ":"\n"); if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-20;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ld dp[305][305][305], PP[305][305][305];
ll A[4];
int main() {
    init();
    ll N;
    cin >> N;
    rep(i,N){
        ll a;
        cin >> a;
        A[a]++;
    }

    PP[A[1]][A[2]][A[3]] = 1;

    repr(t3,N+1){
        repr(t2,N+1){
            repr(t1,N+1){
                ld T = t1 + t2 + t3, D = dp[t1][t2][t3], P = PP[t1][t2][t3];
                if (T == 0 or P < EPS) continue;
                if(t1>0){
                    PP[t1 - 1][t2][t3] += P * t1 / T;
                    dp[t1 - 1][t2][t3] += (D + N * P / T) * t1 / T;
                }
                if(t2>0){
                    PP[t1 + 1][t2 - 1][t3] += P * t2 / T;
                    dp[t1 + 1][t2 - 1][t3] += (D + N * P / T) * t2 / T;
                }
                if(t3>0){
                    PP[t1][t2 + 1][t3 - 1] += P * t3 / T;
                    dp[t1][t2 + 1][t3 - 1] += (D + N * P / T) * t3 / T;
                }
            }
        }
    }

    cout << dp[0][0][0] << endl;
}


Measured memory_bytes: 506240
n, m, x = map(int, input().split())
l = []
for i in range(n):
    tmp = list(map(int, input().split()))
    l.append(tmp)
inf = 1001001001001
ans = inf
for mask in range(1 << n):
    out = False
    pay = 0
    exp = [0 for _ in range(m)]
    for i in range(n):
        if (mask >> i & 1) == 1:
            pay += l[i][0]
            # 理解度計算
            for j in range(m):
                exp[j] += l[i][j + 1]
    # 理解度チェック
    for i in exp:
        if i < x:
            out = True
            break
    if not out:
        ans = min(ans, pay)
if ans == inf:
    print(-1)
else:
    print(ans)


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

ll memo[1000];
ll fib(ll n) {
  if(n == 0) return 2;
  else if(n == 1) return 1;
  else if(memo[n]) return memo[n];
  else return memo[n] = fib(n-1) + fib(n-2);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  while(1) {
    bool ok = true;
    int now = n;
    int dig = now % 10;
    now /= 10;
    while(now > 0) {
      if(now % 10 != dig) {
        ok = false;
        break;
      }
      now /= 10;
    }

    if(ok) {
      cout << n << endl;
      break;
    }
    n++;
  }

}


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

int q;
int a[100], b[100];

int main() {
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d %d", &a[i], &b[i]);
    }

    for (int i = 0; i < q; i++) {
        long c = static_cast<long>(a[i]) * b[i];
        long d = static_cast<long>(sqrt(static_cast<double>(c) + 0.1));
        int ans = 2 * d - 3;
        if (a[i] == b[i]) ans++;
        if (d * (d + 1) >= c && c > d * d) ans++;
        if (static_cast<long>(d) * (d + 1) < c) ans += 2;
        printf("%d\n", ans);
    }

    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    string code;
    while(cin>>code){
        int Lflag=0,Rflag=0,cnt=0;
        if(code[0]=='#')break;
        for(int i=0;i<code.size();i++){
            if(code[i]=='y'||code[i]=='u'||code[i]=='i'||code[i]=='o'||code[i]=='p'||code[i]=='h'||code[i]=='j'||code[i]=='k'||code[i]=='l'||code[i]=='n'||code[i]=='m'){
                if(Lflag==1){
                    Rflag=1;Lflag=0;
                    cnt++;
                }
                else Rflag=1;
            }
            else{
                if(Rflag==1){
                    Rflag=0;Lflag=1;
                    cnt++;
                }
                else Lflag=1;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 1180
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N, Q;
	string S;
	cin >> N >> S >> Q;
	vector<set<int>>Set(26);
	vector<int>Str(N);//
	for (int n = 0; n < S.size(); ++n) {
		Set[S[n] - 'a'].insert(n);
		Str[n] = S[n] - 'a';//
	}
	vector<int>Ans;
	for (int n = 0; n < Q; ++n) {
		int q1;
		cin >> q1;
		if (1 == q1) {
			int q2;
			string q3;
			cin >> q2 >> q3;
			Set[Str[q2 - 1]].erase(q2 - 1);
			Set[q3[0] - 'a'].insert(q2 - 1);
			Str[q2 - 1] = q3[0] - 'a';//
		}
		else
		{
			int q2, q3;
			cin >> q2 >> q3;
			int ans = 0;
			for (int m = 0; m < 26; ++m) {
				set<int>::iterator it = Set[m].lower_bound(q2 - 1);
				if (it != Set[m].end() && *it < q3) {
					++ans;
				}
			}
			Ans.push_back(ans);
		}
	}
	for (int n = 0; n < Ans.size(); ++n) {
		cout << Ans[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 29272
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
map<ll,ll>m;
int main()
{   ll n,q;cin>>n;
     ll a[n],ans[n],ans1=0;
     for(ll i=0;i<n;i++){
         cin>>a[i];
         ans1^=a[i];
         
     }
   for(ll i=0;i<n;i++){
       ans[i]=ans1^a[i];
   }
 
 for(ll i=0;i<n;i++)
 cout<<ans[i]<<" ";
 
 
}

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

mod = 10**9+7
ans = 0

for i in range(K,N+2):
    min = (0+i-1)*i//2
    max = (N+N-i+1)*i//2
    
    ans += (max-min+1)%mod
    
print(ans%mod)

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

using namespace std;

#define int long long
#define pb push_back
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0);

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  string s;
  cin >> s;
  if(s.size() == 2) {
    if(s[0] == s[1]) cout << "1 2" << endl;
    else cout << "-1 -1" << endl;
    return 0;
  }

  REP(i, s.size()-2) {
    if(s[i] == s[i+1] || s[i+1] == s[i+2] || s[i+2] == s[i]) {
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }

  cout << -1 << " " << -1 << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep_1(i, n) for (int(i) = 0; (i) <= (n); (i)++)
#define rep_2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {
  ll n, d;
  cin >> n >> d;
  vector<ll> x(n);
  vector<ll> y(n);
  rep(i, n) cin >> x[i] >> y[i];
  ll ans = 0;
  rep(i, n) {
    double dis = sqrt(pow(x[i], 2) + pow(y[i], 2));
    if (dis <= d) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6428
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

int main(){
  int n,h,w,ans=0;

  cin >> n >> h >> w;
  for(int i=0;i<n;i++){
    int x, y;
    cin >> x >> y;
    if(x>=h&&y>=w)ans++;
  }
  cout << ans << endl;
  return 0;
}


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

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W;
    cin >> H >> W;
    vector<string> mp(H);
    for(int i=0; i<H; i++) cin >> mp.at(i);

    vector<vector<int>> hidari(H, vector<int>(W, 0));
    for(int i=0; i<H; i++)
    {
        int cnt = 0;
        for(int j=0; j<W; j++)
        {
            if(mp[i][j] == '.') cnt++;
            else cnt = 0;
            hidari[i][j] = cnt;
        }
    }

    vector<vector<int>> migi(H, vector<int>(W, 0));
    for(int i=0; i<H; i++)
    {
        int cnt = 0;
        for(int j=W-1; j>=0; j--)
        {
            if(mp[i][j] == '.') cnt++;
            else cnt = 0;
            migi[i][j] = cnt;
        }
    }

    vector<vector<int>> ue(H, vector<int>(W, 0));
    for(int j=0; j<W; j++)
    {
        int cnt = 0;
        for(int i=0; i<H; i++)
        {
            if(mp[i][j] == '.') cnt++;
            else cnt = 0;
            ue[i][j] = cnt;
        }
    }

    vector<vector<int>> shita(H, vector<int>(W, 0));
    for(int j=0; j<W; j++)
    {
        int cnt = 0;
        for(int i=H-1; i>=0; i--)
        {
            if(mp[i][j] == '.') cnt++;
            else cnt = 0;
            shita[i][j] = cnt;
        }
    }

    int ans = 0;
    for(int i=0; i<H; i++)
    {
        for(int j=0; j<W; j++)
        {
            chmax(ans, hidari[i][j] + migi[i][j] + ue[i][j] + shita[i][j] - 3);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 67328
#include <iostream>
#include <algorithm>
#include <map>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i=0; i< (int)(n); i++)
typedef long long ll;
bool DEBUG = false;


int main() {
    int H,W;
    cin >> H >> W;

    vector<vector<char>> grid(H);
    rep(i, H){
        string si;
        cin >> si;
        rep(j,W){
            grid[i].push_back(si[j]);
        }
    }

    vector<vector<int>> horizontal(H);
    vector<vector<int>> vertical(H);
    if (DEBUG) cout << "input done" << endl;

    // horizontal direction
    rep(row, H){
        vector<int> blocks;
        blocks.push_back(-1);
        rep(col, W){
            if (grid[row][col] == '#'){
                blocks.push_back(col);
            }
        }
        blocks.push_back(W);
        if (DEBUG) cout << "blocks created for row: " << row << endl;

        // [-1, 0, 1]
        // h: [ ]
                if (DEBUG) {
            cout << "blocks are ";
            rep(i, blocks.size()) {
                cout << blocks[i] << " ";
            } 
            cout << endl;
        }
        int bsize = (int) blocks.size();
        if (DEBUG) cout << "w" << endl;

        for (int bi = 0; bi < bsize - 1; bi++){ // i:3
            if (DEBUG) cout << "x" << endl;

            if (bi != 0) horizontal[row].push_back(0); // horizontal[blocks[i]] = 0;
            int val_insert = blocks[bi+1] - blocks[bi] - 1;
            if (DEBUG) cout << "y"<< endl;
            rep(j, val_insert){
                // horizontal[blocks[i] + 1 + j] = val_insert;
                if (DEBUG) cout << "z1" << endl;
                
                horizontal[row].push_back(val_insert);
                if (DEBUG) cout << "z" << endl;
            }
        }
        vector<int>().swap(blocks);
    }
    if (DEBUG) cout << "horizontal done" << endl;

    // vertical direction
    rep(col, W){
        vector<int> blocks;
        blocks.push_back(-1);
        rep(row, H){
            if (grid[row][col] == '#'){
                blocks.push_back(row);
            }
        }
        blocks.push_back(H);
        if (DEBUG) cout << "blocks created for col: " << col << endl;

        // blocks: [-1, 0, 3, 4]
        if (DEBUG) {
            cout << "blocks are ";
            rep(i, blocks.size()) {
                cout << blocks[i] << " ";
            } 
            cout << endl;
        }
        for (int i = 0; i < (int) blocks.size() - 1; i++){ // i: 1
            if (i != 0) vertical[blocks[i]].push_back(0); // vertical[blocks[i]] = 0;
            int val_insert = blocks[i+1] - blocks[i] - 1;
            rep(j, val_insert){
                // vertical[blocks[i] + 1 + j] = val_insert;
                vertical[blocks[i] + j + 1].push_back(val_insert);
            }
        }
        if (DEBUG) cout << "vales added for col: " << col << endl;
    }
    if (DEBUG) cout << "vertical done" << endl;

    // calc sum
    int ans = 0;
    rep(i, H){
        rep(j, W){
            ans = max(horizontal[i][j]+vertical[i][j], ans);
        }
    }

    cout << ans - 1 << endl;

}

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

//region Template
#include "ext/pb_ds/assoc_container.hpp"

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int MOD2 = 998244353;
const int MOD = 1000000007;
using namespace std;
#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);
#define fi first
#define se second
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
#define is_empty(...) ( sizeof( (char[]){#__VA_ARGS__} ) == 1 )

void print() {}
template<typename T, typename... Args>
void print(T firstArg, Args... args) {
	#ifdef LOCAL
	cout << firstArg << endl;
	print(args...);
	#endif
}

//endregion

/* Notes:
 * Fry my kartoshka
 */

const int MAXN = 21;
const int INF = 2e9;

bool ok[MAXN][MAXN];

ll dp[22][1 << 21 + 1];

int main(){
	//usaco("milkvisits");

#ifdef LOCAL
	setIn("in.txt");
	setOut("out.txt");
#endif

	fastIO;

	int n;
	cin >> n;

	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> ok[i][j];
		}
	}

	for(int i = 0; i < n; i++){
		dp[0][1 << i] = ok[0][i];
	}


		for(int j = 0; j < (1 << n); j++){
			int i = __builtin_popcount(j) - 1;
			if(i < 1) continue;
			for(int b = 0; b < n; b++){
				if(ok[i][b] && j & (1 << b)){
					dp[i][j] += dp[i - 1][j ^ (1 << b)];
					if(dp[i][j] >= MOD){
						dp[i][j] -= MOD;
					}
				}
			}
		}

	ll ans = 0;

	ans = dp[n - 1][(1 << n) - 1] % MOD;
	cout << ans;
}


Measured memory_bytes: 321920
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N;
  cin>>N;
  vector<int> A(N*3);
  for(int &i:A)
    cin>>i;
  sort(A.begin(),A.end());
  int j=0;
  for(int i=N;i<N*3;i+=2)
    j+=A[i];
  cout<<j<<endl;
}

Measured memory_bytes: 5516
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N;
    cin >> N;
    map<string,int> A;
    rep(i,N){
        string a;
        cin >> a;
        A[a]++;
    }
    cout << int(A.size()) << endl;
    
    
    

    return 0;
}


Measured memory_bytes: 19212
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
const ll MOD=1000000007;
const ll INF=1e18;

int cnt[5];

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    rep(i,0,6){
        int a;
        cin>>a;
        a--;
        cnt[a]++;
    }
    bool ok=true;
    rep(i,0,4){
        if(!(cnt[i]==1||cnt[i]==2))ok=false;
    }
    if(ok)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

vector<int>a,b;
vector<vector<int> > v;
vector<bool>flag;
string p;
void bfs(int x){
    if(flag[x])return;
    if(a[x]>0&&b[x]>0)return;
    flag[x] = 1;
    for(auto y:v[x]){
        if(flag[y])continue;
        if(p[x]=='A'){
            a[y]--;
            bfs(y);
        }
        if(p[x]=='B'){
            b[y]--;
            bfs(y);
        }
    }
}

int main(){
    int n,m;
    cin >> n >> m >> p;
    set<pair<int,int> > st;
    a.resize(n+1);
    b.resize(n+1);
    v.resize(n+1);
    flag.resize(n+1);
    rep(i,m){
        int s,t;
        cin >> s >> t;
        s--;
        t--;
        if(s>t)swap(s,t);
        if(st.count(MP(s,t))==1){
            continue;
        }else{
            if(s==t){
                v[s].PB(s);
                if(p[s]=='A'){
                    a[s]++;
                }else{
                    b[s]++;
                }
            }else{
                v[s].PB(t);
                v[t].PB(s);
                if(p[s]=='A'){
                    a[t]++;
                }else{
                    b[t]++;
                }
                if(p[t]=='A'){
                    a[s]++;
                }else{
                    b[s]++;
                }
            }
        }
    }
    for(int i=0;i<n;i++){
        bfs(i);
    }
    bool ans=0;
    for(int i=0;i<n;i++){
        if(!flag[i]){
            ans = 1;
        }
    }
    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    int sum = 0;
    rep(i, N) {
        cin >> L[i];
        sum += L[i];
    }
    sort(L.rbegin(), L.rend());
    if (L[0] < sum - L[0]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict




BS, SL = '\\', '/'

diagram = list(input())

flood = defaultdict(int)
total = 0
stack = []

for cur, terrain in enumerate(diagram):
    if terrain == BS:
        stack.append(cur)
    elif terrain == SL and stack:
        first = stack.pop()
        water = cur-first
        total += water
        for (f_first, f_last) in list(flood):
            if first < f_first < cur:
                flood[(first, cur)] += flood.pop((f_first, f_last))
        flood[(first, cur)] += water

print(total)
print(' '.join(map(str, [len(flood)] + list(flood.values()))))



Measured memory_bytes: 6992
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*int find(int a){
     if(a==par[a])return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);
     if(a==b)return ;
     par[b]=a;
}
ll modexpo(ll a,ll b)
{
     int ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
*/












queue<int> a[100005];
queue<pair<pair<int,int>,int>> q;
int vis[100005];
int main(){
     int n;
     cin>>n;
     for(int i=1;i<=n;i++){
          for(int j=0;j<n-1;j++){
               int x;cin>>x;a[i].push(x);
          }
     }
     for(int i=1;i<=n;i++){
          int x=a[i].front(),y=a[x].front();
          if(vis[x]||vis[y])continue;
          if(y==i){
               q.push({{x,y},1});vis[x]=1,vis[y]=1;
          }
     }
     int res=0;
     while(!q.empty()){
          int x=q.front().fi.fi,y=q.front().fi.se,val=q.front().se;
          res=max(res,val);
          a[x].pop();a[y].pop();q.pop();
          int u=-1,v=-1;
          if(!a[x].empty())u=a[x].front();
          if(!a[y].empty())v=a[y].front();
          if(u!=-1&&a[u].front()==x){
               q.push({{x,u},val+1});
          }
          if(v!=-1&&a[v].front()==y){
               q.push({{y,v},val+1});
          }

     }
     bool flag=true;
     for(int i=1;i<=n;i++){
          if(!a[i].empty()){flag=false;break;}
     }
     if(!flag)cout<<-1;
     else cout<<res;

}



















































Measured memory_bytes: 74528
n, m, L = map(int, input().split())
  
a = [list(map(int, input().split())) for _ in range(n)]
b = [list(map(int, input().split())) for _ in range(m)]
c = [[sum(ak * bk for ak, bk in zip(ai,bj)) for bj in zip(*b)] for ai in a]
  
for ci in c:
    print(*ci)

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    int n = (int) s.size();
    int count = 0;
    for(int i=0;i<n;++i){
        int num = s[i] - '0';
        count += num;
    }
    if(count%9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
    
}

Measured memory_bytes: 3776
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n[] = new int[3];
		n[0] = sc.nextInt();
		n[1] = sc.nextInt();
		n[2] = sc.nextInt();
		
		if(n[0] * n[1] * n[2] == 25 * 7) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


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

using namespace std;
#define X first
#define Y second
#define pb push_back
typedef double db;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=1e5+10;
ll res[MAXN],k,top;
int vis[MAXN],st[MAXN];
int n,m,x,d[MAXN],nxt[MAXN];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) 
		scanf("%d",&d[i]),nxt[i]=i;
	for(int i=n;i>=1;i--) d[i]=d[i]-d[i-1];
	scanf("%d%lld",&m,&k);
	for(int i=1;i<=m;i++)
		scanf("%d",&x),swap(nxt[x],nxt[x+1]);
	
	for(int i=1;i<=n;i++)
	{
		if(vis[i]) continue;
		top=0;
		for(int j=i;!vis[j];j=nxt[j])
		{
			st[++top]=j;
			vis[j]=1;
		}
		for(int j=1;j<=top;j++)
			res[st[j]]=d[st[(j+k-1)%top+1]];
	}
	for(int i=1;i<=n;i++)
		res[i]+=res[i-1],printf("%lld\n",res[i]);
	return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;

    vector<int> H(N);
    for(int i = 0; i < N; i++){
        cin >> H.at(i);
    }

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

    long long ans = 0;
    for(int i = 0; i < N - K; i++){
        ans += H.at(i);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using i64 = int64_t;

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

    return 0;
}

Measured memory_bytes: 19156
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
using namespace std;

int main(){
  vector<vector<char>> v(3, vector<char>(3));
  for (int i=0; i<3; i++)
    for (int k=0; k<3; k++)
      cin >> v[i][k];

  cout << v[0][0] << v[1][1] << v[2][2] << endl;

}


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

using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;



int main() {
const ll INF = 1001001001;
const ld PI = 3.14159265358979323846;
int N,count=0;
string S;
cin>>N;
rep3(i,N){
    S = to_string(i);
    if(S.size()%2==1){
        count++;
    }

}
cout<<count<<endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int n, a;
  cin >> n >> a;
  n %= 500;
  cout << (n <= a ? "Yes" : "No") << endl;

  return 0;
}




//


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define INF -1

int Q[N], M[N][N], head,tail;
int d[N];   //距離で訪問状態を管理する
int n;
int dequeue();
void enqueue(int q);
int enpty();
void bfs(int);

int main(){
  int a,b,c;
  int i,j;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&a,&b);
    a--;
    for(j=0;j<b;j++){
      scanf("%d",&c);
      c--;
      M[a][c] = 1;
    }
  }

  bfs(0);

  return 0;
}


int dequeue(){  //キューからデータを取り出す
  int x=Q[head];
  
  head=(head+1)%N;
  return x;
}

void enqueue(int q){ //キューにデータを入れる
  Q[tail]=q;
  tail=(tail+1)%N;
}


int enpty(){
  if(tail==head)
    return 1;
  else
    return 0;
}

void bfs(int s){
  int i;
  int u,v;
  enqueue(s);

  for(i=0;i<n;i++){
    d[i]=INF;
  }

  d[s]=0;

  while(!enpty()){
    u = dequeue();
    for(v=0;v<n;v++){
      if(M[u][v] == 0)continue;
      if(d[v] != INF)continue;
      d[v] = d[u] + 1;
      enqueue(v);
    }
  }

  for(i=0;i<n;i++){
    printf("%d %d\n",i+1,((d[i] == INF)? -1 : d[i]));
  }
}




Measured memory_bytes: 2036
object Main extends App {
	override def main(args: Array[String]) = {
		val sc = new java.util.Scanner(System.in)
		
		Iterator.continually(new Statement(left = sc.nextInt, op = sc.next, right = sc.nextInt))
		.takeWhile(_.isContinue).foreach{ s =>
			println(s.getValue)
		}
	}
	
	class Statement(val left:Int , val right:Int , val op:String){
		
		val isContinue = op != "?"
		
		lazy val getValue:Int = op match {
			case "+" => left + right
			case "-" => left - right
			case "/" => left / right
			case "*" => left * right
		}
	}
}

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

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

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

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

    for(int i=0; i<N; i++){
        if(a[i] >= X[(N+1)/2]){
            cout<<X[(N+1)/2-1]<<endl;
        }else{
            cout<<X[(N+1)/2]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4768
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右攜下昴 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 敘大公約摧
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 敘擣公倍摧
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/


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

	ll n;
	cin >> n;
	vector<pair<ll, ll>> ba(n);
	rep(i, n) cin >> ba[i].second >> ba[i].first;

	// 貪欲法？
	sort(allof(ba));

	bool can = true;

	ll time = 0;
	rep(i, n) {
		if (time + ba[i].second > ba[i].first) {
			can = false;
			//cout << i << endl;
			break;
		}

		time += ba[i].second;
	}

	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

long long modpow(long long a, long long n, long long mod) {
  if(n == 0) {
    return 1;
  } else if(n % 2 == 1) {
    return modpow(a, n - 1, mod) * a % mod;
  } else {
    ll t = modpow(a, n / 2, mod);
    return t * t % mod;
  }
}

int main() {
  int m; ll n; cin >> m >> n;
  cout << modpow(m, n, pow(10, 9) + 7) << endl;
}


Measured memory_bytes: 3116
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair 
#define INF 1000000000
#define MOD 1000000007 
#define e 65436534565367ull
#define MAXN 100010
namespace IO
{
	inline ll getint()
	{
		ll x=0,p=1;char c;
		c=getchar();
		while (c<=32)c=getchar();
		if(c==45)p=-p,c=getchar();
		while (c>32)x=x*10+c-48,c=getchar();
		return x*p;
	}
	inline void _putint(ll x)
	{
		if(x)_putint(x/10),putchar(x%10+48);
	}
	inline void putint(ll x)
	{
		if(x==0) putchar(48);
	    else if(x<0)putchar(45),_putint(-x);
		else _putint(x);
	}
}

using namespace IO;

ll n,a[MAXN];

int main()
{
	n=getint();
	for(int i=0;i<n;i++)a[i]=getint();
	ll minx=2,maxx=2;
	for(int i=n-1;i>=0;i--)
	{
		if(maxx<a[i])
		{
			putint(-1);
			return 0;
		}
		minx=((minx-1)/a[i]+1)*a[i];
		ll y=maxx/a[i]*a[i];
		maxx=y+a[i]-1;
		if(minx>maxx)
		{
			putint(-1);
			return 0;
		}
	}
	
	putint(minx);putchar(' ');putint(maxx);putchar('\n'); 
	return 0;	
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int count(int a)
{
    int ans = 1;
    for (int i = 2; i <= sqrt(a); i++)
    {
        int cnt = 0;
        while (a % i == 0)
        {
            cnt++;
            a /= i;
        }
        ans *= (cnt + 1);
        if (a == 1)
            break;
    }
    if (a != 1)
        ans *= 2;
    return ans;
}
int main(void)
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n - 1; i++)
    {
        ans += count(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
import java.util.Arrays;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		long A[] = new long[3];
		A[0] = scanner.nextInt();
		A[1] = scanner.nextInt();
		A[2] = scanner.nextInt();
		if (A[0] % 2 == 0 || A[1] % 2 == 0 || A[2] % 2 == 0) {
			System.out.println(0);
		} else {
			Arrays.sort(A);
			System.out.println(A[0] * A[1]);
		}
	}
}

Measured memory_bytes: 10064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int c[10][10];
int H, W, A, ans;

int main()
{
	scanf("%d%d", &H, &W);
	for (int i = 0; i < 10; i++)
		for (int j = 0; j < 10; j++)
			scanf("%d", &c[i][j]);
	for(int k=0;k<10;k++)
		for(int i=0;i<10;i++)
			for (int j = 0; j < 10; j++) {
				if (c[i][j] > c[i][k] + c[k][j])
					c[i][j] = c[i][k] + c[k][j];
			}
	ans = 0;
	for(int i=0;i<H;i++)
		for (int j = 0; j < W; j++) {
			scanf("%d", &A);
			if (A >= 0)
				ans += c[A][1];
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define ll long long
ll N, M;
const int mod = 1000000007;

ll fact(ll n){
    if(n == 1)
        return 1;
    else
        return (n * fact(n - 1)) % mod ;
}

int main(){

    cin >> N >> M ;

    if(N < M){
        ll temp = N;
        N = M;
        M = temp;
    }
    
    ll abs = N - M;

    if(abs > 1){
        cout << 0 << '\n';
    }
    else if(abs ==1){
       ll x = fact(N);
       ll y = fact(M);
       cout << (x * y) % mod << '\n';
    }
    else if(abs == 0){
        ll x = fact(N);
        cout << (((x * x) % mod)  * 2) % mod << '\n'; 
    }
}


Measured memory_bytes: 1792
// https://atcoder.jp/contests/abc044/tasks/abc044_b

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

int main()
{
    string w;
    cin >> w;
    vector<int> ctr(26, 0);
    for (int i = 0; i < w.size(); i++)
    {
        int j = w[i] - 'a';
        ctr[j] ^= 1;
    }
    int cond = 0;
    for (int i = 0; i < 26; i++)
    {
        cond += ctr[i];
    }
    cout << (cond ? "No" : "Yes") << endl;
    return 0;
}


Measured memory_bytes: 3644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {

    String[] input = null;
    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      input = br.readLine().split("\\s");
    } catch (IOException e) {
      e.printStackTrace();
      System.exit(1);
    }

    int a = Integer.parseInt(input[0]);
    int b = Integer.parseInt(input[1]);

    int max = a + (a - 1);
    max = Math.max(max, a + b);
    max = Math.max(max, b + (b - 1));
    System.out.print(max);
  }

}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <complex>

using namespace std;

int main(){

    int A,B,C,D,P,answer;

    cin>>A>>B>>C>>D>>P;

    if(P<C){
        if(A*P<B) answer = A*P;
        else answer = answer = B;
    } 
    else{
        if(B+D*(P-C)<A*P) answer = B+D*(P-C);
        else answer = A*P;
    }

    cout<<answer<<endl;

    return 0;


}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;

    int mxl = 0, mnr = 1000000;
    for (int i = 0; i < m; i++){
        int l, r;
        cin >> l >> r;
        mxl = max(l, mxl);
        mnr = min(r, mnr);
    }
    
    if (mnr - mxl + 1 < 0)
        cout << 0 << '\n';
    else
        cout << mnr - mxl + 1 << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int MAXN = 1e9 + 7;

long long n, aw;
int main()
{
	aw = 1;
	scanf("%I64d", &n);
	for(int i = 1; i <= n; i++)
	{
		aw = (aw * i) % MAXN;
	}
	printf("%I64d\n", aw);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    int i, hand[6]={};
    
    while(1){
    int x[4]={0, 0, 0, 0};
    for(i=1; i<=5; i++){
        cin >> hand[i];
        if(hand[i] == 1) x[1]=1;  //グー
        else if(hand[i] == 2) x[2]=1; //チョキ
        else if(hand[i] == 3) x[3]=1; //パー
        else return 0;
    }
    
    if(x[1] == 1){ //グーが出た
        if(x[2] == 1){ //チョキが出た
            if(x[3] == 1){ //パーが出た
                //あいこ
                for(i=1; i<=5; i++){
                    cout << '3' << endl;
                }
            }
            else{   //グーとチョキだけ
                for(i=1; i<=5; i++){
                    if(hand[i] == 1) cout << 1 << endl; //勝ち
                    else cout << '2' << endl; //負け
                    }
            }
        }
        else{ //チョキは出ない
            if(x[3] == 1){ //グーとパーだけ
                for(i=1; i<=5; i++){
                    if(hand[i] == 3) cout << 1 << endl; //勝ち
                    else cout << '2' << endl; //負け
                }
            }
            else{ //パーも出ない＝グーだけ
                for(i=1; i<=5; i++){
                    cout << '3' << endl; //あいこ
                }
            }
        }
    }
    else{ //グーは出ない
        if(x[2] == 1){ //チョキが出た
            if(x[3] == 1){ //パーが出た
                for(i=1; i<=5; i++){
                    if(hand[i] == 2) cout << 1 << endl; //勝ち
                    else cout << '2' << endl; //負け
                }
            }
            else{ // パーが出ない＝チョキだけ
                for(i=1; i<=5; i++){
                    cout << '3' << endl; //あいこ
                }
            }
        }
        else{ //チョキもでない＝パーだけ
            for(i=1; i<=5; i++){
                cout << '3' << endl; //あいこ
            }
        }
    }
    }
    return 0;
}



Measured memory_bytes: 3020