akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
typedef pair<int, int> P;

int h, w;
char c[510][510];
int d[510][510][26];

int main(){
    cin >> h >> w;
    rep(i, 0, h){
        rep(j, 0, w){
            cin >> c[i][j];
        }
    }
    int ans = 0;
    for(int t = 0;; t++){
        bool f = false;
        char er;
        memset(d, 0, sizeof(d));
        rep(i, 0, h){
            rep(j, 0, w){
                if(c[i][j] == '.') continue;
                for(int k = j + 1; k < w; k++){
                    if(c[i][k] == '.') d[i][k][c[i][j] - 'A']++;
                    else break;
                }
                for(int k = j - 1; j >= 0; k--){
                    if(c[i][k] == '.') d[i][k][c[i][j] - 'A']++;
                    else break;
                }
                for(int k = i + 1; k < h; k++){
                    if(c[k][j] == '.') d[k][j][c[i][j] - 'A']++;
                    else break;
                }
                for(int k = i - 1; k >= 0; k--){
                    if(c[k][j] == '.') d[k][j][c[i][j] - 'A']++;
                    else break;
                }
            }
        }
        rep(i, 0, h){
            rep(j, 0, w){
                rep(k, 0, 26){
                    if(d[i][j][k] == 2){
                        f = true;
                        er = 'A' + k;
                        ans += 2;
                        j = w; i = h; break;
                    }
                }
            }
        }
        if(!f) break;
        rep(i, 0, h){
            rep(j, 0, w){
                if(c[i][j] == er){
                    c[i][j] = '.';
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 29760
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000

vector<int> A(MAX + 1);
int H;

int parent(int i)
{
  return floor((double)i / 2.0);
}

int left(int i)
{
  return i * 2;
}

int right(int i)
{
  return i * 2 + 1;
}

void maxHeapify(int i)
{
  int l = left(i);
  int r = right(i);
  int largest;
  // 左の子、自分、右の子で値が最大のノードを選ぶ
  if (l <= H && A.at(l) > A.at(i))
  {
    largest = l;
  }
  else
  {
    largest = i;
  }
  if (r <= H && A.at(r) > A.at(largest))
  {
    largest = r;
  }

  if (largest != i)
  {
    swap(A.at(i), A.at(largest));
    maxHeapify(largest);
  }
}

void buildMaxHeap()
{
  for (int i = H / 2; i >= 1; i--)
  {
    maxHeapify(i);
  }
}

int main()
{
  cin >> H;
  for (int i = 1; i <= H; i++)
  {
    cin >> A.at(i);
  }
  buildMaxHeap();
  for (int i = 1; i <= H; i++)
  {
    cout << " " << A.at(i);
    if (i == H)
    {
      cout << endl;
    }
  }
}


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

int hantei(string,string,int);
int main(){ 
  int n,l;
  cin>>n>>l;
  string s[100];
  for(int i=0;i<n;i++){
    cin>>s[i];
  }
  string temp;
  for(int j=0;j<n-1;j++){
  	for(int k=n-1;k>j;k--){
      if(2==hantei(s[k-1],s[k],l)){
        temp=s[k];
        s[k]=s[k-1];
        s[k-1]=temp;
      }
    }
  }
  for(int m=0;m<n;m++){
    cout<<s[m];
  }
  return 0;  
}

int hantei(string s1,string s2,int l){
  for(int i=0;i<l;i++){
    if(s1[i]<s2[i]){
      return 1;
    }else if(s1[i]>s2[i]){
      return 2;
    }
  }
  return 0;
} 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <cctype>

int main()
{
	std::string input_text;
	std::getline(std::cin, input_text);
	std::transform(
			input_text.begin(), input_text.end(),
			std::ostream_iterator<char>(std::cout, ""),
			static_cast<int(*)(int)>(&std::toupper));
	std::cout << std::endl;

	return 0;
}

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

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

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N;cin>>N;
    int A[200010];
    map<int,int> mp;
    for(int i=0;i<N;i++){
        cin>>A[i];
        mp[A[i]]++;
    }
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        if(itr->second>1){
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}

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

using namespace std;

#define ll long long

const ll mod = (ll)1e9 + 7;

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


	// count[i] := a中にiが何個登場するか
	ll count[2001];
	for (int i = 0; i < 2001; ++i)
		count[i] = 0;
	for (auto ai : a)
		++count[ai];

	// t := a1つの中での転倒数
	ll t = 0;
	for (int i = 0; i < n; ++i)
		for (int j = i + 1; j < n; ++j)
			if (a[i] > a[j])
				++t;

	// sum[i] := a中にi未満が何個存在するか
	ll sum[2001];
	for (int i = 0; i < 2001; ++i)
		sum[i] = 0;
	for (int i = 1; i < 2001; ++i)
		sum[i] = sum[i - 1] + count[i - 1];

	ll p = 0;
	for (int i = 0; i < 2001; ++i)
		p = (p + count[i] * sum[i] % mod) % mod;

	ll ans1 = k * t % mod;
	ll ans2 = (k * (k - 1) / 2) % mod * p % mod;
	cout << (ans1 + ans2) % mod << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
n = int(input())
l = 0
r = n-1
print(0)
sys.stdout.flush()
i = input()
if i == "Vancant": exit()

for _ in range(19):
    m = (l+r)//2
    print(m)
    sys.stdout.flush()
    j = input()
    if j == "Vancant": exit()
    if (m-l)%2 == 0 and i != j: r = m-1
    elif (m-l)%2 == 1 and i == j: r = m-1
    else:
        l = m+1
        i = "Male" if j == "Female" else "Female"

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

#define rep(i,n) for(int i=0;i<(n); ++i)
#define INF 100000 // 2^31-1
#define MAX_V 100000


using namespace std;

using ll =long long;
using P = pair<int,int>;

string replaceAll(string &replacedStr, string from, string to) {
    unsigned int pos = replacedStr.find(from);
    int toLen = to.length();
 
    if (from.empty()) {
        return replacedStr;
    }
 
    while ((pos = replacedStr.find(from, pos)) != string::npos) {
        replacedStr.replace(pos, from.length(), to);
        pos += toLen;
    }
    return replacedStr;
}
 
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

//22
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int gettt(long long int num){
    int digit=0;
if(num<10){
digit=0;
}else{
    while(num>1){
        num /= 10;
        digit++;
    }
}
    return digit;
}




int main() {

ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin>>n>>k;

int p[n];
for(int i=0;i<n;i++){
cin>>p[i];
}
sort(p,p+n);
int kot=0;
for(int i=0;i<n;i++){
if(i<k){
kot+=p[i];


}else break;
}
cout<<kot<<endl;

}
//double res=10.11;
//printf("%.10f",ans);
//cout << fixed << setprecision(5) <<(n*2)*M_PI << endl;


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 3e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int n;

int main() {
	scanf("%d", &n);
	double ans = (n / 3.0) * (n / 3.0) * (n / 3.0);
	printf("%.10lf\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt();
            }

            int prepre = 0;
            int pre = Math.abs(arr[0] - arr[1]);

            for (int i = 2; i < n; i++) {
                int oldPre = pre;
                pre = Math.min(pre + Math.abs(arr[i] - arr[i - 1]), prepre + Math.abs(arr[i] - arr[i - 2]));
                prepre = oldPre;
            }

            System.out.println(pre);
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n, k;
    cin >> n >> k;

    mp m;
    rep(i, n){
        int a;
        cin >> a;
        m[a]++;
    }

    if(m.size() <= k){
        cout << 0 << endl;
    }else{
        int x = m.size() - k;
        vector<int> v;
        for (auto& p : m) {
            v.push_back(p.second);
        }
        sort(all(v));
        int ans = 0;
        for (int i = 0; i < x; ++i) {
            ans += v[i];
        }

        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 10744
EAST = 0
WEST = 1

def build_cumsum(s)
  cumsum = [[0, 0]]
  s.split('').each_with_index do |x, i|
    if x == 'E' then
      cumsum[i + 1] = [cumsum[i][EAST] + 1, cumsum[i][WEST]]
    else
      cumsum[i + 1] = [cumsum[i][EAST], cumsum[i][WEST] + 1]
    end
  end
  return cumsum
end

def diff_cumsum(a, b)
  [b[EAST] - a[EAST], b[WEST] - a[WEST]]
end
  
def main(argv)
  n = gets.chomp.to_i
  s = gets.chomp
  
  cumsum = build_cumsum(s)
  
  m = n + 1
  (0...n).each do |i|
    a = diff_cumsum(cumsum[0], cumsum[i])
    b = diff_cumsum(cumsum[i + 1], cumsum[n])
    m = [m, a[WEST] + b[EAST]].min
  end  
  puts m.to_s
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 48268
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n;cin>>n;
  vector<int> p(n);
  rep(i, n) {
    cin>>p[i];
  }
  dump(p);
  vector<int> q(n);
  rep(i, n) {
    cin>>q[i];
  }
  dump(q);

  vi x(n);
  iota(all(x), 1LL);

  int i = 0;
  int a = 0;
  int b = 0;
  do{
    if (x==p){
      a = i;
    }
    if (x==q){
      b = i;
    }
    i++;
  } while (next_permutation(all(x)));
  cout << abs(a-b) << endl;
  return 0;
}


Measured memory_bytes: 256
package main

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

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

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

func main() {
	const MAX int = 60
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	a := make([]int64, n)
	var s int64
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &a[i])
		s ^= a[i]
	}

	for i := 0; i < n; i++ {
		a[i] = a[i] &^ s
	}

	var rank int
	for i := 59; i >= 0; i-- {
		var j int
		for j = rank; j < n; j++ {
			if a[j]&(1<<uint(i)) > 0 {
				break
			}
		}
		if j == n {
			continue
		}
		if j > rank {
			a[rank] ^= a[j]
		}
		for j := rank + 1; j < n; j++ {
			a[j] = min(a[j], a[j]^a[rank])
		}
		rank++
	}

	var x int64
	for i := 0; i < n; i++ {
		x = max(x, x^a[i])
	}

	ans := x*2 + s
	fmt.Println(ans)
}


Measured memory_bytes: 4736
n = int(input())
p = input().split()

counter = 0
for i in range(2, n):
    if int(p[i - 2]) > int(p[i - 1]) > int(p[i]):
        counter += 1
    elif int(p[i - 2]) < int(p[i - 1]) < int(p[i]):
        counter += 1
print(counter)


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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(a > b) { a = b; return true; } return false; }

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n, m; cin >> n >> m;
    vi c(n);
    REP(i, m)
    {
        int a, b; cin >> a >> b;
        c[a-1]++; c[b-1]++;
    }
    REP(i, n) cout << c[i] << endl;
}

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

int main()
{
	int x, num, sum = 0,tmp;

	cin >> num;
	x = num;
	while (num)
	{
		tmp = num % 10;
		sum = sum + tmp;
		num = num / 10;
	}

	if (x % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1e9+1;


void solve(){
    int n;
    cin >> n;
    cout << 1110-n << endl;
}

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


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

using namespace std;

const int BASE = 10000;

int n, m, r;

struct dat{
	vector <int> d;
	
	dat operator * (const int T) const{
		dat tmp;
		tmp.d = d;
		for(int i = 0; i < d.size(); i++)
		tmp.d[i] *= T;
		for(int i = 0; i < tmp.d.size(); i++){
			if(tmp.d[i] >= BASE){
				if(i == tmp.d.size() - 1)
				tmp.d.push_back(tmp.d[i] / BASE);
				else
				tmp.d[i + 1] += tmp.d[i] / BASE;
				tmp.d[i] %= BASE;
			}
		}
		return tmp;
	}
	
	dat operator / (const int T) const{
		dat tmp;
		tmp.d = d;
		int cur = 0;
		for(int i = tmp.d.size() - 1; i >= 0; i--){
			cur = cur * BASE + tmp.d[i];
			tmp.d[i] = cur / T;
			cur %= T;
		}
		
		for(int i = 0; i < tmp.d.size(); i++){
			if(tmp.d[i] >= BASE){
				if(i == tmp.d.size() - 1)
				tmp.d.push_back(tmp.d[i] / BASE);
				else
				tmp.d[i + 1] += tmp.d[i] / BASE;
				tmp.d[i] %= BASE;
			}
		}
		
		while(tmp.d.size() && tmp.d.back() == 0)
		tmp.d.pop_back();
		
		return tmp;
	}
	
	void print(){
		if(d.empty())
		printf("0");
		else{
			printf("%d", d.back());
			for(int i = d.size() - 2; i >= 0; i--){
				printf("%.4d", d[i]);
			}
		}
		printf("\n");
	}
}res;

int main(){
	scanf("%d%d%d", &n, &m, &r);
	
	r -= n * m;
	
	if(r < 0) return 0 * printf("0\n");
	
	//(n + r - 1)C(r)
	
	res.d.push_back(1);
	
	for(int i = 1; i <= n + r - 1; i++)
	res = res * i;
	
	for(int i = 1; i <= r; i++)
	res = res / i;
	
	for(int i = 1; i <= n - 1; i++)
	res = res / i;
	
	res.print();
	
}



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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    i64 X = input();

    map< i64, int > mp;
    for (i64 a = 0; ; a++) {
        i64 A = a * a * a * a * a;
        mp[A] = a;
        if (mp.count(A - X)) {
            cout << a << " " << mp[A - X] << endl;
            return;
        }
        if (mp.count(-(A - X))) {
            cout << a << " " << -mp[-(A - X)] << endl;
            return;
        }
    }
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
int main() {
	lli n;
	cin>>n;
	lli a[n+1],dp[n+1];
	for(int i = 1; i <= n; i++)
        cin>>a[i];
    dp[1] = 0;
    for(int i = 2; i <= n; i++){
        dp[i] = dp[i-1] + abs (a[i] - a[i-1]);
        if(i > 2){
            dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]));
        }
    }
    cout << dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 5116
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back      
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 1000000007
#define N 211111

#define TASK "1"

using namespace std;

int main(){
	#ifdef home
		freopen(TASK".in","r",stdin);	
		freopen(TASK".out","w",stdout);
	#endif		
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	string t = "CODEFESTIVAL2016";
	int ans = 0;
	for (int i = 0; i < t.size(); i++) ans += t[i] != s[i];
	cout << ans << endl;
	return 0;
}

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

using namespace std;

namespace {

    typedef double real;
    struct Point {
        real x, y, z;
        Point() {}
        Point(real x, real y, real z) : x(x), y(y), z(z) {}
    };
    istream& operator>>(istream& is, Point& p) {
        return is >> p.x >> p.y >> p.z;
    }

    int N;
    vector<Point> S;
    int M;
    vector<Point> T;
    vector<real> P;
    bool input() {
        cin >> N;
        if (N == 0) return false;
        S.clear(); S.resize(N);
        for (int i = 0; i < N; i++) cin >> S[i];
        cin >> M;
        T.clear(); T.resize(M);
        P.clear(); P.resize(M);
        for (int i = 0; i < M; i++) {
            cin >> T[i];
            cin >> P[i];
        }
        return true;
    }

    real distance(const Point& a, const Point& b) {
        real dx = a.x - b.x;
        real dy = a.y - b.y;
        real dz = a.z - b.z;
        return sqrt(dx * dx + dy * dy + dz * dz);
    }

    const Point zero = Point(0, 0, 0);

    void solve() {
        vector<bool> flag(N, false);
        for (int i = 0; i < N; i++) {
            if (flag[i]) continue;
            for (int j = 0; j < M; j++) {
                real s = distance(zero, S[i]);
                real t = distance(zero, T[j]);
                real u = distance(S[i], T[j]);
                real cos_t = (s * s + t * t - u * u) / (2 * s * t);
                real cos_p = cos(P[j]);
                if (cos_t > cos_p) {
                    flag[i] = true;
                    break;
                }
            }
        }
        int ans = 0;
        for (int i = 0; i < N; i++) if (flag[i]) ans++;
        cout << ans << endl;
    }
}

int main() {
    while (input()) solve();
    return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a < b) {
		cout << "a < b" << endl;
	}
	if (a > b) {
		cout << "a > b" << endl;
	}
	if (a == b) {
		cout << "a == b" << endl;
	}
}



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

const int N = (int)1e5 + 10;
const double eps = 1e-8;

template <typename T> inline T gcd(T a, T b) { a = abs(a), b = abs(b); while ( b ) { a %= b; swap(a, b); } return a; }
vector <pair <int, int> > adj[N + 7];


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector <pair <ll, ll> > arr(n);
	for ( int i = 0; i < n; ++i ) {
		cin >> arr[i].first >> arr[i].second;
	}
	sort(arr.begin(), arr.end());
	int total = 0;
	ll taka = 0;
	for ( int i = 0; i < n; ++i ) {
		int temp = m - total;
		if ( arr[i].second <= temp ) {
			total += arr[i].second;
			taka += (arr[i].second * arr[i].first);
		} else if ( arr[i].second > temp ) {
			taka += ((m - total) * arr[i].first);
			total = m;
		}
		if ( total >= m ) break;
	}
	cout << taka << endl;
    return 0;
}


Measured memory_bytes: 4224
# B - Judge Status Summary
N = int(input())
dic = dict()

dic['AC'] = 0
dic['WA'] = 0
dic['TLE'] = 0
dic['RE'] = 0

for i in range(N):
	S = input()
	dic[S] += 1

for k, v in dic.items():
	print(k + ' x ' + str(v))

Measured memory_bytes: 9096
from collections import Counter


n = int(input())
v = list(map(int, input().split()))
v_former = Counter(v[::2]).most_common() + [(0, 0)]
v_latter = Counter(v[1::2]).most_common() + [(0, 0)]
if v_former[0][0] != v_latter[0][0]:
    print(n - v_former[0][1] - v_latter[0][1])
else:
    print(n - max(v_former[0][1] + v_latter[1][1], v_former[1][1] + v_latter[0][1]))


Measured memory_bytes: 20572
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <vector>

std::string sub(const std::string& a, const std::string& b) {
    int a_ = 0, b_ = 0;

    int k = 1;
    for(int i = 3; i >= 0; --i) {
        a_ += k * (a[i] - '0');
        b_ += k * (b[i] - '0');

        k *= 10;
    }

    char hoge[4];
    sprintf(hoge, "%04d", a_ - b_);

    return hoge;
}

int func(int i, const std::string& s) {
    if(s == "6174") {
        return i;
    }

    auto a = s, b = s;

    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end(), std::greater<char>());

    return func(i + 1, sub(b, a));
}

inline
bool same(const std::string& a) {
    bool same = true;

    for(int i = 1; i < a.size(); ++i) {
        if(a[i - 1] != a[i]) {
            same = false;
        }
    }

    return same;
}

int main() {
    std::string  n;

    while(std::cin>> n, n != "0000") {
        if(same(n)) {
            std::cout << "NA" << std::endl;

            continue;
        }

        std::cout << func(0, n) << std::endl;
    }
}

Measured memory_bytes: 3292
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_program(s) cout << s <<endl;return 0
int kai_size = 1000001;
vel kai(kai_size, 1);
vel ink(kai_size, 1);
vel dist;
int RE() {
	vel v(3, 2);
	return v.at(4); 
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, kai_size-1) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, kai_size) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	if (r < 0 || n < r) { return 0; }
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
vel dis(int mid1, vvel &way) {
	int n = way.size();
	vel dist(n, -1); dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front(); q.pop();
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) {
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
	return dist;
}
pin most_far(int now, int n, vvel &way) {
	vel dist1 = dis(now, way);
	pin ans = mkp(-1, 0);
	rep(i, n) {
		if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
	}
	return ans;
}

int per(int a, int b) {
	int ans = a % b;
	if (ans < 0) { ans += b; }
	return ans;
}
vel uni(vel &v) {
	sor(v);
	vel ans(1, v[0]);
	for (int i = 1; i < v.size(); i++) {
		if (v[i] != v[i-1]) { ans.push_back(v[i]); }
	}
	v = ans;
	return v;
}
int s_gcd(int a, int b) {
	if (b == 0) { return a; }
	return s_gcd(b, a%b);
}
int gcd(int a, int b) {
	if (a < b) { swap(a, b); }
	return s_gcd(a, b);
}
bool is_prime(int i) {
	for (int j = 2; j*j <= i; j++) {
		if (i%j == 0) { return false; }
	}
	return true;
}
int get(int i, int j, vvel &ans) {
	int n = ans.size();
	if (i < 0 || n <= i || j < 0 || n <= j) { return 1; }
	return ans[i][j];
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
signed main() {
	string s; cin >> s;
	int n = s.size();
	vvel lis(3);
	vel sum(n + 1);
	bool fl = true;
	rep(i, n) {
		lis[sum[i]].push_back(i);
		sum[i + 1] = sum[i] + (s[i] - 'a') + 1; sum[i + 1] %= 3;
		if (i % 2 == 0 xor s[i] == s[0]) { fl = false; }
	}
	if (fl) { cout << 1 << endl; return 0; }
	vel dp(n);
	dp[0] = 1;
	int ans = 0;
	rep(i, n) {
		if (sum[i] != sum[n]) { ans += dp[i]; }
		int pla = (sum[i] + 1) % 3;
		auto itr = lower_bound(lis[pla].begin(), lis[pla].end(), i);
		if (itr != lis[pla].end()) { dp[*itr] += dp[i]; dp[*itr] %= p; }
		pla++; pla %= 3;
		itr = lower_bound(lis[pla].begin(), lis[pla].end(), i);
		if (itr != lis[pla].end()) { dp[*itr] += dp[i]; dp[*itr] %= p; }
	}
	cout << ans%p << endl;
	return 0;
}


Measured memory_bytes: 18768
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 405;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
ll dp[maxn][maxn];
ll sum[maxn];
int a[maxn];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n;
    scanf("%d",&n);
    memset(dp,LL_INF,sizeof(dp));
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    for(int i=1;i<=n;i++) dp[i][i]=a[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n-i+1;j++)
        {
            int l=j,r=j+i-1;
            for(int k=l;k<=r;k++)
            {
                dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]+sum[r]-sum[l-1]);
            }
        }
    }
    printf("%lld\n",dp[1][n]-sum[n]);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}



Measured memory_bytes: 1536
#include<stdio.h>
int main(){
int a, b, c;
char op;
scanf("%d %c %d", &a, &op, &b);
while( 1 ){
if ( op == '+' ){
c = a + b;
printf("%d\n",c);
} 
else if ( op == '-' ){
c = a - b;
printf("%d\n",c);
} 
else if ( op == '*' ){
c = a * b;
printf("%d\n",c);
} 
else if ( op == '/' ){
c = a / b;
printf("%d\n",c);
} 
else {
break;
}
scanf("%d %c %d", &a, &op, &b);
}
return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000000000000001;
const ll MOD = 1000000007;

//vector< vector<ll> > g(N);
//vector< pair<ll, pair< ll, ll > > > g(N);
//ll vis[N] = {0}, par[N] = {0}, child[N] = {0},cnt = 0;


void solve(){
    ll n; cin >> n;
    ll a[n];
    f(0, n-1) cin >> a[i];
    sort(a,a +n);
    ll ans = 0;
    for(ll i=0; i<n; i++){
        for(ll j=i+1; j<n; j++){
            for(ll k=j+1; k<n; k++){
                if(a[i] + a[j] > a[k] and a[i]!= a[j] and a[j] != a[k]) ans ++;
            }
        }
    }
    cout << ans << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
   //ll t;cin >> t;for(ll index=1; index<=t; index++){
        //cout << "Case #" << index << ": " ;
        solve();
   // }
    return 0;
}

Measured memory_bytes: 3656
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    a1 = list(map(int, readline().split()))
    a2 = list(map(int, readline().split()))

    ans = 0
    for i in range(n):
        s = sum(a1[:i + 1]) + sum(a2[i:])
        ans = max(ans, s)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    
    static int H;
    static int W;
    static int K;
    static int[] XYZ;
    static int MOD = (int)1e9 + 7;
    
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        H = sc.nextInt();
        W = sc.nextInt();
        K = sc.nextInt();
        
        long[][] dp = new long[H+1][W];
        
        dp[0][0] = 1; 
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                
                XYZ = new int[3];
                dfs(0, 0b0, j);
                
                if(j>=1){
                    dp[i+1][j-1] += XYZ[0] * dp[i][j];
                    dp[i+1][j-1] %= MOD;
                } 
                
                dp[i+1][j]   += XYZ[1] * dp[i][j];
                dp[i+1][j] %= MOD;
                
                if(j<=W-2){
                    dp[i+1][j+1] += XYZ[2] * dp[i][j];
                    dp[i+1][j+1] %= MOD;
                } 
            }
        }
        
        System.out.println(dp[H][K-1]);
    }
    
    static void dfs(int num, int ptn, int j){
        
        if(num > W-1){
            if( W>=j && ((ptn >> W-j) & 1) == 1 ){
                XYZ[0]++;
                return;
            }
            
            if( W-1>=j && ((ptn >> W-j-1) & 1) == 1 ){
                XYZ[2]++;  
                return;
            } 
            
            XYZ[1]++;
            return;
        }
        
        if( num > 0 && (ptn & (1 << num-1)) == 0 ){
            dfs(num+1, ptn | 1 << num, j);    
        }
        dfs(num+1, ptn, j);

    }

}


Measured memory_bytes: 23252
#include <stdio.h>

int main() {
  int A, B, C, D;
  int sum = 0;
  
  scanf("%d %d %d %d", &A, &B, &C, &D);

  if (A >= B) {
    sum += B;
  }
  else {
    sum += A;
  }

  if (C >= D) {
    sum += D;
  }
  else {
    sum += C;
  }

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

  return 0;
}


Measured memory_bytes: 128
//https://atcoder.jp/contests/abc133/tasks/abc133_a
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
// clang-format on
int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
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(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n=5;
    vi vec(n);
    cin>>vec;
    int ans=0;
    int mi=10;
    int mix=0;
    REP(i,n){
        if(vec[i]%10&&vec[i]%10<mi){
            mi=vec[i]%10;
            mix=i;
        }
    }
    REP(i,n){
        if(mix==i){
            ans+=vec[i];
        }else{
            ans+=((vec[i]+9)/10*10);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	String w[] = {"Sunny", "Cloudy", "Rainy"};
	String S = sc.next();

	int i;
	for (i = 0; i < 3; i++) {
	    if (S.equals(w[i])) {
		i++;
		break;
	    }
	}
	if (i == 3)
	    i = 0;

	System.out.println(w[i]);
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define mxn (int)1e5+10
#define INF (int)1e4+10
using namespace std;

int ar[mxn], dp[mxn];

// simple recursive
int solve(int n, int k) {

    if(n == 0) return 0;
    if(n < 0) return INF;

    if(dp[n] != -1) return dp[n];

    int ans = INT_MAX;

    for(int i=1; i<=k; ++i) {
        ans = min(ans, solve(n-i, k) + abs(ar[n-i] - ar[n]));
    }

    return dp[n] = ans;
}

int main() {
    int n, k; cin >> n >> k;
    for(int i=0; i<n; ++i) cin >> ar[i];
    for(int i=0; i<mxn; ++i) dp[i] = -1;

    cout << solve(n-1, k) << '\n';

    return 0;
}


Measured memory_bytes: 7296
#include<iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int count = 0, count_wa = 0, count_tle = 0, count_re = 0;
  string S;
  while(cin >> S) {
    if (S == "AC") {
      count += 1;
    }
    else if (S == "WA") {
      count_wa += 1;
    }
    else if (S == "TLE") {
      count_tle += 1;
    }
    else {
      count_re += 1;
    }
  }
  cout << "AC x " << count << endl;
  cout << "WA x " << count_wa << endl;
  cout << "TLE x " << count_tle << endl;
  cout << "RE x " << count_re << endl;
  return 0;
}

Measured memory_bytes: 3624
# E - Two Currencies

import heapq

n, m, s = map(int, input().split())
adj = {u: [] for u in range(1, n+1)}
max_silver = 0
for i in range(m):
    u, v, a, b = map(int, input().split())
    adj[u].append((v, a, b)) # to, 料金, 時間
    adj[v].append((u, a, b)) # to, 料金, 時間
    max_silver += a # 全路線の料金の総和 (これ以上は不要)
exch = {}
for u in range(1, n+1):
    c, d = map(int, input().split())
    exch[u] = (c, d) # レート, 時間

s = min(s, max_silver) # max_silverまでで十分

# n <= 50, m <= 100, max_silver <= 5000

# (都市,所有銀貨)を頂点とする最短経路問題
# Dijkstra
dist = {(1, s): 0}  # 開始頂点のみ距離0
queue = [(0, 1, s)]
dmin = {1: 0} # dmin[u] = min(dist[(u, si)] for si)
nfin = 1      # 距離が決まった都市数

while len(queue) > 0:
    di, u, si = heapq.heappop(queue)
    # 用済みのデータ
    if (u, si) in dist and di > dist[(u, si)]:
        continue
    # 都市uの距離を保存
    if u not in dmin:
        dmin[u] = di
        nfin += 1
        if nfin >= n:  # 全都市の距離が決まった
            break
    # uから直接行ける各都市について
    for v, a, b in adj[u]:
        if si < a:  # 銀貨不足
            continue
        xsi = si - a
        if (v, xsi) not in dist or \
            dist[(v, xsi)] > di + b:
            dist[(v, xsi)] = di + b
            heapq.heappush(queue, (di + b, v, xsi))
    # 両替による遷移
    c, d = exch[u]
    xsi = min(si + c, max_silver)
    if (u, xsi) not in dist or \
        dist[(u, xsi)] > di + d:
        dist[(u, xsi)] = di + d
        heapq.heappush(queue, (di + d, u, xsi))

for u in range(2, n+1):
    print(dmin[u])


Measured memory_bytes: 130612
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

int main(){
    //freopen("in.txt","r",stdin);
    string s;
    cin>>s;
    int a=0,b=0;
    for(int i=0;i<3;i++){
        if(s[i]=='A') a++;
        else b++;
    }
    if(a==3||b==3) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;

}


Measured memory_bytes: 256
/**
 * File    : C.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-3-11 20:48:25
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

ll N, M;

ll ans()
{
  if (N > M)
    swap(N, M);
  if (N == 1)
  {
    if (M == 1)
    {
      return 1;
    }
    if (M == 2)
    {
      return 0;
    }
    return M - 2;
  }
  else if (N == 2)
  {
    if (M == 2)
    {
      return 0;
    }
    return 0;
  }
  return (N - 2) * (M - 2);
}

int main()
{
  cin >> N >> M;
  cout << ans() << endl;
}

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

template <typename T>
vector<T> dijkstra(Int s,vector<vector<pair<Int, T> > > & G,T INF){
  using P = pair<T, Int>;
  Int n=G.size();
  vector<T> d(n,INF);
  vector<Int> b(n,-1);
  priority_queue<P,vector<P>,greater<P> > q;
  d[s]=0;
  q.emplace(d[s],s);
  while(!q.empty()){
    P p=q.top();q.pop();
    Int v=p.second;
    if(d[v]<p.first) continue;
    for(auto& e:G[v]){
      Int u=e.first;
      T c=e.second;
      if(d[u]>d[v]+c){
	d[u]=d[v]+c;
	b[u]=v;
	q.emplace(d[u],u);
      }
    }
  }
  return d;
}

using P = pair<Int, Int>;
struct SegmentTree{
  Int n;
  vector<P> v;
  vector<vector<Int> > dat;
  SegmentTree(){};
  SegmentTree(Int n,vector<P> v):v(v){init(n);build();};
  
  void init(Int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1);
  }
  
  void build(){
    for(Int i=0;i<(Int)v.size();i++)
      dat[v[i].first+(n-1)].emplace_back(v[i].second);
    
    for(Int i=0;i<n;i++)
      sort(dat[i+n-1].begin(),dat[i+n-1].end());
    
    for(Int i=n-2;i>=0;i--){
      merge(dat[i*2+1].begin(),dat[i*2+1].end(),
	    dat[i*2+2].begin(),dat[i*2+2].end(),
	    back_inserter(dat[i]));
    }
  }
  // [a,b) * [c,d)
  inline Int query(Int a,Int b,Int c,Int d){
    Int res=0;
    auto calc=[a,b,c,d](vector<Int> &x){
      auto latte=lower_bound(x.begin(),x.end(),d);
      auto malta=lower_bound(x.begin(),x.end(),c);
      return Int(latte-malta);
    };
    for(Int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
      if(l&1) res+=calc(dat[(l++)-1]);
      if(r&1) res+=calc(dat[(--r)-1]);
    }
    return res;
  }
  
};

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

  Int n, m;
  Int INF = 1LL << 61;
  cin >> n >> m;

  using P = pair<Int, Int>;
  vector<vector<P> > G(n);
  for ( Int i = 0; i < m; i++ ) {
    Int a, b, c;
    cin >> a >> b >> c;
    G[a].push_back(P(b, c));
    G[b].push_back(P(a, c));
  }

  vector<Int> ds = dijkstra(0, G, INF);
  vector<Int> df = dijkstra(n-1, G, INF);

  vector<Int> fs, fg;
  Int q;
  cin >> q;
  for ( Int i = 0; i < q; i++ ) {
    Int a, b;
    cin >> a >> b;
    //cout << a << " " << b << endl;     
    fs.push_back(a);
    fg.push_back(b);
  }
  

  map<Int, Int> ms,mf;
  {
    vector<Int> d = ds;
    for ( Int i = 0; i < q; i++ ) d.push_back(fs[i]);
    d.push_back(INF);
    sort(d.begin(),d.end());
    d.erase(unique(d.begin(),d.end()),d.end());
    //for ( int i = 0; i < (Int)d.size(); i++ ) cout << d[i] << " ";
    //cout << endl;
    for(Int i=0;i<(Int)d.size();i++) ms[d[i]]=i;
  }
  {
    vector<Int> d = df;
    for ( Int i = 0; i < q; i++ ) d.push_back(fg[i]);
    d.push_back(INF);
    sort(d.begin(),d.end());
    d.erase(unique(d.begin(),d.end()),d.end());
    for(Int i=0;i<(Int)d.size();i++) mf[d[i]]=i;
  }
  
  
  vector<P> vp;
  for ( Int i = 0; i < n; i++ ) {
    vp.push_back(P(ms[ds[i]], mf[df[i]]));
  }
      
  SegmentTree t(n+q+1000, vp);

  for ( Int i = 0; i < q; i++ ) {
    cout << t.query(0, ms[fs[i]]+1, mf[fg[i]], mf[1LL << 61]) << endl;
    //cout << fs[i] << " " << fg[i] << endl;
    //cout << ms[fs[i]]+1 << " " << mf[fg[i]] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 74928
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  int a[N];
  int change = 0;
  
  for(int i=0;i<N;i++) {
    cin >> a[i];
  }
  for(int i=0;i<N;i++) {
    if(a[i]!=i+1) {
      change++;
    }
    if(change > 2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

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

#define MOD 1000000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

ll dp[105][100005];

int n, w;
ll peso[105], val[105];

ll knap(int obj, int valor){
    if(dp[obj][valor]!=-1){
        return dp[obj][valor];
    }
    if(obj>n && valor>0){
        return dp[obj][valor]=INF;
    }
    if(obj>n && valor<=0){
        return dp[obj][valor]=0;
    }
    ll nao=knap(obj+1, valor);
    if(valor-val[obj]>=0){
        ll pega=peso[obj]+knap(obj+1, valor-val[obj]);
        return dp[obj][valor]=min(nao, pega);
    }
    return dp[obj][valor]=nao;
}

int main(){
    fastio;
    cin >> n >> w;
    memset(dp, -1, sizeof(dp));
    for(int i=1; i<=n; i++){
        cin >> peso[i] >> val[i];
    }
    for(int i=100000; i>=0; i--){
        if(knap(1, i)<=w){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 82304
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int n,a; cin >> n >> a;
	cout << (n%500 <= a? "Yes": "No") << endl;
}

Measured memory_bytes: 256