akhauriyash/Code-Regression huggingface dataset:
class UnionFindTree:
    def __init__(self, size):
        self.parent = list(range(size))
        self.dist = [0]*size

    def find_root(self, x):
        if self.parent[x] == x:
            return x, 0
        else:
            self.parent[x], d = self.find_root(self.parent[x])
            self.dist[x] += d
            return self.parent[x], self.dist[x]

    def union(self, x, y, d):
        r1, d1 = self.find_root(x)
        r2, d2 = self.find_root(y)

        if r1 != r2:
            self.parent[r2] = r1
            self.dist[r2] = (d1 - d2) + d
        else:
            if (d2 - d1) != d:
                return False

        return True

def main():
    (N, M) = tuple(map(int, input().split(' ')))

    tree = UnionFindTree(N)

    for i in range(M):
        l, r, d = map(int, input().split(' '))

        if not tree.union(l-1, r-1, d):
            print('No')
            return

    print('Yes')

main()


Measured memory_bytes: 9844
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;         
#define f(var,start,end) for(ll var = start; var <end ; ++var)
#define rf(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define nl cout<<"\n"
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
	ll a,b;
	cin>>a>>b;
	cout<<a*b;
	nl;
}

Measured memory_bytes: 3636
import itertools
points = []
n, m, q = map(int, input().split())
for _ in range(q):
    points.append(list(map(int, input().split())))
ans = 0


li = list(itertools.combinations_with_replacement(range(1, m + 1), n))


for num in li:
    p = 0
    for point in points:
        if num[point[1] - 1] - num[point[0] - 1] == point[2]:
            p += point[3]
    ans = max(p, ans)


print(ans)

Measured memory_bytes: 84436
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = null;

		try {
			sc = new Scanner(System.in);
			while (sc.hasNext()) {
				int[] numList = new int[2];
				for (int i = 0; i < 2; i++) {
					numList[i] = sc.nextInt();
				}
				int numRank = ("" + (numList[0] + numList[1])).length();
				System.out.println(numRank);
			}

		}catch (Exception e) {
			System.out.println(e);
		} finally {
			if (sc != null) {
				try {
					sc.close();
				} catch (Exception e) {
					// TODO: handle exception
				}
			}
		}
	}

}

Measured memory_bytes: 26020
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        Console.WriteLine(Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).Take(2).Sum());
    }
}


Measured memory_bytes: 13396
N, Y = map(int, input().split())

for x in range(N+1):
  for y in range(N-x+1):
    z = N-x-y
    if 10000*x + 5000*y + 1000*z == Y and x+y+z == N:
      print(x, y, z)
      quit()

print("-1 -1 -1")

Measured memory_bytes: 3060
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def main():
    n = int(input())
    ans = 1
    for i in range(1,n+1):
        ans *= i
        ans %= MOD
    print(ans)
    


if __name__ == '__main__':
    main()


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

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589
#define MOD 1000000007

using namespace std;

template<typename T> T gcd(T a, T b){return (a % b)? gcd(b, a % b) : b;}
template<typename T> T lcm(T a, T b){return a * b / gcd(a, b);}

void solve_A(){
    char s;
    cin >> s;
    if(isupper(s)){
        cout << "A" << endl;
    } else cout << "a" << endl;
}

void solve_B(){
    int n, k;
    cin >> n >> k;
    int p[n];
    REP(i,n) cin >> p[i];

    sort(p, p+n);
    ll ans = 0;
    REP(i, k){
        ans += p[i];
    }
    cout <<ans << endl;
}

int main(void){
    solve_B();
    
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i <= (ll)(n); ++i)
#define MAX 500010
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;

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

	ll N;
	cin >> N;

	vector<ll> a(N);
	ll asum = 0;
	rep(i,N){
		cin >> a[i];
		asum += a[i];
	}

	ll ave = round((double)asum / N);
	//cout << ave << endl;

	rep(i,N){
		ans += abs(ave - a[i]) * abs(ave - a[i]); 
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
use v5.10;
use List::Util qw/max min/;

my ($a, $b, $c, $x, $y) = split(/[ \n]+/, <>);

# AB set = C * 2
$c *= 2;

for ($i = 0; $i <= 10 ** 5; $i++) {
  $p = $i * $c + max(0, $x - $i) * $a + max(0, $y - $i) * $b;
  push(@price, $p);
}

say min(@price);


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

using namespace std;

int main() {
    int N, L;
    cin >> N >> L;
    vector<string> strings(N);
    for(int i = 0; i < N; i++) {
        cin >> strings[i];
    }
    sort(strings.begin(), strings.end());
    for(string str: strings)
        cout << str;
    cout << endl;
    return 0;
}


Measured memory_bytes: 760
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <utility>
#define LL long long
#define INF (LL)(1LL<<60)
using namespace std;

int main(){
    LL H, W;
    cin >> H >> W;
    vector<string> tab(H);
    for(LL i=0; i<H; i++)cin >> tab[i];

    deque<pair<LL, pair<LL, LL>>> q;
    vector<vector<LL>> shortest(H, vector<LL>(W, INF));
    q.emplace_back(make_pair(0, make_pair(0, 0)));

    while(!q.empty()){
        auto l0=q.front().first, x=q.front().second.first, y=q.front().second.second;
        q.pop_front();
        if(tab[y][x] == '#' || l0 >= shortest[y][x])continue;
        shortest[y][x]=l0;
        if(x>0)q.emplace_back(make_pair(l0+1, make_pair(x-1, y)));
        if(x<W-1)q.emplace_back(make_pair(l0+1, make_pair(x+1, y)));
        if(y>0)q.emplace_back(make_pair(l0+1, make_pair(x, y-1)));
        if(y<H-1)q.emplace_back(make_pair(l0+1, make_pair(x, y+1)));
    }

    LL cnt=0;
    for(LL y=0; y<H; y++)
        for(LL x=0; x<W; x++)
            if(tab[y][x]=='.')
                cnt++;

    cout << (shortest[H-1][W-1]<INF ? cnt-shortest[H-1][W-1]-1 : -1) << endl;
    return 0;
}


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


int main() {
	int N, K;
	cin >> N >> K;
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		int num;
		cin >> num;
		ans += 2 * min(abs(0 - num), abs(K - num));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3604
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        long N = scanner.nextLong();
        long K = scanner.nextLong();
        long Q = scanner.nextLong();

        Map<Long, Long> players = new HashMap<>();

        for (long i = 0 ; i < Q ; i++) {
            long A = scanner.nextLong();
            players.put(A, players.getOrDefault(A, 0L) + 1);
        }

        for (long i = 1 ; i <= N ; i++) {
            long score =  K - (Q - players.getOrDefault(i, 0L));
            if (score > 0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}


Measured memory_bytes: 63812
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007 
#define ll long long 
#define N 100005
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define piii pair<int, pii>
#define print(x) cout << #x << "=" << x << "\t";
#define endl "\n"
#define newline cout << endl;

int n;
int k;
vector<int> v;
bool dp[N];

int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); 
    cin >> n >> k;
    v.resize(n);
    for(auto &u : v)
        cin >> u;
    for(int i=1;i<=k;i++)
        for(auto u : v)
            if (i - u >= 0 && dp[i - u] == false)
                dp[i] = true;
    cout << (dp[k] ? "First" : "Second");
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int L, R; cin >> L >> R;
    if(R - L + 1 >= 2019){
        Out(0);
    }else{
        int ans = INF;
        FOR(i, L, R) FOR(j, i + 1, R + 1) Min(ans, (i * j) % 2019);
        Out(ans);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

int main(){
    int n;
    int a[100000];
    cin>>n;
    rep(i,n) cin>>a[i];

    int ans=0;
    rep(i,n) ans|=(a[i]&1);

    if(ans){
        cout<<"first"<<endl;
    }else{
        cout<<"second"<<endl;
    }
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  ll n, m;
  cin >> n >> m;
  vl a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  // sort(a.rbegin(), a.rend());
  dump(n, m, a);
  ll sum = 0;
  auto calc = [&](ll x) {
    ll num = 0;
    sum = 0;
    int j = n - 1;
    rep(i, n) {
      while (j >= 0 && a[i] + a[j] >= x) {
        sum += a[j] * (n - i);
        j--;
      }
      sum += (n - (j + 1)) * a[i];
      num += n - (j + 1);
      dump(x, i, j, num, sum);
    }
    return num;
  };
  ll ok = 0;
  ll ng = 100000 * 2 + 1;
  while(abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (m <= calc(mid))
      ok = mid;
    else
      ng = mid;
    dump(ng, ok);
  }
  ll x = calc(ok);
  ll s = sum;
  ll ans = sum - (x - m) * ok;
  dump(ans);
  dump(ng, ok, sum);
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] l=sc.next().toCharArray();
        for(char c:l) {
            System.out.print((char)(c<'D'?c+23:c-3));
        }
        System.out.println();
    }
}


Measured memory_bytes: 26584
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, b;
	cin >> a >> b;
	
	if (a > 0) {
		cout << "Positive";
	}
	else if (a == 0 || b == 0) {
		cout << "Zero";
	}
	else if (a < 0 && 0 < b) {
		cout << "Zero";
	}
	else {
		if ((b - a + 1) % 2 == 0) {
			cout << "Positive";
		}
		else {
			cout << "Negative";
		}
	}
	
	return 0;
}

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

int main(){
  int N;
  int i;
  int k;
  int j;
  cin >> N;
  vector<int> a(N); 
  for(i = 0;i < N;i++){
    cin >> a.at(i);
  }
  for(j = 0;j > -1;j++){
    for(k = 0;k < N;k++){
      if(a.at(k) % 2 == 1){
        break;
      }
    }
    if(k == N){
      for(i = 0;i < N;i++){
        a.at(i) /= 2;
      }
    }else{
      break;
    }
  }
  cout << j << endl;
}
  

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[])
{
	int day;
	scanf("%d",&day);
	printf("Christmas");
	if(day == 24)	printf(" Eve\n");
	else if(day == 23)	printf(" Eve Eve\n");
	else if(day == 22)	printf(" Eve Eve Eve\n");
	return 0;
}


Measured memory_bytes: 128
#include <iostream> 
using namespace std;
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
int main()
{
	
	int k ,x;
	cin>>k>>x;
	vector<int>res;
	for(int i = x-k+1;i<=x+k-1;i++)
	{
		res.push_back(i);
	}
	
	bool tf = false;
	for(auto &x :res)
	{
		if(tf)
		cout<<" ";
		cout<<x;
		tf=true;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int a, b; scanf("%d%d", &a, &b);

	for(int i = 1; i < 10000; i++) {
		if(i * 8 / 100 != a or i * 10 / 100 != b) continue;
		printf("%d\n", i);
		return 0;
	}
	printf("-1\n");
	return 0;
}


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

int main() {
    int n;
    auto f = [](int n) { return n * (n + 1) / 2; };
    vector<int> cnt(500555, 0);
    for (int i = 1; i <= 1000; i++) {
        for (int len = 2; i + len <= 1000; len++) {
            cnt[f(i + len - 1) - f(i - 1)]++;
        }
    }
    while (cin >> n, n) {
        cout << cnt[n] << endl;
    }
    return 0;
}


Measured memory_bytes: 4468
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string S;
  cin >> S;
  long ans = 0;
  if (S[0] == '1') ans++;
  if (S[1] == '1') ans++;
  if (S[2] == '1') ans++;
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

using namespace std;

int n, x, m, l[108], r[108], s[108];


int p(int x, int n){
	if(n == 0)return 1;
	return x * p(x, n - 1);
}

bool check(int p){
	vector<int> res;
	bool ss = true;
	for(int i = 0;i < n;i++){
		res.push_back(p%x);
		p/=x;
		if(res[i] != 2 *i)ss = false;
	}
	int ans = 0;
	for(int i = 0;i < m;i++){
		ans = 0;
		for(int j = l[i];j <= r[i];j++){
			ans += res[j-1];
		}
		if(ans != s[i])return false;
	}
	for(int i = 0;i < n;i++){
		if(i)cout << " ";
		cout << res[i];
	}   cout << endl;
	return true;
}

int main(){
	cin >> n >> x >> m;
	x++;
	for(int i = 0;i < m;i++){
		cin >> l[i] >> r[i] >> s[i];
	}
	
	for(int i = p(x, n) - 1;i >= 0;i--){
		if(check(i)){
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 1220
from collections import defaultdict,deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp():
    '''
    一つの整数
    '''
    return int(input())
def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


a, b, n = inpl()
x=min(b-1,n)
ans = a * x // b
print(ans)

Measured memory_bytes: 69112
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n,l;
    cin>>n>>l;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    sort(s,s+n);
    for(int i=0;i<n;i++){
        cout<<s[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a, b;
    cin >> a >> b;
    if (a[0] == b[2] && b[0] == a[2] && a[1] == b[1])
        cout << "YES";
    else
        cout << "NO";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

const ll MN = 200010;
vi f(MN, 0);

struct UnionFind{
    // par[i] parent. if i == par[i] i is root
    vector<ll> par;
    // sizes[i] sizeof tree i if i is root
    vector<ll> sizes;

    UnionFind(ll n) : par(n), sizes(n, 1){
        // init: all node is root i
        rep(i, n) par[i] = i;
    }

    // find root of x
    ll find(ll x){
        if (x == par[x])
            return x;
        return par[x] = find(par[x]); // recursive, editing root
    }

    // merge x, y
    void unite(ll x, ll y){
        // root
        x = find(x);
        y = find(y);

        // do not merge if same tree
        if (x == y)
            return;

        // force size x > y
        if (sizes[x] < sizes[y])
            swap(x, y);

        // unite: x is parent of y
        par[y] = x;
        sizes[x] += sizes[y];
    }

    // x, y same root
    bool same(ll x, ll y){
        return find(x) == find(y);
    }

    // size of tree containing x
    ll size(ll x){
        return sizes[find(x)];
    }
};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    vll b(n+1);
    rep(i, n){
        cin >> a[i];
        b[a[i]] = i+1;
    }
    UnionFind uf(n+1);
    vll cnt(n+1, 0);
    for(int i = n; i >= 1; i--){
        ll j = b[i];
        f[j] = 1;
        if(i < n){
            cnt[i] = cnt[i+1];
        }
        if(f[j+1]){
            cnt[i] -= uf.size(j+1)*(uf.size(j+1)+1)/2;
            uf.unite(j, j+1);
        }
        if(f[j-1]){
            cnt[i] -= uf.size(j-1)*(uf.size(j-1)+1)/2;
            uf.unite(j-1, j);
        }
        cnt[i] += uf.size(j)*(uf.size(j)+1)/2;
    }
    dump(cnt);
    repr(i, 1, n){
        cnt[i] -= cnt[i+1];
    }
    dump(cnt);
    ll ans = 0;
    repr(i, 1, n+1){
        ans += cnt[i]*i;
    }
    cout << ans << endl;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	
	for(x=0;x<=N;x+=4) {
		if((N-x)%7==0) return _P("Yes\n");
	}
	_P("No\n");
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	static int[][] c;

	static boolean[] u;

	static void perm(int depth, int sum) {
		c[depth][sum]++;
		for (int i = 0; i < 10; i++) {
			if (u[i])
				continue;
			u[i] = true;
			perm(depth + 1, sum + (depth + 1) * i);
			u[i] = false;
		}
	}

	public static void main(String[] args) throws Exception {
		c = new int[11][331];
		u = new boolean[10];
		Arrays.fill(u, false);
		for (int i = 0; i < 11; i++)
			Arrays.fill(c[i], 0);
		perm(0, 0);
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		String str;
		while ((str = bf.readLine()) != null) {
			String p[] = str.split(" ");
			if(p.length!=2)break;
			int n = Integer.parseInt(p[0]);
			int s = Integer.parseInt(p[1]);
			System.out.println((n<=10&&s<=330)?c[n][s]:0);
		}
	}
}

Measured memory_bytes: 9444
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>

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

using namespace std;
typedef long long ll;

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

    string S, T;
    cin >> S >> T;

    int size = S.size();
    int res = 0;
    for (int i = 0; i < size; i++)
    {
        if (S[i] != T[i])
            res++;
    }

    cout << res << endl;
}


Measured memory_bytes: 3428
N = gets.to_i

X = (1..N).map { |i| gets.chomp.split.map(&:to_i) }

x = []
x << [0, 0, 0]

N.times do |i|
  x << [0, 0, 0]

  3.times do |j|
    3.times do |k|
      next if j == k
      c = x[-2][j] + X[i][k]
      x[-1][k] = c if c > x[-1][k]
    end
  end
end

print x[N].max


Measured memory_bytes: 11900
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<string>
#include<set>
#include<cstring>
#include<climits>
#include<queue>
using namespace std;

static int A, B, C, X;

int main()
{
	while (scanf("%d%d%d%d", &A, &B, &C, &X) != EOF)
	{
		int ans = 0;
		for (int i = 0; i <= A; i++)
		{
			for (int j = 0; j <= B; j++)
			{
				for (int k = 0; k <= C; k++)
				{
					if (i * 500 + j * 100 + k * 50 == X)++ans;
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
const ll mod = 998244353ll;
int n, m;
vector<vi> g, gt;
vi p, h;
set<int> par;
void dfs(int v, ll maxh) {
	par.insert(v);
	int upd = 0;
	for(auto i : g[v]) {
		if(maxh < h[i]) upd = 1;
		if(h[i]) maxh = max(maxh, h[i]);
	}
	for(auto i : gt[v]) {
		if(h[i]&&h[i]+1!=h[v]) maxh = max(maxh, h[i]);
	}
	for(auto i : g[v]) {
		if(!h[i]) continue;
		if(upd&&h[i] == maxh&& par.count(i)) {
			vi ans;
			while(v != i)
				ans.pb(v), v = p[v];
			ans.pb(i);
			cout << ans.size() << "\n";
			for(auto i : ans) cout << i << "\n";
			exit(0);
		}
	}
	for(auto i : g[v]) {
		if(h[i]) continue;
		h[i] = h[v] + 1;
		p[i] = v;
		dfs(i, maxh);
	}
	par.erase(v);
}

int main() {
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	cin >> n >> m;
	g.resize(n+1);
	gt.resize(n+1);
	for(int f, t, i = 0; i < m; i++) {
		cin >> f >> t;
		g[f].pb(t);
		gt[t].pb(f);
	}
	for(int i = 1; i <= n; i++) {
		p.assign(n+1, 0);
		h.assign(n+1, 0);
		h[i] = 1;
		dfs(i, 0);
	}
	cout << -1;
}


Measured memory_bytes: 512
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var XYZK = Sarray();
            var X = XYZK[0];
            var Y = XYZK[1];
            var Z = XYZK[2];
            var K = XYZK[3];
            var Ai = Sarray();
            var Bi = Sarray();
            var Ci = Sarray();
            var ABi = new long[X * Y];
            var cnt = 0;
            foreach (var a in Ai)
                foreach (var b in Bi)
                    ABi[cnt++] = a + b;
            Array.Sort(ABi);Array.Reverse(ABi);
            Array.Sort(Ci);Array.Reverse(Ci);
            var abNum = Min(ABi.Length, K);
            var cNum = Min(Ci.Length, K);
            var ABCi = new long[abNum * cNum];
            cnt = 0;
            foreach (var ab in ABi.Take((int)abNum))
                foreach (var c in Ci.Take((int)cNum))
                    ABCi[cnt++] = ab + c;
            Array.Sort(ABCi);Array.Reverse(ABCi);
            foreach (var abc in ABCi.Take((int)K))
                WriteLine(abc);
        }
    }
}

Measured memory_bytes: 45024
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define INPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in"
#define OUTPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

void solve()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    //freopen(INPUT, "r", stdin);freopen(OUTPUT, "w", stdout);
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 256
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from itertools import combinations_with_replacement

n, m, q = na()
abcd = nan(q)

ans = 0
for p in combinations_with_replacement(range(1, m + 1), n):
    t = 0
    for i in range(q):
        a, b, c, d = abcd[i]
        a -= 1
        b -= 1
        if p[b] - p[a] == c:
            t += d
    ans = max(ans, t)

print(ans)

Measured memory_bytes: 9288
#include <stdio.h>

int main(void){
	int i,n;
	double s,x[22][2];

	for(n=0;scanf("%lf,%lf",&x[n][0],&x[n][1])!=EOF;n++);

	for(i=s=0;i<n;i++){
		if(i == n - 1){
			s += x[i][0] * x[0][1] - x[i][1] * x[0][0];
		}
		else{
			s += x[i][0] * x[i+1][1] - x[i][1] * x[i+1][0];
		}
	}
	if(s < 0) s = -s;
	printf("%.6lf\n",s/2);

	return 0;
}


Measured memory_bytes: 2028
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    /*
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    set<char> _ans(s[0].begin(), s[0].end());
    rep(i, n) {
        set<char> cur(s[i].begin(), s[i].end());
        string str(100, 'A');
        auto it = set_intersection(all(_ans), all(cur), str.begin());
        str.resize(it - str.begin());
        _ans = set<char>(str.begin(), str.end());
    }
    */
   vector<map<char, ll>> s(n);
   rep(i, n) {
       string _s; cin >> _s;
       for (auto elem : _s) {
           s[i][elem]++;
       }
   }

    map<char, ll> citems = s[0];
   for (size_t i = 1; i < s.size(); i++)
   {
       map<char, ll> _citems;
       for (auto elem : s[i]) {
           if (citems.find(elem.first) != citems.end()) {
               _citems[elem.first] = min(citems[elem.first], elem.second);
           }
       }
       citems = _citems;
   }
   
   for (auto elem : citems) {
       cout << string(elem.second, elem.first);
   }
   cout << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

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

    int **line = new int*[n];
    for(int i = 0; i< n; i++)
    {
        line[i] = new int[m];
    }
    int *b = new int[m];

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

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


    for(int i=0;i<n;i++)
    {
        int sum = 0;
        for(int j=0;j<m;j++)
        {
            sum += line[i][j] * b[j];
        }
        cout << sum << "\n";
    }

    for(int i=0;i<n;i++)
    {
        delete[] line[i];
    }
    delete[] line;
    delete[] b;

    return 0;
}


Measured memory_bytes: 3140
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
char m(char x, char y){
    if(x=='T' && y=='F') return 'F';
    else return 'T';
}
int main()
{
    int n; cin>>n;
    char c[100001];
    for(int i=0; i<n; i++) cin>>c[i];
    char ans=m(c[0], c[1]);
    for(int i=2; i<n; i++){
        ans=m(ans, c[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll a;
    cin >> a;
    cout << a * a << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;

set< string> setik;

int main ()  {
    int n;
    cin.tie(0)->sync_with_stdio(false);
    cin >> n;
    for (int i = 1 ; i <= n ; ++ i) {
        string s;
        cin >> s;
        setik.insert(s);
    }

    cout << (int)setik.size();
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 19288
#include <iostream>
#include <algorithm>
using namespace std;
int gcd(int x, int y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
int main() {
	int H, W, C;
	cin >> H >> W >> C;
	int g = gcd(H, W);
	cout << (H / g) * (W / g) * C << endl;
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

int main(int argc, char const* argv[])
{
    string s;
    cin >> s;

    map<char,int> mp;
    bool truth = true;
    for (int i = 0; i < s.length(); i++) {
        mp[s[i]]++;
        if (mp[s[i]] > 1) {
            truth = false;
            cout << "no" << endl;
            break;
        }
    }

    if (truth) {
        cout << "yes" << endl;
    }
    return 0;
}


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

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

Measured memory_bytes: 3096
package main

// Insertion Sort

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	s := make([]int, n)
	for i := range s {
		s[i] = nextInt()
	}
	for i, v := range s {
		for j := i - 1; 0 <= j && v < s[j]; j-- {
			s[j+1] = s[j]
			s[j] = v
		}
		fmt.Println(convertIntToString(s, " "))
	}
}

func convertIntToString(s []int, d string) string {
	b := make([]string, len(s))
	for i, v := range s {
		b[i] = strconv.Itoa(v)
	}

	return strings.Join(b, d)
}

// =================================
// I/O util
// =================================

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

// =================================



Measured memory_bytes: 1412
#include <iostream>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
int N;
ll A[16][16], dp[1<<16], dp2[1<<16];
constexpr ll INF = 1e18;
ll dfs(int bit) {
  if (__builtin_popcount(bit) == N) return 0;
  if (dp[bit] != INF) return dp[bit];

  const int S = ((1 << N)-1) ^ bit;
  ll ans = 0;
  for (int T = S;; T = (T-1) & S) {
    if (T == 0) break;
    if (dp2[T] != INF) {
      ans = max(ans, dfs(bit | T) + dp2[T]);
      continue;
    }
    ll tmp = 0;
    rep(i, N) rep(j, N) {
      if (i >= j)
        continue;
      if ((T & (1 << i)) && (T & (1 << j)))
        tmp += A[i][j];
    }
    dp2[T] = tmp;
    ans = max(ans, dfs(bit | T) + tmp);
  }
  return dp[bit] = ans;
}

int main() {
  cin >> N;
  rep(i, N) rep(j, N)
    cin >> A[i][j];
  rep(i, 1  << N)
    dp[i] = dp2[i] = INF;
  cout << dfs(0) << endl;

  return 0;
}


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

int main(){
    ll n,d; cin >> n >> d;
    vector<ll> X(n),Y(n);
    for(int i=0; i<n; i++) cin >> X[i] >> Y[i];

    ll ans = 0;
    for(int i=0; i<n; i++){
        if(pow(d,2) >= pow(X[i],2)+pow(Y[i],2)){
            ans++;
        }
    }

    cout << ans << endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<int> s;
    for (int i=0;i<4;++i){
        int N; cin >> N; s.emplace(N);
    }
    int ok=1;
    vector<int> v={1,9,7,4};
    for (int i=0;i<4;++i) if (!s.count(v[i])) ok=0;
    cout << (ok?"YES":"NO") << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define INF 1000000000000

using namespace std;

int main()
{
   FAST/**/
   ll n,m;
   cin>>n>>m;
   
   string s;
   cin>>s;
   
   ll dp[n+1+m+1];
   for(ll i=0;i<n+m+2;i++)
        dp[i] = INF;
   
   multiset<pair<ll,ll>> ms;
   ll next[n+m+2];
   for(ll i=0;i<n+m+2;i++)
        next[i] = i;   
   
   dp[n] = 0;
   
   for(ll i=1;i<m;i++)        
       ms.insert(mp(dp[n+i],i));
   
   ms.insert(mp(dp[n],n));
   
   for(ll i=n-1;i>-1;i--)
   {
       ms.erase(mp(dp[i+m+1],i+m+1));
       if(s[i] == '1')
       {
           ms.insert(mp(dp[i],i));
           continue;
       }
       dp[i] = min(dp[i], ms.begin()->first + 1);
       next[i] = min(ms.begin()->second,n);
       ms.insert(mp(dp[i],i));
       
   }
   
   if(dp[0] == INF)
   {
       cout<<-1;
       return 0;
   }
   vector<ll> hold;
   ll curr = 0;
   while(curr<n)
   {
       hold.pb(curr);
       curr = next[curr];
   }
   
   hold.pb(n);
   for(ll i=1;i<hold.size();i++)
        cout<<hold[i]-hold[i-1]<<" ";
        
   
   return 0;
}  
   


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

int main () {
  int N;
  cin >> N;
  
  if (N == 1){
    cout << 1 << endl;
    return 0;
  }
  
  vector<int>A(N);
  vector<vector<vector<int>>> data(N, vector<vector<int>>(N, vector<int>(2)));
 
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    for (int j = 0; j < A.at(i); j++) {
      for (int k = 0; k < 2; k++) {
        cin >> data.at(i).at(j).at(k);
      }
    }
  }
 
  int Max = 0;

  // すべての選び方を試して、総和がKになるものがあるかを調べる
  for (int tmp = 0; tmp < (1 << 15); tmp++) {
    bitset<15> s(tmp);  // 最大20個なので20ビットのビット列として扱う
    
    if (N < 15 && s.test(N)) {
      break;
    }
    // ビット列の1のビットに対応する整数を選んだとみなして総和を求める
    int count = 0;
    int honest = 0;
    
    for (int i = 0; i < N; i++) {
      if (s.test(i)) {
        honest++;
        for (int j = 0; j < A.at(i); j++) {
          int B = data.at(i).at(j).at(0) - 1;
          if (s.test(B)){
            if (data.at(i).at(j).at(1) == 0){
              count++;
            }
          }
          else {
            if (data.at(i).at(j).at(1) == 1){
              count++;
            }
          } 
        }
      }
    }
    if (count == 0){
      if (honest > Max){
        Max = honest;
      }
    }
  }
  
  cout << Max << endl;
}



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

int main()
{
    string S;
    cin >> S;
    int ans;
    if (S == "SUN") ans = 7;
    if (S == "MON") ans = 6;
    if (S == "TUE") ans = 5;
    if (S == "WED") ans = 4;
    if (S == "THU") ans = 3;
    if (S == "FRI") ans = 2;
    if (S == "SAT") ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int a[200];
int b[200];


signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int2(n, m);
    rep(i, n + n)a[i] = i;

    for(;m--;){
      int(k);
      if(k == 0){
        rep(i, n){
          b[i * 2] = a[i];
          b[i * 2 + 1] = a[n + i];
        }
      }else{
        rep(i, k)b[n + n - k + i] = a[i];
        for(;i < n + n;++i)b[i - k] = a[i];
      }
      rep(i, n + n)a[i] = b[i];
    }
    rep(i, n + n)pri(a[i] + 1);

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3232
#include <iostream>
using namespace std;
int main (void) {
    int N;

    cin >> N;

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        if (A % 2 == 1) {
            cnt++;
        }
    }

    if (cnt % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>
#include<queue>
#include<set>


#define MOD 1000000007
#define DEBUG 0


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}



bool comp(const pair<long long int, vector<int>> a, const pair<long long int, vector<int>> b) {
	if (a.first != b.first) {
		return a.first < b.first;
	}
	else {
		return a.second < b.second;
	}

}





int solve(string str) {

	if (str == "") {
		return solve("3") + solve("5") + solve("7");
	}
	
	long long int num = stoi(str);

	if (num >= 1e9)return 0;
	
	



}
	





int main(){

	int n;
	cin >> n;

	string str;
	cin >> str;

	for (int i = 0; i < str.size(); i++) {
		int wk = str[i];
		wk += n;
		if (wk > 'Z') {
			wk -= 26;
		}
		str[i] = wk;
	}

	cout << str << endl;


	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    System.out.println(a + b >= c ? "Yes" : "No");
  }

}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

int main() {
    string s;
    int count = 0;
    cin >> s;

    for (int i = 0; i < 3; i++) {
        if (s[i] == '1') count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
a = 0
b = 0
c = 0
for i in s:
    if i == "a":
        a += 1
    if i == "b":
        b += 1
    if i == "c":
        c += 1

if max(a,b,c)-min(a,b,c) <= 1:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 73312
#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 i=0;i<N;i++){cin >> x[i];}
    for(int i=0;i<M;i++){cin >> y[i];}
    string ans="No War";
    int a=x[0];
    for(int i=0;i<N;i++){a=max(a,x[i]);}
    int b=y[0];
    for(int i=0;i<M;i++){b=min(b,y[i]);}
    if(a>=b){ans="War";}
    if(a>=Y){ans="War";}
    if(b<=X){ans="War";}
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int x,a,b,A,B;

    scanf("%d %d %d",&x,&a,&b);
    A=x-a;
    B=x-b;
    if(A*A>B*B){
        printf("B");
    }
    else{
        printf("A");
    }

    return 0;
}

Measured memory_bytes: 128