akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

int N, A[1<<20], maxm = 0;

bool comparator(const pair<int, int> &a, const pair<int, int> &b) {
  if(a.first != b.first) {
    return (a.first < b.first);
  }

  return (a.second > b.second);
}

int BIT[1<<20];

int query(int idx) {
  int ans = 0;
  while(idx > 0) {
    ans += BIT[idx];
    idx -= (idx & -idx);
  }
  return ans;
}

void update(int idx) {
  while(idx <= (N+1)) {
    BIT[idx] += 1;
    idx += (idx & -idx);
  }
}

long long getInversionCount(vector<int> &B) {
  vector<pair<int, int> > C(B.size());
  for(int i = 0;i < B.size();i++) {
    C[i] = make_pair(B[i], i+1);
  }

  sort(C.begin(), C.end(), comparator);

  for(int i = 1;i <= C.size();i++) BIT[i] = 0;

  long long ans = 0;
  for(int i = 0;i < C.size();i++) {
    ans += query(C[i].second);
    update(C[i].second);
  }

  return ans;
}

long long LessThanEqual(int x) {
  vector<int> B(N+1, 0);

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

  // Find number of (i,j) such that Bi < Bj
  // for(auto &x : B) cout << x << " ";cout << endl;
  return getInversionCount(B);
}

int main() {
//  freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> N;
  for(int i = 0;i < N;i++) {
    cin >> A[i];
    maxm = max(A[i], maxm);
  }

  int lo = 1, hi = maxm, mid;
  while (lo != hi) {
    mid = (lo + hi) / 2;
    //cout << "mid:" << mid << endl;
    long long tp = LessThanEqual(mid);
    //cout << "tp:" << tp << endl;

    if(tp > N*1LL*(N+1)/4) {
      hi = mid;
    } else {
      lo = mid + 1;
    }
  }

  cout << lo << endl;

  return 0;
}


Measured memory_bytes: 3856
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

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

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

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

    vector<long long> diff(m - 1);
    for (int i = 0; i < m - 1; i++) {
        diff[i] = abs(x[i] - x[i + 1]);
    }

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

    long long cost = 0;
    for (int i = 0; i < m - n; i++) {
        cost += diff[i];
    }

    cout << cost << endl;
}


Measured memory_bytes: 1408
#include<stdio.h>

int main(void){
  int x;
  scanf("%d", &x);
  if(x<600){
    printf("8");
  }else if(x<800){
    printf("7");
  }else if(x<1000){
    printf("6");
  }else if(x<1200){
    printf("5");
  }else if(x<1400){
    printf("4");
  }else if(x<1600){
    printf("3");
  }else if(x<1800){
    printf("2");
  }else{
    printf("1");
  }
  return 0;
}

Measured memory_bytes: 1660
A = [list(map(int, s.split())) for s in open(0)][0]
x, y = A[0], A[1]
if y > x:
    l, s = y, x
else:
    l, s = x, y
while l % s >  0:
    m = l % s 
    l = s 
    s = m
print(s)


Measured memory_bytes: 5608
#include <iostream>
using namespace std;
int a[22], b[210];
int n, q;
// 选择第i个元素后面的元素, 能组成和为m 
bool solve(int i, int m)
{
	if(m == 0)	return true;
	if(i >= n)	return false;
	
	return solve(i + 1, m) || solve(i + 1, m - a[i]);
}
int main()
{
	cin >> n;
	for(int i = 0; i < n; ++ i)
		cin >> a[i];
	cin >> q;
	for(int i = 0; i < q; ++ i)
	{
		cin >> b[i];
		if(solve(0, b[i]))	cout << "yes" << endl;
		else	cout << "no" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3116
n, m = map(int, input().split())

c = [0] * m
for i in range(n):
    l = list(map(int, input().split()))
    k = l[0]
    for j in range(k):
        c[l[1+j]-1] += 1

ans = 0
for i in range(m):
    if c[i] == n:
        ans += 1

print(ans) 

Measured memory_bytes: 3060
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextInt()
    val X = input.nextInt()
    val T = input.nextInt()
    val unit = N / X + if (N % X != 0) 1 else 0
    
    println (unit * T)
  }  
}

Measured memory_bytes: 36416
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		while (sc.hasNextLine()) {
			String[] nico = sc.nextLine().split(" ");
			
			BigDecimal dxab = new BigDecimal(nico[0]).subtract(new BigDecimal(nico[2]));
			BigDecimal dyab = new BigDecimal(nico[1]).subtract(new BigDecimal(nico[3]));
			BigDecimal dxcd = new BigDecimal(nico[4]).subtract(new BigDecimal(nico[6]));
			BigDecimal dycd = new BigDecimal(nico[5]).subtract(new BigDecimal(nico[7]));
			
			if ((dxab.multiply(dxcd).add(dyab.multiply(dycd))).doubleValue() == 0.0) System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 26480
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1
struct Node { int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u) {
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " <<  D[u] << ", ";

  if(T[u].p == NIL) cout << "root, ";
  else if(T[u].l == NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for ( i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

int rec(int u, int p) {
  D[u] = p;
  if(T[u].r != NIL)rec(T[u].r, p);
  if(T[u].l != NIL) rec(T[u].l, p + 1);
  return 0;
}

int main()  {
  int i, j, d, v, c, l, r;
  cin >> n;
  for(i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i = 0; i < n; i++) {
    cin >> v >> d;
    for(j = 0; j < d; j++) {
      cin >> c;
      if(j == 0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i = 0; i < n; i++) {
    if(T[i].p == NIL) r = i;
  }

  rec(r, 0);

  for(i = 0; i < n; i++) print(i);

  return 0;
}



Measured memory_bytes: 7696
#include <stdio.h>

int main(){
	int a,i,b[3];
	scanf("%d",&a);
	for(i = 0;i < 3;i++){
	b[i] = a % 10;
	if(b[i] == 1)
		b[i] = 9;
	else if(b[i] == 9)
		b[i] = 1;
	a = a / 10;
	}
	printf("%d%d%d",b[2],b[1],b[0]);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		scanner.next();
		int result = 1;
		char[] array = scanner.next().toCharArray();
		scanner.close();
		for (int i = 1; i < array.length; i++) {
			if(array[i - 1] != array[i]) ++result;
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 25684
#include<stdio.h>
#include<string.h>

int main(void){
	char w[11], t[1000];
	int cnt = 0, i, len;
	
	scanf("%s\n", w);
	do{
		scanf("%s\n", t);
		if(strncmp(t, "END_OF_TEXT", 11) == 0){
			break;
		}
		len = strlen(t);
		for(i = 0; i < len; i++){
			if('A' <= t[i] && t[i] <= 'Z'){
				t[i] += 32;
			}
		}
		if(strncmp(t, w, 11) == 0){
			cnt++;
		}
	}while(1);
	printf("%d\n", cnt);
	
	return 0;
}



Measured memory_bytes: 2064
n, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
if a[0] > x:
    ans += a[0] - x
    a[0] = x
for i in range(n-1):
    if a[i] + a[i+1] > x:
        ans += a[i] + a[i+1] - x
        a[i+1] -= a[i] + a[i+1] - x
print(ans)

Measured memory_bytes: 14252
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int h = scanner.nextInt();
        int w = scanner.nextInt();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        for (int i = 0; i < h - b; ++i) {
            for (int j = 0; j < w - a; ++j)
                writer.print(1);
            for (int j = w - a; j < w; ++j)
                writer.print(0);
            writer.println();
        }
        for (int i = h - b; i < h; ++i) {
            for (int j = 0; j < w - a; ++j)
                writer.print(0);
            for (int j = w - a; j < w; ++j)
                writer.print(1);
            writer.println();
        }

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 43868
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
int kind[200010];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k; cin >> n >> k;
	VE a(n); rep(i, n)cin >> a[i];
	int cnt = 0;
	rep(i, 200010)kind[i] = INF;
	rep(i, n) {
		if (kind[a[i]] == INF) {
			kind[a[i]] = 0;
			cnt++;
		}
		kind[a[i]]++;
	}
	sort(kind, kind + 200010);
	int ans = 0;
	rep(i, cnt - k) {
		ans += kind[i];
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;


int main() {

    int N;
    cin >> N;
    vector<pair<int,int>> vec;

    for(int i = 0 ; i < N; ++i)
    {
        int n;
        cin >> n;
        vec.push_back({n,i});
    }

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

    for(int i = 0 ; i < N; ++i)
    {
        cout << vec[i].second+1 << " ";
    }

    return 0;
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;
const int MOD = 1000000007;

struct Combination{
  vector<int> fact; //　fact[i] = iの階乗
  Combination(int n) : fact(n+1){
    fact[0] = fact[1] = 1;
    for(int i = 2; i <= n; i++){
      fact[i] = fact[i-1] * i % MOD;
    }
  }

  int nCr(int n, int r){ // nCr = n!/r!(n-r)!
    if(n < r) return 0;
    return fact[n] * inv(fact[r]*fact[n-r]%MOD) % MOD;
  }

  int inv(int n, int p = MOD-2){ // a/n ≡ a*n^(p-2) nとpは互いに素
    int r = 1;
    for(; p > 0; p >>= 1){
      if(p & 1LL) r = r * n % MOD;
      n = n * n % MOD;
    }
    return r; // r = n^p % MOD
  }
};

signed main(){

  int k; cin >> k;
  string s; cin >> s;

  Combination c(2e6);
  int n = s.size(), ans = 0;
  for(int i = 0; i <= k; i++){
    // **o*o*****o*****
    // <  n-1  ><1>
    ans = (ans + c.nCr(n-1+i, n-1) * c.inv(25, i) % MOD * c.inv(26, k-i)) % MOD;
  }
  cout << ans << endl;

  return 0;
}

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

// #define int long long
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define endl "\n"
#define ends " "
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
#define debugV(v) cerr << #v << ": [ "; for(int __ = 0; __ < v.size(); __++) cerr << v[__] << ((__ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugVP(v) cerr << #v << ": [ "; for(int ___ = 0; ___ < v.size(); ___++) cerr << '{' << v[___].first << ", " << v[___].second << '}' << ((___ != v.size() - 1) ? ", " : ends); cerr << ']' << endl
#define debugA(a, n) cerr << #a << ": [ "; for(int ____ = 0; ____ < n; ____++) cerr << a[____] << ((____ != n - 1) ? ", " : ends); cerr << ']' << endl
#define print(args...) fprintf (stderr, args)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 1e9, MOD = INF + 7 /* INF - 1755647 */;

/////////////////////////////////////////////////////////////////////

const int N = 3e5 + 20;

int32_t main() {

    sync;

    int a, b; cin >> a >> b;
    cout << max(max(a + a - 1, b + b - 1), a + b) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <cmath>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9+7;


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int k,t;
	cin >>k >>t;
	VI a(t);
	rep(i,t) cin >>a[i];
	sort(all(a));
	int mx=a.back();
	rep(i,t-1){
		mx -=a[i];
	}
	cout << (mx<2? 0: mx-1) <<endl;
	return 0;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


int main(){
    string s;
    cin >>s;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i]==',')s[i]=' ';
    }
    cout <<s<<endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn.{readLine,readInt}
import scala.math.pow

object Main {
  val N = 1000000007

  def multi(m:Long, n:Long) = { ( (m%N) * (n%N) ) % N }

  def pow(m:Long, n:Long, b1:Long, b2:Long, b3:Long):Long = {
    n match {
      case 0 => 1
      case 1 => multi(b1,b3)
      case _ =>
        val c = b2 match {
          case 1 => m % N
          case _ => multi(b2,b2)
        }
        pow(m, n/2, multi(b1,b1), c, (if (n%2==0) 1 else c) * (b3 % N))
    }
  }

  def main(args: Array[String]) = {
    val l = readLine().split(" ").map(_.toLong)
    val (m,n) = (l(0),l(1))
    println(pow(m,n,m,1,1))
  }
}

Measured memory_bytes: 43868
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  cout << n*n*n << "\n";
  return 0;
}


Measured memory_bytes: 256
import math
MOD = 10 ** 9 + 7

fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]

def init(n):
    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        factinv.append((factinv[-1] * inv[-1]) % MOD)

def nPk(n, k):
    return fact[n] * factinv[n - k] % MOD

def nCk(n, k):
    return fact[n] * factinv[n - k] * factinv[k] % MOD

N, M = map(int, input().split())
init(M)
ans = 0
for k in range(N + 1):
    if k % 2 == 0:
        ans += nCk(N, k) * nPk(M - k, N - k)
    else:
        ans -= nCk(N, k) * nPk(M - k, N - k)
    ans = (ans + MOD) % MOD
ans *= nPk(M, N)
ans %= MOD
print(ans)


Measured memory_bytes: 68344
//void __(){
//    _(int,n);
//    _(int,m);
//    _(int,q);
//    int ans = MOD;
//    _(vi,a,n);
//    _(vi,b,m);
//    ans = min(a)+min(b);
//    while(q--){
//        _(int,u);
//        _(int,v);
//        _(int,w);
//        --u;
//        --v;
//        int tmp = a[u]+b[v]-w;
//        ans = min(ans,tmp);
//    }
//    print ans;
//}
//
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
T1 istream& operator>>(istream& stream, vector<T>& t){
    return read(all(t), stream);
}
T1 istream& read(T b, T e, istream& stream){
    for(T it = b; it != e; ++it)
        stream >> *it;
    return stream;
}
T1 T min(const vector<T>& arr){
    assert(!arr.empty());
    T ans = arr[0];
    for(auto& cur : arr)
        ans = min(ans, cur);
    return ans;
}
struct _print {
    string sep,end;
    bool space;
    ostream &stream;
    _print(string _sep=" ",string _end="\n",
            ostream &_stream = cout)
        : sep(_sep),end(_end),space(false),
            stream(_stream) {}
    ~_print() { stream << end; }
    template <typename T>
        _print &operator , (const T &t) {
            if (space) stream << sep;
            space = true;
            stream << t;
            return *this;
        }
};
#define print _print(),
#define INPUT_WITHOUT_INIT(type,name) type name; cin >> name
#define _IWI(type,name,...) type name(__VA_ARGS__); cin >> name
#define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__)
void __(){
    _(int,n);
    _(int,m);
    _(int,q);
    int ans = MOD;
    _(vi,a,n);
    _(vi,b,m);
    ans = min(a)+min(b);
    while(q--){
        _(int,u);
        _(int,v);
        _(int,w);
        --u;
        --v;
        int tmp = a[u]+b[v]-w;
        ans = min(ans,tmp);
    }
    print ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        __();
}


Measured memory_bytes: 1024
while True:
    N = int(input())
    if N==0:break
    dataset = input()
    mens = ["" for _ in range(N)]
    i = 0
    p = ""
    while dataset:
        if i == N: i = 0
        card, dataset = dataset[0], dataset[1:]
        if card == "M":
            mens[i] += card
        elif card == "S":
            p += card + mens[i]
            mens[i] = ""
        else:
            mens[i] += card + p
            p = ""
        i += 1
    print(' '.join(map(str, sorted([len(m) for m in mens]))), len(p))

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

#define INF 1145141919
int N, MA, MB;
int dp[401][401];

int main() {
  cin >> N >> MA >> MB;
  for (int a=0; a<=400; a++) {
    for (int b=0; b<=400; b++) {
      dp[a][b] = INF;
    }
  }

  dp[0][0] = 0;
  for (int i=0; i<N; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    for (int j=400; j>=a; j--) {
      for (int k=400; k>=b; k--) {
        dp[j][k] = min(dp[j][k], dp[j-a][k-b] + c);
      }
    }
  }
  int m = INF;
  for (int i=1; i<=1000; i++) {
    int a = MA*i, b = MB*i;
    if (a > 400 || b > 400)  break;
    m = min(m, dp[a][b]);
  }
  cout << (m!=INF?m:-1) << "\n";
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

int main(){
  string s;
  cin >> s;
  cout << s.substr(0,s.size()-8) << endl;

}


Measured memory_bytes: 892
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int nx[4] = {1,0,-1,0};
int ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<pair<string,int>> a;
    string s;
    int k;
    cin >> s >> k;
    int n = s.length();
    rep(i,n){
        string t = "aaaaa";
        rep(j,min((ll)k,n-i)){
            t[j] = s[i+j];
            a.insert(make_pair(t,j+1));
        }
    }
    auto itr = a.begin();
    rep(i,k-1) itr++;
    string ans = "";
    rep(i,(*itr).second) ans += (*itr).first[i];
    PRINT(ans);
}


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

int main(){
  int D;
  cin >> D;
  if(D == 22)cout << "Christmas Eve Eve Eve";
  if(D == 23)cout << "Christmas Eve Eve";
  if(D == 24)cout << "Christmas Eve";
  if(D == 25)cout << "Christmas";
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
(n, m,), *sub = [i.split() for i in open(0)]

r = {str(i+1): 0 for i in range(int(n))}
pen = 0
ac = 0
for p, s in sub:
    if r[p]>-1:
        if s == "WA":
            r[p]+=1
        else:
            ac += 1
            pen += r[p]
            r[p] = -1
print(ac, pen)


Measured memory_bytes: 52464
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(s: String);

    let ss = vec!["Sunny", "Cloudy", "Rainy"];
    for i in 0..3 {
        if ss[i] == s {
            println!("{}", ss[(i + 1) % 3]);
        }
    }
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

char maze[100][100];
ll sx, sy;
ll gx, gy;

ll d[100][100];

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

ll bfs() {
    queue<P> que;
    REP(i, n+1) {
        REP(j, m+1) {
            d[j][i] = INF;
        }
    }
    que.push(P(sx, sy));
    d[sx][sy] = 0;
    while (que.size()) {
        P p = que.front();
        que.pop();
        if (p.first == gx && p.second == gy) {
            break;
        }
        REP(i, 4) {
            ll nx = p.first + dx[i];
            ll ny = p.second + dy[i];
            if (0 <= nx && nx < m && 0 <= ny && ny < n&&maze[nx][ny] != '#'&&d[nx][ny] == INF) {
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[gx][gy];
}

int main() {
    sx = 0;
    sy = 0;
    cin >> n >> m;
    gx = m-1;
    gy = n-1;
    REP(i, n) {
        REP(j, m) {
            cin >> maze[j][i];
            if (maze[j][i] == '#') {
                cnt++;
            }
        }
    }
    ans = bfs();
    if (ans == INF) {
        cout << -1 << endl;
        return 0;
    }
    cout << n * m - (ans + 1) - cnt << endl;
}

Measured memory_bytes: 256
from collections import deque
from sys import stdin

def main():
    S = deque([s for s in input()])
    Q = int(input())
    order = True
    for i in range(Q):
        query = stdin.readline().split()
        t = int(query[0])
        if t == 1:
            order = not order
        else:
            f = int(query[1])
            c = query[2]
            if not order:
                f = 3  - f # 2, 1 -> 1, 2
            left = True
            if f == 1:
                S.appendleft(c)
            else:
                S.append(c)
    if not order:
        S.reverse()
    print(''.join(S))

if __name__ == '__main__':
    main()


Measured memory_bytes: 8548
import math

mod = 10**9 + 7
n2 = 2**100 % (mod)
n4 = n2**100 % (mod)
n6 = n4**100 % (mod)
n8 = n6**100 % (mod)


def iip():
    return [int(i) for i in input().split()]

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p/2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

def conbination(n, r):
    #print("conbination")
    ret = 1
    for i in range(1, r+1):
        ret *= (i+n-r)
        ret = ret % mod

    ret *= power(math.factorial(r), mod-2)
    ret = ret % mod

    #print(f"conbination {n}, {r} = {ret}")
    return ret

def binaly(n):
    return power(2, n)


def raw(n, a, b):
    d = binaly(n)
    c1 = conbination(n, a)
    c2 = conbination(n, b)
    return d - c1 - c2 - 1

def answer(n, a, b):
    return raw(n, a, b) % (10**9+7)

n, a, b = iip()

#print(factorial(1000000))
#print(math.factorial(1000000)%mod)
print(answer(n, a, b))


Measured memory_bytes: 5476
#!/usr/bin/env python3
import sys

def count(h, w, S: "List[str]") -> int:
    return (S[h-1][w] + S[h][w-1] + S[h-1][w-1] + S[h+1][w-1] + S[h-1][w+1] + S[h+1][w+1] + S[h+1][w] + S[h][w+1]).count("#")

def solve(H: int, W: int, S: "List[str]"):
    S = ["." * W] + S + ["." * W]
    for h in range(H+2):
        S[h] = "." + S[h] + "."
    ans = ["" for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if S[h+1][w+1] != "#":
                ans[h] += str(count(h+1, w+1, S))
            else:
                ans[h] += "#"
    for a in ans:
        print("".join(a))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ar array<int,2>
#define inf 1000000000000000000 
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}


const int N=2e5+5;



void solve()
{
   int a,b,c,d;
   cin>>a>>b>>c>>d;
   int ans=max({a*c,a*d,b*c,b*d});
   cout<<ans; 
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 srand(time(0));
 int t=1;
 //cin>>t;
 //cout<<(t^1);
 for(int i=1;i<=t;i++)
 {
   solve();
 }


}

Measured memory_bytes: 3648
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y % MOD;};



int main(){
  ll A, B, C; cin >> A >> B >> C;
  ll ans = 0;
  while(true){
    if(A % 2 || B % 2 || C % 2) break;
    if(ans > 100) break;
    ll nA, nB, nC;
    nA = (B + C) / 2;
    nB = (A + C) / 2;
    nC = (A + B) / 2;
    A = nA;
    B = nB;
    C = nC;
    ans++;
  }
  if(ans > 100) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  string S;
  cin >> S;
  S = "0" + S;
  ll N = S.size();
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    A.at(i) = myctoi(S.at(i));
  }
  reverse(A.begin(), A.end());

  vector<vector<ll>> dp(N + 1, vector<ll>(2, INF));
  dp.at(0).at(0) = 0;
  for (ll i = 0; i < N; i++)
  {
    chmin(dp.at(i + 1).at(0), dp.at(i).at(0) + A.at(i));
    chmin(dp.at(i + 1).at(1), dp.at(i).at(0) + 10 - A.at(i));

    chmin(dp.at(i + 1).at(0), dp.at(i).at(1) + A.at(i) + 1);
    chmin(dp.at(i + 1).at(1), dp.at(i).at(1) + 9 - A.at(i));
  }

  ll ans = min(dp.at(N).at(0), dp.at(N).at(1));
  cout << ans << endl;
}

Measured memory_bytes: 63792
import sys
input = sys.stdin.readline
from collections import defaultdict

def prime(n: int) -> defaultdict:
    f, i = defaultdict(int), 2
    while i * i <= n:
        while n % i == 0: f[i] += 1; n //= i
        i += 1
    if n != 1: f[n] = 1
    return f

def solve(n: int) -> int:
    if n == 1: return 1
    r, l = n, 0
    while (r - l) > 1:
        m = (l + r) // 2
        if m * (m + 1) // 2 <= n: l = m
        else: r = m
    return l

n, res = int(input()), 0
for k, v in prime(n).items(): res += solve(v)
print(res)

Measured memory_bytes: 65896
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
const ll mod =   1e9 +7  ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
   int n ;
   cin >> n ;
   vector < int > a(n);
   const int nmax = 1e5 + 1 ;
   vector < int > hash(nmax,0);
   ll s= 0  ;
   for( int i = 0 ; i < n ; i++) cin >> a[i], hash[a[i]]++ , s+= a[i]   ;
   int q ;
   cin >> q ;
   for( int i = 0 ; i < q ; i++){
        int b , c ;
        cin >> b >> c ;
        ll x = hash[b] ;
        hash[b] = 0 ;
        s -= b*x ;
        s += c*x ;
        hash[c] += x ;
        cout << s << "\n";
   }



}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}



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

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

  int cntL = 0;
  int cntR = 0;
  deque<int> deq;
  for(int i = 0; i < N; i++) {
    deq.push_back(S.at(i));
    if(S.at(i) == '(') {
      cntL++;
    } else if(S.at(i) == ')') {
      if(cntL > 0) {
        cntL--;
      } else {
        cntR++;
      }
    }
  }

  for(int i = 0; i < cntL; i++) {
    deq.push_back(')');
  }
  for(int i = 0; i < cntR; i++) {
    deq.push_front('(');
  }

  for_each(deq.begin(), deq.end(), [](char x) {
    cout << x;
  });
  cout << endl;
}


Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  string s;
  cin >> s;
  rep(i, s.size()) {
    if (s[i] == '1')
      cout << '9';
    else
      cout << '1';
  }
  cout << endl;
  return 0;
}


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

int main(int argc, const char * argv[]) {
    char b;
    
    cin >> b;
    switch (b) {
        case 'A':
            cout << "T" << endl;
            break;
        case 'T':
            cout << "A" << endl;
            break;
        case 'C':
            cout << "G" << endl;
            break;
        case 'G':
            cout << "C" << endl;
            break;
    }
    
    return 0;
}

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

int main()
{

    int a, b;
    cin >> a >> b;
    if (a < b)
        for (int i = 0; i < b; i++)
            cout << a;
    else
        for (int i = 0; i < a; i++)
            cout << b;
}


Measured memory_bytes: 3472
program rally
implicit none
integer n
integer, allocatable :: listx(:)
integer i, j
integer power, powerold
!
! input
read *, n
allocate(listx(n))
read *, listx
!
! calculation
powerold=1000000
do i = 1, 100
  power = 0
  do j = 1, n
    power = power + (listx(j) - i)**2
  end do
  if(power<powerold) then
    powerold = power
  end if
end do
!
! output
print '(i0)', powerold
end program

Measured memory_bytes: 256
#include <cstdio>

int next[20][100005];
int prev[20][100005];
int xs[100005];

int main(){
  int N,L,Q;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&xs[i]);
  }
  scanf("%d %d",&L,&Q);
  int j=N-1;
  for(int i=N-1;i>=0;i--){
    while(xs[j]-xs[i]>L){
      j--;
    }
    next[0][i]=j;
    for(int k=1;k<20;k++){
      next[k][i]=next[k-1][next[k-1][i]];
    }
  }
  j=0;
  for(int i=0;i<N;i++){
    while(xs[i]-xs[j]>L){
      j++;
    }
    prev[0][i]=j;
    for(int k=1;k<20;k++){
      prev[k][i]=prev[k-1][prev[k-1][i]];
    }
  }
  
  for(int i=0;i<Q;i++){
    int A,B;
    scanf("%d %d",&A,&B);
    A--,B--;
    if(A<B){
      int res=1;
      for(int k=20-1;k>=0;k--){
	if(next[k][A]<B){
	  A=next[k][A];
	  res+=(1<<k);
	}
      }
      printf("%d\n",res);
    }else{
      int res=1;
      for(int k=20-1;k>=0;k--){
	if(prev[k][A]>B){
	  A=prev[k][A];
	  res+=(1<<k);
	}
      }
      printf("%d\n",res);
    }
  }
  return 0;
}


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

using namespace std;

int check(int a){
    int sum = 1;
    for(int i = 1; i < a / 2; i++){
        if(a % i == 0){
            sum++;
        }
    }
    return sum == 8 ? 1 : 0;
}

int main(void){
    int n;
    cin >> n;
    int sum = 0;
    for(int i = 11; i <= n; i += 2){
        sum += check(i);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce


N = int(input())
A = list(map(int, input().split()))
P = int(1e9+7)

def lcm_base(x, y):
    ret = (x * y) // math.gcd(x, y)
    return ret


def lcm(iter):
    return reduce(lcm_base, iter, 1)


lcm_a = lcm(A) % P
ans = 0
for a in A:
    a_inv = pow(a, P-2, P)
    ans = (ans + lcm_a*a_inv) %P
print(ans)


Measured memory_bytes: 75116
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for (int i=0,_n=(int)(n); i < _n; i++)
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
 
typedef long long ll;

const int MAX_N = 100000 + 10;
int A[MAX_N];
vector<int> g[MAX_N];
bool ans;

ll f(int v, int p) {
  if (!ans) return 0;
  ll T = 0;
  if (g[v].size() == 1 && p == -1) {
    ll ci = f(g[v][0], v);
    if (A[v] != ci) { ans = false; }
    return 0;
  } else if (g[v].size() == 1 && p != -1) {
    T = A[v];
  } else {
    ll L = 0;
    ll cmax = 0;
    for (int u : g[v]) if (u != p) {
      ll ci = f(u, v);
      L += ci;
      cmax = max(cmax, ci);
    }
    T = 2 * A[v] - L;
    if (T < 0 || T > A[v]) { ans = false; }
    if ((L - T) < 0) { ans = false; }
    if (min(L/2, L-cmax) < (L - T) / 2) { ans = false; }
  }
  if (p == -1) {
    if (T != 0) { ans = false; }
  }
  return T;
}

int main2() {
  REP(i, MAX_N) g[i].clear();
  int N;
  scanf("%d", &N);
  REP(i, N) {
    scanf("%d", &A[i]);
  }
  REP(i, N-1) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ans = true;
  f(0, -1);
  cout << (ans ? "YES":"NO") << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

const int MAX_N = 333;
const int MAX_M = MAX_N * MAX_N;

int N, M, L;
VPII G[MAX_N];
int gas_his[MAX_N];

int Q;
int s[MAX_M], t[MAX_M];

LL dist[MAX_N][MAX_N];
int ans[MAX_N][MAX_N];

int main(void) {
    cin >> N >> M >> L;
    REP(i, N) REP(j, N) dist[i][j] = LLINF;
    REP(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;b--;

        if (c > L) continue;

        G[a].EB(b, c);
        G[b].EB(a, c);
        dist[a][b] = dist[b][a] = c;
    }

    REP(k, N) REP(i, N) REP(j, N) {
        chmin(dist[i][j], dist[i][k] + dist[k][j]);
    }

    REP(i, N) REP(j, N) ans[i][j] = i == j ? 0 : INF;
    REP(i, N) REP(j, N) {
        if (dist[i][j] <= L) {
            ans[i][j] = 0;
        }
    }

    REP(k, N) REP(i, N) REP(j, N) {
        chmin(ans[i][j], ans[i][k] + ans[k][j] + 1);
    }

    cin >> Q;
    REP(i, Q) {
        cin >> s[i] >> t[i];
        s[i]--;t[i]--;
    }

    REP(i, Q) {
        if (ans[s[i]][t[i]] < INF) cout << ans[s[i]][t[i]] << endl;
        else cout << -1 << endl;
    }
}


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

int main() {
	string S0, s;
	getline(cin, S0);
	for (int i = 0; i < S0.size(); i++)
	{
		if ((s = S0.at(i)) == " ") {
			s = S0.at(i + 1);
			break;
		}
	}
	
	cout << "A"+s+"C" << endl;
}

Measured memory_bytes: 3600
S = input()

res = "AC"
if S[0] != "A" or S.count("C") != 1:
    res = "WA"

if "C" not in S[2:-1]:
    res = "WA"

if res == "AC":
    for s in S[1:]:
        if s != "C" and s != s.lower():
            res = "WA"
            break
print(res)

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

using namespace std;

int n, k;
int a[105];
int b[105];
long long mem[105][100005];

long long f(int i, int w)
{
    if(mem[i][w]) return mem[i][w];
    if(i == n) return 0;

    mem[i][w] = f(i+1, w);
    if(w+a[i] <= k) mem[i][w] = max(mem[i][w], f(i+1, w+a[i]) + b[i]);

    return mem[i][w];
}
int main()
{
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; i++)
    {
        scanf("%d%d", &a[i], &b[i]);
    }
    printf("%lld", f(0, 0));
}


Measured memory_bytes: 78080
def inpl(): return list(map(int, input().split()))

N = int(input())
P = inpl()
Q = sorted(P)

OK = False
for i in range(N):
    for j in range(N):
        P[i], P[j] = P[j], P[i]
        if P == Q:
            OK = True
        P[i], P[j] = P[j], P[i]
print("YES" if OK else "NO")

Measured memory_bytes: 38896
#include <bits/stdc++.h>
using namespace std;
int dizi[10005];
int main(){
	long long int a;
	cin>>a;
	int top=0;
	for(int i = 0 ;i<a;i++){
		cin>>dizi[i];
		if(dizi[i]!=i+1){
			top++;
		}
	}
	if(top == 0 || top == 2){
		cout<<"YES";
	}
	else{
		cout<<"NO";
	}
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	PrintWriter out = new PrintWriter(System.out);
	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tok = new StringTokenizer("");
    String next() throws IOException {
        if (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); }
        return tok.nextToken();
    }
    int ni() throws IOException { return Integer.parseInt(next()); }
    long nl() throws IOException { return Long.parseLong(next()); }
  
    void solve() throws IOException {
        
            char a=next().charAt(0);
            a++;
            System.out.println(a);
        
    }
    
    public static void main(String[] args) throws IOException {
        new Main().solve();
    }
}

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

int n,ans;

struct node
{
	int val,oin;
}a[int(1e5+7)];

bool cmp(node a,node b)
{
	return a.val<b.val;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i].val);
		a[i].oin=i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;++i)
	{
		if((a[i].oin-i)%2)ans++;
	}
	printf("%d",ans/2);
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

struct Edge{
    int to;
    int cost;
};

int n;
vector<vector<Edge>> tree;
vi ans;

void dfs(int v = 0, int p = -1, int cost = 0){
    if(ans[v] != -1) return;
    if(p == -1) ans[v] = 0;
    else ans[v] = (ans[p] + cost) % 2;
    for(auto e : tree[v]){
        dfs(e.to, v, e.cost);
    }    
}

void Main() {
    cin >> n;
    
    tree.resize(n);
    ans.resize(n, -1);
    
    rep(i, n-1){
        int u, v, w;
        cin >> u >> v >> w;
        u--; v--;
        w %= 2;
        tree[u].pb(Edge{v,w});
        tree[v].pb(Edge{u,w});
    }

    dfs();
    
    rep(i, n) cout << ans[i] << endl;    
    
	return;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 7424