akhauriyash/Code-Regression huggingface dataset:
N, Z, W = map(int, input().split())
a = list(map(int, input().split()))
if N == 1:
    print(abs(a[0] - W))
elif abs(a[-1] - W) > abs(a[-1] - a[-2]):
    print(abs(a[-1] - W))
else:
    print(abs(a[-1] - a[-2]))

Measured memory_bytes: 3188
N, M  = map(int,input().strip().split())
edges = [[x for x in  map(int,input().strip().split())] for i in range(M)]
import numpy as np
a = np.zeros([N+1,N+1],dtype = np.int32) # adjacency matrix
for e in edges:
    a[e[0],e[1]] = 1
a = a.T+a
def iter(visited_nodes):
    if len(visited_nodes) == N:
        return 1
    else:
        now = visited_nodes[-1] 
        return sum(iter(visited_nodes+[node]) for node, aij in enumerate(a[now]) if aij == 1 and not (node in visited_nodes))
print(iter([1]))



Measured memory_bytes: 21352
import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  val out:BufferedWriter =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0
  class Node(var key:Int, var left:Node = null, var right:Node = null) { }

  def insert(tree:Node, key:Node) = {
    val keyNode = key
    def getNodeToInsert(node:Node):Node =
      if(node.key > keyNode.key) {
        if(node.left == null) node
        else getNodeToInsert(node.left)
      } else {
        if(node.right == null) node
        else getNodeToInsert(node.right)
      }

    val target = getNodeToInsert(tree)

    if(keyNode.key < target.key) target.left = keyNode
    else target.right = keyNode
  }

  def inOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      inOrder(tree.left)
      out.write(" ")
      out.write(tree.key.toString)
      if(count<1000) count += 1
      else {
        out.flush
        count = 0
      }
      inOrder(tree.right)
    }

  def preOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      out.write(" ")
      out.write(tree.key.toString)
      if(count<1000) count += 1
      else {
        out.flush
        count = 0
      }
      preOrder(tree.left)
      preOrder(tree.right)
    }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = new Node(-1)

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" =>
          if(tree.key == -1) tree.key = s(1).toInt
          else insert(tree, new Node(s(1).toInt))
        case _ => {
          inOrder(tree)
          out.write("\n")
          out.flush()
          preOrder(tree)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

Measured memory_bytes: 301872
#include<cstdio>
using namespace std;
int main(){
	int A,B;
	scanf("%d %d",&A,&B);
	if(A==1) A=14;
	if(B==1) B=14;
	if(A==B) printf("Draw");
	else if(A>B) printf("Alice");
	else if(A<B) printf("Bob");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int X = sc.nextInt();
		for (int i = X - K + 1; i < X + K; i++) {
			System.out.print(i);
			if (i !=  X + K - 1) {
				System.out.print(" ");
			}
		}
	}
}




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


int main() {
  int H,W,K;
  cin >> H >> W >> K;
  vector<vector<char>> choco(H,vector<char>(W));
  rep(i,H)rep(j,W) cin >> choco[i][j];
  //入力
  
  int aaa=10000;
  rep(bit,1 << (H-1)){
    int g = 0;
    vector<int> id(H);
    rep(i,H){
      id[i]=g;
      if(bit >>i & 1) g++;
    }
    g++; //グループ数
    int ans = g-1;
    vector<vector<int>> c(g,vector<int>(W));
    rep(i,H)rep(j,W) c[id[i]][j] += (choco[i][j]-'0');
    
    //横の分け方がダメなときの判定
    bool a =false;
    rep(j,W)rep(i,g){
      if(c[i][j] > K){
        a =true; break;
      }
    }
    if(a) continue;
    
    vector<int> now(g);
    rep(j,W){
      rep(i,g) now[i] += c[i][j];
      rep(i,g){
      	if(now[i]>K){
        ans++;
        now =vector<int>(g);
        rep(i,g) now[i] += c[i][j];
      	}
      }
    }
    aaa = min(aaa,ans);
  }
  cout << aaa << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		String[] foo =new String[n];
		
		foo[0] = sc.nextLine();
		for(int i=0;i<n;i++) {
			foo[i] = sc.nextLine();
		}
		Arrays.sort(foo);
		for(int i=0;i<n;i++) {
			System.out.print(foo[i]);
		}
	}
}


Measured memory_bytes: 36240
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

template< typename T >
class BinaryIndexedTree{
  private:
    vector<T> data;
  public:
    BinaryIndexedTree(int n){
      data = vector<T>(++n,0);
    }

    T sum(int k){
      T ret = 0;
      for(++k; k>0; k-=k&-k) ret += data[k];
      return ret;
    }

    void add(int k, T x=1){
      for(++k; k<data.size(); k+= k&-k) data[k] += x;
    }
};

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  string S;cin >> S;
  vector<BinaryIndexedTree<int> > bits(26,BinaryIndexedTree<int>(N));
  rep(i,N){
    int x = S[i] - 'a';
    bits[x].add(i);
  }

  int Q;cin >> Q;
  while(Q--){
    int t;cin >> t;
    if(t==1){
      int i;char c;cin >> i >> c;
      --i;
      int x = S[i] - 'a';
      int y = c - 'a';
      S[i] = c;
      bits[x].add(i,-1);
      bits[y].add(i);
    }else{
      int l,r;cin >> l >> r;
      --l;
      --l;--r;
      int count = 0;
      rep(i,26){
        if(bits[i].sum(r) - bits[i].sum(l)>0) ++count;
      }
      cout << count << endl;
    }
  }
  return 0;
}


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


int main() {

	vector<int> vtimes;
	int time;
	int a;
	int sumtime = 0;
	int timemod;
	int min = 10;

	for (int i = 0; i < 5; i++) {
		cin >> time;
		timemod = time % 10;
		if (0 < timemod && timemod < min) {
			min = timemod;
		}
		if (timemod != 0) {
			sumtime = sumtime + time + 10 - timemod;
		}
		else {
			sumtime = sumtime + time;
		}
	}

	sumtime = sumtime - 10 + min;

	
	cout << sumtime << endl;


		
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include<queue>
#include<math.h>
#include <iomanip>
#define rep(i,n) for (int i=0; i<(n);++i)
using namespace std;
using ll=long long;
const ll INF = 1LL << 60;
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; }
const double PI = 3.14159265358979323846;




int main() {
	
	string A = "ACL";
	string B;
	int K=0;

	cin >> K;

	for (int i = 0; i < K; i++) {
		B+=A;
	}

	cout << B;
	return 0;
}

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

typedef long long ll;

const int MAX_N = 8000 + 3;
ll n, x, y, ans;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> x >> y;
	while (x * 2 <= y) {
		x *= 2;
		ans++;
	}

	cout << ans + 1 << "\n";
	return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 200000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string as = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string ab = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

ll lcm(ll x, ll y) {
  return (x*y)/gcd(x, y);
}

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

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



int main() {

  int s[3];
  cin >> s[0] >> s[1] >> s[2];

  sort(s, s+3);

  cout << s[0]+s[1] << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  for(ll i=1;i<10;i++){
    if(a%i==0){
      if(a/i<10){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
  
      
                        
                        
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

int main(){
	cin.tie(0);					//cinとcoutの結び付きを解除
	ios::sync_with_stdio(false);//stdioとの同期を解除
	
	char inputb, inputa;
	cin >> inputb;
	cin >> inputa;
	
	int inpb, inpa;
	
	switch (inputb){
		case 'A':
			inpb = 1;
			break;
		case 'B':
			inpb = 2;
			break;
		case 'C':
			inpb = 3;
			break;
		case 'D':
			inpb = 4;
			break;
		case 'E':
			inpb = 5;
			break;
		case 'F':
			inpb = 6;
			break;
	}
	
	switch (inputa){
		case 'A':
			inpa = 1;
			break;
		case 'B':
			inpa = 2;
			break;
		case 'C':
			inpa = 3;
			break;
		case 'D':
			inpa = 4;
			break;
		case 'E':
			inpa = 5;
			break;
		case 'F':
			inpa = 6;
			break;
	}
	
	if(inpb == inpa) {
		cout << "=";
	}else if(inpb > inpa) {
		cout << ">";
	}else if(inpb < inpa) {
		cout << "<";
	}
	
	return 0;
	
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define INF (1<<29)
int cb[16];

int main(){
	int n,m;
	while(cin>>n>>m,n|m){
		for(int i=0;i<m;i++)cin>>cb[i];
		int dp[2*256];
		int *cur=dp,*next=dp+256;
		for(int i=0;i<256;i++)cur[i]=INF;
		cur[128]=0;
		for(int i=0;i<n;i++){
			int x;
			cin>>x;
			for(int j=0;j<256;j++)next[j]=INF;
			for(int j=0;j<256;j++){
				for(int k=0;k<m;k++){
					int a = j+cb[k];
					if(a<0)a=0;
					else if(255<a)a=255;
					next[a] = min(next[a],cur[j]+(a-x)*(a-x));
				}
			}
			swap(cur,next);
		}
		cout<<*min_element(cur,cur+256)<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   : combinatorics NCR
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define rw freopen("graphs_as_a_service.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define rep(i,a) lp(i,0,a-1)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 1e5 + 5, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
vii v[N];
int st[N], fi[N], t, e[N], vis[N], cur = 0;
void dfs(int node) {
	st[node] = (++t);
	for (auto u : v[node]) {
		int ch = u.F;
		if (!st[ch])
			dfs(ch);
		else if (!fi[ch]) {
			puts("No");
			exit(0);
		}
	}
	fi[node] = (++t);
}
bool in[N];
inline void dij(int node) {
	priority_queue<pii, vii, greater<pii>> pq;
	e[node] = 0;
	vis[node] = cur;
	pq.push( { 0, node });
	while (!pq.empty()) {
		pii a = pq.top();
		pq.pop();
		for (auto u : v[a.S]) {
			if (vis[u.F] && vis[u.F] < cur)
				continue;
			if (e[u.F] > a.F + u.S && e[u.F] == INF) {
				e[u.F] = a.F + u.S;
				vis[u.F] = cur;
				pq.push( { e[u.F], u.F });
			} else if (e[u.F] != a.F + u.S && e[u.F] != INF) {
				puts("No");
				exit(0);
			}
		}
	}
}
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	int n, m;
	cin >> n >> m;
	lp(i,1,m)
	{
		int a, b, c;
		cin >> a >> b >> c;
		in[b] = true;
		v[a].pb( { b, c });
	}
	lp(i,1,n)
	{
		if (!st[i])
			dfs(i);
	}
	lp(i,1,n)
		e[i] = INF;
	lp(i,1,n)
	{
		cur++;
		if (!in[i] && !vis[i])
			dij(i);
	}
	f("Yes");
	return 0;
}


Measured memory_bytes: 10368
N, M = map(int, input().split())
ils = [map(int, input().split()) for _ in range(M)]

par = [-1 for i in range(N)]

def root(x):
    if par[x] < 0:
        return x
    else:
        par[x] = root(par[x])
        return par[x]
        
def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    if size(x) < size(y):
        x, y = y, x
    par[x] += par[y]
    par[y] = x
    
def same(x, y):
    return root(x) == root(y)

def size(x):
    return - par[root(x)]
    
    
inconv = N * (N - 1) // 2
result = [0] * M
for i in range(M - 1, -1, -1):
    A, B = ils[i]
    A -= 1
    B -= 1
    result[i] = inconv
    if not same(A, B):
        inconv -= size(A) * size(B)
        unite(A, B)
    
for i in result:
    print(i)

Measured memory_bytes: 51684
N = int(input())
H = list(map(int, input().split()))

min = 0
for i in range(1, N):
    if H[i-1] > H[i]:
        if H[i-1] - H[i] > 1:
            print('No')
            exit()
        if H[i] < min:
            print('No')
            exit()
        min = H[i]
print('Yes')



Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    int N, a = 0, b = 0, cnt = 0, dob = 0;
    cin >> N;
    vector<string> str(N);
    for (int i = 0; i < N; i++)
    {
        cin >> str[i];
        string s = str[i];
        int sz = s.size();
        if (s[0] == 'B')
            b++;
        if (s[sz - 1] == 'A')
            a++;
        if (s[0] == 'B' && s[sz - 1] == 'A')
            a--, b--, dob++;

        for (int j = 0; j + 1 < sz; j++)
        {
            if (s[j] == 'A' && s[j + 1] == 'B')
                cnt++;
        }
    }
    if (dob > 0 && (a > 0 || b > 0))
        a++, b++;
    if (dob >= 2)
        cnt += dob - 1;
    cnt += min(a, b);
    cout << cnt << endl;
}

Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int x0 = a % b;
    int x = x0;
    do {
        if(x == c) { cout << "YES" << endl; return 0; }
        x = (x + x0) % b;
    } while(x != x0);
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int m,d;
	cin>>m>>d;
	int flag=0,cnt=0;
	for(int i=2;i<=d;i++){
		for(int j=2;j<=9;j++){
			if(i*10+j>d) {
				flag=1;
				break;
			}
			if(i*j<=m) cnt++;
			//else cout<<i<<" "<<j<<" "<<i*j<<endl;
		}
		if(flag) break;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
import numpy as np

N, K, Q = map(int, input().split()) 
score = np.array([0]*N)

def change_score(N ,A, score):
    #score = score - np.array([1]*N)
    score[A-1] = score[A-1] + 1
    return score

for i in range(Q):
    A = int(input())
    score = change_score(N, A, score)
    #print(score)
    f_score = score

for i in f_score:
    if i + K - Q > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14012
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){
    int n, a[120], alice=0, bob=0;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    for(int i=0; i<n; i++){
        if(i%2==0) alice += a[i];
        else bob += a[i];
    }
    int ans = alice - bob;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<queue>
#include<set>
using namespace std;

int main()
{
  int n, result = 0;
  cin >> n;
  vector<int> v(n);

  for (int i = 0; i < n; i++)
    cin >> v[i];

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

  for (int i = 0; i < n; i++)
    result += v[i];

  if (result % 10 != 0)
  {
    cout << result << endl;
    exit(0);
  }

  for (int i = 0; i < n; i++)
  {
    if (v[i] % 10 != 0)
    {
      cout << result - v[i] << endl;
      exit(0);
    }
    else if (i == n-1)
    {
      cout << 0 << endl;
      exit(0);
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

#pragma GCC optimize("Ofast")

int main(){
    ll i,j;
    ll n,k;
    cin>>n>>k;
    if(n==1) {
        ll x;
        cin>>x;
        if(k%2==0) return 0;
        else {
            cout<<x<<endl;
            return 0;
        }
    }
    ll a[2*n+1];
    for(i=1;i<=n;i++) {
        cin>>a[i];
        a[i+n]=a[i];
    }

    vector<ll> m(202020,0);
    vector<ll> v(n+1);

    for(i=1;i<=2*n;i++){
        if(m[a[i]]==0) m[a[i]]=i;
        else if(m[a[i]]<=n) {
            v[m[a[i]]]=i-m[a[i]]+1;
            m[a[i]]=i;
        }
    }

    ll po=1+v[1];

    while(po%n!=1){
        if(po%n==0) po=po+v[n];
        else po=po+v[po%n];
    }
    

    ll loop=(po-1)/n;
    k%=loop;

    po=1;
    ll prev;
    
    while(po<=k*n){
        prev=po;
        if(po%n==0) po=po+v[n];
        else po=po+v[po%n];
    }

    if(po==k*n+1){
        return 0;
    }
    
    if(prev%n==0) prev=n;
    else prev=prev%n;

    vector<ll> ans;

    while(prev<=n){
        if(prev+v[prev]<=n+1){
           prev=prev+v[prev];
        }
        else{
            ans.pb(a[prev]);
            prev++;
        }
    }

    if(ans.size()==0) return 0;
    printf("%d",ans[0]);
    for(i=1;i<ans.size();i++) printf(" %d",ans[i]);
    cout<<endl;

    return 0;
}

Measured memory_bytes: 9456
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)


int main(){
    int n;
    cin >> n;
    vector<ll>x(n),y(n),h(n);
    rep(i,n)cin >> x[i] >> y[i] >> h[i];
    bool flag =0;
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            ll H;
            for(int k=1;k<=200;k++){
                bool pflag = 1;
                ll p = i;
                ll q = j;
                H = k;
                for(int l=0;l<n;l++){
                    if(h[l]!=max(H-abs(p-x[l])-abs(q-y[l]),0LL)){
                        pflag = 0;
                        break;
                    }
                }
                if(pflag){
                    flag = 1;
                }
                if(flag)break;
            }
            if(flag){
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
    ll H;
    rep(i,101){
        rep(j,101){
            bool pflag = 1;
            rep(k,n){
                if(k==0){
                    H = h[k] + abs(i-x[k])+abs(j-y[k]);
                }else{
                    if(h[k]!=max(H-abs(i-x[k])-abs(j-y[k]),0LL)){
                        pflag = 0;
                        break;
                    }
                }
            }
            if(pflag){
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){

	int m,n,s[200][2],t[1000][2];
	int i,j,k,x,y;

	while(1){
		scanf("%d",&m);
		if(!m)break;
		for(i=0;i<m;i++){
			scanf("%d%d",&s[i][0],&s[i][1]);
		}
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d%d",&t[i][0],&t[i][1]);
		}
		for(i=0;i<n;i++){
			x=t[i][0]-s[0][0];
			y=t[i][1]-s[0][1];
			for(j=1;j<m;j++){
				for(k=0;k<n;k++){
					if(s[j][0]+x==t[k][0]&&s[j][1]+y==t[k][1]){
						break;
					}
				}
				if(k==n)break;
			}
			if(j==m){
				printf("%d %d\n",x,y);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 608
//****** @mdazmat9 **********
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define EB emplace_back
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define MOD2 998244353
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


void solve() {
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        dp[i]=abs(a[i]-a[i-1])+dp[i-1];
        dp[i]=min(dp[i],abs(a[i]-a[i-2])+dp[i-2]);

    }
    cout<<dp[n-1]<<endl;

}
int32_t main() {
    IOS;
    int test = 1;
//    cin >> test;
    for(int i=1;i<=test;i++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
  int a,b,i,j;
  while(1)
       {
  scanf("%d%d",&a,&b);
  if(a==0&&b==0){break;}
 
  for(i=1;i<=a;i++)
    {
      for(j=1;j<=b;j++)
    {
      if(i>1&&i<a&&j<b&&j>1)printf(".");
      else printf("#");
    }
      printf("\n");
    }
  printf("\n");
     
       }
  return 0;
}


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

const int N = (int) 2e5 + 5;

long long n;
int dp[N][25];

int main() {
	//freopen(".inp", "r", stdin); freopen(".out", "w", stdout);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int a; scanf("%d", &a);
		for (int mask = 0; mask < 20; mask++) dp[i][mask] = dp[i - 1][mask];
		for (int mask = 0; mask < 20; mask++) dp[i][mask] += ((a >> mask) & 1);
	}
	int pos = 1;
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		while (true) {
			if (pos == i) break;
			bool ok = true;
			for (int mask = 0; mask < 20; mask++)
				if (dp[i][mask] - dp[pos - 1][mask] > 1) {
					ok = false;
					break;
				}
			if (ok == true) break;
			pos++;
		}
		ans += i - pos + 1;
	}
	printf("%lld\n", ans);
	return 0;
}

/* 	a + b = (a ^ b) + 2 * (a & b)
		a + b >= a ^ b. The equality holds if and only if a & b = 0	


*/

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

using namespace std;

int main()
{
	string s;
	cin >> s;
	map<char, bool> m;
	for (int i = 0; i < s.size(); i++)
		m[s[i]] = true;
	if (m['N'] == m['S'] && m['W'] == m['E'])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
import math
a,b,h,m = map(int, input().split(" "))

hrad = h * 30 + m * 0.5
mrad = m * 6

l = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(abs(hrad - mrad))))
print(l)


Measured memory_bytes: 9400
///=======================///
/// coder: Andy - Tohrumi ///
///=======================///

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i > b; i--)

using namespace std;

typedef pair<ll, ll> pll;	typedef pair<int, int> ii;
typedef vector<pll> vll;	typedef vector<string> vs;		typedef vector<ii> vii;
typedef vector<int> vi; 	typedef vector<ll> vl;

///====code start here====///

const int mod = 1000000007;
const int N = 105, K = 100005;
ll dp[N][K], pre[N][K];

signed main() {
	fastio;
	ll n, k; cin >> n >> k;
	ll a[n]; rep(i, 0, n) cin >> a[i];
	
	rep(i, 0, a[0] + 1) dp[0][i] = 1;
	rep(i, 1, k + 2) pre[0][i] = pre[0][i - 1] + dp[0][i - 1];
	
	rep(i, 1, n) {
		rep(j, 0, k + 1) {
			dp[i][j] = (pre[i - 1][j + 1] - pre[i - 1][max(j - a[i], 0ll)] + mod) % mod;
			pre[i][j + 1] = (pre[i][j] + dp[i][j]) % mod;
		}
	}
	
	return cout << dp[n - 1][k] << endl, 0;
}


Measured memory_bytes: 159804
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define LL long long
#define INF 1000000001
#define mod 1000000007
using namespace std;
int keta(int n,int k){return (n/int(pow(10,double(k-1)))) % 10;} //nの下からk桁目
ll gcd(ll n,ll m){
	if(n<m){ll a=m;m=n;n=a;}
	ll r=n%m;
	while(r!=0){
		n=m;
		m=r;
		r=n%m;
	}
	return m;
}
ll lcm(ll n,ll m){
	return n*m/gcd(n,m);
}

int main(){
	
	int n;
	cin>>n;
	if(n>63)cout<<64<<endl;
	else if(n>31)cout<<32<<endl;
	else if(n>15)cout<<16<<endl;
	else if(n>7)cout<<8<<endl;
	else if(n>3)cout<<4<<endl;
	else if(n>1)cout<<2<<endl;
	else cout<<1<<endl;


}

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

int main()
{
    int n,i,j,k,ans=0;

    cin>>n;

    int a[n+2];

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

    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            for(k=j+1;k<n;k++){
                if(a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k]&&a[i]+a[j]>a[k]){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


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

  int n;
  cin>>n;
  int m=n;

  if(n%2){
    cout<<0<<endl;
    return 0;
  }
  
  int ans=0;
  n/=10;
  while(n){
    ans+=n/5;
    n/=5;
  }
  ans+=m/10;
  cout<<ans<<endl;


}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] arr = new String[n];
		for (int i = 0; i < n; i++) {
		    char[] org = sc.next().toCharArray();
		    Arrays.sort(org);
		    arr[i] = new String(org);
		}
		Arrays.sort(arr);
		long total = 0;
		long count = 1;
		String prev = "";
		for (int i = 0; i < n; i++) {
		    if (prev.equals(arr[i])) {
		        count++;
		    } else {
		        total += count * (count - 1) / 2;
		        count = 1;
		        prev = arr[i];
		    }
		}
		total += count * (count - 1) / 2;
		System.out.println(total);
   }
}


Measured memory_bytes: 51724
#include <stdio.h>
#define S 100000
#define T 50000

int main(){
	int i;
	int n, q;
	int l, r, m;
	int count = 0;
	int s[S];
	int t[T];

	scanf("%d", &n);
	for( i=0; i<n; i++ ){
		scanf("%d", &s[i]);
	}
	scanf("%d", &q);
	for( i=0; i<q; i++ ){
		scanf("%d", &t[i]);
	}
	for( i=0; i<q; i++ ){
		l=0;
		r=n;
		while( l<r ){
			m=(l+r)/2;
			if( s[m]==t[i] ){
				count++;
				break;
			}
			else if( t[i]<s[m] ) r=m;
			else if( t[i]>s[m] ) l=m+1;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 1184
#include<stdio.h>
#define MAX 100
int main(){
  int i,j,n,k,v,u;
  int M[MAX][MAX];

   scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++)M[i][j]=0;
  }
 
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;//0 origin
    
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
       if(j)printf(" ");
      printf("%d",M[i][j]);
     
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 640
import java.io.*;
import java.util.Arrays;
import java.util.stream.Stream;
import static java.util.stream.Collectors.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println(
            br.lines().skip(1)
                .map(s -> Stream.of(s.split(" "))
                    .mapToInt(Integer::parseInt)
                    .toArray())
                .map(i -> {Arrays.sort(i); return i;})
                .map(i -> Math.pow(i[0], 2) + Math.pow(i[1],2) == Math.pow(i[2], 2))
                .map(b -> b ? "YES" : "NO")
                .collect(joining("\n")));
    }
}

Measured memory_bytes: 32056
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
 
#define INF 10000000000
#define M 1000000007

#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))

int compare_long(const void *a, const void *b) {
	return *(long*)a - *(long*)b;
}

int main() {
	long W, H;
	long p[100001];
	long q[100001];
	long i, j;
	long ans = 0;
	int wc = 0, hc = 0;
	
	scanf("%ld %ld", &W, &H);
	for(i=0;i<W;i++) {
		scanf("%ld", &p[i]);
	}
	p[W] = INF;
	qsort((void *)p, W, sizeof(long), compare_long);
	
	for(i=0;i<H;i++) {
		scanf("%ld", &q[i]);
	}
	q[H] = INF;
	qsort((void *)q, H, sizeof(long), compare_long);
	
	for(i=0;i<W+H;i++) {
		//printf("%d %d -> ", wc, hc);
		if(p[wc] < q[hc]) {
			ans += (p[wc] * (H + 1 - hc));
			wc++;
		} else {
			ans += (q[hc] * (W + 1 - wc));
			hc++;
		}
		//printf("%d %d: %ld\n", wc, hc, ans);
	}
	
	printf("%ld\n", ans);
	
	return 0;
}

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

using namespace std; 
int main()
{
	int n,max=-1,pos=0;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
		if(v[i]>max)
		{
			max=v[i];
			pos=i;
		}
			
	}
	sort(v.rbegin(),v.rend());
	for(int i=0;i<n;i++)
	{
		if(i != pos)
			cout<<v[0]<<endl;
		else
			cout<<v[1]<<endl;
	}
	
		
	
	return 0;		
}




Measured memory_bytes: 2432
//JAI SRI KRISHNA.//
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,m,c=0,a,b;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>a>>b;
       double d=sqrt(a*a+b*b);
       if(d<=m)
        c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    ll n; cin >> n;
    queue<ll> q;
    rep(i, n) {
        ll p; cin >> p;
        if(i+1 == p) q.push(i);
    }
    ll ans = 0;
    while(q.size()) {
        ans++;
        ll a = q.front(); q.pop();
        ll b = q.front();
        if(a + 1 == b) q.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 3948
def main():
    s = 0
    n = int(input())
    for i in range(1, n+1):
        for j in range(1, n+1):
            gcd_tmp = gcd(i, j)
            for k in range(1, n+1):
                s += gcd(gcd_tmp, k)
    print(s)


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


if __name__ == "__main__":
    main()


Measured memory_bytes: 9192
#include <bits/stdc++.h>
template<typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from, int to, T cost) {
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
};
bool operator == (Edge<int> e1, Edge<int> e2) {
    return e1.from == e2.from &&
            e1.to == e2.to &&
            e1.cost == e2.cost;
}
bool operator > (Edge<int> e1, Edge<int> e2) {
    return e1.cost < e2.cost;
}
template<typename T>
using Edges = std::vector<Edge<T>>;
template<typename T>
using Graph = std::vector<Edges<T>>;
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
ll leaf = 0;
P sch(int now, int prev, int wn, int wp, const Graph<int> &g) {
  if((int)(g[now].size()) == 1) {
    leaf += g[now][0].cost;
    return make_pair(wp, prev);
  } else {
    P res = make_pair(-1, -1);
    for(int i=0;i<(int)(g[now].size());++i) {
      int next = g[now][i].to, cost = g[now][i].cost;
      if(next == prev) continue;
      P tmp = sch(next, now, wn+cost, wn, g);
      res = max(res, tmp);
    }
    return res;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    vector<int> p(n), d(n);
    for(int i=0;i<n-1;++i) {
      cin >> p[i];
      p[i]--;
    }
    for(int i=0;i<n-1;++i) {
      cin >> d[i];
    }
    Graph<int> g(n);
    ll su = 0;
    for(int i=1;i<n;++i) {
      su += d[i-1];
      g[i].emplace_back(Edge<int>(i, p[i-1], d[i-1]));
      g[p[i-1]].emplace_back(Edge<int>(p[i-1], i, d[i-1]));
    }
    P tmp1 = {-1, -1};
    for(int i=0;i<n;++i) {
      tmp1 = sch(i, -1, 0, 0, g);
      if(tmp1.first != -1 && tmp1.second != -1) break;
    }
    leaf = 0;
    P tmp2 = sch(tmp1.second, -1, 0, 0, g);
    cout << su + (su - leaf) * 2 - tmp2.first << endl;
  }
}



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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  int n;
  cin >> n;
  
  rep(i, 0, n){
    cout << "ACL";
  }
  
  cout << endl;
  
  return 0;
  
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T&a , T b){
    if(a<b){
        a=b; return true;
    }else{
        return false;
    }
}
template<class T> inline bool chmin(T&a , T b){
    if(a>b){
        a=b; return true;
    }else{
        return false;
    }
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

vector<vector<int> > G;
int dp[100005];

//dpにメモ化していく
int rec(int v){
    if(dp[v]!=-1) return dp[v];
    int res=0;
    for(auto nv : G[v]){
        chmax(res,rec(nv)+1);
    }
    return dp[v]=res;
}

int main(){
    int n,m;
    cin >> n >> m;
    G.assign(n,vector<int>());
    rep(i,m){
        int x,y;
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
    }
    rep(i,n) dp[i]=-1;

    int res=0;
    rep(i,n) chmax(res,rec(i));
    cout << res << endl;

}

Measured memory_bytes: 8192
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

int main(void) {
  int a, b;
  char ch;
  scanf("%d %c %d", &a, &ch, &b);
  printf("%d\n", ch == '+' ? a+b : a-b);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[101];
	int n,a;
	scanf("%s",s);
	n=strlen(s);
	a=n-2;
	printf("%c%d%c\n",s[0],a,s[n-1]);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
ls=[]
for i in range(N):
    a,b=map(int,input().split())
    ls.append([a,b])
ls = sorted(ls,key=lambda x:x[1])

time=0
for i in range(N):
    time+=ls[i][0]
    if time > ls[i][1]:
        print("No")
        break
    if i == N-1:
        print("Yes")

Measured memory_bytes: 39588
import sys

f_i = sys.stdin

n = int(f_i.readline())

adj = [[]] * n
for x in f_i:
    x = list(map(int, x.split()))
    adj[x[0]] = [c_v for c_v in zip(x[3::2], x[2::2])]

import heapq

def dijkstra():
    PQ = [(0, 0)]
    isVisited = [False] * n
    distance = [999900001] * n

    distance[0] = 0
    
    while PQ:
        uc = heapq.heappop(PQ)
        u = uc[1]

        if uc[0] > distance[u]:
            continue

        isVisited[u] = True
        
        for c, v in adj[u]:
            if isVisited[v] == True:
                continue
            t_cost = distance[u] + c
            if t_cost < distance[v]:
                distance[v] = t_cost
                heapq.heappush(PQ, (t_cost, v))

    for v, d in enumerate(distance):
        print(v, d)


dijkstra()

Measured memory_bytes: 70184
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

double Distance(double x,double y){
    return sqrt(x*x+y*y);
}

int main(){
    int n,d;
    cin>>n>>d;
    int count=0;

    rep(i,n){
        double x,y;
        cin>>x>>y;
        if(d>=Distance(x,y)) count++;
    }

    cout<<count<<endl;
}

Measured memory_bytes: 3720
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<P> task;
    ll a,b;
    rep(i,n){
        cin >> a >> b;
        task.push_back(P(b,a));
    }
    ll now = 0;
    SORT(task);
    rep(i,n){
        tie(b,a) = task[i];
        if (now+a > b){
            PRINT("No");
            return 0;
        }
        now += a;
    }
    PRINT("Yes");
}


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

int gcd(long long a, long long b){
  long long M = max(a, b), m = min(a, b);
  while(m != 0){
  	long long r = M%m;
    M = m; m = r;
  }
  return M;
}

int digit_sum(long long n){
  long long ans;
  while(n != 0){
  	ans += n%10;
  	n /= 10;
  }
  return ans;
}

int main(){
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(n);
  for(int i = 0; i < q; i++){
  	int p;
  	cin >> p;
    a.at(p-1)++;
  }
  for(int i = 0; i < n; i++){
  	if(k-q+a.at(i) > 0){
    	cout << "Yes" << endl;
    }
  	else{
    	cout << "No" << endl;
    }
  }
  
}

Measured memory_bytes: 1024
<?php
function isPrime($num, $n) {
    if ($num == 2) {
        return true;
    } elseif ( $num < 2 or $num % 2 == 0) {
        return false;
    } else {
        $start = 3;
        while ($start <= sqrt($num) + 1) {
            if ($num % $start == 0) {
                return false;
            }
            $start += 2;
        }
        return true;
    }
}

$n = trim(fgets(STDIN));
$count = 0;

for ($i = 0; $i < $n; $i++) {
    $number = (int) fgets(STDIN);
    if (isPrime($number, $n)) $count++;
}

echo $count . PHP_EOL;



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

using namespace std;

int main(void)
{
  string s; cin>>s;
  int n=s.size();
  int moji1=(n-1)/2;
  int moji2=(n+3)/2;
  string s1=s.substr(0,moji1);
  string s2=s.substr(moji2-1);
  
  if(s1==s2){puts("Yes");}
  else{puts("No");}
  
  //cout<<s1<<endl<<s2<<endl;
  return 0;
}

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

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

    vector<int> v(N);
    for (int i = 0; i < N; ++i) {cin >> v[i];}
    sort(v.begin(), v.end());

    int Nmax = v.back();
    vector<int> b(Nmax+1);
    for (int i = 0; i < Nmax+1; ++i) {b[i] = 1;}
    for (int i = 0; i < N; ++i) {
        if (b[v[i]]) {
            if (i > 0) {
                if (v[i] == v[i-1]) {
                    b[v[i]] = 0;
                    continue;
                }
            }
            for (int j = 2 * v[i]; j < Nmax+1; j += v[i]) {
                b[j] = 0;
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += int(b[v[i]]);
    }
    cout << ans << endl;
    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int query(int u) {
    cout << u << endl;
    fflush(stdout);

    string x;
    cin >> x;

    if (x == "Vacant") {
        return 0;
    } else if (x == "Male") {
        return 1;
    } else
        return -1;
}

int main() {
    int N;
    cin >> N;
    int basic = query(0);

    if (basic == 0) return 0;

    int low = 0, high = N;

    while (true) {
        int mid = (low + high) >> 1;
        int col = query(mid);

        if (col == 0) return 0;

        int exp = (mid % 2 == 1 ? -basic : basic);

        if (exp == col) {
            low = mid + 1;
        } else {
            high = mid - 1;
        }
    }
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, b, c, k;
  in(k);
  in(n);
  vector<ll> a(n + 1);
  rep(i, n)
    in(a[i]);
  a[n] = a[0] + k;
  c = 0;
  rep(i, n){
    c = max(c, a[i + 1] - a[i]);
  }
  out(k - c);
  memi;
}


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

int h, w;
char meiro[20][20];
int visit[20][20];

void init_visit() {
    rep(i, 20) rep(j, 20) visit[i][j] = 0;
}

int find(int si, int sj, int ei, int ej) {
    if (meiro[si][sj] == '#' || meiro[ei][ej] == '#') {
        return 0;
    }
    if (si == ei && sj == ej) return 0;

    queue<pair<int, P>> que;
    que.push({0, {si, sj}});
    P idou[4] = {{1,0}, {-1,0}, {0,1}, {0,-1}};
    while(true) {
        pair<int, P> now = que.front(); que.pop();
        int row = now.second.first;
        int col = now.second.second;
        int cnt = now.first;
        for (P x : idou) {
            int nexti = row + x.first, nextj = col + x.second;

            if (nexti == ei && nextj == ej) {
                init_visit();
                return cnt + 1;
            }
            if (0 <= nexti && nexti < h && 0 <= nextj && nextj < w
                    && visit[nexti][nextj] == 0 && meiro[nexti][nextj] == '.') {
                visit[nexti][nextj] = 1;
                que.push({cnt+1, {nexti, nextj}});
            }
        }
    }
    init_visit();
    return 0;
}

void solve() {
    cin >> h >> w;
    rep(i, h) rep(j, w) cin >> meiro[i][j];
    int ans = 0;
    rep(si, h) rep(sj, w) rep(ei, h) rep(ej, w) {
        ans = max(ans, find(si, sj, ei, ej));
    }
    cout << ans << endl;
}

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




Measured memory_bytes: 256