akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
vector<string> table(12);
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };

void dfs(int x, int y)
{
    table[y][x] = '0';
    for (int i = 0; i < 4; i++) {
        int px = x + dx[i];
        int py = y + dy[i];
        if (px < 0 || px >= 12 || py < 0 || py >= 12) continue;
        if (table[py][px] == '0') continue;
        dfs(px, py);
    }
}

int main()
{
    while (1) {
        int ans = 0;
        for (int i = 0; i < 12; i++) {
            cin >> table[i];
            if (cin.eof()) { return 0; }
        }
        for (int i = 0; i < 12; i++) {
            for (int j = 0; j < 12; j++) {
                if (table[i][j] == '0') continue;
                dfs(j, i);
                ans++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3056
#include <iostream>

using namespace std;

int main()
{
    int N,a,b;

  while(cin>>N)
  {
   a=N/10;
   b=N%10;
   if(a==9||b==9)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;
  }
   return 0;
}


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


void solve(long long N, std::string S){
  long long maxVal = 0;
  long long currVal = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'I') currVal++;
    else currVal--;
    maxVal = max(maxVal, currVal);
  }
  cout << maxVal << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
$K = <STDIN>;

my @dat = (1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51);
print "$dat[$K-1]";

Measured memory_bytes: 512
N = int(input())
H = [int(i) for i in input().split()]

dp = [0]*N
dp[1] = abs(H[1]-H[0])

for i in range(2,N):
    dp[i] = min(abs(H[i]-H[i-1])+dp[i-1],abs(H[i]-H[i-2])+dp[i-2])

print(dp[-1])


Measured memory_bytes: 13980
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
const int MOD = 1000000007;
using namespace std;

int main(void)
{
    int a, b, c;
    set<int> st;
    rep(i, 0, 3)
    {
        int tmp;
        cin >> tmp;
        st.insert(tmp);
    }
    cout << st.size() << endl;
}

Measured memory_bytes: 3568
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <queue>
#include <assert.h>

using namespace std;

template <typename T, typename Pr = less<T>>
class pqueue {
public:
	pqueue() : total_(T()) {}
	void   push(T x)     { total_ += x;             values_.push(x); }
	void   pop()         { total_ -= values_.top(); values_.pop(); }
	T      top()   const { return values_.top(); }
	bool   empty() const { return values_.empty(); }
	T      total() const { return total_; }
	T      size()  const { return (T)values_.size(); }
private:
	priority_queue<T, vector<T>, Pr> values_;
	T total_;
};


int main(int argc, char** argv) {
    int Q, qtype;

    cin >> Q;

	pqueue<long long, less<long long>> fst_half;
	pqueue<long long, greater<long long>> lst_half;
	long long a, b, b_sum = 0;

	for (int i = 0; i < Q; i++) {
		cin >> qtype;

		if (qtype == 1) {
			cin >> a >> b;

			if (fst_half.size() <= lst_half.size()) {
				fst_half.push(a);
			}
			else {
				lst_half.push(a);
			}

			// swap
			if (!fst_half.empty() && !lst_half.empty() &&  fst_half.top() > lst_half.top()) {
				fst_half.push(lst_half.top()); lst_half.pop();
				lst_half.push(fst_half.top()); fst_half.pop();
			}
			b_sum += b;
		}
		else {
			long long median = fst_half.top();
			long long sum = (fst_half.size() * median - fst_half.total()) + (lst_half.total() - lst_half.size() * median) + b_sum;
			cout << median << ' ' << sum << endl;
		}
	}
}

Measured memory_bytes: 3828
#include<stdio.h>

int main(){
  int n, i, j, m, k, v;
  int am[105][105];

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      am[i][j] = 0;
    }
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&m,&k);
    m--;
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v);
      v--;
      am[m][v] = 1;
    }
  }

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      if(j > 0) printf(" ");
      printf("%d",am[i][j]);
    }
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2140
N,M = map(int,input().split())
list = [list(map(int,input().split())) for _ in range(N)]
score = 0
ans = 0
for i in range(2**3):
    do = [0] * 3
    for j in range(N):
      if ((i >> j) & 1):
        do[j] = 1
    L = []
    for n in range(N):
      x = 0
      for k in range(3):
        if do[k] == 1:
          x += list[n][k]
        else:
          x -= list[n][k]
      L.append(x)
    L = sorted(L)[::-1]
    ans = max(ans,sum(L[:M]))
print(ans)

Measured memory_bytes: 3316
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define M 1010
#define N 1000000
#define D double
#define LL long long
#pragma GCC optimize(2)
using namespace std;
LL a[N],b[N],sum,n,x,y; 
int main()
{
	std::ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++) 
	{
		cin>>x>>y;
		a[i]=x+y;
		b[i]=x-y;
	}
	sort(a,a+n),sort(b,b+n);
    cout<<max((a[n-1]-a[0]),(b[n-1]-b[0]));
	return 0;
}
/*
*/


Measured memory_bytes: 6720
/************************************************
 # @Author:      miniLCT
 # @DateTime:    2019-12-22 20:17:32
 # @Description: You build it.You run it
 # @More: If lots of AC,try BF,dfs,DP
 ***********************************************/
#include <bits/stdc++.h>

using namespace std;
#define eps 1e-8
#define int  long long 
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
const int maxn = 1e6;
const int INF = 1e9;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
typedef long long ll;
ll mul(ll a,ll b) {
    ll ret=0;
    while(b) {
        if(b&1)
            ret=(ret+a);
        a=(a<<1);
        b=b>>1;
    }
    return ret;
}
ll quickPow(ll a,ll b) {
    ll ret=1;
    while(b) {
        if(b&1)
            ret=mul(ret,a);  //直接相乘的话可能会溢出
        a=mul(a,a);
        b=b>>1;
    }
    return ret;
}
int32_t main()
{
	close;
	ll n;
	cin >> n;
	if(n & 1){
		cout << 0 << endl;
		return 0;
	}
	else {
		int nn = n;
		int tmp = 0;
		while(nn != 0){
			tmp++;
			nn /= 5;
		}
		tmp--;
		int ans = 0;
		for(int i = 1; i <= tmp;i++){
			ans += n/(2*quickPow(5,i));
		}
		cout << ans <<endl;
	}
}
//1000000000000000000
//124999999999999995
//249999999999999770
//199999999999999980
// 75000000000000205
//100000000000000000


/******************************************************
 stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?), set tle
  * do smth instead of nothing and stay organized
*******************************************************/

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    h = list(map(int, input().split()))
    hills = [1] * n

    for _ in range(m):
        a, b = map(int, input().split())
        if h[a-1] > h[b-1]:
            hills[b-1] = 0
        elif h[a-1] < h[b-1]:
            hills[a-1] = 0
        elif h[a-1] == h[b-1]:
            hills[a - 1] = 0
            hills[b - 1] = 0
    print(sum(hills))

if __name__ == '__main__':
    main()


Measured memory_bytes: 20324
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    int n,a,b,A=0,B=0,C=0;
    cin >> n >> a >> b;
    vector<int> p(n);
    for(int i=0; i<n; i++){
        cin >> p[i];
        if(p[i]<=a)A++;
        else if(p[i]<=b)B++;
        else C++;
    }
    cout << min(A,min(B,C)) <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;
using ll = long long;

const ll inf = 1ll << 60ll;
vector<ll> tree[200005];

pair<ll, ll> far_node(ll k);
ll far_path(void);

ll n;
ll a, b;
ll path;

int main()
{

    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        cin >> a >> b;
        
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    path = far_path() + 1;

    cerr << path << endl;

    switch(path % 3) {
    case 0:
        puts("First");
        break;
    case 1:
        puts("First");
        break;
    case 2:
        puts("Second");
        break;
    }
}

pair<ll, ll> far_node(ll k)
{
    vector<ll> min_cost(200005, inf);
    queue<ll> que;

    ll far_node = k;
    ll max_cost = 0;

    que.push(k);
    min_cost[k] = 0;
    while (!que.empty()) {
        ll node = que.front();
        que.pop();

        for (int i = 0; i < tree[node].size(); i++) {
            ll nnode = tree[node][i];

            if (min_cost[nnode] > min_cost[node] + 1) {
                min_cost[nnode] = min_cost[node] + 1;
                que.push(nnode);
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        if (max_cost < min_cost[i]) {
            max_cost = min_cost[i];
            far_node = i;
        }
    }

    return pair<ll, ll>(far_node, max_cost);
}

ll far_path(void)
{
    ll s = far_node(1).first;

    return far_node(s).second;
}


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

int main() {

	int count, min, max, multiple, rem;
	
	count = 0;
	rem = 0;
	
	cin >> min >> max >> multiple;
	
	while (min <= max){
	
		rem = min % multiple;
	
		if(rem == 0)
			count ++;		
		min ++;
	}	
		
	
	cout << count << endl;
	
}

Measured memory_bytes: 3552
N=int(input())
A=[0]*N
for i in range(N):
    A[i]=int(input())
B   = [0]*N
B[0]= A[0] %2
ans= A[0]//2

for i in range(1,N):
    #print(i,A[i],B[i-1], (B[i-1]+A[i])//2 )
    pair= (B[i-1]+A[i])//2
    ans += pair
    if (A[i]+B[i-1]) %2==1 and A[i]!=0:
        B[i] = 1
    else:
        B[i] = 0

print(ans)


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

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse

int main(){
    int N;
    cin>>N;
    rep(c,N){
        string A,B;
        cin>>A>>B;
        int a=A.length();
        int b=B.length();
        vector<vector<int> >dp(a+1,vector<int>(b+1,0));

        //i,j時点での最長文字列を格納する
        //一致した文字があればそこでインクリメントする。(iの時)
        //以前に共通文字列がカウントされていればそれに合わさる形となる。前後関係も正しい(i+1の時)

        rep(i,a){
            rep(j,b){
                if(A[i]==B[j])dp[i+1][j+1]=max(dp[i][j]+1,dp[i+1][j+1]);
                dp[i+1][j+1]=max(dp[i+1][j],dp[i+1][j+1]);
                dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1]);
            }
        }
        cout<<dp[a][b]<<endl;
    }

    return 0;
}

//a=97,z=122


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

int main()
{
    char c;
    int line[2],centerLine,squareCount=0,diamondCount=0;
    while(cin>>line[0]>>c>>line[1]>>c>>centerLine){
        if(line[0]!=line[1]&&sqrt(line[0]*line[0]+line[1]*line[1])==centerLine){
            squareCount++;
        }
        if(line[0]==line[1]&&centerLine!=0){
            diamondCount++;
        }
    }
    cout<<squareCount<<endl<<diamondCount<<endl;
}

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

//data types
typedef long long ll;
typedef long li;
typedef int ii;
typedef float ff;
typedef double dd;
typedef long double pp;
typedef vector<int> vi;
typedef pair<int,int> pi;

//vector and pair components
#define f first
#define s second
#define push_back pb
#define make_pair mp

//loops
#define for1(x,v,m) for(x=v;x<=m;x++)
//#define rev(v,x,z) for(v=x;v>=z;v--)
//#define inf(m,j,k) for(m=j;m>=k;m++)

ii main()
{

    string s;
    
    cin>>s;
    
    
    if(s=="ABC")
    {
        cout<<"ARC"<<"\n";
    
    }
    else
    {
        
        cout<<"ABC"<<"\n";
        
    }
    
    
    
    
    
}


Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());
            var span = TimeSpan.FromSeconds(input);
            Console.WriteLine("{0}:{1}:{2}",
                span.Hours,
                span.Minutes,
                span.Seconds);
        }
    }
}

Measured memory_bytes: 5660
#include <bits/stdc++.h>
#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 rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define all(c) begin(c),end(c)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
 
 
 
 
int main() {
  int n,q;
  ll k;
  cin>>n>>k>>q;
  ll a[n],b[q];
  rep(i,n){
    a[i]=k-q;
  }
  
  rep(i,q){
    cin>>b[i];
  }
  for(int l=0;l<q;l++){
    a[b[l]-1]++;

  }


  rep(i,n){
    if(a[i]>0){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  

}




Measured memory_bytes: 2176
import sys
from collections import defaultdict, deque
import math

# import copy
# from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7

def divide(k):
    return pow(k, MOD-2, MOD)


def make_nck(n):
    ret = [1]
    for i in range(1, n+1):
        ret.append((ret[-1] * (n + 1 - i) * divide(i)) % MOD)

    # print(ret)
    return ret

def make_nigojyo(n):
    ret = [1]

    for i in range(1, n+1):
        ret.append((ret[-1] * 25) % MOD)

    # print(ret)
    return ret


def solve():
    nx = {"a": 0, "b": 1, "c": 2}

    cards = [getS() for i in range(3)]
    idxs = [0 for i in range(3)]
    cur = 0
    while True:
        try:
            # print(cur, idxs)
            nxt = nx[cards[cur][idxs[cur]]]
            idxs[cur] += 1
            cur = nxt
        except:
            print("ABC"[cur])
            return



def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 65500
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,t = LI()
    g = LIR(n)
    g = [i for (i,j) in g if j <= t]
    if not g:
        print("TLE")
    else:
        print(min(g))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38384
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        String N = sc.next();
        char[] n = N.toCharArray();
      
        for(int i = 0; i < n.length; i++){
          if(n[i] == '7'){
            System.out.println("Yes");
            return;
          }
        }
        System.out.println("No");
	}
}

Measured memory_bytes: 35600
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

//range maximum query
template<typename T>
struct segtree {
    T INF = 0;
    int n;
    vector<T> dat;
 
    void init(int n_) {
        n = 1;
        while (n < n_) {
            n *= 2;
        }
        dat.assign(2 * n - 1, INF);
    }
 
    void update(int k, T a) {
        k += n - 1;
        dat[k] = a;
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
 
    T basequery(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return INF;
        }
        if (a <= l && r <= b) {
            return dat[k];
        } else {
            T vl = basequery(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = basequery(a, b, k * 2 + 2, (l + r) / 2, r);
            return max(vl, vr);
        }
    }

    //[l, r)の範囲の最大値を返す
    T query(int l, int r) {
        return basequery(l, r, 0, 0, n);
    }
};

int main() {
    ll N;
    cin >> N;
    ll h[N], a[N];
    REP(i, 0, N) {
        cin >> h[i];
    }
    REP(i, 0, N) {
        cin >> a[i];
    }
    tlglglg data[N];
    REP(i, 0, N) {
        data[i] = tlglglg(h[i], i, a[i]);
    }
    sort(data, data + N);
    segtree<ll> seg;
    seg.init(N);
    REP(i, 0, N) {
        tlglglg t = data[i];
        ll ind = get<1>(t);
        seg.update(ind, seg.query(0, ind) + get<2>(t));
    }
    ll ans = seg.query(0, N);
    cout << ans << endl;
}


Measured memory_bytes: 12160
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tmp, _ := reader.ReadString('\n')
	tmp = strings.Trim(tmp, "\n")

	tmp2 := strings.Split(tmp, " ")
	n, _ := strconv.ParseInt(tmp2[0], 10, 64)
	d, _ := strconv.ParseInt(tmp2[1], 10, 64)

	r := n / (2*d + 1)
	c := n % (2*d + 1)
	if c > 0 {
		r = r + 1
	}
	fmt.Println(r)
}


Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#include <bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
pair<int,int> pre[1<<19];
ll dp[1<<19];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>a(1<<n);
    rep(i,1<<n){
        cin >> a[i];
    }
    for(int i = 1; i < (1<<n); i++){
        pre[i] = {i,0};
    }
    for(int i = 0; i < n; i++){
        for(int j = 0; j < (1<<n); j++){
            if(0 == (j & (1<<i))){
               vector<int>b = {pre[j].first,pre[j].second,pre[j|(1<<i)].first,pre[j|(1<<i)].second};
                sort(b.begin(),b.end(),[&](int x,int y){return a[x] > a[y];});
                b.erase(unique(b.begin(),b.end()),b.end());
                pre[j|(1<<i)] = {b[0],b[1]};
//                cerr << i << " " << j << " " << b[0] << " " << b[1] << endl;
            }
        }
    }
    for(int i = 1; i < (1<<n); i++){
        dp[i] = a[pre[i].first] + a[pre[i].second];
        dp[i] = max(dp[i],dp[i-1]);
        cout << dp[i] << "\n";
    }
}

Measured memory_bytes: 12288
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

using ll = long long;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A[i];
    A[i] -= (i + 1);
  }

  sort(A.begin(), A.end());
  
  ll med1 = A[N/2], med2 = A[N/2 + 1], med3 = A[N/2 - 1];
  ll result1 = 0, result2 = 0, result3 = 0;
  for (ll i = 0; i < N; ++i) {
    result1 += abs(A[i] - med1);
    result2 += abs(A[i] - med2);
    result3 += abs(A[i] - med3);
  }

  ll minimum = result1;
  if (minimum > result2) minimum = result2;
  if (minimum > result3) minimum = result3;
  cout << minimum << endl;

  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>

using namespace std;

int N;
int a[100010];
int main(){
    cin >> N;
    int cnt = 0;
    for(int i=1; i<=N; i++){
        int x;
        cin >> x;
        a[i] = x;
        if( i == a[x] ) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 640
local s=io.read()
local t={"A","G","C","T"}
local max=0
local len=0
for i=1,#s do
    local check=false
    for j=1,4 do
        if s:sub(i,i)==t[j] then
            check=true
        end
    end
    if check then
        len=len+1
    else
        len=0
    end
    max=math.max(max,len)
end
print(max)

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<string> s(10);
  s[0] = "pon";
  s[1] = "pon";
  s[2] = "hon";
  s[3] = "bon";
  s[4] = "hon";
  s[5] = "hon";
  s[6] = "pon";
  s[7] = "hon";
  s[8] = "pon";
  s[9] = "hon";
  cout << s[n%10] << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rangeRep(i, start, end) for(int i = (int)(start); i < (int)(end); i++)



int main() {
    ll n, cnt;
    cnt = 0;
    cin >> n;
    vector<vector<ll>> a(10, vector<ll>(10));


    rangeRep(i, 1, 10) {
        rangeRep(j, 1, 10) {
            ll tmp = 0;
            rangeRep(k, 1, n+1) {
                if (k % 10 == j &&
                    to_string(k).at(0) == to_string(i).at(0)) {
                    a[i][j]++;
                }
            }
        }
    }

    rangeRep(i, 1, 10){
        rangeRep(j , 1, 10){
            cnt += a[i][j] * a[j][i];
        }
    }

    cout << cnt << endl;

}


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

	for(int i=0;i<N-1;i++){
		for(int j=N-1;i<j;j--){
			if(A.at(j) > A.at(j-1)){
				int temp = A.at(j-1);
				A.at(j-1) = A.at(j);
				A.at(j) = temp;
			}
		}
	}

	int math=1;
	for(int i=0;i<N-1;i++){
		if(A.at(i) != A.at(i+1)){
			math++;
		}
	}
	cout << math<< endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
int n, k;
ll dp[200000];
ll a[200000];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
        dp[i] = 1e9;
    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (i > 0)
            dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), (i > 1 ? dp[i - 2] + abs(a[i] - a[i - 2]) : (int)(1e9)));
    }
    cout << dp[n - 1];
}


Measured memory_bytes: 1792
"""
すべての秒数の最小公倍数を求める
Gを最大公約数として持つX,Yの最小公倍数はG*X/G*Y/G
"""
def gcd(a,b):
    return a if b==0 else gcd(b,a%b)
N = int(input())
T = [int(input()) for _ in range(N)]
tmp = T[0]
for i in range(1,N):
    t = T[i]
    g = gcd(tmp,t)
    tmp = g*(tmp//g)*(t//g)
print(tmp)


Measured memory_bytes: 62592
#include <iostream>

using namespace std;

int N;

int main() {
	cin >> N;

	int* A = new int[N + 2];

	int sum = 0;
	A[0] = 0, A[N + 1] = 0;
	for (int i = 1; i < N + 1; i++) {
		cin >> A[i];
		sum += abs(A[i - 1] - A[i]);
	}
	sum += abs(A[N] - A[N + 1]);

	for (int i = 1; i < N + 1; i++) {
		cout << sum - abs(A[i - 1] - A[i]) - abs(A[i] - A[i + 1]) + abs(A[i - 1] - A[i + 1]) << endl;
	}

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

string words[] = {"eraser", "erase", "dreamer", "dream"};
string s;
int n;

int f(int i) {
    if (i == n) return 1;
    int r = 0;
    for (auto &p : words) {
        int m = p.size();
        if (s.substr(i, m) == p) {
            r = f(i+m);
            if (r) break;
        }
    }
    return r;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    cin >> s;
    n = s.size();
    if (f(0)) cout << "YES\n";
    else cout << "NO\n";
}


Measured memory_bytes: 2384
function main()
	s = chomp(readline())
	n = length(s)
	w = Array{Int}(n)
	if s[1] == 'W'
		w[1] = 1
	else
		w[1] = 0
	end
	for i in 2:n
		w[i] = w[i-1]
		if s[i] == 'W'
			w[i] += 1
		end
	end
	maxw = w[n]
	k = 0
	for i in 1:n
		if s[i] == 'B'
			k += maxw-w[i]
		end
	end
	print(k)
end

main()

Measured memory_bytes: 149672
import java.util.Scanner;

public class Main{
	public static void main(String args[]){


		Scanner sc = new Scanner(System.in);
		int intW = sc.nextInt();
		int intH = sc.nextInt();
		int intX = sc.nextInt();
		int intY = sc.nextInt();
		int intR = sc.nextInt();
		int intAns = 0;

		//????????´???????????????????????£????????¶??????????§???¢?????\??£????????????
		if(intX < 0){
			intAns = 1;
		}
		if(intY < 0){
			intAns = 1;
		}

		//?¨???????????????????????????????????¢????
		if(intX - intR < 0){
			intAns = 1;
		}
		if(intX + intR > intW){
			intAns = 1;
		}

		//?????????????????????????????????????¢????
		if(intY - intR < 0){
			intAns = 1;
		}
		if(intY + intR > intH){
			intAns = 1;
		}

		if(intAns == 1){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
	}
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int di[] = {0,-1,0,1};
int dj[] = {-1,0,1,0};

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    int h,w,n; cin >> h >> w >> n;
    int sr,sc; cin >> sr >> sc;
    string s,t;
    cin >> s >> t;

    map<char, int> ope = {
        {'L', 0},
        {'U', 1},
        {'R', 2},
        {'D', 3},
    };

    string ans = "YES";
    int ni,nj;
    rep(k,4){
        ni = sr-1, nj = sc-1;
        rep(i,n){
            int si = ope[s[i]];
            int ti = ope[t[i]];
            if(si == k){
                ni += di[si];
                nj += dj[si];
            }
            if(ni < 0 || h <= ni) ans = "NO";
            if(nj < 0 || w <= nj) ans = "NO";
            if(ti == (k+2)%4){
                if(ni + di[ti] < 0 || h <= ni + di[ti]) continue;
                if(nj + dj[ti] < 0 || w <= nj + dj[ti]) continue;
                ni += di[ti];
                nj += dj[ti];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4008
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int gcd(int x, int y)
{
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

int main()
{
  int N;
  cin >> N;
  int A[N];
  rep(i, N)
  {
    cin >> A[i];
  }

  int L[N + 2];
  int R[N + 2];

  repd(i, 0, N)
  {
    if (i == 0)
    {
      L[i] = A[i];
      continue;
    }
    L[i] = gcd(L[i - 1], A[i]);
  }

  repdm(i, N - 1, 0)
  {
    if (i == N - 1)
    {
      R[i] = A[i];
      continue;
    }
    R[i] = gcd(R[i + 1], A[i]);
  }

  int ans = 0;
  int d = 0;
  rep(i, N)
  {
    if (i == 0)
    {
      d = R[i + 1];
    }
    else if (i == N - 1)
    {
      d = L[i - 1];
    }
    else
    {
      d = gcd(L[i - 1], R[i + 1]);
    }
    if (ans < d)
      ans = d;
  }
  cout << ans;
}

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

const int maxn=100+10;
int n,a[maxn],ans;

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

Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

def init_kaijo(MAX, MOD):
    kaijo = [0] * MAX
    kaijo[0] = 1
    for i in range(1, len(kaijo)):
        kaijo[i] = kaijo[i-1] * i % MOD
    return kaijo
MOD = 10**9+7
kaijo = init_kaijo(500000, MOD)

def inv(x, MOD):
    return pow(x, MOD-2, MOD)

def nPk(n, k, MOD):
    return kaijo[n] * inv(kaijo[n-k], MOD) % MOD

def nCk(n, k, MOD):
    # log("{}C{} = {}".format(n,k,nPk(n,k, MOD) * inv(kaijo[k], MOD)))
    return nPk(n,k, MOD) * inv(kaijo[k], MOD)

h, w, a, b = get_nums_l()

ans = 0
for i in range(h-a):
    # (0,0)から(b-1, i)に到着するパターン数 * (b,i)から(W-1, H-1)に到着するパターン数
    # log(nCk(b+i-1, i, MOD), nCk(w-b+h-i-2, h-i-1, MOD))
    ans += nCk(b+i-1, i, MOD) * nCk(w-b+h-i-2, h-i-1, MOD) % MOD

print(ans % MOD)


Measured memory_bytes: 45800
import scala.io.StdIn.readInt

object Main extends App {

  val n = readInt
  val arr = Array.fill(n)(0)
  for (i <- 0 until n) {
    arr(i) = readInt
  }
  shellSort(arr, n)
  println(arr.mkString("\n"))

  def shellSort(arr: Array[Int], n: Int): Unit = {
    var cnt = 0
    val G = buildGArray(n)
    G.foreach(g => cnt += insertionSort(arr, n, g))
    println(G.length)
    println(G.mkString(" "))
    println(cnt)
  }

  def buildGArray(n: Int): Array[Int] = {
    var v = 1
    var arr = Array[Int](v)
    val increment = (v: Int) => {v * 3 + 1}
    v = increment(v)
    while (v < n) {
      arr = arr :+ v
      v = increment(v)
    }
    arr.reverse
  }

  def insertionSort(arr: Array[Int], n: Int, g: Int): Int = {
    var cnt = 0
    for (i <- g to n - 1) {
      val v = arr(i)
      var j = i - g
      while (j >= 0 && arr(j) > v) {
        arr(j + g) = arr(j)
        j = j - g
        cnt += 1
      }
      arr(j + g) = v
    }
    cnt
  }
}



Measured memory_bytes: 286680
#include <iostream>
#include <cstdio>
using namespace std;
string a;
int i,sum=0;
int main() 
{
    cin>>a;
    for(i=0;i<a.length();i++)
    {
        if(a[i]=='C'&&sum==0)
        sum++;
        else if(a[i]=='F'&&sum==1)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int get(int ,int);

int main(){
	int n, s = 0; cin >> n;
	while(n--){
		int a, k; cin >> a >> k;
		s ^= get(a, k);
	}
	if(!s) puts("Aoki");
	else puts("Takahashi");
	return 0;
}

int get(int a, int k){
	if(a < k) return 0;
	if(a % k == 0) return a / k;
	int m = a / k;
	return get(a - (a - m * (k - 1)) / (m + 1) * (m + 1), k);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string x;
  cin >> x;
 
if(x=="A"){          
    cout << "A" << endl;
}
  else if(x=="B"){          
    cout << "A" << endl;
  }
 else   if(x=="C"){          
    cout << "A" << endl;
 }
   else   if(x=="E"){          
    cout << "A" << endl;
   }
       else if(x=="F"){          
    cout << "A" << endl;
       }
        else  if(x=="G"){          
    cout << "A" << endl;
        }
          else  if(x=="H"){          
    cout << "A" << endl;
          }
  else  if(x=="I"){          
    cout << "A" << endl;
  }
              else  if(x=="J"){          
    cout << "A" << endl;
              }
  else  if(x=="K"){          
    cout << "A" << endl;
  }
  else  if(x=="L"){          
    cout << "A" << endl;
  }
  else  if(x=="M"){          
    cout << "A" << endl;
  }
  else  if(x=="N"){          
    cout << "A" << endl;
  }
  else  if(x=="O"){          
    cout << "A" << endl;
  }
  else  if(x=="P"){          
    cout << "A" << endl;
  }
  else  if(x=="Q"){          
    cout << "A" << endl;
  }
  else  if(x=="R"){          
    cout << "A" << endl;
  }
  else  if(x=="S"){          
    cout << "A" << endl;
  }
  else  if(x=="T"){          
    cout << "A" << endl;
  }
  else  if(x=="U"){          
    cout << "A" << endl;
  }
  else  if(x=="V"){          
    cout << "A" << endl;
  }
  else  if(x=="W"){          
    cout << "A" << endl;
  }
  else  if(x=="X"){          
    cout << "A" << endl;
  }
  else  if(x=="Y"){          
    cout << "A" << endl;
  }
  else  if(x=="Z"){          
    cout << "A" << endl;
  }
  else {cout <<"a"<<endl;
  }
}

Measured memory_bytes: 3608
using System;
using System.Linq;
 
class QQ
{
    static void Main()
    {
        var qq =
            from x in Enumerable.Range( 1, 9 )
            from y in Enumerable.Range( 1, 9 )
            select x + "x" + y + "=" + x * y;
        foreach( var item in qq )
            Console.WriteLine( item );
    }
}

Measured memory_bytes: 5812
#include<stdio.h>

int main()
{
  int i,j,n,count=0;
  int G[101][101],color[101],d[101],pi[101],mincost,ii;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&G[i][j]);
    }
  }
  for(i=0;i<n;i++){
    color[i]=0;
    pi[i]=-1;
    d[i]=2001;
  }
  d[0]=0;

  while(1){
    mincost=2001;
    for(i=0;i<n;i++){
      if(color[i]!=2 && d[i]<mincost){
        mincost=d[i];
        ii=i;
      }
    }
    if(mincost==2001)break;
    color[ii]=2;
    for(i=0;i<n;i++){
      if(G[ii][i]!=-1 && color[i]!=2 && G[ii][i]<d[i]){
	pi[i]=ii;
	d[i]=G[ii][i];
	color[i]=1;
      }
    }
  }
  for(i=0;i<n;i++){
    if(pi[i]!=-1)count+=G[i][pi[i]];
    }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 640
h, w = map(int, input().split())
f = ['.' * (w+2)]
for _ in range(h):
    f += ['.' + input() + '.']
f += ['.' * (w+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if not f[i][j] == '#':
            continue
        else:
            if f[i][j-1]=='#' or f[i-1][j]=='#' or f[i+1][j]=='#' or f[i][j+1]=='#':
                pass
            else:
                print('No')
                exit()

print('Yes')

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long ll;

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

int main() {

    ll X;
    cin >> X;
    ll out = 0;
    for(int i=1;i<=32;i++){
        for(int j=2;j<=10;j++){
            ll a = pow(i,j);
            if(a<=X && a>=out) out = a;
            else if(a>X) break;
        }
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31))



//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[600010];//適宜変える
	int id[100010];//適宜変える
}G;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}

G g;
ll s,t;
void readgraph(){
	//適宜変える
	ll n,m;
	scanf("%lld%lld",&n,&m);
	scanf("%lld%lld",&s,&t);
	s--;t--;
	rep(i,0,m){
		ll x,y,c;
		scanf("%lld%lld",&x,&y);
		x--,y--;
		g.e[2*i].s=x;
		g.e[2*i].g=y;
		g.e[2*i].c=1;
		g.e[2*i+1].s=y;
		g.e[2*i+1].g=x;
		g.e[2*i+1].c=1;
	}
	g.vcnt=n;
	g.ecnt=2*m;
	qsort(g.e,g.ecnt,sizeof(E),esort);
//	qsort(g.e,g.ecnt,sizeof(E),csort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}

ll daikusutorappp[1<<21];

//プラキュー（二分ヒープ）（優先度変更ありバージョン）
ll heapN,heap[1<<20],heapinv[1<<20];
int PQhikaku(int i,int j);//jの方が優先度が高いならtrueを返す
void PQchange(int n);
void heap_utod(int n){
	if(2*n>heapN)return;
	int rflag=(2*n+1<=heapN)&&(PQhikaku(2*n,2*n+1));
	if(PQhikaku(n,2*n+rflag)){
		ll temp=heap[2*n+rflag];
		heap[2*n+rflag]=heap[n];
		heap[n]=temp;
		heapinv[heap[n]]=n;
		heapinv[heap[2*n+rflag]]=2*n+rflag;	
		heap_utod(2*n+rflag);
	}
}
void heap_dtou(int n){
	if(n==1||PQhikaku(n,n/2))return;
	ll temp=heap[n];
	heap[n]=heap[n/2];
	heap[n/2]=temp;
	heapinv[heap[n]]=n;
	heapinv[heap[n/2]]=n/2;
	heap_dtou(n/2);
}
ll PQpop(){
	ll rr=heap[1];
	heapinv[heap[1]]=0;
	heap[1]=heap[heapN--];
	heapinv[heap[1]]=1;
	heap_utod(1);
	return rr;
}
void PQpush(ll n){
	heap[++heapN]=n;
	heapinv[heap[heapN]]=heapN;
	heap_dtou(heapN);
}
//この2つを変える
//ダイクストラ用
int PQhikaku(int i,int j){return daikusutorappp[heap[i]]>daikusutorappp[heap[j]];}//これをdaikusutora2の最後に書く
void PQchange(int n){if(heapinv[n])heap_dtou(heapinv[n]);}//必ず優先度を高く変更するので

//早い方のダイクストラ
//グラフと始点を引いて各点への最短距離・最短経路を返す
//プラキューが必要
//O((E+V)logV)
void daikusutora2(ll s){
	rep(i,0,g.vcnt)daikusutorappp[i]=i==s?0:INF;
	rep(i,0,g.vcnt)PQpush(i);
	while(heapN){
		ll mv=PQpop();
		for(ll t=g.id[mv];g.e[t].s==mv;t++){
			if(daikusutorappp[g.e[t].g]>daikusutorappp[mv]+g.e[t].c){
				daikusutorappp[g.e[t].g]=daikusutorappp[mv]+g.e[t].c;
				//daikusutorappp[n+g.e[t].g]=mv;//最短経路がいる場合はこれ
				PQchange(g.e[t].g);
			}
		}
	}
}

int a[100010];
int main(){
	readgraph();
	daikusutora2(s);
	rep(i,0,g.vcnt)if(daikusutorappp[i]!=INF)a[daikusutorappp[i]]++;
	ll len=daikusutorappp[t];
	daikusutora2(t);
	ll ans=0;
	rep(i,0,g.vcnt)if(daikusutorappp[i]<=len-2)ans+=a[len-2-daikusutorappp[i]];
	printf("%lld\n",ans);
}


Measured memory_bytes: 20356
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

map<char, int>mp{
    { 'M',0 },
    { 'A',1 },
    { 'R',2 },
    { 'C',3 },
    { 'H',4 },
};

bool isMARCH(char c) {
    return (c == 'M' || c == 'A' || c == 'R' || c == 'C' || c == 'H');
}

int bit(int x) {
    int cnt = 0;
    while (x != 0) {
        if (x & 1)cnt++;
        x /= 2;
    }
    return cnt;
}

int main() {
    int N;
    cin >> N;
    vector<long long>cnt(5, 0);
    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        if (isMARCH(S[0]))cnt[mp[S[0]]]++;
    }

    long long ans = 0;
    for (int i = 0; i < 1 << 5; i++) {
        if (bit(i) == 3) {
            long long x = 1;
            for (int j = 0; j < 5; j++)if((i & 1 << j))x *= cnt[j];
            ans += x;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
a = int(input())
l = list(map(int, input().split()))
cnt = 0
num = 1
if 1 in l:
  for i in range(a):
    if l[i] == num:
      num += 1
    else:
      cnt += 1
  print(cnt if cnt > 0 else 0)
else:
  print(-1)

Measured memory_bytes: 26140
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[200010];
    rep(i, N) cin >> a[i];
    deque<int> dq;
    rep(i, N) {
        if (N % 2 != i % 2) dq.push_front(a[i]);
        else dq.push_back(a[i]);
    }
    rep(i, N) {
        if (i != 0) cout << " ";
        cout << dq[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3840
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
		String[] list = s.split("");
      	list[5] = " ";
      	list[13] = " ";
      	for(int i=0; i<s.length(); i++) System.out.print(list[i]);
	}
}

Measured memory_bytes: 35408
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();
    if(a < b){
      if(b < c){
        System.out.println(a + " " + b + " " + c);
      }
      else if(a < c){
        System.out.println(a + " " + c + " " + b);
      }
      else{
        System.out.println(c + " " + a + " " + b);
      }
    }
    else{
      if(a < c){
        System.out.println(b + " " + a + " " + c);
      }
      else if(b < c){
        System.out.println(b + " " + c + " " + a);
      }
      else{
        System.out.println(c + " " + b + " " + a);
      }
    }
}
}

Measured memory_bytes: 26248
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  string s;
  while(cin >> s) {
    int state = 0;
    int J, O, I;
    int ans = 0;
    REP(i, s.size()) {
      if (s[i] == 'J') {
        if (state == 1) {
          J++;
        } else {
          state = 1;
          J = 1;
        }
      } else if (s[i] == 'O') {
        if (state == 1) {
          state = 2;
          O = 1;
        } else if (state == 2) {
          O++;
        } else state = 0;
      } else {
        if (state == 2) {
          state = 3;
          I = 1;
          if (J>=O&&I>=O)
            ans = max(ans, O);
        } else if (state == 3) {
          I++;
          if (J>=O&&I>=O)
            ans = max(ans, O);
        } else {
          state = 0;
        }
      }
      //cout << J << " " << O << " " << I << "  : " << state << endl;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1984
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d,e,f;
  while(cin>>a>>b>>c){
    if(a==-1)break;
    f=-c;e=-b;d=2-a;
    if(f<0)f+=60,e--;
    if(e<0)e+=60,d--;
    printf("%.2d:%.2d:%.2d\n",d,e,f);
    f*=3,e*=3,d*=3;if(f>59)e+=f/60,f%=60;
    if(e>59)d+=e/60,e%=60;
    printf("%.2d:%.2d:%.2d\n",d,e,f);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <bits/stdc++.h>
#include <iomanip>
#include <numeric>
#include <utility>
#include <map>
#include <algorithm>
using namespace std;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string str;
    cin >> str;
    for (int i = 0; i < str.length(); ++i)
    {
        if (str[i] == '?')
        {
            str[i] = 'D';
        }
    }
    cout << str << "\n";
}


Measured memory_bytes: 3712
#include<stdio.h>

void swap (int *, int *);
int partition (int * , int, int);
void quick_sort (int *, int , int );

int main(void){
    int n,i,k_len;
    scanf("%d",&n);
    int d[n];
    for(i=0; i <= n-1 ;i++){
    scanf("%d",&d[i]);
    }

    quick_sort(d,0,n-1);
    k_len = d[n/2 ] - d[n/2 - 1];

    printf("%d",k_len);
    return 0;


}


/* 値を入れ替える関数 */
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}



Measured memory_bytes: 2116
#include <cstdio>

using namespace std;

int main(void){
	int m, n, s, l, ans, i;
	while(1){
		scanf("%d",&l);
		if(l == 0){
			break;
		}
		s = ans = 0;
		for(i = 1;i <= 12;i++){
			scanf("%d%d",&m,&n);
			s += m - n;
			if(ans == 0 && s >= l){
				ans = i;
			}
		}
		if(ans != 0){
			printf("%d\n",ans);
		}else{
			printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1040