akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(all(c)); c.erase(unique(all(c)), c.end()); }
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

inline ll powll(ll x,ll y) {ll p=1; while(y--) p*=x; return p;}

template <class T> T comb(T n, T r)
{
    if (n < 0 || n < r || r < 0)
        return 0;

    r = min(r, n - r);
    if (r == 0)
        return 1;

    vector<T> numer(r);
    vector<T> denom(r);

    iota(all(numer), n - r + 1);
    iota(all(denom), 1);

    for (T i = 1; i < r; i++) {
        T divisor = denom[i];
        if (divisor > 1) {
            T offset = (n - r) % (i + 1);
            for (T j = i; j < r; j += i + 1) {
                numer[j - offset] /= divisor;
                denom[j] /= divisor;
            }
        }
    }
    
    T p = 1;
    for(T i = 0; i < r; i++)
        p *= numer[i];

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

    int N, P;
    cin >> N >> P;

    int A;
    int even, odd = 0;
    rep(i, N) {
        cin >> A;
        if (A%2) odd++;
    }
    even = N - odd;

    ll ans = 0;
    for (int i = (P == 0 ? 0 : 1); i <= odd; i+=2)
        ans+= comb(odd, i);
    ans *= powll(2, even);

    cout << ans << endl;
}


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

using ld = long double;
int main(){
    cout<<fixed<<setprecision(12);
    int n;
    cin>>n;
    vector<complex<ld>> a(n);
    ld l;
    const ld pi = acos(-1);
    cin>>l;
    rep(i,n){
        ld x;
        cin>>x;
        a[i]=complex<ld>(cos(x*pi/l),sin(x*pi/l));
    }
    complex<ld> ans=0;
    rep(i,n)rep(j,i){
        ans-=((ld)1.0*(i-j-1))*a[i]*a[j];
        ans+=((ld)1.0*(n-2-(i-j-1)))*a[i]*a[j];
    }
    ans*=6.0/n/(n-1)/(n-2);
    cout<<ans.real()<<" "<<ans.imag()<<endl;
    return 0;

}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <algorithm>

int main()
{
  int N;
  scanf("%d", &N);

  int max;
  if(N >= 64) max = 64;
  else if(N >= 32) max = 32;
  else if(N >= 16) max = 16;
  else if(N >= 8) max = 8;
  else if(N >= 4) max = 4;
  else if(N >= 2) max = 2;
  else if(N == 1) max = 1;
  printf("%d\n", max);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int a,b,w;
char op;
w=0;
while(1){
scanf("%d",&a);scanf("%s",&op);scanf("%d",&b);
if(op=='+')w=a+b;
else if(op=='-')w=a-b;
else if(op=='*')w=a*b;
else if(op=='/')w=a/b;
else if(op=='?')break;
printf("%d\n",w);
}






return 0;
}

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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

vector< ll > divisor(ll n) {
  vector< ll > ret;

  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);

      if (i != (n / i)) {
        ret.push_back(n / i);
      }
    }
  }

  return ret;
}

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

  ll N;

  CIN(N);

  vector< ll > d = divisor(N);

  ll c = N;
  for (ll i : d) {
    for (ll j : d) {
      if (i * j == N) {
        c = min(c, i + j - 2);
      }
    }
  }
  COUT(c);

  return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  string s;cin>>s;
  int result = 0;
  rep(i, s.size())result += s[i]-'0';

  if(result%9==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 3752
n=int(input())
s=input()
cnt=[1 for i in range(26)]

for c in s:
    cnt[ord(c) - ord('a')]+=1
res=1

MOD=10**9+7
for num in cnt:
    res = (res*num)%MOD
res = (res-1+MOD)%MOD
print(res)


Measured memory_bytes: 3188
#include <stdio.h>

int main(){
  int flag;
  double x[4],y[4];
  double al,be;
  double s_x, s_y, t_x, t_y, u_x, u_y;
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3]) != EOF){
    flag = 0;
    s_x = x[1]-x[0];
    s_y = y[1]-y[0];
    t_x = x[3]-x[0];
    t_y = y[3]-y[0];
    u_x = x[2]-x[0];
    u_y = y[2]-y[0];
    al = (u_x*t_y-t_x*u_y)/(s_x*t_y-t_x*s_y);
    be = (u_x*s_y-s_x*u_y)/(t_x*s_y-s_x*t_y);
    if(al+be <= 1){
      flag = 1;
    }
    s_x = x[0]-x[1];
    s_y = y[0]-y[1];
    t_x = x[2]-x[1];
    t_y = y[2]-y[1];
    u_x = x[3]-x[1];
    u_y = y[3]-y[1];
    al = (u_x*t_y-t_x*u_y)/(s_x*t_y-t_x*s_y);
    be = (u_x*s_y-s_x*u_y)/(t_x*s_y-s_x*t_y);
    if(al+be <= 1){
      flag = 1;
    }
    if(flag == 1){
      printf("NO\n");
    }else{
      printf("YES\n");
    }
  }
  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define endl "\n"
#define PI 3.14159265
int  MAX_CHARS=10000;
const int mod=1e9+7;
const int INF =LONG_LONG_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}

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

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

    for(int len=1;len<=n;len++)
    {
        for(int i=0;i<=n-len;i++)
        {
            int j=len+i-1;
            dp[i][j]=1e18;
            //cout<<i<<" "<<j<<endl;

            if(len==1)
                {dp[i][j]=0;continue;}
            int x=pre[j]-(i-1>=0?pre[i-1]:0);
            for(int k=i;k<=j-1;k++)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+x);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1536
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

bool isInside(long xp1, long yp1, long xp2, long yp2, long xp3, long yp3, long x, long y) {
    xp1 -= x;
    xp2 -= x;
    xp3 -= x;
    yp1 -= y;
    yp2 -= y;
    yp3 -= y;
    auto s1 = xp1*yp2 - xp2*yp1;
    auto s2 = xp2*yp3 - xp3*yp2;
    auto s3 = xp3*yp1 - xp1*yp3;
    return s1*s2 > 0 && s2*s3 > 0 && s3*s1 > 0;
}

void main(){
    auto n = readLong();
    foreach(i; iota(n)) {
        auto line = readLongs();
        writeln(isInside(line[0], line[1], line[2], line[3], line[4], line[5], line[6], line[7])
            ^ isInside(line[0], line[1], line[2], line[3], line[4], line[5], line[8], line[9]) ?
            "OK": "NG");
    }
}

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

const int inf = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3fLL;

const ll mx = 1e18;

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

    int n; cin >> n;
    vector<ll> as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    if (count(as.begin(), as.end(), 0)) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    for (auto a: as) {
        if (ans * a > mx || ans > mx / a) {
            cout << -1 << endl;
            return 0;
        }
        ans *= a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3992
(H, W) = list(map(int, input().split()))

a = list()
for height in range(H):
    line = input()
    if line == '.' * W:
        pass
    else:
        a.append(list(line))

# 転置して空白行を削除
a = [list(x) for x in zip(*a)]
a_trim = list()
for a_row in a:
    if ''.join(a_row) == '.' * len(a_row):
        pass
    else:
        a_trim.append(a_row)

a = [list(x) for x in zip(*a_trim)]  # 転置

for row in a:
    print(''.join(row))


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

map<int, int> mp;
int main(){
	int n;
	cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		v.push_back(a);
	}
	v.push_back(0);
	v.push_back(0);
	v.push_back(0);
	v.push_back(0);
	sort(v.begin(), v.end());
	vector<int> len;
	while (len.size() < 2){
		if (v[v.size() - 2] == v[v.size() - 1]){
			len.push_back(v.back());
			v.pop_back();
			v.pop_back();
		}
		else{
			v.pop_back();
		}
	}
	long long int ans = len[0];
	ans *= len[1];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 892
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 5e5 + 4;

int n, p[N], pr[N];

string s;

void fpi(int* pi) {
    pi[0] = 0;
    for (int i = 1; i < n; ++i) {
        int j = pi[i - 1];
        while (j && s[i] != s[j]) {
            j = pi[j - 1];
        }
        if (s[i] == s[j]) {
            ++j;
        }
        pi[i] = j;
    }
}

bool check(int len, int c) {
    if (len == 1) {
        return true;
    }
    return len == c || len % c;
}

void calc() {
    n = size(s);
    fpi(p);
    reverse(all(s));
    fpi(pr);

    int cycle = n - p[n - 1];
    if (cycle == n || n % cycle) {
        cout << "1\n1\n";
    } else {
        if (cycle == 1) {
            cout << n << "\n1\n";
        } else {
            int res = 0;
            for (int i = 0; i < n; ++i) {
                int c1 = i + 1 - p[i];
                int c2 = (n - i - 1) - pr[n - i - 2];
                if (check(i + 1, c1) && check(n - i - 1, c2)) {
                    ++res;
                }
            }
            cout << "2\n" << res << "\n";
        }
    }
}

void solve() {
    cin >> s;
    calc();
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 7728
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int main()
{
	int i,j,k,n,m,x,y;
	ll a,b;
	cin>>a>>b;
	x=0;
	while(a<=b)
	{
		a*=2ll;
		x++;
	}
	printf("%d",x);
	return 0;
}

Measured memory_bytes: 256
s=input()

ss=s[::-1]

if ss!=s:
    print("No")
    exit()

t=s[:(len(s)-1)//2]
tt=t[::-1]
if tt!=t:
    print("No")
    exit()

u=s[(len(s)+1)//2:]
uu=u[::-1]
if uu!=u:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define Nmax 300005

using namespace std;

struct Segm
{
    int x,y,ind;
    bool operator <(const Segm &A) const
    {
        return y<A.y;
    }
} segm[Nmax],Ev[Nmax*20];
int aib[Nmax],len,ans[Nmax];

inline void upd(int p, int val)
{
    for(int i=p;i;i-=(i&(-i))) aib[i]+=val;
}

inline int qry(int p)
{
    int sol=0;
    for(int i=p;i<Nmax;i+=(i&(-i))) sol+=aib[i];
    return sol;
}

int main()
{
    int n,m,i,j,d;
    /*#ifndef ONLINE_JUDGE
        freopen ("date.in","r",stdin);
        freopen ("date.out","w",stdout);
    #endif*/

    cin>>n>>m;
    for(i=1;i<=n;++i) cin>>segm[i].x>>segm[i].y;
    sort(segm+1,segm+n+1);

    for(d=1;d<=m;++d)
    {
        for(i=d;i<=m;i+=d)
        {
            Ev[++len].y=i-1;
            Ev[len].x=i-d+1;
            Ev[len].ind=d;
        }
        i-=d;
        if(i<m)
        {
            Ev[++len].y=m;
            Ev[len].x=i+1;
            Ev[len].ind=d;
        }
    }
    sort(Ev+1,Ev+len+1);

    for(i=j=1;i<=len;++i)
    {
        for(;j<=n && segm[j].y<=Ev[i].y;upd(segm[j++].x,1));
        ans[Ev[i].ind]+=qry(Ev[i].x);
    }

    for(i=1;i<=m;++i) cout<<n-ans[i]<<"\n";
    return 0;
}


Measured memory_bytes: 20096
#include<iostream>
#include<memory>
#include<cassert>
#include<algorithm>
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)

template<typename T>
class Queue{
private:
    std::unique_ptr<T[]> arr_;
    size_t length_;
    size_t front_ptr_;
    size_t back_ptr_;
    size_t next_(size_t ptr) const {
        return (ptr + 1) % length_; 
    }
public:
    Queue(size_t length=100){
        length_ = length + 1; // +1 is buffer
        arr_.reset(new T[length_]);
        front_ptr_ = 0;
        back_ptr_ = 0;
    }
    ~Queue(){
        arr_.reset();
    }

    bool empty() const {
        return front_ptr_ == back_ptr_;
    }

    size_t length() const {
        return length_;
    } 

    void push(T element){
        assert(next_(back_ptr_) != front_ptr_);

        arr_[back_ptr_] = element;
        back_ptr_ = next_(back_ptr_);
    }

    void pop(){
        assert(!empty());

        front_ptr_ = next_(front_ptr_);
    }

    T front() const {
        assert(!empty());

        return arr_[front_ptr_];
    }
};

struct Process{
    std::string name;
    size_t neededTime;

    Process(std::string name = "p", size_t neededTime = 0){
        this->name = name;
        this->neededTime = neededTime;
    }
};

int main(){
    size_t N, timeSlice;
    std::cin >> N >> timeSlice;
    Queue<Process> processes(N);
    Queue<Process> finished(N);

    std::string name;
    size_t neededTime;
    for(int i=0;i<N;i++){
        std::cin >> name >> neededTime;
        Process process(name,neededTime);
        processes.push(process);
    }

    size_t cumTime = 0;
    while(!processes.empty()){
        Process process = processes.front();
        processes.pop();

        size_t processTime = std::min(timeSlice, process.neededTime);
        cumTime += processTime;
        process.neededTime -= processTime;

        if(process.neededTime <= 0){
            process.neededTime = cumTime;
            finished.push(process);
        }
        else {
            processes.push(process);
        }
    }
    
    for(int i=0;i<N;i++){
        Process process = finished.front();
        finished.pop();
        std::cout << process.name << " " << process.neededTime << '\n';
    }
}


Measured memory_bytes: 9136
import math

def combinations_count(n, r):
    if n <= 0 or n-r < 0:
      return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]
  
N = int(input())
primes = primes(N)
num = [0] * 5

for prime in primes:
  cnt = 0
  x = N
  while x >= prime:
    x = int(x/prime)
    cnt += x
  if cnt >= 74:
    num[0] += 1
  if cnt >= 24:
    num[1] += 1
  if cnt >= 14:
    num[2] += 1
  if cnt >= 4:
    num[3] += 1
  if cnt >= 2:
    num[4] += 1

ans = num[0] + num[1] * (num[4] - 1) + num[2] * (num[3] - 1) + \
combinations_count(num[3], 2) * (num[4] - 2)
print(ans)

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

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    int s;
    scanf("%d",&s);
    printf("%d:%d:%d\n",s/3600,(s%3600)/60,s%60);
    return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

ll n,len,q;
ll num;
ll block;
ll a[100010];
ll b[100010];
ll to[100010];
ll nxt[100010];
ll step[100010];

ll find(ll x)
{
	ll ans=0;
	ll l=x+1,r=n;
	while(l<=r)
	{
		ll mid=(l+r)/2;
		if(a[mid]-a[x]<=len)
		{
			l=mid+1;
			ans=mid;
		}
		else
		{
			r=mid-1;
		}
	}
	return ans;
}

void build()
{
	for(ll i=1;i<n;i++)
	{
		to[i]=find(i);
	}
	to[n]=n+1;	//这句话一定要加，不然就在下面while的地方死循环 
	block=sqrt(n);
	num=ceil(n/block);
	for(ll i=1;i<=n;i++)
	{
		b[i]=(i-1)/block+1;
	}
	for(ll i=1;i<=n;i++)
	{
		ll p=i,cnt=0;
		while(b[p]==b[i])
		{
			p=to[p];
			cnt++;
		}
		nxt[i]=p;
		step[i]=cnt;
	}
}

ll query(ll x,ll y)
{
	ll res=0;
	while(b[x]<b[y])
	{
		res+=step[x];
		x=nxt[x];
	}
	while(x<y)
	{
		x=to[x];
		res++;
	}
	return res;
}

int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	sort(a+1,a+n+1);
	scanf("%lld%lld",&len,&q);
	build();
	for(ll i=1;i<=q;i++)
	{
		ll x,y;
		scanf("%lld%lld",&x,&y);
		if(x>y) swap(x,y);
		printf("%lld\n",query(x,y));
	}
	return 0;
}












Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
const long MOD = 1000000007;

int main() {
vector<long> a(3);
rep(i, 3) cin >> a.at(i);
sort(a.begin(), a.end());
long ans = a.at(2) * 10 + a.at(0) + a.at(1);




cout << ans << endl;
return 0;

}



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

using namespace std;

int main()
{
  int kind;
  int volume;
  int init_vol;
  int input;
  int min_donut = 0;
  // vector<int> donut_v;
  int max_donut;

  cin >> kind >> volume;

  max_donut = kind;

  for (int i = 0; i < kind; i++) {
    cin >> input;
    // donut_v.push_back(input); 
    init_vol += input;
    if(min_donut > input || min_donut == 0) {
      min_donut = input;
    }
  }

  max_donut += (volume - init_vol) / min_donut;
  cout << max_donut << 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++)
typedef pair<int, int> P;

int n, m, k[20], s[20][20], p[20];

bool islight(int S){
  rep(i, m){
    int cnt = 0;
    rep(j, k[i]){
      int switch_num = s[i][j];
      switch_num--;
      if(S & (1 << switch_num)){
        cnt++;
      }
    }
    if(cnt % 2 != p[i]){
     return false;
    }
  }
  return true;
}

int main(){
  cin >> n >> m;
  rep(i, m){
    cin >> k[i];
    rep(j, k[i]){
      cin >> s[i][j];
    }
  }
  rep(i, m){
    cin >> p[i];
  }
  
  int res = 0;
  for(int S = 0; S < (1 << n); S++){
    if(islight(S)){
      res++;
    }
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {

    public Main(){
        Scanner SC = new Scanner(System.in);
        long N = SC.nextLong();
        long K = SC.nextLong();

        int  A = 0;
        long R = 1;
        while(true){
            if(N < R) break;
            R = 1;
            for(int i=0;i<A;i++)
                R *= K;
            A++;
        }

        System.out.println(A-1);
    }

    public static void main(String[] args){
        Main main = new Main();
    }
}


Measured memory_bytes: 21204
#pragma GCC optimize("O3")
/*{{{*/
#include <bits/stdc++.h>
#ifdef LOCAL
int c_ = 0;
#define cout (c_?cerr:cout)
#define debug(...) \
{if(!c_++)cerr<<"\033[96;1m"; \
__VA_ARGS__; \
if(!--c_)cerr<<"\033[0m";}
#else
#define debug(...) {}
#endif
#define assrt(...) debug(\
if (not (__VA_ARGS__)) \
    exit((cerr << __LINE__ << ": " << #__VA_ARGS__ << '\n', 0));\
)
#define st first
#define nd second
#define all(...) (__VA_ARGS__).begin(), (__VA_ARGS__).end()
using namespace std; using ll = long long;
template < typename t > using V = vector< t >;
template < typename t, size_t s > using A = array< t, s >;
void print() {cout << '\n';}
template< typename t, typename... v >
void print(const t& a, const v&... b)
{cout << a << (sizeof...(b)?" ":""); print(b...);}
template< typename t > void print_range(t a, const t& b)
{ while (a != b) cout << (*a++) << ' '; cout << '\n';}
#define dump(...) debug(print(#__VA_ARGS__,'=',__VA_ARGS__))
#define dump_range(...) debug(cerr<<#__VA_ARGS__ << ": "; print_range(__VA_ARGS__))
/*}}}*/

constexpr int nax = 1e5;

int n, c, k, tab[nax];
multiset< int > S;

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n >> c >> k;

    for (int i = 0; i < n; ++i)
        cin >> tab[i];

    sort(begin(tab), begin(tab) + n);

    int res = 0;

    for (int i = 0; i < n; ++i)
    {
        while (not S.empty() and (*S.begin()) + k < tab[i])
        {
            ++res;
            int cnt = c;
            while (not S.empty() and cnt)
                --cnt, S.erase(S.begin());
        }
        S.insert(tab[i]);
    }

    while (S.size())
    {
        ++res;
        int cnt = c;
        while (not S.empty() and cnt)
            --cnt, S.erase(S.begin());
    }

    print(res);
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
     
    using namespace std;
     
    int main()
    {
        int n;
        cin>>n;
        vector<int> a(n+1);
        vector<int> b(n+1);
        a[0]=99999;
        b[0]=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        for(int i=2;i<=n;i++)
        {
            b[i]=min(abs(a[i]-a[i-1])+b[i-1],abs(a[i]-a[i-2])+b[i-2]);
            //cout<<b[i]<<endl;
            //cout<<abs(a[i]-a[i-1])<<endl;
            //cout<<abs(a[i]-a[i-2])<<endl;
        }
        cout<<b[n];
    }

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"sort"
)

func isEven(n int) bool { return n%2 == 0 }

func main() {
	var x, y, z int
	fmt.Scan(&x, &y, &z)

	if isEven(x) || isEven(y) || isEven(z) {
		fmt.Println(0)
		return
	}

	a := []int{x, y, z}
	sort.Ints(a)
	// fmt.Println(a)
	fmt.Println(a[0] * a[1])
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, x, n) for(int i = x; i > n; i--)
long long MOD = 1e9+7;
long long INF = 1e15;
typedef pair<long long, long long> P;
typedef long long ll;

int main(){
    string S;
    ll K;
    cin >> S >> K;
    int N = S.size();
    vector<ll> vec;
    int i = 0;
    while(i < N){
        int l = 1;
        while(i+l < N && S[i] == S[i+l]){
            l++;
        }
        vec.push_back(l);
        i += l;
    }
    int n = vec.size();
    if(n == 1){
        cout << N*K/2 << endl;
    }
    else if(S[0] == S[N-1]){
        ll sum = 0;
        rep2(i, 1, n-1){
            sum += vec[i]/2;
        }
        ll x = (vec[0] + vec[n-1])/2;
        cout << sum * K + x * (K-1) + vec[0]/2 + vec[n-1]/2 << endl;
    }
    else{
        ll sum = 0;
        rep(i, n){
            sum += vec[i]/2;
        }
        cout << sum * K << endl;
    }
}

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

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < n; ++i)
#define fore(i, a, b) for(int i = a; i < b; ++i)

#define endl '\n'

const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int mx[2];
    cin >> mx[0] >> mx[1];
    int n;
    cin >> n;
    int pos[2];
    cin >> pos[0] >> pos[1];
    string s1, s2;
    cin >> s1 >> s2;
    map<char, int> mp = {{'D', 0}, {'R', 1}, {'U', 2}, {'L', 3}};
    for (auto &c: s1) {
        c = mp[c];
    }
    for (auto &c: s2) {
        c = mp[c];
    }
    for (int t: {0, 1}) {
        pos[t]--;
        int l1 = 0;
        int r1 = 0;
        int l2 = 0;
        int r2 = 0;
        for (int i = 0; i < n; ++i) {
            if (s1[i] == t) {
                r1++;
            }
            else if (s1[i] == t + 2) {
                l1++;
            }
            // cout << int(s1[i]) << " " << int(s2[i]) << " | " << l1 << " " << r1 << " | " << l2 << " " << r2 << endl;
            while (pos[t] + r1 >= mx[t] || pos[t] - l1 <= 0) {
                if (pos[t] + r1 >= mx[t]) {
                    if (l2) {
                        l2--;
                        pos[t]--;
                    }
                    else break;
                }
                else {
                    if (r2) {
                        r2--;
                        pos[t]++;
                    }
                    else break;
                }
            }
            if (pos[t] + r1 >= mx[t] || pos[t] - l1 < 0) {
                cout << "NO" << endl;
                return 0;
            }
            if (s2[i] == t) {
                if (l1) l1--;
                else r2++;
            }
            else if (s2[i] == t + 2) {
                if (r1) r1--;
                else l2++;
            }
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 920
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <cmath>
 

using namespace std;

int64_t get_cost(const vector<int64_t>& as, const int initial_sgn)
{
    int64_t cost = 0;
    int64_t s = 0;
    int sgn = initial_sgn;

    for(auto a : as)
    {
        s += a;
        sgn *= -1;

        if(s * sgn > 0) continue;

        const auto d = abs(s) + 1;
        cost += d;
        s += sgn * d;
    }
    return cost;
};

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

    int n;
    cin >> n;
    
    vector<int64_t> as(n);
    for(auto& a : as)
        cin >> a;
    
    cout << min(get_cost(as, -1), get_cost(as, 1)) << '\n';
    
    return 0;
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**9)

def unite(par, i, j):
    j = get_par(par, j)
    par[j] = get_par(par, i)

def get_par(par, p):
    while par[p] != p:
        p = par[p]
    return par[p]

n,k,l = map(int, input().split())
pq = []
road = [i for i in range(n+1)]
rail = [i for i in range(n+1)]
for i in range(k):
    p,q = map(int,input().split())
    pq.append((p,q))
    aa = get_par(road, p)
    bb = get_par(road, q)
    if aa == bb:
        continue
    # unite
    if aa < bb:
        road[bb] = aa
    else:
        road[aa] = bb

rs = []
for i in range(l):
    p,q = map(int,input().split())
    rs.append((p,q))
    aa = get_par(rail, p)
    bb = get_par(rail, q)
    if aa == bb:
        continue
    # unite
    if aa < bb:
        rail[bb] = aa
    else:
        rail[aa] = bb

ans = [(road[get_par(road, i)], rail[get_par(rail, i)]) for i in range(1,n+1)]
from collections import Counter
c = Counter(ans)
print(*[c[(road[get_par(road, i)], rail[get_par(rail, i)])] for i in range(1,n+1)])


Measured memory_bytes: 74376
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

use std::cmp::{max, min};

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let k: i64 = read();
    println!(
        "{} {}",
        if a < k { 0 } else { a - k },
        if b < k - a { 0 } else { b - max(0, k - a) }
    );
}


Measured memory_bytes: 4352
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define fore(x, c) for(auto &&x : c)
#define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i)
#define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i)
#define sz(c) ((int)c.size())
#define contains(c, x) (c.find(x) != end(c))
#define inseg(l, x, r) ((l) <= (x) && (x) < (r))
#define dump(...)
#define pb push_back
#define eb emplace_back
#define _ 0
const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL;
const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
  is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap = priority_queue<T, deque<T>, greater<T>>;
struct before_main_function {
  before_main_function() {
      cin.tie(nullptr); ios::sync_with_stdio(0);
      cout << setprecision(15) << fixed;
  }
} before_main_function;
// clang-format on
//------------------8<------------------------------------8<--------------------

signed main() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;
  string ans;
  rep(i, 0, sz(s)) {
    ans += s[i];
    ans += t[i];
  }
  cout << ans << endl;
  return (0 ^ _ ^ 0);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define N 200005
#define gc getchar()
using namespace std;
int n,a[N],b[N];
int read(){
	int x=1;
	char ch;
	while (ch=gc,ch<'0'||ch>'9')
		if (ch=='-') x=-1;
	int s=ch-'0';
	while (ch=gc,ch>='0'&&ch<='9')
		s=s*10+ch-'0';
	return s*x;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int cnt=0;
	for (int i=n;i>1&&cnt<2;i--)
		if (a[i]==a[i-1]) b[++cnt]=a[i],i--;
	if (cnt<2) puts("0");
	else printf("%lld\n",(ll)b[1]*b[2]);
	return 0;
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

def main(a=''):
    # 整数の入力
    a = int(input())
    a = int(a)
    # スペース区切りの整数の入力
    # b, c = map(int, input().split())
    # b, c = map(int, input())

    # # 文字列の入力
    # a = input()
    # 出力
    # print("{} {}".format(a+b+c, s))
    sum = 0
    sum_same = 0
    sum_same_2 = 0
    for i in range(1, a + 1):
        for j in range(1, a + 1):
            if i > j:
                continue
            for k in range(1, a + 1):
                if j > k:
                    continue
                # print(i,j,k,)
                if i == j == k:
                    # print('同じ')
                    sum_same += gcd(i, j, k)
                elif i==j or j==k or i==k:
                    # print('2つ同じ')
                    sum_same_2 += gcd(i, j, k)
                else:
                    # print('違う')
                    sum += gcd(i, j, k)

    print(sum*6 + sum_same + sum_same_2*3)


if __name__ == '__main__':
    # main('200')
    main()

Measured memory_bytes: 9632
while True:
    e,a = map(int,input().split())
    if e ==0 and a ==0:
        break
    cnt = 0
    for i in range(1,e+1):
        for j in range(1,e+1):
            if j<=i:
                continue
            X = a - (i + j)
            if X > j and X <=e:
                cnt +=1
    print(cnt)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(1e5)+5
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define max3(x, y, z) max(x, max(y, z))
#define ull long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c << endl;
			
	
}


Measured memory_bytes: 768
#include<stdio.h>

int main(){
  int n;
  int t,x,y;
  

  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d%d%d",&t,&x,&y);
    if(t-(x+y)>=0&&(t-(x+y))%2==0);
    else{
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}
  


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main() {
	int L, R, d;
	cin >> L>> R>>d;
	int ans = 0;
	for(int i = L; i <= R; ++i){
		if(i%d == 0)ans++;
	}
	cout << ans << endl;
	return 0;
}



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

int main(void){
  char s[1000];
  int i,j,n,t;

  scanf("%s",s);
  n = strlen(s);

  for(i=n-1;i>0;i--){
    if(i%2!=0) continue;
    t=0;
    for(j=0;j<i/2;j++){
      if(s[j]==s[i/2+j]) t++;
    }
   if(t==i/2){
      printf("%d\n",i);
      break;
    }
  }

  return 0;
}



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

typedef long long ll;

main()
{
    string s, t;
    cin >> s >> t;
    int a, b, ans = 0;
    a = s.size(), b = t.size();
    for(int i = 0; i <= a - b; i++){
        int c = 0;
        for(int j = 0; j < b; j++){
            if(s[i + j] == t[j]){
                c++;
            }
        }
        ans = max(ans, c);
    }
    cout << b - ans;

}





///promy_pompom
//hello world


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <boost/range/adaptor/reversed.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using boost::irange;
using boost::sort;
using boost::adaptors::reversed;

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

    int ans = 0;

    ans += min(a, k);
    k -= min(a, k);

    if (k) {
        k -= min(b, k);
    }

    if (k) {
        ans -= min(c, k);
        k -= min(c, k);
    }

    cout << ans << endl;
}


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

int main() {
  int l,r,d;
  cin >> l >> r >> d;
  int ans = 0;
  rep(i,l,r+1) {
    if (i % d == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
n,k=map(int,input().split())
if k>(n-1)*(n-2)//2:print(-1);exit()
e=[]
for i in range(1,n):e.append((0,i))
ee=[]
for i in range(1,n-1):
  for j in range(i+1,n):
    ee.append((i,j))
for i in range((n-1)*(n-2)//2-k):
  e.append(ee[i])
print(len(e))
for i,j in e:print(i+1,j+1)

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

int main(void){
    char str[101];
    int cnt = 0,len;
    scanf("%s", str);
    len = strlen(str);
    for(int i = 0; i < len / 2; i++){
        if(str[i] != str[len - i - 1]){
            cnt ++;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){
    
    ll N, K;
    cin >> N >> K;
    ll ans = abs(N - K);
    ll t = N / K;
    chmin(ans, abs(N - K * t));
    chmin(ans, abs(N - K * (t + 1)));
    cout << ans << endl;  

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
string s;
bool x[30];
int main(void){
    cin>>s;
    for(int i=0;i<s.size();i++){
        x[s[i]-'a']=true;
    }
    for(int i=0;i<26;i++){
        if(x[i]==false){
            char ans='a'+i;
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
    
}


Measured memory_bytes: 3672
n = int(input())
h = list(map(int, input().split()))
def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default
if sum(h)==0:
  print(0)
else:
  count = 0
  while sum(h) > 1:
    while h[0] == 0:
      h = h[1::]
    p = my_index(h, 0, -1)
    if p >= 0:
      d = min(h[:p])
      count += d
      for i in range(p):
        h[i] = h[i] - d
    else:
      d = min(h)
      count += d
      h = [x - d for x in h]
  print(count + sum(h))

Measured memory_bytes: 3064
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

public static class Program
{
    static void Main()
    {
        string[] line1 = Console.ReadLine().Split(' ');
        int N = int.Parse(line1[0]);
        int X = int.Parse(line1[1]);
        string[] line2 = Console.ReadLine().Split(' ');
        int[] place = new int[N];
        int[] distance = new int[N];
        for (int i = 0; i < N; i++)
        {
            place[i] = int.Parse(line2[i]);
            distance[i] = Math.Abs(place[i] - X);
        }
        int result = distance[0];
        for(int i = 1; i < distance.Length; i++)
        {
            result = gcd(result, distance[i]);
        }
        Console.WriteLine(result);
    }
    static int gcd(int x, int y)
    {
        if (x == 0) return y;
        if (y == 0) return x;
        if (x < y) return gcd(x, y % x);
        else return gcd(x % y, y);
    }
}


Measured memory_bytes: 18784
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a[3][3],i,j,x=0,y=0,z=0,r=0,s=0,t=0,g=0,h=0;
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}
	int n;
	cin>>n;
	int b[n];
	for(i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			for(int k=0;k<n;k++)
			{
				if(a[i][j]==b[k])
				{
					int u,v;
					u=i+1;
					v=j+1;
					if(u==v)
					{
						x++;
					}
					if(u+v==4)
					{
						y++;
					}
					if(u==1)
					{
						z++;
					}
					if(u==2)
					{
						r++;
					}
					if(u==3)
					{
						s++;
					}
					if(v==1)
					{
						t++;
					}
					if(v==2)
					{
						g++;
					}
					if(v==3)
					{
						h++;
					}
					
				}
			}
		}
	}

if(x==3 || y==3 || z==3 || r==3 || s==3 || t==3 || g==3 || h==3)
{
	cout<<"Yes"<<endl;
}
else
{
	cout<<"No"<<endl;
}

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int h, w;
string s[105];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> h >> w;
	FOR(i, h) cin >> s[i];
	h += 2;
	w += 2;
	vector<string> ans(h, "");
	FOR(i, h) {
		if (i == 0 || i == h-1) {
			FOR(j, w) ans[i] += "#";
		}
		else {
			ans[i] = "#" + s[i-1] + "#";		
		}
	}
	FOR(i, h) cout << ans[i] << endl;
	return 0;
}

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

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    unordered_map<int, int> P(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> P[i];
        --P[i];
    }
    vector<int> C(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> C[i];
    }

    long ans = -1e18;
    for (int i = 0; i < N; ++i)
    {

        long cycle_cnt = 0;
        long cycle_sum = 0;
        int pos = i;
        for (int j = 0; j < N; ++j)
        {
            ++cycle_cnt;
            cycle_sum += C[pos];
            pos = P[pos];
            if (pos == i)
            {
                break;
            }
        }

        long acc_score = 0;
        pos = i;

        for (int j = 0; j < cycle_cnt; ++j)
        {
            if (j >= K)
            {
                break;
            }
            acc_score += C[pos];
            long score = acc_score + max(0l, cycle_sum) * ((K - j - 1) / cycle_cnt);
            ans = max(ans, score);
            pos = P[pos];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3828
#include<cstdio>
#include<vector>
using namespace std;

const int MAX_N = 200000;
char s[MAX_N+1];
vector<int> G[MAX_N];
bool valid[MAX_N];
int a_deg[MAX_N];
int b_deg[MAX_N];

void invalidate(int v) {
	valid[v] = false;
	for(int i=0;i<G[v].size();i++) {
		int u = G[v][i];
		if(valid[u]) {
			if(s[v] == 'A') a_deg[u]--;
			else b_deg[u]--;
			if(a_deg[u] == 0 || b_deg[u] == 0) invalidate(u);
		}
	}
}

void add_edge(int u, int v) {
	G[u].push_back(v);
	if(s[v] == 'A') a_deg[u]++;
	else b_deg[u]++;
}

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	scanf("%s", s);
	for(int i=0;i<m;i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		a--; b--;
		add_edge(a, b);
		add_edge(b, a);
	}
	for(int i=0;i<n;i++) valid[i] = true;
	for(int i=0;i<n;i++) if(valid[i]) {
		if(a_deg[i] == 0 || b_deg[i] == 0) invalidate(i);
	}
	bool empty = true;
	for(int i=0;i<n;i++) if(valid[i]) empty = false;
	printf("%s\n", empty ? "No" : "Yes");
	return 0;
}


Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k;
    cin >> n >> k;
    long int a[n+1];
    a[0] = 0;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=k+1;i<=n;i++){
        if(a[i]>a[i-k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 5180
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int main(){
  int p,q,r;
  cin>>p>>q>>r;

  cout<<p+q+r-max(p,max(r,q))<<endl;

  return 0;
}


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

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

int n,U;
int ans;
int c[22],need[22]; //eÈÚÌPÊ, C·éÌÉKvÈÈÚ(rbgÇ)

//ÈÚÌæèûÉµªÈ¢©Ç¤©`FbN·é
bool check(int used){
  rep(i,n){
    //CÈÚÉKvÈÈÚÌPÊªæêÄé©`FbN
    if((used & (1<<i)) > 0 && (used & need[i]) != need[i]){
      return false;
    }
  }
  return true;
}

//id:ÈÚÔ, used:ÇÌÈÚæÁ½©(rbgÇ), sum:PÊv, cnt:CÈÚ
void solve(int id,int used,int sum,int cnt){
  if(id == n){
    if(sum >= U && ans > cnt && check(used)){
      ans = cnt;
    }
    return;
  }

  solve(id+1,used,sum,cnt); //ÆçÈ¢
  solve(id+1,used|(1<<id),sum+c[id],cnt+1); //Æé
}

int main(void){
  while(scanf("%d%d",&n,&U),n||U){
    rep(i,n){
      int k;
      scanf("%d%d",&c[i],&k);
      need[i] = 0;

      while(k--){
        int r;
        scanf("%d",&r);
        need[i] |= (1<<r);
      }
    }

    ans = INT_MAX;
    solve(0,0,0,0);
    printf("%d\n",ans);
  }

  return 0;
}

Measured memory_bytes: 876
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
	   PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt();
		int k=sc.nextInt();
		double[] arr=new double[n];
		for(int i=0;i<n;i++) {
			arr[i]= (sc.nextDouble()+1)/2;
		}
		double max=0;
		double sum=0;
		for(int i=0;i<k;i++) sum+=arr[i];
		max=Math.max(sum, max);
		int c=0;
		sum-=arr[c++];
		for(int i=k;i<n;i++) {
			sum+=arr[i];
			max=Math.max(sum, max);
			sum-=arr[c++];

		}
		pw.println(max);
		pw.flush();
		pw.close();
	}
	static class Scanner
    {
        StringTokenizer st;
        BufferedReader br;
 
        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
 
        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
 
        public int nextInt() throws IOException {return Integer.parseInt(next());}
 
        public long nextLong() throws IOException {return Long.parseLong(next());}
 
        public String nextLine() throws IOException {return br.readLine();}
 
        public double nextDouble() throws IOException
        {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if(x.charAt(0) == '-')
            {
                neg = true;
                start++;
            }
            for(int i = start; i < x.length(); i++)
                if(x.charAt(i) == '.')
                {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                }
                else
                {
                    sb.append(x.charAt(i));
                    if(dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg?-1:1);
        }
 
        public boolean ready() throws IOException {return br.ready();}
 
 
    }

}


Measured memory_bytes: 45740
x, y = map(int, input().split())
A=[1,3,5,7,8,10,12]
B=[4,6,9,11]
C=[2]

if (x in A and y in A) or (x in B and y in B) or (x in C and y in C):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060