akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
#include <tuple>
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N;

    cin >> N;

    vector<int> a(N);
    vector<int> b(N);

    vector<int> c(N + 1);
    vector<vector<int> > d(N + 1);

    vector<int> ans(N, -1);

    for(int i = 1; i < N; i++) {
        cin >> a[i] >> b[i];
        c[a[i]]++;
        c[b[i]]++;
        d[a[i]].push_back(i);
        d[b[i]].push_back(i);
    }

    int K = *max_element(c.begin(), c.end());

    queue<pair<int, int> > q;

    q.push(make_pair(1, -1));

    while(!q.empty()) {
        int x = q.front().first;
        int r = q.front().second;
        cerr << x << " " << r << endl;
        q.pop();
        int y = 1;
        for(int i = 0; i < d[x].size(); i++) {
            if(y == r) {
                y++;
            }
            if(ans[d[x][i]] == -1) {
                ans[d[x][i]] = y;
                if(a[d[x][i]] == x) {
                    q.push(make_pair(b[d[x][i]], y));
                } else {
                    q.push(make_pair(a[d[x][i]], y));
                }
                y++;
            }
        }
    }

    cout << K << endl;

    for(int i = 1; i <= N - 1; i++) {
        cout << ans[i] << endl;
    }
}


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

int main(){
	int n;

	while (cin >> n, n != 0){
		int o;
		int point[21][21] = { 0 };
		int X, Y;
		char dir;
		int move;
		int x = 10, y = 10;
		int count = 0;

		for (int i = 0; i < n; i++){
			cin >> X >> Y;
			point[X][Y] = 1;
		}

		cin >> o;

		for (int i = 0; i < o; i++){
			cin >> dir >> move;

			for (int j = 0; j < move; j++){
				if (dir == 'N'){
					y += 1;
				}
				if (dir == 'E'){
					x += 1;
				}
				if (dir == 'S'){
					y -= 1;
				}
				if (dir == 'W'){
					x -= 1;
				}
				if (point[x][y] == 1){
					count++;
					point[x][y] = 0;
				}
			}
		}
		if (n == count) cout << "Yes" << endl;
		else cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>

int main(void)
{ 
	int a[3];
	int i,j,m;
	for(i=0;i<3;i++) scanf("%d",&a[i]);
	for(i=0;i<3;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				m=a[i];
				a[i]=a[j];
				a[j]=m;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
	return 0;
}


Measured memory_bytes: 2024
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b)cout << c << endl;
	else if (a == c)cout << b << endl;
	else cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main () {
  	int hp, types;
	cin >> hp >> types;
  	int count = types;
	while (count > 0 ) {
      int atk;
      cin >> atk;
      hp -= atk;
      count--;
    }
  	if (hp > 0 ) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n;
string s;

signed main() {
    cin >> n >> s;
    rep(i,s.size()) s[i] = (s[i]-'A'+n)%26+'A';
    cout << s << endl;
}




Measured memory_bytes: 256
// AOJ 2473 Poor Computer
// 2018.2.1 bal4u

#include <stdio.h>

#define MAX 42

typedef struct { long long s; int k; } Q;
Q q[10000]; int top;

int lim;
long long goal;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int bitcount64(long long x)
{
	x = ((x & 0xAAAAAAAAAAAAAALL) >>  1) + (x & 0x55555555555555LL);
	x = ((x & 0xCCCCCCCCCCCCCCLL) >>  2) + (x & 0x33333333333333LL);
	x = ((x & 0xF0F0F0F0F0F0F0LL) >>  4) + (x & 0x0F0F0F0F0F0F0FLL);
	x = ((x & 0x00FF00FF00FF00LL) >>  8) + (x & 0xFF00FF00FF00FFLL);
	x = ((x & 0xFF0000FFFF0000LL) >> 16) + (x & 0x00FFFF0000FFFFLL);
	x = ((x & 0xFFFFFF00000000LL) >> 32) + (x & 0x000000FFFFFFFFLL);
	return (int)x;
}

int trailingZero(long long x)
{
#if 0
	int k = 0;
	while (!(x & 1)) k++, x >>= 1;
	return k;
#endif
	return bitcount64(~x & (x-1));
}

int check(long long s, int k)
{
	int i, j, t;
	long long s1, s2;

	q[0].s = s, q[0].k = k, top = 1;
	while (top) {
		s = q[--top].s, k = q[top].k;
		if (k + bitcount64(goal & ~s) > lim) continue;
		if ((s & goal) == goal) return 1;

		for (s1 = s; s1; s1 &= s1-1) {
			i = trailingZero(s1);
			for (s2 = s; s2; s2 &= s2-1) {
				j = trailingZero(s2);

				t = i+j;
				if (t <= MAX && !((s >> t)&1)) {
					q[top].s = s | (1LL << t), q[top++].k = k+1;
				}

				t = i-j; if (t < 0) t = -t;
				if (t > 0 && !((s >> t)&1)) {
					q[top].s = s | (1LL << t), q[top++].k = k+1;
				}
			}

			while (i < MAX) {
				if (!((s >> i) & 1)) {
					q[top].s = s | (1LL << i), q[top++].k = k+1;
				}
				i <<= 1;
			}
		}
	}
	return 0;
}

int main()
{
	int n;

	lim = n = in();
	while (n--) goal |= 1LL << in();
	while (!check(2LL, 0)) lim++;
	printf("%d\n", lim);
	return 0;
}


Measured memory_bytes: 2080
# -*- coding: utf-8 -*-

s = input()
q = int(input())
qs = [list(input().split()) for i in range(q)]

pls_vec = []
pls_append = pls_vec.append

mns_vec = []
mns_append = mns_vec.append

q1_vec = 1
for qi in qs:
    if qi[0]=="1":
        q1_vec*=(-1)
    else:
        if q1_vec==1:
            if qi[1]=="1":
                mns_append(qi[2])
            else:
                pls_append(qi[2])
        else:
            if qi[1]=="1":
                pls_append(qi[2])
            else:
                mns_append(qi[2])

ret = "".join(mns_vec[::-1]) + s + "".join(pls_vec)
if q1_vec==-1:
    ret=ret[::-1]
print(ret)

Measured memory_bytes: 33024
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
inline int  in(){int n;scanf("%lld",&n);return n;}
inline void out(int n){printf("%lld\n",n);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

string s;

signed main(){
    io();
    cin>>s;
    if(s[0]!='A'){
        cout<<"WA"<<endl;
        return 0;
    }
    bool f=false;
    int index;
    REP(i,2,s.size()-1){
        if(s[i]=='C'){
            if(!f){
                f=true;
                index=i;
            }else{
                cout<<"WA"<<endl;
                return 0;
            }
        }
    }
    if(!f){
        cout<<"WA"<<endl;
        return 0;
    }
    REP(i,1,s.size()){
        if(i==index) continue;
        if(!islower(s[i])){
            cout<<"WA"<<endl;
            return 0;
        }
    }
    cout<<"AC"<<endl;

    return 0;
}


Measured memory_bytes: 888
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

struct Person{
    ll gold, silver, bronze;
    bool operator < (const Person &other) const {
        return gold - silver < other.gold - other.silver;
    }
} person[200005];

ll gold[200005], silver[200005], x, y, z;
int main(){

    ios :: sync_with_stdio(false);
    cin >> x >> y >> z;
    int N = x+y+z;

    ll ans = 0;
    FOR(i,N){
        cin >> person[i].gold >> person[i].silver >> person[i].bronze;
        person[i].gold -= person[i].bronze;
        person[i].silver -= person[i].bronze;
        ans += person[i].bronze;
    }

    sort(person+1, person+N+1);
    priority_queue<ll, vector<ll>, greater<ll> > pq;

    ll sum = 0;
    FOR(i,N){
        pq.push(person[i].silver);
        sum += person[i].silver;
        if(pq.size() > y){
            sum -= pq.top();
            pq.pop();
        }
        gold[i] = sum;
    }

    sum = 0;
    while(!pq.empty()) pq.pop();
    FORD(i,N,1){
        pq.push(person[i].gold);
        sum += person[i].gold;
        if(pq.size() > x){
            sum -= pq.top();
            pq.pop();
        }
        silver[i] = sum;
    }

    ll mx = -1e16;
    FORU(i, y, y+z) mx = max(mx, gold[i] + silver[i+1]);
    ans += mx;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6520
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();
    int n = A - B*2;
    if(n > 0){
      System.out.println(n);
    }else{
      System.out.println(0);
    }


  }
}

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

int main()
{
    int  x,y;
    cin>>x>>y;

    long long  sum=0;

    for(int i=y+1;i<=x;i++)
    {
        sum=sum+(i-y)*(x/i);
        if(x%i-y>=0)
            sum=sum+1+x%i-y;
        //cout<<sum<<endl;
    }
    if(y==0)
        sum=sum-x;

    cout<<sum<<endl;




    return 0;
}


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

int main() {
  long long B,X,i;
  long double A;
  
  cin >> X ;
  A = 100;
  i = 0;
  
  while(A < X)
  {
    B = (A * 0.01);
    A = A + B;
    i++;
  }
  cout << i << endl;
}


Measured memory_bytes: 3596
# -*- coding: utf-8 -*-
"""
Created on Mon May 11 16:14:32 2020

@author: shinba
"""


n = int(input())

X = list(map(int,input().split()))

A = sorted(X)

a = A[n//2-1]
b = A[n//2]
med = (a+b)/2

for i in range(n):
    if X[i] >= med:
        print(a)
    else:
        print(b)
        

Measured memory_bytes: 26772
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N,M = inpl()
lines = defaultdict(set)
hh = [0]*N
for _ in range(M):
    x,y = inpl()
    lines[x].add(y)
    hh[y] += 1

q = queue.Queue()
for t in range(N):
    if hh[t] == 0:
        q.put(t)

topological = []
while not q.empty():
    s = q.get()
    topological.append(s)
    for t in lines[s]:
        hh[t] -= 1
        if hh[t] == 0:
            q.put(t)

for x in topological:
    print(x)



Measured memory_bytes: 14748
package main

import(
    "fmt"
    "strconv"
)



func main() {
    var s string
    fmt.Scan(&s)
    a := s[:2]
    b := s[2:]
    c, _ := strconv.Atoi(a)
    d, _ := strconv.Atoi(b)
    ans := "NA"
    switch{
        case c>=1 && c<=12 && d>=1 && d<=12:
            ans = "AMBIGUOUS"
        case (c==0 && d>12) || (c>12 && d==0) || (c==0 && d==0) || (c>12 && d>12):
            ans = "NA"
        case c>=1 && c<=12:
            ans = "MMYY"
        default:
            ans = "YYMM"
    }
    fmt.Println(ans)
}





func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}


Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <string>
//#include <cmath>
#include <vector>
// #include <algorithm>
// #include <bits/stdc++.h>
using namespace std;

int main() {
  int n=0;
  cin >> n;

  int ary[4][3][10] = {{{0}}};

  for (int i=0; i<n; i++) {
    int b,f,r,v;
    cin >> b >> f >> r >> v;
    ary[b-1][f-1][r-1] = ary[b-1][f-1][r-1] + v;
  }
  
  for (int i=0; i<4; i++) {
    for (int j=0; j<3; j++) {
      for (int k=0; k<10; k++) {
  	cout << " " << ary[i][j][k];
      }
      cout << endl;
    }
    if (i != 3) cout << "####################" << endl;
  }
  
  return 0;
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,K;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	set<int> S;
	cin>>A>>B>>K;
	for(i=A;i<A+K && i<=B;i++) S.insert(i);
	for(i=B;i>B-K && i>=A;i--) S.insert(i);
	FORR(s,S) cout<<s<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
import sys
n,m = list(map(int,input().split()))

a = [list(map(int,input().split())) for i in range(m)]

ans = '0' * n
temp = []


for i in range(m):
    if ((a[i][0] - 1) not in temp) or (str(a[i][1]) == ans[a[i][0]-1]):
        ans = ans[:a[i][0]-1] + str(a[i][1]) + ans[a[i][0]:]
        temp.append(a[i][0] - 1)
        if (a[i][0] - 1) == 0 and a[i][1] == 0 and n != 1:
            print(-1)
            sys.exit()
    else:
        print(-1)
        sys.exit()

if n == 1 and int(ans) == 0:
    print(0)
    sys.exit()

   
if ans[0] == '0':
    ans = '1' + ans[1:]
    print(ans)
else:
    print(ans)


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

int main() {
  int N,ans=0;
  cin >> N;
  vector<string>s(N);
  vector<int>t(N);
  for(int i=0; i<N; i++){
    cin >> s[i] >> t[i];
  }
  string X;
  cin >> X;
  for(int i=0; i<N; i++){
    if(s[i] == X){
      for(int j=i+1; j<N; j++){
        ans += t[j];
      }
      cout << ans << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3616
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{	
		string s = Console.ReadLine();
		int K = Int32.Parse(Console.ReadLine());

		Dictionary<string,bool> dict = 
			new Dictionary<string,bool>();
		for(int i = 1; i <= Math.Min(K,s.Length); i++)
		{
			for(int j = 0; j <= s.Length - i; j++)
			{
				string str = s.Substring(j,i);  // start:j, length:i
				if(!dict.ContainsKey(str))
					dict[str] = true;
			}
		}

		List<string> list = new List<string>();
		foreach(string key in dict.Keys)
			list.Add(key);
		list.Sort();
		Console.WriteLine(list[K-1]); 
	}	
}





Measured memory_bytes: 13408
l = input().split()
H = int(l[0])
W = int(l[1])
N = int(input())


c= [[0 for i in range(W)] for j in range(H)]
color_num = [int(i) for i in input().split()]
row = 0
column = 0

for i in range(N):
    index = color_num[i]
    for j in range(0, index):
        c[row][column] = i+1

        if W!=1:
            if column % (W-1) == 0 and column != 0:
                row += 1
                column = 0
            else:
                column += 1
        else:
            row += 1

for i in range(H):
    if i%2 == 1:
        c[i].reverse()


for i in range(0, H):
    for j in range(0, W):
        print(c[i][j], end=' ')
    print('')

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<char>> A(N, vector<char> (N));
  vector<vector<char>> B(M, vector<char> (M));
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      cin >> A.at(i).at(j);
    }
  }
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < M; j++) {
      cin >> B.at(i).at(j);
    }
  }
  bool can= true;
  bool ans = false;
  for(int i = 0; i <= N-M; i++) {
    if(ans) break;
    for(int j = 0; j <= N-M; j++) {
      if(ans) break;
      can = true;
      for(int k = 0; k < M; k++) {
        if(!can) break;
        for(int l = 0; l < M; l++) {
          if(A.at(i+k).at(j+l) != B.at(k).at(l)) {
            can = false;
            break;
          }
        }
        if(k == M-1 && can) ans = true;
      }
    }
  }
  if(ans) cout << "Yes" << endl;
  if(!ans) cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = ll(1e9 + 7);
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    
    ll b = stoll(s.substr(0,s.find('.')));
    ll c = stoll(s.substr(s.find('.')+1));
    cout << n*b + (n*c)/100 << endl;


  }
}


Measured memory_bytes: 3656
N = int(input())
W = list()

for x in range(0,N):
    w = input()
    W.append(w)

alphabet = W[0][0]
answer = True

for x in W:
    if not alphabet == x[0]:
        answer = False
        break
    if not W.count(x) == 1:
        answer = False
        break
    alphabet = x[len(x)-1]

if answer:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int l[300009], r[300009], n; string S;
 
int main() {
	cin >> n >> S;
	for (int i = 1; i <= S.size(); i++) {
		l[i] = l[i - 1];
		if (S[i - 1] == 'W') l[i] += 1;
	}
	for (int i = S.size(); i >= 1; i--) {
		r[i] = r[i + 1];
		if (S[i - 1] == 'E') r[i] += 1;
	}
	int minx = (1 << 30);
	for (int i = 1; i <= n; i++) {
		minx = min(minx, l[i - 1] + r[i + 1]);
	}
	cout << minx << endl;
	return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[2005];

int main()
{
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    REP(i, N)
    {
        cin >> A[i];
    }
    REP(i, N)
    {
        ll a = 0;
        REP(j, N)
        {
            if (A[i] > A[j])
                a++;
        }
        ll b = 0;
        FOR(j, N, i + 1)
        {
            if (A[i] > A[j])
                b++;
        }
        ans += b * K + ((K * (K - 1) / 2) % MOD) * a;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

func solve() {
	h, n := getInt(), getInt()
	type magic struct{ a, b int }
	ms := make([]magic, n)
	for i := range ms {
		ms[i].a = getInt()
		ms[i].b = getInt()
	}

	dp := make([][]int, h+1)
	for i := range dp {
		dp[i] = make([]int, n+1)
		for j := range dp[i] {
			dp[i][j] = inf
		}
	}
	dp[0][0] = 0

	for i := 0; i < n; i++ {
		for j := 0; j < h; j++ {
			dp[j][i+1] = min(dp[j][i+1], dp[j][i])
			next := min(h, j+ms[i].a)
			dp[next][i+1] = min(dp[next][i+1], dp[j][i+1]+ms[i].b)
		}
	}

	ans := inf
	for _, mp := range dp[h] {
		ans = min(ans, mp)
	}
	fmt.Fprintln(wr, ans)
}

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

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 86400
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {
	int n, k, p;
	cin >> n;
	while (n--) {
		cin >> k >> p;
		if (k <= p)
			cout << k << endl;
		else if (k % p == 0)
			cout << p << endl;
		else
			cout << k % p << endl;
	}

	return 0;
}

Measured memory_bytes: 3124
#include <iostream>

using namespace std;

int main(void) {

	string input;
	cin >> input;

	long total=0;
	for(auto c : input) {
		total += c - '0';
	}

	if(total % 9) {
        cout << "No";
    }
	else {
		cout << "Yes";
	}
		
	return 0;
}


Measured memory_bytes: 3676
#include<stdio.h>
 
int main(){
  int i,l[11],v1,v2,mi,ll[12];
  double zi,ha,haha;
  while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9],&v1,&v2) != EOF){
    mi = 0;
    ll[0] = 0;
    for(i=0;i<10;i++){
      mi += l[i];
      ll[i+1] = ll[i]+l[i]; 
    }
    zi = (double)mi/(double)(v1+v2);
    ha = zi*(double)v1;
    haha = zi*(double)v2;
  
    for(i=0;i<=9;i++){
      if(ll[i] <= ha && ha <= ll[i+1]){
    printf("%d\n",i+1);
    break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 2032
n = gets.to_i
hs = gets.chomp.split.map(&:to_i)
ans = 0

n.times do |i|
	if i == n - 1
		ans += hs[i]
		break
	end
	if hs[i] > hs[i+1]
		ans += hs[i] - hs[i+1]
	end
end

puts ans

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int M = in.nextInt();

            int[] a = new int[M];
            int[] b = new int[M];
            for (int i = 0; i < M; i++) {
                a[i] = in.nextInt() - 1;
                b[i] = in.nextInt() - 1;
            }

            int[] count = new int[N];
            for (int i = 0; i < M; i++) {
                count[a[i]]++;
                count[b[i]]++;
            }

            for (int i = 0; i < N; i++) {
                System.out.println(count[i]);
            }
        }
    }
}


Measured memory_bytes: 21716
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>

#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
typedef unsigned long long ull;
#define mp make_pair
#define pb push_back

#define debug(x) cerr << #x << " = " << x << " "

int gcd(int x, int y)
{
  return x?gcd(y, y%x):y;
}

int main()
{
  int n; scanf("%d", &n);
  vector<int> v(n);
  for (auto & e : v) scanf("%d", &e);
  int cur = 0;
  for (;; cur ^= 1)
    {
      vector<int> cnt(2, 0);
      vector<int> last(2, -1);
      for (int i = 0; i < v.size(); ++i)
	{
	  int parity = v[i]%2;
	  ++cnt[parity];
	  last[parity] = i;
	}
      if (cnt[0]%2 == 1) 
	{
	  break;
	}
      else if (cnt[1] == 1 && v[last[1]] != 1)
	{
	  --v[last[1]];
	  int g = 0;
	  for (auto e : v) g = __gcd(g, e);
	  for (auto &e : v) e /= g;
	}
      else 
	{
	  cur ^= 1;
	  break;
	}
    }
  puts(cur?"Second":"First");
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 500010;
const int maxm = 1200010;
const int inf  = 0x3f3f3f3f;

int n,m,tol,len,head[maxn]; LL val[maxn];
struct node
{
    int u,v,w;
}data[maxn>>1];
struct edge
{
    int to,cost,next;
}es[maxm];
void addedge( int u , int v , int w )
{
    es[tol].to = v;
    es[tol].cost = w;
    es[tol].next = head[u];
    head[u] = tol++;
}
int dis[maxn],vis[maxn];
struct point
{
    int pos,dis;
    friend bool operator<( const point&a , const point&b )
    {
        return a.dis>b.dis;
    }
};
void dijkstra()
{
    for ( int i=1 ; i<=n+len ; i++ )
        dis[i] = inf,vis[i] = 0;
    dis[1] = 0;
    point p;
    priority_queue<point>Q;
    p.pos = 1;
    p.dis = 0;
    Q.push(p);
    while ( !Q.empty() )
    {
        p = Q.top();
        Q.pop();
        int u = p.pos;
        for ( int i=head[u] ; i!=-1 ; i=es[i].next )
        {
            int v = es[i].to,w = es[i].cost;
            if ( dis[v]>dis[u]+w )
            {
                dis[v] = dis[u]+w;
                p.pos = v;
                p.dis = dis[v];
                Q.push(p);
            }
        }
    }
}

int main()
{
    for ( ; scanf ( "%d%d" , &n , &m )==2 ; )
    {
        tol = 0;
        len = 0;
        memset ( head , -1 , sizeof(head) );
        for ( int i=1 ; i<=m ; i++ )
        {
            scanf ( "%d%d%d" , &data[i].u , &data[i].v , &data[i].w );
            val[++len] = 1LL*1000000*data[i].u+data[i].w;
            val[++len] = 1LL*1000000*data[i].v+data[i].w;
        }
        sort ( val+1 , val+len+1 );
        len = unique( val+1 , val+len+1 )-val-1;
        for ( int i=1 ; i<=m ; i++ )
        {
            LL uw = 1LL*1000000*data[i].u+data[i].w;
            LL vw = 1LL*1000000*data[i].v+data[i].w;
            int tu = lower_bound( val+1 , val+len , uw )-val+n;
            int tv = lower_bound( val+1 , val+len , vw )-val+n;
            addedge( data[i].u , tu , 1 );
            addedge( tu , data[i].u , 1 );
            addedge( tu , tv , 0 );
            addedge( tv , tu , 0 );
            addedge( data[i].v , tv , 1 );
            addedge( tv , data[i].v , 1 );
        }
        dijkstra();
        if ( dis[n]==inf )
            dis[n] = -2;
        printf ( "%d\n" , dis[n]>>1 );
    }
    return 0;
}


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

int main() {
    string ABCD;
    cin >> ABCD;
    int A, B, C, D, temp;
    temp = stoi(ABCD);
    A = temp / 1000;
    temp -= A * 1000;
    B = temp / 100;
    temp -= B * 100;
    C = temp / 10;
    temp -= C * 10;
    D = temp;
    //cout << "A " << A << ", B " << B << ", C " << C << ", D " << D << endl;

    vector<bool> ops(4, true);
    int ops_n = 0;
    bool phase1 = true, phase2 = false;

    while (true) {
        int sum = A;
        if (ops[0]) {
            sum += B;
        } else if (!ops[0]) {
            sum -= B;
        }

        if (ops[1]) {
            sum += C;
        } else if (!ops[1]) {
            sum -= C;
        }

        if (ops[2]) {
            sum += D;
        } else if (!ops[2]) {
            sum -= D;
        }

        if (sum == 7) {
            break;
        }

        /*cout << A;
        if (ops[0]) {
            cout << '+';
        } else {
            cout << '-';
        }
        
        cout << B;
        if (ops[1]) {
            cout << '+';
        } else {
            cout << '-';
        }

        cout << C;
        if (ops[2]) {
            cout << '+';
        } else {
            cout << '-';
        }
        cout << D << endl;*/

        if (phase1) {
            //cout << "Phase1 Roop : " << ops_n << endl;
            ops[ops_n] = false;
            if (ops_n > 0) {
                ops[ops_n - 1] = true;
            }
            if (ops_n == 3) {
                phase1 = false;
                phase2 = true;
                for (int i = 0; i < 3; i++) {
                    ops[i] = false;
                }
                ops_n = -1;
                //cout << "Phase1 finished;" << endl;
            }
            ops_n++;
        } else if (phase2) {
            ops[ops_n] = true;
            if (ops_n > 0) {
                ops[ops_n - 1] = false;
            } else if (ops_n == 3) {
                phase2 = false;
            }
            ops_n++;
        } else if (!phase1 && !phase2) {
            for (int i = 0; i < 3; i++) {
                ops[i] = false;
            }
        }
    }

    cout << A;
    if (ops[0]) {
        cout << '+';
    } else {
        cout << '-';
    }
    
    cout << B;
    if (ops[1]) {
        cout << '+';
    } else {
        cout << '-';
    }

    cout << C;
    if (ops[2]) {
        cout << '+';
    } else {
        cout << '-';
    }

    cout << D << "=7" << endl;

    return 0;
}

Measured memory_bytes: 3620
n, k = map(int, input().split())
list = []
for p in range(k):
  d = int(input())
  k_list = [int(x) for x in input().split()]
  m = len(k_list)
  for q in k_list:
    if not q in list:
      list.append(q)
l = len(list)
print(n - l)

Measured memory_bytes: 9188
def solve():
    import sys
    input = sys.stdin.readline

    N, M, Q = map(int, input().split())
    Sss = [input().rstrip() for _ in range(N)]

    numVertexss = [[0]*(M+1)] + [[0] + list(map(int, Ss)) for Ss in Sss]
    numEdgeVss = [[0]*(M+1) for _ in range(N+1)]
    numEdgeHss = [[0]*(M+1) for _ in range(N+1)]
    for i in range(1, N):
        for j in range(1, M+1):
            if numVertexss[i][j] and numVertexss[i+1][j]:
                numEdgeVss[i][j] = 1
    for i in range(1, N+1):
        for j in range(1, M):
            if numVertexss[i][j] and numVertexss[i][j+1]:
                numEdgeHss[i][j] = 1

    def getAccAss(Ass):
        for x in range(1, N+1):
            for y in range(M+1):
                Ass[x][y] += Ass[x-1][y]
        for x in range(N+1):
            for y in range(1, M+1):
                Ass[x][y] += Ass[x][y-1]
    def getRangeSum2D(accAss, xFr, xTo, yFr, yTo):
        return accAss[xTo+1][yTo+1] - accAss[xTo+1][yFr] - accAss[xFr][yTo+1] + accAss[xFr][yFr]

    getAccAss(numVertexss)
    getAccAss(numEdgeVss)
    getAccAss(numEdgeHss)

    anss = []
    for _ in range(Q):
        x1, y1, x2, y2 = map(int, input().split())
        x1, y1, x2, y2 = x1-1, y1-1, x2-1, y2-1
        ans = getRangeSum2D(numVertexss, x1, x2, y1, y2)
        ans -= getRangeSum2D(numEdgeVss, x1, x2-1, y1, y2)
        ans -= getRangeSum2D(numEdgeHss, x1, x2, y1, y2-1)
        anss.append(ans)

    print('\n'.join(map(str, anss)))


solve()


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

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

	if ( N > M ) {
		swap(N, M);
	}
	if ( N == 1 ) {
		if ( M == 1 ) {
			cout << 1 << endl;
		} else {
			cout << M - 2 << endl;
		}
	} else {
		cout << (int64_t)(N - 2) * (M - 2) << endl;
	}
	return ( 0 );
}


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

int main(void){
    string s;
    cin >> s;
    
    int ans = 0;
    char c = s[0];
    int i;
    for(i = 1; i < s.length(); i++){
        if(s[i] != c){
            ans++;
        }
        c = s[i];
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String num = sc.nextLine();
        int sum=0;
        for(int i=0;i<num.length();i++){
            int x =Character.getNumericValue(num.charAt(i));
            sum+=x;
        }
        if(sum%9==0)
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Measured memory_bytes: 41048
#include <cstdio>
const int MAXN = 20;
char S[MAXN];
int K, N;

int main() {
  scanf(" %d%s%d", &N, S+1, &K);
  for (int i = 1; i <= N; ++i) {
    putchar((S[i] == S[K]) ? S[K] : '*');
  }
  putchar('\n');
  return 0;
}

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

namespace contest8
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                //文字列読み込み
                var line_origin = Console.ReadLine();

                //空なら終わり
                if (string.IsNullOrEmpty(line_origin))
                {
                    break;
                }
                int ans = int.Parse(line_origin);

                int count = 0;

               var choice = from a in Enumerable.Range(0, 10)
                             from b in Enumerable.Range(0, 10)
                             from c in Enumerable.Range(0, 10)
                             from d in Enumerable.Range(0, 10)
                             where a + b + c + d == ans
                             select 0;

                foreach (int i in choice)
                {
                    count++;
                }

/*
                for (int a = 0; a < 10; a++)
                {
                    for (int b = 0; b < 10; b++)
                    {
                        for (int c = 0; c < 10; c++)
                        {
                            for (int d = 0; d < 10; d++)
                            {
                                if (a + b + c + d == ans)
                                {
                                    count++;
                                }
                            }
                        }
                    }
                }
*/
                Console.WriteLine(count.ToString());
            }
        }
    }
}

Measured memory_bytes: 6148
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  string s, t;
  cin >> s >> t;
  vector<vector<int>> ch(26);
  int n = s.size(), m = t.size();
  rep(i, n) ch[s[i]-'a'].push_back(i);
  rep(i, n) ch[s[i]-'a'].push_back(i + n);

  ll ans = 0;
  int it = 0;
  rep(i, m) {
    int c = t[i] - 'a';
    if(ch[c].size() == 0) {
      puts("-1");
      return 0;
    }
    it = *lower_bound(ch[c].begin(), ch[c].end(), it) + 1;
    if(it >= n) {
      ans += n;
      it -= n;
    }
    
  }
  ans += it;
  cout << ans << endl;
}

Measured memory_bytes: 1724
#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
//#include <intrin.h>  //AtCoder (gcc) 上ではこれがあると動かない。__popcnt用のincludeファイル。
using namespace std;
using Graph = vector<vector<int>>;

typedef long long ll;
typedef long double ld;


#define int long long
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((long double) (d), 0.50)

const ll INF = 2e9;
const ll large_P = 1e9 + 7;



//繰り返し2乗法
//N^aの、Mで割った余りを求める。
ll my_pow(ll N, ll a, ll M) {
	ll tempo;
	if (a == 0) {
		return 1;
	}
	else {
		if (a % 2 == 0) {
			tempo = my_pow(N, a / 2, M);
			return (tempo * tempo) % M;
		}
		else {
			tempo = my_pow(N, a - 1, M);
			return (tempo * N) % M;
		}
	}
}



//N_C_a を M で割った余り
ll my_combination(ll N, ll a, ll M) {
	ll answer = 1;

	rep(i, a) {
		answer *= (N - i);
		answer %= M;
	}

	rep(i, a) {
		answer *= my_pow(i + 1, M - 2, M);
		answer %= M;
	}

	return answer;
}



ll my_gcd(ll& a, ll& b) {
	if (b == 0) return a;
	ll temp = a % b;
	return my_gcd(b, temp);
}



// long long型 n を、base 進法での、i 桁目の数が入った vector にする。
void ll_to_vector(ll base, ll n, vector<ll>& v) {
	ll tempo = n;

	ll n_digit = floor(log10(n) / log10(base)) + 1;
	v.assign(n_digit, 0);

	//ll n_digit = v.size();

	for (ll i = 0; i < n_digit; i++) {
		v.at(i) = tempo / pow(base, n_digit - 1 - i);
		tempo -= v.at(i) * pow(base, n_digit - 1 - i);
	}
}







signed main() {
	int N; cin >> N;
	map<string, int> memo;
	string temp;

	rep(i, N) {
		cin >> temp;
		memo[temp]++;
	}

	cout << memo.size() << endl;
}

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

#define lli long long int

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

    float ans = 0.0;
    if(n == 2)
    {
        ans = (float)(a[0] + a[1])/2;
        cout << ans;
    }
    else
    {

        sort(a, a + n);
        float temp = a[0];
        for(int i = 1; i < n; i++)
        {
            temp = (float)((temp + a[i])/2);
        }
        cout << temp;
    }



    return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "2 3 3" ].parse.expand.solve == "0 2" );
	assert( [ "500000000000 500000000000 1000000000000" ].parse.expand.solve == "0 0" );
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abk = input.front.split.to!( long[] );
	return tuple( abk[ 0 ], abk[ 1 ], abk[ 2 ] );
}

auto solve( long a, long b, long k )
{
	return format( "%s %s", max( 0, a - k ), max( 0, b - max( 0, k - a ) ) );
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int A,B;
    cin>>A>>B;
    if(A+B>=10)cout<<"error"<<endl;
    else cout<<A+B<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] n = line.split(" ");
		int a = Integer.parseInt(n[0]);
		int b = Integer.parseInt(n[1]);
		int c = Integer.parseInt(n[2]);

		if (a < b && b < c) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}



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

int main(){
    int n;
    cin >> n;
    map<int,int> date;
    for(int i=0;i<n;i++){
        int num;
        cin >> num;
        date[num]++;
        if(date[num]==2){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 12928
fn main() {
    proconio::input! {
        h: usize,
        w: usize,
        ss: [proconio::marker::Chars; h],
    }
    let v = ss
        .iter()
        .map(|s| {
            s.iter()
                .map(|c| {
                    if *c == '#' {
                        None
                    } else {
                        Some(std::usize::MAX)
                    }
                })
                .collect::<Vec<_>>()
        })
        .collect::<Vec<_>>();
    let mut max = 0;
    for i in 0..h {
        for j in 0..w {
            if v[i][j] == None {
                continue;
            }
            let mut v = v.clone();
            let mut deque = std::collections::VecDeque::new();
            deque.push_back((i, j, 0));
            while let Some((x, y, dist)) = deque.pop_front() {
                if v[x][y].is_some() && v[x][y].unwrap() > dist {
                    v[x][y] = Some(dist);
                    let (new_x, new_y) = (x.wrapping_sub(1), y);
                    if new_x < h && new_y < w && v[new_x][new_y].is_some() {
                        deque.push_back((new_x, new_y, dist + 1));
                    }
                    let (new_x, new_y) = (x, y.wrapping_sub(1));
                    if new_x < h && new_y < w && v[new_x][new_y].is_some() {
                        deque.push_back((new_x, new_y, dist + 1));
                    }
                    let (new_x, new_y) = (x + 1, y);
                    if new_x < h && new_y < w && v[new_x][new_y].is_some() {
                        deque.push_back((new_x, new_y, dist + 1));
                    }
                    let (new_x, new_y) = (x, y + 1);
                    if new_x < h && new_y < w && v[new_x][new_y].is_some() {
                        deque.push_back((new_x, new_y, dist + 1));
                    }
                }
            }
            max = std::cmp::max(
                max,
                v.iter()
                    .map(|item| {
                        item.iter()
                            .filter(|x| x.is_some() && x.unwrap() != std::usize::MAX)
                            .map(|x| x.unwrap())
                            .max()
                            .or(Some(0))
                            .unwrap()
                    })
                    .max()
                    .unwrap(),
            );
        }
    }
    println!("{}", max);
}


Measured memory_bytes: 2208
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)
using namespace std;
using Weight = int;
using Array = vector<int>;
using Matrix = vector<Array>;
constexpr int INF = 1000000000;


pair<Weight, Array> hungarian(const Matrix &m) {
  int n = m.size();
  int p, q;
  Array fx(n, INF), fy(n, 0);
  vector<int> x(n, -1), y(n, -1);
  for (int i = 0; i < n; ) {
    vector<int> t(n, -1), s(n+1, i);
    for (p = q = 0; p <= q && x[i] < 0; ++p)
      for (int k = s[p], j = 0; j < n && x[i] < 0; ++j)
        if (fx[k] + fy[j] == m[k][j] && t[j] < 0) {
          s[++q] = y[j], t[j] = k;
          if (s[q] < 0)
            for (p = j; p >= 0; j = p)
              y[j] = k = t[j], p = x[k], x[k] = j;
        }
    if (x[i] < 0) {
      Weight d = INF;
      for (int k = 0; k <= q; ++k)
        REP(j,n)
          if (t[j] < 0) d = min(d, fx[s[k]] + fy[j] - m[s[k]][j]);
      REP(j,n) fy[j] += (t[j] < 0 ? 0 : d);
      for (int k = 0; k <= q; ++k) fx[s[k]] -= d;
    } else ++i;
  }
  Weight ret = 0;
  REP(i,n) ret += m[i][x[i]];
  return make_pair(ret, x);
}

int main() {
  int n;
  cin>>n;
  Matrix w(n, Array(n));
  REP(i,n)REP(j,n) cin >> w[i][j];
  Matrix e(n, Array(n));
  REP(i,n)REP(j,n) cin >> e[i][j];
  vector<string> m(n);
  Matrix mat(n, Array(n));
  int cost = 0;
  REP(i,n) {
    cin>>m[i];
    REP(j,n) {
      if (m[i][j] == 'o') {
        mat[i][j] = 1000 + e[i][j];
        cost += e[i][j];
      } else {
        mat[i][j] = 1000 - w[i][j];
      }
    }
  }
  auto res = hungarian(mat);
  cout << (n*1000 - res.first + cost) << endl;
  int cnt = 0;
  stringstream ss;
  REP(i,n)REP(j,n) {
    if (m[i][j] == 'o') {
      if (res.second[i] != j) {
        ss << (i+1) << ' ' << (j+1) << " erase" << endl;
        ++cnt;
      }
    } else {
      if (res.second[i] == j) {
        ss << (i+1) << ' ' << (j+1) << " write" << endl;
        ++cnt;
      }
    }
  }
  cout << cnt << endl;
  cout << ss.str() << flush;
  return 0;
}

Measured memory_bytes: 3292
#include<bits/stdc++.h>
#define rep(i,n,k) for(long long int i=k; i<n; ++i)
#define drep(i,n,k) for(long long int i=n-1; i>=k; --i)
using namespace std;

int main(){
  string s;
  cin >> s;
  vector<char> ans;
  rep(i,s.size(),0){
    if(s[i] == 'B'){
      if(ans.size() != 0) ans.pop_back();
    }
    else{
      ans.push_back(s[i]);
    }
  }
  rep(i,ans.size(),0) cout << ans[i];
  cout << endl;
}

Measured memory_bytes: 256
S = input()

acgt = {'A', 'C', 'G', 'T'}

for i in range(len(S)):
    window = len(S) - i
    for j in range(len(S) - window + 1):
        if set(S[j:j + window]).issubset(acgt):
            print(len(S[j:j + window]))
            break
    else:
        continue
    break
else:
    print(0)


Measured memory_bytes: 3060
#include<stdio.h>

long long  num[10000];

int main(void){
    int i;
    long long n,sum,max,min;

    scanf("%lld",&n);
    for(i = 0;i < n;i++)
        scanf("%lld",&num[i]);

    max = -1000001;min = 1000001;
    for(i = 0;i < n;i++){
        if(max < num[i])
            max = num[i];
        if(min > num[i])
            min = num[i];
    }

    sum = 0;
    for(i = 0;i < n;i++)
        sum += num[i];

    printf("%lld %lld %lld\n",min,max,sum);
    return 0;
}

Measured memory_bytes: 2736
import sys
inf = float('inf')
n, ma, mb = map(int, input().split())
t = [[inf] * 401 for _ in range(401)]
t[0][0] = 0
for _ in range(n):
  a, b, c = map(int, input().split())
  for aa in range(400, -1, -1):
    for bb in range(400, -1, -1):
      if t[aa][bb] == inf:
        continue
      if t[a + aa][b + bb] > c + t[aa][bb]:
        t[a + aa][b + bb] = c + t[aa][bb]
result = inf
for a in range(400, 0, -1):
  for b in range(400, 0, -1):
    if a * mb == b * ma and t[a][b] < result:
      result = t[a][b]
if result == inf:
  print(-1)
else:
  print(result)


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //10^19 < 9223372036854775807
typedef unsigned long long ull; //10^20 < 18446744073709551615

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size()) 

#define MOD 1000000007

int main(void)
{
    string S;
    cin >> S;

    ll sum = 0;
    for (ll i = 0; i < S.length(); i++) {
        sum += S[i] - '0';
    }

    string ans = "No";
    if (sum % 9 == 0)
        ans = "Yes";

    cout << ans << endl;

    return 0;
}


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

int main(){

    ll n,m;

    cin >> n >> m;

    ll t=n-m;

    ll u=pow(2,m);

    ll ans=u*(1900*m+100*t);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384