akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
typedef long long ll;
const int MAXN = 52, MAXC = 5002;
struct road{
	ll t;
	int v, c;
	friend bool operator<(const road &a, const road &b){
		return a.t>b.t;
	}
};
int N, M, S, sum;
ll dis[MAXN][MAXC];
vector<road>adj[MAXN];
pair<int, ll>trade[MAXN];
priority_queue<road>pq;
int mc(int coins){
	return min(coins, sum);
}
void ist(int curV, int v, int curC, int c, ll curT, ll t){
	if(dis[v][c]>dis[curV][curC]+curT+t){
		dis[v][c] = dis[curV][curC]+curT+t;
		pq.push({dis[v][c], v, c});
	}
}
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> N >> M >> S;
	for(int i = 1, u, v, a, b;i<=M;i++){
		cin >> u >> v >> a >> b;
		adj[u].push_back({b, v, a});
		adj[v].push_back({b, u, a});
		sum+=a;
	}
	S = mc(S);
	for(int i = 1, c, d;i<=N;i++){
		cin >> c >> d; c = mc(c);
		trade[i] = {c, d};
	}
	memset(dis, 0x3f3f, sizeof(dis));
	dis[1][S] = 0;
	pq.push({0, 1, S});
	while(!pq.empty()){
		road cur = pq.top(); pq.pop();
		int v = cur.v, c = cur.c, cleft = 0;
		for(road i:adj[v]){
			for(int j = 0;j<MAXC;j++){
				cleft = c+(trade[v].first*j)-i.c;
				if(cleft>=sum)break;
				cleft = mc(cleft);
				if(cleft>=0){
					ist(v, i.v, c, cleft, (1LL)*j*trade[v].second, i.t);
				}
			}
		}
	}
	for(int i = 2;i<=N;i++){
		ll qry = 1e18;
		for(int j = 0;j<MAXC;j++){
			qry = min(qry, dis[i][j]);
		}
		cout << qry << nl;
	}
	return 0;
}


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

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    ll last_gain = -1;
    ll first_bottom = -1;
    rep(i, n){
        cin >> a[i];
        if(i>0 && a[i] > a[i-1]) last_gain = i;
        if(first_bottom==-1 && i>0 && a[i] > a[i-1]) first_bottom = i-1;
    }
    if(first_bottom == -1){
        cout << 1000 << endl;
        return 0;
    }

    ll prev;
    if(first_bottom == 0) prev = a[0];
    else prev = a[first_bottom];

    ll money = 1000;
    ll stock = 0;
    for(ll i = first_bottom; i < n; ++i){
        if(prev < a[i]){
            ll gain = money / prev;
            stock += gain;
            money -= gain * prev;
        }

        if(prev > a[i]){
            money += prev * stock;
            stock = 0;
        }

        if(i == last_gain){
            money += stock*a[i];
            break;
        }
        prev = a[i];
    }

    cout << money << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
typedef pair<int,int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define REPR(i,n) for (int i = n-1; i >= 0; --i)
#define PB push_back
#define MP make_pair

const int MAX = 2e5+10;

int H, W, N;
int sr, sc;
string S, T;

bool check(char l, char r, int start, int width) {
    int left = 1, right = width;
    REPR (i, N) {
        if (T[i] == l) right = min(width, right+1);
        else if (T[i] == r) left = max(1, left-1);

        if (S[i] == l) left += 1;
        else if (S[i] == r) right -= 1;
        if (left > right) return false;
    }
    return left <= start && start <= right;
}

int main() {
    cin >> H >> W >> N >> sr >> sc >> S >> T;

    bool ans = true;
    ans &= check('L', 'R', sc, W);
    ans &= check('U', 'D', sr, H);

    if (ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 776
package main

import "fmt"

func main(){
	var N int
	fmt.Scan(&N);
	S := make([]string, N);

	for i:= 0 ; i < N ; i++{
		fmt.Scan(&S[i]);
	}
	m := make(map[string]int);

	for i := 0 ; i < N ; i++{
		m[S[i]] = 1;
	}
	fmt.Println(len(m));
}

Measured memory_bytes: 27224
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		String[] param = null;
		String str = null;

		if (line.indexOf(" ") != -1) {
			param = line.split(" ");
		} else {
			str = line;
		}

		String mozi = "#"; //並べる文字

		int str1 = Integer.parseInt(param[0]); // 縦軸
		int str2 = Integer.parseInt(param[1]); // 横軸

		String[] yoko = new String[str2 + 2];
		for (int i = 0; i < yoko.length; i++) {
			System.out.print(mozi);
		}
		System.out.println();

		for (int j = 0; j < str1; j++) {
			System.out.print(mozi);
			System.out.print(br.readLine());
			System.out.print(mozi);
			System.out.println();
		}

		for (int i = 0; i < yoko.length; i++) {
			System.out.print(mozi);
		}
	}
}

Measured memory_bytes: 23120
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll n,k;
	cin >> n >> k;
	vector<ll> x(n);
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}

	// vector<ll> d(n+1);
	// d[0] = 0;
	// for(int i = 0; i < n; i++){
	// 	d[i] = x[i] - x[0];
	// 	//cout << d[i] << endl;
	// }

	// ll ans = INF;
	// for(int i = 0; i < n; i++){

	// 	if(i+k-1<n){
	// 		ll res = d[i+k-1] - d[i];
	// 		if(x[i] < 0) res += -x[i];
	// 		else res += x[i];
	// 		ans = min(res,ans);
	// 	}
	// 	// ll res = d[i+k-1] - d[i];
	// 	// if(x[i-1] < 0) res += -x[i];
	// 	// ans = min(res,ans);
	// }
	ll ans = INF;
	for(int i = 0; i < n; i++){
		if(i+k-1 < n){
			ll res = x[i+k-1] - x[i];
			if(x[i+k-1]*x[i] < 0){
				res += min(-x[i],x[i+k-1]);
			}else if(x[i] > 0) res += x[i];
			else res -= x[i+k-1];
			ans = min(res,ans);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int n;
int a[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	for(int i = 1; i <= n; i++){
		if(a[i-1] > a[i]){
			cout << "No" << endl;
			return 0;
		}
		if(a[i-1] < a[i]) a[i]--;
	}
	cout << "Yes" << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
using namespace std;
using ll = long long;
int main(){
  int n,m;
  cin >> n >> m;

  priority_queue<ll,vector<ll>,greater<ll>> q;
  for(int i=0;i<n;i++){
    ll a;
    cin >> a;
    q.push(a);
  }

  vector<pair<ll,int>> cb(m);
  for(int i=0;i<m;i++) cin >> cb[i].second >> cb[i].first;

  sort(cb.begin(),cb.end());

  for(int i=m-1;i>=0;i--){
    for(int j=0;j<cb[i].second;j++){
      ll v = q.top();
      if(v < cb[i].first){
        q.pop();
        q.push(cb[i].first);
      }else{
        break;
      }
    }
  }

  ll sum = 0;
  while(!q.empty()){
    ll v = q.top();
    q.pop();
    sum += v;
  }

  cout << sum << "\n";
}


Measured memory_bytes: 2676
#include <iostream>

using namespace std;

int main() {
    int i,a,b;
    cin>>a>>b;
    for(i=0;(a!=0 || b!=0);i++)
    {
        if (a >=b)
        {
            a=a+b;
            b=a-b;
            a=a-b;
        }
        cout<<a<<" "<<b<<endl;
        cin>>a>>b;
    }
}


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

using namespace std;

int main(){

	int a, b, flag;
	char tmp;
	vector< vector<int> > board;

	cin>> a >> b;
	board.resize(a);
	for(int i=0;i<a;i++) board[i].resize(b);

	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			cin>> tmp;
			if(tmp=='#') board[i][j]=1;
			else board[i][j]=0;
		}
	}

	for(int i=0;i<b;i++){
		flag=1;
		for(int j=0;j<a;j++){
			if(board[j][i]==1) flag=0;
		}
		if(flag){
			for(int j=0;j<a;j++) board[j].erase(board[j].begin() + i);
			i--;
			b--;
		}
	}

	for(int i=0;i<a;i++){
		flag=1;
		for(int j=0;j<b;j++){
			if(board[i][j]==1) flag=0;
		}
		if(flag){
			board.erase(board.begin() + i);
			i--;
			a--;
		}
	}

	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(board[i][j]==1) cout<< '#';
			else cout<< '.';
		}
		cout<< endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main(){
	int n,k,sum=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)scanf("%d",a+i);
	sort(a,a+n);
	for(int i=0;i<k;i++)sum+=a[i];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3744
package main

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

func solve() {
	n := getInt()
	as := getIntSlice(n)

	m := make(map[int]bool)
	ans := "YES"
	for _, a := range as {
		if _, exist := m[a]; exist {
			ans = "NO"
			break
		}
		m[a] = true
	}

	fmt.Fprintln(wr, ans)
}

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

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: 11136
def main():
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    T = [int(input()) for i in range(D)]
    contest_last_opened = [0]*26  # コンテストiを前回開催した日
    score = 0
    for d, t in enumerate(T, start=1):
        get_score = S[d-1][t-1]
        score += get_score
        contest_last_opened[t-1] = d
        loss_score = 0
        for i in range(26):
            ld = contest_last_opened[i]
            loss_score += C[i]*(d-ld)
        score -= loss_score
        print(score)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68484
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;

void solve() {
	cin >> N >> M;
	cout << ((N - M) * 100 + 1900 * M) * (1 << M) << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
template <class T> bool chmax(T& a, const T& b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template <class T> bool chmin(T& a, const T& b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}
#define INF 1e9
using ll = int64_t;
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
	// a >= b && b != 0
	std::int64_t c;
	do {
		c = a % b;
		a = b;
		b = c;
	} while (c);

	return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
	std::int64_t a = max(aa, bb);
	std::int64_t b = min(aa, bb);
	std::int64_t c;
	if (b == 0) {
		return -1;
	}
	do {
		c = a % b;
		a = b;
		b = c;
	} while (c);

	return a;
}
void rle(std::vector<std::pair<char, std::int64_t>>& data, std::string str) {
	char now = str[0];
	std::int64_t count = 0;
	for (std::int64_t i = 0; i < str.size() + 1; i++) {
		if (i == str.size()) {
			data.push_back(make_pair(str[i - 1], count));
			break;
		}
		else if (now != str[i]) {
			data.push_back(make_pair(now, count));
			now = str[i];
			count = 0;
		}
		count++;
	}

	return;
}

void Main() {
	//自動整形防止用コメント
	int m, d;
	std::cin >> m >> d;

	int counter = 0;
	repf(month, 4, m + 1) {
		repf(day, 22, d + 1) {
			string tmp = to_string(day);
			int tmp2 = tmp[1] - '0';
			int tmp1 = tmp[0] - '0';
			if (month == tmp1 * tmp2 && tmp2 > 1 && tmp1 > 1) {
				counter++;
			}
		}
	}

	std::cout << counter << '\n';
	return;
}

int main() {
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll Maxn=1e5+10;
map <ll,ll> cnt;
ll a[Maxn];
int main() {
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1;i<=n;i++)    cin>>a[i],cnt[a[i]]++,sum+=a[i];
    ll q;
    cin>>q;
    for(ll i=1;i<=q;i++){
        ll b,c;
        cin>>b>>c;
        ll now=cnt[b];
        cnt[c]+=cnt[b];
        cnt[b]=0;
        sum+=(c-b)*now;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 10200
/* ABC131-B
   Yuta Takayanagi  */

#include<stdio.h>
#include<math.h>
int main(void){
    int number, l, taste, pie, i;

    i = 0;
    pie = 0;

    scanf( "%d %d" , &number, &l);

    taste = l + i;

    for(i=1; i < number; i++){

        if(fabs(taste) > fabs(l+i)){

            pie += taste;
            taste = l + i;

        }else{

            pie += l + i;
            
        }

    }

    printf( "%d" , pie);

}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	cout << (n == m ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
s = list(input())
n = len(s)
s1 = s[0:(n-1)//2]
s2 = s[(n+1)//2:n]

if s == s[::-1] and s1 == s1[::-1] and s2 == s2[::-1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  vvi a(3, vi(3));
  vvi check(3, vi(3, 0));
  rep(y, 3){
    rep(x, 3){
      cin >> a[y][x];
    }
  }
  int n;
  cin >> n;
  rep(i, n){
    int b;
    cin >> b;
    rep(y, 3){
      rep(x, 3){
        if(a[y][x] == b) check[y][x] = 1;
      }
    }
  }
  rep(y, 3){
    bool all = true;
    rep(x, 3){
      if(!check[y][x]) all = false;
    }
    if(all){
      cout << "Yes" << endl;
      return 0;
    }
  }
  rep(x, 3){
    bool all = true;
    rep(y, 3){
      if(!check[y][x]) all = false;
    }
    if(all){
      cout << "Yes" << endl;
      return 0;
    }
  }
  bool all = true, all2 = true;
  rep(i, 3){
    if(!check[i][i]) all = false;
    if(!check[i][2 - i]) all2 = false;
  }
  if(all || all2){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

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

	A, B := getString(), getString()

	a := len(A)
	b := len(B)

	ans := "EQUAL"
	if a > b {
		ans = "GREATER"
	} else if a < b {
		ans = "LESS"
	} else {
		for i := 0; i < a; i++ {
			if A[i] > B[i] {
				ans = "GREATER"
				break
			} else if A[i] < B[i] {
				ans = "LESS"
				break
			}
		}
	}

	out(ans)
}


Measured memory_bytes: 640
// 2014/07/24 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		for(int i=0; i<n; i++){
			int x1, y1, z1, w1, x2, y2, z2, w2;
			cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;

			int x3 = x1*x2-y1*y2-z1*z2-w1*w2;
			int y3 = x1*y2+y1*x2+z1*w2-w1*z2;
			int z3 = x1*z2-y1*w2+z1*x2+w1*y2;
			int w3 = x1*w2+y1*z2-z1*y2+w1*x2;

			cout << x3 << ' ' << y3 << ' ' << z3 << ' ' << w3 << endl;
		}
	}

	return 0;
}

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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(false);cin.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define error_old(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {it++;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); }

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

void solve(){
    int n, W;
    cin >> n >> W;

    vi w(n), v(n);
    rep(i, n){
        cin >> w[i] >> v[i];
    }

    vector<vi> dp(n, vi(W + 1, 0));

    repA(wi, 1, W){
        if(wi >= w[0])
            dp[0][wi] = v[0];
    }

    repA(i, 1, n - 1){
        repA(wi, 1, W){
            dp[i][wi] = dp[i - 1][wi];
            if(wi - w[i] >= 0){
                dp[i][wi] = max(dp[i][wi], dp[i - 1][wi - w[i]] + v[i]);
            }
        }
    }
    cout << dp[n - 1][W] << endl;
}

signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    solve();

    return 0;
}


Measured memory_bytes: 79488
import           Control.Exception (assert)

main :: IO ()
main = do
  n <- readLn
  as <- map read . words <$> getLine
  bs <- map read . words <$> getLine
  assert (length as == n + 1 && length bs == n) $
    print $ solve as bs

type Monster = Int
type Brave = Int
type Kill = Int
type Rest = Int

solve :: [Int] -> [Int] -> Int
solve monsters braves =
  let
    f (rest, total) (monster, brave) =
      let
        (monster', kill) = extraAttack monster rest
        (kill', rest') = attack monster' brave
      in
        (rest', total + kill + kill')
  in
    (\(rest, total) -> total + min (last monsters) rest) $ foldl f (0, 0) $ zip monsters braves

extraAttack :: Monster -> Rest -> (Monster, Kill)
extraAttack monster rest =
  let
    kill = min monster rest
  in
    (monster - kill, kill)

attack :: Monster -> Brave -> (Kill, Rest)
attack monster brave =
  let
    kill = min monster brave
  in
    (kill, brave - kill)


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

int main(){
    string S;
    int N, K;
    
    cin >> N >> K >> S;
    if(S.at(K-1) == 'A'){
        S.at(K-1) = 'a';
    }else if(S.at(K-1) == 'B'){
        S.at(K-1) = 'b';
    }else{
        S.at(K-1) = 'c';
    }
    cout << S << endl;
    
    return 0;
}

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

int main()
{
    int m,f,r;
    while(1)
    {
        scanf("%d %d %d",&m,&f,&r);
        if(m == -1&&f==-1&&r==-1) break;
        if(m == -1 || f == -1 || m+f < 30){
            printf("F\n");
        }else if(m+f >= 80){
            printf("A\n");
        }else if(m+f >= 65){
            printf("B\n");
        }else if(m+f >=50 || m+f >=30&&r>=50){
            printf("C\n");
        }else if(m+f >= 30){
            printf("D\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}
#define ntuples(type1,type2,type3,v,n) vector<tuple<type1,type2,type3>> v(n);for(size_t i=0;i<(n);i++){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  long long n;
  cin>>n;
  if(n%2==1){
     cout<<0;
     return 0;
  }
  long long k=0;
  n/=2;
  for (int i = 1; i < 30; i++) {
    n/=5;
    k+=n;
    if(n==0) break;
  }
  cout<<k;
}

Measured memory_bytes: 256
$\=$/;$L=0,$|=$R=10,$_.=${print($q="? ",($_.($%=$L+$R>>1))*1e9),<>=~Y?$R:$L=$%while$R-$L>1;L}while$i++<9;print$q,++$_+s/0*$//;print$q,($_.=0)+1while<>=~(/^9*$/?Y:N);print"! ",$_

Measured memory_bytes: 972
package main

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

// Queue is for bfs
type Queue struct {
	data []interface{}
}

// Push adds a value to queue
func (q *Queue) Push(v interface{}) {
	q.data = append(q.data, v)
}

// Pop removes the last element and return it
func (q *Queue) Pop() (interface{}, error) {
	if q.Empty() {
		return nil, fmt.Errorf("queue is empty")
	}
	v := q.data[0]
	q.data = q.data[1:]
	return v, nil
}

// Empty returns true if queue is empty
func (q *Queue) Empty() bool {
	return len(q.data) == 0
}

// NewQueue generates a new queue
func NewQueue() *Queue {
	return &Queue{make([]interface{}, 0)}
}

// Graph is a set of nodes
type Graph struct {
	Nodes []*Node
}

// Node has its value and neighbors
type Node struct {
	Val    interface{}
	Neighs []*Node
}

// Show shows a graph
func (g *Graph) Show() {
	nodes := g.Nodes
	for _, node := range nodes {
		fmt.Printf("%v: ", node.Val.(int)+1)
		for _, neigh := range node.Neighs {
			fmt.Printf("%v ", neigh.Val.(int)+1)
		}
		fmt.Println()
	}
}

func dfs(g *Graph, node *Node, groups map[*Node]*Node) map[*Node]bool {
	set := make(map[*Node]bool)
	q := NewQueue()
	q.Push(node)
	set[node] = true
	for !q.Empty() {
		src, _ := q.Pop()
		if v, ok := src.(*Node); ok {
			for _, neigh := range v.Neighs {
				if !set[neigh] {
					q.Push(neigh)
					set[neigh] = true
					groups[neigh] = node
				}
			}
		}
	}
	return set
}

func findSets(g *Graph) map[*Node]map[*Node]bool {
	sets := make(map[*Node]map[*Node]bool)
	groups := make(map[*Node]*Node)
	nodes := g.Nodes
	for _, node := range nodes {
		if leader, ok := groups[node]; ok {
			sets[node] = sets[leader]
			continue
		}

		sets[node] = dfs(g, node, groups)
	}
	return sets
}

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)
	n, m, k := nextInt(), nextInt(), nextInt()
	people := make([]*Node, n)
	for i := 0; i < n; i++ {
		people[i] = &Node{i, make([]*Node, 0)}
	}

	for i := 0; i < m; i++ {
		a, b := nextInt(), nextInt()

		people[a-1].Neighs = append(people[a-1].Neighs, people[b-1])
		people[b-1].Neighs = append(people[b-1].Neighs, people[a-1])
	}

	g := &Graph{people}

	sets := findSets(g)

	blocked := make(map[*Node]int)
	for i := 0; i < k; i++ {
		c, d := nextInt(), nextInt()

		setc := sets[people[c-1]]
		if setc[people[d-1]] {
			blocked[people[c-1]]++
		}

		setd := sets[people[d-1]]
		if setd[people[c-1]] {
			blocked[people[d-1]]++
		}
	}

	for i := 0; i < n; i++ {
		pi := people[i]
		set := sets[pi]
		fmt.Printf("%v ", len(set)-len(pi.Neighs)-blocked[pi]-1)
	}
	fmt.Println()
}


Measured memory_bytes: 32000
from sys import stdin
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

n = I()
t = [0]
x = [0]
y = [0]
for _ in range(n):
    tmp = LI()
    t.append(tmp.pop(0))
    x.append(tmp.pop(0))
    y.append(tmp.pop(0))

for i in range(1,n+1):
    dx = abs(x[i]-x[i-1])
    dy = abs(y[i]-y[i-1])
    dt = abs(t[i]-t[i-1])
    if dt<dx+dy:
        print('No')
        exit()
    else:
        tmp = dt-dx-dy
        if tmp%2:
            print('No')
            exit()

print('Yes')

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

using namespace std;

int main(){
  int n;
  std::cin >> n;

  string p = "";
  string q = "";
  vector<int> permutation(n);
  for(int i=0; i<n; i++){
    string temp;
    std::cin >> temp;
    p += temp;
  }
  for(int i=0; i<n; i++){
    string temp;
    std::cin >> temp;
    q += temp;
  }
  for(int i=0; i<n; i++) permutation[i] = i+1;
  int a = 1;
  int b = 1;
  int count = 1;
  do{
    string temp = "";
    for(int i=0; i<permutation.size(); i++){
      temp += to_string( permutation[i] );
    }
    if( temp == p ) a = count;
    if( temp == q ) b = count;
    count += 1;
  }while( next_permutation( permutation.begin(), permutation.end() ) );
  std::cout << std::abs(a - b) << '\n';
  return 0;
}


Measured memory_bytes: 256
/* fucklove - when you give everything to someone and it's stil not enough */
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

 
using namespace std;
 
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
 
const ll N=1e3 + 5 ,  INF = 1e6 + 10 , md=1e9+7;
 
int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b);} 
int takemod(int a, int mod ){a%=mod;if(a<0)a+=mod;return a;}
int fast_exp(int base, int expo, int mod ) {
	int res=1;
	while(expo>0) {
		if(expo&1) res=(res*base)%mod;
		base=(base*base)%mod;
		expo>>=1;}
	return res;}
int modinv(int a, int mod ){return takemod(fast_exp(takemod(a,mod), mod-2, mod), mod);}


int main()
{
	fast_cin();
	int t=1;
//	cin >> t;
	while(t--){
		string s,r; cin>>s>>r;
		int a,b; cin >>a>>b;
		string u; cin>>u;
		if(s==u) a--;
		else if(r==u)b--;

		cout <<a<<" "<<b<<endl;

	
	}
	return 0;
}
 

Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> load(N);
  int a,b;
  for(int i=0;i<M;++i){
    cin >> a >> b;
    --a; --b;
    load.at(a)++;
    load.at(b)++;
  }

  for(int i=0;i<N;++i) cout << load.at(i) << endl;

  return 0;
}


Measured memory_bytes: 3616
from collections import deque
Q=deque()
a=input()
Q.append(a)
q=int(input())
reverse=False
for i in range(q):
    d=input()
    if d[0]=="1": reverse= not reverse
    elif d[0]=="2":
        _, f, c=d.split()
        if f == "1":
            if reverse:
                Q.append(c)
            else:
                Q.appendleft(c)
        elif f =="2":
            if reverse:
                Q.appendleft(c)
            else:
                Q.append(c)
ans="".join(Q)
if reverse:
    ans=ans[::-1]
print(ans)


Measured memory_bytes: 6900
#include <stdint.h>
#include <iostream>
#include <string>

int main() {
    std::ios::sync_with_stdio(false);

    for (std::string s; std::cin >> s;) {
        uint64_t counts[256] = {0};
        uint64_t result = 1;
        for (unsigned i = 0; i < s.size(); ++i) {
            result += i - counts[s[i]];
            ++counts[s[i]];
        }
        std::cout << result << '\n';
    }
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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 repa(i,a,n) for(int i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
#define COUT(x) cout<<(x)<<endl
#define YES(x) cout<<(x?"YES":"NO")<<endl
#define Yes(x) cout<<(x?"Yes":"No")<<endl
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a / gcd(a, b)*b;}
//cout << fixed << setprecision(15);
int N, M, K, H, W, L, R, X, Y;
string S, T;

signed main(){
  cin >> S;
  N = S.size();
  if(S[0]!='A') {cout << "WA" << endl; return 0;}
  int c = 0, cp;
  for(int i = 2; i<=N-2; i++) if(S[i] == 'C') {c++; cp = i;}
  if(c != 1) {cout << "WA" << endl; return 0;}
 
  rep1(i,N){
    if(i==cp) continue;
    if(!islower(S[i])){cout << "WA" << endl; return 0;}
  }
  cout << "AC" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
#define ci(n,a)   vi a(n); rep(i,(n)) cin>>a[i];
#define rep(i,n)  for(ll i = 0; i < (n); ++i)
#define red(i,n)  for(ll i = (n)-1; i >= 0; --i)
#define all(a)    begin(a),end(a)
#define pb(a)     push_back(a)
#define mp(a,b)   make_pair(a,b)
#define yn(a)     cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;


int main(int argc,char* argv[])
{
    ll n,m;
    string s,t,ans;
    cin>>n>>m>>s>>t;
    if(s[0]!=t[0]) cout<<-1<<endl,exit(0);
    if(gcd(n,m)==1) cout<<n*m<<endl,exit(0);
    if(n<m) swap(n,m),swap(s,t);
    rep(i,gcd(n,m)) if(s[i*n/gcd(n,m)]!=t[i*m/gcd(n,m)]) cout<<-1<<endl,exit(0);
    cout<<n*m/gcd(n,m)<<endl;
    return 0;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
n = int(input())

coin = [1]
for i in range(1, 6):
    coin.append(pow(9, i))
for i in range(1, 7):
    coin.append(pow(6, i))

inf = pow(10, 10)
dp = [inf for _ in range(n + 1)]
dp[0] = 0
for i in range(1, n + 1):
    for j in range(len(coin)):
        if i - coin[j] >= 0:
            dp[i] = min(dp[i], dp[i - coin[j]] + 1)
print(dp[n])


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

#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define sz(x) ((ll)(x).size())
#define pb push_back
typedef long long ll;

int main(){
#define int ll
  int n; cin >> n;
  int k = 0;
  vector<bool> ans;
  while(n){
    if(n&1){
      ans.pb(1);
      n -= pow(-1,k);
    }else ans.pb(0);
    n /= 2;
    k++;
  }

  if(sz(ans) == 0) cout << 0 << endl;
  else{
    ROF(i,ans.size(),0) cout << ans[i];
    cout << endl;
  }
}

Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let r: usize = sc.read();
    let g: usize = sc.read();
    let b: usize = sc.read();
    let n: usize = sc.read();

    let mut ans: u64 = 0;
    for ri in 0..(n + 1) {
        for gi in 0..(n + 1) {
            let sum = ri * r + gi * g;
            if sum > n || (n - sum) % b != 0 {
                continue;
            }
            ans += 1;
        }
    }
    println!("{}", ans);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<int> H(N);
  for(int i = 0; i < N; i++) cin >> H[i];
  
  vector<vector<int>> to(N);
  
  for(int i = 0; i < M; i++){
    int A, B;
    cin >> A >> B;
    A--; B--;
    
    to[A].push_back(B);
    to[B].push_back(A);
  }
  
  int good = N;
  
  for(int i = 0; i < N; i++){
    for(int next : to[i]){
      if(H[i] <= H[next]){
        --good;
        break;
      }
    }
  }
  
  cout << good << endl;
  
  return 0;
}

Measured memory_bytes: 8804
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

//int gcd(int a, int b) {
//    int v0 = a, v1 = b, v2 = a % b;
//    while (v2 != 0) {
//        v0 = v1;
//        v1 = v2;
//        v2 = v0 % v1;
//    };
//    return v1;
//}

int main() {
    int N;
    cin >> N;
    long A[N];
    for (int i=0; i<N; i++) {
        cin >> A[i];
    }
    int nega=0;
    long sum=0;
    for (int i=0; i<N; i++) {
        if(A[i]<0){
            nega++;
            A[i]=(-1)*A[i];
        }
        sum+=A[i];
    }
    long min=A[0];
    for (int i=1; i<N; i++) {
        if (min>A[i]) {
            min=A[i];
        }
    }
    long ans=0;
    if (nega%2==0) {
        ans = sum;
    }
    else{
        ans=sum-(2*min);
    }
    cout << ans << endl;
}


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

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

    int n, k;
    cin >> n >> k;
    
    int h[n], c[n];
    rep(i, n) cin >> h[i];

    c[0] = 0;
    c[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; ++i){
        int m = min(i, k);
        c[i] = (1 << 31) - 1;
        for(int j = 1; j <= m; ++j){
            c[i] = min(c[i], c[i-j] + abs(h[i] - h[i-j]));
        }
    }

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

    return 0;
}


Measured memory_bytes: 1152
inf =  1100000
def main():
  N =  int(input())
  a = list(map(int, input().split()))
  a.sort()
  detect = [0] *inf
  for x in a:
    if detect[x] != 0:
      detect[x] = 2
      continue
    for i in range(x, inf, x):
      detect[i] += 1
  ans = 0
  for i in range(N):
    if detect[a[i]] == 1:
      ans += 1
  print(ans)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 32236
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main(){
  ll N; cin >> N;
  vector<ll> cnt(13,0), D(N+1);
  D[0] = 0; cnt[0]++; //高橋くん
  REP(i,N){
    cin >> D[i+1];
    cnt[D[i+1]]++;
  }
  //0,12が2人以上いれば,必ずs=0
  if(cnt[0]>=2 || cnt[12]>=2){
    cout << 0 << endl;
    return 0;
  }
  //D(>=1)が同じ人が3人以上いれば，必ずs=0
  FOR(i,1,13){
    if(cnt[i]>=3){
      cout << 0 << endl;
      return 0;
    }
  }
  //同じDを取る人は2人以下
  //2人いる場合は別時刻としてよい
  ll U = (1<<12);
  ll ans = 0;
  vector<bool> use(24,false);
  use[0] = true;
  FOR(i,1,13){
    if(cnt[i]==2){
      use[i] = true;
      use[24-i] = true;
    }
  }
  REP(i,U){
    vector<bool> use2 = use;
    FOR(j,1,13){
      if(cnt[j]!=1) continue;
      if(i&(1<<(j-1))) use2[j] = true;
      else use2[24-j] = true;
    }
    ll mini = 1e18;
    REP(i,23) FOR(j,i+1,24) if(use2[i]&&use2[j]){
      ll b = j-i;
      mini = min(mini, min(b,24-b));
    }
    ans = max(ans,mini);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N,M,X=map(int,input().split())
Ai=list(map(int,input().split()))

goto_0=0
goto_N=0

for i in range(0,X):
    if i in Ai:
        goto_0 += 1

for i in range(X,N):
    if i in Ai:
        goto_N += 1

print(min(goto_0,goto_N))

Measured memory_bytes: 9008
from functools import reduce

def myMin(v1,v2):
    if v1 > v2:
        return v2
    return v1

def myMax(v1,v2):
    if v1 < v2:
        return v2
    return v1

def mySum(v1,v2):
    return v1 + v2

n = int(input())
values = list(map(int, list(input().split())))

print(reduce(myMin, values, 1000001), reduce(myMax, values, -1000001), reduce(mySum, values, 0))


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b and b == c){
        cout << 1 << endl;
    }else if (a == b){
        cout << 2 << endl;
    }else if (b == c){
        cout << 2 << endl;
    }else if (c == a){
        cout << 2 << endl;
    }else{
        cout << 3 << endl;
    }
    return 0;
}

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

using ll = long long;

const int N = 3e3 + 69;
const ll MOD = 998244353;

int n, s;
int ar[N];
ll dp[N][N];

ll modpow(ll a, ll b) {
	ll res = 1;
	while(b) {
		if(b & 1) {res = res * a % MOD;}
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	cin >> n >> s;
	for(int i = 1; i <= n; i++) {
		cin >> ar[i];
	}
	// dp[0][0] = 1;
	dp[1][ar[1]] = 1;
	for(int i = 2; i <= n; i++) {
		for(int j = 1; j <= s; j++) {
			if(j < ar[i]) {
				dp[i][j] = 2 * dp[i - 1][j];
				dp[i][j] %= MOD;
			}
			if(j > ar[i]) {
				dp[i][j] = 2 * dp[i - 1][j] + dp[i - 1][j - ar[i]];
				dp[i][j] %= MOD;
			}
			if(j == ar[i]) {
				dp[i][j] = 2 * dp[i - 1][j] + modpow(2, i - 1);
				dp[i][j] %= MOD;
 			}
		}
	}

	// for(int i = 1; i <= n; i++) {
	// 	for(int j = 1; j <= s; j++) {
	// 		cerr << i << " " << j << " " << dp[i][j] << "\n";
	// 	}
	// }

	cout << dp[n][s] << "\n";
	return 0;
}


Measured memory_bytes: 75532
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(10));
    vector<vector<int>> P(N, vector<int>(11));
    REP(n, N) {
        REP(i, 10) {
            cin >> F[n][i];
        }
    }
    REP(n, N) {
        REP(i, 11) {
            cin >> P[n][i];
        }
    }

    int ans = -2 * 1e9;
    REP(i, 1 << 10) {
        if (i == 0) continue;
        int score = 0;
        REP(n, N) {
            char same = 0;
            REP(j, 10) {
                same += (F[n][j] && (i & (1 << j)));
            }
            score += P[n][same];
        }
        ans = max(score, ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n-1];
		int sum = 0;
		
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}
		
		for(int i = 0; i < n; i++){
			b[i] = sc.nextInt();
		}
		
		for(int i = 0; i < n-1; i++){
			c[i] = sc.nextInt();
		}
		
		for(int i = 0; i < n; i++){
			sum += b[a[i] - 1];
			if(i < n-1){
				if(a[i+1] - a[i] == 1){
				sum += c[a[i]-1];
			}
		}}
	
		System.out.println(sum);
	}
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  string A, B, C;
  cin >> A >> B >> C;
  int ans = 0;
  REP(i, N) {
    set<char> st;
    st.insert(A[i]);
    st.insert(B[i]);
    st.insert(C[i]);
    if (st.size() == 1) ans += 0;
    if (st.size() == 2) ans += 1;
    if (st.size() == 3) ans += 2;
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class _1180
{
    public static void Main()
    {
        string str = Console.ReadLine(), argument, san;
        string[] data;
        int an = 0, max, min, count, L;
        bool flag;
        char[] maxChar, minChar;
        Dictionary<int, int> nums = new Dictionary<int, int>();
        while (str != "0 0")
        {
            data = str.Split();
            nums.Clear();
            an = int.Parse(data[0]);
            L = int.Parse(data[1]);
            argument = "D" + L;
            san = an.ToString(argument);
            flag = false;
            count = 0;
            maxChar = new char[L];
            minChar = new char[L];
            nums.Add(an, count);
            while (!flag)
            {
                count++;
                san.ToCharArray().CopyTo(maxChar, 0);
                maxChar.CopyTo(minChar, 0);
                Array.Sort(maxChar);
                Array.Sort(minChar);
                Array.Reverse(maxChar);
                max = int.Parse(new string(maxChar));
                min = int.Parse(new string(minChar));
                an = max - min;
                san = an.ToString(argument);
                if (nums.ContainsKey(an))
                {
                    Console.WriteLine(nums[an] + " " + an + " " + (count - nums[an]));
                    flag = true;
                }
                else
                {
                    nums.Add(an, count);
                }
            }
            str = Console.ReadLine();
        }
    }
}

Measured memory_bytes: 6456
n = int(input())
sp = []
for i in range(n):
    sp.append(list(map(str, input().split())))
    sp[i].append(i+1)
sp = sorted(sp, key=lambda x:int(x[1]), reverse=True)
sp = sorted(sp, key=lambda x:x[0])
for i in range(n):
    print(sp[i][2])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
typedef long long T;
 
struct point { 
    T x,y;
    int i; 
    point operator - (const point &rhs) {
        return {x-rhs.x, y-rhs.y};
    }
    T dot(const point &rhs) {
        return x*rhs.x + y*rhs.y;
    }
    T cross(const point &rhs) {
        return x*rhs.y - y*rhs.x;
    }
    T len2() {
        return x*x + y*y;
    }
};
 
int compare(T x, T y) {
    if(y-x > 0) return -1;
    if(x-y > 0) return 1;   
    return 0;
}
 
T cross(point p, point q, point r) { return (r-q).cross(p-q); }
 
int turn(point p, point q, point r) { return compare(cross(p,q,r), 0); }
 
int cw(point p, point q, point r) { return turn(p,q,r) < 0; }
 
double angle(point a, point o, point b) // angle AOB (in radians)
{
   point u = a - o; // u: vector oa
   point v = b - o; // v: vector ob
   return acos(u.dot(v) / sqrt(1.0 * u.len2() * v.len2())); // dot product
}

bool cmp(const point &p, const point &q)
{
    return p.x < q.x || (p.x == q.x && p.y < q.y);
}
 
vector<point> convex_hull(vector<point> &p)
{
    int n = (int)p.size(), k = 0;
    vector<point> h(2 * n);
    sort(p.begin(), p.end(), cmp);
    for(int i = 0; i < n; i++) 
    {
        while(k >= 2 && cw(h[k-2], h[k-1], p[i])) k--;
        h[k++] = p[i];
    }
    for(int i = n - 2, t = k + 1; i >= 0; i--) 
    {
        while(k >= t && cw(h[k-2], h[k-1], p[i])) k--;
        h[k++] = p[i];
    }
    h.resize(k); h.pop_back(); 
    return h;
}
 
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(10);
    int n,m;
    vector<point> p,h;
    double ans[105];
    while(cin >> n)
    {
        p = vector<point>(n);
        for(int i = 0; i < n; i++)
        {
            cin >> p[i].x >> p[i].y;
            p[i].i = i;
        }
        h = convex_hull(p);
        for(int i = 0; i < n; i++)
            ans[i] = 0;
        m = h.size();
        for(int i = 0; i < m; i++)
            ans[h[i].i] = (M_PI - angle(h[(i-1+m)%m], h[i], h[(i+1)%m])) / (2*M_PI);
        for(int i = 0; i < n; i++)
            cout << ans[i] << '\n';
    }
    return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main(){
  long long n;
  cin>>n;
  for(int i=0;i<n;i++){
    long long s,d;
    cin>>s>>d;
    long long ans=0;
    while(s<d){
      long long n_=1;
      long long next=1;
      while(n_<=d-s){
	if(s%n_==0){
	  next=n_;
	}
	n_*=2;
      }
      s+=next;
      ans++;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3084