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

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	int k;
	string s;
	cin>>k;
	cin>>s;
	int n = s.size();
	if(n <= k)
		cout<<s<<"\n";
	else
		cout<<s.substr(0,k) + "...";
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main() {
	char*N = new char[3];

	cin >> N;

	if (N[0] == '7' || N[1] == '7' || N[2] == '7') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

using namespace std;

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

    vector<long long int> H(N);
    for(int n=0; n<N; n++) {
        cin >> H[n];
    }
    
    sort(H.begin(), H.end(), greater<long long int>());
    long long int ans=0;
    for(int k=K; k<N; k++) {
        ans += H[k];
    }
    
    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 1792
import sys
s = input()
t = input()
yetlist = {}
yetlist2 = {}
for i in range(len(s)):
    if s[i] in yetlist:
        if t[i] != yetlist[s[i]]:
            print("No")
            sys.exit()
    else:
        yetlist[s[i]] = t[i]
    if t[i] in yetlist2:
        if s[i] != yetlist2[t[i]]:
            print("No")
            sys.exit()
    else:
        yetlist2[t[i]] = s[i]   
            
print("Yes")

Measured memory_bytes: 3632
x,k,d=map(int,input().split())

num_moved = min(abs(x) // d, k)
num_remained = k - num_moved
if num_moved > k:
  now = x % d
else:
  tmpa = x + d*num_moved
  tmpb = x - d*num_moved
  now = min(abs(tmpa), abs(tmpb))
#  now = x - d*num_moved

if num_remained % 2 == 0:
  result = abs(now)
else:
  tmpa = now + d
  tmpb = now - d
  if abs(tmpa) > abs(tmpb):
    result = abs(tmpb)
  else:
    result = abs(tmpa)
print(result)

Measured memory_bytes: 9168
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = (arg[0]);
    const T = (arg[1].split(""));
    
    let answer = T.length;
    
    // if(S === T.join("")) {
    //     console.log(0);
    //     return;
    // }
    
    // for(let i=0; i<T.length; i++) {
    //     let t = T[i];
        
    //     for(let j=i; j<S.length; j++) {
    //         let s = S[j];
    //         let temp = 0;
            
    //         if(S.length - j < T.length) {
    //             continue;
    //         }

    //         if(t === s) {
    //             temp++;
    //             let cnt = 1;
                
    //             // console.log("一致！");
    //             // console.log(i + "番目の:" + t);
    //             // console.log(j + "番目の:" + s);
                
    //             while(i + cnt < T.length && j + cnt <S.length) {
    //                 // console.log("その次");
    //                 // console.log("T[i+cnt]:" + T[i+cnt]);
    //                 // console.log("S[j+cnt]:" + S[j+cnt]);
                
    //                 if(T[i+cnt] === S[j+cnt]) {
    //                     temp++;
    //                 }
                    
    //                 cnt++;
    //             }
    //         }
            
    //         // console.log("temp:" + temp);
    //         // console.log("-----")
    //         answer = Math.min(T.length - temp, answer);
    //     }
    // }
    
    // console.log(S.length);
    // console.log(T.length);
    
    for(let i=0; i<S.length - T.length + 1; i++) {
        const str = S.slice(i, i + T.length).split("");
        let temp = 0;
        
        // console.log("str:" + str);
        
        for(let j=0; j<str.length; j++) {
            // console.log("str[j]:" + str[j]);
            // console.log("T[j]:" + T[j]);
            // console.log(".......")
            
            if(str[j] !== T[j]) {
                temp++;
            }
        }
        
        // console.log("書き換える必要がある数:" + temp);
        answer = Math.min(answer, temp);
        // console.log("-------")
    }

    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int x,y;
  while(1){
    cin >> x >> y;
    if(x==0 && y==0)break;
    if(x<=y)cout << x << ' ' << y << endl;
    else cout << y << ' ' << x << endl;
  }
}



Measured memory_bytes: 3088
#include<stdio.h>
#include<stdlib.h>
int count = 0;
int visit(int s,int count3,int n,int **a,int *visited) {
	if (count3 == n) {
		count++;
		return;
	}
	int i;
	for ( i = 0; i < n; i++)
	{
		if (visited[i] == 0&&a[s][i]==1) {
			visited[i] = 1;
			visit(i, count3+1, n, a, visited);
			visited[i] = 0;
		}
	}
	return ;
}
int main() {
	int n, m;
	scanf("%d %d",&n,&m);
	int i,j;
	int** a = malloc(sizeof(int *) * n);
	int x, y;
	for ( i = 0; i < n; i++)
	{
		a[i] = malloc(sizeof(int) * n);
		for (j = 0; j < n; j++)
			a[i][j] = 0;
	}

	for (i = 0; i < m; i++)
	{
		scanf("%d %d", &x,&y);
		a[x-1][y-1] = 1;
		a[y - 1][x - 1] = 1;
	}
	int  k, l;
	int* visited = malloc(sizeof(int) * n);
	for ( i = 0; i < n; i++)
	{
		visited[i] = 0;
	}
	visited[0] = 1;
	visit(0, 1, n, a, visited);
	printf("%d", count);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int H,W;
    cin >> H >> W;
    char S[W][H];
    rep(i,H) {
        rep(j, W) {
            cin >> S[j][i];
        }
    }
    int dx[] = { 0, 0, 1,-1};
    int dy[] = {-1, 1, 0, 0};
    bool result = false;
    rep(i,H) {
        rep(j, W) {
            bool found = false;
            if (S[j][i] == '.') continue;
            rep(k,4) {
                if (j + dx[k] < 0 || j + dx[k] > W) continue;
                if (i + dy[k] < 0 || i + dy[k] > H) continue;
                if (S[j + dx[k]][i + dy[k]] == '#') {
                    found = true;
                    break;
                }
            }
            if (!found) {
                cout << "No" << endl; exit(0);
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
using namespace std;

signed main(){
    int n; cin>>n;
    int ans=n/11*2;
    n%=11;
    if(n==0);
    else if(n<=6) ans++;
    else ans+=2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll a,b,n; cin >> a >> b >> n;
	ll ans = a*min(b-1,n)/b;
	cout << ans << endl;
}

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

using namespace std;


int main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    sort(a.begin(), a.end());
    for(int i = 0; i < n-1; i++) {
        if(x >= a[i]) {
            x -= a[i];
            ans++;
        } else {
            break;
        }
    }
    if(a[n-1] == x) {
        ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


long long n;

bool ok(long long a){
  long long k = n;
  while(!(k % a) && k >= a) k /= a;
  if(k % a == 1) return true;
  return false;
}


int main() {
  cin >> n;
  vector<long long> a, a1;
  for(long long i = 1; i * i <= n; ++i){
    if(n % i == 0){
      a.push_back(i);
      if(n / i != i) a.push_back(n / i);
    }
  }
  for(long long i = 1; i * i <= n - 1; ++i){
    if((n - 1) % i == 0){
      a1.push_back(i);
      if((n - 1) / i != i) a1.push_back((n - 1) / i);
    }
  }
  set<long long> s;
  for(long long i = 0; i < a.size(); ++i){
    if(a[i] >= 2 && ok(a[i])) s.insert(a[i]);
  }
  for(int i = 0; i < a1.size(); ++i){
    if(a1[i] >= 2 && (n % a1[i])) s.insert(a1[i]);
  }
  cout << s.size();
}


Measured memory_bytes: 888
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;


int main()
{
	int n, k;
	cin >> n >> k;
	vector<int>l(n);
	for (int& x : l)cin >> x;

	sort(l.begin(), l.end());
	cout << accumulate(l.end()-k,l.end(),0) << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin>>a>>b;
  int count=0;
  for(int i=a;i<=b;i++){
    string str_i=to_string(i);
    vector<char> str_is(str_i.size());
    for(int j=0;j<str_i.size();j++){str_is.at(j)=str_i.at(j);}
    reverse(str_is.begin(),str_is.end());
    string rev_str_i;
    for(int j=0;j<str_i.size();j++){rev_str_i=rev_str_i+str_is.at(j);}
    if(str_i==rev_str_i){count++;}
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("outp.txt","w",stdout);
    #endif
    ll n,i,sum=0;
    cin>>n;
    vector<ll> v(n);
    map<ll,ll> m;
    for(i=0;i<n;i++)
    {
        cin>>v[i];
        m[v[i]]++;
    }
    map<ll,ll>::iterator it;
    for(it=m.begin();it!=m.end();it++)
    {
        sum=sum+((it->second*(it->second-1))/2);
    }
    for(i=0;i<n;i++)
    {
        ll x=m[v[i]]-1;
        ll y=(m[v[i]]*(m[v[i]]-1))/2;
        x=(x*(x-1))/2;
        cout<<sum-y+x<<endl;
    }
}

    


Measured memory_bytes: 12680
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr(be, en) for(int i = be; i <= en; i++) 
ll mod = LLONG_MAX;
ll power(ll a, ll b)
{
	if(b == 0) return 1;
	ll ans = power(a, b/2);
	ans = (ans*ans)%mod;
	if(b%2) ans*=a;
	return ans%mod;
}
ll mul(ll a,ll n, ll mod)
{
	ll ret;
	if(n==0) return 0;
	ret = mul(a,n/2, mod);
	ret = (ret+ret)%mod;
	if(n%2)	ret=(ret+a)%mod;
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	ll n, t;
	cin >> n;
	ll ans = 0;
	t = n;
	map<ll, ll> :: iterator it;
	map<ll, ll> hm;
	for(ll i = 2; i*i <= t; i++)
	{
		if(n%i) continue;
		it = hm.find(i);
		if(it == hm.end()) hm.insert({i, 0});
		it = hm.find(i);
		while(n%i == 0) { it->se++; n/=i; }		
	}
	if(n != 1)
	{
		it = hm.find(n);
		if(it == hm.end()) hm.insert({n, 1});
		else it->se++;
	}
	ll num = 1;
	for(it = hm.begin(); it != hm.end(); it++)
	{
		ll x = 1;
		while((x*(x + 1))/2 <= it->se) x++;
		x--;
		ans += x;
	}
	cout << ans;
}

Measured memory_bytes: 3656
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmin(T &a, T b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
mt19937 mt;          
random_device rnd;    
int n = 26;
int D;
ll c[26];
ll s[365][26];
set<int> st[26];
int last[26];
int res[365];

void climing(){
    int day = mt()%365;
    int ch = mt()%26;
    while(ch==res[day]){
        ch = mt()%26;
    }
    ll score = 0;
    score += s[day][ch] - s[day][res[day]];
    auto x = st[res[day]].lower_bound(day);
    ll pre;
    if(x==st[res[day]].begin()){
        pre = 0;
    }else{
        x--;
        pre = (*x);
        x++;
    }
    x++;
    ll nxt;
    if(x==st[res[day]].end()){
        nxt = D;
    }else{
        nxt = (*x);
    }
    score -= (nxt-pre+1)*(nxt-pre+2)/2*c[res[day]] - (nxt-day)*(nxt-day+1)/2*c[res[day]] - (day-pre)*(day-pre+1)/2*c[res[day]];   
    x = st[ch].lower_bound(day);
    if(x==st[ch].begin()){
        pre = 0;
    }else{
        x--;
        pre = (*x);
        x++;
    }
    if(x==st[ch].end()){
        nxt = D;
    }else{
        nxt = (*x);
    }
    score += (nxt-pre+1)*(nxt-pre+2)/2*c[ch] - (nxt-day)*(nxt-day+1)/2*c[ch] - (day-pre)*(day-pre+1)/2*c[ch];   
    if(score>0){
        st[res[day]].erase(day);
        st[ch].insert(day);
        res[day] = ch;
    }
    // cerr << "test" << endl;
}
void init(){
    //初期解
    rep(i,D){
        ll mx = 0;
        rep(j,26){
            if(chmax(mx,s[i][j]+ c[j]*(i-last[j]))){
                
                res[i] = j;
            }
        }
        last[res[i]] = i;
        st[res[i]].insert(i);
    }
    return;
}
int main(){
    std::chrono::system_clock::time_point  start, end; // 型は auto で可
    start = std::chrono::system_clock::now(); // 計測開始時間
    mt.seed(rnd());
    cin >> D;
    rep(i,n){
        cin >> c[i];
    }
    rep(i,D){
        rep(j,26){
            cin >> s[i][j];
        }
    }
    init();
    while(1){
        end = std::chrono::system_clock::now();  // 計測終了時間
        double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count(); 
        if(elapsed >= 1950)break;
        climing();
    }
    rep(i,D){
        cout << res[i]+1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 3292
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string a,b; cin>>a>>b;
	vector<int> pa,pb;
	pa.emplace_back(0);
	for(auto &i:a){
		if(i=='A') pa.emplace_back(pa.back()+1);
		else       pa.emplace_back(pa.back()+2);
	}
	pb.emplace_back(0);
	for(auto &i:b){
		if(i=='A') pb.emplace_back(pb.back()+1);
		else       pb.emplace_back(pb.back()+2);
	}
	int q; cin>>q;
	int s1,t1,s2,t2;
	while(q--){
		cin>>s1>>t1>>s2>>t2;
		int a1=pa[t1]-pa[s1-1];
		int a2=pb[t2]-pb[s2-1];
		if(a1%3==a2%3) cout<<"YES\n";
		else cout<<"NO\n";
	}
	return 0;
}





























Measured memory_bytes: 2884
A,B,C,D,E,F=map(int,input().split())

from itertools import product
w=[]
for i,j in product(range(F//(100*A)+1),range(F//(100*B)+1)):
    if 0<100*A*i+100*B*j<=F:
        w.append(100*A*i+100*B*j)
s=[]
for i,j in product(range(E*F//(100*C)+1),range(E*F//(100*C)+1)):
    if C*i+D*j<=E*(F//100):
        s.append(C*i+D*j)

w.sort()
s.sort()
ans=[]
for a in w:
    for b in s:
        if (a//100)*E>=b and a+b<=F:
            ans.append([a+b,b])
        else:
            break
ans.sort(key=lambda x:x[1]/(x[0]+x[1]),reverse=True)
print(ans[0][0],ans[0][1])


Measured memory_bytes: 130976
import java.util.Scanner;

public class Main {

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

		System.out.println(check(s) ? "AC" : "WA");
	}

	static boolean check(String s) {
		int cnt = 0;
		if(s.charAt(0) != 'A') return false;
		for (int i = 1; i < s.length(); i++) {
			if('A' <= s.charAt(i) && s.charAt(i) <= 'Z') {
				if(i == 1 || i == s.length() - 1 || s.charAt(i) != 'C') return false;
				cnt++;
			}
		}
		if(cnt != 1) return false;

		return true;
	}
}

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

using namespace std;

int main() {
  int n, ans = 0, i = 1;
  scanf("%d", &n);
  while (true) {
    if (i * 2 - 1 > n) {
      printf("%d\n", ans);
      return 0;
    } else {
      ans++;
    }
    i *= 2;
  }
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
#define int ll
const ll mod=1e9+7;

int power(int x, int y, int p)  
{  
    int res = 1;
    x = x % p; 
    if (x == 0) return 0;   
    while (y > 0)  
    {   
        if (y & 1)  
            res = (res*x) % p;
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 

int32_t main()
{
    int N,W;
    cin>>N>>W;
    int w[N+1],v[N+1],dp[N+1][W+1];
    for (int i = 1; i <= N; ++i)
    {
        cin>>w[i]>>v[i];
    }
    //int dp[N+1][w+1];
    memset(dp,0,sizeof(dp));
    for (int i = 0; i < N; ++i)
    {
        dp[i][0]=0;
    }
    for (int i = 0; i <= W; ++i)
    {
        dp[0][i]=0;
        if(i>=w[1])
        {
            //cout<<v[1]<<"a"<<endl;
            dp[1][i]=v[1];
        }
        else
            dp[1][i]=0;
    }
    // for (int i = 0; i <= W; ++i)
    // {
    //     cout<<dp[1][i]<<endl;
    // }
    for (int i = 2; i <= N; ++i)
    {
        for (int j = 0; j <= W; ++j)
        {
            if(j-w[i]>=0)
            {
                dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
            }
            else
            {
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    // for (int i = 1; i <= N; ++i)
    // {
    //     for (int j = 0; j <= W; ++j)
    //     {
    //        cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    cout<<dp[N][W]<<endl;
}




Measured memory_bytes: 79104
#include <iostream>
#include <vector>

using namespace std;

int main() {
  long long N, M;
  long long K;
  cin >> N;
  cin >> M;
  cin >> K;
  
  vector <long long> sumA(N + 1, 0);
  vector <long long> sumB(M + 1, 0);
  
  long long tmp = 0L;
  for (int i = 0; i < N; ++i) {
    long long a;
    cin >> a;
    tmp += a;
    sumA[i + 1] = tmp;
  }
  
  tmp = 0L;
  for (int j = 0; j < M; ++j) {
    long long b;
    cin >> b;
    tmp += b;
    sumB[j + 1] = tmp;
  }

  long long j = M;
  long long ans = 0;
  // read i books from the top of A
  for (int i = 0; i <= N; ++i) {
    if (sumA[i] > K) break;
    while (sumA[i] + sumB[j] > K) j--;
    ans = max(ans, i + j);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6052
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> b(n-1);
    for(int i = 0; i < n - 1; i++) {
        cin >> b[i];
    }
    
    ll ans = 0;
    int tmp = 10000000;
    for(int i = 0;i < n- 1; i++) {
        ans += min(b[i], tmp);
        tmp = b[i];
    }
    
    cout << ans + b[n - 2] << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
#include <cctype>

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

using namespace std;

struct expr
{
	char c;
	bool is_op;
	expr *x, *y;

	expr(char c)
		: c(c), is_op(false), x(NULL), y(NULL)
	{
	}

	expr(char op, expr *x, expr *y)
		: c(op), is_op(true), x(x), y(y)
	{
	}

	~expr()
	{
		delete x;
		delete y;
	}

	string to_string()
	{
		stringstream buf;
		if (is_op)
			buf << "(" << x->to_string() << c << y->to_string() << ")";
		else
			buf << c;
		return buf.str();
	}
};

string src;
int p;

bool end() { return p >= src.length(); }
char peek() { return src[p]; }
void succ() { if (!end()) ++p; }

bool is_lassoc[11];
int prec[128]; // 値が大きい方が結合が強い

// op が来た時、op0 を reduce するか？
bool reduce(char op, char op0)
{
	return prec[op] < prec[op0] || (is_lassoc[prec[op0]] && prec[op] == prec[op0]);
}

expr *parse()
{
	stack<char> ost;
	stack<expr *> est;

	while (!end())
	{
		char c = peek();
		if (c == ')') break;
		if (isalpha(c))
		{
			succ();
			est.push(new expr(c));
		}
		else if (c == '(')
		{
			succ();
			est.push(parse());
			if (peek() == ')') succ();
		}
		else
		{
			succ();
			while (!ost.empty() && reduce(c, ost.top()))
			{
				expr *y = est.top(); est.pop();
				expr *x = est.top(); est.pop();
				est.push(new expr(ost.top(), x, y));
				ost.pop();
			}
			ost.push(c);
		}
	}
	while (!ost.empty())
	{
		expr *y = est.top(); est.pop();
		expr *x = est.top(); est.pop();
		est.push(new expr(ost.top(), x, y));
		ost.pop();
	}
	return est.top();
}

int main()
{
	int D;
	cin>>D;
	while(D--)
	{
		int G;
		cin>>G;
		rep(i,G)
		{
			char A;
			int M;
			cin>>A>>M;
			is_lassoc[i] = A == 'L';
			rep(j,M)
			{
				char op;
				cin>>op;
				prec[op] = i;
			}
		}

		int N;
		cin>>N;
		rep(i,N)
		{
			cin>>src;
			p = 0;
			expr *e = parse();
			cout << e->to_string() << endl;
			delete e;
		}

		if (D) cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1000
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	l := nextInt()
	taste := 0
	if l >= 0 {
		for i := 1; i < n; i++ {
			taste += i + l
		}
	} else if l < 0 && (n + l) > 0 {
		for i := 0; i < n; i++ {
			taste += i + l
		}
	} else {
		for i := 0; i < n-1; i++ {
			taste += i + l
		}
	}
	fmt.Println(taste)
}


Measured memory_bytes: 640
#!/usr/bin/env python2
"""
This file is part of https://github.com/cheran-senthil/PyRival
Copyright 2019 Cheran Senthilkumar <hello@cheran.io>

"""
from __future__ import division, print_function

import itertools
import os
import sys
from atexit import register
from cStringIO import StringIO
from collections import Counter

range = xrange

filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip

sys.stdout = StringIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = StringIO(os.read(0, os.fstat(0).st_size)).readline

MOD = 10**9 + 7
MODF = float(MOD)

MAGIC = 6755399441055744.0
SHRT = 65536.0

MODF_INV = 1.0 / MODF
SHRT_INV = 1.0 / SHRT

fround = lambda x: (x + MAGIC) - MAGIC
fmod = lambda a: a - MODF * fround(MODF_INV * a)
fmul = lambda a, b, c=0.0: fmod(fmod(a * SHRT) * fround(SHRT_INV * b) + a * (b - SHRT * fround(b * SHRT_INV)) + c)


def main():
    n = input()
    s = input().rstrip('\r\n')

    res = 1
    for key, value in Counter(s).items():
        res = fmul(res, (value + 1))

    print(int(res - 1) % MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 33180
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
    int n,q,t;
    string name;
    
    queue<pair<string, int> > Q;
    
    cin >> n >> q;
    
    for(int i=0; i<n; i++){
        cin >> name >> t;
        Q.push(make_pair(name,t));
    }
    
    pair<string, int> u;
    int elaps = 0,a;
    
    while(!Q.empty()){
        u = Q.front(); Q.pop();
        a = min(u.second, q);
        u.second -= a;
        elaps += a;
        if(u.second > 0){
            Q.push(u);
        }else{
            cout << u.first << " " << elaps << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 6176
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

unsigned get_digit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main() {
    unsigned a,b;
    cin >> a >> b;
    unsigned int p = a * pow(10, get_digit(b)) + b;
    /* cout << get_digit(b) << endl; */
    /* cout << p << endl; */
    /* cout << sqrt(p) << endl; */
    if (p % int(sqrt(p)) == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
const Weight INF=1<<29;

void shortestPath(const Graph &g, int s,
    vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    for(auto &f:g[e.dst]) {
      if (dist[f.dst] > e.weight+f.weight) {
        dist[f.dst] = e.weight+f.weight;
        Q.push(Edge(f.src, f.dst, e.weight+f.weight));
      }
    }
  }
}

int main(){
	int n;
	scanf("%d",&n);
	vector<int> input(n+1);
	vector<int> target(n+1);
	for(int i=1;i<=n;i++)scanf("%d",&input[i]);
	//build target point
	for(int i=1;i<=n;i++)if(!target[i]){
		set<int>lst;
		int cur=i;
		for(;input[cur];){
			if(lst.find(cur)!=lst.end()){
				for(auto &e:lst)target[e]=-1;
				break;
			}
			lst.insert(cur);
			cur+=input[cur];
		}
		if(!input[cur]){
			for(auto &e:lst)target[e]=cur;
			target[cur]=cur;
		}
	}
	//dijkstra
	Graph g(n+1);
	for(int i=1;i<=n;i++)for(int j=1;j<=6;j++)if(i+j<=n&&~target[i+j])g[i].push_back(Edge(i,target[i+j],1));
	vector<Weight>dist;
	vector<int>prev;
	shortestPath(g,1,dist,prev);
	printf("%d\n",dist[n]);
}

Measured memory_bytes: 15780
n,m = [int(i) for i in input().split()]
a = [int(input()) for  i in range(m)]
a.append(n+1)
x = [1,1]
mod = 10**9+7
for i in range(n-1):
    x.append((x[-2]+x[-1])%mod)
if a[0]-1:
    ans = x[a[0]-1]
    p = a[0]
else:
    ans = 1
    p = 1
for i in range(1, m+1):
    if a[i]-p-1:
        ans = (ans*x[a[i]-p-2])%mod
        p = a[i]
    else:
        ans = 0
print(ans)

Measured memory_bytes: 11052
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n, *A;
void maxHeapify(int i){
  int l, r, max, cp;
  l = 2*i;
  r = 2*i+1;
  if(l <= n && A[l] > A[i])
    max = l;
  else max = i;
  if(r <= n && A[r] > A[max])
    max = r;
  if(max != i){
    cp = A[i];
    A[i] = A[max];
    A[max] = cp;
    maxHeapify(max);
  }
  return;
}
void buildMaxHeap(){
  int i;
  for(i = n/2; i > 0; i--)
    maxHeapify(i);
}
int main(){
  int i;
  scanf("%d",&n);
  A = malloc(sizeof(int)*(n+1));
  for(i = 1; i <= n; i++) scanf("%d",&A[i]);
  buildMaxHeap();
  for(i = 1; i <= n; i++)
    printf(" %d",A[i]);
  printf("\n");
  free(A);
  return 0;
}

Measured memory_bytes: 2472
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> a(N), b(N);
    vector<pair<ll, ll>> cnt(N);
    REP(i, N) {
        cin >> a[i] >> b[i];
        cnt[i] = make_pair(a[i], b[i]);
    }
    // aiをbi個数挿入する
    // N回後の配列でK番目
    sort(cnt.begin(), cnt.end());
    ll res = 0;
    for(int i = 0; i < N; i++) {
        res += cnt[i].second;
        if(res >= K) {
            cout << cnt[i].first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3328
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        if (n%2==1){
            System.out.println("No");
        }else{
            String t = s.substring(0,n/2);
            String u = s.substring(n/2);
            if (t.equals(u))System.out.println("Yes");
            else System.out.println("No");
        }
    }
}


Measured memory_bytes: 35696
#include <cstdio>
#include <algorithm>
#include <queue>

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

using namespace std;

typedef pair<int, pair<int, int>> P;

struct E{
	int t, c;
};

int n, m, p;
vector<E> g[100];
int d[2][100];
double c[2][100];

int main(){
	while(1){
		scanf("%d%d%d", &n, &m, &p);
		if(n == 0 && m == 0 && p ==0){
			break;
		}

		rep(i, m){
			int a, b, c;
			scanf("%d%d%d", &a, &b, &c);
			g[a].push_back(E{b, c});
			g[b].push_back(E{a, c});
		}

		rep(i, 2){
			fill(d[i], d[i] + n, 2e8);
			fill(c[i], c[i] + n, 0);

			priority_queue<P, vector<P>, greater<P>> q;
            int s = i == 0 ? 0 : n - 1;
			d[i][s] = 0;
			q.push(P(0, {s, -1}));
			while(!q.empty()){
				P v = q.top();
				q.pop();
				if(v.first > d[i][v.second.first]){
					continue;
				}
				bool f = c[i][v.second.first] != 0;
				c[i][v.second.first] += v.second.second != -1 ? c[i][v.second.second] : 1;
				if(f){
					continue;
				}
				for(auto& x: g[v.second.first]){
					if(d[i][x.t] >= d[i][v.second.first] + x.c){
						d[i][x.t] = d[i][v.second.first] + x.c;
						q.push(P(d[i][x.t], {x.t, v.second.first}));
					}
				}
			}
		}

        /*
        rep(i, 2){
            printf("\n");
            rep(j, n){
                printf("%.8f, %d\n", c[i][j], d[i][j]);
            }
            printf("\n");
        }
        */

        rep(i, p){
            int z;
            scanf("%d", &z);

            if(d[0][z] + d[1][z] == d[0][n - 1]){
                printf("%.8f\n", c[0][z] * c[1][z] / c[0][n - 1]);
            }
            else{
                printf("%.8f\n", 0.0);
            }
        }

		rep(i, n){
			g[i].clear();
		}
        printf("\n");
	}
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

char A[1001][1001];
int d[1001][1001];

struct pos
{
    int x;
    int y;
};
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};

void solve()
{
    int H, W;
    cin >> H >> W;
    queue<pos> Q;
    REP1 (h, H)
    {
        REP1 (w, W)
        {
            cin >> A[h][w];
            if (A[h][w] == '.')
                d[h][w] = INTINF;
        }
    }

    REP1 (h, H)
    {
        REP1 (w, W)
        {
            bool isinside = true;
            if (A[h][w] == '#')
            {
                REP0 (i, 4)
                {
                    int x = w + dx[i];
                    int y = h + dy[i];
                    if (1 <= x and x <= W and 1 <= y and y <= H and A[y][x] == '.')
                        isinside = false;
                }

                if (!isinside)
                {
                    Q.push(pos{w, h});
                }
            }
        }
    }

    int ans = 0;

    while (Q.size())
    {
        pos p = Q.front();
        Q.pop();

        REP0 (i, 4)
        {
            int x = p.x + dx[i];
            int y = p.y + dy[i];
            if (1 <= x and x <= W and 1 <= y and y <= H and A[y][x] == '.')
            {
                d[y][x] = d[p.y][p.x] + 1;
                A[y][x] = '#';
                Q.push(pos{x, y});
                ans = max(ans, d[y][x]);
            }
        }
    }

    std::cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


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

typedef long long int ll;
typedef long double ld;

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ln length()
#define M 1000000007

ll n,dp[200005][27],nxt[200005][27];
string s;
string ans;
void solve(ll st){
    if(st == n+1){
        ans+="a";
        return;
    }
    pll mi={(ll)1e15,(ll)1e15};
    rev(i,26,1) mi=min(mi,{dp[st][i],i});
    ans+=(mi.S-1+'a');
    if(mi.F == 1) return;
    solve(nxt[st][mi.S]+1);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>s;n=s.size();
    s="$"+s;
    rep(i,1,26) nxt[n][i]=n+1;
    nxt[n][s[n]-'a'+1]=n;
    rev(i,n-1,1){
        rep(j,1,26) nxt[i][j]=nxt[i+1][j];
        nxt[i][s[i]-'a'+1]=i;
    }
    rep(i,1,26) dp[n][i]=1;
    dp[n][s[n]-'a'+1]=2;
    rev(i,n-1,1){
        rep(j,1,26){
            if(nxt[i][j] == n+1) dp[i][j]=1;
            else if(nxt[i][j] == n) dp[i][j]=2;
            else{
                dp[i][j]=1e15;
                rep(k,1,26) dp[i][j]=min(dp[i][j],dp[nxt[i][j]+1][k]+1);
            }
        }
    }
    solve(1);
    cout<<ans<<'\n';
}


Measured memory_bytes: 84944
#include<bits/stdc++.h>                                                   //---------------------------------------------------------------
                                                                    
# define ll long long   
# define ld long double                                               
# define mod 1000000007                                                   
# define MAX 100005
# define pi 3.141592653589793238                                                                                  //shortcut keys
                                                                                
# define pb push_back                                                                     
# define mp make_pair 
# define all(x) x.begin(),x.end()                                                      
                                                                  
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------                                       
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s=="ARC")
	cout<<"ABC";
	else
	cout<<"ARC";
	return 0;
	

	
}

Measured memory_bytes: 3620
// package app;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

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

        int N = sc.nextInt();
        // int K = sc.nextInt();

        // int[] a = new int[N];
        List<Integer> a = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            // a[i] = sc.nextInt();
            // a.add(i);
            a.add(sc.nextInt() - 1);
        }

        boolean[] isTrace = new boolean[N];

        int currPos = 0;
        int cnt = 0;
        while(!isTrace[currPos]) {
            if (currPos == 1) break;
            isTrace[currPos] = true;
            currPos = a.get(currPos);
            cnt++;
        }

        System.out.println(currPos == 1 ? cnt : -1);

    }
}

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

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

const long long MOD = 1000000007;

int mpow(int x){
  if(x==0) return 1;
  if(x==1) return 10;
  int a=mpow(x/2);
  a = (a*a) % 13;
  if(x%2) a=(a*10) % 13;
  return a;
}

int main(){
  string s;
  cin >> s;
  int n=s.size();
  vector<vector<ll>> dp(n+1,vector<ll>(13,0));
  dp.at(0).at(0)=1;
  rep(i,n){
    rep(j,13){
      int d=n-i;
      int f=mpow(d-1);
      if(s.at(i)!='?'){
        dp.at(i+1).at((j+(s.at(i)-'0')*f)%13) += dp.at(i).at(j);
        dp.at(i+1).at((j+(s.at(i)-'0')*f)%13) %= MOD;
      }
      else{
        rep(k,10){
          dp.at(i+1).at((j+k*f)%13) += dp.at(i).at(j);
          dp.at(i+1).at((j+k*f)%13) %= MOD;
        }
      }
    }
  }
  cout << dp.at(n).at(5) << endl;
}


Measured memory_bytes: 13696
// *INDENT-OFF*
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef pair<int, int>pii;typedef pair<ll, int>pli;typedef pair<ll,ll>pll;typedef pair<double,double>pdd;typedef long double ld;
pll exgcd(const ll x,const ll y){if(!y)return{1,0};pll cur=exgcd(y,x%y);return {cur.second,cur.first-(x/y)*cur.second};}
template<typename T>ostream &operator<<(ostream &out,const vector<T>&vec){const int n=vec.size();out<<'[';for(int i=0;i<n;i++)out<<vec[i]<<(i==n-1?"":", ");out<<']';return out;}
template<typename T,typename U>ostream &operator<<(ostream&out,const pair<T,U>&p){out<<'<'<<p.first<<", "<<p.second<<'>';return out;}
const ll __mod__=998244353ll;ll mod(ll x,ll p=__mod__){return((x%p)+p)%p;}ll mmod(){return 1ll;}ll fpow(ll a,ll b,ll m){ll ans=1ll;for(a%=m;b;a=a*a%m,b>>=1)if(b&1)ans=ans*a%m;return ans;}
template<typename...U>ll mmod(const ll&hd,const U&...tl){return mod((hd%__mod__)*mmod(tl...),__mod__);}
void print(){cout<<"\n";}template<typename T,typename...U>void print(const T&hd,const U&...tl){cout<<hd<<(sizeof...(tl)?" ":"");print(tl...);}
inline ll fmul(ll a,ll b,ll m){ll d=(ll)floor(a*(ld)b/m+0.5);ll r=(a*b-d*m)%m;if(r<0)r+=m;return r;}void Main();
#ifdef ConanYu
void err(){cerr<<"\n";}template<typename T,typename...U>void err(const T&hd,const U&...tl){cerr<<hd<<(sizeof...(tl)?", ":"");err(tl...);}
#define debug(x...) {cerr<<""#x" = ";err(x);}
#else
#define debug(...) 0
#endif
#define SZ(o) (int(o.size()))
#define all(o) o.begin(), o.end()
int main() {
#ifdef ConanYu
  clock_t clock_start = clock();assert(freopen("test.txt", "r", stdin));
#else
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
  int T = 1;
  // cin >> T;
  while(T--) Main();
#ifdef ConanYu
  cerr << "time: " << ((clock() - clock_start) * 1.0 / CLOCKS_PER_SEC) << "\n";
#endif
  return 0; }
// *INDENT-ON*
// ********************************************************************************************************

void Main() {
  string s;
  cin >> s;
  for(int i = 0; i < 3; i++) {
    if(s[i] == s[i + 1]) {
      cout << "Bad\n";
      return;
    }
  }
  cout << "Good\n";
}


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

int main() {
	
	string a,b;
	int hit=0,blow=0;
	while(1){
		cin >> a >>b ;
		if(a[0]=='0' && b[0]=='0') break;
		for(int i=0;i<4;i++){
			if(a[i]==b[i]){
				hit++;
			}else{
				for(int j=0;j<4;j++){
					if(a[i]==b[j]){
						blow++;
					}
				}
			}
		}
		cout << hit << " " << blow << endl;
		hit=0;
		blow=0;
		
	}
	
	
	return 0;
}

Measured memory_bytes: 3000
#include <iostream>
#include <string>
using namespace std;
int main(){
  int i;
  while(cin>>i){
    if(i == 0) break;
    else{
  string w;
  int  dice[3]={1,2,3},jey[3]={1,2,3},ans=1;
  for(int j=0;j<i;j++){
    jey[0]=dice[0];
    jey[1]=dice[1];
    jey[2]=dice[2];
    cin>>w;
      if(w=="North"){
	dice[0]=jey[1];
	dice[1]=7-jey[0];
      } 
      if(w=="East"){
      dice[0]=7-jey[2];
      dice[2]=jey[0];
}
 if(w=="West"){
   dice[0]=jey[2];
   dice[2]=7-jey[0];
}
 if(w=="South"){
   dice[0]=7-jey[1];
   dice[1]=jey[0];
}
 if(w=="Right"){
   dice[1]=jey[2];
   dice[2]=7-jey[1];
}
 if(w=="Left"){
   dice[1]=7-jey[2];
   dice[2]=jey[1];
}
 ans+=dice[0];
  }
  cout<<ans<<endl;
    }}
  return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>

int main(){
  int w,h,n,x,y,a,g[100][100]={},cnt=0;
  scanf("%d %d %d",&w,&h,&n);
  for(int i=0;i<n;i++){
    scanf("%d %d %d",&x,&y,&a);
    if(a==1){
      for(int j=0;j<x;j++)
        for(int k=0;k<h;k++)
          g[j][k]=1;
    }
    if(a==2){
      for(int j=x;j<w;j++)
        for(int k=0;k<h;k++)
          g[j][k]=1;
    }
    if(a==3){
      for(int j=0;j<w;j++)
        for(int k=0;k<y;k++)
          g[j][k]=1;
    }
    if(a==4){
      for(int j=0;j<w;j++)
        for(int k=y;k<h;k++)
          g[j][k]=1;
    }
  }
  for(int i=0;i<w;i++)
    for(int j=0;j<h;j++)
      if(g[i][j]==0)
        cnt++;
  printf("%d\n",cnt);
}

Measured memory_bytes: 256
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, D, A = in.nextInt
  class Monster(val x: Long, var h: Long)
  val Monsters = Array.fill(N)(new Monster(in.nextLong, in.nextLong)).sortBy(_.x)
  val q = new scala.collection.mutable.Queue[(Long, Long)]

  def attack(i: Int, sum: Long, prevA: Long): Long = {
    if (i == N) sum
    else {
      val m = Monsters(i)
      def checkQ(cur: Long): Long = {
        q.headOption match {
          case None => cur
          case Some((x, a)) => 
            if (x < m.x) {
              q.dequeue
              checkQ(cur - a)
            } else cur
        }
      }
      val newA = checkQ(prevA)

      if (m.h <= newA) attack(i + 1, sum, newA)
      else {
        val attacks = (m.h - newA + A - 1) / A
        q += ((m.x + 2 * D, A * attacks))
        attack(i + 1, sum + attacks, newA + A * attacks)
      }
    }
  }

  println(attack(0, 0L, 0L))
}

Measured memory_bytes: 122832
# AOJ 0522: JOI and IOI
# Python3 2018.6.30 bal4u

import re

match = re.findall(r'[0-9]+', 'xxxx1aaaa22cc333ssss')
while True:
	try: s = input()
	except: break
	joi = ioi = 0
	for i in range(len(s)-2):
		if s[i+1] == 'O' and s[i+2] == 'I':
			if s[i] == 'J': joi += 1
			if s[i] == 'I': ioi += 1
	print(joi, ioi, sep='\n')


Measured memory_bytes: 6536
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    print(*A)
    for i in range(1, N):
        v = A[i]
        j = i-1
        while j>=0 and A[j]>v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(*A)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 6036