akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;

bool even(int n) { return n % 2 == 0; }

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  int m = max(max(A, B), C);
  int m3 = m * 3;
  int tot = A + B + C;

  int ans = 0;
  if (even(m3) && even(tot) || !even(m3) && !even(tot)) {
    ans = (m3 - tot) / 2;
  } else {
    ans = ((m + 1) * 3 - tot) / 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int t, x; cin >> t >> x;
  double ans = (double)t/x;
  cout << ans << '\n';
  return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

ll n;
vvll to,dis;

void dfs(ll cur, ll pre, ll dist, ll which){
	dis[which][cur]=dist;
	for(auto&& next:to[cur]){
		if(next==pre) continue;
		dfs(next,cur,dist+1,which);
	}
}

int main()
{
	ll u,v,a,b,ans=0;
	cin >> n >> u >> v;
	u--;
	v--;
	to.resize(n);
	dis.resize(2,vll(n));
	rep(i,n-1){
		cin >> a >> b;
		a--;
		b--;
		to[a].pb(b);
		to[b].pb(a);
	}
	dfs(u,-1,0,0);
	dfs(v,-1,0,1);
	rep(i,n){
		if(dis[0][i]<dis[1][i]) chmax(ans,dis[1][i]-1);
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main()
{
	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	vector<long long> v1 = { a, b };
	vector<long long> v2 = { c, d };

	if (a < 0 && 0 < b) v1.push_back(0);
	if (c < 0 && 0 < d) v2.push_back(0);

	long long ans = a * c;
	for (auto x : v1) {
		for (auto y : v2) {
			ans = max(ans, x * y);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3548
n = int(raw_input())
in_s = raw_input()
arr = map(int, in_s.split())
ans = 1<<30
for a in arr:
        cand = 0
        buf = a
        while True:
                if (buf%2) ==1:
                        break
                buf = buf/2
                cand+=1
        ans = min(ans,cand)
print ans


Measured memory_bytes: 2568
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
//#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


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

int main(){
  int N;
  cin >> N;
  while(N != 0){
    double ave = 0;
    vector<double> a(N);
    for(int i=0; i<N; i++){
      cin >> a[i];
      ave += a[i];
    }
    ave /= N;
    double ans=0;
    for(int i=0; i<N; i++){
      ans += (a[i]-ave)*(a[i]-ave);
    }
    ans /= N;
    cout<< fixed << setprecision(10) << sqrt(ans) << endl;
    cin >> N;
  }
  return 0;
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int x, y;
    cin >> x >> y;

    int opCount = 0;
    if (abs(x) == abs(y)) {
        if (x == y)
            opCount = 0;
        else
            opCount = 1;
    } else if (abs(x) < abs(y)) {
        if (x < 0) opCount += 1;
        opCount += abs(y) - abs(x);
        if (y < 0) opCount += 1;
    } else {  // abs(x) > abs(y)
        if (x > 0) opCount += 1;
        opCount += abs(x) - abs(y);
        if (y > 0) opCount += 1;
    }
    cout << opCount << endl;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	string a, b, c;
	cin >> a >> b;
	c = a + b;
	int num = stoi(c);
	REPS(i, sqrt(100100)) {
		if (num == i * i) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <deque>
using namespace std;

int main() {
    int L, R;
    cin >> L >> R;
    int bl = L / 2019;
    int modl = L % 2019;
    int modr = R % 2019;
    if( (modl > 0 && R >= (bl + 1) * 2019) || modl == 0)
    {
        cout << 0;
        return 0;
    }

    int m = __INT_MAX__;
    for(int i = modl; i < modr; ++i)
    {
        for(int j = i + 1; j <= modr; ++j)
        {
            int m_c = (i * j) % 2019;
            
            if(m_c < m)
            {
                m = m_c;
            }
        }
    }
    cout << m;
}


Measured memory_bytes: 384
import java.util.*;
 
public class Main {
  public static void main(String[] args)  {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int a = Integer.parseInt(s.substring(0, 1));
    int b = Integer.parseInt(s.substring(1, 2));
    int c = Integer.parseInt(s.substring(2, 3));
    int d = Integer.parseInt(s.substring(3, 4));
    
    if (a + b + c + d == 7) {
      System.out.println(a + "+" + b + "+" + c + "+" + d + "=7");
      return;
    }
    if (a + b + c - d == 7) {
      System.out.println(a + "+" + b + "+" + c + "-" + d + "=7");
      return;
    }
    if (a + b - c + d == 7) {
      System.out.println(a + "+" + b + "-" + c + "+" + d + "=7");
      return;
    }
    if (a + b - c - d == 7) {
      System.out.println(a + "+" + b + "-" + c + "-" + d + "=7");
      return;
    }
    if (a - b + c + d == 7) {
      System.out.println(a + "-" + b + "+" + c + "+" + d + "=7");
      return;
    }
    if (a - b + c - d == 7) {
      System.out.println(a + "-" + b + "+" + c + "-" + d + "=7");
      return;
    }
    if (a - b - c + d == 7) {
      System.out.println(a + "-" + b + "-" + c + "+" + d + "=7");
      return;
    }
    if (a - b - c - d == 7) {
      System.out.println(a + "-" + b + "-" + c + "-" + d + "=7");
      return;
    }
  }
}

Measured memory_bytes: 39588
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

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

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

ll inf =1e9+7;

#define pi 3.14159265358979323846L
bool isprime(ll a)
{
	
	ll cnt=0;	
	for(ll i=1;i*i<a;i++)
	{
		
	 	if(a%i==0)
	 	{
	 		cnt+=2;
		 }
		
		
	}
	
		if(cnt==2)
		return true;
		else
		return false;
		
}
ll mod(ll a)
{
	if(a<inf)return a;
	else
	return a%inf;
}
void solve()
{

string s,t;
cin>>s>>t;
if(s==t.substr(0,s.size()) &&t.size()==s.size()+1)
{
	cout<<"Yes";
	
}
else
cout<<"No";
}

int main()
{


ios::sync_with_stdio(0); 
	cin.tie(0);

		solve();
	
return 0;

		
	}
	
	
	


Measured memory_bytes: 3644
from collections import deque
 
N = int(input())
Ass = tuple(deque(map(int, input().split())) for _ in range(N))
 
dp = [0 for _ in range(N)]
Q = set(range(N))
ans = -1
while Q:
    ans += 1
    Q2 = Q.copy()
    Q.clear()
    for i in Q2:
        if not Ass[i]:
            continue
        t = Ass[i][0] - 1
        if not Ass[t]:
            continue
        if Ass[t][0] == i + 1:
            Q.add(i)
            Q.add(t)
    for i in Q:
        Ass[i].popleft()

if any(Ass):
    print(-1)
else:
    print(ans)

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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORD(i,a,n) for(int i=(a); i>=(n); i--)
#define REPD(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
	int a,b;
	cin >> a >> b;
	int ans = -1;

	if(a > 9 || b > 9) {
		cout << ans << endl;
	} else {
		cout << a*b << endl;
	}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> triple;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define popb()      pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define ast(x,a,b)  assert(x>=a and x<=b)				
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define se          second
#define fi          first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


ll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	sc(n);
	pr(n*n*n);

	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ll JUDGE_ONLINE = 1;
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	}
	if (!JUDGE_ONLINE) cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";  
		
}

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

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

int main(void)
{
	int n;
	while (cin >> n, n){
		int field[21][21];
		int x, y, jewel = 0, dir = 0;
		for (int i = 0; i < 21; i++) fill(field[i], field[i] + 21, 0);
		for (int i = 0; i < n; i++){
			cin >> x >> y;
			field[y][x] = 1;
			if (x == 10 && y == 10) {
				jewel--;
				field[y][x] = 0;
			}
			jewel++;
		}
		int m, move, nx = 10, ny = 10;
		char c;
		cin >> m;
		for (int i = 0; i < m; i++){
			cin >> c >> move;
			if (c == 'N') dir = 1;
			if (c == 'E') dir = 0;
			if (c == 'S') dir = 3;
			if (c == 'W') dir = 2;
			for (int j = 0; j < move; j++){
				nx += dx[dir];
				ny += dy[dir];
				if (field[ny][nx] == 1){
					field[ny][nx] = 0;
					jewel--;
				}
			}
		}
		
		if (jewel) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a;i<=b;++i)
typedef long long ll;
const int N = 2e5+50;
int sze[N];
signed main() {
	int n,a;
	scanf("%d",&n);
	f(i,2,n) {
		scanf("%d",&a);
		++sze[a];
	} 
	f(i,1,n) printf("%d\n",sze[i]);
}


Measured memory_bytes: 4496
main :: IO ()
main = do
    n <- read <$> getLine
    s <- getLine
    putStrLn $ show $ solve n s


solve :: Int -> String -> Int
solve n s = maximum $ map sameCount $ cutEnum n s


sameCount :: (String, String) -> Int
-- aとbに共に含まれる文字の数をカウント
-- ("aab", "bca") -> 2 ('a', 'b'が該当)

sameCount (a, b) =
    length [x | x <- ['a'..'z'], x `elem` a && x `elem` b]


cutEnum :: Int -> String -> [(String, String)]
-- 切断した文字列のペアを作成
-- "abcd" -> [("a", "bcd"), ("ab", "cd"), ("abc", "d")]

cutEnum 0 s = [splitAt 0 s]
cutEnum n s = (splitAt n s) : cutEnum (n - 1) s

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

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            n = input()
            if n == 0:
                break
            w, h = map(int, raw_input().split())
            m = [[None for j in range(w+1)] for i in range(h+1)]
            for i in range(n):
                x, y = map(int, raw_input().split())
                m[y][x] = '*'
            s, t = map(int, raw_input().split())
            ans = -1
            for i in range(1, h+1):
                for j in range(1, w+1):
                    count = 0
                    for k in range(t):
                        for l in range(s):
                            if i + k <= h and j + l <= w and m[i+k][j+l] == '*':
                                count += 1
                    if ans < count:
                        ans = count            
            print ans
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Measured memory_bytes: 4816
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  for (int W = 0; ; W++) {
   int A, B;
   cin >> A >> B;
    if (A == 0 && B == 0) {
     break;
    }
    for (int X = 0; X < A; X++) {
     for (int Y = 0; Y < B; Y++) {
      cout << "#";
     }
     cout << endl;
    }
    cout << endl;
  }
}


Measured memory_bytes: 3076
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int ans = 0;
		for (int i = 0; i < N; i++) {
			int x = sc.nextInt();
			ans += Math.min(x * 2, Math.abs(x - K) * 2);
		}
		System.out.println(ans);
		sc.close();
	}

}

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

using namespace std;

int main()
{
  int n; cin >> n;
  int a[200000]; for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a+n);
  for (int i = 0; i < n-1; ++i)
    if (a[i] == a[i+1]) {cout << "NO" << endl; return 0;}
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF=2e18;
string S;
ll Q;
int main(){
    cin>>Q;
    for(ll i=0;i<Q;i++){
        ll A,B;
        cin>>A>>B;
        ll border;
        if(A==B){
            border=A-1;
        }
        else{
            border=sqrt(A*B);
        }
        if(border==0){
            cout<<0<<endl;
            continue;
        }
        ll x = (A*B%border==0 ? -1:0);
        ll y = (A*B%border==0 ? -1:0);
        cout<<(A*B/border+x)-(min(A,B)+1) +border + min(A,B)-1<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_N 10000
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

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

int n;
vector< int > graph[MAX_N];
priority_queue< int, vector< int >, greater< int > > pq;

void dfs(int v, bool visited[], int d[]){
  if(visited[v]) return;
  visited[v] = true;
  for(int w: graph[v]){
    dfs(w, visited, d);
  }
  d[v] = pq.top();
  pq.pop();
}

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

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

  for(int i = 0; i < n - 1; i++){
    graph[a[i]].push_back(b[i]);
    graph[b[i]].push_back(a[i]);
  }
  for(int i = 0; i < n; i++){
    pq.push(c[i]);
  }

  int d[n];
  bool visited[n];
  fill(visited, visited + n, false);

  dfs(0, visited, d);

  int m = 0;
  int mx = 0;
  for(int i = 0; i < n; i++){
    m += c[i];
    mx = max(mx, c[i]);
  }
  m -= mx;

  string buf;
  buf += to_string(m) + "\n";
  for(int i = 0; i < n; i++){
    buf += to_string(d[i]) + " ";
  }

  cout << buf << endl;

  return 0;
}


Measured memory_bytes: 1920
def yaku(n, ns)
  if n == 2
    ns.each do |k|
      return true if k == 2
    end

    return false
  end

  for i in (0..6)
    if ns[i] > 0 && ns[i + 1] > 0 && ns[i + 2] > 0
      ns[i] -= 1
      ns[i + 1] -= 1
      ns[i + 2] -= 1

      return true if yaku(n - 3, ns)

      ns[i] += 1
      ns[i + 1] += 1
      ns[i + 2] += 1
    end
  end

  for i in (0..8)
    if ns[i] >= 3
      ns[i] -= 3

      return true if yaku(n - 3, ns)

      ns[i] += 3
    end
  end

  false
end

### main

while (line = gets)
  ns = (0..8).map{0}
  line.chomp.split("").each{|s| ns[s.to_i - 1] += 1}

  ws = []

  for i in (0..8)
    if (ns[i] < 4)
      ns0 = ns.clone
      ns0[i] += 1
      ws.push(i + 1) if yaku(14, ns0)
      ns0[i] -= 1
    end
  end

  puts (ws.length == 0) ? "0" : ws.join(" ")
end

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

void intarrayinput(int sz,int a[]){for(int ___=0;___<sz;++___)scanf("%d",a+___);}
void intarrayoutput(int sz,int a[]){for(int ___=0;___<sz;++___)printf("%d ",a[___]);printf("\n");}
template<class T>T emin(T& t1,T t2){if(t1>t2)return t1=t2;else return t1;}
template<class T>T emax(T& t1,T t2){if(t1<t2)return t1=t2;else return t1;}
template<class T1,class T2>ostream& operator<<(ostream& out,pair<T1,T2> _p){out<<_p.first<<" "<<_p.second;return out;}
template<class T>ostream& operator<<(ostream& out,vector<T> _v){for(int i=0;i<_v.size();++i)out<<_v[i]<<(i+1==_v.size()?"":" ");return out;}
template<class T>void byebye(T t){cout<<t<<endl;exit(0);}

const int maxn=100005;

int n,m;
int a[maxn],b[maxn];
vector<int> t[maxn];
priority_queue<int> task;

ll ans;

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;++i){
		scanf("%d%d",a+i,b+i);
		if(a[i]>m)continue;
		t[m-a[i]].push_back(b[i]);
	}
	for(int i=m;i>=0;--i){
		for(int j=0;j<t[i].size();++j)task.push(t[i][j]);
		if(task.empty())continue;
		ans+=task.top();
		task.pop();
	}
	printf("%lld\n",ans);
	return 0;
}




Measured memory_bytes: 6400
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
    int N;
    long long int ans;
    cin >> N;
    int F[N][10],P[N][11];
    for(int i=0;i<N;i++){
        for(int j=0;j<10;j++){
            cin >> F[i][j];
        }
    }

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

    for(int i=1;i<pow(2,10);i++){
        long long int now=0;
        vector<int> bit(10);
        for(int j=0;j<10;j++){
            bit[j] = (i>>j)&1;
        }

        for(int j=0;j<N;j++){
            int sum = 0;
            for(int k=0;k<10;k++){
                if(F[j][k] && bit[k]){
                    sum++;
                }
            }
            now += P[j][sum];
        }
        if(i==1){
            ans = now;
        }else{
            ans = max(ans,now);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
function main(input) {
    input = input.split(" ");
    var n = parseInt(input[0], 10);
    var m = parseInt(input[1], 10);

    if (n===m) {
        console.log("Yes")
    } else {
        console.log("No")
    }
  }
   
  main(require("fs").readFileSync("/dev/stdin", "utf8"));



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

typedef long long ll;
typedef vector<int> vi;

string S, T;
int sz_s, sz_t;
vector<vi> C;

void input_init(void) {
	cin >> S >> T;
	sz_s = S.length();
	sz_t = T.length();
	C.resize(26);
	for (int i = 0; i < sz_s; ++i) {
		int idx = (int)(S[i] - 'a');
		C[idx].push_back(i);
	}
}

bool enable(void) {
	bool ret = true;
	for (int i = 0; i < sz_t; ++i) {
		int idx = (int)(T[i] - 'a');
		if (C[idx].size() == 0) {
			ret = false;
			break;
		}
	}
	return ret;
}

ll solve(void) {
	int cnt = 0;
	int sp = 0;
	int st = 0;
	int pre = -1;
	while (st < sz_t) {
		int idx = (int)(T[st] - 'a');
		vector<int>::iterator itr;
		itr = upper_bound(C[idx].begin(), C[idx].end(), pre);
		if (itr == C[idx].end()) {
			++cnt;
			pre = -1;
		}
		else {
			pre = *itr;
			++st;
		}
	}
	ll ret = (ll)sz_s * cnt + pre + 1;
	return ret;
}

int main(void) {
	input_init();
	ll ans = (ll)-1;
	if (enable())
		ans = solve();
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1216
N = int(input())

AB = []
for n in range(N):
    AB.append(list(map(int,input().split())))

aaa = sorted(AB, key=lambda x:(x[1]))

sumW = 0
for a in aaa:
    sumW += a[0]
    if sumW > a[1]:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 89816
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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 dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int main(){
  ll n,k; cin >> n >> k;
  vector<ll> v(n);
  rep(i,0,n){
    cin >> v[i];
  }
  ll ans = 0;
  rep(i,0,n){
    ll m=0, al=0;
    rep(j,i,n-1){
      if(v[i]>v[j+1]) m++;
    }
    rep(j,0,n){
      if(v[i]>v[j]) al++;
    }
    ans += k*m % mod;
    ans %= mod;
    ans += ((((k-1)*k)/2)%mod) * (al) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
int main(void){
    int c[] = {0, 6000, 4000, 3000, 2000};
    int t, p;
    for (int i = 0; i < 4; i++) {
        scanf("%d %d", &t, &p);
        printf("%d\n", c[t]*p);
    }
    return 0;
}



Measured memory_bytes: 2712
k, x = map(int, input().split())

min_x = x - (k - 1)
min_x = -1000000 if min_x < -1000000 else min_x

max_x = x + (k - 1)
max_x = 1000000 if max_x > 1000000 else max_x

xs = list(range(min_x, max_x + 1))
print(" ".join(map(str, xs)))

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
  int N;
  string s;
  cin >> N >> s;
  vector<int> R(N+1,0),W(N+1,0);
  int i;
  for(i=0;i<N;i++) {
    R[i+1] = R[i]+(s[i] == 'W'?1:0);
    W[i+1] = W[i]+(s[N-i-1] == 'R'?1:0);
  }
  int ans = N+1;
  for(i=0;i<=N;i++)ans = min(ans,max(R[i],W[N-i]));
  cout << ans << endl;
}

Measured memory_bytes: 5236
#include <stdio.h>
int main(void){
    int N, A, B, max, min;
    if (scanf("%d %d %d", &N, &A, &B) == -1) return -1;
    max = (A > B) ? B : A;
    min = (A + B - N > 0) ? A + B - N : 0;
    printf("%d %d\n", max, min);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
int main()
{
    int H, W;
    cin >> H >> W;
    vvint a(W, vint(H));
    rep(i, H)
    {
        rep(j, W)
        {
            cin >> a[j][i];
        }
    }
    //全部(0,0)に移動させる
    const int MAX = H * W;
    int N = 0;
    vint X(MAX), Y(MAX), X_(MAX), Y_(MAX);
    for (int x = W - 1; x >= 0; x--)
    {
        for (int y = H - 1; y >= 0; y--)
        {
            if (x == 0 and y == 0)
            {
                continue;
            }
            while (a[x][y] % 2 != 0)
            {
                X[N] = x;
                Y[N] = y;
                if (x == 0)
                {
                    X_[N] = x;
                    Y_[N] = y - 1;
                }
                else
                {
                    X_[N] = x - 1;
                    Y_[N] = y;
                }
                a[X_[N]][Y_[N]]++;
                a[x][y]--;
                N++;
            }
        }
    }
    cout << N << endl;
    rep(i, N)
    {
        cout << Y[i] + 1 << " " << X[i] + 1 << " " << Y_[i] + 1 << " " << X_[i] + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 7040
from heapq import heappush,heapify,heappop
INF = 10**10

n,m = map(int,input().split())

es=[[] for _ in range(n)] # es[i] = (頂点iの(隣接する頂点,コスト)の組)
d = [INF]*n # 頂点sからの最短距離
prev=[-1]*n # 経路復元

# 入力
for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    es[a].append((b,1))
    es[b].append((a,1)) # 無向グラフ


def dijkstra(s):
    v = -1
    que = [(0,s)]
    heapify(que)
    d[s] = 0
    while que:
        p = heappop(que)
        v = p[1]
        if d[v] < p[0]:
            continue
        for e in es[v]:
            if d[e[0]] > d[v] + e[1]:
                d[e[0]] = d[v] + e[1]
                heappush(que, (d[e[0]], e[0])) 
                prev[e[0]] = v
def get_path(t):
    path = []
    while t != -1:
        path.append(t)
        t = prev[t]
    path.reverse()
    return path
dijkstra(0)
print("Yes")
for i in range(1,n):
    print(prev[i]+1)

Measured memory_bytes: 107348
n = gets.to_i
dict = []
for i in 1..n do
  s, p = gets.chomp.split
  dict.push([i, s, p.to_i])
end
dict.sort! { |e, f|
  if e[1] == f[1]
    -e[2] <=> -f[2]
  else
    e[1] <=> f[1]
  end
}
dict.each { |e|
  puts e[0]
}


Measured memory_bytes: 1788
#include <iostream>

int dp[3030][3030];

int main(){
    std::string s, t;
    std::cin >> s >> t;
    bool flag = false;
    for(int i = 0; i < s.length(); i++){
        for(int j = 0; j < t.length(); j++){
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }else{
                dp[i+1][j+1] = std::max(dp[i][j+1], dp[i+1][j]);
            }
        }
    }

    int i = s.length(), j = t.length();
    std::string ans = "";
    while(i > 0 && j > 0){
        if(dp[i][j] == dp[i-1][j]){
            --i;
        }else if(dp[i][j] == dp[i][j-1]){
            --j;
        }else{
            ans = s[i-1] + ans;
            --i; --j;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 35840
N = int(input())
L = [tuple(map(int, input().split())) for _ in range(N)]

def get_H(Cx, Cy):
    for x, y, h in L:
        if h == 0:
            continue
        H = h + abs(x - Cx) + abs(y - Cy)
        if H >= 1:
            return H

def check(Cx, Cy, H):
    for x, y, h in L:
        if h != max(H - abs(x - Cx) - abs(y - Cy), 0):
            return False
    return True

for Cx in range(101):
    for Cy in range(101):
        H = get_H(Cx, Cy)
        if check(Cx, Cy, H):
            print(Cx, Cy, H)
            exit()

Measured memory_bytes: 3064
n = gets.chomp.to_i

m = -Float::INFINITY
num = gets.chomp.to_i
bottom = num
for i in 2..n do
  num = gets.chomp.to_i
  if num-bottom > m
    m = num-bottom
  end
  if bottom > num
    bottom = num
  end
end
printf("%d\n",m)


Measured memory_bytes: 8904
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: i32,
        b: i32,
    }
    println!("{}",
        std::cmp::max(a+b, std::cmp::max(a*b, a-b)));
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/27  Problem: ABC 111 C / Link: http://abc111.contest.atcoder.jp/tasks/abc111_c  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	LL N; 
	cin >> N;
	
	vector<LL> a,b;
	for (int i = 0; i < N; ++i) {
		LL x; cin >> x;
		if (i % 2) {
			a.push_back(x);
		}
		else {
			b.push_back(x);
		}
	}
	auto f = [](VL & a) {
		// aの頻度2top
		map<LL, LL>M;
		for (auto it : a) {
			M[it]++;
		}
		vector<PII> b;
		for (auto it : M) {
			b.push_back(PII(it.second,it.first));
		}
		b.push_back(PII(0, INF));
		RSORT(b);


		VI res({b[0].second,b[1].second});
		return res;
	};


	// 頻度2top
	VI as = f(a);
	VI bs = f(b);
	auto g = [](const VL& a, const LL x) {
		LL cnt = 0;
		for (auto it : a) {
			if (it != x)cnt++;
		}

		return cnt;
	};
	ans = INF;
	for (auto aa : as) {
		for (auto bb : bs) {
			if(aa!=bb)
			ans = min(ans, g(a,aa)+g(b,bb));
		}
	}


	
	cout << ans << "\n";

	return 0;
}


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

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

int main(){
    int A, B, K;
    cin >> A >> B >> K;

    int g = gcd (A, B);
    int ans;
    int cnt =0;
    for(int i=1; i<=g; i++){
        if(g%i == 0){
            cnt++;
        }
        if(cnt==K) {
            ans = g/i;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, j, n) for (int i = j; i < (n); ++i)
#define SORT(a) sort(a.begin(), a.end())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;


int GetDigit(int num){
    return std::to_string(num).length();
}

map< ll, int > prime_factor(ll n) {
  map< ll, int > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
    ll n;
    cin >> n;
    int ans = 100100100;
    for(ll i = 1; i * i <= n; i++) {
        if(n%i!=0) continue;
        int cd = n/i;
        ans = min(ans,max(GetDigit(i),GetDigit(cd)));
    }

    cout<<ans<<endl;
}

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

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

    ll n;
    cin>>n;
    ll a[n];
    for(int i = 0; i<n; i++){
        cin>>a[i];
    }
    sort(a , a + n , greater<ll>());
    ll ans = a[0];
    int m = 2;
    for(int i = 1; i<n; i++){
        if(m >= n){
            break;
        }
        ans += min((2LL)*a[i],(n - m)*a[i]);
        m+=2;
    }
    cout<<ans;
}

Measured memory_bytes: 5192
#include <iostream>

using namespace std;

struct card {
    char suit;
    int number;
    int order;

    bool operator<=(const card &other) { return this->number <= other.number; }
};

card deck[100010];

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

void quickSort(card a[], int p, int r) {
    if (p >= r) return;
    int q = partition(a, p, r);
    quickSort(a, p, q - 1);
    quickSort(a, q + 1, r);
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; deck[i].order = i++) cin >> deck[i].suit >> deck[i].number;
    quickSort(deck, 0, n - 1);
    int j = 0;
    for (; j < n; ++j) if (deck[j - 1].number == deck[j].number && deck[j - 1].order > deck[j].order) break;
    cout << (j == n ? "Stable" : "Not stable") << endl;
    for (int i = 0; i < n; ++i) printf("%c %d\n", deck[i].suit, deck[i].number);
    return 0;
}


Measured memory_bytes: 4312
N = int(input())

An = sorted([int(i) for i in input().split()])
Bn = map(int, input().split())
Cn = sorted([int(i) for i in input().split()])


def lowerBound(a, v):
    # 以上
    return lb(a, 0, len(a), v)


def upperBound(a, v):
    # より大きい
    # 値をプラス1
    return lb(a, 0, len(a), v + 1)


def lb(a, l, r, v):
    low = l - 1
    high = r

    while high - low > 1:
        mid = low + high >> 1
        if a[mid] >= v:
            high = mid
        else:
            low = mid

    return high


def main():
    print(sum([lowerBound(An, Bi)
               * (N - upperBound(Cn, Bi)) for Bi in Bn]))

    return


main()


Measured memory_bytes: 26528
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m;
    while(cin>>n>>m,n,m){
    	bool num[100000]={};
    	int co=0;
    	for(int i=0,x;i<m;i++){
    		cin>>x;
    		if(x==0)co++;
    		else num[x]=1;
    	}
    	int ans=0;
    	for(int i=1;i<=n-ans;i++){
    		if(num[i]){
    			for(int j=i+1,now=1,fin=co;;j++,now++){
    				if(!num[j]&&fin>0)fin--;
    				else if(!num[j]){
    					ans=max(ans,now);
    					break;
    				}
    			}
    		}
    	}
    	cout<<ans<<endl;
    }
}

Measured memory_bytes: 1264
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//????????????????????°?????\???
		int set = sc.nextInt();
		int[] num = new int[9];
		int[] color = new int[9];
		for (int setCount = 0; setCount < set; setCount++) {
			int RCount = 0;
			int GCount = 0;
			int[] used = new int[9];
			int trueSet = 0;
			//??\???
			for (int count = 0; count < 9; count++ ) {
				num[count] = sc.nextInt();
			}
			for (int count = 0; count < 9; count++) {
				String cl = sc.next();
				if (cl.equals("R") ) {
					color[count] = 0;
					RCount++;
				} else if (cl.equals("G") ) {
					color[count] = 1;
					GCount++;
				} else {
					color[count] = 2;
				}
			}
			//??????1
			if ((RCount == 0 && GCount == 0) || (RCount == 0 && GCount == 3) ||
				(RCount == 0 && GCount == 6) || (RCount == 3 && GCount == 0) ||
				(RCount == 3 && GCount == 3) || (RCount == 3 && GCount == 6) ||
				(RCount == 6 && GCount == 0) || (RCount == 6 && GCount == 3) ||
				(RCount == 9) || (GCount == 9)) {
				//?????????????????????????????????
				for (int i = 0; i < 8; i++) {
					for (int j = i+1; j < 9; j++) {
						if (num[i] > num[j]) {
							int numTaihi = num[i];
							num[i] = num[j];
							num[j] = numTaihi;
							int colorTaihi = color[i];
							color[i] = color[j];
							color[j] = colorTaihi;
						}
					}
				}
				//????????????????????????????????????
				for (int xMaime = 0; xMaime < 7; xMaime++) {
					if (used[xMaime] == 0) {
						for (int yMaime = xMaime + 1; yMaime < 8; yMaime++) {
							if (used[xMaime] == 1) {
								break;
							}
							if(used[yMaime] == 0) {
								for (int zMaime = yMaime + 1; zMaime < 9; zMaime++) {
									if (used[xMaime] == 1) {
										break;
									}
									if (used[zMaime] == 0) {
										if (color[xMaime] == color[yMaime] && color[xMaime] == color[zMaime]) {
											if (num[xMaime] == num[yMaime] && num[xMaime] == num[zMaime]) {
												trueSet++;
												used[xMaime]++;
												used[yMaime]++;
												used[zMaime]++;
											} else if (num[xMaime]+1 == num[yMaime] && num[yMaime]+1 == num[zMaime]) {
												trueSet++;
												used[xMaime]++;
												used[yMaime]++;
												used[zMaime]++;
											}
										}
									}
								}
							}
						}
					}
				}
				//??????
				if (trueSet == 3) {
					System.out.println(1);
				} else {
					System.out.println(0);
				}
			} else {
				System.out.println(0);
			}
		}
	}
}

Measured memory_bytes: 29028
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

vector<int> divisor(int n) {
  vector<int> ret;
  for(int i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
	int N;
	cin >> N;
	vector<int> a(N), c(N,0);
	rep(i, N) cin >> a[i];

	vector<int> b;

	for(int i=N-1; i>=0; i--) {
		//cout << "c,a " << c[i] << ' ' << a[i] << endl;
		if(c[i]==a[i]) continue;
		else {
			b.push_back(i); 
			//cout << "i: " << i << endl;
			for(auto j: divisor(i+1)) {
				c[j-1] = (c[j-1]+1)%2;
				//cout << "  j: " << j << "  c[j-1]: " << c[j-1] << endl;
			}
		}
	}

	cout << b.size() << endl; // M
	rep(i, b.size()) {
		cout << b[i]+1 << ' ';
	}
	cout << endl;

  return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}


int main(){
	int r, g, b;
	cin >> r >> g >> b;
	int s = r*100 + g*10 + b;
	Cout(YES(s%4==0));
}


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

using namespace std;
int main() {
	int n,a;
	vector<int> num(3,0);
	cin >> n;
	for (int i = 0; i < n;i++) {
		cin >> a;
		if (a%4 == 0) {
			num[0]++;
		}
		else if(a%2 == 0){
			num[1]++;
		}
		else {
			num[2]++;
		}
	}
	if (num[2] == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	if (num[0] == 0) {
		cout << "No" << endl;
		return 0;
	}
	if (num[1] > 0) {
		num[2]++;
	}
	if (num[0]-num[2] >= -1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}



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

int n,m,q;
int a[55], b[55], c[55], d[55];

int A[10];
int ans = 0;

void dfs(int v, int itr) {
  if(itr == n) {
    int tmp = 0;

    for (int i = 0; i < q; i++) {
      if(A[b[i]] - A[a[i]] == c[i]) tmp += d[i];
    }

    ans = max(ans, tmp);
    return;
  }

  for (int i = v; i <= m; i++) {
    A[itr] = i;
    dfs(i, itr + 1);
  }
  return;
}

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

  cin >> n >> m >> q;
  for (int i = 0; i < q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }

  dfs(1, 0);
  cout << ans << '\n';
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,k,ans;
int x,y;
signed main(){
	
	double n;
	cin>>n;
	cout<<n*3.14*2.0<<endl;
	
}


Measured memory_bytes: 3748
import sys
readline = sys.stdin.readline
MAX_DIGIT = 40

def main():
    N, K = map(int, readline().rstrip().split())
    K_bin = bin(K)[2:].zfill(MAX_DIGIT)
    A = list(map(int, readline().rstrip().split()))
    A = [bin(a)[2:].zfill(MAX_DIGIT) for a in A]
    dp = [[-1] * 2 for _ in range(MAX_DIGIT+1)]
    # dp[i][j=0,1] = 上からi桁まで決めて、j=0: k未満が確定, j=1: 今のところkと一致

    dp[0][0] = 0
    mul = 2 ** (MAX_DIGIT - 1)
    for d in range(MAX_DIGIT):
        cnt = len([1 for a in A if a[d] == '1'])  # Aで元々d桁目にビットが立っているものの個数
        cost0 = cnt * mul
        cost1 = (N - cnt) * mul

        # smaller -> smaller
        if dp[d][1] != -1:
            dp[d+1][1] = max(dp[d+1][1], dp[d][1] + max(cost0, cost1))  # 0でも1でも自由に大きい方
        
        # exact -> smaller
        if dp[d][0] != -1:
            # Kのd桁目が1だったら、Xのd桁目は0にする
            if K_bin[d] == '1':
                dp[d+1][1] = max(dp[d+1][1], dp[d][0] + cost0) 

        # exact -> exact (Kにぴったり合わせる)
        if dp[d][0] != -1:
            # Kのd桁目が1だったら、Xのd桁目は0にする
            if K_bin[d] == '1':
                dp[d+1][0] = max(dp[d+1][0], dp[d][0] + cost1)
            else:
                dp[d+1][0] = max(dp[d+1][0], dp[d][0] + cost0)
        
        mul //= 2
    
    print(max(dp[MAX_DIGIT]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 17820
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var i int
	var a, b string
	fmt.Scan(&a, &b)
	c := a + b
	i, _ = strconv.Atoi(c)
	ans := numSquares(i)

	if ans == 1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func numSquares(n int) int {
	dp := make([]int, n+1)
	dp[0] = 0

	for i := 0; i <= n; i++ {
		dp[i] = i
		for j := 1; i-j*j >= 0; j++ {
			dp[i] = Min(dp[i], dp[i-j*j]+1)
		}
	}

	return dp[n]
}

func Min(a, b int) int {
	if a >= b {
		return b
	} else {
		return a
	}
}


Measured memory_bytes: 1280