akhauriyash/Code-Regression huggingface dataset:
H,W = [int(i) for i in input().split()]
ccc = []
AAA = []
for i in range(10):
    ccc.append([int(i) for i in input().split()])
for i in range(H):
    AAA.append([int(i) for i in input().split()])

for k in range(10):
    for i in range(10):
        for j in range(10):
            ccc[i][j] = min(ccc[i][j],ccc[i][k]+ccc[k][j])

ans = 0
for h in range(H):
    for w in range(W):
        if AAA[h][w] != -1:
            ans += ccc[AAA[h][w]][1]

print(ans)

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

using namespace std;

class Solution {
public:
	void solve() {
		string s;
		cin >> s;
		if (s == "ABC")
			cout << "ARC"
					 << "\n";
		else
			cout << "ABC"
					 << "\n";
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 3612
import sys
import itertools
MOD = 3
INF = 1000000000


def input():
    return sys.stdin.readline().rstrip()


def main():
    n, c = [int(e) for e in input().split()]
    dMat = [[int(e) for e in input().split()] for _ in range(c)]
    cMat = [[int(e) for e in input().split()] for _ in range(n)]

    cost = [[0 for _ in range(c)] for _ in range(MOD)]
    for hi in range(n):
        for wi in range(n):
            cMod = ((hi + 1) + (wi + 1)) % MOD
            for ci in range(c):
                cost[cMod][ci] += dMat[cMat[hi][wi] - 1][ci]

    ans = INF
    for perm in itertools.permutations(range(c), MOD):
        costSum = 0
        for di in range(MOD):
            costSum += cost[di][perm[di]]
        ans = min(ans, costSum)
    print(ans)


main()


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int n,r;
	while(true){
		cin >> n >> r;
		if(!n&&!r) break;
		vector<int> fuda;
		REP(i,n) fuda.push_back(i+1);
		REP(i,r){
			int p, c;
			cin >> p >> c;
			for(int j=c-1;j>=0;j--){
				fuda.push_back(fuda[n-p-j]);
			}
			REP(i,c)fuda.erase(fuda.begin()+n-p-i);
		}
		cout << fuda[n] << endl;
	}
}

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

def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)

A = num2alpha(N)
print(A.lower())

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#include <tuple>
using namespace std;
using ll = long long;

int main()
{
  ll n;
  cin >> n;
  // Fが一番大きい値で初期化
  ll ans = to_string(n).size();
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i != 0) // 割り切れなければ
      continue;
    // iかn/iの桁数どちらかのうち大きい方がF
    ll cur = max(to_string(i).size(), to_string(n / i).size());
    // 答えを最小化したいので
    ans = min(ans, cur);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "../../../debug_print.hpp"
#else
#define debug(...)
#endif
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int N, K;
    scan(N, K);
    vector<ll> h(N);
    scan(h);
    rsort(h);
    ll ans = 0;
    rep(i, N) {
        if (K <= i)
            ans += h[i];
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 1792
dic = ["", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan",
       "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"]
while True:
  m, n = map(int, input().split())
  if m == 0:
    break
  x = m ** n
  ind = 0
  ans = ""
  while x:
    if x % 10000:
      ans = str(x % 10000) + dic[ind] + ans
    x //= 10000
    ind += 1
  print(ans)


Measured memory_bytes: 5600
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut p: [usize; n],
    }

    let mut count = 0;
    for i in 0..p.len() - 1 {
        if p[i] != (i + 1) {
            continue;
        };
        count += 1;
        p[i + 1] = p[i];
    }
    if p[p.len() - 1] == p.len() {
        count += 1;
    }

    println!("{}", count);
}


Measured memory_bytes: 3320
#include<stdio.h> 
int main(void) { 
    int w,h,x,y,r,a; 
    scanf("%d%d%d%d%d",&w,&h,&x,&y,&r); 
    a=0; 
    if(x-r<0){ 
        a+=1; 
        
    } if(y-r<0){ 
        a+=1; } 
        if(y+r>h){ 
            a+=1; 
            
        } if(x+r>w){ 
            a+=1; 
            
        } if(a==0){ 
            printf("Yes\n"); 
            
        } if(a>0){ 
            printf("No\n"); 
            
        } return 0; 
    
} 


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

int main() {
 int a;
 cin >> a;
 int b = a / 1000;
 int c = b+1;
 if(a % 1000 == 0){
   cout << 0 << endl;
   return 0;
 }
 
 cout << c*1000 - a << endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll n;cin>>n;
  map<ll,ll> s,t;
  rep(i,0,n){
    ll a;cin>>a;

    if(i%2){s[a]++;}
    else{t[a]++;}
  }
  ll ms=0,mt=0,ss,mt2=0,ms2=0,tt;
  for(auto u:s){
    if(ms<u.second){
      ms=u.second;
      ss=u.first;
    }
  }
  for(auto v:t){
    if(v.first==ss)continue;
    mt=max(mt,v.second);
  }
  for(auto u:t){
    if(mt2<u.second){
      mt2=u.second;
      tt=u.first;
    }
  }
  for(auto v:s){
    if(v.first==tt)continue;
    ms2=max(ms2,v.second);
  }
  cout<<min(n-ms-mt,n-ms2-mt2)<<endl;
}



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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i];
    }
    
    double yui = 0;
    rep(i, n) {
        yui += data[i];
    }

    yui /= n;
    int ans = 0;
    Rep(i, n) {
        if (abs(yui - (double)data[i]) < abs(yui - (double)data[ans])) {
            ans = i;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,k;
    cin>>n;

    int a[n],b[n],c[n];
    int ans[n][3]={0};
    int pc[n];
    for(int i=0;i<n;i++){

        cin>>a[i]>>b[i]>>c[i];
    }
    ans[0][0]=a[0];
    ans[0][1]=b[0];
    ans[0][2]=c[0];
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            if(j==0){
                ans[i][j]=max(ans[i][j],a[i]+max(ans[i-1][1],ans[i-1][2]));
            }
            else if(j==1)
                ans[i][j]=max(ans[i][j],b[i]+max(ans[i-1][0],ans[i-1][2]));
            else
                ans[i][j]=max(ans[i][j],c[i]+max(ans[i-1][0],ans[i-1][1]));
        }
    }


    cout<<max({ans[n-1][0],ans[n-1][1],ans[n-1][2]});
}


Measured memory_bytes: 5916
import java.io.*;
import java.util.Scanner;

class Main
{
	public static void main (String[] args) throws IOException
	{
  		Scanner in = new Scanner(System.in);

		for(int i = 1; i > 0; i++){

	      	String X;
	  		int x;
	
	  		X = in.nextLine();
	  		x = Integer.parseInt(X);
	
	      	if(x == 0){
	        	break;
	      	}else{
		  		System.out.println("Case " + i + ": " + x);
      		}
    	}
	}
}

Measured memory_bytes: 51904
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef vector<pii> vpii;
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
    tree_order_statistics_node_update> ost;

const int N=510;
vpii q;
int c, ans[N*N];

void put(int w, int dir) {
    while(ans[c]) c+=dir;
    ans[c]=w;
    c+=dir;
}

int main() {
    int i, n, t;
    scanf("%d", &n);
    for(i=1; i<=n; i++) {
        scanf("%d", &t);
        q.pb(pii(t, i));
        ans[t]=i;
    }
    sort(all(q));
    c=1;
    for(auto z:q) {
        for(i=1; i<z.sc; i++) put(z.sc, 1);
        if(c>z.fs) return printf("No\n"), 0;
    }
    reverse(all(q));
    c=n*n;
    for(auto z:q) {
        for(i=n; i>z.sc; i--) put(z.sc, -1);
        if(c<z.fs) return printf("No\n"), 0;
    }
    printf("Yes\n");
    for(i=1; i<=n*n; i++)
        printf(i==n*n? "%d\n":"%d ", ans[i]);
    return 0;
}

Measured memory_bytes: 2176
def main():
    N, M, K=map(int, input().split())
    friend_or_block = [0] * N
    friends_chain = UnionFindTree(N)

    for _ in range(M):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        friends_chain.unite(a, b)
        friend_or_block[a] += 1
        friend_or_block[b] += 1

    for _ in range(K):
        c, d = map(int, input().split())
        c, d = c-1, d-1
        if friends_chain.same(c, d):
            friend_or_block[c] += 1
            friend_or_block[d] += 1

    ans = [None] * N
    for i in range(N): ans[i] = str(friends_chain.count(i) - friend_or_block[i] - 1)
    print(' '.join(map(str, ans)))

class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]

    def root(self, x):
        p, seq = self.parent[x], list()
        while p >= 0:
            seq.append(x)
            x, p = p, self.parent[p]
        for c in seq: self.parent[c] = x
        return x

    def same(self, x, y): return self.root(x) == self.root(y)

    def count(self, x): return -self.parent[self.root(x)]

    def unite(self, x, y):
        xr, yr = self.root(x), self.root(y)
        if xr == yr: return
        if self.parent[xr] > self.parent[yr]: xr, yr = yr, xr
        self.parent[xr] += self.parent[yr]
        self.parent[yr] = xr

if __name__ == '__main__':
    main()



Measured memory_bytes: 87840
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    int64_t n;
    cin>>n;
    if (n%2==0)
    {
        cout<<n<<endl;
    }else
    {
        cout<<2*n<<endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 3604
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array.Unboxed
import qualified Data.Vector.Unboxed as VU
import Data.Maybe
import qualified Data.ByteString.Char8 as BS

readIntBS = fst . fromJust . BS.readInt

main = do
  s <- BS.getLine
  t <- BS.getLine
  q <- readLn :: IO Int

  let
    ls = BS.length s
    lt = BS.length t
    sa = VU.fromList $ scanl (+) 0 [if BS.index s i=='A' then 1 else 0 | i<-[0..ls-1]] :: VU.Vector Int
    sb = VU.fromList $ scanl (+) 0 [if BS.index s i=='A' then 0 else 1 | i<-[0..ls-1]] :: VU.Vector Int
    ta = VU.fromList $ scanl (+) 0 [if BS.index t i=='A' then 1 else 0 | i<-[0..lt-1]] :: VU.Vector Int
    tb = VU.fromList $ scanl (+) 0 [if BS.index t i=='A' then 0 else 1 | i<-[0..lt-1]] :: VU.Vector Int
 
  replicateM_ q $ do
    [a,b,c,d] <- map readIntBS . BS.words <$> BS.getLine :: IO [Int]
    let
      sa' = (sa VU.! b) - (sa VU.! (a-1))
      sb' = (sb VU.! b) - (sb VU.! (a-1))
      ta' = (ta VU.! d) - (ta VU.! (c-1))
      tb' = (tb VU.! d) - (tb VU.! (c-1))

    putStrLn $ if (sa'+2*sb')`mod`3 == (ta'+2*tb')`mod`3 then "YES" else "NO"
  


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    cin >> N;
    vector<ll> V(N+1);

    for(int i = 1; i <= N; i++){
        int tmp = i;
        for(int j = 2; j <= sqrt(i); j++){
            while(tmp % j == 0){
                V[j]++;
                tmp /= j;
            }
        }
        V[tmp]++;
    }

    ll ans = 1;
    for(int i = 2; i <= N; i++){
        // cout << i << ": " << V[i] << endl;
        ans = ans * (V[i] + 1) % INF;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

using ll=long long;

int main() {
  int N,M,X; cin >>N >>M >>X;
  vector<int> C(N);
  vector<vector<int>> A(N,vector<int>(M));
  rep(i,0,N) {
    cin >>C[i];
    rep(j,0,M) {
      cin >>A[i][j];
    }
  }

  int ans=INT_MAX;
  int all=1<<N;
  rep(mask,0,all) {
    vector<int> level(M);
    int cost=0;
    rep(i,0,N) {
      if (mask>>i&1) {
        cost+=C[i];
        rep(j,0,M) {
          level[j]+=A[i][j];
        }
      }
    }
    bool flag=true;
    rep(j,0,M) {
      if (level[j]<X) {
        flag=false;
      }
    }
    if (flag) {
      ans=min(ans,cost);
    }
  }
  if (ans==INT_MAX) {
    cout <<-1 <<endl;
  } else {
    cout <<ans <<endl;
  }
  return 0;
}


Measured memory_bytes: 3624
S = input()
A = [0 for _ in range(len(S) + 1)]

for idx in range(len(S)):
    if S[idx] == "<":
        A[idx + 1] = max(A[idx + 1], A[idx] + 1)

for idx in reversed(range(len(S))):
    if S[idx] == ">":
        A[idx] = max(A[idx], A[idx + 1] + 1)

print(sum(A))


Measured memory_bytes: 24092
#include<bits/stdc++.h>
#define N 16
using namespace std;
int n,x,y,z,ans,val[1<<(N+1)],cnt[N*2],dp[1<<N];
vector<int>G[N*2];
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		scanf("%d%d%d",&x,&y,&z);
		x++;y++;
		val[x]^=z;val[y]^=z;
	}
	for (int i=1;i<=n;i++) cnt[val[i]]++;
	for (int i=1;i<=15;i++) ans+=cnt[i]/2,val[i]=cnt[i]%2;
	int now=0,tot=0;
	for (int i=1;i<=15;i++) if (val[i]) now|=(1<<i),tot++;
	memset(dp,127,sizeof(dp));int inf=dp[now];dp[now]=0;
	for (int i=0;i<(1<<16);i++) G[__builtin_popcount(i)].push_back(i);
	for (int i=tot;i;i--){
		for (int j=0;j<(int)G[i].size();j++){
			int S=G[i][j];
			if (dp[S]==inf) continue;
			for (int x=1;x<=15;x++){
				for (int y=1;y<=15;y++){
					if (x==y||(!(S>>x&1))||(!(S>>y&1))) continue;
					int tmp=x^y;
					int S1=S^(1<<x)^(1<<y);
					if (S1&(1<<tmp)) dp[S1^(1<<tmp)]=min(dp[S1^(1<<tmp)],dp[S]+2);
					else dp[S1|(1<<tmp)]=min(dp[S1|(1<<tmp)],dp[S]+1);
				}
			}
		}
	}
	//cerr<<inf<<endl;
	printf("%d\n",min(dp[1],dp[0])+ans);
	return 0;
}

Measured memory_bytes: 1280
//Author:- Yatin Patel
//Mail:- yatinpatel.gt@gmail.com

#include <bits/stdc++.h>
#define FILEIN ifstream fin;fin.open("input.txt");
#define FILEOUT ofstream fout;fout.open("output.txt");

using namespace std;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

#define FAST ios::sync_with_stdio(false);ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second

#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define RFOR(i,a,b) for(ll i=a;i>b;i--)
#define FILL(a,b) memset((a),(b),sizeof((a)))

#define MOD 1000000007
#define INF LONG_MAX
#define MINF LONG_MIN

ll power(ll x, unsigned ll y){
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}

//#define fin cin
//#define fout cout

int main(){

    FAST;
    ll cnt = 0;
    bool arr[10] = {0};
    FOR(i,0,4){
        ll t;
        cin>>t;
        if(t==1 && !arr[t]) {
            cnt++;
            arr[t] = true;
        }
        
        if(t==9 && !arr[t]) {
            cnt++;
            arr[t] = true;
        }
        
        if(t==7 && !arr[t]) {
            cnt++;
            arr[t] = true;
        }
        
        if(t==4 && !arr[t]) {
            cnt++;
            arr[t] = true;
        }
    }

    if(cnt==4){
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }

    return 0;
}






Measured memory_bytes: 764
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct node{int p,l,r;};

node t[MAX];
int n,D[MAX];

void print(int u){
  int i,c;
  cout << "node "<< u << ": ";
  cout << "parent = "<<t[u].p<<", ";
  cout << "depth = "<<D[u]<<", ";

  if(t[u].p==NIL) cout<<"root, ";
  else if(t[u].l==NIL) cout<<"leaf, ";
  else cout<<"internal node, ";
  cout<<"[";

  for(i=0,c=t[u].l;c!=NIL;i++,c=t[c].r){
    if(i) cout<<", ";
    cout<<c;
  }
  cout<<"]"<<endl;
}

int rec(int u,int p)
{
  D[u]=p;
  if(t[u].r!=NIL) rec(t[u].r,p);
  if(t[u].l!=NIL) rec(t[u].l,p+1);
}

int main(){
  int i,j,d,v,c,l,r;
  cin>>n;
  for(i=0;i<n;i++) t[i].p=t[i].l=t[i].r=NIL;

  for(i=0;i<n;i++){
    cin >> v >>d;
    for(j=0;j<d;j++){
	cin>>c;
	if(j==0) t[v].l=c;
	else t[l].r=c;
	l=c;
	t[c].p=v;
      }
  }
  for(i=0;i<n;i++){
    if(t[i].p==NIL) r=i;
  }

  rec(r,0);
  for(i=0;i<n;i++) print(i);

  return 0;
}



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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if (a+b<c+d){
    cout<<"Right"<<endl;
  }
  else if (a+b==c+d) {
    cout<<"Balanced"<<endl;
  }
  else {
    cout<<"Left"<<endl;
  } 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

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



int main(){
    int N;
    cin >> N;
    for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
            if(N == i * j){
                cout << "Yes"  << endl;
                return 0;
            }
        }
    }
    cout << "No"  << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bitset>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;


int main(){
    char c;
    cin>>c;
    cout<<char(c + 1)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll MOD = 1e9 + 7;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl;
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
#define INF INT_MAX/2

const int MAX = 101010;
ll fac[MAX], finv[MAX], inv[MAX];

void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	ll n, k;
	cin >> n >> k;
	combinit();
	for (ll i = 1; i <= k; i++) {
		ll ans = comb(n-k+1,i)*comb(k-1,k-i);
		cout << ans%MOD << endl;
	}

	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,k,s,a[500010];
int main(){
	cin>>n>>k>>s;
	FOR(i,1,k) a[i]=s;
	FOR(i,k+1,n) if (s==1000000000) a[i]=1; else a[i]=1000000000;
	FOR(i,1,n) printf("%d ",a[i]);
	return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
int main()
{

    int n,count=0;
    scanf("%d",&n);
    int h[n];
    for(int i=0;i<n;i++)
        scanf("%d",&h[i]);
    int big=h[0];
    for(int i=0;i<n;i++)
    {
        if(h[i]>=big)
        {
           count+=1;
           big=h[i];
        }

    }

    printf("%d",count);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
typedef long long ll;

int main() {
  string s;
  ll k;
  cin >> s >> k;

  for (int i = 0; i < k; i++) {
    if (s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
  }

  cout << 1 << endl;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 1000001;
const int MOD = 1000000007;
   
        signed main() {
           string s;
           cin>>s;
           int ans=0;
           for(int i=0;i<s.size();i++)if(s[i]=='o')ans++;
           if(ans+(15-s.size())>=8)cout<<"YES";
           else cout<<"NO"<<endl
           ;
           return 0;

        }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
int main() {
	ll ans, add = 0;
	string s;
	cin >> s;
	ans = s.size();
	rep(i, s.size()) {
		if (s[i] == 'S')
			add++;
		else if (add >0 && s[i] == 'T') {
			add--;
			ans -= 2;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let r: usize = iterator.next().unwrap().parse().unwrap();

    if r < 1200 {
        return "ABC".to_string();
    }

    if r < 2800 {
        return "ARC".to_string();
    }

    return "AGC".to_string();
}


Measured memory_bytes: 2072
import sys
while 1:
  H, W = map(int, raw_input().split())
  if H==0 and W==0:
    break
  for i in range(H):
    for j in range(W):
      if (i+j)%2==0:
        sys.stdout.write('#')
      else:
        sys.stdout.write('.')
    sys.stdout.write('\n')
  print ''

Measured memory_bytes: 6436
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

int main(){
	int N, X;
	cin >> N >> X;
	int x[N];

	rep(i,N) {
		int y;
		cin >> y;
		x[i] = y-X;
	}

	int ans = 0;
	rep(i,N) ans = gcd(ans,x[i]);
	cout << abs(ans) << endl;
return 0;
}


Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
const int MAX = 5010;
long long t[3][MAX], tt[3][MAX];
int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  vector<int>v(n);
  for(int i = 0; i < n; ++i){
    if(s[i] == 'R')v[i] = 0;
    else if(s[i] == 'G')v[i] = 1;
    else v[i] = 2;
  }
  int r = 0, b = 0, g = 0;
  for(int i = n-1; i >= 0; --i) {
    tt[0][i] = r;
    tt[1][i] = g;
    tt[2][i] = b;
    r+= v[i] == 0;
    g+= v[i] == 1;
    b+= v[i] == 2;
  }
  r = 0;
  b = 0;
  g = 0;
  for(int i = 0; i < n; ++i) {
    t[0][i] = r;
    t[1][i] = g;
    t[2][i] = b;
    r+= v[i] == 0;
    g+= v[i] == 1;
    b+= v[i] == 2;
  }
  long long ans = 0;
  for(int i = 0; i < n; ++i) {
    int prox = (v[i]+1)%3;
    int prev = (v[i]+2)%3;
    ans+= t[prox][i] * tt[prev][i];
    ans+= tt[prox][i] * t[prev][i];
    for(int j = 1; i-j >= 0 && i +j < n; ++j){
      if((v[i] != v[i+j]) && (v[i] != v[i-j]) && (v[i+j] != v[i-j]))--ans;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3840
// AOJ 0142: Nature of Prime Numbers
// 2017.8.16 bal4u@uu
// 2017.11.21

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX  10000
#define HALF 5000
int sqr[HALF+5];
int a[HALF+5];
int d[HALF+5];
char f[MAX+5];

char prime[MAX+5];
int tbl[24] = {
  3,  5,  7, 11, 13, 17, 19, 23, 29, 31,
 37, 41, 43, 47, 53, 59, 61, 67, 71, 73,
 79, 83, 89, 97 };
int sqp[24] = {
  9,25,49,121,169,289,361,529,841,961,
1369,1681,1849,2209,2809,3481,3721,4489,5041,
5329,6241,6889,7921,9409 };

int main()
{
	int n;
	int i, j, k, b, m;
	char buf[10];

	for (i = 0; i < 24; i++) {
		k = tbl[i];
		for (j = sqp[i]; j < MAX; j += k) prime[j] = 1;
	}

	while (fgets(buf, 10, stdin) && *buf != '0') {
		n = atoi(buf), k = n >> 1;
		// 4m+3????´???°
		if (!prime[n] && (n & 3) == 3) {
			sprintf(f, "%d", k-1);
			while(k--) puts(f);
			continue;
		}

		// ???????\???°????????????????????????????¨????
		memset(d, 0, sizeof(int)*(k+2));
		memset(f, 0, sizeof(char)*(n+2));
		for (m = 0, i = 1; i <= k; i++) {
			if (!sqr[i]) sqr[i] = i*i;
			b = sqr[i] % n;
			if (!f[b]) f[b] = 1, a[m++] = b;
		}
		for (i = 0; i < m; i++) {
			for (j = 0; j < i; j++) {
				if (b = a[i] - a[j]) {
					if (b < 0) b += n;
					if (b > k) b = n - b;
					d[b]++;
		//			d[n-b]++;
				}
			}
		}
		for (i = 1; i <= k; i++) printf("%d\n", d[i]<<1);
	}
	return 0;
}

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

int main()
{
    int X, Y;
    cin >> X >> Y;
    for (int i = 0; i <= X; i++)
    {
        if (Y == i * 2 + (X - i) * 4)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
using namespace std;

int main(void){
    int H,W; cin>>H>>W;
    char s[51][51];
    for(int i=1;i<=W;i++){
        for(int j=1;j<=H;j++){
            cin>>s[i][j];
        }
    }
    for(int i=1;i<=W;i++){
        for(int j=1;j<=H;j++){
            if((s[i][j]=='#'&&s[i-1][j]=='#')||(s[i][j]=='a'&&s[i-1][j]=='#')||(s[i][j]=='#'&&s[i-1][j]=='a')){
                s[i][j]='a';
                s[i-1][j]='a';
            }
            if((s[i][j]=='#'&&s[i][j-1]=='#')||(s[i][j]=='#'&&s[i][j-1]=='a')||(s[i][j]=='a'&&s[i][j-1]=='#')){
                s[i][j]='a';
                s[i][j-1]='a';
            }
        }
    }
    int ans=0;
    for(int i=1;i<=W;i++){
        for(int j=1;j<=H;j++){
            if(s[i][j]=='#'){
                ans++;
            }
        }
    } 
    if(ans==0)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
int n,a[100];
long long maxx[100];
vector<int>v[100];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
	}
	for(int i=1;i<=n;++i){
		for(int j=i+1;j<=n;++j){
			if(a[j]>a[i]){
				v[j].push_back(i);
			}
		}
	}
	maxx[1]=1000;
	for(int i=2;i<=n;++i){
		maxx[i]=maxx[i-1];
		for(int j=0;j<v[i].size();++j){
			long long t=a[i]-a[v[i][j]],g=maxx[v[i][j]]/a[v[i][j]];
			if(maxx[i]<maxx[v[i][j]]+g*t){
				maxx[i]=maxx[v[i][j]]+g*t;
			}
		}
	}
	printf("%lld\n",maxx[n]);
	return 0;
}

Measured memory_bytes: 3264
#include <iostream>
#include <vector>
#include <stack>
#include <unordered_set>
#include <numeric>
#include <iterator>
#include <unordered_map>
#include <array>
#include <map>
#include <cstring>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctgmath>
#include <set>
#include <queue>
#include <fstream>
#include <ostream>
#include <list>
#include <string>
#define int long long
using namespace std;
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	vector<vector<int>> all(n);
	for (int i = 0; i < n; i++)
	{
		int x, y, z;
		cin >> x >> y >> z;

		all[i].push_back(x);
		all[i].push_back(y);
		all[i].push_back(z);

	}

	vector<vector<int>> dp(n);

	dp[0].push_back(all[0][0]);
	dp[0].push_back(all[0][1]);
	dp[0].push_back(all[0][2]);

	for (int i = 1; i < n; i++)
	{
		dp[i].push_back(max(dp[i - 1][1], dp[i - 1][2]) + all[i][0]);
		dp[i].push_back(max(dp[i - 1][0], dp[i - 1][2]) + all[i][1]);
		dp[i].push_back(max(dp[i - 1][1], dp[i - 1][0]) + all[i][2]);
	}

	cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << "\n";
}


Measured memory_bytes: 14336
#include <stdio.h>
#include <cmath>
#include <algorithm>

#define NUM 51000

int main(){
	int table[NUM],limit;

	for(int i=0; i < NUM;i++)table[i] = 1;
	table[0] = 0;
	table[1] = 0;

	limit = sqrt(NUM);

	for(int i=2;i<=limit;i++){
		if(table[i] == 1){
			for(int k=2*i;k < NUM; k += i){
				table[k] = 0;
			}
		}
	}

	int n,count;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		count = 0;
		for(int i=2; i<= (n+1)/2; i++){
			if(i <= n-i &&  table[i] == 1 && table[n-i] == 1)count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 2808
number = int(input())
if number in range(400, 600):
    print('8')
elif number in range(600, 800):
    print('7')
elif number in range(800, 1000):
    print('6')
elif number in range(1000, 1200):
    print('5')
elif number in range(1200, 1400):
    print('4')
elif number in range(1400, 1600):
    print('3')
elif number in range(1600, 1800):
    print('2')
elif number in range(1800, 2000):
    print('1')

Measured memory_bytes: 9200
import collections
n = int(input())
a_list = list(map(int,input().split()))
a_list2 = [i-a for i,a in enumerate(a_list)]
a_list_dic = collections.Counter(a_list2)
count = 0
for i,a in enumerate(a_list):
    a_list_dic[i-a] -= 1
    count += a_list_dic[i+a]

print(count)

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

void solve(long long a, long long b){
    int h = 0;
    REP(i, b - a)
        h += i;
    cout << h - a << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> g(200005);
vector<int> sum(200005);
vector<bool> visited(200005);

void bfs(int s) {
  queue<int> Q;
  Q.push(s);
  while (!Q.empty()) {
    int u = Q.front(); Q.pop();
    visited[u] = true;
    for (int to: g[u]) {
      if (visited[to]) continue;
      sum[to] += sum[u];
      Q.push(to);
    }
  }
}

int main(void) {
  int n, q;
  cin >> n >> q;
  rep (i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].pb(b);
    g[b].pb(a);
  }

  rep (i, q) {
    int p, x;
    cin >> p >> x;
    p--;
    sum[p] += x;
  }

  bfs(0);

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

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

int main(){
	int k, n;
	cin >> k >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) cin >> vec.at(i);
	vector<int> distance(n);
	distance.at(0) = vec.at(0) + k - vec.at(n - 1);
	for (int i = 1; i < n; i++) {
		distance.at(i) = vec.at(i) - vec.at(i - 1);
	}
	sort(distance.begin(), distance.end());
	int ans = k - distance.at(n-1);
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int counter(int x) {
    set<int> s;
    for (int i = 1; i * i <= x; ++i) if (x % i == 0) s.insert(i), s.insert(x / i);
    return s.size();
}
int main() {
    int N, cnt = 0; cin >> N;
    for (int i = 9; i <= N; i += 2) {
        if (counter(i) == 8) cnt++;
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
//#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14 
 
signed main(){
    int n;
    cin >> n;
    long long ans = 0;
    if(n == 1)
        cout << 1 << endl;
    else{
        long long ikkomae = 1, nikomae = 2;
        rep(i, n - 1){
            ans = ikkomae + nikomae;
            nikomae = ikkomae;
            ikkomae = ans;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
#define vec vector<int>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main(){
  int n;
  int ans;
  cin>>n;
  if(n%2==0){
    ans=(n/2)-1;
  }
  else{
    ans=(n/2);
  }
  cout<<ans<<endl;
}


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

using std::cin;
using std::cout;
using std::endl;
using std::vector;

// 2 2 4
// r1 + r2 = 2 * 2
// r2 + r3 = 2 * 2
// r3 + r1 = 4 * 2
//
// r1 - r3 = 0
// r1 + r1 = 8

static int
solve_r1(int N, vector<int> const &A)
{
  int x = A[0];
  for (int i = 1; i < N; i += 2)
  {
    x = x - A[i] + A[i + 1];
  }
  return x;
}

int
main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  int r = solve_r1(N, A);
  for (int i = 0; i < N - 1; i++)
  {
    cout << r << ' ';
    r = (A[i] - r / 2) * 2;
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 1664
N = int(input())
h = list(map(int, input().split()))

def find_res(h):
    count = 0

    if h == []:
        return 0
    if len(h) == 1:
        return h[0]

    while len(h) > 1:
        if 0 in h:
            idx = h.index(0)
            # print(h[0:idx], h[idx+1:])
            count +=  find_res(h[0:idx]) + find_res(h[idx+1:])
            return count
        else:
            min_h = min(h)
            h = [a - min_h for a in h]
            count += min_h

    return count

ans = find_res(h)
print(ans)

Measured memory_bytes: 3064
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
#include<cmath>
#include<set>
#include<utility>

using namespace std;


int main()
{
	string n;
	cin >> n;
	int x = 0;
	for (int i = 0; i < n.size(); i++)
	{
		if (i != 0)
		{
			if (n.at(i) == n.at(i - 1))
			{
				x++;
			}
			else
			{
				x = 0;
			}
			
			if (x == 2)
			{
				cout << "Yes" << endl;
				return 0;
			}
	 }
	}
	cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int K;
  cin >> K;
  set<char> a;
  REP(i, s.size()) { a.insert(s[i]); }
  vector<char> best;
  auto itr = a.begin();
  for(int i = 0; i < K && itr != a.end(); i++, itr++) {
    best.push_back(*itr);
  }
  set<string> ans;
  for(char c : best) {
    REP(i, s.size()) {
      if(s[i] == c) {
        REP(j, K) {
          if(i + j >= s.size()) { break; }
          ans.insert(s.substr(i, j + 1));
        }
      }
    }
  }
  auto ittt = ans.begin();
  REP(i, K - 1) { ittt++; }
  cout << *ittt << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;
typedef vector<lint> poly;

const lint mod = 1e9 + 7;
const lint INF = mod * mod;

typedef struct RollingHash{
    const ulint hash_mod = (1ULL << 61ULL) - 1, hash_base = mod;
    const ulint mask_30bit = (1ULL << 30ULL) - 1, mask_31bit = (mask_30bit << 1ULL) + 1;
    const ulint num = hash_mod << 2LL;
    vector<ulint> pow_table, hash;
    int n;

    ulint calc_mul31(ulint a, ulint b){
        ulint au = a >> 31ULL, ad = a & mask_31bit;
        ulint mid = au * b, midu = mid >> 30ULL, midd = mid & mask_30bit;
        return midu + (midd << 31ULL) + ad*b;
    }

    ulint calc_mul61(ulint a, ulint b){
        ulint au = a >> 31ULL, ad = a & mask_31bit;
        ulint bu = b >> 31ULL, bd = b & mask_31bit;
        ulint mid = au * bd + ad * bu, midu = mid >> 30ULL, midd = mid & mask_30bit;
        return 2*au*bu + midu + (midd << 31ULL) + ad*bd;
    }

    ulint calc_mod(ulint x){
        x = (x & hash_mod) + (x >> 61ULL);
        if(x > hash_mod) x -= hash_mod;
        return x;
    }

    RollingHash(string &s){
        n = s.size();
        pow_table.resize(n+1);
        hash.resize(n+1);
        pow_table[0] = 1ULL;
        rep(i, n) pow_table[i+1] = calc_mod(calc_mul61(pow_table[i], hash_base));
        hash[0] = 0ULL;
        rep(i, n) hash[i+1] = calc_mod(calc_mul61(hash[i], hash_base) + s[i]);
    }

    ulint slice(int i, int len){
        return calc_mod(hash[i+len] +num - calc_mul61(hash[i], pow_table[len]));
    }
}Loli;

bool check(int len, Loli &rh){
    rep(i, rh.n-len+1){
        for(int j=i+len; j+len-1<rh.n; ++j){
            if(rh.slice(i, len) == rh.slice(j, len)) return true;
        }
    }
    return false;
}

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

    int low = 0, high = n/2 + 1;
    while(high - low > 1){
        int mid = (high + low) / 2;
        (check(mid, rh) ? low : high) = mid;
    }

    printf("%d\n", low);
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    char[] s = scanner.next().toCharArray();
    int[] numW = new int[s.length + 1];
    numW[s.length] = 0;
    for (int i = s.length - 1; i >= 0; i--) {
      numW[i] = numW[i + 1];
      if (s[i] == 'W') numW[i]++;
    }

    long sum = 0;
    for (int i = 0; i < s.length; i++) {
      if (s[i] == 'B') sum += numW[i];
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 28044
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int X = sc.nextInt();
   	int count=0;
    int j=0;
    int Nums[]=new int[M];
    for(int i=0;i<M;i++){
    	Nums[i]=sc.nextInt();
    }

    if(X<N/2){
    for(int i=M-1;i>=0;i--){
    	if(Nums[i]<X){
          count++;
   		 }
      }
    }else{
      for(int i=0;i<M;i++){
    	if(Nums[i]>X){
          count++;
   		 }
    }
    }
    System.out.println(count);
  }
}


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

int main() {
  int N;
  string s;
  cin >> N >> s;
  vector<bool> ch(N,false);
  for (int i=0; i<N; i++) {
    if (s[i] == '(') {
      ch[i] = true;
    }
  }
  int ans = 0;
  int term = 0;
  for (int i=0; i<N; i++) {
    if (ch[i]) {
      term -= 2;
    }
    term ++;
    ans = max(ans,term);
  }
  for (int i=0; i<ans; i++) {
    cout << '(';
  }
  cout << s;
  ans = 0;
  term = 0;
  for (int i=N-1; i>=0; i--) {
    if (ch[i]) {
      term += 2;
    }
    term--;
    ans = max(ans,term);
  }
  for (int i=0; i<ans; i++) {
    cout << ')';
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define per(i, a, b) for(int i = (a); i >= (b); --i)
using namespace std;

typedef long long ll;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int match[1007][1007];
int ans[1007];
queue<int> q[1007];
int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	rep(i, 1, n){
		rep(j, 1, n-1){
			scanf("%d", &match[i][j]);
			q[i].push(match[i][j]);
		}
	}
	while(1){
		bool flag = 0;
		int top;
		rep(i, 1, n){
			if(q[i].empty())	continue;
			top = q[i].front();
			if(!q[top].empty() && q[top].front() == i){
				flag = 1;
				q[top].pop();
				q[i].pop();
				ans[top] = ans[i] = max(ans[i], ans[top]) + 1;
			}
		}
		int cnt = 0;
		rep(i, 1, n)	cnt += q[i].empty();
		if(cnt == n)	break;
		if(flag == 0){
			printf("-1\n");
			return 0;
		}
	}
	printf("%d\n", *max_element(ans+1, ans+1+n));
	return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a, b,c;
    cin >> a>> b >>c;
    cout << (a+b)*c/2;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

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

int main(){
    int N;
    vector<long long int> A;

    int i, j;

    cin >> N;
    for(i=0;i<N;i++){
        ll ai;
        cin >> ai;
        A.push_back(ai);
    }

    ll S = 0;
    ll sum = 0;
    ll mod = 1000000000 + 7;
    for(j=1;j<N;j++){
        sum += A[j];
        sum = sum % mod;
    }

    for(i=0;i<N-1;i++){
        S += A[i] * sum;
        S =  S % mod;
        sum -= A[i+1];
        if(sum < 0){sum += mod;}
    }

    cout << S << endl;

    return 0;
}


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

int main() {
  int a, cou = 0;
  cin >> a;
  long long arr[a] = {0};
  for (int i = 0; i < a; i++) {
    cin >> arr[i];
    while (arr[i] % 2 == 0) {
      if (arr[i] % 2 == 0)
        cou++;
      arr[i] = arr[i] / 2;
      if (arr[i] == 0)
        break;
    }
  }
  cout << cou << endl;

  return 0;
}


Measured memory_bytes: 384
from collections import Counter
N = int(input())
A = Counter([int(i) for i in input().split()])
mt4 = []
mt2 = []
for k, v in A.items():
    if v >= 4:
        mt4.append(k)
        mt2.append(k)
    elif v >= 2:
        mt2.append(k)

ans = 0
if len(mt4) != 0:
    ans = max(mt4) ** 2
if len(mt2) >= 2:
    mt2.sort(reverse = True)
    ans = max(ans, mt2[0] * mt2[1])

print(ans)

Measured memory_bytes: 18600
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int a,b,p=0,c=0;
	cin>>a>>b;
	for(int i=a;i<=b;i++)
	{
		int x=i;
		while(x>0)
		{
			p=(p*10)+(x%10);
			x/=10;
		}
		if(p==i)
		{
			c++;
		}
		p=0;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3576
#include<iostream>
using namespace std;
int main()
{
    // 標準入力１行目、２行目の数字の数
    int n;
    cin >> n;
    //３つの要素を順に取り出してa~cの変数にほりこむ
    int a;
    cin >> a;
    int b;
    cin >> b;
    int c;
    cin >> c;
    
    //条件を満たすPの数カウント用変数を i とする
    int i;
    i = 0 ;
    
    /* 繰り返し */
    
    for (int j = 0; j < ( n - 1); j++) {
        
        // 連続する数の大小判定
        if (a < b && b < c) {
            i = i + 1;
        } else if ( a > b && b > c) {
            i = i + 1;
        }
        // 変数aにb, bにcを代入し、cを標準出力より取得
        a = b;
        b = c;
        cin >> c;
    }
    // 出力
    cout << i << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,M,ans=1e9,L,sum;
int main(){
	cin>>n>>M;
	int a[n];
	r(i,n)cin>>a[i];
	for(int R=0;R<n;R++){
		sum+=a[R];
		while(sum>=M){
			ans=min(ans,(R-L)+1);
			sum-=a[L++];
		}
	}
	cout<<(ans==1e9?0:ans)<<endl;
}


Measured memory_bytes: 3500