akhauriyash/Code-Regression huggingface dataset:
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        PriorityQueue<Integer> l = new PriorityQueue<>(Comparator.reverseOrder());
        PriorityQueue<Integer> r = new PriorityQueue<>();
        for (int i = 0; i < m; i++) {
            l.add(Integer.parseInt(sc.next()));
            r.add(Integer.parseInt(sc.next()));
        }

        int result = r.peek() - l.peek() + 1;

        System.out.println(result < 0 ? 0 : result);
    }
}

Measured memory_bytes: 63892
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)

int main(){
    int n, t;
    cin >> n >> t;
    vector<int> A(n);
    REP(i, n) cin >> A[i];

    int min_A = 1e9, diff = -1e9, cnt = 1;
    REP(i, n){
        min_A = min(min_A, A[i]);
        if(diff == A[i] - min_A){
            cnt++;
        }else if(diff < A[i] - min_A){
            diff = A[i] - min_A;
            cnt = 1;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 640
# 3:53-
n, s = gets.to_s.split.map{|t| t.to_i }
a    = gets.to_s.split.map{|t| t.to_i }

dp = [0] * (s+1)
dp[0] = 1

# {1} 1: 1
# {1, 2}, {1}, {2}, 1: 2, 2: 1, 3: 1
# {1, 2, 3}, {1, 2}, {2, 3}, {1, 3}, {1}, {2}, {3} 1: 3, 2: 4, 3: 4, 4: 2, 5: 2, 6: 1
a.each do |t|
  
  s.downto(0) do |j|
    dp[j] *= 2 
    dp[j] += dp[j-t] if j - t >= 0
    dp[j] %= 998244353
  end
end

puts dp[s]


Measured memory_bytes: 14440
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int N, K;
    cin >> N >> K;
    int denko = 1;
    REP(i, N) denko = min(denko*2, denko+K);
    cout << denko << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
using namespace std;
 
#define PI 3.14159265358979323846264338327950L
 
int main() {
	long long A, B, N;
	cin >> A >> B >> N;

	long long x;
	if (B - 1 <= N) {
		x = B - 1;
	} else {
		x = N;
	}
	long long max = (A * x) / B - A * (x / B);
	cout << max << endl;
}

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

int main(){
  ll N;
  cin>>N;
  for(ll h=1;h<=3500;h++){
    for(ll n=1;n<=3500;n++){
      if(4*h*n-N*n-N*h>0){
        if((N*h*n)%(4*h*n-N*n-N*h)==0){
          cout<<h<<" "<<n<<" "<<(N*h*n)/(4*h*n-N*n-N*h)<<endl;
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(n):
    if (a[i] % 2 == 0):
        if (a[i] % 3 != 0 and a[i] % 5 != 0):
            ans += 1
            break
if (ans == 0):
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
using namespace std;

int Zi[90001];
int Zj[90001];

int X[90001] = {};
int D;

int main() {
    int H, W;
    cin >> H >> W >> D;

    int x;

    for (int i=1; i<=H; i++) {
        for (int j=1; j<=W; j++) {
            cin >> x;
            Zi[x] = i;
            Zj[x] = j;
        }
    }

    for (int a=1; a<=H*W; a++) {
        if (a-D <= 0) continue;
        X[a] = X[a-D] + abs(Zi[a-D] - Zi[a]) + abs(Zj[a-D] - Zj[a]);
    }

    int Q, L, R;
    cin >> Q;

    for (int q=0; q<Q; q++) {
        cin >> L >> R;
        int result = X[R] - X[L];
        cout << result << endl;
    }

}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printaa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ for(int j = 0; j < (sizeof(x[0])/sizeof(x[0][0])); j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
#define mp make_pair
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;
const ll INF15 = (ll)1e15;

using namespace std;
const int N = 100010;
ll dist[N]; //distance from start point
ll dist_tmp[N];
vector< pair<ll, int> > g[N];
vector< pair<ll, int> > G[N];

void dijkstra(int start){
    set<pair<ll, int> > setik;
    rep(i,0,N){
        dist[i] = INF15;
        if (i == start) dist[i] = 0; //start point
        setik.insert(mp(dist[i], i));
    }

    while(!setik.empty()) {
        start = setik.begin()->second;
        setik.erase(setik.begin());
        for(pair<ll, int> e : g[start]){
            int t = e.second;
            ll w = dist[start] + e.first;
            if(w >= dist[t]) continue;

            setik.erase(mp(dist[t], t));
            dist[t] = w;
            setik.insert(mp(dist[t], t));
        }


    }



    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,s,t;
    cin >> n >> m >> s >> t;
    s--; t--;
    int u[N], v[N];
    ll a[N], b[N];
    rep(i,0,m){
        cin >> u[i] >> v[i] >> a[i] >> b[i];
    }
    rep(i,0,m){
        u[i]--; v[i]--;
        g[v[i]].push_back(mp(a[i], u[i]));
        G[v[i]].push_back(mp(b[i], u[i]));

        g[u[i]].push_back(mp(a[i], v[i]));
        G[u[i]].push_back(mp(b[i], v[i]));
    }
    dijkstra(s);

    swap(dist, dist_tmp);
    swap(g,G);
    dijkstra(t);
    ll ans[N];
    rep(i,0,n){
        ans[i] = dist_tmp[i] + dist[i];
    }
    for(int i = n-2; i >= 0; i--){
        ans[i] = min(ans[i], ans[i+1]);
    }
    rep(i,0,n){
        ll aa = INF15 - ans[i];
        print(aa);
    }



}


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

namespace ABC138C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] vinput = Console.ReadLine().Split(' ');
            int[] v = new int[N];
            for(int i = 0; i < N; i++)
            {
                v[i] = int.Parse(vinput[i]);
            }
            Array.Sort(v);
            decimal ans = v[0];
            for(int i = 1; i < N; i++)
            {
                ans += v[i];
                ans /= 2;
            }
            Console.WriteLine(ans);
        }
    }
}


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/d.in", "r", stdin);
//  freopen("../IO/d.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

char s[200000 + 25];
void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n >> (s + 1);
  vector<int> p1(n+2, 0), p2(n+2, 0);
  for (int i = 1; i <= n; ++i) {
    p1[i] += s[i] == 'W';
    p2[i] += s[i] == 'R';
    p1[i] += p1[i - 1];
    p2[i] += p2[i - 1];
  }
  p1[n+1] = p1[n];
  p2[n+1] = p2[n];
  int ans = n;
  for (int i = 0; i <= n + 1; ++i) {
    int c1 = p1[i]; // белые на префиксе
    int c2 = p2[n] - p2[i]; // черные на суффиксе
    int cc = min(c1, c2);
    c1 -= cc;
    c2 -= cc;
    int ops = c1 + c2 + cc;
    ans = min(ans, ops);
  }
  out << ans;
}


Measured memory_bytes: 5048
import java.util.Scanner;
import java.util.PriorityQueue;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		Unionfind uf=new Unionfind(n);
		PriorityQueue<Long> q=new PriorityQueue<>();
		long[] a=new long[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextLong();
		}
		for(int i=0; i<m; i++){
			int x=sc.nextInt();
			int y=sc.nextInt();
			uf.unite(x,y);
		}
		long[] min=new long[n];
		int[] index=new int[n];
		Arrays.fill(min,1000000001);
		for(int i=0; i<n; i++){
			int root=uf.root(i);
			if(min[root]>a[i]){
				min[root]=a[i];
				index[root]=i+1;
			}
		}
		boolean[] o=new boolean[n];
		for(int i=0; i<n; i++){
			if(index[i]!=0){
				o[index[i]-1]=true;
			}
		}
		long ans=0;
		int count=0;
		for(int i=0; i<n; i++){
			if(min[i]!=1000000001){
				count++;
				ans+=min[i];
			}
			if(!o[i]){
				q.add(a[i]);
			}
		}
		if(count==1){
			System.out.println(0);
			return;
		}else if(count+count-2>n){
			System.out.println("Impossible");
			return;
		}
		for(int i=0; i<count-2; i++){
			ans+=q.poll();
		}
		System.out.println(ans);
	}
	static class Unionfind{
		int[] parent;
		public Unionfind(int n){
			this.parent=new int[n];
			for(int i = 0; i<n; i++){
				parent[i]=i;
			}
		}
		public int root(int t){
			if(parent[t]==t){
				return t;
			}else{
				return parent[t]=root(parent[t]);
			}
		}
		public void unite(int x,int y){
			if(same(x,y)){
				return;
			}
			int xroot = root(x);
			int yroot = root(y);
			parent[yroot]=xroot;
		}
		public boolean same(int x,int y){
			return root(x)==root(y);
		}
	}
}


Measured memory_bytes: 93432
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v(1,1);
  for (ll i = 2; n >= i * i; ++i) {
		if(!(n % i)){
      v.pb(i);
	  }
  }
  if(v.size()==1)v.pb(n);
  return v;
}



int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n;cin>>n;
  vector<int> x(n),y(n),h(n);rep(i,n)cin>>x[i]>>y[i]>>h[i];
  int zero = 0;
  rep(i,n)zero += h[i] == 0;
  if(zero == n-1){
    rep(i,n){
      if(h[i]){
        cout<<x[i]<<' '<<y[i]<<' '<<h[i]<<endl;
        return 0;
      }
    }
  }
  rep(cx,101){
    rep(cy,101){
      ll H;
      rep(i,n)if(h[i] != 0)H = h[i]+abs(x[i]-cx)+abs(y[i]-cy);
      bool ok = true;
      rep(i,n){
        if(h[i] == 0)continue;
        if(h[i]+abs(x[i]-cx)+abs(y[i]-cy) != H){
          ok = false;
          break;
        }
      }
      if(ok){
        cout<<cx<<' '<<cy<<' '<<H<<endl;
        return 0;
      }
    }
  }
  return 0;
} 

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

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

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

int main(void){

    string s;
    cin >> s;

    ll ans = 0;

    int cur = 0;
    int count = 0;
    for(int i = 0;s[i] != '\0';i++){
        if(s[i] == 'W'){
            ans += count;
        }else{
            count++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
N, M = map(int, input().split())
from collections import defaultdict

counter = 0

g = defaultdict(list)
for i in range(M):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

visited = []
def h(a):
    global counter
    visited.append(a)
    if len(visited) == N:
        counter += 1
        return
    for i in g[a]:
        if not i in visited:
            h(i)
            visited.remove(i)
h(1)
print(counter)

Measured memory_bytes: 3316
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto s = RD!string;

	writeln(s[0] ~ to!string(s.length-2) ~ s[$-1]);
	stdout.flush();
	debug readln();
}

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

int main() {
  int K;
  
  cin >> K;
  
  int amari = 7 % K;
  
  rep(i, K){
     if(amari == 0){
       cout << i + 1 << endl;
       return 0;
     }
    
    amari = (amari * 10 + 7) % K;
  }
  
  cout << -1 << endl;

}


Measured memory_bytes: 3536
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define prev __
using namespace std;

const int maxn = 100;

int n;
vector<int> g[maxn];
int prev[maxn];

int Find(int u) {
  memset(prev, -1, sizeof prev);
  queue<int> q;
  q.push(u);
  prev[u] = u;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int v : g[u]) {
      if (prev[v] == -1) {
        prev[v] = u;
        q.push(v);
      }
    }
  }
  return u;
}

int d[maxn];

void Dfs(int u, int p, int dep = 0) {
  int cnt = 0;
  for (int v : g[u]) {
    if (v == p) continue;
    Dfs(v, u, dep + 1);
    ++cnt;
  }
  d[dep] = max(d[dep], cnt);
}

int st[maxn], top;

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int u = Find(0);
  int v = Find(u);
  for (int k = v; k != u; k = prev[k]) {
    st[top++] = k;
  }
  st[top++] = u;
  if (top & 1) {
    int c = st[top >> 1], h = top >> 1;
    long long ans = 1;
    Dfs(c, -1);
    for (int i = 0; i < h; ++i) {
      ans *= d[i];
    }
    for (int c2 : g[c]) {
      memset(d, 0, sizeof d);
      Dfs(c, c2);
      Dfs(c2, c);
      long long res = 2;
      for (int i = 0; i < h; ++i) {
        res *= d[i];
      }
      ans = min(ans, res);
    }
    printf("%d %lld\n", h + 1, ans);
  } else {
    int c1 = st[(top >> 1) - 1], c2 = st[top >> 1], h = (top >> 1) - 1;
    long long ans = 2;
    Dfs(c1, c2);
    Dfs(c2, c1);
    for (int i = 0; i < h; ++i) {
      ans *= d[i];
    }
    printf("%d %lld\n", h + 1, ans);
  }
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct State{
    int at;
    ll cost;
    State(int a, ll c) : at(a), cost(c){}
    bool operator>(const State& s) const{
        return cost > s.cost;
    }
};

struct Edge{
    int to;
    ll cost;
    Edge(int t, ll c) : to(t), cost(c){}
};

using Graph = vector<vector<Edge> >;
const ll INF = 1e15;

void dijkstra(int s, const Graph& G, vector<ll>& minc){
    minc.assign(G.size(), INF);
    priority_queue<State, vector<State>, greater<State> > pq;
    pq.emplace(s, 0);
    minc[s] = 0;
    while(!pq.empty()){
        State cur = pq.top();
        pq.pop();
        if(minc[cur.at] < cur.cost) continue;
        for(const Edge& e : G[cur.at]){
            ll cost = cur.cost + e.cost;
            if(minc[e.to] <= cost) continue;
            minc[e.to] = cost;
            pq.emplace(e.to, cost);
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i,n-1){
        G[i+1].push_back(Edge(i, 0));
    }
    rep(i,m){
        int l, r, c;
        cin >> l >> r >> c;
        --l; --r;
        G[l].push_back(Edge(r, c));
    }
    vector<ll> dist;
    dijkstra(0, G, dist);
    if(dist[n-1] == INF) dist[n-1] = -1;
    cout << dist[n-1] << endl;
    return 0;
}


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

int main() {
    long long X, Y;
    cin >> X >> Y;
    long long ans = INT_MIN;
    for (long long i = X; i <= X; i++) {
        long long tmp = 1;
        for (long long j = X * 2; j <= Y; j *= 2) {
            tmp++;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
for c in input():
  if c<"c":
    if c<"b" and a+b:
      if a:a-=1
      else:b-=1
      print("Yes")
    elif b:
      b-=1
      print("Yes")
    else:
      print("No")
  else:print("No")      

Measured memory_bytes: 9140
#include <stdio.h>

int main()
{
    int time[5][3];
    int i,j,k,ans;
    j = 0;
    k = 0;
    ans = 0;
    for(i = 0;i <= 4;i++){
        scanf("%d",&time[i][0]);
        time[i][1] = (time[i][0] / 10 + 1) * 10;
        if(time[i][0]%10 == 0) time[i][1] -= 10;
        time[i][2] = time[i][1] - time[i][0];
        //printf("<%d %d %d>\n",time[i][0],time[i][1],time[i][2]);
        j = (j < time[i][2]) ? time[i][2] : j;
    }
    for(i=0;i<=4;i++){
        ans += time[i][1];
    }
    printf("%d",ans - j);
    return 0;
}


Measured memory_bytes: 128
# import sys
 
# N:県, M:市
N, M = list(map(int, input().split()))

A = {}
# {ken: [(city_no, city_year)],...}

res = [None] * M

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

for i in range(M):
  k, y = L[i]
  if k in A.keys():
    A[k].append((i, y))
  else:
    A[k] = [(i, y)]

# print(A)
# A: {県番号: {市1の年:市1のindex, 市2の年:市2のindex}}

for k, v in A.items():
  # sort by year
  c_list = sorted(v, key=lambda x: x[1])
  counter = 1
  for c in c_list:
    res[c[0]] = (k, counter)
    counter += 1

for x in res:
  print("{:0>6}{:0>6}".format(x[0], x[1]))


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

int main() {
  long long n;
  cin >> n;
  for(int i=0; i<= 50000; i++) {
    if(floor(i*1.08) == n) {cout << i << endl; return 0;}
  }
  cout << ":(" << endl;
}


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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  int cnt = 0;
  for(int i=0;i<n;i++) if(cnt+1==a[i]) cnt++;
  if(cnt==0) cout << -1 << endl;
  else cout << n-cnt << endl;
}

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

#define INF 12345678

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  int h,w;
  cin >> h >> w;
  int ch,cw,dh,dw;
  cin >> ch >> cw >> dh >> dw;
  ch--;
  cw--;
  dh--;
  dw--;
  vector<vector<char>> s(h,vector<char>(w));
  for (int i=0;i<h;i++) {
    for (int j=0;j<w;j++) {
      cin >> s[i][j];
    }
  }
  vector<vector<int>> mins(h,vector<int>(w,INF));
  mins[ch][cw] = 0;
  deque<pair<int,int>> deq;
  deq.push_front(make_pair(ch,cw));
  while (!deq.empty()) {
    pair<int,int> nowp = deq.front();
    deq.pop_front();
    int ni = nowp.first;
    int nj = nowp.second;
    for (int i=-2;i<=2;i++) {
      for (int j=-2;j<=2;j++) {
        int ci = ni+i;
        int cj = nj+j;
        if (ci < 0 || ci >= h || cj < 0 || cj >= w) {
          continue;
        }
        if (i == 0 && j == 0) continue;
        if (s[ci][cj] == '#') continue;
        if (abs(i)+abs(j) == 1) {
          if (mins[ci][cj] > mins[ni][nj]) {
            mins[ci][cj] = mins[ni][nj];
            deq.push_front(make_pair(ci,cj));
          }
        } else {
          if (mins[ci][cj] > mins[ni][nj]+1) {
            mins[ci][cj] = mins[ni][nj]+1;
            deq.push_back(make_pair(ci,cj));
          }
        }
      }
    }
  }
  if (mins[dh][dw] != INF) cout << mins[dh][dw] << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 8616
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define n_inf -(1 < <30);

vector<vector<long long int>> v_t;
vector<vector<long long int>> v_p;

long long int dfs(int depth,long long int kaitenlist[],int N){
    if(depth==10){
        int check=0;
        for(int i=0;i<10;i++){
            check += kaitenlist[i];
        }
        if(check==0) return -longinf;

        long long int res=0;
        for(int i=0;i<N;i++){
            check=0;
            for(int j=0;j<10;j++){
                check += kaitenlist[j]*v_t.at(i)[j];
            }
            res += v_p.at(i)[check];
        }
        return res;
    }
    kaitenlist[depth]=1;
    long long int ret1 = dfs(depth+1,kaitenlist,N); 
    kaitenlist[depth]=0;
    long long int ret2 = dfs(depth+1,kaitenlist,N); 

    return max(ret1,ret2);
}

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

    for(int i=0;i<n;i++){
        vector<long long int> v;
        for(int j=0;j<10;j++){
            int tmp;cin >> tmp;
            v.push_back(tmp);
        }
        v_t.push_back(v);
    }

    for(int i=0;i<n;i++){
        vector<long long int> v;
        for(int j=0;j<=10;j++){
            int tmp;cin >> tmp;
            v.push_back(tmp);
        }
        v_p.push_back(v);
    }
    long long int list[10]={};
    p(dfs(0,list,n))
} 

Measured memory_bytes: 384
#include<stdio.h>
int main(){
int n,m,dp[50001],a[21],i,j;
scanf("%d %d\n",&n,&m);
for(i=0;i<m;i++){
scanf("%d",&a[i]);
}
for(i=1;i<=n;i++){
dp[i]=50001;
}
for(i=0;i<m;i++){
for(j=a[i];j<=n;j++){
if(dp[j-a[i]]+1<dp[j]){
dp[j]=dp[j-a[i]]+1;
}
}
}
printf("%d\n",dp[n]);
return 0;
}


Measured memory_bytes: 2108
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

ifoldl' :: (b -> Int -> a -> b) -> b -> [a] -> b
ifoldl' !f !a !xs = foldl' (\(!acc) (!i, !x) -> f acc i x) a $ zip [0 ..] xs

solve :: Int -> Int -> Int -> Int -> VU.Vector Int -> Int
solve !n !a !b !c !vn = minimum
  $ map (\(!ga, !gb, !gc) -> cost a ga + cost b gb + cost c gc) groups
 where
  indices = replicateM n "abcd"
  groups =
    filter (\(!a, !b, !c) -> not (null a) && not (null b) && not (null c)) $ map
      (ifoldl'
        (\(!ga, !gb, !gc) (!i) (!ch) -> case ch of
          'a' -> (vn VU.! i : ga, gb, gc)
          'b' -> (ga, vn VU.! i : gb, gc)
          'c' -> (ga, gb, vn VU.! i : gc)
          'd' -> (ga, gb, gc)
        )
        ([], [], [])
      )
      indices

  cost k xs = countComposition (length xs) * 10 + abs (sum xs - k)

  countComposition n | n <= 1    = 0
                     | otherwise = n `div` 2 + countComposition (n - n `div` 2)

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, a, b, c) <-
    (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2, vec VU.! 3))
    .   VU.unfoldrN 4 readInt
    <$> B.getLine
  vn <-
    VU.replicateM n $ (\vec -> vec VU.! 0) . VU.unfoldrN 1 readInt <$> B.getLine

  print $ solve n a b c vn


Measured memory_bytes: 3836
x, y ,z, k = map(int,input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
 
A.sort(reverse = True)
B.sort(reverse = True)
C.sort(reverse = True)
 
now = [0, 0, 0]
que = [[A[0] + B[0] + C[0], 0, 0, 0]]
memory = [[0, 0, 0]]
ans = []
while len(ans) < k:
  maxli = max(que, key = lambda x:x[0])
  ans.append(maxli[0])
  now = maxli[1:]
  que.remove(maxli)
  n0 = min(now[0] + 1, x - 1)
  n1 = min(now[1] + 1, y - 1)
  n2 = min(now[2] + 1, z - 1)
  a = A[n0]
  b = B[n1]
  c = C[n2]
  if [n0, now[1], now[2]] not in memory:
    que.append([a + B[now[1]] + C[now[2]], n0, now[1], now[2]])
    memory.append([n0, now[1], now[2]])
  if [now[0], n1, now[2]] not in memory:
    que.append([A[now[0]] + b + C[now[2]], now[0], n1, now[2]])
    memory.append([now[0], n1, now[2]])
  if [now[0], now[1], n2] not in memory:
    que.append([A[now[0]] + B[now[1]] + c, now[0], now[1], n2])
    memory.append([now[0], now[1], n2])
  if que == []:
    break

print(*ans, sep = "\n")

Measured memory_bytes: 4852
import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int n=sc.nextInt();
		if(n==1){
			System.out.println("Hello World");
		}else{
			int a=sc.nextInt();
			int b=sc.nextInt();
			System.out.println(a+b);
		}

	}
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main() {
    fastIO;
    int n, d, rta = 0;
    cin >> n >> d;
    int a[n][d];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> a[i][j];
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            ll sum = 0, aux;
            for(int k = 0; k < d; k++){
                sum += (a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
            }
            aux = sqrt(sum);
            if(aux*aux == sum) rta++;
        }
    }
    cout << rta << endl;
    return 0;
}



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

const int N = 1010;
const double eps = 1e-12;
const double inf = 1e10;
typedef pair<double, int> di;

int n;
int x[N], y[N], r[N];
double d[N];
double f[N][N];

double dist(int i, int j) { return hypot(x[i] - x[j], y[i] - y[j]); }

void dijkstra() {
	for (int i = 1; i <= n; ++i) d[i] = inf;
	priority_queue < di, vector<di>, greater<di> > pq;
	pq.push(di(0, 0));
	while(!pq.empty()) {
		di t = pq.top(); pq.pop();
		int u = t.second; double du = t.first;
		if (!(abs(d[u] - du) <= eps)) continue;

		for (int v = 1; v <= n; ++v) if (u != v && d[v] > d[u] + f[u][v] + eps) {
			d[v] = d[u] + f[u][v];
			pq.push(di(d[v], v));
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> x[0] >> y[0] >> x[1] >> y[1];
	cin >> n; ++n;
	for (int i = 2; i <= n; ++i) {
		cin >> x[i] >> y[i] >> r[i];
	}
	for (int i = 0; i <= n; ++i) {
		for (int j = i + 1; j <= n; ++j) {
			f[i][j] = dist(i, j) - r[i] - r[j];
			if (f[i][j] < -eps) f[i][j] = 0.0;
			f[j][i] = f[i][j];
		}
	}

	dijkstra();

	cout << setprecision(12) << fixed << d[1] << endl;
}

Measured memory_bytes: 14064
while 1:
    deck = input()
    if deck == "-":
        break
    m = int(input())
    h = [0 for _ in range(m)]
    for i in range(m):
        h[i] = int(input())

    for i in range(m):
        deck_l = deck[:h[i]]
        deck_u = deck[h[i]:]
        deck = deck_u + deck_l

    print(deck)

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

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

	vector<int> vc;
	 long int sum = 0;
	int n,min,max,temp;

	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> temp;
		vc.push_back(temp);
		sum +=temp;
	}
	sort(vc.begin(), vc.end());
	int last = vc.back(); 
	cout << vc[0] << " "<< last <<" "<< sum <<"\n";

	return 0;

}

Measured memory_bytes: 1340
#include <iostream>
#include <string>

using namespace std;

int main() {
	string a,b,c,d;
	cin >> a;
	b = a.substr(0, 5);
	c = a.substr(6, 7);
	d = a.substr(14, 5);
	cout << b << " " << c << " " << d << endl;
	return 0;
}

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

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};


const int MOD = 1000000007;
using mint = Fp<MOD>;


int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}
int gyaku(int n){
    return modpow(n,MOD-2);
}

//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap
auto pfactor(int n){
  map<int,int> res;
  int t=sqrt(n);
  for(int i=2;i<=t;i++){
    for(;n%i==0;n/=i)res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
vector<int>kai(0);
void kaizyou(vector<int>&kai){
    rep(i,kai.size()){
        kai[i+1]=kai[i]*(i+1)%MOD;
      }
  }
int comb(int a,int b){
  return (kai[a]*gyaku(kai[a-b]))%MOD*gyaku(kai[b])%MOD;
}
////////////////////////////////////////////////////////////////////////
signed main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int r=0,w=0;
  rep(i,n){
    if(s[i]=='R')r++;
    else w++;
  }
  int ans=0;
  rep(i,r){
    if(s[i]!='R')ans++;
  }
  rep(i,w){
    if(s[i+r]!='W')ans++;
  }
  cout<<ans/2<<endl;
  }


Measured memory_bytes: 3748
#include <iostream>
using namespace std;
long long int A,B;
int main(){
    scanf("%d%d", &A, &B);
    if (A > B){
        int tmp = A;
        A = B;
        B = tmp;
    }

    long long int hcf;
    for (int i=1;i<=A;i++){
        if (A%i == 0 && B%i == 0){
            hcf = i;
        }
    }

    long long int ans;

    ans = (A * B) / hcf;

    printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;//qwq
string query(int x)
{
	cout<<x<<endl;
	fflush(stdout);
	string s; cin>>s;
	if(s=="Vacant") exit(0);
	return s;
}
int main()
{
	cin>>n;
	string a=query(0),b=query(n-1);
	int l=1,r=n-2;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		string k=query(mid);
		if(mid%2==0)
		{
			if(k==a) l=mid+1;
			else r=mid-1;
		}
		else
		{
			if(k==b) l=mid+1;
			else r=mid-1;
		}
	}
	return 0;
}

Measured memory_bytes: 852
#include <stdio.h>

int main()
{
	int i, N, u, w;
	long long ans = 0, tmp;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) ans += (long long)(N - i + 2) * (N - i + 1) / 2;
	for (i = 1; i <= N - 1; i++) {
		scanf("%d %d", &u, &w);
		if (u > w) {
			u ^= w;
			w ^= u;
			u ^= w;
		}
		ans -= (long long)u * (N - w + 1);
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

using ll=long long;
const ll MOD=1000000007;
typedef pair<ll,ll> P;

int main() {
  int n;
  cin >> n;
  vector<P> p(n);
  for(int i=0;i<n;i++){
    cin >> p[i].second >> p[i].first;
  }
  sort(p.begin(),p.end());
  ll sum=0;
  bool a=1;
  for(int i=0;i<n;i++){
    sum +=p[i].second;
    if(sum>p[i].first)
      a=0;
  }
  if(a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main(){
 int x,y;

 while (1){
  cin >> x >> y;
  if (x==0&&y==0) break;
  
  if (x>y) swap(x,y);
  
  cout << x << " " << y << endl;
  
 }
 return 0;
}

void swap(int x,int y){
 int n=x;
 x=y;
 y=n;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

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

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

const ll INF = 1LL << 60;

int N;

//DPテーブル
vector<ll> dp(100010);

int main() {
    ll x;
    cin >> x;
    ll cnt=0,money=100;
    while(x>money) {
        cnt++;
        money+=(money)/100;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3860
#include <set>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

int dp[4][4][101];

int main(){
  int n = getInt();
  int k = getInt();
  vector<int> d(n, -1);
  REP(i,k){
    int a = getInt();
    int b = getInt();
    d[a - 1] = b;
  }
  dp[0][0][0] = 1;

  REP(k,n) REP(i,4) REP(j,4) if(dp[i][j][k]){
    if(d[k] != -1){
      if(i != j || i != d[k])
        dp[j][d[k]][k + 1] = (dp[j][d[k]][k + 1] + dp[i][j][k]) % 10000;
    }else{
      REP(t,3) if(i != j || i != t + 1)
        dp[j][t + 1][k + 1] = (dp[j][t + 1][k + 1] + dp[i][j][k]) % 10000;
    }
  }

  int ans = 0;
  REP(i,3) REP(j,3) ans = (ans + dp[i+1][j+1][n]) % 10000;

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

  return 0;
}

Measured memory_bytes: 0
from math import gcd

A,B,C,D=map(int,input().split())

lcm = C*D//gcd(C,D)

def n_mul(c):
  if A%c==0 and B%c==0:return(B//c-A//c+1)
  elif A%c==0 and B%c!=0:return(B//c-A//c+1)
  elif A%c!=0 and B%c==0:return(B//c-A//c)
  else:return(B//c-A//c)

print(B-A+1-(n_mul(C)+n_mul(D)-n_mul(lcm)))

Measured memory_bytes: 9144
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		int[][] x = new int[n][n];
		boolean[][] y = new boolean[n][n];


		for(int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			for(int j = 0; j < a[i]; j++) {
				x[i][j] = scan.nextInt()-1;
				y[i][j] = (scan.nextInt() == 1);
			}
		}

		boolean[] yet = new boolean[n];		//既に言及されたかのフラグ
		boolean[] yesNo = new boolean[n];	//正直者かどうか．trueなら正直者
		boolean ctrd = false;					//矛盾が生じたらtrue

		int max = 0;					//正直者の最大人数


		for(int b = 1; b < 1<<n; b++) {
			yet = new boolean[n];
			yesNo = new boolean[n];
			ctrd = false;

			//正直者の数のカウントと正直者をyesNo=trueにする
			int cnt = 0;
			for(int i = 0; i < n; i++) {
				if(((b >> i) & 1) == 1) {
					cnt++;
					yesNo[i] = true;
				}
			}

			//各証言を確かめる
			for(int i = 0; i < n; i++) {
				if(yesNo[i]) {	//正直者の証言のみ確認
					for(int j = 0; j < a[i]; j++) {
						if(y[i][j] != yesNo[x[i][j]]) {
							ctrd = true;
						}
					}
				}
			}

			if (!ctrd){
				if(cnt > max) {
					max = cnt;
				}
			}

		}


		System.out.println(max);


	}

}


Measured memory_bytes: 24784
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int H, W, K; scanf("%d%d%d", &H, &W, &K);
    int sx, sy, gx, gy; scanf("%d%d%d%d", &sx, &sy, &gx, &gy);
    sx--, sy--, gx--, gy--;
    vector<string> board(H);
    for(int i=0; i<H; i++) cin >> board[i];

    vector< vector< vector< int > > > dist(
        H,
        vector< vector<int> >(
            W,
            vector<int>(4, INF)
            )
        );
                                                                            
    deque< tuple<int, int, int> > v0, v1;
    for(int k=0; k<4; k++) {
        dist[sx][sy][k] = 0;
        v0.emplace_back(sx, sy, k);
    }

    for(int iter=0; v0.size(); iter++) {
        while(v0.size()) {
            int x, y, d; tie(x, y, d) = v0.front(); v0.pop_front();
            int m = dist[x][y][d];
            if(m < 0) continue;
            dist[x][y][d] = -1;
            if(m + 1 <= K) {
                int nx = x + dx[d], ny = y + dy[d];
                if(nx < 0 or nx >= H or ny < 0 or ny >= W) continue;
                if(board[nx][ny] == '@') continue;
                if(dist[nx][ny][d] > m + 1) {
                    v0.emplace_back(nx, ny, d);
                    v1.emplace_back(nx, ny, d);
                    dist[nx][ny][d] = m + 1;
                }
            }
        }

        while(v1.size()) {
            int x, y, d; tie(x, y, d) = v1.back(); v1.pop_back();
            if(x == gx and y == gy) {
                printf("%d\n", iter + 1);
                return 0;
            }
            for(int k=0; k<4; k++) {
                if(dist[x][y][k] == 0) continue;
                dist[x][y][k] = 0;
                v0.emplace_back(x, y, k);
            }
        }
    }
    puts("-1");
    return 0;
}


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

int n, arr[100000];

int solve(int key) {
	arr[n]=key;
	int i=0;
	while(arr[i]!=key) i++;
	return i!=n;
}


int main() {
	int key ,q, count=0;
	cin >> n ;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	cin >> q;
	for (int j = 0; j < q; j++) {
			cin >> key;
			if(solve(key)) count++;
		}	
	
	cout << count << endl;
}


Measured memory_bytes: 3116
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int N, M;
bool connected[10+1][10+1];

int ccnt(int bit, int d) {
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if ((bit >> i & 1) && connected[d][i + 1]) {
            ++cnt;
        }
    }
    return cnt;
}

int main() {
    cin >> N >> M;
    for (int i = 1; i <= M; ++i) {
        int k; cin >> k;

        for (int j = 0; j < k; ++j) {
            int s; cin >> s;
            connected[i][s] = true;
        }
    }

    vector<int> P(M + 1);
    for (int i = 1; i <= M; ++i) {
        cin >> P[i];
    }

    int ans = 0;
    for (int i = 0; i < (1 << N); ++i) {
        bool suc = true;
        for (int j = 1; j <= M; ++j) {
            int cnt = ccnt(i, j);
            if (cnt % 2 != P[j]) {
                suc = false;
                break;
            }
        }

        if (suc) ++ans;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
A = []
for _ in range(3):
  A.append(list(map(int, input().split())))
n = int(input())
b = []
for _ in range(n):
  b.append(int(input()))

result = []
for i in b:
  for j in range(0, 3):
    for k in range(0, 3):
      if A[j][k] == i:
        A[j][k] = "z"

z = "z"
if A[0][0] == z and A[1][1] == z and A[2][2] == z:
  print("Yes")
  exit()
if A[0][2] == z and A[1][1] == z and A[2][0] == z:
  print("Yes")
  exit()

for i in range(0, 3):
  if A[0][i] == z and A[1][i] == z and A[2][i] == z:
    print("Yes")
    exit()
  if A[i][0] == z and A[i][1] == z and A[i][2] == z:
    print("Yes")
    exit()
  
print("No")
  

Measured memory_bytes: 62136
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int n;
    cin>>n;
    vector<int> as(n);
    cin>>as;

    ll ans = LINF;
    for (int i = -100; i <= 100; ++i) {
        ll acc = 0;
        rep(j, n) acc += (as[j] - i) * (as[j] - i);
        chmin(ans, acc);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())
if A>=B:
    if (A-V*T)<=(B-W*T):
        print("YES")
    else:
        print("NO")
else:
    if (A+V*T)>=(B+W*T):
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 61800
s = gets.chomp

def judge(s)
    s = s.chomp("dream")
    s = s.chomp("dreamer")
    s = s.chomp("erase")
    s = s.chomp("eraser")
    s
end

while true
    t = judge(s)
    if t == s
        puts "NO"
        break
    elsif t == ''
        puts "YES"
        break
    end
    s = t
end


Measured memory_bytes: 58104
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
int main() {
    string str;
    cin>>str;
    int len=str.size();

    int same=0,diff=0;
    for(int i=1;i<len;i++){
        if(str[i]==str[i-1])
            same++;
        else
            diff++;
    }

    if(same==len-1)
        printf("%d\n",0);
    else
        printf("%d\n",diff);

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> D(N);
    
  for(int i=0; i<N; i++){
   cin >> D.at(i) ; 
  }
  
    for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
        if((D.at(i) == D.at(j)) && (i!=j)){
         D.at(j) = 0; 
        }
      }
    }
  int ans=0 ;
  
  for(int i=0; i<N; i++){
   if(D.at(i) != 0){
     ans++ ;
   }
  }
    
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void solve(){
	ll n,k;
	cin>>n>>k;
	cout<<min(n-n/k*k,(n/k+1)*k-n);
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}






Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())

for c in range(max(X, Y)+1):
    if c < X:
        a = X - c
    else:
        a = 0

    if c < Y:
        b = Y - c
    else:
        b = 0

    if c == 0:
        min = a*A + b*B + c*C*2
    elif a*A + b*B + c*C*2 < min:
        min = a*A + b*B + c*C*2

print(min)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N,K,ans[MX];
priority_queue<pi> pq;
vi adj[MX];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    F0R(i,N-1) {
        int a,b; cin >> a >> b;
        adj[a].pb(b), adj[b].pb(a);
    }
    FOR(i,1,N+1) ans[i] = -MOD;
    cin >> K;
    F0R(i,K) {
        int x,y; cin >> x >> y;
        ans[x] = y;
        pq.push({y,x});
    }
    while (sz(pq)) {
        auto a = pq.top(); pq.pop();
        for (auto b: adj[a.s]) if (ans[b] == -MOD) {
            ans[b] = a.f-1;
            pq.push({ans[b],b});
        }
    }
    FOR(i,1,N+1) for (int j: adj[i]) if (abs(ans[i]-ans[j]) != 1) {
        cout << "No";
        exit(0);
    }
    cout << "Yes\n";
    FOR(i,1,N+1) cout << ans[i] << "\n";
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 7924
//
//  ABProblem.c
//  AOJ
//
//  Created by admin on 2014/07/12.
//
//

#include <stdio.h>

main(){
    
    int a,b;
    
    scanf("%d %d",&a,&b);
    
    printf("%d %d %.5lf\n",a/b,a%b,(double)a/b);
    return 0;
}

Measured memory_bytes: 636