akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
typedef long long LL;

int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, i, a, count, max_c, ans = 1;

    cin >> n;
    max_c = 0;
    for (i=2; i<=n; i++) {
        a = i;
        count = 0;
        while (a >= 2) {
            if (a%2)
                break;
            a /= 2;
            count++;
        }
        if (count >= max_c) {
            max_c = count;
            ans = i;
        }
    }
    cout << ans;
}



Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))

A = [0 for _ in range(N)]

# A[0] = B[0]
for i in range(N-1):
    # とりあえず両方入れる
    A[i] = B[i]
    A[i+1] = B[i]

    # 上書きされた結果条件を満たさないなら書き換える
    if i >= 1:
        if A[i] > B[i-1]:
            A[i] = B[i-1]

print(sum(A))


Measured memory_bytes: 3060
X = int(input())
dp = [0 for i in range(100001)]
for i in range(100, 106):
    dp[i] = 1

for i in range(len(dp)):
    if dp[i] == 1:
        for j in range(100, 106):
            if i + j <= 100000:
                dp[i + j] = 1

print(dp[X])

Measured memory_bytes: 44784
#include <stdio.h>
#define MAX 210

int n;
int num[MAX];

void slove(int cnt) {
	int i;
	for(i=1;i<=n;i++) {
		if(num[i]%2) break;
		num[i]/=2;
	}
	
	if(i>n) slove(cnt+1);
	else printf("%d", cnt);
}

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

Measured memory_bytes: 128
#include <stdio.h>
#define M 100000
#define N -1

struct Node{
int parent,left,right;
};
struct Node T[M];
int D[M];

void print(int u){
  int c,i;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("depth = %d, ",D[u]);

  if(T[u].parent == N){
    printf("root, ");
  }
  else if(T[u].left == N){
    printf("leaf, ");
  }
  else printf("internal node, ");

  printf("[");

  c=T[u].left;
  for(i=0;c!=N;i++){
    if(i!=0)printf(", ");
      printf("%d",c);
  c=T[c].right;
  }

  printf("]\n");

}

void setdepth(int u,int p){
  D[u]=p;
  if(T[u].right != N) setdepth(T[u].right,p);
  if(T[u].left != N) setdepth(T[u].left,p+1);
}

int main(){
  int i,j,n,o,p,q,r,l;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].parent=N;
      T[i].left=N;
      T[i].right=N;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&o,&p);
    for(j=0;j<p;j++){
      scanf("%d",&q);
      if(j==0)T[o].left=q;
      else T[l].right=q;
      l=q;
      T[q].parent=o;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].parent == N)r=i;
  }
  setdepth(r,0);

  for(i=0;i<n;i++)print(i);

  return 0;
}




Measured memory_bytes: 6448
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)
int main()
{
  string s;
  while(cin >> s) {
    int jcnt = 0,icnt = 0;
    Rep(i,s.size() - 2) {
      if(s[i + 2] == 'I' && s[i + 1] == 'O') {
	if(s[i] == 'J') {
	  jcnt++;
	}else if(s[i] == 'I') {
	  icnt++;
	}
      }
    }
    cout << jcnt << endl << icnt << endl;
  }
  return 0;
}

  

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

int main() {
    int h, w, n, sh, sw, nh, nw;
    string s, t;
    bool ans = true;
    cin >> h >> w >> n >> sh >> sw >> s >> t;
    auto reset_pos = [&]() { nh = sh; nw = sw; };
    auto is_out = [&]() { return (nh <= 0 || h < nh || nw <= 0 || w < nw);};
    
    // L のみ移動
    reset_pos();
    for (int i = 0; i < n; i++) {
        if (s[i] == 'L') nw--;
        if (is_out()) ans = false;
        if (t[i] == 'R' && nw < w) nw++;
    }
    
    reset_pos();
    for (int i = 0; i < n; i++) {
        if (s[i] == 'R') nw++;
        if (is_out()) ans = false;
        if (t[i] == 'L' && 1 < nw) nw--;
    }
    
    reset_pos();
    for (int i = 0; i < n; i++) {
        if (s[i] == 'U') nh--;
        if (is_out()) ans = false;
        if (t[i] == 'D' && nh < h) nh++;
    }
    
    reset_pos();
    for (int i = 0; i < n; i++) {
        if (s[i] == 'D') nh++;
        if (is_out()) ans = false;
        if (t[i] == 'U' && 1 < nh) nh--;
    }
    
    cout << (ans ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 776
#include <algorithm>
#include <cstdio>
#include <utility>
#include <vector>

using namespace std;

#define int long long
#define dotimes(i, n) for (int i = 0, i##max__ = (n); i < i##max__; i++)
#define whole(x, f, ...) ([&](decltype((x)) c) { return (f)(begin(c), end(c), ## __VA_ARGS__); })(x)

int rint() {
  int x;
  scanf("%lld", &x);
  return x;
}

void wint(int x) {
  printf("%lld\n", x);
}

template<typename T> int size(T const& c) { return static_cast<int>(c.size()); }
template <typename T> bool maxs(T& a, T const& b) { return a < b ? a = b, true : false; }
template <typename T> bool mins(T& a, T const& b) { return a > b ? a = b, true : false; }

signed main() {
  const int N = rint();
  vector<pair<int, int>> cxs, cys;
  cxs.reserve(2*N);
  cys.reserve(2*N);
  dotimes(i, N) {
    cxs.emplace_back(rint(), 2*i);
    cys.emplace_back(rint(), 2*i);
    cxs.emplace_back(rint(), 2*i+1);
    cys.emplace_back(rint(), 2*i+1);
  }
  // compress
  auto second_lt = [](pair<int, int> p1, pair<int, int> p2) { return p1.second < p2.second; };
  whole(cxs, sort);
  vector<int> xs;
  xs.emplace_back(cxs[0].first);
  dotimes(i, 2*N) {
    if (xs.back() != cxs[i].first)
      xs.emplace_back(cxs[i].first);
    cxs[i].first = ::size(xs)-1;
  }
  whole(cxs, sort, second_lt);
  whole(cys, sort);
  vector<int> ys;
  ys.emplace_back(cys[0].first);
  dotimes(i, 2*N) {
    if (ys.back() != cys[i].first)
      ys.emplace_back(cys[i].first);
    cys[i].first = ::size(ys)-1;
  }
  whole(cys, sort, second_lt);
  // imoz
  vector<vector<int>> board(ys.size(), vector<int>(xs.size()));
  dotimes(i, N) {
    board[cys[2*i].first][cxs[2*i].first]++;
    board[cys[2*i].first][cxs[2*i+1].first]--;
    board[cys[2*i+1].first][cxs[2*i].first]--;
    board[cys[2*i+1].first][cxs[2*i+1].first]++;
  }
  dotimes(j, ys.size()) dotimes(i, xs.size()-1) board[j][i+1] += board[j][i];
  dotimes(i, xs.size()) dotimes(j, ys.size()-1) board[j+1][i] += board[j][i];
  int r = 0;
  dotimes(j, ys.size()-1) dotimes(i, xs.size()-1) if (board[j][i]) r += (ys[j+1] - ys[j]) * (xs[i+1] - xs[i]);
  wint(r);
  return 0;
}



Measured memory_bytes: 127800
using System;

class Ab
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    int C = 0;
    for (int i = 1; i <= N; i++) {
      if (i.ToString().Length % 2 == 1) {
        C++;
      }
    }
    Console.WriteLine(C);
  }
}

Measured memory_bytes: 13140
from collections import namedtuple
Card = namedtuple('Card', 'suit value')

def BubbleSort(C):
    for i in range(len(C)):
        for j in range(len(C)-1,i,-1):
            if C[j].value < C[j-1].value:
                C[j],C[j-1] = C[j-1],C[j]

def SelectionSort(C):
    for i in range(len(C)):
        mini = i
        for j in range(i,len(C)):
            if C[j].value < C[mini].value:
                mini = j
        C[i],C[mini] = C[mini],C[i]

def checkStable(C0, C1):
    result = True
    for i in range(1,10):
        f0 = [x.suit for x in list(filter(lambda c: c.value==i,C0))]
        f1 = [x.suit for x in list(filter(lambda c: c.value==i,C1))]
        if f0!=f1:
            result = False
    return result

if __name__=='__main__':
    N = int(input()) 
    Co = list(map(lambda X: Card(X[0],int(X[1])), map(list, input().split())))
    Cb,Cs = [Co[:] for _ in range(2)]
    for C, Sort in zip([Cb,Cs], [BubbleSort, SelectionSort]):
        Sort(C)
        print(*["".join([X.suit,str(X.value)]) for X in C])
        print("Stable" if checkStable(Co,C) else "Not stable")

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

int main()
{
	int n;
	cin>>n;
	vector<int> a(26,50);
	for(int i=0;i<n;i++)
	{
		string s;
		cin>>s;
		vector<int> b(26);
		for(int j=0;j<s.size();j++)
		b[s[j]-'a']++;
		for(int j=0;j<26;j++)
		a[j]=min(a[j],b[j]);
	}
	string ans;
	for(int i=0;i<26;i++)
	{
	for(int j=0;j<a[i];j++)
	{
		ans+=('a'+i);
	}}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations
n=int(input())
d={'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(n):
     s=input()
     if s[0] in d:
          d[s[0]]+=1
a=['M','A','R','C','H']
s=combinations(a,3)
cnt=0
for x in s:
     cnt+=d[x[0]]*d[x[1]]*d[x[2]]
print(cnt)

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

a = list(map(int, input().split()))
defo = sum(a)
default = [0]*100001
for i in a:
  default[i]+=1

q = int(input())
for _ in range(q):
  b, c = map(int, input().split())
  defo = defo + (c-b)*default[b]
  print(defo)
  default[c] += default[b]
  default[b] = 0

Measured memory_bytes: 20876
import Control.Applicative
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = getLine >> solve <$> f >>= print
  where
    f = readil B.readInteger <$> B.getLine

solve :: [Integer] -> Integer
solve = foldl f 1
  where
    f (-1) 0 = 0
    f (-1) _ = (-1)
    f m x = let mx = m * x in
              if mx > 1000000000000000000 then (-1) else mx

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')


Measured memory_bytes: 9452
import copy


# k = 1の場合の転倒数を求める
def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -1):
            if A[j] < A[j - 1]:
                A[j], A[j - 1] = A[j - 1], A[j]
                cnt += 1
    return cnt


n, k = map(int, input().split())
a = list(map(int, input().split()))
# aはソートされてしまうので、元の並びを複製する
b = copy.deepcopy(a)
# k = 1の場合の転倒数が初項となる等差数列
initial = bubble_sort(a)
ans = initial
bigger = [0] * n
# bigger[i]: リストaに含まれる要素1つに着目した際に、その要素よりも小さい要素の個数
# ex. a = [1,3,4] のとき、 bigger[1] = 1
# 3より小さいのは1のみであるため。
for i in range(n):
    cnt = 0
    for j in b:
        if b[i] > j:
            cnt += 1
    bigger[i] = cnt
# biggerの合計が公差となる
d = sum(bigger)
# 等差数列の和の公式
ans = k * (2 * initial + d * (k - 1)) // 2
print(ans % (10 ** 9 + 7))


Measured memory_bytes: 3700
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> v(N);
    for (int i = 0; i < N; i++) cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end(), [](const auto& p, const auto& q) {
        return p.first + p.second < q.first + q.second;
    });
    int ans = 0, x = 0;
    for (const auto& p : v) {
        if (max(0, p.first - p.second) < x) continue;
        ans++;
        x = p.first + p.second;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

const ll MOD = 1000000007;

template <int MOD>
struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0) v += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
  constexpr Fp operator+(const Fp& r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator-(const Fp& r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator*(const Fp& r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator/(const Fp& r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp& operator+=(const Fp& r) noexcept {
    val += r.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  constexpr Fp& operator-=(const Fp& r) noexcept {
    val -= r.val;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr Fp& operator*=(const Fp& r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp& operator/=(const Fp& r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
      long long t = a / b;
      a -= t * b;
      swap(a, b);
      u -= t * v;
      swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr bool operator==(const Fp& r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator!=(const Fp& r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream& operator<<(ostream& os, const Fp<MOD>& x) noexcept {
    return os << x.val;
  }
  friend constexpr istream& operator>>(istream& is, Fp<MOD>& x) noexcept {
    return is >> x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
    if (n == 0) return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1) t = t * a;
    return t;
  }
  friend constexpr Fp<MOD> modinv(const Fp<MOD>& a) noexcept {
    return modpow(a, MOD - 2);
  }
};

using mint = Fp<MOD>;

int N;
vector<string> S(2);
int main() {
  cin >> N;
  cin >> S[0] >> S[1];

  mint ans = (S[0][0] == S[1][0] ? 3 : 6);
  rep(i, N - 1) {
    if (S[0][i] == S[0][i + 1] && S[1][i] == S[1][i + 1]) continue;

    if (S[0][i] == S[1][i]) {
      ans *= 2;
    } else if (S[0][i + 1] != S[1][i + 1]) {
      ans *= 3;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

using Graph = vector<vector<int>>;
using P = pair<int, int>;

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

    int a, b, m;
    cin >> a >> b >> m;
    vector<int> v1(a);
    vector<int> v2(b);
    int MIN1 = 1001001001;
    int MIN2 = 1001001001;
    for (int i = 0; i < a; i++)
    {
        cin >> v1[i];
        MIN1 = min(MIN1, v1[i]);
    }
    for (int i = 0; i < b; i++)
    {
        cin >> v2[i];
        MIN2 = min(MIN2, v2[i]);
    }
    int ans = MIN1 + MIN2;
    for (int i = 0; i < m; i++)
    {
        int x, y, c;
        cin >> x >> y >> c;
        x--;
        y--;
        ans = min(ans, v1[x] + v2[y] - c);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var N, M, X int
	fmt.Scan(&N, &M, &X)

	var a int
	l, r := 0, 0
	for i := 0; i < M; i++ {
		fmt.Scan(&a)
		if a < X {
			l++
		} else if a > X {
			r++
		}
	}

	ans := l
	if r < l {
		ans = r
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 100001
vector<vector<int> > arr(max1);




int main(){	
	string s,t;
	cin>>s>>t;
	int n=s.length();
	int m=t.length();
	int flag=0;
	if(n+1==m){
		if(t.substr(0,n)==s){
			flag=1;
		}
	}
	if(flag){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 5428
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 100010;
 
int n;
int tot = -1, head[N];
struct Edge {
    int p, nxt;
    Edge(int p = 0, int nxt = 0) : p(p), nxt(nxt) {}
} edge[N * 2];
inline void Add(int u, int v) {
    edge[++tot] = Edge(v, head[u]);
    head[u] = tot;
    return;
}
 
int f[N], g[N], c[N];
 
void DFS1(int u, int fa) {
    for (int i = head[u]; ~i; i = edge[i].nxt) {
        int v = edge[i].p;
        if (v == fa) continue;
        DFS1(v, u);
        if (f[v]) g[u] += f[v];
        else ++c[u];
    }
    f[u] = g[u] + max(c[u] - 1, 0);
    return;
}
 
int res;
 
void DFS2(int u, int fa, int ff) {
    if (fa) res = min(res, g[u] + ff + max(c[u] + !ff - 1, 0));
    else res = min(res, f[u]);
    for (int i = head[u]; ~i; i = edge[i].nxt) {
        int v = edge[i].p;
        if (v == fa) continue;
        if (fa) DFS2(v, u, g[u] - f[v] + ff + max(c[u] - !f[v] + !ff - 1, 0));
        else DFS2(v, u, g[u] - f[v] + max(c[u] - !f[v] - 1, 0));
    }
    return;
}
 
int main() {
    scanf("%d", &n);
    if (n == 1) {
        puts("0");
        return 0;
    }
    memset(head, -1, sizeof(head));
    for (int i = 1; i < n; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        ++u;
        ++v;
        Add(u, v);
        Add(v, u);
    }
    DFS1(1, 0);
    res = n;
    DFS2(1, 0, 0);
    printf("%d\n", res + 1);
    return 0;
}

Measured memory_bytes: 9216
#!/usr/bin/perl -w
#https://atcoder.jp/contests/abc141/tasks/abc141_b

use strict;
chomp(my @string = split //, <>);

my $length = @string;
my $easy = 0;

for (my $i = 0; $i < $length; $i++) {
  if ($i % 2 == 0) {#odd
    if ($string[$i] eq "L") {
      $easy = 1;
      last;
    }
  }else{            #even
    if ($string[$i] eq "R") {
      $easy = 1;
      last;
    }
  }
}

if ($easy == 0) {
  print "Yes";
} else {
  print "No";
}


Measured memory_bytes: 512
#include"bits/stdc++.h"
using namespace std;
int main(){
	int n;
	cin >> n;
	int ans = 0;
	vector<int> x, y;
	for(int i = 0; i != n; ++i){
		int a;
		cin >> a;
		x.push_back(a);
	}
	for(int i = 0; i != n; ++i){
		int a;
		cin >> a;
		y.push_back(a);
	}
	for(int i = 0; i != n; ++i){
		if(x[i] > y[i])
			ans += x[i] - y[i];
	}
	cout << ans;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	ios_base::sync_with_stdio(0); cin.tie(0);
 	int h, w, n;
 	cin >> h >> w >> n;
 	if (h >= w) cout << (n - 1) / h + 1 << '\n';
 	else cout << (n - 1) / w + 1 << '\n';
 	return 0;
}

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

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

  for(int i = 9;i >= 1;i--) {
    if(N%i == 0) {
      if(N/i < 10) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl; 
}


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

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    int N,K,Q;
    cin>>N>>K>>Q;
    map<int,int> dict;
    for(int i = 0;i < Q;i++) {
        int a;
        cin>>a;
        a--;
        dict[a]++;
    }

    for(int i = 0;i < N;i++) {
        if(K-Q+dict[i] > 0) {
            cout<<"Yes"<<endl;
        } else {
            cout<<"No"<<endl;
        }
    }

    return 0;
}


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

using namespace std;

int main(){
    long long N,T;
    cin>>N>>T;
    vector <long long>t(N);
    for(int i=0 ; i<N ; i++){
        cin>>t[i];
    }
    
    long long ans = T;
    for(int i=1 ; i<N ; i++){
        if (t[i] - t[i-1] < T)ans += t[i] - t[i-1];
        else ans += T;
    }

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


Measured memory_bytes: 1792
n, k = map(int, input().split())
h = list(map(int, input().split()))

#def cost(i,j):
#    return abs(h[i] - h[j])

dp=[10**9]*n
dp[0]=0

for i in range(1,n):
    for j in range(i-k,i):
        if j>=0:
            cst = dp[j]+abs(h[i] - h[j])
            if dp[i] > cst:
                dp[i]=cst

print(dp[n-1])

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

int clog2(int n){
  n--;
  int res = 0;
  while(n > 0)res++, n >>=1;
  return res;
}

struct LCA{
  int n, root, logn;
  vector<int> lvl;
  vector<vector<int>> ady, up;

  LCA(vector<vector<int>> ady, int root):
    ady(ady), n(ady.size()), root(root), logn(clog2(n)){init();}

  void init(){
    up.assign(n, vector<int>(logn + 1));
    lvl.assign(n, 0);
    dfs(root, root, 0);
    for(int p = 1; p <= logn; p++){
      for(int i = 0; i < n; i++){
	up[i][p] = up[up[i][p - 1]][p - 1];
      }
    }
  }

  void dfs(int v, int p, int l){
    lvl[v] = l;
    up[v][0] = p;
    for(int u : ady[v]){
      if(u != p) dfs(u, v, l + 1);
    }
  }

  int jump(int u, int d){
    for(int p = logn; p >= 0; p--){
      if(d & (1 << p)) u = up[u][p];
    }
    return u;
  }
  
  int lca(int u, int v){
    if(lvl[u] > lvl[v]) swap(u, v);
    v = jump(v, lvl[v] - lvl[u]);
    if(u == v) return u;
    for(int p = logn; p >= 0; p--){
      if(up[u][p] != up[v][p]){
	u = up[u][p], v = up[v][p];
      }
    }
    return up[u][0];
  }
};

// test: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_5_C

int main(){
  int n;
  cin >> n;
  vector<vector<int>> ady;
  for(int i = 0; i < n; i++){
    int k;
    cin >> k;
    vector<int> v(k);
    for(int j = 0; j < k; j++){
      cin >> v[j];
    }
    ady.push_back(v);
  }
  LCA lca(ady, 0);
  int q;
  cin >> q;
  while(q--){
    int u, v;
    cin >> u >> v;
    cout << lca.lca(u, v) << endl;
  }
}



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

using namespace std;
int main(){
    int i,n,a = 0,b = 0,c = 0,d = 0; cin >> n;
    for(i=0;i<n;i++){
        string s; cin >> s;
        if(s[0]=='A') a++;
        if(s[0]=='W') b++;
        if(s[0]=='T') c++;
        if(s[0]=='R') d++;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << b << endl;
    cout << "TLE x " << c << endl;
    cout << "RE x " << d << endl;
 }

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false) ; cin.tie(NULL) ; cout.tie(NULL);
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007


int32_t main(){
    IOS;

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

cout<<dp[n-1]<<endl;


}


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

 main()
 {  int n,i,a,st=0,m,s=0;
 cin>>n;


for(i=0;i<n;i++)
{cin>>a;
s=s+a;
st=st+(a*(a-1))/2;

}
m=(s*(s-1))/2;

cout<<m-st<<endl;



return 0;

}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;

bool check(string s1, string s2) {
	REP(i, s1.size()) {
		if(s1[i] == '*') {
			continue;
		} else if(s1[i] != s2[i]) {
			return false;
		}
	}

	return true;
}

int main() {
	int n, m;

	while(cin >> n >> m, n) {
		vs number(n);
		vi prize(n);
		int money = 0;

		REP(i, n) {
			cin >> number[i] >> prize[i];
		}
				
		string kuji;
		REP(i, m) {
			cin >> kuji;

			REP(j, n) {
				if(check(number[j], kuji)) {
					money += prize[j];
					break;
				}
			}
		}

		cout << money << endl;
	}
}

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

int main()
{
    int num;
    int blood[4] = {};

    char p;
    string b;

    while( cin >> num >> p >> b )
    {
        if( b == "A" )
            blood[0]++;
        if( b == "B" )
            blood[1]++;
        if( b == "AB" )
            blood[2]++;
        if( b == "O" )
            blood[3]++;
    }
    for( int i = 0; i < 4; i++ )
    cout << blood[i] << endl;
    return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N; cin >> N;
    string S; cin >> S;
    VI b(N+1,0), w(N+1,0);
    REP(i,N){
        if(S[i]=='.') w[i+1] += 1;
        else b[i+1] += 1;
        b[i+1] += b[i];
        w[i+1] += w[i];
    }

    VI n(N+1);
    REP(i,N+1){
        n[i] = b[i] + w[N] - w[i];
    }
    int ans = INT_INF;
    REP(i,N+1) chmin(ans, n[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2948
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	ll N, M;
	cin >> N >> M;
	vector<pll> AB(N);
	rep(i, N)
		cin >> AB[i].first >> AB[i].second;
	sort(AB.begin(), AB.end(), less <pll>());
	ll ans = 0;
	rep(i, N){
		ll A = AB[i].first;
		ll B = AB[i].second;
		ll buy_num = min(M, B);
		ans += A * buy_num;
		if (buy_num == M)
			break;
		else
			M -= B;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
class UnionFind:
    def __init__(self, n):
        self._par = [i for i in range(n + 1)]
        self._size = [1] * (n + 1)

    def find(self, x):
        if self._par[x] == x:
            return x
        else:
            self._par[x] = self.find(self._par[x])
            return self._par[x]

    def is_same_root(self, x, y):
        x = self.find(x)
        y = self.find(y)
        return x == y

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self._size[x] < self._size[y]:
            self._par[x] = y
            self._size[y] += self._size[x]
        else:
            self._par[y] = x
            self._size[x] += self._size[y]

    def size(self, x):
        return self._size[self.find(x)]


def main():
    n, m = [int(i) for i in input().split()]
    bridges = [[int(i) for i in input().split()] for _ in range(m)]

    union_find = UnionFind(n)
    connection = []
    for i, j in bridges[::-1]:
        if union_find.is_same_root(i, j):
            connection.append(0)
        else:
            connection.append(union_find.size(i) * union_find.size(j))
            union_find.unite(i, j)

    sum_ = 0
    for i in connection[::-1]:
        sum_ += i
        print(sum_)


if __name__ == '__main__':
    main()


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

#define lson(id) (id<<1)
#define rson(id) ((id<<1)|1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int mo=998244353;
const int maxn=400007;

int head[maxn],fa[maxn],a[maxn],lz[maxn<<2],sgt[maxn<<2];
struct EDGE{
	int to,nxt;
}edge[maxn<<1];
void addedge(int u,int v){
	static int sz=0;edge[++sz].to=v;
	edge[sz].nxt=head[u];head[u]=sz;
}

void change(int id,int w){
	sgt[id]=w;
	lz[id]=w;
}

void pushdown(int id){
	if(lz[id]){
		change(lson(id),lz[id]);
		change(rson(id),lz[id]);
		lz[id]=0;
	}
}

int query(int id,int l,int r,int pos){
//	printf("Q %d %d %d %d\n",id,l,r,pos);
	if(l==r) return sgt[id];
	int mid=(l+r)/2;
	pushdown(id);
	if(pos<=mid)return query(lson(id),l,mid,pos);
	else return query(rson(id),mid+1,r,pos);
}

void update(int id,int l,int r,int L,int R,int w){
//	printf("U %d %d %d %d %d %d\n",id,l,r,L,R,w);
	if(l>=L&&r<=R){
		change(id,w);
		return ;
	}
	if(l>R||L>r) return ;
	int mid=(l+r)/2;
	pushdown(id);
	update(lson(id),l,mid,L,R,w);
	update(rson(id),mid+1,r,L,R,w);
}

int f[maxn],n;
void dfs(int u){
	int mul=1,to;
	for(int i=head[u];i;i=edge[i].nxt){
		to=edge[i].to;
		dfs(to);
		mul=1ll*mul*f[to]%mo;
	}
	f[u]=(mul+1)%mo;
}

pii tmp[maxn],robot[maxn];
int tn;
int main(){
	scanf("%d",&tn);
	for(int i=1;i<=tn;++i){
		scanf("%d%d",&tmp[i].first,&tmp[i].second);
		tmp[i].second+=tmp[i].first-1;
	}
	sort(tmp+1,tmp+tn+1);
	for(int i=1;i<=tn;++i){
		if(i==n||tmp[i].first!=tmp[i+1].first)
			robot[++n]=tmp[i]; 
	}
	for(int i=1;i<=n;++i){
		a[i*2-1]=robot[i].first;
		a[i*2]=robot[i].second;
//		printf("(%d %d)\n",robot[i].first,robot[i].second);
	}
//	puts("###");
	sort(a+1,a+2*n+1);
	int N=unique(a+1,a+2*n+1)-a-1;
	for(int i=1;i<=n;++i){
		robot[i].first=lower_bound(a+1,a+N+1,robot[i].first)-a;
		robot[i].second=lower_bound(a+1,a+N+1,robot[i].second)-a;
//		printf("(%d %d)\n",robot[i].first,robot[i].second);
		fa[i]=query(1,1,N,robot[i].first);
		update(1,1,N,robot[i].first,robot[i].second,i);
	}
//	puts("^^^");
	for(int i=1;i<=n;++i){
		addedge(fa[i],i);
//		printf("%d -> %d\n",fa[i],i);
	}
	dfs(0);
	printf("%d\n",(f[0]+mo-1)%mo);
	return 0;
}



Measured memory_bytes: 37760
import sys

n, q = map(int, sys.stdin.readline().split())
g = [[] for _ in range(n+1)]
for _ in range(n-1):
    a, b = map(int, sys.stdin.readline().split())
    g[a].append(b)
    g[b].append(a)

px = zip(*[map(int, sys.stdin.read().split())] * 2)

def main():
    value = [0] * (n + 1)
    for p, x in px:
        value[p] += x
    
    stack = [1]
    par = [None] * (n + 1)
    while stack:
        u = stack.pop()
        for v in g[u]:
            if v != par[u]:
                par[v] = u
                value[v] += value[u]
                stack.append(v)
    
    return value[1:]
    
if __name__ == '__main__':
    ans = main()
    print(*ans, sep=' ')

Measured memory_bytes: 74680
# include <bits/stdc++.h>
# define FILE

using namespace std;

int main(){

    # ifdef FILEs
        freopen( "input.txt", "r", stdin );
        freopen( "output.txt", "w", stdout );
    # endif
        int x;
        cin >> x;
        for( int i = x; i; i ++ ){
        	bool t= true;
        	for( int j = 2; j * j <= i; j ++ ){
        		if( i % j == 0 )t = false;
        	}
        	if( t ){
        		cout << i;
        		exit( 0 );
        	}
        }
}	




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  bool done = 0;
  long long a[100001], ans = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0;
      done = 1;
    }
  }  
  for (int i = 0; i < n; i++) {
    if (done) break;
    if (((1000000000000000000 / a[i]) < ans)) {
      cout << -1;
      break; 
    }
    else {
      ans *= a[i];
      if (i == n-1) cout << ans;
    }
    
  }
}

Measured memory_bytes: 4396
from collections import deque
q=int(input())
lis=deque()
lq=[]
for i in range(q):
	lq.append([int(x) for x in input().split(' ')])

for i in lq:
	order=i[0]
	if order==0:
		d=i[1]
		if d==0:
			lis.appendleft(i[2])
		else:
			lis.append(i[2])
	elif order==1:
		print(lis[i[1]])
	elif order==2:
		d=i[1]
		if d==0:
			lis.popleft()
		else:
			lis.pop()







Measured memory_bytes: 63204
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
using namespace std;

int n, k;
int rk[300100];
int tmp[300100];

bool compare_sa(int i, int j) {
	if(rk[i] != rk[j]) return rk[i] < rk[j];
	int ri, rj;
	ri = i + k <= n ? rk[i+k] : -1;
	rj = j + k <= n ? rk[j+k] : -1;
	return ri < rj;
}

void constract_sa(const string & s, vector<int> & v) {
	v.resize(s.size()+1);
	n = s.size()+1;
	for(int i = 0; i < v.size(); i++)
		v[i] = i;
	for(int i = 0; i < s.size(); i++)
		rk[i] = s[i]+1;
	rk[s.size()] = 0;
	for(k = 1; k <= n; k *= 2) {
		sort(v.begin(), v.end(), compare_sa);
		tmp[v[0]] = 0;
		for(int i = 1; i < v.size(); i++) {
			if(compare_sa(v[i-1], v[i]))
				tmp[v[i]] = tmp[v[i-1]] + 1;
			else
				tmp[v[i]] = tmp[v[i-1]];
		}
		for(int i = 0; i <= n; i++) {
			rk[i] = tmp[i];
		}

	}
}

void construct_lcp(const string & s, const vector<int> & sa, vector<int> & lcp) {
	int n = s.size();
	lcp.resize(n);
	for(int i = 0; i <= n; i++) rk[sa[i]] = i;
	int h = 0;
	lcp[0] = 0;
	for(int i = 0; i < n; i++) {
		assert(rk[i]-1 >= 0);
		int j = sa[rk[i]-1];
		if(h > 0) h--;
		for(; j + h < n && i + h < n; h++) {
			if(s[j+h] != s[i+h]) break;
		}
		lcp[rk[i]-1] = h;
	}
}

int main() {
	string S, T;
	vector<int> sa[2];
	vector<int> same[2];
	cin >> S >> T;

	for(int i = 0; i < 2; i++) {
		int len = 0;
		constract_sa(S, sa[i]);
		same[i].resize(sa[i].size());
		vector<int> lcp;
		construct_lcp(S, sa[i], lcp);
		for(int j = 0; j < sa[i].size(); j++) {
			if(j && lcp[j-1] < len) len = lcp[j-1];
			while(len > 0 && S[sa[i][j]+len-1] != T[len-1])
				len--;
			for(int k = sa[i][j]+len; k < S.size() && len < T.size(); k++) {
				if(S[k] == T[len]) len++;
				else break;
			}
			same[i][sa[i][j]] = len;
		}
		reverse(T.begin(),T.end());
		reverse(S.begin(),S.end());
	}

	/*
	for(int i = 0; i < 2; i++) {
		for(int j = 0; j < sa[i].size(); j++) {
			cout << j << ":" << sa[i][j] << endl;
		} cout << endl;
	}
	for(int i = 0; i < 2; i++) {
		for(int j = 0; j < same[i].size(); j++) {
			cout << same[i][j] << " ";
		} cout << endl;
	}
	// */

	int res = 0;
	for(int i = 0; i < same[0].size(); i++) {
		if(0 <= (int)S.size()-(int)(T.size()+i) && same[0][i] + same[1][S.size()-(T.size()+i)] == T.size()-1) {
			res++;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 9972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
#define v_inputrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)

int main(){
    string w;
    cin >> w;
    map<char, int> mp;
    rep(i, w.length()){
        mp[w[i]]++;
    }

    bool flag = true;

    for(auto itr = mp.begin() ; itr != mp.end() ; itr++){
        if(itr->second % 2 == 1){
            flag = false;
        }
    }

    if(flag){cout << "Yes";}
    else{cout << "No";}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pq priority_queue

using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> nums(3 * n);
    //sliding window
    for (int i = 0; i < 3 * n; i++) {
        cin >> nums[i];
    }
    //look at first n
    vector<int> scores_A(n + 1);
    pq<int, vector<int>, greater<int>> A;
    int init_score = 0;
    for (int i = 0; i < n; i++) {
        A.push(nums[i]);
        init_score += nums[i];
    }
    scores_A[0] = init_score;
    //push for next n
    for (int i = n; i < 2 * n; i++) {
        if (A.top() < nums[i]) {
            A.push(nums[i]);
            scores_A[i - n + 1] = scores_A[i - n] + (nums[i] - A.top());
            A.pop();
        } else {
            scores_A[i - n + 1] = scores_A[i - n];
        }
    }
    //reverse for B
    vector<int> scores_B(n + 1);
    pq<int> B;
    init_score = 0;
    for (int i = 2 * n; i < 3 * n; i++) {
        B.push(nums[i]);
        init_score += nums[i];
    }
    scores_B[n] = init_score;
    //push for next n
    for (int i = 2 * n - 1; i >= n; i--) {
        if (B.top() > nums[i]) {
            B.push(nums[i]);
            scores_B[i - n] = scores_B[i - n + 1] - (B.top() - nums[i]);
            B.pop();
        } else {
            scores_B[i - n] = scores_B[i - n + 1];
        }
    }
    //find max
    int max_score = -9223372036854775807;
    for (int i = 0; i < n + 1; i++) {
        int score = scores_A[i] - scores_B[i];
        max_score = max(max_score, score);
    }
    cout << max_score;
}

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

int main(){
long long a;
  long long b[87];
  b[0]=2;
  b[1]=1;
  for(long long i=2;i<87;i++){
  b[i]=b[i-1]+b[i-2];
  }
  cin >>a;

    cout <<b[a];
  

return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
long long MOD = 1000000007;


template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }

long long dp[200100];

int main(){
    int N, T;
    cin >> N >> T;

    int ans = 9999;
    rep(i,N){
        int c, t;
        cin >> c >> t;

        if(t <= T)ans =min(ans,c);
    }
    
    if(9999 == ans)cout << "TLE" << endl;
    else cout << ans << endl;
}



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

int main(){
	bool yes=true;
	bool yes_ij;
	int h,w;
	vector<string> cam;
	string row;
	cin >> h >> w;
	
	for(int i=0;i<h;i++){
		cin >> row;
		cam.push_back(row);
	}
	for(int i=0;i<h&&yes;i++){
		for(int j=0;j<w;j++){
			if(cam[i][j]=='#'){
				yes_ij=false;
				if(i>0)yes_ij=yes_ij||cam[i-1][j]=='#';
				if(j>0)yes_ij=yes_ij||cam[i][j-1]=='#';
				if(i<h-1)yes_ij=yes_ij||cam[i+1][j]=='#';
				if(j<w-1)yes_ij=yes_ij||cam[i][j+1]=='#';
				yes=yes&&yes_ij;
			}
		}
	}
	if(yes){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100000

int n,k;
long long T[MAX];

int check(long long P){
	int i=0;
	for(int j=0;j<k;j++){
		long long s=0;
		while(s+T[i]<=P){
			s+=T[i];
			i++;
			if(i==n)return n;
		}
	}
	return i;
} 

int solve(){
	long long left = 0;
	long long right = 100000*10000;
	long long mid;
	while(right-left>1){
		mid=(left+right)/2;
		int v=check(mid);
		if(v>=n)right=mid;
		else left=mid;
	}
	return right;
}

int main() {
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>T[i];
	long long ans=solve();
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3904
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int n, h[101];

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

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

class Program
{
    static bool Check(long[] W, int k, long P)
    {
        long p = P;
        int wi = 0;
        for (int i = 0; i < k; i++)
        {
            while (true)
            {
                if (W[wi] <= p)
                {
                    p -= W[wi];
                    wi++;
                    if (wi == W.Length) return true;
                }
                else
                {
                    p = P;
                    break;
                }
            }
        }
        return wi == W.Length;
    }
    static long BinarySearch(long[] W, int k)
    {
        long min = 0;
        long max = 1000000000;
        long mid = 0;
        while (min < max)
        {
            mid = (min + max) / 2;
            bool flag = Check(W, k, mid);
            if (flag)
            {
                max = mid;
            }
            else
            {
                min = mid + 1;
            }
        }
        return max;
    }
    public static void Main(string[] args)
    {
        string[] s = Console.ReadLine().Split(' ');
        int n = int.Parse(s[0]);
        int k = int.Parse(s[1]);
        long[] W = new long[n];
        for (int i = 0; i < n; i++) W[i] = long.Parse(Console.ReadLine());
        Console.WriteLine(BinarySearch(W, k));
    }
}


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

int main() {
	// your code goes here
	char s[5]; cin >> s;
	if(strlen(s)==2) cout << s << endl;
	else{
		for(int i=2;i>=0;i--) cout << s[i];
		cout << endl;
	}
	return 0;
}

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

int main() {
  int n;
  int m;
  int a = 0;
  int x;
  int o;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d", &x);
    a += x;
  }
  o = n - a;
  if (o < 0) {
    o = -1;
  }
  printf("%d\n", o);
  return 0;
}


Measured memory_bytes: 1708
fun main(args: Array<String>) = p20()

fun p20() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }.toLongArray().sortedArray()
    val bList = readLine()!!.split(' ').map { it.toLong() }.toLongArray().sortedArray()
    val cList = readLine()!!.split(' ').map { it.toLong() }.toLongArray().sortedArray()

    var answer = 0L

    fun lowerBound(list: LongArray, key: Long): Int {
        var ng = -1
        var ok = list.size

        while (ok - ng > 1) {
            val mid = (ok + ng) / 2
            if (list[mid] >= key) ok = mid else ng = mid
        }
        return ok
    }

    for (b in bList) {
        answer += lowerBound(aList, b).toLong() * (n - lowerBound(cList, b + 1))
    }

    println(answer)
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << (1 <= a && a <= 9 && 1 <= b && b <= 9 ? a * b : -1) << "\n";
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace A___Product
{
    class Program
    {
        static void Main(string[] args)
        {
            var a_b = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = a_b[0];
            var b = a_b[1];

            Console.WriteLine((a * b) % 2 == 1 ? "Odd" : "Even");
        }
    }
}


Measured memory_bytes: 13396
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

#define errp(...) fprintf(stderr, __VA_ARGS__)

int main () { 
	int a,b,c,k,sum,n,m;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	 if(a<b)
		n=b,m=c+a;
	 else n=a,m=c+b;

	 if(n<c)
	 	n=c,m=a+b;

	 	for(int i=0;i<k;i++)
	 	{
	 		n=2*n;
	 	}
	sum=m+n;
	printf("%d",sum);
}

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

int main() {
  int N;
  cin>>N;
  
  vector<int> a(N);
  for(int i=0;i<N;++i){
    cin>>a[i];
  }
  
  int amax=0;
  int imax=0;
  for(int i=0;i<N;++i){
    if(a[i]>amax){
      amax=a[i];
      imax=i;
    }
  }
  
  for(int i=0;i<N;++i){
    if(i!=imax)
      cout<<amax<<endl;
    else{
      sort(a.begin(),a.end(),greater<int>());
      cout<<a[1]<<endl;
    }
  }
  
}

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

int main() {
  string S;
  cin >> S;
  
  sort(S.begin(), S.end());
  
  if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {

		for(int i=1;;i++){
			int val=sc.nextInt();
			if(val==0){
				break;
			}
			ln("Case "+i +": "+val);
		}
	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
import sys
sys.setrecursionlimit(10**6)

n=int(input())
edge=[[]for i in range(n+1)]

for i in range(n-1):
    u,v,w=map(int,input().split())
    if w%2==0:
        edge[u].append((v,1))
        edge[v].append((u,1))
    else:
        edge[u].append((v,-1))
        edge[v].append((u,-1))
        
color=[None]*(n+1)

def set_color(x,col):
    color[x]=col
    
    for i,j in edge[x]:
        if color[i] is None:
            set_color(i,j*col)

set_color(1,1)
for i in color[1:]:
    print((i+1)//2)

Measured memory_bytes: 76464
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(i, a) for (auto &i: (a))
#define sz(x) (int)(x).size()
#define all(v) (v).begin(), (v).end()
#define fr(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    clock_t beg = clock();
    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    #endif 
    int t = 1; 
    // cin >> t;    
    int tt = t;
    while (t--) {
        // cout << "Case #" << tt - t << ": "; 
        solve();
    }
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
    return 0;
}
const int N = 2e5 + 5;
vector<int> adj[N];
int dp[N];
int n;
int ans = 0;
void dfs (int v, int p) {
    if (v == 1) {
        ans += n;
    }
    else if (p > v) {
        ans += (p - v) * v;
    } 
    else if (v > p) {
        ans += (n - v + 1) * (v - p);
    }
    for (auto i : adj[v]) {
        if (i != p) 
            dfs(i, v);  
    }
}
void solve() {  
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1, 0);
    cout << ans;
}       

Measured memory_bytes: 23804
#include <iostream>
#include <unordered_map>
using namespace std;
unordered_map <int,int> ump;

int main()
{
    int N;
    cin >> N;
    int data[100010];
    int point=0;
    for (int i = 0 ; i<N; i++)
    {
        int a ;
        cin >> a;
        if (ump[a]!=0)
        {
            ump[a]++;
        }
        else
        {
            data[point] = a;
            point++;
            ump[a] = 1;
        }
    }
    int final_ans=0;
    for (int i = 0 ; i <point; i++)
    {
        if (ump[data[i]] >= data[i])
        {
            final_ans = final_ans + ump[data[i]]-data[i];
        }
        else
        {
            final_ans = final_ans + ump[data[i]];
        }
    }
    cout << final_ans;
}


Measured memory_bytes: 4644