akhauriyash/Code-Regression huggingface dataset:
// AtCoder :: Beginner Contest 177 ::
//

#include <bits/stdc++.h>

using namespace std;

vector<int> PRIMES;

void sievePrimes(int N) {
    // Sieve of Eratosthenes.
    deque<bool> sieve(N+1, true);
    sieve[0] = sieve[1] = false;

    for (int j{4}; j <= N; j += 2) {
        sieve[j] = false;
    }

    int k{3};
    while (k * k <= N) {
        if (sieve[k]) {
            for (int j = k * k; j <= N; j += k) {
                sieve[j] = false;
            }
        }
        k += 2;
    }
    for (int n{2}; n <= N; ++n) {
        if (sieve[n]) {
            PRIMES.push_back(n);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // Sieve the primes.
    sievePrimes(1000);
    int N;
    cin >> N;
    vector<int> A;
    A.reserve(N);
    copy_n(istream_iterator<int>(cin), N, back_inserter(A));
    bool pairwiseCoprime = true;
    bool setwiseCoprime = true;
    for (int p : PRIMES) {
        // Count the number of A[i] divisible by prime p.
        int count{0};
        for (int i{0}; i < N; ++i) {
            if (A[i] % p == 0) {
                count++;
                A[i] /= p;
            }
        }
        // If the number of A[i] divisible by p > 1 then 
        // A is not pairwise coprime because there is 
        // at lease one pair of numbers divisible by p.
        if (count > 1) {
            pairwiseCoprime = false;
        }

        // If the number of A[i] divsible by p == N then
        // A is not setwise coprime.
        if (count == N) {
            setwiseCoprime = false;
            break;
        }
    }

    // Check for any primes still in A.
    unordered_map<int, int> S;
    for (int a : A) {
        if (a > 1) {
            S[a] += 1;
            auto freq = S[a];
            if (freq > 1) {
                pairwiseCoprime = false;
            } else if (freq == N) {
                setwiseCoprime  = false;
                break;
            }
        }
    }

    if (pairwiseCoprime) {
        cout << "pairwise coprime\n";
    } else if (setwiseCoprime) {
        cout << "setwise coprime\n";
    } else {
        cout << "not coprime\n";
    }

    return EXIT_SUCCESS;
}


Measured memory_bytes: 14060
#include <cstdio>
int n, a, b, c, x;
int main() {
	scanf("%d%d", &n, &a);
	for(int i=1; i<n; i++) {
		scanf("%d", &b);
		if(b==a) continue;
		if(x) {if(x==1 && b<a || x==-1 && b>a) x=0, c++;}
		else x = b>a ? 1:-1;
		a = b;
	}
	printf("%d", c+1);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int INF = 2e9;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
namespace NetworkFlow {
	const int INF = 2e9;
	const int MAXP = 5e5 + 5;
	struct edge {
		int dest, flow;
		unsigned pos;
	};
	vector <edge> a[MAXP];
	int tot, s, t, dist[MAXP];
	unsigned curr[MAXP];
	void addedge(int x, int y, int z) {
		a[x].push_back((edge) {y, z, a[y].size()});
		a[y].push_back((edge) {x, 0, a[x].size() - 1});
	}
	int dinic(int pos, int limit) {
		if (pos == t) return limit;
		int used = 0, tmp;
		for (unsigned &i = curr[pos]; i < a[pos].size(); i++)
			if (a[pos][i].flow != 0 && dist[pos] + 1 == dist[a[pos][i].dest] && (tmp = dinic(a[pos][i].dest, min(limit - used, a[pos][i].flow)))) {
				used += tmp;
				a[pos][i].flow -= tmp;
				a[a[pos][i].dest][a[pos][i].pos].flow += tmp;
				if (used == limit) return used;
			}
		return used;
	}
	bool bfs() {
		static int q[MAXP];
		int l = 0, r = 0;
		memset(dist, 0, sizeof(dist));
		dist[s] = 1, q[0] = s;
		while (l <= r) {
			int tmp = q[l];
			for (unsigned i = 0; i < a[tmp].size(); i++)
				if (dist[a[tmp][i].dest] == 0 && a[tmp][i].flow != 0) {
					q[++r] = a[tmp][i].dest;
					dist[q[r]] = dist[tmp] + 1;
				}
			l++;
		}
		return dist[t] != 0;
	}
	int flow() {
		int ans = 0;
		while (bfs()) {
			memset(curr, 0, sizeof(curr));
			ans += dinic(s, INF);
		}
		return ans;
	}
}
int n, a[MAXN], b[MAXN];
int va[MAXN], vb[MAXN];
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]), a[i]++;
	for (int i = 1; i <= n; i++)
		read(b[i]), b[i]++;
	for (int i = 1; i <= n; i++) {
		if (va[i]) continue;
		int pos = i;
		while (va[pos] == 0) {
			va[pos] = i;
			pos = a[pos];
		}
	}
	for (int i = 1; i <= n; i++) {
		if (vb[i]) continue;
		int pos = i;
		while (vb[pos] == 0) {
			vb[pos] = i + n;
			pos = b[pos];
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans += a[i] != b[i];
	int s = NetworkFlow :: s = 2 * n + 1;
	int t = NetworkFlow :: t = 2 * n + 2;
	for (int i = 1; i <= n; i++) {
		if (a[i] == b[i]) {
			if (a[i] == i) continue; ans += 2;
			NetworkFlow :: addedge(s, va[i], 1);
			NetworkFlow :: addedge(vb[i], t, 1);
			NetworkFlow :: addedge(va[i], vb[i], 2);
		} else {
			if (a[i] == i) NetworkFlow :: addedge(s, vb[i], 1);
			else if (b[i] == i) NetworkFlow :: addedge(va[i], t, 1);
			else NetworkFlow :: addedge(va[i], vb[i], 1);
		}
	}
	ans -= NetworkFlow :: flow();
	writeln(ans);
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  int a = (M/2)*2+1;
  for (int i=1; i<=M/2; i++)
    cout << i << ' ' << a+1-i << endl;
  for (int i=1; i<=(M+1)/2; i++)
    cout << a+i << ' ' << 2*M+2-i << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int read();
void chmin(int &x, int y) { x > y ? x = y : x; }
int n;
queue<int> q;
int vis[102];
struct Graph {
    int hd[102], nx[202], to[202], deg[202], cnt;
    void init() {
        cnt = 0;
        for (int i = 1; i <= n; ++i) hd[i] = deg[i] = 0;
    }
    void add(int f, int t) {
        nx[++cnt] = hd[f], hd[f] = cnt, ++deg[to[cnt] = t];
    }
    int fa[102];
    void getfa(int u) {
        for (int i = hd[u], v; i; i = nx[i])
            if ((v = to[i]) != fa[u]) fa[v] = u, getfa(v);
    }
    int topo() {
        int rt = 0;
        for (int i = 1; i <= n; ++i)
            if (vis[i] && !deg[i]) ++rt, q.push(i);
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int i = hd[u], v; i; i = nx[i])
                if (!(--deg[v = to[i]])) ++rt, q.push(v);
        }
        return rt;
    }
} A, B, G;
int res;
int work() {
    int rt = 0;
    for (int i = 1; i <= n; ++i) rt += (vis[i] = A.fa[i] != B.fa[i]);
    if (rt >= res) return n + 1;
    G.init();
    for (int i = 1; i <= n; ++i) {
        if (!vis[i]) {
            if (vis[A.fa[i]]) return n + 1;
            continue;
        }
        if (vis[A.fa[i]]) G.add(i, A.fa[i]);
        if (vis[B.fa[i]]) G.add(B.fa[i], i);
    }
    return G.topo() == rt ? rt : n + 1;
}
int main() {
    int T = read();
    while (T--) {
        res = (n = read()) + 1, A.init(), B.init();
        for (int i = 1, u, v; i < n; ++i)
            u = read(), v = read(), A.add(u, v), A.add(v, u);
        for (int i = 1, u, v; i < n; ++i)
            u = read(), v = read(), B.add(u, v), B.add(v, u);
        for (int i = 1; i <= n; ++i) {
            A.fa[i] = B.fa[i] = 0, A.getfa(i), B.getfa(i), chmin(res, work());
            if (A.deg[i] == 1)
                for (int j = 1; j <= n; ++j)
                    if (i != j) {
                        A.fa[j] = i, A.getfa(j), B.getfa(i);
                        A.fa[i] = B.fa[i] = 0, chmin(res, work() + 1);
                    }
        }
        printf("%d\n", res > n ? -1 : res);
    }
    return 0;
}
const int _SIZE = 1 << 22;
char ibuf[_SIZE], *iS = ibuf, *iT = ibuf;
#define gc                                                         \
    (iS == iT ? iT = ((iS = ibuf) + fread(ibuf, 1, _SIZE, stdin)), \
     (iS == iT ? EOF : *iS++) : *iS++)
int read() {
    int x = 0, f = 1;
    char c = gc;
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = gc;
    while (isdigit(c)) x = x * 10 + c - '0', c = gc;
    return x * f;
}

Measured memory_bytes: 3756
from collections import deque

n, q = map(int, input().split())
eg = [[] for _ in range(n + 1)]

for _ in range(n - 1):
    a, b = map(int, input().split())
    eg[a].append(b)
    eg[b].append(a)

cnt = [0] * (n + 1)
for i in range(q):
    p, x = map(int, input().split())
    cnt[p] += x


q = deque()
q.append(1)
seen = {1}
ans = [0] * (n + 1)
ans[1] = cnt[1]
while q:
    v = q.pop()
    for t in eg[v]:
        if t in seen:
            continue
        q.append(t)
        seen.add(t)
        ans[t] = ans[v] + cnt[t]

print(*ans[1:])


Measured memory_bytes: 156732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int B = 1;
  for (int i = 0; i < N; i++) {
    int B2 = B;
    B += K;
    B2 *= 2;
	if (B > B2) {
      B = B2;
    }
  }
  cout << B << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int K, X;
	cin >> K >> X;
	for (int i = X - K + 1; i <= X + K - 1; i++)
	{
		cout << i;
		if (i != X + K - 1)cout << " ";
	}
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C + D){
    cout << "Left" << endl;
  }
  
  else if (A + B < C + D){
    cout << "Right" << endl;
  }
  
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k,t1,t2,t,sol,k1,s1,s2;
char s[1000006],v[1000006];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;++i) cin>>s[i];
    for(int i=1;i<=n;++i)
    {
        if(s[i]==s[i-1]) ++sol;
        else v[++t]=s[i];
    }
    for(int i=1;i<=t;++i)
    {
        if(v[i]=='L') continue;
        if(i==1||i==t) ++t1;
        else ++t2;
    }
    k1=k;
    s1+=min(k1*2,t2*2);
    if(k1>t2)
    {
        k1-=t2;
        s1+=min(t1,k1);
    }



    t1=t2=0;
    for(int i=1;i<=t;++i)
    {
        if(v[i]=='R') continue;
        if(i==1||i==t) ++t1;
        else ++t2;
    }
    k1=k;
    s2+=min(k1*2,t2*2);
    if(k1>t2)
    {
        k1-=t2;
        s2+=min(t1,k1);
    }
    if(t>1) sol=sol+max(s1,s2);
    cout<<sol;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=m-1; i>=n; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x,n/2)%MOD;
  return x%MOD*POW(x,n-1)%MOD;
}

ll POW2(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW2(x*x,n/2);
  return x*POW2(x,n-1);
}

ll POW3(ll x,ll n,ll m){
  x%=m;
  if(n==0)return 1;
  if(n%2==0)return POW3(x*x,n/2,m)%m;
  return x*POW3(x,n-1,m)%m;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

ll lcm(ll u, ll v) {
  return u*v/gcd(u,v);
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll KAI2(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI2(m-1);
}

ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll COM2(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI2(m)/KAI2(n)/KAI2(m-n);
}

ll DEC(ll x,ll m,ll n)//xのm進数でのx^nの位の値
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)//xのn進数での桁数
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)//x!のnで割り切れる回数
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)//xのnで割り切れる回数
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

ll SGS(ll x,ll y, ll m)//1+x+…+x^(y-1)をmで割った余り
{
  if(y==0)return 0;
  if(y%2==0){
    return (1+POW3(x,y/2,m))*SGS(x,y/2,m)%m;
  }
  return (1+x*SGS(x,y-1,m))%m;
}

ll SSGS(ll x,ll y,ll m)//Σ[k=1→y](1+x+…+x^(k-1))をmで割った余り
{
  if(y==0)return 0;
  if(y==1)return 1;
  if(y%2==0){
    return (SSGS(x,y/2,m)*(POW3(x,y/2,m)+1)%m+SGS(x,y/2,m)*y/2%m)%m;
  }
  return (SSGS(x,y-1,m)*x%m+y)%m;
}

int main()
{
  ll a,b,c;
  cin >> a >> b >> c;
  if(b==1)printf("0");
  else printf("%lld",a-b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll n,a,b;cin>>n>>a>>b;
    cout<<n/(a+b)*a+min(a,n%(a+b))<<endl;
    return 0;
}

Measured memory_bytes: 3528
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

const int N=10005;

int a,b,n,stack[N],ans[N];

int main()
{
	scanf("%d%d",&a,&b);
	if (a<=b) {printf("Impossible");return 0;}
	n=a+b;
	int top=0,re;
	for (int i=1;i<n;i++)
	{
		if (!top) {stack[++top]=i;continue;}
		printf("? %d %d\n",stack[top],i);
		fflush(stdout);
		char op[2];scanf("%s",op);
		if (op[0]=='N') top--;
		else stack[++top]=i;
	}
	re=stack[top];
	for (int i=0;i<n;i++)
	{
		printf("? %d %d\n",re,i);
		fflush(stdout);
		char op[2];scanf("%s",op);
		if (op[0]=='N') ans[i]=0;
		else ans[i]=1;
	}
	printf("! ");
	for (int i=0;i<n;i++) putchar(ans[i]+'0');
	puts("");
	return 0;
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
#define int long long
 
using namespace std;
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    int dpl[n + 1], dpr[n + 1];
    dpl[0] = 0;
    dpr[0] = 0;
    int last = -10000000;
    for (int i = 1; i <= n; ++i) {
        if (s[i - 1] == 'x') dpl[i] = dpl[i - 1];
        else if (last + c < i) {
            last = i;
            dpl[i] = dpl[i - 1] + 1;
        }
        else dpl[i] = dpl[i - 1];
    }
    last = -10000000;
    for (int i = 1; i <= n; ++i) {
        if (s[n - i] == 'x') dpr[i] = dpr[i - 1];
        else if (last + c < i) {
            last = i;
            dpr[i] = dpr[i - 1] + 1;
        }
        else dpr[i] = dpr[i - 1];
    }
    //for (int i = 0; i <= n; ++i) cout << dpr[i] << " ";
    for (int i = 0; i < n; ++i) {
        int left = i;
        int right = n - i - 1;
        if (s[i] == 'o' && dpl[left] + dpr[right] < k) cout << i + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 5012
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

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

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	int a,b;
	int c[5002],d[5002];
	
	scanf("%d%d",&a,&b);
	rep(i,a){
		scanf("%d",&c[i]);
	}
	rep(i,b){
		scanf("%d",&d[i]);
	}
	
	int ret = 0;
	
	rep(i,b){
		int k = 0;
		for(int j = i ; j < b ; j ++){
			while(k < a && c[k] != d[j])k ++;
			if(k >= a)break;
			ret = max ( ret , j-i+1 );
			k ++;
		}
	}
	
	printf("%d\n",ret);
}

Measured memory_bytes: 1212
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;


void output(vector<int> & V);

int main()
{
    vector<int> V;

    int n;
    cin >> n;

    int a;
    while (n--)
    {
        cin >> a;
        V.push_back(a);
    }

    if (prev_permutation(V.begin(), V.end()))
        output(V);
    
    next_permutation(V.begin(), V.end());
    output(V);

    if (next_permutation(V.begin(), V.end()))
        output(V);


}


void output(vector<int> & V)
{
    vector<int>::iterator it = V.begin();
    cout << *it++;
    while (it != V.end())
    {
        
        cout << ' ' << *it;
        it++;
    }
    cout << endl;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<ll>A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  vector<ll>c(N,0);
  ll ans=1;
  for(int i=0;i<N;i++){
    c[A[i]]++;
    if(A[i]==0)ans=(ans*(4-c[0]))%MOD;
    else ans=(ans*(c[A[i]-1]-c[A[i]]+1))%MOD;
  }
  cout<<(ans)%MOD<<endl;
  return 0;
}


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

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

using namespace std;
using ll = long long;

template<typename T>
T pown(T b, ll e) {
    if(e == 0) return 1;
    T p = pown(b, e / 2);
    if(e % 2 == 0) return p * p;
    return p * p * b;
}

template<const int mod>
struct Intmod {
    ll a;
    Intmod(ll a = 0): a(((a % mod) + mod) % mod) {}

    Intmod operator-() const {return Intmod(-a);}

    Intmod& operator+=(const Intmod b) {
        if((a += b.a) >= mod) a -= mod;
        return *this;
    }
    Intmod& operator+=(const ll b) {
        if((a += b) >= Intmod(mod).a) a -= mod;
        return *this;
    }
    Intmod& operator-=(const Intmod b) {
        if((a -= b.a) < 0) a += mod;
        return *this;
    }
    Intmod& operator-=(const ll b) {
        if((a -= Intmod(b).a) < 0) a += mod;
        return *this;
    }
    Intmod& operator*=(const Intmod b) {
        (a *= b.a) %= mod;
        return *this;
    }
    Intmod& operator*=(const ll b) {
        (a *= Intmod(b).a) %= mod;
        return *this;
    }

    template<typename T> Intmod operator+(const T b) const {return Intmod(*this) += b;}
    template<typename T> Intmod operator-(const T b) const {return Intmod(*this) -= b;}
    template<typename T> Intmod operator*(const T b) const {return Intmod(*this) *= b;}

    // Valid for prime mod. pown() needs to be included.
    int i = 0;
    Intmod inv() {
        if(a == 0) throw "Inverse of zero does not exist.";
        if(!i) i = pown(*this, mod - 2).a;
        return Intmod(i);
    }
    Intmod& operator/=(const Intmod b) {return *this *= b.inv();}
    Intmod& operator/=(const ll b) {return *this *= Intmod(b).inv();}
    template<typename T> Intmod operator/(const T b) const {return Intmod(*this) /= b;}
};
template<const int mod> Intmod<mod> operator+(const ll b, Intmod<mod> a) {return a += b;}
template<const int mod> Intmod<mod> operator-(const ll b, Intmod<mod> a) {return a -= b;}
template<const int mod> Intmod<mod> operator*(const ll b, Intmod<mod> a) {return a *= b;}
template<const int mod> Intmod<mod> operator/(const ll b, Intmod<mod> a) {return a /= b;} //Valid for prime mod.

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

    const int MOD = 1000000007;

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a.at(i);

    Intmod<MOD> sum = 0, sum_diag = 0, ans = 1;

    rep(i, n) {
        sum += a.at(i);
        sum_diag -= a.at(i) * a.at(i);
    }

    ans *= sum;
    ans *= sum;
    ans += sum_diag;
    ans /= 2;

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

    return 0;
}

Measured memory_bytes: 4780
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){

int N,M;
cin>>N>>M;
bool path[N+1][N+1];
memset(path,false,sizeof(path));
rep(i,M){
    int a,b;
    cin>>a>>b;
    path[a][b]=true;
    path[b][a]=true;
}

vector<int> order(N-1);
int count=0;
    for (int i = 2; i <= N; ++i) order[i-2] = i;

    // 探索
    
    do {
        bool judge=true;
        if(!path[1][order[0]])judge=false;
        rep(i,N-2)if(!path[order[i]][order[i+1]])judge=false;
        if(judge)count++;

    } while (next_permutation(order.begin(), order.end()));

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

Measured memory_bytes: 3576
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: String,
    }
    let mut sum: i32 = 0;
    for c in n.chars() {
        sum = (sum + (c as i32) - ('0' as i32)) % 9;
    }
    println!("{}", if sum == 0 { "Yes" } else { "No" });
}


Measured memory_bytes: 2344
#include<iostream>
#include<algorithm>
#include<cstring>
#include<numeric>
#include<vector>
using namespace std;

#define int long long

#ifdef lioraju
	#define ndbg(x) 
#else
	#define ndbg(x) x
#endif

const int mxsz = 1e5 + 5;

int v[mxsz][5];

int dp[mxsz][5];
bool vis[mxsz][5];

int d(int i, int j)
{
	if (!i) return v[i][j];
	if (vis[i][j]) return dp[i][j];
	
	vis[i][j] = 1;
	int mxn = -1e9;
	for (int j2=0;j2<3;j2++)
		if (j2!=j) mxn = max(mxn, d(i-1, j2) + v[i][j]);
	
	return dp[i][j] = mxn;
}

signed main()
{
	ndbg( ios::sync_with_stdio(0); cin.tie(0); );
	int n; cin>>n;
	for (int i=0;i<n;i++)
		for (int j=0;j<3;j++) cin>>v[i][j];
	
	int mxn = 0;
	for (int j=0;j<3;j++) mxn = max(mxn, d(n-1, j));
	cout<<mxn<<'\n';
}

Measured memory_bytes: 14848
n = int(input())
a = list(map(int,input().split()))
dic = {}
for i in a:
    if i in dic:
        dic[i] +=1
    else:
        dic[i] = 1

ans = 0
for i in dic.values():
    ans += i * (i - 1) // 2

for i in a:
    sa = dic[i] * (dic[i] - 1) // 2 - ((dic[i] - 1) * (dic[i] - 2) // 2)
    print(ans - sa)

Measured memory_bytes: 25644
#include <bits/stdc++.h>
using namespace std;
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 fact(int n); 
int nCr(int n, int r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
// Returns factorial of n 
int fact(int n) 
{ 
    int res = 1; 
    for (int i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 










int main() {
  int N=0;
  cin >> N;
  if(N%2==0){
    cout << N/2 << endl;
  } 
  else {
    cout << N/2 +1 << endl;
  }
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli a,b,c;
	cin>>a>>b>>c;
	lli k,count=0;
	cin>>k;
	while(1)
	{
		if(b<=a)
		{
			b*=2;
			count++;
		}
		else
			break;
	}
	while(1)
	{
		if(c<=b)
		{
			c*=2;
			count++;
		}
		else
			break;
	}
	if(count<=k)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}

	
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<math.h>
#include<string>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a;
	cin >> b;
	cin >> c; 
	cin >> d;
	if (a >= b && c >= d) cout << b + d;
	else if (a >= b && c < d) cout << b+c;
	else if (a < b && c >= d) cout << a + d;
	else if (a < b && c < d) cout << a + c;
}

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

void solve(const string & in){
  for(int i = 0;i < in.size();i++){
    if (i + 1 < in.size() && in[i] == in[i+1]){
      cout << i+1 <<" " << i+2 << endl;
      return;
    }
    if (i + 2 < in.size() && in[i] == in[i+2]){
      cout << i+1 <<" " << i+3 << endl;
      return;
    }
  }

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


main(){
  string in;
  cin >> in;
  solve(in);
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>
#include <cmath>    
#include <complex>
using namespace std;

int tmp[101]={0};

int ab(int ans){
	int u=ans,d=ans;
	if(tmp[ans]==0){
		return ans;
	}else{
		while(1){
			if(tmp[u]==0){
				break;
			}
			u++;
		}
		while(1){
			if(tmp[d]==0){
				break;
			}
			d--;
		}
		if(abs(ans-d)<=abs(ans-u)){
			return d;
		}else{
			return u;
		}
	}
}

int main() {
	int x,n;
	cin>>x>>n;
	int a[n],ans=x;
	for(int i=0;i<n;i++){
		cin>>a[i];
		tmp[a[i]]=1;
		
	}
	ans=ab(ans);
	cout<<ans<<endl;
	// your code goes here
	return 0;
}

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

int main(){
    int X,Y;
    cin >> X >> Y;
    if (Y%2==0 && Y >= 2*X && Y<=4*X){
        cout << "Yes" << endl;
    }
    else{
        cout << "No"<< endl;
    }
}

Measured memory_bytes: 3584
from __future__ import division
from collections import defaultdict, deque
from heapq import heappush, heappop
from sys import stdin


def floyd(graph):
    n = len(graph["nodes"])
    dis = [[10 ** 20 for _ in range(n)] for _ in range(n)]
    for i in range(n): dis[i][i] = 0

    for x in graph["nodes"]:
        for (y, w) in graph["adj"][x]:
            dis[x][y] = w


    for k in range(n):
        for i in range(n):
            for j in range(n):
                if dis[i][k] < 10 ** 20 and dis[k][j] < 10 ** 20:
                    dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])

    return dis


if __name__ == '__main__':
    V, E= map(int, stdin.readline().strip().split())
    graph = {}
    graph["nodes"] = [i for i in range(V)]
    graph["edges"] = []
    graph["adj"] = defaultdict(list)
    for _ in range(E):
        x, y, w = map(int, stdin.readline().strip().split())
        graph["edges"].append((x, y, w))
        graph["adj"][x].append((y, w))

    dis = floyd(graph)

    negcycle = False

    for i in range(len(graph["nodes"])):
        if dis[i][i] < 0:
            negcycle = True

    if negcycle:
        print "NEGATIVE CYCLE"
    else:
        for row in dis:
            print ' '.join(map(lambda x: str(x) if x < 10 ** 20 else "INF", row))

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

int main()
{
	int n;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++)
	{
		cin>>a[i];
	}
	sort(a, a+n);
	cout<<a[n/2]-a[n/2-1];
 } 


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
#define PP 1000000007
using namespace std;

ll N, M, Ans = 0;
priority_queue<ll> Q;

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

rep(i, 0, N){

  ll a;cin >> a;

  Q.push(a);

}

rep(i, 0, M){

  ll m = Q.top();

  Q.pop();

  Q.push(m/2);

}

rep(i, 0, N){

  Ans += Q.top();

  Q.pop();

}
cout << Ans;
}

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

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(string, s);
    unordered_map<char, int> m;
    for(char &c : s) m[c] ++;
    CoutYN(max({m['a'], m['b'], m['c']}) - min({m['a'], m['b'], m['c']}) <= 1);
}





Measured memory_bytes: 512
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define LL long long

using namespace std;

const int N = 1e6 + 7;
const LL mod = 1e9 + 7;
const int B = sqrt(1e5);

LL n,k,q;
LL d[4*N];
LL a[N];

void f( LL x , LL y )
{
    while( x < N ){
        d[x] += y;
        x += x & -x;
    }
}

LL ff( LL x )
{
    LL cnt = 0;
    while( x > 0 ){
        cnt += d[x];
        x -= x & -x;
    }
    return cnt;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    cin >> n >> k >> q;
    f(1 , k);
    for( int i = 1; i <= q; i++ ){
        LL x;
        cin >> x;
        f(x + 1 , -1);
        f(1 , -1);
        f(x , 1);
    }
    for( int i = 1; i <= n; i++ ){
        LL x = ff(i);
        if( x > 0 )cout << "Yes\n";
        else cout << "No\n";
    }
}


Measured memory_bytes: 6784
import math

def is_prime(X):
    if X == 1:
        return 0
    for i in range(2, int(math.sqrt(X)) + 1):
        if X % i == 0:
            return 0
    return 1

N = int(input())

while True:
    if is_prime(N):
        print(N)
        break
    else:
        N += 1

Measured memory_bytes: 3060
import bisect

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a.sort()
b.sort()
c.sort()
ans=0
for i in range(n):
	a_l=bisect.bisect_left(a,b[i])
	c_l=bisect.bisect(c,b[i])
	ans+=a_l*(n-c_l)

print(ans)    


Measured memory_bytes: 23360
#! /usr/bin/env python3

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

flag = 0
done = [0] * (N + 1)

root = []
ind = 0

ind = A[0]
root = [1]
done[1] = 1

while True:

    if done[ind]:
        flag = 1
        break
    done[ind] = 1

    root += [ind]
    ind = A[ind-1]

if flag:
    if len(root) <= K:
        left = root.index(ind) - 1
        loopcnt = len(root) - (root.index(ind))

        root2 = root[left+1:]
        print(root2[(K-(left+1)) % loopcnt])
    else:
        print(root[K])
else:
    print(root[K-1])


Measured memory_bytes: 33608
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());

        // 降順
        PriorityQueue<Integer> A = new PriorityQueue<>(Collections.reverseOrder());
        for (int i = 0; i < N; i++) {
            A.add(Integer.parseInt(scanner.next()));
        }
        scanner.close();

        int useTicketCount = M;
        // 割引件を使い切る
        while (useTicketCount > 0) {
            int tmp = (int) Math.floor(A.remove() / 2.0);
            A.add(tmp);
            useTicketCount--;
        }

        long ans = 0;
        for (int n : A) {
            ans += n;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 48676
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
using namespace std;
 int main(){
   int n; cin >> n;
   int v[n],c[n];
   for(int i=0;i<n;i++) cin >> v[i];
   for(int j=0;j<n;j++) cin >> c[j];
   int ans=0;
   for(int k=0;k<n;k++){
     if(v[k]>=c[k]) ans+=(v[k]-c[k]);
     else ans+=0;
   }
   cout<<ans<<endl;
   return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

bool visited[101010];
ll ans[101010];
int main() {
    ll n;
    cin>>n;

    vector<ll> c(101010);
    vector<vector<ll>> node(101010);
    REP(i, 0, n-1){
        ll a, b;
        cin>>a>>b;
        a--;
        b--;
        node[a].emplace_back(b);
        node[b].emplace_back(a);
    }
    REP(i, 0, n) cin>>c[i];

    sort(c.begin(), c.end());
    reverse(c.begin(), c.end());

    ll mx=0, idx;
    REP(i, 0, n){
        if(mx<node[i].size()){
            mx=node[i].size();
            idx=i;
        }
    }

    ll cnt=0;
    queue<ll> que, que2;
    que.push(idx);
    while(!que.empty()){
        ll cur=que.front();
        que.pop();
        visited[cur]=true;
        ans[cur]=c[cnt];
        cnt++;

        REP(i, 0, node[cur].size()){
            if(visited[node[cur][i]]) continue;
            que.push(node[cur][i]);
        }
    }

    ll sum=0;
    REP(i, 0, n) visited[i]=false;
    que2.push(0);
    while(!que2.empty()){
        ll cur=que2.front();
        que2.pop();
        visited[cur]=true;

        REP(i, 0, node[cur].size()){
            if(visited[node[cur][i]]) continue;

            sum+=min(ans[cur], ans[node[cur][i]]);
            que2.push(node[cur][i]);
        }
    }


    cout<<sum<<endl;
    REP(i, 0, n-1){
        cout<<ans[i]<<" ";
    }
    cout<<ans[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 3968
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] deta = new int[n];

        for (int i = 0; i < n; i++) {
            deta[i] = sc.nextInt();
        }
        for (int i = n - 1; i > 0; i--) {
            System.out.print(deta[i] + " ");
        }
        System.out.println(deta[0]);
    }
}



Measured memory_bytes: 26304
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
ll f(ll n){
  ll ans = 0;
  while(n > 0) {
    n /= 10;
    ans++;
  }
  return ans;
}
int main(){
  ll n;
  cin >> n;
  ll ans = f(n);

  for(ll i = 1; i <= sqrt(n) + 1; i++){
    if(n % i == 0){
      ans = min(ans, f(max((ll)i, n / i)));
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <variant>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w;
  cin>>h>>w;
  int ch,cw;
  cin>>ch>>cw;
  --ch;--cw;
  int dh,dw;
  cin>>dh>>dw;
  --dh;--dw;
  vector<string> mat(h);
  REP(i,h)cin>>mat[i];
  constexpr int INF = 1e8;
  vecint dist(h*w, INF);
  dist[ch*w+cw] = 0;
  deque<tuple<int,int>> q;
  q.emplace_back(ch,cw);
  while (!q.empty()) {
    auto[i,j] = q.front();
    q.pop_front();
    int di[]={1,0,-1,0};
    int dj[]={0,-1,0,1};
    REP(k,4) {
      int ni=i+di[k];
      int nj=j+dj[k];
      if(ni<0||nj<0||ni>=h||nj>=w) continue;
      if(mat[ni][nj] == '#')continue;
      if(dist[ni*w+nj] > dist[i*w+j]) {
        dist[ni*w+nj] = dist[i*w+j];
        q.emplace_front(ni,nj);
      }
    }
    REP(r,5)REP(c,5) {
      int ni=i+r-2;
      int nj=j+c-2;
      if(ni<0||nj<0||ni>=h||nj>=w) continue;
      if(mat[ni][nj] == '#')continue;
      if(dist[ni*w+nj] > dist[i*w+j]+1) {
        dist[ni*w+nj] = dist[i*w+j]+1;
        q.emplace_back(ni,nj);
      }
    }
  }
  if (dist[dh*w+dw] < INF) {
    cout<<dist[dh*w+dw]<<endl;
  } else {
    cout<<-1<<endl;
  }
  return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<int,pii> box;
#define s first
#define w second.first
#define v second.second
#define maxn 1005
#define maxs 20005
int main()
{
	int n;
	scanf("%d",&n);
	box b[maxn];
	for(int i=0; i<n; i++){
		scanf("%d%d%d", &b[i].w, &b[i].s, &b[i].v);
		b[i].s += b[i].w;
	}
	sort(b,b+n);
	LL dp[maxs] = {};
	LL ans = 0;
	for(int i=0; i<n; i++)
	{
		for(int j=b[i].s; j>=b[i].w; j--)
		{
			dp[j] = max(dp[j], dp[j-b[i].w]+b[i].v);
			ans = max(ans, dp[j]);
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    int ans = (a - 1) * (b - 1);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ld long double
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
const int MAX = 510000;
const ll MOD = 1000000007;
int main(){
  int n;
  cin >> n;
  set<int> even;
  set<int> odd;
  int b[n];
  rep(i,n){
    int u;
    cin >> u;
    if(i%2==0)even.insert(u);
    else odd.insert(u);
    b[i]=u;
  }
  sort(b,b+n);
  int cnt=0;
  rep(i,n){
    int u=b[i];
    if((i%2==0&&odd.count(u))||(i%2==1&&even.count(u)))cnt++;
  }
  cout << cnt/2 << endl;
}


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#define llint long long

using namespace std;

llint N, M;
vector<llint> G[100005];
vector< pair<bool, llint> > cmp;
bool used[100005];
int color[100005];

bool check(int v)
{
	queue<int> Q;
	Q.push(v);
	color[v] = 1;
	
	int u;
	while(Q.size()){
		u = Q.front();
		Q.pop();
		for(int i = 0; i < G[u].size(); i++){
			if(color[G[u][i]] == color[u]) return false;
			if(color[G[u][i]] == color[u] * -1) continue;
			color[G[u][i]] = color[u] * -1;
			Q.push(G[u][i]);
		}
	}
	return true;
}

llint count(int v)
{
	used[v] = true;
	llint ret = 0;
	for(int i = 0; i < G[v].size(); i++){
		if(used[G[v][i]]) continue;
		ret += count(G[v][i]);
	}
	return ret+1;
}

int main(void)
{
	cin >> N >> M;
	llint u, v;
	for(int i = 0; i < M; i++){
		cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	bool bi; int cnt;
	llint bi_cnt = 0, nbi_cnt = 0, iso_cnt = 0;
	
	for(int i = 1; i <= N; i++){
		if(used[i]) continue;
		cmp.push_back( make_pair( bi = check(i), cnt = count(i) ) );
		if(cnt == 1) iso_cnt++;
		else{
			if(bi) bi_cnt++;
			else nbi_cnt++;
		}
	}
	
	llint ans = 0;
	for(int i = 0; i < cmp.size(); i++){
		if(cmp[i].second == 1) ans += N;
		else if(cmp[i].first) ans += bi_cnt*2 + nbi_cnt + iso_cnt * cmp[i].second;
		else ans += bi_cnt + nbi_cnt + iso_cnt * cmp[i].second;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12160
#include<cstdio>
int a[20],b[20];
int f[1<<19][20];
int vis[20];

int min(int a,int b){ return a>b?b:a; }

int main(){
    //printf("%d\n",(1<<18)*18*18);
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    for(int i = 1; i <= n; i++) scanf("%d",&b[i]);
    int inf = 1e8+7;
    f[0][0] = 0;
    int ans = inf;
    for(int i = 1; i < (1<<n); i++){
        for(int j = 1; j <= n; j++){
            f[i][j] = inf;
            int mask = i, cost = 0, cnt = 0;
            for(int k = 1; k <= n; k++){
                vis[k] = mask%2;
                if(k>j) cost += vis[k];
                cnt += vis[k];
                mask /= 2;
            }
            if(vis[j]){
                mask = i;
                int value = ((j-cnt)%2)?b[j]:a[j];
                for(int k = 1; k <= n; k++){
                    if(vis[k] && k!=j){
                        int lastValue = ((k-cnt-1)%2)?b[k]:a[k], lastMask = mask^(1<<(j-1));
                        if(lastValue<=value) f[i][j] = min(f[i][j],f[lastMask][k]+cost);
                    }
                }
                if(cnt==1) f[i][j] = 0;
            }
            if(i==((1<<n)-1)) ans = min(ans,f[i][j]);
            //printf("f[%d][%d] = %d\n",i,j,f[i][j]);
        }
    }
    if(ans<inf) printf("%d\n",ans);
    else printf("-1\n");
    return 0;
}


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

int main() {
  int N, x;
  cin >> N >> x;
  if (x == 1 || x == 2 * N - 1) {
    cout << "No" << endl;
    return 0;
  }
  vector<int> ans(2 * N - 1);
  for (int i = 0; i < 2 * N - 1; i++)
    ans[i] = ((x - N) + i + 2 * N - 1) % (2 * N - 1) + 1;

  cout << "Yes" << endl;
  for (int a : ans) {
    cout << a << endl;
  }
}

Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

int h, w; 

void solve() {
	cin >> h >> w;
	vector<vector<int>> a(h, vector<int>(w));
	vector<vector<int>> b(h, vector<int>(w));
    rep(i, h) {
        rep(j, w) {
            cin >> a[i][j];
        }
    }
    rep(i, h) {
        rep(j, w) {
            cin >> b[i][j];
        }
    }
	//vector<vector<bitset<300000>>> dp(h, vector<bitset<300000>>(w, 0));
	static bitset<300000> dp[85][85];
	int x = a[0][0] - b[0][0] + 80;
	int y = b[0][0] - a[0][0] + 80;
	dp[0][0][x] = 1;
	dp[0][0][y] = 1;
	rep(i, h) {
		rep(j, w) {
			if(i - 1 >= 0) dp[i][j] |= (dp[i - 1][j] << (a[i][j] - b[i][j] + 80));
			if(i - 1 >= 0) dp[i][j] |= (dp[i - 1][j] << (b[i][j] - a[i][j] + 80));
			if(j - 1 >= 0) dp[i][j] |= (dp[i][j - 1] << (a[i][j] - b[i][j] + 80));
			if(j - 1 >= 0) dp[i][j] |= (dp[i][j - 1] << (b[i][j] - a[i][j] + 80));
		}
	}
	int ans = inf;
	rep(k, 300000) {
		if(dp[h - 1][w - 1][k]) {
			chmin(ans, abs(k - (h + w - 1) * 80));
		}
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}


Measured memory_bytes: 250368
A, B, C = [int(x) for x in input().split()]

c1 = 0 if C % 2 == 0 else A * B
c2 = 0 if B % 2 == 0 else A * C
c3 = 0 if A % 2 == 0 else B * C
ans = min(c1, c2, c3)

print(ans)


Measured memory_bytes: 2940