akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {
	
	
	int n;
	cin >> n;
	vector<vector<int>>p(n), d(n);
	vector<int>x(n,-1);

	for (int i = 0; i < n-1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		p[a].push_back(b);
		p[b].push_back(a);
		d[a].push_back(c);
		d[b].push_back(c);
	}
	x[0] = 0;
	vector<int>m;
	m.push_back(0);

	while (m.size()) {
		int t = m.front();
		m.erase(m.begin());
		for (int i = 0; i < p[t].size(); i++) {
			int u = p[t][i];
			int w = d[t][i];
			if (x[u] != -1)continue;
			x[u] = (x[t] + w) % 2;
			m.push_back(u);
		}
	//	cout << m.size() << endl;

	}
	for (int i = 0; i < n; i++)cout << x[i] << endl;;




	return 0;


}

Measured memory_bytes: 11904
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    int N, M;
    cin >> N >> M;
    vector<map<int, int>> A;
    A.assign(N + 1, map<int, int>());
    map<int, string> whole;
    vector<int> order;

    rep(i, M) {
        int a, b;
        cin >> a >> b;
        A[a][b] = 0;
        order.push_back(b);
    }

    for (int i = 1; i <= N; i++) {
        int cnt = 0;
        if (A[i].empty()) {
            continue;
        }

        for (auto p : A[i]) {
            cnt++;
            string ans = "";
            string num1 = to_string(i);
            string num2 = to_string(cnt);
            int left, right;
            left = 6 - num1.size();
            right = 6 - num2.size();
            rep(i, left) { ans += "0"; }

            ans += num1;

            rep(i, right) { ans += "0"; }

            ans += num2;
            whole[p.first] = ans;
        }
    }

    rep(i, M) { cout << whole[order[i]] << endl; }

    return 0;
}

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

ll solve() {
    ll A, B, N;
    cin >> A >> B >> N;

    ll ans = 0;
    if ( N < B ) {
        ans = A * N / B; 
    } else {
        ans = A * (B-1) / B; 
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n, p, c[2];
ll ps[51][51];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ps[0][0] = 1;
  FOR(i, 1, 51){
    ps[i][0] = 1;
    FOR(j, 1, i+1) ps[i][j] = ps[i-1][j] + ps[i-1][j-1];
  }
  cin >> n >> p;
  ll ans = 0;
  FOR(i, 0, n){
    int a;
    cin >> a;
    c[a%2]++;
  }
  for(int i = p; i <= c[1]; i+=2) ans += ps[c[1]][i];
  ans *= 1ll<<c[0];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = input().split()
a = [int(x) for x in a]

i = 0
magic = 0
while(i < n):
	length = 1
	while(a[i] == a[i+1]):
		length += 1
		i += 1
		if(i == n-1):
			break
	magic += int(length / 2)
	i += 1
	if(i == n-1):
		break
print(magic)

Measured memory_bytes: 3064
a,b,h,m = gets.split(" ").map(&:to_i)
hr = 30*h + 0.5*m
mr = 6*m
r = hr > mr ? hr - mr : mr - hr
r = 360 - r if r > 180
p Math.sqrt( a**2 + b**2 - 2*a*b*Math.cos(r*Math::PI/180))

Measured memory_bytes: 14724
A, B, M = map(int, input().split())
alist = [int(i) for i in input().split()]
blist = [int(i) for i in input().split()]
xyclist = [map(int, input().split()) for _ in range(M)]

res = min(alist) + min(blist)

for x, y, c in xyclist:
    cand = alist[x-1] + blist[y-1] - c
    if cand < res:
        res = cand

print(res)

Measured memory_bytes: 62308
import java.util.Scanner;

public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		sc = new Scanner(System.in);
		Long N = sc.nextLong();
		long K =  1;
		Long z=(long) Math.pow(10, 9);
		int i;
		for(i=1;i<=N;i++){
		K=K*i % (z+7);
		
		}
		
		System.out.println(K);
	

	}
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
#define INF 0x3f3f3f3f
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a,b;
	cin >> a >> b;
	if(b>=a){
		cout<<"unsafe";
	}
	else{
		cout<<"safe";
	}
	return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>

int main(void) {
	char S[128];
	int i;
	int utida_maaya = 0;
	S[0] = 'A';
	if (scanf("%127s", &S[1]) != 1) return 1;
	for (i = 1; S[i] != '\0'; i++) {
		if (S[i - 1] >= S[i]) utida_maaya++;
	}
	printf("%d\n", utida_maaya);
	return 0;
}



Measured memory_bytes: 2136
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




#define SIZE 100005

ll N;
ll num_X,num_Y;
bool visited[2*SIZE];
vector<int> G[2*SIZE];


void dfs(int node_id){

	for(int i = 0; i < G[node_id].size(); i++){

		int next = G[node_id][i];
		if(visited[next])continue;

		visited[next] = true;
		if(next >= SIZE){

			num_Y++;
		}else{

			num_X++;
		}
		dfs(next);
	}
}


int main(){

	scanf("%lld",&N);

	ll x,y;

	for(ll i = 0; i < N; i++){

		scanf("%lld %lld",&x,&y);
		y += SIZE;

		G[x].push_back(y);
		G[y].push_back(x);
	}

	for(int i = 0; i < 2*SIZE; i++){

		visited[i] = false;
	}

	ll ans = 0;

	for(int i = 0; i < SIZE; i++){
		if(visited[i])continue;

		visited[i] = true;
		num_X = 1;
		num_Y = 0;

		dfs(i);

		ans += num_X*num_Y;
	}

	ans -= N;

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

	return 0;
}


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

int main(){
 int D;
  std::cin >> D;
  switch(D){
    case 22:
      std::cout << "Christmas Eve Eve Eve" << std::endl;
      break;
      case 23:
      std::cout << "Christmas Eve Eve" << std::endl;
      break;
      case 24:
      std::cout << "Christmas Eve" << std::endl;
      break;
      case 25:
      std::cout << "Christmas" << std::endl;
      break;
  }
}

Measured memory_bytes: 256
while (1):
    res = list(map(int, input().split()))
    if res[0] == -1 and res[1] == -1 and res[2] == -1:
        break
    elif res[0] == -1 or res[1] == -1:
        grad = "F"
    elif res[0] + res[1] >= 80:
        grad = "A"
    elif res[0] + res[1] >= 65:
        grad = "B"
    elif res[0] + res[1] >= 50:
        grad = "C"
    elif res[0] + res[1] >= 30:
        if res[2] >= 50:
            grad = "C"
        else:
            grad = "D"
    else:
        grad = "F"
    
    print(grad)



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

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

    for(int i = 0;i < n+1;i ++){
        for(int j = 0;j < n - i +1;j ++){
            if(i*10000 + j*5000 + (n-i-j)*1000 == y){
                cout << i << " " << j << " " << n-i-j << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
}

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

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    int n, k;
    cin >> n >> k;
    map<int, ll> mp;
    vi a(n), pre(n + 1, 0);

    ll ans = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        a[i] %= k;
        pre[i + 1] = (pre[i] + a[i]) % k;
    }

    for(int i = 1; i <= n; i++)
        pre[i] = (pre[i] - (i % k) + k) % k;
        
    mp[0] = 1;
    for(int i = 1; i <= n; i++)
    {
        if(i - k >= 0) mp[pre[i - k]]--;
        ans += mp[pre[i]];
        mp[pre[i]]++;
    }

    cout << ans << endl;

    return 0;
}

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




int main(){
   string s;
   string s2;
   cin>>s>>s2;
   int cnt=0;
   rep(i,3)if(s[i]==s2[i])cnt++;
   cout<<cnt<<endl;
   return 0;
}



Measured memory_bytes: 256
INF = 1000000007


def modmulti(a, b):
    # aとbを掛けた値をmodする(a * b mod p)
    res = 0
    mod = a % INF
    while b > 0:
        if b & 1 == 1:
            res += mod
            if res > INF:
                res -= INF
        mod <<= 1
        if mod > INF:
            mod -= INF
        b >>= 1
    return res


N = int(input())

ans = 1

for i in range(1, N + 1):
    ans = modmulti(ans, i)

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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() {
    LL N, H;
    cin >> N >> H;
    vector<LL> a(N), b(N);
    for(int i=0; i<N; i++) cin >> a[i] >> b[i];

    // 振り最強剣
    LL a_max = *max_element(all(a));
    // 強いものから投げる
    sort(all(b));
    reverse(all(b));
    LL ans = 0;
    for(int i=0; i<N; i++){
        if(a_max < b[i]){
            H -= b[i];
            ans++;
            // 投げで倒した
            if(H <= 0) break;
        }
    }
    // 剣を振りまくって倒す
    if(H > 0) ans += (H + (a_max-1)) / a_max;
    cout << ans << endl;
}

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

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<long long> A(X), B(Y), C(Z);
  for (int i = 0; i < X; i++) cin >> A.at(i);
  for (int i = 0; i < Y; i++) cin >> B.at(i);
  for (int i = 0; i < Z; i++) cin >> C.at(i);
  vector<long long> AB;
  // A_i + B_j を列挙
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) AB.push_back(A.at(i) + B.at(j));
  }
  sort(AB.begin(), AB.end(), greater<long long>());
  vector<long long> ABC;
  // A_i + B_j は上位 K 組のみに注目すればよい
  for (int i = 0; i < min(K, (int)AB.size()); i++) {
    for (int j = 0; j < Z; j++) ABC.push_back(AB.at(i) + C.at(j));
  }
  sort(ABC.begin(), ABC.end(), greater<long long>());
  for (int i = 0; i < K; i++) cout << ABC.at(i) << endl;
}

Measured memory_bytes: 43368
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define ppi pair<int,pair<int,int> >
#define fr first
#define sc second
#define PI acos(-1)
#define mp make_pair

using namespace std;



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

    ll t; cin >> t;
    cout << t * (t - 1) / 2;

    return 0;
}


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

using namespace std;

void SelectionSort()
{
	int N;
	int a[100] = {0};
	int count = 0;

	int min;
	int minIndex;

	cin>>N;

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

	for (int i = 0; i < N - 1; i++)
	{
		min = a[i];
		minIndex = i;

		for (int j = i + 1; j < N; j++) 
		{
			if (min > a[j])
			{
				min = a[j];
				minIndex = j;
			}
		}

		if (minIndex != i)
		{
			a[minIndex] = a[i];
			a[i] = min;
			count++;
		}
		

	}

	for(int i  = 0; i < N - 1; i++)
	{
		cout<<a[i]<<" ";
	}
	cout<<a[N - 1]<<endl;
	cout<<count<<endl;
}

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

Measured memory_bytes: 1160
#include<stdio.h>
int A[4];
int B[4];
int keisan();
int keisan2();
int main(){
  int c=0;
  int d=0;
  while(scanf("%d %d %d %d %d %d %d %d",&A[0],&A[1],&A[2],&A[3],&B[0],&B[1],&B[2],&B[3])!=EOF){
    c=keisan();
    d=keisan2();
    printf("%d %d\n",c,d);
  }
  return 0;
}
int keisan(){
int f=0;
int g=0;
for(f=0;f<4;f++){
if(A[f]==B[f]){
g=g+1;
}
}
return g;
g=0;
}
int keisan2(){
int e=0;
int f=0;
int h=0;
for(e=0;e<4;e++){
for(f=0;f<4;f++){
if(A[e]==B[f]&&e!=f){
h=h+1;
}
}
}
return h;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define DBG(a) cout<<#a<<" ->->->-> "<<a<<endl
#define EN cout<<"\n"
#define fi first
#define se second
#define PI (acos(-1))
#define fastread ios::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 1000005
template<class T> ostream& operator<<(ostream &s,pair<T,ll> a)
{
    s<<a.fi<<' '<<a.se;
    return s;
}
int main()
{
    fastread;
    ll T=1;
//    cin>>T;
    for(ll qq=1;qq<=T;qq++)
    {
        ll n,k;
        cin>>n>>k;
        ll x=1,ans=0;
        while(x<=n)x*=k,ans++;
        cout<<ans<<endl;
    }
    return 0;
}



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

int main() {
int n,count=0;;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
    cin>>arr[i];
}

unordered_map <int, int> umap;
for(int i=0;i<n;i++){
    umap[arr[i]]++ ;
}
for(auto x: umap ){
    if(x.first != x.second){
        if(x.second > x.first){
            count += (x.second - x.first);
        }
        else{
            count += x.second;
        }
    }
}
cout<<count ;
    
 
    return 0;
}

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

int main()
{
	int n,c1=0,c2=0;
	cin>>n;
	string str;
	cin>>str;
	for(int i=0;i<n;i++)
	{
		if(str[i]=='R')
			c1++;
	}
	if(c1==n)
	{
		cout<<0<<endl;
		return 0;
	}
	for(int i=0;i<c1;i++)
	{
		if(str[i]=='R')
			c2++;
	}
	cout<<c1-c2<<endl;
	return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
  int i,j;
  int r,c;
  int **arr;
  int *sumOfRow,*sumOfCol;
  int sumOfAll=0;
  scanf("%d%d",&r,&c);
  arr=(int**)malloc(sizeof(int*)*r);
  sumOfRow=(int*)malloc(sizeof(int)*r);
  sumOfCol=(int*)malloc(sizeof(int)*c);
  for(i=0;i<r;i++)
    {
      arr[i]=malloc(sizeof(int)*c);
      sumOfRow[i]=0;
      for(j=0;j<c;j++)
        {
          if(j==0) sumOfCol[i]=0;
          arr[i][j]=0;
        }
    }
  for(i=0;i<r;i++)
    {
      for(j=0;j<c;j++)
        {
          scanf("%d",&arr[i][j]);
          sumOfRow[i]+=arr[i][j];
          sumOfCol[j]+=arr[i][j];
        }
      sumOfAll+=sumOfRow[i];
    }
  for(i=0;i<r;i++)
    {
      for(j=0;j<c;j++) printf("%d ",arr[i][j]);
      printf("%d\n",sumOfRow[i]);
    }
  for(j=0;j<c;j++) printf("%d ",sumOfCol[j]);
  printf("%d\n",sumOfAll);
  return 0;
}


Measured memory_bytes: 2108
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    for(int i=1;i<1001;i++){
        double q,w;
        q = i * 0.08;
        w = i * 0.10;
        if((int)q == a){
            if((int)w == b){
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << -1 <<endl;
    return 0;
}

Measured memory_bytes: 3632
using System;

class Program
{
  public static void Main(string[] args)
  {
    string[] tmp = Console.ReadLine().Split(' ');
    int[] numbers = new int[3];
    for(int i = 0;i < 3;i++)
    {
      numbers[i] = int.Parse(tmp[i]);
    }
    if(numbers[0] < numbers[1] && numbers[1] < numbers[2]){
      Console.WriteLine("Yes");
    }
    else Console.WriteLine("No");
  }
}

Measured memory_bytes: 8956
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <string.h>

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

int main(void)
{
    int N;
    scanf("%d",&N);
    int array[N];
    for (int i=0; i<N; i++)
    {
        scanf("%d",&array[i]);
    }
    qsort(array, N, sizeof(int), cmpfunc);

    int min = INT_MAX;

    int count = 0;

    int sum =0;
    for (int i=array[0]; i<=array[N-1]; i++)
    {
        for (int j=0; j<N; j++)
        {
            sum+=pow((array[j]-i),2);
        }
        if (sum<min)
            min=sum;
        sum=0;
    }
    printf("%d",min);

    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
### classes

class Node
  attr_accessor :id, :lvds, :nbrs

  $nds = []
  $nn = 0
  
  def initialize(id)
    @id = id
    @lvds = []
    @nbrs = []
  end

  def self.add
    this = self.new($nn)
    $nds << this
    $nn += 1
    this
  end

  def self.clear
    $nds = []
    $nn = 0
  end
end

### subroutines

def same_dists(mtx, k)
  for nd in $nds
    sdist = mtx[k][0] - nd.lvds[0]
    ok = true
    for j in (1...k)
      d = mtx[k][j] - nd.lvds[j]
      if sdist != d
        ok = false
        break
      end
    end
    return [nd, sdist] if ok
  end
  [nil, nil]
end

### main

loop do
  n = gets.to_i
  break if n == 0

  mtx = n.times.map{gets.split.map(&:to_i)}
  #p mtx

  Node.clear
  nd0 = Node.add
  nd0.lvds << 1
  
  for k in (1...n)
    cnd, sdist = same_dists(mtx, k)
    if cnd.nil?
      p "error"
      exit
    end
    
    while sdist > 1
      nd = Node.add
      cnd.nbrs << nd
      nd.nbrs << cnd
      nd.lvds = cnd.lvds.map{|d| d + 1}
      sdist -= 1
      cnd = nd
    end

    cnd.lvds[k] = 1
    q = [cnd]
    while ! q.empty?
      u = q.shift
      nvd = u.lvds[k] + 1
      for v in u.nbrs
        if v.lvds[k].nil?
          v.lvds[k] = nvd
          q << v
        end
      end
    end
    #p lvs.map{|nd| nd.id}
    #p $nds.map{|nd| nd.to_s}
  end

  ndegs = $nds.map{|nd| nd.nbrs.length + nd.lvds.count{|d| d == 1}}
  puts ndegs.sort.join(' ')
end

Measured memory_bytes: 6360
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001
#define mod 1000000007

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int n;
    int l[max], r[max];
    int sum=0;
    
    scanf("%d", &n);
    rep(i, n){
        scanf("%d%d", &l[i], &r[i]);
        sum+=r[i]-l[i]+1;
    }
    
    printf("%d", sum);
    
    return 0;
}


Measured memory_bytes: 1752
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int digits(int X){ int sum = 0;
  while( X > 0){
    sum += X % 10;
    X /= 10;}
                  return sum;}

int main(){
  int X; cin >> X;
   int Y = digits(X);
  if( X % Y == 0){cout << "Yes" << endl;}
  else{cout << "No"<< endl;}
  
  return 0;}
    

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

#define TRUE 1
#define FALSE -1

class Array 
{
    protected:
        int *Sarray, *Tarray, slen, tlen;
    
    public:
        Array() : Sarray(NULL), Tarray(NULL), slen(0), tlen(0)
        {

        }

        void SetArray() {
            scanf("%d", &slen);
            Sarray = (int *)malloc(slen * sizeof(int));
            for(int i=0; i<slen; ++i)
                scanf("%d", &Sarray[i]);

            scanf("%d", &tlen);
            Tarray = (int *)malloc(tlen * sizeof(int));
            for(int i=0; i<tlen; ++i)
                scanf("%d", &Tarray[i]);
        }

        void PrintArray() {
            for(int i=0; i<slen; ++i) {
                if(!i) printf("Sarray ");
                if(i) printf(" ");
                printf("%d", Sarray[i]);
            }
            printf("\n");

            for(int i=0; i<tlen; ++i) {
                if(!i) printf("Tarray ");
                if(i) printf(" ");
                printf("%d", Tarray[i]);
            }
            printf("\n");
        }

        int getslen() {
            return slen;
        }

        int gettlen() {
            return tlen;
        }
        
        int* getSptr() {
            return (&Sarray[0]);
        }

        int* getTptr() {
            return (Tarray);
        }

        void freeArray() {
            free(Sarray);
            free(Tarray);
        }
};

class ExhaustiveSearch : public Array
{
    private:
        int res;
    public:
        ExhaustiveSearch() : res(0)
        {

        }
        int solve(int i, int m) {
            if(m == 0)
                return true;
            
            if(i >= slen)
                return false;

            res = solve(i + 1, m) || solve(i + 1, m - Sarray[i]);
            return res;
        }

        void searching() {
            int ret;
            SetArray();
            for(int i=0; i<tlen; ++i) {
                ret = solve(0, Tarray[i]);
                if(ret == 0) puts("no");
                else puts("yes");
            }
            freeArray();
        }
};
int main() {
    ExhaustiveSearch _ex;
    _ex.searching();
    return 0;
}


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

int main() {
  int n;cin>>n;
  vector<int> vec(n),p(n),q(n);
  rep(i,n)vec[i]=i+1;
  map<vector<int>,int> mp;
  rep(i,n)cin>>p[i];
  rep(i,n)cin>>q[i];
  do{
    mp[vec]=mp.size();
  }while(next_permutation(all(vec)));
  int ans=abs(mp[p]-mp[q]);
  cout<<ans<<endl;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int a, b, c, x; cin >> a >> b >> c >> x;
    int ans = 0;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                int sum = i * 500 + j * 100 + k * 50;
                if(sum == x) ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
N,Q = map(int,input().split())

adj = [list() for _ in range(N)]
for _ in range(N-1):
    a,b = map(int,input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)

memo = [0]*N
for _ in range(Q):
    p,x = map(int,input().split())
    memo[p-1] += x

result = [0]*N
stack = [(None,0)]
while stack:
    p,v = stack.pop()
    result[v] += memo[v]
    for u in adj[v]:
        if u == p:
            continue
        result[u] += result[v]
        stack.append((v,u))

print(*result)

Measured memory_bytes: 136804
use std::io::stdin;
use std::str::FromStr;

fn main(){
    let (a, b): (i64, i64) = get_pair();
    let ans = vec_max(&vec![2*a-1, 2*b-1, a+b]);
    println!("{}", ans);
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}

#[allow(dead_code)]
fn vec_min(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MAX, std::cmp::min)
}

#[allow(dead_code)]
fn vec_max(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MIN, std::cmp::max)
}

#[allow(dead_code)]
fn vec_sum(xs: &Vec<i64>) -> i64 {
    xs.iter().fold(0, |acc, &x| acc+x)
}


Measured memory_bytes: 4352
S = input()

ans = 0 
ans_lis = [0]

for i in range(len(S)):
    if S[i] in "ACGT":
        ans = ans + 1 
        if i == (len(S)-1):
            ans_lis.append(ans)
    else:
        ans_lis.append(ans)
        ans = 0 

print(max(ans_lis))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
int exp(int x,int y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x);
    int t=exp(x,y/2);
    return (t*t);
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}

int main(){
  int n,m;cin >> n >> m;
  vector<int> money(m);
  vector<bitset<12>> can(m,bitset<12>(0));
  rep(i,m){
    int b;
    cin >> money[i] >> b;
    rep(j,b){
      int k;cin >> k;k--;
      can[i][k]=1;
    }
  }
  
  //鍵の開いているか否かは2^12通り
  //それをbitで表現してdp
  //dp[i][j]:=(0_indexでの)i-1番までの鍵でjにする時の費用のmin
  //can[s]のbitをkとして
  //dp[i+1][j+k]=min(dp[i+1][j+k],dp[i][j]+money[s])
  //dp[i+1][j]=min(dp[i][j],dp[i+1][j])
  
  vector<vector<ll>> dp(m+1,vector<ll>(exp(2,n),1000000000));
  dp[0][0]=0;
  
  rep(i,m){
    //i番の鍵を使う.dp[i+1][]を更新していく
    rep(j,exp(2,n)){
      dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
      bitset<12> s(j);
      s =(s|can[i]);//jと新しい鍵で論理和を取る
      int t=s.to_ullong();
      dp[i+1][t]=min(dp[i+1][t],dp[i][j]+money[i]);
    }
  }
  
  if(dp[m][exp(2,n)-1]>=1000000000)cout << -1 << endl;
  else cout << dp[m][exp(2,n)-1] << endl;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    unordered_map<int, int> m;
    REP(i, N) {
        if (m.count(a[i])) {
            m[a[i]]++;
        } else {
            m[a[i]] = 1;
        }
    }
    int ans = 0;
    for (auto item : m) {
        if (item.first == item.second) {
            continue;
        } else if (item.first > item.second){
            ans += item.second;
        } else if (item.first < item.second){
            ans += item.second - item.first;
        }
    }
    cout << ans << endl;
}

signed main() {
    solve();
}


Measured memory_bytes: 4644
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stdio.h>

using namespace std;
int main(void)
{
    int w, h, n;
    int x, y, a;
    int s[105][105];

    cin >> w >> h >> n;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            s[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++) {
        cin >> x >> y >> a;
        switch (a)  {
            case 1:
                for (int j = 0; j < h; j++) {
                    for (int k = 0; k < x; k++) {
                        s[j][k] = 1;
                    }
                }
                break;
            case 2:
                for (int j = 0; j < h; j++) {
                    for (int k = x; k < w; k++) {
                        s[j][k] = 1;
                    }
                }
                break;
            case 3:
                for (int j = 0; j < y; j++) {
                    for (int k = 0; k < w; k++) {
                        s[j][k] = 1;
                    }
                }
                break;
            case 4:
                for (int j = y; j < h; j++) {
                    for (int k = 0; k < w; k++) {
                        s[j][k] = 1;
                    }
                }
                break;
            default:
                continue;
        }
    }

    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (s[i][j] == 0) {
                ans++;
            }
        }
    }

    cout << ans << endl;


    return 0;
}

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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

signed main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;
  for (int r = 0; r <= 3000; r++) {
    for (int g = 0; g <= 3000; g++) {
      int tmp = r * R + g * G;
      if (N - tmp >= 0 && (N - tmp) % B == 0) {
        ans++;
      }
    }
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
using namespace std;
const char Alpha[] = "ABCDEFGHIJKOMNOPQRSTUVWXYZ";
const char alpha[] = "abcdefghijkomnopqrstuvwxyz";

int main(){
  string str;

  getline(cin, str);

  // for (size_t i = 0; i < str.size(); ++i)
  //   {
  //     if (str[i] >= 'a' && str[i] <= 'z')
  //       {
  //         str[i] = Alpha[(int)(str[i]-'a')];
  //       }
  //     else if (str[i] >= 'A' && str[i] <= 'Z')
  //       {
  //         str[i] = alpha[(int)(str[i]-'A')];
  //       }
  //   }
  for (size_t i = 0; i < str.size(); ++i)
    {
      if (islower(str[i]))
        {
          str[i] = toupper(str[i]);
        }
      else if (isupper(str[i]))
        {
          str[i] = tolower(str[i]);
        }
    }
  cout << str << endl;
}

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

#define int long long
#define endl '\n'

#ifdef LOCAL
#include <C:\Programs\prettyprint.hpp>
template <typename ...Ts>
void trace1(Ts ...T){ ((cerr << "{ " << T << " }\n" ), ...); }
#define trace(...) cerr << "[" #__VA_ARGS__ << "] : " << '\n', trace1(__VA_ARGS__), cerr << '\n';
#else
#define trace(...)
#define trace1(...)
#endif

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    for (auto &i: a)    cin >> i;
    for (auto &i: b)    cin >> i;
    sort(a.begin(), a.end());
    sort(b.rbegin(), b.rend());
    priority_queue<pair<int, int>> pq;
    int lo = 0, hi = 0, ans;
    for (int i = 0; i < n; i++) {
        pq.push({a[i] * b[i], a[i]});
        hi = max(hi, a[i] * b[i]);
    }
    auto ops = [&] (int mid) {
        auto q = pq;
        int ret = 0;
        while (q.top().first > mid) {
            int x = q.top().first, y = q.top().second;
            q.pop();
            x /= y;
            ret += y - mid / x;
            y = mid / x;
            x *= y;
            q.push({x, y});
        }
        return ret;
    };
    while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (ops(mid) <= k) {
            ans = mid;
            hi = mid - 1;
        } else {
            lo = mid + 1;
        }
    }
    cout << ans;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int n,p;
    while (cin >> n >> p, n) {
        vector<int> st(n,0);
        int wan = p;
        int pl = 0;
    
        while (true) {
            if (wan == 0) {
                wan += st[pl];
                st[pl] = 0;
            }
            else {
                st[pl]++;
                if (st[pl] == p) break;
                wan--;
            }
            pl = (pl + 1) % n;
        }
        cout << pl << endl;
    }

    return 0;
}


Measured memory_bytes: 2976
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; typedef long double ld;
const int INF32 = 1e9+10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int H, W; cin >> H >> W;
  char a[110][110];
  bool h[110]; bool w[110];
  for (int i = 0; i < 110; i++) {
    h[i] = false; w[i] = false;
  }
  for (int j = 0; j < H; j++) {
    for (int i = 0; i < W; i++) {
      cin >> a[j][i];
      if (a[j][i] == '#') {
        h[j] = true; w[i] = true;
      }
    }
  }
  for (int j = 0; j < H; j++) {
    for (int i = 0; i < W; i++) {
      if (h[j] && w[i])
        cout << a[j][i];
    }
    if (h[j])
      cout << '\n';
  }
  /*int h[110]; int w[110];
  for (int i = 0; i < 110; i++) {
    h[i] = 1; w[i] = 1;
  }
  for (int i = 0; i < W; i++) {
    int c = 0;
    for (int j = 0; j < H; j++)
      c += (a[j][i] == '.');
    if (c == H)
      w[i] = 0;
  }
  for (int j = 0; j < H; j++) {
    int c = 0;
    for (int i = 0; i < W; i++)
      c += (a[j][i] == '.');
    if (c == W)
      h[j] = 0;
  }
  for (int j = 0; j < H; j++) {
    for (int i = 0; i < W; i++) {
      if (!(h[j] == 0 || w[i] == 0))
        cout << a[j][i];
    }
    if (h[j] != 0)
      cout << endl;
  }*/
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる






int main() {
  string s,t;
  cin>>s>>t;
  int n=s.size();
  int m=t.size();

  int ans[n+10][m+10]={};

  rep(i,n+1){
    rep(j,m+1){
      chmax(ans[i+1][j],ans[i][j]);
      chmax(ans[i][j+1],ans[i][j]);
      if(i<n && j<m && s[i]==t[j]) chmax(ans[i+1][j+1],ans[i][j]+1);
    }
  }

  string x="";
  while(1){
    if(ans[n][m]==ans[n-1][m]) n--;
    else if(ans[n][m]==ans[n][m-1]) m--;
    else {
      x=s[n-1]+x;
      n--;m--;
    }
    if(n==0||m==0) break;
  }

  cout << x << endl;
}


Measured memory_bytes: 35712
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
	int w,n,a,b; cin >> w >> n;
	int* num = new int[w+1];

	for(int i=0; i<w+1; i++){ num[i]=i;}
	for(int i=0; i<n; i++){
		scanf("%d,%d", &a, &b);
		swap(num[a],num[b]); 
	}
	for(int i=1; i<w+1; i++){ cout << num[i] << endl;}

	delete[] num;
	return 0;
}

Measured memory_bytes: 1240
X, n = map(int,input().split())

if n == 0:
    print(X)
    exit()

l = list(map(int,input().split()))
#print(X,n)
#print(l)



l = sorted(l)
#print(l)
l_min = min(l)
l_max = max(l)

x = [i for i in range(l_min, l_max+1)]

x = [l_min-1] + x + [l_max+1]
#print(x)

y = []
for j in x:
    if j not in l:
        y.append(j)
#print(y)

ans = 0
tmp = 1000
for k in y:
    if tmp > abs(k - X):
        tmp = abs(k - X)
        ans = k

print(ans)



Measured memory_bytes: 9164
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <string.h>
#include <algorithm>
#include <utility>
#include <iomanip>

using namespace std;

pair<string, int> p;
int N;
string X;
int main(){
    cin >> N;
    vector<pair<string,int>> pla(N);
    for(int i = 0; i < N; i++){
        cin >> p.first >> p.second;
        pla[i] = p;
    }
    cin >> X;
     
    int ptr = 0;
    int ttl = 0;
    for(int i = 0; i < N; i++){
        if(ptr){
            ttl += pla[i].second;
        }
        if(pla[i].first == X){
            ptr = 1;
        }
    }

    cout << ttl << endl;
}

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

int main(void){
    int h,n,sum=0 ;
    cin >> h >> n ;
    for (int i=0; i<n; i++){
        int x ;
        cin >> x ;
        sum+=x ;
    }
    if (sum>=h){
        cout << "Yes" << endl ;
    } else {
        cout << "No" << endl ;
    }
}

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

int main()
{
  vector<int> x(5);
  rep(i, x.size()) cin >> x.at(i);

  rep(i, x.size())
  {
    if (x.at(i) == 0)
    {
      cout << i+1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3496
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
#define int long long
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
const ll MOD = 1e9+7;
const int MAX = 1001001;
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i % MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i) % MOD;
        finv[i]=finv[i-1]*inv[i] % MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0 || k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;
}
signed main(){
    COMinit();
    int n; cin >> n;
    vector<ll> a(n),x(n);
    rep(i,n) cin >> a[i];
    rep(i,n-1) x[i]=a[i+1]-a[i];
    vector<ll> sum(n);
    sum[1]=1;
    for(int i=2;i<n;i++){
        sum[i]=sum[i-1]+inv[i];
    }
    ll ans=0;
    rep(i,n){
        ll res=(x[i]*sum[i+1])%MOD;
        ans+=res; ans%=MOD;
    }
    for(ll i=1;i<n;i++){
        ans*=i;
        ans%=MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 26112
#include <bits/stdc++.h>
#include <cstdlib>  
#include <cmath>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using P= pair<ll,ll>;
 
int main() {
    int N,X,T;
    cin>>N>>X>>T;
    int count=N/X;
    if(N%X==0)
    {
      cout<<count*T<<endl;
    }else{
      cout<<(count+1)*T<<endl;  
    }
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

vector<vector<pil>> Graph(100010);
vector<long> dis(100010,-1);

void dfs(int v, int pv){
  for(pil P : Graph.at(v)){
    int nv = P.first;
    if(nv == pv) continue;
    long cost = P.second;
    dis.at(nv) = dis.at(v) + cost;
    dfs(nv,v);
  }
  return;
}

int main(){
  int n;
  cin >> n;
  rep(i,n-1){
    int a,b;
    long c;
    cin >> a >> b >> c;
    Graph.at(a-1).push_back(pil(b-1,c));
    Graph.at(b-1).push_back(pil(a-1,c));
  }
  int q,k;
  cin >> q >> k;
  dis.at(k-1) = 0;
  dfs(k-1,-1);

  rep(i,q){
    int x,y;
    cin >> x >> y;
    cout << dis.at(x-1) + dis.at(y-1) << endl;
  }
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main()
{
    cin>>n>>m;
    int a[m][2],b[n];
    memset(b,0,sizeof(b));
    for(int i=0;i<m;i++)
        cin>>a[i][0]>>a[i][1];
    for(int i=0;i<m;i++){
        b[a[i][0]-1]++;
        b[a[i][1]-1]++;
    }
    for(int i=0;i<n;i++)
        cout<<b[i]<<endl;
    return 0;
}


Measured memory_bytes: 256
s = gets.chomp
(s.length - 1).times do |i|
  if s[i] == s[i + 1]
    puts [i + 1, i + 2].join(' ')
    exit
  end
  if s[i] == s[i + 2]
    puts [i + 1, i + 3].join(' ')
    exit
  end
end
puts [-1, -1].join(' ')


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

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)

//vector<vector<int>> data(, vector<int>());

int main(){
    string s;
    cin >> s ;
    
    int ans=0;
    rep(i,4){
        if(s[i] == '+' ) ans++;
        if(s[i] == '-' ) ans--;
    }

    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {

	double n, m, d;
	cin >> n >> m >> d;
	if (d != 0) {
		cout << fixed << setprecision(10) << 2 * (n - d) * (m - 1) / (n * n) << endl;

	}
	else {
		cout << fixed << setprecision(10) <<  (m - 1) / n << endl;

	}
	}

Measured memory_bytes: 3780