akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N;
	string S;
	cin >> N >> S;

	string rsl = "";
	int cnt = 0;
	rep(i, 0, N) {
		if(S[i] == '(') cnt++;
		else cnt--;
		if(cnt < 0) {
			rsl = '(' + rsl;
			cnt++;
		}
		rsl += S[i];
	}

	rep(i, 0, cnt) rsl += ')';
	cout << rsl << endl;
}


Measured memory_bytes: 256
import heapq
n, m = map(int, input().split())
jobs = [[] for _ in range(m)]

for i in range(n):
  a, b = map(int, input().split())
  if a > m:
    continue
  jobs[m-a].append(b)

que = []#候補入れ
ans = 0
for i in range(m-1, -1, -1):
  for wage in jobs[i]:
    heapq.heappush(que, wage*-1)
  if len(que):
    ans += heapq.heappop(que)*-1
    
print(ans)

  

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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;
typedef double Double;

const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
const Double EPS = 1e-9;

int n;

void solve() {
	bool flag = true;
	int b = 0;
	
	for_(i,0,n) {
		char p; int x; cin >> p >> x;
		
		if (p == '(') b += x;
		else b -= x;
		
		if (b < 0) flag = false;
	}
	
	if (b > 0) flag = false;
	
	if (flag) cout << "YES" << endl;
	else cout << "NO" << endl;
}

int main() {
	cin >> n;
	solve();
	return 0;
}

Measured memory_bytes: 1156
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace AtCoder {
    class Practice {
        static void Main() => CustomMain();

        static void Solve() {
            var n = ReadInt();
            var l = ReadIntArray();

            Array.Sort(l);

            var ans = 0;
            for (int i = 0; i < l.Length; i += 2) {
                ans += Math.Min(l[i], l[i + 1]);
            }

            WriteAnswer(ans);
        }


        static void CustomMain() {
#if DEBUG
            // ファイルからテストケースを読み込む
            global::Common.ChangeStdIn();
            // 時間計測
            var stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            // 出力高速化
            var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(streamWriter);
            // 回答
            Solve();
#if DEBUG
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
#endif
            Console.Out.Flush();
        }

        static string ReadString() => Console.ReadLine().Trim();
        static int ReadInt() => int.Parse(ReadString());
        static long ReadLong() => long.Parse(ReadString());
        static float ReadFloat() => float.Parse(ReadString());
        static double ReadDouble => double.Parse(ReadString());

        static string[] ReadStringArray() => ReadString().Split(' ');
        static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
        static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
        static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
        static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

        static T TypeConversion<T>(string s) {
            if (typeof(T) == typeof(int)) {
                return (T) Convert.ChangeType(int.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(long)) {
                return (T) Convert.ChangeType(long.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(double)) {
                return (T) Convert.ChangeType(double.Parse(s), typeof(T));
            } else {
                return (T) Convert.ChangeType(s, typeof(T));
            }
        }

        static void ReadMulti<T, U>(out T a, out U b) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
        }

        static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
            c = TypeConversion<V>(str[2]);
        }

        static void WriteAnswer(object ans) => Console.WriteLine(ans);

        static bool IsOdd(long num) {
            return (num & 1) == 1;
        }

        static bool IsEven(long num) {
            return (num & 1) == 0;
        }

        static long GCD(long a, long b) {
            return b != 0 ? GCD(b, a % b) : a;
        }
    }
}

Measured memory_bytes: 11220
import java.util.*;

public class Main
{
    static final int inf = 99999;
    int[][] a;

    Main(){
	Scanner sc = new Scanner(System.in);
	int n, m, s, t;

	while(sc.hasNext()){
	    n = sc.nextInt();
	    a = new int[n+1][n+1];

	    for(int i = 0; i <= n; ++i)
		for(int j = i+1; j <= n; ++j)
		    a[i][j] = a[j][i] = inf;

	    for(int i = 0; i < n; ++i){
		s = sc.nextInt();
		m = sc.nextInt();
		for(int j = 0; j < m; ++j){
		    t = sc.nextInt();
		    a[s][t] = 1;
		}
	    }

	    for(int k = 1; k <= n; ++k)
		for(int i = 1; i <= n; ++i)
		    for(int j = 1; j <= n; ++j)
			a[i][j] = Math.min(a[i][j], a[i][k]+a[k][j]);

	    n = sc.nextInt();
	    for(int i = 0; i < n; ++i){
		s = sc.nextInt();
		t = sc.nextInt();
		m = sc.nextInt();
		if(a[s][t] < m)
		    System.out.println(Integer.toString(a[s][t]+1));
		else
		    System.out.println("NA");
	    }
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 0
// atcoder/abc127/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  while (cin >> n >> m) {
    vector<int> a(n);
    cin >> a;

    vector<pair<int, int>> v(m);
    cin >> v;
    each (i, a) v.push_back(make_pair(1, i));

    sort(v.begin(), v.end(), [] (auto i, auto j) {
      return i.second < j.second;
    });

    vector<lli> b;
    while (b.size() < n) {
      b.push_back(v.back().second);
      --v.back().first;
      if (v.back().first == 0) v.pop_back();
    }

    cout << accumulate(b.begin(), b.end(), 0LL) << endl;
  }

  return 0;
}


Measured memory_bytes: 4804
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;


int main()
{
    int n;
    cin >> n;
    int h[n];
    int c[n];
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    c[0] = 0;
    c[1] = abs(h[1]-h[0]);
    for(int i = 2; i < n; i++){
        c[i] = min(c[i-1] + abs(h[i]-h[i-1]),c[i-2] + abs(h[i]-h[i-2]));
    }
    cout << c[n-1];
}

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

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

n,k = LI()
p = LI()
lst = [(i+1)/2 for i in p]
l = [0]+ list(accumulate(lst))
ans = 0
for i in range(n-k+1):
    ans = max(ans,l[i+k] - l[i])
print(ans)

Measured memory_bytes: 78968
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{   
    Senky_Bansal
    IIIT_ALLAHABAD
     
    string s;
    cin>>s;
    ll ans=0;
    for(int i=0;i<s.size() && i<15;i++)
    {
        if(s[i]=='o')
        ans++;
    }
    ll q=s.size();
    if(ans+max(15-q,0LL)>=8)
    cout<<"YES\n";
    else
    cout<<"NO\n";
     
     


}





Measured memory_bytes: 256
n=int(input())
w=[int(i) for i in input().split()]

minnum=100000000000
for i in range(n-1):
    s1=0
    for j in range(i+1):
        s1+=w[j]
    s2=0
    for j in range(i+1,n):
        s2+=w[j]
    if abs(s1-s2)<minnum:
        minnum=abs(s1-s2)
    
print(minnum)

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

int main(){
    int N, count;
    string str;
    bool before_is_A = false;
    bool first_is_B = false;
    int inside_AB=0;
    int last_A=0;
    int first_B=0;
    int last_A_first_B=0;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> str;
        first_is_B=false;
        before_is_A=false;
        for(int j=0; j<str.length(); j++){
            if(j==0&& str[j]=='B'){
                first_B++;
                first_is_B=true;
            }
            else if(j==str.length()-1&&str[j]=='A'){
                if(first_is_B){
                    first_B--;
                    last_A_first_B++;
                }else{
                    last_A++;
                }
            }else if(str[j]=='A'){
                before_is_A = true;
                
            }else if(str[j]=='B'){
                if(before_is_A){
                    inside_AB++;
                }
                before_is_A = false;
            }else{
                before_is_A = false;
            }
        }
    }
    count = inside_AB;
    if(last_A == 0&& first_B==0&&last_A_first_B>0){
        count += last_A_first_B-1;
    }
    else if(last_A > first_B){
        count += first_B;
        count += last_A_first_B;
    }else {
        count += last_A;
        count += last_A_first_B;
    }
    cout << count << 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 r = sc.nextInt(),c = sc.nextInt(),sum;
        int[][] a = new int[c][r];
        for(int i = 0;i < r;++i){
            for(int j = 0;j < c;++j) a[j][i] = sc.nextInt();
        }
        int[] b = new int[c];
        for(int i = 0;i < r;++i){
            sum = a[0][i];
            b[0] += a[0][i];
            System.out.print(a[0][i]);
            for(int j = 1;j < c;++j){
                int v = a[j][i];
                sum += v;
                b[j] += v;
                System.out.printf(" %d",v);
            }
            System.out.printf(" %d\n",sum);
        }
        sum = b[0];
        System.out.print(b[0]);
        for(int i = 1;i < c;++i){
            sum += b[i];
            System.out.printf(" %d",b[i]);
        }
        System.out.printf(" %d\n",sum);
    }

}

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

using namespace std;

typedef long long ll;

int main() {
	ll a, b, x;
	cin >> a >> b >> x;

	ll ans = (b / x) - (a / x);
	
	if (a % x == 0)ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000009;

int main(){
	string s;
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5]){
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}


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

class Program {
    static void Main(string[] args) {

        int a = cin.ni();
        int b = cin.ni();
        int c = cin.ni();
        HashSet<int> penks = new HashSet<int>() { a, b, c };  
        Console.WriteLine(penks.Count);

    }
}


public class cin {
    private static string[] s = new string[0];
    private static int i = 0;

    private static char[] cs = new char[] { ' ' };

    public static string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return next();
    }

    public static int ni() {
        return int.Parse(next());
    }

    public static long nextLong() {
        return long.Parse(next());
    }

    public static double nextDouble() {
        return double.Parse(next());
    }

}


Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

double sq(int a1, int a2, int b1, int b2)
{
    int x = pow(a1 - a2, 2);
    int y = pow(b1 - b2, 2);
    return sqrt((double)x + y);
}

int main()
{
    int n; cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    vector<int> num(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
        num[i] = i;
    }
    int kai = 1;
    for (int i = 1; i <= n; ++i) kai *= i;
    vector<double> tmp(kai, 0.0);
    int idx = 0;

    double ans = 0.0;
    do {
        for (int i = 0; i < n-1; ++i) {
            tmp[idx] += sq(x[num[i]], x[num[i+1]], y[num[i]], y[num[i+1]]);
        }
        ++idx;
    } while(next_permutation(num.begin(), num.end()));

    for (int i = 0; i < tmp.size(); ++i) {
        ans += tmp[i];
    }
    ans /= tmp.size();

    cout << fixed << setprecision(10);
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 512
import numpy as np

def main():
    n, m = map(int, input().split(" "))
    As = np.array(list(map(int, input().split(" "))))
    #print(np.sum(As) /(4 * m))
    #print(As >= (np.sum(As) /(4 * m)))
    if np.count_nonzero(As >= (np.sum(As) /(4 * m))) >= m:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 21784
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

N = k()
A = []
for i in range(N):
    a = k()
    A.append(a)
    
aaa = 0    
ans = A[0]
count = 1
 
for i in range(N):
    if ans == 2:
        aaa = 1
        break
    else:
        ans = A[ans-1]
        count += 1
if aaa == 1:
    print(count)
else:
    print(-1)

Measured memory_bytes: 14376
'use strict'

function main(input) {
  input = input
    .trim()
    .split(' ')
    .map(Number)

  const x1 = input[0]
  const y1 = input[1]
  const x2 = input[2]
  const y2 = input[3]

  const x3 = x2 - (y2 - y1)
  const y3 = y2 + (x2 - x1)
  const x4 = x1 - (y2 - y1)
  const y4 = y1 + (x2 - x1)

  console.log([x3, y3, x4, y4].join(' '))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

// 正方形

Measured memory_bytes: 21192
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

K = int(input())
S = 0

for i in range(1,K+1):
    for j in range(i+1,K+1):
        for k in range(j+1,K+1):
            S += gcd(i,j,k)*6

for i in range(1,K+1):
    for j in range(i+1,K+1):
        S+= gcd(i,j)*6

for i in range(1,K+1):
    S+=i

print(S)


Measured memory_bytes: 9656
#include<iostream>
using namespace std;
int pd[1010];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		int a;
		cin>>a;
		for(int j=1;j<=a;j++)
		{
			int b;
			cin>>b;
			pd[b]++;
		}
	}
	int sum=0;
	for(int i=1;i<=m;i++)
	{
		if(pd[i]==n)
		sum++;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
n = input()
m = len(n)
K = int(input())
#状態をもつ：i桁目まで見たときのj（その値は指定された値未満かどうか）において0でない数字がk個ある状態
dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(m + 1)]
dp[0][0][0] = 1

for i in range(1, m+1):
    l = int(n[i-1])
    for k in range(K+1):
        
        #その値通りだった時、l=0だと0の数を増やせないので
        if l == 0:
            dp[i][0][k] = dp[i-1][0][k]
        else:
            if k >= 1:
                dp[i][0][k] += dp[i-1][0][k-1]
        

        dp[i][1][k] += dp[i-1][1][k]
        if l != 0:
            dp[i][1][k] += dp[i-1][0][k]
        if k >= 1:
            dp[i][1][k] += 9*dp[i-1][1][k-1]
            if l != 0:
                dp[i][1][k] +=  (l-1)*dp[i-1][0][k-1]

print(dp[m][0][K] + dp[m][1][K])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >> S;
    int ans = 0;

    if(S == "RRR"){
        ans = 3;
    }
    else if(S == "RRS" || S == "SRR" ){
        ans = 2;
    }
    else if(S == "SSS"){
        ans = 0;
    }
    else{
        ans = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
 
#define N 10000
#define Nil -1
 
typedef struct{
  int p,l,r;
    }Node;
 
Node T[N];
int n,D[N],H[N];
 
void setDepth(int, int);
int setHeight(int);
int getSibling(int);
void print(int);
 
int main(){
  int i,v,l,r,root=0;
 
  scanf("%d",&n);
  for(i=0;i<n;i++)
    T[i].p = Nil;
 
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
 
    T[v].l = l;
    T[v].r = r;
 
    if(l!=Nil) T[l].p = v;
    if(r!=Nil) T[r].p = v;
  }
 
  for(i=0;i<n;i++)
    if(T[i].p == Nil) root = i;
 
  setDepth(root,0);
  setHeight(root);
 
  for(i=0;i<n;i++)
    print(i);
 
  return 0;
}
 
void setDepth(int u, int d){
 
  if(u==Nil) return;
 
  D[u] = d;
 
  setDepth(T[u].l, d+1);
  setDepth(T[u].r, d+1);
 
}
 
int setHeight(int u){
  int h1,h2;
 
  h1 = h2 = 0;
 
  if(T[u].l != Nil) h1 = setHeight(T[u].l) + 1;
  if(T[u].r != Nil) h2 = setHeight(T[u].r) + 1;
 
  return H[u] = (h1 > h2 ? h1 : h2); 
}
 
int getSibling(int u){
 
  if(T[u].p ==Nil) return Nil;
 
  if(T[T[u].p].l != u && T[T[u].p].l != Nil)
    return T[T[u].p].l;  
  if(T[T[u].p].r != u && T[T[u].p].r != Nil)
    return T[T[u].p].r;
 
  return Nil;
}
 
void print(int u){
  int deg;
  
  printf("node %d: parent = %d, sibling = %d, ",u,T[u].p,getSibling(u));
  
  deg = 0;
  
  if(T[u].l != Nil)deg++;
  if(T[u].r != Nil)deg++;
  
  printf("degree = %d, depth = %d, height = %d, ",deg,D[u],H[u]);
  
  if(T[u].p == Nil)printf("root\n");
  else if(T[u].l == Nil && T[u].r == Nil)printf("leaf\n");
  else printf("internal node\n");
}
 
 



 

Measured memory_bytes: 1768
/*********************
*  Author: xuziyuan  * 
*********************/
 
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
const LL MOD=1e9+7;

int n,m,x,y,z,a[20][20],val[40000],dp[40000][20],dp2[40000],sum=0;

int main()
{
	cin>>n>>m;
	rep(i,m)
	{
		cin>>x>>y>>z;
		x--;
		y--;
		a[x][y]=a[y][x]=z;
		sum+=z;
	}
	rep(i,1<<n) rep(j,n) for(int k=j+1;k<n;k++) if((i&(1<<j))>0&&(i&(1<<k))>0) val[i]+=a[j][k];
	rep(i,39995) rep(j,18) dp[i][j]=-1;
	rep(i,1<<n) if((i&1)>0) dp[i][0]=val[i];
	rep(i,1<<n)
	{
		rep(j,n)
		{
			if(dp[i][j]==-1) continue;
			rep(k,n)
			{
				if(a[j][k]==0||(i&(1<<k))>0) continue;
				dp[i|(1<<k)][k]=max(dp[i|(1<<k)][k],dp[i][j]+a[j][k]);
			}
		}
	}
	rep(i,39995) dp2[i]=-1;
	rep(i,1<<n) dp2[i]=dp[i][n-1];
	rep(i,1<<n)
	{
		if(dp2[i]==-1) continue;
		rep(j,n)
		{
			if((i&(1<<j))==0) continue;
			int rest=(1<<n)-1-i;
			for(int k=rest;k>0;k=(k-1)&rest) dp2[i|k]=max(dp2[i|k],dp2[i]+val[k|(1<<j)]);
		}
	}
	cout<<sum-dp2[(1<<n)-1]<<endl;
	return 0;
}

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

#define 	pi 				3.1415926536
#define 	mod 			1000000007
#define 	lli 			long long int
#define 	rep(i, n) 		for(int i = 0 ; i < n ; i++)
#define 	repn(i, n) 		for(int i = n - 1 ; i >= 0 ; i--)
#define 	loop(i, a, b)	for(int i = a ; i < b ; i++)
#define 	mod1 			1000003
#define 	hello 			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define 	F 				first
#define 	S 				second
#define 	pb 				push_back
#define 	mp				make_pair
#define 	B 				begin()
#define 	E 				end()
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define 	vi 				vector<int>
#define 	vs 				vector<string>
#define 	print(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//g++ -std=c++14
//fixed<<setprecision(9);
//max_element(mp.begin(), mp.end(), compare)


bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return a.second < b.second; }

bool compare(const pair<string, int> &a, const pair<string, int> &b){ return a.second < b.second; }

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

int main()
{
	boost;
	int  n, m;
	cin>>n>>m;
	if(n==m)
		cout<<"Yes"<<nl;
	else
		cout<<"No"<<nl;

}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll << 61;
const double eps = 0.000000000001;
typedef long long ll;
struct edge { int to; int cost;};
int a[505];
signed main() {
	int n, k; cin >> n >> k;
	rep(i, n)cin >> a[i];
	int s = 0;
	rep(i, n)s += a[i];
	vector<int>V;
	for (int i = 1; i*i <= s; i++) {
		if (s%i == 0) {
			V.push_back(i);
			if (i*i != s)V.push_back(s / i);
		}
	}
	sort(V.begin(), V.end());
	int ans = 0;
	rep(i, V.size()) {
		int asum = 0;
		vector<int>sv;
		rep(j, n) {
			int x = a[j] % V[i];
			sv.push_back(x);
			asum += x;
		}
		sort(sv.begin(), sv.end());
		asum /= V[i];
//		cout << V[i] << ' ' << asum << endl;
		int aasum = 0;
		rep(j, n - asum)aasum += sv[j];

		if (aasum <= k)ans = max(ans, V[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
 
using namespace std;
 
#define MAX 20
 
double L[MAX],a[MAX],b[MAX];
 
double calc(int x,int y){
    return pow(L[x]-L[y],2)+pow(a[x]-a[y],2)+pow(b[x]-b[y],2);
}
 
int main(){
    int N,M;
    cin >> N >> M;
    for(int i = 0 ; i < N ; i++){
	cin >> L[i] >> a[i] >> b[i];
    }
    double ans = 0;
    for(int S = 0 ; S < 1<<N ; S++){
	if(__builtin_popcount(S) == M){
	    double dist = 0;
	    vector<int> vec;
	    for(int i = 0 ; i < N ; i++){
		if(!(S >> i & 1)) continue;
		vec.push_back(i);
	    }
	    for(int i = 0 ; i < M ; i++){
		for(int j = i+1 ; j < M ; j++){
		    dist += calc(vec[i],vec[j]);
		}
	    }
	    ans = max(ans,dist);
	}
    }
    printf("%.10f\n",ans);
 
    return 0;
}

Measured memory_bytes: 3288
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


int H, W;
int start_x, start_y;
int end_x, end_y;
bool field[1001][1001];
bool flg[1001][1001];

int _dx[] = { 1,0,-1,0 };
int _dy[] = { 0,1,0,-1 };

bool IsIn(int x, int y)
{
	return 0 <= x && x < W && 0 <= y && y < H;
}


signed main()
{
	cin >> H >> W;
	cin >> start_y >> start_x;
	cin >> end_y >> end_x;
	start_y--;
	start_x--;
	end_y--;
	end_x--;
	REP(y, H)
	{
		string s;
		cin >> s;
		REP(x, W)
		{
			field[x][y] = (s[x] == '#');
		}
	}


	int ans = 0;
	queue<int> toho_q;
	queue<int> maho_q;

	toho_q.push(start_x);
	toho_q.push(start_y);
	maho_q.push(start_x);
	maho_q.push(start_y);
	flg[start_x][start_y] = true;

	while (true)
	{
		while (toho_q.size() > 0)
		{
			int toho_cnt = toho_q.size() / 2;
			for (int i = 0; i < toho_cnt; i++)
			{
				int x = toho_q.front();
				toho_q.pop();
				int y = toho_q.front();
				toho_q.pop();

				for (int d = 0; d < 4; d++)
				{
					int nx = x + _dx[d];
					int ny = y + _dy[d];

					if (nx == end_x && ny == end_y)
					{
						cout << ans << endl;
						return 0;
					}

					if (IsIn(nx, ny) && !flg[nx][ny] && !field[nx][ny])
					{
						flg[nx][ny] = true;
						toho_q.push(nx);
						toho_q.push(ny);
						maho_q.push(nx);
						maho_q.push(ny);
					}
				}
			}
		}

		int maho_cnt = maho_q.size() / 2;
		for (int i = 0; i < maho_cnt; i++)
		{
			int x = maho_q.front();
			maho_q.pop();
			int y = maho_q.front();
			maho_q.pop();

			for (int mx = -2; mx <= 2; mx++)
			{
				for (int my = -2; my <= 2; my++)
				{
					int nx = x + mx;
					int ny = y + my;

					if (nx == end_x && ny == end_y)
					{
						cout << (ans + 1) << endl;
						return 0;
					}

					if (IsIn(nx, ny) && !flg[nx][ny] && !field[nx][ny])
					{
						flg[nx][ny] = true;
						toho_q.push(nx);
						toho_q.push(ny);
						maho_q.push(nx);
						maho_q.push(ny);
					}
				}
			}
		}

		if (toho_q.size() == 0) break;
		ans++;
	}


	cout << -1 << endl;
}



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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

template<int mod> struct modulo {
	int w;
	operator int&() { return w; }
	operator int() const { return w; }
	
	modulo() {}
	modulo(int w, bool f = 0) { this->w = w; if (f) fix(); }
	void inline fix() { if (w >= mod || w < -mod) w %= mod; if (w < 0) w += mod; }
	
	inline modulo  operator -  () { w = -w + mod; return *this; }
	inline modulo  operator +  (const modulo &b) { modulo r = *this; return r += b; }
	inline modulo  operator -  (const modulo &b) { modulo r = *this; return r -= b; }
	inline modulo  operator *  (const modulo &b) { return (num) w * b.w % mod; }
	inline modulo  operator /  (const modulo &b) { return *this * inv(b); }
	inline modulo& operator += (const modulo &b) { if ((w += b.w) >= mod) w -= mod; return *this; }
	inline modulo& operator -= (const modulo &b) { if ((w -= b.w) < 0) w += mod; return *this; }
	inline modulo& operator *= (const modulo &b) { return *this = *this * b; }
	inline modulo& operator /= (const modulo &b) { return *this /= inv(b); }
	
	friend inline modulo inv(const modulo &w) {
		int a = w, m = mod, u = 0, v = 1, t;
		for (; a != 0; t = m / a, m -= t * a, swap(a, m), u -= t * v, swap(u, v));
		return modulo(u, 1);
	}
	
	friend inline modulo pow(const modulo &w, int p) {
		if (!w)  return 0;
		modulo a = w, r = 1;
		for (; p > 0; a *= a, p >>= 1) if (p & 1) r *= a;
		return r;
	}
};
const int mod = int(1e9) + 7;
typedef modulo<mod> rem;

const int nsz = 300;
int n, m;
rem dp[nsz + 5][nsz + 5][nsz + 5], ans;

int main() {
	scanf("%d%d", &n, &m);
	int o = 0, x = 1;
	dp[o][1][1] = 1;
	loop (i, m) {
		cont (j, min(i + 1, n)) {
			cont (k, j) {
				rem val = dp[o][j][k];
				dp[x][j + 1][k] += val * rem(n - j);
				dp[x][j][k] += val * rem(j - k);
				dp[x][j][j] += val * rem(k);
			}
		}
		swap(o, x);
		memset(dp[x], 0, sizeof(dp[x]));
	}
	ans = dp[o][n][n];
	printf("%d\n", ans.w);
}

Measured memory_bytes: 4456
count = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]

n = int(input())
for i in range(n):
    b, f, r, v = map(int, input().split())
    
    count[b-1][f-1][r-1] += v
 #   for y in range(4):

x = 0
for i in range(4):
    if x != 0:
        print("#"*20)
    x += 1
 
    for a in range(3):
        for b in range(10):
            print(" %d"%(count[i][a][b]),end = "")
        print()


Measured memory_bytes: 5624
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3076
#![allow(unused)]

use std::io::{Read, StdinLock};
use std::iter::{FromIterator, Iterator};
use std::str::{FromStr};
use std::string::String;

macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

pub fn read_bytes<T: FromIterator<char>>(s: &mut StdinLock) -> T {
    s.bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<T>()
}

pub fn reads(s: &mut StdinLock) -> String {
    read_bytes::<String>(s)
}

pub fn read<T: FromStr>(s: &mut StdinLock) -> T {
    reads(s).parse().ok().unwrap()
}

//==============================================================================
//
// Problem specific code
//
//==============================================================================

fn main() {
    let sin = std::io::stdin();
    let mut sin = sin.lock();

    let n: usize = read(&mut sin);

    let ans: usize = (1..=n).filter(|i| i % 3 != 0 && i % 5 != 0).sum();
    println!("{}", ans);
}

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

bool hw(string s)
{
	for(int i=0;i<=s.size()-1;i++)if(s[i]!=s[s.size()-1-i])return false;
	return true;
}

int main()
{
	string s;
	cin>>s;
	int n=s.size();
	if(n%2==0)cout<<"No",exit(0);
	if(!hw(s))cout<<"No",exit(0);
	string sa;
	for(int i=0;i<=(n-1)/2-1;i++)
		sa+=s[i];
	if(!hw(sa))cout<<"No",exit(0);
	string sb;
	for(int i=(n+3)/2-1;i<=n-1;i++)
		sb+=s[i];
	if(!hw(sb))cout<<"No",exit(0);
	cout<<"Yes";
}

Measured memory_bytes: 256
let n = Scanf.scanf " %d" (+) 0
let vcs = Array.init 2 @@ fun _ -> Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let _ = Array.mapi (fun i v -> max 0 @@ v - vcs.(1).(i)) vcs.(0) |> Array.fold_left (+) 0 |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define w(t) int t;cin>>t; while(t--)
using namespace std;

int main(){
    int n, k;
    cin>>n>>k;
    int dp[n+1];
    memset(dp, 0, sizeof(dp));
    while(k--){
        int d;
        cin>>d;
        for(int i=0 ; i<d; i++){
            int x; 
            cin>>x;
            dp[x]++;
        }
    }
    int ans = 0;
    for(int i=1; i<=n; i++){
        if(dp[i] == 0){
            ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
char S[20],T[20];
int main(){
	scanf("%s",S+1);scanf("%s",T+1);
	reg int n=strlen(T+1);
	for(reg int i=1;i<n;i++)
		if(S[i]!=T[i])return 0*puts("No");
	puts("Yes");
	return 0;
}

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

int f(const string &A, const string &B) {
  	int ans = 0;
	vector<int> ca(128, 0), cb(128, 0);
  	for(int i = 0; i < A.length(); i++) ca[A[i]]++;
  	for(int i = 0; i < B.length(); i++) cb[B[i]]++;
  	for(int i = 'a' ; i <= 'z'; i++) {
      if(ca[i] > 0 && cb[i] > 0) ans++;
    }
  	return ans;
}

int main() {
  int N; string S; cin>>N>>S;
  int ans = 0;
  for(int i = 1; i < N; i++) {
    string A = S.substr(0, i);
    string B = S.substr(i);
    int tmp = f(A, B);
    ans = max(ans, tmp);
    //cout << A << "," << B << "," << tmp << endl;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> H(N);
	for (int i = 0; i < N; ++i)
		cin >> H[i];
	vector<vector<int>> g(N);
	for (int i = 0; i < M; ++i) {
		int a, b; cin >> a >> b;
		--a, --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int res = 0;
	for (int i = 0; i < N; ++i) {
		bool ok = true;
		for (auto nx : g[i])
			ok &= H[i] > H[nx];
		res += ok ? 1 : 0;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 8740
#include<stdio.h>
int strlng(char a[])
{
    int i;
    for(i=1; a[i]!='\0'; i++)
    {

    }
    return i;
}
int main()
{
    char w[1000];
    int i, j, ln, count, flag=0;
    scanf("%s", w);
    ln = strlng(w);
    for(i=0; i<ln; i++)
    {
        count = 0;
        for(j=0; j<ln; j++)
        {
            if(w[j] == w[i])
            {
                count++;
            }
        }
        if(count%2 == 0)
        {
            flag=1;
        }
        else if(count%2 != 0)
        {
            printf("No\n");
            return 0;
        }
    }
    if(flag==1)
    {
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    sort(l.begin(), l.end());
    int sum = 0;
    rep(i, n - 1) {
        sum += l[i];
    }
    reverse(l.begin(), l.end());
    if(l[0] < sum) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main()
{
  int N, D;
  cin >> N >> D;

  int X, Y;
  int ans = 0;

  for (int i = 0; i < N; i++)
  {
    cin >> X >> Y;
    if (sqrt(pow(X, 2) + pow(Y, 2)) <= D)
      ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3652
from collections import deque
n, q = map(int, input().split())
que = deque([])

for i in range(n):
    name, time = input().split()
    time = int(time)
    que.append([name, time])

t = 0

while len(que) > 0:
    atop = que.popleft()
    spend = min(atop[1], q)
    atop[1] -= spend
    t += spend
    if atop[1] == 0:
        print(atop[0], t)
    else:
        que.append(atop)



Measured memory_bytes: 13272
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n,m;cin>>n>>m;
    char a[n][n],b[m][m];
    rep(i,n)rep(j,n) cin>>a[i][j];
    rep(i,m)rep(j,m) cin>>b[i][j];
    rep(i,n-m+1)rep(j,n-m+1){
        bool ok=true;
        rep(k,m)rep(l,m){
            if(a[i+k][j+l]!=b[k][l]){
                ok=false;
                break;
            }
        }
        if(ok){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

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

int main() {

  long long int n;
  cin >> n;

  string s;
  cin >> s;

  vector< long long int > b;
  long long int cnt = 0;
  b.push_back(0);
  for ( long long int i = 0; i < n; i++ ) {
    if ( s[i] == '#' ) {
      cnt++;
    }
    b.push_back( cnt );
  }
  long long int ans = b[n];
  cnt = 0;
  for ( long long int i = 0; i < n; i++ ) {
    if ( s[ n - 1 - i ] == '.' ) {
      cnt++;
    }
    ans = min( ans, cnt + b[ n - 1 - i ] );
  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 2680
#include <stdio.h>

int main() {
    int n = 0, b = 0;
    int a[3][3] = {};

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            scanf("%d ", &a[i][j]);
        }
    }
    scanf("%d", &n);

    for (int k = 0; k < n; k++) {
        scanf("%d", &b);
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (a[i][j] == b)
                    a[i][j] = 0;
            }
        }
    }

    for (int i = 0; i < 3; i++) {
        if ((a[0][i] + a[1][i] + a[2][i] == 0) ||
            (a[i][0] + a[i][1] + a[i][2] == 0)) {
            printf("Yes\n");
            return 0;
        }
    }

    if ((a[0][0] + a[1][1] + a[2][2] == 0) ||
        (a[2][0] + a[1][1] + a[0][2] == 0)) {
        printf("Yes\n");
        return 0;
    }
    printf("No\n");
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;

public class Main {
    public static void main(String[] args) throws IOException {
        InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
        BufferedReader in = new BufferedReader(reader);
        String[] str = in.readLine().split("");
        double num = 0;
        double res = 0;

        for(int i=0; i < str.length; i++) {
        	num = num*10 + Integer.parseInt(str[i]);
        	if(i % 10 == 0 ) {
        		res += num % 9;
        		num = 0;
        	}
            else if(i == str.length-1){
        		res += num % 9;
            }
        }
        if(res % 9 == 0) {
            System.out.println("Yes");

        }else {
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 50228
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int ans = pow(n,3);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n;
  cin >> n;
  cout << n * (n - 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(300000)


def dfs(v, x, G, X, visited, ans):
    visited[v] = True
    ans[v] = x
    # print(visited)

    for nv in G[v]:
        if visited[nv]:
            continue
        dfs(nv, x+X[nv], G, X, visited, ans)


def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)
    X = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        X[p-1] += x
    # print(G)
    # print(X)
    
    visited = [False]*N
    ans = [0]*N
    dfs(0, X[0], G, X, visited, ans)
    print(' '.join(list(map(str, ans))))
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 241476
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;
//struct edge { int to, cost; };

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

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int modinv2(int a, int mod) {
    return mod_pow(a, mod - 2, mod);
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

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

    int n, m;
    int h[100005];
    bool ans[100005];

    cin >> n >> m;
    rep(i, n) cin >> h[i];
    rep(i, n) ans[i] = true;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (h[a] > h[b]) {
            ans[b] = false;
        }
        else if (h[a] < h[b]) {
            ans[a] = false;
        }
        else {
            ans[a] = false;
            ans[b] = false;
        }
    }
    int cnt = 0;
    rep(i, n) {
        if (ans[i]) cnt++;
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 4556
import java.util.*;
class Main{
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        String s="0",s2="0";
        while(sc.hasNext()){
        	s2=sc.nextLine();
            s=s.concat(s2);
        	
        }
        s=s.toLowerCase();
        char []c=new char[26];
        int []count=new int[26];
        char code=97;
        for(int i=0;i<26;i++){
            c[i]=code++;
        }
        for(int i=0;i<s.length();i++){
            for(int j=0;j<26;j++){
            	if(c[j]==s.charAt(i)){
                    count[j]++;
            	}
            }
        }
        for(int i=0;i<count.length;i++){
            System.out.println(c[i]+" : "+count[i]);
        }
    }
}


Measured memory_bytes: 26316
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <functional>
#include <atcoder/all>
using namespace std; using namespace atcoder;
using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vlll = vector<vll>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
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; }
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, LIS, digitDP, treeDP, Rerooting//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA, FordFulkerson//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q, T;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vll flag, D; vector<vpll> path; vs S;
int main() {
	ll T;
	cin >> T;
	for (i = 0; i < T; i++) {
		ll n, m, a, b;
		cin >> n >> m >> a >> b;
		cout << floor_sum(n, m, a, b) << endl;
	}
}

Measured memory_bytes: 3652