akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else if (A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B < C + D) {
    cout << "Right" << endl;
  }
}


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

KA = []
for i in range(N):
    if i == 0:
        lbe = list(map(int, input().split()))[1:]
    else:
        tmp = []
        for j in list(map(int, input().split()))[1:]:
            if j in lbe:
                tmp.append(j)
        lbe = tmp

print(len(lbe))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define forn(i,n) for(int i = 0 ; i < (int)n ; ++i)
#define fi first
#define se second
#define for1(i,n) for(int i=1; i<= (int)n; ++i)
#define fore(i,l,r) for(int i=(int)l; i<= (int)r; ++i)
#define ford(i,n) for(int i=(int)(n) - 1; i>= 0; --i)
#define fored(i,l,r) for(int i=(int)r; i>= (int)l; --i)
#define pb push_back
#define el '\n'
#define d(x) cout<< #x<< " " << x<<el
#define ri(n) scanf("%d",&n)
#define __USE_MINGW_ANSI_STDIO 0
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<char,int> pci;
typedef tuple<int, int, int> tiii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

//const ll INF = LONG_LONG_MAX;
const double PI = acos(-1);
const int MAXN = 1e9+200;
const double EPS= 1e-10;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    int dp[n];
    int a[n];
    forn(i,n){
        cin>>a[i];
    }
    dp[0]=0;
    dp[1]=abs(a[0]-a[1]);
  //  dp[2]=abs(a[0]-a[2]);
    for(int i = 2 ; i < n ; ++i){
        int mini = MAXN;
        for1(j,min(k,i)){
            mini = min(mini,dp[i-j]+abs(a[i-j]-a[i]));
        }
        dp[i] = mini;
    }
    cout<<dp[n-1];

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 N;
  cin >> N;

  unordered_map<int, int> m;
  for (int i = 0; i < (int)N; ++i) {
    int A;
    cin >> A;
    m[A] = 1;
  }
  cout << (m.size() == N ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 8520
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	auto m = IN();
	auto d = IN();
	int ans = 0;
	FOR(i, 1, m+1)
	{
		FOR(j, 1, d+1)
		{
			i64 d1 = j % 10;
			i64 d10 = j / 10;
			if (d1 >= 2 && d10 >= 2 && d1*d10 == i)
				ans++;
		}
	}
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()

int main(){
    int a,b; cin >>a >> b; --a; --b;
    int H = 100; int W = 100;
    vector<string > field(H);
    
    for(int i = 0; i < H/2; ++i){
  	  for(int j = 0; j < W; ++j){
  	      if(a>0 && i%2==0 && j%2==0){
  	          field[i] += ".";
                --a;
            }
            else{
            	 field[i] += "#";
            }
        }
    }
    for(int i = H-1; i >= H/2; --i){
  	  for(int j = 0; j < W; ++j){
  	      if(b>0 && i%2!=0 && j%2==0){
  	          field[i] += "#";
                --b;
            }
            else{
            	 field[i] += ".";
            }
        }
    }
    cout << H << " " << W<< endl;
    for(int i = 0; i < H; ++i){
        cout << field[i] << endl;  
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=2000005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

ll nPk(ll n,ll k){
	return nCk(n,k)*F[k]%mod;
}

int n;

int main(){
	cin>>n;
	cout<<(1000-n%1000)%1000<<endl;
}

Measured memory_bytes: 3576
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

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

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


int main(void) {
	
	string s;
	long long int black = 0, white = 0;
	long long int pos = 0;
	long long int count = 0;

	cin >> s;

	LFOR(i, 0, s.size() - 1) {
		if (s[i] == 'W') {
			count += (i - pos);
			pos++;
		}
	}

	cout << count << endl;


	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  vi v;
  int cnt0 = 0;
  int cnt1 = 0;
  rep(i,n) {
    if(cnt1>0 && s[i]=='0') {
      v.push_back(cnt1);
      cnt1 = 0;
      cnt0 = 1;
    }
    else if(cnt0>0 && s[i]=='1') {
      v.push_back(cnt0);
      cnt0 = 0;
      cnt1 = 1;
    }
    else if(s[i]=='1') cnt1++;
    else cnt0++;
  }
  if(cnt0>0) v.push_back(cnt0);
  else v.push_back(cnt1);
  if(s[0]=='1') {
    int ans = 0;
    int tmp = 0;
    rep(i,2*k+1) {
      if(i>=v.size()) break;
      tmp += v[i];
    }
    ans = tmp;
    rep(i,v.size()-2*k-1) {
      if(i<0 || 2*k+1+i >= v.size()) break;
      tmp -= v[i];
      tmp -= v[i+1];
      tmp += v[2*k+1+i];
      if(2*k+2+i < v.size()) tmp += v[2*k+2+i];
      ans = max(ans,tmp);
      i++;
    }
    cout << ans << endl;
    return 0;
  }
  else {
    int ans = 0;
    int tmp = 0;
    rep(i,2*k) {
      if(i>=v.size()) break;
      tmp += v[i];
    }
    ans = tmp;
    rep(i,v.size()-2*k) {
      if(i==0) {
        tmp -= v[i];
        if(2*k+i < v.size()) tmp += v[2*k+i];
        if(2*k+i+1 < v.size()) tmp += v[2*k+i+1];
        ans = max(ans,tmp);
        continue;
      }
      if(i<0 || 2*k+1+i >= v.size()) break;
      if(i==0) {
        tmp -= v[i];
        tmp += v[2*k+i];
        tmp += v[2*k+i+1];
        ans = max(ans,tmp);
        continue;
      }
      tmp -= v[i];
      tmp -= v[i+1];
      tmp += v[2*k+1+i];
      if(2*k+2+i < v.size()) tmp += v[2*k+2+i];
      ans = max(ans,tmp);
      i++;
    }
    cout << ans << endl;
    return 0;
  }
}

Measured memory_bytes: 1020
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    string s; cin >> s;
    int res = 0;
    if(s[0]=='R' && s[1] == 'S' && s[2] == 'R')res = 1;
    else{
        res = count(all(s), 'R');
    }
    cout << res << ln;
}
    


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define speed                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define ll long long
#define pb push_back
#define mem1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))
#define endl "\n"
#define mod 1000000007
#define mod1 998244353
#define ff first
#define ss second
#define MAX 500005
#define N 300005
#define INF 1000000009
#define all(v) v.begin(), v.end()
#define sbit(a) __builtin_popcount(a)
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<ll, ll> pll;
typedef pair<pll, ll> ppl;
typedef map<ll, ll> mpll;
typedef map<vector<ll>, ll> mpvl;
ll power(ll x, ll y, ll p)
{
    ll res = 1;

    x = x % p;

    if (x == 0)
        return 0;
    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }

    return res;
}

void solve()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll pref[n];
    ll sum = 0;
    mem0(pref);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        if (i)
            pref[i] = a[i] + pref[i - 1];
        else
            pref[i] = a[i];
        sum+=a[i];
    }
    ll ans=0;
    for (ll i = 0; i < n - 1; i++)
    {
        ans+=(a[i]%mod)*((sum-pref[i])%mod);
        ans%=mod;
    }
    cout<<ans<<endl;
}

int main()
{

    speed;

    ll kk;
    kk = 1;
    // cin >> kk;
    while (kk--)
    {

        solve();
    }
    return 0;
}

Measured memory_bytes: 6372
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;



int main(){
    
    string s;
    int a[110],d[200],MAX,Dc=-1;
    rep(i,0,200)d[i]=-1;
    cin>>s;
    int N=s.size();
    rep(i,0,N){
        a[i]=s.at(i)+'0';
    }
    rep(i,145,171){
        MAX=-1;
        Dc=-1;
        rep(j,0,N){
            if(a[j]==i){
                MAX=max(MAX,j-Dc-1);
                Dc=j;
            }
        }
        if(Dc!=-1){
        MAX=max(MAX,N-Dc-1);
        }
        d[i]=MAX;
    }
    int MINI=9999;
    rep(i,0,200){
        if(d[i]!=-1){
            MINI=min(MINI,d[i]);
        }
    }
    cout<<MINI<<endl;
}






Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int ans = 0;
        
        System.out.println(B / A >= C ? C : B / A);
    }
}


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

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    cout << vec.at(i) << ", ";
  }
  cout << "]" << endl;
}

int main()
{
  int m, f, b;
  cin >> m >> f >> b;

  if (m + f < b)
  {
    printf("NA\n");
  }
  else if (m > b)
  {
    printf("0\n");
  }
  else
  {
    printf("%d\n", b - m);
  }
}



Measured memory_bytes: 3212
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);
    static int[][] dp = new int[1005][1005];
    static String x, y;

    public static void main(String[] args) {
        int N = sc.nextInt();
        for (int i = 0; i < N; i++) {
            read();
            clear();
            System.out.println(lcs(0, 0));
        }
    }

    public static void read() {
        x = sc.next();
        y = sc.next();
    }

    public static int lcs(int i, int j) {
        if (dp[i][j] >= 0) {
            return dp[i][j];
        } else if (x.length() == i || y.length() == j) {
            return dp[i][j] = 0;
        } else if (x.charAt(i) == y.charAt(j)) {
            return dp[i][j] = lcs(i + 1, j + 1) + 1;
        } else {
            return dp[i][j] = Math.max(lcs(i + 1, j), lcs(i, j + 1));
        }
    }

    public static void clear() {
        for (int i = 0; i < 1005; i++) {
            for (int j = 0; j < 1005; j++) {
                dp[i][j] = -1;
            }
        }
    }
}

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

int n;
int p[310][310] = {};
int rui[310][310] = {};


typedef struct{
  int num;
  int idx;
} Data;
Data dp[310][310][310] = {};

int getRuiseki(int x1, int y1, int x2,int y2){
  if(x1 > x2 || y1 > y2)        return 0;
  x2++; y2++;
  return rui[y2][x2] - rui[y2][x1] - rui[y1][x2] + rui[y1][x1];
}

int getDonut(int x1, int y1, int x2, int y2){
  return getRuiseki(x1,y1,x2,y2) - getRuiseki(x1+1,y1+1,x2-1,y2-1);
}

int getL(int x1, int x2, int y){
  return getRuiseki(x1,0,x2,y) - getRuiseki(x1, 0, x2-1, y-1);
}

int main(){
  cin >> n;
  for(int i = 1;i <= n;i++){
    for(int j = 1;j <= n;j++){
      cin >> rui[i][j];
    }
  }

  for(int i = 0;i <= n;i++){
    for(int j = 0;j <= n;j++){
      rui[i][j+1] += rui[i][j];
    }
  }

  for(int j = 0;j <= n;j++){
    for(int i = 0;i <= n;i++){
      rui[i+1][j] += rui[i][j];
    }
  }


  for(int finx = n-1;finx >= 0;finx--){
    for(int x = finx;x >= 0;x--){
      dp[finx][x][n-1].num = getDonut(x, 0, finx, n-1);
      dp[finx][x][n-1].idx = n-1;
      for(int y = n-2;y >= 0;y--){
        int tmp = getDonut(x, 0, finx, y);
        if(tmp > dp[finx][x][y+1].num){
          dp[finx][x][y].num = tmp;
          dp[finx][x][y].idx = y;
        }else{
          dp[finx][x][y] = dp[finx][x][y+1];
        }
      }
    }
  }

  int ans = INT_MIN;
  for(int x = 0; x < n; x++){
    for(int y = 0;y < n;y++){
      for(int x2 = x;x2 < n;x2++){
        ans = max(ans,getDonut(x,y,x2,dp[x2][x][y].idx));
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 113996
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <climits>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false)

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int max_N = 2e5 + 10;
vector<int> E[max_N];
int source[max_N], target[max_N];

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= M; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (x > y) {
			swap(x, y);
		}

		if (x == 1) {
			source[y] = 1;
		}
		if (y == N) {
			target[x] = 1;
		}
	}

	for (int i = 2; i < N; ++i) {
		if (source[i] && target[i]) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 6528
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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(){
	int n;
	cin >> n;
	vector<ll> a(n);
	REP(i,n) cin >> a[i];
	
	sort(a.begin(),a.end(),greater<ll>());
	
	ll big = a[0];
	ll sma = a[n-1];
	REP(i,n){
		if(i==0) continue;
		
		if(abs((double)big/2 - sma) > abs((double)big/2 - a[i])){
			sma = a[i];
		}
	}
	
	cout << big << " " << sma << endl;
	
	return 0;
}

Measured memory_bytes: 4036
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;
vector <int> edges[200000];
int diameter;
bool used[200000];
int dfs(int cur_node){
    used[cur_node] = true;
    vector <int> dists;
    for(int i = 0; i < edges[cur_node].size(); i++){
       int next_node = edges[cur_node][i];
       if(!used[next_node]){
        dists.push_back(1 + dfs(next_node));
       } 
    }

    sort(dists.begin(), dists.end());
    if(dists.size() >= 2){
        diameter = max(diameter, dists[dists.size() - 1] + dists[dists.size() - 2]);
    }

    if(dists.size() == 0){
        return 0;
    }  
    return *max_element(dists.begin(), dists.end());
}

bool win_dp[200001];
int main(){
    int N;
    cin >> N;

    for(int i = 0; i < N - 1; i++){
        int a;
        int b;
        cin >> a >> b;
        edges[a - 1].push_back(b - 1);
        edges[b - 1].push_back(a - 1);
    }

    diameter = max(diameter, dfs(0));

    win_dp[0] = true;
    win_dp[1] = false;
    for(int i = 2; i <= diameter; i++){
        if(!win_dp[i - 2] || !win_dp[i - 1]){
            win_dp[i] = true;
        } else {
            win_dp[i] = false;
        }
    }
    if(win_dp[diameter]){
        cout << "First" << endl;
    } else {
        cout << "Second" << endl;
    }
    return 0;
}


Measured memory_bytes: 26496
n, m = map(int, raw_input().split())
l = map(int, raw_input().split())
dp = [-1]*(n+10)
dp[0] = 0
cost = [0,2,5,5,4,5,6,3,7,6]
for i in range(1, n + 1):
    for j in l:
        if cost[j] <= i:
            dp[i] = max(dp[i], dp[i-cost[j]]*10 + j)
print dp[n]


Measured memory_bytes: 14372
//created by missever

#include<bits/stdc++.h>
#define MAX 1000000007
using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int maxn = 1e5 + 5;
vector<int> g[maxn];
int f[maxn],tot = 0;
int p[maxn];

bool dfs(int u,int fa,int e) {
    f[tot++] = u;
    if(u == e) return true;
    for(auto v:g[u]) {
        if(v == fa) continue;
        if(dfs(v,u,e)) return true;
    }
    tot--;
    return false;
}

void ff(int u,int fa,int k) {
    if(!p[u]) p[u] = k;
    for(auto v:g[u]) {
        if(v == fa) continue;
        ff(v,u,p[u]);
    }
}

int main() {
    int n,i,u,v;
    scanf("%d",&n);
    for(i = 1;i < n; i++) {
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,0,n);
    for(i = 0;i < (tot + 1) / 2; i++) p[f[i]] = 1;
    while(i < tot) p[f[i++]] = 2;
    ff(1,0,p[1]);
    u = 0;
    for(i = 1;i <= n; i++) u += (p[i] == 1);
    if(u > n - u) printf("Fennec\n");
    else printf("Snuke\n");
    return 0;
}


Measured memory_bytes: 11136
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    akari<int> ls(n);
    for (int i = 0; i < n; i++)
    {
        cin >> ls[i];
    }
    sort(ls.begin(), ls.end());
    long ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
        {
            ans += distance(ls.begin(), lower_bound(ls.begin(), ls.end(), ls[i] + ls[j])) - j - 1;
        }
    cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string t;
    cin>>t;

    ll count = 0;
    ll ans = 0;
    for(ll i=0;i<t.size();++i){
        if(t[i] == 'S'){
            count++;
        }else{
            if(count > 0){
                count--;
                ans += 2;
            }
        }
    }
    ans = t.size() - ans;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#include<map>
#define MEM(var,val) memset(var,(val),sizeof(var))
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define nitro   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define tc ll tes;cin>>tes;while(tes--)
#define inf 10000000000
const double pi = std::acos(-1);
ll lcm(ll a,ll b){
return (a*b)/__gcd(a,b);
}
ll solve(ll a,ll b,ll c,ll d)
{
    ll t=0;
    if(b>=a)
        return b;
    else{
        t=b;
        if(d>=c)
            return -1;
        if((a-t)%(c-d)==0)
            t+=c*((a-t)/(c-d));
        else t+=c*((a-t)/(c-d))+c;
        return t;
    }
}
ll n,k;
vll v,dp;
void solve(ll i)
{
    if(i>k)
        return ;
    if(dp[i]==1)
        for(int j=0;j<n;j++)
        dp[i+v[j]]=MAX(dp[i+v[j]],0);
    if(dp[i]==0)
        for(int j=0;j<n;j++)
        dp[i+v[j]]=1;
    for(int j=0;j<n;j++)
        solve(i+v[j]);
    return;

}
int main()
{
nitro;
cin>>n>>k;
v.resize(n);
dp.resize(k+1,0);

for(int i=0;i<n;i++)
    cin>>v[i];
    dp[0]=0;
    for(int i=0;i<=k;i++)
        for(int j=0;j<n;j++)
    {if(dp[i]==1&&(i+v[j])<=k)
        dp[i+v[j]]=MAX(dp[i+v[j]],0);
    else if(i+v[j]<=k) dp[i+v[j]]=1;}
    if(dp[k]==1)
        cout<<"First\n";
    else cout<<"Second\n";


   }




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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const ll mod = 1000000007;
const ll INF = 1001001001001001000;

int main() {
    int n,t; cin >> n >> t;
    vector<pair<int,int>> f(n);
    rep(i,n) {
        int a,b; cin >> a >> b;
        f[i] = {a,b};
    }
    sort(all(f));

    int dp[6005]; rep(j,6005) dp[j] = 0;
    rep(i,n) {
        int a = f[i].first;
        int b = f[i].second;
        for(int j = t-1; j >= 0; j--) {
            dp[j+a] = max(dp[j+a], dp[j]+b);
        }
    }
    int ans = 0;
    rep(j,6005) ans = max(ans, dp[j]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3676
type Zipper a = ([a],[a])
                                                                                                                           
left :: Int -> Zipper a -> Zipper a
left 0 (xs,ys) = (xs,ys)
left _ ([],ys) = ([],ys)
left n (x:xs,ys) = left (n-1) (xs,x:ys)

right :: Int -> Zipper a -> Zipper a
right 0 (xs,ys) = (xs,ys)
right _ (xs,[]) = (xs,[])
right n (xs,y:ys) = right (n-1) (y:xs,ys)

now :: Zipper a -> Maybe a
now ([],_) = Nothing
now (x:xs,ys) = Just x

fromList :: Int -> [a] -> Zipper a
fromList n xs = right n ([],xs)

toList :: Zipper a -> [a]
toList (xs,ys) = snd $ left (length xs) (xs,ys)

count :: Zipper Char -> [(Int,Int)]
count (x:xs,[]) = (length (filter (=='W') xs),0):[]
count ([],y:ys) = count ([y],ys)
count (x:xs,y:ys) = ((head counts) `dplus` (l,r)):counts
  where counts = count (y:x:xs,ys)
        dplus (a,b) (c,d) = (a+c,b+d)
        l = if (x == 'W') then (-1) else 0
        r = if (y == 'E') then 1 else 0


main :: IO ()
main = do
  n  <- (read :: String -> Int) <$> getLine
  xs <- getLine

  print $ foldr1 min $ map (\(x,y) -> x+y) (count $ fromList 0 xs)

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

int main(void){
    char c[3][3];
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++)
            cin >> c[i][j];
    }

    cout << c[0][0];
    cout << c[1][1];
    cout << c[2][2] << endl;

    return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  AtCoder
//
//  Created by s on 2018/11/28.
//  Copyright © 2018 s. All rights reserved.
//

// ----------------------------------------------------------
// --https://kenkoooo.com/atcoder/#/table/soma62jp

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

#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long LL;
typedef unsigned int UI;
typedef long double LD;

#define LL MOD          (LL)1000000007
#define LL_INF          (LL)1 << 62
#define INT_INF         (int)1 << 30

#define rSort(a)        sort(a.rbegin(),a.rend())
#define Sort(a)         sort(a.begin(),a.end())
#define Reverse(a)      reverse(a.begin(),a.end())
#define Sum(a)          accumulate(a.begin(), a.end(), 0)
#define REP(i, n)       for(UI i = 0;i < n;i++)
#define REPR(i, n)      for(UI i = n;i >= 0;i--)
#define FOR(i, m, n)    for(UI i = m;i < n;i++)
#define pb(i)           push_back(i)
#define SWAP(x,y)       ((x!=y)&&(x^=y,y^=x,x^=y))

int main(int argc, char* argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long long N,K,Q;
    vector<long long> A;
    
    cin >> N >> K >> Q;
    
    vector<long long> P(N,0);
    A.resize(Q);
    
    REP(i,Q){
        cin >> A[i];
    }

    REP(i,Q){
        P[A[i] - 1]++;
    }
    
    REP(i,N){
        
        if(P[i]-(Q-K)>=1){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        
    }
    
    return 0;
    
}





Measured memory_bytes: 2176
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
main=print.solve.V.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve as=f 0 1 where
  n=V.head as
  f k i
    |k>n= -1
    |i==2=k
    |otherwise=f(k+1)(as V.! i)

Measured memory_bytes: 7972
/*
#include<cstdio>
const int N = 1e5;
int n, a, b, c;
int vis[N];
int main() {
	return 0;
}
*/
#include<cstdio>
#include<cmath>
#include<map>
using namespace std;
const int N = 2e5 + 5;
int n, a[N], b[N];
long long ans;
map<int, int> m;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		ans += m[i - a[i]], m[a[i] + i]++;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 21156
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#define pb push_back
#define mp make_pair
#define p1 first
#define p2 second
using namespace std;

const int N = 2e5+5;
int n ,m ,b[N], a[N], sq[N], cnt;

int main()
{
    //freopen("a.inp","r",stdin);

    cin >> n;
    for(int i=1; i<=n; ++i) scanf("%d",a+i);

    for(int i=1; sq[i-1] <= n; ++i) sq[i] = i*i;
    for(int i=n; i>=1; --i) if (a[i]) {
        b[i] = 1; m = sqrt(i); cnt += 1;
        for(int j=1; j<=m; ++j) if (i % j == 0) {
            a[j] ^= 1; if (sq[j] != i) a[i/j] ^= 1;
        }
    }

    cout << cnt << endl;
    for(int i=1; i<=n; ++i) if (b[i]) printf("%d ",i);
}


Measured memory_bytes: 2432
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18) + 1;
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll h, w, n;
map<ll, int> m;
map<ll, int> used;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> h >> w >> n;
    vector<ll> ans(10, 0);
    vector<ll> a, b;
    for (int i = 0; i < n; i++)
    {
        ll temp, temp1;
        cin >> temp >> temp1;
        temp--;
        temp1--;
        m[temp * w + temp1]++;
        a.push_back(temp);
        b.push_back(temp1);
    }
    ll allcount = (h - 2) * (w - 2);
    ll countsum = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 9; j++)
        {
            ll temp = j % 3;
            ll temp1 = j / 3;
            if (a[i] - temp1 < 0 || b[i] - temp < 0 || a[i] - temp1 + 2 >= h || b[i] - temp + 2 >= w)
            {
                continue;
            }
            ll count = 0;
            if (used[(a[i] - temp1) * w + b[i] - temp])
                continue;
            used[(a[i] - temp1) * w + b[i] - temp] = true;
            for (int k = 0; k < 9; k++)
            {
                ll temp2 = k % 3;
                ll temp3 = k / 3;
                ll temp4 = a[i] - temp1 + temp3;
                ll temp5 = b[i] - temp + temp2;
                if (m[temp4 * w + temp5])
                {
                    count++;
                }
            }
            ans[count]++;
            countsum++;
        }
    }
    ans[0] = allcount - countsum;
    for (int i = 0; i < 10; i++)
    {
        cout << ans[i] << "\n";
    }
}


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

using namespace std;

const int MAXN=2e5+7;


int N,M;
vector<int> graph[MAXN];
bool visited[MAXN];

int DFS(int cur){
    int ret=1;
    visited[cur]=true;
    for(auto adj:graph[cur]){
        if (visited[adj]) continue;
        ret+=DFS(adj);
    }

    return ret;
}

int main(){
    scanf("%d%d",&N,&M);
    for(int i=0;i<M;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    int ans=0;
    for(int i=1;i<=N;i++){
        if (visited[i]) continue;
        ans=max(ans,DFS(i));
    }

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


    return 0;
}

Measured memory_bytes: 23676
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
using namespace std;
typedef long long llong;
typedef vector <llong> vll;

int maxv(vll &x){
	llong tmp=x[0];
	for (int i=1; i<x.size(); i++)
		if (x[i]>tmp) tmp=x[i];
	return tmp;
}

int main(void){
	int n;
	vll x;
	while (cin>>n, n!=0){
		llong s = LLONG_MIN;
		for (int i=0; i<n; i++){
			int n2;
			cin>>n2;

			for (int j=0; j<x.size(); j++){
				x[j] += n2;
			}
			x.push_back(n2);
			llong tmp=maxv(x);
			if (tmp>s) s=tmp;
		}
		cout<<s<<endl;
		x.clear();
	}
	return 0;
}

Measured memory_bytes: 1268
#include<stdio.h>
int main(void)
{
	int a,b,c,d;
	for(c=0;c<4;c++){
		scanf("%d %d",&a,&b);
		if(a==1){
			d=6000*b;
		}
		if(a==2){
			d=4000*b;
		}
		if(a==3){
			d=3000*b;
		}
		if(a==4){
			d=2000*b;
		}
		printf("%d\n",d);
	}
	return 0;
}

Measured memory_bytes: 600
def test_case():
    while True:
        a, b = map(int, input().split())
        if a == 0 and b == 0:
            break
        t_b = ''.join(['#' for _ in range(b)])
        inner = '#{}#'.format(''.join(['.' for _ in range(b-2)]))
        for idx, _ in enumerate(range(a)):
            if idx == 0 or idx == (a - 1):
                print(t_b)
            else:
                print(inner)
        print('')


if __name__ == "__main__":
    test_case()



Measured memory_bytes: 5620
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;

// solve

int main(int argc, char const* argv[])
{
  int w, n;
  cin >> w >> n;
  vector<int> vec = vector<int>(w, 0);
  rep(i, w){
    vec[i] = i;
  }
  rep(i, n){
    string s;
    cin >> s;
    int a, b;
    rep(j, s.size()){
      if(s[j] == ','){
        a = stoi(s.substr(0, j));
        b = stoi(s.substr(j+1, -1));
        break;
      }
    }
    a--; b--;
    swap(vec[a], vec[b]);
  }
  rep(i, w){
    cout << vec[i] + 1 << endl;
  }
	return 0;
}



Measured memory_bytes: 3188
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    vector<int> a;
    int in;
    int m4 = 0;
    int m2 = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> in;
        a.emplace_back(in);
        if (in % 4 == 0)
        {
            m4++;
        }else if(in % 2 == 0)
        {
            m2++;
        }
        
    }

    if (m4 >= N / 2)
    {
        cout << "Yes" << endl;
    }else
    {
        if (m2 == N - m4 * 2)
        {
            cout << "Yes" << endl;
        }else
        {
            cout << "No" << endl;
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<ll,int> ii;
typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

const int maxn = 2e5 + 5;
const int inf = 1e9 + 1;
int n;
vector<int> adj[maxn];
int ans[maxn];
int A , B , C;
int dp[maxn][2];

void dfs(int u , int par){
    dp[u][0] = 1;
    for(auto c : adj[u]){
        if(c == par)continue;
        dfs(c,u);
        for(int j = 0 ; j < 2 ; ++j){
            dp[u][(j + 1) % 2] += dp[c][j];
        }
    }
}

int root = 0;
bool ok = 0;

void go(int u , int par , int dep1 , int dep2){
    dep1 += dp[u][0];dep2 += dp[u][1];
//    cout << u << " " << dep1 << " " << dep2 << endl;
    if(min(dep1,dep2) >= B){
        root = u;
        if(dep2 == min(dep1,dep2))ok = 0;
        else ok = 1;
//        return;
    }
    dep1 -= dp[u][0];dep2 -= dp[u][1];
    for(auto c : adj[u]){
        if(c == par)continue;
        go(c,u,dep2+dp[u][1]-dp[c][0],dep1+dp[u][0]-dp[c][1]);
    }
}

int cnt[3];

void col(int u , int par , bool bit){
    if(cnt[bit] <= n){
        ans[u] = cnt[bit];
        cnt[bit] += 3;
    }
    for(auto c : adj[u]){
        if(c != par)col(c,u,bit^1);
    }
}
void col1(int u, int par , bool bit){
    if(bit == 0){
        if(cnt[0] <= n){
            ans[u] = cnt[0];
            cnt[0] += 3;
        }else if(cnt[1] <= n){
            ans[u] = cnt[1];
            cnt[1] += 3;
        }else{
            ans[u] = cnt[2];
            cnt[2] += 3;
        }
    }else{
        ans[u] = cnt[2];
        cnt[2] += 3;
    }
    for(auto c : adj[u]){
        if(c != par)col1(c,u,bit^1);
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    A = n / 3 + (n % 3 != 0);
    B = n / 3 + (n % 3 > 1);
    C = n / 3;
    for(int i = 1 ; i < n ; ++i){
        int u , v;cin >> u >> v;
        adj[u].pb(v);adj[v].pb(u);
    }
    dfs(1,0);
    go(1,0,0,0);
    cnt[0] = 1;
    cnt[1] = 2;
    col(root,0,ok);
    if(root == 0){
        cnt[0] = 1;cnt[1] = 2;cnt[2] = 3;
        col1(1,0,0);
        if(cnt[2] - 3 > n){
            cnt[0] = 1;cnt[1] = 2;cnt[2] = 3;
            col1(1,0,1);
        }
        for(int i = 1 ; i <= n ; ++i)assert(ans[i] <= n);
    }
    for(int i = 1 ; i <= n ; ++i)if(ans[i] == 0)ans[i] = (++cnt[2]) * 3;
    for(int i = 1 ; i <= n ; ++i)cout << ans[i] << " ";
}




Measured memory_bytes: 24576
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 1010101010;

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

    int N;
    cin >> N;
    vector<LL> a(N);
    REP(i, N) cin >> a[i];
    vector<LL> b(N);
    REP(i, N) cin >> b[i];

    LL ans = 0;
    REP(i, N){
        if(b[i] < a[i]) ans -= a[i]-b[i];
        else if(a[i] < b[i]) ans += (b[i]-a[i])/2; 
    }
    cout << (ans >= 0 ? "Yes" : "No") << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int mypow(int a,int b,int c){
	if(b==0)return 1;
	if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
int x[15][15],y[15][15],z[15],a[15];
signed main(){
	int n,ans=0;
	cin>>n;
	f(i,n){
		cin>>a[i];
		f(j,a[i]){
			cin>>x[i][j]>>y[i][j];
		}
	}
	f(i,(int)pow(2,n)){
		int zz=i,cnt=0;
		f(j,n){
			z[j]=zz%2;
			cnt+=zz%2;
			zz/=2;
		}
		f(j,n){
			if(z[j]==0)continue;
			f(k,a[j]){
				if(z[x[j][k]-1]!=y[j][k])goto loop;
			}
		}
		ans=max(ans,cnt);
		loop:;
	}
	cout<<ans<<endl;
}


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

int main() {
  int n;
  cin >> n ;
  vector<int> as(n);
  vector<int> log(1);

  for (int i=0;i<n;i++)
  {
    cin >> as.at(i);
  }
  for (int i=0;i<n;i++)
  {
    bool judge = true;
    for (int j=0;j<log.size();j++)
    {
      if (as.at(i)==log.at(j)) judge=false;
    }
    if (judge) log.push_back(as.at(i));
  }
  cout << log.size()-1 << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair

int n, a[202020], b[202020];

int main(){

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

cin >> n;
rep(i, 1, n){
cin >> a[i];
b[i]=a[i];
}

sort(b+1, b+n+1);

rep(i, 1, n){

if(a[i]<=b[n/2])cout << b[(n)/2+1] << endl;
else cout << b[(n)/2] << endl;

}

}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[m];
    int sum = 0;
    for (int &x : a) cin >> x, sum += x;
    if (sum > n) cout << -1 << "\n";
    else cout << (n - sum) << "\n";
    return 0;
}

Measured memory_bytes: 3652
# coding: utf-8
import math

if __name__ == "__main__":
    N = int(input())
    H = list(map(int, input().split(" ")))
    c = 0
    max_c = 0
    for i in range(N-1):
        if H[i+1] <= H[i]: c += 1
        else: c = 0
        if max_c < c: max_c = c
    print(max_c)

Measured memory_bytes: 15020
#include<stdio.h>
int main()
{
    int a, b;
    scanf("%d %d", &a,&b);
    if(a<b)
    {
        printf("a < b\n");
    }
    else if(a>b)
    {
        printf("a > b\n");
    }
    else if(a==b)
    {
        printf("a == b\n");
    }
    return 0;

}



Measured memory_bytes: 2148
program main
   implicit none
   integer:: i,j,k,minv=1000
   character*10 a
   read(*,*)a
   do i=1,len_trim(a)-2
      read(a(i:i+2),*)j
      if(abs(753-j)<=minv)minv=abs(j-753)
   enddo
   write(*,*)minv
end program main


Measured memory_bytes: 768
def phi(n):
	result = n
	for i in range(2, n + 1):
		if i ** 2 > n:
			break
		elif n % i == 0:
			while n % i == 0:
				n /= i
			result -= result / i
	if n > 1:
		result -= result / n
	return int(result)

print(phi(int(input())))


Measured memory_bytes: 5604
input()
ls = list(map(int, input().split(' ')))
ls.sort(reverse=True)

def main(ls):
    if ls.count(0) > 0:
        print(0)
        return
    result = 1
    for i in ls:
        result *= i
        if result > 10 ** 18:
            print(-1)
            return

    print(result)

main(ls)

Measured memory_bytes: 21500
#include<stdio.h>
#include<stdlib.h>
int A[11]={};
int a[50],b[50],c[50],d[50];
int N,M,Q;
int d_max=0;

int max_cal(int a,int b)
{
  if(a>=b) return a;
  else if(a<b) return b;
}
void d_max_cal(void)
{
  int tmp=0;
  for(int i=0;i<Q;i++){
    if((A[b[i]]-A[a[i]])==c[i]) tmp+=d[i];
  }
  d_max=max_cal(d_max,tmp);
}
void for_loop(int n)
{
  for(int i=A[n-1];i<=M;i++){
    A[n]=i;
    if(n==N) d_max_cal();
    else if(n<N) for_loop(n+1);
  }  
}
main(void)
{
  scanf("%d%d%d",&N,&M,&Q);
  for(int i=0;i<Q;i++){
    scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
  }
  A[0]=1;
  for_loop(1);
  printf("%d",d_max);
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vector<int>>
#define vvii vector<vector<ii>>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define uni(v) v.erase(unique(v.begin(), v.end()), v.end())
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (ll) a / __gcd(a, b) * b
#define what_is(x) cerr << #x << " is " << x << endl;

using namespace std;

void write();
template <typename T, typename... Args>
void write(T x, Args... args);
template <typename T>
void print_all(vector<T>& a);

void solve() {
    int n, k;
    cin >> n >> k;
    vi p(n);
    for (auto& i : p) cin >> i;
    sort(all(p));
    int s = 0;
    for (int i = 0; i < k; ++i) s += p[i];
    write(s);
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    // freopen("in", "r", stdin);

    int t = 1;
    // cin >> t;
    while (t--) solve();

    return 0;
}

void write() { cout << "\n"; }
template <typename T, typename... Args>
void write(T x, Args... args) {
    cout << x << ' ';
    write(args...);
}
template <typename T>
void print_all(vector<T>& a) {
    for (int i = 0; i < a.size(); ++i) cout << a[i] << " \n"[i == a.size() - 1];
}


Measured memory_bytes: 3664
#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>

using namespace std;
using ll = long long;

template<typename T> void print(T t) { cout << t << endl; }

int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	print(max((N - 2) * (B - A) + 1, 0ll));
}

Measured memory_bytes: 3636