akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        string str = Console.ReadLine();
        int data;
        var list = new List<int>();
        long sum = 0;

        var str2 = str.Split(' ');

        for (int i = 0; i < n; i++)
        {
            data = int.Parse(str2[i]);
            list.Add(data);
            sum += data;
        }

        list.Sort();

        Console.Write($"{list[0]} ");
        Console.Write($"{list[n-1]} ");
        Console.WriteLine($"{sum}");
    }
}


Measured memory_bytes: 18216
// Author: Jinhai Chen
#include <bits/stdc++.h>
typedef long long ll;
ll INF = 0x3f3f3f3f3f3f3f3f;
#define mst(a,x) memset(a,x,sizeof(a))
using namespace std;
const int maxn = 100010;
int fa[maxn],tt[maxn];
int findfa(int x) { return fa[x]!=x? fa[x]=findfa(fa[x]) : x; }
ll ans[maxn],u[maxn],v[maxn];
ll n,m;

int main() {
#ifdef CJHCJH
	freopen("data.in","r",stdin);
#endif
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++) fa[i]=i,tt[i]=1;
	for(int i=0;i<m;i++) cin>>u[i]>>v[i];
	ans[m]=n*(n-1)/2;
	for(int i=m-1;i>=0;i--) {
		int a=u[i],b=v[i];
		a=findfa(a),b=findfa(b);
		if(a==b) {
			ans[i]=ans[i+1];
			continue;
		}
		ll t = tt[a]*tt[b];
		ans[i]=ans[i+1]-t;
		fa[b]=a;
		tt[a]+=tt[b];
	}
	for(int i=1;i<=m;i++) cout<<ans[i]<<endl;
	
	return 0;
}















Measured memory_bytes: 4480
#include<iostream>
#include<map>
#include<string>
#include<cstdio>
using namespace std;

int main()
{
  map<char,char> mp;
  int n,m;
  char od,nw;

  while(1){
    
    mp.clear();

    scanf("%d",&n);
    if(n == 0)break;
    while(n--){
      scanf(" %c %c",&od,&nw);
      mp[od] = nw;
    }

    scanf(" %d",&m);
    char ans[m];
    for(int i = 0;i < m;i++){
      scanf(" %c",&od);
      if(mp.find(od) != mp.end()){  //map内を検索する
        ans[i] = mp[od]; //あったとき
      }else{
        ans[i] = od; //なかったとき
      }
    }
    
    for(int i = 0;i < m;i++)printf("%c",ans[i]);
    printf("\n");
  }
}

Measured memory_bytes: 1256
s = input()
n = len(s)

lis = [0]*n

r = 0
l = 0
for i in range(n):
    r += 1
    if s[i] == 'L':
        lis[i-1] += r//2
        lis[i] += (r+1)//2
        r = 0

for j in range(n-1, -1, -1):
    l += 1
    if s[j] == 'R':
        lis[j+1] += l//2
        lis[j] += (l+1)//2
        l = 0
    lis[j] -= 1

print(*lis)

Measured memory_bytes: 10668
lst_str = [input() for _ in range(5)]
lst_int = [int(x) for x in lst_str]

sum_lst = sum(lst_int)

lst_diff = []
for i in lst_str:
    val = int(i[-1])
    if val != 0:
        lst_diff.append(10 - val)

if lst_diff == []:
    lst_diff = [0]
diff = sum(lst_diff) - max(lst_diff)

ans = sum_lst + diff
print(ans)

Measured memory_bytes: 3064
def solve():
    h = read()
    result = think(h)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(h):
    cost = [0 for _ in range(len(h))]
    cost[1] = abs(h[1] - h[0])
    for i in range(2, len(h)):
        cost[i] = min(cost[i - 1] + abs(h[i] - h[i - 1]), cost[i - 2] + abs(h[i] - h[i - 2]))
    return cost[len(h) - 1]


def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 13924
N = int(input())
A = list(map(int, input().split()))
A.sort()

ru = [A[0]]
for i in range(1, N):
    ru.append(A[i]+ru[-1])

x = 0
for i in range(N-1, 0, -1):
    if ru[i-1]*2 < A[i]:
        x = i
        break

print(N-x)

Measured memory_bytes: 20468
#include <bits/stdc++.h>
#define ll long long
#define _69e27 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e2+5, M=1e5+5, oo=0x3f3f3f3f, mod = 1e9+7;

ll n, W, arrv[N], arrw[N], mem[N][M];
ll solve(int ind, int rem){
    if(ind == n) return 0;
    if(mem[ind][rem] != -1) return mem[ind][rem];
    ll op1 = solve(ind+1, rem);
    ll op2 = (rem >= arrw[ind]) ? (solve(ind+1, rem-arrw[ind])+arrv[ind]) : -oo;
    return mem[ind][rem] = max(op1, op2);
}
int main()
{
    _69e27
    memset(mem, -1, sizeof mem);
    cin >> n >> W;
    for(int i=0; i<n; i++)
        cin >> arrw[i] >> arrv[i];
    cout << solve(0, W);
    return 0;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
using ll = int_fast64_t;
using ull = uint_fast64_t;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vull = vector<ull>;
#define rep(i, n) for (ull i = 0; i < n; ++i)
#define rep1(i, n) for (ull i = 1; i < n; ++i)
#define iter(it, v) for (auto it = v.begin(); it != v.end(); ++it)
#define pb push_back
#define fi first
#define se second
#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }
template <typename T> void vecout(const T &v) {
  for (auto it = v.begin(); it != v.end();
       ++it, cout << (it != v.end() ? " " : "\n")) {
    cout << *it;
  }
}

void solve() {
  // main coding
  ull n,k; cin>>n>>k;
  ull ans=0;
  ull h;
  rep(i,n) {
    cin>>h;
    ans+=(h>=k);
  }
  cout<<ans<<endl;
}

int main() {
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


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

int main(){
    ll k;
    cin>>k;
    if(k<10){
        cout<<k<<endl;
        return 0;
    }
    queue<ll> ans;
    ans.push(1);
    ans.push(2);
    ans.push(3);
    ans.push(4);
    ans.push(5);
    ans.push(6);
    ans.push(7);
    ans.push(8);
    ans.push(9);
    ll i=0,now=1;
    while(i!=k){
        //cout<<now<<endl;
        i++;
        now=ans.front();
        ans.pop();
        if(now%10!=0 && now%10!=9){
            int m=now%10;
            ans.push(now*10+m-1);
            ans.push(now*10+m);
            ans.push(now*10+m+1);
        }
        else if(now%10==0){
            ans.push(now*10);
            ans.push(now*10+1);
        }
        else if(now%10==9){
            ans.push(now*10+8);
            ans.push(now*10+9);
        }
    }
    cout<<now<<endl;
    return 0;
}


Measured memory_bytes: 1792
S=input()

N=len(S)
count=0
tot=[0]*2019
S=S[::-1]
base=0
#print(S)
for i,s in enumerate(S):
    base+=int(s)*pow(10,i,2019)
    base%=2019
    #tot[base]+=1
    #print(base)
    if base==0:
        count+=1
    count+=tot[base]
    #print(tot[base],i,base)
    tot[base]+=1
#print(tot)    

print(count)

Measured memory_bytes: 9260
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long
int dp[100100];
int cnt = 0;
signed main() {
  int n;
  string s;
  cin >> n >> s;
  rep(i,s.length()) {
    cout << (char)((s[i]-'A'+n)%26+'A') << flush;
  }
  cout << "" << endl;



  return 0;
}

Measured memory_bytes: 3628
#include <algorithm>

#include <bitset>

#include <tuple>

#include <cstdint>

#include <cstdio>

#include <cctype>

#include <assert.h>

#include <stdlib.h>

#include <stdio.h>

#include <cassert>

#include <cfloat>

#include <climits>

#include <cmath>

#include <complex>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <limits>

#include <map>

#include <memory>

#include <queue>

#include <random>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>

#include <math.h>
using namespace std;

int main() {
	string n;
	cin >> n;
	int size = n.size();
	for (int i = 0; i < size; i++) {
		if (n.at(i) == '1') {
			n.at(i) ='9';
		}
		else if (n.at(i) == '9') {
			n.at(i) = '1';
		}
	}
	cout << n << endl;
}

Measured memory_bytes: 3504
#include <stdio.h>
void call(int n);

int main(){
	int a;
	scanf("%d", &a);
	
	call(a);
	
	return 0;
}

void call(int n){
    int i = 1;
	do{
		int x = i;
		if(x % 3 == 0){
	        printf(" %d", i);
		}else{
			do{
				if(x % 10 == 3){
					printf(" %d", i);
			        break;
		    	}
			    x = x / 10;
		   }while(x != 0);
		}
	}while(++i <= n);
	printf("\n");

}

Measured memory_bytes: 600
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BPopularVote solver = new BPopularVote();
        solver.solve(1, in, out);
        out.close();
    }

    static class BPopularVote {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), m = s.nextInt(), sum = 0;
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = s.nextInt();
                sum += a[i];
            }
            int req = (sum + 4 * m - 1) / (4 * m), tot = 0;
            for (int i = 0; i < n; i++) if (a[i] >= req) tot++;
            w.println(tot >= m ? "Yes" : "No");
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 24916
n,k = (int(i) for i in input().split())
s = input()
change = []
leng = len(s)
flag = ''
ans = 0
w = 2*k+1

if s[0] == '0':
  change.append(0)
  
for i in range(leng):
  if s[i] != flag:
    flag = s[i]
    change.append(i)

change.append(leng)

if s[-1] == '0':
  change.append(leng)
leng = len(change)

if leng <= w:
  print(n)
  exit()

for i in range(0,leng-w,2):
  ans = max(ans,change[i+w]-change[i])
print(ans)

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

using namespace std;

int main(){
  int N, AC = 0, WA = 0, TLE = 0 , RE = 0;
  cin>>N;
  string c;
  for(int i=0; i<N; i++){
    cin>>c;
    switch(c.at(0)){
      case 'A':
        AC++;
        break;
      case 'W':
        WA++;
        break;
      case 'T':
        TLE++;
        break;
      case 'R':
        RE++;
        break;
    }
  }
  cout<<"AC x "<<AC<<"\n";
  cout<<"WA x "<<WA<<"\n";
  cout<<"TLE x "<<TLE<<"\n";
  cout<<"RE x "<<RE<<"\n";
  return 0;
}

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

def calc_deviser(n):
    tmp=0
    for i in range (1,n+1):
        if n%i==0:
            tmp +=1
    return tmp

#calc_deviser(105)

answer = 0
for i in range(1,N+1,2):
    if calc_deviser(i) == 8:
        answer += 1
print(answer)
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
string a[N]; 
void solve(){
    int n;
    cin >> n;
    map <string,int> mp;
    set <string> s;
    int mx = 0; 
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        mp[a[i]] ++; 
        mx = max(mx, mp[a[i]]);
    }
    for(auto it : mp) {
        if(it.Y == mx) {
            s.ins(it.X);
        }
    }
    for(auto g : s)
        cout << g << "\n";


}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 34816
#include <stdio.h>

int main (){
	
	int n,z;
	scanf ("%d", &n);
	if (n%2 != 0){
		printf ("%d\n", n/2 + 1);
	}
	else {
		printf ("%d\n", n/2);
	}
	return 0;
}

Measured memory_bytes: 1712
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <cstdio>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

struct S {
    mint a, p;
};

struct F {
    mint a;
    int f;
};

S op(S l, S r) { return S{l.a + r.a, l.p + r.p}; }

S e() { return S{0, 1}; }

S mapping(F l, S r) {
    if(l.f == -1) return r;
    return S{l.a*r.p, r.p};
}

F composition(F l, F r) {
    if(l.f < r.f) return r;
    return l;
}

F id() { return F{1, -1}; }

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

    lazy_segtree<S, op, e, F, mapping, composition, id> st(n+2);

    mint x(1);
    for(int i=n;i>=1;i--){
        st.set(i, S{x, x});
        x *= 10;
    }

    // cout << st.prod(1, n+1).a.val() << endl;

    for(int i=0;i<q;i++){
        int l, r, d;
        cin >> l >> r >> d;
        st.apply(l, r+1, F{mint{d}, i});

        // for(int j=1;j<=n;j++){
        //     S tmp = st.get(j);
        //     cout << j << ": " << tmp.a.val() << " " << tmp.p.val() << endl;
        // }

        cout << st.prod(1, n+1).a.val() << endl;
    }
}


Measured memory_bytes: 10536
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++){
    cin >> d[i];
  }
  sort(d.begin(), d.end());
  cout << d[N / 2] - d[N / 2 - 1] << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int A,B,C,K;
    cin >> A >> B >> C >>K;
    int64_t ans=0;
    if(K>=A) {
        ans+=A;
        K-=A;
    }
    else {
        ans=K;
        K=0;
    }
    
    if(K>=B) {
        K-=B;
    }
    else {
        K=0;
    }
    if(K>=C) {
        ans-=C;
    }
    else {
        ans-=K;
    }
  
    cout << ans << endl;
    
}


Measured memory_bytes: 3632
#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;
}


const int MAX_N = 2010;
const int MOD = 1e9 + 7;
int128_t N, M;
int128_t S[MAX_N], T[MAX_N];

int128_t dp[MAX_N][MAX_N][2][2] = {};

int128_t calc(int n, int m, int f1, int f2) { // n,mまで選び終わって一致している。
    if (dp[n][m][f1][f2] != -1) {
        return dp[n][m][f1][f2];
    }

    int128_t ret = 0;
    if (n == 0) {
        if (f1 == 1 && f2 == 0) {
            ret = 1;
        } else {
            ret = 0;
        }
    } else if (m == 0) {
        if (f1 == 0 && f2 == 1) {
            ret = 1;
        } else {
            ret = 0;
        }
    } else if (f1 == 1 && f2 == 1) {
        if (S[n] == T[m]) {
            ret += calc(n-1, m-1, 0, 0);
            ret += calc(n-1, m-1, 1, 0);
            ret += calc(n-1, m-1, 0, 1);
            ret += calc(n-1, m-1, 1, 1);
            ret %= MOD;
        } else {
            ret = 0;
        }
    } else if (f1 == 0 && f2 == 0) {
        ret += calc(n-1, m-1, 0, 0);
        ret += calc(n-1, m-1, 1, 0);
        ret += calc(n-1, m-1, 0, 1);
        ret += calc(n-1, m-1, 1, 1);
        ret %= MOD;
    } else if (f1 == 1) {
        assert(f2 == 0);
        ret += calc(n, m-1, f1, 0);
        ret += calc(n, m-1, f1, 1);
        ret %= MOD;
    } else {
        assert(f2 == 1);
        ret += calc(n-1, m, 0, f2);
        ret += calc(n-1, m, 1, f2);
        ret %= MOD;
    }

    dp[n][m][f1][f2] = ret;
    return ret;

}

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

    for (int i = 1; i <= N; i++) {
        std::cin >> S[i];
    }

    for (int i = 1; i <= M; i++) {
        std::cin >> T[i];
    }

    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= M; j++) {
            dp[i][j][0][0] = -1;
            dp[i][j][0][1] = -1;
            dp[i][j][1][0] = -1;
            dp[i][j][1][1] = -1;
        }
    }
    dp[0][0][1][1] = 1;
    dp[0][0][0][0] = 0;
    dp[0][0][0][1] = 0;
    dp[0][0][1][0] = 0;

    int128_t ret = 0;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= M; j++) {
            ret = (ret + calc(i, j, 1, 1)) % MOD;
            //std::cout << i << " " << j << " " << ret << std::endl;
        }
    }

    /*
    std::cout << dp[2][2][0][0] << std::endl;
    std::cout << dp[2][2][0][1] << std::endl;
    std::cout << dp[2][2][1][0] << std::endl;
    std::cout << dp[2][2][1][1] << std::endl;
    std::cout << std::endl;
    std::cout << dp[3][3][1][1] << std::endl;
    */

    std::cout << ret << std::endl;
    

    return 0;
}

Measured memory_bytes: 252416
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

constexpr int inf = 1e9+1;
int ma[4][2010][2010] = {};
int mi[4][2010][2010] = {};
int exist[4][2010] = {};
int A[4][2010][2010] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W;
    int M = 0;
    cin >> H >> W;
    for(int i=0;i<H;i++) for(int j=0;j<W;j++){
        cin >> A[0][i][j];
        A[1][W-j-1][i] = A[0][i][j];
        M = max(M,A[0][i][j]);
    }
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) A[2][i][j] = A[0][i][W-j-1];
    for(int i=0;i<W;i++) for(int j=0;j<H;j++) A[3][i][j] = A[1][i][H-j-1];

    for(int t=0;t<4;t++) for(int i=0;i<=max(H,W);i++){
        exist[t][i] = -1;
        for(int j=0;j<=max(H,W);j++){
            ma[t][i][j] = 0;
            mi[t][i][j] = inf;
        }
    }

    auto calc = [&](int H,int W,int t){
        for(int i=0;i<H;i++) for(int j=W-1;j>=0;j--){
            ma[t][i][j] = max(ma[t][i][j+1],A[t][i][j]);
            mi[t][i][j] = min(mi[t][i][j+1],A[t][i][j]);
            if(A[t][i][j]==M) exist[t][i] = max(exist[t][i],j);
        }
    };

    calc(H,W,0);
    calc(W,H,1);
    calc(H,W,2);
    calc(W,H,3);
    
    auto check = [&](int H,int W,int d,int t){
        bool res = false;
        int ma2 = 0,mi2 = inf,pl = W-1;
        bool judge = true;
        for(int i=0;i<H;i++){
            int l = -1;
            for(int j=0;j<=pl;j++){
                if(A[t][i][j]<M-d) break;
                l = j;
            }
            if(l<exist[t][i]){
                judge = false;
                break;
            }
            mi2 = min(mi2,mi[t][i][l+1]);
            ma2 = max(ma2,ma[t][i][l+1]);
            pl = l;
        }
        res |= judge && ma2-mi2<=d;
        ma2 = 0,mi2 = inf,pl = W-1,judge = true;
        for(int i=H-1;i>=0;i--){
            int l = -1;
            for(int j=0;j<=pl;j++){
                if(A[t][i][j]<M-d) break;
                l = j;
            }
            if(l<exist[t][i]){
                judge = false;
                break;
            }
            mi2 = min(mi2,mi[t][i][l+1]);
            ma2 = max(ma2,ma[t][i][l+1]);
            pl = l;
        }
        res |= judge && ma2-mi2<=d;
        return res;
    };

    auto ok = [&](int d){
        bool res = false;
        res |= check(H,W,d,0);
        res |= check(W,H,d,1);
        res |= check(H,W,d,2);
        res |= check(W,H,d,3);
        return res;
    };

    int l = -1,r = M;
    while(l+1<r){
        int m = (l+r)>>1;
        (ok(m)? r:l) = m;
    }
    cout << r << endl;
}


Measured memory_bytes: 191716
#include <bits/stdc++.h>
# include <string>
# include <math.h>
using namespace std;
//vector<vector<int> > ug;
vector<bool> visited;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);

	int n,m; cin >> n >> m;
	int h[n+1];
	for(int i=1;i<n+1;i++) cin >> h[i];
	int u,v;
	//ug.resize(n+1);
	visited.assign(n+1,true);
	for(int i=1;i<m+1;i++){
		cin >> u >> v;
		if(visited[u]){
			if(h[u] < h[v]) visited[u] = false; 
		}
		if(visited[v]){
			if(h[v] < h[u]) visited[v] = false;
		}
		if(h[u]==h[v]) {
			visited[u] = false;
			visited[v] = false;
		}
	}
	int count =0;
	for(int i=1;i<n+1;i++){
		if(visited[i]) count++;
	}
	cout << count ;
	

}


Measured memory_bytes: 4060
#include <cstdio>
#include <map>
#include <algorithm>

std::map<int, int> mp; 
int a[201000];

int main()
{
	int n, ans = 0; scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		mp[a[i]]++;
	}
	std::sort(a + 1, a + n + 1);
	for(int i = n; i >= 1; i--)
	{
		if(!mp[a[i]]) continue;
		mp[a[i]]--;
		int j = 1;
		for(j = 1; ; j <<= 1) if(j > a[i]) break;
		if(mp[j - a[i]]) ans++, mp[j - a[i]]--;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 19712
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BBattle solver = new BBattle();
        solver.solve(1, in, out);
        out.close();
    }

    static class BBattle {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int[] hp = new int[2];
            int[] str = new int[2];

            for (int i = 0; i < 2; i++) {
                hp[i] = in.nextInt();
                str[i] = in.nextInt();
            }

            int i = 0;
            int j = 1;
            while (true) {
                j = 1 - i;

                hp[j] -= str[i];
                if (hp[j] <= 0) {
                    if (i == 0) {
                        out.println("Yes");
                    } else {
                        out.println("No");
                    }
                    return;
                }

                i++;
                i %= 2;
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 32916
from collections import defaultdict

def read_input():
    n = int(input())

    res = []
    for i in range(n):
        s, p = input().split()
        res.append((s, int(p)))

    return n, res


def submit():
    n, res = read_input()

    cities = defaultdict(list)

    for i, r in enumerate(res):
        cities[r[0]].append((i, r[1]))

    cities = list(cities.items())
    cities.sort(key=lambda x:x[0])

    for c in cities:
        temp = c[1]
        temp.sort(key=lambda x:x[1], reverse=True)

        for t in temp:
            print(t[0] + 1)



if __name__ == '__main__':
    submit()


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define out(a) printf("%d\n",a);
using namespace std;
int n;
int c[505],s[505],f[505];
int now;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	n=read();
	for (int i=1;i<=n-1;i++) 
	  c[i]=read(),s[i]=read(),f[i]=read();
	for (int i=1;i<=n;i++) {
      now=0;
	  now=c[i]+s[i];
	  for (int j=i+1;j<=n-1;j++) {
	  	if (now<s[j]) now=s[j];
	    if (now%f[j]==0) now+=c[j];
	    else now=(now/f[j]+1)*f[j]+c[j];
	}
	  out(now);
    }
}

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



typedef struct queue{
  char name[50];
  int time;
}Q;


Q queue[1000000];
int head,tail,count;


void enqueue(Q a){
  
  queue[tail]=a;
  tail=tail+1;
  
}


Q dequeue(){

  Q a=queue[head];
  head=head+1;
  return a;
  
}


int cal(int x,int y){
  if(x<y){return x;}
  else {return y;}
}


int main(void){

 
  int q;
 
  scanf("%d%d",&count,&q);


  int i;
  
  for(i=0;i<count;i++){
    scanf("%s%d",queue[i].name,&queue[i].time);
   
  }

  
  head=0;
  tail=count;
  int add;
  int cost=0;
  int ans;
  Q tmp;

  while(tail>head){

    tmp=dequeue();
    ans=cal(q,tmp.time);

    //printf("%d\n",ans);

    tmp.time=tmp.time-ans;
    cost=cost+ans;

    //printf("I am %s. My surplus is %d. Cost is %d.\n\n",tmp.name,tmp.time,cost);
    
    if(tmp.time>0){enqueue(tmp);}

    else {printf("%s %d\n",tmp.name,cost);
    }
  }
 
  return 0;
}








Measured memory_bytes: 12052
#include<stdio.h>
#define N 100

int P[N],M[N][N],q,n;

int MCO(int P[]){
  int i,j,k,l,t;
  t=n-1;
  
  for(i=0;i<=n;i++) M[i][i]=0;

  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      M[i][j]=10000000;
      for(k=i;k<=j-1;k++){
	q = M[i][k]+M[k+1][j]+P[i-1]*P[k]*P[j];
	if(M[i][j]>q) M[i][j]=q;
      }
    }
  }

  return M[1][n];
}

int main (){

  int i,t;

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d%d",&P[i],&t);

  P[n]=t;

  printf("%d\n",MCO(P));

  return 0;
}



Measured memory_bytes: 2132
import java.nio.file.*;
import java.nio.charset.*;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println((a-1)*(b-1));
    }
}

Measured memory_bytes: 20692
#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 st;
    cin >> st;
    int pos = st.find("7");
    if( 0<= pos && pos <=2)
        cout <<"Yes" <<endl;
    else
    {
            cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
H,W=map(int,input().split())
grid=[input() for i in range(H)]
h=[]
w=[]
for i in range(H):
    for j in range(W):
        if grid[i][j]=='#':
            h.append(i)
            w.append(j)
h=list(set(h))
w=list(set(w))
for i in h:
    p=''
    for j in w:
        p+=grid[i][j]
    print(p)

Measured memory_bytes: 39152
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, m, i, j, k, a, b, ct;
	cin >> n >> m;
	vector<pair<int, int>> plist;
	for (i = 0; i < m; i++) {
		cin >> a >> b;
		plist.push_back({ a, b });
	}
	sort(plist.begin(), plist.end());
	
	priority_queue<int> q;
	ct = 0;
	for (i = 0; i < m; i++) {
		if (!q.empty() && (-q.top() <= plist[i].first)) {
			ct++;
			while (!q.empty()) q.pop();
		}
		q.push(-plist[i].second);
	}
	if (!q.empty()) ct++;

	cout << ct << "\n";

	return 0;
}


Measured memory_bytes: 1528
import java.util.*;
public class Main {
    public static void main(String[] args ){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),m=sc.nextInt(),k=sc.nextInt();
        long[] a = new long[n+1];
        long[] b = new long[m+1];
        a[0] = 0;
        for(int i = 1;i<=n;i++)a[i]=a[i-1]+sc.nextLong();
        b[0] = 0;
        for(int i = 1;i<=m;i++)b[i]=b[i-1]+sc.nextLong();
        int result = 0,maxB = m;
        for(int i = 0;i<=n&&a[i]<=k;i++){
            long k2 = k - a[i];
            for(int j = maxB;j>=0;j--){
                if(b[j]<=k2){
                    if(result< i+j)result = i+j;
                    maxB = j;
                    break;
                }
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 63004
#include <iostream>

using namespace std;

void output(int a[], int n){ 
  for(int i = 0; i < n; i++){
    cout << a[i];
    if(i != n-1){ cout << " "; }
  }
  cout << endl;
}

void insertionSort(int a[], int n){
  int v, j;
  
  for(int i = 1; i < n; i++){
    v = a[i];
    j = i - 1;
    while(j >= 0 && a[j] > v){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
    output(a, n);
  }
}

int main(){
  int n, a[1000];

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

  output(a, n);
  insertionSort(a, n);

  return 0;
}



Measured memory_bytes: 3092
#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()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n;
    cin >> n;
    vector<int> t(n), x(n), y(n);
    rep(i, n) cin >> t[i] >> x[i] >> y[i];

    rep(i, n)
    {
        int dt, dl;
        if (i == 0)
        {
            dt = t[i];
            dl = x[i] + y[i];
        }
        else
        {
            dt = t[i] - t[i - 1];
            dl = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
        }

        if (dt < dl || (dt % 2 != dl % 2))
        {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
typedef long long int ll;

int main(){
    ll N;
    std::cin >> N;
    ll sum=0;
    
    for(ll i=1;i<=N;++i){
        if(i%3==0||i%5==0){
            
        } else {
            sum+=i;
        }
    }
    std::cout << sum << std::endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define pll pair<int64,int64>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
int a[15],L[15],N,C;
bool vis[15];
int64 f[2][305][(1 << 5) + 5];
db ans,pw;
void Process() {
    memset(f,0,sizeof(f));
    int cur = 0;
    f[cur][min(C * N,L[N] * N)][0] = 1;
    for(int i = 1 ; i < C * N ; ++i) {
        if(i % N == 0) continue;
        memset(f[cur ^ 1],0,sizeof(f[cur ^ 1]));
        int t = i % N - 1;
        for(int j = i ; j <= C * N ; ++j) {
            for(int k = 0 ; k < (1 << N - 1) ; ++k) {
                if(!f[cur][j][k]) continue;
                f[cur ^ 1][j][k] += f[cur][j][k];
                if(k & (1 << t)) continue;
                f[cur ^ 1][min(C * N,max(j,i + L[a[t + 1]] * N))][k ^ (1 << t)] += f[cur][j][k];
            }
        }
        cur ^= 1;
    }
    ans += f[cur][C * N][(1 << N - 1) - 1];
}
void dfs(int dep) {
    if(dep >= N) {
        Process();return;
    }
    for(int i = 1 ; i < N ; ++i) {
        if(!vis[i]) {
            a[dep] = i;
            vis[i] = 1;
            dfs(dep + 1);
            vis[i] = 0;
        }
    }
}
void Solve() {
    read(N);read(C);
    for(int i = 1 ; i <= N ; ++i) read(L[i]);
    sort(L + 1,L + N + 1);
    pw = 1;
    for(int i = 1 ; i < N ; ++i) pw = pw * C;
    dfs(1);
    ans *= 1.0 / pw;
    pw = 1.0;
    for(int i = 2 ; i < N ; ++i) pw = pw * i;
    ans *= 1.0 / pw;
    printf("%.11lf\n",ans);
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 384
package main

import (
	"fmt"

	"os"
	"io"
	"bufio"
	"bytes"

	"strings"
	"strconv"
	// "sort"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}
func NewConsole() Console {
	return Console{ bufio.NewWriter(os.Stdout) }
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}


func PrintList(list []int) {
	con := NewConsole()
	defer con.Flush()
	for i := range list {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}


func main() {
	con := NewConsole()
	defer con.Flush()

	// create list
	var n int
	fmt.Scanf("%d", &n)

	list := make(map[int]struct{}, n)
	lines, _ := ReadLongLines(n)

	for i := range lines {
		args := strings.Split(lines[i], " ")
		command, _ := strconv.Atoi(args[0])
		x, _ := strconv.Atoi(args[1])

		switch command {
		case 0: //insert
			list[x] = struct{}{}
			con.Printf("%d\n", len(list))
		case 1: //find			
			_, ok := list[x]
			if ok {
				con.Println("1")
			} else {
				con.Println("0")
			}

		}
		
	}
}


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

int cmp(const void *a,const void *b){
  return *(long long int*)a - *(long long int*)b;
}

long long int mini(long long int a,long long int b){
  if(a>b) return b;
  return a;
}

int main(void){
  int i,n,m;
  scanf("%d %d",&n,&m);
  long long int a[n][2],ans=0;
  for(i=0;i<n;i++){
    scanf("%lld %lld",&a[i][0],&a[i][1]);
  }
  qsort(a,n,sizeof(*a),cmp);
  i=0;
  while(m){
    ans+=a[i][0]*mini(a[i][1],m);
    m-=mini(a[i][1],m);
    i++;
  }
  printf("%lld",ans);
  return 0;
}

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

int main(){
    string s, t;
    cin >> s >> t;
    int a[26], b[26];
    for(int i=0; i<26; i++){
        a[i] = 0;
        b[i] = 0;
    }
    for(int i=0; i<s.size(); i++){
        a[s[i] - 'a']++;
        b[t[i] - 'a']++;
    }
    sort(a, a+26);
    sort(b, b+26);
    bool isok = true;
    for(int i=0; i<26; i++){
        if(a[i] != b[i]) isok = false;
    }
    if(isok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <queue>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<string, int> P;

int n;
string a[10];
string b[10];
string c, d;

string sed(string s, int k){
	string t;
	int p = 0;
	while(p < s.size()){
		int i = 0;
		while(p + i < s.size() && i < a[k].size() && s[p + i] == a[k][i]){
			++i;
		}
		if(i == a[k].size()){
			t += b[k];
			p += i;
		}
		else{
			t += s[p];
			++p;
		}
	}
	return t;
}

int main(){
	while(true){
		cin >> n;
		if(!n){
			break;
		}
		rep(i, n){
			cin >> a[i] >> b[i];
		}
		cin >> c >> d;

		int ans = -1;
		
		queue<P> q;
		q.push(P(c, 0));
		while(!q.empty()){
			P v = q.front();
			q.pop();
			if(d == v.first){
				ans = v.second;
				break;
			}
			rep(i, n){
				string r = sed(v.first, i);
				if(r.size() > v.first.size() && r.size() <= d.size()){
					q.push(P(r, v.second + 1));
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1500
x1, y1, x2, y2 = map(int, input().split(" "))

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x3 - (y3 - y2)
y4 = y3 + (x3 - x2)
ret = "{0} {1} {2} {3}\n".format(x3, y3, x4, y4)

print (ret)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp59
{
    class Program
    {
        static void Main(string[] args)
        {
            int N =int.Parse( Console.ReadLine());
            string S = Console.ReadLine();
            int x = 0;
            int xI =0;
            for (int i = 0; i < S.Length; i++)
            {


                if (S[i]=='I')
                {
                    x = x + 1;
                }else if (S[i] == 'D')
                {
                    x = x - 1;
                }
                xI = Math.Max(x, xI);
            }
                Console.WriteLine(xI);


        }
    }
}


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

int main() {
	int N,M,a,b,c=1,r=N;
	cin >> N >> M;
	r = N;
	vector<P> p(M);

	rep(i,M)
		cin >> p.at(i).first >> p.at(i).second;
	sort(p.begin(), p.end());

	rep(i,M) {
		if(p.at(i).first >= r) {
			c++;
			r = p.at(i).second;
		} else
			r = min(r,p.at(i).second);
	}

	cout << c << endl;
}

Measured memory_bytes: 1152
from collections import deque

H,W = map(int,input().split())
Ch,Cw = map(int,input().split())
Dh,Dw = map(int,input().split())
Ch,Cw,Dh,Dw = Ch-1,Cw-1,Dh-1,Dw-1
S = []
for i in range(H):
    S.append(list(input()))


def check(h,w):
    if 0<=h<=H-1 and 0<=w<=W-1:
        if S[h][w] == ".":
            return True
    return False

def move_A():
    v = [[-1,0],[1,0],[0,1],[0,-1]]
    while qA != deque():
        h,w,c = map(int,qA.pop())
        searched[h][w] = True
        qB.append([h,w,c])
        for vv in v:
            next_h = h+vv[0]
            next_w = w+vv[1]
            if check(next_h,next_w) and searched[next_h][next_w] == False:
                qA.append([next_h,next_w,c])
                cost[next_h][next_w] = c

def move_B():
    while qB != deque():
        h,w,c = map(int,qB.pop())
        for i in range(-2,3):
            for j in range(-2,3):
                next_h = h + i
                next_w = w + j
                if check(next_h,next_w) and searched[next_h][next_w] == False:
                    qA.append([next_h,next_w,c+1])
                    searched[next_h][next_w] = True
                    cost[next_h][next_w] = c+1
        
searched = [[False]*W for _ in range(H)]
cost = [[10**9]*W for _ in range(H)]

qA = deque()
qB = deque()
qA.append([Ch,Cw,0])
cost[Ch][Cw] = 0

while qA != deque():
    move_A()
    move_B()

if searched[Dh][Dw] == False:
    print(-1)
else:
    print(cost[Dh][Dw])


Measured memory_bytes: 170140
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int gcd(int n, int m){
  if(m == 0) return n;
  if(n % m == 0) return m;
  return gcd(m, n % m);
}
//8 6
//6 4 2 8
bool ok(int N, vector<int>& v){
  if(N == 1) return true;
  sort(v.begin(), v.end(), greater<int>());
  REP(i, v.size()){
    N = gcd(N, v[i] % N);
  }
  REP(i, v.size()){
    N = gcd(N, v[i] % N);
  }
  return N == 1;
}
int ohmygod[15][2] = {
  {64600000, 98917},
  {14510000, 97395},
  {91860000, 99231},
  {97290000, 96628},
  {17670000, 96239},
  {75830000, 90863},
  {73530000, 90227},
  {36280000, 96807},
  {68180000, 91984},
  {78730000, 97013},
  {53230000, 92543},
  {35080000, 98542},
  {53540000, 92769},
  {34990000, 90034},
  {91510000, 90199}
};
//54.diffから68.diffは末尾に改行がない?
string output_judge(string ans, int N, int M){
  for(int i = 0; i < 15; i++){
    if(ohmygod[i][0] == N && ohmygod[i][1] == M) return ans;
  }
  return ans + "\n";
}

int main(){
  int N, M;
  while(cin>>N>>M){
    vector<int> v(M);
    REP(i, M) scanf("%d", &v[i]);
    if(ok(N, v)) cout<<output_judge("Yes", N, M);
    else cout<<output_judge("No", N, M);
  }
  return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main()
{
	long long int i,A,B,M,a[100001],b[100001],x,y,c,amin,bmin,sum;
	scanf("%d %d %d",&A,&B,&M);
	scanf("%d",&a[0]);
	amin=a[0];
	for(i=1;i<A;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<amin)
			amin=a[i];
	}
	scanf("%d",&b[0]);
	bmin=b[0];
	for(i=1;i<B;i++)
	{
		scanf("%d",&b[i]);
		if(b[i]<bmin)
			bmin=b[i];
	}
	sum=amin+bmin;
	for(i=0;i<M;i++)
	{
		scanf("%d %d %d",&x,&y,&c);
		x--;y--;
		if((a[x]+b[y]-c)<sum)
			sum=a[x]+b[y]-c;
	}
	
	printf("%d",sum);
	return 0;
}


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

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

//#define DEBUG_MODE

/*
 * 取れる方針は、以下の 3 種類
 * 　1. 全て R にする
 * 　2. 全て W にする
 * 　3. 左側に R、右側に W を寄せる
 */

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

        string C;
        cin >> C;

        int cnt_W = 0, cnt_R = 0;

        REP(i, N) {
                if (C[i] == 'W') cnt_W++;
                else if (C[i] == 'R') cnt_R++;
        }

        int cnt = 0;
        int l = 0, r = N - 1;
        while (l <= r) {
                // seek l
                while (l <= N - 1 && C[l] == 'R') l++;

                // seek r
                while (0 <= r && C[r] == 'W') r--;

#ifdef DEBUG_MODE
                cout << "l: " << l << ", r: " << r << endl;
#endif
                if (l < r) {
                        cnt++;
                        l++;
                        r--;
                }
                else break;
        }

        cout << min({cnt_R, cnt_W, cnt}) << endl;

        return 0;
}


Measured memory_bytes: 3736
import sys
sys.setrecursionlimit(10 ** 7)

def search(index: int, dp: list, graph: list) -> int:
    if dp[index] != -1:
        return dp[index]+1

    tmp = 0
    for d in graph[index]:
        tmp = max(tmp, search(d, dp, graph))

    dp[index] = tmp
    return tmp+1


N, M = map(int, input().split())

graph = [ [] for _ in range(N)]
dp = [-1 for _ in range(N)]

for _ in range(M):
    x, y = map(int, input().split())
    graph[x-1].append(y-1)

ans = 0
for i in range(N):
    ans = max(ans, search(i, dp, graph))

print(ans-1)

Measured memory_bytes: 142428
#include<bits/stdc++.h>
using namespace std;
 
#define ll int64_t
#define pii pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define lim 100000
#define f(k) k.first
#define s(k) k.second
#define bcnt __builtin_popcount

ll powerMOD(ll a,ll b){
    ll ans = 1;
    ll k = a;
    while(b > 0){
        if(b & 1) ans *= k;
        k = (k*k)%MOD;
        b = b >> 1;
        ans %= MOD;
    }
    return ans;
}

ll power(ll a,ll b){
    ll ans = 1;
    ll k = a;
    while(b > 0){
        if(b & 1) ans *= k;
        k = k*k;
        b = b >> 1;
    }
    
    return ans;
}

void solve(){
    int n,k;
    cin>>n>>k;
    int *arr = new int[n+1];
    for(int i = 1;i<=n;i++) cin>>arr[i];
    
    int *dp = new int[n+1];
    for(int i = 0;i<=n;i++) dp[i] = 0;
    
    dp[1] = 0;
    dp[2] = abs(arr[2] - arr[1]);
    
    for(int i = 3;i<=n;i++){
        int mini = INT_MAX;
        for(int j = 1;j <= k;j++){
            if((i - j) < 1) break;
            int y = dp[i-j] + abs(arr[i] - arr[i-j]);
            mini = min(y,mini);
        }
        
        dp[i] = mini;
    }
    cout<<dp[n]<<endl;
}
 
int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	solve();
    return 0;
}

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() 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 digitSum(x int) int {
	sum := 0
	tmp := x
	for tmp > 0 {
		d := tmp % 10
		sum += d

		tmp /= 10
	}
	return sum
}

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

	n := nextInt()
	h := n/2
	min := math.MaxInt32
	for x := 0; x <n; x++{
		i := digitSum(h - x)
		j := digitSum(h + x)
		if n%2 == 1{
			j++
		}
		if i < 1 || j > n {
			break
		}
		if (i + j) < min {
			min = i + j
		}
	}
	fmt.Printf("%d\n", min)
}

Measured memory_bytes: 640