akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >=0; --i)
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int,int>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} c(200005);

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

  ll ans = 0;
  if(n>1 && m>1) ans = (n-2) * (m-2);
  else if (n==1 && m >1) ans = m-2;
  else if (m==1 && n > 1) ans = n-2;
  else ans = 1;
  
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
N = int(input())
S = input()
count = 0
ans = 1
m = 10**9 + 7
 
for i in range(N):
  if S[2*i] == "W":
    ans = ans * ((2*i) - (count*2))%m
    count += 1
  if S[2*i + 1] == "B":
    ans = ans * ((2*i + 1) - (count*2))%m
    count += 1
 
if count != N:
  print(0)
else:
  for o in range(1, N+1):
    ans *= o
    ans %= m
  print(ans % m)

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

int main() {
  long long a,b,n;
  cin >> a >> b >> n;
  long long ans;
  if (n >= b - 1){
    ans = (a*(b-1))/b;
  }else{
    ans = (a*n)/b - a*(n/b);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

std::string S;

int main(int argc, char **argv) {
    std::cin >> S;

    for (int i = 0; i < 3; i++) {
        if (S[i] == S[i+1]) {
            std::cout << "Bad" << std::endl;
            return 0;
        }
    }

    std::cout << "Good" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,m,n) for(int i = m; i < n; ++i)
#define RFOR(i,m,n) for(int i = n - 1; i >= m; --i)
#define CIN(a) cin >> a
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a << endl
#define COUT2(a, b) cout << a << " " << b << endl
#define COUT3(a, b, c) cout << a << " " << b << " " << c << endl
#define pb push_back
#define PB push_back
#define VINT(v, n) vector<int> v(n); REP(i, n) { v[i] = 0 }
#define VINT2(v, n, m) vector<vector<int> > v(n, vector<int>(m)); REP(i, n) { REP(j, m) { v[i][j] = 0 } }
#define VCHAR(v, n) vector<char>v(n)
#define KIRIAGE(a, b) a += (b - a % b) % b
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
	set<int> s;
	REP(i, 3) {
		set<int>::iterator ite;
		int a;
		CIN(a);
		ite = s.find(a);
		if(ite == s.end()) {
			s.insert(a);
		}
	}
	COUT(s.size());
}


Measured memory_bytes: 256
def ans():
  N = int(input())
  AB = sorted([list(map(int,input().split())) for _ in range(N)], key = lambda x: -x[1])
  CD = sorted([list(map(int,input().split())) for _ in range(N)])
  cnt = 0
  for c, d in CD:
    for a, b in AB:
      if(a < c and b < d):
        cnt += 1
        AB.remove([a,b])
        break
  print(cnt)
ans()

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
	ll a, b, x;
	cin >> a >> b >> x;

	cout << ((a == 0) ? (b / x + 1) : (b / x - (a - 1) / x)) << '\n';
	return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTS(s) printf("%s\n",(s))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

typedef long long ll;


int main() {
	int M;
	scanf("%d", &M);
	PRINTD(48 - M);
}

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

int main(void)
{
    long long A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    if (2 * C >= A + B)
    {
        cout << A * X + B * Y << endl;
        exit(0);
    }
    else if(X >= Y && A > 2 * C)
    {
        cout << C * X * 2 << endl;
        exit(0);
    }
    else if(X >= Y && A <= 2 * C)
    {
        cout << C * Y * 2 + A * (X-Y) << endl;
        exit(0);
    }
    else if(Y > X && B > 2 * C)
    {
        cout << C * Y * 2 << endl;
        exit(0);
    }
    else if(Y > X && B <= 2 * C)
    {
        cout << C * X * 2 + B * (Y-X) << endl;
        exit(0);
    }
}

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

int main(){
	while(1){
		int H;
		cin>>H;

		if(H==0)
			break;

		int S[10][5];
		for(int y=0;y<H;y++)
			for(int x=0;x<5;x++)
				cin>>S[y][x];
	
		int sco=0;
	
		while(1){
			bool flg=false;
	
			for(int y=0;y<H;y++){
				int m=S[y][2];
				if(m==0)
					continue;
	
				if(S[y][0]==m&&S[y][1]==m){
					sco+=m*3;S[y][0]=S[y][1]=S[y][2]=0;flg=true;
					if(S[y][3]==m){
						sco+=m;S[y][3]=0;
						if(S[y][4]==m){
							sco+=m;S[y][4]=0;
						}
					}
				}
				else if(S[y][1]==m&&S[y][3]==m){
					sco+=m*3;S[y][1]=S[y][2]=S[y][3]=0;flg=true;
					if(S[y][4]==m){
						sco+=m;S[y][4]=0;
					}
				}
				else if(S[y][3]==m&&S[y][4]==m){
					sco+=m*3;S[y][2]=S[y][3]=S[y][4]=0;flg=true;
				}
			}
	
			if(!flg)
				break;
		
			for(int x=0;x<5;x++){
				for(int y=H-1;y>=0;y--){
					if(S[y][x]!=0)
						continue;

					for(int y2=y-1;y2>=0;y2--){
						if(S[y2][x]!=0){
							S[y][x]=S[y2][x];S[y2][x]=0;break;
						}
					}
				}
			}
		}

		cout<<sco<<endl;
	}

	return 0;
}


Measured memory_bytes: 3068
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def mi(): return map(int, input().split())


def li(): return list(mi())


def li_(): return [int(x) - 1 for x in input().split()]


def lin(n: int): return [input() for _ in range(n)]


def llin(n: int): return [li() for _ in range(n)]


def llin_(n: int): return [li_() for _ in range(n)]


def lli(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def f(): return float(input())


def s(): return input().replace('\n', '')


def main():
    N, W = mi()
    WV = llin(N)
    max_val = 0
    for i in range(N):
        max_val += WV[i][1]
    max_val += 1
    # dp[i][j]:=i番目の品で、価値がj以上になるように選んだときの最小重量
    dp = [[inf] * max_val for i in range(N)]
    for v in range(max_val):
        if v <= WV[0][1]:
            dp[0][v] = WV[0][0]
        else:
            break
    for i in range(1, N):
        for v in range(max_val):
            if v >= WV[i][1]:
                # print(dp[i - 1][v], dp[i - 1]
                #               [v - WV[i][1]] + WV[i][0])
                dp[i][v] = min(dp[i - 1][v], dp[i - 1]
                               [v - WV[i][1]] + WV[i][0])
            else:
                dp[i][v] = dp[i - 1][v]
            if v <= WV[i][1]:
                dp[i][v] = min(dp[i][v], WV[i][0])

    for v in reversed(range(max_val)):
        if dp[N-1][v] <= W:
            print(v)
            exit()


if __name__ == '__main__':
    main()


Measured memory_bytes: 299640
//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define cin(x) cin >> x

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    int N = 0;
    cin(N);

    vint a(N);
    REP(i,N) cin(a[i]);


    //本文
    int ans = 0;

    REP(i,N){
        int con = a[i];
        if(a[con-1] == i+1){
            ans ++;
        }
    }
    //出力
    cout << ans/2 << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

Measured memory_bytes: 3732
import sys
from heapq import heappush, heappop
import numpy as np

def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():

    def dijkstra(s):
        def push(v, s, x):
            if s < 0: 
                return
            if dist[v, s] <= x:
                return
            dist[v, s] = x
            heappush(que, (x, v, s))
        
        inf = 10**18
        dist = np.full((n, MAX_S+1), inf, dtype=int)
        # time, remain, node
        que = []
        push(0, s, 0)
        while que:
            x, v, s = heappop(que)
            if dist[v, s] < x:
                continue
            ns = min(s+c[v], MAX_S)
            push(v, ns, x+d[v])
            for nv, a, b in adj[v]:
                push(nv, s-a, x+b)
        return np.min(dist, axis=1)

    n, m, s = mi()
    adj = [[] for i in range(n)]
    MAX_S = 0
    for i in range(m):
        u, v, a, b = mi()
        u -= 1
        v -= 1
        adj[u].append((v, a, b))
        adj[v].append((u, a, b))
        MAX_S = max(MAX_S, a)
    MAX_S *= n-1
    s = min(s, MAX_S)
    c, d = [0]*n, [0]*n
    for i in range(n):
        c[i], d[i] = mi()
    ans = dijkstra(s)
    print(*ans[1:], sep='\n')


if __name__ == '__main__':
    main()

Measured memory_bytes: 38572
import java.util.Scanner;

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


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

int main(){
	string A,B,C;
	cin>>A>>B>>C;
	if(A[A.size()-1]==B[0]&&B[B.size()-1]==C[0]){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

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

int main() {
  int N, res = 0;  // N、答え

  cin >> N;
  for (int j = 1; j <= N; j *= 2) {  // 2^nで割る
    res = j;
  }

  cout << res << endl;
}


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

int main()
{
    int a;
    std::vector<int> dataSets;
    dataSets.reserve(10000);
    while (std::cin >> a) {
        if (a == 0) {
            break;
        }
        dataSets.push_back(a);
    }

    int cnt = 1;
    for (int x : dataSets) {
        std::cout << "Case " << cnt++  << ": " << x << std::endl;
    }

    return 0;
}


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

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

using namespace std;

int main() {
	int n;
	cin >> n;
	printf("ABC%03d\n", n);
	return 0;
}

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

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

    while(true){
        int n, x;
        std::cin >> n >> x;
        if(n==0 && x==0) break;
        int cnt = 0;
        for(int i=1; i<=n; ++i){
            for(int j=i+1; j<=n; ++j){
                for(int k=j+1; k<=n; ++k){
                    if(i+j+k==x) ++cnt;
                }
            }
        }
        std::cout << cnt << "\n";
    }
    return 0;
}

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

#define ll long long int
ll const mod = 1e9 + 7;

ll power(ll x, ll y, ll p){ //x^y % p
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {
        if (y & 1) // If y is odd, multiply x with result 
        res = (res*x) % p; 
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
}

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    double  m;
    cin>>n>>m;
    int a[n];
    double s=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        s+=a[i];
    }
    double req = s/(4*m);
    sort(a, a+n);
    int c=0;
    for(int i=n-1;i>=0;i--)
    {
        if(a[i]>=req)
        c++;
        else
        break;
    }
    if(c<m)
    cout<<"No";
    else
    cout<<"Yes";
    cout<<endl;
    
	// your code goes here
	return 0;
}


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

lint n;
set<string> st;

void dfs(string s, lint k) {
    if(s.length() == n) {
        st.insert(s);
        return;
    }

    for(lint i=0; i<k; i++) {
        s.push_back('a' + i);
        dfs(s, k);
        s.pop_back();
    }
    s.push_back('a'+k);
    dfs(s, k+1);
}

int main() {
    cin >> n;
    dfs("a", 1);

    for(auto e : st) {
        cout << e << endl;
    }
}

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

int main() {
  int n, s = 0, t = 0;
  cin >> n;
  vector<int> w(n);
  for(int i = 0; i < n; i++) {
    cin >> w.at(i);
    s += w.at(i);
  }
  for(int i = 0; i < n; i++) {
    t += w.at(i);
    if(t > s / 2) {
      cout << min(abs(s - t * 2), abs(s - t * 2 + w.at(i) * 2)) << endl;
      break;
    }
  }
}

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

vector <long long> par;

long long root(long long v){
	if (par[v] < 0)
		return v;
	return par[v] = root(par[v]);
}

bool merge(long long v, long long u){
	v = root(v);
	u = root(u);
	if (v == u)
		return false;
	if (par[v] > par[u])
		swap(v, u);
	par[v] += par[u];
	par[u] = v;
	return true;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n, m;
	cin >> n >> m;
	par.resize(n, -1);
	long long ans = n;
	for (long long i = 0; i < m; i++){
		long long x, y, z;
		cin >> x >> y >> z;
		x --;
		y --;
		if (merge(x, y))
			ans --;
	}
	cout << ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;


int main(){ 
    Int N; cin >> N;
    vector<int> p(N);
    rep(i,N) {
        cin >> p[i];
        p[i]--;
    }

    vector<Int> A(N), B(N);
    rep(i,N){
        A[i] = 30000 * (i+1);
        B[N-i-1] = 30000 * (i+1);
    }

    rep(i,N) A[p[i]] += i;

    rep(i,N) cout << A[i] << " ";
    cout << endl;
    rep(i,N) cout << B[i] << " ";
    cout << endl;

}


Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
mod=10**6+3

MUL=[1]
for i in range(1,mod):
    MUL.append(MUL[-1]*i%mod)

Q=int(input())
for i in range(Q):
    x,d,n=map(int,input().split())

    if d==0:
        print(pow(x,n,mod))
        continue
    start=x*pow(d,mod-2,mod)%mod
    if start+n-1>=mod:
        print(0)
    else:
        print(MUL[start+n-1]*pow(MUL[start-1],mod-2,mod)%mod*pow(d,n,mod)%mod)


Measured memory_bytes: 45712
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
#define INF 999999999
#define int64 long long
#define rep(i, n) for(int i = 1; i <= (int)(n); i++)
int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
    int N, K;
    cin >> N;
    string S;
    cin >> S;
    cin >> K;
    char c = S[K-1];
    for(int i=0; i<S.length(); ++i){
        if (S[i] != c){
            cout << "*";
        }
        else cout << S[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

int main() {
#ifdef LOCAL
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    string s;
    cin >> s;
    map<char, int> mp;
    bool ok = 0;
    forn(i, sz(s)) {
        mp[s[i]]++;
        if (mp[s[i]] == 2) {
            ok = 1;
        }
    }
    if (ok)
        cout << "no" << endl;
    else
        cout << "yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
const long long LLINF = 1LL << 62;
const int INF = 1LL << 30;
using namespace std;


int main(void) {
	int P, Q, R;
	cin >> P >> Q >> R;
	
	cout << min({ P + Q,Q + R,R + P }) << endl;
}

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

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	vector<int> cnt(3);
	rep(i, n) {
		if (p[i] <= a) cnt[0]++;
		else if (p[i] <= b) cnt[1]++;
		else cnt[2]++;
	}
	cout << min(cnt[0], min(cnt[1], cnt[2])) << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
    using System.Text;
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string ret = string.Empty;

            double value = n / 1.08;

            int[] applePie = new int[2];
            int[] tax = new int[2];

            applePie[0] = (int)value;
            applePie[1] = (int)value + 1;

            tax[0] = (int)(applePie[0] * 1.08);
            tax[1] = (int)(applePie[1] * 1.08);

            if (tax[0] == n)
            {
                ret = applePie[0].ToString();
            }
            else if (tax[1] == n)
            {
                ret = applePie[1].ToString();
            }
            else
            {
                ret = ":(" + Environment.NewLine;
            }

            Console.WriteLine(ret);

        }
    }

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std; 
using lint =                            long long int;
using plint =                           pair<lint, lint>;
#define vli                             vector<lint>
#define pb                              push_back
#define ALL(x)                          begin(x),end(x)
#define inf                             (1LL<64)-1
#define SZ(x)                           ((lint)(x).size())
#define                                 FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define                                 IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define                                 REP(i, n) FOR(i,0,n)
#define                                 IREP(i, n) IFOR(i,0,n)
#define                                 f_ip   ios_base::sync_with_stdio(false); cin.tie(NULL);
template<typename T>                    istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }

/*
   -------
         |
    **   |
   -------      
   |
   ------------------------------------------------------------------------------------------------------
*/

vector<vector<int>> V = 
{
    {0,1,2},
    {3,4,5},
    {6,7,8},
    {0,4,8},
    {2,4,6},
    {0,3,6},
    {1,4,7},
    {2,5,8}};            //linearization of matrix  , usef for final check;

void solve()
{
   vector<lint> A(9);
   cin>>A;
   int N;
   cin>>N;
   while(N--){
        int b;
        cin>>b;
        for(auto &x : A) if (x == b)  x = 0;          
   }
   for(auto vec : V){
       bool b = true;
       for(auto x : vec) if ( A[x] ) b = false;                          //if any of the row, column or the two diagonal is marked, then return true from here;
       if(b) 
       {
           puts("YES");
           return ;
       }
   }

   puts("NO");
}

int main()
{   
    //  f_ip
  
    // solve();
//     vector<lint> A(9);
//    cin>>A;
//    int N;
//    cin>>N;
//    while(N--){
//         int b;
//         cin>>b;
//         for(auto &x : A) if (x == b)  x = 0;          
//    }
//    for(auto vec : V){
//        bool b = true;
//        for(auto x : vec) if ( A[x] ) b = false;                          //if any of the row, column or the two diagonal is marked, then return true from here;
//        if(b) 
//        {
//            puts("YES");
//            return 0;
//        }
//    }

//    puts("NO");

    vector<lint> A(9);
    cin >> A;
    int N;
    cin >> N;
    while (N--) {
        int b;
        cin >> b;
        for (auto &x : A) if (x == b) x = 0;
    }
    for (auto vec : V) {
        bool b = true;
        for (auto x : vec) if (A[x]) b = false;
        if (b) {
            puts("Yes");
            return 0;
        }
    }
    puts("No");

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,arr[103],gap[103];
int main()
{
    scanf("%d",&N);
    for(int i=1; i<=N; i++)
    {
        scanf("%d",&arr[i]);
        gap[i] = i-arr[i];
    }
    vector <int> out;
    while(1)
    {
        int id=-1;
        for(int i=N;i>=1;i--)
        {
            if(gap[i] == 0)
            {
                id = i;
                out.push_back(arr[i]);
                for(int j=id;j<=N;j++) gap[j]--;
                break;
            }
        }
        if(id==-1) break;
    }
    if(out.size()<N) return !printf("-1");
    for(int i=out.size()-1;i>=0;i--) printf("%d\n",out[i]);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int N, N100, N10, N1;
	do{
		scanf("%d", &N);
	}while(N < 100 || N > 999);

	N100 = N / 100;
	N10 = N % 100;
	N1 = N10 % 10;

	if(N100 == N1)	printf("Yes\n");
	else	printf("No\n");

	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
vector<ll>dist(1000000,-1);
void dfs(int now_v,Graph_weighted &G){
  for(auto i : G[now_v]){
    if(dist[i.first] != -1)continue;
    dist[i.first] = dist[now_v] + i.second;
    dfs(i.first,G); 
  }
}
int solve(){
  int n;
  cin >> n;
  Graph_weighted G(n);
  rep(i,n - 1){
    int a,b,c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }
  int q,k;
  cin >> q >> k;
  k--;
  dist[k] = 0;
  dfs(k,G);
  while(q--){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    cout << dist[x] + dist[y] << endl;
  }
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}


Measured memory_bytes: 17664
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います

  for(var i=0; i<input.length; i++){
    tmp = input[i].split(" ");
    for(j =0; j<tmp.length; j++){
      tmp[j] = parseInt(tmp[j], 10);
    }
    input[i] = tmp;
  }

  var N = parseInt(input[0][0], 10);
  var K = parseInt(input[0][1], 10);

  var arr = [];
  for(i=0; i<=N; i++){
    arr[i]=0;
  }

  for(i=2; i<input.length; i+=2){
    tmp = input[i];
    for(j=0; j<tmp.length; j++){
      arr[tmp[j]] += 1;
    }
  }
  var ans = 0;
  for(i=1; i<arr.length; i++){
    if(arr[i] == 0) ans++;
  }

	//出力
  // console.log(N, K, arr);
	console.log('%d', ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29628
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    string ans = "Christmas";
    int d;
    cin>>d;
    if(d==24)ans += " Eve";
    else if(d==23)ans += " Eve Eve";
    else if(d==22)ans += " Eve Eve Eve";
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define ac(x, i) get<i>(x)
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll ,ll>
#define ff first
#define ss second
#define MOD 1000000007

const int infi = 1e9;
const ll infl = 1e18;

const int N = 1e5 + 300;
const int K = 110;
ll dp[N][K];

int main() {
  #ifndef ONLINE_JUDGE
  //freopen("input.txt", "r", stdin);
  #endif
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int n; cin >> n;
  int k; cin >> k;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++) {
      dp[i][j] = infl;
    }
  }
  int a[n+110];
  memset(a, infi, sizeof(a));
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int j = 0; j < k; j++) dp[1][j] = 0LL;
  for (int i = 1; i < n; i++) {
    ll MIN = infl;
    for (int j = 0; j < k; j++) {
      if (dp[i][j] < MIN) MIN = dp[i][j];
    }
    for (int j = 0; j < k; j++) {
      dp[i+j+1][j] = MIN + abs(a[i+j+1] - a[i]);
    }
  }
  ll MIN = infl;
  for (int j = 0; j < k; j++) {
    if (dp[n][j] < MIN) MIN = dp[n][j];
  }
  cout << MIN << "\n";
  return 0;
}

Measured memory_bytes: 86656
package main

import "fmt"
import "math"
import "sort"

var H, W int
var min1, min2 int
var S1, S2, S3 int
var s1_h, s1_w, s2_h, s2_w, s3_h, s3_w int

func getM(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func getMin(s1_h, s1_w, s2_h, s2_w, s3_h, s3_w int) int {
	var s [3]int
	s[0] = s1_h * s1_w
	s[1] = s2_h * s2_w
	s[2] = s3_h * s3_w
	sort.Ints(s[:])
	return s[2] - s[0]
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func main() {
	fmt.Scan(&H, &W)
	min1 = math.MaxInt64 / 8
	min2 = math.MaxInt64 / 8
	// One rectangle use Height
	for w := 1; w < W; w++ {
		S1 = H * w
		s2_w = int((W - w) / 2)
		s3_w = W - w - s2_w
		d1 := getMin(H, w, H, s2_w, H, s3_w)

		s2_h = int(H / 2)
		s3_h = H - s2_h
		d2 := getMin(H, w, s2_h, W-w, s3_h, W-w)
		d := 0
		if d1 < d2 {
			d = d1
		} else {
			d = d2
		}

		if min1 > d {
			min1 = d
		} else {
			break
		}
	}

	// One rectangle use Width
	for h := 1; h < H; h++ {
		S1 = h * W
		s2_h = int((H - h) / 2)
		s3_h = H - h - s2_h
		d1 := getMin(h, W, s2_h, W, s3_h, W)

		s2_w = int(W / 2)
		s3_w = W - s2_w
		d2 := getMin(h, W, H-h, s2_w, H-h, s3_w)
		d := 0
		if d1 < d2 {
			d = d1
		} else {
			d = d2
		}

		if min2 > d {
			min2 = d
		} else {
			break
		}
	}

	fmt.Println(getM(min1, min2))
}


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

int main(){
    int H, W, i;
    string r = "#";
    string p = ".";
    while(1){
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        i = 0;
        string wide = "";
        string period = "";
        while (i < W){
            wide += r;
            i++;
        }
        i = 0;
        period += r;
        while (i < W-2){
            period += p;
            i++;
        }
        period += r;
        i = 0;
        cout << wide << endl;
        while (i < H-2){
            cout << period << endl;
            i++;
        }
        cout << wide << endl;
        cout << "" << endl;
        
    }
    return 0;
}


Measured memory_bytes: 3164
// AtCoder Grand Contest 014
// A - Cookie Exchanges

#include <cstdio>
#include <algorithm>
#include <numeric>
#define MAX_N 3
using namespace std;
typedef long long int ll;

ll a[MAX_N];

int main() {

  ll tmp_a[MAX_N];
  ll sum, max_a;
  int j, m;
  bool is_odd;

  max_a = 0;
  for (int i = 0; i < MAX_N; i++) {
    scanf("%lld", &a[i]);
    max_a = max(max_a, a[i]);
  }
  for (m = 0; (1 << m) <= max_a; m++) {}
  for (j = 0; j <= m; j++) {
    is_odd = false;
    for (int i = 0; i < MAX_N; i++) {
      if (a[i] % (MAX_N - 1) != 0) {
        is_odd = true;
        break;
      }
    }
    if (is_odd) {
      break;
    }
    sum = accumulate(a, a + MAX_N, 0);
    swap(a, tmp_a);
    for (int i = 0; i < MAX_N; i++) {
      a[i] = (sum - tmp_a[i]) / (MAX_N - 1);
    }
  }
  if (is_odd) {
    printf("%d\n", j);
  } else {
    printf("%d\n", -1);
  }

  return 0;

}




Measured memory_bytes: 128
N,K = map(int,input().split())
A = list(map(int,input().split()))

MOD = 10**9+7

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if A[i] > A[j]:
            ans += 1
ans *= K

from collections import Counter
ctr = Counter(A)

P = (K*(K-1)//2) % MOD

s = 0
for k,v in sorted(ctr.items()):
    tmp = (v*s*P)%MOD
    ans += tmp
    ans %= MOD
    s += v

print(ans)

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

int main() {
    int num;
    cin >> num;
    int sum_1=0, sum_2=0;
    int i=0;
    while(i<num){
        string str_1, str_2;
        cin >> str_1 >> str_2;
        if(str_1>str_2)
        sum_1+=3;
        else if (str_1<str_2)
        sum_2+=3;
        else{
            sum_1+=1;
            sum_2+=1;
        }
        i++;
    }
    cout << sum_1 << " " << sum_2 << endl;
}



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

const long long mod = 1000000007;

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

	vector<int> a(n + 1, true);
	for (int i = 0; i < m; i++) { 
		int b; cin >> b;
		a[b] = false;
	}

	vector<long long> dp(n + 1);

	dp[0] = 1;
	
	for (int i = 0; i < n; i++) {
	
		for (int j = i + 1; j <= min(n, i + 2); j++) {

			if (a[j]) {
				dp[j] += dp[i];
				dp[j] %= mod;
			}
		}
	}
	
	cout << dp[n] << endl;

	return 0;
}

Measured memory_bytes: 1408
N = int(input())
S = input()
i = j = ans = 0
while j < N:
  if S[i:j] in S[j:]:
    ans = max(ans, len(S[i:j]))
    j += 1
  else:
    i += 1

  if i == j:
    i += 1
    j += 2
print(ans)

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

int main() {
  int N;
  string s;
  cin >> N;
  cin >> s;
  
  int x;
  int b = 0;
  int y = N - 1;
  int count = 0;
  
  rep(i, N){
    if(s.at(i) == 'W'){
      for(int j = y; j > i; j--){
        if(s.at(j) == 'R'){
          char tmp = s.at(i);
          s.at(i) = s.at(j);
          s.at(j) = tmp;
          count++;
          b = 1;
          y = j - 1;
          break;
        }
      }
      if(b == 0){
        cout << count << endl;
        return 0;
      }
      b = 0;
    }
    
  }
  
  cout << count << endl;

}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

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

    if (s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3624
import copy

H,W = map(int, input().split())
s = [list("."+input()+".") for _ in range(H)]
S = [["."]*(W+2)] + s + [["."]*(W+2)]
T = copy.deepcopy(S)

for i in range(1,H+1):
    for j in range(1,W+1):
        cnt = S[i-1][j-1:j+2].count('#')+S[i][j-1].count('#')
        cnt += S[i][j+1].count('#')+S[i+1][j-1:j+2].count('#')
        if T[i][j]!="#":
            T[i][j] = str(cnt)

ans = T[1:-1]
for i in range(H):
    ans[i] = ans[i][1:-1]
    print ("".join(ans[i]))

Measured memory_bytes: 3700
<?php
list($n, $a, $b) = explode(' ', fgets(STDIN));
$num = 0;
$res = 0;
 
for($n_for = $n; $n_for > 0; $n_for--){
  $arr = str_split($n_for);
  $num =  array_sum($arr);
    if (($a <= $num) && ($num <= $b)){
      $res += $n_for;
    }
}
 
echo $res;
?>

Measured memory_bytes: 16048
/*input
10
5 3
5 7
8 9
1 9
9 10
8 4
7 4
6 10
7 2
*/

#include <bits/stdc++.h>
#include <unistd.h>

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 1e18
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define UQ(x) (x).resize(distance((x).begin(),unique(x.begin(),x.end())))

using namespace std;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2){
			ans*=a;
			ans%=(mod);
		}
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

void solve(){
	ll i,j,_;
	ll n;
	cin>>n;
	ll ans=0,k;
	rep(i,1,n+1)ans+=(n-i+1)*i;
	rep(i,0,n-1){
		cin>>j>>k;
		if(j>k)swap(j,k);
		ans-=(n-k+1)*j;
	}	
	cout<<ans<<endl;
}


int main()
{
	ios::sync_with_stdio(0);
 	cin.tie(0);
	ll T=1;
	//cin>>T;
	while(T--){
		solve();
	}
	return 0;
}




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

using namespace std;

long long Sum(long long n)
{
  return n * (n + 1) / 2;
}

void hawawa()
{
  int n;
  cin >> n;
  int mi = 1, ma = n;
  while (mi < ma) {
    int mid = (mi + ma) / 2;
    if (n <= Sum(mid)) {
      ma = mid;
    } else {
      mi = mid + 1;
    }
  }
  int score = Sum(mi);
  for (int i = 1; i <= mi; i++) {
    if (score - n == i) {
      continue;
    }
    cout << i << "\n";
  }
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
int N;
int main(){
	cin>>N;
	int t=0,x=0,y=0;
	bool ans=true;
	REP(i,N){
		int t2,x2,y2;
		cin>>t2>>x2>>y2;
		if (abs(x2-x)+abs(y2-y)>t2-t ||(t2-t-abs(x2-x)-abs(y2-y))%2==1){
			ans=false;
		}
		t2=t;
		x2=x;
		y2=y;
	}
	cout<<(ans ? "Yes" : "No")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main(){
    int h,w; cin>>h>>w;
    vector<string> grid(h);
    rep(i,0,h) cin>>grid[i];
    vector<vector<int>> dp(h,vector<int>(w,INF));
    if(grid[0][0]=='#') dp[0][0]=1;
    else dp[0][0]=0;

    rep(i,0,h){
        rep(j,0,w){
            if(i>=1){
                if(grid[i-1][j]=='.' and grid[i][j]=='#') chmin(dp[i][j],dp[i-1][j]+1);
                else chmin(dp[i][j],dp[i-1][j]);
            }
            if(j>=1){
                if(grid[i][j-1]=='.' and grid[i][j]=='#') chmin(dp[i][j],dp[i][j-1]+1);
                else chmin(dp[i][j],dp[i][j-1]);
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------
signed main() {
	int n, m;
	priority_queue<int>p;
	cin >> n >> m;
	for (int i = 0; i < n; i++) p.push(read());
	for (int i = 0; i < m; i++) {
		p.push(p.top() / 2);
		p.pop();
	}
	int ans = 0;
	rep(i, n) {
		ans += p.top(); p.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>

using namespace std;

int main(){

    int n;
    scanf("%d", &n);
    int number[210];

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

    bool flag;
    int answer = 0;
    while(true){
        flag = true;
        for(int i = 0;i < n;i++){
            if(number[i] % 2 != 0){
                flag = false;
            }
        }
        if(flag == false){
            break;
        }
        for(int i = 0;i < n;i++){
            number[i] /= 2;
        }
        answer++;
    }

    printf("%d\n", answer);

    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

    void solve() {
        try (Scanner in = new Scanner(System.in)) {
            long x = in.nextLong();
            long a = 0, b = 0;
            while (b < x) {
                b += ++a;
            }
            // if ((b - x) % 2 == 1) ++a;
            System.out.println(a);
        }
    }

    void tr(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int H, W;
	cin >> H >> W;
	
	if (H == 1 || W == 1) {
		cout << 1 << endl;
		return 0;
	}
	
	Int ans = ((H + 1) / 2) * ((W + 1) / 2) + (H / 2) * (W / 2);
	cout << ans << endl;

	return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    Bint A[200010];
    rep(i, N) cin >> A[i];
    sort(A, A + N);
    if(A[0] == 0) {
        cout << 0 << endl;
        return 0;
    }
    Bint a = 1;
    rep(i, N) {
        a *= A[i];
        if(a > INF2) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << a << endl;

    return 0;
}


Measured memory_bytes: 10008
#include<bits/stdc++.h>
using namespace std;
inline long long read(){
	char c=getchar();long long x=0,f=1;
	while(c<'0'||c>'9'){ if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return x*f;
}
long long Q,H,S,D,n,one;
int main(){
	Q=read(),H=read(),S=read(),D=read();
	n=read();
	one=min(Q*4,min(H*2,S));
	if(n%2==0){
		cout<<min(one*n,D*n/2);
	}
	else{
		if(n>2) cout<<min((one+D*(n/2)),min(D+(one*(n-2)),one*n));
		else cout<<one;
	}
	return 0;
}


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

#define pb push_back
#define mp make_pair
#define inf 1000000000
#define mod 1000000007

vector<int> primes;
void sieve()
{
    vector<int> a(1000000,0);
    for(int u=2;u<=1000000;u++)
    {
        if(a[u])continue;
        for(int i=2*u;i<=1000000;i+=u)a[i]=u;
    }
    for(int i=2;i<=1000000;i++)
    {
        if(!a[i])primes.pb(i);
    }
}

int gcd(int a, int b)
{
    while(1)
    {
        if(a==0)return b;
        b%=a;
        if(b==0) return a;
        a%=b;
    }
}
int lcm(int a, int b)
{
    int g=gcd(a,b);
    return ((a*b)/g);
}

int digitCount(int n)
{
    int c=0;
    while(n!=0)
    {
        c+=n%10;
        n/=10;
    }
    return c;
}

int parseInt(string str)
{
    int a=0;
    int l=str.length();
    for(int i=0;i<l;i++)
    {
        a*=10;
        a+=str[i]-48;
    }
    return a;
}

long long parseLong(string str)
{
    long long a=0;
    int l=str.length();
    for(int i=0;i<l;i++)
    {
        a*=10;
        a+=str[i]-48;
    }
    return a;
}

int main()
{
    string str;
    cin>>str;
    int l=str.length();
   for(int i=l-1;i>1;i--)
    {
        //cout<<l<<endl;
        int n=i/2;
        if(str.substr(0,n)==str.substr(n,n))
        {
            if(i%2==0)cout<<i<<endl;
            else cout<<i-1<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    int n, x, y;
    cin >> n >> x >> y;
    vector<int> a(n);
    rep(n) cin >> a[i];
    if(n > 1) cout << max(abs(a[n-1] - y), abs(a[n-1] - a[n-2]));
    else cout << abs(a[n-1]-y);

    /*
    int i = 0;
    int turn_x = 1;
    while(i < n){
        int new_i = n-1;
        if(turn_x){
            int max = abs(a[n-1] - y);
            for(int j=n-2;j>=i;j--){
                if(max < abs(a[n-1] - a[j])){
                    new_i = j;
                    max = abs(a[n-1] - a[j]);
                }
            }
            x = a[new_i];
        }else{
            int min = abs(a[n-1] - x);
            for(int j=n-2;j>=i;j--){
                if(min > abs(a[n-1] - a[j])){
                    new_i = j;
                    min = abs(a[n-1] - a[j]);
                }
            }
            y = a[new_i];
        }
        i = new_i + 1;
        turn_x = 1-turn_x;
        cout << x << " " << y << endl;
    }
    
    cout << abs(x-y);
    */
}

Measured memory_bytes: 256