akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
int nxt[N][26];
int main() {
    string s, t;
    cin >> s >> t;
    int z[26];
    fill(z, z+26, -1);
    int n = s.length();
    for(int i = n-1; i >= 0; i--) {
        for(int j = 0; j < 26; j++) {
            nxt[i][j] = z[j];
        }
        z[s[i] - 'a'] = i;
    }
    ll ans = 0, j = -1;
    for(int i = 0; i < t.length(); i++) {
        if(j != -1) {
            j = nxt[j][t[i] - 'a'];
        }
        if(j == -1) {
            j = z[t[i] - 'a'];
            ans++;
            if(j == -1) {
                ans = -1;
                break;
            }
            continue;
        }
    }
    if(ans==-1) ans=-1;
    else {
        ans = (ans-1)*n+j+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
int64_t N, Z, W;
const int MAXN = 2010;
const int64_t INF = (1LL << 62);
vector<int64_t> A(MAXN);
vector<vector<int64_t>> DP(2, vector<int64_t>(MAXN, -1)); // turn/topの時の最大値

int64_t dfs(int64_t turn, int64_t top, int64_t x, int64_t y) // x: turn = 0, y: turn = 1
{
  if (top == N)
  {
    return abs(x - y);
  }
  if (DP[turn][top] != -1)
  {
    return DP[turn][top];
  }
  if (turn) // y
  {
    int64_t ret = INF;
    for (int i = top; i < N; i++) // i番目のカードまで取る
    {
      ret = min(ret, dfs(!turn, i + 1, x, A.at(i)));
    }
    return DP[turn][top] = ret;
  }
  else // x
  {
    int64_t ret = 0;
    for (int i = top; i < N; i++) // i番目のカードまで取る
    {
      ret = max(ret, dfs(!turn, i + 1, A.at(i), y));
    }
    return DP[turn][top] = ret;
  }
}

int main()
{
  cin >> N >> Z >> W;
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  cout << dfs(0, 0, Z, W) << endl;
}

Measured memory_bytes: 3828
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
#include <numeric>
#include <stdio.h>
#include<cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;



int main() {
  long long int n, a, b;
  cin >> n >> a >> b;
  long long int d;
  d = n / ( a + b);
  long long int e;
  e = n % ( a + b);
  long long int ans = 0;
  ans += d * a;
  ans += min(e,a);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
void swap(int *,int *);

int main(){
  int i,j,N;
  int k=0;
  int A[100];

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
}

  for(i=0;i<N-1;i++){
    for(j=N-1;j>i;j--){
      if(A[j]<A[j-1]){
	swap(&A[j],&A[j-1]);
	k++;
      }
    }
  }

  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i!=N-1){
      printf(" ");
    }
  }
  printf("\n%d\n",k);
  return 0;
}

void swap(int *x,int *y){
  int z;
  z=*x;
  *x=*y;
  *y=z;
}



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

using namespace std;

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

    string S;
    cin >> S;
    int n = S.size();
    reverse(begin(S), end(S));

    constexpr int MOD = 1'000'000'007;
    vector<vector<int>> dp(n + 1, vector<int>(13, 0));
    dp[0][0] = 1;
    for (int i = 0, mul = 1; i < n; ++i) {
        for (int j = 0; j < 13; ++j) {
            if (S[i] == '?') {
                for (int dig = 0; dig < 10; ++dig) {
                    int nj = (j + mul * dig) % 13;
                    dp[i + 1][nj] = (dp[i + 1][nj] + dp[i][j]) % MOD;
                }
            } else {
                int dig = S[i] - '0';
                int nj = (j + mul * dig) % 13;
                //cout << i << " " << j << " -> " << nj << " " << dig << endl;
                dp[i + 1][nj] = (dp[i + 1][nj] + dp[i][j]) % MOD;
            }
        }
        mul = mul * 10 % 13;
    }
    
    cout << dp[n][5] << "\n";

    return 0;
}

Measured memory_bytes: 8912
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int n;
    double t, a;
    cin >> n >> t >> a;

    vector<double> h(n);
    rep(i, n){
        cin >> h[i];
    }

    double at = (t - a) / 0.006;

    int ans = 0;
    for(int i = 1; i < n; i++){
        if(abs(at - h[ans]) > abs(at - h[i])){
            ans = i;
        }
    }
    cout << ans + 1 << endl;

    return 0;
}


Measured memory_bytes: 888
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n = int(input())
a = [int(i) for i in readline().split()]

from collections import deque

ans = deque()

x = 1
for i in a:
    if x: ans.append(i)
    else: ans.appendleft(i)
    x^=1

if x: print(*ans)
else: print(*(reversed(ans)))


Measured memory_bytes: 26032
# UF木 サイズ付
# 上位ノードほど @rank が大きい数字となる
class Node
  attr_accessor :parent, :rank, :size

  # 親は自分自身、ランクは 0 として初期化する
  def initialize(n)
    @parent = n
    @rank = 0
    @size = 1
  end
end

class UnionFind
  # 0 から n - 1 までのノードを初期化する
  def initialize(n)
    @nodes = (0...n).map { |i| Node.new(i) }
  end

  # 再帰で最も上位の親を探し、その値を返す（更新しないため少し遅い）
  def root(x)
    return x if @nodes[x].parent == x
    root(@nodes[x].parent)
  end

  # a と b を仲間にする
  def unite(a, b)
    a_root = root(a)
    b_root = root(b)
    # a 及び b の親が同じ場合は何もしない
    return if a_root == b_root

    # a親ランク < b親ランク の場合は、b親をa親の親とする
    # なお、ランクをいじる必要はなし
    if @nodes[a_root].rank < @nodes[b_root].rank
      @nodes[b_root].size += @nodes[a_root].size
      @nodes[a_root].parent = b_root
    # その他の場合は、a親をb親の親とする
    else
      @nodes[a_root].size += @nodes[b_root].size
      @nodes[b_root].parent = a_root
    # a親、及びb親のランクが同じ場合は、a親のランクを +1 する
      @nodes[a_root].rank += 1 if @nodes[a_root].rank == @nodes[b_root].rank
    end
  end

  # a と b の最も上位の親が同じかどうかを返す
  def same?(a, b)
    root(a) == root(b)
  end

  # 各ノードの親を全て出力する確認用
  def parents
    @nodes.map(&:parent)
  end
  
  # 属するUF木のサイズを返す
  def size(a)
    @nodes[root(a)].size
  end

  # 各ノードの最も上位の親を全て出力する確認用
  def roots
    @nodes.size.times.map { |i| root(i) }
  end
end

n, m, k = gets.split.map(&:to_i)
friends = Array.new(n + 1) { Array.new }
uf = UnionFind.new(n + 1)
m.times do
  a, b = gets.split.map(&:to_i)
  friends[a] << b
  friends[b] << a
  uf.unite(a, b)
end
blocks = Array.new(n + 1) { Array.new }
k.times do
  a, b = gets.split.map(&:to_i)
  blocks[a] << b
  blocks[b] << a
end

ans = []
1.upto(n) do |i|
  tmp = uf.size(i) - 1
  tmp -= friends[i].size
  blocks[i].each { |b| tmp -= 1 if uf.same?(i, b) }
  ans << tmp
end

puts ans.join(" ")


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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define RREP(i,a) for(int i = a;i >= 0;i--)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

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

    int x;
    cin >> x;
    cout << (x ? 0 : 1) << endl;
    return 0;
}

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

// warshall_floyd

const int INF = 1e9;
const int MAX_V = 200;
const int MAX_E = 20000;
const int MAX_R = 10;
int V, E, R;
int r[MAX_R + 10];
int d[MAX_V + 10][MAX_V + 10];

// O(V^3)
// 全対点最短経路
// 負の閉路が存在するかどうか
bool warshall_floyd (){
    for (int k = 1; k <= V; ++k)
        for (int i = 1; i <= V; ++i)
            for (int j = 1; j <= V; ++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    for (int i = 1; i <= V; ++i)
        for (int j = 1; j <= V; ++j) 
            if (d[i][j] < 0) return true;

    return false;
}

int main(){

    cin >> V >> E >> R;
    for (int i = 0; i < R; ++i){
        cin >> r[i];
    }
    for (int i = 1; i <= V; ++i){
        for (int j = 1; j <= V; ++j) {
            if (i == j) d[i][j] = 0;
            else d[i][j] = INF;
        }
    }
    for (int i = 0; i < E; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
    }

    warshall_floyd();

    int ans = INF;

    sort(r, r+R);
    do {
        int sum = 0;
        for (int i = 0; i < R - 1; ++i) sum += d[r[i+1]][r[i]];
        ans = min(ans, sum);
    }while(next_permutation(r, r+R));

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

Measured memory_bytes: 384
N,W = map (int,input().split()) 
dp = [[0 for i in range(W + 1)] for j in range(N+1)]
weight = []
value = []
for i in range(N):
    w,v = map( int, input().split() )
    weight.append(w)
    value.append(v)

for i in range(1,N+1):
    for j in range(0,W+1):
        if j - weight[i-1] >= 0:
            dp[i][j] = max( dp[i-1][ j - weight[i-1] ] + value[i-1], dp[i][j])
        dp[i][j] = max(dp[i][j],dp[i-1][j])
        
print(dp[N][W])


Measured memory_bytes: 171400
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m, x, y; cin >> n >> m >> x >> y;
	vector<int> xx(n), yy(m);
	for(int i = 0; i < n; i++) cin >> xx[i];
	for(int i = 0; i < m; i++) cin >> yy[i];
	xx.push_back(x); yy.push_back(y);
	sort(xx.begin(), xx.end()); sort(yy.begin(), yy.end());
	if(xx.back() < yy.front()) cout << "No War" << endl;
	else cout << "War" << endl;
	return 0;
}

Measured memory_bytes: 256
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
vector<int> vi[105];
int cost[105];
int main()
{
	int n,i,j,k,x,y,ans,curr,temp,m;
	int tc;
    cin >> n >> m >> x;
    for(i=1;i<=n;i++) {
        cin >> cost[i];
        for(j=1;j<=m;j++) {
            cin >> curr;
            vi[i].push_back(curr);
        }
    }
    int chaeng = 1e9;
    int maxi = 1 << n;
    for(i=0;i<maxi;i++) {
        curr = 0;
        int master[m+2];
        memset(master, 0, sizeof(master));
        for(j=0;j<n;j++) {
            if(i & (1 << j)) {
                curr += cost[j+1];
                for(k=0;k<m;k++) {
                    master[k] += vi[j+1][k];
                }
            }
        }
        int mini = 1e9;
        for(j=0;j<m;j++) {
            mini = min(mini, master[j]);
        }
        if(mini >= x) {
            chaeng = min(chaeng, curr);
        }
    }
    if(chaeng == 1e9) cout << "-1";
    else cout << chaeng;
    cout << endl;
	return 0;
}


Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define LOG1(x1,x2) cout << x1 << ": " << x2 << endl;
#define LOG2(x1,x2,y1,y2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << endl;
#define LOG3(x1,x2,y1,y2,z1,z2) cout << x1 << ": " << x2 << " , " << y1 << ": " << y2 << " , " << z1 << ": " << z2 << endl;
typedef long long ll;
typedef double db;
const int N = 1e5+100;
const int M = 1e5+100;
const db EPS = 1e-9;
using namespace std;

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

int main()
{
	scanf("%d",&n);
	rep(i,1,n+1) scanf("%d",&a[i]);
	rep(i,1,n) scanf("%d",&b[i]);
	ll ans = 0;
	rep(i,1,n){
		if(b[i] >= a[i]){
			ans += a[i]; b[i] -= a[i];
			ans += min(b[i],a[i+1]);
			a[i+1] -= min(b[i],a[i+1]);
		}
		else ans += b[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long ans = 0;
		for( int i=0; i<N; i++ ){
			ans += sc.nextLong()-1;
		}
		System.out.println(ans);
	}
}


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

int main(){
    int N, K;
    string S;
    cin >> N >> S >> K;
    for(int i = 0; i < N; i++){
        if(S[i] == S[K - 1])cout << S[i];
        else cout << "*";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 *    author:  milos
 *    created: 04.08.2020 22:46:46      
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false); 
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);      
  vector<int> b(n);
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  vector<vector<int>> dp(n, vector<int>(3, 0));
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  for (int i = 1; i < n; i++) {
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];   
    dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
  }
  cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << '\n';
  return 0;   
}

Measured memory_bytes: 9800
#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(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;

using qul = queue<ll>;

int main() {
    long double A, B;
    ll ans;
    cin >> A >> B;
    ans = A * B;
    cout << ans << endl;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lld long double
#define vc vector<ll>
typedef pair<ll,ll>pairs;
int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	ll t,n,i,j,k,l,c,f;
	cin>>n;
	vc a;
	string s="";
    char ch;
	//s+='a'+((n)%i-1);
	//l=log(n)/log(26);
	while(n>0)
	{
	    a.push_back(n%26);
	    n/=26;
	}
	n=a.size();
	i=n-1;
	while(i>=0)
	{
	    if(a[i-1]==0&&i>0)
	    {
	        a[i]--;
	        a[i-1]=26;
	    }
	    i--;
	}
	if(a[n-1]<=0)
	n--;
	i=0;
	while(i<n)
	{
	    if(a[i]<=0&&i<n-1)
	    {
	        a[i]+=26;
	        a[i+1]--;
	    }
	    if(a[i]!=0)
	    {
	        ch='a'+(a[i]-1);
	        s=ch+s;
	    }
	    i++;
	}
	cout<<s;
	return 0;
}


Measured memory_bytes: 3664
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, p: "List[int]"):
    counter = 0
    i = 0
    while i < N:
        if i+1 == p[i]:
            if i+1 < N and i+2 == p[i+1]:
                counter += 1
                i += 2
                continue
            else:
                counter += 1
                i += 1
                continue
        else:
            i += 1
            continue
    print(counter)

    return


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
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, p)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14008
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int H, W;
vector<string> field;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


int main() {
    cin >> H >> W;
    field.resize(H);
    rep(i,H) cin >> field[i];
    int ans = 0;
    int d[H][W];
    rep(si,H) {
        rep(sj,W) {
            if (field[si][sj]=='#') continue;
            rep(gi,H) {
                rep(gj,W) {
                    if (field[gi][gj]=='#') continue;
                    if (si==gi&&sj==gj) continue;
                    
                    queue<P> que;
                    rep(i,H)rep(j,W) d[i][j] = INF;
                    que.push(P(si,sj));
                    d[si][sj] = 0;
                    while(que.size()) {
                        P p = que.front(); que.pop();
                        if (p.fi == gi &&  p.se == gj) break;
                        rep(i,4) {
                            int nh = p.fi + dy[i];
                            int nw = p.se + dx[i];
                            if (nh < 0 || nh >= H || nw < 0 || nw >= W || field[nh][nw]=='#' || d[nh][nw] != INF) continue;
                            que.push(P(nh,nw));
                            d[nh][nw] = d[p.fi][p.se] + 1;
                        }
                    }
                if (d[gi][gj]!=INF) ans = max(ans, d[gi][gj]);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}






















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
void fastscan(int &x)
 {
        bool neg=false;
        register int c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    } 
string alpha = "abcdefghijklmnopqrstuvwxyz";
const int mod = 1e9+7;
const int inf = 2e18+5;
const int nax = 100010;
const int mod1 = 998244353;
   

signed main()
 {
int n;
  cin>>n;
  vector<int> v;
  loop(i,0,n)
   {
    int x;
    cin>>x;
    v.pb(x);
   }
   int dp[n];
   dp[n-2] =abs(v[n-2] - v[n-1]);
   dp[n-3] =abs(v[n-3] - v[n-1]);
   loopb(i,n-3,0)
    {
      dp[i-1] = min(dp[i]+abs(v[i]-v[i-1]),dp[i+1]+abs(v[i+1]-v[i-1]));
    }
    cout<<dp[0];
return 0;
}

Measured memory_bytes: 1908
#include <stdio.h>
#include <stdlib.h>

int H;
int arr[500002];
int tmp = 0;

void maxHeapify(int i){
    int l = 2*i;
    int r = 2*i+1;
    int largest;
    if(l <= H && arr[l] > arr[i]){
        largest = l;
    }
    else largest = i;
    if(r <= H && arr[r] > arr[largest]){
        largest = r;
    }
    if(largest != i){
        tmp = arr[i];
        arr[i] = arr[largest];
        arr[largest] = tmp;
        maxHeapify(largest);
    }
}

void buildMaxHeap(){
    int i;
    for(i=H/2; i>0; i--){
        maxHeapify(i);
    }
}

int main()
{
    scanf("%d", &H);
    for(int i=1; i<=H; i++){
        scanf("%d", &arr[i]);
    }
    buildMaxHeap();
    for(int i=1; i<=H; i++){
        printf(" %d", arr[i]);
    }
    printf("\n");

    return 0;
}



Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

int main(){
  int N;
  cin >> N;
  int a[N];
  rep(i,N) cin >> a[i];
  int mmax=0;
  int pmax=0;
  int mind, pind;
  rep(i,N){
    if(a[i]<0){
      if(mmax > a[i]){
	mmax=a[i];
	mind=i;
      }
    }
    else if(a[i]>0){
      if(pmax < a[i]){
	pmax=a[i];
	pind=i;
      }
    }    
  }
/*  rep1(i,N-1) {
    if(a[i-1] <= a[i]){
      //      cout << i;
      if(i==N-1){
	cout << 0 << endl;
	return 0;
      }
    }
    else {
      break;
    }
  }*/
  if(mmax==0 && pmax==0){
    cout << 0 << endl;
    return 0;
  }
  //cout << mmax << " " << pmax << endl;
  vector<pair<int, int> > ans;  
  if(abs(mmax) < abs(pmax)){
    rep(i,N){
      if(a[i] < 0){
	ans.pb(mp(pind,i));
	a[i]+=a[pind];
      }
    }
    rep1(i,N-1){
      if(a[i-1] > a[i] ){
	ans.pb(mp(i-1,i));
	a[i]+=a[i-1];
      }
    }
  }
  else{
    rep(i,N){
      if(a[i] > 0){
        ans.pb(mp(mind,i));
	a[i]+=a[mind];
      }
    }
    for(int i=N-1; i>0; i--){
      if(a[i-1] > a[i] ){
	ans.pb(mp(i,i-1));
	a[i-1]+=a[i];
      }
    }
  }
  cout << ans.size() << endl;  
  rep(i,ans.size()){
    cout << ans[i].first + 1 << " " << ans[i].second + 1 << " " << endl;
  }
  
  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  string S;
  cin>>N>>S;
  if(N%2==1){
    cout<<"No"<<endl;
    return 0;
  }
  bool f=true;
  REP(i,N/2){
    if(S[i]!=S[i+N/2])f=false;
  }
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}


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

int main(){
  string str;
  cin >> str;
  if(str.length() % 2 == 1){
    cout << "No" << endl;
    return 0;
  }
  for(int i=0; i<str.length(); i++){
    if(i % 2 == 0){
      if(str[i] != 'h'){
        cout << "No" << endl;
        return 0;
      }
    }else{
      if(str[i] != 'i'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,a[200005],m;long long tot;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		a[i]-=i;
	}
	sort(a+1,a+n+1);
	if(n%2) m=a[(n+1)/2];
	else m=(a[n/2]+a[n/2+1])/2; 
	for(int i=1;i<=n;++i)
		tot+=abs(a[i]-m);
	printf("%lld",tot);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  string a="ABC";
  string b="ARC";
  string s;
  cin >> s;
  if(s==a) cout << b << endl;
  else cout << a << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long int
#define ff first
#define pb push_back
#define ss second
#define ff first
#define mp make_pair

using namespace std;

vector<int> vec;

int ar[1000050];

map<int,int> has;


int main() 
{
    int n,m,t,p,q,r,s,a,b,c,d,e,f,g,h,sum,res,flag,u,v,i,j,l,k,z,x,y,len;
    
    string str,ptr;
    
    vector<int>::iterator it;
    
    cin>>str;
    
    len=str.length();
    
    for(i=0;i<len;i++)
    has[str[i]]++;
    
    for(i=97;i<=122;i++)
    {
       if(has[i]==0)
       {
       	  cout<<(char)i;
       	  return 0;
	   }
	}
	
	cout<<"None";
     
     
   
    return 0;
}


Measured memory_bytes: 512
import math

N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)


if N == 2:
    print(A[0])
else:
    ans = A[0]
    ind = 1
    num = 0
    for i in range(N-2):
        if num < 2:
            ans += A[ind]
            num += 1
        else:
            ind += 1
            ans += A[ind]
            num = 1
        
    print(ans)




Measured memory_bytes: 104236
n = int(input())

x = []
u = []

for i in range(n):
  money,label = input().split()
  x.append(float(money))
  u.append(label)

sum = 0

for i in range(n):
  if u[i] == "BTC":
    sum += (x[i]) * 380000
  else:
    sum += (x[i])
    
print(sum)


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

const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


int main(){
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> s(k);
    rep(i, k){
        cin >> s[i].first >> s[i].second;
    }
    vector<mint> dp(n);
    vector<mint> sum(n);
    sum[0] = 1;
    dp[0] = 1;
    rep(i, n){
        rep(j, k){
            if (i - s[j].first >= 0)
                dp[i] += sum[i - s[j].first];
            if (i - s[j].second - 1 >= 0)
                dp[i] -= sum[i - s[j].second - 1];
        }
        if (i) sum[i] += dp[i] + sum[i - 1];
    } 
    cout << dp[n - 1].x << endl;
}

Measured memory_bytes: 6348
N=int(input())
r=[tuple(map(int,input().split())) for i in range(N)]
b=[tuple(map(int,input().split())) for i in range(N)]
r.sort()
b.sort()
a=0
for i in b:
    t=(-1,-1)
    for j in r:
        if j[0]>i[0]:
            break
        if t[1]<j[1]<i[1]:
            t=j
    if t!=(-1,-1):
        r.remove(t)
        a+=1
print(a)

Measured memory_bytes: 38768
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {

  i64 H, W, K, i, j;
  cin >> H >> W >> K;
  vector<string> S(H);
  REP(0, H, i) {
    cin >> S[i];
  }

  vvi C(H+1, vi(W+1, 0));
  REP(0, H, i) {
    REP(0, W, j) {
      C[i+1][j+1] = C[i+1][j] + C[i][j+1] - C[i][j] + (S[i][j] - '0');
    }
  }

  auto cumsum = [&C](i64 l, i64 r, i64 t, i64 b) {
    return C[b][r] - C[t][r] - C[b][l] + C[t][l];
  };

  i64 ans = (W - 1) * (H - 1); // upper bound
  using ui64 = unsigned long long;
  ui64 B = 0;
  REP(0, (1ULL << (H-1)), B) {
    // segments
    vector<pi> segs;
    
    {
      pi cur(0, 0);
      REP(0, H-1, i) {
	if((B & (1LL << i)) != 0) {
	  cur.second = i + 1;
	  segs.pb(cur);
	  cur.first = i + 1;
	}
      }
      cur.second = H;
      segs.pb(cur);
    }

    // iterate over x
    bool valid = true;
    i64 cur_x = 0;
    i64 candidate = segs.size() - 1;
    // linear search
    // binary search could be better
    REP(0, W, i) {
      bool ok = true;
      for(auto seg: segs) {
	i64 S = cumsum(cur_x, i + 1, seg.first, seg.second);
	if(S > K) {
	  ok = false;
	  break;
	}
      }
      if(!ok) {
	// check whether it is possible to divide
	for(auto seg: segs) {
	  i64 S = cumsum(i, i + 1, seg.first, seg.second);
	  if(S > K) {
	    valid = false;
	    break;
	  }
	}
	if(!valid) {
	  break;
	}

	// divide
	cur_x = i;
	candidate++;
      }
    }
    if(valid) {
      ans = min(ans, candidate);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  int ans=0;
  for(int i=0;i<N;i++){
    if(A.at(i)>=K){
      ans++;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3732
import copy

N = int(input())
a = list(map(int,input().split()))
ans = "NO"
b = copy.deepcopy(a)
if b == sorted(a):
    ans = "YES"
else:
    for i in range(0, N-1):
        if ans == "YES":
            break
        for j in range(i, N):
            b = copy.deepcopy(a)
            temp = b[i]
            b[i] = b[j]
            b[j] = temp
            if b == sorted(a):
                ans = "YES"
                break
print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int MOD = 1000000007;
const ll INF = 1LL << 60;
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> vc(5);
  for (int i = 0; i < 5; i++)
  {
    cin >> vc[i];
    if (vc[i] == 0)
    {
      cout << i + 1 << endl;
    }
  }
}

Measured memory_bytes: 3584
#include<stdio.h>
#include<string.h>
int main() {
	int n, i, j=0, k=0;
	char a[100], b[100];
	scanf("%d", &n);
	for (i = 0;i < n;i++) {
		scanf("%s %s", a, b);
		if (strcmp(a, b) == 0) {
			j=j+1;
			k=k+1;
		}
		if (strcmp(a, b) > 0) {
			j = j + 3;
		}
		if (strcmp(a, b) < 0) {
			k = k + 3;
		}
	}
	printf("%d %d\n", j, k);
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
//ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
//ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}


int main(){

  int n,ans=0;
  cin >> n;
  
  vector<ll> dp(n+2,INF);
  dp[0] = -1;
  for (int i = 0; i < n; ++i){
    ll a;
    cin >> a;
    int ind = POSL(dp,a);
    dp[ind] = min(dp[ind],a);
    ans = max(ans,ind);
  }
  cout << ans << endl;
}



Measured memory_bytes: 3612
N, Q = map(int, input().split())
s = input()
td = [tuple(input().split()) for i in range(Q)]

def left_check(pos):
    nowpos = pos
    for t, d in td:
        if(d=="L" and t==s[nowpos]):
            nowpos -= 1
        elif(d=="R" and t==s[nowpos]):
            nowpos += 1
        if(nowpos == N):
            return False
        elif(nowpos == -1):
            return True
    return False

def right_check(pos):
    nowpos = pos
    for t, d in td:
        if(d=="L" and t==s[nowpos]):
            nowpos -= 1
        elif(d=="R" and t==s[nowpos]):
            nowpos += 1
        if(nowpos == N):
            return False
        elif(nowpos == -1):
            return True
    return True

def nibun(l, h, func):
    low = l
    high = h
    mid = (l+h)//2
    while low <= high:
        x = func(mid)
        if(x):
            low = mid+1
        else:
            high = mid-1
        mid = (low+high)//2
    return mid

print(nibun(0, N-1, right_check)-nibun(0, N-1, left_check))


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

int main(){
    int n; ll k;
    cin >> n >> k;
    ll k2 = k;
    vector<int> a(n); for(int i=0; i<n; ++i){cin >> a[i]; a[i]--;}
    vector<int> seen(n, 0);
    deque<int> que;
    ll now = 0;
    while(1){
        if(k==0){break;}
        if(seen[now]){break;}
        que.push_back(now);
        seen[now] = 1;
        now = a[now]; 
        k--;
    }

    if(k==0){cout << now + 1 << endl; return 0;}

    while(que[0]!=now){
        que.pop_front();
        k2--;
        if(k2==0){cout << que[0]+1 << endl; return 0;}
    }
    k2 %= que.size();
    cout << que[k2] + 1 << endl;
    return 0;
}

Measured memory_bytes: 5400
n = input()
S = [raw_input() for i in xrange(n)]
dic = {}
for i in xrange(n):
    for c in S[i]:
        dic.setdefault(c, [0]*n)[i] += 1
ans = ""
for k in sorted(dic.keys()):
    cnt = min(dic[k])
    ans += k*cnt
if ans:
    print ans

Measured memory_bytes: 2568
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];
		int answer = 0;

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			answer += a[i];
		}

		System.out.println(answer - N);
	}

}


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

int main(){
	
	int H, W;
	string S[50];
	
	cin >> H >> W;
	for( int i = 0; i < H; i++ ) cin >> S[i];
	
	const int dx[4] = { 1, 0, -1, 0 };
	const int dy[4] = { 0, 1, 0, -1 };
	bool can = true;
	
	for( int i = 0; i < H; i++ ){
		for( int j = 0; j < W; j++ ){
			bool flag = false; // S[i][j]の上下左右に少なくとも一つ#があるか
			if( S[i][j] == '#' ){
				for( int d = 0; d < 4; d++ ){
					const int nx = i + dx[d];
					const int ny = j + dy[d];
					if( nx >= H or nx < 0 ) continue;
					if( ny >= W or ny < 0 ) continue;				
					if( S[nx][ny] == '#' ){
						flag = true;
						break;
					}
				}
				if( ! flag ){
					can = false;
					break;
				}
			}
		}
		if( ! can ) break;
	}
		
	if( can ) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
	
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {

	solve();
    }

    static void solve(){
	int p = kbd.nextInt();
	for(int i=2; i>0; i--){
	    int pp = kbd.nextInt();
	    if(p>pp) p=pp;
	}

	int j = kbd.nextInt();
	int j2 = kbd.nextInt();
	if(j>j2) j=j2;


	System.out.println(j+p-50);
    }
}

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

int main(){
    int a,b,c;
    while(cin>>a>>b>>c,a||b||c){
        int n,parts[500],input[10000][4],bd;
        for(int i=0;i<500;i++) parts[i]=2;
        cin>>n;
        for(int _i=0;_i<n;_i++){
            for(int _j=0;_j<4;_j++){
                cin>>input[_i][_j];
            }
            if(input[_i][3]==1){
                for(int i=0;i<3;i++){
                    parts[input[_i][i]]=1;
                }
            }
            for(int i=0;i<=_i;i++){
                if(input[i][3]==1) continue;
                bd=-1;
                for(int j=0;j<3;j++){
                    if(parts[input[i][j]]==2 && bd==-1) bd=input[i][j];
                    else if(parts[input[i][j]]!=1){
                        bd=-1;
                        break;
                    }
                }
                if(bd!=-1) parts[bd]=0;
            }
        }
        for(int i=1;i<=a+b+c;i++){
            printf("%d\n",parts[i]);
        }
    }
    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 998244353;
const int INF = 1 << 30;

lint dp[3100][3100][3] = {};

int main() {
    int n, s;
    cin >> n >> s;
    vec a(n);
    rep(i, n) cin >> a[i];

    dp[0][0][0] = 1;

    rep(i, n) {
        int ni = i+1;
        for (int j = 0; j <= s; j++) {
            rep(k, 3) {
                dp[ni][j][k] += dp[i][j][k];
                dp[ni][j][k] %= MOD;
            }
        }

        for (int j = 0; j + a[i] <= s; j++) {
            rep(k, 2) {
                if (k == 0) {
                    dp[ni][j + a[i]][1] += dp[i][j][k] * (i+1);
                    dp[ni][j + a[i]][1] %= MOD;
                    dp[ni][j + a[i]][2] += (dp[i][j][k] * (n-i) * (i+1));
                    dp[ni][j + a[i]][2] %= MOD;
                }
                else {
                    dp[ni][j + a[i]][1] += dp[i][j][k];
                    dp[ni][j + a[i]][1] %= MOD;
                    dp[ni][j + a[i]][2] += (dp[i][j][k] * (n-i));
                    dp[ni][j + a[i]][2] %= MOD;
                }
            }
        }
    }

    cout << dp[n][s][2] << endl;
    return 0;
}

Measured memory_bytes: 219264
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
        int ans = Math.max(10 * a + b + c, Math.max(a + 10 * b + c, a + b + 10 * c));
        System.out.println(ans);
    }
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll H, W;
  IN(H,W);

  if(H==1 || W==1){
    OUT(1);
    return 0;
  }

  ll H1 = (H+1)/2;
  ll H2 = H/2;
  ll W1 = (W+1)/2;
  ll W2 = W/2;

  OUT(H1*W1+H2*W2);

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

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

typedef long long ll;

using namespace std;

int main() {
    string str; 
    cin >> str;
    rep(i, str.size()) {
        if(str[i] == str[i-1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

typedef  long long ll;
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;}

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

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n=0;
int x[15][15],y[15][15];
int a[20];
int count(int bit){
    if(bit==0){
        return 0;
    }
    return count(bit>>1) + (bit&1);
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        for(int j=1;j<=a[i];j++){
            cin>>x[i][j]>>y[i][j];
        }
    }
    int ans=0;
    for(int bit=1;bit<(1<<n);bit++){
    bool check = true;
        for(int i=1;i<=n;i++){
            if(!((bit&(1<<(i-1)))))continue;
            for(int j=1;j<=a[i];j++){
            if(((bit>>(x[i][j]-1))&1)^y[i][j])check = false;
            }
        }
        if(check)ans = max(ans,count(bit));
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M; cin >> N >> M;
  vector<vector<ll> > B(M+1, vector<ll>());
  REP(i, N){
    ll a, b; cin >> a >> b;
    if(a > M) continue;
    B[a].push_back(b);
  }
  priority_queue<ll> pq;
  ll ans = 0;
  for(ll i = 1; i <= M; i++){
    if(!B[i].empty()){
      for(auto j : B[i]){
        pq.push(j);
      }
    }
    if(!pq.empty()){
      ans += pq.top(); pq.pop();
    }
  }
  cout << ans << endl;
}

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

int main()
{
    int N;
    cin >> N;
    vector<long long> A(N);
    long long X = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        X ^= A[i];
    }
    X ^= (A[0] ^ A[1]);
    long long S = A[0] + A[1];
    long long D = (S - X) / 2;
    if (D < 0 || (D & X) != 0 || (D ^ 0) > A[0] || ((S + X) & 1) != 0)
        cout << -1 << endl;
    else
    {
        long long ans = D;
        for (long long i = 40; 0 <= i; i--)
        {
            if ((X >> i) & 1)
            {
                if ((ans | (1LL << i)) <= A[0])
                    ans |= (1LL << i);
            }
        }
        if (A[0] - ans >= 0 && ans > 0)
            cout << A[0] - ans << endl;
        else
            cout << -1 << endl;
    }
}

Measured memory_bytes: 3616
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = 12;

using namespace std;

int n, m;
string s[N];
bool used[N], was[N];

void check(vector < pair < int, int > > v) 
{
	for (int i = 0; i < (int)v.size(); i++)
	{
		if (v[i].first == v[i].second)
		{
			swap(v[i], v[(int)v.size() - 1]);
			break;
		}
	}
	vector < string > a;	
	for (int i = 0; i < (int)v.size(); i++)
	{
		a.pb(s[v[i].first]);
	}
	for (int i = (int)v.size() - 1; i >= 0; i--)
	{	
		if (v[i].first != v[i].second)
			a.pb(s[v[i].second]);
	}
	bool found = false;
	vector < string > b;
	for (int i = 0; i < m; i++)
	{
		string cur;
		for (int j = 0; j < n; j++)
			cur += a[j][i];
		b.pb(cur);		
	}
	fill(was, was + m, false);
	for (int i = 0; i < m; i++)
	{
		if (was[i])
			continue;
		reverse(all(b[i]));
		for (int j = i + 1; j < m; j++)
		{
			if (!was[j] && b[i] == b[j])
			{
				was[i] = was[j] = true;
				break;
			}
		}		
		reverse(all(b[i]));
		if (!was[i])
		{	
			if ((m & 1) && !found)
			{
				string t = b[i];
				reverse(all(t));
				if (b[i] == t)
				{
					found = true;
					was[i] = true;
				}
			}
		}
		if (!was[i])
		{
			return;
		}
	}
	cout << "YES" << endl;
	exit(0);
}

void rec(int id, bool found, vector < pair < int, int > > & v)
{
	if (id == n)
	{
		check(v);
		return;		
	}
	if (used[id])
	{
		rec(id + 1, found, v);	
		return;
	}
	if ((n & 1) && !found)
	{
		used[id] = true;
		v.pb({id, id});
		rec(id + 1, true, v);
		v.pop_back();
		used[id] = false;
	}
	for (int i = id + 1; i <= n; i++)
	{
		if (!used[i])
		{
			used[id] = used[i] = true;
			v.pb({id, i});
			rec(id + 1, found, v);
			used[id] = used[i] = false;
			v.pop_back();
		}
	}
	return;
}	 

int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie();
	//cout.tie();		

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		cin >> s[i];	
	//~solve
	vector < pair < int, int > > v;
	rec(0, false, v);
	cout << "NO" << endl;

	return 0;
}



Measured memory_bytes: 384
A=int(input())
B=int(input())
C=int(input())
X=int(input())
a=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500*i + 100*j +50*k ==X):
                a+=1
print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}

int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


int main(){
  int N,R;
  cin >> N >> R;
  int ans = R;
  if(N<10){
    ans += 100*(10-N);
  }

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




Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
int a[1000010],b[1000010];
int n,m;
int c,d;
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&c,&d);
        if(c==1)a[d]=1;
        if(d==n)b[c]=1;
    }
    for(int i=1;i<=m;i++)
        if(a[i]==1&&b[i]==1)
        {
            printf("POSSIBLE\n");
            return 0;
        }
    printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  if(a==23){
    cout<<"Christmas Eve Eve"<<'\n';
  }
  else if(a==25){
    cout<<"Christmas"<<'\n';
  }
  else if(a==24){
    cout<<"Christmas Eve"<<'\n';
  }
  else if(a==22){
    cout<<"Christmas Eve Eve Eve"<<'\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int64_t n,x;
    cin >> n>>x;
    vector<int64_t> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int64_t sum=0;
    for(int i=0;i<n-1;i++){
        if(a[i]+a[i+1]>x){
            sum += a[i]+a[i+1]-x;    
            if(a[i]>x){
                a[i] = x; 
            }
            a[i+1] = x-a[i];
        
        }
    }
    /*
    rep(i,n){
        cout<<a[i]<<" ";
    }
    cout<<endl;
    */
    cout<<sum<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		String s = sc.next();
		String key = "keyence";
		String tmp;
		boolean b = false;
		for (int i = 0; i < key.length() + 1; i++) {
			tmp = key.substring(0, i) + ".*" + key.substring(i, key.length());
			if (s.matches(tmp)) {
				b = true;
				break;
			}
		}
		if (b) {
			sb.append("YES");
		} else {
			sb.append("NO");
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 21844