akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int C[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

void update(string& a, const string& b) {
  if (b.size() > a.size() || (b.size() == a.size() && b > a)) {
    a = b;
  }
}

int main() {
#ifdef DEBUG
  ifstream cin("in.txt");
#endif
  int N, M;
  while (cin >> N >> M) {
    vector<int> A(M);
    for (int i = 0; i < M; i++) cin >> A[i];
    vector<string> dp(N + 1, "");
    dp[0] = "_";
    for (int i = 0; i < N; i++) {
      if (dp[i].empty()) continue;
      for (int j = 0; j < M; j++) {
        if (i + C[A[j]] > N) continue;
        update(dp[i + C[A[j]]], dp[i] + char('0' + A[j]));
      }
    }
    cout << dp[N].substr(1) << endl;
  }
  return 0;
}


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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

constexpr ll maxN = 200000;
ll N;
ll v[2][maxN];
vector<ll> vLeft, vRight;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif
  cout << setprecision(20);

  cin >> N;
  ll bMax = 0;
  ll sMax = 0;
  ll bMin = 1e10;
  ll sMin = 1e10;
  ll bIdx = -1;
  ll sIdx = -1;
  for (ll i = 0; i < N; i++) {
    cin >> v[0][i] >> v[1][i];
    if (v[0][i] > v[1][i]) swap(v[0][i], v[1][i]);
    bMax = max(bMax, v[1][i]);
    bMin = min(bMin, v[1][i]);
    sMax = max(sMax, v[0][i]);
    sMin = min(sMin, v[0][i]);
    if (bMax == v[1][i]) bIdx = i;
    if (sMin == v[0][i]) sIdx = i;
  }
  ll cand1 = (bMax - bMin) * (sMax - sMin);
  ll cand2;
  if (bIdx == sIdx) cand2 = cand1;
  else {
    ll safeL = min(v[0][bIdx], v[1][sIdx]);
    ll safeR = max(v[0][bIdx], v[1][sIdx]);
    DLOG("safeL = %lld, safeR = %lld", safeL, safeR);
    for (ll i = 0; i < N; i++) {
      if (v[1][i] < safeL) safeL = v[1][i];
      if (safeR < v[0][i]) safeR = v[0][i];
    }
    DLOG("safeL = %lld, safeR = %lld", safeL, safeR);
    for (ll i = 0; i < N; i++) {
      if ((safeL <= v[0][i] && v[0][i] <= safeR) ||
	  (safeL <= v[1][i] && v[1][i] <= safeR)   ) continue;
      vLeft.push_back(v[0][i]);
      vRight.push_back(v[1][i]);
    }
    ll k = vLeft.size();
    DLOG("k = %lld", k);
    if (k == 0) {
      cand2 = safeR - safeL;
    }else {
      vector<ll> order(k);
      iota(order.begin(), order.end(), 0);
      sort(order.begin(), order.end(),
	   [](ll a, ll b){ return vRight[a] > vRight[b]; });
      ll leftB = safeL;
      cand2 = 1e10;
      for (ll i = 0; i < k; i++) {
	cand2 = min(cand2, vRight[order[i]] - leftB);
	leftB = min(leftB, vLeft[order[i]]);
      }
      cand2 = min(cand2, safeR - leftB);
    }
    cand2 *= bMax - sMin;
  }
  cout << min(cand1, cand2) << endl;

  return 0;
}



Measured memory_bytes: 3456
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]E - Red and Green Apples
            var line = ReadLine();
            var X = line[0];
            var Y = line[1];
            var A = line[2];
            var B = line[3];
            var C = line[4];

            var p = GetApples(X); //赤色のリンゴのうち幸福度の高いものをX個選ぶ
            var q = GetApples(Y); //緑色も幸福度の高いものをY個選ぶ

            var pq = Enumerable.Concat(p, q);

            //無色のリンゴを混ぜる
            var noneColors = GetNoneColorApples();
            var apples = Enumerable.Concat(pq, noneColors).ToArray();

            Array.Sort(apples);
            Array.Reverse(apples);

            Console.WriteLine(apples.Take((int)(X + Y)).Sum());
        }

        static IEnumerable<long> GetApples(long count)
        {
            var apples = ReadLine();

            Array.Sort(apples);
            Array.Reverse(apples);

            return apples.Take((int)count);
        }

        static IEnumerable<long> GetNoneColorApples()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => long.Parse(x));
        }

        static long[] ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => long.Parse(x)).ToArray();
        }
    }
}


Measured memory_bytes: 40396
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n; cin>>n; 
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    ll l=a[n-1];
    ll s =a[0];
    rep(i,n-1){
        if(abs(l-a[i]*2)<abs(l-s*2)){
            s=a[i];
        }
    }
    cout<<l<<" "<<s<<endl;
    

}




Measured memory_bytes: 1152
import sys
N = int(input())
inputs = []
for _ in range(0, N):
    inputs.append(int(input()))
index = inputs[0]-1
count = 1
for _ in range(0, N):
    if index == 1:
        print(count)
        sys.exit()
    index = inputs[index]-1
    count += 1
print(-1)

Measured memory_bytes: 7084
object Main extends App {
    val stn = ('a' to 'z') ++ ('A' to 'Z')
    val in = io.Source.stdin.getLines
    for (n <- in if n != "0") {
        val k = in.next.split(" ").map(_.toInt)
        val kk = Stream.continually(k).flatten
        println(in.next.zip(kk).map{case (c, i) =>
            stn((stn.indexWhere(_ == c)-i+52)%52)
        }.mkString)
    }
}

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

int main() {

	int n, k, c;
	cin >> n >> k >> c;
	string s;
	cin >> s;

	vector<int> ans1, ans2;

	for (int i = 0; i < n; i++) {
		if (s[i] == 'o' && ans1.size() < k) {
			ans1.push_back(i);
			i += c;
		}
	}

	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == 'o' && ans2.size() < k) {
			ans2.push_back(i);
			i -= c;
		}
	}

	for (int i = 0; i < k; i++) {
		if (ans1[i] == ans2[k - i - 1])
			cout << ans1[i] + 1<< "\n";
	}

	return 0;
}

Measured memory_bytes: 3448
import java.util.*;

class Main{
    static int mod = 1000000000+7;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        int w = sc.nextInt();
        if(w>=s){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }
        
    }
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    int x,y;
    cin>>x>>y;
    int ans = 0;
    if(x==1 && y==1){
        ans = 1'000'000;
    }else{
        ans += max(4-x,0) * 100000;
        ans += max(4-y,0) * 100000;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

vector<int> MapData;
int Coordinate[4];

int solve(int x, int y) {
	int flag, color, curPos;

	flag = 0;
	color = 1;
	curPos = 0;
	while (true) {
		if (MapData.size() < 2) {
			MapData.push_back(1);
		} else {
			MapData.push_back(MapData[curPos - 1] + MapData[curPos]);
		}
		++curPos;
		if (flag == 0) {
			Coordinate[1] += MapData[curPos];
		}else if (flag == 1) {
			Coordinate[3] += MapData[curPos];
		}else if (flag == 2) {
			Coordinate[0] -= MapData[curPos];
		}else if (flag == 3) {
			Coordinate[2] -= MapData[curPos];
		}
		//cout << Coordinate[0] << ends << Coordinate[1] << ends << Coordinate[2] << ends << Coordinate[3] << endl << "color:" << color << endl;
		if (x >= Coordinate[0] && x <= Coordinate[1] && y >= Coordinate[2] && y <= Coordinate[3]) {
			return color + 1;
		}
		flag = (flag + 1) % 4;
		color = (color + 1) % 3;
	}
}

int main() {
	int x, y;

	memset(Coordinate, 0, sizeof(Coordinate));
	MapData.push_back(1);
	cin >> x >> y;
	if (x == 0 && y == 0) {
		cout << "1" << endl;
		return 0;
	}
	cout << solve(x, y) << endl;

	return 0;
}


Measured memory_bytes: 3144
import java.util.Scanner;

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

        int[][] peaks = new int[2][N];

        for (int i = 0; i < N; i++) {
            peaks[0][i] = scanner.nextInt();
        }

        for (int i = 0; i < M; i++) {
            int A = scanner.nextInt();
            int B = scanner.nextInt();

            if (peaks[0][A - 1] > peaks[0][B - 1]) {
                peaks[1][B - 1]++;
            } else if (peaks[0][A - 1] < peaks[0][B - 1]) {
                peaks[1][A - 1]++;
            } else {
                peaks[1][A - 1]++;
                peaks[1][B - 1]++;
            }
        }
        scanner.close();
        int ans = 0;
        for (int index : peaks[1]) {
            if (index == 0) {
                ans++;
            }
        }

        System.out.println(ans);
    }
}


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

int main()
{
    long long int a,b,c,d,i,x,y,z,m,n,o,p,r,s,u,v,w;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    i=b-a+1;
    x=(a-1)/c;
    y=b/c;
    o=y-x;
    m=(a-1)/d;
    n=b/d;
    p=n-m;
    r=__gcd(c,d);
    s=(c*d)/r;
    u=(a-1)/s;
    v=b/s;
    w=v-u;
    z=i-(o+p-w);
    printf("%lld\n",z);
   return 0;
}


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

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

string c="RYGB";

int main(void){
	int h,w,d,i,j,x,y;
	cin >> h >> w >> d;
	for(i=0; i<h; ++i){
		for(j=0; j<w; ++j){
			x = (i+j)/d;
			y = (500+i-j)/d;
			cout << c[(x%2)*2+y%2];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 512
#!/usr/bin/env python3
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += min(a[i] + a[i + 1], b[i])
    r = max(0, b[i] - a[i])
    a[i + 1] = max(0, a[i + 1] - r)
print(ans)


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

signed main() {
  int N;
  cin>>N;
  int k;
  std::vector<int> T(N),A(N);
  for(int i=0;i<N;i++)cin>>T[i]>>A[i];
  int t=T[0];
  int a=A[0];
  for(int i=1;i<N;i++){
    k=max((t-1)/T[i],(a-1)/A[i]);
    t=(k+1)*T[i];
    a=(k+1)*A[i];
  }
  cout<<a+t<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        char[] s = sc.next().toCharArray();
        int[] east = new int[s.length+1];
        int[] west = new int[s.length+1];
        east[0] = 0;
        west[0] = 0;
        for(int i = 1;i<s.length+1;i++){
            east[i] = east[i-1];
            west[i] = west[i-1];
            if(s[i-1] == 'W'){
                east[i] += 1;
            }
            if(s[i-1] == 'E'){
                west[i] += 1;
            }
        }
        // for(int data:west){
        //     System.out.print(data + " ");
        // }
        // System.out.println("");
        // System.out.println("e");
        // for(int data:east){
        //     System.out.print(data + " ");
        // }
        // System.out.println("");
        int min = Integer.MAX_VALUE;
        for(int i = 1;i<s.length+1;i++){
            int count = 0;
            count += east[i-1];
            count += west[s.length] - west[i];
            min = Math.min(min,count);
        }
        System.out.println(min);
    }
}

Measured memory_bytes: 32836
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
const long long inf=1e9+7;
const long long mod=1e9+7;
const int64_t CYCLES_PER_SEC=2800000000;
//
inline uint32_t Xor128(){
	static uint32_t x=123456789;
	static uint32_t y=362436069;
	static uint32_t z=521288629;
	static uint32_t w=88675123;
	uint32_t t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}
struct Timer{
	int64_t start;
	Timer(){reset();}
	void reset(){start=getcycle();}
	void plus(double a){start-=(a*CYCLES_PER_SEC);}
	inline double get(){return (double)(getcycle()-start)/CYCLES_PER_SEC;}
	inline int64_t getcycle(){
		uint32_t low,high;
		__asm__ volatile ("rdtsc":"=a"(low),"=d"(high));
		return ((int64_t)low)|((int64_t)high<<32);
	}
};
//
long long n,m,l,q;
long long t[300][300];
long long p[300][300];
int main(){
	cin>>n>>m>>l;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			t[i][j]=1e9+7;
			p[i][j]=1e9+7;
		}
	}
	for(int i=0;i<m;i++){
		long long a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		t[a][b]=c;
		t[b][a]=c;
	}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i!=j&&j!=k&&k!=i){
					t[i][j]=min(t[i][j],t[i][k]+t[k][j]);
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(t[i][j]<=l){
				p[i][j]=1;
			}
		}
	}
	for(int k=0;k<n;k++){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i!=j&&j!=k&&k!=i){
					p[i][j]=min(p[i][j],p[i][k]+p[k][j]);
				}
			}
		}
	}
	cin>>q;
	for(int i=0;i<q;i++){
		long long s,g;
		cin>>s>>g;
		s--;g--;
		if(p[s][g]==1e9+7){
			cout<<-1<<endl;
		}else{
			cout<<p[s][g]-1<<endl;
		}
	}
	return 0;
}

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

int main(){
    int n;
    double ans = 0.0;
    cin >> n;
    pair<double,double> g[n];
    for(int i = 0 ; i < n ; i += 1){
        cin >> g[i].first >> g[i].second;
    }
    sort(g,g+n);
    do{
        double v=0.0;
        for(int i = 1 ; i < n ; i += 1){
            v += sqrt((g[i].first-g[i-1].first)*(g[i].first-g[i-1].first) + (g[i].second-g[i-1].second)*(g[i].second-g[i-1].second));
        }
        ans += v;
    }while(next_permutation(g,g+n));
    for(double i = 1 ; i <= n ; i += 1){
        ans /= i;
    }
    cout << setprecision(6) << fixed;
    cout << ans;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static class UnionFind {
		int[] par; //

		public UnionFind(int n) {
			par = new int[n];
			for(int i = 0; i < n; i++){
				par[i] = -1;
			}
		}

		public int find(int x) {
			if(par[x] < 0){
				return x;
			}else{
				return par[x] = find(par[x]);
			}
		}

		public boolean union(int x, int y) {
			x = find(x);
			y = find(y);

			if(x != y){
				if(par[y] < par[x]){ // 多い方が根になるようにスワップする.
					int tmp = x;
					x = y;
					y = tmp;
				}
				par[x] += par[y];
				par[y] = x;
				return true;
			}else{
				return false;
			}
		}

		public boolean same(int x, int y) {
			return find(x) == find(y);
		}

		public int size(int x) {
			return -par[find(x)];
		}
	}
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			
			UnionFind uf = new UnionFind(N);
			
			for(int i = 0; i < M; i++) {
				final int A = sc.nextInt() - 1;
				final int B = sc.nextInt() - 1;
				
				uf.union(A, B);
			}
			
			int max = Integer.MIN_VALUE;
			for(int i = 0; i < N; i++) {
				max = Math.max(max, uf.size(i));
			}
			
			System.out.println(max);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 57964
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f,N=1e6+5;
int n;
int two[N];
int calc(int x)
{
	int s=0;
	while(x%2==0)
	{
		x=x/2;
		s++;
	}
	return s;
}
int a[N];
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i;

	string s;
	cin>>n;
	for(i=1;i<=n;i++)
		two[i]=two[i-1]+calc(i);

//	for(i=1;i<=n;i++)
//		cout<<two[i]<<" ";
//	cout<<endl;
	cin>>s;
	for(i=1;i<=n;i++)
		a[i]=s[i-1]-'1';
		
	bool f=0;
	for(i=1;i<=n;i++)
		if(a[i]==1) f=1;
	if(!f)
	{
		for(i=1;i<=n;i++)
			a[i]=a[i]/2;
	}
	int ans=0;
	for(i=1;i<=n;i++)
	{
	//	cout<<two[n]-two[i]-two[n-i]<<" "<<a[i]<<endl;
		if((two[n-1]-two[i-1]-two[n-i])<=0)
		{
			ans+=a[i];
			ans=ans%2;
		}
	}
	if(!f) ans=ans*2;
	cout<<ans<<endl;
}

Measured memory_bytes: 9220
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int i,j,n,n1,a,b,x,x1,m,m1;
	cin>>a>>b>>x;
	x1=x;
	m=10000000;
	n=x/1000;
	if(x%1000!=0) n=n+1;
	n1=x/500;
	if(x%500!=0) n1=n1+1;
	for(i=0;i<=n;i++){
		x1=x-1000*i;
		for(j=0;j<=n1;j++){
			if(x1<=0){
				m1=a*i+b*j;
				break;
			}
			x1=x1-500;
		}
		if(m>m1) m=m1;
	}
	cout<<m<<endl;
	return 0;
}



Measured memory_bytes: 3120
N = int(input())
A = input().split()
num_list = [0] * 10**5
ans = 0

for i in range(N):
    num_list[int(A[i])-1] += 1

for i in range(10**5):
    ans += (i+1) * num_list[i]

Q = int(input())

for i in range(Q):
    B, C = map(int, input().split())

    ans = ans + C * num_list[B-1] - B * num_list[B-1]
    num_list[C-1] += num_list[B-1]
    num_list[B-1] = 0

    print(ans)

Measured memory_bytes: 17568
#include<stdio.h>
char p, *P[]={"No","Yes"};
int n, a[2], i;
char c;
int main(void){
  scanf("%d\n", &n);
  for(i=n-1; i>=0; i--){
    c=getchar();
    a[c=='B']++;
  }
  p = a[0]>a[1];
  puts(P[p]);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

const int mod = 1e9 + 7, p1 = 17, p2 = 998244353;

int pw(int x, int p) {
    int r = 1;
    while (p) {
        if (p & 1) r = (llong)r * x % mod;
        x = (llong)x * x % mod;
        p >>= 1;
    }
    return r;
}

int n;
char in[250002];
pii S[250001];
int P[250001];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> in + 1;
    for (int i = 1; i <= n; ++i) {
        if (in[i] == '+') {
            P[i] = P[i - 1];
            S[i].fs = (S[i - 1].fs + pw(p1, P[i])) % mod;
            S[i].se = (S[i - 1].se + pw(p2, P[i])) % mod;
        }
        else if (in[i] == '-') {
            P[i] = P[i - 1];
            S[i].fs = (S[i - 1].fs + mod - pw(p1, P[i])) % mod;
            S[i].se = (S[i - 1].se + mod - pw(p2, P[i])) % mod;
        }
        else if (in[i] == '>') {
            P[i] = (P[i - 1] + 1) % (mod - 1);
            S[i] = S[i - 1];
        }
        else {
            P[i] = (P[i - 1] + mod - 2) % (mod - 1);
            S[i] = S[i - 1];
        }
    }
    llong ans = 0;
    map<pii, int> mp;
    for (int i = 0; i <= n; ++i) {
        ans += mp[S[i]];
        pii v(((llong)pw(p1, P[i]) * S[n].fs + S[i].fs) % mod
            , ((llong)pw(p2, P[i]) * S[n].se + S[i].se) % mod);
        ++mp[v];
    }
    printf("%lld\n", ans);
}

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

int position(int A[])
{
    int i;
    for(i=0; i<5; i++){
        if(A[i]==0){
            break;
        }
    }
    return i+1;
}

int main()
{
    int a[5], loc;
    for(int i=0; i<5; i++){
        cin>>a[i];
    }
    loc = position(a);
    cout << loc << endl;
}


Measured memory_bytes: 3636
n, m = map(int,input().split())
mat = [0]*n
vec = [0] * m
for i in range(n):
    mat[i] = list(map(int,input().split()))
for j in range(m):
    vec[j] = int(input())

for i in range(n):
    r = 0
    for k,l in zip(mat[i],vec):
        r += k*l
    print(r)



Measured memory_bytes: 6016
/* include */
#include"bits/stdc++.h"
/* namespace */
using namespace std;

/* typedef */
/* long系 */
typedef long long ll;	// long long
typedef long double ld;	// long double
/* vector系 */
typedef vector<int> vint;	// intのvector
typedef vector<double> vdouble;	// doubleのvector
typedef vector<ll> vll;	// llのvector
typedef vector<ld> vld;	// ldのvector
typedef vector<pair<int, int>> vi_i;	// i_iのvector
typedef vector<pair<double, double>> vd_d;	// d_dのvector
typedef vector<pair<ll, ll>> vl_l;	// l_lのvector
typedef vector<pair<ld, ld>> vld_ld;	// ld_ldのvector
typedef vector<string> vstring;	// stringのvector
/* pair系 */
typedef pair<int, int> i_i;	// int同士のpair
typedef pair<double, double> d_d;	// double同士のpair
typedef pair<ll, ll> l_l;	// ll同士のpair
typedef pair<ld, ld> ld_ld;	// ld同士のpair

/* define */
#define pb push_back	// push_back
#define all(v) v.begin(),v.end()	// コンテナ全体
#define PI (acos(-1))  // 円周率pi

/* 変数入出力 read, write */
template <typename T>	// 1変数
void read(T& x) {
	cin >> x;
}
template <typename T, typename T0>	// 2変数
void read(T& x, T0& y) {
	cin >> x >> y;
}
template <typename T, typename T0, typename T1>	// 3変数
void read(T& x, T0& y, T1& z) {
	cin >> x >> y >> z;
}
template <typename T, typename T0, typename T1, typename T2>	// 4変数
void read(T& x, T0& y, T1& z, T2& w) {
	cin >> x >> y >> z >> w;
}
template <typename T>	// 1変数
void write(T& x) {
	cout << x << endl;
}
template <typename T, typename T0>	// 2変数
void write(T& x, T0& y) {
	cout << x << " " << y << endl;
}
template <typename T, typename T0, typename T1>	// 3変数
void write(T& x, T0& y, T1& z) {
	cout << x << " " << y << " " << z << endl;
}
template <typename T, typename T0, typename T1, typename T2>	// 4変数
void write(T& x, T0& y, T1& z, T2& w) {
	cout << x << " " << y << " " << z << " " << w << endl;
}
// vectorの出力
template <typename T>
void printvec(const vector<T> &data) {
    		    for (const auto elm : data) {
      		    	cout << elm << " ";
    		    }
    		    cout << endl;
}


int main(int argc, char const *argv[]) {
    ll n; read(n);
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) ans += i;
    }
    write(ans);

    return 0;
}


Measured memory_bytes: 3636
<?php
fscanf(STDIN, "%d", $n);
$d = explode(" ", trim(fgets(STDIN)));
$sum = 0;
for ($i = 0; $i < $n; $i++) for ($j = $i + 1; $j < $n; $j++) $sum += $d[$i] * $d[$j];
echo $sum;
?>

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

int main()
{
    string s,r;
    int n,m,x,y,sum;
    cin>>n;
    cin>>s;
    if(n%2) cout<<"No"<<endl;
    else{
        string a,b;
        x=n/2;
        y=x;
        for(int i=0;i<x;i++)
            a+=s[i],b+=s[y++];
        if(a==b)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
  ll N;
  cin>>N;
  vector<ll> J(4, 0);
  rep(i, N){
    string S;
    cin>>S;
    if(S=="AC")J[0]++;
    if(S=="WA")J[1]++;
    if(S=="TLE")J[2]++;
    if(S=="RE")J[3]++;
  }
  cout<<"AC x "<<J[0]<<endl;
  cout<<"WA x "<<J[1]<<endl;
  cout<<"TLE x "<<J[2]<<endl;
  cout<<"RE x "<<J[3]<<endl;

  
} 

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
using vl= vector<ll>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(void){
  ll n,k,ans;
  cin>>n>>k;
  ans= min(n%k, k-(n%k));
  cout << ans;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
	
}

int main()
{
	int a,b,c,ans=0;
	string S,T;
	cin>>a>>S;
	for(int i=0;i<a-2;i++){
		if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C')ans++;
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long  
#define mod 1000000007
#define endl "\n"
#define VI vector<int>
#define fo(i,a,b) for(int i=a;i<b;i++)
#define fb(i,a,b) for(int i=a ;i>=b;i--)
#define pb push_back
#define ff first
#define ss second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 

using namespace std;
 int32_t main(){
 #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fastio;
int n;
cin>>n;
cout<<(n/1000+(n%1000!=0))*1000-n<<"\n";

 return 0;
 }

Measured memory_bytes: 3624
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iostream>

using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(b*2>=a){
        cout << 0;
    }
    else{
        cout << a-(b*2);
    }
    
}




Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;

int main()
{
    double RR;
    cin >> RR;
    
    cout << RR*2.*3.141592653589;
    return 0;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >>b;
  
  for ( int i = 0 ; i < b+2 ; i++ ) {
    cout << "#";
  }
   cout << endl;
  
  for ( int i = 0 ; i < a ; i++ ) {
    vector<char> vec(b);
    for ( int j = 0 ; j < b ; j++ ) {
      cin >> vec.at(j);
    }
    
    cout << "#" ;
    for ( int k = 0 ; k < b ; k++ ) {
      cout << vec.at(k);
    }
    
    cout << "#" << endl;
  }
  
  for ( int i = 0 ; i < b+2 ; i++ ) {
    cout << "#";
  }
} 

Measured memory_bytes: 256
N, M = map(int, input().split())
prime = [True] * 35001
prime[0] = prime[1] = False
primes = []
for i in range(2, 35001):
  if prime[i]:
    prime[i*2::i] = [False] * ((35000 - i) // i)
    primes.append(i)

mod = 10 ** 9 + 7
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]

for i in range(2, N+1000):
  g1.append((g1[-1] * i) % mod)
  inv.append((-inv[mod % i] * (mod//i)) % mod)
  g2.append((g2[-1] * inv[-1]) % mod)

def cmb(n, r):
  if r < 0 or r > n:
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r]

numFactors = [0] * len(primes)
while True:
  for i, p in enumerate(primes):
    if M % p == 0:
      numFactors[i] += 1
      M //= p
      break
  else:
    if M > 1:
      # prime
      numFactors.append(1)
    break

ans = 1
for nf in numFactors:
  if nf == 0:
    continue
  ans *= cmb(N+nf-1, nf)
  ans %= mod
print(ans)

Measured memory_bytes: 15752
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;


signed main(){
	int N;
	cin >> N;
	N %= 10;
	vector<int>a = {2,4,5,7,9};
	vector<int>b = {0,1,6,8};
	vector<int>c = {3};
	for(auto e:a){
		if(e == N){
			out("hon");
			return 0;
		}
	}
	for(auto e:b){
		if(e == N){
			out("pon");
			return 0;
		}
	}
	out("bon");
}

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

int main() {
  char c;
  cin >> c;

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

}


Measured memory_bytes: 256
#include <cstdlib>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;

int main(){
    int a;
    cin >> a;
    bool flag = false;
    do {
        string num = to_string(a);
        flag = true;
        string tmp = num.substr(0,1);
        for(int i = 1; i < num.size(); i++){
            if(tmp != num.substr(i,1)){
                flag = false;
                a++;
                break;
            }
        }
    } while(!flag);

    cout << a;
    return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : abc113c.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

int main() {
	int N;
	int M;
	cin >> N >> M;
	vector<pair<long long, int>> city;
	map<long long, int> city_born_array;
	vector<pair<long long, int>> city_born_ac;
	for(int i = 0; i < M; ++i){
		long long y;int p;
		cin >> p >> y;

		city.push_back(make_pair(y, p));
		city_born_ac.push_back(make_pair(y, p));
	}

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


	for(int i = 0; i < M; ++i){
		static map<int, int> mp;
		int p = city_born_ac[i].second;
		long long y = city_born_ac[i].first;
		city_born_array[y] = mp[p] + 1;
		++mp[p];
	}




	for(int i = 0; i < M; ++i){
		printf("%06d%06d\n", city[i].second, city_born_array[city[i].first]);
	}
	return 0;
}


Measured memory_bytes: 16484
s = input()
if "N" in s:
  if "S" not in s :
    print("No")
    exit()
if "E" in s:
  if "W" not in s:
    print("No")
    exit()
if "S" in s:
  if "N" not in s :
    print("No")
    exit()
if "W" in s:
  if "E" not in s:
    print("No")
    exit()
print("Yes")

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

int main(){
    int t=1;
   // cin>>t;
    while(t--){
        int n,p;
        cin>>n>>p;
        cout<<(n*(n-1))/2+(p*(p-1))/2<<endl;
        
        
        
    }
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())
attack_num_t = 0
attack_num_a = 0

if a % d == 0:
    attack_num_a = a // d
else:
    attack_num_a = a // d + 1

if c % b == 0:
    attack_num_t = c // b
else:
    attack_num_t = c // b + 1

if attack_num_t <= attack_num_a:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 9176
from itertools import accumulate
from math import sqrt, ceil
from bisect import bisect_left

N = int(input())
n = list(accumulate(range(ceil(sqrt(2 * N)) + 1)))

r = bisect_left(n, N)
answer = list(map(str, range(1, r + 1)))

if n[r] != N:
    d = n[r] - N
    answer.remove(str(d))

print('\n'.join(answer))

Measured memory_bytes: 3572
import sys
#import numpy as np
from collections import deque
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()

"""
    全く分からなかったので解説放送の写し。
        ・マス目に対してもBFSはできるのか！
        ・(NEW!)座標圧縮という技を使って計算量を削減できるのか
    あと壁に厚みを持たせて黒マスとして扱えばBFSがしやすくなる
"""

def main():
    N, M = map(int, input().split())
    X = set([])
    Y = set([])
    mapX = {}  # mapX[x] = (柵の座標xが小さい方から何番目か)
    mapY = {}  # mapX[y] = (柵の座標yが小さい方から何番目か)
    horizontal = []
    vertical = []
    for _ in range(N):
        a, b, c = map(int, input().split())
        X.add(a)
        X.add(b)
        Y.add(c)
        vertical.append((a, b, c))
    for _ in range(M):
        d, e, f = map(int, input().split())
        X.add(d)
        Y.add(e)
        Y.add(f)
        horizontal.append((d, e, f))
    X = list(X)
    Y =list(Y)
    X.sort()
    Y.sort()

    # 座標圧縮とはすなわち左（下）から何番目かを求めることに他ならない
    for i, x in enumerate(X):
        mapX[x] = i
    for i, y in enumerate(Y):
        mapY[y] = i

    # 圧縮後の座標平面に対してグリッドを張るので、そのサイズを求めておく
    # 柵は偶数マス目に乗るようにするので２倍しておく
    h = len(mapX) * 2
    w = len(mapY) * 2
    #print("grid size: (h,w)=({},{})".format(h, w))

    # グリッド作成、柵部分は-1の値を入れたブロックとして扱う
    # また偶数グリッドは面積0として扱う
    grid = [[0] * w for _ in range(h)]
    for i in range(N):
        a = mapX[vertical[i][0]] * 2
        b = mapX[vertical[i][1]] * 2
        c = mapY[vertical[i][2]] * 2
        for x in range(a, b + 1): grid[x][c] = -1
    for j in range(M):
        d = mapX[horizontal[j][0]] * 2
        e = mapY[horizontal[j][1]] * 2
        f = mapY[horizontal[j][2]] * 2
        for y in range(e, f + 1): grid[d][y] = -1
    
    # BFSをする前に、スタート地点が柵単位で数えたためにもはや(0, 0)ではなくなっているため、
    # まずは開始位置を二分探索で求めておく
    start_x = bisect_left(X, 0) * 2 - 1
    start_y = bisect_left(Y, 0) * 2 - 1
    if start_x < 0 or start_y < 0 or start_x >= h - 1 or start_y >= w - 1:
        print("INF")
        return
    grid[start_x][start_y] = 1
    #print("start=({}, {})".format(start_x, start_y))
    #print(np.array(grid))

    # BFS
    dx = [-1, 0, 1, 0]
    dy = [0, -1, 0, 1]
    ans = 0
    q = deque([(start_x, start_y)])
    grid[start_x][start_y] = 1
    while q:
        x, y = q.popleft()
        #print("({}, {})".format(x, y))
        ans += (X[x // 2 + 1] - X[x // 2]) * (Y[y // 2 + 1] - Y[y // 2])
        for i in range(4):
            nx, ny = x + dx[i], y + dy[i]
            if (nx == h - 2 and grid[nx][ny] == 0) or ny == w:
                print("INF")
                return
            if grid[nx][ny] != 0: continue
            nnx, nny = nx + dx[i], ny + dy[i]
            if nnx < 0 or nny < 0 or nnx == h - 1 or nny == w - 1:
                print("INF")
                return
            if grid[nnx][nny] != 0: continue  # 既に訪れたか、柵に乗ったら無視
            grid[nnx][nny] = 1
            q.append((nnx, nny))
        #print(q)
        #print(np.array(grid))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 430904
import sys

N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]

mod = sum(XY[0]) % 2
if any(mod != ((x+y)%2) for x, y in XY):
    print(-1)
    sys.exit()

m = 33 - mod
print(m)
D = [2 ** i for i in range(31, -1, -1)]
if mod == 0:
    D.append(1)

print(' '.join(map(str, D)))
for x, y in XY:
    w = ''
    for d in D:
        if 0 <= x - y and 0 <= x + y:
            w += 'R'
            x -= d
        elif 0 > x - y and 0 <= x + y:
            w += 'U'
            y -= d
        elif 0 <= x - y and 0 > x + y:
            w += 'D'
            y += d
        else:
            w += 'L'
            x += d
    print(w)

Measured memory_bytes: 3188
import collections
N, C = map(int, input().split())
stc = [list(map(int, input().split())) for i in range(N)]

stc.sort(key=lambda x: x[0])
table = collections.defaultdict(list)
for s, t, c in stc:
    table[c].append((s, t))
maxtime = 0
for x in table:
    for i in range(len(table[x]) - 1):
        if table[x][i][1] == table[x][i+1][0]:
            table[x][i+1] = (table[x][i][0], table[x][i+1][1])
            table[x][i] = (-1, -1)
    maxtime = max(maxtime, table[x][-1][1])

im = [0]*(maxtime+2)

for x in table:

    for s, t in table[x]:
        if s == -1:
            continue
        im[s] += 1
        im[t+1] -= 1

s = [0]*(maxtime+3)
for i in range(1, maxtime+2):
    s[i+1] = s[i]+im[i]

print(max(s))


Measured memory_bytes: 36792
#include<bits/stdc++.h>
using namespace std;
int n,s=0,t;
long long ans=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		s=floor(log10(i))+1;
		if(s%2==1)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var H = readLine()!!.toLong()

    var counter = 0
    while (H > 0) {
        H /= 2
        counter++
    }


    var ans = 1L
    var base = 2L
    repeat(counter - 1) {
        ans += base
        base *= 2
    }
    println(ans)

}



Measured memory_bytes: 31868
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
struct pairhash {
    size_t operator()(const pair<int, int>& p) const {
        return hash<int>()(p.first) ^ hash<int>()(p.second);
    }
};
int main()
{
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N, M, K = 1; cin >> N >> M;
    unordered_map<pair<int, int>, int, pairhash> mapping;
    mapping.reserve(1e6);
    int id = 0;
    auto node2id = [&](int i, int c) {
        auto it = mapping.find({i, c});
        if (it != end(mapping)) return it->second;
        mapping[{i, c}] = ++id;
        return id;
    };
    vector<vector<pair<int, int>>> G(1e6);
    vector<set<int>> C(N);
    for (int i = 0; i < M; i++) {
        int a, b, c; cin >> a >> b >> c; a--, b--;
        G[node2id(a, c)].emplace_back(node2id(b, c), 0);
        G[node2id(b, c)].emplace_back(node2id(a, c), 0);
        C[a].insert(c);
        C[b].insert(c);
    }
    for (int a = 0; a < N; a++) {
        for (int c : C[a]) {
            G[node2id(a, -1)].emplace_back(node2id(a, c), 1);
            G[node2id(a, c)].emplace_back(node2id(a, -1), 0);
        }
    }
    int s = node2id(0, -1);
    int e = node2id(N-1, -1);
    deque<pair<int, int>> D;
    D.emplace_back(s, 0);
    vector<bool> visited(1e6);
    while (!D.empty()) {
        int node, cost; tie(node, cost) = D.front();
        D.pop_front();
        if (visited[node]) continue;
        visited[node] = true;
        if (node == e) {
            cout << cost * K << '\n';
            return 0;
        }
        for (auto& p : G[node]) {
            int next, c; tie(next, c) = p;
            if (c == 0) {
                D.emplace_front(next, cost + 0);
            } else {
                D.emplace_back(next, cost + 1);
            }
        }
    }
    cout << -1 << '\n';
    return 0;
}


Measured memory_bytes: 98176
h, w, a, b = map(int, input().split())
ans = []
for _ in range(h):
    ans.append([0 for __ in range(w)])
for i in range(b):
    for j in range(w):
        ans[i][j] = (ans[i][j]+1)%2
for i in range(a):
    for j in range(h):
        ans[j][i] = (ans[j][i]+1)%2
for i in range(h):
    for j in range(w):
        if j != w-1:
            print(ans[i][j], end="")
        else:
            print(ans[i][j])

Measured memory_bytes: 120668
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

int main() {
    fastio();

    int a, b;
    cin >> a >> b;

    cout << 6 - a - b << endl;

    return 0;
}

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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if(A+B>C+D){
    cout<<"Left"<<endl;
  }
  if(A+B<C+D){
    cout<<"Right"<<endl;
  }
  if(A+B==C+D){
    cout<<"Balanced"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
 
int main(){
  string str;
  long long k;
  cin >> str;
  cin >> k;
  long long tmp=k;
  long long idx=0;
  string ret="";
  while(tmp>0){
    long long dis='z' - str[idx]+1;
    if( str[idx] != 'a' && dis <= tmp){
      tmp -= dis;
      ret += "a";
    }
    else{
      ret += str[idx];
    }
    idx++;
    if(idx == str.size()){
      break;
    }
  }
  for(;idx<str.size();idx++)
    ret += str[idx];
  idx = str.size();
  ret[idx-1] = ret[idx-1] + tmp%26;
  cout << ret <<endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(10);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair< ll,pair<ll , ll> >; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
////////////////

// c++17での名前衝突を避けるためdefine
#define gcd nyagcd
#define lcm nyalcm
ll nyagcd(ll x, ll y){
  ll z;
  if(x > y) swap(x,y);
  while(x){
    x = y % (z = x); y = z;
  }    
  return y;
}
ll nyalcm(ll x,ll y){
  return 1LL * x / gcd(x,y) * y;
}

void solve(){
  ini(M,N);
  out(6 - M - N);


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>


using namespace std;
typedef long long ll;
ll N;
//余りはA *B まででループする.
int main(){

    ll A, B, C;
    cin >> A >> B >> C;

    for(ll i = 1; i <= B; i++){
        //cout << A * i % B  << endl;
        if(A * i % B == C){
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << endl;
    return 0;

}

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

Int isprime(Int x){
  if(x<=1) return 0;
  for(Int i=2;i*i<=x;i++)
    if(x%i==0) return 0;
  return 1;
}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> v;
  for(Int i=2;i<55555;i++)
    if(isprime(i)&&i%5==3) v.emplace_back(i);
  
  vector<Int> p(5e5,0);
  for(Int i=2;i<5e5;i++)
    p[i]=isprime(i);

  while(1){
    random_shuffle(v.begin(),v.end());
    bool flg=0;
    for(Int i=0;i<n;i++)
      for(Int j=0;j<i;j++)
	for(Int k=0;k<j;k++)
	  for(Int s=0;s<k;s++)
	    for(Int t=0;t<s;t++)
	      flg|=p[v[i]+v[j]+v[k]+v[s]+v[t]];
    //cout<<flg<<endl;
    if(flg) continue;
    for(Int i=0;i<n;i++){
      if(i) cout<<" ";
      cout<<v[i];
    }
    cout<<endl;
    return 0;
  }
  
  return 0;
}


Measured memory_bytes: 4224