akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納　par[x] == x の時そのノードは根
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0)
        self.rank = [0] * (n+1)
        # 各々の集合の要素数（根が代表して値を持っておく）
        self.count = [1] * (n+1)

    # 検索
    def find(self, x):
        # 根ならその番号を返す
        root = x
        queue = [x]
        data = []
        while queue:
            now = queue.pop()
            if self.par[now] == now:
                root = now
            else:
                # 根でないなら親の要素で再検索
                data.append(now)
                queue.append(self.par[now])
        # 検索する過程で親を更新
        for y in data:
            self.par[y] = root
        return root

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        t = (x == y)
        if UnionFind.same_check(self,x,y):
            return t
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.count[y] += self.count[x]
            self.count[x] = 0
        else:
            self.par[y] = x
            self.count[x] += self.count[y]
            self.count[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        return t


    # 同じ集合に属しているか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # 属している集合の要素数
    def size(self,x):
        q = UnionFind.find(self,x)
        return self.count[q]

n,m,k = map(int,input().split())
u = UnionFind(n)
friend = [1 for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    friend[a] += 1
    friend[b] += 1
    u.union(a,b)


ans = [u.size(i)-friend[i] for i in range(n)]
#print(*ans)
for i in range(k):
    c,d = map(int,input().split())
    c -= 1
    d -= 1
    if u.same_check(c,d):
        ans[c] -= 1
        ans[d] -= 1

print(*ans)

Measured memory_bytes: 77984
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  ll b;
  cin>>b;
  vector<char>vec(a);
  for(ll i=0;i<a;i++){
    cin>>vec.at(i);
  }
  vec.at(b-1)=vec.at(b-1)-'A'+'a';
  for(ll i=0;i<a;i++){
    cout<<vec.at(i);
  }
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <functional>
#include <ctime>
#include <queue>
#include <string>
#include <map>
#include <sstream>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define form(i,a,b) for(int i=(a);i<(b);i++)
#define sz(x) ((int)(x).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorm_s(vector<string> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
//int cmp( const void *p, const void *q ) {if( ＊(double＊)p > ＊(double＊)q ) return 1;if( ＊(double＊)p < ＊(double＊)q ) return -1;return 0;}

int main(void){
   cin.tie(0);
   ios::sync_with_stdio(false);
   unsigned long a,b,c,d,e;
   //int ad,bd;
   unsigned long f=0;
   string st,tt,nt;
   vi ad,bd,cd,dd;
   vs A,W,B;
   int X=0;
   vs as,bs,cs,ds;
   vector<char> C;
   string sa;
  // char cd;
   int flag=0,nfl,ta,tb;
   std::cin>>a>>b;
   printa(a+(b/2));

   return 0;
}


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

double sign;
double ans;

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

  for (ll i = 0; i <= 1000; i++)
  {
    for (ll j = 0; j < i; j++)
    {
      if (pow(i, 5) - pow(j, 5) == n)
      {
        cout << i << " " << j << endl;
        return 0;
      }
      if (pow(i, 5) + pow(j, 5) == n)
      {
        cout << i << " " << -j << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 4096
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <climits>
#include <cmath>
#include <functional>
#include <map>
#include <queue>
#include <set>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

const int maxi = 1e6+10;
string s;
vector<int> v(maxi),result;
int n,b;
ll a[maxi];

int main () {
  int count = 0;
  cin >> n;
  // cout << "get n";
  for (size_t i = 1; i <= n; i++) {
    // cout << i << endl;
    cin >> b; a[i] = b; v[i] = b;
    // cout << "," << endl;
  }
  // cout << "a" << endl;
  for(int i = n; i>0; i--) {
    // cout << i << endl;
    for (size_t j = 2; i*j <= n; j++) {
      v[i] += v[i*j];
      v[i] %= 2;
    }
  }
  // cout << "b" << endl;
  rep(i,n) {
    if(v[i+1] == 1) {
      count++;
      result.push_back(i+1);
    }
  }

  cout << count << endl;
  rep(i,result.size()) cout << result[i] << ' ';
  // rep(i,n) cout << v[i+1] << endl;
}


Measured memory_bytes: 7032
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
typedef long long ll;

int n, m, t[30000];

int main(void) {
    while (1) {
        cin >> n >> m;
        if (n == 0 && m == 0) break;
        for (int i = 0; i < n+m; i++) {
            cin >> t[i];
        }
        sort(t, t+(n+m));
        int ma = t[0];
        for (int i = 1; i < n+m; i++) {
            ma = max(t[i]-t[i-1], ma);
        }
        cout << ma << endl;
    }
    return 0;
}

Measured memory_bytes: 1256
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        int[] n = io.r<int>(' ');
        int W = n[0];
        int H = n[1];
        int x = n[2];
        int y = n[3];
        int r = n[4];
        if (((x - r) >= 0) && ((x + r) <= W) && ((y - r) >= 0) && ((y + r) <= H)) { io.w("Yes"); }
        else { io.w("No"); }
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

Measured memory_bytes: 10340
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main() {
    int a,b;
    cin >> a >> b;
    if(a == b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
  

    return 0;
}


Measured memory_bytes: 256
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N,M;
	cin >> N>>M;
	ll k[M];
	vector<ll> s[M];
	REP(i,M){
		cin>>k[i];
		REP(j,k[i]){
			ll s_tmp;cin>>s_tmp;s_tmp--;
			s[i].pb(s_tmp);
		}
	}
	ll p[M];
	REP(i,M)cin>>p[i];

	// 解法
	ll ans = 0;
	REP(i,pow(2,N)){
		ll on[N];
		ll tmp = i;
		REP(j,N){
			on[j] = tmp%2;
			tmp /=2;
		}
		// REP(j,N) printf("%lld ", on[j]);
		// printf("\n");
		
		ll count= 0;
		REP(j,M){
			ll tmp = 0;
			REP(l,s[j].size()){
				tmp += on[s[j][l]];
			}
			if (tmp%2==p[j]) count++;
			
		}
		if (count==M) ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
	int i,n,d,x,a,ans;
	scanf("%d%d%d",&n,&d,&x);
	ans=n+x;
	for(i=0;i<n;i++){
		scanf("%d",&a);
		ans+=(d-1)/a;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string>
int a[]={1,3,5,7,8,10,12};
int b[]={4,6,9,11};
int c[]={2};

int main()
{
	int x,y;
	int flagx,flagy;
	scanf("%d %d",&x,&y);
	for(int i=0;i<7;i++)
	{
		if(x==a[i]) flagx=1;
		if(y==a[i]) flagy=1;
	}
	for(int i=0;i<4;i++)
	{
		if(x==b[i]) flagx=2;
		if(y==b[i]) flagy=2;
	}
	if(x==2) flagx=3;
	if(y==2) flagy=3;
	if(flagx==flagy) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
def solve():
  n = int(input())
  count = n//100
  rem = n%100
  if n < 100:
    return False
  if rem == 0:
    return True
  ll = 0
  for i in range(5,0,-1):
    q,r = shakutori(rem,i)
    if q != 0:
      ll += q
      rem = r
  if ll <= count:
    return True
  else:
    return False

def shakutori(n,i):
  return n//i,n%i

if __name__ == '__main__':
  print(int(solve()))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <bitset>
#include <regex>
#include <cassert>
#include <set>
#include <map>
using namespace std;
#define inf 2000000000
#define mod 1000000007
map<string, bool> dict;
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	string s;
	cin >> n;
	while(n--){
		cin >> s;
		dict[s] = true;
	}
	cout << dict.size();
}

Measured memory_bytes: 19256
# include<bits/stdc++.h>
 
using namespace std;
 
# define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 
# define S second
# define F first
# define kill(x) return(cout << x << endl, 0)
# define debug(x) cerr<< #x << " : " << x << endl
# define ddebug(x, y) cerr<< #x << " : " << x  << ", " << #y << " : " << y << endl
# define sz(s) (int)s.size()
# define sq(x) (x) * (x)
# define PB(x) push_back(x)
# define smax(x, y) (x) = max((x), (y))
# define smin(x, y) (x) = min((x), (y))
# define all(x) x.begin(), x.end()
# define SP fixed << setprecision(10)
# define UB upper_bound 

const int MAXN = 50 + 10;
int a[MAXN];

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

	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
		cin >> a[i];
	int sum = 0;
	for (int i = 0; i < n; i ++)
		for (int j = i + 1; j < n; j ++)
			sum += a[i] * a[j];
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(INF)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b; cin>>a>>b;
	cout<<max(max(a+b,a-b),a*b)<<"\n";
	return 0;
}




























Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n,m;
	ll t[101],p[101],x[101];
	ll c[101]={};

	cin>>n;
	for(ll i=1; i<n+1; i++){
		cin>>t[i];
	}
	cin>>m;
	for(ll j=1; j<m+1; j++){
		cin>>p[j]>>x[j];
	}
	for(ll j=1; j<m+1; j++){
		c[j]=x[j];
		for(ll i=1; i<n+1; i++){
			if(i!=p[j]){
				c[j]+=t[i];
			}
		}
	}
	for(ll j=1; j<m+1; j++){
		cout<<c[j]<<endl;
	}
	return 0;
}


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

int main () {
  int N, M, c, d;
  c = 0;
  cin >> N;
  vector<string> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  cin >> M;
  vector<string> b(M);
  for (int i = 0; i < M; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < N; i++) {
    d = 0;
    for (int j = 0; j < N; j++) {
      if (a.at(i) == a.at(j)) {
        d++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (a.at(i) == b.at(j)) {
        d--;
      }
    }
    if (d > c) {
      c = d;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 3636
#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"




def main():
    a,b,c = mi()
    if c-a-b<=0:
        print(no)
        exit()
    else:
        if (c-a-b)**2 > 4*a*b:
            print(yes)#gcdは3.4.3だとfractionsにある
from fractions import gcd
import math

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "YES"
no = "NO"


def main():
    n,l = mi()
    a = li()

    flag = False
    lp = 0
    for i in range(n-1):
        if a[i]+a[i+1] >= l:
            print("Possible")
            flag = True
            lp = i+1
            break
    
    if not flag:
        print("Impossible")
        exit()

    for i in range(1,lp):
        print(i)
    for i in range(n-1,lp,-1):
        print(i)
    print(lp)
    
    

    


main()



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

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


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100000

int parent(int);
int left(int);
int right(int);
int n;
int main(){
  int i,A[N],k;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }

  for(i=1;i<=n;i++){
    printf("node %d: ",i);
    printf("key = %d, ",A[i]);
    k=parent(i);
    if(k!=-1){
      printf("parent key = %d, ",A[k]);
    }
    if(left(i)!=-1){
      printf("left key = %d, ",A[left(i)]);
    }
    if(right(i)!=-1){
      printf("right key = %d, ",A[right(i)]);
    }
    printf("\n");
  }

return 0;
}


int parent(int id){
  static int pid=0;
  if(id%2==0){
    pid++;
  }
  if(pid==0){return -1;}
  else{return pid;}
}

int left(int id){
  int lid;
  lid=2*id;
  if(lid<=n){
  return lid;}
  else{return -1;}
}

int right(int id){
  int rid;
  rid=2*id+1;
  if(rid<=n){
  return rid;}
  else{return -1;}
}



Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<int64_t> x(N), y(N), z(N);
    for(int i=0; i<N; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }

    int64_t ans = numeric_limits<int64_t>::min();
    for(int bit=0; bit<8; bit++) {
        vector<int64_t> v(N);
        for(int i=0; i<N; i++) {
            v[i] = x[i]*(((bit>>0) & 1) * 2 - 1) + y[i]*(((bit>>1) & 1) * 2 - 1) + z[i]*(((bit>>2) & 1) * 2 - 1);
        }
        sort(v.rbegin(), v.rend());
        ans = max(ans, accumulate(v.begin(), v.begin()+M, 0L));
    }

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


Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

fn read_line<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

fn main() {
    let vec: Vec<i64> = read_line();
    let n = vec[0];
    let mut num = 0;

    for i in 1..n {
        num += i;
    }

    if n == 1 {
        println!("{}", 0);
    } else {
        println!("{}", num);
    }
}

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

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    int n,m;
    cin >> n >> m;
    vector<int> s(n+1),a(m);
    for(int i = 0;i < m;i ++){
        cin >> a.at(i);
    }

    for(int i = 0;i < m;i ++){
        s.at(a.at(i)) = -1;
    }

    s.at(0) = 1;

    if(s.at(1) != -1){
        s.at(1) = 1;
    }

    for(int i = 2;i < n+1;i ++){
        if(s.at(i) < 0){
            continue;
        }

        if(s.at(i-2) != -1){
            s.at(i) += s.at(i-2);
        }
        if(s.at(i-1) != -1){
            s.at(i) += s.at(i-1);
        }

        s.at(i) %= 1000000007;
    }

    cout << s.at(n);
}

Measured memory_bytes: 1024
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int N;
int main() {
	cin>>N;
	int A,B,C,D;
	A=N/1000;
	B=(N%1000)/100;
	C=(N%1000)%100/10;
	D=N%10;

	if(A==B&&B==C)cout<<"Yes"<<endl;
	else if(B==C&&C==D)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	
	ll k;
	cin >> k;
	ll onaji = 1;
	char moji = s[0];
	ll ans = 0,ans2=0;

	for(int i=1;i<s.size();i++)
	{
		if (moji == s[i])
		{
			onaji++;
		}
		else
		{
			ans += onaji / 2;
			moji = s[i];
			onaji = 1;
		}
	}
	if (onaji == s.size())
	{
		cout << onaji * k / 2 << endl;
		return 0;
	}
	if (k > 1)
	{
		for (int i = 0; i < s.size(); i++)
		{
			if (moji == s[i])
			{
				onaji++;
				if (k == 2 && i == s.size() - 1)
				{
					ans2 += onaji / 2;
				}
			}
			else
			{
				ans2 += onaji / 2;
				moji = s[i];
				onaji = 1;
			}

		}
		if (k == 2)
			ans += ans2;
		else
		{
			ans += ans2 * (k - 2);

			for (int i = 0; i < s.size(); i++)
			{
				if (moji == s[i])
				{
					onaji++;
					if (i == s.size() - 1)
					{
						ans += onaji / 2;
					}
				}
				else
				{
					ans += onaji / 2;
					moji = s[i];
					onaji = 1;
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        int[] n = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int N = n[0];
        int A = n[1];
        int B = n[2];
        int sum = 0;
        for(int i = 1; i <= N; i++)
        {
            int digitSum = CulcSumDigits(i);
            if (digitSum >= A && digitSum <= B)
                sum += i;
        }
        Console.WriteLine(sum);
    }
    static int CulcSumDigits(int n)
    {
        int sum = 0;
        while(n > 0)
        {
            sum += n % 10;
            n /= 10;
        }
        return sum;
    }
}


Measured memory_bytes: 13268
X, Y = list(map(int, input().split()))

result = 'No'
for i in range(0, 101):
    for j in range(0, 101):
        XX = i + j
        YY = i * 2 + j * 4
        if X == XX and Y == YY:
            result = 'Yes'

print(result)


Measured memory_bytes: 9176
N = int(input())
ans = [0 for _ in range(10050)]
for i in range(1,105):
  for j in range(1,105):
    for k in range(1,105):
      v = i*i+j*j+k*k+i*j+j*k+k*i;
      if v<10050:
        ans[v]+=1
for l in range(N):
  print(ans[l+1])

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

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

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

    C[1] = 0;
    for ( int i = 0; i < N; i++ ) {
        B[A[i]] = 1;
        if ( B[A[i]-1] ) { C[ A[i] ] = 1; }
    }

    int best = 0;
    int cnt = 0;
    for ( int i = 1; i <= N; i++ ) {
        if ( C[i] ) { cnt++; }
        else { cnt = 0; }
        best = max( best, cnt+1 );
    }
    cout << N-best << endl;

    return 0;
}

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

using ll = long long;

constexpr ll INF = 1e18;

int main() {
    int n;
    cin >> n;
    vector<vector<ll>> dp(n, vector<ll>(n, INF));
    vector<ll> a(n), b(n);
    for(int i=0; i<n; ++i) {
        cin >> a[i] >> b[i];
    }
    for(int i=0; i<n; ++i) {
        dp[i][i] = 0;
    }
    for(int w=1; w<n; ++w) {
        for(int i=0; i+w<n; ++i) {
            for(int j=i; j<i+w; ++j) {
                dp[i][i+w] = min(dp[i][i+w], dp[i][j] + dp[j+1][i+w] + a[i]*b[j]*a[j+1]*b[i+w]);
            }
        }
    }
    cout << dp[0][n-1] << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef pair<int,Pii > P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
set<string> memo;
char str[32];
void dfs(string s,int bit,int idx,int len){
	//cout <<idx << ":" << str << "\n";
	if(s.size() == len){
		memo.insert(s);
		return ;
	}
	if(str[idx] == 'z'){
		if(bit&1<<('z'-'a'))dfs(s+"z",bit|1<<('z'-'a'),idx+1,len);
	}
	else{
		if(bit & 1<<(str[idx]-'a')){
			dfs(s+str[idx],bit|1<<(str[idx]-'a'),idx+1,len);
		}
		if((bit & 1<<(str[idx]-'a'+1)) == 0){
			dfs(s+(char)(str[idx]+1),bit|1<<(str[idx]-'a'+1),idx+1,len);
		}
	}
	return ;
}
int main(){
	while(true){
		scanf("%s",str);
		if(strcmp(str,"#") == 0){
			break;
		}
		memo.clear();
		int length = strlen(str);
		dfs("",1,0,length);
		set<string>::iterator it;
        printf("%d\n",memo.size());
        if(memo.size() < 10){
            for(it=memo.begin();it != memo.end(); it++){
                printf("%s\n",(*(it)).c_str());
            }   
        }
        else{
            int cnt = 0;
            for(it=memo.begin();it != memo.end(); it++){
                if(cnt < 5 || cnt >= memo.size()-5)printf("%s\n",(*(it)).c_str());
                cnt++;
            }   
        }
	}
	return 0;
}

Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <map>
#include <limits.h>
#include <queue>

#define INF INT_MAX

using namespace std;

int main()
{
  string s;
  for(;cin>>s;)
    {
      int ans=0,tmp=0;
      int n[]={1000,500,100,50,10,5,1};
      string nn="MDCLXVI";
      for(int i=0;i<s.size();i++)
	{
	  for(int j=0;j<nn.size();j++)
	    {
	      if(s[i]==nn[j])
		{
		  ans+=n[j];
		  if(tmp<n[j])
		    ans-=tmp*2;
		  tmp=n[j];
		}
	    }
	}
      cout<<ans<<endl;
    }
}

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

using namespace std;

string N;

int toint(string s) {
	int res = 0;
	for (int i = 0; i < (int)s.size(); i++) res = 10 * res + (s[i] - '0');
	return res;
}

string tostr(int i) {
	stringstream s;
	s << i;
	return s.str();
}

void solve() {
	set<int> use;
	use.insert(toint(N));
	
	int cnt = 0;
	
	while ((int)N.size() != 1) {
		int maxi = 0;
		
		int len = (int)N.size();
		for (int i = 1; i < len; i++) {
			string l = N.substr(0, i), r = N.substr(i);
			int li = toint(l), ri = toint(r);
			int mul = li * ri;
			maxi = max(maxi, mul);
		}
		
		if (use.find(maxi) != use.end()) {
			cout << -1 << endl;
			return;
		}
		
		use.insert(maxi);
		N = tostr(maxi);
		
		cnt++;
	}
	
	cout << cnt << endl;
}

int main() {
	int Q; cin >> Q;
	
	for (int i = 0; i < Q; i++) {
		cin >> N;
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define MAX 1005
const ll MOD=1e9+7;
using namespace std;
ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}
ll lcm(ll a, ll b) {
  ll tmp=gcd(a,b);
  return (a/tmp)*(b/tmp)*tmp;
}
ll ex(ll x){
  if(x==1) return 1;
  return (x*ex(x-1))%MOD;
}

int main() {
  ll N,M;
  cin >> N >> M;
  if(llabs(N-M)>=2) {
    cout << 0 << endl;
    return 0;
  }
  if(llabs(N-M)==1) {
    cout << ex(N)*ex(M)%MOD  << endl;
  }else if(M==N) {
    cout << 2*ex(N)*ex(M)%MOD  << endl;
  }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}




signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int x;cin>>x;
  if(x==1)puts("Hello World\n");
  else{
    int a,b;cin>>a>>b;
    cout<<a+b<<endl;
  }
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long power = 1;
		
		for(long i = 1; i <= n; i++){
			power = (power * i) % 1000000007; 
		}
		System.out.println(power);
	}

}


Measured memory_bytes: 21840
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int N;

int b;
int main(){
  int N;
  cin >> N;
  int a[N];
  rep(i,N){
    cin >> a[i];
  }
  rep(i,N){
    if(a[i] != i+1) b++;
  }
  if(b == 0 || b == 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')

typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        a[i] = i + 1;
    }
    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> q[i];
    }
    int cnt1 = 0, cnt2 = 0;
    int cnt = 0;
    do
    {
        cnt++;
        int flag = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] != p[i])
            {
                flag = 1;
                break;
            }
        }
        if (!flag)
            cnt1 = cnt;
        int flag1 = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] != q[i])
            {
                flag1 = 1;
                break;
            }
        }
        if (!flag1)
            cnt2 = cnt;
    } while (next_permutation(a.begin(), a.end()));
    cout << abs(cnt1 - cnt2) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
typedef long long intl;

intl GCD(intl x, intl y) {
    while (x != y)
    {
        if (x > y)
        {
            x = x - y;
        } else {
            y = y - x;
        }
    }
    return x;
}

int main() {
    intl a,b,c,d;
    cin >> a >> b >> c >> d;
    intl ans = b-a+1; //個数
    intl gcd = GCD(c,d);
    if (d > c)
    {
        intl tmp = c;
        c = d;
        d = tmp;
    }
    // c <= d 
    intl modc = b / c - (a-1) / c;
    intl modd = b / d - (a-1) / d;
    ans -= (modc + modd);

    //重複して引いた数は，LCMの商となる．
    intl lcm = c*d/gcd;
    intl dupulicate = b/lcm - (a-1)/lcm;
    ans += dupulicate;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
// Copyright 2020 yaito3014
#include <iostream>
#include <vector>

int main() {
  using namespace std;
  int K;
  cin >> K;
  string S;
  cin >> S;
  const int N = K + S.length();
  constexpr long long kMod = 1000000007;
  auto modpow = [&](long long a, int b) {
  	long long r = 1;
  	for (; b > 0; b /= 2) {
  		if (b % 2) r = r * a % kMod;
  		a = a * a % kMod;
  	}
  	return r;
  };
  auto inv = [&](int a) { return modpow(a, kMod - 2); };
  vector<long long> fact(N + 1, 1);
  for (int i = 0; i < N; ++i) fact[i + 1] = fact[i] * (i + 1) % kMod;
  vector<long long> inv_fact(N + 1);
  inv_fact[N] = inv(fact[N]);
  for (int i = N; i > 0; --i) inv_fact[i-1] = inv_fact[i] * i % kMod;
  auto c = [&](int n, int r){
  	return fact[n] * inv_fact[n-r] % kMod * inv_fact[r] % kMod;
  };
  long long m25 = 1;
  long long ans = 1;
  for (int i = 1; i <= K; ++i) {
  	m25 = m25 * 25 % kMod;
  	ans += c(N, i) % kMod * m25 % kMod;
  	if (ans > kMod) ans -= kMod;
  }
  cout << ans << '\n';
}


Measured memory_bytes: 35180
//
//  MAIN.cpp
//
//  Created by Sultan.
//  Copyright © 2017 Sultan. All rights reserved.
//

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <typeinfo>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define ll long long
#define ioi exit(0);

#define inf int(1e9)

#define f first
#define s second

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define pb push_back
#define ppb(x) pop_back(x)

#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x++)

using namespace std;

string s,s1="YAKI";

int main() {
	
	cin >> s;
	
	for(int i=0;i<4;i++){
		if(s[i]!=s1[i]){
			cout << "No" << endl;
			ioi
		}
	}
	
	cout << "Yes" << endl;
	
	ioi
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
    // 標準入力からデータを読み込む準備
        try (Scanner sc = new Scanner(System.in)) {
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];
            for (int i = 0; i < values.length; i++) {
                values[i] = i + 1;
            }
            for (int i = 0; i < n; i++) {
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0]) - 1;
                int b = Integer.parseInt(ab[1]) - 1;
                // aとbを使ってvaluesを操作しよう
                int num = values[a];
                values[a] = values[b];
                values[b] = num;
            }
            // valuesを出力しよう
            for(int i=0; i<values.length; i++){
                System.out.println(values[i]);
            }
        }
    }
}


Measured memory_bytes: 26152
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
using namespace std;

int n,m;

int a[111][111];
int c[511];
int g[11];
int main()
{
    int i,j;
    char d;
    cin>>n>>m;
    
    memset(c,0,sizeof(c));
    memset(g,0,sizeof(g));
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            cin>>d;
            c[d-'a']++;
        }
    }
    
    for(i=1;i<=(n+1)/2;i++)
    {
        for(j=1;j<=(m+1)/2;j++)
        {
            int tmp=1;
            if(i!=n+1-i)tmp*=2;
            if(j!=m+1-j)tmp*=2;
            
            g[tmp]++;
        }
    }
    
    //cout<<g[1]<<' '<<g[2]<<' '<<g[4]<<endl;
    
    for(i=4;i>=1;i--)
    {
        for(j=0;j<26;j++)
        {
            if(g[i]==0)break;
            
            if(c[j]>=i)
            {
                c[j]-=i;
                g[i]--;
                j--;
            }
        }
    }
    
    if(g[4]==0 && g[2]==0 && g[1]==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
edges = [LI() for _ in range(n-1)]
count = [0] * n

for i in range(n-1):
    edges[i].sort()
ans = 0
tmp = 0
for i in range(n):
    ans += (n - i) * (n - i + 1) // 2
for u, v in edges:
    ans -= u * (n - v + 1)
print(ans)

Measured memory_bytes: 101776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e12;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    int A[N];
    vi V(N,INF);
    rep(i,N) cin >> A[i];
    rep(i,N){
        *lower_bound(all(V),A[i])=A[i];
    }
    cout << lower_bound(all(V),INF)-V.begin() << endl;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}


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

    int i = 0;
    int j = N-1;
    int ans = 0;

    while(i < j ){

    while(i <= N-1){
        if(S[i] == 'W') break;
        i++;
    }

    while(j >= 0){
        if(S[j] == 'R') break;
        j--;
    }

    if(i < j){
        ans++;
        i++;
        j--;
    }
    
    }

    cout << ans << endl;

}



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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	int A[1000];
	cin >> N;
	rep(i, 0, N)
	{
		cin >> A[i];
	}

	sort(A, A + N);

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

	return 0;
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    
    int cnt = 0;
    
    for(int i = 1; i <= n; ++i){
        int temp = i;
        int digit = 0;
        while(temp > 0){
            temp /= 10;
            digit++;
        }
        if(digit % 2 != 0){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
#define Bit(n) (1LL << (n))
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  vector<pii> v;
  REP(i, N) {
    int a;
    cin >> a;
    v.EB(a, 0);
  }
  REP(i, N) {
    int b;
    cin >> b;
    v.EB(b, 1);
  }
  sort(ALL(v));

  int s = 0;
  int ans = 1;
  for (auto p : v) {
    if (p.second == 0) {
      if (s < 0) (ans *= -s) %= MOD;
      s++;
    } else {
      if (s > 0) (ans *= s) %= MOD;
      s--;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 6384
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]


# @lru_cache(None)
a,v=l()
b,u=l()
t=l()[0]
d=b-a
rel=v-u
if(rel<=0):
    print("NO")
else:
    T=abs(d)/rel
    if(T<=t):
        print("YES")
    else:
        print("NO")




Measured memory_bytes: 10644