akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 



n = int(input())
#n,m = [int(i) for i in input().split()]
#ab = [[int(i) for i in input().split()] for _ in range(n-1)]

s = input()

ans = []

x = ord("A")
for i in s:
    c = ord(i) + n
    if c > ord("Z"): c -= 26
    ans.append(chr(c))

print("".join(ans))


Measured memory_bytes: 3060
def base_10_to_n(X, n):
    if (int(X/n)):
        return base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def f(a,A):
    if len(a) == 0:
        return 1e12
    return (len(a)-1)*10 + abs(sum(a)-A)

N,A,B,C = map(int,input().split())
l = [int(input()) for i in range(N)]

ans = 1e12
for i in range(4**N+1):
    tmp = list(base_10_to_n(i,4).zfill(N))
    a,b,c = [],[],[]
    for s,t in zip(tmp,l):
        if s == "1":
            a.append(t)
        elif s == "2":
            b.append(t)
        elif s == "3":
            c.append(t)
    ans = min(ans,f(a,A)+f(b,B)+f(c,C))

print(ans)
        

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

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int main() {
    long N; cin >> N;

    vector<long> v;
    REP(0, i, 5) {
        long tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    sort(v.begin(), v.end());

    cout << 5 + (N % v[0] == 0 ? N / v[0] - 1 : N / v[0]) << endl;

    return 0;
}


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

bool checkEven(char *s, int len) {
  if (len % 2 == 1) return false;
  for (int i = 0; i < len / 2; ++i) {
    if (s[i] != s[i + len / 2])
      return false;
  }
  return true;
}

int main(int argc, char**argv) {
  char s[201];
  scanf("%s", s);

  int len = strlen(s);
  for (int i = len - 1; i >= 2; --i) {
    s[i + 1] = 0;
    if (checkEven(s, i)) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl

#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define hell 1000000007

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 300009

ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
int main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
        
	string s,t;
	cin>>s>>t;
	if(s.length()>=t.length())
	{
		cout<<"No"<<endl;
	}
	if(s.length()!=(t.length()-1))
	{
		cout<<"No"<<endl;
		return 0;
	}
	rep(i,0,s.length())
	{
		if(s[i]!=t[i])
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
  int P,Q,R,a,b,c,d;
  cin>>P>>Q>>R;
  a=P+Q;
  b=Q+R;
  c=R+P;
  d=min({a,b,c});
  cout<<d<<endl;
}

Measured memory_bytes: 3604
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES

#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <iterator>
#include <bitset>
#include <complex>
#include <limits>
#include <random>
#include<fstream>
#include<array>


using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

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

	int N;
	cin >> N;

	vector<bool> A(N, false);

	int a, b;
	rep(i, 0, N)
	{
		cin >> a >> b;
		if (a == b)A[i] = true;
	}

	rep(i, 0, N)
	{
		int cnt = 0;
		rep(j, 0, 3)
		{
			if (i + j < N&&A[i + j])cnt++;
		}
		if (cnt == 3)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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;
}

int main(){

    int n;
    cin >> n;

    vector<ll> a(n+1);
    vector<ll> b(n);

    for(int i = 0; i < n+1; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    ll ans = 0;
    for(int i = 0; i < n; i++){
        ll tmp1, tmp2;
        tmp1 = min(a[i], b[i]);
        tmp2 = min(a[i+1], b[i] - tmp1);
        a[i+1] -= tmp2;
        ans += tmp1 + tmp2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

from collections import deque

if __name__ == '__main__':
    n = int(input())
    L = deque()

    for _ in range(n):
        command = input().split(" ")
        if command[0] == "insert":
            L.appendleft(command[1])
        elif command[0] == "delete":
            try:
                L.remove(command[1])
            except:
                pass
        elif command[0] == "deleteFirst":
            L.popleft()
        elif command[0] == "deleteLast":
            L.pop()

    print(" ".join(L))



Measured memory_bytes: 69744
N=int(input())

def SumOfDigits(n):
	ans=0
	while(True):
		if n==0:
			break
		ans+=n%10
		n=n//10
	return ans

ans=N
for a in range(N):
	if a!=0:
		b=N-a
		if ans>SumOfDigits(a)+SumOfDigits(b):
			ans=SumOfDigits(a)+SumOfDigits(b)
print(ans)


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

int main() {
  int n, q, temp;
  std::vector<int> S, T;
  
  std::cin >> n;
  for (auto i=0; i<n; ++i) {
    std::cin >> temp;
    S.emplace_back(temp);
  }
  std::cin >> q;
  for (auto i=0; i<q; ++i) {
    std::cin >> temp;
    T.emplace_back(temp);
  }
  
  int cnt = 0;
  
  for (auto &&e : T) {
    for (auto &&f : S) {
      if (e == f) {
        ++cnt;
        break;
      }
    }
  }
  std::cout << cnt << std::endl;
}


Measured memory_bytes: 3184
/*
	*	Created By: 'Present_Sir'
	*	Created On: Sunday 13 September 2020 05:37:57 PM IST
*/

#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) ((int)v.size())
#define lgt(s) ((int)s.length())
#define int long long
using namespace std;

class Solver{
    public:
        void test(){
            //int t; cin>>t; for(int i=1; i<=t; ++i)
            {
                //cout<<"Case #"<<i<<": ";
                this->solve();
            }
        }
        void solve(){
            int a,b;
            cin>>a>>b;

            int c,d;
            cin>>c>>d;

            int mx = a*c;
            mx = max(mx, a*d);
            mx = max(mx, b*c);
            mx = max(mx, b*d);
            if( (a<=0 and b>=0) or ( c<=0 and d>=0) ){
                mx = max(mx, 0LL);
            }
            cout<<mx<<endl;
        }
};


int32_t main(){
    IOS;
    Solver S;
    S.test();
    return 0;
}



Measured memory_bytes: 3652
/*
 * 2420.cc: Anipero 2012
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const int MAX_M = 50;
const int MAX_S = 8;

const int INF = 1 << 30;

/* typedef */

/* global variables */

int as[MAX_N], bs[MAX_N], cs[MAX_N];
int dp[MAX_N + 1][MAX_M + 1][MAX_S + 1];

/* subroutines */

/* main */

int main() {
  int n, m;
  cin >> n >> m;

  for (int i = 0; i < n; i++) cin >> as[i] >> bs[i] >> cs[i];

  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++)
      for (int k = 0; k <= MAX_S; k++) dp[i][j][k] = -INF;
  dp[0][m][0] = 0;

  for (int i = 0; i < n; i++)
    for (int j = 0; j <= m; j++)
      for (int k = 0; k <= MAX_S; k++) // Level 1
	if (dp[i][j][k] > -INF) {
	  int max_s = min(j, MAX_S);
	  for (int s = 0; s <= max_s; s++) { // Level 2
	    int maxd = -INF;
	    for (int an = 0; an <= s; an++) {
	      int max_bn = min(k, MAX_S - an);
	      for (int bn = 0; bn <= max_bn; bn++) {
		int d = (an == 0 && bn == 0) ? cs[i] : as[i] * an + bs[i] * bn;
		if (maxd < d) maxd = d;
	      }
	    }
	    maxd += dp[i][j][k];
	    if (dp[i + 1][j - s][s] < maxd) dp[i + 1][j - s][s] = maxd;
	    //printf("i=%d, maxd=%d\n", i, maxd);
	  }
	}
  
  int ans = -INF;
  for (int j = 0; j <= m; j++)
    for (int k = 0; k <= MAX_S; k++)
      if (ans < dp[n][j][k]) ans = dp[n][j][k];
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n, m;
	cin >> n;
	string s;
	vector<string> t;
	map<string, int> mp1, mp2;
	for (int i = 0; i < n; i++) {
		cin >> s;
		mp1[s]++;
		t.push_back(s);
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> s;
		mp2[s]++;
	}
	int mx = -1000000;
	for (int i = 0; i < t.size(); i++) {
		mx = max(mx, mp1[t[i]] - mp2[t[i]]);
	}
	cout << max(mx, 0) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#ifndef M_PI
#define M_PI 3.1415926535897932384626433832795
#endif
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#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()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

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

bool comp(pair<double,string> const&l,pair<double,string> const&r){
  if(l.F!=r.F)return l.F>r.F;
  return l.S<r.S;
}

main(){
  int n;
  while(cin>>n,n){
    vector<pair<double,string> > ans;

    rep(i,n){
      string l;
      int a,b,c,d,e,f,s,m,p;
      cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      ans.pb(mp(1.0*(f*m*s-p)/(a+b+c+(d+e)*m),l));
    }
    sort(ALL(ans),comp);
    rep(i,n)cout<<ans[i].S<<endl;
    cout<<'#'<<endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n) {
		par = vector<int>(n, -1);
	}
	int root(int x) {
		if (par[x] < 0) return x;
		else return root(par[x]);
	}
	int size(int x) {
		return -par[root(x)];
	}
	bool unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry) return false;
		if (size(rx) < size(ry)) swap(rx, ry);
		par[rx] += par[ry];
		par[ry] = rx;
		return true;
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	int count() {
		int res = 0;
		rep(i, par.size()) {
			if (par[i] < 0) res++;
		}
		return res;
	}
};
int main() {
	int n, m;
	cin >> n >> m;
	V p(n);
	rep(i, n) {
		cin >> p[i];
		p[i]--;
	}
	UnionFind G(n);
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		G.unite(a, b);
	}
	// 同じ連結成分にある頂点どうしは好きにいじることができる
	int ans = 0;
	rep(i, n) {
		if (G.same(p[i], i)) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 桁DPで範囲を絞る、0と9が例外
# 10桁からやってみる
K = ir()
dp = [[0] * 10 for _ in range(11)]
dp[0] = [1] * 10 # 0, 1-8, 9 1桁目
for i in range(1, 11):
    dp[i] = dp[i-1].copy()
    for j in range(10):
        if j > 0:
            dp[i][j] += dp[i-1][j-1]
        if j < 9:
            dp[i][j] += dp[i-1][j+1]

count = 0
for i in range(11):
    bl = False
    for j in range(1, 10):
        prev = count
        count += dp[i][j]
        if count >= K:
            start = (j, i, K-prev)
            bl = True
            break
    if bl:
        break

def dfs(i, last, num):
    global count, answer
    if i == 1:
        count -= 1
        if count == 0:
            print(num); exit()
    else:
        num *= 10
        if last == 0:
            dfs(i-1, 0, num + 0)
            dfs(i-1, 1, num + 1)
        elif last < 9:
            dfs(i-1, last-1, num + last - 1)
            dfs(i-1, last, num + last)
            dfs(i-1, last+1, num + last + 1)
        else:
            dfs(i-1, 8, num + 8)
            dfs(i-1, 9, num + 9)

answer = 0
head, digit, c = start
count = c
dfs(digit+1, head, head)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

int h,w;
char board[110][110];

int main(void){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>board[i][j];
        }
    }
    map<char,int>m;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            m[board[i][j]]++;
        }
    }
    if((h%2==0)&&(w%2==0)){
        for(auto itr=m.begin();itr!=m.end();++itr){
            int x=itr->second;
            if(x%4!=0){
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
    }
    else{
        if((w%2==1)&&(h%2==1)){
            int num=h*w-h-w+1;
            int c=0;
            for(auto itr=m.begin();itr!=m.end();++itr){
                int x=(itr->second)/4;
                c+=4*x;
                itr->second=(itr->second)-4*x;
            }
            if((h!=1&&w!=1)&&num!=c){
                cout<<"No"<<endl;
                return 0;
            }
            for(auto itr=m.begin();itr!=m.end();++itr){
                if(itr->second==0)continue;
                int x=(itr->second)/2;
                itr->second=(itr->second)-2*x;
            }
            int odd=0;
            for(auto itr=m.begin();itr!=m.end();++itr){
                if(itr->second==0)continue;
                if(itr->second==1)odd++;
            }
            if(odd==1)cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
        else{
            int num=0;
            if(h%2==0)num=h*w-h;
            else num=h*w-w;
            int c=0;
            for(auto itr=m.begin();itr!=m.end();++itr){
                int x=(itr->second)/4;
                itr->second=(itr->second)-4*x;
                c+=4*x;
            }
            if(((h!=1)&&(w!=1))&&num!=c){
                cout<<"No"<<endl;
                return 0;
            }
            for(auto itr=m.begin();itr!=m.end();++itr){
                if(itr->second==0)continue;
                int x=(itr->second)/2;
                itr->second=(itr->second)-2*x;
            }
            int odd=0;
            for(auto itr=m.begin();itr!=m.end();++itr){
                if(itr->second==0)continue;
                if(itr->second==1)odd++;
            }
            if(odd==0)cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n, b, f, r, v;
  int rooms[4][3][10];

  for(int i = 0; i < 4; i++){
	for(int j = 0; j < 3; j++){
	  for(int k = 0; k < 10; k++){
		rooms[i][j][k] = 0;
	  }
	}
  }

  scanf("%d", &n);
  for(int i = 0; i < n; i++){
	scanf("%d %d %d %d", &b, &f, &r, &v);
	rooms[b-1][f-1][r-1] += v;
  }

  for(int i = 0; i < 4; i++){
	for(int j = 0; j < 3; j++){
	  for(int k = 0; k < 10; k++){
		printf(" %d", rooms[i][j][k]);
	  }
	  printf("\n");
	}
	if(i != 3){printf("####################\n");}
  }

  return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int K, A, B;
    cin >> K >> A >> B;

    FOR(i,A,B+1) {
        if (i % K == 0) {
            print("OK");
            return 0;
        }
    }

    print("NG");
            return 0;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_a && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_a && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_a && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  int t=1;
  while(t--)
  {
      int n;
      cin>>n;
      vector<double> dp(n+1);
      //dp[i]=probability that there are i no of heads so far
      dp[0]=1;
      for(int toss=0;toss<n;toss++)
      {
          double ph;
          cin>>ph;
          for(int i=toss+1;i>=0;i--)
          {
              dp[i]=(i==0 ? 0:dp[i-1]*ph) + dp[i]*(1-ph);
          }
      }
      double ans=0.000;
      for(int i=0;i<=n;i++)
      {
          int tails=n-i;
          if(i>tails)
          ans+=dp[i];
      }
      cout<<fixed<<setprecision(12)<<ans;
  }  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef pair <int, int> PII;
typedef pair <int, PII> Node;
typedef priority_queue <Node, vector <Node>, greater <Node> > Queue;
const int inf = INT_MAX;

int main() {
    int n;
    while ( cin >> n && n ) {
        int D[2][101];
        for ( int i = 0; i < 2; ++ i ) {
            for ( int j = 0; j < n; ++ j ) {
                cin >> D[i][j];
            }
        }
        
        Queue Q;
        Node start1( 0, PII( 0, 0 ) );
        Node start2( 0, PII( 1, 0 ) );
        Q.push( start1 );
        Q.push( start2 );

        int MC[2][101];
        for ( int i = 0; i < 2; ++ i ) {
            for ( int j = 0; j < n; ++ j ) {
                MC[i][j] = inf;
            }
        }

        int answer = -1;
        while ( ! Q.empty() ) {
            Node node = Q.top();
            Q.pop();

            int d = node.first;
            int r = node.second.first;
            int c = node.second.second;
            while ( c + 1 < n && c + 1 >= 0 && D[r][c] == 1 && D[r][c + 1] == 1 ) {
                c ++;
            }

            if ( c >= n - 1 ) {
                answer = d;
                break;
            }

            for ( int i = 1; i <= 2; ++ i ) {
                int nd = d + 1;
                int nr = r == 0 ? 1 : 0;
                int nc = c + i;
                while ( nc + 1 < n && nc + 1 >= 0 && D[nr][nc] == 1 && D[nr][nc + 1] == 1 ) {
                    nc ++;
                }
                while ( nc < n && nc > 0 && D[nr][nc] == 2 ) {
                    nc --;
                }
                if ( nd >= MC[nr][nc] ) continue;
                MC[nr][nc] = nd;
                Node next( nd, PII( nr, nc ) );
                Q.push( next );
            }
        }

        if ( answer == -1 ) {
            cout << "NA" << endl;
        } else {
            cout << answer << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)
int main(){
    ll n;
    cin >> n;
    int fin=1;
    for(int i=(int)sqrt(n)+1; i>=1; i--){
        if(n%i==0) {fin= i; break;}
    }
    cout << (fin-1)+(n/fin-1) << endl;
}

Measured memory_bytes: 256
n = int(input())
p = [int(c) for c in input().split()]
ans = 0

def check(i):
	return p[i] < p[i+1] and p[i+1] < p[i+2] or p[i] > p[i+1] and p[i+1] > p[i+2]
for i in range(n-2):
	if check(i):ans+=1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
using namespace std;

int count(int* bit, int* mask);
int masksum(int* mask);
unsigned long decode(int* bit, int* mask);

int main(void){
  int n;
  cin>>n;
  int mask[n][64];
  int bit[64];
  for(int i=0;i<n;i++){
    for(int j=0;j<64;j++){
      mask[i][j]=0;
    }
  }
  for(int i=0;i<64;i++){
    bit[i]=0;
  }
  int k;
  int b;
  for(int i=0;i<n;i++){
    cin>>k;
    for(int j=0;j<k;j++){
      cin>>b;
      mask[i][b]=1;
    }
  }
  int q;
  cin>>q;
  int query,m;
  for(int i=0;i<q;i++){
    cin>>query>>m;
    if(query==0){
      cout<<bit[m]<<endl;
    }
    else if(query==1){
      for(int j=0;j<64;j++){
        if(mask[m][j]==1){
          bit[j]=1;
        }
      }
    }
    else if(query==2){
      for(int j=0;j<64;j++){
        if(mask[m][j]==1){
          bit[j]=0;
        }
      }
    }
    else if(query==3){
      for(int j=0;j<64;j++){
        if(mask[m][j]==1){
          bit[j]=1-bit[j];
        }
      }
    }
    else if(query==4){
      if(count(bit, mask[m])==masksum(mask[m])){
        cout<<1<<endl;
      }
      else{
        cout<<0<<endl;
      }
    }
    else if(query==5){
      if(count(bit, mask[m])>0){
        cout<<1<<endl;
      }
      else{
        cout<<0<<endl;
      }
    }
    else if(query==6){
      if(count(bit, mask[m])==0){
        cout<<1<<endl;
      }
      else{
        cout<<0<<endl;
      }
    }
    else if(query==7){
      cout<<count(bit,mask[m])<<endl;
    }
    else{
      cout<<decode(bit,mask[m])<<endl;
    }

  }
  return 0;
}

int count(int* bit, int* mask){
  int retval=0;
  for(int i=0;i<64;i++){
    if(mask[i]==1){
      retval+=bit[i];
    }
  }
  return retval;
}

int masksum(int* mask){
  int dummy[64];
  for(int i=0;i<64;i++){
    dummy[i]=1;
  }
  return count(mask, dummy);
}

unsigned long decode(int* bit, int* mask){
  unsigned long retval=0;
  for(int i=0;i<64;i++){
    if(mask[i]==1){
      retval+=((unsigned long)bit[i])*((unsigned long)pow(2,i));
    }
  }
  return retval;
}



Measured memory_bytes: 3252
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())

A = sorted(A)

if N % 2 == 0:
    c = N // 2 - 1
    print((sum(A[c+2:]) - sum(A[:c])) * 2 + (A[c+1] - A[c]))
else:
    c = (N - 1) // 2
    t = max(2*A[c+1] - A[c] - A[c-1], A[c+1] + A[c] - 2 * A[c-1])
    print(t + (-sum(A[:c-1]) + sum(A[c+2:])) * 2)


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

using namespace std;

int main() {
	int a, b;
	string op;
	vector<int> ans;
	while (cin >> a >> op >> b) {
		if (op == "+") {
			ans.push_back(a + b);
		}
		else if (op == "-") {
			ans.push_back(a - b);
		}
		else if (op == "*") {
			ans.push_back(a*b);
		}
		else if (op == "/") {
			ans.push_back(a / b);
		}
		else if (op == "?") {
			break;
		}
	}
	for (int i=0; i<ans.size(); i++) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3144
import fractions
import math
A,B = map(int,input().split())

g = fractions.gcd(A,B)
h = math.floor(math.sqrt(g))
D = {1:1}
for i in range(2,h+1):
    while g%i == 0:
        D[i] = D.get(i,0) + 1
        g //= i
    if g == 1:
        break
if g > 1:
    D[g] = D.get(g,0) + 1

print(len(D))

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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const double eps = 1e-9;
const int oo = 0x3f3f3f3f;
const int mod = 1000000007;

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

    string s; cin >> s;

    int64 k; cin >> k;

    int64 a = 0, b = 0, c = 0;

    char last = 0;

    for (auto x : s) {
        if (x == last){
            ++a;
            last = 0;
        } else {
            last = x;
        }
    }

    for (auto x : s) {
        if (x == last){
            ++b;
            last = 0;
        } else {
            last = x;
        }
    }

    for (auto x : s) {
        if (x == last){
            ++c;
            last = 0;
        } else {
            last = x;
        }
    }

    int64 answer = a;
    k--;

    answer += (k / 2) * (b + c);
    if (k & 1) answer += b;

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
typedef pair<int,int> P;
int nx[8]={-1,-1,0,1,1,1,0,-1};
int ny[8]={0,-1,-1,-1,0,1,1,1};

int main()
{
    int h,w;
    cin >> h >> w;
    vector <string> str(h);
    rep(i,h) cin >> str[i];
    vector <vector<int>> num(h,vector<int>(w,0));
    rep(i,h)rep(j,w){
        if(str[i][j]=='.') continue;
        else {
            num[i][j]=inf;
            int s=i; int t=j;
            int oi=s; int oj=t;
            for(int k=0;k<8;k++){
                s=oi+nx[k]; t=oj+ny[k];
                if(s<0||s>=h||t<0||t>=w) continue;
                num[s][t]++;
            }
        }
    }
    rep(i,h){
        rep(j,w){
            if(num[i][j]>=inf) cout <<'#';
            else cout << num[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main() {
    int r;
    cin >> r;
    
    cout << r * r * 3 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

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

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll a, b;
    cin >> a >> b;
    cout << min(string(a, b+'0'), string(b, a+'0')) << endl;

    return 0;
}

Measured memory_bytes: 256
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    std::string S;
    std::cin >> S;

    int d[4];

    for (int i = 0; i < 4; ++i) {
        d[i] = S[i] - '0';
    }

    for (uint64_t bit = 0; bit < (1 << 3); ++bit) {
        bool op1 = bit & (1 << 2);
        bool op2 = bit & (1 << 1);
        bool op3 = bit & (1 << 0);

        auto ans = d[0];
        ans = op1 ? ans + d[1] : ans - d[1];
        ans = op2 ? ans + d[2] : ans - d[2];
        ans = op3 ? ans + d[3] : ans - d[3];

        if (ans == 7) {
            std::cout << d[0] << (op1 ? '+':'-')
                      << d[1] << (op2 ? '+':'-')
                      << d[2] << (op3 ? '+':'-')
                      << d[3] << "=7" << std::endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 256
class Main {
    public static void main (String[] args) {
        int i, j;
        for (i = 1; i <= 9; i++) {
            for (j = 1; j <= 9; j++) {
                System.out.println(i + "x" + j + "=" + (i * j));
            }
        }
    }
}

Measured memory_bytes: 24012
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) {
        if (A[i] % 2 == 0) {
            if ((A[i] % 3 != 0) && (A[i] % 5 != 0)) {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;



const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c; cin >> a >> b >> c;
	if (a + b + c >= 22)cout << "bust" << endl;
	else cout << "win" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(std::string S){
    int n;
    if (S.size() % 2) n = S.size()/2 + 1;
    else n = S.size()/2;
    string s1 = S.substr(0, n);
    string s2 = S.substr(n);
    reverse(s2.begin(), s2.end());
    int count = 0;
    REP(i, S.size()/2)
        if (s1[i] != s2[i]) count++;
    cout << count << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

using namespace std;
int popcount(int bits) {
  return __builtin_popcount(bits);
}


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

  int n;
  cin >> n;
  vector<int> opens(n);
  for (auto &e : opens) {
    int o;
    for (int i = 0; i < 10; ++i) {
      cin >> o;
      e |= o << i;
    }
  }

  vector<vector<int>> prof(n, vector<int>(11, 0));
  for (auto &e : prof) {
    for (int i = 0; i < 11; ++i) {
      cin >> e[i];
    }
  }

  int ans = INT_MIN;
  for (int i = 1; i < 1024; ++i) {
    int score = 0;
    for (int j = 0; j < n; ++j) {
      score += prof[j][popcount(opens[j] & i)];
    }
    ans = max(ans, score);
  }
  cout << ans << "\n";
}


Measured memory_bytes: 256
#include <cstring>
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(){
    //freopen("data.in","r",stdin);
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define lint long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807

void solve()
{
  int A,B;
  cin>>A>>B;
  while(true)
  {
    if(B>A) swap(A,B);
    if(B == 0) break;
    A = A%B;
  }

  cout<<A<<endl;
    
    
  
  
  
  return;
}

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

  solve();

  return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main(){
    // Your code
    int H,W;
    cin >> H >> W;

    vector<vector<char>> v (H,vector<char>(W));

    for (int i=0;i<H;i++){
        for (int k=0;k<W;k++){
          cin >> v[i][k];
        }
    }

    for(int i=0;i<H;i++){
        for(int k=0;k<W;k++){

         if (v[i][k]=='#'){
             vector<int> v1={1,-1,0,0};
             vector<int> v2={0,0,1,-1}; 

            bool flag = true;
             for(int j=0;j<4;j++){
                 int x=i+v1[j];
                 int y=k+v2[j];

                if( x < 0 || H <= x) continue;
                if( y < 0 || W <= y) continue;

                if (v[x][y]=='#'){
                    flag = false;
                    
                }
            
             }
             if(flag){
                cout << "No" <<endl;
                return 0;
            } 
         }
            
        }
    }

    cout << "Yes" <<endl;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p.at(i);

    int count = 0;
    rep(i, n - 2) {
        vector<int> tmps = {p.at(i), p.at(i + 1), p.at(i + 2)};
        sort(tmps.begin(), tmps.end());
        if (p.at(i + 1) == tmps.at(1)) count++;
    }

    cout << count << endl;

    return 0;
}


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

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


Measured memory_bytes: 5148
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
#define coa cout << ans << endl
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;


int main(){
    int n;
    cin >> n;
    vector<int> buka(n, 0);
    // int buka[n];
    rep(i, n - 1){
        int tmp;
        cin >> tmp;
        tmp--;
        buka[tmp]++;
    }

    rep(i, n){
        cout << buka[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4012
#!python3.4
# -*- coding: utf-8 -*-
# abc154/abc154_d
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N,K = i2nn()
    q = [(1+int(s))/2 for s in i2s().split()]
    sum_pi = 0
    sum_k = sum(q[0:K])
    sum_k_max = sum_k
    for i in range(K, N):
        sum_k += q[i] - q[i - K]
        if sum_k_max < sum_k:
            sum_k_max = sum_k
    print(sum_k_max)
    return

main()


Measured memory_bytes: 23876
N = int(input())
A = [int(input()) for _ in range(N)]
count = 0

def insertion_sort(N, A, gap):
  for i in range(gap, N):
    value = A[i]  # 対象を取得する
    j = i - gap  # 一つ前の値を取得する
    while j >= 0 and A[j] > value:
      A[j+gap] = A[j]  # 一つずつ後ろにずらしていく
      j -= gap
      global count
      count += 1
    A[j+gap] = value  # 挿入する

def shell_sort(N, A):
  m = 0
  G = []
  num = 0
  # 3n+1(n = 0,1,2)の配列を作成する
  for i  in  range(0,N):
    num = num * 3 + 1
    if num > N:
      break
    G.append(num)
    m += 1
  G.reverse()

    
  for i in range(0, m):
    insertion_sort(N, A, G[i])
  print(str(m))
  print(' '.join(map(str, G)))
  print(str(count))
  for i in range(N):
    print(str(A[i]))

shell_sort(N, A)


Measured memory_bytes: 45524
#include <bits/stdc++.h>
#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()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;

const int MAX = 1e5;
struct edge{
    int v; // 次の頂点.
    int w; // 距離.
    edge(int v, int w) : v(v), w(w) {}
};

vector<edge> adj[MAX]; // 隣接リスト
bool visited[MAX];
int LD[MAX]; // 各頂点の高さ

// グラフを深さ優先探索する.
// @param c: グラフの探索開始頂点.
// @param d: グラフの探索開始頂点からの距離を保存.
// @return: 特に無し.
void dfs(int c, int d) {
    // 1. 訪問済みならば, 終了.
    if(visited[c]) return;

    // 2. 訪問済みフラグ設定.
    visited[c] = true;
    
    // 3. 未訪問の頂点であれば, 距離を更新.
    LD[c] = max(LD[c], d);
    for(auto &e : adj[c]) if(!visited[e.v]) dfs(e.v, d + e.w);

}

int main(){
    
    // 1. 入力情報取得.
    int N; // 頂点数
    scanf("%d", &N);
    for(int i = 0; i < N - 1; ++i){
        int s, t, w;
        // s : from, t : to, w : cost
        scanf("%d %d %d", &s, &t, &w);
        adj[s].emplace_back(t, w);
        adj[t].emplace_back(s, w);
    }
    memset(LD, 0, sizeof(LD));
    
    // 2. 頂点の次数が, 1 のものに対して, 木の高さを計算.
    for(int r = 0; r < N; r++){
        if(adj[r].size() == 1){
            memset(visited, 0, sizeof(visited));
            dfs(r, 0);
        }
    }
    
    // 3. 出力 ～ 後処理.
    for(int r = 0; r < N; r++){
        printf("%d\n", LD[r]);
    }
    return 0;
}





Measured memory_bytes: 6676
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>

#define log(x) cout << x << endl
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long lint;
using namespace std;

// <<fixed<<setprecision(6)<<

int gcd(lint x, lint y)
{
    return y == 0 ? x : gcd(y, x % y);
}

int main()
{
    string s, a, b;
    int l, l2;
    bool isyes = true;
    cin >> s;
    l = s.size();
    a = s.substr(0, (l - 1) / 2);
    b = s.substr(((l + 3) / 2) - 1);
    for (int i = 0; i < l / 2; i++)
    {
        if (s[i] != s[l - 1 - i])
        {
            isyes = false;
            break;
        }
    }

    if (isyes)
    {
        l = a.size();
        for (int i = 0; i < l / 2; i++)
        {
            if (a[i] != a[l - 1 - i])
            {
                isyes = false;
                break;
            }
        }
        for (int i = 0; i < l / 2; i++)
        {
            if (b[i] != b[l - 1 - i])
            {
                isyes = false;
                break;
            }
        }
    }
    if(isyes){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;

int dp[10000][10000];




int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  for (int i = n-1; i >= 0; i--) {
    if(s[n-1] == s[i]) dp[n-1][i] = 1;
  }
  for (int i = n-2; i >= 0; i--) {
    for (int j = n-1; j >= 0; j--) {
      dp[i][j] = (s[i] == s[j]) ? dp[i+1][j+1] + 1 : 0;
    }
  }
  int res = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      int now = min(dp[i][j], j-i);
      res = max(res, now);
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 196096