akhauriyash/Code-Regression huggingface dataset:
n = input()
k = int(input())
n_len = len(n)
dp0 = [[0]*k for i in range(n_len)]
dp1 = [[0]*k for i in range(n_len)]
for i in range(k):
    if i == 0:
        dp0[0][i]=int(n[0])-1
        dp1[0][i]=1
    else:
        dp0[0][i]=0
        dp1[0][i]=0

for i in range(1,n_len):
    for j in range(k):
        if j == 0:
            dp0[i][j]=9 + dp0[i-1][0] + dp1[i-1][0]*min(1,int(n[i]))
            dp1[i][j]=dp1[i-1][0] if int(n[i]) == 0 else 0
        else:
            dp0[i][j]=dp0[i-1][j-1]*9 + dp1[i-1][j-1]*max(0,int(n[i])-1) + dp0[i-1][j] + dp1[i-1][j]*min(1,int(n[i]))
            dp1[i][j]=dp1[i-1][j-1] if int(n[i]) != 0 else dp1[i-1][j]
            
print(dp0[n_len-1][k-1]+dp1[n_len-1][k-1])

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = array[0], K = array[1];

            if (K == 1)
                Console.WriteLine(0);
            else
                Console.WriteLine(N - K);
        }
    }
}


Measured memory_bytes: 13268
N = int(input())
dic = dict()

for _ in range(N):
    s = input()
    if s not in dic:
        dic[s] = 1
    else:
        dic[s] += 1
maxlist = []
# sort_dic = sorted(dic.items(), key=lambda x: x[1], reverse=True)
maxv = max(dic.values())
for di, dv in dic.items():
    if dv == maxv:
        maxlist.append(di)

maxlist.sort()
print("\n".join(maxlist))


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

const int MAX_N = 100;

int main()
{
  int N, A[MAX_N], minj, cnt;
  cin >> N;
  REP(i, N) cin >> A[i];

  cnt = 0;
  REP(i, N) {
    minj = i;
    REP(j, N) {
      if (j < i) continue;
      if (A[j] < A[minj]) minj = j;
    }
    if (A[i] != A[minj]) {
      swap(A[i], A[minj]);
      cnt++;
    }
  }
  REP(i, N-1) cout << A[i] << ' ';
  cout << A[N-1] << endl;
  cout << cnt << endl;

  return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

vector<pair<int, int>> g[N];
map<pair<int, int>, int> edges;
vector<pair<int, int>> actualEdges;
int mama = -1;

void dfs(int u, int p = -1) {
  set<int> s;
  for (int i = 0; i < g[u].size(); ++i) {
    s.insert(i);
    mama = max(mama, i);
  }
  for (auto &pa: g[u]) {
    pa.second = edges[make_pair(u, pa.first)];
    s.erase(pa.second);
  }
  for (auto &pa: g[u]) {
    if (pa.first == p) continue;
    pa.second = *s.begin();
    s.erase(pa.second);
    edges[make_pair(pa.first, u)] = edges[make_pair(u, pa.first)] = pa.second;
    dfs(pa.first, u);
  }
}

void solve() {
  int n; scanf("%d", &n);
  for (int u, v, i = 0; i < n-1; ++i) {
    scanf("%d%d", &u, &v);
    g[--u].emplace_back(--v, n);
    g[v].emplace_back(u, n);
    edges[make_pair(v, u)] = edges[make_pair(u, v)] = n;
    actualEdges.emplace_back(u, v);
  }
  dfs(0);
  printf("%d\n", mama+1);
  for (const auto &e: actualEdges) {
    printf("%d\n", edges[e]+1);
  }
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 26152
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}


vector<int> argmin_subseq(const vector<int> &seq,const int K){
  vector<int> A=seq;
  const int mi=numeric_limits<int>::min();
  int N=A.size(),mx=mi,amx;
  assert(0<K && K<=N);
  vector<int> idx,nx;
  for(auto &I:A){I*=-1;}
  for(int i=0;i+K<=N;i++){mx=max(mx,A[i]);}
  for(auto &I:A){I-=mx;}
  for(int i=0;i+K<=N;i++){
    if(A[i]==0){A[i]++; idx.push_back(i);}
  }
  for(int len=1;len<K;){
    mx=mi;
    amx=-1;
    for(auto I:idx){
      if(mx<=A[I+len]){
        mx=A[I+len];
        amx=I;
      }
    }
    if(mx<=0){
      for(auto I:idx){
        if(A[I+len]==mx){A[I]++; nx.push_back(I);}
      }
      len++;
    }
    else{
      reverse(idx.begin(),idx.end());
      int ls=idx[0];
      if(ls+len+K>N){
        for(int j=0;j<mx && len+j<K;j++){
          if(seq[amx+len+j]>seq[ls+len+j]){return {ls};}
          else if(seq[amx+len+j]==seq[ls+len+j]){
            A[ls]++;
            if(amx+len==ls){mx++;}
          }
          else{break;}
        }
      }
      mx=mi;
      for(auto I:idx){
        A[I]+=max(0,min(A[I+len],K-len));
        mx=max(mx,A[I]);
      }
      reverse(idx.begin(),idx.end());
      for(auto I:idx){
        if(A[I]==mx){nx.push_back(I);}
      }
      len=mx;
    }
    idx.clear();
    swap(nx,idx);
  }
  return idx;
}

vector<int> argmin2(string s,int N){
  vector<int> ret;
  string mi=s.substr(0,N);
  for(int i=1;i<=N;i++){mi=min(mi,s.substr(i,N));}
  for(int i=0;i<=N;i++){
    if(mi==s.substr(i,N)){ret.push_back(i);}
  }
  return ret;
}

int main(){
  ll N,K;
  cin>>N>>K;
  string s;
  cin>>s;
  string t=s;
  reverse(t.begin(),t.end());
  s+=t;
  vector<int> A(s.size());
  for(int i=0;i<(int)s.size();i++){A[i]=(int)s[i];}
  vector<int> ret=argmin_subseq(A,N);
  vector<int> ret2=argmin2(s,N);
  assert(ret==ret2);
  int idx=ret[0];
  int cnt=0,c=0;
  for(int i=0;i<N;i++){
    if(A[idx]==A[idx+i]){cnt++;}
    else{break;}
  }
  c=cnt;
  while(K>1 && cnt<N){cnt*=2; K--;}
  string ans;
  for(int i=0;i<cnt && i<N;i++){ans+=s[idx];}
  for(int i=cnt;i<N;i++){ans+=s[idx+c+(i-cnt)];}
  cout<<ans<<endl;

  
  return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

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

using namespace std;

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

    string s;
    cin >> s;
    ll cnt = 0;
    for (char c : s) if (c == 'p') cnt++;
    cout << s.size()/2 - cnt << "\n"; 
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

int main() {
  ll N;cin>>N;
  string S;cin>>S;
  if (N%2==1) {
    OUT("No");
    return 0;
  }

  string before,after;
  REP(i,N/2) {
    before.push_back(S[i]);
    after.push_back(S[i+N/2]);
  }
  (before==after) ? OUT("Yes") : OUT("No");

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
int V[50],C[50];
int i=0,N,X=0;
cin>>N ;
for(i=0;i<N;i++){
cin>>V[i];

}
for(i=0;i<N;i++){
cin>>C[i];

}
for(i=0;i<N;i++){
if (C[i]<V[i]) {X+=V[i]-C[i];}

}
cout<<X ;
}


Measured memory_bytes: 256
import sys
# def input():
#     return sys.stdin.readline()[:-1]

# n = int(input())
# A = [input().split() for i in range(n)]

class Node():
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None


def insert(key):
    global root
    x = root # x is current node
    y = None  #  parent of x 
    while x:
        y = x # set parent
        if key < x.key:
            x = x.left # move to left child
        else:
            x = x.right #move to right child
    
    if root is None:
        root = Node(key)
    elif key < y.key: # set z as left child of y
        y.left = Node(key)
    else: 
        y.right = Node(key) # set z as right child of y
        

def inorder(inorder_list, node):
    if node.left is not None:
        inorder(inorder_list, node.left)
    inorder_list.append(str(node.key))
    if node.right is not None:
        inorder(inorder_list, node.right)
    return inorder_list
        
def preorder(preorder_list, node):
    preorder_list.append(str(node.key))
    if node.left is not None:
        preorder(preorder_list, node.left)
    if node.right is not None:
        preorder(preorder_list, node.right)
    return preorder_list
        
root = None

input()
for o in sys.stdin:
    if o[0]=='i':
        insert(int(o[7:]))
    else:
        x = root
        inorder_list = inorder([], x)
        print(' '+' '.join(inorder_list))
        preorder_list = preorder([], x)
        print(' '+' '.join(preorder_list))


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

int main(){
    int n,m; cin>>n>>m;
    vector<P> p(m);
    rep(i,m) cin>>p[i].first>>p[i].second;
    rep(x,1000){
        int nx=x/10;
        vector<int> d(1,x%10);
        while(nx){
            d.push_back(nx%10);
            nx/=10;
        }
        reverse(d.begin(),d.end());
        if(d.size()!=n) continue;
        bool ok=true;
        rep(i,m){
            if(d[p[i].first-1]!=p[i].second) ok=false;
        }
        if(ok){
            cout<<x<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


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

using namespace std;

int main(){
#ifdef ljn
  freopen("1.in","r",stdin);
  freopen("1.out","w",stdout);
#endif
  int a,b,c; cin>>a>>b>>c;
  if(a>b) swap(a,b);
  if(a>c) swap(a,c);
  if(b>c) swap(b,c);
  printf("%d\n",(b-a+1)/2+(b-a)%2+c-b);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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


	bool ok = false;
	if (n % 7 == 0) {
		ok = true;
	}
	else {
		while (n > 0) {
			if (n % 4 == 0) {
				ok = true;
				break;
			}
			n -= 7;
		}
	}

	cout << (ok ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n;

ll powmod(ll a, ll b) {
	a %= MOD;
	ll res = 1;
	while (b > 0) {
		if (b % 2 == 1)res = res * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return res;
}

ll f[210000];
void cominit() {
	f[0] = 1;
	REP(i, 200000)f[i + 1] = f[i] * (i + 1) % MOD;
}

ll com(ll n, ll r) {
	if (n < r)return 0;
	if (n < 0 or r < 0)return 0;
	return f[n] * powmod(f[r] * f[n - r], MOD - 2) % MOD;
}

ll perm(ll n, ll r) {
	if (n < r)return 0;
	if (n < 0 or r < 0)return 0;
	return f[n] * powmod(f[n - r], MOD - 2) % MOD;
}
int main() {
	cominit();
	cin >> n;
	vector<ll> s(n);
	REP(i, n)cin >> s[i];
	//REP(i, n - 1)cout << t[i] << " ";
	ll ans = 0, now = 0;
	REP(i, n - 1) {
		now *= i + 1;
		now %= MOD;
		now += f[i];
		now %= MOD;
		ans += (s[i + 1] - s[i]) % MOD * now % MOD * powmod(f[i + 1], MOD - 2) % MOD * f[n - 1] % MOD ;
		//cout << now << endl;
		ans %= MOD;
	}
	cout << ans << endl;
}



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

using namespace std;

int main()
{
  long long int n,k;
  cin>>n>>k;
  long long int sum=0;
  std::vector<long long int> v(n);
  for (int i = 0; i <n ; ++i)
  {
    cin>>v[i];
  }
  sort(v.begin(),v.end());
  for (int i = 0; i < n-k; ++i)
  {
    sum+=v[i];
  }
  cout<<sum<<'\n';
  
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
using namespace std;
typedef long long ll;
//定義場所//
int i, j, k, l, m, n;
int N, M, Q;

////////////

int main()
{
	int A, B;
	cin >> A >> B;
	if (A >= 13) {
		cout << B;
	}
	else if (A <= 5) {
		cout << 0;
	}
	else {
		cout << B / 2;
	}
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/04  Problem: ABC 098 A / Link: http://abc098.contest.atcoder.jp/tasks/abc098_a  ----- */


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

	LL A, B; cin >> A >> B;

	LL ans = max({A+B,A-B,A*B});
	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
using System;

public class Problem_C
{
  public static void Main()
  {
    var inputs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    int A = inputs[0], B = inputs[1], C = inputs[2], X = inputs[3], Y = inputs[4];

    var total = 0;
    if (2 * C < A + B)
    {
      var min = Math.Min(X, Y);
      total += (2 * C) * min;
      if (X - min > 0) total += Math.Min(2 * C * (X - min), A * (X - min));
      if (Y - min > 0) total += Math.Min(2 * C * (Y - min), B * (Y - min));
    }
    else
    {
      total += A * X;
      total += B * Y;
    }
    Console.WriteLine($"{total}");
  }
}


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

int main() {
  ll n;
  cin >> n;
  mat a(n,vec(n));
  for(ll i=0;i<n;i++) for(ll j=0;j<n;j++) cin >> a[i][j];
  vec dp(1<<n);
  for(ll S=0;S<(1<<n);S++) {
    for(ll i=0;i<n;i++) {
      for(ll j=0;j<i;j++) {
        if(S>>i&S>>j&1) dp[S]+=a[i][j];
      }
    }
    for(ll T=S;T>0;T=T-1&S) {
      if(T==S) continue;
      dp[S]=max(dp[S],dp[T]+dp[S^T]);
    }
  }
  cout << dp[(1<<n)-1] << endl;
}

Measured memory_bytes: 768
from math import factorial
MOD = 10**9+7
N,M = map(int,input().split())
ans = 0
if abs(N-M) > 1:
    pass
elif abs(N-M) ==1:
    ans = factorial(N)*factorial(M) % MOD
elif N==M:
    ans = 2*factorial(N)*factorial(M) % MOD

print(ans)

Measured memory_bytes: 5180
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;

	int up = y + r, down = y - r, right = x + r, left = x - r;

	if (h >= up && down >= 0 && w >= right && left >= 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    int a, b;
    cin >> a >> b;

    string u;
    cin >> u;

    if (s == u) {
        cout << a - 1 << " " << b << endl;
    }
    else {
        cout << a << " " << b - 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll  MOD = 1e9+7;

ll power(ll a,ll n){
  ll cnt = 0,ans = 1;
  while(n > 0){
    if(n == 1) {
      ans *= a;
      ans %= MOD;
      break;
    }
    ll key = 1,tmpM = a;
    while(key*2 <= n){
      cnt++;
      key *= 2;
      tmpM = tmpM*tmpM;
      tmpM %= MOD;
    }
    ans *= tmpM;
    ans %= MOD;
    n -= key;
  }
  return ans;
}

int main(){
  ll m,n;
  cin >> m >> n;
  cout << power(m,n) << endl;
}


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

# CODE FESTIVAL 2016 qual A
# Problem A

if __name__ == '__main__':
    original = 'CODEFESTIVAL2016'
    s = input()
    count = 0

    for si, original_s in zip(s, original):
        if si != original_s:
            count += 1

    print(count)


Measured memory_bytes: 2940
n = input()
op = [-1, 1]
op_c = ['-', '+']
for i in range(8):
  if int(n[0]) + op[i&1]*int(n[1]) + op[i>>1&1]*int(n[2]) + op[i>>2&1]*int(n[3]) == 7:
    print('{}{}{}{}{}{}{}=7'.format(n[0], op_c[i&1], n[1], op_c[i>>1&1], n[2], op_c[i>>2&1], n[3]))
    exit()

Measured memory_bytes: 3064
r, c = map(int, input().split())
t = [list(map(int, input().split())) for i in range(r)]
t.append([0]*c)
for i in t:
    i.append(sum(i))
for co in range(c+1):
    la = 0
    for ro in range(r):
        la += t[ro][co]
    t[r][co] = la
for l in t:
    print(*l)


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

int main() {
  int H, W;
  cin >> H >> W;
    
  for (int i=0; i<H+2; i++){
    vector<char> pic(W+2,'#');
    for (int j=0; j<W+2; j++){
      if (i==0 || i==H+1 || j==0 || j==W+1){
        cout << pic.at(j);
      }else{
        cin >> pic.at(j);
        cout << pic.at(j);
      }
    }
    cout << endl;
  }
  
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 2e3 + 10;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}

int a[maxn];

int main(void) {
    FAST_IO;
    
    int n;
    scanf("%d", &n);
    // vector<int> x;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    int cnt = 0;
    sort(a, a + n);

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int pos = upper_bound(a, a + n, a[i] + a[j] - 1) - a;
            cnt += pos - j - 1;
        }
    } 

    printf("%d\n", cnt);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  vs s(3);
  rep(i, 3) cin >> s[i];
  vi a(3, 0);
  ll i = 0;
  while(true) {
    if(a[i] == ll(s[i].size())) {
      cout << char(i + 'A') << endl;
      return 0;
    }
    ll ni = s[i][a[i]] - 'a';
    a[i]++;
    i = ni;
  }
}

Measured memory_bytes: 3620
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    long long K;
    cin >> K;
    vector<long long> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    ++K;
    long long mx = K;
    for (auto x : A) {
        mx = max(mx, x);
    }

    int h = 0;
    while (1LL << (h + 1) <= mx) {
        ++h;
    }

    vector<int> D(h + 1, 0);
    for (int i = 0; i <= h; ++i) {
        if (K & (1LL << i)) {
            D[i] = 1;
        }
    }


    const long long INF = 1LL << 62;
    vector<long long> dp(2, -INF);
    dp[0] = 0;
    auto ndp = dp;
    for (int i = h; i >= 0; --i) {
        int d = D[i];
        fill(ndp.begin(), ndp.end(), -INF);
        for (int j = 0; j < 2; ++j) {
            if (dp[j] < 0) {
                continue;
            }

            int l = 0, r = 1;
            if (j == 0) {
                r = d;
            }
            for (int x = l; x <= r; ++x) {
                int nj = j;
                if (x < d) {
                    nj = 1;
                }

                long long sum = 0;
                for (int k = 0; k < n; ++k) {
                    if (((A[k] >> i) & 1) ^ x) {
                        sum += 1LL << i;
                    }
                }

                ndp[nj] = max(ndp[nj], dp[j] + sum);
            }
        }
        swap(ndp, dp);
    }

    // cout << dp[0] << '\n';
    cout << dp[1] << '\n';


    return 0;
}

Measured memory_bytes: 1024
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

r = INT()
print(r**2)
    

Measured memory_bytes: 5400
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
	int len;
	char st[51];
	scanf("%s", st);
	for (len = 0; st[len] != 0; len++);
	st[len - 8] = 0;
	printf("%s\n", st);
}

Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 10000)
	sc.Buffer(buf, 1000000)
	nk, s := strings.Split(nextLine(), " "), nextLine()
	k, _ := strconv.Atoi(nk[1])

	// 連続する数を記録
	data := []int{}
	cnt := 0
	currNum := "1"
	hasLast := false
	for _, c := range strings.Split(s, "") {
		if c == currNum {
			cnt++
			hasLast = true
		} else {
			hasLast = false
			data = append(data, cnt)
			cnt = 1
			currNum = c
		}
	}
	if hasLast {
		data = append(data, cnt)
	}
	if len(data)%2 == 0 {
		data = append(data, 0)
	}
	solution := 0
	for i := 0; i < len(data); i += 2 {
		end := (i + (2*k + 1))
		if len(data) < end {
			end = len(data)
		}
		target := data[i:end]
		total := 0
		for _, v := range target {
			total += v
		}
		if solution < total {
			solution = total
		}
	}
	fmt.Println(solution)
}


Measured memory_bytes: 6400
package main

import "fmt"

func main() {
	var n, k, d, tmp int
	fmt.Scanf("%d %d", &n, &k)
	m := map[int]int{}
	for i := 0; i < k; i++ {
		fmt.Scan(&d)
		for j := 0; j < d; j++ {
			fmt.Scan(&tmp)
			_, exists := m[tmp]
			if exists {
				m[tmp]++
			} else {
				m[tmp] = 0
			}
		}
	}
	fmt.Println(n - len(m))
}


Measured memory_bytes: 2408
str = gets.split
N,M = str[0].to_i, str[1].to_i
a = [1,2,4,8,16,32,64,128,256,512,1024]

b = Array.new(M,0)
for x in 0...M
  str = gets.split
  for y in 1..str[0].to_i
    b[x] += a[str[y].to_i-1]
  end
end

c = 0
str = gets.split
for x in 0...M
  if str[x] == "1"
    c += a[x]
  end
end

answer = 0
d = 0
e = 0
for x in 0...a[N]
  d = 0
  for y in 0...M
    e = x&b[y]
    for z in 0...N
      if e&a[z] != 0
        d = d ^ a[y]
      end
    end
  end
  if d == c
    answer += 1
  end
end

puts answer

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

int main() {
	int a,b;
	while(scanf("%d",&a)!=EOF) {
		scanf("%d",&b);
		int total=a+b,ans=1;
		while((total/1)>=10) {
			total/=10;
			++ans;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
using namespace std;
long long  e[100002];
int main()
{
  long long a,b,c,d=0,i;
  cin>>a>>b>>c;
  for(i=1;i<=a;i++)
  {
  	 cin>>e[i];
  	 if(e[i]<b||e[i]>=c)
  	   d++;
  }
   cout<<d;
  cout<<endl;		
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
vector<int> par;
vector<int> sz;
int getpar(int u)
{
    if(par[u]==u) return u;
    else return par[u]=getpar(par[u]);
}
void merge(int u,int v)
{
    int u1=getpar(u);
    int v1=getpar(v);
    if(u1==v1) return;
    else 
    {
        if(sz[u1]>sz[v1]) swap(u1,v1);
        par[u1]=v1;
        sz[v1]+=sz[u1];
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    par.resize(n);
    sz.resize(n,1);
    iota(par.begin(),par.end(),0);
    while(m--)
    {
        int u,v;
        cin>>u>>v;
        u--;
        v--;
        merge(u,v);
    }
    vector<int> vis(n);
    int ans=0;
    for(int i=0;i<n;i++)
    {
       ans=max(ans,sz[getpar(i)]);
    }
    cout<<ans<<"\n";



}

Measured memory_bytes: 5632
A, B, C, D = map(int, input().split())
def gcd(a, b):
    if a < b:
        a, b = b, a
    a, b = b, a % b
    if b == 0 :
        return a
    else:
        return gcd(a, b)
cd = C * D //gcd(C, D)
print(B - B // C - B // D + B // cd - A + 1 + (A - 1) // C + (A - 1)// D - (A - 1)// cd)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int arr[200000] = {0};
    
    int a;
    cin >> a;
    
    for(int i = 0; i < a; i++){
        int tmp;
        cin >> tmp;
        arr[i] = tmp;
    }
    sort(arr,arr+a);
    
    for(int i = 0; i < a; i++){
        if(arr[i] == arr[i+1]){
            cout<<"NO";
            return 0;
        }
    }
    cout << "YES";
    

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	int a, b, c, d, e, f, A, B, C, D, E, F, SUM[2];

	cin >> a >> b >> c >> d >> e >> f;

	A = a * 1;
	B = b * 5;
	C = c * 10;
	D = d * 50;
	E = e * 100;
	F = f * 500;

	SUM[0] = A + B + C + D + E + F;
	SUM[1] = SUM[0] / 1000;

	if (SUM[1] > 0)
	{
		cout << "1" << endl;
	}
	else
	{
		cout << "0" << endl;
        }
      
}

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

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

    vector<pair<int, int>> up;
    vector<pair<int, int>> down;
    string S;
    int sum = 0;
    for (size_t i = 0; i < N; i++)
    {
        cin >> S;
        int current = 0;
        int minimum = 0;
        for (char s : S)
        {
            if (s == '(')
            {
                current++;
            }
            if (s == ')')
            {
                current--;
            }
            minimum = min(minimum, current);
        }
        sum += current;
        if (current < 0)
        {
            down.push_back(make_pair(minimum - current, -current));
        }
        else
        {
            up.push_back(make_pair(minimum, current));
        }
    }
    if (sum != 0)
    {
        cout << "No" << endl;
        return 0;
    }

    int current = 0;
    sort(up.rbegin(), up.rend());
    for (pair<int, int> p : up)
    {
        if (current + p.first < 0)
        {
            cout << "No" << endl;
            return 0;
        }
        current += p.second;
    }

    current = 0;
    sort(down.rbegin(), down.rend());
    for (pair<int, int> p : down)
    {
        if (current + p.first < 0)
        {
            cout << "No" << endl;
            return 0;
        }
        current += p.second;
    }

    cout << "Yes" << endl;
}


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

#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int main(){
	fastio
	ll n;
	cin >> n;
	vector<char> tmp;
	while(n!=0){
		n--;
		tmp.push_back((char)(n%26+'a'));
		//cout << n%26 << " ";
		n/=26;
	}
	reverse(tmp.begin(),tmp.end());
	for(auto x : tmp) cout << x;
}

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

int main(){
  double dis, dig, x=0, y=0, dig2=0;
  while(scanf("%lf,%lf", &dis, &dig), dis+dig){
    x += dis * sin(dig2 * M_PI/180.0);
    y += dis * cos(dig2 * M_PI/180.0);
    dig2 += dig;
  }
  printf("%d\n",(int)x);
  printf("%d\n",(int)y);
  return 0;
}

Measured memory_bytes: 628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final int k = scanner.nextInt();

        final List<Integer> list = IntStream.range(0, n)
            .mapToObj(i -> scanner.nextInt())
            .collect(Collectors.toList());

        final int sum = list.stream()
            .mapToInt(Integer::intValue)
            .sum();

        final List<Integer> divided = IntStream.rangeClosed(1, sum)
            .filter(i -> sum % i == 0)
            .boxed().collect(Collectors.toList());
        Collections.reverse(divided);
        for (final int value : divided) {
            final List<Integer> tmp = list.stream()
                .filter(i -> i%value != 0)
                .map(i -> i % value)
                .sorted()
                .collect(Collectors.toList());
            if (tmp.size() == 0) {
                System.out.println(value);
                return;
            }

            final int[] fromLeft = new int[tmp.size()];
            fromLeft[0] = tmp.get(0);
            for (int i = 1; i < tmp.size(); i++) {
                fromLeft[i] = fromLeft[i - 1] + tmp.get(i);
            }
            final int[] fromRight = new int[tmp.size()];
            fromRight[tmp.size() - 1] = value - tmp.get(tmp.size() - 1);
            for (int i = tmp.size() - 2; i >= 0; i--) {
                fromRight[i] = fromRight[i + 1] + value - tmp.get(i);
            }

            for (int i = 0; i < tmp.size() - 1; i++) {
                if (fromLeft[i] == fromRight[i + 1]) {
                    if (fromLeft[i] <= k) {
                        System.out.println(value);
                        return;
                    } else {
                        break;
                    }
                }
            }
        }
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}
    

Measured memory_bytes: 55892
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  r, D, x = map(int, readline().split())
  for _ in range(10):
    x = r*x -D
    print(x)
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;

  int ans = 1;
  FOR(i,1,n-1){
    if(s[i]!=s[i-1]) ++ans;
  }

  cout << ans << endl;

}



Measured memory_bytes: 512
from collections import deque
n, m = map(int, input().split())
w = [set() for _ in range(n + 1)]
for _ in range(m):
  u, v = map(int, input().split())
  w[u].add(v)
s, t = map(int, input().split())

memo = [[-1,-1,-1] for _ in range(n+1)]

d = deque()
d.append((s,0,0))
while d:
    i,q,r = d.popleft()
    for nx in w[i]:
        if nx ==t and r ==2:
            print((q+1)//3)
            exit()
        if memo[nx][(r+1)%3] == -1:
            memo[nx][(r+1)%3] = q+1
            d.append((nx,q+1,(r+1)%3))
print(-1)

Measured memory_bytes: 118988
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#define mid ((l+r)>>1)
using namespace std;
const int maxn=5e3+10;
int n,a[maxn],m;
char c[maxn];
int sa[maxn],height[maxn],rk[maxn],tax[maxn],tp[maxn];
void Rsort(){
    for(int i=0; i<=m; ++i) tax[i]=0;
    for(int i=1; i<=n; ++i) tax[rk[tp[i]]]++;
    for(int i=1; i<=m; ++i) tax[i]+=tax[i-1];
    for(int i=n; i>=1; --i) sa[tax[rk[tp[i]]]--]=tp[i];
}

bool cmp(int *f,int i,int j,int k){
    return f[i]==f[j]&&f[i+k]==f[j+k];
}

void get_s(){
    for(int i=1; i<=n; ++i) rk[i]=a[i], tp[i]=i;
    m=180;
    Rsort();
    for(int w=1; w<n; w<<=1){
        int num=0;
        for(int i=n-w+1; i<=n; ++i) tp[++num]=i;
        for(int i=1; i<=n; ++i) if(sa[i]>w) tp[++num]=sa[i]-w;
        Rsort();
        swap(rk,tp);
        rk[sa[1]]=num=1;
        for(int i=2; i<=n; ++i) rk[sa[i]]=cmp(tp,sa[i],sa[i-1],w)?num:++num;
        m=num;
    }
}

void get_h(){
    int k=0;
    for(int i=1; i<=n; ++i) rk[sa[i]]=i;
    for(int i=1; i<=n; ++i){
        if(rk[i]==1) continue;
        if(k) --k;
        int j=sa[rk[i]-1];
        while(i+k<=n && j+k<=n && a[i+k]==a[j+k]) ++k;
        height[rk[i]]=k;
    }
}

int solve(){
    int r=n, l=0, flag,ans;
    while(l<=r){
        int low=sa[1],high=sa[1];
        flag=0;
        for(int i=2; i<=n; ++i)
            if(height[i]<mid){low=sa[i]; high=sa[i];}
            else{
                low=min(low,sa[i]);
                high=max(high,sa[i]);
                if(high-low>=mid){flag=1;break;}
            }
        if(flag) ans=mid, l=mid+1;
        else r=mid-1;
    }
    return ans;
}

int main(){
    scanf("%d",&n);
    scanf("%s",c);
    for(int i=0; i<n; ++i) a[i+1]=c[i];
    get_s();
    get_h();
    cout<<solve()<<endl;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
long long MAX(long long a,long long b){return a<b?b:a;}
double PI=acos(-1);
double eps=1e-6;
double rad(double r){return r*PI/180.0;}
int main(){
  int n,j;
  long long x[110],y[110],m=0,sx,sy;
  double i;
  scanf("%d",&n);
  for(j=0;j<n;j++)scanf("%lld %lld",&x[j],&y[j]);
  for(i=0;i<360;i+=0.001){
    sx=sy=0;
    for(j=0;j<n;j++){
      if(cos(rad(i))*x[j]+sin(rad(i))*y[j]>eps){
	sx+=x[j];
	sy+=y[j];
      }
    }
    m=MAX(m,sx*sx+sy*sy);
  }
  printf("%.12lf\n",sqrt(m));
  return 0;
}
	
    


Measured memory_bytes: 384
package main

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

func solve() {
	ns := getIntSlice(4)

	ans := ""
	for i := 0; i < (1 << 3); i++ {
		str := strconv.Itoa(ns[0])
		sum := ns[0]
		for j := uint(0); j < 3; j++ {
			if i&(1<<j) >= 1 {
				str += "+" + strconv.Itoa(ns[j+1])
				sum += ns[j+1]
			} else {
				str += "-" + strconv.Itoa(ns[j+1])
				sum -= ns[j+1]
			}
		}

		if sum == 7 {
			str += "=7"
			ans = str
			break
		}
	}

	fmt.Fprintln(wr, ans)
}

// -----------------------------------------

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanRunes)
	solve()
	wr.Flush()
}

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

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


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

res = []
while n > 0:
    if n % 26 == 0:
        res.append('z')
        n = n // 26 - 1
    else:
        res.append(chr(n % 26 + ord('a') - 1))
        n //= 26

print(''.join(res[::-1]))

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


int main() {
    string S, T;
    cin >> S >> T;
    int find_index = -1;
    for(int i=S.size()-T.size(); i >=0; i--) {
        bool flag = true;
        rep(j, T.size()){
            if(S[i+j]!=T[j] && S[i+j]!='?'){
                flag = false;
                break;
            }
        }
        if(flag){
            find_index = i;                
            break;
        }
    }
    if (find_index==-1) cout << "UNRESTORABLE" << endl;
    else{
        rep(i, S.size()){
            if(find_index<=i && i<find_index+(int)T.size()) cout << T[i-find_index];
            else{
                if(S[i] == '?') cout << 'a';
                else cout << S[i];
            }
        }
        cout << endl;
    }
}


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

string solve( vector< string >& map )
{
	char row, col, rd, ld, comp;
	rd = map[ 0 ][ 0 ];
	ld = map[ 0 ][ 2 ];
	for( int i = 0; i < 3; ++i ){
		row = map[ 0 ][ i ];
		col = map[ i ][ 0 ];
		for( int j = 0; j < 3; ++j ){
			if( row != map[ j ][ i ] ){
				row = 0;
			}
			if( col != map[ i ][ j ] ){
				col = 0;
			}
		}
		comp = row | col;
		if( comp && comp != '+' ){
			return string( 1, row | col );
		}
		if( rd != map[ i ][ i ] ){
			rd = 0;
		}
		if( ld != map[ i ][ 2 - i ] ){
			ld = 0;
		}
	}

	comp = rd | ld;

	return ( comp && comp != '+' ) ? string( 1, comp ) : "NA";
}

int main()
{
	string s;
	while( cin >> s && s != "0" ){
		vector< string > map;
		map.push_back( s );
		for( int i = 0; i < 2; ++i ){
			cin >> s;
			map.push_back( s );
		}
		cout << solve( map ) << endl;
	}

	return 0;
}

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


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

int main() {
  int k; cin >> k;
  int ans = 0;
  for (int h=1; h<=k; ++h) {
    for (int i=1; i<=k; ++i) {
      for (int j=1; j<=k; ++j) {
        ans += gcd(h, gcd(i,j));
      }
    }              
  }
  cout << ans << endl;
                
  return 0;
} 



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	sort(s.begin(),s.end());
	if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2])
	{
		cout<<"Yes"<<endl;
	}
	else
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();

		ArrayList<Integer>V = new ArrayList<>();
		for(int i=0; i<N; i++) {
			V.add(sc.nextInt());
		}

		int CNT = Math.min(N, K);

		int ans = 0;
		for(int A=0; A<=CNT; A++) {
			ArrayList<Integer> al = new ArrayList<>();
			int asum = 0;
			for(int i=0; i<A; i++) {
				al.add(V.get(i));
				asum += V.get(i);
			}
			for(int B=0; B<=CNT-A; B++) {
				ArrayList<Integer> bl = new ArrayList<>();
				int bsum = 0;
				for(int i=0; i<B; i++) {
					bl.add(V.get(N-1-i));
					bsum += V.get(N-1-i);
				}

				ArrayList<Integer> abl = new ArrayList<>(al);
				abl.addAll(bl);
				Collections.sort(abl);
				int absum = asum+bsum;
				int BC = Math.min(abl.size(), K-abl.size());

				for(int j=0; j<BC; j++) {
					if(abl.get(j)>=0) break;
					absum -= abl.get(j);
				}
				ans = Math.max(ans, absum);
			}
		}
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 24148
#include<stdio.h>
#define MAX 100
#define INF 100000000
#define W 0
#define G 1
#define B 2

int n,M[MAX][MAX];

int prim(){
  int i,j,u,min,sum=0;
  int d[MAX],p[MAX],color[MAX];

  for(i=0;i<n;i++){
    d[i]=INF;
    p[i]=-1;
    color[i]=W;
  }
  d[0]=0;
  while(1){
    min=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(min>d[i]&&color[i]!=B){
	u=i;
	min=d[i];
      }
    }
    if(u==-1)break;
    color[u]=B;
    for(j=0;j<n;j++){
      if(color[j]!=B&&M[u][j]!=INF){
	if(d[j]>M[u][j]){
	  d[j]=M[u][j];
	  p[j]=u;
	  color[j]=G;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1) sum+=M[i][p[i]];
  }

  return sum;
}

int main(){
  int i,j,e;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j]=(e==-1)?INF:e;
    }
  }
  printf("%d\n",prim());

  return 0;
}

Measured memory_bytes: 636
#coding:utf-8
N = int(input())
nums = list(map(int,input().split()))

for ID,num in enumerate(nums,1):
    if 1 <= ID // 2 <= N:
        p = "parent key = {}, ".format(nums[ID // 2 - 1])
    else:
        p = ""
    if 1 <= 2 * ID <= N:
        l = "left key = {}, ".format(nums[2*ID - 1])
    else:
        l = ""
    if 1 <= 2 * ID + 1 <= N:
        r = "right key = {}, ".format(nums[2*ID])
    else:
        r = ""

    print("node {}: key = {}, ".format(ID,num) + p + l + r)


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  long long N, M;
  cin >> N >> M;
  long long T = 1900 * M + (N - M) * 100;
  long long f = pow(2, M);

  long double ans = 0;
  long double sumT = T;
  long double sumf = f;
  long double sumff = 1;

  rep(i, 100000)
  {
    long double num = sumT / sumf * sumff;
    if (num < 0.01 || num > 1e9)
      break;
    ans += num;
    sumT += T;
    sumf *= f;
    sumff *= (f - 1);
  }
  cout << ceil(ans) << endl;
  return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define ini(a,n)    memset(a,n,sizeof(a))
#define ff          first
#define ss          second
#define inf         10000000000000000
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;
unordered_map<ll,vi> g;
unordered_map<ll,ll> vis;

const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
const ll N = 2e5+10;
ll dx[4]={-1, +1, 0, 0};
ll dy[4]={0, 0, +1, -1};
bool imp = false;
bool isPowerOfTwo (ll x)
{
    return x && (!(x&(x-1)));
}

void solve() {
    map<ll,ll> mp;
    ll n;cin>>n;
    ll a[n+1];
    ll s=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        s = s xor a[i];
    }

    for(ll i=0;i<n;i++){
        cout<<(s xor a[i])<<" ";
    }


}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif

    fio
    int t=1;
    if(imp) cin>>t;

    while(t--)
    {
        // cout<<"Case #"<<tc<<": ";
        g.clear();
        vis.clear();
        solve();
        // tc++;
    }

}


Measured memory_bytes: 5168
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=9000000009;


signed main(){
  int a,b;
  int f=0;
  while(cin>>a>>b,a){
    if(f)cout<<endl;
    f=1;
    vector<int> y;
    for(int i=a;i<=b;i++){
      if(i%4==0){
        if(i%100!=0){
          y.PB(i);
          continue;
        }
        if(i%400==0)y.PB(i);
      }
    }
    if(y.size()==0){
      cout<<"NA"<<endl;
    }else{
      for(auto x:y)cout<<x<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3008
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#define int long long
using namespace std;

int32_t main()
{ 
  int n;
  cin >> n;
  map<string, int> ana;
  string s;
  for (int i = 0; i < n; i++)
  {
    cin >> s;
    sort(s.begin(), s.end());
    ana[s]++;
  }
  int ans = 0;
  for (auto x : ana)
  {
    ans+= x.second * (x.second - 1) / 2; // nC2 
  }
  cout << ans << endl;
  return 0;
}
    

Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		for(int i = 0 ; i < x + 1 ; i++) {
			if(y == i * 2 + (x - i) * 4) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}


}



Measured memory_bytes: 35708
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
 
befo = -100
sat = 0
for i in range(N):
    index = A[i] - 1
    sat += B[index]
    if befo + 1 == index:
        sat += C[befo]
    befo = index
 
print(sat)

Measured memory_bytes: 3064