akhauriyash/Code-Regression huggingface dataset:
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scd(x) scanf("%lf", &x)
#define scld(x) scanf("%Lf", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

const int sz = 1e6+5;
const ll MD = 1e9+7;

inline ll MUL(ll a, ll b) {
	return (a * b) % MD;
}

inline ll ADD(ll a, ll b) {
	b %= MD;
	b += MD;
	b %= MD;
	return (a + b) % MD;
}

inline ll powMod(ll a, ll p) {
	ll res = 1;
	for (; p; p >>= 1, a = MUL(a, a)) {
		if (p & 1) res = MUL(res, a);
	}
	return res;
}

ll fac[sz];
ll inv[sz];

void PreCompute() {
	fac[0] = 1;
	for (int i = 1; i < sz; ++i) {
		fac[i] = MUL(fac[i-1], i);
	}
	inv[sz-1] = powMod(fac[sz-1], MD-2);
	for (int i = sz-2; i >= 0; --i) {
		inv[i] = MUL(inv[i+1], i+1);
	}
}

inline ll C(ll n, ll k) {
	if (k > n) return 0;
	return MUL(fac[n], MUL(inv[k], inv[n-k]));
}

int main() {
	PreCompute();
	int N, K;
	sci(N), sci(K);
	vll dat(N);
	for (int i = 0; i < N; ++i) {
		scll(dat[i]);
	}
	VSORT(dat);
	reverse(ALL(dat));
	ll tot = 0;
	for (int i = 0; i < N-1; ++i) {
		tot = ADD(tot, MUL(dat[i], C(N-1-i, K-1)));
	}
	reverse(ALL(dat));
	for (int i = 0; i < N-1; ++i) {
		tot = ADD(tot, -MUL(dat[i], C(N-1-i, K-1)));
	}
	tot %= MD;
	tot += MD;
	tot %= MD;
	printf("%lld\n", tot);
	return 0;
}

Measured memory_bytes: 16640
#include<stdio.h>

int main(void){
	int x[10000],i;
	
	i=0;
	while(1){
		scanf("%d",&x[i]);
		if(x[i]==0){
			break;
		}
		printf("Case %d: %d\n",i+1,x[i]);
		i++;
	}
	return 0;
}

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

int main (){
	int a,b;cin>>a>>b;
	int x[201];
	int ans=0;
	for(int i=1;i<=a;i++){
		x[i]=b+i-1;
		ans+=x[i];
	}
	if(x[1]>0)ans-=x[1];
	if(x[a]<0)ans-=x[a];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
    int i,j,n;
    double sar[1001];
    double ave,sdiv;
    
    while(1){
        
        ave=0;
        sdiv=0;
        
        scanf("%d",&n);
        if(n==0) break;
        
        for(i=0;i<n;i++){
            scanf("%lf",&sar[i]);
            ave+=sar[i]/n;
        }    
        
        for(j=0;j<n;j++){
            sdiv+=pow(sar[j]-ave,2)/n;
        }
        
        printf("%f\n",sqrt(sdiv));
    }
    return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
        char stra[10000],strb[10000];
        scanf("%s%s",stra,strb);

        int lena = strlen(stra);
        int lenb = strlen(strb);

        if (lena > lenb){
                printf("GREATER\n");
        }
        else if (lena < lenb){
                printf("LESS\n");
        }
        else if (lena == lenb){
                int i;
                for (i = 0; i <lena; i++){
                        if (stra[i] - '0' > strb[i] - '0'){
                                printf("GREATER\n");
                                break;
                        }
                        else if (stra[i] - '0' < strb[i] - '0'){
                                printf("LESS\n");
                                break;
                        }
               }
                if (i == lena)
                        printf("EQUAL\n");
        }
        return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
  int x,y,d;
 
  scanf("%d%d", &x, &y);
  while(1){
    if( y==0 )break;
    d = x%y;
    x = y;
    y = d;
  }
  printf("%d\n",x);
  return 0;
}

Measured memory_bytes: 1792
// problem-type?
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int gcd(int a, int b){
    if(a == 0) return b;
    if(a == 1 || b == 1) return 1;
    return gcd(max(a, b) % min(a, b), min(a, b));
}

void solve(){
    int k;
    cin >> k;
    k++;
    int table[k+5][k+5] = {};
    ll sum = 0;
    for(int i=1; i<k; ++i){
        for(int j=i; j<k; ++j){
            for(int l=j; l<k; ++l){
                int mult = 0;
                if(i == j && j == l) mult = 1;
                else if(i == j || j == l || l == i) mult = 3;
                else mult = 6;
                sum += gcd(gcd(i, j), l) * mult;
            }
        }
    }
    cout << sum;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int t = 1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a;
  cin >> N;
  a = 0;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int i = 0; i < (N + 1) / 2; i++) {
    a += vec.at(i * 2);
    if (N % 2 == 0 || i < (N - 1) / 2) {
      a -= vec.at(i * 2 + 1);
    }
  }
  cout << a << endl;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a,b,c,d;

    cin>>a>>b>>c>>d;
    while(a>0 || c>0)
    {
        c=c-b;
        a=a-d;
        if(c<=0)
        {

            cout<<"Yes";
            break;
        }
        if(a<=0)
        {
            cout<<"No";
            break;
        }

    }

}


Measured memory_bytes: 3632
import sys
def main():
    n = int(input())
    txy = []
    for _ in range(n):
        txy.append(tuple(map(int, input().split())))

    t = x = y = 0
    for i1 in range(n):
        txye = txy[i1]
        t, dt = txye[0], txye[0] - t
        x, dx = txye[1], abs(txye[1] - x)
        y, dy = txye[2], abs(txye[2] - y)
        if dt < (dx + dy):
            print('No')
            sys.exit()
        elif dt > (dx + dy) and (dt - dx - dy) % 2 != 0:
            print('No')
            sys.exit()

    print('Yes')


if __name__ == '__main__':
    main()


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

int n, m, a, b, x, y=1e9;
int main() {
	cin>>n>>m;
	while(m--) {
		scanf("%d%d", &a, &b);
		x = max(x, a);
		y = min(y, b);
	}
	cout<<max(y-x+1, 0);
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_d

#include "algorithm"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;
  string S;
  cin >> S;

  V<multiset<ll>> indices(10);

  rep(i, N) {
    auto c = S[i];
    auto cl = c - '0';
    indices[cl].insert(i);
  }

  ll res = 0;
  rep(f, 10) {
    auto fit = indices[f].lower_bound(0);
    auto f_i_i = distance(indices[f].begin(), fit);

    if (f_i_i == indices[f].size()) continue;
    ll f_i = *fit;

    rep(s, 10) {
      auto sit = indices[s].lower_bound(f_i + 1);
      auto s_i_i = distance(indices[s].begin(), sit);

      if (s_i_i == indices[s].size()) continue;
      auto s_i = *sit;

      rep(t, 10) {
        auto tit = indices[t].lower_bound(s_i + 1);
        auto t_i_i = distance(indices[t].begin(), tit);

        if (t_i_i == indices[t].size()) continue;
        auto t_i = *tit;

        res++;
      }
    }
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 1664
include Math
Vector = Struct.new(:x, :y)

def koch n, a, b
  return nil if n == 0
  th = (PI * 60 / 180).to_f
  s = Vector.new
  t = Vector.new
  u = Vector.new
  s.x = (2.0 * a.x + 1.0 * b.x).to_f / 3.0
  s.y = (2.0 * a.y + 1.0 * b.y).to_f / 3.0
  t.x = (1.0 * a.x + 2.0 * b.x).to_f / 3.0
  t.y = (1.0 * a.y + 2.0 * b.y).to_f / 3.0
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y

  koch n - 1 , a, s
  printf "%.8f %.8f\n", s.x, s.y
  koch n - 1, s, u
  printf "%.8f %.8f\n", u.x, u.y
  koch n - 1, u, t
  printf "%.8f %.8f\n", t.x, t.y
  koch n - 1, t, b
end

a = Vector.new 0, 0
b = Vector.new 100, 0
n = gets.to_i

printf "%.8f %.8f\n", a.x, a.y
koch n, a, b
printf "%.8f %.8f\n", b.x, b.y

Measured memory_bytes: 9004
//package com.company;

import java.io.*;
import java.util.*;

public class Main {
    static long TIME_START, TIME_END;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(System.out);
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.in"));

        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
//        System.out.println("Memory increased:" + (usedMemoryAfter-usedMemoryBefore) / 1000000 );
//        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");

    }


    public static class Task {
        public int dist(int a, int b){
            return Math.abs(a - b);
        }
        //https://arc093.contest.atcoder.jp/tasks/arc093_a
        // 3978
        // Traveling Plan
        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            int n = sc.nextInt();
            int[] a = new int[n + 2];
            for (int i = 1; i <= n; i++) {
                a[i] = sc.nextInt();
            }
            int[] prefix = new int[n + 2];
            int[] suffix = new int[n + 2];
            for (int i = 1; i <= n; i++) {
                prefix[i] = prefix[i - 1] + dist(a[i-1], a[i]);
            }
            for (int i = n; i > 0; i--) {
                suffix[i] = suffix[i + 1] + dist(a[i+1], a[i]);
            }
            for (int i = 1; i <= n; i++) {
                pw.println(prefix[i-1] + dist(a[i-1], a[i+1]) + suffix[i+1]);
            }

        }




    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public Scanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {return br.readLine();}

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

        public boolean ready() throws IOException {return br.ready();}
    }
}


Measured memory_bytes: 43444
// -*- mode:c++; coding:utf-8; c-basic-offset:2; -*-
// ALDS1_5-B: Merge Sort

#include <cstdio>
#include <cstring>

static void print_ints(const int as[], const unsigned int n, const char* sep = " ") {
  const char* out_sep = "";
  for (auto i = 0u; i < n; ++i) {
    std::printf("%s%d", out_sep, as[i]);
    out_sep = sep;
  }
  std::printf("\n");
}

static void print_int(const unsigned int n) {
  std::printf("%d\n", n);
}

static unsigned int comparison_count = 0u;

static void merge(int* const ss, const unsigned int n) {
  auto n1 = n/2, n2 = n-n1;
  int tmp[n1];
  std::memcpy(tmp, ss, sizeof(tmp));
  auto ss1 = tmp, ss2 = ss+n1;
  auto i = 0u, i1 = 0u, i2 = 0u;
  while (i1 < n1 && i2 < n2) {
    ++comparison_count;
    if (ss1[i1] < ss2[i2]) {
      ss[i++] = ss1[i1++];
    } else {
      ss[i++] = ss2[i2++];
    }
  }
  while (i1 < n1) {
    ++comparison_count;
    ss[i++] = ss1[i1++];
  }
  while (i2 < n2) {
    ++comparison_count;
    ss[i++] = ss2[i2++];
  }
}

void merge_sort(int* const ss, const unsigned int n) {
  if (n > 1) {
    auto n1 = n/2, n2 = n-n1;
    auto ss1 = ss, ss2 = ss+n1;
    merge_sort(ss1, n1); // ss[0..n/2-1] is sorted
    merge_sort(ss2, n2); // ss[n/2..n-1] is sorted
    merge(ss, n);
  }
}

int main(void) {
  unsigned int n;
  std::scanf("%d", &n);
  int ss[n];
  for (auto i = 0u; i < n; ++i) {
    std::scanf("%d", &ss[i]);
  }

  merge_sort(ss, n);

  print_ints(ss, n);
  print_int(comparison_count);

  return 0;
}

// eof

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	string s; cin >> s;
	int n = s.size();
	for(int i = 0; i <= n - 2; i++) {
		string t = s.substr(i, 2);
		string r = s.substr(i ,3);
		set<int> a, b;
		for(int j = 0; j < 3; j++) {
			a.insert(t[j % 2]);
			b.insert(r[j]);
		}
		if(a.size() == 1) {
			cout << i + 1 << " " << i + 2 << '\n';
			return 0;
		}
		if(b.size() <= 2) {
			cout << i + 1 << " "  << i + 3 << '\n';
			return 0;
		}
	}
	cout <<  -1 << " " << -1 << '\n';
	return 0;	
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		int[] A = new int[N];
		int idx;
		double ans;
		double sum = 0.0;
		for (idx = 0; idx < N; idx++) {
			A[idx] = Integer.parseInt(sc.next());
			sum += 1.0d / A[idx];
		}
		ans = 1.0d / sum;

		System.out.println(ans);

	}

}


Measured memory_bytes: 21972
n, m = map(int,input().split())
a = list(map(int,input().split()))
h = sum(a)/(4*m)
ans = 0

for i in range(n):
    if a[i] < h:
        continue
    else:
        ans += 1

if ans < m:
    print('No')
else:
    print('Yes')


Measured memory_bytes: 9176
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

odd = v[::2]
even = v[1::2]

ac = Counter(odd).most_common(2)
bc = Counter(even).most_common(2)

if ac[0][0] != bc[0][0]:
    print(n-ac[0][1]-bc[0][1])
else:
    if len(ac) == 1 or len(bc) == 1:
        print(n//2)
    else:
        print(n-max(ac[0][1]+bc[1][1], ac[1][1]+bc[0][1]))

Measured memory_bytes: 15972
#include<bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;

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

int main(){
  int r,g,b,n; cin >> r >> g >> b >> n;
  int cnt = 0;
  for(int i=0; i*r<=n; i++) {
    for(int j=0; j*g<=n; j++) {
      int k = n - i*r - j * g;
      if(k < 0) continue;
      else if(k == 0) cnt++;
      else {
        if(k%b == 0) cnt++;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}

// EOF


Measured memory_bytes: 256
import itertools

n = int(input())
X = []
ans = 0
for i in range(n):
  X.append(tuple(map(int,input().split())))
ls = list(itertools.permutations(X))
for v in ls:
  for j in range(len(X)-1):
    ans += ((v[j][0] - v[j+1][0])**2 + (v[j][1] - v[j+1][1])**2)**0.5
print(ans/len(ls))

Measured memory_bytes: 8180
#include <cstdio>
#include <climits>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int N, K, i, buf, hmin = INT_MAX, hdif;
	scanf("%d %d", &N, &K);

	vector<int> h(N);
	for (i = 0; i < N; i++) {
		scanf("%d", &buf);
		h[i] = buf;
	}

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

	for (i = 0; i <= N-K; i++) {
		hdif = h[i+K-1] - h[i];
		if (hmin > hdif)
			hmin = hdif;
	}

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

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

lint x, y, z, k;
vector<lint> a, b, c;

//美味しさの合計がm以上なる組み合わせがいくつあるか
lint count(lint m) {
    lint res = 0;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            lint now = a[i] + b[j];
            res += c.end() - lower_bound(c.begin(), c.end(), m - now);
        }
    }
    return res;
}

bool isvalid(lint m) {
    return count(m) >= k;
}

int main() {
    cin >> x >> y >> z >> k;
    a.resize(x);
    b.resize(y);
    c.resize(z);
    for (int i = 0; i < x; i++) cin >> a[i];
    for (int i = 0; i < y; i++) cin >> b[i];
    for (int i = 0; i < z; i++) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    lint ok = 0, no = LLONG_MAX / 2;
    while (abs(ok - no) > 1) {
        lint mid = (ok + no) / 2;
        if (isvalid(mid)) {
            ok = mid;
        } else {
            no = mid;
        }
    }
    vector<lint> ans;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            lint now = a[i] + b[j];
            auto bdry = upper_bound(c.begin(), c.end(), ok - now);
            for (auto itr = bdry; itr != c.end(); itr++) {
                ans.push_back(now + *itr);
            }
        }
    }
    sort(ans.begin(), ans.end(), greater<lint>());
    for (auto e : ans) {
        cout << e << endl;
    }
    for (int i = 0; i < k - (lint)ans.size(); i++) {
        cout << ok << endl;
    }
}

Measured memory_bytes: 384
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    final int LIKE_NUM = 753;
    int min = Integer.MAX_VALUE;
    for(int i=0; i<S.length()-2; i++){
      int tmp = Integer.parseInt(S.substring(i, i+3));
      tmp = Math.abs(LIKE_NUM - tmp);
      min = Math.min(min, tmp);
    }
    System.out.print(min);
  }
}


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

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> cake(n);
	for (int i = 0; i < n; i++) {
		cin >> cake.at(i);
	}
	sort(cake.begin(), cake.end());
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (x >= cake.at(i)) {
			count++;
			x -= cake.at(i);
		}
		else break;
		if (i == n - 1 && x > 0) count--;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define X first
#define Y second
using namespace std;

struct UnionFindTree{
	UnionFindTree():pos(pair<int, int>(-1, -1)), root(NULL){}
	pair<int, int> pos;
	UnionFindTree *root;
};

void dfs(int x, int y, int &count, vector<vector<UnionFindTree> > &pos){
	if(pos[pos[y][x].pos.Y][pos[y][x].pos.X].root==NULL){
		if(pos[y][x].root==NULL) pos[pos[y][x].pos.Y][pos[y][x].pos.X].root = &pos[y][x];
		else pos[pos[y][x].pos.Y][pos[y][x].pos.X].root = pos[y][x].root;
		dfs(pos[y][x].pos.X, pos[y][x].pos.Y, count, pos);
	}
	else if(pos[y][x].root == pos[pos[y][x].pos.Y][pos[y][x].pos.X].root){
		count++;
	}
	pos[y][x].root = pos[pos[y][x].pos.Y][pos[y][x].pos.X].root;
	return;
}

int main(){
	int n = 0;
	while(cin >> n && n != 0){
		vector<vector<UnionFindTree> > pos(n, vector<UnionFindTree>(n, UnionFindTree()));
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> pos[i][j].pos.X >> pos[i][j].pos.Y;
			}
		}
		int count = 0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(pos[i][j].root != NULL) continue;
				dfs(j, i, count, pos);
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1332
#include<stdio.h>

int main(void)
{
  int a,b,c,d,x,n;
  while(scanf("%d",&n)!=EOF) {
  x  =0;
    for(a=0;a<10;a++) {
      for(b=0;b<10;b++) {
        for(c=0;c<10;c++) {
          for(d=0;d<10;d++) {
            if ( a + b + c + d == n ) x++;

          }
        }
      }
    }
    printf( "%d\n", x );
  }
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=998244353;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
int dx[8]={0,0,1,1,1,-1,-1,-1};
int dy[8]={1,-1,1,-1,0,1,-1,0};
int main(){
    ll s=1;
    int keta=0;
    char c;
    bool f=false;
    for(int i=1;i<=11;i++){
        cout<<"? "<<s<<endl;
        cin>>c;
        keta=i-1;
        if(c=='N'){
            f=true;
            break;
        }
        s*=10;
    }
    if(!f){
        s=1;
        for(int i=1;i<10;i++){
            cout<<"? "<<s+1<<endl;
            cin>>c;
            if(c=='Y'){
                cout<<"! "<<s<<endl;
                return 0;
            }
            s*=10;
        }
    }
    int now=1;
    s=0;
    while(1){
        if(now==keta){
            int en=0;
            if(keta==1){
                en=1;
            }
            for(int i=9;i>=en;i--){
                cout<<"? "<<(s+i)*10<<endl;
                cin>>c;
                if(c=='N'){
                    cout<<"! "<<s+i+1<<endl;
                    return 0;
                }   
            }
            cout<<"! "<<s+en<<endl;
            return 0;
        }else{
            int ok=0,ng=10;
            while(ng-ok>1){
                int mid=(ng+ok)/2;
                cout<<"? "<<s+mid<<endl;
                cin>>c;
                if(c=='Y'){
                    ok=mid;
                }else{
                    ng=mid;
                }
            }
            s+=ok;            
        }
        now++;
        s*=10;
    }
}


Measured memory_bytes: 684
#include <iostream>
#include <vector>
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
    int n; cin >> n;
    vector<ll> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    
    int cap_num[3] = {0};
    ll ans = 1;
    for(int i = 0; i < n; i++) {
        ll select_num = 0;
        for(int j = 0; j < 3; j++) {
            if(cap_num[j] == v[i]) {
                select_num++;
            }
        }
        
        ans *= select_num;
        ans %= MOD;
        
        for(int j = 0; j < 3; j++) {
            if(cap_num[j] == v[i]) {
                cap_num[j]++;
                break;
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,L,R;
  cin >> a >> b >> c >> d;
  L=a+b;
  R=c+d;
  if(L>R)
    cout << "Left" << endl;
  else if(L<R)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		boolean[] tri = new boolean[1000001];
		for (int i = 1; i * (i + 1) / 2 <= 100000; i++) {
			int a = i * (i + 1) / 2;
			tri[a] = true;
		}
		loop: while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int sum = 0;
			List<Integer> list = new ArrayList<Integer>();
			for (int i = 0; i < n; i++) {
				int a = scanner.nextInt();
				list.add(a);
				sum += a;
			}
			if (tri[sum]) {
				int res = 0;
				int R = n;
				while (res <= 10000) {
					if (slove(list)) {
						System.out.println(res);
						continue loop;
					}
					int size = list.size();
					for (ListIterator<Integer> it = list.listIterator(); it
							.hasNext();) {
						int a = it.next();
						if (a == 1)
							it.remove();
						else
							it.set(a - 1);

					}
					list.add(size);

					res++;
				}
			}
			System.out.println(-1);
		}
	}

	private boolean slove(List<Integer> list) {
		for (int i = 0; i < list.size(); i++)
			if (i + 1 != list.get(i))
				return false;
		return true;
	}
}

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

using namespace std;


typedef long long int ll;
typedef vector<int>vi;
typedef deque<int> di;
#define f(i, a, b) for(int i = a; i < b; i++)

int main () {
int a;
int b;
cin >> a >> b;
b += b;
if (a - b >= 0) {

    cout << a-b;
}
else {

    cout << 0;
}
return 0;
}


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

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

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[m];
        int etc = (int)Math.pow(10, 9) + 7;
        for(int i=0;i<n;i++){
        	x[i] = sc.nextInt();
        }
        for(int i=0;i<m;i++){
        	y[i] = sc.nextInt();
        }
        Arrays.sort(x);
        Arrays.sort(y);
        long xcount = 0;
        long ycount = 0;
        long ans = 0;
        for(int i=0;i<n;i++){
        	xcount += (long)i * (long)x[i] - ((long)n - (long)i - 1) * (long)x[i];
        }

        for(int i=0;i<m;i++){
        	ycount += (long)i * (long)y[i] - ((long)m - (long)i - 1) * (long)y[i];
        }
        xcount = xcount%etc;
        ycount = ycount%etc;
        ans = xcount*ycount%etc;

        System.out.println(ans%etc);
    }
}

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

ll n, m;
typedef pair<ll,ll> pll;
vector< ll > g[100005];
vector< pll> ans;
ll dp[100005];
map<ll,ll> mp[100005];
ll dfs(ll s, ll pr)
{
        if(dp[s] != -1) return -2;
        dp[s] = 0;
        for(auto &i : g[s]) {
                if(i == pr) continue;
                if(mp[s][i]) continue;
                if(dp[i] == -1) {
                        ll g = dfs(i, s);
                        if(g == 1) continue;
                }
                if(dp[i] == 0){
                        dp[s] = 1 - dp[s];
                        ans.pb(make_pair(s,i));
                        mp[s][i] = 1;
                        mp[i][s] = 1;
                }else {
                        dp[i]=0;
                        ans.pb(make_pair(i,s));
                        mp[i][s] = 1;
                        mp[s][i] = 1;
                }
        }
        ll ret = 0;
        if(dp[s] == 1){
                dp[s] = 0;
                ans.pb(make_pair(s, pr));
                mp[s][pr] = 1;
                mp[pr][s] = 1;
                ret = 1;
        }
        return ret;
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL); cout.tie(NULL);
        cin >> n >> m;
        for(ll i=1;i<=m;i++) {
                ll u,v;
                cin >> u >> v;
                g[u].pb(v);
                g[v].pb(u);
        }
        if(m%2 == 1){
                cout << "-1\n"; return 0;
        }
        memset(dp,-1,sizeof dp);
        ll yo = dfs(1,-1);
        for(auto &i : ans) cout << i.first << " " << i.second << "\n";
        return 0;
}


Measured memory_bytes: 35824
using System;
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var N = NextInt();
		var a = new int[N];
		for (var i = 0; i < N; i++) {
			a[i] = NextInt();
		}
		Array.Sort(a);
		Array.Reverse(a);
		var ans = 0;
		for (var i = 0; i < N; i++) {
			ans += a[i] * new int[] { 1, -1 }[i % 2];
		}
		WriteLine(ans);
	}

	static int NextInt() {
		return int.Parse(NextString());
	}

	static string NextString() {
		var result = new List<char>();
		while (true) {
			int next = Read();
			if (next < 0)
				break;
			var nextChar = (char)next;
			if (!char.IsWhiteSpace(nextChar))
				result.Add(nextChar);
			else if (nextChar != '\r')
				break;
		}
		return string.Join("", result);
	}
}

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

  int hour,min,sec,sum;

  scanf("%d",&sum);

  hour = sum / 3600 ;
  sum = sum % 3600 ;
  min = sum / 60 ;
  sec = sum % 60 ;
  
  printf("%d:%d:%d\n",hour,min,sec);

  return 0;

}

Measured memory_bytes: 592
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int A[200010];
    rep(i, n) cin >> A[i];
    int sum = 0;
    rep(i, n) sum += A[i];
    int ans = sum;
    int tmp = 0;
    rep(i, n - 1) {
        tmp += A[i];
        ans = min(ans, abs(tmp* 2 - sum));
        //cout << tmp << " " << tm
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 1792
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long,long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

bool is_753(ll N) {
    map<char,int> res;
    string S = to_string(N);
    for(int i = 0; i < S.size(); i++) {
        if(res.count(S.at(i))) res[S.at(i)]++;
        else res[S.at(i)] = 1;
    }
    bool ans;
    if(res.count('7') && res.count('3') && res.count('5')) ans = true;
    else ans = false;
    return ans;
}

int main() {
    ll N;
    cin >> N;
    queue<ll> que;
    que.push(3);
    que.push(5);
    que.push(7);
    int ans = 0;
    while(1) {
        ll a = que.front();
        que.pop();
        que.push(a*10+3);
        que.push(a*10+5);
        que.push(a*10+7);
        if(is_753(a) && a <= N) {
            //cout << a << endl;
            ans++;
        }
        else if(a > N)break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
#include<cstdio>
typedef long long ll;
int main()
{
    ll k,a,b;
    scanf("%lld%lld%lld",&k,&a,&b);
    if(k<=a) return printf("1\n"),0;
    if(a<=b) return printf("-1\n"),0;
    ll ans=(k-a)/(a-b);
    if((k-a)%(a-b)) ans=2*ans+3;
    else ans=2*ans+1;
    printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define debug(...)
#define DEBUG(...)
#else
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    _debug(__VA_ARGS__);               \
    cerr << endl;                      \
  } while (0)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<i64> A(N), B(N);
  for (auto& x : A) cin >> x;
  for (auto& x : B) cin >> x;

  auto solve = [&]() -> i64 {
    priority_queue<pair<i64, int>> pq;
    int ok_cnt = 0;
    REP(i, N) {
      if (B[i] < A[i]) return -1;
      if (B[i] > A[i]) {
        pq.emplace(B[i], i);
      } else {
        ok_cnt++;
      }
    }
    i64 step = 0;
    while (pq.size()) {
      i64 btop = pq.top().first;
      int bix = pq.top().second;
      pq.pop();
      assert(B[bix] == btop);
      assert(B[bix] > A[bix]);
      int l = (bix - 1 + N) % N;
      int r = (bix + 1) % N;
      i64 bnext = max(B[l], B[r]);
      i64 batch;
      if (A[bix] >= bnext) {
        if ((B[bix] - A[bix]) % (B[l] + B[r]) != 0) return -1;
        batch = (B[bix] - A[bix]) / (B[l] + B[r]);
      } else {
        // Ensure btop - batch*(B[l]+B[r]) < bnext.
        batch = (btop - bnext + (B[l] + B[r] - 1)) / (B[l] + B[r]);
      }
      if (batch == 0) return -1;
      step += batch;
      B[bix] -= batch * (B[l] + B[r]);
      if (B[bix] < A[bix]) return -1;
      if (B[bix] > A[bix]) {
        pq.emplace(B[bix], bix);
      } else {
        ok_cnt++;
      }
    }
    assert(ok_cnt == N);
    return step;
  };
  cout << solve() << endl;
}


Measured memory_bytes: 9456
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cfloat>
#include <climits>
#include <cassert>
#include <random>

int main() {
	long long int health; int n; std::cin >> health >> n;
	std::vector<int> skill(n); for (auto& a : skill) std::cin >> a;
	if (std::accumulate(skill.begin(), skill.end(), 0LL) >= health) {
		std::cout << "Yes\n";
	}
	else {
		std::cout << "No\n";
	}
}

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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();

		int max = a > b ? a : b;
		List<Integer> list = new ArrayList<Integer>();

		for (int i = 1; i <= max; i++) {

			if (a % i == 0 && b % i == 0) {
				list.add(i);
			}

		}

		Collections.sort(list);
		Collections.reverse(list);

		System.out.println(list.get(k - 1));

	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn;
	cin >> nn;
	vector<int64> aa(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> aa[ii];
	}
	map<int64, int64> memo;
	int64 allgcd = aa[0];
	for(int64 ii = 1;ii < nn;ii++)
	{
		allgcd = gcd(allgcd, aa[ii]);
		if(allgcd == 1)
		{
			break;
		}
	}
	if(allgcd != 1)
	{
		cout << "not coprime" << endl;
		return 0;
	}
	for(int64 ii = 0;ii < nn;ii++)
	{
		int64 tmp = aa[ii];
		for(int64 jj = 2;jj <= sqrt(aa[ii]) && tmp != 1;jj++)
		{
			if(tmp % jj == 0)
			{
				while(tmp % jj == 0)
				{
					tmp /= jj;
				}
				if(memo[jj] == 0)
				{
					memo[jj] = 1;
				}
				else
				{
					cout << "setwise coprime" << endl;
					return 0;
				}
			}
		}
		if(tmp != 1)
		{
			if(memo[tmp] == 0)
			{
				memo[tmp] = 1;
			}
			else
			{
				cout << "setwise coprime" << endl;
				return 0;
			}
		}
	}
	cout << "pairwise coprime" << endl;
	return 0;
}

Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

 
int main() {
    ll n, ans = 0;
    vector<int> a, b, c;
    
    cin >> n;

    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        a.push_back (temp);
    }

    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        b.push_back (temp);
    }

    for (int i = 0; i < n-1; i++) {
        int temp;
        cin >> temp;
        c.push_back (temp);
    }

    for (int i = 0; i < n; i++) {
        ans += b[a[i]-1];
        if (i > 0 && a[i-1] == a[i] - 1) ans += c[a[i-1]-1];
    }

    cout << ans << endl;

    
    
}

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

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

  string S; cin >> S;
  if (S[0] == S[1] && S[1] == S[2]) cout << "No" << "\n";
  else cout << "Yes" << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#define REP(i,j,n) for(int i=j;i<n;i++)
#define SORT(x) sort(x.begin(),x.end())

using namespace std;

int main() {
	int n,min=-1,max=-1;
	long long sum = 0;
	cin >> n;
	vector<int> v(n);
	REP(i, 0, n) cin >> v[i];

	REP(i, 0, n) {
		sum += v[i];
		if (max == -1) max = v[i];
		else if (max < v[i]) max = v[i];

		if (min == -1) min = v[i];
		else if (min > v[i]) min = v[i];
	}

	cout << min <<" "<< max <<" "<< sum << endl;

	return 0;
}

Measured memory_bytes: 3136
import java.util.Scanner;

class Circle {
	private int _x;
	private int _y;
	private int _r;
	
	public Circle(int x, int y, int r) {
		_x = x;
		_y = y;
		_r = r;
	}
	public int getX() { return _x; }
	public int getY() { return _y; }
	public int getR() { return _r; }
}

class Rectangle {
	private int _w;
	private int _h;
	public Rectangle(int w, int h) {
		_w = w;
		_h = h;
	}
	public int getW() { return _w; }
	public int getH() { return _h; }
}

class CircleInRectangle {
	private Circle circle;
	private Rectangle rectangle;
	
	CircleInRectangle(int w, int h, int x, int y, int r) {
		circle = new Circle(x, y, r);
		rectangle = new Rectangle(w, h);
	}
	
	public void control() {
		System.out.println(toString(isIncluded()));
	}
	
	private boolean isIncluded() {
		if (0 >= circle.getX() || 0 >= circle.getY())
			return false;
		
		if (rectangle.getW() - circle.getR() < circle.getX())
			return false;
		if (rectangle.getH() - circle.getR() < circle.getY())
			return false;
		return true;
	}
	
	private String toString(boolean isIncluded) {
		if (isIncluded)
			return "Yes";
		return "No";
	}
}
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		new CircleInRectangle(scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt()).control();

	}

}



Measured memory_bytes: 26248
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	ret = 0
	for i in range(1, n):
		ret += (n-1)//i
	return ret
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

char word[10];
stack<int> S;
int n, m;

void operandInsert() {
	n = S.top();
	S.pop();
	m = S.top();
	S.pop();
}


signed main() {
	while (cin >> word) {
		if (word[0] == '+') {
			operandInsert();
			S.push(n + m);
		}
		else if (word[0] == '-') {
			operandInsert();
			S.push(m - n);
		}
		else if (word[0] == '*') {
			operandInsert();
			S.push(n * m);
		}
		else {
			S.push(stoi(word));
		}
	}
	cout << S.top() << endl;
}




Measured memory_bytes: 3192
n,m = map(int,input().split())
city = [[] for _ in range(n+1)]
ret = ["" for _ in range(m)]
def createSix(s):
    while len(s) != 6:
        s = "0" + s
    return s
for i in range(m):
    a,b = map(int, input().split())
    city[a].append((b, i))
for i in range(n+1):
    city[i].sort()
for i in range(n+1):
    for j in range(len(city[i])):
        ret[city[i][j][1]] = createSix(str(i)) + createSix(str(j+1))
for i in ret:
    print(i)


Measured memory_bytes: 36016
using System;
using System.Linq;

class Mainclass 
{
    static void Main()
    {
        int[] input = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
        if (input[2] <= input[1])
        {
            Console.WriteLine("delicious");
        }
        else
        {
            Console.WriteLine(input[2]<=input[0]+input[1]?"safe":"dangerous");
        }
    }
}

Measured memory_bytes: 27544
#include<bits/stdc++.h>
using namespace std;
 
int n,m;
vector<int>v[100001];
int clr[100001]={};
int dis[100001][11];
 
void dfs(int x,int d,int c){
	if (dis[x][d])return;
	if (d<0)return;
	if (!clr[x])clr[x]=c;
	dis[x][d]=c;
	for (int i:v[x])
		dfs(i,d-1,c);
}
 
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	while(m--){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int q;
	cin>>q;
	int x[100001],d[100001],c[100001];
	for (int i=0;i<q;++i){
		cin>>x[i]>>d[i]>>c[i];
	}
	for (int i=q-1;i>-1;--i)
		dfs(x[i],d[i],c[i]);
	for (int i=1;i<n+1;++i)cout<<clr[i]<<endl;
}


Measured memory_bytes: 12408
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>


int main()
{
    // std::cout << std::fixed << std::setprecision(10);
    int n; std::cin >> n;
    std::vector<int> p(n);
    for(int i=0; i<n; i++) std::cin >> p[i];
    int cnt = 0;
    for(int i=2; i<n; i++)
    {
        if((p[i-2]<p[i-1] && p[i-1]<p[i]) || (p[i]<p[i-1] && p[i-1]<p[i-2])) cnt++;
    }

    std::cout << cnt << std::endl;
    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

class MinimumSpanningTree{
	ll cost;
	deque<bool> use;
public:
	MinimumSpanningTree(ConnectNodeInfo& connect){
		int N = connect.size();
		use.resize(N,false);

		auto comp = [](pair<ll,ll>& l,pair<ll,ll>& r){return l.second>r.second;};
		priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,decltype(comp)> Q(comp);
		Q.emplace(0,0);
		cost=0;
		while(!Q.empty()){
			auto e=Q.top();
			Q.pop();
			if(use[e.first]) continue;
			use[e.first] = true;
			cost += e.second;
			for(auto& x:connect[e.first]){
				Q.push(x);
			}
		}
	}
	ll GetCost(){return cost;}
};

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

	int N=in(),E=in();
	ConnectNodeInfo connect(N);
	REP(i,E){
		int u=in(),v=in(),w=in();
		connect.AddNonDirectionalConnection(u,v,w);
	}
	
	MinimumSpanningTree MST(connect);

	out(MST.GetCost());
	return 0;
}


Measured memory_bytes: 12504
n,l = map(int,input().split())

taste = []
j = 500
k = 0
adr = 0
for i in range(l,n+l,1):
    taste.append(i)
    j = min(j,abs(i))
    if j == abs(i):
        adr = k
    k += 1

res = sum(taste) - taste[adr]
print(res)


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

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

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll X;
  cin>>X;
  ll ansa,ansb;
  REP(a,501){
    FOR(b,-500,501){
      ll a5=1ll, b5=1ll;
      REP(i,5){
        a5*=a;
        b5*=b;
      }
      if(a5-b5==X){
        ansa=a;ansb=b;
      }
    }
  }
  cout<<ansa<<' '<<ansb<<endl;
}


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

int main(){
    string a,b,c;
    cin >> a >> b;
    if(b[0] >= 0x61 && b[0] <= 0x7a){
        b[0] = b[0] - 32;}
    cout << "A" << b[0] << "C" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;
 
int main()
{
        LL a;
        cin>>a;
        LL x=a;
        LL y=pow(a,2);
        LL z=pow(a,3);
        cout<<x+y+z<<endl;

    return 0;
}

Measured memory_bytes: 4004
#include <bits/stdc++.h>
     
using namespace std;
     
int main(){
  int h,w; cin >> h >> w;
  long long c[10][10];
  int a;
  for(int i=0;i<10;++i)
    for(int j=0;j<10;++j)
      cin >> c[i][j];
  
  for(int k=0;k<10;++k)
    for(int i=0;i<10;++i)
      for(int j=0;j<10;++j)
	c[i][j]=min(c[i][j],c[i][k]+c[k][j]);

  long long ans=0;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      cin >> a;
      if(a!=1 && a!=-1){
	ans+=c[a][1];
      }
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256