akhauriyash/Code-Regression huggingface dataset:
#include <array>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

constexpr int ALPHA = 4;
constexpr int MAX_V = 10000;
const int BASE = 'a';

struct trie {
	int v;
	int failure;
	bool accept;
	array<int, ALPHA> next;

	explicit trie(int v_):v(v_), failure(0), accept(false) { next.fill(-1); }
};

vector<trie> nodes;
char convert[128];

void add(const string &s) {
	int v = 0;

	for(const char &c : s) {
		const int id = convert[c] - BASE;
		if(nodes[v].next[id] == -1) {
			nodes[v].next[id] = nodes.size();
			nodes.emplace_back(nodes.size());
		}
		v = nodes[v].next[id];
	}
	nodes[v].accept = true;
}

void construct(const vector<string> &dict) {
	nodes.clear();
	nodes.reserve(MAX_V);
	nodes.emplace_back(0);

	for(const auto &s : dict) {
		add(s);
	}

	queue<int> que;
	que.push(0);

	while(!que.empty()) {
		const trie &current = nodes[que.front()];
		que.pop();

		for(int i = 0; i < ALPHA; ++i) {
			const int next_id = current.next[i];

			if(next_id == -1) continue;

			que.push(next_id);

			trie &u = nodes[next_id];

			if(current.v) {
				int f = current.failure;
				while(f && nodes[f].next[i] == -1) {
					f = nodes[f].failure;
				}

				const int nf = nodes[f].next[i];

				if(nf != -1) {
					u.failure = nf;
					u.accept |= nodes[nf].accept;
				}
			}
		}
	}
}

int move_to(int v, char c) {
	const int id = c - BASE;

	while(v && nodes[v].next[id] == -1) {
		v = nodes[v].failure;
	}

	if(nodes[v].next[id] != -1) {
		v = nodes[v].next[id];
	}

	return v;
}

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

inline bool out(int x, int y, int w, int h) {
	return x < 0 || y < 0 || x >= w || y >= h;
}

inline int bfs(const vector<string> &field) {
	const int h = field.size();
	const int w = field[0].size();

	vector<vector<unordered_map<int, int>>> dist(h, vector<unordered_map<int ,int>>(w));
	queue<tuple<int, int, int>> que;

	for(int y = 0; y < h; ++y) {
		for(int x = 0; x < w; ++x) {
			if(field[y][x] == 'S') {
				dist[y][x][0] = 0;
				que.push(make_tuple(x, y, 0));
				goto end_init;
			}
		}
	}

end_init:;

	while(!que.empty()) {
		int x, y, v;
		tie(x, y, v) = que.front();
		que.pop();

		const int next_dist = dist[y][x][v] + 1;

		for(int d = 0; d < 4; ++d) {
			const int nx = x + dx[d];
			const int ny = y + dy[d];
			if(out(nx, ny, w, h) || field[ny][nx] == '#') continue;

			const int nv = move_to(v, d + BASE);

			if(nodes[nv].accept) continue;

			if(field[ny][nx] == 'G') return next_dist;
			if(!dist[ny][nx].count(nv)) {
				dist[ny][nx][nv] = next_dist;
				que.push(make_tuple(nx, ny, nv));
			}
		}
	}

	return -1;
}

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

	const string dir = "LDRU";
	for(unsigned i = 0; i < dir.size(); ++i) {
		convert[dir[i]] = 'a' + i;
	}

	for(int h, w; cin >> h >> w && h;) {
		vector<string> field(h);
		for(auto &e : field) cin >> e;

		int n;
		cin >> n;

		vector<string> ng(n);
		for(auto &e : ng) cin >> e;

		construct(ng);

		cout << bfs(field) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 5432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int x[] = new int[N];

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

		int ans = Integer.MAX_VALUE;

		for (int j = 1; j <= 100; j++) {
			
			int cost = 0;
			
			for (int i : x) {
				cost += (i - j) * (i - j);
			}
			ans = Math.min(ans, cost);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <string.h>

using namespace std;
#define ll long long int

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

	ll n;
	string s;
	cin>>n>>s;
	ll count=0,i=0,j=n-1;
	while(i<j){
		while(i<n && s[i]=='R') i++;
		while(j>=0 && s[j]=='W') j--;
		if(i>=j) break;
		s[i]='R';
		s[j]='W';
		count++;
	}
	cout<<count<<endl;

	return 0;
}


Measured memory_bytes: 3764
#include "bits/stdc++.h"

using namespace std;

void Main() {
    int X;
    cin >> X;
    cout << (X >= 30 ? "Yes" : "No") << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    float total = 0;
    for(int i = 0;i < N; i++){
        float x;
        string u;
        cin >> x;
        cin >> u;
        if(u == "JPY"){
            total += x;
        }
        if(u == "BTC"){
            total += (380000*x);
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES(n)          cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n)          cout << ((n) ? "Yes" : "No"  ) << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

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

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  int n; cin >> n;
  vector<int> a(n); rep(i, n) cin >> a[i];
  double ave = 0;
  rep(i, n) ave += a[i];
  ave /= n;

  double sub = __INT_MAX__;
  int ans = 0;
  // debug(ave);
  rep(i, n) {
    double b = abs(ave - a[i]);
    if (b < sub) {
      sub = b;
      ans = i;
    }
  }
  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main(){
    int N;
    cin >> N;
    string W[100];
    for(int i=0;i<N;i++)
        cin >> W[i];
    //一致
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(W[j] == W[i] && i != j){
                //cout << "一致有り" << endl;
                cout << "No" << endl;
                return 0;
            }
        }
    }
    //末尾
    string word1, word2;    
    char last, first;
    for(int i=1;i<N;i++){
        word1 = W[i-1];
        for(int i=0;word1[i] != '\0';i++)
            last = word1[i];
        word2 = W[i];
        first = word2[0];
        if(last != first){
            //cout << "末尾不正" << endl;
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)cin >> a[i];
	vector<int> v;
	if (n % 2 == 0) {
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0)v.push_back(a[i]);
			else v.insert(v.begin() + 0, a[i]);
	 }
	}
	if (n % 2 == 1) {
		for (int i = 0; i < n; i++) {
			if (i % 2 == 1)v.push_back(a[i]);
			else v.insert(v.begin() + 0, a[i]);
		}
	}
	for (int i = 0; i < n; i++)cout << v[i] << ' ' ;
	cout << endl;

	return 0;
}

Measured memory_bytes: 3956
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

const int MAX_N = 10000;
const int MAX_M = 20000;
const int INF = 100000000;

struct edge{
	int to;
	int dis;
	int cost;
	edge(){}
	edge(int t, int d, int c){
		to = t;
		dis = d;
		cost = c;
	}
};

typedef pair<int, int> P;				//first := 最小距&#31163;, second := &#32534;号

//&#36755;入
int N, M;
vector<edge> es[MAX_N + 1];				//&#37051;接矩&#38453;


int d[MAX_N + 1];						//最小距&#31163;
int pre[MAX_N + 1];						//前&#32512;&#32467;点
bool used[MAX_N + 1];					//避免重&#22797;&#32479;&#35745;，&#26631;&#35760;是否已&#35745;算

void dijkstra(){
	//初始化
	priority_queue<P, vector<P>, greater<P> > que;			//返回当前&#31163;1最短距&#31163;
	que.push(P(0, 1));
	fill(d, d + N + 1, INF);
	d[1] = 0;

	while(!que.empty()){
		P p = que.top();
		que.pop();
		//若已存在更小距&#31163;，&#21017;忽略
		int v = p.second;
		if(d[v] < p.first)continue;
		//否&#21017;，更新
		for(vector<edge>::iterator it = es[v].begin(); it != es[v].end(); it ++){
			edge e = *it;
			if(d[e.to] > d[v] + e.dis){
				//存在更小路径，&#21017;加入&#38431;列
				d[e.to] = d[v] + e.dis;
				pre[e.to] = v;
				que.push(P(d[e.to], e.to));
			}
			else{
				if(d[e.to] == d[v] + e.dis){
					//存在等价路径，&#21017;替&#25442;&#20026;更小的&#36793;
					int tmp, x = pre[e.to];
					for(vector<edge>::iterator it = es[x].begin(); it != es[x].end(); it ++){
						edge etmp = *it;
						if(etmp.to == e.to){
							tmp = etmp.cost;
							break;
						}
					}
					if(tmp > e.cost){
						pre[e.to] = v;
					}
				}
			}
		}
	}

}

void solve(){
	//求出1到其他点的最短路径
	dijkstra();
/*	printf("d:\n");
	for(int i = 1; i <= N; i ++)
		printf("%d ", d[i]);
	printf("\n");
	printf("pre:\n");
	for(int i = 1; i <= N; i ++)
		printf("%d ", pre[i]);
	printf("\n\n");
*/	fill(used, used + N + 1, false);
	used[1] = true;
	int ans = 0;
	for(int i = 2; i <= N; i ++){
		int k = i;
		while(k != 1 && !used[k]){
			used[k] = true;
			int x = pre[k], tmp;
			for(vector<edge>::iterator it = es[x].begin(); it != es[x].end(); it ++){
				edge e = *it;
				if(e.to == k){
					tmp = e.cost;
					break;
				}
			}
			ans += tmp;
			k = x;
		}
	}
	printf("%d\n", ans);
	for(int i = 1; i <= N; i ++)
		es[i].clear();
}


int main(int argc, char const *argv[]){

//	freopen("in.txt", "r", stdin);

	while(scanf("%d %d", &N, &M)){
		if(N == 0 && M == 0)break;
		for(int i = 0; i < M; i ++){
			int u, v, x, y;
			scanf("%d %d %d %d", &u, &v, &x, &y);
			es[u].push_back(edge(v, x, y));
			es[v].push_back(edge(u, x, y));
		}
		solve();
	}

	return 0;
}

Measured memory_bytes: 3280
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct Node {
    int va;
    struct Node *before;
    struct Node *next;
};
    
struct Node *note;
    
void insert(int va) {
    struct Node *x = (struct Node *)malloc(sizeof(struct Node));
    x->va = va;
    note->next->before = x;
    x->next = note->next;
    note->next = x;
    x->before = note;
}
    
struct Node* search(int va) {
    struct Node *x = note->next;
    while(x != note && x->va != va ) {
        x = x-> next;
    }
    return x;
}
    
void deleteNode(struct Node *t) {
    if (t == note) return;
    t->before->next = t->next;
    t->next->before = t->before;
}
 void deleteva(int va) {
    deleteNode(search(va));
}  
void deleteFirst() {
    deleteNode(note->next);
}
    
void deleteLast() {
    deleteNode(note->before);
}
    
void print() {
    struct Node *x;
    x = note->next;
    int i = 0;
    while(1) {
        if (x == note) break;
        if(i++ > 0) printf(" ");
        printf("%d", x->va);
        x = x->next;
    }
    printf("\n");
}
    
    
int main(void) {
    int va, n;
    char order[20];
    scanf("%d", &n);
    note = (struct Node *)malloc(sizeof(struct Node));
    note->next = note;
    note->before = note;
    for (int i = 0; i < n; i++) {
        scanf("%s%d",order, &va);
        if(order[0] == 'i') {
            insert(va);
        }else if(order[0] == 'd') {
            if(strlen(order) > 6) {
                if( strlen(order) > 10) {
                    deleteFirst();
                }else if( strlen(order) > 9) {
                    deleteLast();
                }
            }else {
                deleteva(va);
            }
        }
    }
    print();
    return 0;
}

Measured memory_bytes: 36204
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int x, a, b;
  cin >> x >> a >> b;
  
  if(abs(x - a) < abs(b - x))
  	cout << "A" << endl;
  else
    cout << "B" << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <cmath>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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; }


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

    int A, B;

    cin >> A >> B;

    cout << A * B - A - B + 1 << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

#define rep(i, start, end) for (int(i) = (start); (i) < (end); (i)++)
#define rep_r(i, end, start) for (int(i) = (end); (i) >= (start); i--)
#define len(ar) (sizeof(ar) / sizeof(ar[0]))

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

  map<int, int> m;
  rep(i, 0, N) m[i + 1] = 0;

  int a, b;
  rep(i, 0, M) {
    cin >> a >> b;
    m[a]++;
    m[b]++;
  }

  rep(i, 0, N) cout << m[i + 1] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
int main(){
	//keyence
	string s;
	cin>>s;
	int sign=0;
	for(int i=0;i<s.length();i++){
		for(int j=0;j<s.length()-i;j++){
			string s1 = s;
			s1.erase(i,j);
			if(s1=="keyence"){
				sign=1;
				break;	
			}
		}
	}
	if(sign) cout<<"YES\n";
	else cout<<"NO\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>

int main() {
  int N;
  std::cin >> N;
  int t=0, x=0, y=0;
  int flag = 0;
  for (int i=0; i<N; i++) {
    int temp_t, temp_x, temp_y;
    std::cin >> temp_t >> temp_x >> temp_y;
    int t_diff = temp_t - t;
    int x_diff = temp_x - x;
    int y_diff = temp_y - y;
    t = temp_t;
    x = temp_x;
    y = temp_y;
    if (t_diff%2 != std::abs((x_diff + y_diff)%2) || t_diff < std::abs(x_diff)+std::abs(y_diff)) {
      flag = 1;
      break;
    }
  }
  if (flag) {
    std::cout << "No" << std::endl;
  }
  else {
    std::cout << "Yes" << std::endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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; }

using ll = long long;

ll N;
ll a[100010];
std::map<ll, ll> mp;
ll ans;

int main()
{
  std::cin >> N;
  rep( i, N )
    std::cin >> a[i], ++mp[a[i]];

  for( auto it = mp.begin(); it != mp.end(); ++it )
  {
    if( it->second < it->first )
      ans += it->second;
    else
      ans += it->second-it->first;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 7040
#include <iostream>
#include <map>

using namespace std;
int n;
int a[110];
string station ="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  map<char,int> place;
  for(int i = 0;i < station.length();i++){
    place[station[i]] = i;
  }
  while(cin>>n,n){
    string str;
    for(int i = 0;i < n;i++){
      cin>>a[i];
    }
    cin>>str;
    string ans ="";
    int pos = 0;
    for(int i = 0;i < str.length();i++){
      char c;
      int x = place[str[i]];
      if(x - a[pos] >= 0){
	ans += station[x - a[pos]];
      }else{
	ans += station[station.length() + (x - a[pos])];
      }
      pos =(pos + 1)%n;
    }
    cout <<ans<<endl;

  }
return 0;
}

Measured memory_bytes: 1216
# heapq が最小ヒープなので、Aの数値は負にする
from heapq import heappop, heappush

N, M = [int(i) for i in input().split()]

heap = []
for i in input().split():
    heappush(heap, -int(i))

for i in range(M):
    a = -heappop(heap)
    half = a // 2
    heappush(heap, -half)
    
ans = -sum(heap)
print(ans)

Measured memory_bytes: 14180
#include <bits/stdc++.h>
#define f(i,q,a) for(long long i=q; i<a; i++)
#define ll long long
#define pb push_back
#define mod 1000000007
#define oo 666666666666666
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll x;
    cin>>x;
    if(x)cout<<0<<endl;
    else cout<<1<<endl;
    return 0;
}


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

int solve(string s,int N){
  int k;
  for(k=0;k<N/2;k++){
    if(s[k]!=s[k+N/2]){
      return 0;
    }
  }
  return 1;
}
int main(){
  int N,i;
  cin >> N;
  char temp1,temp2;
  string s,s1,s2;
  cin >> s;
  
  if(N%2 == 1){
    cout << "No" << endl;
    return 0;
  }
  if(solve(s,N)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys


num = input()
list = {}
for i in range(1, int(num) + 1): 
    list[i] = i
    
for i in range(int(input())) :
    x, y = map(int, input().split(','))
    
    temp = list[x]
    list[x] = list[y]
    list[y] = temp
    
for i in range(1, len(list) + 1):
    print(list[i])

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

int     main() {
        int N;
        cin >>N;
        vector<int> A(N);
        vector<int> B(N);
        for (int i=0; i<N; i++) cin >> A.at(i);
        B=A;
        sort(B.begin(), B.end());
        bool ONE=true;
        //if (B.at(N-1)==B.at(N-2)) ONE=false;
        for (int i=0; i<N; i++) {
                if (B.at(N-1)==A.at(i)) {
                        cout << B.at(N-2) << endl;
                } else {
                        cout << B.at(N-1) << endl;
                }
        }
        return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; 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 VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    string s;
    cin >> s;

    ll n = s.size();
    REP(i, (n - 1) / 2) {
        if (s[i] != s[(n - 1) / 2 - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
        if (s[(n + 3) / 2 - 1 + i] != s[n - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
        if (s[i] != s[n - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
    int N;
    int count =1;
    cin>>N;
    vector<int> data(N);
    for(int i=0;i<N;i++){
        cin>>data.at(i);
    }
    int mx=1000000;
    for(int i=0;i<N-1;i++){
        mx =min(data[i],mx);
        if(data[i+1]<=mx)count++;
    }
    cout <<count<<endl;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		//List<Integer> list=new ArrayList<Integer>();
		//Integer[] array = new Integer[m];
		String s = sc.next();
		String t = sc.next();
		List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		if(s.equals(t))
			System.out.println("Yes");
		else {
			for(int i=0;list.size()>i;i++) {
				String answer = "";
				String last = list.get(list.size()-1);
				for(int j=list.size()-1;-1<j;j--) {
					if(j!=0) {
						String m = list.get(j-1);
						//System.out.println(m);
						list.set(j, m);
					}
					else
						list.set(0, last);
				}
				for(int j=0;list.size()>j;j++) {
					answer=answer+list.get(j);
				}
				//System.out.println(answer);
				if(answer.equals(t)) {
					System.out.println("Yes");
					System.exit(0);
				}
			}
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 27348
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

long long int DP[20000];

int main()
{
	long long int N, W;
	cin >> N >> W;
	
	for(int i = 0; i < 20000; i++){
		DP[i] = INF;
	}
	DP[0] = 0;
	
	for(int i = 0; i < N; i++){
		long long int v, w;
		cin >> v >> w;
		for(int j = 20000; j >= v; j--){
			DP[j] = min(DP[j], DP[j - v] + w);
		}
	}
	
	long long int ans = 0;
	for(int i = 0; i < 20000; i++){
		if(DP[i] <= W){
			ans = i;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3268
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>

#define REP(i,n) for(i=0;i<n;i++)
#define ll long long

int main(void){
    int i;
    int N;
    scanf("%d",&N);

    int a[N];
    REP(i, N){
        scanf("%d",&a[i]);
    }
    
    int max = 0, min = pow(10, 9);
    REP(i, N){
        if(a[i] >= max) max = a[i];
        if(a[i] <= min) min = a[i];
    }

    printf("%d",abs(max - min));
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <decimal/decimal>
using namespace std;
using namespace __gnu_pbds;

#define rep(i, s, t) for (int i = s; i < int(t); ++i)

#define sc	scanf
#define pr	printf
#define ff	first
#define ss	second
#define mp	make_pair
#define pb	push_back
#define eb	emplace_back
#define range(c)	c.begin(), c.end()
#define lowbit(x)	((x) & -(x))
#define pop_count	__builtin_popcount
#define pop_count_64	__builtin_popcountll
#define tail_count	__builtin_ctz
#define tail_count_64	__builtin_ctzll
#define lead_count	__builtin_clz
#define lead_count_64	__builtin_clzll

#define TEMP template<typename
#define CONST(type) constexpr type const

TEMP... Ts> struct is_con { static CONST(bool) value = false; };
TEMP... Ts> struct is_con<vector<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<list<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<deque<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<set<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<unordered_set<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<map<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<unordered_map<Ts...>> { static CONST(bool) value = true; };

TEMP T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2> const& p) { return os << "<" << p.ff << "," << p.ss << ">"; }
TEMP T> typename enable_if<is_con<T>::value, ostream>::type& operator<<(ostream& os, T const& c) {
	os << "{";
	bool first = true;
	for (auto const& x : c) {
		if (first) first = false;
		else os << ",";
		os << " " << x;
	}
	return os << " }";
}

TEMP T, typename... Ts> void dbg(T h, Ts... t) { cerr << " " << h; dbg<Ts...>(t...); }
template<> void dbg<int>(int x) { cerr << endl; }

#ifdef LOCAL
#define debug(...) cerr << "[ "#__VA_ARGS__" ] :", dbg(__VA_ARGS__, 0)
#else
#define debug(...) 0
#endif

TEMP T, typename U> using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
TEMP T> using ordered_set = ordered_map<T, null_type>;

typedef long long i64;
typedef decimal::decimal128 i99;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef float f32;
typedef double f64;
typedef long double f80;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<i64> vl;

TEMP T> T& minn(T& lhs, T const& rhs) { return lhs = min(lhs, rhs); }
TEMP T> T& maxx(T& lhs, T const& rhs) { return lhs = max(lhs, rhs); }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	cout << (h2 - h1) * 60 + m2 - m1 - k << endl;
}


Measured memory_bytes: 3656
input = gets(nil).chomp

c = {}
c["A"] = true
c["B"] = false
c["C"] = false

input.split("\n").each do |line|
  c1, c2 = line.split(",")
  c[c1], c[c2] = c[c2], c[c1]
end

c.each do |k, v|
  puts k if v
end

Measured memory_bytes: 6096
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define NEW(p,n) {p = malloc((n)*sizeof(p[0]));}

int main(){
  int A,B,a,b,c,x;
  scanf("%d %d",&A,&B );
  a=A+B;
  b=A-B;
  c=A*B;
  x=a;
  if(a<=b){
    x=b;
  if(b<=c)
   x=c;
  }else{//a>=bの時
   if(a<=c)
   x=c;
 }
 printf("%d",x);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define fi first
#define se second
#define mk make_pair
using namespace std;
map<int,pair<int,int> >max_p,min_p;
map<char,int>mc;
int h,w,c,vis[101];
string s[51];
void mae(){
  r(i,h)r(j,w)
   if(s[i][j]=='.')s[i][j]='0';
   else{
    if(mc[s[i][j]])s[i][j]=mc[s[i][j]];
    else{
      mc[s[i][j]]=(c++)+'0';
      s[i][j]=(c-1)+'0';
    }
   }
}
void in(){
  for(int k=1;k<c;k++){
    int px=0,py=0,mx=1000,my=1000;
    r(i,h)r(j,w)
      if(s[i][j]-'0'==k){
        px=max(px,j);
        py=max(py,i);
        mx=min(mx,j);
        my=min(my,i);
      }
    max_p[k]=mk(px,py);
    min_p[k]=mk(mx,my);
  }
}
bool dfs(int d,int x){
  if(d){
    pair<int,int>p1=min_p[x],p2=max_p[x];
    for(int i=p1.se;i<=p2.se;i++)
      for(int j=p1.fi;j<=p2.fi;j++)
        if(!vis[s[i][j]-'0'])return 0;
  }
  if(d==c-1)return 1;
  for(int i=1;i<c;i++)
    if(!vis[i]){
      vis[i]=1;
      if(dfs(d+1,i))return 1;
      vis[i]=0;
    }
  return 0;
}
int main(){
  int n;
  cin>>n;
  while(n--){
    memset(vis,0,sizeof(vis));
    max_p.clear();
    min_p.clear();
    mc.clear();c=1;
    cin>>h>>w;
    r(i,h)cin>>s[i];
    mae();in();
    if(dfs(0,0))cout<<"SAFE"<<endl;
    else cout<<"SUSPICIOUS"<<endl;
  }
}

Measured memory_bytes: 3040
n,k=map(int,input().split())

p=list(map(int,input().split()))

c=[0]*len(p) #期待値

for i in range(len(p)):
  if i>0:
    c[i]=(((p[i]+1)*p[i])/(2*p[i]))+c[i-1]
  else:
    c[i]=(((p[i]+1)*p[i])/(2*p[i]))

maxev=0

for i in range(len(p)-k+1):
  ev=0

  if i==0:
    ev=c[i+k-1]
  else:
    ev=c[i+k-1]-c[i-1]

  if maxev==0 or maxev<ev:
    maxev=ev

print(maxev)


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

using namespace std;

long long A, B, C, K;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%lld %lld %lld %lld", &A, &B, &C, &K);
if (K & 1LL) printf ("%lld\n", B - A);
else printf ("%lld\n", A - B);
/*int steps = 100;
while (steps --)
{
    printf ("%lld\n", A - B);
    long long x = A, y = B, z = C;
    A = y + z, B = x + z, C = x + y;
}*/

return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
int main() {
    uint32_t N;
    std::cin >> N;
    int buf = 0;
    std::vector<int64_t> qee(N, 0);
    for(int i=0; i<N; i++){
        std::cin >> buf;
        qee[(buf -1)] = (i+1);
    }
    for(int k=0; k < N; k++){
        std::cout << qee[k] << " ";
    }
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	char c;
	cin >> c;
	if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
		cout << "vowel" << endl;
	}
	else{
		cout <<"consonant "<< endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
	int X, Y, Z, K;
	long long A[1000], B[1000], C[1000];
	vector<long long> val;

	cin >> X >> Y >> Z >> K;
	for (int i = 0; i < X; i++){
		cin >> A[i];
	}
	sort(A, A + X, std::greater<long long>());
	for (int i = 0; i < Y; i++){
		cin >> B[i];
	}
	sort(B, B + Y, std::greater<long long>());
	for (int i = 0; i < Z; i++){
		cin >> C[i];
	}
	sort(C, C + Z, std::greater<long long>());

	for (int i = 0; i < X; i++){
		for (int j = 0; j < Y; j++){
			for (int k = 0; k < Z; k++){
				if(i*j*k <= K){
					val.push_back(A[i] + B[j] + C[k]);
				} else {
					break;
				}
			}
		}
	}
	sort(val.begin(), val.end(), std::greater<long long>());
	
	for (int i = 0; i < K; i++){
		cout << val[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 35044
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

typedef long long ll;
typedef map<ll, ll> M;
typedef pair<ll, ll> P;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ((ll)(x).size())

int main() {
  ll n, mod = 1000000000 + 7, result = 0;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  ll tmp = 0;
  REP(i, n-1) tmp += a[i];
  for (ll i = n-1; i > 0; i--) {
    result += ((tmp % mod) * (a[i] % mod)) % mod;
    tmp -= a[i-1];
  }
  cout << result % mod << endl;
  return 0;
}


Measured memory_bytes: 4824
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int ans = (m+n)/2;

        System.out.println((m+n) % 2 != 0?ans+1:ans);
        
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
bool is_not_out_of_range(size_t now, size_t max_num)
{
	return !(now < 0 || max_num <= now);
}
int main()
{
	ll n;
	cin >> n;
	ll nn = n;
	ll t = 0;
	while (n > 0)
	{
		t += n % 10;
		n /= 10;
	}
	cout << (nn % t ? "No" : "Yes") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 60;
const double EPS = 1e-10;

int N, K;
int h[100010];
int dp[100010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> K;
  REP(i, N) cin >> h[i];
  fill(dp, dp+N, INF);
  dp[0] = 0;
  REP(i, N) {
    FOR(j, 1, K+1) {
      if (i+j<N) chmin(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
    }
  }
  cout << dp[N-1] << endl;

  return 0;
}

Measured memory_bytes: 1792
from collections import defaultdict, deque
import sys
sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def main():
    N, K = [int(a) for a in input().split()]
    if N == 1:
        print(K)
        return
    if K == 1:
        print(0)
        return

    ab = [
        [int(a) for a in input().split()]
        for _ in range(N - 1)
    ]

    edges = defaultdict(lambda: [])
    for ai, bi in ab:
        r = edges[ai]
        r.append(bi)
        edges[ai] = r
        r = edges[bi]
        r.append(ai)
        edges[bi] = r

    childrentable = [None] * (N + 1)

    q = deque()
    q.append((None, 1))

    while len(q) != 0:
        parent_i, current_i = q.pop()

        children = []
        for nei in edges[current_i]:
            if nei == parent_i:
                continue
            q.append((current_i, nei))
            children.append(nei)
        childrentable[current_i] = children

    if len(childrentable[1]) > K - 1:
        print(0)
        return

    def c(a, b):
        k = 1
        for i in range(b):
            if a - i <= 0:
                raise ValueError()
            k = (k * (a - i)) % MAX
        return k

    def f(index):
        target = childrentable[index]
        childcount = len(target)

        a = c(K - 2, childcount)
        for child in target:
            r = f(child) % MAX
            a = (a * r) % MAX
        return a

    try:
        result = K * c((K - 1), len(childrentable[1]))
        for child in childrentable[1]:
            r = f(child) % MAX
            result = (result * r) % MAX
    except:
        print(0)
        return
    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 136032
#include <iostream>
#include <vector>
using namespace std;
#define MAX_N 60
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int> > G(MAX_N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  for (int i = 1; i <= N; i++) cout << G[i].size() << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<iomanip>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

int retl(int K,int L){
    int tmp=0;
    while(pow(2,tmp) * L < K){
        tmp++;
    }
    return tmp;
}

struct A{
    string s;
    int p;
    int order;
};


int main(){
    int N;
    cin  >> N;
  
    int answer=180*(N-2);

    cout <<answer<<endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			long n = long.Parse(Console.ReadLine());
			for (long i = (long)Math.Floor(Math.Sqrt(n)); i > 0; i--) {
				if (n % i == 0) {
					long x = i;
					long y = n / i;
					System.Diagnostics.Debug.WriteLine($"{x}*{y}={x * y}:{n}");
					Console.WriteLine((x - 1) + (y - 1));
					break;
				}
			}


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 13140
#include <string.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstring>
#include <math.h>
#include <set>
#include <vector>
#include <algorithm>
#include <map>
#pragma warning(disable:4996)

using namespace std;

typedef long long ll;
#define INF 0x3f3f3f3f
#define ESP 1e-8;
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
const double PI = acos(-1.0);
#define N 100005
int a[N], d[N];

int gcd(int x, int y) {
	if (x < y)
		swap(x, y);
	if (x % y == 0)
		return y;
	return gcd(y, x%y);
}

int main() {
	int n, x, i, ans;
	while (scanf("%d%d", &n, &x) != EOF) {
		for (i = 1; i <= n; i++)
			scanf("%d", &a[i]);
		a[++n] = x;
		sort(a + 1, a + 1 + n);
		for (i = 2; i <= n; i++)
			d[i - 1] = a[i] - a[i - 1];
		n--;
		ans = d[1];
		for (i = 2; i <= n; i++)
			ans = gcd(ans, d[i]);
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 1024
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() (int, []int) {
	n := scanInt(sc)
	as := nextIntSlice(sc, n)
	return n, as
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return int(a)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextIntSlice(sc *bufio.Scanner, n int) (a []int) {

	a = make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt(sc)
	}
	return a
}
func resolve(n int, as []int) int {
	dp = make([][]int, len(as))
	for i := 0; i < len(as); i++ {
		dp[i] = make([]int, len(as))
		for j := 0; j < len(as); j++ {
			dp[i][j] = -1
			dp[i][j] = -1
		}
	}
	return _resolve(as, len(as), 0, len(as)-1)
}

var dp [][]int

func _resolve(as []int, n, l, r int) int {
	if dp[l][r] != -1 {
		return dp[l][r]
	}
	pTurn := n - (r - l + 1)
	if l == r {
		if pTurn%2 == 0 {
			dp[l][r] = as[l]
		} else {
			dp[l][r] = -as[l]
		}
		return dp[l][r]
	}
	switch pTurn % 2 {
	case 0:
		dp[l][r] = max(
			_resolve(as, n, l+1, r)+as[l],
			_resolve(as, n, l, r-1)+as[r],
		)
	case 1:
		dp[l][r] = min(
			_resolve(as, n, l+1, r)-as[l],
			_resolve(as, n, l, r-1)-as[r],
		)
	}
	return dp[l][r]
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 77700
/// Swift5 -> Swift2.2
 
extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
extension Array where Element: Comparable {
    // sorted()
    func sorted() -> [Element] {
        return self.sort( { $0 < $1 } )
    }
}
// stride(from:through:by:)
func stride(from start: Int, through end: Int, by stride: Int) -> StrideThrough<Int> {
    return start.stride(through: end, by: stride)
}
// stride(from:to:by)
func stride(from start: Int, to end: Int, by stride: Int) -> StrideTo<Int> {
    return start.stride(to: end, by: stride)
}
extension Range {
    func reversed() -> [Element] {
        return self.reverse()
    }
}
 
/// end
 
 
let input = readLine()!.split(separator: " ").map { Int($0)! }
let N = input[0]
let W = input[1]
 
var dp = Array(repeating: 0, count: W + 1)
 
for _ in 0 ..< N {
    let knapsack = readLine()!.split(separator: " ").map { Int($0)! }
    let weight = knapsack[0]
    let value = knapsack[1]
 
  	var i = W
  	while i >= weight {
        dp[i] = max(dp[i], dp[i - weight] + value)
        i -= 1
    }
}
 
print(dp.last!)

Measured memory_bytes: 4208
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i,c=0;
  string s;
  cin>>n>>s;
  for(i=0;i<n-2;i++) if(s.at(i)=='A' &&s.at(i+1)=='B' &&s.at(i+2)=='C') c++;
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define H 250
int main() {
  int A[H];
  int count, i;

  scanf("%d",&count);
  for( i=1 ; i<=count ; i++) scanf("%d", &A[i]);
  for( i=1 ; i<=count ; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if( i!=1 && i%2==0 ) printf("parent key = %d, ", A[i/2]);
    if( i!=1 && i%2==1 ) printf("parent key = %d, ", A[(i-1)/2]);
    if( i*2-1 < count ) printf("left key = %d, ", A[i*2]);
    if( i*2 < count ) printf("right key = %d, ", A[i*2+1]);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <vector>
#define INF (1<<30)
#define ll long long
using namespace std;

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

ll H, W;
vector<vector<ll>> m(1010, vector<ll>(1010, -1));
vector<vector<ll>> C(1010, vector<ll>(1010, 0));

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	cin >> H >> W;
	for (int i = 1; i <= H;i++) {
		for (int j = 1; j <= W; j++) {
			char c; cin >> c;
			if (c != '.') {
				m[i][j] = c - '0';
			}
			else {
				for (int k = 0;k < 8; k++) {
					C[i + dx[k]][j + dy[k]]++;
				}
			}
		}
	}

	ll res = 0;
	queue<pair<pair<ll, ll>, ll>> q;

	for (int i = 2; i <= H - 1;i++) {
		for (int j = 2; j <= W - 1; j++) {
			if (m[i][j] > 0) {
				if (C[i][j] >= m[i][j]) {
					q.push({ {i,j},1 });
					m[i][j] = -1;
				}
			}
		}
	}

	while (!q.empty()) {
		auto p = q.front(); q.pop();
		res = p.second;
		for (int i = 0; i < 8;i++) {
			int x = p.first.first + dx[i];
			int y = p.first.second + dy[i];
			if (m[x][y] == -1)continue;

			C[x][y]++;

			if (C[x][y] >= m[x][y]) {
				q.push({{ x,y }, res + 1});
				m[x][y] = -1;
			}
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 19212
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    char name[20];
    int vl;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    ll N,M,K;
    scanf("%lld%lld%lld",&N,&M,&K);
    ll a[N],b[M];
    for(ll i=0;i<N;i++){
        scanf("%lld",&a[i]);
    }
    for(ll i=0;i<M;i++){
        scanf("%lld",&b[i]);
    }
    ll wa[N+1];
    ll wb[M+1];
    wb[0]=0;
    wa[0]=0;
    for(int i=0;i<N;i++){
        wa[i+1]=wa[i]+a[i];
    }
    for(int i=0;i<M;i++){
        wb[i+1]=wb[i]+b[i];
    }
    ll j=N;
    ll min=0;
    for(int i=0;i<=M && wb[i]<=K;i++){
        while((wb[i]+wa[j])>K){
            j--;
        }
        if(min<i+j)
            min=i+j;
    }
    printf("%lld",min);
}


Measured memory_bytes: 7976
#include <iostream>
# include <stdio.h>
using namespace std;

int main(){
    int a[10000], b[10000], i=0, temp;
    while(cin >> a[i] >> b[i]){
        if(a[i] == 0 && b[i] == 0) break;
        if(a[i] > b[i]){
            temp = a[i];
            a[i] = b[i];
            b[i] = temp;
        }
        i++;
    }
    for(int j=0; j<i; j++)
        printf("%d %d\n", a[j], b[j]);
}

Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  map <int,int> m;
  while(k--)
  {
    int d;
    cin>>d;
    int arr[d];
    for(int i=0;i<d;i++)
    {
      cin>>arr[i];
      m[arr[i]]++;
    }
  }
  cout<<n-m.size()<<endl;
}


Measured memory_bytes: 3632
max_num = 1000000
cnt = 0
p = [1] * max_num
p[0] = p[1] = 0
for i in xrange(2, int(max_num ** 0.5) + 1):
    if p[i]:
        p[i * i::i] = [0] * len(p[i * i::i])

for i in xrange(max_num):
    cnt += p[i]
    p[i] = cnt

while True:
    try: print(p[int(raw_input())])
    except: break

Measured memory_bytes: 35964
#include<iostream>

using namespace std;

#define MAX_INT 1000

int A[MAX_INT];

int bubbleSort(int*A, int N)
{
    int count=0;
    bool flg =true;

    while(flg)
    {
        flg =false;
        for(int j=N-1;j>0;--j)
        {
            if(A[j] < A[j-1])
            {
                int tmp;
                tmp = A[j-1];
                A[j-1] = A[j];
                A[j]=tmp;
                flg =true;
                count ++;
            }
        }
    }
    for(int k=0;k<N;k++)
    {
        if(k<N-1) cout << A[k] << " ";
        if(k==N-1) cout<< A[k]<<endl;
    }
    
    return count;
}
int main()
{
    int N; cin >>N;

    for(int i =0;i< N; ++i)
    {
        cin >> A[i];
    }

    cout<<bubbleSort(A,N)<<endl;
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>

using namespace std;

#define MP make_pair 
#define PB push_back 
#define PH push

int n;
pair<int,int> x[100100],y[100100];
vector<pair<int,int> > vec[100100];     //距离 位置 
set<pair<int,int> > s;
int visit[100100];
int ans=0;

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int a,b;
		cin>>a>>b;
		x[i]=MP(a,i);
		y[i]=MP(b,i); 
	}
	
	sort(x,x+n);
	sort(y,y+n);
	
//for(int i=0;i<n;i++) cout<<x[i].second<<" "; cout<<endl;
//for(int i=0;i<n;i++) cout<<y[i].second<<" "; cout<<endl; 
	
	for(int i=0;i<n;i++)
	{
		int a=x[i].second;
		if(i) vec[a].PB(MP(x[i].first-x[i-1].first,x[i-1].second));
		if(i!=n-1)vec[a].PB(MP(x[i+1].first-x[i].first,x[i+1].second));
		int b=y[i].second;
		if(i) vec[b].PB(MP(y[i].first-y[i-1].first,y[i-1].second));
		if(i!=n-1) vec[b].PB(MP(y[i+1].first-y[i].first,y[i+1].second));
	}
	
	s.insert(MP(0,0));
	while(s.size())
	{
		int a=s.begin()->first;
		int b=s.begin()->second;
		s.erase(s.begin());
		if(visit[b]) continue;
//cout<<a<<" "<<b<<endl; 
		visit[b]=1;
		ans+=a;
		
		for(int i=0;i<vec[b].size();i++)
		{
//cout<<vec[b][i].second;
			if(visit[vec[b][i].second]) continue;
			s.insert(vec[b][i]); 
		}
	} 
	
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 14464