akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>  // std::accumulate(m.begin(), m.end(), 0LL);
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int N, M, X; std::cin >> N >> M >> X;
  std::vector<int> A(M); for(int i=0; i<M; i++) std::cin >> A[i];

  int zero = 0;
  int enu  = 0;
  for(int i=0; i<M; i++) {
    if( A[i] < X ) zero++;
    else enu++;
  }
  std::cout << std::min(zero,enu) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
//const ll mod=1000000007;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=330;
ll mod,comb[N][N],dp[N][N],sdp[N][N];
int n,k;
ll gao(int r,int len);
ll sufgao(int r,int len) {
	if (r==k+1) return 0;
	if (sdp[r][len]!=-1) return sdp[r][len];
	ll &c=sdp[r][len]; c=0;
	return c=(sufgao(r+1,len)+gao(r,len))%mod;
}
ll gao(int r,int len) {
	if (dp[r][len]!=-1) return dp[r][len];
	if (len==0) return 1;
	ll &c=dp[r][len]; c=0;
	rep(pl,0,len) {
		c=(c+sufgao(r+1,pl)*gao(r,len-1-pl)%mod*comb[len-1][pl])%mod;
	}
	return c;
}
int main() {
	scanf("%d%d%lld",&n,&k,&mod);
	memset(dp,-1,sizeof(dp));
	memset(sdp,-1,sizeof(sdp));
	rep(i,0,n+1) {
		comb[i][0]=comb[i][i]=1;
		rep(j,1,i) comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
	}
	printf("%lld\n",gao(0,n));
}


Measured memory_bytes: 2816
N = int(input())
v = list(map(int,input().split()))
v = sorted(v)
for i in range(N-1):
  if(i == 0):
    tmp = v.pop(0)
    tmp2 = v.pop(0)
    ave = (tmp+tmp2)/2
    tmp = tmp2
  else:
    tmp2 = v.pop(0)
    ave = (ave+tmp2)/2
print(str(ave))

Measured memory_bytes: 9132
### a<=b<=cととることとし、a,bを固定すると
### cは　c<a+b
from bisect import bisect_left
def main():
    N = int(input())
    lst = list(map(int, input().split()))
    sor = sorted(lst)
    res = 0
    for i in range(N):
        for j in range(i+1, N):##ここでa<=bを満たしている
            ab = sor[i] + sor[j]
            highbound = bisect_left(sor, ab)
            res += highbound - j - 1
    print(res)
main()
### ライブラリを使おう！！！

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

int main() {
  string pass;
  cin >> pass;
  int check =0;
  
  for(int k=0;k<3;k++){
    if(pass.at(k) == pass.at(k+1)){
      cout << "Bad" <<endl;
      check = 1;
      break;
    }
  }
  
  if(check == 0){
    cout << "Good" <<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int c[10];
int n;
string s;
int main(){
	
	cin>>n;
	
	while(n--){
		
		cin>>s;
		if(s[0]=='A'){
			c[0]++;
		}
		if(s[0]=='W'){
			c[1]++;
		}
		if(s[0]=='T'){
			c[2]++;
		}
		if(s[0]=='R'){
			c[3]++;
		}
	}
	cout<<"AC x "<<c[0]<<endl;
	cout<<"WA x "<<c[1]<<endl;
	cout<<"TLE x "<<c[2]<<endl;
	cout<<"RE x "<<c[3]<<endl;
}

Measured memory_bytes: 3572
n,m = map(int,input().split())
if n == 1 and m == 0:
    print(0)
    exit()
lst = [-1 for _ in range(n)]
for i in range(m):
    s,c = map(int,input().split())
    if lst[s-1] != -1:
        if lst[s-1] != c:
            print(-1)
            exit()
    else:
        lst[s-1] = c
if lst[0] == 0 and n != 1:
    print(-1)
    exit()
if lst[0] == -1:
    lst[0] = 1
for i in range(n):
    if lst[i] == -1:
        lst[i] = 0
    lst[i] = str(lst[i])
print("".join(lst))

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

using namespace __gnu_pbds;
using namespace std;

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

const int infI=1e9+5;
const long long infL=1e16;
const int MOD=1e9+7;
const int MAX=2e5+5;

#define mp make_pair
#define in &
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vvl vector<vector<ll> >
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define eb emplace_back
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define debug(x) cerr<<x<<endl
#define test(t) int t;cin>>t;while(t--)
#define fordebug(x) cerr<<x<<" "

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference

ll a[25][25],dp[1LL<<22];

ll solve(int i,ll setup,int n){
    // cerr<<i<<" "<<setup<<endl;
    if(i==n){
        return (__builtin_popcountll(setup)==n);
    }
    if(dp[setup]!=-1){
        return dp[setup];
    }
    ll &cnt = dp[setup];
    cnt = 0;
    forn(j,0,n){
        if(a[i][j] and ((setup&(1LL<<j))==0)){
            cnt += solve(i+1,setup|(1LL<<j),n);
            cnt%=MOD;
        }
    }
    return cnt;
}

int main(){
    int n;
    cin>>n;
    forn(i,0,n){
        forn(j,0,n){
            cin>>a[i][j];
        }
    }
    forn(i,0,1LL<<n){
        dp[i] = -1;
    }
    cout<<solve(0,0,n);
    return 0;
}

Measured memory_bytes: 18688
import sys
n = int(input())
limit = 10 ** 18
ans = 1
a = [int(x) for x in input().split() ]
if 0 in a:
    print(0)
    sys.exit()

for i in a:
    ans *= i
    if ans > limit:
        print(-1)
        sys.exit()

print(ans)

Measured memory_bytes: 21716
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

const ll oo=1ll<<60;

ll n,A,l,r,val,tmp,res=oo;

ll Pow(ll a,ll b){
	ll res=1;
	For(i,0,b){
		if (1.0*res*a>=n) return n;
		res*=a;
	}
	return res;
}
ll Work(int k){
	l=0,r=n/k+19;
	while (l<=r){
		ll mid=(l+r>>1);
		if (Pow(mid,k)>=n) val=mid,r=mid-1;else l=mid+1;
	}
	For(i,1,k+1)
		if (1.0*Pow(val,i)*Pow(val-1,k-i)>=n){
			tmp=i;
			break;
		}
	return tmp*val+(k-tmp)*(val-1);
}

int main(){
	cin>>n>>A;
	For(k,1,50){
		res=min(res,Work(k)+(k-1)*A);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W= sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            }else {
                for (int h = 0; h < H; h++) {
                    for (int w = 0; w < W; w++) {
                        if (h % 2 == 0) {
                            if (w % 2 == 0)
                                System.out.print("#");
                            else
                                System.out.print(".");
                        } else {
                            if (w % 2 == 0)
                                System.out.print(".");
                            else
                                System.out.print("#");
                        }
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }
        sc.close();
    }
}



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

int main(){
  int n;  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++)
    cin >> a[i];

  sort(a.rbegin(), a.rend());

  int alice = 0, bob = 0;
  for(int i=0; i<n; i++)
    if(i % 2)  bob += a[i];
    else     alice += a[i];

  cout << alice - bob << endl;
  return 0;
}


Measured memory_bytes: 3600
while True:
    m=int(input())
    p=1000-m
    y500=p//500
    x500=p%500
    y100=x500//100
    x100=x500%100
    y50=x100//50
    x50=x100%50
    y10=x50//10
    x10=x50%10
    y5=x10//5
    x5=x10%5
    
    if m==0:
        break
    
    print(y500+y100+y50+y10+y5+x5)


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

using namespace std;

constexpr int D = 365;

int score(const vector<int>& c, const vector<vector<int>>& s, const vector<int>& t) {
	int S = 0;

	vector<int> last(26, 0);
	for (size_t i = 0; i < D; i++) {
		S += s[i][t[i]-1];
		
		last[t[i] - 1] = i+1;
		for (size_t j = 0; j < 26; j++) {
			S -= c[j] * (i+1 - last[j]);
		}
	}

	return S;
}

vector<int> solve(const vector<int>& c, const vector<vector<int>>& s) {
	vector<int> t(D);

	vector<int> last(26, 0);
	for (size_t i = 0; i < D; i++) {
		int mscore = 0, idx = 0, dscore = 0;
		vector<int> dlast(last);

		for (size_t j = 0; j < 26; j++) {
			dscore += s[i][j];

			dlast[j] = i + 1;
			for (size_t r = 0; r < 26; r++) {
				dscore -= c[r] * (i + 1 - dlast[r]);
			}

			if (dscore >= mscore) {
				mscore = dscore;
				idx = j;
				last = dlast;
			}
		}

		t[i] = idx;
	}

	return t;
}

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

	vector<int> c(26);
	vector<vector<int>> s(D, vector<int>(26));
	
	for (int i = 0; i < 26; i++) {
		cin >> c[i];
		//c[i] = rand() % 100;
	}

	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			cin >> s[i][j];
			//s[i][j] = rand() % 20000;
		}
	}

	auto t = solve(c, s);

	for (size_t i = 0; i < D; i++) cout << t[i] << endl;

	return 0;
}

Measured memory_bytes: 3588
<?php
  
  fscanf(STDIN,"%d %d",$n,$d);

for($i=0;$i<$n;$i++){
  $x_li[] = explode(" ",trim(fgets(STDIN)));
}


$sum=0;
$count=0;

for($i=0;$i<$n;$i++){
  for($j=0;$j<$n;$j++){
   if($i<$j){
     for($k=0;$k<$d;$k++){
       //echo $x_li[$j][$k]." ".$x_li[$i][$k]." ".($x_li[$j][$k]-$x_li[$i][$k])."\n";
       $sum+= ($x_li[$j][$k]-$x_li[$i][$k])**2;
     }
      // echo $sum."\n";
	if(sqrt($sum)-(int)sqrt($sum)==0){
      $count++;
    }
   }
    $sum=0;
  }
}

echo $count."\n";

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y,a,b,c,i,j;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a),q(b),r(c),s(x+y+c);
  for(i=0;i<a;i++)
  {
    cin >> p.at(i) ;
  }
  for(i=0;i<b;i++)
  {
    cin >> q.at(i) ;
  }
  for(i=0;i<c;i++)
  {
    cin >> r.at(i) ;
  }
  sort(p.begin(),p.end());
  sort(q.begin(),q.end());
  sort(r.begin(),r.end());
  reverse(p.begin(),p.end());
  reverse(q.begin(),q.end());
  reverse(r.begin(),r.end());
  for(i=0;i<x;i++)
  {
    s.at(i)=p.at(i);
  }
  for(i=0;i<y;i++)
  {
    s.at(i+x)=q.at(i);
  }
  for(i=0;i<c;i++)
  {
    s.at(i+x+y)=r.at(i);
  }
  
  sort(s.begin(),s.end());reverse(s.begin(),s.end());
  //for(i=0;i<x+y+c;i++) cout << s.at(i);
  long long ans=0;
  for(i=0;i<x+y;i++)
  {
    ans+=s.at(i);
  }
  cout << ans << endl;
    
  
  
  
  
}



Measured memory_bytes: 2560
a,b,c = list(map(int, input().split()))
k = int(input())

c1=0
while(1):
    if a<b:
        break
    else:
        c1+=1
        b=b*2

c2=0
while(1):
    if b<c:
        break
    else:
        c2+=1
        c=c*2

if c1+c2<=k:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
n = int(input())
t = [int(i) for i in input().split()]
m = int(input())
l = [[int(j) for j in input().split()] for i in range(m)]
tot = sum(t)
for i in range(m):
    print(tot - t[l[i][0] - 1] + l[i][1])

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=0;i<VMAX+1;i++) C[i]=0;
  
  for(i=0;i<n;i++){
    
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++; 
	  }
  for(i=1;i<VMAX+1;i++) C[i] = C[i] + C[i-1];
  for(j=1;j<n+1;j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;

  }
  for(i=1;i<n+1;i++){
    printf("%d",B[i]);
    if(i != n) printf(" ");
    
    
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG

using namespace std;
typedef long long ll;

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

int main()
{
    string s;
    cin >> s;
    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
#def main(S, b):

if __name__ == '__main__':
    N = int(input())

    emp_dict = {}

    for i in range(N):
        s = input()
        if s in emp_dict:
            emp_dict[s] += 1
        else:
            emp_dict[s] = 1

    a = max(list(emp_dict.values()))

    A = []

    for k in emp_dict.keys():
        if emp_dict[k] == a:
            A.append(k)

    A.sort()
    for a in A:

        print(a)


Measured memory_bytes: 32224
#include <cstdio>
#include <stack>
using namespace std;

//深さ優先 

bool dfs(int i, int sum, int n[4], stack<int> st) {
    if (i == 4) {
        if (sum == 7) {
            char f[] = "0123456=7";
            for (i=0; i<4; i++) {
                f[2*i] = n[i] + '0';
                if (i < 3) {
                    f[5-2*i] = (st.top() == 1) ? '+' : '-';
                    st.pop();
                }
            }
            printf("%s\n",f);
            return true;
        } else 
            return false;
    } else {
        st.push(1);
        if (dfs(i+1, sum+n[i], n, st))
            return true;
        else {
            st.pop();
            st.push(-1);
            return dfs(i+1, sum-n[i], n, st);
        }
    }
}

int main() {
    char s[5];
    int n[4];
    scanf("%s",s);
    stack<int> st;
    for (int i=0; i<4; i++) {
        n[i] = s[i] - '0';
    }
    dfs(1,n[0],n,st);
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9+1)
#define MAXX (int)1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (ll)(1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
//printf("myco\n");//for debug
/*--------------------------------------------*/
int main(){
   int h,w;cin>>h>>w;
   vector<vector<char>> a(h+1,vector<char>(w+1));
   vector<vector<int>> dp(h+1,vector<int>(w+1,0));
   rep(i,h){
       rep(j,w){
           char tmp;
           cin>>tmp;
           a[i+1][j+1]=tmp;//1-index
       }
   }
   //dp[i][j]:(i,j)までの経路の数
   dp[1][1]=1;  
   for(int i=1;i<w;i++){if(a[1][i+1]!='#')dp[1][i+1]=dp[1][i];}
   for(int i=1;i<h;i++)if(a[i+1][1]!='#')dp[i+1][1]=dp[i][1];  
   for(int i=2;i<=h;i++){
       for(int j=2;j<=w;j++){
           if(a[i][j]!='#'){
               dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
           //printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
           }
       }
   }
   cout<<dp[h][w]<<endl;
}

Measured memory_bytes: 5248
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    n = int(input())
    edge = []
    for i in range(n):
        u,k,*v_li = map(int,input().split())
        u-= 1
        for j in range(len(v_li)):
            v_li[j] -= 1
        edge.append(v_li)
    ans_edge = [[0]*n for j in range(n)]
    
    for j in range(len(edge)):
        for k in range(len(edge[j])):
            ans_edge[j][edge[j][k]] = 1
    for j in range(len(ans_edge)):
        print(*ans_edge[j])


Measured memory_bytes: 7104
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N = int(input())
graph = [[] for _ in range(N)]
for n in range(1, N):
    a = int(input()) - 1
    graph[a].append(n)


def dfs(p):
    Ds = []
    for np in graph[p]:
        Ds.append(dfs(np))
    if not Ds:
        return 0
    l = len(Ds)
    Ds.sort(reverse=True)
    for i in range(l):
        Ds[i] += i+1
    return max(Ds)

ans = dfs(0)
print(ans)

Measured memory_bytes: 118960
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    auto a = iota(3).map!(i => readln.split.to!(int[])).array;
    int N;
    scan(N);
    auto b = iota(N).map!(i => readln.chomp.to!int).array;
    foreach (bi ; b) {
        foreach (i ; 0 .. 3) {
            foreach (j ; 0 .. 3) {
                if (a[i][j] == bi) {
                    a[i][j] = 0;
                }
            }
        }
    }

    foreach (i ; 0 .. 3) {
        if (a[i].all!"a == 0") {
            writeln("Yes");
            return;
        }
    }
    foreach (j ; 0 .. 3) {
        if (!a[0][j] && !a[1][j] && !a[2][j]) {
            writeln("Yes");
            return;
        }
    }
    if ((!a[0][0] && !a[1][1] && !a[2][2]) || (!a[0][2] && !a[1][1] && !a[2][0])) {
        writeln("Yes");
        return;
    }
    writeln("No");
}




void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}





Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>

using namespace std;
typedef long long ll;
ll N;
ll M;
string s;
vector<ll > input1;  
vector<vector <ll > > input2;

int main(){
    
    //cin >> N;
    string s;
    cin >> s;

   if(s[0] == s[1]){
       cout << "Bad" << endl;
       return 0;
   }else if(s[1] == s[2]){
        cout << "Bad" << endl;
        return 0;
   }else if(s[2] == s[3]){
    cout << "Bad" << endl;
    return 0;
   }

     cout << "Good" << endl;

} 

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import bisect


def solve(N: int, A: "List[int]"):
    A.sort()
    count_minus = bisect.bisect_left(A, 0)
    A = [abs(x) for x in A]
    A.sort()
    ret = sum(A)
    if count_minus % 2 != 0:
        ret -= A[0] * 2
    print(ret)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 19744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=200005;
int a[N];
ll sum,s,ans;
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	int n=read();
	For(i,1,n)sum+=(a[i]=read());
	ans=sum;
	For(i,1,n-1){
		s+=a[i];
		ans=min(ans,abs(2*s-sum));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 4356
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N;
	string S;
	scan(N);scan(S);
	int Wnum[300001]={},Enum[300001]={};
	int scoremin=INF;
	rep1(i,N){
		Wnum[i]=Wnum[i-1];
		Enum[i]=Enum[i-1];
		if(S[i-1]=='W') Wnum[i]++;
		else Enum[i]++;
	}
	rep1(i,N){
		int score=Enum[N]-Enum[i]+Wnum[i-1]-Wnum[0];
		scoremin=min(scoremin,score);
	}
	prin(scoremin);
	return 0;
}


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

int main (){
  int N, K;
  cin >> N >> K;
  vector<int> vec(K);
  for(int i=0; i<K; i++){
    cin >> vec.at(i);
  }

  int y = 1;
  int ans = N;
  
  while(N > 0){
    int x = N%10;
    for(int i=0; i<K; i++){
      if(vec.at(i) == x){
        ans++;
        N = ans*10;
        break;
      }
    }
    N /= 10;
  }
  cout << ans << endl;
}

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

static const int MAX = 100;
static const int UNVISITED = 0;
static const int VISITING = 1;
static const int VISITED = 2;

static const int INFTY = (1 << 21);


int n, M[MAX][MAX];

void Dijkstra() {
	
   int d[MAX], s[MAX];
   int  minv;

   for( int i = 0; i < n; i++) {
    	d[i] = INFTY;
       	s[i] = UNVISITED;
    }
    
   d[0] = 0;
  int u = 0;
   while( u != -1 ) {
      s[u] = VISITED; 
   	  minv = INFTY;
      int e = -1;
      for( int v = 0; v < n; v++ ) {

      	if( s[v] != VISITED && M[u][v] !=INFTY ) {
      		if( d[v] > d[u] + M[u][v] ) {
      			d[v] = d[u] + M[u][v];
      		}
      	}

      	if( s[v] != VISITED  && minv > d[v]) {
           
        		e = v;
        		minv = d[v];
     		}
      }
        
      u = e;
    }  

  
   for(int i = 0; i < n; i++ ) {
   	
   	cout << i << ' ' << d[i] << endl;
   }
   	
   
}


int main() {
   cin >> n;

   for( int i = 0; i < n; i++ ) {
   	for( int j = 0; j < n; j++ ) {
      	M[i][j] =  INFTY ;
   	}
   }
   
   int u, k, v, c;
   for( int i = 0; i < n; i++) {
   	cin >> u >> k;
   	while( k-- ) {
   		cin >> v >> c;
   		M[u][v] = c;
   	}
   }

    Dijkstra() ;

   return 0;
}




Measured memory_bytes: 3120
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {
    double ans;
    double x1, y1, x2, y2;
    
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    ans = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1);
    
    printf("%lf\n", sqrt(ans));
    
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    vint ls(n);
    map<int, int> mp;
    rep(i, n) {
        ls[i] = abs(i-(n-1-i));
        mp[ls[i]]++;
    }
    sort(all(ls));
    rep(i, n) {
        if (a[i] != ls[i]) {
            puts("0");
            return 0;
        }
    }
    int ans = 1;
    for(auto x : mp) {
        ans *= x.se;
        ans %= MOD;   
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
using namespace std;
 
string print(string s, int a, int b){
    return s.substr(a, b - a + 1);
}
 
string reverse(string s, int a, int b){
    string news = s;
    for (int i = 0; i < b - a + 1; i++){
        news[b - i] = s[a + i];
    }
    return news;
}
 
string replace(string s, int a, int b, string p){
    return s.replace(a, b - a + 1, p);
}
 
int main()
{
    string str, command;
    int q;
    cin >> str;
    cin >> q;
    for (int i = 0; i < q; i++){
        cin >> command;
        int a, b;
        cin >> a >> b;
        string p;
        if (command == "print"){
            cout << print(str, a, b) << endl;
        }
        else if (command == "reverse"){
            str = reverse(str, a, b);
        }
        else if (command == "replace"){
            cin >> p;
            str = replace(str, a, b, p);
        }
    }
    return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
int n;string s;
bool go(int l,int r){
	while (r>l){
		if (s[l]!=s[r]) return 0;
		r--,l++;
	}
	return 1;
}
int main(){
	cin>>s;n=s.size();s="("+s;
	if (go(1,n) && go(1,(n-1)/2) && go((n+3)/2,n)) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=998244353,MAX=1e2+2;

int main(){
    IOS;
    int c,ans;
    cin>>c;
    if(c>=400&&c<=599)
        ans=8;
    else if(c>=600&&c<=799)
        ans=7;
    else if(c>=800&&c<=999)
        ans=6;
    else if(c>=1000&&c<=1199)
        ans=5;
    else if(c>=1200&&c<=1399)
        ans=4;
    else if(c>=1400&&c<=1599)
        ans=3;
    else if(c>=1600&&c<=1799)
        ans=2;
    else if(c>=1800&&c<=1999)
        ans=1;
    cout<<ans;
}
/*

*/


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

using namespace std;

int main(){
  int w, h ,n;
  cin >> w >> h >> n;
  int paper[w][h]={};
  int x, y, a, x_start, x_end, y_start, y_end;
  for(int i=0;i<n;i++){
    cin >> x >> y >> a;
    if(a==1){
      x_start=0;
      x_end=x-1;
      y_start=0;
      y_end=h-1;
    }
    else if(a==2){
      x_start=x;
      x_end=w-1;
      y_start=0;
      y_end=h-1;
    }
    else if(a==3){
      x_start=0;
      x_end=w-1;
      y_start=0;
      y_end=y-1;
    }
    else if(a==4){
      x_start=0;
      x_end=w-1;
      y_start=y;
      y_end=h-1;
    }
    for(int j=x_start;j<=x_end;j++){
      for(int k=y_start;k<=y_end;k++){
        paper[j][k]++;
      }
    }
  }
  int white=0;
  for(int j=0;j<w;j++){
    for(int k=0;k<h;k++){
      if(paper[j][k]==0)white++;
        //cout << paper[j][k] << " ";
    }
      //cout << endl;
  }
  cout << white << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    int t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

bool dfs(int s,int n,vector<vector<int>> &graph,vector<int> &seen){
    rep(i,n){ 
        if(graph[s][i]==1){
            if(seen[i]!=-1){
                if(seen[i]==seen[s])return false;
            }else{
                seen[i]=1-seen[s];
                if(!dfs(i,n,graph,seen))return false;
            }
        }
    }
    return true;
}

int main(){
    ios::sync_with_stdio(false);std::cin.tie(nullptr);
    int n;cin >> n;
    vector<vector<int>> graph(n,vector<int>(n,1000*n));//1000*nはINF
    rep(i,n)graph[i][i]=0;
    rep(i,n)rep(j,n){
        char s;cin >> s;
        if(s=='1')graph[i][j]=1;
    }
    
    //二部グラフでない時-1
    vector<int> seen(n,-1);
    seen[0]=0;
    if(!dfs(0,n,graph,seen)){cout << -1 << '\n';return 0;}
    
    //warshall_floyd
    rep(k,n)rep(i,n)rep(j,n){
        graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
        graph[j][i]=graph[i][j];
    }
    
    ll ans=0;
    rep(i,n)rep(j,n){
        ans=max(ans,graph[i][j]);
    }
    cout << ans+1 << '\n';
}

Measured memory_bytes: 480
#include<iostream>

using namespace std;

int bingo[3][3];
int n;
int target[10];
bool isok[3][3];

int main() {
	for (int i = 0; i < 3; i++)for (int j = 0; j < 3; j++)cin >> bingo[i][j];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> target[i];

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (bingo[j][k] == target[i])isok[j][k] = true;
			}
		}
	}
	if ((isok[0][0] && isok[0][1] && isok[0][2]) ||
		(isok[1][0] && isok[1][1] && isok[1][2]) ||
		(isok[2][0] && isok[2][1] && isok[2][2]) ||
		(isok[0][0] && isok[1][0] && isok[2][0]) ||
		(isok[0][1] && isok[1][1] && isok[2][1]) ||
		(isok[0][2] && isok[1][2] && isok[2][2]) ||
		(isok[0][0] && isok[1][1] && isok[2][2]) ||
		(isok[0][2] && isok[1][1] && isok[2][0]))
		cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int a,b;
	cin >> a >> b;
	if (a == 1 && b == 2)
	{
		cout << 3;
	}
	else if (a == 1 && b == 3)
	{
		cout << 2;
	}
	else if (a == 2 && b == 3)
	{
		cout << 1;
	}
	else if (a == 3 && b == 2)
	{
		cout << 1;
	}
	else if (a == 3 && b == 1)
	{
		cout << 2;
	}
	else if (b == 1 && a == 2)
	{
		cout << 3;
	}
	else if (b == 2 && a == 3)
	{
		cout << 1;
	}
	else if (b == 3 && a == 2)
	{
		cout << 1;
	}
	else
	{
		cout << 2;
	}
}



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

int main() {
    long long N;
    int a=1,ans=1,b=0;
    cin >> N;

    map<string, long> list;
    vector<string> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        list[A.at(i)]++;
    }
    vector<pair<long, string> > pairs(N);
    long j=0,m=0; 
    for (auto const& entry: list){
        m = max(m,entry.second);
        pairs[j] = make_pair(entry.second, entry.first);
        j++;
    }
    sort(pairs.begin(), pairs.end());
    for (int i = 0; i < N; i++) {
        if(pairs[i].first==m) cout << pairs[i].second << endl;
    }
    
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> l(n, 0), wa(n, 0);
    int ac = 0, answa = 0;
    int p;
    string s;
    for (int i = 0; i < m; i++)
    {
        cin >> p >> s;
        if (l[p - 1] == 0)
        {
            if (s == "AC")
            {
                l[p - 1] = 1;
                ac++;
            }
            else
            {
                wa[p - 1]++;
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (l[i] == 1)
        {
            answa += wa[i];
        }
    }
    cout << ac << " " << answa << endl;
    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back

const ll MAX=1e18;
vll a(100010);

int main() {
  int n; cin>>n;
  ll ans=1;
  rep(i,n) {
    cin>>a[i];
    if(a[i]==0) {
      cout<<0<<endl;
      return 0;
    }
  }
  rep(i,n) {
    if(ans>MAX/a[i]) {
      ans=-1;
      break;
    }
    else ans*=a[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll x,b,c;
    cin >> x;
    rep(a,1,10000){
    	bool minu=false;
    	b = a*a*a*a*a-x;
    	if(b==0){
    		cout << a << " 0" << endl;
    		return 0;
    	}
    	if(b<0){
    		minu=true;
    		b = -b;
    	} 
    	c = max((long long)pow((double)b, 0.2) - 40, 0ll);
    	rep(j,c,10000){
    		if(j*j*j*j*j==b){
    			if(minu) cout << a << " " << -j << endl;
    			else cout << a << " " << j << endl;
    			return 0;
    		}
    		if(j*j*j*j*j>b) break;
    	}
    }
    return 0;
}

Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  map<int,vector<ll>> memo;
  rep(i,N){
    ll a, b;
    cin >> a >> b;
    memo[a].push_back(b);
  }

  ll sum = 0;
  priority_queue<ll> que;
  REP(day,1,M+1){
    if(memo.count(day) > 0){
      vector<ll> v = memo[day];
      
      rep(i,v.size()){
        que.push(v[i]);
      }
    }
    if(!que.empty()){
      sum += que.top();
      que.pop();
    }
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 10880
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.Remoting.Services;
using System.Text;

namespace ConsoleApplication1
{
    internal static class Program
    {
        public static void Main(string[] args)
        {
            var scanner = new StreamScanner(Console.OpenStandardInput());
            var n = scanner.Integer();
         
            var arr = new int[n];
            for (var i = 0; i < n; i++)
            {
                arr[i] = scanner.Integer();
            }

            var stables = new HashSet<int>(Enumerable.Range(0, n).Where(x =>
                (x == 0 || arr[x] != arr[x - 1]) && (x == n - 1 || arr[x] != arr[x + 1])
            ));

            var score = 0;

            for (var i = 0; i < n - 1; i++)
            {
                if (stables.Contains(i)) continue;

                var j = i + 1;
                for (; j < n; j++)
                {
                    if (stables.Contains(j)) break;
                }

                var diff = j - i;
                if (diff == 1) score += 1;
                else if (diff % 2 == 0) score += diff / 2;
                else if (diff % 2 == 1) score += (diff - 1) / 2;
                i = j - 1;
            }

            Console.WriteLine(score);
        }
    }
    
    
    // https://qiita.com/Camypaper/items/de6d576fe5513743a50e
    public class StreamScanner
    {   
        private readonly Stream stream;
        private readonly byte[] buf = new byte[1024];
        private int len, pos;
        private bool isEof = false;
        public bool IsEndOfStream => isEof;

        public StreamScanner(Stream stream) { this.stream = stream; }
        
        private byte Read()
        {
            if (isEof) throw new EndOfStreamException();
            if (pos >= len) {
                pos = 0;
                if ((len = stream.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[pos++];
        }
        
        public char Char() 
        {
            byte b = 0;
            do b = Read();
            while (b < 33 || 126 < b);
            return (char)b; 
        }
        
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)Read())
                sb.Append(b);
            return sb.ToString();
        }
        
        public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = Read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = Read(); }
            for (; true; b = Read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        
        public int Integer() { return (int)Long(); }
        public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
}


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

using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    int n, m;
    cin >> n >> m;
    vi a(m);
    vi gu, ki;
    rep (i, m) {
        cin >> a[i];
        if (a[i] % 2 == 0) gu.push_back(a[i]);
        else ki.push_back(a[i]);
    }
    if (ki.size() > 2) {
        cout << "Impossible" << endl;
        return 0;
    }

    vi aa;
    if (ki.size() > 0) aa.push_back(ki[0]);
    rep (i, gu.size()) aa.push_back(gu[i]);
    if (ki.size() > 1) aa.push_back(ki[1]);

    rep (i, m) cout << aa[i] << " ";
    cout << endl;
    vi b;
    rep (i, aa.size()) {
        if (i == 0) {
            if (aa[i] > 1) b.push_back(aa[i] - 1);
        }            
        else if (i == aa.size() - 1) b.push_back(aa[i] + 1);
        else b.push_back(aa[i]);
    }
    if (aa.size() == 1) b.push_back(1);

    cout << b.size() << endl;
    rep (i, b.size()) cout << b[i] << " ";
    cout << endl;
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define I1000000007 (1000000007)
#define I998244353   (998244353)
#define IINF             (1<<28)
#define LINF           (1LL<<60)
#define ALL(a)         (a).begin(), (a).end()
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template<class T> inline bool chmin(T& a, const T& b) {
  if (a > b) { a = b; return true; } else return false;
}
template<class T> inline bool chmax(T& a, const T& b) {
  if (a < b) { a = b; return true; } else return false;
}

namespace solver {
  using namespace std;
  using ll = long long;

  // static const int MAX = 100010;
  // int N, M, K, as[MAX], bs[MAX];

  void init() {
  }

  void solve() {
    int A, B;
    cin >> A >> B;
    cout << A * B << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define r(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int main(){
	string s;
	while(cin>>s){
		if(s[0]=='#')break;
		char a='A';
		r(i,0,s.size()){
			if(a=='A')a=(s[i]=='0')?'X':'Y';
			else if(a=='X')a=(s[i]=='0')?'Q':'Z';
			else if(a=='Y')a=(s[i]=='0')?'X':'Q';
			else if(a=='Z')a=(s[i]=='0')?'W':'B';
			else if(a=='W')a=(s[i]=='0')?'B':'Y';
			else if(a=='B')a=(s[i]=='0')?'Y':'X';
			if(a=='Q')break;
		}
		if(a=='B')cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}

}

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

int gcd(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    int x1, y1;
    int d = gcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

bool isValid(int a, int b, int c, int &x0, int &y0, int &g) {
    g = gcd(abs(a), abs(b), x0, y0);
    if (c % g) {
        return false;
    }

    x0 *= c / g;
    y0 *= c / g;
    if (a < 0) x0 = -x0;
    if (b < 0) y0 = -y0;
    return true;
}


int main(){

    int x,y;
    scanf("%d%d",&x,&y);

    int maxleg = x*4;
    int minleg = x*2;

    if(
        (y>maxleg)||(y<minleg)
    )   cout<<"No";

    else{
        int a,b,g;
        bool ans = isValid(4,2,y,a,b,g);
        cout<<(ans?"Yes":"No");
    }

    return 0;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int quo=n,rem=0;
  while(quo!=0)
  {
    quo = quo/k;
    rem++;
  }
  cout<<rem;
  return 0;
}
    
    
  

Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int dt[1001];
		dt[0]=0;
		loop(i,1,1001)dt[i]=dt[i-1]+i;
		int cnt=0;
		loop(i,1,n+1){
			loop(j,i+1,n+1)if(dt[j]-dt[i]+i==n){
				cnt++;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}


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

bool check_p(int val);

int main(){
    int X;
    cin >> X;
    
    while(true){
        bool flag = check_p(X);
        if(flag){
            cout << X << endl;
            break;
        }
        X += 1;
    }
    return 0;
}

bool check_p(int val){
    int max_v = int(pow(val, 0.5));
    for(int j=2; j<=max_v; j++){
        if(val%j == 0){
            return false;
        }
    }
    return true;
}

Measured memory_bytes: 3984
n=int(input())
lis=list(map(int,input().split()))
num=(n*(n+1))//2
ll=sum(lis)
if ll%num!=0:
  print("NO")
  exit()
ans=0
for i in range(n):
  if abs(lis[i]-lis[i-1]-ll//num)%n!=0:
    print("NO")
    exit()
  ans+=abs(lis[i]-lis[i-1]-ll//num)//n
if ans == ll//num:print("YES")
else:print("NO")


Measured memory_bytes: 14996