akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const long long INF = 1LL << 60;

int main()
{
  ll N,D;
  ll d;
  cin >> N >> D;
  
  int res = 0;
  rep(i,N)
  {
    ll x, y;
    cin >> x >> y;
    d = x*x + y*y;
    if(d <= D*D) res++; 
  }
  
  cout << res << endl;
}

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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, M;

struct S {
    int A, B;
};

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

    vector<S> SV(N);
    for (int i = 0; i < N; i++) {
        cin >> SV[i].A >> SV[i].B;
    }

    sort(SV.begin(), SV.end(),
         [](S x, S y) -> int {
             return (x.A < y.A);
         });

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ll n = min(SV[i].B, M);
        M -= n;
        ans += SV[i].A * n;
        if (M == 0) break;
    }

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 1000000000;
typedef pair<int, int> P;
const int MAX_N = 1000000000;
typedef int64_t ll;
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; }



int main() {
	string road;
	cin >> road;
	int no=0, so=0, we=0, ea=0;
	rep(i, road.size()) {
		switch (road.at(i))
		{
		case 'N' :
			no=1;
			break;
		case 'S':
			so=1;
			break;
		case 'W':
			we=1;
			break;
		case 'E':
			ea=1;
			break;
		default:
			break;
		}
	}
	if (no==so && we==ea)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N, V[50], C[50];
  cin >> N;
  int S=0;
  
  for(int i=0; i<N ; i++){
    cin >> V[i];
  }
  for(int i=0; i<N; i++){
    cin >> C[i];
  }
  
  for(int i=0; i<N; i++){
    if(V[i]>C[i]){
      S += (V[i]-C[i]);
    }
    else
      continue;
  }
  
  cout << S << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct node *Node;

struct node{
  int key;
  Node right, left, parent;
};

Node root, NIL;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n, i, x;
  char com[20];

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s",com);
    if(strcmp(com,"insert") == 0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(com,"print") == 0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 25184
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;
vector<pair<int,int>> S[MAX];
int V,dis[MAX];

void DFS(int u){
    for(int i=0;i<S[u].size();i++){
        int a=S[u][i].first;
        if(dis[a]!=INF) continue;
        dis[a]=dis[u]+S[u][i].second;
        DFS(a);
    }
}


int main(){

    cin>>V;
    for(int i=0;i<V-1;i++){
        int a,b,c;cin>>a>>b>>c;
        S[a].push_back(make_pair(b,c));
        S[b].push_back(make_pair(a,c));
    }
    
    for(int i=0;i<V;i++){
        dis[i]=INF;
    }
    dis[0]=0;
    
    DFS(0);
    
    int point=0,maxi=0;
    
    for(int i=0;i<V;i++){
        if(dis[i]>maxi){
            maxi=dis[i];
            point=i;
        }
    }
    
    for(int i=0;i<V;i++){
        dis[i]=INF;
    }
    dis[point]=0;
    
    DFS(point);
    
    int ans=0;
    
    for(int i=0;i<V;i++){
        ans=max(ans,dis[i]);
    }
    
    cout<<ans<<endl;
    
    
    
}




Measured memory_bytes: 13596
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
int n;
std::string x;
std::vector<std::string> s;
std::vector<int> t;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n;
    s.resize(n);
    t.resize(n);
    for (int i = 0; i < n; ++i)
        std::cin >> s[i] >> t[i];
    std::cin >> x;
    std::cout << std::accumulate(std::find(s.begin(), s.end(), x) - s.begin() + 1 + t.begin(), t.end(), 0) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,a[100009],L[100009],R[100009],M;

int gcd(int x,int y){
    if(x>y){
        int t=x;
        x=y;
        y=t;
    }
    if(x==0) return y;
    return gcd(y%x,x);
}

int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++){
        L[i]=gcd(L[i-1],a[i]);
    }for(int i=n;i;i--){
        R[i]=gcd(R[i+1],a[i]);
    }
    for(int i=1;i<=n;i++){
        M=max(M,gcd(L[i-1],R[i+1]));
    }
    cout<<M;
}

Measured memory_bytes: 1408
n=int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
l=make_divisors(n)
ans=10**18
for i in l:
    j=n//i
    ans=min(ans,i+j-2)
print(ans)

Measured memory_bytes: 3280
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

struct rest {
	ll id;
	string s;
	ll p;
};

bool cmp(rest a, rest b) {
	if (a.s == b.s) { return a.p > b.p; }
	return a.s < b.s;
}


int main() {

	ll A, P;
	cin >> A >> P;

	cout << (3 * A + P) / 2;


	system("PAUSE");

	

}


Measured memory_bytes: 504
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  (n, h, w) = InputLine.to_ia

  c = 0
  n.times do |i|
    (a, b) = InputLine.to_ia
    c += 1 if ((a >= h) and (b >= w))
  end
  puts c.to_s
end

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

Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>
#include <iomanip>

using namespace std;

using ll = long long;

typedef pair<int, int> P;

#define rep(i,N) for(long long i = 0;i < (long long)N; ++i)

static int mod = 1000000007;
static int large = 1000000000;

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

int a, b, k;
int cnt = 0;
int ans;
int num[100];

int main() {
	cin >> a >> b >> k;
	for (int i = 1; i < 101; i++) {
		if (i > a || i > b) {
			break;
		}
		if (a % i == 0 && b % i == 0) {
			num[cnt] = i;
			cnt++;
		}
	}
	sort(num, num + cnt);
	cout << num[cnt - k] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  //
  ll a, b;
  cin >> a >> b;
  ll k = 50;
  vector<string> data(2 * k, string(2 * k, '.'));
  rep(i, k) {
    rep(j, 2 * k) { data[i][j] = '#'; }
  }
  ll black = 0, white = 0;
  while (white < a - 1) {
    int i = white / (k / 2);
    int j = 4 * (white % (k / 2)) + 2 * (i & 1);
    data[i][j] = '.';
    white++;
  }
  while (black < b - 1) {
    int i = 2 * k - 1 - (black / (k / 2));
    int j = 4 * (black % (k / 2)) + 2 * (i & 1);
    data[i][j] = '#';
    black++;
  }
  cout << 100 << " " << 100 << endl;
  rep(i, 2 * k) {
    rep(j, 2 * k) { cout << data[i][j]; }
    cout << endl;
  }
  return 0;
}


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

int main(){
	string T="ACGT", S; cin>>S;
	vector<int> A(S.size());
	int maxi = A[0] = T.find(S[0])<T.size()? 1: 0;
	for(int i=1; i<S.size(); ++i){
		A[i] = T.find(S[i])<T.size()? A[i-1]+1: 0;
		maxi = max(maxi, A[i]);
	}
	cout<< maxi <<endl;
}

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

template <typename T>
struct weighted_Union_Find {
	int n;
	vector<int> tree;
	vector<T> ws;
	
	weighted_Union_Find(int n) : n(n), tree(n, -1), ws(n, 0) {
		
	}
	
	int size(int x) {
		assert(0 <= x && x < n);
		return -tree[root(x)];
	}
	
	T weight(int x) {
		assert(0 <= x && x < n);
		root(x);
		return ws[x];
	}
	
	int root(int x) {
		assert(0 <= x && x < n);
		if (tree[x] < 0) {
			return x;
		}
		int r = root(tree[x]);
		ws[x] += ws[tree[x]];
		return tree[x] = r;
	}
	
	bool same(int x, int y) {
		assert(0 <= x && x < n && 0 <= y && y < n);
		return root(x) == root(y);
	}
	
	//x - y
	T diff(int x, int y) {
		assert(0 <= x && x < n && 0 <= y && y < n);
		return weight(x) - weight(y);
	}
	
	//x + w == y
	bool merge(int x, int y, T w) {
		assert(0 <= x && x < n && 0 <= y && y < n);
		w += weight(x);
		w -= weight(y);
		x = root(x);
		y = root(y);
		if (x == y) {
			return false;
		}
		if (tree[x] > tree[y]) {
			swap(x, y);
			w = -w;
		}
		tree[x] += tree[y];
		tree[y] = x;
		ws[y] = w;
		return true;
	}
};

int main() {
	int64_t n, m;
	cin >> n >> m;
	int64_t l[m], r[m], d[m];
	for (int i = 0; i < m; i++) {
		cin >> l[i] >> r[i] >> d[i];
		l[i]--;
		r[i]--;
	}
	weighted_Union_Find<int64_t> w_uf(n);
	for (int i = 0; i < m; i++) {
		if (w_uf.same(l[i], r[i])) {
			if (w_uf.diff(r[i], l[i]) != d[i]) {
				cout << "No" << endl;
				return 0;
			}
		} else {
			w_uf.merge(l[i], r[i], d[i]);
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF 2 << 29
#define MOD 1000000007
#define Yes(f) puts((f)? "Yes" : "No")
#define YES(f) puts((f)? "YES" : "NO")
int gcd(int a, int b) {
	if (b != 0)return gcd(b, a % b);
	return a;
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

using Graph = vector<vector<int>>;

int main(){
	ll k; cin >> k;
	ll sum = 0;
	rep(i, k){
		rep(j, k){
			rep(l, k){
				sum += gcd(i + 1, gcd(j + 1, l + 1));
			}
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 3640
def primes(N):
    p = [False, False] + [True] * (N - 1)
    for i in range(2, int(N ** 0.5) + 1):
        if p[i]:
            for j in range(i * 2, N + 1, i):
                p[j] = False
    return p


p, c = primes(10 ** 5), [0]
for i in range(1, 10 ** 5 + 1):
    c.append(c[-1] + 1 if p[i] and p[(i + 1) // 2] else c[-1])

Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    print(c[r] - c[l - 1])


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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    long ans = 0;
    int min = 2000000000;
    int count = 0;
    for(int i=0;i<n;i++){
        if(a[i] < 0){
            count++;
            ans += (-a[i]);
            if(min > (-a[i])){
                min = (-a[i]);
            }
        }
        else{
            ans += a[i];
            if(min > a[i]){
                min = a[i];
            }
        }
    }
    if(count%2 == 0){
        cout << ans << endl;
    }
    else{
        ans = ans - 2*min;
        cout << ans << endl;
    }
}

Measured memory_bytes: 640
import sys
import itertools
from itertools import accumulate
def main():
    input = sys.stdin.readline
    def inputs():
        return [int(x) for x in input().split()]
    A1= tuple(input())
    dp = [[0]*2 for _ in range(len(A1)+1)]
    dp[0][0]=1
    for i in range(len(A1)):
        if A1[i]=="1":
            dp[i+1][0]=max(dp[i+1][0],dp[i][0]*2)%(10**9+7)
            dp[i+1][1]=max(dp[i+1][1],dp[i][1]*3+dp[i][0])%(10**9+7)
        else:
            dp[i+1][0]=max(dp[i+1][0],dp[i][0])%(10**9+7)
            dp[i+1][1]=max(dp[i+1][1],dp[i][1]*3)%(10**9+7)
    #print(dp[len(A1)][0]+dp[len(A1)][1]-len(A1)**2)
    print((dp[len(A1)-1][0]+dp[len(A1)-1][1])%(10**9+7))
main()

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

int main() {
    int n, k;
    cin >> n >> k;
    int x;
    double ans = 0;
    for (int i = 1; i <= n; i++) {
        x = i;
        int cnt = 0;
        while (x < k) {
            x *= 2;
            cnt++;
        }
        ans += pow(0.5, cnt);
    }
    ans = ans / n;
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 4136
import sys
import heapq
heappush = heapq.heappush
heappop = heapq.heappop
heapreplace = heapq.heapreplace
input = sys.stdin.readline

D = int(input())
cost = list(map(int, input().strip().split()))
S = [list(map(int, input().strip().split())) for _ in range(D)]
k = 26
last_held = [[-1 for i in range(26)] for _ in range(k)]
ans = [[] for _ in range(k)]
for date, daily_scores in enumerate(S):
    max_score = []
    minus_scores = []
    for state in range(k):
        minus_score = 0
        for i in range(26):
            minus_score += cost[i] * (date - last_held[state][i])

        for i in range(k-len(max_score)):
            tmp = daily_scores[i] + cost[i] * (date - last_held[state][i])
            heappush(max_score, (tmp, i, state))

        for i, daily_score in enumerate(daily_scores):
            if state == 0 and i < k:
                continue
            tmp = daily_score + cost[i] * (date - last_held[state][i])
            if max_score[0][0] < tmp:
                heapreplace(max_score, (tmp, i, state))
    if date != D-1:
        #print(max_score)
        next_last_held = []
        next_ans = []
        for score, i, state in max_score:
            next_last_held.append(last_held[state][:])
            next_last_held[-1][i] = date
            next_ans.append(ans[state][:])
            next_ans[-1].append(i+1)
        ans = next_ans
        last_held = next_last_held
    else:
        score, i, state = max(max_score)
        next_ans = ans[state][:]
        next_ans.append(i+1)
        ans = next_ans

print("\n".join(map(str, ans)))


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

#define ONLINE_JUDGE

using namespace std;
#ifndef ONLINE_JUDGE
#define wi(x) cerr << #x << ": " << (x) << '\n';
#else
#define wi(x)
#endif


typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
template<typename T>
inline T getNum() {
    T k = 0;
    int c = getchar(), f = 1;
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
    for (; isdigit(c); c = getchar()) k = k * 10 + c - '0';
    return k * f;
}
#define gn() getNum<int>()
#define gl() getNum<ll>()
clock_t opt, edt;
inline void init() {
#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
//    freopen("../input.txt", "w", stdout);
    opt = clock();
#endif
}

inline void tini() {
#ifndef ONLINE_JUDGE
    edt = clock();
    cerr << "\n#cost: " <<  (double)(edt - opt) / CLOCKS_PER_SEC << "s\n";
#endif
}

int main() {
    init();
///////////////////////////////////////////////////////////////////////////////

    int a = gn(), b = gn();
    cout  << (a *(a - 1)) / 2 + (b * (b - 1)) / 2;











///////////////////////////////////////////////////////////////////////////////
    tini();
}



/*
char Ma[MAXN*2];
int Mp[MAXN*2];
void Manacher(char s[],int len){
    int l=0;
    Ma[l++]='$';
    Ma[l++]='#';
    for(int i=0;i<len;i++){
        Ma[l++]=s[i];
        Ma[l++]='#';
    }
    Ma[l]=0;
    int mx=0,id=0;
    for(int i=0;i<l;i++){
        Mp[i]=mx>i?min(Mp[2*id−i],mx−i):1;
        while(Ma[i+Mp[i]]==Ma[i−Mp[i]])Mp[i]++;
        if(i+Mp[i]>mx){
            mx=i+Mp[i];
            id=i;
        }
    }
}
*/
 /*
 * * abaaba
 * * i:     0 1 2 3 4 5 6 7 8 9 10 11 12 13
 * * Ma[i]: $ # a # b # a # a # b  #  a  #
 * * Mp[i]: 1 1 2 1 4 1 2 7 2 1 4  1  2  1
 */
 /*
char s[MAXN];
int main(){
    while(scanf("%s",s)==1){
        int len=strlen(s);
        Manacher(s,len);
        int ans=0;
        for(int i=0;i<2*len+2;i++)
            ans=max(ans,Mp[i]−1);
        printf("%d\n",ans);
    }
    return 0;
}
*/

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		List<Long> list_p = new LinkedList<>();
		List<Long> list_n = new LinkedList<>();
		long ans = 0;
		long p_min = Integer.MAX_VALUE;
		long n_max = Integer.MIN_VALUE;
		for(int i=0;i<n;i++) {
			long tmp = in.nextInt();
			if(tmp>=0) {
				if(tmp<p_min) p_min = tmp;
				list_p.add(tmp);
				ans += tmp;
			}else {
				if(tmp>n_max) n_max = tmp;
				list_n.add(tmp);
				ans -= tmp;
			}
		}
		if(list_p.size()==0) ans += 2*n_max;
		if(list_n.size()==0) ans -= 2*p_min;
		System.out.println(ans);
		while(list_n.size()+list_p.size()>1) {
			if(list_n.size()==0 && n!=2) {
				long b = list_p.remove(list_p.indexOf(p_min));
				long a = list_p.remove(0);
				list_n.add(-a+b);
				System.out.println(b + " " + a);
			}else if(list_n.size()==0 && n==2){
				long b = list_p.remove(list_p.indexOf(p_min));
				long a = list_p.remove(0);
				list_p.add(a-b);
				System.out.println(a + " " + b);
			}else if(list_p.size()==0) {
				long b = list_n.remove(list_n.indexOf(n_max));
				long a = list_n.remove(0);
				list_p.add(-a+b);
				System.out.println(b + " " + a);
			}else {
				long a = list_p.get(0);
				long b = list_n.get(0);
				if(list_p.size()<=list_n.size()) {
					list_p.add(a-b);
					System.out.println(a + " " + b);
				}else {
					list_n.add(-a+b);
					System.out.println(b + " " + a);
				}
				list_p.remove(0);
				list_n.remove(0);
			}
		}
		
		in.close();

	}

}


Measured memory_bytes: 83908
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define MOD 1000000007

ll dp[100000];
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,i,ans=0;
	cin>>n;
	ll a[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	for(i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 5160
/**
 *    author:  tourist
 *    created: 15.09.2018 15:51:30       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long X;
  cin >> n >> X;
  vector<long long> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  vector<long long> s(n + 1);
  s[0] = 0;
  for (int i = 0; i < n; i++) {
    s[i + 1] = s[i] + x[i];
  }
  long long ans = (long long) 9e18;
  for (int k = 1; k <= n; k++) {
    long long cur = 0;
    long long coeff = 3;
    for (int i = n; i > 0; i -= k) {
      cur += (s[i] - s[max(0, i - k)]) * max(coeff, 5LL);
      coeff += 2;
      if (cur >= ans) {
        break;
      }
    }
    cur += (k + n) * X;
    ans = min(ans, cur);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3328
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    N = int(input().rstrip())
    S1 = (input().rstrip())
    S2 = (input().rstrip())
    S3 = (input().rstrip())
    cnt = 0
    for x in range(N):
        ic = 0
        if(S1[x] == S2[x]):
            ic += 1
        if(S3[x] == S2[x]):
            ic += 1
        if(S1[x] == S3[x]):
            ic += 1    

        if(ic == 1):
            cnt += 1
        elif(ic < 1):
            cnt += 2
        else:
            cnt += 0
    
    print(cnt)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 3944
n = int(input())
s = input().strip()

is_zoo = False
start = 'SS'
for _s in s[1:-1]:
  if start[-1] == 'S':
    if _s == 'o':
      start += start[-2]
    else:
      start += 'S' if start[-2] == 'W' else 'W'
  else:
    if _s == 'x':
      start += start[-2]
    else:
      start += 'S' if start[-2] == 'W' else 'W'
if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'o') or \
  (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'o') or \
  (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'x') or \
  (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'x'):
  print(start)
  is_zoo = True

start = 'SW'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'x') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'x') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'o') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'o'):
    print(start)
    is_zoo = True

start = 'WS'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'x') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'x') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'o') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'o'):
    print(start)
    is_zoo = True

start = 'WW'
if not is_zoo:
  for _s in s[1:-1]:
    if start[-1] == 'S':
      if _s == 'o':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
    else:
      if _s == 'x':
        start += start[-2]
      else:
        start += 'S' if start[-2] == 'W' else 'W'
  if (start[-1] == 'S' and s[-1] == 'o' and start[-2] == 'W' and s[0] == 'o') or \
    (start[-1] == 'S' and s[-1] == 'x' and start[-2] == 'S' and s[0] == 'o') or \
    (start[-1] == 'W' and s[-1] == 'o' and start[-2] == 'S' and s[0] == 'x') or \
    (start[-1] == 'W' and s[-1] == 'x' and start[-2] == 'W' and s[0] == 'x'):
    print(start)
    is_zoo = True

if not is_zoo:
  print(-1)


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

int abs(int a){
  if(a<0){
    return a*(-1);
  }else{
    return a;
  }
}

int main(){
  int n;
  cin>>n;
  int t[n],x[n],y[n];
  for(int i=0;i<n;i++){
    cin>>t[i]>>x[i]>>y[i];
  }
  int pre_x=0;
  int pre_y=0;
  int pre_t=0;
  for(int i=0;i<n;i++){
    if(((t[i]-pre_t)-((abs(x[i]-pre_x)+abs(y[i]-pre_y))))%2!=0){
      cout<<"No"<<endl;
      return 0;
    }
    if(t[i]-pre_t<abs(x[i]-pre_x)+abs(y[i]-pre_y)){
      cout<<"No"<<endl;
      return 0;
    }
    pre_t=t[i];
    pre_x=x[i];
    pre_y=y[i];
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	int l = 0, r = N;
	for (int i = 0; i < M; i++) {
		int L, R;
		cin >> L >> R;
		l = max(l, L);
		r = min(r, R);
	}
	if (l <= r) cout << r - l + 1 << endl;
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 3600
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const ll mod = LLONG_MAX;

int main() {
	int n, k, x, y;
	cin >> n;
	cin >> k;
	cin >> x;
	cin >> y;
	int count=0;
	rep(i, 1, n+1) {
		if (i > k) { count += y;}
		else { count += x; }
	}
	print(count);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using pll = pair<ll,ll>;
using vll = vector<pll>;

#define VAL first
#define IDX second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

struct UnionFind {
    vector<int> data;
   
    UnionFind(int sz) {
        data.assign(sz, -1);
    }
   
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }
   
    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }
   
    int size(int k) {
        return (-data[find(k)]);
    }
};

int main() {
    int n; cin >> n;
    vl a(n), b(n);
    vll a_sorted(n), b_sorted(n);
    rep(i,n) {
        cin >> a[i];
        a_sorted[i] = pll(a[i], i);
    }
    rep(i,n) {
        cin >> b[i];
        b_sorted[i] = pll(b[i], i);
    }
    sort(all(a_sorted));
    sort(all(b_sorted));
    rep(i,n) if (a_sorted[i].VAL > b_sorted[i].VAL) {
        cout << "No" << endl;
        return 0;
    }
    
    int cnt = 0;
    UnionFind uf(n);
    rep(i,n) uf.unite(a_sorted[i].IDX, b_sorted[i].IDX);
    rep(i,n) cnt += (uf.find(i) == i);
    if (cnt > 1) {
        cout << "Yes" << endl;
        return 0;
    }
    rep(i,n-1) {
        if (a_sorted[i+1].VAL <= b_sorted[i].VAL) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;
 
string query(int num){
    cout<<num<<endl;
    fflush(stdout);
    string s;
    cin>>s;
    return s;
    
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    string vac="Vacant";
    
    if(n==3){
        for(int i=0; i<2; i++){
            string s=query(i);
            if(s==vac) return 0;
        }
    }
    
    int l=2, r=n-1;
    string lval=query(l);
    if(lval==vac) return 0;
    string rval=query(r);
    if(rval==vac) return 0;
    if(lval ==rval){
        string s=query(0);
        if(s==vac) return 0;
        s=query(1);
        if(s==vac) return 0;
    }
    
    while(1){
        int mid=l+r>>1;
        if((mid%2)!=(r%2)) mid++;
        if(mid==r){
            query(r-1);
            return 0;
        }
        
        string midVal=query(mid);
        if(midVal==vac) return 0;
        if(midVal==lval) l=mid;
        else r=mid;
    }
    
    
    
    
    
    
    
    
  
    return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

int N;

void solve() {
    cin >> N;
    int o = 0;
    int m4 = 0;
    rep(i,N) {
        int a;
        cin >> a;
        if (a % 2 == 1) o++;
        if (a % 4 == 0) m4++;
    }
    if (o == m4 + 1 && o + m4 == N) {
        cout << "Yes" << endl;
    } else if (o <= m4) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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


Measured memory_bytes: 256
s = input()
ans = [0,0]
if 1 <=  int(s[:2]) <= 12:
    ans[0] = 1
if 1 <= int(s[2:]) <= 12:
    ans[1] = 1
print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][ans[0]][ans[1]])

Measured memory_bytes: 9172
#include <cstdio>
#include <vector>
#include <algorithm>

#define MAX 1000000

typedef long int li;

int main()
{
	li N, side, i=0;
	// std::vector<li> ans;
	scanf("%ld", &N);
	while(N>(i*i)){
		i++;
		if(N%i==0){
			side = i;
		}
	}

	li ans = (side-1) + (N/side-1);
	// li b = (ans[num-1]-1) + (N/ans[num-1]-1);
	// a = std::min(a,b);
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
#define MAX 50000

bool prime[MAX];

void is_prime(){
    fill(prime,prime+MAX,true);
    prime[0] = prime[1] = false;
    
    for(int i = 2 ; i*i < MAX ; i++)
        if(prime[i])
            for(int j = 2*i ; j < MAX ; j += i)
                prime[j] = false;
}

int main(){
    int n;
    is_prime();
    while(cin >> n,n){
        int cnt = 0;
        
        for(int i = 2 ; i <= n/2 ; i++){
            if(prime[i]&&prime[n-i]) cnt++;
        }
        cout << cnt << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
using namespace std;

int main()
{
	int N, A;
	cin >> N >> A;
	if (A - N % 500 >= 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
n,y = map(int,input().split())
for i in range(n+1):
  for j in range(n+1):
    if (y - 1000*i - 5000*j)/10000 == n-i-j and n-i-j>=0:
      print(n-i-j,j,i)
      exit()
print(-1,-1,-1)

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

int main() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int h;
        cin >> h;
        if (h >= k) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return b.second > a.second;
    }
    return a.first < b.first;
}

ll arr[1000010];
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(6);

    int n, m;
    while (cin >> n >> m)
    {
        if (n == 0 && m == 0)
            break;

        int arr[1010] = {0};

        vector<int> v;
        int cnt = 0;
        int idx = 0;
        while ((int)v.size() != n)
        {
            if (arr[idx] == 0)
            {
                cnt++;
            }
            if (cnt == m)
            {
                arr[idx] = 1;
                v.push_back(idx);
                cnt = 0;
            }
            idx++;
            idx %= n;
        }
        cout << v[v.size() - 1] + 1 << endl;
    }
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<pair<int, int>, int> PP;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
//------------------------------------------------------------------------------------------------------------------------------

int N, M;
bool on[20];
vector<int> p(20);
vector<int> V[20];

int func(int s) {
    int ret = 0;
    if (s == N) {
        bool flag = true;
        for (int i = 0; i < M; i++) {
            int sz = V[i].size();
            int cnt = 0;
            for (int j = 0; j < sz; j++) {
                if (on[V[i][j]]) cnt++;
            }
            if (cnt % 2 != p[i]) flag = false;
        }
        if (flag) return 1;
        return 0;
    }
    on[s] = true;
    ret += func(s + 1);
    on[s] = false;
    ret += func(s + 1);
    return ret;
}
int main(void) { 
    cin >> N >> M; 
    for(int i = 0; i < M; i++) {
        int k;
        cin >> k;
        for(int j = 0; j < k; j++) {
            int s;
            cin >> s;
            s--;
            V[i].push_back(s);
        }
    }
    for(int i = 0; i < M; i++) {
        int t;
        cin >> t;
        p[i] = t;
    }
    cout << func(0) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<cctype>
using namespace std;
int k,s,ans;
int main()
{
    scanf("%d%d",&k,&s);
    for(int x=0;x<=k;x++)
    {
        for(int y=0;y<=k;y++)
        {
            if(s-x-y>=0&&s-x-y<=k) ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define INF 1<<30
#define mp make_pair

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

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

	vector<int> v(2*n);
	rep(i, 2*n) cin >> v[i];

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

	int ans = 0;
	rep(i, 2*n) {
		if(i % 2 == 1) continue;
		ans += v[i];
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
  int n,m;
  cin>>n>>m;
  vector<int> ac(n),pena(n);
  for(int i=0;i<m;i++){
    int num;
    string str;
    cin>>num>>str;
    num--;
    if(ac[num]) continue;
    if(str=="AC"){
      ac[num] =1;
    }else {
      pena[num]++;
    }
  }
  int AC=0,PENA=0;
  for(int i=0;i<n;i++){
    AC+=ac[i];
    if(ac[i]) PENA+=pena[i];
  }
  cout<<AC<<" "<<PENA<<endl;
  return 0;
}
  
    
  
  
  
  
  


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<array>
#include<vector>
#include<set>
#include <utility>
#include <map>
#include<queue>
using namespace std;
const long long INF = 1LL<<60;


int main(){
  int n; cin>>n; int k; cin>>k;
  int h[110000];
  for(int i=0;i<n;i++)
  cin>>h[i];
  long long res=INF;
  long long  dp[110000];
  dp[0]=0;dp[1]=abs(h[1]-h[0]);
  for(int i=2;i<n;i++){
    dp[i]=99999999999999999;
    for(int j=1;j<=k;j++)
    if(i-j>=0) {dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));}
  }
  cout<<dp[n-1]<<endl;


}


Measured memory_bytes: 1408
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long ans = Long.MAX_VALUE;
		int N = I.nextInt();
		long[] pref = new long[N+1];
		for (int i = 1; i <= N; i++) {
			pref[i]=pref[i-1];
			pref[i]+=I.nextLong();
			//O.p(pref[i]+" ");
		}
		for (int cur = 0; cur <= N; cur++) {
			int L = cur;
			int R = N-cur;
			long Rsum = pref[N]-pref[L];
			long curans = Math.abs(Rsum-pref[L]);
			//O.pln(curans);
			ans=Math.min(curans,ans);
		}
		O.pln(ans);
	}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 55976
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int count = 0;
        int min = a[0];
        int ans = 0;
        for (int i = 0; i < i - 1; i++) {
            min = Math.min(a[i], a[i + 1]);
        }
        boolean flag = true;
        while (flag) {
            count = 0;
            for (int i = 0; i < n; i++) {
                if (a[i] % 2 == 0) {
                    count++;
                    a[i] /= 2;
                } else {
                    flag = false;
                    break;

                }

            }
            if (count == n) {
                ans++;
            }
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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_MAX	2,147,483,647 = 2*1.0e9

int main(){
  int A, B;
  cin >> A >> B;
  int sum = A+B;
  if(sum%2 == 1){
    cout << "IMPOSSIBLE" << endl;
  } else {
    cout << sum/2 << endl;
  }

  return 0;
}



Measured memory_bytes: 888
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
5 4
0 1
1 2
2 3
3 4

output:
0 1
1 2
2 3
3 4
"""

import sys

sys.setrecursionlimit(int(1e5))


def dfs_Tarjan(current, visited, parent, low, disc):
    global timer
    children = 0
    visited[current] = True
    disc[current] = timer
    low[current] = timer
    timer += 1

    for adj in adj_table[current]:
        if not visited[adj]:
            parent[adj] = current
            children += 1
            dfs_Tarjan(adj, visited, parent, low, disc)
            low[current] = min(low[current], low[adj])
            if low[adj] > disc[current]:
                ans.append(sorted([current, adj]))
        elif adj != parent[current]:
            low[current] = min(low[current], disc[adj])

    return None


def dfs_init():
    visited = [False] * v_num
    disc = [float("Inf")] * v_num
    low = [float("Inf")] * v_num
    parent = [-1] * v_num

    for v in range(v_num):
        if not visited[v]:
            dfs_Tarjan(v, visited, parent, low, disc)

    return ans


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    v_num, e_num = map(int, _input[0].split())
    edges = map(lambda x: x.split(), _input[1:])
    adj_table = tuple([] for _ in range(v_num))
    for v_info in edges:
        source, target = map(int, v_info)
        adj_table[source].append(target)
        adj_table[target].append(source)

    timer = 0
    ans = list()

    dfs_init()
    # ans.sort()
    for ele in sorted(ans):
        print(*ele)

Measured memory_bytes: 23780
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int X, Y;
	cin >> X >> Y;

	for (int i = 0; i < 100; i++)
	{
		for (int j = 0; j < 100; j++)
		{
			if (i + j == X && i * 2 + j * 4 == Y)
			{
				cout << "Yes";
				return 0;
			}
		}
	}

	cout << "No";

	return 0;
}


Measured memory_bytes: 3652
use v5.18; # strict say state
use warnings;

chomp (my ($r, $g, $b, $n) = split / /, <STDIN>);
my $ans = 0;
for my $i (0..$n) {
  last if $r * $i > $n;
  for my $j (0..$n) {
    last if $r * $i + $g * $j > $n;
    my $c = $n - $r * $i - $g * $j;
    $ans++ if $c % $b == 0;
  }
}
say $ans;

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
  int N,M;
  cin >> N >> M;
  int sum=0;
  for(int i=0;i<M;i++){
    int tmp = 0;
     cin >> tmp;
     sum+= tmp;
  }
  if(N-sum>=0) cout << N-sum << endl;
  else cout << -1 << endl;
  return 0;
}

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

int main() {
  vector<int> vec(3);
  for(int i=0; i < 3; i++) {
    cin >> vec.at(i);
  }
  if (count(vec.begin(),vec.end(),5) == 2 && count(vec.begin(),vec.end(),7) == 1) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int all[3];
    
    cin >> all[0] >> all[1] >> all[2];
    sort(all, all + 3);
    
    if(all[0] == all[1]){
    	if(all[1] == all[2]) cout << "No";
    	if(all[1] != all[2]) cout << "Yes";
	}
	if(all[0] != all[1]){
		if(all[1] != all[2]) cout << "No";
		if(all[1] == all[2]) cout << "Yes";
	}

	return 0;
}



Measured memory_bytes: 256
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();
		int l = sc.nextInt();
		int vecnm[][] = new int[n][m];
		int vecml[][] = new int[m][l];
		int i,j,k;
		long veca[][] = new long[n][l];
		
		for(i=0;i<n;i++){
			for(j=0;j<m;j++){
				vecnm[i][j] = sc.nextInt();
			}
		}
		for(i=0;i<m;i++){
			for(j=0;j<l;j++){
				vecml[i][j] = sc.nextInt();
			}
			
		}
		sc.close();
		
		for(i=0;i<n;i++){
			for(j=0;j<l;j++){
				for(k=0;k<m;k++){
					veca[i][j]+=vecnm[i][k]*vecml[k][j];
				}
			}
		}
		for(i=0;i<n;i++){
			for(j=0;j<l;j++){
				System.out.print(veca[i][j]);
				if(j!=(l-1)){
					System.out.print(" ");
				}
			}
			//if(i!=(n-1)){
				System.out.println();
			//}
		}
	}

}


Measured memory_bytes: 53296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int n,x,t;
  string s;
  cin >> n >> x >> t;
  cout << ((n + x -1)/x )* t << endl; 


  return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
#define MAX 100000

int partition(int p,int r);

int A[MAX],n;

int main(){
  int i,q;

  scanf("%d",&n);
  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }

  q = partition(0,n - 1);

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

  return 0;
}

int partition(int p,int r){
  int x,i,j,t;
  
  x = A[r];
  i = p-1;
  for(j = p;j <= r-1;j++){
    if(A[j] <= x){
      i = i + 1;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i + 1;
}
  



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

using namespace std;

int main()
{
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    vector<int> v(3, 0);
    char c = sa[v[0]++];

    while (true) {
        if (c == 'a') {
            if (v[0] >= sa.size()) {
                cout << "A" << endl;
                break;
            } else {
                c = sa[v[0]++];
            }
        } else if (c == 'b') {
            if (v[1] >= sb.size()) {
                cout << "B" << endl;
                break;
            } else {
                c = sb[v[1]++];
            }
        } else {
            if (v[2] >= sc.size()) {
                cout << "C" << endl;
                break;
            } else {
                c = sc[v[2]++];
            }
        }
    }

    return 0;
}


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

public class Main {
    public static PrintWriter out;
    public static FastScanner in;

    private void solve(){
        int W = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();

        int ax = a+W;
        int bx = b+W;

        if(a < b && ax <= b){
            out.print(b-ax);
            return;
        }

        if(b < a && bx <= a){
            out.print(a-bx);
            return;
        }
        out.print(0);
    }

    private void runIO() {
        in = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        solve();
        out.close();
    }
    private static class FastScanner {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private FastScanner() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

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

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

        private String nextLine() {
            String ret = "";
            try {
                ret = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
int x,y;
int main () {
	cin >> x >>y;
if (x==1 || x==3 || x==5||x==7||x==8||x==10||x==12) {
	if (y==1 || y==3 || y==5||y==7||y==8||y==10||y==12) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
} else if(x==2) {
	if (y==2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
} else {
	if (y==4||y==6||y==9||y==11) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

}



Measured memory_bytes: 256