akhauriyash/Code-Regression huggingface dataset:
n = gets.chop.to_i
as = []
n.times do
  as << gets.chop.to_i
end

as.sort!
ans = 0

tmp = [as.pop]
(n-1).times do |i|
  f_f = (as.first - tmp.first).abs
  f_l = (as.first - tmp.last).abs
  l_f = (as.last - tmp.first).abs
  l_l = (as.last - tmp.last).abs
  max_abs = [f_f, f_l, l_f, l_l].max
  if f_f == max_abs
    tmp.unshift(as.shift)
  elsif f_l == max_abs
    tmp.push(as.shift)
  elsif l_f == max_abs
    tmp.unshift(as.pop)
  elsif l_l == max_abs
    tmp.push(as.pop)
  end
  ans += max_abs
end
puts ans

# small_flag = true
# (n-1).times do |i|
#   if small_flag
#     num = as.shift
#     first = (num - tmp.first).abs
#     last = (num - tmp.last).abs
#     if first > last
#       tmp.unshift(num)
#       ans += first
#     else
#       tmp.push(num)
#       ans += last
#     end
#     small_flag = !(small_flag) if i.odd?
#   else
#     num = as.pop
#     first = (num - tmp.first).abs
#     last = (num - tmp.last).abs
#     if first > last
#       tmp.unshift(num)
#       ans += first
#     else
#       tmp.push(num)
#       ans += last
#     end
#     small_flag = !(small_flag) if i.odd?
#   end
# end

Measured memory_bytes: 4840
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll n, m;
  cin >> n >> m;
  if (n == 1 and m == 1) {
    cout << 1 << endl;
    return 0;
  }
  if (n == 1) {
    cout << m - 2  << endl;
    return 0;
  }

  if (m == 1) {
    cout << n - 2 << endl;
    return 0;
  }
  cout << (n * m - (n * 2 + m *  2 - 4)) << endl;
}


Measured memory_bytes: 256
s = input()
if s[0]==s[1]==s[2]:
    print('No')
elif s[0]==s[1]:
    if s[2]==s[3]:
        print('Yes')
    else:
        print('No')
elif s[0]==s[2]:
    if s[1]==s[3]:
        print('Yes')
    else:
        print('No')
elif s[0] == s[3]:
    if s[1]==s[2]:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

int main()
{
	std::string s, t;
	std::cin >> s >> t;

	std::sort( s.begin(), s.end() );
	std::sort( t.begin(), t.end(), std::greater<int> () );

	int r = s.compare( t );
	std::cout << ( r < 0 ? "Yes" : "No" ) << std::endl;
	return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  ll ans=0,n,t;cin>>n>>t;
  vll tt(n);
  rep(i,0,n){
    cin>>tt[i];
  }
  rep(i,0,n-1){
    ans+=min(tt[i+1]-tt[i],t);
  }
  cout<<ans+t<<endl;
}



Measured memory_bytes: 1792
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
  a[i]+=1
cnt=[0]*(n+1)
cnt[0]=3
ans=1
mod=10**9+7
for i in range(n):
  if cnt[a[i]-1]>0:
    ans*=cnt[a[i]-1]%mod
    cnt[a[i]-1]-=1
    cnt[a[i]]+=1
  else:
    print(0)
    exit()
print(ans%mod)

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

using namespace std;

#define ll long long

int main()
{
	int N;
	cin >> N;
	vector < ll > A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

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

	cout << A[N - 1] - A[0] << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(){
	int X,t;
	cin>>X>>t;

	printf("%d\n",max(0,X-t));

	return 0;
}



Measured memory_bytes: 256
# D - Prediction and Restriction 
N,K = map(int,input().split())
RSP = tuple(map(int,input().split()))
T = input()

# じゃんけんの勝敗を返す関数
def judge(a,b):
    if a == 'r' and b == 2:
        return True
    elif a == 's' and b == 0:
        return True
    elif a == 'p' and b == 1:
        return True
    return False

# dp[i][j]: i 回目のじゃんけんで j を出したときの最大値
# グー:0, チョキ:1, パー:2
dp = [[0]*3 for _ in range(N+1)]

# v 回目のじゃんけん
for v in range(1,N+1):
    # v 回目に出した手
    for w in range(3):
        # v-K 回目に出した手 
        for k in range(3):
            if w == k:
                continue
            # じゃんけんで勝ったとき
            if judge(T[v-1],w):
                dp[v][w] = max(dp[v][w],dp[v-K][k] + RSP[w])
            # じゃんけんで負けか引き分けたとき
            else:
                dp[v][w] = max(dp[v][w],dp[v-K][k])         
# K 個に分けた各グループの部分和の最大値の総和を求める
ans = 0
for a in range(1,K+1):
    ans += max(dp[-a])
print(ans)

Measured memory_bytes: 85312
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS cin.tie(0);ios::sync_with_stdio(false)
#define MP_ make_pair
#define PB_ push_back
#define FIR first
#define SEC second
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZ(x) ((int)(x).size())
typedef long long int lli;
using namespace std;
int c2i(char c){if(c>='0' and c<='9'){return (int)c-'0';}return -1;}


  
int digiS(int n)
{
  int cnt = 0;
  int m = n;
  string S = to_string(m);
  
  REP(i,SIZ(S))
    {
      cnt += c2i(S[i]);
      
    }
  return cnt;
  
  
}

int main()
{
  IOS; /* making cin faster */
  int N;
  cin >> N;

  int b;
  int mn = INF;
  
  FOR(a,1,N)
    {
      b = N - a;

      if( digiS(a) + digiS(b) < mn )
	{
	  mn = digiS(a) + digiS(b);
	  
	}
      
    }

  
  cout << mn << endl;
  

}


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

using namespace std;

int main(){

	long long a,b,c,k;
	cin >> a >> b >> c >> k;
	if (a < b) { swap(a, b); }
	if (a < c) { swap(a, c); }
	if (b < c) { swap(b, c); }
	cout << a*pow(2, k)+b+c << endl;


}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int N = sc.nextInt();
			if(N==0)break;
			int t=0;
			for(int i=0;i<(N/4);i++){
				t += sc.nextInt(); 
			}
			System.out.println(t);
		}
	}

}

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

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int X = sc.nextInt();
		int Y = sc.nextInt();

	    int ans = X+(Y/2);
	    System.out.println(ans);
	    sc.close();
	}



}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,M,X,Y;
cin>>N>>M>>X>>Y;
vector<int>x(N),y(M);
for(int &n:x)cin>>n;
for(int &n:y)cin>>n;
sort(x.begin(),x.end());
sort(y.begin(),y.end());
if((X<y[0]&&y[0]<=Y)&&(y[0]>x[N-1]))cout<<"No War";
else cout<<"War";
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vaector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
ll pow(ll x, ll y,ll m) { ll res = 1;x=x%m; while (y > 0) { if (y & 1) res = ((res%m) * (x%m))%m; y = y >> 1; x = ((x%m) * (x%m))%m; } return res%m; }
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
const ll INF = 0xFFFFFFFFFFFFFFFL;
clock_t time_p=clock();
void abhigyan10()
{time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF){return uniform_int_distribution<ll>(l,r)(rng);}
#define clrbuf cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define preciset(x) cout<<setprecision(x)<<fixed;
const ll mod =1000000007;
int main()
{
        FastIO

        int l,h,m,a,b,ans=INT_MAX;
        cin>>a>>b;

        l=1;h=100000;

        while(l<=h)
        {
        	m=(l+h)/2;

        	int A= (int)m*(0.08);
        	int B= (int)m*(0.10);
        	
        	if(a== A && B==b)
        	{
        		
        		ans= min(m,ans);
        		h=m-1;
        	}
        	else if(A<a || B<b)
        	{
        		l=m+1;
        	}
        	else
        	{
        		h=m-1;
        	}
        }

        if(ans==INT_MAX)
        	cout<<-1;
        else
        	cout<<ans;
        return 0;
    }



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <string>

using namespace std;
		
int main(void){
	char ch;
	int alp[26]={0};
	while( cin >> ch){
		ch = tolower(ch);
		if(islower(ch)){
			alp[ch-'a']++;
		}
	}
	for(int i=0;i<26;i++){
		cout<<(char)('a'+ i)<<" : "<<alp[i]<<endl;
	}
  return 0;
}

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

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

	vector<long long> a(n);
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		if (i + 1 < n && a[i] % 2 == 1 && a[i + 1] > 0) {
			ans++;
			a[i]--;
			a[i + 1]--;
		}
		ans += a[i] / 2;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {

    int n;
    cin>>n;
    int count=0;
    long long ans=0;
    long long mn=1e9;
    for(int i=0;i<n;i++)
    {long long x;
    cin>>x;

    if(x<0)
        count++;
    ans+=abs(x);
    mn=min(mn,abs(x));
    //cout<<ans<<endl;
    }
    if(count%2==0)
        cout<<ans;
    else
        cout<<ans-(2*mn);
 //   cout<<mn;


    return 0;

}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int a, b;
	cin >> a >> b;
	int res;
	if (a >= b) {
		res = a;
		a--;
	}
	else {
		res = b;
		b--;
	}
	res += max(a, b);
	pv(res)
	return 0;
}

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

int main(){
	int n,m,a,b;
	
	while( cin >> n >> m , n||m ){
		int ans = 0;
		char f[510][510] = {0};
		char g[510] = {0};

		for(int i=0 ; i<m ; i++ ){
			cin >> a >> b;
			f[a][b] = 1;
			f[b][a] = 1;
		}
		for(int i=1 ; i <= n ; i++ ){
			if( f[1][i] ){
				g[i] = 1;
				for(int j=1 ; j <= n ; j++ ){
					if( f[i][j] ){
						g[j] = 1;
					}
				}
			}
		}
		for(int i=2 ; i <= n ; i++ ){
			if( g[i] ){
				ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;


int main(){
    ll s,tmp;
    ll x1,x2,y1,y2,x3,y3;
    scanf("%lld",&s);
    tmp=(ll)ceil(sqrt(s));
    if(tmp*tmp==s){
        printf("0 0 %lld 0 0 %lld\n",tmp,tmp);
        return 0;
    }
    x2=tmp; y3=tmp;
    tmp=tmp*tmp-s;
    for(x3=1;;x3++){
        if(tmp%x3==0&&tmp/x3<=1000000000LL){
            y2=tmp/x3;
            break;
        }
    }
    printf("0 0 %lld %lld %lld %lld\n",x2,y2,x3,y3);
    return 0;
}


Measured memory_bytes: 2208
N = int(input())
P = list(map(int, input().split()))

memo = [0] * N
memo[0] = 1
minn = P[0]
for i in range(1, N):
    if P[i] <= minn:
        memo[i] = 1
    else:
        memo[i] = 0
    minn = min(minn, P[i])
print(sum(memo))


Measured memory_bytes: 26012
n = int(input())
s = input()
res = n
e = s.count("E")

l_w = 0
l_e = 0
for i in range(n):
    if i == n - 1 and s[i] == "E":
        l_e += 1
    tmp = l_w + (e - l_e)
    res = min(tmp, res)
    if s[i] == "W":
        l_w += 1
    else:
        l_e += 1
print(res)


Measured memory_bytes: 9716
import sys

readline = sys.stdin.readline

H, W = map(int, readline().split())
A = [list(map(int, readline().split())) for _ in range(H)]
B = [list(map(int, readline().split())) for _ in range(H)]
dp = [[0] * W for _ in range(H)]
X = (H + W) * 80
d = abs(A[0][0] - B[0][0])
dp[0][0] = 1 << (X - d)
for h in range(H):
    for w, (a, b) in enumerate(zip(A[h], B[h])):
        if h == w == 0:
            continue

        d = abs(a - b)
        x = 0
        if h != 0:
            x |= (dp[h - 1][w] << d)
            x |= (dp[h - 1][w] >> d)
        if w != 0:
            x |= (dp[h][w - 1] << d)
            x |= (dp[h][w - 1] >> d)
        dp[h][w] = x

bit = bin(dp[-1][-1])[2:]
can = [i - X for i, b in enumerate(bit[::-1]) if b == '1']
answer = min(x if x >= 0 else -x for x in can)
print(answer)

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

using namespace std;

int main() {
	int j, y;
	cin >> j >> y;
	if (j >= 5 || y >= 5) {
		if (j == 5 && y == 5) {
			vector<int> d(j+y-2, 2);
			for (int i = 0; i < j-1; i++) {
				d[i] = 1;
			}
			do {
				for (int i = 0; i < j+y-2; i++) {
					if (d[i] == 1) {
						cout << 'A';
					} else {
						cout << 'B';
					}
				}
				cout << "AB" << endl;
				for (int i = 0; i < j+y-2; i++) {
					if (d[i] == 1) {
						cout << 'A';
					} else {
						cout << 'B';
					}
				}
				cout << "BA" << endl;
			} while (next_permutation(d.begin(), d.end()));
		} else if (j == 5) {
			vector<int> d(j+y-1, 2);
			for (int i = 0; i < j-1; i++) {
				d[i] = 1;
			}
			do {
				for (int i = 0; i < j+y-1; i++) {
					if (d[i] == 1) {
						cout << 'A';
					} else {
						cout << 'B';
					}
				}
				cout << "A" << endl;
			} while (next_permutation(d.begin(), d.end()));
		} else if (y == 5) {
			vector<int> d(j+y-1, 2);
			for (int i = 0; i < j; i++) {
				d[i] = 1;
			}
			do {
				for (int i = 0; i < j+y-1; i++) {
					if (d[i] == 1) {
						cout << 'A';
					} else {
						cout << 'B';
					}
				}
				cout << "B" << endl;
			} while (next_permutation(d.begin(), d.end()));
		} else if (j == 6) {
			vector<int> d(j+y-2, 2);
			for (int i = 0; i < j-2; i++) {
				d[i] = 1;
			}
			do {
				for (int i = 0; i < j+y-2; i++) {
					if (d[i] == 1) {
						cout << 'A';
					} else {
						cout << 'B';
					}
				}
				cout << "AA" << endl;
			} while (next_permutation(d.begin(), d.end()));
		} else {
			vector<int> d(j+y-2, 2);
			for (int i = 0; i < j; i++) {
				d[i] = 1;
			}
			do {
				for (int i = 0; i < j+y-2; i++) {
					if (d[i] == 1) {
						cout << 'A';
					} else {
						cout << 'B';
					}
				}
				cout << "BB" << endl;
			} while (next_permutation(d.begin(), d.end()));
		}
	} else {
		vector<int> d(j+y, 2);
		for (int i = 0; i < j; i++) {
			d[i] = 1;
		}
		do {
			for (int i = 0; i < j+y; i++) {
				if (d[i] == 1) {
					cout << 'A';
				} else {
					cout << 'B';
				}
			}
			cout << endl;
		} while (next_permutation(d.begin(), d.end()));
	}
	return 0;
}

Measured memory_bytes: 1188
A, B, K = map(int, input().split())

ans = []
for i in range(K):
    if A + i <= B:
        ans.append(A + i)
    else:
        break

for j in range(K):
    if B - j >= A:
        ans.append(B - j)
    else:
        break

ans2 = sorted(list(set(ans)))

for a in ans2:
    print(a)


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

int main() {
  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<long long>p(a);
  vector<long long>q(b);
  vector<long long>r(c);
  for(int i=0;i<a;i++) cin>>p[i];
  for(int i=0;i<b;i++) cin>>q[i];
  for(int i=0;i<c;i++) cin>>r[i];
  long long ans=0;
  sort(p.begin(),p.end());
  sort(q.begin(),q.end());
  sort(r.begin(),r.end());
  vector<long long>d;
  for(int i=0;i<x;i++) d.push_back(p[a-1-i]);
  for(int i=0;i<y;i++) d.push_back(q[b-i-1]);
  for(int i=0;i<c;i++) d.push_back(r[i]);
  sort(d.begin(),d.end());
  for(int i=0;i<x+y;i++) ans+=d[x+y+c-1-i];
  cout<<ans<<endl;
}


Measured memory_bytes: 8304
a,b,c=map(int,input().split())
if a%2==1 or b%2==1 or c%2==1:
    print("0")
    exit()
if a==b==c:
    print("-1")
    exit()
count=0
while a%2==0 and b%2==0 and c%2==0:
    a,b,c=(b+c)//2,(c+a)//2,(a+b)//2
    count+=1
print(count)

Measured memory_bytes: 9200
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll D;

int main() {
	scanf("%lld", &D);
	if(D == 22) {
		printf("Christmas Eve Eve Eve\n");
	}
	else if(D == 23) {
		printf("Christmas Eve Eve\n");
	}
	else if(D == 24) {
		printf("Christmas Eve\n");
	}
	else {
		printf("Christmas\n");
	}
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n,m;
int k[15];
int s[12][12];

int count(int x){
    int cnt=0;
    do{
        cnt+=x&1;
        x>>=1;
    }
    while(x);
    return cnt;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>k[i];
        for(int j=1;j<=k[i];j++){
            cin>>s[i][j];
        }
    }
    int p[m+3];
    int ans=0;
    rep(i,m)cin>>p[i+1];
    for(int i=0;i<1<<n;i++){
        bool ok=true;
        for(int j=1;j<=m;j++){
        int temp=0;
        for(int l=1;l<=k[j];l++){
            if((i>>(s[j][l]-1))&1)temp++;
        }
            if(temp%2!=p[j])ok=false;
        }
        if(ok)ans++;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=1e16;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int f(ll a){
	int co=0;
	while(a){
		a/=10;
		co++;
	}
	return co;
}
int main(){
	ll n;
	cin>>n;
	int mi=1000;
	for(ll i=1;i*i<=n;i++)if(n%i==0){
		mi=min(mi,max(f(i),f(n/i)));
	}
	cout<<mi<<endl;
}









Measured memory_bytes: 256
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

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

using namespace std;

typedef long long int64;
typedef unsigned long long uint64;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) (((S)&two(X))!=0)
#define containL(S,X) (((S)&twoL(X))!=0)
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> inline void ckmin(T &a,T b){if(b<a) a=b;}
template<class T> inline void ckmax(T &a,T b){if(b>a) a=b;}
template<class T> inline T sqr(T x){return x*x;}
typedef pair<int,int> ipair;
#define SIZE(A) ((int)A.size())
#define LENGTH(A) ((int)A.length())
#define MP(A,B) make_pair(A,B)
#define PB(X) push_back(X)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,a) for(int i=0;i<(a);++i)
#define ALL(A) A.begin(),A.end()

const int maxn=500000+16;
const int MOD=1000000007;

int n;
char s[maxn];
unordered_map<string,int> f[maxn];
int p2[maxn];

inline void ADDTO(int &a,int b) { a=((a+b>=MOD)?(a+b-MOD):(a+b)); }

int solve(int p,string s);
int solve2(int p,string s)
{
	if (s=="000" || s=="001") return solve(p,"0");
	if (s=="011") return solve(p,"1");
	if (s=="1000" || s=="1001") return solve(p,"10");
	if (s=="11") return p2[p];
	if (s=="010") return solve(p,"0");
	if (s=="101") return solve(p,"1");
	return solve(p,s);
}
int solve(int p,string s)
{
	if (p>=n) return (int)(s=="101" || s=="1");
	auto it=f[p].find(s);
	if (it!=f[p].end()) return it->second;
	int ret=0;
	if (::s[p]!='1') ADDTO(ret,solve2(p+1,s+'0'));
	if (::s[p]!='0') ADDTO(ret,solve2(p+1,s+'1'));
	return f[p][s]=ret;
}
int main()
{
#ifdef _MSC_VER
	freopen("input.txt","r",stdin);
#endif
	std::ios::sync_with_stdio(false);
	cin>>s;
	n=strlen(s);
	p2[n]=1;
	for (int i=n-1;i>=0;i--)
	{
		p2[i]=p2[i+1];
		if (s[i]=='?') ADDTO(p2[i],p2[i+1]);
	}
	int ret=solve(0,"");
	printf("%d\n",ret);
	return 0;
}



Measured memory_bytes: 179072
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;

  vector<int> cnt(26, 0), rcnt(26, 0);
  rep(i, N) { rcnt[s[i] - 'a']++; }

  int result = 0;

  rep(i, N) {
    int j = s[i] - 'a';
    cnt[j]++;
    rcnt[j]--;
    int score = 0;
    rep(k, 26) { score += (cnt[k] > 0 && rcnt[k] > 0 ? 1 : 0); }
    result = max(result, score);
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>




int main()
{
  int h,w,n,x,y;
  scanf("%d %d %d",&h,&w,&n);
  scanf("%d %d",&y,&x);

  char c;
  int sx[n],sy[n];
  int i;
  for(i=0;i<n;i++)
    {
      scanf(" %c",&c);
      if(c=='L')
	{sx[i]=-1;sy[i]=0;}
      if(c=='R')
	{sx[i]=1;sy[i]=0;}
      if(c=='U')
	{sx[i]=0;sy[i]=-1;}
      if(c=='D')
	{sx[i]=0;sy[i]=1;}
    }

  int tx[n],ty[n];
  for(i=0;i<n;i++)
    {
      scanf(" %c",&c);
      if(c=='L')
	{tx[i]=-1;ty[i]=0;}
      if(c=='R')
	{tx[i]=1;ty[i]=0;}
      if(c=='U')
	{tx[i]=0;ty[i]=-1;}
      if(c=='D')
	{tx[i]=0;ty[i]=1;}
    }

  
  int k,l=0,r=w+1,u=0,d=h+1;
  char flag=1;
  for(k=n-1;k>=0;k--)
    {
      if(tx[k]>0 && l>=1)l--;
      if(tx[k]<0 && r<=w)r++;
      if(ty[k]>0 && u>=1)u--;
      if(ty[k]<0 && d<=h)d++;
      //      printf("T(%d,%d) x:%d-%d, y:%d-%d\n",tx[k],ty[k],l,r,u,d);

      if(sx[k]>0) r--;
      if(sx[k]<0) l++;
      if(sy[k]>0) d--;
      if(sy[k]<0) u++;
      //      printf("S(%d,%d) x:%d-%d, y:%d-%d\n",sx[k],sy[k],l,r,u,d);
      if(d-u<=1 || r-l<=1)
	{
	  flag=0;
	  break;
	}
    }
  if(flag)
    {
      if(x<=l || r<=x)flag=0;
      if(y<=u || d<=y)flag=0;
    }


  
  if(flag)printf("YES");
  else printf("NO");

}




Measured memory_bytes: 3328
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 100005, MAXM = 45004, Mod = 998244353 , MAXLog = 20;

long long arr[MAXN];
long long memo[MAXN][2];
int n;
long long solve(int idx, bool sign) {
    if (idx == n)
        return sign ? 0 : -OO;
    long long &ret = memo[idx][sign];
    if (~ret)
        return ret;
    long long ch1 = arr[idx] * (sign ? 1 : -1) + solve(idx + 1, 1);
    long long ch2 = arr[idx] * (sign ? -1 : 1) + solve(idx + 1, 0);

    return ret = max(ch1, ch2);
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

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

    memset(memo, -1, sizeof memo);

    cout << solve(0, 1) << '\n';

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){

  ll N;
  IN(N);
  vll W(N);
  ll W_sum = 0;
  REP(i,N){
    IN(W[i]);
    W_sum += W[i];
  }

  ll W_tmp = 0;
  ll ans = INFLL;

  REP(i,N-1){
    W_tmp += W[i];
    ll W_others = W_sum - W_tmp;
    ans = min(ans, abs(W_others-W_tmp));
  }

  OUT(ans);

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<functional>
#include<queue>
#include<math.h>
#define INF 999999

using namespace std;

int memo[50];

int fib(int n)
{
	memo[0] = 1;
	memo[1] = 1;

	if (n == 0)return 1;
	else if (n == 1)return 1;
	else {
		for (int i = 2; i <= n; i++) {
			memo[i] = memo[i - 1] + memo[i - 2];
		}
		return memo[n];
	}
}

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

	int ans = fib(n);
	cout << ans << endl;

	return 0;
}

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


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

    int R;
    cin >> R;
    cout << fixed << setprecision(10);

    cout << 2*R*3.1415926535<<endl;


}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int arr1[20];
int arr2[20];
vector<int> adj[100005];
vector<int> sz(100005);
int ans = 0;

void dfs(int v, int par = 0)
{
    sz[v] = 1;
    for (auto x : adj[v])
    {
        if (x == par) continue;
        dfs(x, v);
        sz[v] += sz[x];
    }
    if (sz[v] % 2 == 0) ans++;
}

int32_t main()
{
    c_p_c();
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    int x = l / d;
    for (int i = x * d; i <= r; i += d)
    {
        if (i >= l)
            ans++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 6276
# -*- coding: utf-8 -*-
# Luis Yoichi Morales January 2019

N=int(raw_input())
A=sorted(map(int,raw_input().split()))
B=sorted(map(int,raw_input().split()))
C=sorted(map(int,raw_input().split()))

x=0
z=0
res=0

for y in B:
    while x<N and A[x]<y:
        x+=1
    while z<N and C[z]<=y:   #org
        z+=1
    res+=x*(N-z)   #org
print res


Measured memory_bytes: 17884
#include <iostream>
#include<vector>
#define inf 1e9
using namespace std;
int solve(vector<int> h, int n, int k){
    vector<int> dp(n+1);
    dp[1] = 0;
    for(int i=2;i<=n;i++){
        dp[i] = inf;
        for(int j = i-1 ; j >= 1 && (i-j) <= k ; j--){
            dp[i] = min(dp[i],abs(h[i]-h[j]) + dp[j]);
        }
    }
    return dp[n];
}
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> h(n+1);
    for(int i=1;i<=n;i++){
        cin>>h[i];
    }
    cout<<solve(h,n,k);
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll  = long long;
#define int ll

const int N = 1e6;

int n, m;
vector<pair<int, int>> g[N];
int val[N];
bool was[N];

void dfs(int v) {
	was[v] = true;
	for (auto e : g[v]) {
		int u = e.x, w = e.y;
		if (!was[u]) {
			val[u] = val[v] + w;
			dfs(u);
		} else if (val[u] != val[v] + w) {
			cout << "No\n";
			exit(0);
		}
	}
}

signed main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	while (m--) {
		int v, u, d;
		cin >> v >> u >> d;
		--v;
		--u;
		g[v].emplace_back(u, d);
		g[u].emplace_back(v, -d);
	}
	for (int i = 0; i < n; ++i) {
		if (!was[i]) {
			dfs(i);
		}
	}
	cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 37376
n = int(input())
A = list(map(int, input().split()))
 
from collections import Counter
c = Counter(A)
 
mul = []
for k, v in c.items():
    if v >= 2:
        mul.append(k)
    if v >= 4:
        mul.append(k)
mul.sort()
if len(mul) < 2:
    print(0)
else:
    print(mul[-1]*mul[-2])

Measured memory_bytes: 18316
import copy
import sys
N=int(input())
P=list(map(int,input().split()))
for i in range(N):
    for j in range(N):
        Pt=copy.copy(P)
        Pt[j]=P[i]
        Pt[i]=P[j]

        tmp=Pt[0]
        for k,t in enumerate(Pt[1:]):
            if t>tmp:
                tmp=t
            else:
                break
            if k==N-2:
                print('YES')
                sys.exit()
            
print('NO')


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define ll 				long long
#define int             long long int
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define modp            998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
// void aks()
// {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
// }

int ac = 0, re = 0, tle = 0, wa = 0;
void solve()
{
	string s;
	cin >> s;
	if(s == "AC")
		ac++;
	if(s == "WA")
		wa++;
	if(s == "TLE")
		tle++;
	if(s == "RE")
		re++;
}
 
int32_t main()
{
	FIO
    //aks();
    ac = 0, re = 0, tle = 0, wa = 0;
    w(t)
    {
    	solve();
    }
    cout << "AC" << " " << "x" << " " << ac << endl;
    cout << "WA" << " " << "x" << " " << wa << endl;
    cout << "TLE" << " " << "x" << " " << tle << endl;
    cout << "RE" << " " << "x" << " " << re << endl;
    return 0;
}
	

	

Measured memory_bytes: 3656
fn main() {
    let (a, b) = read_tuple();
    if a % 2 == 0 || b % 2 == 0 { 
        println!("Even");
    } else {
        println!("Odd")
    }   
}

fn read_tuple() -> (u32, u32) {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut buf = buf.trim().split_whitespace();
    let a = &buf.next().unwrap().parse::<u32>().unwrap();
    let b = &buf.next().unwrap().parse::<u32>().unwrap();
    (*a, *b) 
}


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

int main(){
    int H, W;
    while(1){
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if ((i + j) % 2 == 0){
                    cout << "#";
                } else {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<int> A(3*N);
  REP(i, 3*N) cin >> A[i];

  sort(ALL(A), greater<int>());

  int ans = 0;
  for(int i = 1; i < 2*N; i += 2) ans += A[i];

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
x1, x2, x3, x4, x5 = map(int, input().split())

if x1 == 0:
    print(1)
elif x2 == 0:
    print(2)
elif x3 == 0:
    print(3)
elif x4 == 0:
    print(4)
elif x5 == 0:
    print(5)

Measured memory_bytes: 9068
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
   ;
    //サンプルコード;;
    //ABC076-A;;
    ;;
    string s;;;
    cin >> s;;;
    ;;
    vector<char> klst;;;
    for(int i = 1; i <= s.size(); ++i){; klst.push_back(s[i-1]);;;};;
    sort(klst.begin(), klst.end());;;
    char val_0_ = klst[1-1];;
    char val_1_ = klst[2-1];;
    char val_2_ = klst[3-1];;
    if(val_0_=='a'&&val_1_=='b'&&val_2_=='c'){ cout << "Yes" << endl;;;}
    else { cout << "No" << endl;;;}
}

Measured memory_bytes: 888
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int x[]=new int[n+1];
        for(int i=0;i<n;i++){
            x[i]=0;
        }
        for(int i=0;i<m;i++){
            x[sc.nextInt()]++;
            x[sc.nextInt()]++;
        }
        for(int i=1;i<=n;i++){
            System.out.println(x[i]);
        }
        

    }
}

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

using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll,ll>;
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)

int N, M;
vvl G;
vl visited;
map<pll,bool> used;

bool isUsed(int from, int to) {
    if (from > to) swap(from, to);
    return used[pll(from,to)];
}

void output(int from, int to) {
    printf("%d %d\n", from+1, to+1);
    if (from > to) swap(from, to);
    used[pll(from,to)] = true;
}

bool dfs(int v, int parent = -1) {
    if (visited[v]) return isUsed(parent, v);
    visited[v] = true;
    
    bool isOdd = false;
    for (auto to : G[v]) {
        if (isUsed(v, to)) continue;
        if (to == parent) continue;
        if (!dfs(to, v)) {
            isOdd = !isOdd;
            output(v, to);
        }
    }
    if (isOdd) output(v, parent);
    return isOdd;
}

int main() {
    cin >> N >> M;
    G.resize(N);
    visited.assign(N,false);
    rep(i,M) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b); G[b].push_back(a);

        if (a > b) swap(a,b);
        used[pll(a,b)] = false;
    }
    if (M & 1) cout << -1 << endl;
    else dfs(0);
    return 0;
}


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

int n, M, x[100005], nums[100005], p[100005], cnt[100005];
long long ans;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> M;
    for(int i=0; i<n; i++) {
        cin >> x[i];
        cnt[x[i]]++;
        nums[x[i]%M]++;
    }
    for(int i=1; i<=100000; i++) {
        p[i%M] += cnt[i]/2;
    }

    for(int i=0; 2*i<=M; i++) {
        if(i==0 || (i==M/2&&M%2==0)) {
            ans += nums[i]/2;
            continue;
        }
        int gap = min(nums[i], nums[M-i]);
        nums[i] -= gap;
        nums[M-i] -= gap;
        ans += gap;
        if(nums[i]==0) ans += min(p[M-i], nums[M-i]/2);
        else if(nums[M-i]==0) ans += min(p[i], nums[i]/2);
    }
    cout << ans << '\n';

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 30;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

struct edge {int to; ll cost;};
vector<vector<edge>> g(100000+1);
vector<ll> dist(100000+1, INF64);

void dfs(int now) {
  for(auto next : g[now]) {
    if(dist[next.to] == INF64) {
      dist[next.to] = dist[now]+next.cost;
      dfs(next.to);
    }
  }
}

int main()
{
  int n, m; cin >> n >> m;
  vector<int> l(m), r(m), d(m);
  rep(i, m) {
    cin >> l[i] >> r[i] >> d[i];
    edge x = {r[i], d[i]};
    edge y = {l[i], -d[i]};
    g[l[i]].push_back(x);
    g[r[i]].push_back(y);
  }

  for(int i = 1; i <= n; ++i) {
    if(dist[i] == INF64) {
      dist[i] = 0;
      dfs(i);
    }
  }
  rep(i, m) {
    if(dist[r[i]]-dist[l[i]] != d[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 18816
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public class Test
{

	public static void Main()
	{
        int[] nums = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int N = nums[0];
        int Y = nums[1];
        
        bool no = true;
        for(int x = 0 ; x <=  N ; x++)
        {
            for(int y = 0 ; y <= N ; y++)
            {
                if(x*10000+ y*5000 + (N-x-y)*1000 == Y && N-x-y >= 0 && no)
                {
                    Console.WriteLine(x+" "+y+" "+(N-x-y));
                    no = false;
                    break;
                }
            }
        }
        
        if(no) Console.WriteLine(-1+" "+-1+" "+-1);

    }

}

Measured memory_bytes: 13396
#!/usr/bin/env python3
def func(a, i):
    return {a[0]:i, a[1]:i+1, a[2]:i+2}
A = {}
for i in range(3):
    A.update(func(input().split(), 3*i))
N = int(input())
b = [A.get(input(), -1) for _ in range(N)]
bingo = [[0, 1, 2], [3, 4, 5], [6, 7, 8],
         [0, 3, 6], [1, 4, 7], [2, 5, 8],
         [0, 4, 8], [2, 4, 6]]
for i in bingo:
    if set(i) <= set(b):
        print("Yes")
        break
else:
    print("No")

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

struct coin {
    int gold;
    int silver;
    int bronz;

    bool operator<( const coin& rright ) const {
        return gold == rright.gold ? silver < rright.silver : gold < rright.gold;
    }
};

long long X, Y, Z;
coin coins[100005];
vector<pair<long long, coin> >cvec;

long long lleft[100005];
long long rright[100005];

int main(){
	cin >> X >> Y >> Z;
	for(long long i = 0; i < X + Y + Z; i++){
		cin >> coins[i].gold >> coins[i].silver >> coins[i].bronz;
		cvec.push_back(make_pair(coins[i].gold - coins[i].silver, coins[i]));
	}

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

	for(int i = 0; i < cvec.size(); i++){
		coins[i] = cvec[i].second;
	}

	//小さい方を処理したい
	//                silver - bronz
	priority_queue<pair<long long, coin>,
			vector<pair<long long, coin> >,
			greater<pair<long long, coin> > >que;

	long long scur = 0;
	long long bcur = 0;
	for(int i = 0; i < Y; i++){
		que.push(make_pair(coins[i].silver - coins[i].bronz, coins[i]));
		scur += coins[i].silver;
	}

	for(int i = Y; i < Y + Z; i++){
		lleft[i] = scur + bcur;
		if(que.top().first < coins[i].silver - coins[i].bronz){
			scur -= que.top().second.silver;
			scur += coins[i].silver;
			bcur += que.top().second.bronz;
			que.pop();
			que.push(make_pair(coins[i].silver - coins[i].bronz, coins[i]));
		}else{
			bcur += coins[i].bronz;
		}
	}
	lleft[Y+Z] = scur + bcur;


	//小さい方を処理したい
	//                gold - bronz
	priority_queue<pair<long long, coin>,
			vector<pair<long long, coin> >,
			greater<pair<long long, coin> > >que2;

	scur = 0;
	bcur = 0;
	long long gcur = 0;

	for(int i = X + Y + Z - 1; i >= Y + Z; i--){
		que2.push(make_pair(coins[i].gold - coins[i].bronz, coins[i]));
		gcur += coins[i].gold;
	}
	rright[Y + Z] = gcur + bcur;

	for(int i = Y + Z - 1; i >= Y; i--){
		if(que2.top().first < coins[i].gold - coins[i].bronz){
			gcur -= que2.top().second.gold;
			gcur += coins[i].gold;
			bcur += que2.top().second.bronz;
			que2.pop();
			que2.push(make_pair(coins[i].gold - coins[i].bronz, coins[i]));
		}else{
			bcur += coins[i].bronz;
		}
		rright[i] = gcur + bcur;
	}


	long long ans = 0;
	for(long long K = Y - 1; K < Y + Z; K++){
		ans = max(ans, lleft[K+1] + rright[K+1]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 10224