akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using System.Text;
 
class DandA {
    static void Main(string[] args) {
        int n = ReadLineInt();
        int[] aList = ReadLineIntArray();
        int[] bList = ReadLineIntArray();
        int[] cList = ReadLineIntArray();
        int rtn = 0;
        int wk = -10;
        for (int i = 0; i < n; i++) {
            rtn += bList[aList[i] - 1];
            if (wk == aList[i] - 1) {
              rtn += cList[aList[i] - 2];
            }
            wk = aList[i];
        }
        Console.WriteLine(rtn);
    }
 
    static string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    static string[] strAry = new string[] {"L", "R", "U", "D"}; 
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private long ReadLineLong() {return long.Parse(Console.ReadLine());}
    static private double ReadLineDouble() {return double.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private long[] ReadLineLongArray() {return Console.ReadLine().Trim().Split().Select(a => long.Parse(a)).ToArray();}
    static private double[] ReadLineDoubleArray() {return Console.ReadLine().Trim().Split().Select(a => double.Parse(a)).ToArray();}
    static private decimal[] ReadLineDecimalArray() {return Console.ReadLine().Trim().Split().Select(a => decimal.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
 
    static private bool IsPrime(int num) {
        if (num < 2) return false;
        if (num == 2) return true;
        else if (num % 2 == 0) return false;
        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) return false;
        }
        return true;
    }
}

Measured memory_bytes: 13396
package main

import (
  "fmt"
)

func main() {
  var (
    n int
  )
  fmt.Scan(&n)
  s := make([]string, n)
  for i:=0; i<n; i++ {
    fmt.Scan(&s[i])
  }

  s2 := removeDuplicate(s)
  if len(s2) > n {
    fmt.Println(n)
  } else {
    fmt.Println(len(s2))
  }
}

func removeDuplicate(args []string) []string {
    results := make([]string, 0, len(args))
    encountered := map[string]bool{}
    for i := 0; i < len(args); i++ {
        if !encountered[args[i]] {
            encountered[args[i]] = true
            results = append(results, args[i])
        }
    }
    return results
}


Measured memory_bytes: 26632
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
        int h,w;
        cin>>h>>w;
        int hh[100] = {0};
        int ww[100] = {0};
        string mp[100];
        for(int i=0;i<h;i++)cin>>mp[i];

        string ht = "";
        string wt = "";

        for(int i=0;i<h;i++)ht += ".";
        for(int i=0;i<w;i++)wt += ".";

        for(int i=0;i<h;i++){
                if(wt == mp[i]) hh[i] = 1;
        }

        for(int i=0;i<w;i++){
                string tmp = "";
                for(int j=0;j<h;j++)tmp += mp[j][i];
                if(ht == tmp) ww[i] = 1;
        }

        string ans[100];
        int hcount =0;
        for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                        if(hh[i] == 0){
                                if(ww[j] ==0) ans[hcount]+=mp[i][j];
                        }
                }
                if(hh[i] ==0) hcount++;
        }

        for(int i=0;i<hcount;i++){
                cout<<ans[i]<<endl;
        }

        return 0;
}


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

int ans[30];
int cnt[55][30];

int main(){
    int n; cin>>n;
    fill(ans,ans+30,INF);
    for(int i=0;i<n;i++){
        string s; cin>>s;
        for(int j=0;j<s.size();j++){
            cnt[i][s[j]-'a']++;
        }
        for(int j=0;j<30;j++){
            ans[j]=min(ans[j],cnt[i][j]);
        }
    }
    for(int i=0;i<30;i++){
        while(ans[i]>0){
            cout<<(char)('a'+i);
            ans[i]--;
        }
    }
    cout<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
div = make_divisors(N)
ans = 10 ** 10
import bisect
idx = bisect.bisect(div, N ** (1 / 2))
loop = [idx-1, idx, idx+1]
can = []
for i in loop:
    if 0 <= i < len(div):
        can.append((div[i], N // div[i]))
for j in can:
    left, right = j
    ans = min(ans, max(len(str(left)), len(str(right))))
print(ans)


Measured memory_bytes: 3188
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = long.Parse(Console.ReadLine());
        //int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();

        long ans = 0;
        ans += ((n - 1)*(1 + n - 1)) / 2;
        ans += n % 1;

        // 出力
        Console.WriteLine(ans);
    }
}

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

typedef long long int ll;

ll gcd(ll a, ll b){
	return (b > 0)? gcd( b , a%b ) : a ;
}

ll lcm(ll a, ll b){
	return a / gcd(a,b) * b;
}

int main(){
	ll a1, a2, a3, m1, m2, m3;
	while( cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3 , a1||m1||a2||m2||a3||m3 ){
		ll x, y, z, a, b, c;
		a = b = c = x = y = z = 1;
		x = (x * a1) % m1;
		y = (y * a2) % m2;
		z = (z * a3) % m3;
		for( ; x != 1 ; a++ ){
			x = (x * a1) % m1;
		}
		for( ; y != 1 ; b++ ){
			y = (y * a2) % m2;
		}
		for( ; z != 1 ; c++ ){
			z = (z * a3) % m3;
		}
		ll ans = lcm( lcm(a,b) , c);
		cout << ans << endl;
	}
}

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

using namespace std;
typedef long long ll;

int main() {
    string s;ll c=0;
    cin>>s;
    for(auto i:s){
        if(i=='o')c++;
    }
    if((c+15-s.size())>=8)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
<?php
list($a,$b,$c,$d)=explode(" ",trim(fgets(STDIN)));
$i=0;
while($i<1000){
  $c-=$b;
  if($c<=0){
    echo "Yes";
    exit;
  }
  $a-=$d;
  if($a<=0){
    echo "No";
    exit;
  }
  ++$i;
}

Measured memory_bytes: 16108
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

string s, t, s2;
ll nextC[100001][26] = {}, place[26] = {}, p = 0, ans = 0;

int main() {
	cin >> s;
	cin >> t;
	s2 = s + s;
	rep(i, 26)place[i] = -1;
	for (int i = sz(s2) - 1; i >= 0; i--) {
		place[s2[i] - 'a'] = i;
		if (i < sz(s)) {
			rep(j, 26)nextC[i][j] = place[j];
		}
	}
	rep(i, sz(t)) {
		if (place[t[i] - 'a'] == -1) {
			cout << -1 << endl;
			return 0;
		}
		p = nextC[p][t[i] - 'a'] + 1;
		if (p >= sz(s)) {
			p -= sz(s);
			ans += sz(s);
		}
	}
	cout << ans + p << endl;
	return 0;
}

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

using namespace std;

using ll = long long;

const ll MOD = 998244353;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll f[4005], fi[4005];

ll comb(int r, int c) {
    if (r < 0 || c < 0 || r < c) return 0;
    return f[r] * fi[c] % MOD * fi[r - c] % MOD;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, n;
    cin >> K >> n;

    f[0] = 1;
    for (int i = 1; i <= n + K; i++) {
        f[i] = f[i - 1] * i % MOD;
    }
    fi[n + K] = modpow(f[n + K], MOD - 2);
    for (int i = n + K; i > 0; i--) {
        fi[i - 1] = fi[i] * i % MOD;
    }

    for (int i = 2; i <= 2 * K; i++) {
        ll sum = 0;

        int x = 0;
        for (int j = 1; j < i; j++) {
            if (j > K) break;
            int k = i - j;
            if (k > K || k < j) continue;
            x++;
        }

        for (int j = 0; j <= x; j++) {
            int bar = K - (2 * x - (i % 2 == 0)) - 1;
            ll tmp;
            if (j > 0 && i % 2 == 0) {
                tmp = comb(x - 1, j - 1) * modpow(2, j - 1) % MOD * comb(n - j + bar + j - 1, bar + j - 1) % MOD;
                if (x > j) tmp += comb(x - 1, j) * modpow(2, j) % MOD * comb(n - j + bar + j, bar + j) % MOD;
                tmp %= MOD;
            } else {
                tmp = comb(x, j) * modpow(2, j) % MOD * comb(n - j + bar + j, bar + j) % MOD;
            }
            (sum += tmp) %= MOD;
        }
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 384
import numpy as np
N, K = map(int,input().split())
H = np.array([int(input()) for _ in range(0, N)])
H = np.sort(H)
H_diff = np.diff(H)
best = int(np.min(np.convolve((H_diff), np.ones(K-1), mode='valid')))
print(best)

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

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

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

  vector<int64_t> cnt(N + 1, 0);
  for (int64_t i = 0; i < N; i++) {
    cnt[A[i]]++;
  }

  int64_t sum = 0;
  for (int64_t c : cnt) {
    sum += c * (c - 1) / 2;
  }

  for (int64_t a : A) {
    cout << sum - cnt[a] + 1 << endl;
  }

  return 0;
}


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

int main(){
	ll n,k;
	cin >> n >> k;
	vector<ll> a(n);
	vector<ll> f(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> f[i];
	sort(a.rbegin(),a.rend());
	sort(f.begin(),f.end());
	ll l = -1;
	ll r = 1e+18;
	while(r - l > 1){
		ll m = (l+r)/2;
		ll count = 0;
		rep(i,n){
			count += max(ll(0), a[i] - m/f[i]);
		}
		if(count > k){
			l = m;
		}else{
			r = m;
		}
	}
	cout << r << endl;
    return 0;
}

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

int main(){
  int num[128],tempn,index[128][128],i,j,k,l,m,alc,count;
  char word[128][128],tempw[128],dict[128][128];
  i=0;
  while(~scanf("%s %d",word[i],&num[i]))i++;

  i=i-1;

  j=0;
  while(j<i)
    {
      if(strcmp(word[j],word[j+1])>0)
	{
	  strcpy(tempw,word[j]);
	  strcpy(word[j],word[j+1]);
	  strcpy(word[j+1],tempw);
	  tempn=num[j];
	  num[j]=num[j+1];
	  num[j+1]=tempn;
	  j=0;
	}
      else
	j++;
    }
 
  l=0;
  alc=0;
  count=0;

  for(k=0;k<=i;k++)
    {
      if(k==0)
	{
	  strcpy(dict[0],word[0]);
	  index[0][0]=num[0];
	  l++;
	}
      else
	{
	  if(strcmp(dict[l-alc-1],word[k]) != 0)
	    {
	      count=0;
	      strcpy(dict[l-alc],word[k]);
	      index[l-alc][0]=num[k];
	      l++;
	    }
	  else
	    {
	      count++;
	      alc++;
	      index[l-alc][count]=num[k];
	      l++;
	    }
	}
    }
  for(k=0;k<i;k++)
    {
      m=0;
      while(index[k][m+1] != 0)
	{
	  if(index[k][m]>index[k][m+1])
	    {
	      tempn=index[k][m];
	      index[k][m]=index[k][m+1];
	      index[k][m+1]=tempn;
	      m=0;
	    }
	  else
	    m++;
	}
    }

  for(k=0;k<l-alc;k++)
    {
      m=0;
      printf("%s\n",dict[k]);
      while(index[k][m+1] != 0)
	{
	  printf("%d ",index[k][m]);
	  m++;
	}
      printf("%d\n",index[k][m]);
    }

  return 0;
}

Measured memory_bytes: 672
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

string day[7] =  {"Sunny", "Cloudy", "Rainy"};

int main(){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    S[K - 1] += 'a' - 'A';
    cout << S << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;
const long long MINF = LLONG_MIN;

// -------------------------------------------------------
int dp[1000][1000];
int N, Ma, Mb;
int a[100], b[100], c[100];

int main() {
  cin >> N >> Ma >> Mb;
  rep(i, 0, N) { cin >> a[i] >> b[i] >> c[i]; }

  rep(i, 0, 1000) {
    rep(j, 0, 1000) { dp[i][j] = 100000; }
  }
  dp[0][0] = 0;

  rep(i, 0, N) {
    int ca = a[i];
    int cb = b[i];
    int cc = c[i];
    for (int j = 400; j >= 0; --j) {
      for (int k = 400; k >= 0; --k) {
        chmin(dp[j + ca][k + cb], dp[j][k] + cc);
      }
    }
  }

  int ans = 100000;
  repe(i, 1, 400) {
    int cma = i * Ma;
    int cmb = i * Mb;
    if (cma > 400 || cmb > 400) break;

    chmin(ans, dp[cma][cmb]);
  }
  if (ans >= 100000) {
    cout << -1;
    return 0;
  }

  cout << ans;
}


Measured memory_bytes: 7504
x,y,z,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ans=[]
for i in range(x):
    if i > k:
        break
    for j in range(y):
        if i*j > k:
            break
        for l in range(z):
            if i*j*l > k:
                break
            ans.append(a[i]+b[j]+c[l])

ans.sort(reverse=True)

for i in range(k):
    print(ans[i])

Measured memory_bytes: 105100
from heapq import heappush, heappop
from collections import deque
import re
import math
import functools

def sRaw():
    return input().rstrip("\r")

def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29


def make1d_arr(n, val=INF):
    return [val for i in range(n)]


def make2d_arr(h, w, val=INF):
    return [[val for i in range(w)]for i in range(h)]


def gcd(a, b):
    if(b == 0):
        return a
    return gcd(b, a % b)


def BFord(n,es):
    v_cost = [INF]*n
    v_cost[0] = 0
    for v in range(n*2):
        for e in es:
            frm = e[0]
            to = e[1]
            if v_cost[to] > v_cost[frm]+e[2]:
                v_cost[to] = v_cost[frm]+e[2]
                if v >= n:
                    v_cost[to] = -INF
        if v == n-1:
            prev = v_cost[:]
    v_cost = [-INF if prev[idx]!=v_cost[idx] else v_cost[idx] for idx in range(n)]
    return v_cost
    
def ZAlgo(s):
    l = len(s)
    A = [0]*l
    i =1
    j =0
    A[0]=l
    while i<l:
        while i+j<l and s[j] == s[i+j]:
            j+=1
        if j==0:
            i+=1
            continue
        A[i]=j
        k=1
        while (i+k<l) and (k+A[k]<j):
            A[i+k] =A[k]
            k+=1
        i+=k
        j-=k
    return A


def main():
    N = iRaw()
    ans =0
    if N%2!=0:
        return N//2
    else:
        return (N-1)//2

if __name__ == "__main__":
    print(main())


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

int A[22][22], B[22];

int main() {
    int N, M, C;
    cin >> N >> M >> C;
    for (int i = 0; i < M; i++) cin >> B[i];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int sum_num = C;
        for (int j = 0; j < M; j++) {
            sum_num += A[i][j] * B[j];
        }
        if (sum_num > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	ll a,b,n;
	cin>>a>>b>>n;
	ll x=min(b,n);
	if(x%b==0)x--;
	ll ans=floor((a*x)/b);
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
typedef pair<P,int> PP;

void Main() {
  int n,m;
  cin >> n >> m;
  PP a[m];
  rep(i,m) {
    cin >> a[i].F.S >> a[i].F.F;
    a[i].S=i;
  }
  sort(a,a+m);
  string s[m];
  map<int,int> ma;
  rep(i,m) {
    string t1,t2;
    stringstream s1,s2;
    ma[a[i].F.S]++;
    s1 << a[i].F.S;
    s2 << ma[a[i].F.S];
    s1 >> t1;
    s2 >> t2;
    while(t1.size()<6) t1='0'+t1;
    while(t2.size()<6) t2='0'+t2;
    s[a[i].S]=t1+t2;
  }
  rep(i,m) pr(s[i]);
}

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


Measured memory_bytes: 12800
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
d = []
if n>=m or m==1:
    print(0)
elif n<m:
    for i in range(m-1):
        d.append(x[i+1] - x[i])
    print(sum(sorted(d)[:m-n]))

Measured memory_bytes: 20472
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793




int main(){
   int n,k;
   string s;
   cin >> n>> s >> k;
   char x=s.at(k-1);
   vector<char> ans(n);
   rep(i,n){
       if(s.at(i)==x)ans.at(i)=x;
       else ans.at(i)='*';
   }
   rep(i,n)cout << ans.at(i);
   cout << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 11, M = 1002;

int a[N][M];

signed main()
{
	IO_OP;
	
	int h, w, k;
	cin >> h >> w >> k;
	for(int i=0;i<h;i++) {
		string s;
		cin >> s;
		for(int j=0;j<w;j++) {
			a[i][j] = s[j] - '0';
		}

	}
	int ans = INF;
	for(int cut=0;cut<(1<<(h-1));cut++) {
		vi pos({-1});
		for(int j=0;j<(h-1);j++) if(cut >> j & 1) pos.PB(j);
		pos.PB(h-1);
		V<vi> v(pos.size()-1);
		bool ok = true;
		for(int i=0;i<(int)pos.size() - 1;i++) {
			for(int j=0;j<w;j++) {
				int sum = 0;
				for(int l=pos[i]+1;l<=pos[i+1];l++) {
					sum += a[l][j];
				}
				v[i].PB(sum);
				if(sum > k) ok = false;
			}
		}
		if(!ok) continue;
		int cans = v.size()-1;
		for(int i=0;i<w;i++) {
			int mx = -INF;
			for(int j=0;j<v.size();j++) {
				if(i) v[j][i] += v[j][i-1];
				mx = max(mx, v[j][i]);
			}
			if(mx > k) {
				cans++;
				for(int j=0;j<v.size();j++) {
					if(i) v[j][i] -= v[j][i-1];
				}				
			}
		}
		ans = min(ans, cans);
	}
	cout << ans << endl;
	
}





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

int main(){

    string s; cin >> s;
    int n = s.size();

    int cnt = 0;
    for(int i = 0; i < n; i++){
        int ok = 1;
        for(int j = i; j < n; j++){
            if(!(s[j] == 'A' || s[j] == 'G' || s[j] == 'T' || s[j] == 'C'))
                ok = 0;
            if(ok) cnt = max(cnt, j-i+1);
        }
    }
    cout << cnt << endl;

	return 0;
}

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

int main(){
  int n,m;
  cin >>n >>m;
  cout << (n*(n-1)+m*(m-1))/2 << endl;
  return 0;
}

Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32
    }
    println!("{}", n.pow(3))
}


Measured memory_bytes: 4352
#include<iostream>

using namespace std;
int main() {
	int n;
	int c, v[25], ans = 0;
	cin >> n;

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

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

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

using namespace std;
typedef long long ll;

ll memo[110][100100]; // simpan min weight untuk capai val

ll N, W, w[110], v[110];
const ll INF = 1e18 + 10;
ll dp(ll n, ll val) {
	if (n == 0) {
		if (val == 0) return 0;
		return INF;
	}
	ll &ans = memo[n][val];
	if (ans != -1) return ans;

	ans = min(dp(n - 1, val - v[n]) + w[n], dp(n - 1, val));

	return ans;
}
int main() {
	memset(memo, -1, sizeof(memo));
	cin >> N >> W;
	for (ll i = 1; i <= N; i++) {
		cin >> w[i] >> v[i];
	}

	ll ans = -1;
	for (ll i = 1; i < 100100; i++) {
		if (dp(N, i) <= W) ans = i;
	}

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

Measured memory_bytes: 86272
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n,s,m=1e10;
	scanf("%lld%lld",&n,&s);
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		m=min(m,t);
		s-=t;
	}
	printf("%lld",n+s/m);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <atcoder/all>
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 REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using namespace atcoder;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[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;
}

int main()
{
  ll N,M;
  cin >> N >> M;
  vector<P> A(M);
  dsu d(N);
  REP(i,M){
    cin >> A[i].first >> A[i].second;
    A[i].fi--;
    A[i].se--;
    d.merge(A[i].fi,A[i].se);
  }

  set<int> st;
  REP(i,N){
    st.insert(d.leader(i));
  }

  cout << sz(st)-1 << endl;
}


Measured memory_bytes: 7696
from itertools import accumulate
N, M = map( int, input().split())
l = 1
r = N
for _ in range(M):
    a, b = map( int, input().split())
    if l <= a:
        l = a
    if b <= r:
        r = b
if r - l >= 0:
    print(r-l+1)
else:
    print(0)

Measured memory_bytes: 45288
#include <stdio.h>
#include <limits.h>

int H, N, A[10002], B[10002];
int h2mp[10000]; // このHPを倒すのに必要な最小のMP                              

int main() {
  int i, j;
  scanf("%d %d", &H, &N);
  for (i = 0; i < N; i++) { scanf("%d %d", &(A[i]), &(B[i])); };

  for (i = 1; i <= H; i++) {
    int min = INT_MAX;
    for (j = 0; j < N; j++) {
      int total = i - A[j];
      int mp = B[j];
      if (total > 0) { mp += h2mp[total]; }
      if (mp < min) { min = mp;}
    }
    h2mp[i] = min;
  }
  printf("%d\n", h2mp[H]);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int n;
  cin >> n;
  cout << a[n-1] << endl;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n, k;
	cin >> n >> k;
	unsigned long long int are = 0;
	unsigned long long int sore = 0;
	for (int i = 1; i <= n; ++i)
	{
		if (i % k == 0)
		{
			++are;
		}
		if(k % 2 == 0 && i % k == k / 2)
		{
			++sore;
		}
	}
	cout << (unsigned long long int)(sore*sore*sore + are*are*are) << endl;
	return 0;
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, b, e) for (i64 i = (b); i <= (e); ++i)
#define repr(i, b, e) for (i64 i = (b); i >= (e); --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// input
void input() {}
template <class Head, class... Tail>
void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

// outs
void outs() {}
template <class Head, class... Tail>
void outs(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  outs(forward<Tail>(tail)...);
}

template <class T>
void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void outs(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// outl
void outl() {}
template <class Head, class... Tail>
void outl(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  outl(forward<Tail>(tail)...);
}

template <class T>
void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// outn
void outn() {}
template <class Head, class... Tail>
void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

// dump
template <class T>
void dump_(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

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

  var(i64, d, n);

  i64 norm = pow(100, d);
  i64 res = (n < 100 ? norm * n : norm * 101);

  outl(res);

  return 0;
}


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

int n;
char s[233];
stack<char>S;
int L,R;

int main(){
    scanf("%d", &n);
    scanf("%s", s + 1);
    for(int i = 1 ; i <= n; i++){
        if(s[i] == ')'){
            if(!S.empty() && S.top() == '(') S.pop(), R--;
            else S.push(')'), L++;
        }
        else S.push('('), R++;
    }
    for(int i = 1; i <= L; i++) printf("(");
    for(int i = 1; i <= n; i++) printf("%c",s[i]);
    for(int i = 1; i <= R; i++) printf(")");
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N;
	cin >> N;
	vector<int> a(N);
	REP(i, N) {
		cin >> a[i];
		a[i]--;
	}
	vector<bool> used(N, false);
	int i = 0;
	used[0] = true;
	int res = 0;
	while (1) {
		i = a[i];
		res++;
		if (i == 1) {
			cout << res << "\n";
			return 0;
		}
		if (used[i]) {
			cout << -1 << "\n";
			return 0;
		}
		used[i] = true;
	}

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int x, y;
	while(1){
		//数値を2つ入力
		scanf("%d %d", &x, &y);
		//数値が2つとも0なら終了,それ以外は結果を出力
		if(x == 0 && y == 0){
			break;
		}else if(x > y){
			printf("%d %d\n", y, x);
		}else{
			printf("%d %d\n", x, y);
		}
	}
	
	return 0;
}

Measured memory_bytes: 596
import itertools

N=input()
Len=len(N)-1

if(N[Len]=="2" or N[Len]=="4" or N[Len]=="5" or N[Len]=="7" or N[Len]=="9"):
    print("hon")
elif(N[Len]=="3"):
    print("bon")
else:
    print("pon")


Measured memory_bytes: 8968
#include <stdio.h>

#define WHITE 0
#define GRAY 1
#define BLACK 2

int G[100][100],n,color[100],d[100],f[100],time;


void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  d[u] = ++time;
  for(v=0;v<n;v++){
    if(G[u][v]==0) continue;
    if(color[v] == WHITE){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++time;
}


void dfs(){
  int u;
  for(u=0;u<n;u++) color[u] = WHITE;
  time = 0;

  for(u=0;u<n;u++) {
    if(color[u] == WHITE) dfs_visit(u);
  }
  for(u=0;u<n;u++) {
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}
  

int main(){
  int i,j,u,k,v;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      G[u][v] = 1;
    }
  }

  dfs();

  return 0;
}



Measured memory_bytes: 2112
# 青のカードを記録
N = int(input())
colors = {}
for _ in range(N):
    color = input()
    if colors.get(color):
        colors[color] += 1
    else:
        colors[color] = 1

# 赤のカードを記録        
M = int(input())
for _ in range(M):
    color = input()
    if colors.get(color):
        colors[color] -= 1
    else:
        colors[color] = -1

max_point = 0
for value in colors.values():
    if value > max_point:
        max_point = value
print(max_point)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {


    void solve() {
        Scanner sc = new Scanner(System.in);
        int L = sc.nextInt();
        int R = sc.nextInt();

        long min = Long.MAX_VALUE;
        for (int i = L; i <= R; i++) {
            for (int j = i + 1; j <= R; j++) {
                long ij = ((long)i * j) % 2019;
                if (ij == 0) {
                    min = 0;
                    break;
                }
                min = Math.min(min, ij);
            }
            if (min == 0) {
                break;
            }
        }
        System.out.print(min);
    }

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



Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
const int minn=1001001001;
int a[12][12];

int main(){
int n,m,x;
cin>>n>>m>>x;
vector<int> c(n);
for(int i=0;i<n;i++){
  cin>>c[i];
  for(int j=0;j<m;j++){
    cin>>a[i][j];
  }
}
int ans=minn;
for(int s=0;s<(1<<n);s++){
  int cost =0;
  vector<int> d(m);
  for(int i=0;i<n;i++){
    if(s&(1<<i)){
      cost+=c[i];
      for(int j=0;j<m;j++){
        d[j]+=a[i][j];
      }
    }
  }
  bool ok=true;
  for(int j=0;j<m;j++){
    if(d[j]<x){
      ok=false;
    }
  }
  if(ok){
      ans=min(ans,cost);
    }
  
}
if(ans==minn){
  cout<<-1<<endl;
}
else{
  cout<<ans<<endl;
}
return 0;
}


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	double n,a,sum=0;
	cin>>n;
	vector<double>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		sum+=v[i];
	}
	a=sum/n;
	double mi=10000,ans=-1;
	for(int i=0;i<n;i++){
		if(abs(v[i]-a)<mi){
			mi=abs(v[i]-a);
			ans=i;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
[A, B] = [int(i) for i in input().split()]

flag = False

X = min([(A*100)//8, B*10])

while  X*8 < A*100 + 100 and X*10 < B*100 + 100:
    if A*100 <= X*8 and B*100 <= X*10:
        flag = True
        break
    
    X += 1
    
if flag:
    print(X)
else:
    print(-1)

Measured memory_bytes: 3060
/* ITP1_7_B */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();
      String str = "";

      while((str = br.readLine()).equals("0 0") == false){
        // input
        String[] input = str.split(" ");
        int n = Integer.parseInt(input[0]);
        int x = Integer.parseInt(input[1]);
        if(n < 3 || n > 100) return;

        int count = 0;
        // check
        for(int i = 1; i <= n; i++){
          for(int j = (i + 1); (i + j) < x; j++){
            int k = x - i - j;
            if(k > j && k <= n) count++;
          }
        }
        sb.append(count + "\n");
      }
      // output
      System.out.print(sb);
    }catch(Exception e){
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 24556
import bisect

n, k = map(int, input().split())
a = list(map(int, input().split()))

mod = 10**9 + 7

reverse = 0
for i in range(n):
    for j in range(i+1, n):
        if a[i] > a[j]:
            reverse += 1

ans = reverse * k % mod

if k == 1:
    print(ans)
else:
    k -= 1
    a.sort()
    m = n
    for ai in a:
        i = bisect.bisect_right(a, ai)
        count = n - i
        ans += count * k * (k+1) // 2 % mod
        ans %= mod
    print(ans)



Measured memory_bytes: 42716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MX = 100;

int h, w;
int grid[MX][MX];
int transitions[MX][MX];
bool used[MX][MX];

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

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0 ; j < w; j++) {
            char c; cin >> c;
            grid[i][j] = (c == '#');
        }
    }
 
    queue<pair<int, int>> q;
    q.push({0, 0});
    transitions[0][0] = grid[0][0];
    used[0][0] = true;
    while (!q.empty()) {
        pair<int, int> v = q.front();
        q.pop();
        for (int i = 0; i < 2; i++) {
            int a = v.first + dx[i], b = v.second + dy[i];
            if (a < 0 || a >= h || b < 0 || b >= w) continue;
            if (used[a][b]) {
                int ch = transitions[v.first][v.second] + (!grid[v.first][v.second] && grid[a][b]);
                transitions[a][b] = min(transitions[a][b], ch);
            } else {
                q.push({a, b});
                used[a][b] = true;
                transitions[a][b] = transitions[v.first][v.second] + (!grid[v.first][v.second] && grid[a][b]);
            }
        }
    }
    
    // for (int i = 0; i < h; i++) {
        // for (int j = 0; j < w; j++) {
            // cout << transitions[i][j] << ' ';
        // }
        // cout << '\n';
    // }
    
    cout << transitions[h - 1][w - 1];
}


Measured memory_bytes: 384
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>   
#include <functional>

#define lnd '\n'
#define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mkp make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

void solution();

template <class T>
T GCD (T a, T b) {
  if(b == 0) return a;
  return GCD(b, a%b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

void solution(){
    int n, m;
    cin >> n >> m;
    if(n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

long N, X;
long p_num[51];
long sum[51];

long get_sum(long n)
{
    if(sum[n] == -1) {
        if(n == 0) {
            sum[0] = 1;
        } else {
            sum[n] = 3 + 2 * get_sum(n - 1);
        }
    }
    return sum[n];
}


long get_p(long n)
{
    if(p_num[n] == -1) {
        if(n == 0) {
            p_num[0] = 1;
        } else {
            p_num[n] = 1 + 2 * get_p(n - 1);
        }
    }
    return p_num[n];
}

long f(long n, long x)
{
    //cout << "f: (n, x) = (" << n << ", " << x << ")" << endl;
    if(n == 0) {
        return 1; // n = 0 の時は唯一いちばん下がパンではなくパティなので 1 となる
    }
    if(x == 1) {
        //cout << "A" << endl;
        return 0;
    } else if(x < get_sum(n) / 2 + 1) {
        //cout << "B" << endl;
        return f(n - 1, x - 1);
    } else if(x == get_sum(n) / 2 + 1) {
        //cout << "C" << endl;
        return get_p(n - 1) + 1;
    } else if(x < get_sum(n)) {
        //cout << "D" << endl;
        return get_p(n - 1) + f(n - 1, x - get_sum(n - 1) - 2) + 1;
    } else { // x == get_sum(n)
        //cout << "E" << endl;
        return get_p(n - 1) * 2 + 1;
    }
}

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

    for(int i = 0; i <= 50; i++) {
        p_num[i] = -1;
        sum[i] = -1;
    }

    //cout << get_sum(50) << endl;
    cout << f(N, X) << endl;

    return 0;
}


Measured memory_bytes: 256
//ABC143
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	int ans = max(a-2*b,0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//@source : 
//@create : 19:17:46 Saturday 27/06/2020
//@author : nghethuat102
//@status : 
#include <bits/stdc++.h>
using namespace std;

int a[10000001];

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        a[i] = 1;
    }
    for (int i = 2; i <= n; ++i) {
        for (int j = i; j <= n; j += i) {
            ++a[j];
        }
    }
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += 1LL * i * a[i];
    }
    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    while (t--) {
        solve();
    }
  //  cerr << fixed << setprecision(5) << double(clock()) * 1000 / CLOCKS_PER_SEC << " ms\n";
    return 0;
}

Measured memory_bytes: 42712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner in = new Scanner(System.in)) {
			int N = Integer.parseInt(in.next());
			int[] hills = new int[N];
			
			for (int i = 0; i < N; i++) {
				hills[i] = in.nextInt();
			}
			
			int coutner = 1;
			boolean isHigh = false;
			for (int i = 1; i < N; i++) {
				int hill_i = hills[i];
				for (int j = 0; j < i; j++) {
					int hill_j = hills[j];
					if (hill_i < hill_j) {
						isHigh = false;
						break;
					} else {
						isHigh = true;
					}
				}
				if (isHigh) coutner++;
			}
			
			System.out.println(coutner);
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}


Measured memory_bytes: 23760
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var A, B, K int

func main() {
	sc.Split(bufio.ScanWords)

	A, B, K = nextInt(), nextInt(), nextInt()
	if K > (B-A)/2 {
		for i := A; i <= B; i++ {
			fmt.Println(i)
		}
		return
	}
	for i := A; i < A+K; i++ {
		fmt.Println(i)
	}

	for i := B - K + 1; i <= B; i++ {
		fmt.Println(i)
	}

}


Measured memory_bytes: 640